Network topology configuration of Test Agents

Overview

// typedefs

typedef struct cfg_net_node_t cfg_net_node_t;
typedef enum cfg_nat_setup_t cfg_nat_setup_t;
typedef struct cfg_net_t cfg_net_t;
typedef struct cfg_nets_t cfg_nets_t;
typedef struct cfg_net_pci_info_t cfg_net_pci_info_t;

typedef te_errno tapi_cfg_net_node_cb(
    cfg_net_t *net,
    cfg_net_node_t *node,
    const char *str,
    cfg_oid *oid,
    void *cookie
    );

typedef struct tapi_cfg_net_assigned tapi_cfg_net_assigned;

// enums

enum cfg_nat_setup_t;
enum net_node_rsrc_type;
enum net_node_type;

// structs

struct cfg_net_node_t;
struct cfg_net_pci_info_t;
struct cfg_net_t;
struct cfg_nets_t;
struct tapi_cfg_net_assigned;

// global functions

void tapi_cfg_net_init_pci_info(cfg_net_pci_info_t* pci_info);
void tapi_cfg_net_free_pci_info(cfg_net_pci_info_t* pci_info);
enum net_node_rsrc_type tapi_cfg_net_get_node_rsrc_type(cfg_net_node_t* node);
te_errno tapi_cfg_net_get_net(cfg_handle net_handle, cfg_net_t* net);
te_errno tapi_cfg_net_get_nets(cfg_nets_t* nets);
void tapi_cfg_net_free_net(cfg_net_t* net);
void tapi_cfg_net_free_nets(cfg_nets_t* nets);
te_errno tapi_cfg_net_register_net(const char* name, cfg_net_t* net, ...);
te_errno tapi_cfg_net_unregister_net(const char* name, cfg_net_t* net);
int tapi_cfg_net_get_pairs(enum net_node_type first, enum net_node_type second, unsigned int* p_n_pairs, cfg_handle(**) p_pairs[2]);
int tapi_cfg_net_find_net_by_node(const char* oid, char* net);
int tapi_cfg_net_get_nodes_values(const char* net_name, enum net_node_type node_type, const char* ta_name, char*** oids);
void tapi_cfg_net_free_nodes_values(char** oids);
int tapi_cfg_net_get_switch_port(const char* ta_node, unsigned int* p_port);
te_errno tapi_cfg_net_remove_empty(void);
te_errno tapi_cfg_net_foreach_node(tapi_cfg_net_node_cb* cb, void* cookie);
te_errno tapi_cfg_net_bind_driver_by_node(enum net_node_type node_type, enum tapi_cfg_driver_type driver);
te_errno tapi_cfg_net_get_iut_if_pci_info(cfg_net_pci_info_t* iut_if_pci_info);
te_errno tapi_cfg_net_nodes_update_pci_fn_to_interface(enum net_node_type type);
te_errno tapi_cfg_net_nodes_switch_pci_fn_to_interface(enum net_node_type type);
te_errno tapi_cfg_net_reserve_all(void);
te_errno tapi_cfg_net_all_up(bool force);
te_errno tapi_cfg_net_delete_all_ip4_addresses(void);
te_errno tapi_cfg_net_delete_all_ip6_addresses(void);
te_errno tapi_cfg_net_all_check_mtu(void);
int tapi_cfg_net_assign_ip(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned);
te_errno tapi_cfg_net_unassign_ip(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned);
te_errno tapi_cfg_net_all_assign_ip(unsigned int af);
int tapi_cfg_net_assign_ip_one_end(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned);
cfg_net_node_t* tapi_cfg_net_get_gateway(const cfg_net_t* net_src, const cfg_net_t* net_tgt);
te_errno tapi_cfg_net_assigned_get_subnet_ip(tapi_cfg_net_assigned* assigned, struct sockaddr** addr, unsigned int* prefix_len);
te_errno tapi_cfg_net_delete_all(void);
te_errno tapi_cfg_net_create_routes(unsigned int af);
te_errno tapi_cfg_net_create_nat(unsigned int af);
te_errno tapi_cfg_net_node_get_pci_oids(const cfg_net_node_t* node, unsigned int* n_pci, char*** pci_oids);
te_errno tapi_cfg_net_node_interface(const char* node_value, char** iface_name);

