Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dpapp] Initial dpapp implementation being a vpp plugin #609

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/dash-bmv2-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,24 @@ jobs:
run: make docker-bmv2-bldr
- name: Generate SAI API
run: DOCKER_FLAGS=$docker_fg_flags make sai
- name: Pull/Build docker dpapp image
run: make docker-dash-dpapp
- name: Build bmv2 dpapp
run: DOCKER_FLAGS=$docker_fg_flags make dpapp
- name: Check if SAI spec is updated
run: DOCKER_FLAGS=$docker_fg_flags make check-sai-spec
- name: Build libsai c++ tests
run: DOCKER_FLAGS=$docker_fg_flags make test
- name: Prepare network
run: DOCKER_FLAGS=$docker_fg_flags make network
run: DOCKER_FLAGS=$docker_fg_flags make network HAVE_DPAPP=y
- name: Run P4 software switch (bmv2) with P4Runtime
run: DOCKER_FLAGS=$docker_bg_flags make run-switch
run: DOCKER_FLAGS=$docker_bg_flags make run-switch HAVE_DPAPP=y
- name: Force bmv2 to load forwarding pipeline config via dummy libsai call
run: DOCKER_FLAGS=$docker_fg_flags make init-switch
- name: Test SAI library over P4RT to switch
run: DOCKER_FLAGS=$docker_fg_flags make run-libsai-test
- name: Run dpapp
run: DOCKER_FLAGS=$docker_bg_flags make run-dpapp HAVE_DPAPP=y
- name: Generate saithrift-server
run: DOCKER_FLAGS=$docker_fg_flags make saithrift-server
- name: Generate saithrift-client local docker
Expand Down
1 change: 0 additions & 1 deletion dash-pipeline/bmv2/dash_headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ header dash_packet_meta_t {
const bit<16> PACKET_META_HDR_SIZE=dash_packet_meta_t.minSizeInBytes();

#define DASH_ETHTYPE 0x876d
#define DPAPP_MAC 0x02fe23f0e413 /* FIXME temp hardcode */

struct headers_t {
/* packet metadata headers */
Expand Down
1 change: 1 addition & 0 deletions dash-pipeline/bmv2/dash_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ struct metadata_t {
bit<16> dash_tunnel_next_hop_id;
bit<32> meter_class;
bit<8> local_region_id;
EthernetAddress cpu_mac;
}

#endif /* _SIRIUS_METADATA_P4_ */
2 changes: 1 addition & 1 deletion dash-pipeline/bmv2/stages/conntrack_lookup.p4
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ control conntrack_build_dash_header(inout headers_t hdr, in metadata_t meta,
hdr.packet_meta.length = length + PACKET_META_HDR_SIZE;

hdr.dp_ethernet.setValid();
hdr.dp_ethernet.dst_addr = DPAPP_MAC;
hdr.dp_ethernet.dst_addr = meta.cpu_mac;
hdr.dp_ethernet.src_addr = meta.u0_encap_data.underlay_smac;
hdr.dp_ethernet.ether_type = DASH_ETHTYPE;
}
Expand Down
2 changes: 2 additions & 0 deletions dash-pipeline/bmv2/stages/pre_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ control pre_pipeline_stage(inout headers_t hdr,

action set_internal_config(EthernetAddress neighbor_mac,
EthernetAddress mac,
EthernetAddress cpu_mac,
bit<1> flow_enabled) {
meta.u0_encap_data.underlay_dmac = neighbor_mac;
meta.u0_encap_data.underlay_smac = mac;
meta.cpu_mac = cpu_mac;
meta.flow_enabled = (bool)flow_enabled;
}

Expand Down
2 changes: 1 addition & 1 deletion dash-pipeline/dockerfiles/Dockerfile.saithrift-client-bldr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ADD requirements.txt /tests/
RUN apt update && apt install -y python3 python3-pip sudo && \
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 && \
sudo python3 -m pip install -r /tests/requirements.txt && \
sudo pip3 install scapy pysubnettree
sudo pip3 install scapy pysubnettree p4runtime

WORKDIR /

Expand Down
11 changes: 11 additions & 0 deletions dash-pipeline/dpapp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind to add a README here to help people getting started on it?


project(dash-plugin)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I /SAI/SAI/inc -I /SAI/SAI/experimental")

find_package(VPP)

add_subdirectory(dash)
24 changes: 24 additions & 0 deletions dash-pipeline/dpapp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SHELL=/bin/bash
BUILD_DIR=build
CMAKE_ARGS=

ifeq ($(V),1)
CMAKE_ARGS += --verbose
endif

all: dpapp

.PHONY:configure install clean

configure:
@cmake $(CMAKE_ARGS) -G Ninja -S . -B $(BUILD_DIR)

dpapp: configure
@cmake --build $(BUILD_DIR) $(CMAKE_ARGS)

clean:
@cmake --build $(BUILD_DIR) $(CMAKE_ARGS) -- clean

install:
@sudo cmake --build $(BUILD_DIR) $(CMAKE_ARGS) -- install

36 changes: 36 additions & 0 deletions dash-pipeline/dpapp/dash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_directories(${CMAKE_SOURCE_DIR})

# for generated API headers:
include_directories(${CMAKE_BINARY_DIR})

add_vpp_plugin(dash
SOURCES
node.c
dash.c
flow.c
saiapi.c

MULTIARCH_SOURCES
node.c

API_FILES
dash.api

API_TEST_SOURCES
dash_test.c

COMPONENT vpp-plugin-dash
)
34 changes: 34 additions & 0 deletions dash-pipeline/dpapp/dash/dash.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Hey Emacs use -*- mode: C -*- */
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* Define a simple binary API to control the feature */

option version = "0.1.0";
import "vnet/interface_types.api";

autoreply define dash_enable_disable {
/* Client identifier, set from api_main.my_client_index */
u32 client_index;

/* Arbitrary context, so client can match reply to request */
u32 context;

/* Enable / disable the feature */
bool enable_disable;

/* Interface handle */
vl_api_interface_index_t sw_if_index;
};
212 changes: 212 additions & 0 deletions dash-pipeline/dpapp/dash/dash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @brief Dash Plugin, plugin API / trace / CLI handling.
*/

#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <dash/dash.h>

#include <vlibapi/api.h>
#include <vlibmemory/api.h>

#include <dash/dash.api_enum.h>
#include <dash/dash.api_types.h>

#define REPLY_MSG_ID_BASE sm->msg_id_base
#include <vlibapi/api_helper_macros.h>

/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER () = {
.version = DASH_PLUGIN_BUILD_VER,
.description = "Dash of VPP Plugin",
};
/* *INDENT-ON* */

VLIB_REGISTER_LOG_CLASS (dash_log) = {
.class_name = "dash",
};

dash_main_t dash_main;

/**
* @brief Enable/disable the dash plugin.
*
* Action function shared between message handler and debug CLI.
*/

int dash_enable_disable (dash_main_t * sm, u32 sw_if_index,
int enable_disable)
{
vnet_sw_interface_t * sw;
int rv = 0;

/* Utterly wrong? */
if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
sw_if_index))
return VNET_API_ERROR_INVALID_SW_IF_INDEX;

/* Not a physical port? */
sw = vnet_get_sw_interface (sm->vnet_main, sw_if_index);
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return VNET_API_ERROR_INVALID_SW_IF_INDEX;

vnet_feature_enable_disable ("dash-pipeline", "dash-pipeline-input",
sw_if_index, enable_disable, 0, 0);

return rv;
}

static clib_error_t *
dash_cmd_set_enable_disable_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
dash_main_t * sm = &dash_main;
u32 sw_if_index = ~0;
int enable_disable = 1;
int rv;

while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
if (unformat (input, "disable"))
enable_disable = 0;
else if (unformat (input, "%U", unformat_vnet_sw_interface,
sm->vnet_main, &sw_if_index))
;
else
break;
}

