FD.io VPP  v21.06-3-gbb25fbf28
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>
22 
23 #include <vnet/vnet_msg_enum.h>
25 
26 #define vl_typedefs /* define message structures */
27 #include <vnet/vnet_all_api_h.h>
28 #undef vl_typedefs
29 
30 #define vl_endianfun /* define message structures */
31 #include <vnet/vnet_all_api_h.h>
32 #undef vl_endianfun
33 
34 /* instantiate all the print functions we know about */
35 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
36 #define vl_printfun
37 #include <vnet/vnet_all_api_h.h>
38 #undef vl_printfun
39 
41 
42 #define foreach_vpe_api_msg \
43 _(P2P_ETHERNET_ADD, p2p_ethernet_add) \
44 _(P2P_ETHERNET_DEL, p2p_ethernet_del)
45 
46 void
48 {
51  int rv;
52 
53  u32 parent_if_index = htonl (mp->parent_if_index);
54  u32 sub_id = htonl (mp->subif_id);
55  u32 p2pe_if_index = ~0;
56  u8 remote_mac[6];
57 
58  if (!vnet_sw_if_index_is_api_valid (parent_if_index))
59  {
60  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
61  goto bad_sw_if_index;
62  }
63  if (!vnet_sw_if_index_is_api_valid (sub_id))
64  {
65  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
66  goto bad_sw_if_index;
67  }
68 
69  clib_memcpy (remote_mac, mp->remote_mac, 6);
70  rv =
71  p2p_ethernet_add_del (vm, parent_if_index, remote_mac, sub_id, 1,
72  &p2pe_if_index);
73 
75 
76  /* *INDENT-OFF* */
77  REPLY_MACRO2(VL_API_P2P_ETHERNET_ADD_REPLY,
78  ({
79  rmp->sw_if_index = htonl(p2pe_if_index);
80  }));
81 
82 
83  /* *INDENT-ON* */
84 }
85 
86 void
88 {
91  int rv;
92 
93  u32 parent_if_index = htonl (mp->parent_if_index);
94  u8 remote_mac[6];
95 
96  if (!vnet_sw_if_index_is_api_valid (parent_if_index))
97  {
98  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
99  goto bad_sw_if_index;
100  }
101 
102  clib_memcpy (remote_mac, mp->remote_mac, 6);
103  rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, ~0, 0, 0);
104 
106  REPLY_MACRO (VL_API_P2P_ETHERNET_DEL_REPLY);
107 }
108 
109 /*
110  * p2p_ethernet_api_hookup
111  * Add vpe's API message handlers to the table.
112  * vlib has already mapped shared memory and
113  * added the client registration handlers.
114  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
115  */
116 #define vl_msg_name_crc_list
117 #include <vnet/vnet_all_api_h.h>
118 #undef vl_msg_name_crc_list
119 
120 static void
122 {
123 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
124  foreach_vl_msg_name_crc_p2p_ethernet;
125 #undef _
126 }
127 
128 static clib_error_t *
130 {
132 
133 #define _(N,n) \
134  vl_msg_api_set_handlers(VL_API_##N, #n, \
135  vl_api_##n##_t_handler, \
136  vl_noop_handler, \
137  vl_api_##n##_t_endian, \
138  vl_api_##n##_t_print, \
139  sizeof(vl_api_##n##_t), 1);
141 #undef _
142 
143  /*
144  * Set up the (msg_name, crc, message-id) table
145  */
147 
148  return 0;
149 }
150 
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
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:87
vl_api_p2p_ethernet_del_t::parent_if_index
vl_api_interface_index_t parent_if_index
Definition: p2p_ethernet.api:60
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: p2p_ethernet_api.c:121
vl_api_p2p_ethernet_add_reply_t
Definition: p2p_ethernet.api:42
am
app_main_t * am
Definition: application.c:489
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
vnet_msg_enum.h
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
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
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
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:129
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:47
vnet_all_api_h.h
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
foreach_vpe_api_msg
#define foreach_vpe_api_msg
Definition: p2p_ethernet_api.c:42
vl_api_p2p_ethernet_del_reply_t
Definition: p2p_ethernet.api:64