summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-02-25 09:54:45 -0500
committerimarom <imarom@cisco.com>2016-02-25 09:57:23 -0500
commitaaef3f95683bfa1574537c543e4ffc86afb0480f (patch)
tree01bf5d21786fb59d13338a75b644eb0fa9a5f20d /scripts/automation/trex_control_plane
parented7c04b5d7d5bb15aa13144e62caa786e73f7d05 (diff)
port attributes - promiscuous and etc.
Diffstat (limited to 'scripts/automation/trex_control_plane')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py6
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py82
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py30
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py21
4 files changed, 138 insertions, 1 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 0beb10df..53817464 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -332,6 +332,12 @@ class TRexConsole(TRexGeneralCmd):
def help_push (self):
return self.do_push("-h")
+ def do_portattr (self, line):
+ '''Change/show port(s) attributes\n'''
+ return self.stateless_client.set_port_attr_line(line)
+
+ def help_portattr (self):
+ return self.do_portattr("-h")
def do_history (self, line):
'''Manage the command history\n'''
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 fe162096..90a17ce2 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
@@ -609,6 +609,15 @@ class STLClient(object):
return rc
+ def __set_port_attr (self, port_id_list = None, attr_dict = None):
+
+ port_id_list = self.__ports(port_id_list)
+ rc = RC()
+
+ for port_id in port_id_list:
+ rc.add(self.ports[port_id].set_attr(attr_dict))
+
+ return rc
# connect to server
def __connect(self):
@@ -1639,6 +1648,47 @@ class STLClient(object):
raise STLTimeoutError(timeout)
+ #
+ """
+ set port(s) attributes
+
+ :parameters:
+ promiscuous - set this to True or False
+
+ :raises:
+ None
+
+ """
+ @__api_check(True)
+ def set_port_attr (self, ports = None, promiscuous = None):
+ # by default use all acquired 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())
+
+ # check arguments
+ validate_type('promiscuous', promiscuous, bool)
+
+ # build attributes
+ attr_dict = {}
+ if promiscuous is not None:
+ attr_dict['promiscuous'] = {'enabled': bool(promiscuous)}
+
+ # no attributes to set
+ if not attr_dict:
+ return
+
+ self.logger.pre_cmd("Applying attributes on port(s) {0}:".format(ports))
+ rc = self.__set_port_attr(ports, attr_dict)
+ self.logger.post_cmd(rc)
+
+ if not rc:
+ raise STLError(rc)
+
"""
clear all events
@@ -2022,3 +2072,35 @@ class STLClient(object):
return True
+
+
+ @__console
+ def set_port_attr_line (self, line):
+ '''Sets port attributes '''
+
+ parser = parsing_opts.gen_parser(self,
+ "port",
+ self.set_port_attr_line.__doc__,
+ parsing_opts.PORT_LIST_WITH_ALL,
+ parsing_opts.PROMISCUOUS_SWITCH)
+
+ opts = parser.parse_args(line.split())
+ if opts is None:
+ return
+
+ try:
+ self.set_port_attr(opts.ports, opts.prom)
+ except STLError as e:
+ print e.brief()
+ return
+
+ # show
+ print ""
+ for port_id in opts.ports:
+ print format_text('Port {0}:\n'.format(port_id), 'bold', 'underline')
+ for k, v in self.get_port(port_id).get_attr().iteritems():
+ print "{0}:".format(k)
+ for pk, pv in v.iteritems():
+ print " {0}: {1}".format(pk, format_text(str(pv), 'bold'))
+ print ""
+
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 4dd07a13..8d542b35 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
@@ -54,6 +54,7 @@ class Port(object):
self.streams = {}
self.profile = None
self.session_id = session_id
+ self.attr = {}
self.port_stats = trex_stl_stats.CPortStats(self)
@@ -138,6 +139,9 @@ class Port(object):
self.next_available_id = long(rc.data()['max_stream_id']) + 1
+ # attributes
+ self.attr = rc.data()['attr']
+
# sync the streams
params = {"port_id": self.port_id}
@@ -448,10 +452,34 @@ class Port(object):
return self.ok()
+ def set_attr (self, attr_dict):
+ if not self.is_acquired():
+ return self.err("port is not owned")
+
+ if (self.state == self.STATE_DOWN):
+ return self.err("port is down")
+
+ params = {"handler": self.handler,
+ "port_id": self.port_id,
+ "attr": attr_dict}
+
+ rc = self.transmit("set_port_attr", params)
+ if rc.bad():
+ return self.err(rc.err())
+
+
+ self.attr.update(attr_dict)
+
+ return self.ok()
+
+
+ def get_attr (self):
+ return self.attr
+
def get_profile (self):
return self.profile
-
+
def print_profile (self, mult, duration):
if not self.get_profile():
return
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
index 92e9a1d6..0c70801f 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
@@ -27,6 +27,9 @@ FULL_OUTPUT = 15
IPG = 16
SPEEDUP = 17
COUNT = 18
+PROMISCUOUS = 19
+NO_PROMISCUOUS = 20
+PROMISCUOUS_SWITCH = 21
GLOBAL_STATS = 50
PORT_STATS = 51
@@ -223,6 +226,19 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
'default': 1,
'type': int}),
+ PROMISCUOUS: ArgumentPack(['--prom'],
+ {'help': "sets port promiscuous on",
+ 'dest': "prom",
+ 'default': None,
+ 'action': "store_true"}),
+
+ NO_PROMISCUOUS: ArgumentPack(['--no_prom'],
+ {'help': "sets port promiscuous off",
+ 'dest': "prom",
+ 'default': None,
+ 'action': "store_false"}),
+
+
PORT_LIST: ArgumentPack(['--port'],
{"nargs": '+',
'dest':'ports',
@@ -305,6 +321,11 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
'default': []}),
+ # promiscuous
+ PROMISCUOUS_SWITCH: ArgumentGroup(MUTEX, [PROMISCUOUS,
+ NO_PROMISCUOUS],
+ {'required': False}),
+
# advanced options
PORT_LIST_WITH_ALL: ArgumentGroup(MUTEX, [PORT_LIST,
ALL_PORTS],