OpenNSL API Guide and Reference Manual
Macros | Functions | Variables
example_routing.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sal/driver.h>
#include <opennsl/error.h>
#include <opennsl/vlan.h>
#include <opennsl/switch.h>
#include <opennsl/l2.h>
#include <opennsl/l3.h>
#include <examples/util.h>

Go to the source code of this file.

Macros

#define DEFAULT_SUBNET_IP   0x37000000 /* 55.0.0.0 */
 
#define DEFAULT_SUBNET_MASK   0xff000000 /* /8 network */
 
#define EGRESS_VLAN   20
 
#define HOST1   0x14010102 /* 20.1.1.2 */
 
#define INGRESS_VLAN   10
 
#define MAX_DIGITS_IN_CHOICE   5
 
#define MY_MAC   {0x00, 0x11, 0x22, 0x33, 0x99, 0x58}
 
#define NEXTHOP_MAC   {0x00, 0x00, 0x70, 0x5B, 0xC7, 0x34}
 

Functions

int example_add_host (int unit, unsigned int addr, int intf)
 Add host address to the routing table.
 
int example_create_l3_egress (int unit, unsigned int flags, int out_port, int vlan, int l3_eg_intf, opennsl_mac_t next_hop_mac_addr, int *intf)
 create l3 egress object object includes next hop information.
 
int example_create_l3_intf (int unit, int open_vlan, opennsl_gport_t port, opennsl_vlan_t vid, opennsl_mac_t mac_addr, int *l3_id)
 Creates Router interface.
 
int example_l2_addr_add (int unit, opennsl_mac_t mac, int port, int vid)
 To add a given MAC and VID to the L2 forwarding database.
 
int example_set_default_route (int unit, int subnet, int mask, int intf, opennsl_gport_t trap_port)
 Add default route to a subnet.
 
int example_vlan_port_add (int unit, int open_vlan, opennsl_vlan_t vlan, int port)
 To add a port to the VLAN.
 
int main (int argc, char *argv[])
 Main function for routing sample application.
 

Variables

char example_usage []
 
int verbose = 3
 

Macro Definition Documentation

#define DEFAULT_SUBNET_IP   0x37000000 /* 55.0.0.0 */

Definition at line 79 of file example_routing.c.

Referenced by main().

#define DEFAULT_SUBNET_MASK   0xff000000 /* /8 network */

Definition at line 80 of file example_routing.c.

Referenced by main().

#define EGRESS_VLAN   20

Definition at line 77 of file example_routing.c.

Referenced by main().

#define HOST1   0x14010102 /* 20.1.1.2 */

Definition at line 78 of file example_routing.c.

Referenced by main().

#define INGRESS_VLAN   10

Definition at line 76 of file example_routing.c.

Referenced by main().

#define MAX_DIGITS_IN_CHOICE   5

Definition at line 85 of file example_routing.c.

#define MY_MAC   {0x00, 0x11, 0x22, 0x33, 0x99, 0x58}

Definition at line 81 of file example_routing.c.

Referenced by main().

#define NEXTHOP_MAC   {0x00, 0x00, 0x70, 0x5B, 0xC7, 0x34}

Definition at line 83 of file example_routing.c.

Referenced by main().

Function Documentation

int example_add_host ( int  unit,
unsigned int  addr,
int  intf 
)

Add host address to the routing table.

Parameters
unit[IN] Unit number.
addr[IN] 32 bit IP address value
intf[IN] egress object created using example_create_l3_egress
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 281 of file example_routing.c.

References opennsl_l3_host_s::l3a_flags, opennsl_l3_host_s::l3a_intf, opennsl_l3_host_s::l3a_ip_addr, opennsl_l3_host_s::l3a_port_tgid, OPENNSL_E_NONE, opennsl_errmsg, opennsl_l3_host_add(), opennsl_l3_host_t_init(), print_ip_addr(), and verbose.

Referenced by main().

int example_create_l3_egress ( int  unit,
unsigned int  flags,
int  out_port,
int  vlan,
int  l3_eg_intf,
opennsl_mac_t  next_hop_mac_addr,
int *  intf 
)

create l3 egress object object includes next hop information.

  - packets sent to this interface will be send through out_port over
    given l3_eg_intf with next next_hop_mac_addr VLAN. SA is driven from
    l3_eg_intf as configure in example_create_l3_intf().
Parameters
unit[IN] Unit number
flags[IN] special controls set to zero
out_port[IN] egress port
vlan[IN] VLAN identifier
l3_eg_intf[IN] egress router interface will derive (VLAN, SA)
next_hop_mac_addr[IN] next hop mac address
*intf[OUT] returned interface ID
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 237 of file example_routing.c.

References opennsl_l3_egress_s::intf, opennsl_l3_egress_s::mac_addr, opennsl_l3_egress_s::module, OPENNSL_E_NONE, opennsl_l3_egress_create(), opennsl_l3_egress_t_init(), opennsl_l3_egress_s::port, verbose, and opennsl_l3_egress_s::vlan.

