/* * nsh_cli.c - nsh cli functions * * Copyright (c) 2019 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 /* 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 unformat_nsh_action (unformat_input_t * input, va_list * args) { u32 *result = va_arg (*args, u32 *); u32 tmp; if (unformat (input, "swap")) *result = NSH_ACTION_SWAP; else if (unformat (input, "push")) *result = NSH_ACTION_PUSH; else if (unformat (input, "pop")) *result = NSH_ACTION_POP; else if (unformat (input, "%d", &tmp)) *result = tmp; else return 0; return 1; } static u8 * format_nsh_action (u8 * s, va_list * args) { u32 nsh_action = va_arg (*args, u32); switch (nsh_action) { case NSH_ACTION_SWAP: return format (s, "swap"); case NSH_ACTION_PUSH: return format (s, "push"); case NSH_ACTION_POP: return format (s, "pop"); default: return format (s, "unknown %d", nsh_action); } return s; } u8 * format_nsh_map (u8 * s, va_list * args) { nsh_map_t *map = va_arg (*args, nsh_map_t *); s = format (s, "nsh entry nsp: %d nsi: %d ", (map->nsp_nsi >> NSH_NSP_SHIFT) & NSH_NSP_MASK, map->nsp_nsi & NSH_NSI_MASK); s = format (s, "maps to nsp: %d nsi: %d ", (map->mapped_nsp_nsi >> NSH_NSP_SHIFT) & NSH_NSP_MASK, map->mapped_nsp_nsi & NSH_NSI_MASK); s = format (s, " nsh_action %U\n", format_nsh_action, map->nsh_action); switch (map->next_node) { case NSH_NODE_NEXT_ENCAP_GRE4: { s = format (s, "encapped by GRE4 intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_ENCAP_GRE6: { s = format (s, "encapped by GRE6 intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_ENCAP_VXLANGPE: { s = format (s, "encapped by VXLAN GPE intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_ENCAP_VXLAN4: { s = format (s, "encapped by VXLAN4 intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_ENCAP_VXLAN6: { s = format (s, "encapped by VXLAN6 intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_DECAP_ETH_INPUT: { s = format (s, "encap-none"); break; } case NSH_NODE_NEXT_ENCAP_LISP_GPE: { s = format (s, "encapped by LISP GPE intf: %d", map->sw_if_index); break; } case NSH_NODE_NEXT_ENCAP_ETHERNET: { s = format (s, "encapped by Ethernet intf: %d", map->sw_if_index); break; } default: s = format (s, "only GRE and VXLANGPE support in this rev"); } return s; } static adj_index_t nsh_get_adj_by_sw_if_index (u32 sw_if_index) { adj_index_t ai = ~0; /* *INDENT-OFF* */ pool_foreach_index (ai, adj_pool) { if (sw_if_index == adj_get_sw_if_index(ai)) { return ai; } } /* *INDENT-ON* */ return ~0; } /** * CLI command for NSH map */ static clib_error_t * nsh_add_del_map_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1; u32 nsp, nsi, mapped_nsp, mapped_nsi, nsh_action; int nsp_set = 0, nsi_set = 0, mapped_nsp_set = 0, mapped_nsi_set = 0; int nsh_action_set = 0; u32 next_node = ~0; u32 adj_index = ~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; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "nsp %d", &nsp)) nsp_set = 1; else if (unformat (line_input, "nsi %d", &nsi)) nsi_set = 1; else if (unformat (line_input, "mapped-nsp %d", &mapped_nsp)) mapped_nsp_set = 1; else if (unformat (line_input, "mapped-nsi %d", &mapped_nsi)) mapped_nsi_set = 1; else if (unformat (line_input, "nsh_action %U", unformat_nsh_action, &nsh_action)) nsh_action_set = 1; else if (unformat (line_input, "encap-gre4-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_GRE4; else if (unformat (line_input, "encap-gre6-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_GRE6; else if (unformat (line_input, "encap-vxlan-gpe-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_VXLANGPE; else if (unformat (line_input, "encap-lisp-gpe-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_LISP_GPE; else if (unformat (line_input, "encap-vxlan4-intf %d", &sw_if_index)) 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-eth-intf %d", &sw_if_index)) { next_node = NSH_NODE_NEXT_ENCAP_ETHERNET; adj_index = nsh_get_adj_by_sw_if_index (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'", format_unformat_error, line_input); } unformat_free (line_input); if (nsp_set == 0 || nsi_set == 0) return clib_error_return (0, "nsp nsi pair required. Key: for NSH entry"); if (mapped_nsp_set == 0 || mapped_nsi_set == 0) return clib_error_return (0, "mapped-nsp mapped-nsi pair required. Key: for NSH entry"); if (nsh_action_set == 0) 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 ]"); clib_memset (a, 0, sizeof (*a)); /* set args structure */ a->is_add = is_add; a->ma
/*
 * 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.
 */
#ifndef included_vnet_p2p_ethernet_h
#define included_vnet_p2p_ethernet_h

#include <vnet/vnet.h>
#include <vnet/ethernet/ethernet.h>


typedef struct {
  /**
   * Hash mapping parent sw_if_index and client mac address to p2p_ethernet sub-interface
   */
  uword * p2p_ethernet_by_key;

  u32 *p2p_ethernet_by_sw_if_index;

  // Pool of p2p