-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
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) | ||
|
||
add_vpp_packaging( | ||
NAME "dash-plugin" | ||
VENDOR "fd.io" | ||
DESCRIPTION "VPP Dash Plugin" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: vpp | ||
|
||
.PHONY:configure install clean | ||
|
||
configure: | ||
@cmake $(CMAKE_ARGS) -G Ninja -S . -B $(BUILD_DIR) | ||
|
||
vpp: configure | ||
@cmake --build $(BUILD_DIR) $(CMAKE_ARGS) | ||
|
||
clean: | ||
@cmake --build $(BUILD_DIR) $(CMAKE_ARGS) -- clean | ||
|
||
install: | ||
@sudo cmake --build $(BUILD_DIR) $(CMAKE_ARGS) -- install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* */ | ||
|
Oops, something went wrong.