Detailed Documentation

Typedefs

typedef struct cfg_net_node_t cfg_net_node_t

Node description structure

typedef enum cfg_nat_setup_t cfg_nat_setup_t

Supported NAT setup procedures

typedef struct cfg_net_t cfg_net_t

Net description structure

typedef struct cfg_nets_t cfg_nets_t

Nets description structure

typedef struct cfg_net_pci_info_t cfg_net_pci_info_t

PCI device of node description structure

typedef te_errno tapi_cfg_net_node_cb(
    cfg_net_t *net,
    cfg_net_node_t *node,
    const char *str,
    cfg_oid *oid,
    void *cookie
    )

Prototype of the function to be called for each node.

Iterator terminates if callback returns non zero.

Parameters:

net

Network the node belongs to

node

Node itself

str

Node OID value in string format

oid

Parsed node OID

cookie

Callback opaque data

Returns:

Status code.

typedef struct tapi_cfg_net_assigned tapi_cfg_net_assigned

Information about made assignments

Global Functions

void tapi_cfg_net_init_pci_info(cfg_net_pci_info_t* pci_info)

Initialize PCI device info structure.

Parameters:

pci_info

Pointer to PCI info structure.

void tapi_cfg_net_free_pci_info(cfg_net_pci_info_t* pci_info)

Free resources allocated for info of PCI device.

Parameters:

pci_info

Pointer to PCI info structure.

enum net_node_rsrc_type tapi_cfg_net_get_node_rsrc_type(cfg_net_node_t* node)

Get type of the network node resource.

Returns cached value if it is already known and tries to fill in cache otherwise.

te_errno tapi_cfg_net_get_net(cfg_handle net_handle, cfg_net_t* net)

Get configuration of the net.

@retval Status code.

Parameters:

net_handle

Configurator handle of the net to get

net

Location for net data (OUT)

te_errno tapi_cfg_net_get_nets(cfg_nets_t* nets)

Get nets configuration.

Parameters:

nets

Pointer to nets description structure (OUT)

Status

code.

void tapi_cfg_net_free_net(cfg_net_t* net)

Free network dump structure.

Parameters:

net

Pointer to net description structure

void tapi_cfg_net_free_nets(cfg_nets_t* nets)

Free networks dump structure.

Parameters:

nets

Pointer to nets description structure

te_errno tapi_cfg_net_register_net(const char* name, cfg_net_t* net, ...)

Register a new network in ‘/net’ CM tree. The function could be useful when you need to build a network dynamically (for example if you want to build some L3 network with a set of nodes, which you later want to assign IP addresses or do some other stuff available for ‘ cfg_net_t ‘ data types).

Other parameters are pairs of type:

  • “const char *node_oid_str” - the value of ‘/net/node’ instance to be added into a newly created network;

  • “enum net_node_type node_type” - node type value of ‘/net/node/type’ instance.

Trailing NULL tells there is no more pairs.

Parameters:

name

network name to assign

net

placeholder for a network data to be filled in

Returns:

Status of the operation.

te_errno tapi_cfg_net_unregister_net(const char* name, cfg_net_t* net)

Unregister net previously registered with tapi_cfg_net_register_net() function.

Parameters:

name

network name to unregister

net

network data structure (previously filled in with tapi_cfg_net_register_net() function)

Returns:

Status of the operation.

int tapi_cfg_net_get_pairs(enum net_node_type first, enum net_node_type second, unsigned int* p_n_pairs, cfg_handle(**) p_pairs[2])

Get pair (if available) from each configured network.

