Improve tunnel interface creation performance
[vpp.git] / src / vnet / vxlan-gpe / vxlan_gpe.c
1 /*
2  * Copyright (c) 2015 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  *  @file
17  *  @brief Common utility functions for IPv4 and IPv6 VXLAN GPE tunnels
18  *
19 */
20 #include <vnet/vxlan-gpe/vxlan_gpe.h>
21 #include <vnet/fib/fib.h>
22 #include <vnet/ip/format.h>
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vnet/mfib/mfib_table.h>
26 #include <vnet/adj/adj_mcast.h>
27 #include <vnet/interface.h>
28 #include <vlib/vlib.h>
29
30 /**
31  * @file
32  * @brief VXLAN-GPE.
33  *
34  * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
35  * to span multiple servers. This is done by building an L2 overlay on
36  * top of an L3 network underlay using VXLAN-GPE tunnels.
37  *
38  * This makes it possible for servers to be co-located in the same data
39  * center or be separated geographically as long as they are reachable
40  * through the underlay L3 network.
41  *
42  * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
43  */
44
45 vxlan_gpe_main_t vxlan_gpe_main;
46
47 static u8 *
48 format_decap_next (u8 * s, va_list * args)
49 {
50   vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
51
52   switch (t->protocol)
53     {
54     case VXLAN_GPE_PROTOCOL_IP4:
55       s = format (s, "protocol ip4 fib-idx %d", t->decap_fib_index);
56       break;
57     case VXLAN_GPE_PROTOCOL_IP6:
58       s = format (s, "protocol ip6 fib-idx %d", t->decap_fib_index);
59       break;
60     case VXLAN_GPE_PROTOCOL_ETHERNET:
61       s = format (s, "protocol ethernet");
62       break;
63     case VXLAN_GPE_PROTOCOL_NSH:
64       s = format (s, "protocol nsh");
65       break;
66     default:
67       s = format (s, "protocol unknown %d", t->protocol);
68     }
69
70   return s;
71 }
72
73 /**
74  * @brief Format function for VXLAN GPE tunnel
75  *
76  * @param *s formatting string
77  * @param *args
78  *
79  * @return *s formatted string
80  *
81  */
82 u8 *
83 format_vxlan_gpe_tunnel (u8 * s, va_list * args)
84 {
85   vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
86   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
87
88   s = format (s, "[%d] lcl %U rmt %U vni %d fib-idx %d sw-if-idx %d ",
89               t - ngm->tunnels,
90               format_ip46_address, &t->local, IP46_TYPE_ANY,
91               format_ip46_address, &t->remote, IP46_TYPE_ANY,
92               t->vni, t->encap_fib_index, t->sw_if_index);
93
94 #if 0
95   /* next_dpo not yet used by vxlan-gpe-encap node */
96   s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
97   */
98 #endif
99     s = format (s, "decap-next-%U ", format_decap_next, t);
100
101   if (PREDICT_FALSE (ip46_address_is_multicast (&t->remote)))
102     s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
103
104   return s;
105 }
106
107 /**
108  * @brief Naming for VXLAN GPE tunnel
109  *
110  * @param *s formatting string
111  * @param *args
112  *
113  * @return *s formatted string
114  *
115  */
116 static u8 *
117 format_vxlan_gpe_name (u8 * s, va_list * args)
118 {
119   u32 dev_instance = va_arg (*args, u32);
120   return format (s, "vxlan_gpe_tunnel%d", dev_instance);
121 }
122
123 /**
124  * @brief CLI function for VXLAN GPE admin up/down
125  *
126  * @param *vnm
127  * @param hw_if_index
128  * @param flag
129  *
130  * @return *rc
131  *
132  */
133 static clib_error_t *
134 vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
135                                    u32 flags)
136 {
137   u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
138     VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
139   vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
140
141   return 0;
142 }
143
144 /* *INDENT-OFF* */
145 VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
146   .name = "VXLAN_GPE",
147   .format_device_name = format_vxlan_gpe_name,
148   .format_tx_trace = format_vxlan_gpe_encap_trace,
149   .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
150 };
151 /* *INDENT-ON* */
152
153
154 /**
155  * @brief Formatting function for tracing VXLAN GPE with length
156  *
157  * @param *s
158  * @param *args
159  *
160  * @return *s
161  *
162  */
163 static u8 *
164 format_vxlan_gpe_header_with_length (u8 * s, va_list * args)
165 {
166   u32 dev_instance = va_arg (*args, u32);
167   s = format (s, "unimplemented dev %u", dev_instance);
168   return s;
169 }
170
171 /* *INDENT-OFF* */
172 VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
173   .name = "VXLAN_GPE",
174   .format_header = format_vxlan_gpe_header_with_length,
175   .build_rewrite = default_build_rewrite,
176 };
177 /* *INDENT-ON* */
178
179 static void
180 vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_t * t)
181 {
182   dpo_id_t dpo = DPO_INVALID;
183   u32 encap_index = vxlan_gpe_encap_node.index;
184   fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->remote) ?
185     FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
186
187   fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
188   dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
189   dpo_reset (&dpo);
190 }
191
192 static vxlan_gpe_tunnel_t *
193 vxlan_gpe_tunnel_from_fib_node (fib_node_t * node)
194 {
195   ASSERT (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
196   return ((vxlan_gpe_tunnel_t *) (((char *) node) -
197                                   STRUCT_OFFSET_OF (vxlan_gpe_tunnel_t,
198                                                     node)));
199 }
200
201 /**
202  * Function definition to backwalk a FIB node -
203  * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
204  */
205 static fib_node_back_walk_rc_t
206 vxlan_gpe_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
207 {
208   vxlan_gpe_tunnel_restack_dpo (vxlan_gpe_tunnel_from_fib_node (node));
209   return (FIB_NODE_BACK_WALK_CONTINUE);
210 }
211
212 /**
213  * Function definition to get a FIB node from its index
214  */
215 static fib_node_t *
216 vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
217 {
218   vxlan_gpe_tunnel_t *t;
219   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
220
221   t = pool_elt_at_index (ngm->tunnels, index);
222
223   return (&t->node);
224 }
225
226 /**
227  * Function definition to inform the FIB node that its last lock has gone.
228  */
229 static void
230 vxlan_gpe_tunnel_last_lock_gone (fib_node_t * node)
231 {
232   /*
233    * The VXLAN_GPE tunnel is a root of the graph. As such
234    * it never has children and thus is never locked.
235    */
236   ASSERT (0);
237 }
238
239 /*
240  * Virtual function table registered by VXLAN_GPE tunnels
241  * for participation in the FIB object graph.
242  */
243 const static fib_node_vft_t vxlan_gpe_vft = {
244   .fnv_get = vxlan_gpe_tunnel_fib_node_get,
245   .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
246   .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
247 };
248
249 #define foreach_gpe_copy_field                  \
250 _(vni)                                          \
251 _(protocol)                                     \
252 _(mcast_sw_if_index)                            \
253 _(encap_fib_index)                              \
254 _(decap_fib_index)
255
256 #define foreach_copy_ipv4 {                     \
257   _(local.ip4.as_u32)                           \
258   _(remote.ip4.as_u32)                          \
259 }
260
261 #define foreach_copy_ipv6 {                     \
262   _(local.ip6.as_u64[0])                        \
263   _(local.ip6.as_u64[1])                        \
264   _(remote.ip6.as_u64[0])                       \
265   _(remote.ip6.as_u64[1])                       \
266 }
267
268
269 /**
270  * @brief Calculate IPv4 VXLAN GPE rewrite header
271  *
272  * @param *t
273  *
274  * @return rc
275  *
276  */
277 int
278 vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
279                     u8 protocol_override, uword encap_next_node)
280 {
281   u8 *rw = 0;
282   ip4_header_t *ip0;
283   ip4_vxlan_gpe_header_t *h0;
284   int len;
285
286   len = sizeof (*h0) + extension_size;
287
288   vec_free (t->rewrite);
289   vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
290
291   h0 = (ip4_vxlan_gpe_header_t *) rw;
292
293   /* Fixed portion of the (outer) ip4 header */
294   ip0 = &h0->ip4;
295   ip0->ip_version_and_header_length = 0x45;
296   ip0->ttl = 254;
297   ip0->protocol = IP_PROTOCOL_UDP;
298
299   /* we fix up the ip4 header length and checksum after-the-fact */
300   ip0->src_address.as_u32 = t->local.ip4.as_u32;
301   ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
302   ip0->checksum = ip4_header_checksum (ip0);
303
304   /* UDP header, randomize src port on something, maybe? */
305   h0->udp.src_port = clib_host_to_net_u16 (4790);
306   h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
307
308   /* VXLAN header. Are we having fun yet? */
309   h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
310   h0->vxlan.ver_res = VXLAN_GPE_VERSION;
311   if (protocol_override)
312     {
313       h0->vxlan.protocol = protocol_override;
314     }
315   else
316     {
317       h0->vxlan.protocol = t->protocol;
318     }
319   t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
320   h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
321
322   t->rewrite = rw;
323   t->encap_next_node = encap_next_node;
324   return (0);
325 }
326
327 /**
328  * @brief Calculate IPv6 VXLAN GPE rewrite header
329  *
330  * @param *t
331  *
332  * @return rc
333  *
334  */
335 int
336 vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size,
337                     u8 protocol_override, uword encap_next_node)
338 {
339   u8 *rw = 0;
340   ip6_header_t *ip0;
341   ip6_vxlan_gpe_header_t *h0;
342   int len;
343
344   len = sizeof (*h0) + extension_size;
345
346   vec_free (t->rewrite);
347   vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
348
349   h0 = (ip6_vxlan_gpe_header_t *) rw;
350
351   /* Fixed portion of the (outer) ip4 header */
352   ip0 = &h0->ip6;
353   ip0->ip_version_traffic_class_and_flow_label =
354     clib_host_to_net_u32 (6 << 28);
355   ip0->hop_limit = 255;
356   ip0->protocol = IP_PROTOCOL_UDP;
357
358   ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0];
359   ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1];
360   ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0];
361   ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1];
362
363   /* UDP header, randomize src port on something, maybe? */
364   h0->udp.src_port = clib_host_to_net_u16 (4790);
365   h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
366
367   /* VXLAN header. Are we having fun yet? */
368   h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
369   h0->vxlan.ver_res = VXLAN_GPE_VERSION;
370   if (protocol_override)
371     {
372       h0->vxlan.protocol = t->protocol;
373     }
374   else
375     {
376       h0->vxlan.protocol = protocol_override;
377     }
378   t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
379   h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
380
381   t->rewrite = rw;
382   t->encap_next_node = encap_next_node;
383   return (0);
384 }
385
386 static uword
387 vtep_addr_ref (ip46_address_t * ip)
388 {
389   uword *vtep = ip46_address_is_ip4 (ip) ?
390     hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
391     hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
392   if (vtep)
393     return ++(*vtep);
394   ip46_address_is_ip4 (ip) ?
395     hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
396     hash_set_mem_alloc (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
397   return 1;
398 }
399
400 static uword
401 vtep_addr_unref (ip46_address_t * ip)
402 {
403   uword *vtep = ip46_address_is_ip4 (ip) ?
404     hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
405     hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
406   ASSERT (vtep);
407   if (--(*vtep) != 0)
408     return *vtep;
409   ip46_address_is_ip4 (ip) ?
410     hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
411     hash_unset_mem_free (&vxlan_gpe_main.vtep6, &ip->ip6);
412   return 0;
413 }
414
415 /* *INDENT-OFF* */
416 typedef CLIB_PACKED(union {
417   struct {
418     fib_node_index_t mfib_entry_index;
419     adj_index_t mcast_adj_index;
420   };
421   u64 as_u64;
422 }) mcast_shared_t;
423 /* *INDENT-ON* */
424
425 static inline mcast_shared_t
426 mcast_shared_get (ip46_address_t * ip)
427 {
428   ASSERT (ip46_address_is_multicast (ip));
429   uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
430   ASSERT (p);
431   return (mcast_shared_t)
432   {
433   .as_u64 = *p};
434 }
435
436 static inline void
437 mcast_shared_add (ip46_address_t * remote,
438                   fib_node_index_t mfei, adj_index_t ai)
439 {
440   mcast_shared_t new_ep = {
441     .mcast_adj_index = ai,
442     .mfib_entry_index = mfei,
443   };
444
445   hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
446 }
447
448 static inline void
449 mcast_shared_remove (ip46_address_t * remote)
450 {
451   mcast_shared_t ep = mcast_shared_get (remote);
452
453   adj_unlock (ep.mcast_adj_index);
454   mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
455
456   hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
457 }
458
459 static inline fib_protocol_t
460 fib_ip_proto (bool is_ip6)
461 {
462   return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
463 }
464
465 /**
466  * @brief Add or Del a VXLAN GPE tunnel
467  *
468  * @param *a
469  * @param *sw_if_index
470  *
471  * @return rc
472  *
473  */
474 int vnet_vxlan_gpe_add_del_tunnel
475   (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
476 {
477   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
478   vxlan_gpe_tunnel_t *t = 0;
479   vnet_main_t *vnm = ngm->vnet_main;
480   vnet_hw_interface_t *hi;
481   uword *p;
482   u32 hw_if_index = ~0;
483   u32 sw_if_index = ~0;
484   int rv;
485   vxlan4_gpe_tunnel_key_t key4, *key4_copy;
486   vxlan6_gpe_tunnel_key_t key6, *key6_copy;
487   u32 is_ip6 = a->is_ip6;
488
489   if (!is_ip6)
490     {
491       key4.local = a->local.ip4.as_u32;
492       key4.remote = a->remote.ip4.as_u32;
493       key4.vni = clib_host_to_net_u32 (a->vni << 8);
494       key4.pad = 0;
495
496       p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
497     }
498   else
499     {
500       key6.local.as_u64[0] = a->local.ip6.as_u64[0];
501       key6.local.as_u64[1] = a->local.ip6.as_u64[1];
502       key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
503       key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
504       key6.vni = clib_host_to_net_u32 (a->vni << 8);
505
506       p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
507     }
508
509   if (a->is_add)
510     {
511       l2input_main_t *l2im = &l2input_main;
512
513       /* adding a tunnel: tunnel must not already exist */
514       if (p)
515         return VNET_API_ERROR_TUNNEL_EXIST;
516
517       pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
518       memset (t, 0, sizeof (*t));
519
520       /* copy from arg structure */
521 /* *INDENT-OFF* */
522 #define _(x) t->x = a->x;
523       foreach_gpe_copy_field;
524       if (!a->is_ip6)
525         foreach_copy_ipv4
526       else
527         foreach_copy_ipv6
528 #undef _
529 /* *INDENT-ON* */
530
531       if (!a->is_ip6)
532         t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
533
534       if (!a->is_ip6)
535         {
536           rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
537         }
538       else
539         {
540           rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
541         }
542
543       if (rv)
544         {
545           pool_put (ngm->tunnels, t);
546           return rv;
547         }
548
549       if (!is_ip6)
550         {
551           key4_copy = clib_mem_alloc (sizeof (*key4_copy));
552           clib_memcpy (key4_copy, &key4, sizeof (*key4_copy));
553           hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
554                         t - ngm->tunnels);
555         }
556       else
557         {
558           key6_copy = clib_mem_alloc (sizeof (*key6_copy));
559           clib_memcpy (key6_copy, &key6, sizeof (*key6_copy));
560           hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
561                         t - ngm->tunnels);
562         }
563
564       if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
565         {
566           vnet_interface_main_t *im = &vnm->interface_main;
567           hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
568             [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
569           _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
570
571           hi = vnet_get_hw_interface (vnm, hw_if_index);
572           hi->dev_instance = t - ngm->tunnels;
573           hi->hw_instance = hi->dev_instance;
574           /* clear old stats of freed tunnel before reuse */
575           sw_if_index = hi->sw_if_index;
576           vnet_interface_counter_lock (im);
577           vlib_zero_combined_counter
578             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
579              sw_if_index);
580           vlib_zero_combined_counter (&im->combined_sw_if_counters
581                                       [VNET_INTERFACE_COUNTER_RX],
582                                       sw_if_index);
583           vlib_zero_simple_counter (&im->sw_if_counters
584                                     [VNET_INTERFACE_COUNTER_DROP],
585                                     sw_if_index);
586           vnet_interface_counter_unlock (im);
587         }
588       else
589         {
590           hw_if_index = vnet_register_interface
591             (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
592              vxlan_gpe_hw_class.index, t - ngm->tunnels);
593           hi = vnet_get_hw_interface (vnm, hw_if_index);
594         }
595
596       /* Set vxlan-gpe tunnel output node */
597       u32 encap_index = vxlan_gpe_encap_node.index;
598       vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
599
600       t->hw_if_index = hw_if_index;
601       t->sw_if_index = sw_if_index = hi->sw_if_index;
602       vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
603                                ~0);
604       ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
605
606       /* setup l2 input config with l2 feature and bd 0 to drop packet */
607       vec_validate (l2im->configs, sw_if_index);
608       l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
609       l2im->configs[sw_if_index].bd_index = 0;
610
611       vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
612       si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
613       vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
614                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
615       fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
616       fib_prefix_t tun_remote_pfx;
617       vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
618
619       fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
620       if (!ip46_address_is_multicast (&t->remote))
621         {
622           /* Unicast tunnel -
623            * source the FIB entry for the tunnel's destination
624            * and become a child thereof. The tunnel will then get poked
625            * when the forwarding for the entry updates, and the tunnel can
626            * re-stack accordingly
627            */
628           vtep_addr_ref (&t->local);
629           t->fib_entry_index = fib_table_entry_special_add
630             (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
631              FIB_ENTRY_FLAG_NONE);
632           t->sibling_index = fib_entry_child_add
633             (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
634              t - ngm->tunnels);
635           vxlan_gpe_tunnel_restack_dpo (t);
636         }
637       else
638         {
639           /* Multicast tunnel -
640            * as the same mcast group can be used for mutiple mcast tunnels
641            * with different VNIs, create the output fib adjecency only if
642            * it does not already exist
643            */
644           fib_protocol_t fp = fib_ip_proto (is_ip6);
645
646           if (vtep_addr_ref (&t->remote) == 1)
647             {
648               fib_node_index_t mfei;
649               adj_index_t ai;
650               fib_route_path_t path = {
651                 .frp_proto = fib_proto_to_dpo (fp),
652                 .frp_addr = zero_addr,
653                 .frp_sw_if_index = 0xffffffff,
654                 .frp_fib_index = ~0,
655                 .frp_weight = 0,
656                 .frp_flags = FIB_ROUTE_PATH_LOCAL,
657               };
658               const mfib_prefix_t mpfx = {
659                 .fp_proto = fp,
660                 .fp_len = (is_ip6 ? 128 : 32),
661                 .fp_grp_addr = tun_remote_pfx.fp_addr,
662               };
663
664               /*
665                * Setup the (*,G) to receive traffic on the mcast group
666                *  - the forwarding interface is for-us
667                *  - the accepting interface is that from the API
668                */
669               mfib_table_entry_path_update (t->encap_fib_index,
670                                             &mpfx,
671                                             MFIB_SOURCE_VXLAN_GPE,
672                                             &path, MFIB_ITF_FLAG_FORWARD);
673
674               path.frp_sw_if_index = a->mcast_sw_if_index;
675               path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
676               mfei = mfib_table_entry_path_update (t->encap_fib_index,
677                                                    &mpfx,
678                                                    MFIB_SOURCE_VXLAN_GPE,
679                                                    &path,
680                                                    MFIB_ITF_FLAG_ACCEPT);
681
682               /*
683                * Create the mcast adjacency to send traffic to the group
684                */
685               ai = adj_mcast_add_or_lock (fp,
686                                           fib_proto_to_link (fp),
687                                           a->mcast_sw_if_index);
688
689               /*
690                * create a new end-point
691                */
692               mcast_shared_add (&t->remote, mfei, ai);
693             }
694
695           dpo_id_t dpo = DPO_INVALID;
696           mcast_shared_t ep = mcast_shared_get (&t->remote);
697
698           /* Stack shared mcast remote mac addr rewrite on encap */
699           dpo_set (&dpo, DPO_ADJACENCY_MCAST,
700                    fib_proto_to_dpo (fp), ep.mcast_adj_index);
701
702           dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
703           dpo_reset (&dpo);
704           flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
705         }
706
707       vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
708         flood_class;
709     }
710   else
711     {
712       /* deleting a tunnel: tunnel must exist */
713       if (!p)
714         return VNET_API_ERROR_NO_SUCH_ENTRY;
715
716       t = pool_elt_at_index (ngm->tunnels, p[0]);
717
718       sw_if_index = t->sw_if_index;
719       vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
720       vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
721       si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
722       set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
723                        0);
724       vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
725
726       ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
727
728       if (!is_ip6)
729         hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
730       else
731         hash_unset_mem_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
732
733       if (!ip46_address_is_multicast (&t->remote))
734         {
735           vtep_addr_unref (&t->local);
736           fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
737           fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
738         }
739       else if (vtep_addr_unref (&t->remote) == 0)
740         {
741           mcast_shared_remove (&t->remote);
742         }
743
744       fib_node_deinit (&t->node);
745       vec_free (t->rewrite);
746       pool_put (ngm->tunnels, t);
747     }
748
749   if (sw_if_indexp)
750     *sw_if_indexp = sw_if_index;
751
752   return 0;
753 }
754
755 static clib_error_t *
756 vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
757                                      unformat_input_t * input,
758                                      vlib_cli_command_t * cmd)
759 {
760   unformat_input_t _line_input, *line_input = &_line_input;
761   u8 is_add = 1;
762   ip46_address_t local, remote;
763   u8 local_set = 0;
764   u8 remote_set = 0;
765   u8 grp_set = 0;
766   u8 ipv4_set = 0;
767   u8 ipv6_set = 0;
768   u32 mcast_sw_if_index = ~0;
769   u32 encap_fib_index = 0;
770   u32 decap_fib_index = 0;
771   u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
772   u32 vni;
773   u8 vni_set = 0;
774   int rv;
775   u32 tmp;
776   vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
777   u32 sw_if_index;
778   clib_error_t *error = NULL;
779
780   /* Get a line of input. */
781   if (!unformat_user (input, unformat_line_input, line_input))
782     return 0;
783
784   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
785     {
786       if (unformat (line_input, "del"))
787         is_add = 0;
788       else if (unformat (line_input, "local %U",
789                          unformat_ip4_address, &local.ip4))
790         {
791           local_set = 1;
792           ipv4_set = 1;
793         }
794       else if (unformat (line_input, "remote %U",
795                          unformat_ip4_address, &remote.ip4))
796         {
797           remote_set = 1;
798           ipv4_set = 1;
799         }
800       else if (unformat (line_input, "local %U",
801                          unformat_ip6_address, &local.ip6))
802         {
803           local_set = 1;
804           ipv6_set = 1;
805         }
806       else if (unformat (line_input, "remote %U",
807                          unformat_ip6_address, &remote.ip6))
808         {
809           remote_set = 1;
810           ipv6_set = 1;
811         }
812       else if (unformat (line_input, "group %U %U",
813                          unformat_ip4_address, &remote.ip4,
814                          unformat_vnet_sw_interface,
815                          vnet_get_main (), &mcast_sw_if_index))
816         {
817           grp_set = remote_set = 1;
818           ipv4_set = 1;
819         }
820       else if (unformat (line_input, "group %U %U",
821                          unformat_ip6_address, &remote.ip6,
822                          unformat_vnet_sw_interface,
823                          vnet_get_main (), &mcast_sw_if_index))
824         {
825           grp_set = remote_set = 1;
826           ipv6_set = 1;
827         }
828       else if (unformat (line_input, "encap-vrf-id %d", &tmp))
829         {
830           if (ipv6_set)
831             encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
832           else
833             encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
834
835           if (encap_fib_index == ~0)
836             {
837               error =
838                 clib_error_return (0, "nonexistent encap fib id %d", tmp);
839               goto done;
840             }
841         }
842       else if (unformat (line_input, "decap-vrf-id %d", &tmp))
843         {
844           if (ipv6_set)
845             decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
846           else
847             decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
848
849           if (decap_fib_index == ~0)
850             {
851               error =
852                 clib_error_return (0, "nonexistent decap fib id %d", tmp);
853               goto done;
854             }
855         }
856       else if (unformat (line_input, "vni %d", &vni))
857         vni_set = 1;
858       else if (unformat (line_input, "next-ip4"))
859         protocol = VXLAN_GPE_PROTOCOL_IP4;
860       else if (unformat (line_input, "next-ip6"))
861         protocol = VXLAN_GPE_PROTOCOL_IP6;
862       else if (unformat (line_input, "next-ethernet"))
863         protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
864       else if (unformat (line_input, "next-nsh"))
865         protocol = VXLAN_GPE_PROTOCOL_NSH;
866       else
867         {
868           error = clib_error_return (0, "parse error: '%U'",
869                                      format_unformat_error, line_input);
870           goto done;
871         }
872     }
873
874   if (local_set == 0)
875     {
876       error = clib_error_return (0, "tunnel local address not specified");
877       goto done;
878     }
879
880   if (remote_set == 0)
881     {
882       error = clib_error_return (0, "tunnel remote address not specified");
883       goto done;
884     }
885
886   if (grp_set && !ip46_address_is_multicast (&remote))
887     {
888       error = clib_error_return (0, "tunnel group address not multicast");
889       goto done;
890     }
891
892   if (grp_set == 0 && ip46_address_is_multicast (&remote))
893     {
894       error = clib_error_return (0, "remote address must be unicast");
895       goto done;
896     }
897
898   if (grp_set && mcast_sw_if_index == ~0)
899     {
900       error = clib_error_return (0, "tunnel nonexistent multicast device");
901       goto done;
902     }
903   if (ipv4_set && ipv6_set)
904     {
905       error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
906       goto done;
907     }
908
909   if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
910       || (ipv6_set
911           && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
912     {
913       error = clib_error_return (0, "src and remote addresses are identical");
914       goto done;
915     }
916
917   if (vni_set == 0)
918     {
919       error = clib_error_return (0, "vni not specified");
920       goto done;
921     }
922
923   memset (a, 0, sizeof (*a));
924
925   a->is_add = is_add;
926   a->is_ip6 = ipv6_set;
927
928 /* *INDENT-OFF* */
929 #define _(x) a->x = x;
930   foreach_gpe_copy_field;
931   if (ipv4_set)
932     foreach_copy_ipv4
933   else
934     foreach_copy_ipv6
935 #undef _
936 /* *INDENT-ON* */
937
938   rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
939
940   switch (rv)
941     {
942     case 0:
943       vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
944                        vnet_get_main (), sw_if_index);
945       break;
946     case VNET_API_ERROR_INVALID_DECAP_NEXT:
947       error = clib_error_return (0, "invalid decap-next...");
948       goto done;
949
950     case VNET_API_ERROR_TUNNEL_EXIST:
951       error = clib_error_return (0, "tunnel already exists...");
952       goto done;
953
954     case VNET_API_ERROR_NO_SUCH_ENTRY:
955       error = clib_error_return (0, "tunnel does not exist...");
956       goto done;
957
958     default:
959       error = clib_error_return
960         (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
961       goto done;
962     }
963
964 done:
965   unformat_free (line_input);
966
967   return error;
968 }
969
970 /*?
971  * Add or delete a VXLAN-GPE Tunnel.
972  *
973  * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
974  * to span multiple servers. This is done by building an L2 overlay on
975  * top of an L3 network underlay using VXLAN-GPE tunnels.
976  *
977  * This makes it possible for servers to be co-located in the same data
978  * center or be separated geographically as long as they are reachable
979  * through the underlay L3 network.
980  *
981  * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment.
982  *
983  * @cliexpar
984  * Example of how to create a VXLAN-GPE Tunnel:
985  * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 local 10.0.3.3 vni 13 encap-vrf-id 7}
986  * Example of how to delete a VXLAN Tunnel:
987  * @cliexcmd{create vxlan tunnel src 10.0.3.1 remote 10.0.3.3 vni 13 del}
988  ?*/
989 /* *INDENT-OFF* */
990 VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
991   .path = "create vxlan-gpe tunnel",
992   .short_help =
993   "create vxlan-gpe tunnel local <local-addr> "
994   " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
995   " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
996   " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
997   .function = vxlan_gpe_add_del_tunnel_command_fn,
998 };
999 /* *INDENT-ON* */
1000
1001 /**
1002  * @brief CLI function for showing VXLAN GPE tunnels
1003  *
1004  * @param *vm
1005  * @param *input
1006  * @param *cmd
1007  *
1008  * @return error
1009  *
1010  */
1011 static clib_error_t *
1012 show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
1013                                   unformat_input_t * input,
1014                                   vlib_cli_command_t * cmd)
1015 {
1016   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1017   vxlan_gpe_tunnel_t *t;
1018
1019   if (pool_elts (ngm->tunnels) == 0)
1020     vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1021
1022   /* *INDENT-OFF* */
1023   pool_foreach (t, ngm->tunnels,
1024   ({
1025     vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1026   }));
1027   /* *INDENT-ON* */
1028
1029   return 0;
1030 }
1031
1032 /*?
1033  * Display all the VXLAN-GPE Tunnel entries.
1034  *
1035  * @cliexpar
1036  * Example of how to display the VXLAN-GPE Tunnel entries:
1037  * @cliexstart{show vxlan-gpe tunnel}
1038  * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1039  * @cliexend
1040  ?*/
1041 /* *INDENT-OFF* */
1042 VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1043     .path = "show vxlan-gpe",
1044     .function = show_vxlan_gpe_tunnel_command_fn,
1045 };
1046 /* *INDENT-ON* */
1047
1048 void
1049 vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
1050 {
1051   if (is_ip6)
1052     vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1053                                  sw_if_index, is_enable, 0, 0);
1054   else
1055     vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1056                                  sw_if_index, is_enable, 0, 0);
1057 }
1058
1059
1060 static clib_error_t *
1061 set_ip_vxlan_gpe_bypass (u32 is_ip6,
1062                          unformat_input_t * input, vlib_cli_command_t * cmd)
1063 {
1064   unformat_input_t _line_input, *line_input = &_line_input;
1065   vnet_main_t *vnm = vnet_get_main ();
1066   clib_error_t *error = 0;
1067   u32 sw_if_index, is_enable;
1068
1069   sw_if_index = ~0;
1070   is_enable = 1;
1071
1072   if (!unformat_user (input, unformat_line_input, line_input))
1073     return 0;
1074
1075   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1076     {
1077       if (unformat_user
1078           (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1079         ;
1080       else if (unformat (line_input, "del"))
1081         is_enable = 0;
1082       else
1083         {
1084           error = unformat_parse_error (line_input);
1085           goto done;
1086         }
1087     }
1088
1089   if (~0 == sw_if_index)
1090     {
1091       error = clib_error_return (0, "unknown interface `%U'",
1092                                  format_unformat_error, line_input);
1093       goto done;
1094     }
1095
1096   vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1097
1098 done:
1099   unformat_free (line_input);
1100
1101   return error;
1102 }
1103
1104 static clib_error_t *
1105 set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
1106                           unformat_input_t * input, vlib_cli_command_t * cmd)
1107 {
1108   return set_ip_vxlan_gpe_bypass (0, input, cmd);
1109 }
1110
1111 /*?
1112  * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1113  * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1114  *  for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1115  * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1116  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1117  *
1118  * @cliexpar
1119  * @parblock
1120  * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1121  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1122  *            Name                      Next                    Previous
1123  * ip4-vxlan-gpe-bypass                error-drop [0]
1124  *                                vxlan4-gpe-input [1]
1125  *                                 ip4-lookup [2]
1126  * @cliexend
1127  *
1128  * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1129  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1130  *
1131  * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1132  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1133  *            Name                      Next                    Previous
1134  * ip4-vxlan-gpe-bypass                error-drop [0]               ip4-input
1135  *                                vxlan4-gpe-input [1]        ip4-input-no-checksum
1136  *                                 ip4-lookup [2]
1137  * @cliexend
1138  *
1139  * Example of how to display the feature enabed on an interface:
1140  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1141  * IP feature paths configured on GigabitEthernet2/0/0...
1142  * ...
1143  * ipv4 unicast:
1144  *   ip4-vxlan-gpe-bypass
1145  *   ip4-lookup
1146  * ...
1147  * @cliexend
1148  *
1149  * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1150  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1151  * @endparblock
1152 ?*/
1153 /* *INDENT-OFF* */
1154 VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1155   .path = "set interface ip vxlan-gpe-bypass",
1156   .function = set_ip4_vxlan_gpe_bypass,
1157   .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1158 };
1159 /* *INDENT-ON* */
1160
1161 static clib_error_t *
1162 set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
1163                           unformat_input_t * input, vlib_cli_command_t * cmd)
1164 {
1165   return set_ip_vxlan_gpe_bypass (1, input, cmd);
1166 }
1167
1168 /*?
1169  * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1170  * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1171  *  for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1172  * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1173  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1174  *
1175  * @cliexpar
1176  * @parblock
1177  * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1178  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1179  *            Name                      Next                    Previous
1180  * ip6-vxlan-gpe-bypass                error-drop [0]
1181  *                                vxlan6-gpe-input [1]
1182  *                                 ip6-lookup [2]
1183  * @cliexend
1184  *
1185  * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1186  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1187  *
1188  * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1189  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1190  *            Name                      Next                    Previous
1191  * ip6-vxlan-gpe-bypass                error-drop [0]               ip6-input
1192  *                                vxlan6-gpe-input [1]        ip4-input-no-checksum
1193  *                                 ip6-lookup [2]
1194  * @cliexend
1195  *
1196  * Example of how to display the feature enabed on an interface:
1197  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1198  * IP feature paths configured on GigabitEthernet2/0/0...
1199  * ...
1200  * ipv6 unicast:
1201  *   ip6-vxlan-gpe-bypass
1202  *   ip6-lookup
1203  * ...
1204  * @cliexend
1205  *
1206  * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1207  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1208  * @endparblock
1209 ?*/
1210 /* *INDENT-OFF* */
1211 VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1212   .path = "set interface ip6 vxlan-gpe-bypass",
1213   .function = set_ip6_vxlan_gpe_bypass,
1214   .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1215 };
1216 /* *INDENT-ON* */
1217
1218 /* *INDENT-OFF* */
1219 VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1220 {
1221   .arc_name = "ip4-unicast",
1222   .node_name = "ip4-vxlan-gpe-bypass",
1223   .runs_before = VNET_FEATURES ("ip4-lookup"),
1224 };
1225
1226 VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1227 {
1228   .arc_name = "ip6-unicast",
1229   .node_name = "ip6-vxlan-gpe-bypass",
1230   .runs_before = VNET_FEATURES ("ip6-lookup"),
1231 };
1232 /* *INDENT-ON* */
1233
1234 /**
1235  * @brief Feature init function for VXLAN GPE
1236  *
1237  * @param *vm
1238  *
1239  * @return error
1240  *
1241  */
1242 clib_error_t *
1243 vxlan_gpe_init (vlib_main_t * vm)
1244 {
1245   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1246
1247   ngm->vnet_main = vnet_get_main ();
1248   ngm->vlib_main = vm;
1249
1250   ngm->vxlan4_gpe_tunnel_by_key
1251     = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
1252
1253   ngm->vxlan6_gpe_tunnel_by_key
1254     = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
1255
1256
1257   ngm->mcast_shared = hash_create_mem (0,
1258                                        sizeof (ip46_address_t),
1259                                        sizeof (mcast_shared_t));
1260   ngm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
1261
1262   udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE,
1263                          vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
1264   udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE,
1265                          vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
1266
1267   /* Register the list of standard decap protocols supported */
1268   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
1269                                      VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
1270   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
1271                                      VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
1272   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
1273                                      VXLAN_GPE_INPUT_NEXT_L2_INPUT);
1274
1275   fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
1276
1277   return 0;
1278 }
1279
1280 VLIB_INIT_FUNCTION (vxlan_gpe_init);
1281
1282
1283 /*
1284  * fd.io coding-style-patch-verification: ON
1285  *
1286  * Local Variables:
1287  * eval: (c-set-style "gnu")
1288  * End:
1289  */