ASTF topology Module

Using the topology object you can build a multiple networks and associate each client to a network

ASTFTopology class

class trex.astf.topo.ASTFTopology(vifs=None, gws=None)[source]

Init ASTFTopology from list of TopoVIFs and TopoGWs (default is empty)

add_vif_obj(vif)[source]

Add TopoVIF object

add_gw_obj(gw)[source]

Add TopoGW object

add_vif(*a, **k)[source]
Create (from given arguments) and add TopoVIF object.
Instead of port_id, one may specify trex_port and sub_if - integers, TRex port ID and sub-interface ID respectfully.
add_gw(*a, **k)[source]
Create (from given arguments) and add TopoGW object.
Instead of port_id, one may specify trex_port and sub_if - integers, TRex port ID and sub-interface ID respectfully.
is_empty()[source]

Return True if nothing is added

TopoGW class

class trex.astf.topo.TopoGW(port_id, src_start, src_end, dst, dst_mac='')[source]

Defines next hop for traffic.

Parameters:
port_id: string

Format of “A.B”, where A is TRex port ID and B is sub-interface ID >= 1.

src_start, src_end: strings

IPv4 addresses, traffic within this range will be routed via this GW

dst: string

Either IPv4/v6 or MAC address. IP will need resolve before uploading to server.

dst_mac: string

Resolved MAC, for internal usage.

TopoVIF class

class trex.astf.topo.TopoVIF(port_id, src_mac, src_ipv4='', src_ipv6='', vlan=0)[source]

Source MAC and VLAN are taken from here for traffic.

Parameters:
port_id: string

Format of “A.B”, where A is TRex port ID and B is sub-interface ID >= 1.

src_mac: string

MAC address of virtual interface. Will be used in sent traffic.

src_ipv4: string

IPv4 address of interface. If specified, used in resolve, otherwise taken from TRex port.

src_ipv6: string

IPv6 address of interface. Currently not used.

vlan: int

VLAN ID, will be used in traffic and in resolve process.

ASTFClient snippet

Basic topology usage:

c = self.astf_trex
topo = ASTFTopology()
topo.add_vif(
   port_id = '0.2',
   src_mac = '12:12:12:12:12:12',
   src_ipv4 = '5.5.5.5',
   vlan = 30)

topo.add_gw(
   port_id = '0.2',
    src_start = '16.0.0.0',
    src_end = '16.0.0.2',
    dst = '45:45:45:45:45:45')

try:
    c.topo_load(topo)
    c.topo_resolve() # get MACs from IPs. On success, upload topology to server
    c.load_profile(os.path.join(CTRexScenario.scripts_path, 'astf', 'udp1.py'))
    c.start(mult = 10000, duration = 1)
    c.wait_on_traffic()
finally:
    c.stop()
    c.topo_clear()

Load/Save to file:

c = self.astf_trex
c.topo_load('some_topology.py', {'count': 3})
c.topo_save('/tmp/topo_copy.py')

Topology Python file:

from trex.astf.topo import *

# reserved name "get_topo", will be called by "load" function
def get_topo(**kw):
    print('Creating profile with variables: %s' % kw)

    topo = ASTFTopology()
    topo.add_vif(
        port_id = '0.1',
        src_mac = '12:12:12:12:12:12')
    topo.add_gw(
        port_id = '0.1',
        dst = '15:15:15:15:15:15',
        src_start = '10.0.0.1',
        src_end = '10.0.0.16')
    return topo