Parameters:

first

  • type of the first node

second

  • type of the second node

p_n_pairs

  • location for number of found pairs

p_pairs

  • location for array of found pairs

Returns:

Status code.

int tapi_cfg_net_find_net_by_node(const char* oid, char* net)

Find ‘net’ with node value equal to provided OID.

Parameters:

oid

  • search value

net

  • location for net name (at least CFG_INST_NAME_MAX)

Returns:

Status code.

int tapi_cfg_net_get_nodes_values(const char* net_name, enum net_node_type node_type, const char* ta_name, char*** oids)

For the given network, it returns the list of values gathered on the nodes of specified type.

The function allocates memory under an array of pointers to the values. The last element of this array is set to NULL. Deallocate this memory with tapi_cfg_net_free_nodes_values.

Parameters:

net_name

  • name of the network

node_type

  • type of the node to find

ta_name

  • name of the agent or NULL if it does not matter

oids

  • location for the list of values (OUT)

Status

of the operation

TE_ENOENT

The network does not have any node of specified type attached

See also:

tapi_cfg_net_free_nodes_values

void tapi_cfg_net_free_nodes_values(char** oids)

Frees memory allocated with tapi_cfg_net_get_nodes_values function.

Parameters:

oids

  • Pointer returned with tapi_cfg_net_get_nodes_values

See also:

tapi_cfg_net_get_nodes_values

int tapi_cfg_net_get_switch_port(const char* ta_node, unsigned int* p_port)

Get number of the switch port to which specified TA connected.

Parameters:

ta_node

  • OID of TA node in net configuration model

p_port

  • location for port number

Returns:

Status code.

te_errno tapi_cfg_net_remove_empty(void)

Remove networks with empty interface names from the CS database.

Returns:

Status code.

te_errno tapi_cfg_net_foreach_node(tapi_cfg_net_node_cb* cb, void* cookie)

Execute callback for each node.

Parameters:

cb

Callback function

cookie

Callback opaque data

Returns:

Status code.

te_errno tapi_cfg_net_bind_driver_by_node(enum net_node_type node_type, enum tapi_cfg_driver_type driver)

Bind a driver (with specified type) on a PCI function referenced by every net node matching node_type. The driver names for specific types are discovered from “/local” configurator tree (e.g. “/local/net_driver”).

Net nodes are expected to reference PCI functions, in case when a node references net interface:

  • if NET_DRIVER_TYPE_NET is passed, the function succeeds without performing bind,

  • if passed driver is not NET_DRIVER_TYPE_NET bind fails

Parameters:

node_type

Node type of nets on which bind is performed

driver

Driver type to bind

Returns:

Status code.

te_errno tapi_cfg_net_get_iut_if_pci_info(cfg_net_pci_info_t* iut_if_pci_info)

Fill PCI device info of IUT node.

Parameters:

iut_if_pci_info

Pointer to PCI info structure of IUT node.

Returns:

Status code.

te_errno tapi_cfg_net_nodes_update_pci_fn_to_interface(enum net_node_type type)

Update network nodes specified in terms of PCI function and bound to network driver to refer to corresponding network interfaces.

The interface is reserved as a resource.

Partially done changes are not rolled back in the case of failure.

Parameters:

type

Network node type of the nodes to update, pass NET_NODE_TYPE_INVALID to update all network nodes

Returns:

Status code.

See also:

tapi_cfg_net_bind_driver_by_node()

tapi_cfg_net_nodes_switch_pci_fn_to_interface()

te_errno tapi_cfg_net_nodes_switch_pci_fn_to_interface(enum net_node_type type)

Switch network nodes specified in terms of PCI function to network interfaces incluing rebind the PCI function to network driver.

Partially done changes are not rolled back in the case of failure.

Parameters:

type

Network node type of the nodes to switch, pass NET_NODE_TYPE_INVALID to switch all network nodes

Returns:

Status code.

