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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vnet/vxlan/vxlan.h>
16 #include <vnet/ip/format.h>
17 #include <vnet/fib/fib_entry.h>
18 #include <vnet/fib/fib_table.h>
19 #include <vnet/dpo/receive_dpo.h>
20 #include <vlib/vlib.h>
26 * VXLAN provides the features needed to allow L2 bridge domains (BDs)
27 * to span multiple servers. This is done by building an L2 overlay on
28 * top of an L3 network underlay using VXLAN tunnels.
30 * This makes it possible for servers to be co-located in the same data
31 * center or be separated geographically as long as they are reachable
32 * through the underlay L3 network.
34 * You can refer to this kind of L2 overlay bridge domain as a VXLAN
35 * (Virtual eXtensible VLAN) segment.
39 vxlan_main_t vxlan_main;
41 static u8 * format_decap_next (u8 * s, va_list * args)
43 u32 next_index = va_arg (*args, u32);
47 case VXLAN_INPUT_NEXT_DROP:
48 return format (s, "drop");
49 case VXLAN_INPUT_NEXT_L2_INPUT:
50 return format (s, "l2");
52 return format (s, "next-index %d", next_index);
57 u8 * format_vxlan_tunnel (u8 * s, va_list * args)
59 vxlan_tunnel_t * t = va_arg (*args, vxlan_tunnel_t *);
60 vxlan_main_t * ngm = &vxlan_main;
63 "[%d] src %U dst %U vni %d encap_fib_index %d sw_if_index %d "
66 format_ip46_address, &t->src, IP46_TYPE_ANY,
67 format_ip46_address, &t->dst, IP46_TYPE_ANY,
68 t->vni, t->encap_fib_index, t->sw_if_index, t->fib_entry_index);
69 s = format (s, " decap_next %U\n", format_decap_next, t->decap_next_index);
73 static u8 * format_vxlan_name (u8 * s, va_list * args)
75 u32 dev_instance = va_arg (*args, u32);
76 return format (s, "vxlan_tunnel%d", dev_instance);
79 static uword dummy_interface_tx (vlib_main_t * vm,
80 vlib_node_runtime_t * node,
83 clib_warning ("you shouldn't be here, leaking buffers...");
84 return frame->n_vectors;
88 vxlan_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
90 if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
91 vnet_hw_interface_set_flags (vnm, hw_if_index, VNET_HW_INTERFACE_FLAG_LINK_UP);
93 vnet_hw_interface_set_flags (vnm, hw_if_index, 0);
95 return /* no error */ 0;
98 VNET_DEVICE_CLASS (vxlan_device_class,static) = {
100 .format_device_name = format_vxlan_name,
101 .format_tx_trace = format_vxlan_encap_trace,
102 .tx_function = dummy_interface_tx,
103 .admin_up_down_function = vxlan_interface_admin_up_down,
106 static u8 * format_vxlan_header_with_length (u8 * s, va_list * args)
108 u32 dev_instance = va_arg (*args, u32);
109 s = format (s, "unimplemented dev %u", dev_instance);
113 VNET_HW_INTERFACE_CLASS (vxlan_hw_class) = {
115 .format_header = format_vxlan_header_with_length,
116 .build_rewrite = default_build_rewrite,
120 vxlan_tunnel_restack_dpo(vxlan_tunnel_t * t)
122 dpo_id_t dpo = DPO_INVALID;
123 u32 encap_index = ip46_address_is_ip4(&t->dst) ?
124 vxlan4_encap_node.index : vxlan6_encap_node.index;
125 fib_forward_chain_type_t forw_type = ip46_address_is_ip4(&t->dst) ?
126 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
128 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
129 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
133 static vxlan_tunnel_t *
134 vxlan_tunnel_from_fib_node (fib_node_t *node)
137 ASSERT(FIB_NODE_TYPE_VXLAN_TUNNEL == node->fn_type);
139 return ((vxlan_tunnel_t*) (((char*)node) -
140 STRUCT_OFFSET_OF(vxlan_tunnel_t, node)));
144 * Function definition to backwalk a FIB node -
145 * Here we will restack the new dpo of VXLAN DIP to encap node.
147 static fib_node_back_walk_rc_t
148 vxlan_tunnel_back_walk (fib_node_t *node,
149 fib_node_back_walk_ctx_t *ctx)
151 vxlan_tunnel_restack_dpo(vxlan_tunnel_from_fib_node(node));
152 return (FIB_NODE_BACK_WALK_CONTINUE);
156 * Function definition to get a FIB node from its index
159 vxlan_tunnel_fib_node_get (fib_node_index_t index)
162 vxlan_main_t * vxm = &vxlan_main;
164 t = pool_elt_at_index(vxm->tunnels, index);
170 * Function definition to inform the FIB node that its last lock has gone.
173 vxlan_tunnel_last_lock_gone (fib_node_t *node)
176 * The VXLAN tunnel is a root of the graph. As such
177 * it never has children and thus is never locked.
183 * Virtual function table registered by VXLAN tunnels
184 * for participation in the FIB object graph.
186 const static fib_node_vft_t vxlan_vft = {
187 .fnv_get = vxlan_tunnel_fib_node_get,
188 .fnv_last_lock = vxlan_tunnel_last_lock_gone,
189 .fnv_back_walk = vxlan_tunnel_back_walk,
193 #define foreach_copy_field \
195 _(mcast_sw_if_index) \
197 _(decap_next_index) \
201 static int vxlan4_rewrite (vxlan_tunnel_t * t)
205 ip4_vxlan_header_t * h0;
206 int len = sizeof (*h0);
208 vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
210 h0 = (ip4_vxlan_header_t *) rw;
212 /* Fixed portion of the (outer) ip4 header */
214 ip0->ip_version_and_header_length = 0x45;
216 ip0->protocol = IP_PROTOCOL_UDP;
218 /* we fix up the ip4 header length and checksum after-the-fact */
219 ip0->src_address.as_u32 = t->src.ip4.as_u32;
220 ip0->dst_address.as_u32 = t->dst.ip4.as_u32;
221 ip0->checksum = ip4_header_checksum (ip0);
223 /* UDP header, randomize src port on something, maybe? */
224 h0->udp.src_port = clib_host_to_net_u16 (4789);
225 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
228 vnet_set_vni_and_flags(&h0->vxlan, t->vni);
234 static int vxlan6_rewrite (vxlan_tunnel_t * t)
238 ip6_vxlan_header_t * h0;
239 int len = sizeof (*h0);
241 vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
243 h0 = (ip6_vxlan_header_t *) rw;
245 /* Fixed portion of the (outer) ip6 header */
247 ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
248 ip0->hop_limit = 255;
249 ip0->protocol = IP_PROTOCOL_UDP;
251 ip0->src_address.as_u64[0] = t->src.ip6.as_u64[0];
252 ip0->src_address.as_u64[1] = t->src.ip6.as_u64[1];
253 ip0->dst_address.as_u64[0] = t->dst.ip6.as_u64[0];
254 ip0->dst_address.as_u64[1] = t->dst.ip6.as_u64[1];
256 /* UDP header, randomize src port on something, maybe? */
257 h0->udp.src_port = clib_host_to_net_u16 (4789);
258 h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
261 vnet_set_vni_and_flags(&h0->vxlan, t->vni);
267 static int vxlan_check_decap_next(vxlan_main_t * vxm, u32 is_ip6, u32 decap_next_index)
269 vlib_main_t * vm = vxm->vlib_main;
270 vlib_node_runtime_t *r;
274 r = vlib_node_get_runtime (vm, vxlan4_input_node.index);
275 if(decap_next_index >= r->n_next_nodes)
280 r = vlib_node_get_runtime (vm, vxlan6_input_node.index);
281 if(decap_next_index >= r->n_next_nodes)
288 int vnet_vxlan_add_del_tunnel
289 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp)
291 vxlan_main_t * vxm = &vxlan_main;
292 vxlan_tunnel_t *t = 0;
293 vnet_main_t * vnm = vxm->vnet_main;
294 vnet_hw_interface_t * hi;
296 u32 hw_if_index = ~0;
297 u32 sw_if_index = ~0;
299 vxlan4_tunnel_key_t key4;
300 vxlan6_tunnel_key_t key6;
301 u32 is_ip6 = a->is_ip6;
304 key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
305 key4.vni = clib_host_to_net_u32 (a->vni << 8);
307 p = hash_get (vxm->vxlan4_tunnel_by_key, key4.as_u64);
308 pvtep = hash_get (vxm->vtep4, a->src.ip4.as_u32);
310 key6.src.as_u64[0] = a->dst.ip6.as_u64[0];
311 key6.src.as_u64[1] = a->dst.ip6.as_u64[1];
312 key6.vni = clib_host_to_net_u32 (a->vni << 8);
314 p = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6);
315 pvtep = NULL; /* ip6 vxlan-bypass not yet implemented */
320 l2input_main_t * l2im = &l2input_main;
322 /* adding a tunnel: tunnel must not already exist */
324 return VNET_API_ERROR_TUNNEL_EXIST;
326 /*if not set explicitly, default to l2 */
327 if(a->decap_next_index == ~0)
328 a->decap_next_index = VXLAN_INPUT_NEXT_L2_INPUT;
329 if (vxlan_check_decap_next(vxm, is_ip6, a->decap_next_index))
330 return VNET_API_ERROR_INVALID_DECAP_NEXT;
332 pool_get_aligned (vxm->tunnels, t, CLIB_CACHE_LINE_BYTES);
333 memset (t, 0, sizeof (*t));
335 /* copy from arg structure */
336 #define _(x) t->x = a->x;
343 t->key6 = clib_mem_alloc (sizeof(vxlan6_tunnel_key_t));
344 clib_memcpy (t->key6, &key6, sizeof(key6));
348 t->key4 = 0; /* not yet used */
352 rv = vxlan4_rewrite (t);
354 rv = vxlan6_rewrite (t);
359 pool_put (vxm->tunnels, t);
365 hash_set (vxm->vxlan4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
366 if (pvtep) pvtep[0]++;
367 else hash_set (vxm->vtep4, a->src.ip4.as_u32, 1);
370 hash_set_mem (vxm->vxlan6_tunnel_by_key, t->key6, t - vxm->tunnels);
372 if (vec_len (vxm->free_vxlan_tunnel_hw_if_indices) > 0)
374 vnet_interface_main_t * im = &vnm->interface_main;
375 hw_if_index = vxm->free_vxlan_tunnel_hw_if_indices
376 [vec_len (vxm->free_vxlan_tunnel_hw_if_indices)-1];
377 _vec_len (vxm->free_vxlan_tunnel_hw_if_indices) -= 1;
379 hi = vnet_get_hw_interface (vnm, hw_if_index);
380 hi->dev_instance = t - vxm->tunnels;
381 hi->hw_instance = hi->dev_instance;
383 /* clear old stats of freed tunnel before reuse */
384 sw_if_index = hi->sw_if_index;
385 vnet_interface_counter_lock(im);
386 vlib_zero_combined_counter
387 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX], sw_if_index);
388 vlib_zero_combined_counter
389 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_RX], sw_if_index);
390 vlib_zero_simple_counter
391 (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
392 vnet_interface_counter_unlock(im);
396 hw_if_index = vnet_register_interface
397 (vnm, vxlan_device_class.index, t - vxm->tunnels,
398 vxlan_hw_class.index, t - vxm->tunnels);
399 hi = vnet_get_hw_interface (vnm, hw_if_index);
402 t->hw_if_index = hw_if_index;
403 t->sw_if_index = sw_if_index = hi->sw_if_index;
405 vec_validate_init_empty (vxm->tunnel_index_by_sw_if_index, sw_if_index, ~0);
406 vxm->tunnel_index_by_sw_if_index[sw_if_index] = t - vxm->tunnels;
408 /* setup l2 input config with l2 feature and bd 0 to drop packet */
409 vec_validate (l2im->configs, sw_if_index);
410 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
411 l2im->configs[sw_if_index].bd_index = 0;
413 vnet_sw_interface_set_flags (vnm, sw_if_index,
414 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
415 fib_node_init(&t->node, FIB_NODE_TYPE_VXLAN_TUNNEL);
416 fib_prefix_t tun_dst_pfx;
417 u32 encap_index = !is_ip6 ?
418 vxlan4_encap_node.index : vxlan6_encap_node.index;
419 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
421 fib_prefix_from_ip46_addr(&t->dst, &tun_dst_pfx);
422 if (ip46_address_is_multicast(&t->dst))
427 ip4_multicast_ethernet_address(mcast_mac, &t->dst.ip4);
428 fp = FIB_PROTOCOL_IP4;
430 ip6_multicast_ethernet_address(mcast_mac, t->dst.ip6.as_u32[0]);
431 fp = FIB_PROTOCOL_IP6;
433 t->mcast_adj_index = adj_rewrite_add_and_lock
434 (fp, fib_proto_to_link(fp), t->mcast_sw_if_index, mcast_mac);
436 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
438 /* Stack mcast dst mac addr rewrite on encap */
439 dpo_proto_t dproto = fib_proto_to_dpo(fp);
440 dpo_id_t dpo = DPO_INVALID;
442 dpo_set (&dpo, DPO_ADJACENCY, dproto, t->mcast_adj_index);
443 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
446 /* Add local mcast adj. */
447 receive_dpo_add_or_lock(dproto, ~0, NULL, &dpo);
448 t->fib_entry_index = fib_table_entry_special_dpo_add
449 (t->encap_fib_index, &tun_dst_pfx, FIB_SOURCE_SPECIAL, FIB_ENTRY_FLAG_NONE, &dpo);
453 * source the FIB entry for the tunnel's destination
454 * and become a child thereof. The tunnel will then get poked
455 * when the forwarding for the entry updates, and the tunnel can
456 * re-stack accordingly
458 t->fib_entry_index = fib_table_entry_special_add
459 (t->encap_fib_index, &tun_dst_pfx, FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE, ADJ_INDEX_INVALID);
460 t->sibling_index = fib_entry_child_add
461 (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_TUNNEL, t - vxm->tunnels);
462 vxlan_tunnel_restack_dpo(t);
464 /* Set vxlan tunnel output node */
465 hi->output_node_index = encap_index;
467 vnet_get_sw_interface (vnet_get_main(), sw_if_index)->flood_class = flood_class;
471 /* deleting a tunnel: tunnel must exist */
473 return VNET_API_ERROR_NO_SUCH_ENTRY;
475 t = pool_elt_at_index (vxm->tunnels, p[0]);
477 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */);
478 /* make sure tunnel is removed from l2 bd or xconnect */
479 set_int_l2_mode(vxm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0);
480 vec_add1 (vxm->free_vxlan_tunnel_hw_if_indices, t->hw_if_index);
482 vxm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
484 if (ip46_address_is_multicast(&t->dst))
486 adj_unlock(t->mcast_adj_index);
487 fib_table_entry_delete_index(t->fib_entry_index, FIB_SOURCE_SPECIAL);
491 fib_entry_child_remove(t->fib_entry_index, t->sibling_index);
492 fib_table_entry_delete_index(t->fib_entry_index, FIB_SOURCE_RR);
494 fib_node_deinit(&t->node);
498 hash_unset (vxm->vxlan4_tunnel_by_key, key4.as_u64);
503 hash_unset (vxm->vtep4, a->src.ip4.as_u32);
508 hash_unset_mem (vxm->vxlan6_tunnel_by_key, t->key6);
509 clib_mem_free (t->key6);
511 vec_free (t->rewrite);
512 pool_put (vxm->tunnels, t);
516 *sw_if_indexp = sw_if_index;
521 static u32 fib4_index_from_fib_id (u32 fib_id)
523 ip4_main_t * im = &ip4_main;
526 p = hash_get (im->fib_index_by_table_id, fib_id);
533 static u32 fib6_index_from_fib_id (u32 fib_id)
535 ip6_main_t * im = &ip6_main;
538 p = hash_get (im->fib_index_by_table_id, fib_id);
545 static uword get_decap_next_for_node(u32 node_index, u32 ipv4_set)
547 vxlan_main_t * vxm = &vxlan_main;
548 vlib_main_t * vm = vxm->vlib_main;
549 uword next_index = ~0;
553 next_index = vlib_node_add_next (vm, vxlan4_input_node.index, node_index);
557 next_index = vlib_node_add_next (vm, vxlan6_input_node.index, node_index);
563 static uword unformat_decap_next (unformat_input_t * input, va_list * args)
565 u32 * result = va_arg (*args, u32 *);
566 u32 ipv4_set = va_arg (*args, int);
567 vxlan_main_t * vxm = &vxlan_main;
568 vlib_main_t * vm = vxm->vlib_main;
572 if (unformat (input, "l2"))
573 *result = VXLAN_INPUT_NEXT_L2_INPUT;
574 else if (unformat (input, "node %U", unformat_vlib_node, vm, &node_index))
575 *result = get_decap_next_for_node(node_index, ipv4_set);
576 else if (unformat (input, "%d", &tmp))
583 static clib_error_t *
584 vxlan_add_del_tunnel_command_fn (vlib_main_t * vm,
585 unformat_input_t * input,
586 vlib_cli_command_t * cmd)
588 unformat_input_t _line_input, * line_input = &_line_input;
589 ip46_address_t src , dst;
596 u32 encap_fib_index = 0;
597 u32 mcast_sw_if_index = ~0;
598 u32 decap_next_index = VXLAN_INPUT_NEXT_L2_INPUT;
602 vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a;
603 u32 tunnel_sw_if_index;
605 /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
606 memset(&src, 0, sizeof src);
607 memset(&dst, 0, sizeof dst);
609 /* Get a line of input. */
610 if (! unformat_user (input, unformat_line_input, line_input))
613 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
614 if (unformat (line_input, "del"))
618 else if (unformat (line_input, "src %U",
619 unformat_ip4_address, &src.ip4))
624 else if (unformat (line_input, "dst %U",
625 unformat_ip4_address, &dst.ip4))
630 else if (unformat (line_input, "src %U",
631 unformat_ip6_address, &src.ip6))
636 else if (unformat (line_input, "dst %U",
637 unformat_ip6_address, &dst.ip6))
642 else if (unformat (line_input, "group %U %U",
643 unformat_ip4_address, &dst.ip4,
644 unformat_vnet_sw_interface,
645 vnet_get_main(), &mcast_sw_if_index))
647 grp_set = dst_set = 1;
650 else if (unformat (line_input, "group %U %U",
651 unformat_ip6_address, &dst.ip6,
652 unformat_vnet_sw_interface,
653 vnet_get_main(), &mcast_sw_if_index))
655 grp_set = dst_set = 1;
658 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
661 encap_fib_index = fib6_index_from_fib_id (tmp);
663 encap_fib_index = fib4_index_from_fib_id (tmp);
664 if (encap_fib_index == ~0)
665 return clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
667 else if (unformat (line_input, "decap-next %U", unformat_decap_next,
668 &decap_next_index, ipv4_set))
670 else if (unformat (line_input, "vni %d", &vni))
673 return clib_error_return (0, "vni %d out of range", vni);
676 return clib_error_return (0, "parse error: '%U'",
677 format_unformat_error, line_input);
680 unformat_free (line_input);
683 return clib_error_return (0, "tunnel src address not specified");
686 return clib_error_return (0, "tunnel dst address not specified");
688 if (grp_set && !ip46_address_is_multicast(&dst))
689 return clib_error_return (0, "tunnel group address not multicast");
691 if (grp_set && mcast_sw_if_index == ~0)
692 return clib_error_return (0, "tunnel nonexistent multicast device");
694 if (ipv4_set && ipv6_set)
695 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
697 if (ip46_address_cmp(&src, &dst) == 0)
698 return clib_error_return (0, "src and dst addresses are identical");
700 if (decap_next_index == ~0)
701 return clib_error_return (0, "next node not found");
704 return clib_error_return (0, "vni not specified");
706 memset (a, 0, sizeof (*a));
709 a->is_ip6 = ipv6_set;
711 #define _(x) a->x = x;
715 rv = vnet_vxlan_add_del_tunnel (a, &tunnel_sw_if_index);
721 vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name,
722 vnet_get_main(), tunnel_sw_if_index);
725 case VNET_API_ERROR_TUNNEL_EXIST:
726 return clib_error_return (0, "tunnel already exists...");
728 case VNET_API_ERROR_NO_SUCH_ENTRY:
729 return clib_error_return (0, "tunnel does not exist...");
732 return clib_error_return
733 (0, "vnet_vxlan_add_del_tunnel returned %d", rv);
740 * Add or delete a VXLAN Tunnel.
742 * VXLAN provides the features needed to allow L2 bridge domains (BDs)
743 * to span multiple servers. This is done by building an L2 overlay on
744 * top of an L3 network underlay using VXLAN tunnels.
746 * This makes it possible for servers to be co-located in the same data
747 * center or be separated geographically as long as they are reachable
748 * through the underlay L3 network.
750 * You can refer to this kind of L2 overlay bridge domain as a VXLAN
751 * (Virtual eXtensible VLAN) segment.
754 * Example of how to create a VXLAN Tunnel:
755 * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 encap-vrf-id 7}
756 * Example of how to delete a VXLAN Tunnel:
757 * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 del}
760 VLIB_CLI_COMMAND (create_vxlan_tunnel_command, static) = {
761 .path = "create vxlan tunnel",
763 "create vxlan tunnel src <local-vtep-addr>"
764 " {dst <remote-vtep-addr>|group <mcast-vtep-addr> <intf-name>} vni <nn>"
765 " [encap-vrf-id <nn>] [decap-next [l2|node <name>]] [del]",
766 .function = vxlan_add_del_tunnel_command_fn,
770 static clib_error_t *
771 show_vxlan_tunnel_command_fn (vlib_main_t * vm,
772 unformat_input_t * input,
773 vlib_cli_command_t * cmd)
775 vxlan_main_t * vxm = &vxlan_main;
778 if (pool_elts (vxm->tunnels) == 0)
779 vlib_cli_output (vm, "No vxlan tunnels configured...");
781 pool_foreach (t, vxm->tunnels,
783 vlib_cli_output (vm, "%U", format_vxlan_tunnel, t);
790 * Display all the VXLAN Tunnel entries.
793 * Example of how to display the VXLAN Tunnel entries:
794 * @cliexstart{show vxlan tunnel}
795 * [0] src 10.0.3.1 dst 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
799 VLIB_CLI_COMMAND (show_vxlan_tunnel_command, static) = {
800 .path = "show vxlan tunnel",
801 .short_help = "show vxlan tunnel",
802 .function = show_vxlan_tunnel_command_fn,
807 clib_error_t *vxlan_init (vlib_main_t *vm)
809 vxlan_main_t * vxm = &vxlan_main;
811 vxm->vnet_main = vnet_get_main();
814 /* initialize the ip6 hash */
815 vxm->vxlan6_tunnel_by_key = hash_create_mem(0,
816 sizeof(vxlan6_tunnel_key_t),
819 udp_register_dst_port (vm, UDP_DST_PORT_vxlan,
820 vxlan4_input_node.index, /* is_ip4 */ 1);
821 udp_register_dst_port (vm, UDP_DST_PORT_vxlan6,
822 vxlan6_input_node.index, /* is_ip4 */ 0);
824 fib_node_register_type(FIB_NODE_TYPE_VXLAN_TUNNEL, &vxlan_vft);
829 VLIB_INIT_FUNCTION(vxlan_init);