OpenNSL API Guide and Reference Manual
Macros | Functions | Variables
example_field_redirect.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/port.h>
#include <opennsl/field.h>
#include <examples/util.h>

Go to the source code of this file.

Macros

#define CALL_IF_ERROR_RETURN(op)
 
#define DEFAULT_STAT_ID   2
 
#define DEFAULT_UNIT   0
 
#define MAC_DA   {0x00, 0x00, 0x01, 0x00, 0x02, 0x00}
 
#define MAC_MASK   {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
 
#define NEWCOS_VAL   3
 

Functions

int example_fp_redirect (int unit, int dport)
 Install filters to redirect traffic to a destination port.
 
int main (int argc, char *argv[])
 Main function for redirecting traffic based on destination MAC address.
 

Variables

opennsl_field_entry_t eid = 0
 
char example_usage []
 
opennsl_field_group_t grp = 1
 
int stat_id = DEFAULT_STAT_ID
 
opennsl_field_stat_t stats = opennslFieldStatPackets
 

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 67 of file example_field_redirect.c.

Referenced by example_fp_redirect(), and main().

#define DEFAULT_STAT_ID   2

Definition at line 59 of file example_field_redirect.c.

Referenced by example_fp_redirect().

#define DEFAULT_UNIT   0

Definition at line 53 of file example_field_redirect.c.

Referenced by main().

#define MAC_DA   {0x00, 0x00, 0x01, 0x00, 0x02, 0x00}

Definition at line 55 of file example_field_redirect.c.

Referenced by example_fp_redirect().

#define MAC_MASK   {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

Definition at line 57 of file example_field_redirect.c.

Referenced by example_fp_redirect().

#define NEWCOS_VAL   3

Definition at line 54 of file example_field_redirect.c.

Referenced by example_fp_redirect().

Function Documentation

int example_fp_redirect ( int  unit,
int  dport 
)

Install filters to redirect traffic to a destination port.

Parameters
unit[IN] Unit number
port[IN] Port to which the traffic needs to redirected
Returns
OPENNSL_E_xxx OpenNSL API return code

Create qualification set

Create action set

initialize a group with the create qset

add entries to qualify the packets with configured MAC address and then count it, redirect it to a destination port

add an entry to the group

add actions associated with this entry

Definition at line 88 of file example_field_redirect.c.

References CALL_IF_ERROR_RETURN, DEFAULT_STAT_ID, eid, grp, l2_print_mac(), MAC_DA, MAC_MASK, NEWCOS_VAL, OPENNSL_E_NONE, opennsl_errmsg, opennsl_field_action_add(), OPENNSL_FIELD_ASET_ADD, OPENNSL_FIELD_ASET_INIT, opennsl_field_entry_create_id(), opennsl_field_group_action_set(), opennsl_field_group_create_id(), opennsl_field_group_destroy(), opennsl_field_group_install(), OPENNSL_FIELD_GROUP_PRIO_ANY, OPENNSL_FIELD_QSET_ADD, OPENNSL_FIELD_QSET_INIT, opennsl_field_qualify_DstMac(), opennsl_field_stat_create_id(), OPENNSL_FIELD_STAT_ID_COUNTER_GET, OPENNSL_FIELD_STAT_ID_PROCESSOR_GET, OPENNSL_FIELD_STAT_ID_SET, OPENNSL_GPORT_LOCAL_SET, opennslFieldActionPrioIntNew, opennslFieldActionRedirectPort, opennslFieldActionStat, opennslFieldQualifyDstMac, stat_id, and stats.

Referenced by main().

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

Variable Documentation

Definition at line 62 of file example_field_redirect.c.

Referenced by example_fp_redirect(), and main().

char example_usage[]
Initial value:
=
"Syntax: example_field_redirect \n\r"
" \n\r"
"Paramaters: None. \n\r"
" \n\r"
"Example: The following command is used to redirect traffic with \n\r"
" destination MAC = MAC_DA to a specified destination port. \n\r"
" It also provides an option to display the number of packets \n\r"
" redirected to destination port. \n\r"
" \n\r"
" example_field_redirect \n\r"
" \n\r"
"Usage Guidelines: None. \n\r"

Definition at line 39 of file example_field_redirect.c.

Definition at line 61 of file example_field_redirect.c.

Referenced by example_create_policy(), example_fp_redirect(), and main().

int stat_id = DEFAULT_STAT_ID

Definition at line 63 of file example_field_redirect.c.

Referenced by example_create_policy(), example_fp_redirect(), and main().