FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
vxlan_gpe_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  *------------------------------------------------------------------
17  * vxlan_gpe_api.c - iOAM VxLAN-GPE related APIs to create
18  * and maintain profiles
19  *------------------------------------------------------------------
20  */
21 
22 #include <vnet/vnet.h>
23 #include <vnet/plugin/plugin.h>
25 
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 
29 
30 /* define message IDs */
32 
33 /* define message structures */
34 #define vl_typedefs
36 #undef vl_typedefs
37 
38 /* define generated endian-swappers */
39 #define vl_endianfun
41 #undef vl_endianfun
42 
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #define vl_printfun
47 #undef vl_printfun
48 
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
52 #undef vl_api_version
53 
54 /*
55  * A handy macro to set up a message reply.
56  * Assumes that the following variables are available:
57  * mp - pointer to request message
58  * rmp - pointer to reply message type
59  * rv - return value
60  */
61 
62 #define VXLAN_GPE_REPLY_MACRO(t) \
63 do { \
64  svm_queue_t * q = \
65  vl_api_client_index_to_input_queue (mp->client_index); \
66  if (!q) \
67  return; \
68  \
69  rmp = vl_msg_api_alloc (sizeof (*rmp)); \
70  rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \
71  rmp->context = mp->context; \
72  rmp->retval = ntohl(rv); \
73  \
74  vl_msg_api_send_shmem (q, (u8 *)&rmp); \
75 } while(0);
76 
77 /* *INDENT-OFF* */
78 #define VXLAN_GPE_REPLY_MACRO2(t, body) \
79 do { \
80  svm_queue_t * q; \
81  rv = vl_msg_api_pd_handler (mp, rv); \
82  q = vl_api_client_index_to_input_queue (mp->client_index); \
83  if (!q) \
84  return; \
85  \
86  rmp = vl_msg_api_alloc (sizeof (*rmp)); \
87  rmp->_vl_msg_id = ntohs((t)); \
88  rmp->context = mp->context; \
89  rmp->retval = ntohl(rv); \
90  do {body;} while (0); \
91  vl_msg_api_send_shmem (q, (u8 *)&rmp); \
92 } while(0);
93 /* *INDENT-ON* */
94 
95 /* List of message types that this plugin understands */
96 
97 #define foreach_vxlan_gpe_plugin_api_msg \
98 _(VXLAN_GPE_IOAM_ENABLE, vxlan_gpe_ioam_enable) \
99 _(VXLAN_GPE_IOAM_DISABLE, vxlan_gpe_ioam_disable) \
100 _(VXLAN_GPE_IOAM_VNI_ENABLE, vxlan_gpe_ioam_vni_enable) \
101 _(VXLAN_GPE_IOAM_VNI_DISABLE, vxlan_gpe_ioam_vni_disable) \
102 _(VXLAN_GPE_IOAM_TRANSIT_ENABLE, vxlan_gpe_ioam_transit_enable) \
103 _(VXLAN_GPE_IOAM_TRANSIT_DISABLE, vxlan_gpe_ioam_transit_disable) \
104 
105 
108 {
109  int rv = 0;
110  vl_api_vxlan_gpe_ioam_enable_reply_t *rmp;
111  clib_error_t *error;
113 
114  /* Ignoring the profile id as currently a single profile
115  * is supported */
116  error =
118  if (error)
119  {
120  clib_error_report (error);
121  rv = clib_error_get_code (error);
122  }
123 
124  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_ENABLE_REPLY);
125 }
126 
129 {
130  int rv = 0;
131  vl_api_vxlan_gpe_ioam_disable_reply_t *rmp;
132  clib_error_t *error;
134 
135  /* Ignoring the profile id as currently a single profile
136  * is supported */
137  error = vxlan_gpe_ioam_disable (0, 0, 0);
138  if (error)
139  {
140  clib_error_report (error);
141  rv = clib_error_get_code (error);
142  }
143 
144  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_DISABLE_REPLY);
145 }
146 
149 {
150  int rv = 0;
151  vl_api_vxlan_gpe_ioam_vni_enable_reply_t *rmp;
152  clib_error_t *error;
154  vxlan4_gpe_tunnel_key_t key4;
155  uword *p = NULL;
157  vxlan_gpe_tunnel_t *t = 0;
159  u32 vni;
160 
161 
162  if (!mp->is_ipv6)
163  {
164  clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
165  clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
166  vni = clib_net_to_host_u32 (mp->vni);
167  key4.vni = clib_host_to_net_u32 (vni << 8);
168  key4.pad = 0;
169 
170  p = hash_get_mem (gm->vxlan4_gpe_tunnel_by_key, &key4);
171  }
172  else
173  {
174  return;
175  }
176 
177  if (!p)
178  return;
179 
180  t = pool_elt_at_index (gm->tunnels, p[0]);
181 
182  error = vxlan_gpe_ioam_set (t, hm->has_trace_option,
183  hm->has_pot_option,
184  hm->has_ppc_option, mp->is_ipv6);
185 
186 
187  if (error)
188  {
189  clib_error_report (error);
190  rv = clib_error_get_code (error);
191  }
192 
193  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_ENABLE_REPLY);
194 }
195 
196 
199 {
200  int rv = 0;
201  vl_api_vxlan_gpe_ioam_vni_enable_reply_t *rmp;
202  clib_error_t *error;
204  vxlan4_gpe_tunnel_key_t key4;
205  uword *p = NULL;
207  vxlan_gpe_tunnel_t *t = 0;
208  u32 vni;
209 
210 
211  if (!mp->is_ipv6)
212  {
213  clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
214  clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
215  vni = clib_net_to_host_u32 (mp->vni);
216  key4.vni = clib_host_to_net_u32 (vni << 8);
217  key4.pad = 0;
218 
219  p = hash_get_mem (gm->vxlan4_gpe_tunnel_by_key, &key4);
220  }
221  else
222  {
223  return;
224  }
225 
226  if (!p)
227  return;
228 
229  t = pool_elt_at_index (gm->tunnels, p[0]);
230 
231  error = vxlan_gpe_ioam_clear (t, 0, 0, 0, 0);
232 
233 
234  if (error)
235  {
236  clib_error_report (error);
237  rv = clib_error_get_code (error);
238  }
239 
240 
241  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_DISABLE_REPLY);
242 }
243 
246 {
247  int rv = 0;
248  vl_api_vxlan_gpe_ioam_transit_enable_reply_t *rmp;
250  ip46_address_t dst_addr;
251 
252  memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
253  if (!mp->is_ipv6)
254  {
255  clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
256  }
258  dst_addr,
259  ntohl (mp->outer_fib_index),
260  mp->is_ipv6 ? 0 : 1,
261  1 /* is_add */ );
262 
263  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY);
264 }
265 
268 {
269  int rv = 0;
270  vl_api_vxlan_gpe_ioam_transit_disable_reply_t *rmp;
272  ip46_address_t dst_addr;
273 
274  memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
275  if (!mp->is_ipv6)
276  {
277  clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
278  }
279 
281  dst_addr,
282  ntohl (mp->outer_fib_index),
283  mp->is_ipv6 ? 0 : 1);
284  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY);
285 }
286 
287 /* Set up the API message handling tables */
288 static clib_error_t *
290 {
292 #define _(N,n) \
293  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
294  #n, \
295  vl_api_##n##_t_handler, \
296  vl_noop_handler, \
297  vl_api_##n##_t_endian, \
298  vl_api_##n##_t_print, \
299  sizeof(vl_api_##n##_t), 1);
301 #undef _
302 
303  return 0;
304 }
305 
306 #define vl_msg_name_crc_list
308 #undef vl_msg_name_crc_list
309 
310 static void
312 {
313 #define _(id,n,crc) \
314  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
315  foreach_vl_msg_name_crc_ioam_vxlan_gpe;
316 #undef _
317 }
318 
319 static clib_error_t *
321 {
323  clib_error_t *error = 0;
324  u8 *name;
325  u32 encap_node_index = vxlan_gpe_encap_ioam_v4_node.index;
326  u32 decap_node_index = vxlan_gpe_decap_ioam_v4_node.index;
328  vlib_node_t *vxlan_gpe_decap_node = NULL;
329  uword next_node = 0;
330 
331  sm->vlib_main = vm;
332  sm->vnet_main = vnet_get_main ();
333  sm->unix_time_0 = (u32) time (0); /* Store starting time */
334  sm->vlib_time_0 = vlib_time_now (vm);
335 
336  name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
337 
338  /* Ask for a correctly-sized block of API message decode slots */
340  ((char *) name, VL_MSG_FIRST_AVAILABLE);
341 
342  error = vxlan_gpe_plugin_api_hookup (vm);
343 
344  /* Add our API messages to the global name_crc hash table */
346 
347  /* Hook the ioam-encap node to vxlan-gpe-encap */
348  vxlan_gpe_encap_node = vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-encap");
349  sm->encap_v4_next_node =
350  vlib_node_add_next (vm, vxlan_gpe_encap_node->index, encap_node_index);
351 
352  vxlan_gpe_decap_node =
353  vlib_get_node_by_name (vm, (u8 *) "vxlan4-gpe-input");
354  next_node =
355  vlib_node_add_next (vm, vxlan_gpe_decap_node->index, decap_node_index);
356  vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IOAM, next_node);
357 
359  sm->dst_by_ip4 = hash_create_mem (0, sizeof (fib_prefix_t), sizeof (uword));
360 
361  sm->dst_by_ip6 = hash_create_mem (0, sizeof (fib_prefix_t), sizeof (uword));
362 
364  vec_free (name);
365 
366  return error;
367 }
368 
370 
371 /*
372  * fd.io coding-style-patch-verification: ON
373  *
374  * Local Variables:
375  * eval: (c-set-style "gnu")
376  * End:
377  */
clib_error_t * vxlan_gpe_ioam_enable(int has_trace_option, int has_pot_option, int has_ppc_option)
static void vl_api_vxlan_gpe_ioam_transit_disable_t_handler(vl_api_vxlan_gpe_ioam_transit_disable_t *mp)
Disable iOAM for VXLAN-GPE transit.
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
vlib_main_t * vlib_main
State convenience vlib_main_t.
vlib_node_registration_t vxlan_gpe_decap_ioam_v4_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_decap_ioam_v4_node)
Definition: ioam_decap.c:197
iOAM for VxLAN-GPE disable
#define NULL
Definition: clib.h:55
u32 index
Definition: node.h:273
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:225
#define VXLAN_GPE_REPLY_MACRO(t)
Definition: vxlan_gpe_api.c:62
int vxlan_gpe_enable_disable_ioam_for_dest(vlib_main_t *vm, ip46_address_t dst_addr, u32 outer_fib_index, u8 is_ipv4, u8 is_add)
vxlan_gpe_ioam_sw_interface_t * sw_interfaces
static void setup_message_id_table(vxlan_gpe_ioam_main_t *sm, api_main_t *am)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
clib_error_t * vxlan_gpe_ioam_clear(vxlan_gpe_tunnel_t *t, int has_trace_option, int has_pot_option, int has_ppc_option, u8 ipv6_set)
void vxlan_gpe_ioam_interface_init(void)
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1110
unsigned char u8
Definition: types.h:56
iOAM Over VxLAN-GPE - Set iOAM transport for VxLAN-GPE
vlib_node_registration_t vxlan_gpe_encap_ioam_v4_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_encap_ioam_v4_node)
Definition: ioam_encap.c:168
clib_error_t * vxlan_gpe_ioam_disable(int has_trace_option, int has_pot_option, int has_ppc_option)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:309
int vxlan_gpe_ioam_disable_for_dest(vlib_main_t *vm, ip46_address_t dst_addr, u32 outer_fib_index, u8 ipv4_set)
static void vl_api_vxlan_gpe_ioam_vni_disable_t_handler(vl_api_vxlan_gpe_ioam_vni_disable_t *mp)
vxlan_gpe_ioam_main_t vxlan_gpe_ioam_main
Aggregrate type for a prefix.
Definition: fib_types.h:188
unsigned int u32
Definition: types.h:88
void vxlan_gpe_register_decap_protocol(u8 protocol_id, uword next_node_index)
Definition: decap.c:685
Disable iOAM for a VNI (VXLAN-GPE)
Enable iOAM for a VXLAN-GPE transit.
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:464
static void vl_api_vxlan_gpe_ioam_enable_t_handler(vl_api_vxlan_gpe_ioam_enable_t *mp)
Struct for VXLAN GPE tunnel.
Definition: vxlan_gpe.h:102
vxlan_gpe_main_t vxlan_gpe_main
Definition: vxlan_gpe.c:45
static void vl_api_vxlan_gpe_ioam_disable_t_handler(vl_api_vxlan_gpe_ioam_disable_t *mp)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
clib_error_t * vxlan_gpe_ioam_set(vxlan_gpe_tunnel_t *t, int has_trace_option, int has_pot_option, int has_ppc_option, u8 ipv6_set)
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define clib_memcpy(a, b, c)
Definition: string.h:75
#define foreach_vxlan_gpe_plugin_api_msg
Definition: vxlan_gpe_api.c:97
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
Struct for VXLAN GPE node state.
Definition: vxlan_gpe.h:196
#define clib_error_report(e)
Definition: error.h:113
vxlan_gpe_tunnel_t * tunnels
vector of encap tunnel instances
Definition: vxlan_gpe.h:199
Enable iOAM for a VNI (VXLAN-GPE)
uword * vxlan4_gpe_tunnel_by_key
lookup IPv4 VXLAN GPE tunnel by key
Definition: vxlan_gpe.h:202
u64 uword
Definition: types.h:112
#define clib_error_get_code(err)
Definition: error.h:77
static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler(vl_api_vxlan_gpe_ioam_vni_enable_t *mp)
#define hash_get_mem(h, key)
Definition: hash.h:269
static clib_error_t * vxlan_gpe_init(vlib_main_t *vm)
vlib_node_registration_t vxlan_gpe_encap_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_encap_node)
Definition: encap.c:392
static clib_error_t * vxlan_gpe_plugin_api_hookup(vlib_main_t *vm)
api_main_t api_main
Definition: api_shared.c:35
vnet_main_t * vnet_main
State convenience vnet_main_t.
static void vl_api_vxlan_gpe_ioam_transit_enable_t_handler(vl_api_vxlan_gpe_ioam_transit_enable_t *mp)
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:872
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128