summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-11-07 18:47:23 +0200
committerimarom <imarom@cisco.com>2016-11-07 18:47:23 +0200
commitf9a0c5e2e1e1135cb0c0e6e192565e5b100c5a41 (patch)
treef09e19975f324d9c0eb717608473dcdbd334a608 /scripts/automation/trex_control_plane/stl
parente85ea75669ea39e4f99519138a3a84e4df6eed2d (diff)
RX features - queueing
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py121
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py91
2 files changed, 164 insertions, 48 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 2d5a6379..583917ea 100755
--- 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
@@ -324,26 +324,25 @@ class EventsHandler(object):
# port attr changed
elif (event_type == 8):
- return
- # port_id = int(data['port_id'])
- #
- # if data['attr'] == self.client.ports[port_id].attr:
- # return # false alarm
- #
- # old_info = self.client.ports[port_id].get_formatted_info()
- # self.__async_event_port_attr_changed(port_id, data['attr'])
- #
- # new_info = self.client.ports[port_id].get_formatted_info()
- # ev = "port {0} attributes changed".format(port_id)
- # for key, old_val in old_info.items():
- # new_val = new_info[key]
- # if old_val != new_val:
- # ev += '\n {key}: {old} -> {new}'.format(
- # key = key,
- # old = old_val.lower() if type(old_val) is str else old_val,
- # new = new_val.lower() if type(new_val) is str else new_val)
- # show_event = True
+ port_id = int(data['port_id'])
+
+ if data['attr'] == self.client.ports[port_id].attr:
+ return # false alarm
+
+ old_info = self.client.ports[port_id].get_formatted_info(sync = False)
+ self.__async_event_port_attr_changed(port_id, data['attr'])
+
+ new_info = self.client.ports[port_id].get_formatted_info(sync = False)
+ ev = "port {0} attributes changed".format(port_id)
+ for key, old_val in old_info.items():
+ new_val = new_info[key]
+ if old_val != new_val:
+ ev += '\n {key}: {old} -> {new}'.format(
+ key = key,
+ old = old_val.lower() if type(old_val) is str else old_val,
+ new = new_val.lower() if type(new_val) is str else new_val)
+ show_event = True
# server stopped
@@ -839,6 +838,24 @@ class STLClient(object):
return rc
+ def __set_rx_queue (self, port_id_list, size):
+ port_id_list = self.__ports(port_id_list)
+ rc = RC()
+
+ for port_id in port_id_list:
+ rc.add(self.ports[port_id].set_rx_queue(size))
+
+ return rc
+
+ def __remove_rx_queue (self, port_id_list):
+ port_id_list = self.__ports(port_id_list)
+ rc = RC()
+
+ for port_id in port_id_list:
+ rc.add(self.ports[port_id].remove_rx_queue())
+
+ return rc
+
# connect to server
def __connect(self):
@@ -1754,6 +1771,7 @@ class STLClient(object):
if not rc:
raise STLError(rc)
+
@__api_check(True)
def ping(self):
"""
@@ -1767,6 +1785,11 @@ class STLClient(object):
+ :exc:`STLError`
"""
+ rc = self.set_port_attr(ports = [0, 1], rx_filter_mode = 'all')
+ rc = self.set_rx_queue(ports = [0, 1], size = 1000)
+ if not rc:
+ raise STLError(rc)
+
self.logger.pre_cmd("Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'],
self.connection_info['sync_port']))
@@ -1777,6 +1800,7 @@ class STLClient(object):
if not rc:
raise STLError(rc)
+
@__api_check(True)
def server_shutdown (self, force = False):
"""
@@ -1890,6 +1914,7 @@ class STLClient(object):
link_up = True,
rx_filter_mode = 'hw')
self.remove_rx_sniffer(ports)
+ self.remove_rx_queue(ports)
@@ -2737,7 +2762,8 @@ class STLClient(object):
# check arguments
validate_type('base_filename', base_filename, basestring)
validate_type('limit', limit, (int))
-
+ if limit <= 0:
+ raise STLError("'limit' must be a positive value")
self.logger.pre_cmd("Setting RX sniffers on port(s) {0}:".format(ports))
rc = self.__set_rx_sniffer(ports, base_filename, limit)
@@ -2750,7 +2776,7 @@ class STLClient(object):
@__api_check(True)
- def remove_rx_sniffer (self, ports = None, base_filename = 'rx_capture', limit = 1000):
+ def remove_rx_sniffer (self, ports = None):
"""
Removes RX sniffer from port(s)
@@ -2768,6 +2794,59 @@ class STLClient(object):
if not rc:
raise STLError(rc)
+
+ @__api_check(True)
+ def set_rx_queue (self, ports = None, size = 1000):
+ """
+ Sets RX queue for port(s)
+ The queue is cyclic and will hold last 'size' packets
+
+ :parameters:
+ ports - for which ports to apply a unique sniffer (each port gets a unique file)
+ size - size of the queue
+ :raises:
+ + :exe:'STLError'
+
+ """
+ ports = ports if ports is not None else self.get_acquired_ports()
+ ports = self._validate_port_list(ports)
+
+ # check arguments
+ validate_type('size', size, (int))
+ if size <= 0:
+ raise STLError("'size' must be a positive value")
+
+ self.logger.pre_cmd("Setting RX queue on port(s) {0}:".format(ports))
+ rc = self.__set_rx_queue(ports, size)
+ self.logger.post_cmd(rc)
+
+
+ if not rc:
+ raise STLError(rc)
+
+
+
+ @__api_check(True)
+ def remove_rx_queue (self, ports = None):
+ """
+ Removes RX queue from port(s)
+
+ :raises:
+ + :exe:'STLError'
+
+ """
+ ports = ports if ports is not None else self.get_acquired_ports()
+ ports = self._validate_port_list(ports)
+
+ self.logger.pre_cmd("Removing RX queue on port(s) {0}:".format(ports))
+ rc = self.__remove_rx_queue(ports)
+ self.logger.post_cmd(rc)
+
+ if not rc:
+ raise STLError(rc)
+
+
+
def clear_events (self):
"""
Clear all events
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 4e5778a6..94745d15 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
@@ -62,6 +62,7 @@ class Port(object):
self.streams = {}
self.profile = None
self.session_id = session_id
+ self.status = {}
self.attr = {}
self.port_stats = trex_stl_stats.CPortStats(self)
@@ -250,11 +251,9 @@ class Port(object):
self.next_available_id = int(rc.data()['max_stream_id']) + 1
- # attributes
- self.attr = rc.data()['attr']
+ self.status = rc.data()
- # rx info
- self.rx_info = rc.data()['rx_info']
+ self.attr = rc.data()['attr']
return self.ok()
@@ -520,6 +519,35 @@ class Port(object):
@owned
+ def set_rx_queue (self, size):
+
+ params = {"handler": self.handler,
+ "port_id": self.port_id,
+ "type": "queue",
+ "enabled": True,
+ "size": size}
+
+ rc = self.transmit("set_rx_feature", params)
+ if rc.bad():
+ return self.err(rc.err())
+
+ return self.ok()
+
+ @owned
+ def remove_rx_queue (self):
+ params = {"handler": self.handler,
+ "port_id": self.port_id,
+ "type": "queue",
+ "enabled": False}
+
+ rc = self.transmit("set_rx_feature", params)
+ if rc.bad():
+ return self.err(rc.err())
+
+ return self.ok()
+
+
+ @owned
def pause (self):
if (self.state == self.STATE_PCAP_TX) :
@@ -610,9 +638,6 @@ class Port(object):
if rc.bad():
return self.err(rc.err())
-
- #self.attr.update(attr_dict)
-
return self.ok()
@owned
@@ -693,27 +718,30 @@ class Port(object):
print("\n")
# generate formatted (console friendly) port info
- def get_formatted_info (self):
+ def get_formatted_info (self, sync = True):
- # sync the attributes
- self.sync()
+ # sync the status
+ if sync:
+ self.sync()
+
+ attr = self.attr
info = dict(self.info)
info['status'] = self.get_port_state_name()
- if 'link' in self.attr:
- info['link'] = 'UP' if self.attr['link']['up'] else 'DOWN'
+ if 'link' in attr:
+ info['link'] = 'UP' if attr['link']['up'] else 'DOWN'
else:
info['link'] = 'N/A'
- if 'fc' in self.attr:
- info['fc'] = FLOW_CTRL_DICT_REVERSED.get(self.attr['fc']['mode'], 'N/A')
+ if 'fc' in attr:
+ info['fc'] = FLOW_CTRL_DICT_REVERSED.get(attr['fc']['mode'], 'N/A')
else:
info['fc'] = 'N/A'
- if 'promiscuous' in self.attr:
- info['prom'] = "on" if self.attr['promiscuous']['enabled'] else "off"
+ if 'promiscuous' in attr:
+ info['prom'] = "on" if attr['promiscuous']['enabled'] else "off"
else:
info['prom'] = "N/A"
@@ -740,28 +768,37 @@ class Port(object):
else:
info['is_virtual'] = 'N/A'
- if 'speed' in self.attr:
+ if 'speed' in attr:
info['speed'] = self.get_formatted_speed()
else:
info['speed'] = 'N/A'
- # RX info
- if 'rx_filter_mode' in self.attr:
- info['rx_filter_mode'] = 'Hardware Match' if self.attr['rx_filter_mode'] == 'hw' else 'Fetch All'
+ if 'rx_filter_mode' in attr:
+ info['rx_filter_mode'] = 'Hardware Match' if attr['rx_filter_mode'] == 'hw' else 'Fetch All'
else:
info['rx_filter_mode'] = 'N/A'
- if 'sniffer' in self.rx_info:
- sniffer = self.rx_info['sniffer']
- if sniffer['is_active']:
- info['rx_sniffer'] = '{0}\n[{1} / {2}]'.format(sniffer['pcap_filename'], sniffer['count'], sniffer['limit'])
- else:
- info['rx_sniffer'] = 'off'
+ # RX info
+ rx_info = self.status['rx_info']
+
+
+ # RX sniffer
+ if 'sniffer' in rx_info:
+ sniffer = rx_info['sniffer']
+ info['rx_sniffer'] = '{0}\n[{1} / {2}]'.format(sniffer['pcap_filename'], sniffer['count'], sniffer['limit']) if sniffer['is_active'] else 'off'
else:
info['rx_sniffer'] = 'N/A'
+ # RX queue
+ if 'queue' in rx_info:
+ queue = rx_info['queue']
+ info['rx_queue'] = '[{0} / {1}]'.format(queue['count'], queue['size']) if queue['is_active'] else 'off'
+ else:
+ info['rx_queue'] = 'off'
+
+
return info
@@ -793,7 +830,7 @@ class Port(object):
"flow ctrl" : info['fc'],
"RX Filter Mode": info['rx_filter_mode'],
- "RX Queueing": 'off',
+ "RX Queueing": info['rx_queue'],
"RX sniffer": info['rx_sniffer'],
}