OpenNSL API Guide and Reference Manual
example_vxlan.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * (C) Copyright Broadcom Corporation 2013-2017
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  ******************************************************************************
18  * \file example_vxlan.c
19  *
20  * \brief Example code for VxLAN application
21  *
22  * VXLAN is a L2 VPN technology targeted for Data-Center communication
23  * between Virtual Machines (VM) assigned to the same customer(Tenant) that are
24  * distributed in various racks in the Data-Center. L2VPN over IP/UDP tunnels can provide
25  * E-LAN (similar to VPLS) and E-LINE (similar to VPWS) service. With VXLAN the ethernet
26  * packets are encapsulated in UDP tunnels over an IP network. VXLAN uses UDP Source_Port
27  * as multiplexing field for multiplexing multiple VPNs into the same UDP Tunnel.
28  * E-LINE is point-to-point service without support for Multicast traffic. In E-LINE, Ethernet
29  * frames are mapped into a VXLAN Tunnel based on incoming port plus packet header information.
30  * At the end of Tunnel, forwarding of Ethernet frames after Tunnel decapsulation is based on
31  * VXLAN-VNID and Tunnel lookup.
32  *
33  * In E-LAN, Ethernet frames of interest are also identified by incoming port plus packet
34  * header information. Ethernet frames are switched into one or more VXLAN Tunnels based
35  * on the MAC DA lookup. At the end of Tunnel, forwarding of Ethernet frames after Tunnel
36  * decapsulation is based on the VXLAN-VNID and Tunnel lookup and frames are again forwarded
37  * based on MAC-DA lookup.
38  *
39  * VXLAN VPN can be of type ELINE or ELAN.
40  *
41  * For ELAN, a VPN is similar to a VLAN, which identifies a group of physical ports to be
42  * included in a broadcast domain. However, instead of physical ports, a ELAN VPN identifies
43  * a group of "virtual-ports" to be included in a broadcast domain. In the VXLAN APIs,
44  * a "virtual-port" is called an VXLAN port (see description below). The VPN ID is used to
45  * qualify MAC DA lookups within the VPN.
46  *
47  * For ELINE, a VPN consists of two VXLAN ports. Packets arriving on one VXLAN port are sent
48  * directly out the other VXLAN port.
49  *
50  * This example application creates 2 VxLAN segments, and two access ports that share 1 tunnel:
51  *
52  * Access Port1 --> Segment 1 (VPN 1) \
53  * +-> share 1 network UDP tunnel
54  * Access Port2 --> Segment 2 (VPN 2) /
55  *
56  ******************************************************************************/
57 
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
61 #include <sal/driver.h>
62 #include <opennsl/error.h>
63 #include <opennsl/l2.h>
64 #include <opennsl/switch.h>
65 #include <opennsl/vlan.h>
66 #include <opennsl/tunnel.h>
67 #include <opennsl/multicast.h>
68 #include <opennsl/vxlan.h>
69 #include <examples/util.h>
70 
71 #define DEFAULT_UNIT 0
72 #define DEFAULT_VLAN 1
73 #define MAX_DIGITS_IN_CHOICE 5
74 
75 char example_usage[] =
76 "Syntax: example_vxlan \n\r"
77 " \n\r"
78 "Paramaters: None. \n\r"
79 " \n\r"
80 "Usage Guidelines: None. \n\r";
81 
82 /* debug prints */
83 int verbose = 3;
84 
85 #define TRUE 1
86 #define FALSE 0
87 #define VXLAN_UDP_DEST_PORT 4789
88 
89 /*****************************************************************/
96 static int do_vxlan_global_setting(int unit)
97 {
98  /* Enable L3 Egress Mode */
101 
102  /* Set UDP destination port for VXLAN */
106 
107  /* Enable UDP Source port based HASH for VXLAN */
110 
111  /* Enable VXLAN Tunnel lookup failure settings to send packets to CPU. */
114 
115  /* Enable VXLAN VN_ID lookup failure settings to send packets to CPU. */
118 
119  return OPENNSL_E_NONE;
120 }
121 /* __doxy_func_body_end__ */
122 
123 /*****************************************************************/
131 static int do_vxlan_access_port_settings(int unit, opennsl_port_t a_port)
132 {
133  /* Should disable Vxlan Processing on access port. VXLAN encapsulated packets are
134  * not expected on the access port.
135  */
138 
139  /* Should disable Tunnel Based Vxlan-VnId lookup */
142 
143  /* Should Enable VLAN translation if access port uses 802.1Q or QinQ */
145 
146  return OPENNSL_E_NONE;
147 }
148 /* __doxy_func_body_end__ */
149 
150 /*****************************************************************/
158 static int do_vxlan_net_port_settings(int unit, opennsl_port_t n_port)
159 {
160  /* Enable VXLAN Processing on network port */
163 
164  /* Allow tunnel based VXLAN-VNID lookup */
167 
168  /* Enable Default SVP on network side */
171 
172  return OPENNSL_E_NONE;
173 }
174 /* __doxy_func_body_end__ */
175 
176 /*****************************************************************/
188 static int create_vxlan_vpn(int unit, int vpn_id, int vnid, opennsl_multicast_t bc,
190 {
193 
197  vpn_info.vpn = vpn_id;
198  vpn_info.vnid = vnid;
199  vpn_info.broadcast_group = bc;
200  vpn_info.unknown_multicast_group = mc;
201  vpn_info.unknown_unicast_group = uuc;
202  rv = opennsl_vxlan_vpn_create(unit, &vpn_info);
203 
204  if (rv != OPENNSL_E_NONE)
205  {
206  printf("create_vxlan_vpn: failed to create VXLAN VPN rv %d\n", rv);
207  }
208  return rv;
209 }
210 /* __doxy_func_body_end__ */
211 
212 
213 /*****************************************************************/
228 static int create_vxlan_acc_vp(int unit, opennsl_vpn_t vpn, uint32 flags,
231  opennsl_if_t egr_obj, opennsl_vlan_t vid,
232  opennsl_gport_t *vp)
233 {
234  opennsl_vxlan_port_t vxlan_port;
236 
237  opennsl_vxlan_port_t_init(&vxlan_port);
238  vxlan_port.flags = OPENNSL_VXLAN_PORT_SERVICE_TAGGED | flags;
239  vxlan_port.match_port = port;
240  vxlan_port.criteria = criteria;
241  vxlan_port.egress_if = egr_obj;
242  vxlan_port.match_vlan = vid;
243  rv = opennsl_vxlan_port_add(unit, vpn, &vxlan_port);
244  *vp = vxlan_port.vxlan_port_id;
245 
246  if (rv != OPENNSL_E_NONE)
247  {
248  printf("create_vxlan_acc_vp: failed to create vxlan port rv %d\n", rv);
249  }
250 
251  return rv;
252 }
253 /* __doxy_func_body_end__ */
254 
255 /*****************************************************************/
271 static int create_vxlan_net_vp(int unit, opennsl_vpn_t vpn, uint32 flags, opennsl_gport_t port,
272  opennsl_vxlan_port_match_t criteria, opennsl_if_t egr_obj,
273  opennsl_gport_t tun_init, opennsl_gport_t tun_term,
274  opennsl_gport_t *vp)
275 {
276  opennsl_vxlan_port_t vxlan_port;
278 
279  opennsl_vxlan_port_t_init(&vxlan_port);
280  vxlan_port.flags = OPENNSL_VXLAN_PORT_NETWORK |
283  vxlan_port.match_port = port;
284  vxlan_port.criteria = criteria;
285  vxlan_port.egress_if = egr_obj;
286  vxlan_port.egress_tunnel_id = tun_init;
287  vxlan_port.match_tunnel_id = tun_term;
288  rv = opennsl_vxlan_port_add(unit, vpn, &vxlan_port);
289  *vp = vxlan_port.vxlan_port_id;
290 
291  if (rv != OPENNSL_E_NONE)
292  {
293  printf("create_vxlan_net_vp: failed to create vxlan port rv %d\n", rv);
294  }
295 
296  return rv;
297 }
298 /* __doxy_func_body_end__ */
299 
300 /*****************************************************************/
310 static int add_to_l2_station(int unit, opennsl_mac_t mac, opennsl_vlan_t vid)
311 {
312  opennsl_l2_station_t l2_station;
313  int station_id;
315  opennsl_mac_t bc_mac_mask = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
316 
317  opennsl_l2_station_t_init(&l2_station);
318  memcpy(l2_station.dst_mac, mac, sizeof(opennsl_mac_t));
319  memcpy(l2_station.dst_mac_mask, bc_mac_mask, sizeof(opennsl_mac_t));
320  l2_station.vlan = vid;
321  l2_station.vlan_mask = 0xfff;
322  l2_station.flags = OPENNSL_L2_STATION_IPV4;
323  rv = opennsl_l2_station_add(unit, &station_id, &l2_station);
324 
325  if (rv != OPENNSL_E_NONE)
326  {
327  printf("add_to_l2_station: failed to create l2 entry rv %d\n", rv);
328  }
329 
330  return rv;
331 }
332 /* __doxy_func_body_end__ */
333 
334 /*****************************************************************/
344 int add_to_l2_table(int unit, opennsl_mac_t mac, opennsl_vpn_t vpn_id, int port)
345 {
346  int rv;
347  opennsl_l2_addr_t l2_addr;
348 
349  opennsl_l2_addr_t_init(&l2_addr, mac, vpn_id);
350  l2_addr.flags = OPENNSL_L2_STATIC;
351  l2_addr.port = port;
352  rv = opennsl_l2_addr_add(unit, &l2_addr);
353  if (rv != OPENNSL_E_NONE)
354  {
355  printf("add_to_l2_table: failed to create l2 entry rv %d\n", rv);
356  }
357  return rv;
358 }
359 /* __doxy_func_body_end__ */
360 
361 /*****************************************************************/
370 int vlan_create_add_port(int unit, int vid, int port)
371 {
372  opennsl_pbmp_t pbmp, upbmp;
373 
375  OPENNSL_PBMP_CLEAR(pbmp);
376  OPENNSL_PBMP_CLEAR(upbmp);
377  OPENNSL_PBMP_PORT_ADD(pbmp, port);
378  return opennsl_vlan_port_add(unit, vid, pbmp, upbmp);
379 }
380 /* __doxy_func_body_end__ */
381 
382 /*****************************************************************/
392 static int create_l3_interface(int unit, opennsl_mac_t local_mac, int vid,
393  opennsl_if_t *intf_id)
394 {
395  opennsl_l3_intf_t l3_intf;
397 
398  /* L3 interface and egress object for access */
399  opennsl_l3_intf_t_init(&l3_intf);
400  memcpy(l3_intf.l3a_mac_addr, local_mac, sizeof(opennsl_mac_t));
401  l3_intf.l3a_vid = vid;
402  rv = opennsl_l3_intf_create(unit, &l3_intf);
403  *intf_id = l3_intf.l3a_intf_id;
404 
405  if (rv != OPENNSL_E_NONE)
406  {
407  printf("create_l3_interface: failed to create L3 intf rv %d\n", rv);
408  }
409 
410  return rv;
411 }
412 /* __doxy_func_body_end__ */
413 
414 /*****************************************************************/
427 static int create_egr_obj(int unit, uint32 flag, int l3_if, opennsl_mac_t nh_mac,
428  opennsl_gport_t gport, int vid, opennsl_if_t *egr_obj_id)
429 {
431  opennsl_l3_egress_t l3_egress;
432 
433  opennsl_l3_egress_t_init(&l3_egress);
434  l3_egress.flags = OPENNSL_L3_VXLAN_ONLY | flag;
435  l3_egress.intf = l3_if;
436  memcpy(l3_egress.mac_addr, nh_mac, sizeof(opennsl_mac_t));
437  l3_egress.vlan = vid;
438  l3_egress.port = gport;
439  rv = opennsl_l3_egress_create(unit, flag, &l3_egress, egr_obj_id);
440 
441  if (rv != OPENNSL_E_NONE)
442  {
443  printf("create_egr_obj: failed to create L3 egress object rv %d\n", rv);
444  }
445 
446  return rv;
447 }
448 /* __doxy_func_body_end__ */
449 
450 /*****************************************************************/
463 static int tunnel_initiator_setup(int unit, opennsl_ip_t lip, opennsl_ip_t rip,
464  int dp, int sp, int ttl, int *tid)
465 {
468 
470  tnl_init.type = opennslTunnelTypeVxlan;
471  tnl_init.ttl = ttl;
472  tnl_init.sip = lip;
473  tnl_init.dip = rip;
474  tnl_init.udp_dst_port = dp;
475  tnl_init.udp_src_port = sp;
476  rv = opennsl_vxlan_tunnel_initiator_create(unit, &tnl_init);
477 
478  if (rv != OPENNSL_E_NONE)
479  {
480  printf("tunnel_initiator_setup: failed to create VXLAN tunnel initiator rv %d\n", rv);
481  }
482 
483  *tid = tnl_init.tunnel_id;
484 
485 
486  return rv;
487 }
488 /* __doxy_func_body_end__ */
489 
490 /*****************************************************************/
503 static int tunnel_terminator_setup(int unit, opennsl_ip_t rip, opennsl_ip_t lip,
504  opennsl_vlan_t net_vid, int tunnel_init_id, int *term_id)
505 {
508 
510  tnl_term.type = opennslTunnelTypeVxlan;
511  tnl_term.sip = rip; /* For MC tunnel, Don't care */
512  tnl_term.dip = lip;
513  tnl_term.tunnel_id = tunnel_init_id;
515  if (net_vid != (opennsl_vlan_t)-1) {
516  tnl_term.vlan = net_vid; /* MC tunnel only - for Bud check */
517  }
518  rv = opennsl_vxlan_tunnel_terminator_create(unit, &tnl_term);
519  *term_id = tnl_term.tunnel_id;
520 
521  if (rv != OPENNSL_E_NONE)
522  {
523  printf("tunnel_terminator_setup: failed to create VXLAN tunnel terminator rv %d\n", rv);
524  }
525 
526  return rv;
527 }
528 /* __doxy_func_body_end__ */
529 
530 
531 /*****************************************************************/
540 static void example_vxlan(opennsl_port_t a_port1, opennsl_port_t a_port2,
541  opennsl_port_t n_port)
542 {
543  int unit = DEFAULT_UNIT;
544 
545  /* VPN IDs */
546  opennsl_vpn_t vpn_id_1 = 0x7010, vpn_id_2 = 0x7020;
547  int vnid_1 = 0x12345, vnid_2 = 0x53535;
548  opennsl_multicast_t bc_group_1 = 0, bc_group_2 = 0;
549 
550  /* Used to create a dummy VPN that is used to create network VP */
551  int rsvd_network_vpn = 0x7001;
552  int rsvd_network_vpn_vnid = 0xeeee;
553 
554  /* Access side */
555  /* Access side MAC addresses are not really used */
556  opennsl_mac_t acc_dummy_mac = {0x00, 0x00, 0x01, 0x00, 0x00, 0x01};
557 
558  opennsl_port_t acc_port_1 = a_port1; /* access 1 */
559  opennsl_vlan_t acc_vid_1 = 21;
560  opennsl_if_t acc_intf_id_1 = a_port1;
562  opennsl_if_t acc_egr_obj_1;
563  int acc_vxlan_port_1;
564  opennsl_if_t acc_encap_id_1;
565 
566  opennsl_port_t acc_port_2 = a_port2; /* access 2 */
567  opennsl_vlan_t acc_vid_2 = 20;
568  opennsl_if_t acc_intf_id_2 = a_port2;
570  opennsl_if_t acc_egr_obj_2;
571  int acc_vxlan_port_2;
572  opennsl_if_t acc_encap_id_2;
573 
574  /* Network side */
575  opennsl_port_t net_port = n_port;
576  opennsl_vlan_t net_vid = 22;
577  opennsl_if_t net_intf_id = n_port;
579  opennsl_if_t net_egr_obj;
580  int net_vxlan_port;
581 
582  /* UC Tunnel */
583  uint8 ttl = 16;
584  uint16 udp_dp = VXLAN_UDP_DEST_PORT;
585  uint16 udp_sp = 0xffff;
586  opennsl_mac_t net_local_mac = {0x00, 0x00, 0x00, 0x00, 0x22, 0x22};
587  opennsl_mac_t net_remote_mac = {0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
588  opennsl_ip_t tnl_local_ip = 0x0a0a0a01; /* 10.10.10.1 */
589  opennsl_ip_t tnl_remote_ip = 0xC0A80101; /* 192.168.1.1 */
590  int tunnel_init_id, tunnel_term_id;
591 
592  /* DLF/BC tunnel and virtual port */
593  opennsl_mac_t dlf_mac = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x0A}; /* 224.0.0.10 */
594  opennsl_ip_t tnl_mc_dip = 0xe000000A; /* 224.0.0.10 */
595  opennsl_if_t egr_obj_mc;
596  int vxlan_port_mc;
597  opennsl_if_t encap_id_mc;
598  int tunnel_mc_init_id, tunnel_mc_term_id;
599 
600  /* Payment MAC from access 1 */
601  opennsl_mac_t payload_sa_1 = {0x00, 0x00, 0x00, 0x00, 0x11, 0xaa};
602  opennsl_mac_t payload_da_1 = {0x00, 0x00, 0x00, 0x00, 0x11, 0xbb};
603 
604  /* Payment MAC from access 2 */
605  opennsl_mac_t payload_sa_2 = {0x00, 0x00, 0x00, 0x00, 0x22, 0xaa};
606  opennsl_mac_t payload_da_2 = {0x00, 0x00, 0x00, 0x00, 0x22, 0xbb};
607 
608 
609  /* Global settings */
610  do_vxlan_global_setting(unit);
611 
612  /* Access port settings */
613  do_vxlan_access_port_settings(unit, acc_port_1);
614  do_vxlan_access_port_settings(unit, acc_port_2);
615 
616  /* Network port settings */
617  do_vxlan_net_port_settings(unit, net_port);
618 
619  opennsl_port_gport_get(unit, acc_port_1, &acc_gport_1);
620  opennsl_port_gport_get(unit, acc_port_2, &acc_gport_2);
621  opennsl_port_gport_get(unit, net_port, &net_gport);
622 
623  /* Multicast group for segment BC/DLF/MC */
626 
627  /* Create VXLAN VPNs */
628  create_vxlan_vpn(unit, vpn_id_1, vnid_1, bc_group_1, bc_group_1, bc_group_1);
629  create_vxlan_vpn(unit, vpn_id_2, vnid_2, bc_group_2, bc_group_2, bc_group_2);
630 
631  /* Create VXLAN VPN for assigning Network-VP */
632  create_vxlan_vpn(unit, rsvd_network_vpn, rsvd_network_vpn_vnid, bc_group_2,
633  bc_group_2, bc_group_2);
634 
635  /* Create access side VXLAN port 1 (belongs to VPN 1) */
636 
637  /* VLAN settings */
638  vlan_create_add_port(unit, acc_vid_1, acc_port_1);
639 
640  /* L3 interface and egress object for access 1 - note use a dummy MAC address */
641  create_l3_interface(unit, acc_dummy_mac, acc_vid_1, &acc_intf_id_1);
642  create_egr_obj(unit, 0, acc_intf_id_1, acc_dummy_mac,
643  acc_gport_1, acc_vid_1, &acc_egr_obj_1);
644 
645  /* Create VXLAN VP for access port 1 */
646  create_vxlan_acc_vp(unit, vpn_id_1, 0, acc_gport_1, OPENNSL_VXLAN_PORT_MATCH_PORT,
647  acc_egr_obj_1, acc_vid_1, &acc_vxlan_port_1);
648 
649  /* Create access side VXLAN port 2 (belongs to VPN 2) */
650 
651  /* VLAN settings */
652  vlan_create_add_port(unit, acc_vid_2, acc_port_2);
653 
654  /* L3 interface and egress object for access 2 - note use a dummy MAC address */
655  create_l3_interface(unit, acc_dummy_mac, acc_vid_2, &acc_intf_id_2);
656  create_egr_obj(unit, 0, acc_intf_id_2, acc_dummy_mac,
657  acc_gport_2, acc_vid_2, &acc_egr_obj_2);
658 
659  /* Create VXLAN VP for access port 2 */
660  create_vxlan_acc_vp(unit, vpn_id_2, 0, acc_gport_2, OPENNSL_VXLAN_PORT_MATCH_PORT,
661  acc_egr_obj_2, acc_vid_2, &acc_vxlan_port_2);
662 
663  /* The network tunnel is shared by the two VPNs */
664 
665  /* VLAN settings */
666  vlan_create_add_port(unit, net_vid, net_port);
667 
668  /* L3 interface and egress object for network */
669  create_l3_interface(unit, net_local_mac, net_vid, &net_intf_id);
670  create_egr_obj(unit, 0, net_intf_id, net_remote_mac, net_gport,
671  net_vid, &net_egr_obj);
672 
673  /* Tunnel Setup (Initiator & Terminator - UC) */
674  tunnel_initiator_setup(unit, tnl_local_ip, tnl_remote_ip, udp_dp, udp_sp, ttl, &tunnel_init_id);
675  tunnel_terminator_setup(unit, tnl_remote_ip, tnl_local_ip, -1, tunnel_init_id, &tunnel_term_id);
676 
677  /* Create VXLAN VP for network port */
678  create_vxlan_net_vp(unit, rsvd_network_vpn, 0, net_gport, OPENNSL_VXLAN_PORT_MATCH_VN_ID, net_egr_obj,
679  tunnel_init_id, tunnel_term_id, &net_vxlan_port);
680 
681  /* Station MAC set up - this will terminate incoming L3 packets on network port */
682  add_to_l2_station(unit, net_local_mac, net_vid);
683 
684  /*
685  * DLF/BC network port set up
686  */
687 
688  /* Egress object for non-UC VXLAN VP, use same interface as UC VXLAN network */
689  create_egr_obj(unit, OPENNSL_L3_IPMC, net_intf_id, dlf_mac, net_gport, net_vid, &egr_obj_mc);
690 
691  /* Tunnel Setup (Initiator & Terminator - non-UC) */
692  tunnel_initiator_setup(unit, tnl_local_ip, tnl_mc_dip, udp_dp, udp_sp, ttl, &tunnel_mc_init_id);
693  tunnel_terminator_setup(unit, tnl_remote_ip, tnl_mc_dip, net_vid,
694  tunnel_mc_init_id, &tunnel_mc_term_id);
695 
696  /* Create non-UC VXLAN VP for network port */
697  create_vxlan_net_vp(unit, rsvd_network_vpn, OPENNSL_VXLAN_PORT_MULTICAST, net_gport,
698  OPENNSL_VXLAN_PORT_MATCH_NONE, egr_obj_mc,
699  tunnel_mc_init_id, tunnel_mc_term_id, &vxlan_port_mc);
700 
701  /* Station MAC set up */
702  add_to_l2_station(unit, dlf_mac, net_vid);
703 
704  /*
705  * MC group set up - MC group should contains all Access ports and Network non-UC port
706  */
707 
708  /* BC group 1 (VPN 1)*/
709  opennsl_multicast_vxlan_encap_get(unit, bc_group_1, net_gport, vxlan_port_mc, &encap_id_mc);
710  opennsl_multicast_egress_add(unit, bc_group_1, vxlan_port_mc, encap_id_mc);
711 
712  opennsl_multicast_vxlan_encap_get(unit, bc_group_1, acc_gport_1, acc_vxlan_port_1, &acc_encap_id_1);
713  opennsl_multicast_egress_add(unit, bc_group_1, acc_vxlan_port_1, acc_encap_id_1);
714 
715  /* BC group 2 (VPN 2) */
716  opennsl_multicast_vxlan_encap_get(unit, bc_group_2, net_gport, vxlan_port_mc, &encap_id_mc);
717  opennsl_multicast_egress_add(unit, bc_group_2, vxlan_port_mc, encap_id_mc);
718 
719  opennsl_multicast_vxlan_encap_get(unit, bc_group_2, acc_gport_2, acc_vxlan_port_2, &acc_encap_id_2);
720  opennsl_multicast_egress_add(unit, bc_group_2, acc_vxlan_port_2, acc_encap_id_2);
721 
722  /*
723  * Add Payload L2 address to L2 table
724  */
725 
726  /* Access 1 => Network */
727  add_to_l2_table(unit, payload_da_1, vpn_id_1, net_vxlan_port);
728 
729  /* Network => Access 1 */
730  add_to_l2_table(unit, payload_sa_1, vpn_id_1, acc_vxlan_port_1);
731 
732  /* Access 2 => Network */
733  add_to_l2_table(unit, payload_da_2, vpn_id_2, net_vxlan_port);
734 
735  /* Network => Access 2 */
736  add_to_l2_table(unit, payload_sa_2, vpn_id_2, acc_vxlan_port_2);
737 
738 }
739 /* __doxy_func_body_end__ */
740 
741 /*****************************************************************/
748 int main(int argc, char *argv[])
749 {
750  opennsl_error_t rv;
751  int choice;
752  int index = 0;
753  int unit = DEFAULT_UNIT;
754  int aport_1, aport_2, nport;
755 
756  if(strcmp(argv[0], "gdb") == 0)
757  {
758  index = 1;
759  }
760 
761  if((argc != (index + 1)) || ((argc > (index + 1)) && (strcmp(argv[index + 1], "--help") == 0))) {
762  printf("%s\n\r", example_usage);
763  return OPENNSL_E_PARAM;
764  }
765 
766  /* Initialize the system. */
767  printf("Initializing the switch device.\r\n");
769 
770  if(rv != OPENNSL_E_NONE) {
771  printf("\r\nFailed to initialize the switch device. Error %s\r\n",
772  opennsl_errmsg(rv));
773  return rv;
774  }
775 
776  /* cold boot initialization commands */
777  rv = example_port_default_config(unit);
778  if (rv != OPENNSL_E_NONE) {
779  printf("\r\nFailed to apply default config on ports, rc = %d (%s).\r\n",
780  rv, opennsl_errmsg(rv));
781  }
782 
783  printf("1. Enter Access port 1\n");
784  do
785  {
787  {
788  printf("Invalid port number entered. Please re-enter.\n");
789  continue;
790  }
791  break;
792  } while(1);
793 
794  printf("2. Enter Access port 2\n");
795  do
796  {
798  {
799  printf("Invalid port number entered. Please re-enter.\n");
800  continue;
801  }
802  break;
803  } while(1);
804 
805  printf("3. Enter Network port\n");
806  do
807  {
809  {
810  printf("Invalid port number entered. Please re-enter.\n");
811  continue;
812  }
813  break;
814  } while(1);
815 
816  /* Configure VXLAN settings for access and network ports */
817  example_vxlan(aport_1, aport_2, nport);
818 
819  printf("\r\nVxLAN configuration is done successfully\n");
820 
821  while (1) {
822  printf("\r\nUser menu: Select one of the following options\r\n");
823 #ifdef INCLUDE_DIAG_SHELL
824  printf("9. Launch diagnostic shell\n");
825 #endif
826  printf("0. Quit the application\n");
827 
829  {
830  printf("Invalid option entered. Please re-enter.\n");
831  continue;
832  }
833  switch(choice){
834 
835 #ifdef INCLUDE_DIAG_SHELL
836  case 9:
837  {
838  opennsl_driver_shell();
839  break;
840  }
841 #endif
842 
843  case 0:
844  {
845  printf("Exiting the application.\n");
846  rv = opennsl_driver_exit();
847  return rv;
848  }
849  default:
850  break;
851  } /* End of switch */
852  } /* End of while */
853 
854  return OPENNSL_E_NONE;
855 }
856 /* __doxy_func_body_end__ */