FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
p2p_ethernet_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * p2p_ethernet_api.c - p2p ethernet api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 
24 #include <vnet/format_fns.h>
25 #include <vnet/ethernet/p2p_ethernet.api_enum.h>
26 #include <vnet/ethernet/p2p_ethernet.api_types.h>
27 
28 #define REPLY_MSG_ID_BASE p2p_main.msg_id_base
30 
31 void
33 {
36  int rv;
37 
38  u32 parent_if_index = htonl (mp->parent_if_index);
39  u32 sub_id = htonl (mp->subif_id);
40  u32 p2pe_if_index = ~0;
41  u8 remote_mac[6];
42 
43  if (!vnet_sw_if_index_is_api_valid (parent_if_index))
44  {
45  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
46  goto bad_sw_if_index;
47  }
48  if (!vnet_sw_if_index_is_api_valid (sub_id))
49  {
50  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
51  goto bad_sw_if_index;
52  }
53 
54  clib_memcpy (remote_mac, mp->remote_mac, 6);
55  rv =
56  p2p_ethernet_add_del (vm, parent_if_index, remote_mac, sub_id, 1,
57  &p2pe_if_index);
58 
60 
61  /* *INDENT-OFF* */
62  REPLY_MACRO2(VL_API_P2P_ETHERNET_ADD_REPLY,
63  ({
64  rmp->sw_if_index = htonl(p2pe_if_index);
65  }));
66 
67 
68  /* *INDENT-ON* */
69 }
70 
71 void
73 {
76  int rv;
77 
78  u32 parent_if_index = htonl (mp->parent_if_index);
79  u8 remote_mac[6];
80 
81  if (!vnet_sw_if_index_is_api_valid (parent_if_index))
82  {
83  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
84  goto bad_sw_if_index;
85  }
86 
87  clib_memcpy (remote_mac, mp->remote_mac, 6);
88  rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, ~0, 0, 0);
89 
91  REPLY_MACRO (VL_API_P2P_ETHERNET_DEL_REPLY);
92 }
93 
94 #include <vnet/ethernet/p2p_ethernet.api.c>
95 static clib_error_t *
97 {
98  /*
99  * Set up the (msg_name, crc, message-id) table
100  */
102 
103  return 0;
104 }
105 
107 
108 /*
109  * fd.io coding-style-patch-verification: ON
110  *
111  * Local Variables:
112  * eval: (c-set-style "gnu")
113  * End:
114  */
vl_api_p2p_ethernet_del_t
Delete a point-to-point (p2p) Ethernet sub-interface.
Definition: p2p_ethernet.api:56
api.h
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
vl_api_p2p_ethernet_add_t::parent_if_index
vl_api_interface_index_t parent_if_index
Definition: p2p_ethernet.api:37
vl_api_p2p_ethernet_del_t_handler
void vl_api_p2p_ethernet_del_t_handler(vl_api_p2p_ethernet_del_t *mp)
Definition: p2p_ethernet_api.c:72
vl_api_p2p_ethernet_del_t::parent_if_index
vl_api_interface_index_t parent_if_index
Definition: p2p_ethernet.api:60
vl_api_p2p_ethernet_add_reply_t
Definition: p2p_ethernet.api:42
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_api_p2p_ethernet_del_t::remote_mac
vl_api_mac_address_t remote_mac
Definition: p2p_ethernet.api:61
vl_api_p2p_ethernet_add_t::remote_mac
vl_api_mac_address_t remote_mac
Definition: p2p_ethernet.api:39
p2p_ethernet_add_del
int p2p_ethernet_add_del(vlib_main_t *vm, u32 parent_if_index, u8 *client_mac, u32 p2pe_subif_id, int is_add, u32 *p2pe_if_index)
Definition: p2p_ethernet.c:50
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
vl_api_p2p_ethernet_add_reply_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: p2p_ethernet.api:46
p2p_ethernet.h
vnet_sw_if_index_is_api_valid
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
Definition: api_helper_macros.h:276
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(p2p_ethernet_api_hookup)
p2p_ethernet_api_hookup
static clib_error_t * p2p_ethernet_api_hookup(vlib_main_t *vm)
Definition: p2p_ethernet_api.c:96
format_fns.h
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: p2p_ethernet_api.c:28
u32
unsigned int u32
Definition: types.h:88
api_helper_macros.h
vlib_main_t
Definition: main.h:102
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_p2p_ethernet_add_t_handler
void vl_api_p2p_ethernet_add_t_handler(vl_api_p2p_ethernet_add_t *mp)
Definition: p2p_ethernet_api.c:32
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
vl_api_p2p_ethernet_add_t
Create a point-to-point (p2p) Ethernet sub-interface.
Definition: p2p_ethernet.api:33
vl_api_p2p_ethernet_add_t::subif_id
u32 subif_id
Definition: p2p_ethernet.api:38
vl_api_p2p_ethernet_del_reply_t
Definition: p2p_ethernet.api:64