Manual Revision: 1.00
Revision Date: August 28, 2013
Part Number: 50-1G026-1000
Advance Technologies; Automate the World.
Page 2
Revision History
Rev Date Description
1.00 28/8/2013 Initial release
Switch Manager API Programming Guide
2
Page 3
Switch Manager API Programming Guide
Preface
Copyright 2013 ADLINK Technology, Inc.
This document contains proprietary information protected by copyright. All rights are reserved. No
part of this manual may be reproduced by any mechanical, electronic, or other means in any form
without prior written permission of the manufacturer.
Disclaimer
The information in this document is subject to change without prior notice in order to improve
reliability , design, and fun ction and does not represent a commitm ent on the p art of the manufacturer.
In no event will the manufacturer be liable for direct, indirect, special, incidental, or consequential
damages arising out of the use or inability to use the product or documentation, even if advised of
the possibility of such damages.
Environmental Responsibility
ADLINK is committed to fulfill its social responsibility to global environmental preservation through
compliance with the European Union's Restriction of Hazardous Substances (RoHS) directive and
Waste Electrical and Electronic Equipment (WEEE) directive. Environmental protection is a top
priority for ADLINK. We have enforced measures to ensure that our products, manufacturing
processes, components, and raw materials have as little impact on the environment as possible.
When products are at their end of life, our customers are encouraged to dispose of them in
accordance with the product disposal and/or recovery programs prescribed by their nation or
company.
Trademarks
Product names mentioned herein are used for identification purposes only and may be trademarks
and/or registered trademarks of their respective companies.
Table 6- 1, Qualifier Type Description............................................................................. 34
Table 6- 2, Action Type Description................................................................................. 34
Table 6- 3, Data Descriptions For Different Qualifier Types............................................ 35
Table 6- 4, Data Descriptions for Different Action Types.................................................36
10
Page 11
Switch Manager API Programming Guide
Introduction
This guide describes the how to program ADLINK Switch Management APIs on ADLINK's
switch blades, such as the aTCA-3420, aTCA-N700, and aTCA-3710. Firstly, we will introduce
the overall software architecture for programming. Secondly, we define the released
deliverables, including header file, static library, binary files, example project and readme files.
Finally, detailed API definitions and references will be provided to allow customers to easily
program their own APIs.
Architecture Overview
All the APIs listed in this document are programmed using the following hardware architecture,
shown in Figure 1. In this figure, the client is running on a standalone server. However, it also
can run on the LMP on the switch blade.
Switch Manager
API Library
runs on client
Controller
Figure 1,Hardware architecture for programming
The ADLINK Switch Manager implements the network connections between server and client
so that customers do not have to worry about the connections between them. Provided are the
client API libraries, header files and relevant documentation for easy programming.
Ethernet
Switch Manager
core service runs on
blade server with
switch chip
Blade Server
11
Page 12
Switch Manager API Programming Guide
Deliverables
The ADLINK Switch Manager Library package (adSwitchLib-x.x.x.tar.gz) provides the following
software components
Include: Header files of the ADLINK Switch Manager library
Lib: Static library including the API functions listed in this document
Bin: Binary files for controlling the switch system
Example:
ReadMe: The release notes for different library revisions
Application demo to show usage of the APIs provided
Section 1: Base
This section describes the macro, enum, struct and function for fundamentals. They are defined
in the header file “adlink_api_base.h”.
Enum Type
status_t
typedef enum status
{
ADLINK_E_NONE = 0, /*no error*/
ADLINK_E_PARA = -1, /*parameter error*/
ADLINK_E_RESOURCE = -2, /*no available resource*/
ADLINK_E_EXIST = -3, /*item already exists*/
ADLINK_E_FIND = -4, /*item not found*/
ADLINK_E_SOCKET = -5, /*socket error*/
ADLINK_E_MALLOC = -6, /* mem allocation failed*/
ADLINK_E_OPEN = -7, /* open/fopen failed*/
ADLINK_E_OTHER = -8, /* Error other than above*/
//...
ADLINK_E_SERVER_BASE = -128,/*base error code for server returned*/
}status_t;
This enum describes the return codes of the APIs. They are defined in “adlink_api_base.h”.
Table 1-1 shows the meaning of each error code.
12
Page 13
Switch Manager API Programming Guide
Table 1- 1, Return Code Description
Return Code Description
ADLINK_E_NONE API run successfully
ADLINK_E_PARA Parameter related error
ADLINK_E_RESOURCE Table item overflow
ADLINK_E_EXIST Table item already existing
ADLINK_E_FIND Table item non-existentent
ADLINK_E_SOCKET Error occurs when connecting to BCM server
ADLINK_E_MALLOC Error occurs when memory allocation
ADLINK_E_OPEN Error occurs when open/fopen a handle
ADLINK_E_OTHER Other error
ADLINK_E_SERVER_BASE For a meaningful error code form server, we return it with
this value added. So, if the returned code is less than this
value, we can subtract this value and get the real return
value from server. This is useful for debugging.
Functions
adlink_switch_chip_init ()
PROTOTYPE
int adlink_switch_chip_init(UINT32 server_ip)
DESCRIPTION
This function is used to init the switch chip.
PARAMETERS
server_ip [IN] IP address of the server
RETURN
See the description of status_t above.
adlink_config_write ()
PROTOTYPE
int adlink_config_write()
DESCRIPTION
This function is used to write the current configuration into file. After the function is called
successfully, the configuration will still be in effect after the system reboots.
13
Page 14
Switch Manager API Programming Guide
PARAMETERS
None
RETURN
See the description of status_t above.
Section 2: VLAN
This section describes the macro, enum, struct and function for VLAN. They are defined in the
header file “adlink_api_vlan.h”.
Macro Definitions
MAX_VLAN_MAC_CNT
Maximum entry count of MAC based VLAN.
Enum Type
adlink_vlan_tag_mode_t
typedef enum adlink_vlan_tag_mode_e{
VLAN_MODE_UNTAGGED = 0,
VLAN_MODE_TAGGED = 1,
} adlink_vlan_tag_mode_t;
Define the codes of port mode in VLAN.
UINT8 created; /*whether it is created on hardware*/
UINT8 rsv1[2]; /*for align purpose*/
UINT32 pbmp; /*port bitmap in this vlan*/
UINT32 untag_pbmp; /*port bitmap of untagged ports*/
UINT32 pvid_pbmp; /*port bitmap take VID as default vlan*/
char name[MAX_VLAN_NAME_SIZE]; /*vlan name. 31 characters at maxmium*/
}adlink_vlan_info_t;
Define the entry format of port based VLAN table.
adlink_vlan_mac_t
typedef struct adlink_vlan_mac_s {
UINT8 valid; /*in using or not. VALID/INVALID*/
UINT8 cos; /*priority value. 0-7*/
UINT8 mac[MAC_SIZE]; /*MAC address*/
UINT16 vid; /*VLAN id. 1-4094*/
UINT8 rsv[2]; /*reserved*/
}adlink_vlan_mac_t;
Define the entry format of MAC based VLAN table.
These two functions are used to add port into or remove port from a VLAN.
PARAMETERS
vlan [IN] The VLAN ID in which port member is configured.
port [IN] Port ID to be added/removed.
mode [IN] Port is tagged or untagged in the VLAN. Use ‘VLAN_MODE_TAGGED’ or
‘VLAN_MODE_UNTAGGED’
RETURN
See the description of status_t in Section 1.
These functions are used to configure MAC base VLAN. MAC address can be associated with a
VLAN id.
PARAMETERS
vlan [IN] The VLAN ID which will be assigned to a specified MAC address;
mac [IN] A pointer points to specified MAC address;
cos [IN] Default COS value which will be filled in VLAN tag;
RETURN
See the description of status_t in Section 1.
18
Page 19
Switch Manager API Programming Guide
Section 3: Port
This section describes the macro, enum, struct and function for port. They are defined in the
head file “adlink_api_port.h”.
Macro Definitions
MIN_FABRIC_PORT_ID
MAX_FABRIC_PORT_ID
MIN_BASE_PORT_ID
MAX_BASE_PORT_ID
Define the port index value range of fabric and base switch chips.
FABRIC_PORT_NUM
BASE_PORT_NUM
Total port count of fabric and base switch chip.
SWITCH_PORT_CPU
FRONT_PANEL_XE_START
FRONT_PANEL_XE_END
Define the index value of some specific ports.
19
Page 20
TAPNAMSIZ
Define the maximum length of a NIC device name.
Enum Type
port_duplex_t
typedef enum port_duplex_e{
PORT_DUPLEX_FULL = 0,
PORT_DUPLEX_HALF = 1,
} port_duplex_t;
Define the codes of port duplex mode.
Switch Manager API Programming Guide
port_speed_t
typedef enum port_speed_e{
PORT_SPEED_10M = 10,
PORT_SPEED_100M = 100,
PORT_SPEED_1G = 1000,
PORT_SPEED_10G = 10000,
} port_speed_t;
Define the codes of port speed mode.
port_link_status_t
typedef enum port_link_status_e{ /*Heritage*/
PORT_LINK_STATUS_DOWN = 0,
PORT_LINK_STATUS_UP = 1,
PORT_LINK_STATUS_FAILED = 2,
PORT_LINK_STATUS_REMOTE_FAULT = 3,
} port_link_status_t;
Define the codes of port physical link status.
20
Page 21
port_stp_state_t
typedef enum port_stp_state_e { /*Heritage */
PORT_STP_DISABLE = 0, /* Disabled. */
PORT_STP_BLOCK = 1, /* BPDUs/no learns. */
PORT_STP_LISTEN = 2, /* BPDUs/no learns. */
PORT_STP_LEARN = 3, /* BPDUs/learns. */
PORT_STP_FORWARD = 4, /* Normal operation. */
PORT_STP_COUNT = 5
} port_stp_state_t;
Define the codes of port status for Spanning Tree Protocol.
port_vlan_filter_mode_mask_t
Switch Manager API Programming Guide
typedef enum port_vlan_filter_mode_mask_e { /*Heritage*/
PORT_VLAN_FILTER_INGRESS = 0x00000001,
PORT_VLAN_FILTER_EGRESS = 0x00000002,
} port_vlan_filter_mode_mask_t;
Define the codes of VLAN filter mode in port attribute.
port_rate_limit_mask_t
typedef enum port_rate_limit_mask_e { /*Heritage*/
PORT_RATE_DLF = 0x01,
PORT_RATE_MCAST = 0x02,
PORT_RATE_BCAST = 0x04,
PORT_RATE_UCAST = 0x08,
} port_rate_limit_mask_t;
Define the codes of rate limit type mask in port attribute.
nic_config_mask_t
typedef enum nic_config_mask
{
NIC_CONFIG_IP_MASK = 1, /*Set this bit to flag IP&MASK operation*/
NIC_CONFIG_STATUS = 2, /*Set this bit to flag NIC running status operation*/
}nic_config_mask_t;
Define the codes of NIC operation.
21
Page 22
Data Structure
adlink_port_info_t
typedef struct adlink_port_info_s
{
int enable;
int linkstatus;
int autoneg;
int speed;
int duplex;
UINT32 vlanfilter;
int untagged_priority;
UINT16 untagged_vlan;
int stp_state;
int pfm; /*port filter mode for multicast*/
int loopback;
int pause_tx;
int pause_rx;
int encap_mode;
int mcast_limit;
int mcast_limit_enable;
int bcast_limit;
int bcast_limit_enable;
int dlfbc_limit;
int dlfbc_limit_enable;
int frame_max;
UINT32 fault; /*link fault reason*/
}adlink_port_info_t;
Define the entry format of the port attribute table.
UINT32 rx_pkt_rate;
UINT32 tx_byte_num;
UINT32 tx_byte_rate;
UINT32 tx_pkt_num;
UINT32 tx_pkt_rate;
}adlink_portstat_t;
Define the entry format of the port statistic table.
adlink_set_port_status_cmd_t
typedef struct adlink_set_port_status_cmd {
UINT32 port; /*port ID*/
UINT32 flag; /*PORT_ATTR_xxx in port_attribute_t*/
int status; /*ENABLE/DISABLE*/
int autoneg_mode; /*ENABLE/DISABLE*/
int duplex_mode; /*PORT_DUPLEX_xxx in port_duplex_t*/
int speed_mode; /*PORT_SPEED_xxx in port_speed_t*/
int pvid; /*default 802.1Q vid for untagged packets*/
int cos; /*default 802.1Q cos for untagged packets*/
int mtu; /*max data transmission unit*/
} adlink_set_port_status_cmd_t;
Define the format of parameters used to set port attributes.
adl_nic_config_set_cmd_t
typedef struct adl_nic_config_set_cmd {
char if_name[TAPNAMSIZ];
UINT32 config_mask; //nic_config_mask_t
UINT32 ip;
UINT32 netmask;
UINT32 status; //0 down, 1 up
}adl_nic_config_set_cmd_t;
Define the format of parameters used to set NIC configuration.
adl_nic_config_info_t
typedef struct adl_nic_config_info
{
UINT32 ip;
23
Page 24
UINT32 mask;
UINT32 status;
}adl_nic_config_info_t;
Define the format of retrieved NIC info.
adl_nic_config_get_cmd_t
typedef struct adl_nic_config_get_cmd {
char if_name[TAPNAMSIZ];
}adl_nic_config_get_cmd_t;
Define the format of the get NIC info command parameter.
This function is used to set various port attributes, including administrative status,
auto-negotiation mode, duplex mode, speed, default vid, default cos and MTU.
24
Page 25
Switch Manager API Programming Guide
PARAMETERS
cmd [IN] Port attributes to be set;
RETURN
See the description of status_t in Section 1.
These functions are used to add and delete MAC filter entries. MAC filters will filter ingress
frames with specific source/destination MAC addresses on specific ports.
PARAMETERS
entry [IN] The MAC entry to be filtered;
RETURN
See the description of status_t in Section 1.
The function ‘get’ is used to get statistics of a port, including count and rate in both byte unit and
packet unit. The function ‘clear’ is used to reset all counters.
PARAMETERS
port [IN] The port id;
stat [OUT] Statistics data will be filled in this structure;
25
Page 26
Switch Manager API Programming Guide
RETURN
See the description of status_t in Section 1.
These functions are used to pipe a specific port to another one. “pipe” will directly deliver
ingress traffic on a specific port to another one.
26
Page 27
Switch Manager API Programming Guide
PARAMETERS
src_port [IN] Ingress port;
dst_port [IN|OUT] Destination port traffic will be delivered to;
RETURN
See the description of status_t in Section 1.
Section 4: Trunk
This section describes the macro, enum, struct and function for trunk. They are defined in the
header file “adlink_api_trunk.h”.
Macro Definitions
MIN_TRUNK_ID
MAX_TRUNK_ID
MAX_TRUNK_MEMBER
Trunk group index range and member count limit of a group.
Enum Type
adlink_trunk_psc_t
typedef enum adlink_trunk_psc_e
{
PSC_ZERO = 0,
PSC_SA = 1,
PSC_DA = 2,
PSC_SA_DA = 3,
PSC_SIP = 4,
PSC_DIP = 5,
PSC_SIP_DIP = 6,
}adlink_trunk_psc_t;
Define the codes of trunk port selection criteria. Packets will be dispatched to different ports
based on the criteria.
These functions are used to control trunk groups to be monitored or not. For groups in monitor,
member ports with a link failure will be removed from group.
PARAMETERS
group_index [IN] Trunk group id; Start from ‘1’;
tm [OUT] Trunk group status in monitor;
RETURN
See the description of status_t in Section 1.
30
Page 31
Switch Manager API Programming Guide
Section 5: Layer-2
This section describes the macro, enum, struct and function for Layer-2. They are defined in the
header file “adlink_api_l2.h”.
Macro Definitions
MAC_SIZE
MAC addresses data size in bytes.
ADLINK_L2_xxx
L2 entry flag masks. Flags are special attributes of the MAC entry. For details, please refer to
the definitions in “adlink_api_l2. h”
Enum Type
None
Data Structure
adlink_mac_entry_t
typedef struct adlink_mac_entry_s
{
UINT32 port; /*port ID associated with the entry, start from 1*/
UINT16 vid; /*vlan id*/
UINT8 rsv0[2]; /*reserved*/
UINT32 flag; /*entry flag, ADLINK_L2_XXX*/
UINT8 mac[MAC_SIZE]; /*mac address*/
UINT8 rsv1[2]; /*reserved*/
} adlink_mac_entry_t;
Define the entry format of the MAC table.
Qualifier Type Description
INPORTS Filter for the port ID a packet comes from
SRCIP Filter for source IP address of a packet
DSTIP Filter for destination IP address of a packet
IPPROTOCOL Filter for IP protocol (such as 0x06 for TCP) of a packet
L4SRCPORT Filter for L4 source port of a packet
L4DSTPORT Filter for L4 destination port of a packet
SRCMAC Filter for source MAC address of a packet
DSTMAC Filter for destination MAC address of a packet
SRCTRUNK Filter for the trunk ID a packet comes from
ETHERTYPE Filter for Ethernet type (such as 0x0806 for ARP) of a packet
INNERVLAN Filter for the inner VLAN ID of a packet
OUTERVLAN Filter for the outer VLAN ID of a packet
adlink_action_type_t
typedef enum adlink_action_type
{
REDIRECTPORT = 1, //port bit mask, data32, only one port is permitted
REDIRECTTRUNK, //trunk id, data16
DROP, //no param
} adlink_action_type_t;
Table 6- 2, Action Type Description
Action Type Description
REDIRECTPORT Redirect the packet to a port (cpu0, xe0, xe1, xe2…).
REDIRECTTRUNK Redirect the packet to a trunk
DROP Drop the packet
Data Structure
adlink_acl_data_t
typedef struct adlink_acl_data
{
UINT8 data128[16]; //data128 use, such as ipv6 addr
UINT64 data64; //data64 use
UINT8 data48[6]; //data48 use, such as mac addr
UINT32 data32; //data32 use, such as ip addr
34
Page 35
Switch Manager API Programming Guide
UINT16 data16; //data16 use, such as l4port
UINT8 data8; //data8 use, such as ip protocol
} adlink_acl_data_t;
For different qualifiers and actions, there are different data lengths. For example, an IP address
is 32 bits long, a MAC address is 48 bits long, and an L4 port ID is 16 bits long. This data
structure was defined in order to accommodate these different situations. Careful attention must
be paid to refer to the appropriate member according to the actual situation. The appropriate
members for existing qualifiers and actions are listed in the Tables 6-3 and 6-4.
adlink_acl_qualifier_info_t
typedef struct adlink_acl_qualifier_info
{
adlink_qualifier_type_t type;//qualifier type
adlink_acl_data_t data;//union, use the correct member for different types
adlink_acl_data_t mask;//union, use the correct member for different types
} adlink_acl_qualifier_info_t;
Table 6- 3, Data Descriptions For Different Qualifier Types
Qualifier Type Data mask
INPORTS data32 (port bit maps,cpu0 is
typedef struct adlink_acl_action_info
{
adlink_action_type_t type;
adlink_acl_data_t param0;//union,use the correct member for different types
adlink_acl_data_t param1;//union,use the correct member for different types
} adlink_acl_action_info_t;
35
Page 36
Switch Manager API Programming Guide
Table 6- 4, Data Descriptions for Different Action Types
Action Type Param0 Param1
REDIRECTPORT data32 (port bit maps, only one
port is allowed, cpu0 is bit 0,
xe0 is bit 1,…)
REDIRECTTRUNK Data16 None
DROP None None
None
adlink_acl_rule_info_t
typedef struct adlink_acl_rule_info
{
UINT16 priority; // the priority of the ACL rule
UINT16 qualifier_num; //the number of qualifier of the ACL rule
adlink_acl_qualifier_info_t qualifier[MAX_QUALIFIER_NUM];
//record the qualifier info
adlink_acl_action_info_t action;// record the action info
} adlink_acl_rule_info_t;
This function is used to get the detail information of an ACL rule.
PARAMETERS
rule_id [IN] The ID of the rule that want to get information.
rule_info [OUT] The pointer for saving the rule information.
RETURN
See the description of status_t in Section 1.
37
Page 38
Switch Manager API Programming Guide
Section 7: Static Route
This section describes the macro, enum, struct and function for route. They are defined in the
header file “adlink_api_route.h”.
Macro Definitions
MAX_ROUTE_ENTRY_ONE_TIME_GET
This macro is used for getting route entries from the server. Due to packet size limitations
allowed in the network (MTU), it isn't possible to get all the entries at once. This macro defines
the maximum number of entries retrievable at one time.
Enum Type
None
Data Structure
adlink_route_info_t
typedef struct adlink_route_info
{
UINT32 ip_addr; //ip address
UINT32 ip_mask; //ip mask
UINT32 gateway_ip; // next hop ip address
UINT16 out_port; //exit port ID
UINT16 resv; // alignment
} adlink_route_info_t;
ip_addr [IN] ip address that want to delete.
ip_mask [IN] ip mask that want to delete.
RETURN
See the description of status_t in Section 1.
adlink_route_table_clear ()
PROTOTYPE
status_t adlink_route_table_clear ();
DESCRIPTION
This function is used to clear all routing table entries that have been added by users.
39
Page 40
Switch Manager API Programming Guide
PARAMETERS
None
RETURN
See the description of status_t in Section 1.
adlink_route_table_dump ()
PROTOTYPE
status_t adlink_route_table_dump (UINT32 ip_last, UINT32 mask_last, int *count,
adlink_route_info_t *route_info);
DESCRIPTION
This function is used to get all route entry info that has been added.
PARAMETERS
ip_last /mask_last [IN] These two parameters pass the last route entry that was retrieved. The
function call will start retrieving route entry info after these values. Set both of
these parameters to 0 the first time this function is called.
Count [OUT] This parameter passes the number of route entry values retreived. If
"Count" is less than MAX_ROUTE_ENTRY_ONE_TIME_GET, then all the
route entries have been retrieved. Otherwise, we need to call this function
again to continue retrieving route entry info.
route_info [OUT] This parameter is the pointer for saving the route entry info. It must have
enough space to save as many as MAX_ROUTE_ENTRY_ONE_TIME_GET
route entries.
RETURN
See the description of status_t in Section 1.
40
Page 41
Switch Manager API Programming Guide
Getting Service
ADLINK Technology, Inc.
Address: 9F, No.166 Jian Yi Road, Zhonghe District
New Taipei City 235, Taiwan
Tel: +886-2-8226-5877
Fax: +886-2-8226-5717
Email: service@adlinktech.com
Ampro ADLINK Technology, Inc.
Address: 5215 Hellyer Avenue, #110, San Jose, CA 95138, USA
Tel: +1-408-360-0200
Toll Free: +1-800-966-5200 (USA only)
Fax: +1-408-360-0222
Email: info@adlinktech.com
ADLINK Technology (China) Co., Ltd.
Address: 300 Fang Chun Rd., Zhangjiang Hi-Tech Park,
Pudong New Area, Shanghai, 201203 China
Tel: +86-21-5132-8988
Fax: +86-21-5132-3588
Email: market@adlinktech.com
ADLINK Technology Beijing
Address: Rm. 801, Power Creative E, No. 1, B/D
Shang Di East Rd., Beijing, 100085 China
Tel: +86-10-5885-8666
Fax: +86-10-5885-8625
Email: market@adlinktech.com
ADLINK Technology Shenzhen
Address: 2F, C Block, Bldg. A1, Cyber-Tech Zone, Gao Xin Ave. Sec. 7,
High-Tech Industrial Park S., Shenzhen, 518054 China
Tel: +86-755-2643-4858
Fax: +86-755-2664-6353
Email: market@adlinktech.com