diff options
author | imarom <imarom@cisco.com> | 2016-03-02 16:01:08 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-03-02 16:01:08 +0200 |
commit | 26873712908fcfb26ee5310c961846b79f0a8249 (patch) | |
tree | a94aa192f9bdf998257b5c6764defa5dce74fcbe /scripts/automation/trex_control_plane | |
parent | 9c62e2a6f114d99a7271e259bad2601a28cd9c4a (diff) |
port mapping - hardening
Diffstat (limited to 'scripts/automation/trex_control_plane')
3 files changed, 40 insertions, 31 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index ffad03f3..d96a7623 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -349,17 +349,25 @@ class TRexConsole(TRexGeneralCmd): with self.stateless_client.logger.supress(): table = stl_map_ports(self.stateless_client, ports = ports) - tmp = list(ports) + print format_text('\nAcquired ports topology:\n', 'bold', 'underline') - while tmp: - a = tmp.pop(0) - b = table[a] - tmp.remove(b) - print "port {0} <--> port {1}".format(a, b) + # bi-dir ports + print format_text('Bi-directional ports:\n','underline') + for port_a, port_b in table['bi']: + print "port {0} <--> port {1}".format(port_a, port_b) + + print "" + # unknown ports + print format_text('Mapping unknown:\n','underline') + for port in table['unknown']: + print "port {0}".format(port) print "" + + + def do_history (self, line): '''Manage the command history\n''' diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_imix.py b/scripts/automation/trex_control_plane/stl/examples/stl_imix.py index e3c01ca9..cc7691a3 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_imix.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_imix.py @@ -30,9 +30,10 @@ def imix_test (): # map ports - identify the routes table = stl_map_ports(c) - print "Mapped ports to sides {0} <--> {1}".format(table['dir'][0], table['dir'][1]) - dir_0 = table['dir'][0] - dir_1 = table['dir'][1] + dir_0 = [x[0] for x in table['bi']] + dir_1 = [x[1] for x in table['bi']] + + print "Mapped ports to sides {0} <--> {1}".format(dir_0, dir_1) # load IMIX profile profile = STLProfile.load_py('../../../../stl/imix.py') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py index 72a5ea52..e0b25b1d 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py @@ -4,7 +4,6 @@ from trex_stl_packet_builder_scapy import * # map ports # will destroy all streams/data on the ports def stl_map_ports (client, ports = None): - # by default use all ports if ports == None: ports = client.get_all_ports() @@ -15,12 +14,15 @@ def stl_map_ports (client, ports = None): # generate streams base_pkt = CScapyTRexPktBuilder(pkt = Ether()/IP()) + tx_pkts = {} pkts = 1 for port in ports: + tx_pkts[pkts] = port stream = STLStream(packet = base_pkt, mode = STLTXSingleBurst(pps = 100000, total_pkts = pkts)) client.add_streams(stream, [port]) + pkts = pkts * 2 # inject @@ -33,35 +35,33 @@ def stl_map_ports (client, ports = None): # cleanup client.reset(ports = ports) - table = {} - for port in ports: - table[port] = None + table = {'map': {}, 'bi' : [], 'unknown': []} + # actual mapping for port in ports: + ipackets = stats[port]["ipackets"] + table['map'][port] = None - exp = 1 - while ipackets >= exp: - if ((ipackets & exp) == (exp)): - source = int(math.log(exp, 2)) - table[source] = port + for pkts in tx_pkts.keys(): + if ( (pkts & ipackets) == pkts ): + tx_port = tx_pkts[pkts] + table['map'][port] = tx_port - exp *= 2 - if not all(x != None for x in table.values()): - raise STLError('unable to map ports') + unmapped = list(ports) + while len(unmapped) > 0: + port_a = unmapped.pop(0) + port_b = table['map'][port_a] - dir_a = set() - dir_b = set() - for src, dst in table.iteritems(): - # src is not in - if src not in (dir_a, dir_b): - if dst in dir_a: - dir_b.add(src) - else: - dir_a.add(src) + # if unknown - add to the unknown list + if port_b == None: + table['unknown'].append(port_a) - table['dir'] = [list(dir_a), list(dir_b)] + # bi-directional ports + elif (table['map'][port_b] == port_a): + unmapped.remove(port_b) + table['bi'].append( (port_a, port_b) ) return table |