blob: f2c730b4d257ca6a491332fc132caf648a4a3c3a [file] [log] [blame]
Pavel Kotucek6899a302017-06-08 08:46:10 +02001/*
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>
24#include <vnet/ethernet/p2p_ethernet.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
40#include <vlibapi/api_helper_macros.h>
41
42#define foreach_vpe_api_msg \
43_(P2P_ETHERNET_ADD, p2p_ethernet_add) \
44_(P2P_ETHERNET_DEL, p2p_ethernet_del)
45
46void
47vl_api_p2p_ethernet_add_t_handler (vl_api_p2p_ethernet_add_t * mp)
48{
49 vl_api_p2p_ethernet_add_reply_t *rmp;
50 vlib_main_t *vm = vlib_get_main ();
51 int rv;
52
53 u32 parent_if_index = htonl (mp->parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020054 u32 sub_id = htonl (mp->subif_id);
55 u32 p2pe_if_index;
Pavel Kotucek6899a302017-06-08 08:46:10 +020056 u8 remote_mac[6];
57
58 clib_memcpy (remote_mac, mp->remote_mac, 6);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020059 rv =
60 p2p_ethernet_add_del (vm, parent_if_index, remote_mac, sub_id, 1,
61 &p2pe_if_index);
Pavel Kotucek6899a302017-06-08 08:46:10 +020062
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020063 /* *INDENT-OFF* */
64 REPLY_MACRO2(VL_API_P2P_ETHERNET_ADD_REPLY,
65 ({
66 rmp->sw_if_index = htonl(p2pe_if_index);
67 }));
68 /* *INDENT-ON* */
Pavel Kotucek6899a302017-06-08 08:46:10 +020069}
70
71void
72vl_api_p2p_ethernet_del_t_handler (vl_api_p2p_ethernet_del_t * mp)
73{
74 vl_api_p2p_ethernet_del_reply_t *rmp;
75 vlib_main_t *vm = vlib_get_main ();
76 int rv;
77
78 u32 parent_if_index = htonl (mp->parent_if_index);
79 u8 remote_mac[6];
80
81 clib_memcpy (remote_mac, mp->remote_mac, 6);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020082 rv = p2p_ethernet_add_del (vm, parent_if_index, remote_mac, ~0, 0, 0);
Pavel Kotucek6899a302017-06-08 08:46:10 +020083
84 REPLY_MACRO (VL_API_P2P_ETHERNET_DEL_REPLY);
85}
86
87/*
88 * p2p_ethernet_api_hookup
89 * Add vpe's API message handlers to the table.
90 * vlib has alread mapped shared memory and
91 * added the client registration handlers.
92 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
93 */
94#define vl_msg_name_crc_list
95#include <vnet/vnet_all_api_h.h>
96#undef vl_msg_name_crc_list
97
98static void
99setup_message_id_table (api_main_t * am)
100{
101#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
102 foreach_vl_msg_name_crc_p2p_ethernet;
103#undef _
104}
105
106static clib_error_t *
107p2p_ethernet_api_hookup (vlib_main_t * vm)
108{
109 api_main_t *am = &api_main;
110
111#define _(N,n) \
112 vl_msg_api_set_handlers(VL_API_##N, #n, \
113 vl_api_##n##_t_handler, \
114 vl_noop_handler, \
115 vl_api_##n##_t_endian, \
116 vl_api_##n##_t_print, \
117 sizeof(vl_api_##n##_t), 1);
118 foreach_vpe_api_msg;
119#undef _
120
121 /*
122 * Set up the (msg_name, crc, message-id) table
123 */
124 setup_message_id_table (am);
125
126 return 0;
127}
128
129VLIB_API_INIT_FUNCTION (p2p_ethernet_api_hookup);
130
131/*
132 * fd.io coding-style-patch-verification: ON
133 *
134 * Local Variables:
135 * eval: (c-set-style "gnu")
136 * End:
137 */