OpenNSL API Guide and Reference Manual
Data Structures | Macros | Functions | Variables
example_stp.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sal/driver.h>
#include <opennsl/types.h>
#include <opennsl/port.h>
#include <opennsl/vlan.h>
#include <opennsl/error.h>
#include <opennsl/stg.h>
#include <examples/util.h>

Go to the source code of this file.

Data Structures

struct  stg_info_s
 

Macros

#define CALL_IF_ERROR_RETURN(op)
 
#define DEFAULT_UNIT   0
 
#define MAX_DIGITS_IN_CHOICE   5
 
#define VLANID   100
 

Functions

int example_stg_create (int unit, stg_info_s *info)
 To add a given set of ports and VLAN to spanning tree instance.
 
int example_stg_init (int unit, stg_info_s *info, int port1, int port2)
 Initialization routine to create spanning tree instance and initialize the structures.
 
int main (int argc, char *argv[])
 Main function for Spanning Tree Protocol (STP) sample application.
 
int revert_stg (int unit, stg_info_s *info)
 To destroy the spanning tree instance and VLAN's associate with it.
 

Variables

char example_usage []
 
char * stp_state_str []
 
int verbose = 3
 

Macro Definition Documentation

#define CALL_IF_ERROR_RETURN (   op)
Value:
do { \
int __rv__; \
if ((__rv__ = (op)) < 0) { \
printf("%s:%s: line %d rv: %d failed: %s\n", \
__FILE__, __FUNCTION__, __LINE__, __rv__, \
opennsl_errmsg(__rv__)); \
} \
} while(0)

Definition at line 90 of file example_stp.c.

Referenced by main().

#define DEFAULT_UNIT   0

Definition at line 63 of file example_stp.c.

Referenced by example_stg_create(), and main().

#define MAX_DIGITS_IN_CHOICE   5

Definition at line 65 of file example_stp.c.

#define VLANID   100

Definition at line 64 of file example_stp.c.

Referenced by example_stg_init().

Function Documentation

int example_stg_create ( int  unit,
stg_info_s info 
)

To add a given set of ports and VLAN to spanning tree instance.

Parameters
unit[IN] Unit number.
*info[IN] Pointer to a location where STG information is stored
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 295 of file example_stp.c.

References DEFAULT_UNIT, OPENNSL_E_NONE, opennsl_errmsg, OPENNSL_PBMP_CLEAR, OPENNSL_PBMP_PORT_ADD, opennsl_stg_stp_set(), opennsl_stg_vlan_add(), opennsl_vlan_create(), opennsl_vlan_port_add(), stg_info_s::port_1, stg_info_s::port_2, stg_info_s::stg, stg_info_s::stp_state_1, stg_info_s::stp_state_2, stp_state_str, verbose, and stg_info_s::vlan_1.

Referenced by main().

int example_stg_init ( int  unit,
stg_info_s info,
int  port1,
int  port2 
)

Initialization routine to create spanning tree instance and initialize the structures.

Parameters
unit[IN] Unit number.
*info[IN] Pointer to a location where STG information is stored
port1[IN] First port number.
port2[IN] Second port number.
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 273 of file example_stp.c.

References opennsl_stg_create(), OPENNSL_STG_STP_FORWARD, stg_info_s::port_1, stg_info_s::port_2, stg_info_s::stg, stg_info_s::stp_state_1, stg_info_s::stp_state_2, stg_info_s::vlan_1, and VLANID.

Referenced by main().

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

Main function for Spanning Tree Protocol (STP) sample application.

Parameters
argc,argvcommands line arguments
Returns
OPENNSL_E_XXX OpenNSL API return code *****************************************************i

Definition at line 113 of file example_stp.c.

References CALL_IF_ERROR_RETURN, DEFAULT_UNIT, example_port_default_config(), example_read_user_choice(), example_stg_create(), example_stg_init(), example_usage, NULL, opennsl_driver_exit(), opennsl_driver_init(), OPENNSL_E_NONE, OPENNSL_E_PARAM, opennsl_errmsg, OPENNSL_STG_STP_BLOCK, OPENNSL_STG_STP_FORWARD, opennsl_stg_stp_get(), opennsl_stg_stp_set(), port(), stg_info_s::port_1, stg_info_s::port_2, stg_info_s::stg, stp_state_str, and verbose.

int revert_stg ( int  unit,
stg_info_s info 
)

To destroy the spanning tree instance and VLAN's associate with it.

Parameters
unit[IN] Unit number.
*info[IN] Pointer to a location where STG information is stored
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 372 of file example_stp.c.

References OPENNSL_E_NONE, opennsl_stg_destroy(), opennsl_vlan_destroy(), stg_info_s::stg, and stg_info_s::vlan_1.

Variable Documentation

char example_usage[]
Initial value:
=
"Syntax: example_stp \n\r"
" \n\r"
"Paramaters: \n\r"
" port1 - First port number. \n\r"
" port2 - Second port number. \n\r"
" \n\r"
"Example: The following command is used to demonstrate on how to remove \n\r"
" loop by modifying the spanning tree state of a port. \n\r"
" example_stp 5 6 \n\r"
" \n\r"
"Usage Guidelines: This program takes two ports numbers as input and \n\r"
" place them in VLAN 100 and by default put them in forwarding \n\r"
" state. This results in a loop if both the ports are connected \n\r"
" to a partner switch. Here the program provides the menu with \n\r"
" the following options. \n\r"
" \n\r"
" 1) Configure the STP state of a port. \n\r"
" 2) Display the STP state of ports. \n\r"
" 3) Quit the application. \n\r"
" \n\r"

Definition at line 40 of file example_stp.c.

char* stp_state_str[]
Initial value:
=
{
"Disable",
"Block",
"Listen",
"Learn",
"Forward"
}

Definition at line 77 of file example_stp.c.

Referenced by example_stg_create(), and main().

int verbose = 3

Definition at line 88 of file example_stp.c.