/* * 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. */ #include #include #include #include /** * @file * @brief Layer 2 Rewrite. * * Layer 2-Rewrite node uses classify tables to match packets. Then, using * the provisioned mask and value, modifies the packet header. */ #ifndef CLIB_MARCH_VARIANT l2_rw_main_t l2_rw_main; #endif /* CLIB_MARCH_VARIANT */ typedef struct { u32 sw_if_index; u32 classify_table_index; u32 rewrite_entry_index; } l2_rw_trace_t; static u8 * format_l2_rw_entry (u8 * s, va_list * args) { l2_rw_entry_t *e = va_arg (*args, l2_rw_entry_t *); l2_rw_main_t *rw = &l2_rw_main; s = format (s, "%d - mask:%U value:%U\n", e - rw->entries, format_hex_bytes, e->mask, e->rewrite_n_vectors * sizeof (u32x4), format_hex_bytes, e->value, e->rewrite_n_vectors * sizeof (u32x4)); s = format (s, " hits:%d skip_bytes:%d", e->hit_count, e->skip_n_vectors * sizeof (u32x4)); return s; } static u8 * format_l2_rw_config (u8 * s, va_list * args) { l2_rw_config_t *c = va_arg (*args, l2_rw_config_t *); return format (s, "table-index:%d miss-index:%d", c->table_index, c->miss_index); } /* packet trace format function */ static u8 * format_l2_rw_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 *); l2_rw_trace_t *t = va_arg (*args, l2_rw_trace_t *); return format (s, "l2-rw: sw_if_index %d, table %d, entry %d", t->sw_if_index, t->classify_table_index, t->rewrite_entry_index); } always_inline l2_rw_config_t * l2_rw_get_config (u32 sw_if_index) { l2_rw_main_t *rw = &l2_rw_main; if (PREDICT_FALSE (!clib_bitmap_get (rw->configs_bitmap, sw_if_index))) { vec_validate (rw->configs, sw_if_index); rw->configs[sw_if_index].table_index = ~0; rw->configs[sw_if_index].miss_index = ~0; rw->configs_bitmap = clib_bitmap_set (rw->configs_bitmap, sw_if_index, 1); } return &rw->configs[sw_if_index]; } static_always_inline void l2_rw_rewrite (l2_rw_entry_t * rwe, u8 * h) { u32x4u *d = ((u32x4u *) h) + rwe->skip_n_vectors; switch (rwe->rewrite_n_vectors) { case 5: d[4] = (d[4] & ~rwe->mask[4]) | rwe->value[4]; /* FALLTHROUGH */ case 4: d[3] = (d[3] & ~rwe->mask[3]) | rwe->value[3]; /* FALLTHROUGH */ case 3: d[2] = (d[2] & ~rwe->mask[2]) | rwe->value[2]; /* FALLTHROUGH */ case 2: d[1] = (d[1] & ~rwe->mask[1]) | rwe->value[1]; /* FALLTHROUGH */ case 1: d[0] = (d[0] & ~rwe->mask[0]) | rwe->value[0]; break; default: abort (); } } VLIB_NODE_FN (l2_rw_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { l2_rw_main_t *rw = &l2_rw_main; u32 n_left_from, *from, *to_next, next_index; vnet_classify_main_t *vcm = &vnet_classify_main; f64 now = vlib_time_now (vlib_get_main ()); from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ next_index = node->cached_next_index; while (n_left_from > 0) { u32 n_left_to_next; /* get space to enqueue frame to graph node "next_index" */ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); while (n_left_from >= 6 && n_left_to_next >= 2) { u32 bi0, next0, sw_if_index0, rwe_index0; u32 bi1, next1, sw_if_index1, rwe_index1; vlib_buffer_t *b0, *b1; ethernet_header_t *h0, *h1; l2_rw_config_t *config0, *config1; u64 hash0, hash1; vnet_classify_table_t *t0, *t1; vnet_classify_entry_t *e0, *e1; l2_rw_entry_t *rwe0, *rwe1; { vlib_buffer_t *p2, *p3, *p4, *p5; p2 = vlib_get_buffer (vm, from[2]); p3 = vlib_get_buffer (vm, from[3]); p4 = vlib_get_buffer (vm, from[4]); p5 = vlib_get_buffer (vm, from[5]); vlib_prefetch_buffer_header (p4, LOAD); vlib_prefetch_buffer_header (p5, LOAD); vlib_prefetch_buffer_data (p2, LOAD); vlib_prefetch_buffer_data (p3, 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; b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); h0 = vlib_buffer_get_current (b0); h1 = vlib_buffer_get_current (b1); sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; config0 = l2_rw_get_config (sw_if_index0); /*TODO: check sw_if_index0 value */ config1 = l2_rw_get_config (sw_if_index1); /*TODO: check sw_if_index0 value */ t0 = pool_elt_at_index (vcm->tables, config0->table_index); t1 = pool_elt_at_index (vcm->tables, config1->table_index); hash0 = vnet_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.

