summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/api/stl/examples/stl_simple_burst.py4
-rw-r--r--scripts/automation/trex_control_plane/client/trex_port.py38
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py103
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py8
4 files changed, 120 insertions, 33 deletions
diff --git a/scripts/api/stl/examples/stl_simple_burst.py b/scripts/api/stl/examples/stl_simple_burst.py
index 3b394d10..2ca71b44 100644
--- a/scripts/api/stl/examples/stl_simple_burst.py
+++ b/scripts/api/stl/examples/stl_simple_burst.py
@@ -37,7 +37,7 @@ def simple_burst ():
try:
- #c.logger.set_verbose(c.logger.VERBOSE_NORMAL)
+ #c.set_verbose("high")
# create two bursts and link them
s1 = STLStream(packet = pkt_bld,
@@ -56,7 +56,7 @@ def simple_burst ():
c.reset(ports = [0, 1])
# add both streams to ports
- c.add_streams([s1, s2], ports = [0, 1])
+ stream_ids = c.add_streams([s1, s2], ports = [0, 1])
# run 5 times
for i in xrange(1, 6):
diff --git a/scripts/automation/trex_control_plane/client/trex_port.py b/scripts/automation/trex_control_plane/client/trex_port.py
index c8147faf..eaf64ac2 100644
--- a/scripts/automation/trex_control_plane/client/trex_port.py
+++ b/scripts/automation/trex_control_plane/client/trex_port.py
@@ -177,40 +177,57 @@ class Port(object):
# remove stream from port
- def remove_stream (self, stream_id):
+ def remove_streams (self, stream_id_list):
if not self.is_acquired():
return self.err("port is not owned")
- if not stream_id in self.streams:
+ if not self.is_port_writable():
+ return self.err("Please stop port before attempting to remove streams")
+
+ # single element to list
+ stream_id_list = stream_id_list if isinstance(stream_id_list, list) else [stream_id_list]
+
+ # verify existance
+ if not all([stream_id in self.streams for stream_id in stream_id_list]):
return self.err("stream {0} does not exists".format(stream_id))
- params = {"handler": self.handler,
- "port_id": self.port_id,
- "stream_id": stream_id}
+ batch = []
+ for stream_id in stream_id_list:
+ params = {"handler": self.handler,
+ "port_id": self.port_id,
+ "stream_id": stream_id}
- rc = self.transmit("remove_stream", params)
- if rc.bad():
- return self.err(rc.err())
+ cmd = RpcCmdData('remove_stream', params)
+ batch.append(cmd)
- self.streams[stream_id] = None
+ del self.streams[stream_id]
+
+
+ rc = self.transmit_batch(batch)
+ if not rc:
+ return self.err(rc.err())
self.state = self.STATE_STREAMS if (len(self.streams) > 0) else self.STATE_IDLE
return self.ok()
+
# remove all the streams
def remove_all_streams (self):
if not self.is_acquired():
return self.err("port is not owned")
+ if not self.is_port_writable():
+ return self.err("Please stop port before attempting to remove streams")
+
params = {"handler": self.handler,
"port_id": self.port_id}
rc = self.transmit("remove_all_streams", params)
- if rc.bad():
+ if not rc:
return self.err(rc.err())
self.streams = {}
@@ -231,7 +248,6 @@ class Port(object):
# start traffic
def start (self, mul, duration, force):
-
if not self.is_acquired():
return self.err("port is not owned")
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index 3d4dbc93..34526e69 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -511,26 +511,14 @@ class STLClient(object):
- def __add_stream_pack(self, stream_pack, port_id_list = None):
+ def __remove_streams(self, stream_id_list, port_id_list = None):
port_id_list = self.__ports(port_id_list)
rc = RC()
for port_id in port_id_list:
- rc.add(self.ports[port_id].add_streams(stream_pack))
-
- return rc
-
-
-
- def __remove_stream(self, stream_id, port_id_list = None):
- port_id_list = self.__ports(port_id_list)
-
- rc = RC()
-
- for port_id in port_id_list:
- rc.add(self.ports[port_id].remove_stream(stream_id))
+ rc.add(self.ports[port_id].remove_streams(stream_id_list))
return rc
@@ -703,9 +691,9 @@ class STLClient(object):
# disconenct from server
- def __disconnect(self):
+ def __disconnect(self, release_ports = True):
# release any previous acquired ports
- if self.is_connected():
+ if self.is_connected() and release_ports:
self.__release(self.get_acquired_ports())
self.comm_link.disconnect()
@@ -1017,11 +1005,12 @@ class STLClient(object):
:parameters:
stop_traffic : bool
tries to stop traffic before disconnecting
-
+ release_ports : bool
+ tries to release all the acquired ports
"""
@__api_check(False)
- def disconnect (self, stop_traffic = True):
+ def disconnect (self, stop_traffic = True, release_ports = True):
# try to stop ports but do nothing if not possible
if stop_traffic:
@@ -1030,9 +1019,10 @@ class STLClient(object):
except STLError:
pass
+
self.logger.pre_cmd("Disconnecting from server at '{0}':'{1}'".format(self.connection_info['server'],
self.connection_info['sync_port']))
- rc = self.__disconnect()
+ rc = self.__disconnect(release_ports)
self.logger.post_cmd(rc)
@@ -1077,6 +1067,34 @@ class STLClient(object):
raise STLError(rc)
+ """
+ Release ports
+
+ :parameters:
+ ports : list
+ ports to execute the command
+
+ :raises:
+ + :exc:`STLError`
+
+ """
+ @__api_check(True)
+ def release (self, ports = None):
+ # by default use all acquired ports
+ if ports == None:
+ ports = self.get_acquired_ports()
+
+ # verify ports
+ rc = self._validate_port_list(ports)
+ if not rc:
+ raise STLArgumentError('ports', ports, valid_values = self.get_all_ports())
+
+ self.logger.pre_cmd("Releasing ports {0}:".format(ports))
+ rc = self.__release(ports)
+ self.logger.post_cmd(rc)
+
+ if not rc:
+ raise STLError(rc)
"""
Pings the server
@@ -1173,6 +1191,9 @@ class STLClient(object):
streams: list
streams to attach
+ :returns:
+ list of stream IDs in order of the stream list
+
:raises:
+ :exc:`STLError`
@@ -1203,6 +1224,50 @@ class STLClient(object):
if not rc:
raise STLError(rc)
+ return [stream.get_id() for stream in streams]
+
+
+ """
+ remove a list of streams from ports
+
+ :parameters:
+ ports : list
+ ports to execute the command
+ stream_id_list: list
+ stream id list to remove
+
+
+ :raises:
+ + :exc:`STLError`
+
+ """
+ @__api_check(True)
+ def remove_streams (self, stream_id_list, ports = None):
+ # by default use all ports
+ if ports == None:
+ ports = self.get_acquired_ports()
+
+ # verify valid port id list
+ rc = self._validate_port_list(ports)
+ if not rc:
+ raise STLArgumentError('ports', ports, valid_values = self.get_all_ports())
+
+ # transform single stream
+ if not isinstance(stream_id_list, list):
+ stream_id_list = [stream_id_list]
+
+ # check streams
+ if not all([isinstance(stream_id, long) for stream_id in stream_id_list]):
+ raise STLArgumentError('stream_id_list', stream_id_list)
+
+ # remove streams
+ self.logger.pre_cmd("Removing {0} streams from port(s) {1}:".format(len(stream_id_list), ports))
+ rc = self.__remove_streams(stream_id_list, ports)
+ self.logger.post_cmd(rc)
+
+ if not rc:
+ raise STLError(rc)
+
"""
load a profile file to port(s)
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 6a4af350..c8624626 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -320,6 +320,10 @@ class TRexConsole(TRexGeneralCmd):
def help_history (self):
self.do_history("-h")
+ def do_shell (self, line):
+ return self.do_history(line)
+
+
def do_history (self, line):
'''Manage the command history\n'''
@@ -346,7 +350,9 @@ class TRexConsole(TRexGeneralCmd):
if cmd == None:
return
- self.onecmd(cmd)
+ print "Executing '{0}'".format(cmd)
+
+ return self.onecmd(cmd)