int example_create_l3_intf ( int  unit,
int  open_vlan,
opennsl_gport_t  port,
opennsl_vlan_t  vid,
opennsl_mac_t  mac_addr,
int *  l3_id 
)

Creates Router interface.

  - packets sent in from this interface identified by <port, vlan> with
    specificed MAC address is subject of routing
  - packets sent out through this interface will be encapsulated with
    <vlan, mac_addr>
Parameters
unit[IN] Unit number.
open_vlan[IN] if TRUE create given vlan, FALSE: vlan already opened juts use it
port[IN] Port number
vid[IN] router interface VLAN
mac_addr[IN] my MAC address
l3_id[OUT] returned handle of opened l3-interface
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 179 of file example_routing.c.

References example_vlan_port_add(), l2_print_mac(), opennsl_l3_intf_s::l3a_intf_id, opennsl_l3_intf_s::l3a_mac_addr, opennsl_l3_intf_s::l3a_vid, OPENNSL_E_EXISTS, OPENNSL_E_NONE, opennsl_errmsg, opennsl_l3_intf_create(), opennsl_l3_intf_t_init(), and verbose.

int example_l2_addr_add ( int  unit,
opennsl_mac_t  mac,
int  port,
int  vid 
)

To add a given MAC and VID to the L2 forwarding database.

Parameters
unit[IN] Unit number.
mac[IN] MAC address
port[IN] Port number
vid[IN] VLAN identifier
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 101 of file example_routing.c.

References opennsl_l2_addr_s::flags, OPENNSL_E_NONE, opennsl_l2_addr_add(), opennsl_l2_addr_t_init(), OPENNSL_L2_L3LOOKUP, OPENNSL_L2_STATIC, opennsl_l2_addr_s::port, and port().

int example_set_default_route ( int  unit,
int  subnet,
int  mask,
int  intf,
opennsl_gport_t  trap_port 
)

Add default route to a subnet.

Parameters
unit[IN] Unit number.
subnet[IN] 32 bit IP subnet
mask[IN] 32 bit value network mask
intf[IN] Egress object created using example_create_l3_egress
trap_port[IN] Trap destination. if trap_port is valid trap then it used for default destination. otherwise intf (egress-object) is used
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 320 of file example_routing.c.

References opennsl_l3_route_s::l3a_flags, opennsl_l3_route_s::l3a_intf, opennsl_l3_route_s::l3a_ip_mask, opennsl_l3_route_s::l3a_port_tgid, opennsl_l3_route_s::l3a_subnet, OPENNSL_E_NONE, opennsl_errmsg, opennsl_l3_route_add(), opennsl_l3_route_t_init(), print_ip_addr(), and verbose.

Referenced by main().

int example_vlan_port_add ( int  unit,
int  open_vlan,
opennsl_vlan_t  vlan,
int  port 
)

To add a port to the VLAN.

Parameters
unit[IN] Unit number.
open_vlan[IN] if TRUE create given vlan, FALSE: vlan already opened juts use it
vlan[IN] VLAN identifier
port[IN] Port number
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 131 of file example_routing.c.

References OPENNSL_E_EXISTS, OPENNSL_E_NONE, opennsl_errmsg, OPENNSL_PBMP_CLEAR, OPENNSL_PBMP_PORT_ADD, opennsl_vlan_create(), opennsl_vlan_port_add(), and verbose.

int main ( int  argc,
char *  argv[] 
)

Variable Documentation

char example_usage[]
Initial value:
=
"Syntax: example_routing \n\r"
" \n\r"
"Paramaters: \n\r"
" in_sysport - Ingress port number on which test packet is \n\r"
" received \n\r"
" out_sysport - Egress port number to which packet is routed. \n\r"
" \n\r"
"Example: The following command is used to demonstrate routing from \n\r"
" port 2 to port 6. \n\r"
" example_routing 2 6 \n\r"
" \n\r"
"Usage Guidelines: This program request the user to enter the \n\r"
" ingress and egress port numbers. Using the host route, it routes\n\r"
" the packets arrived on ingress port with VLAN = 10, \n\r"
" destination MAC = 00:11:22:33:99:58 to host 20.1.1.2 attached \n\r"
" to egress port that is a member of VLAN 20. Using the default \n\r"
" route, it also routes packets with VLAN = 10, destination \n\r"
" MAC = 00:11:22:33:99:58 destinated to subnet 55.0.0.0 to egress \n\r"
" port that is a member of VLAN 20. \n\r"
" The routed packet should have destination MAC same as \n\r"
" 00:00:70:5B:C7:34 with TTL decremented by 1. \n\r"

Definition at line 52 of file example_routing.c.

int verbose = 3

Definition at line 88 of file example_routing.c.