FD.io VPP  v17.07.01-10-g3be13f0
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 {
50  vlib_main_t *vm = vlib_get_main ();
51  int rv;
52 
53  u32 parent_if_index = htonl (mp->parent_if_index);
54  u8 remote_mac[6];
55 
56  clib_memcpy (remote_mac, mp->remote_mac, 6);
57  rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, 1);
58 
59  REPLY_MACRO (VL_API_P2P_ETHERNET_ADD_REPLY);
60 }
61 
62 void
64 {
66  vlib_main_t *vm = vlib_get_main ();
67  int rv;
68 
69  u32 parent_if_index = htonl (mp->parent_if_index);
70  u8 remote_mac[6];
71 
72  clib_memcpy (remote_mac, mp->remote_mac, 6);
73  rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, 0);
74 
75  REPLY_MACRO (VL_API_P2P_ETHERNET_DEL_REPLY);
76 }
77 
78 /*
79  * p2p_ethernet_api_hookup
80  * Add vpe's API message handlers to the table.
81  * vlib has alread mapped shared memory and
82  * added the client registration handlers.
83  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
84  */
85 #define vl_msg_name_crc_list
86 #include <vnet/vnet_all_api_h.h>
87 #undef vl_msg_name_crc_list
88 
89 static void
91 {
92 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
93  foreach_vl_msg_name_crc_p2p_ethernet;
94 #undef _
95 }
96 
97 static clib_error_t *
99 {
100  api_main_t *am = &api_main;
101 
102 #define _(N,n) \
103  vl_msg_api_set_handlers(VL_API_##N, #n, \
104  vl_api_##n##_t_handler, \
105  vl_noop_handler, \
106  vl_api_##n##_t_endian, \
107  vl_api_##n##_t_print, \
108  sizeof(vl_api_##n##_t), 1);
110 #undef _
111 
112  /*
113  * Set up the (msg_name, crc, message-id) table
114  */
116 
117  return 0;
118 }
119 
121 
122 /*
123  * fd.io coding-style-patch-verification: ON
124  *
125  * Local Variables:
126  * eval: (c-set-style "gnu")
127  * End:
128  */
void vl_api_p2p_ethernet_del_t_handler(vl_api_p2p_ethernet_del_t *mp)
static void setup_message_id_table(api_main_t *am)
VLIB_API_INIT_FUNCTION(p2p_ethernet_api_hookup)
#define REPLY_MACRO(t)
int p2p_ethernet_add_del(vlib_main_t *vm, u32 parent_if_index, u8 *client_mac, int is_add)
Definition: p2p_ethernet.c:23
api_main_t api_main
Definition: api_shared.c:35
#define clib_memcpy(a, b, c)
Definition: string.h:69
unsigned int u32
Definition: types.h:88
#define foreach_vpe_api_msg
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
void vl_api_p2p_ethernet_add_t_handler(vl_api_p2p_ethernet_add_t *mp)
unsigned char u8
Definition: types.h:56
static clib_error_t * p2p_ethernet_api_hookup(vlib_main_t *vm)