summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib
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/stl/trex_stl_lib
parent951a503356fd359407a8fae791b75fa8881dc04c (diff)
parent2760d0eef3076580f3d112c2e754e108f6028dc7 (diff)
Merge Console merge
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib')
-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
3 files changed, 42 insertions, 39 deletions
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