Namespace modules

The API works when stack: linux_based in trex_cfg Using this API the user can add a separate Linux network namespace that represents a client. This client is virtualy attached to a bridge that connected to TRex port. ARP/IPV6 ND packets move from clients to DUT and DUT to clients but not from clients to clients due to n^2 flood startup issue. Using this method it is possible to leverage linux ipv4/ipv6 network stack for emulating l2 protocols.

notes: adding/removing namespace is rather slow (~100msec)

The following snippet create one namespace with ipv4 and ipv6

c = STLClient(verbose_level = 'error')
c.connect()

my_ports=[0,1]
c.reset(ports = my_ports)

# move to service mode
c.set_service_mode (ports = my_ports, enabled = True)


cmds=NSCmds()
MAC="00:01:02:03:04:05"
cmds.add_node(MAC)  # add namespace
cmds.set_vlan(MAC,[123,123]) # add valn + QinQ tags
cmds.set_ipv4(MAC,"1.1.1.3","1.1.1.2") # configure ipv4 and default gateway
cmds.set_ipv6(MAC,True) # enable ipv6 (auto mode, get src addrees from the router


 # start the batch
c.set_namespace_start( 0, cmds)
# wait for the results
res = c.wait_for_async_results(0);

# print the results
print(res);

Another method to do that:

c = STLClient(verbose_level = 'error')
c.connect()

my_ports=[0,1]
c.reset(ports = my_ports)

# move to service mode
c.set_service_mode (ports = my_ports, enabled = True)

# remove all old name spaces from all the ports
c.namespace_remove_all()

# utility function
MAC="00:01:02:03:04:05"

# each function will block
c.set_namespace(0,method='add_node',mac=MAC)
c.set_namespace(0,method='set_vlan',vlans=[123,123])
c.set_namespace(0,method='set_ipv4', mac=MAC, ipv4="1.1.1.3", dg="1.1.1.2")
c.set_namespace(0,method='set_ipv6', mac=MAC, enable= True)

Get Stats:

c = STLClient(verbose_level = 'error')
c.connect()
my_ports=[0,1]
c.reset(ports = my_ports)

# get all active nodes on port 0
r=c.set_namespace(0, method='get_nodes')
c.set_namespace (0, method='get_nodes_info', macs_list=r)

r=c.set_namespace(0, method='counters_get_meta')
r=c.set_namespace(0, method='counters_get_values', zeros=True)

build a networks of x clients

def get_mac (prefix,index):
    mac="{}:{:02x}:{:02x}".format(prefix,(index>>8)&0xff,(index&0xff))
    return (mac)

def get_ipv4 (prefix,index):
    ipv4="{}.{:d}.{:d}".format(prefix,(index>>8)&0xff,(index&0xff))
    return(ipv4)

# build a networks of  00:01:02:03:xx:xx and 1.1.x.x and IPV6 =auto with default gateway of 1.1.1.2 for all
def build_network (size):
    cmds=NSCmds()
    MAC_PREFIX="00:01:02:03"
    IPV4_PREFIX="1.1"
    IPV4_DG ='1.1.1.2'
    for i in range(size):
        mac = get_mac (MAC_PREFIX,i+257+1)
        ipv4  =get_ipv4 (IPV4_PREFIX,259+i)
        cmds.add_node(mac)
        cmds.set_ipv4(mac,ipv4,IPV4_DG)
        cmds.set_ipv6(mac,True)
    return (cmds)

NSCmds class

class trex.common.trex_ns.NSCmds[source]

namespace commands builder

add_node(mac)[source]

add new namespace

Parameters:
mac: string
MAC address in the format of xx:xx:xx:xx:xx:xx
remove_node(mac)[source]

remove namespace

Parameters:
mac: string
Key to the already created namespace in format xx:xx:xx:xx:xx:xx
set_vlan(mac, vlans, tpids=None)[source]

add/remove QinQ and Dot1Q. could be up to 2 tags

Parameters:
mac: string
Key to the already created namespace in format xx:xx:xx:xx:xx:xx
vlans: list
Array of up to 2 uint16 tags. In case of empty remove the vlans
tpids: list
Array of tpids that correspond to vlans.
Default is [0x8100] in case of single VLAN and [0x88a8, 0x8100] in case of QinQ
set_ipv4(mac, ipv4, dg)[source]

set or change ipv4 configuration

Parameters:
mac: string
Key to the already created namespace in format xx:xx:xx:xx:xx:xx
ipv4: string
IPv4 self address
dg: string
Default gateway
clear_ipv4(mac)[source]

remove ipv4 configuration from the ns

Parameters:None
set_ipv6(mac, enable, src_ipv6=None)[source]

set ns ipv6

Parameters:
enable : bool

enable ipv6

src_ipv6: None for auto, or ipv6 addr

remove_all()[source]

remove all namespace nodes

get_nodes()[source]

get all nodes macs (keys)

get_nodes_info(macs_list)[source]

provide list of macs return alist of objects with each namepace information

clear_counters()[source]

clear debug counters. these counters are global to all users in the system.

counters_get_meta()[source]

get the counters description as dict

counters_get_values(zeros=False)[source]

get the values of the counters, zeros: in case of false skip counters with zero value

get_commands_list()[source]

return the list of the commands

NSCmdResult class

class trex.common.trex_ns.NSCmdResult(data)[source]

namespace batch commands results helper object.

res = c.wait_for_async_results(0);

if res.is_any_error():
handle error

print(res.data)

is_any_error()[source]

do we have any error in batch response

errors()[source]

in case we have an error, get list of all errors