summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-03-03 17:14:28 +0200
committerHanoh Haim <hhaim@cisco.com>2016-03-03 17:14:28 +0200
commit0a10805acc189a36eecb4d49b858bd911bc45f4e (patch)
tree05ab3e32da5a284c50b2b186be2a7857bb364382 /scripts/automation/trex_control_plane
parent951a503356fd359407a8fae791b75fa8881dc04c (diff)
parent2760d0eef3076580f3d112c2e754e108f6028dc7 (diff)
Merge Console merge
Diffstat (limited to 'scripts/automation/trex_control_plane')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py26
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_imix.py7
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py9
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py28
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py44
5 files changed, 65 insertions, 49 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 e037f517..4b5e5f54 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'''
@@ -555,11 +563,15 @@ class TRexConsole(TRexGeneralCmd):
return
if opts.xterm:
+ if not os.path.exists('/usr/bin/xterm'):
+ print format_text("XTERM does not exists on this machine", 'bold')
+ return
info = self.stateless_client.get_connection_info()
exe = './trex-console --top -t -q -s {0} -p {1} --async_port {2}'.format(info['server'], info['sync_port'], info['async_port'])
- cmd = ['xterm', '-geometry', '111x47', '-sl', '0', '-title', 'trex_tui', '-e', exe]
+ cmd = ['/usr/bin/xterm', '-geometry', '111x47', '-sl', '0', '-title', 'trex_tui', '-e', exe]
+
self.terminal = subprocess.Popen(cmd)
return
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_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index 50566853..04dd77ec 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -227,7 +227,7 @@ class AsyncEventHandler(object):
ev = "Port {0} job done".format(port_id)
# call the handler
- self.__async_event_port_stopped(port_id)
+ self.__async_event_port_job_done(port_id)
show_event = True
# port was stolen...
@@ -264,6 +264,9 @@ class AsyncEventHandler(object):
# private functions
+ def __async_event_port_job_done (self, port_id):
+ self.client.ports[port_id].async_event_port_job_done()
+
def __async_event_port_stopped (self, port_id):
self.client.ports[port_id].async_event_port_stopped()
@@ -1332,7 +1335,6 @@ class STLClient(object):
:parameters:
ports : list
ports to execute the command
-
:raises:
+ :exc:`STLError`
@@ -1354,7 +1356,6 @@ class STLClient(object):
if not rc:
raise STLError(rc)
-
"""
update traffic on port(s)
@@ -1433,8 +1434,6 @@ class STLClient(object):
if not rc:
raise STLError(rc)
-
-
"""
resume traffic on port(s)
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
index 6aa18847..4529efa9 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
@@ -334,7 +334,7 @@ class Port(object):
"mul": mul,
"duration": duration,
"force": force}
-
+
rc = self.transmit("start_traffic", params)
if rc.bad():
return self.err(rc.err())
@@ -363,7 +363,6 @@ class Port(object):
if rc.bad():
return self.err(rc.err())
- # only valid state after stop
self.state = self.STATE_STREAMS
return self.ok()
@@ -383,7 +382,6 @@ class Port(object):
if rc.bad():
return self.err(rc.err())
- # only valid state after stop
self.state = self.STATE_PAUSE
return self.ok()
@@ -400,11 +398,12 @@ class Port(object):
params = {"handler": self.handler,
"port_id": self.port_id}
+ # only valid state after stop
+
rc = self.transmit("resume_traffic", params)
if rc.bad():
return self.err(rc.err())
- # only valid state after stop
self.state = self.STATE_TX
return self.ok()
@@ -591,21 +590,26 @@ class Port(object):
- ################# events handler ######################
- def async_event_port_stopped (self):
+ ################# events handler ######################
+ def async_event_port_job_done (self):
self.state = self.STATE_STREAMS
-
- def async_event_port_started (self):
- self.state = self.STATE_TX
-
+ # rest of the events are used for TUI / read only sessions
+ def async_event_port_stopped (self):
+ if not self.is_acquired():
+ self.state = self.STATE_STREAMS
def async_event_port_paused (self):
- self.state = self.STATE_PAUSE
+ if not self.is_acquired():
+ self.state = self.STATE_PAUSE
+ def async_event_port_started (self):
+ if not self.is_acquired():
+ self.state = self.STATE_TX
def async_event_port_resumed (self):
- self.state = self.STATE_TX
+ if not self.is_acquired():
+ self.state = self.STATE_TX
def async_event_forced_acquired (self):
self.handler = None
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