if (sw_if_index == ~0)
return clib_error_return (0, "Please specify an interface...");

rv = dash_enable_disable (sm, sw_if_index, enable_disable);

switch(rv) {
case 0:
break;

case VNET_API_ERROR_INVALID_SW_IF_INDEX:
return clib_error_return
(0, "Invalid interface, only works on physical ports");
break;

case VNET_API_ERROR_UNIMPLEMENTED:
return clib_error_return (0, "Device driver doesn't support redirection");
break;

default:
return clib_error_return (0, "dash_enable_disable returned %d",
rv);
}
return 0;
}

/**
* @brief CLI command to enable/disable the dash plugin.
*/
VLIB_CLI_COMMAND (dash_set_command, static) = {
.path = "set dash",
.short_help =
"set dash <interface-name> [disable]",
.function = dash_cmd_set_enable_disable_fn,
};

/**
* @brief Plugin API message handler.
*/
static void vl_api_dash_enable_disable_t_handler
(vl_api_dash_enable_disable_t * mp)
{
vl_api_dash_enable_disable_reply_t * rmp;
dash_main_t * sm = &dash_main;
int rv;

rv = dash_enable_disable (sm, ntohl(mp->sw_if_index),
(int) (mp->enable_disable));

REPLY_MACRO(VL_API_DASH_ENABLE_DISABLE_REPLY);
}

/* API definitions */
#include <dash/dash.api.c>

/**
* @brief Initialize the dash plugin.
*/
static clib_error_t * dash_init (vlib_main_t * vm)
{
dash_main_t * sm = &dash_main;

sm->vnet_main = vnet_get_main ();

/* Add our API messages to the global name_crc hash table */
sm->msg_id_base = setup_message_id_table ();

/* Reuse SECURE_DATA (0x876D) for dash metadata */
ethernet_register_input_type (vm, ETHERNET_TYPE_SECURE_DATA, dash_node.index);

dash_flow_table_init(dash_flow_table_get());

dash_sai_init();

return 0;
}

VLIB_INIT_FUNCTION (dash_init);

/**
* @brief Hook the dash plugin into the VPP graph hierarchy.
*/
VNET_FEATURE_ARC_INIT (dash_pipeline, static) =
{
.arc_name = "dash-pipeline",
.start_nodes = VNET_FEATURES ("dash-pipeline-input"),
.last_in_arc = "error-drop",
.arc_index_ptr = &dash_main.feature_arc_index,
};

static uword
dash_timer_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{

int i;
f64 sleep_duration = 1.0;

unix_sleep (5.0); /* FIXME: delay 5s */

while (1)
{
/* FIXME: Use time-wheel per-worker thread later */
//for (i = 1; i < vlib_get_n_threads(); i++) {
vlib_node_set_interrupt_pending (vlib_get_main_by_index(1),
dash_flow_scan_node.index);
//}

vlib_process_suspend (vm, sleep_duration);
}
return 0;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (dash_timer_node,static) = {
.function = dash_timer_process,
.name = "dash-timer-process",
.type = VLIB_NODE_TYPE_PROCESS,
};
/* *INDENT-ON* */

Loading
Loading