te_errno tapi_cfg_net_reserve_all(void)

Reserve resources for all interfaces mentioned in networks configuration.

Returns:

Status code.

te_errno tapi_cfg_net_all_up(bool force)

Set UP state for all interfaces (nodes) of networks configuration.

Parameters:

force

If interface is already UP, push it down and up again

Returns:

Status code.

te_errno tapi_cfg_net_delete_all_ip4_addresses(void)

Delete IPv4 addresses from all nodes in networks configuration.

Returns:

Status code.

te_errno tapi_cfg_net_delete_all_ip6_addresses(void)

Delete IPv6 addresses (except link-local) from all nodes in networks configuration.

Returns:

Status code.

te_errno tapi_cfg_net_all_check_mtu(void)

Check all configuration networks that MTU values on the ends of each network does not differ

Returns:

Status code.

int tapi_cfg_net_assign_ip(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned)

Assign IP subnet to specified configuration network.

If assigned is NULL or assigned->pool is CFG_HANDLE_INVALID, IP subnet is allocated using tapi_cfg_alloc_entry from /net_pool:ip4 or /net_pool:ip6. Its handle is returned in assigned->pool. Pool entries assigned to net nodes are returned as array assigned->entries. Order of elements in the same as order of nodes in net->nodes array.

Parameters:

af

Address family

net

Configuration network

assigned

Information about done assignments

Returns:

Status code.

te_errno tapi_cfg_net_unassign_ip(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned)

Reset previously assigned IP addresses from a network.

Parameters:

af

Address family

net

Configuration network

assigned

Information about done assignments (to be unregistered)

Returns:

Status of the operation.

te_errno tapi_cfg_net_all_assign_ip(unsigned int af)

Assign IP subnets for all configuration network.

Parameters:

af

Address family

Returns:

Status code.

int tapi_cfg_net_assign_ip_one_end(unsigned int af, cfg_net_t* net, tapi_cfg_net_assigned* assigned)

Dirty hack, must be removed after sockts_get_host_addr() will be repaired.

cfg_net_node_t* tapi_cfg_net_get_gateway(const cfg_net_t* net_src, const cfg_net_t* net_tgt)

Get gateway node between two given networks.

Parameters:

net_src

Source network.

net_tgt

Target network.

Returns:

Network node.

te_errno tapi_cfg_net_assigned_get_subnet_ip(tapi_cfg_net_assigned* assigned, struct sockaddr** addr, unsigned int* prefix_len)

Obtain information about subnet address and prefix length.

Parameters:

assigned

subnet assignments handle

addr

subnet address (OUT)

prefix_len

subnet prefix length (OUT)

Returns:

Status of the operation

te_errno tapi_cfg_net_delete_all(void)

Delete all nets from network configuration.

Returns:

Status code (see te_errno.h)

te_errno tapi_cfg_net_create_routes(unsigned int af)

Create routes within virtual networks.

Parameters:

af

Address family.

Returns:

Status code (see te_errno.h).

te_errno tapi_cfg_net_create_nat(unsigned int af)

Create iptables for NAT networks.

Parameters:

af

Address family.

Returns:

Status code (see te_errno.h).

te_errno tapi_cfg_net_node_get_pci_oids(const cfg_net_node_t* node, unsigned int* n_pci, char*** pci_oids)

Get PCI devices associated with a network node.

Parameters:

node

Network node configuration

n_pci

Number of PCI devices

pci_oids

PCI device object identifiers (/agent/hardware/pci/device)

Returns:

Status code

te_errno tapi_cfg_net_node_interface(const char* node_value, char** iface_name)

Get network node interface name by PCI instance with or without netdev.

Instances of the following CS objects are supported:

  • /agent/hardware/pci/vendor/device/instance

  • /agent/hardware/pci/vendor/device/instance/netdev

  • /agent/interface

Parameters:

node_value

network node value

iface_name

location for interface name

Returns:

Status code.