From c323cabf23d64b9c55d688bf968194b816e19d67 Mon Sep 17 00:00:00 2001 From: Vengada Date: Tue, 21 Mar 2017 01:01:51 -0700 Subject: Changes for supoprting iOAM/ NSH export. Add a separate node for POP only handling to support iOAM export dynamic node. Change-Id: I411ee93ea3ec34ed24c18c1ba4b5dc1c9533e483 Signed-off-by: Vengada --- nsh-plugin/Makefile.am | 6 +- .../export-nsh-md2-ioam/nsh_md2_ioam_export.c | 180 ++++++++++ .../nsh_md2_ioam_export_thread.c | 50 +++ .../export-nsh-md2-ioam/nsh_md2_ioam_node.c | 155 +++++++++ nsh-plugin/nsh/nsh.api | 2 + nsh-plugin/nsh/nsh.c | 40 ++- nsh-plugin/nsh/nsh.h | 5 + nsh-plugin/nsh/nsh_pop.c | 366 +++++++++++++++++++++ 8 files changed, 789 insertions(+), 15 deletions(-) create mode 100644 nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export.c create mode 100644 nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export_thread.c create mode 100644 nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_node.c create mode 100644 nsh-plugin/nsh/nsh_pop.c diff --git a/nsh-plugin/Makefile.am b/nsh-plugin/Makefile.am index 2da0460..64be6b6 100644 --- a/nsh-plugin/Makefile.am +++ b/nsh-plugin/Makefile.am @@ -22,11 +22,15 @@ CPPFLAGS += -DDEBUG -g lib_LTLIBRARIES = nsh_plugin.la nsh_test_plugin.la nsh_plugin_la_SOURCES = nsh/nsh.c \ + nsh/nsh_pop.c \ vpp-api/nsh.api.h \ nsh-md2-ioam/nsh_md2_ioam.c \ nsh-md2-ioam/nsh_md2_ioam_trace.c \ nsh-md2-ioam/md2_ioam_transit.c \ - nsh-md2-ioam/nsh_md2_ioam_api.c + nsh-md2-ioam/nsh_md2_ioam_api.c \ + nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export.c \ + nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export_thread.c \ + nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_node.c nsh_plugin_la_LDFLAGS = -module diff --git a/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export.c b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export.c new file mode 100644 index 0000000..4860846 --- /dev/null +++ b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export.c @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2016 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. + */ +/* + *------------------------------------------------------------------ + * nsh_md2_ioam_export.c - ioam export API / debug CLI handling + *------------------------------------------------------------------ + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include + + +ioam_export_main_t nsh_md2_ioam_export_main; + + +extern vlib_node_registration_t nsh_md2_ioam_export_node; +extern void nsh_md2_set_next_ioam_export_override (uword next); +/* Action function shared between message handler and debug CLI */ +int +nsh_md2_ioam_export_enable_disable (ioam_export_main_t * em, + u8 is_disable, + ip4_address_t * collector_address, + ip4_address_t * src_address) +{ + vlib_main_t *vm = em->vlib_main; + u32 node_index = nsh_md2_ioam_export_node.index; + vlib_node_t *nsh_input_node = NULL; + + if (is_disable == 0) + { + if (em->my_hbh_slot == ~0) + { + /* Hook this export node to nsh-input */ + nsh_input_node = + vlib_get_node_by_name (vm, (u8 *) "nsh-input"); + if (!nsh_input_node) + { + /* node does not exist give up */ + return (-1); + } + em->my_hbh_slot = + vlib_node_add_next (vm, nsh_input_node->index, + node_index); + } + if (1 == ioam_export_header_create (em, collector_address, src_address)) + { + ioam_export_thread_buffer_init (em, vm); + nsh_md2_set_next_ioam_export_override (em->my_hbh_slot); + /* Turn on the export buffer check process */ + vlib_process_signal_event (vm, em->export_process_node_index, 1, 0); + + } + else + { + return (-2); + } + } + else + { + nsh_md2_set_next_ioam_export_override (0); // VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP + ioam_export_header_cleanup (em, collector_address, src_address); + ioam_export_thread_buffer_free (em); + /* Turn off the export buffer check process */ + vlib_process_signal_event (vm, em->export_process_node_index, 2, 0); + + } + + return 0; +} + + + +static clib_error_t * +set_nsh_md2_ioam_export_ipfix_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + ioam_export_main_t *em = &nsh_md2_ioam_export_main; + ip4_address_t collector, src; + u8 is_disable = 0; + + collector.as_u32 = 0; + src.as_u32 = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "collector %U", unformat_ip4_address, &collector)) + ; + else if (unformat (input, "src %U", unformat_ip4_address, &src)) + ; + else if (unformat (input, "disable")) + is_disable = 1; + else + break; + } + + if (collector.as_u32 == 0) + return clib_error_return (0, "collector address required"); + + if (src.as_u32 == 0) + return clib_error_return (0, "src address required"); + + em->ipfix_collector.as_u32 = collector.as_u32; + em->src_address.as_u32 = src.as_u32; + + vlib_cli_output (vm, "Collector %U, src address %U", + format_ip4_address, &em->ipfix_collector, + format_ip4_address, &em->src_address); + + /* Turn on the export timer process */ + // vlib_process_signal_event (vm, flow_report_process_node.index, + //1, 0); + if (0 != + nsh_md2_ioam_export_enable_disable (em, is_disable, &collector, &src)) + { + return clib_error_return (0, "Unable to set ioam nsh-md2 export"); + } + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_nsh_md2_ioam_ipfix_command, static) = +{ +.path = "set nsh-md2-ioam export ipfix", +.short_help = "set nsh-md2-ioam export ipfix collector src ", +.function = set_nsh_md2_ioam_export_ipfix_command_fn, +}; +/* *INDENT-ON* */ + + +#define IPFIX_NSH_MD2_IOAM_EXPORT_ID 274 // TODO: Move this to ioam/ioam_export.h +static clib_error_t * +nsh_md2_ioam_export_init (vlib_main_t * vm) +{ + ioam_export_main_t *em = &nsh_md2_ioam_export_main; + clib_error_t *error = 0; + + em->set_id = IPFIX_NSH_MD2_IOAM_EXPORT_ID; + em->unix_time_0 = (u32) time (0); /* Store starting time */ + em->vlib_time_0 = vlib_time_now (vm); + + em->my_hbh_slot = ~0; + em->vlib_main = vm; + em->vnet_main = vnet_get_main (); + ioam_export_reset_next_node (em); + + return error; +} + +VLIB_INIT_FUNCTION (nsh_md2_ioam_export_init); + + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export_thread.c b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export_thread.c new file mode 100644 index 0000000..cf6b2e2 --- /dev/null +++ b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_export_thread.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 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. + */ +/* + * nsh_md2_ioam_export_thread.c + */ +#include +#include +#include + +static vlib_node_registration_t nsh_md2_ioam_export_process_node; +extern ioam_export_main_t nsh_md2_ioam_export_main; + +static uword +nsh_md2_ioam_export_process (vlib_main_t * vm, + vlib_node_runtime_t * rt, vlib_frame_t * f) +{ + return (ioam_export_process_common (&nsh_md2_ioam_export_main, + vm, rt, f, + nsh_md2_ioam_export_process_node.index)); +} + + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (nsh_md2_ioam_export_process_node, static) = +{ + .function = nsh_md2_ioam_export_process, + .type = VLIB_NODE_TYPE_PROCESS, + .name = "nsh-md2-ioam-export-process", +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_node.c b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_node.c new file mode 100644 index 0000000..fb76c60 --- /dev/null +++ b/nsh-plugin/nsh-md2-ioam/export-nsh-md2-ioam/nsh_md2_ioam_node.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include +#include +#include + +typedef struct +{ + u32 next_index; + u32 flow_label; +} export_trace_t; + +extern ioam_export_main_t nsh_md2_ioam_export_main; +vlib_node_registration_t export_node; +/* packet trace format function */ +static u8 * +format_export_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + export_trace_t *t = va_arg (*args, export_trace_t *); + + s = format (s, "EXPORT: flow_label %d, next index %d", + t->flow_label, t->next_index); + return s; +} + +vlib_node_registration_t nsh_md2_ioam_export_node; + +#define foreach_export_error \ +_(RECORDED, "Packets recorded for export") + +typedef enum +{ +#define _(sym,str) EXPORT_ERROR_##sym, + foreach_export_error +#undef _ + EXPORT_N_ERROR, +} export_error_t; + +static char *export_error_strings[] = { +#define _(sym,string) string, + foreach_export_error +#undef _ +}; + +typedef enum +{ + EXPORT_NEXT_NSH_MD2_IOAM_INPUT, + EXPORT_N_NEXT, +} export_next_t; + +always_inline void +copy3cachelines (void *dst, const void *src, size_t n) +{ + + u64 *copy_dst, *copy_src; + int i; + copy_dst = (u64 *) dst; + copy_src = (u64 *) src; + if (PREDICT_FALSE (n < DEFAULT_EXPORT_SIZE)) + { + for (i = 0; i < n / 64; i++) + { + copy_dst[0] = copy_src[0]; + copy_dst[1] = copy_src[1]; + copy_dst[2] = copy_src[2]; + copy_dst[3] = copy_src[3]; + copy_dst[4] = copy_src[4]; + copy_dst[5] = copy_src[5]; + copy_dst[6] = copy_src[6]; + copy_dst[7] = copy_src[7]; + copy_dst += 8; + copy_src += 8; + } + return; + } + for (i = 0; i < 3; i++) + { + copy_dst[0] = copy_src[0]; + copy_dst[1] = copy_src[1]; + copy_dst[2] = copy_src[2]; + copy_dst[3] = copy_src[3]; + copy_dst[4] = copy_src[4]; + copy_dst[5] = copy_src[5]; + copy_dst[6] = copy_src[6]; + copy_dst[7] = copy_src[7]; + copy_dst += 8; + copy_src += 8; + } +} + +static void +nsh_md2_ioam_export_fixup_func (vlib_buffer_t * export_buf, + vlib_buffer_t * pak_buf) +{ + /* Todo: on implementing analyse */ +} + +static uword +nsh_md2_ioam_export_node_fn (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + ioam_export_main_t *em = &nsh_md2_ioam_export_main; + ioam_export_node_common (em, vm, node, frame, ip4_header_t, length, + ip_version_and_header_length, + EXPORT_NEXT_NSH_MD2_IOAM_INPUT, + nsh_md2_ioam_export_fixup_func); + return frame->n_vectors; +} + +/* + * Node for iOAM export + */ +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (nsh_md2_ioam_export_node) = +{ + .function = nsh_md2_ioam_export_node_fn, + .name = "nsh-md2-ioam-export", + .vector_size = sizeof (u32), + .format_trace = format_export_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + .n_errors = ARRAY_LEN (export_error_strings), + .error_strings = export_error_strings, + .n_next_nodes = EXPORT_N_NEXT, + /* edit / add dispositions here */ + .next_nodes = + {[EXPORT_NEXT_NSH_MD2_IOAM_INPUT] = "nsh-pop"}, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/nsh-plugin/nsh/nsh.api b/nsh-plugin/nsh/nsh.api index ee3f91f..1ef3c7b 100644 --- a/nsh-plugin/nsh/nsh.api +++ b/nsh-plugin/nsh/nsh.api @@ -88,6 +88,7 @@ define nsh_add_del_map { u32 mapped_nsp_nsi; u32 nsh_action; u32 sw_if_index; + u32 rx_sw_if_index; u32 next_node; }; @@ -114,5 +115,6 @@ define nsh_map_details { u32 mapped_nsp_nsi; u32 nsh_action; u32 sw_if_index; + u32 rx_sw_if_index; u32 next_node; }; diff --git a/nsh-plugin/nsh/nsh.c b/nsh-plugin/nsh/nsh.c index bfa75fd..c97856c 100644 --- a/nsh-plugin/nsh/nsh.c +++ b/nsh-plugin/nsh/nsh.c @@ -234,10 +234,6 @@ nsh_md2_unregister_option (u16 class, return (0); } -typedef struct { - u8 trace_data[256]; -} nsh_input_trace_t; - /* format from network order */ u8 * format_nsh_header (u8 * s, va_list * args) { @@ -507,6 +503,7 @@ int nsh_add_del_map (nsh_add_del_map_args_t *a, u32 * map_indexp) map->mapped_nsp_nsi = a->map.mapped_nsp_nsi; map->nsh_action = a->map.nsh_action; map->sw_if_index = a->map.sw_if_index; + map->rx_sw_if_index = a->map.rx_sw_if_index; map->next_node = a->map.next_node; @@ -666,6 +663,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, int nsh_action_set = 0; u32 next_node = ~0; u32 sw_if_index = ~0; // temporary requirement to get this moved over to NSHSFC + u32 rx_sw_if_index = ~0; // temporary requirement to get this moved over to NSHSFC nsh_add_del_map_args_t _a, * a = &_a; u32 map_index; int rv; @@ -698,7 +696,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, next_node = NSH_NODE_NEXT_ENCAP_VXLAN4; else if (unformat (line_input, "encap-vxlan6-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_VXLAN6; - else if (unformat (line_input, "encap-none %d", &sw_if_index)) + else if (unformat (line_input, "encap-none %d %d", &sw_if_index, &rx_sw_if_index)) next_node = NSH_NODE_NEXT_DECAP_ETH_INPUT; else return clib_error_return (0, "parse error: '%U'", @@ -717,7 +715,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, return clib_error_return (0, "nsh_action required: swap|push|pop."); if (next_node == ~0) - return clib_error_return (0, "must specific action: [encap-gre-intf | encap-vxlan-gpe-intf | encap-lisp-gpe-intf | encap-none ]"); + return clib_error_return (0, "must specific action: [encap-gre-intf | encap-vxlan-gpe-intf | encap-lisp-gpe-intf | encap-none ]"); memset (a, 0, sizeof (*a)); @@ -727,6 +725,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, a->map.mapped_nsp_nsi = (mapped_nsp<< NSH_NSP_SHIFT) | mapped_nsi; a->map.nsh_action = nsh_action; a->map.sw_if_index = sw_if_index; + a->map.rx_sw_if_index = rx_sw_if_index; a->map.next_node = next_node; rv = nsh_add_del_map(a, &map_index); @@ -793,6 +792,7 @@ static void vl_api_nsh_add_del_map_t_handler a->map.mapped_nsp_nsi = ntohl(mp->mapped_nsp_nsi); a->map.nsh_action = ntohl(mp->nsh_action); a->map.sw_if_index = ntohl(mp->sw_if_index); + a->map.rx_sw_if_index = ntohl(mp->rx_sw_if_index); a->map.next_node = ntohl(mp->next_node); rv = nsh_add_del_map (a, &map_index); @@ -1309,6 +1309,7 @@ static void send_nsh_map_details rmp->mapped_nsp_nsi = htonl(t->mapped_nsp_nsi); rmp->nsh_action = htonl(t->nsh_action); rmp->sw_if_index = htonl(t->sw_if_index); + rmp->rx_sw_if_index = htonl(t->rx_sw_if_index); rmp->next_node = htonl(t->next_node); rmp->context = context; @@ -1540,7 +1541,7 @@ next_tlv_md2: always_inline void nsh_md2_decap (vlib_buffer_t * b, nsh_base_header_t * hdr, - u32 header_len, + u32 *header_len, u32 * next, u32 drop_node_val) { @@ -1552,7 +1553,7 @@ nsh_md2_decap (vlib_buffer_t * b, /* Populate the NSH Header */ opt0 = (nsh_md2_data_t *)(hdr + 1); - limit0 = (nsh_md2_data_t *) ((u8 *) hdr + header_len); + limit0 = (nsh_md2_data_t *) ((u8 *) hdr + *header_len); /* Scan the set of variable metadata, process ones that we understand */ while (opt0 < limit0) @@ -1575,6 +1576,8 @@ nsh_md2_decap (vlib_buffer_t * b, /* round to 4-byte */ option_len = ( (opt0->length+3)>>2 ) << 2; opt0 = (nsh_md2_data_t *) (((u8 *) opt0) + sizeof (nsh_md2_data_t) + option_len); + *next = (nm->decap_v4_next_override) ? (nm->decap_v4_next_override) : (*next); + *header_len = (nm->decap_v4_next_override) ? 0 : (*header_len); } return; @@ -1735,13 +1738,13 @@ nsh_input_map (vlib_main_t * vm, /* Manipulate MD2 */ if(PREDICT_FALSE(hdr0->md_type == 2)) { - vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->sw_if_index; - nsh_md2_decap(b0, hdr0, header_len0, &next0, NSH_NODE_NEXT_DROP); + nsh_md2_decap(b0, hdr0, &header_len0, &next0, NSH_NODE_NEXT_DROP); if (PREDICT_FALSE(next0 == NSH_NODE_NEXT_DROP)) { error0 = NSH_NODE_ERROR_INVALID_OPTIONS; goto trace0; } + vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->rx_sw_if_index; } /* Pop NSH header */ @@ -1838,13 +1841,13 @@ nsh_input_map (vlib_main_t * vm, /* Manipulate MD2 */ if(PREDICT_FALSE(hdr1->md_type == 2)) { - vnet_buffer(b1)->sw_if_index[VLIB_RX] = map1->sw_if_index; - nsh_md2_decap(b1, hdr1, header_len1, &next1, NSH_NODE_NEXT_DROP); + nsh_md2_decap(b1, hdr1, &header_len1, &next1, NSH_NODE_NEXT_DROP); if (PREDICT_FALSE(next1 == NSH_NODE_NEXT_DROP)) { error1 = NSH_NODE_ERROR_INVALID_OPTIONS; goto trace1; } + vnet_buffer(b1)->sw_if_index[VLIB_RX] = map0->rx_sw_if_index; } /* Pop NSH header */ @@ -2024,13 +2027,13 @@ nsh_input_map (vlib_main_t * vm, /* Manipulate MD2 */ if(PREDICT_FALSE(hdr0->md_type == 2)) { - vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->sw_if_index; - nsh_md2_decap(b0, hdr0, header_len0, &next0, NSH_NODE_NEXT_DROP); + nsh_md2_decap(b0, hdr0, &header_len0, &next0, NSH_NODE_NEXT_DROP); if (PREDICT_FALSE(next0 == NSH_NODE_NEXT_DROP)) { error0 = NSH_NODE_ERROR_INVALID_OPTIONS; goto trace00; } + vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->rx_sw_if_index; } /* Pop NSH header */ @@ -2282,6 +2285,15 @@ VLIB_REGISTER_NODE (nsh_aware_vnf_proxy_node) = { VLIB_NODE_FUNCTION_MULTIARCH (nsh_aware_vnf_proxy_node, nsh_aware_vnf_proxy); +void +nsh_md2_set_next_ioam_export_override (uword next) +{ + nsh_main_t *hm = &nsh_main; + hm->decap_v4_next_override = next; + return; +} + + clib_error_t *nsh_init (vlib_main_t *vm) { nsh_main_t *nm = &nsh_main; diff --git a/nsh-plugin/nsh/nsh.h b/nsh-plugin/nsh/nsh.h index 501f756..b03c8e7 100644 --- a/nsh-plugin/nsh/nsh.h +++ b/nsh-plugin/nsh/nsh.h @@ -74,6 +74,7 @@ typedef struct { /* encap if index */ u32 sw_if_index; + u32 rx_sw_if_index; u32 next_node; } nsh_map_t; @@ -145,6 +146,7 @@ typedef struct { int (*pop_options[MAX_MD2_OPTIONS]) (vlib_buffer_t * b, nsh_tlv_header_t * opt); u8 *(*trace[MAX_MD2_OPTIONS]) (u8 * s, nsh_tlv_header_t * opt); + uword decap_v4_next_override; /* convenience */ vlib_main_t * vlib_main; @@ -154,6 +156,9 @@ typedef struct { nsh_main_t nsh_main; extern vlib_node_registration_t nsh_aware_vnf_proxy_node; +typedef struct { + u8 trace_data[256]; +} nsh_input_trace_t; u8 * format_nsh_input_map_trace (u8 * s, va_list * args); u8 * format_nsh_header_with_length (u8 * s, va_list * args); diff --git a/nsh-plugin/nsh/nsh_pop.c b/nsh-plugin/nsh/nsh_pop.c new file mode 100644 index 0000000..ed3d84a --- /dev/null +++ b/nsh-plugin/nsh/nsh_pop.c @@ -0,0 +1,366 @@ +/* + * nsh_pop.c - nsh POP only processing + * + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +extern nsh_option_map_t * nsh_md2_lookup_option (u16 class, u8 type); + +extern u8 * format_nsh_header (u8 * s, va_list * args); +extern u8 * format_nsh_node_map_trace (u8 * s, va_list * args); + +/* format from network order */ +u8 * format_nsh_pop_header (u8 * s, va_list * args) +{ + return format_nsh_header(s, args); +} + + + +u8 * format_nsh_pop_node_map_trace (u8 * s, va_list * args) +{ + return format_nsh_node_map_trace(s, args); +} + + +static uword +nsh_pop_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, next_index, *from, *to_next; + nsh_main_t * nm = &nsh_main; + + from = vlib_frame_vector_args(from_frame); + n_left_from = from_frame->n_vectors; + + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from >= 4 && n_left_to_next >= 2) + { + u32 bi0, bi1; + vlib_buffer_t * b0, *b1; + u32 next0 = NSH_NODE_NEXT_DROP, next1 = NSH_NODE_NEXT_DROP; + uword * entry0, *entry1; + nsh_base_header_t * hdr0 = 0, *hdr1 = 0; + u32 header_len0 = 0, header_len1 = 0; + u32 nsp_nsi0, nsp_nsi1; + u32 error0, error1; + nsh_map_t * map0 = 0, *map1 = 0; + + /* Prefetch next iteration. */ + { + vlib_buffer_t * p2, *p3; + + p2 = vlib_get_buffer(vm, from[2]); + p3 = vlib_get_buffer(vm, from[3]); + + vlib_prefetch_buffer_header(p2, LOAD); + vlib_prefetch_buffer_header(p3, LOAD); + + CLIB_PREFETCH(p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD); + CLIB_PREFETCH(p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD); + } + + bi0 = from[0]; + bi1 = from[1]; + to_next[0] = bi0; + to_next[1] = bi1; + from += 2; + to_next += 2; + n_left_from -= 2; + n_left_to_next -= 2; + + error0 = 0; + error1 = 0; + + b0 = vlib_get_buffer(vm, bi0); + b1 = vlib_get_buffer(vm, bi1); + hdr0 = vlib_buffer_get_current(b0); + nsp_nsi0 = hdr0->nsp_nsi; + header_len0 = hdr0->length * 4; + + hdr1 = vlib_buffer_get_current(b1); + nsp_nsi1 = hdr1->nsp_nsi; + header_len1 = hdr1->length * 4; + + /* Process packet 0 */ + entry0 = hash_get_mem(nm->nsh_mapping_by_key, &nsp_nsi0); + if (PREDICT_FALSE(entry0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_MAPPING; + goto trace0; + } + + /* Entry should point to a mapping ...*/ + map0 = pool_elt_at_index(nm->nsh_mappings, entry0[0]); + if (PREDICT_FALSE(map0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_MAPPING; + goto trace0; + } + + /* set up things for next node to transmit ie which node to handle it and where */ + next0 = map0->next_node; + //vnet_buffer(b0)->sw_if_index[VLIB_TX] = map0->sw_if_index; + + if(PREDICT_FALSE(map0->nsh_action == NSH_ACTION_POP)) + { + /* Manipulate MD2 */ + if(PREDICT_FALSE(hdr0->md_type == 2)) + { + if (PREDICT_FALSE(next0 == NSH_NODE_NEXT_DROP)) + { + error0 = NSH_NODE_ERROR_INVALID_OPTIONS; + goto trace0; + } + //vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->sw_if_index; + } + + /* Pop NSH header */ + vlib_buffer_advance(b0, (word)header_len0); + goto trace0; + } + + entry0 = hash_get_mem(nm->nsh_entry_by_key, &map0->mapped_nsp_nsi); + if (PREDICT_FALSE(entry0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_ENTRY; + goto trace0; + } + + trace0: b0->error = error0 ? node->errors[error0] : 0; + + if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) + { + nsh_input_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr)); + clib_memcpy ( &(tr->trace_data), hdr0, (hdr0->length*4) ); + } + + /* Process packet 1 */ + entry1 = hash_get_mem(nm->nsh_mapping_by_key, &nsp_nsi1); + if (PREDICT_FALSE(entry1 == 0)) + { + error1 = NSH_NODE_ERROR_NO_MAPPING; + goto trace1; + } + + /* Entry should point to a mapping ...*/ + map1 = pool_elt_at_index(nm->nsh_mappings, entry1[0]); + if (PREDICT_FALSE(map1 == 0)) + { + error1 = NSH_NODE_ERROR_NO_MAPPING; + goto trace1; + } + + /* set up things for next node to transmit ie which node to handle it and where */ + next1 = map1->next_node; + //vnet_buffer(b1)->sw_if_index[VLIB_TX] = map1->sw_if_index; + + if(PREDICT_FALSE(map1->nsh_action == NSH_ACTION_POP)) + { + /* Manipulate MD2 */ + if(PREDICT_FALSE(hdr1->md_type == 2)) + { + if (PREDICT_FALSE(next1 == NSH_NODE_NEXT_DROP)) + { + error1 = NSH_NODE_ERROR_INVALID_OPTIONS; + goto trace1; + } + //vnet_buffer(b1)->sw_if_index[VLIB_RX] = map1->sw_if_index; + } + + /* Pop NSH header */ + vlib_buffer_advance(b1, (word)header_len1); + goto trace1; + } + + entry1 = hash_get_mem(nm->nsh_entry_by_key, &map1->mapped_nsp_nsi); + if (PREDICT_FALSE(entry1 == 0)) + { + error1 = NSH_NODE_ERROR_NO_ENTRY; + goto trace1; + } + + + trace1: b1->error = error1 ? node->errors[error1] : 0; + + if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) + { + nsh_input_trace_t *tr = vlib_add_trace(vm, node, b1, sizeof(*tr)); + clib_memcpy ( &(tr->trace_data), hdr1, (hdr1->length*4) ); + } + + vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, + n_left_to_next, bi0, bi1, next0, next1); + + } + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0 = 0; + vlib_buffer_t * b0 = NULL; + u32 next0 = NSH_NODE_NEXT_DROP; + uword * entry0; + nsh_base_header_t * hdr0 = 0; + u32 header_len0 = 0; + u32 nsp_nsi0; + u32 error0; + nsh_map_t * map0 = 0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + error0 = 0; + + b0 = vlib_get_buffer(vm, bi0); + hdr0 = vlib_buffer_get_current(b0); + + nsp_nsi0 = hdr0->nsp_nsi; + header_len0 = hdr0->length * 4; + + entry0 = hash_get_mem(nm->nsh_mapping_by_key, &nsp_nsi0); + + if (PREDICT_FALSE(entry0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_MAPPING; + goto trace00; + } + + /* Entry should point to a mapping ...*/ + map0 = pool_elt_at_index(nm->nsh_mappings, entry0[0]); + + if (PREDICT_FALSE(map0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_MAPPING; + goto trace00; + } + + /* set up things for next node to transmit ie which node to handle it and where */ + next0 = map0->next_node; + //vnet_buffer(b0)->sw_if_index[VLIB_TX] = map0->sw_if_index; + + if(PREDICT_FALSE(map0->nsh_action == NSH_ACTION_POP)) + { + /* Manipulate MD2 */ + if(PREDICT_FALSE(hdr0->md_type == 2)) + { + if (PREDICT_FALSE(next0 == NSH_NODE_NEXT_DROP)) + { + error0 = NSH_NODE_ERROR_INVALID_OPTIONS; + goto trace00; + } + //vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->sw_if_index; + } + + /* Pop NSH header */ + vlib_buffer_advance(b0, (word)header_len0); + goto trace00; + } + + entry0 = hash_get_mem(nm->nsh_entry_by_key, &map0->mapped_nsp_nsi); + if (PREDICT_FALSE(entry0 == 0)) + { + error0 = NSH_NODE_ERROR_NO_ENTRY; + goto trace00; + } + + trace00: b0->error = error0 ? node->errors[error0] : 0; + + if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) + { + nsh_input_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr)); + clib_memcpy ( &(tr->trace_data[0]), hdr0, (hdr0->length*4) ); + } + + vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, + n_left_to_next, bi0, next0); + } + + vlib_put_next_frame(vm, node, next_index, n_left_to_next); + + } + + return from_frame->n_vectors; +} + +/** + * @brief Graph processing dispatch function for NSH Input + * + * @node nsh_input + * @param *vm + * @param *node + * @param *from_frame + * + * @return from_frame->n_vectors + * + */ +static uword +nsh_pop (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return nsh_pop_inline (vm, node, from_frame); +} + +static char * nsh_pop_node_error_strings[] = { +#define _(sym,string) string, + foreach_nsh_node_error +#undef _ +}; + +/* register nsh-input node */ +VLIB_REGISTER_NODE (nsh_pop_node) = { + .function = nsh_pop, + .name = "nsh-pop", + .vector_size = sizeof (u32), + .format_trace = format_nsh_pop_node_map_trace, + .format_buffer = format_nsh_pop_header, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = ARRAY_LEN(nsh_pop_node_error_strings), + .error_strings = nsh_pop_node_error_strings, + + .n_next_nodes = NSH_NODE_N_NEXT, + + .next_nodes = { +#define _(s,n) [NSH_NODE_NEXT_##s] = n, + foreach_nsh_node_next +#undef _ + }, +}; + +VLIB_NODE_FUNCTION_MULTIARCH (nsh_pop_node, nsh_pop); + + -- cgit 1.2.3-korg