Network setup library
Overview
Definition of test API to define and set up test network. More…
// typedefs typedef enum tapi_net_iface_type tapi_net_iface_type; typedef struct tapi_net_vlan tapi_net_vlan; typedef struct tapi_net_qinq tapi_net_qinq; typedef struct tapi_net_iface tapi_net_iface; typedef struct tapi_net_endpoint tapi_net_endpoint; typedef enum tapi_net_nat_rule_type tapi_net_nat_rule_type; typedef enum tapi_net_nat_rule_mode tapi_net_nat_rule_mode; typedef struct tapi_net_nat_rule tapi_net_nat_rule; typedef struct tapi_net_ta tapi_net_ta; typedef struct tapi_net_link tapi_net_link; typedef struct tapi_net_ctx tapi_net_ctx; // enums enum tapi_net_iface_type; enum tapi_net_nat_rule_mode; enum tapi_net_nat_rule_type; // structs struct tapi_net_ctx; struct tapi_net_endpoint; struct tapi_net_iface; struct tapi_net_link; struct tapi_net_nat_rule; struct tapi_net_qinq; struct tapi_net_ta; struct tapi_net_vlan; // global functions typedef SLIST_HEAD(tapi_net_iface_head, tapi_net_iface); void tapi_net_ctx_init(tapi_net_ctx* net_ctx); void tapi_net_ctx_release(tapi_net_ctx* net_ctx); void tapi_net_ta_init(const char* ta_name, tapi_net_ta* cfg_net_ta); void tapi_net_ta_set_ifaces(tapi_net_ta* net_cfg_ta, const char** if_name_list); void tapi_net_ta_destroy(tapi_net_ta* cfg_net_ta); te_errno tapi_net_iface_set_vlan_conf(tapi_net_iface* iface, const tapi_net_vlan* vlan); te_errno tapi_net_iface_set_qinq_conf(tapi_net_iface* iface, const tapi_net_qinq* qinq); te_errno tapi_net_logical_iface_add(tapi_net_iface_type iface_type, const char* if_name, tapi_net_iface* base_iface, tapi_net_iface** iface); tapi_net_ta* tapi_net_find_agent_by_name(tapi_net_ctx* net_ctx, const char* ta_name); tapi_net_iface* tapi_net_find_iface_by_name(tapi_net_ta* net_cfg_ta, const char* if_name); tapi_net_iface_type tapi_net_iface_type_by_name(const char* iface_type_str); te_errno tapi_net_setup_ifaces(const tapi_net_ctx* net_ctx); const char* tapi_net_get_top_iface_name(const tapi_net_iface_head* iface_head); te_errno tapi_net_get_top_iface_addr(const tapi_net_iface_head* iface_head, const struct sockaddr** addr); te_errno tapi_net_setup(tapi_net_ctx* net_ctx); void tapi_net_nat_rule_init(tapi_net_nat_rule* rule); te_errno tapi_net_nat_rule_validate(const tapi_net_nat_rule* rule); te_errno tapi_net_nat_rule_check_dup(const tapi_net_ta* agent, const tapi_net_nat_rule* rule); te_errno tapi_net_addr_fill(tapi_net_ctx* net_ctx); const struct sockaddr* tapi_net_ep_resolve_ip_addr(tapi_net_ctx* ctx, const tapi_net_endpoint* ep); // macros #define TAPI_NET_EP_NUM #define TAPI_NET_NAME_LEN
Detailed Documentation
Definition of test API to define and set up test network.
Typedefs
typedef enum tapi_net_iface_type tapi_net_iface_type
Supported interface types.
typedef struct tapi_net_vlan tapi_net_vlan
VLAN-specific configuration.
typedef struct tapi_net_qinq tapi_net_qinq
QinQ-specific configuration.
typedef struct tapi_net_iface tapi_net_iface
Logical interface definition.
Interfaces are organized as a stack, starting from a base and building up through VLAN, QinQ, GRE, or other layers. The stack is represented as a singly linked list, where each interface points to the next one above it.
The structure defines the interface type and any type-specific parameters, such as a VLAN ID.
typedef struct tapi_net_endpoint tapi_net_endpoint
Network endpoint of single connection.
typedef enum tapi_net_nat_rule_type tapi_net_nat_rule_type
Type of NAT rule.
typedef enum tapi_net_nat_rule_mode tapi_net_nat_rule_mode
Mode of NAT rule.
typedef struct tapi_net_nat_rule tapi_net_nat_rule
Single NAT rule.
typedef struct tapi_net_ta tapi_net_ta
Test agent with a list of logical interfaces.
typedef struct tapi_net_link tapi_net_link
Logical network between two endpoints. For the test purposes, networks are modeled as point-to-point connections.
typedef struct tapi_net_ctx tapi_net_ctx
Network configuration context that includes all interface definitions and network topologies.
Global Functions
typedef SLIST_HEAD(tapi_net_iface_head, tapi_net_iface)
Singly-linked list of logical interfaces.
void tapi_net_ctx_init(tapi_net_ctx* net_ctx)
Initialize network configuration context. This sets up vectors and their destructors.
void tapi_net_ctx_release(tapi_net_ctx* net_ctx)
Release Network Configuration Context.
Parameters:
net_ctx |
Network Configuration Context. |
void tapi_net_ta_init(const char* ta_name, tapi_net_ta* cfg_net_ta)
Initialize Test Agent network configuration.
Parameters:
ta_name |
TA name. |
cfg_net_ta |
Resulting TA network configuration. |
void tapi_net_ta_set_ifaces(tapi_net_ta* net_cfg_ta, const char** if_name_list)
Set interfaces in network configuration for specific Test Agent.
Parameters:
cfg_net_ta |
TA network configuration. |
if_name_list |
NULL-terminated list of physical interface names. |
Returns:
Status of the initializion.
void tapi_net_ta_destroy(tapi_net_ta* cfg_net_ta)
Destroy Test Agent network configuration.
Parameters:
net_cfg_ta |
Pointer to TA network configuration. |
te_errno tapi_net_iface_set_vlan_conf(tapi_net_iface* iface, const tapi_net_vlan* vlan)
Set interface VLAN-specific information.
Parameters:
iface |
Pointer to VLAN interface. |
vlan |
VLAN information. |
TE_EINVAL |
Invalid |
0 |
Success. |
Returns:
Status of the setting.
te_errno tapi_net_iface_set_qinq_conf(tapi_net_iface* iface, const tapi_net_qinq* qinq)
Set interface QinQ-specific information.
Parameters:
iface |
Pointer to QinQ interface. |
qinq |
QinQ information. |
TE_EINVAL |
Invalid |
0 |
Success. |
Returns:
Status of the setting.
te_errno tapi_net_logical_iface_add(tapi_net_iface_type iface_type, const char* if_name, tapi_net_iface* base_iface, tapi_net_iface** iface)
Add new logical interface.
Parameters:
iface_type |
Iterface type. |
if_name |
Interface name. |
base_iface |
Pointer to the interface to base on. |
iface |
Pointer to the added interfaces. |
TE_EINVAL |
Unsupported type of logical interface. |
0 |
Success. |
Returns:
Status of the adding.
tapi_net_ta* tapi_net_find_agent_by_name(tapi_net_ctx* net_ctx, const char* ta_name)
Find TA network configuration in network context.
Parameters:
net_ctx |
Network configuration context. |
ta_name |
TA name to find. |
Returns:
Pointer to TA network configuration, or NULL in case of error.
tapi_net_iface* tapi_net_find_iface_by_name(tapi_net_ta* net_cfg_ta, const char* if_name)
Find interface by its name in TA network configuration.
Parameters:
net_cfg_ta |
Pointer TA network configuration. |
if_name |
Interface name to find. |
Returns:
Pointer to interface, or NULL in case of error.
tapi_net_iface_type tapi_net_iface_type_by_name(const char* iface_type_str)
Get interface type by its string representation.
Parameters:
if_name |
String with Network type |
Returns:
Interface type.
te_errno tapi_net_setup_ifaces(const tapi_net_ctx* net_ctx)
Setup interfaces specified in the network context.
Parameters:
net_ctx |
Network context. |
Returns:
Status code.
const char* tapi_net_get_top_iface_name(const tapi_net_iface_head* iface_head)
Get interface name of the top-most interface in the stack.
Parameters:
iface_head |
Head of the interface stack. |
Returns:
Interface name or NULL on error.
te_errno tapi_net_get_top_iface_addr(const tapi_net_iface_head* iface_head, const struct sockaddr** addr)
Get address of the top-most interface in the stack.
Parameters:
iface_head |
Head of the interface stack. |
addr |
Address of the interface. |
TE_ENOENT |
No address assigned to requested interface. |
0 |
Success. |
Returns:
Status of the adding.
te_errno tapi_net_setup(tapi_net_ctx* net_ctx)
Setup network based on network context.
Parameters:
net_ctx |
Network contex to use for setup. |
Returns:
Status code.
void tapi_net_nat_rule_init(tapi_net_nat_rule* rule)
Initialize NAT rule.
Parameters:
rule |
NAT rule to init. |
te_errno tapi_net_nat_rule_validate(const tapi_net_nat_rule* rule)
Validate NAT rule.
Parameters:
rule |
NAT rule to validate. |
TE_EINVAL |
Validation failed. |
0 |
Success. |
Returns:
Status code.
te_errno tapi_net_nat_rule_check_dup(const tapi_net_ta* agent, const tapi_net_nat_rule* rule)
Check NAT rule duplicates.
Parameters:
agent |
Test agent which owns the NAT rule list. |
rule |
Rule to validate. |
TE_EEXIST |
Conflicting rule already exists. |
0 |
Success. |
Returns:
Status code.
te_errno tapi_net_addr_fill(tapi_net_ctx* net_ctx)
Fill in IP addresses for logical interfaces based on netowrks in Configurator.
This function set appropriate IP addresses for the logical interface structures mentioned in Configurator to use them after in tests.
Parameters:
net_ctx |
Network contex |
Returns:
Status code.
const struct sockaddr* tapi_net_ep_resolve_ip_addr(tapi_net_ctx* ctx, const tapi_net_endpoint* ep)
Resolve IP address of specific network endpoint.
Parameters:
net_ctx |
Network contex to use for resolving. |
ep |
Network endpoint. |
Returns:
Resolved IP address.
Macros
#define TAPI_NET_EP_NUM
The limit of endpoint number which can be used in test networks.
#define TAPI_NET_NAME_LEN
Length of network name.