libsixrd_plugin_la_SOURCES =			\
	sixrd/sixrd.c				\
	sixrd/sixrd_dpo.c			\
	sixrd/ip4_sixrd.c			\
	sixrd/ip6_sixrd.c

noinst_HEADERS +=				\
	sixrd/sixrd.h                           \
	sixrd/sixrd_dpo.h

vppplugins_LTLIBRARIES += libsixrd_plugin.la

# vi:syntax=automake
= L2INPUT_FEAT_RW; l2input_set_bridge_features (bridge_domain, mask, disable ? 0 : mask); return 0; } static clib_error_t * l2_rw_set_cli_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u32 bridge_domain; u8 disable = 0; if (unformat_check_input (input) == UNFORMAT_END_OF_INPUT || !unformat (input, "%d", &bridge_domain)) { return clib_error_return (0, "You must specify a bridge domain"); } if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT && unformat (input, "disable")) { disable = 1; } if (l2_rw_enable_disable (bridge_domain, disable)) return clib_error_return (0, "Could not enable or disable rewrite"); return 0; } /*? * Layer 2-Rewrite node uses classify tables to match packets. Then, using * the provisioned mask and value, modfies the packet header. * * @cliexpar * @todo This is incomplete. This needs a detailed description and a * practical example. ?*/ /* *INDENT-OFF* */ VLIB_CLI_COMMAND (l2_rw_set_cli, static) = { .path = "set bridge-domain rewrite", .short_help = "set bridge-domain rewrite [disable]", .function = l2_rw_set_cli_fn, }; /* *INDENT-ON* */ static clib_error_t * l2_rw_init (vlib_main_t * vm) { l2_rw_main_t *rw = &l2_rw_main; rw->configs = 0; rw->entries = 0; clib_bitmap_alloc (rw->configs_bitmap, 1); feat_bitmap_init_next_nodes (vm, l2_rw_node.index, L2INPUT_N_FEAT, l2input_get_feat_names (), rw->feat_next_node_index); return 0; } VLIB_INIT_FUNCTION (l2_rw_init); enum { L2_RW_NEXT_DROP, L2_RW_N_NEXT, }; #define foreach_l2_rw_error \ _(UNKNOWN, "Unknown error") typedef enum { #define _(sym,str) L2_RW_ERROR_##sym, foreach_l2_rw_error #undef _ L2_RW_N_ERROR, } l2_rw_error_t; static char *l2_rw_error_strings[] = { #define _(sym,string) string, foreach_l2_rw_error #undef _ }; /* *INDENT-OFF* */ VLIB_REGISTER_NODE (l2_rw_node) = { .name = "l2-rw", .vector_size = sizeof (u32), .format_trace = format_l2_rw_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = ARRAY_LEN(l2_rw_error_strings), .error_strings = l2_rw_error_strings, .runtime_data_bytes = 0, .n_next_nodes = L2_RW_N_NEXT, .next_nodes = { [L2_RW_NEXT_DROP] = "error-drop"}, }; /* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */