summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-11-09 18:19:09 +0200
committerimarom <imarom@cisco.com>2016-11-09 18:19:09 +0200
commitab28fccc187c6134eeb0400ce0b113a77e498bb2 (patch)
tree8ac54ad7a53992fb25e48d14eee274a2fdab3f37 /scripts/automation
parentd09b123992f990a6c219dd47707cc703fe9055b5 (diff)
RX features - added port attributes for IPv4 and DG
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py94
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py23
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py10
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py7
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py8
5 files changed, 106 insertions, 36 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 b607ce23..d4d09cd7 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
@@ -12,7 +12,7 @@ from .trex_stl_types import *
from .trex_stl_async_client import CTRexAsyncClient
from .utils import parsing_opts, text_tables, common
-from .utils.common import list_intersect, list_difference, is_sub_list, PassiveTimer
+from .utils.common import list_intersect, list_difference, is_sub_list, PassiveTimer, is_valid_ipv4
from .utils.text_opts import *
from functools import wraps
@@ -336,7 +336,7 @@ class EventsHandler(object):
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]
+ new_val = new_info.get(key, 'N/A')
if old_val != new_val:
ev += '\n {key}: {old} -> {new}'.format(
key = key,
@@ -811,8 +811,8 @@ class STLClient(object):
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))
+ for port_id, port_attr_dict in zip(port_id_list, attr_dict):
+ rc.add(self.ports[port_id].set_attr(port_attr_dict))
return rc
@@ -1775,6 +1775,9 @@ class STLClient(object):
self.reset(ports = [0, 1])
+ self.set_port_attr(ports = [0, 1], ipv4 = ['5.5.5.5', '6.6.6.6'])
+ return
+
self.set_rx_queue(ports = [0], size = 1000, rxf = 'all')
#base_pkt = Ether()/ARP()/('x'*50)
@@ -1914,7 +1917,7 @@ class STLClient(object):
@__api_check(True)
- def reset(self, ports = None):
+ def reset(self, ports = None, restart = False):
"""
Force acquire ports, stop the traffic, remove all streams and clear stats
@@ -1922,7 +1925,9 @@ class STLClient(object):
ports : list
Ports on which to execute the command
-
+ restart: bool
+ Restart the NICs (link down / up)
+
:raises:
+ :exc:`STLError`
@@ -1939,7 +1944,7 @@ class STLClient(object):
self.clear_stats(ports)
self.set_port_attr(ports,
promiscuous = False,
- #link_up = True,
+ link_up = True if restart else None,
rxf = 'hw')
self.remove_rx_sniffer(ports)
self.remove_rx_queue(ports)
@@ -2720,16 +2725,23 @@ class STLClient(object):
link_up = None,
led_on = None,
flow_ctrl = None,
- rxf = None):
+ rxf = None,
+ ipv4 = None,
+ default_gateway = None,
+ ):
"""
Set port attributes
:parameters:
- promiscuous - True or False
- link_up - True or False
- led_on - True or False
- flow_ctrl - 0: disable all, 1: enable tx side, 2: enable rx side, 3: full enable
- rxf - 'hw' for hardware rules matching packets only or 'all' all packets
+ promiscuous - True or False
+ link_up - True or False
+ led_on - True or False
+ flow_ctrl - 0: disable all, 1: enable tx side, 2: enable rx side, 3: full enable
+ rxf - 'hw' for hardware rules matching packets only or 'all' all packets
+ ipv4 - configure IPv4 address for port(s). for multiple ports should be a list
+ of IPv4 addresses in the same length of the ports array
+ default_gateway - configure default gateway for port(s). for multiple ports should be a list
+ in the same length of the ports array
:raises:
+ :exe:'STLError'
@@ -2744,22 +2756,55 @@ class STLClient(object):
validate_type('led_on', led_on, (bool, type(None)))
validate_type('flow_ctrl', flow_ctrl, (int, type(None)))
validate_choice('rxf', rxf, ['hw', 'all'])
-
- # build attributes
- attr_dict = {}
+
+ # common attributes for all ports
+ cmn_attr_dict = {}
if promiscuous is not None:
- attr_dict['promiscuous'] = {'enabled': promiscuous}
+ cmn_attr_dict['promiscuous'] = {'enabled': promiscuous}
+
if link_up is not None:
- attr_dict['link_status'] = {'up': link_up}
+ cmn_attr_dict['link_status'] = {'up': link_up}
+
if led_on is not None:
- attr_dict['led_status'] = {'on': led_on}
+ cmn_attr_dict['led_status'] = {'on': led_on}
+
if flow_ctrl is not None:
- attr_dict['flow_ctrl_mode'] = {'mode': flow_ctrl}
+ cmn_attr_dict['flow_ctrl_mode'] = {'mode': flow_ctrl}
+
if rxf is not None:
- attr_dict['rx_filter_mode'] = {'mode': rxf}
+ cmn_attr_dict['rx_filter_mode'] = {'mode': rxf}
+ # each port starts with a set of the common attributes
+ attr_dict = [dict(cmn_attr_dict) for _ in ports]
+
+ # IPv4
+ if ipv4 is not None:
+ ipv4_list = listify(ipv4)
+
+ if len(ipv4_list) != len(ports):
+ raise STLError("'ipv4' must be a list in the same length of ports - 'ports': {0}, 'ip': {1}".format(ports, ipv4_list))
+
+ for ipv4, port_attr in zip(ipv4_list, attr_dict):
+ if not is_valid_ipv4(ipv4):
+ raise STLError("invalid IPv4 address provided: '{0}'".format(ipv4))
+ port_attr['ipv4'] = {'addr': ipv4}
+
+
+ # default gateway
+ if default_gateway is not None:
+ dg_list = listfy(default_gateway)
+
+ if len(dg_list) != len(ports):
+ raise STLError("'default_gateway' must be a list in the same length of ports - 'ports': {0}, 'default_gateway': {1}".format(ports, dg_list))
+
+ for dg, port_attr in zip(dg_list, attr_dict):
+ if not is_valid_ipv4(dg):
+ raise STLError("invalid IPv4 address provided: '{0}'".format(ipv4))
+ port_attr['default_gateway'] = {'addr': dg}
+
+
# no attributes to set
- if not attr_dict:
+ if not any(attr_dict):
return
self.logger.pre_cmd("Applying attributes on port(s) {0}:".format(ports))
@@ -3076,13 +3121,14 @@ class STLClient(object):
parser = parsing_opts.gen_parser(self,
"reset",
self.reset_line.__doc__,
- parsing_opts.PORT_LIST_WITH_ALL)
+ parsing_opts.PORT_LIST_WITH_ALL,
+ parsing_opts.PORT_RESTART)
opts = parser.parse_args(line.split(), default_ports = self.get_acquired_ports(), verify_acquired = True)
if not opts:
return opts
- self.reset(ports = opts.ports)
+ self.reset(ports = opts.ports, restart = opts.restart)
return RC_OK()
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 96c5e832..418ee5a6 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
@@ -785,10 +785,15 @@ class Port(object):
else:
info['rx_filter_mode'] = 'N/A'
+
+ info['mac_addr'] = attr.get('mac_addr', 'N/A')
+ info['ipv4'] = attr.get('ipv4', 'N/A')
+ info['default_gateway'] = attr.get('default_gateway', 'N/A')
+ info['next_hop_mac'] = attr.get('next_hop_mac', 'N/A')
+
# RX info
rx_info = self.status['rx_info']
-
# RX sniffer
if 'sniffer' in rx_info:
sniffer = rx_info['sniffer']
@@ -819,16 +824,18 @@ class Port(object):
info = self.get_formatted_info()
- return {"driver": info['driver'],
- "description": info.get('description', 'N/A')[:18],
- "HW src mac": info['hw_macaddr'],
- "SW src mac": info['src_macaddr'],
- "SW dst mac": info['dst_macaddr'],
- "PCI Address": info['pci_addr'],
- "NUMA Node": info['numa'],
+ return {"driver": info['driver'],
+ "description": info.get('description', 'N/A')[:18],
+ "MAC addr": info['mac_addr'],
+ "Next hop MAC": info['next_hop_mac'],
+ "IPv4": info['ipv4'],
+ "Default gateway": info['default_gateway'],
+ "PCI Address": info['pci_addr'],
+ "NUMA Node": info['numa'],
"--": "",
"---": "",
"----": "",
+ "-----": "",
"link speed": info['speed'],
"port status": info['status'],
"link status": info['link'],
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
index 5e71b7f2..55620689 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
@@ -670,13 +670,15 @@ class CTRexInfoGenerator(object):
("promiscuous", []),
("flow ctrl", []),
("--", []),
- ("HW src mac", []),
- ("SW src mac", []),
- ("SW dst mac", []),
+ ("MAC addr", []),
+ ("Next hop MAC", []),
("---", []),
+ ("IPv4", []),
+ ("Default gateway", []),
+ ("----", []),
("PCI Address", []),
("NUMA Node", []),
- ("----", []),
+ ("-----", []),
("RX Filter Mode", []),
("RX Queueing", []),
("RX sniffer", []),
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
index 72ee8972..f0da9a08 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
@@ -3,6 +3,7 @@ import sys
import string
import random
import time
+import socket
try:
import pwd
@@ -86,3 +87,9 @@ class PassiveTimer(object):
return (time.time() > self.expr_sec)
+def is_valid_ipv4 (addr):
+ try:
+ socket.inet_pton(socket.AF_INET, addr)
+ return True
+ except socket.error:
+ return False
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 715a741e..b93a797d 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
@@ -45,9 +45,11 @@ FLOW_CTRL = 28
SUPPORTED = 29
RX_FILTER_MODE = 30
+
OUTPUT_FILENAME = 31
ALL_FILES = 32
LIMIT = 33
+PORT_RESTART = 34
GLOBAL_STATS = 50
PORT_STATS = 51
@@ -322,6 +324,12 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
'type': str}),
+ PORT_RESTART: ArgumentPack(['-r', '--restart'],
+ {'help': 'hard restart port(s)',
+ 'dest': 'restart',
+ 'default': False,
+ 'action': 'store_true'}),
+
ALL_FILES: ArgumentPack(['--all'],
{'help': 'change RX port filter to fetch all packets',