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

Go to the source code of this file.

Macros

#define DEFAULT_VLAN   1
 
#define MAC_ADDR_LEN   17
 
#define MAX_DIGITS_IN_CHOICE   5
 

Functions

int example_is_dnx_device (int unit)
 Returns true if the device belongs to DNX family of devices.
 
int example_is_qmx_device (int unit)
 Returns true if the device is Qumran-MX device.
 
int example_max_port_count_get (int unit, int *count)
 To get the number of front panel ports.
 
int example_port_default_config (int unit)
 Set default configuration (like STP state, speed/duplex) for all ports.
 
int example_read_user_choice (int *choice)
 Read numeric menu choice from user.
 
char * example_read_user_string (char *buf, size_t buflen)
 Read a string from user.
 
int example_switch_default_vlan_config (int unit)
 Add all ports to default vlan.
 
void l2_print_mac (char *str, opennsl_mac_t mac_address)
 To print the MAC address.
 
int opennsl_ctoi (const char *s, char **end)
 To convert a C-style constant to integer.
 
int opennsl_ip_parse (char *ip_str, unsigned int *ip_val)
 Parse IP string into a IP value.
 
int opennsl_mac_parse (char *buf, unsigned char *macp)
 Parse MAC address string.
 
void print_ip_addr (char *str, unsigned int host)
 To print IP address in dotted decimal format.
 

Macro Definition Documentation

#define DEFAULT_VLAN   1

Definition at line 38 of file util.c.

Referenced by example_switch_default_vlan_config().

#define MAC_ADDR_LEN   17

Referenced by opennsl_mac_parse().

#define MAX_DIGITS_IN_CHOICE   5

Definition at line 39 of file util.c.

Referenced by example_read_user_choice().

Function Documentation

int example_is_dnx_device ( int  unit)

Returns true if the device belongs to DNX family of devices.

Parameters
unit[IN] unit number
Returns
TRUE If the device belongs to DNX family
FALSE Otherwise

This API needs to be invoked after initializing the OpenNSL driver

Definition at line 51 of file util.c.

References opennsl_info_s::device, FALSE, opennsl_info_get(), and TRUE.

Referenced by example_port_default_config().

int example_is_qmx_device ( int  unit)

Returns true if the device is Qumran-MX device.

Parameters
unit[IN] unit number
Returns
TRUE If the device is Qumran-MX device
FALSE Otherwise

This API needs to be invoked after initializing the OpenNSL driver

Definition at line 75 of file util.c.

References opennsl_info_s::device, FALSE, opennsl_info_get(), and TRUE.

Referenced by example_l3_intf_rif_create(), and init_portmap().

int example_max_port_count_get ( int  unit,
int *  count 
)

To get the number of front panel ports.

Parameters
unit[IN] unit number
int[OUT] Number of front panel ports
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 495 of file util.c.

References opennsl_port_config_s::ge, OPENNSL_E_NONE, opennsl_errmsg, OPENNSL_PBMP_COUNT, opennsl_port_config_get(), and opennsl_port_config_s::xe.

int example_port_default_config ( int  unit)
int example_read_user_choice ( int *  choice)

Read numeric menu choice from user.

Parameters
choice[IN/OUT] choice
Returns
OPENNSL_E_xxx OpenNSL API return code

Definition at line 252 of file util.c.

References FALSE, MAX_DIGITS_IN_CHOICE, OPENNSL_E_FAIL, OPENNSL_E_NONE, and TRUE.

Referenced by example_knet_intf_create(), and main().

char* example_read_user_string ( char *  buf,
size_t  buflen 
)

Read a string from user.

Parameters
buf[IN/OUT] Buffer to store the string
buflen[IN] Buffer length
Returns
Valid string if there are no errors. Otherwise, it returns 0

Definition at line 225 of file util.c.

Referenced by example_knet_intf_create(), example_knet_intf_delete(), and main().

int example_switch_default_vlan_config ( int  unit)

Add all ports to default vlan.

Parameters
unit[IN] unit number
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 180 of file util.c.

References DEFAULT_VLAN, opennsl_port_config_s::e, OPENNSL_E_NONE, opennsl_errmsg, OPENNSL_FAILURE, OPENNSL_PBMP_ITER, opennsl_port_config_get(), opennsl_port_untagged_vlan_set(), opennsl_vlan_port_add(), and port().

Referenced by main().

void l2_print_mac ( char *  str,
opennsl_mac_t  mac_address 
)

To print the MAC address.

Returns
void

Definition at line 358 of file util.c.

Referenced by example_create_l3_intf(), example_fp_redirect(), and example_l2_addr_add().

int opennsl_ctoi ( const char *  s,
char **  end 
)

To convert a C-style constant to integer.

Parameters
str[OUT] Buffer to store the IP address
host[IN] MAC address in integer format
Returns
void

Definition at line 446 of file util.c.

int opennsl_ip_parse ( char *  ip_str,
unsigned int *  ip_val 
)

Parse IP string into a IP value.

Parameters
ip_str[IN] IP address in decimal dotted format
ip_val[OUT] IP address in integer format
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 382 of file util.c.

References NULL.

int opennsl_mac_parse ( char *  buf,
unsigned char *  macp 
)

Parse MAC address string.

Parameters
buf[IN] MAC address in string format
macp[OUT] MAC address in integer format
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 293 of file util.c.

References MAC_ADDR_LEN, NULL, OPENNSL_E_FAIL, and OPENNSL_E_NONE.

Referenced by main().

void print_ip_addr ( char *  str,
unsigned int  host 
)

To print IP address in dotted decimal format.

Parameters
str[OUT] Buffer to store the IP address
host[IN] MAC address in integer format
Returns
void

Definition at line 425 of file util.c.

Referenced by example_add_host(), example_fp_ip_block(), example_ip_tunnel_term_print_key(), example_set_default_route(), example_vxlan_egress_tunnel_create(), print_host(), and print_route().