summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-12-25 12:54:09 +0200
committerimarom <imarom@cisco.com>2016-12-25 13:50:56 +0200
commit34cb66c9f06c7a43e68a17b4a8802f8d34298a65 (patch)
treeaa6b081213e5715cf09a18503cc7b0a20168c6fc /scripts/automation/trex_control_plane/stl
parent549f2750ab22db5695a8d29575c136ab06e37235 (diff)
refactor layer config on prot attributes
added guard against unconfigured MAC when going up with empty config file Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py9
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_arp.py15
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py8
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py9
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py16
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py14
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py91
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py5
8 files changed, 84 insertions, 83 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 627761ff..7d47128b 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -373,8 +373,13 @@ class TRexConsole(TRexGeneralCmd):
print("No ports acquired\n")
return
- with self.stateless_client.logger.supress():
- table = stl_map_ports(self.stateless_client, ports = ports)
+
+ try:
+ with self.stateless_client.logger.supress():
+ table = stl_map_ports(self.stateless_client, ports = ports)
+ except STLError as e:
+ print(format_text(e.brief() + "\n", 'bold'))
+ return
print(format_text('\nAcquired ports topology:\n', 'bold', 'underline'))
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_arp.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_arp.py
index 2c159313..3cf97045 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_arp.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_arp.py
@@ -16,15 +16,16 @@ class RXServiceARP(RXServiceAPI):
def pre_execute (self):
- self.dst = self.port.get_dst_addr()
- self.src = self.port.get_src_addr()
-
+ self.layer_cfg = dict(self.port.get_layer_cfg())
return self.port.ok()
# return a list of streams for request
def generate_request (self):
- base_pkt = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(psrc = self.src['ipv4'], pdst = self.dst['ipv4'], hwsrc = self.src['mac'])
+ base_pkt = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(psrc = self.layer_cfg['ipv4']['src'],
+ pdst = self.layer_cfg['ipv4']['dst'],
+ hwsrc = self.layer_cfg['ether']['src'])
+
s1 = STLStream( packet = STLPktBuilder(pkt = base_pkt), mode = STLTXSingleBurst(total_pkts = 1) )
return [s1]
@@ -41,13 +42,11 @@ class RXServiceARP(RXServiceAPI):
arp = scapy_pkt['ARP']
# check this is the right ARP (ARP reply with the address)
- if (arp.op != 2) or (arp.psrc != self.dst['ipv4']):
+ if (arp.op != 2) or (arp.psrc != self.layer_cfg['ipv4']['dst']):
return None
-
+ # return the data gathered from the ARP response
return self.port.ok({'psrc' : arp.psrc, 'hwsrc': arp.hwsrc})
-
- #return self.port.ok('Port {0} - Recieved ARP reply from: {1}, hw: {2}'.format(self.port.port_id, arp.psrc, arp.hwsrc))
def on_timeout_err (self, retries):
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py
index 486cd458..be5b6665 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py
@@ -23,9 +23,7 @@ class RXServiceICMP(RXServiceAPI):
if not self.port.is_resolved():
return self.port.err('ping - port has an unresolved destination, cannot determine next hop MAC address')
- self.src = self.port.get_src_addr()
- self.dst = self.port.get_dst_addr()
-
+ self.layer_cfg = dict(self.port.get_layer_cfg())
return self.port.ok()
@@ -33,7 +31,7 @@ class RXServiceICMP(RXServiceAPI):
# return a list of streams for request
def generate_request (self):
- base_pkt = Ether(dst = self.dst['mac'])/IP(src = self.src['ipv4'], dst = self.ping_ip)/ICMP(type = 8)
+ base_pkt = Ether(dst = self.layer_cfg['ether']['dst'])/IP(src = self.layer_cfg['ipv4']['src'], dst = self.layer_cfg['ipv4']['dst'])/ICMP(type = 8)
pad = max(0, self.pkt_size - len(base_pkt))
base_pkt = base_pkt / (pad * 'x')
@@ -51,7 +49,7 @@ class RXServiceICMP(RXServiceAPI):
return None
ip = scapy_pkt['IP']
- if ip.dst != self.src['ipv4']:
+ if ip.dst != self.layer_cfg['ipv4']['src']:
return None
icmp = scapy_pkt['ICMP']
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 f86fff26..79ed3a36 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
@@ -1396,8 +1396,13 @@ class STLClient(object):
def get_resolvable_ports (self):
return [port_id
for port_id, port_obj in self.ports.items()
- if port_obj.is_acquired() and port_obj.get_dst_addr()['ipv4'] is not None]
-
+ if port_obj.is_acquired() and port_obj.is_l3_mode()]
+
+ def get_resolved_ports (self):
+ return [port_id
+ for port_id, port_obj in self.ports.items()
+ if port_obj.is_acquired() and port_obj.is_resolved()]
+
def get_service_enabled_ports(self):
return [port_id
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
index 464869aa..cf594948 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
@@ -1089,10 +1089,10 @@ def generate_packet(**user_kwargs):
fix_ipv4_checksum = True
ip_src_addr = kwargs['ip_src_addr']
if type(ip_src_addr) is str:
- ip_src_addr = ipv4_str_to_num(is_valid_ipv4(ip_src_addr))
+ ip_src_addr = ipv4_str_to_num(is_valid_ipv4_ret(ip_src_addr))
step = kwargs['ip_src_step']
if type(step) is str:
- step = ipv4_str_to_num(is_valid_ipv4(step))
+ step = ipv4_str_to_num(is_valid_ipv4_ret(step))
if step < 1:
raise STLError('ip_src_step has to be at least 1')
@@ -1129,11 +1129,11 @@ def generate_packet(**user_kwargs):
fix_ipv4_checksum = True
ip_dst_addr = kwargs['ip_dst_addr']
if type(ip_dst_addr) is str:
- ip_dst_addr = ipv4_str_to_num(is_valid_ipv4(ip_dst_addr))
+ ip_dst_addr = ipv4_str_to_num(is_valid_ipv4_ret(ip_dst_addr))
step = kwargs['ip_dst_step']
if type(step) is str:
- step = ipv4_str_to_num(is_valid_ipv4(step))
+ step = ipv4_str_to_num(is_valid_ipv4_ret(step))
if step < 1:
raise STLError('ip_dst_step has to be at least 1')
@@ -1188,11 +1188,11 @@ def generate_packet(**user_kwargs):
if count < 0:
raise STLError('ipv6_src_count has to be at least 1')
if count > 0 or kwargs['ipv6_src_mode'] == 'random':
- ipv6_src_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_src_addr'])[-4:])
+ ipv6_src_addr_num = ipv4_str_to_num(is_valid_ipv6_ret(kwargs['ipv6_src_addr'])[-4:])
step = kwargs['ipv6_src_step']
if type(step) is str: # convert ipv6 step to number
- step = ipv4_str_to_num(is_valid_ipv6(step)[-4:])
+ step = ipv4_str_to_num(is_valid_ipv6_ret(step)[-4:])
if step < 1:
raise STLError('ipv6_src_step has to be at least 1')
@@ -1226,11 +1226,11 @@ def generate_packet(**user_kwargs):
if count < 0:
raise STLError('ipv6_dst_count has to be at least 1')
if count > 0 or kwargs['ipv6_dst_mode'] == 'random':
- ipv6_dst_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_dst_addr'])[-4:])
+ ipv6_dst_addr_num = ipv4_str_to_num(is_valid_ipv6_ret(kwargs['ipv6_dst_addr'])[-4:])
step = kwargs['ipv6_dst_step']
if type(step) is str: # convert ipv6 step to number
- step = ipv4_str_to_num(is_valid_ipv6(step)[-4:])
+ step = ipv4_str_to_num(is_valid_ipv6_ret(step)[-4:])
if step < 1:
raise STLError('ipv6_dst_step has to be at least 1')
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
index 6431b74a..c5fbab90 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
@@ -57,7 +57,7 @@ def mac_str_to_num (mac_buffer):
return _buffer_to_num(mac_buffer)
-def is_valid_ipv4(ip_addr):
+def is_valid_ipv4_ret(ip_addr):
"""
Return buffer in network order
"""
@@ -75,7 +75,7 @@ def is_valid_ipv4(ip_addr):
raise CTRexPacketBuildException(-10,"Not valid ipv4 format");
-def is_valid_ipv6(ipv6_addr):
+def is_valid_ipv6_ret(ipv6_addr):
"""
Return buffer in network order
"""
@@ -136,8 +136,8 @@ class CTRexScIpv4SimpleRange(CTRexScFieldRangeBase):
super(CTRexScIpv4SimpleRange, self).__init__(field_name,field_type)
self.min_ip = min_ip
self.max_ip = max_ip
- mmin=ipv4_str_to_num (is_valid_ipv4(min_ip))
- mmax=ipv4_str_to_num (is_valid_ipv4(max_ip))
+ mmin=ipv4_str_to_num (is_valid_ipv4_ret(min_ip))
+ mmax=ipv4_str_to_num (is_valid_ipv4_ret(max_ip))
if mmin > mmax :
raise CTRexPacketBuildException(-11, 'CTRexScIpv4SimpleRange m_min ip is bigger than max');
@@ -152,8 +152,8 @@ class CTRexScIpv4TupleGen(CTRexScriptsBase):
super(CTRexScIpv4TupleGen, self).__init__()
self.min_ip = min_ipv4
self.max_ip = max_ipv4
- mmin=ipv4_str_to_num (is_valid_ipv4(min_ipv4))
- mmax=ipv4_str_to_num (is_valid_ipv4(max_ipv4))
+ mmin=ipv4_str_to_num (is_valid_ipv4_ret(min_ipv4))
+ mmax=ipv4_str_to_num (is_valid_ipv4_ret(max_ipv4))
if mmin > mmax :
raise CTRexPacketBuildException(-11, 'CTRexScIpv4SimpleRange m_min ip is bigger than max');
@@ -619,7 +619,7 @@ def convert_val (val):
if is_integer(val):
return val
if type(val) == str:
- return ipv4_str_to_num (is_valid_ipv4(val))
+ return ipv4_str_to_num (is_valid_ipv4_ret(val))
raise CTRexPacketBuildException(-11,("init val invalid %s ") % val );
def check_for_int (val):
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 d4275cb1..07587b9f 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
@@ -539,14 +539,14 @@ class Port(object):
@writeable
- def set_l3_mode (self, src_addr, dest_addr, resolved_mac = None):
+ def set_l3_mode (self, src_addr, dst_addr, resolved_mac = None):
if not self.is_service_mode_on():
return self.err('port service mode must be enabled for configuring L3 mode. Please enable service mode')
params = {"handler": self.handler,
"port_id": self.port_id,
"src_addr": src_addr,
- "dst_addr": dest_addr}
+ "dst_addr": dst_addr}
if resolved_mac:
params["resolved_mac"] = resolved_mac
@@ -767,7 +767,10 @@ class Port(object):
if not self.is_l3_mode():
return self.err('port is not configured with L3')
- return self.set_l3_mode(self.get_src_addr()['ipv4'], self.get_dst_addr()['ipv4'])
+ layer_cfg = self.get_layer_cfg()
+
+ # reconfigure server with unresolved IPv4 information
+ return self.set_l3_mode(layer_cfg['ipv4']['src'], layer_cfg['ipv4']['dst'])
@@ -869,29 +872,32 @@ class Port(object):
# RX filter mode
info['rx_filter_mode'] = 'hardware match' if attr['rx_filter_mode'] == 'hw' else 'fetch all'
- info['layer_mode'] = 'IPv4' if self.is_l3_mode() else 'Ethernet'
-
- # src MAC and IPv4
- info['src_mac'] = attr['src_mac']
- info['src_ipv4'] = attr['src_ipv4']
+ # holds the information about all the layers configured for the port
+ layer_cfg = attr['layer_cfg']
+
+ info['src_mac'] = attr['layer_cfg']['ether']['src']
+
+ # pretty show per mode
- if info['src_ipv4'] is None:
- info['src_ipv4'] = '-'
-
- # dest
- dest = attr['dest']
- if dest['type'] == 'mac':
- info['dest'] = dest['mac']
- info['arp'] = '-'
+ if layer_cfg['ipv4']['state'] == 'none':
+ info['layer_mode'] = 'Ethernet'
+ info['src_ipv4'] = '-'
+ info['dest'] = layer_cfg['ether']['dst'] if layer_cfg['ether']['state'] == 'configured' else 'unconfigured'
+ info['arp'] = '-'
- elif dest['type'] == 'ipv4':
- info['dest'] = dest['ipv4']
- info['arp'] = dest['arp']
+ elif layer_cfg['ipv4']['state'] == 'unresolved':
+ info['layer_mode'] = 'IPv4'
+ info['src_ipv4'] = layer_cfg['ipv4']['src']
+ info['dest'] = layer_cfg['ipv4']['dst']
+ info['arp'] = 'unresolved'
- elif dest['type'] == 'ipv4_u':
- info['dest'] = dest['ipv4']
- info['arp'] = 'unresolved'
+ elif layer_cfg['ipv4']['state'] == 'resolved':
+ info['layer_mode'] = 'IPv4'
+ info['src_ipv4'] = layer_cfg['ipv4']['src']
+ info['dest'] = layer_cfg['ipv4']['dst']
+ info['arp'] = layer_cfg['ether']['dst']
+
# RX info
rx_info = self.status['rx_info']
@@ -919,41 +925,24 @@ class Port(object):
def get_port_state_name(self):
return self.STATES_MAP.get(self.state, "Unknown")
- def get_src_addr (self):
- src_mac = self.__attr['src_mac']
- src_ipv4 = self.__attr['src_ipv4']
-
- return {'mac': src_mac, 'ipv4': src_ipv4}
+ def get_layer_cfg (self):
+ return self.__attr['layer_cfg']
def get_rx_filter_mode (self):
return self.__attr['rx_filter_mode']
- def get_dst_addr (self):
- dest = self.__attr['dest']
-
- if dest['type'] == 'mac':
- return {'ipv4': None, 'mac': dest['mac']}
-
- elif dest['type'] == 'ipv4':
- return {'ipv4': dest['ipv4'], 'mac': dest['arp']}
-
- elif dest['type'] == 'ipv4_u':
- return {'ipv4': dest['ipv4'], 'mac': None}
-
- else:
- assert(0)
-
def is_l3_mode (self):
- return self.get_dst_addr()['ipv4'] is not None
+ return self.get_layer_cfg()['ipv4']['state'] != 'none'
- # port is considered resolved if it's dest is either MAC or resolved IPv4
def is_resolved (self):
- return (self.get_dst_addr()['mac'] is not None)
+ # for L3
+ if self.is_l3_mode():
+ return self.get_layer_cfg()['ipv4']['state'] != 'unresolved'
+ # for L2
+ else:
+ return self.get_layer_cfg()['ether']['state'] != 'unconfigured'
+
- # return True if the port is valid for resolve (has an IPv4 address as dest)
- def is_resolvable (self):
- return (self.get_dst_addr()['ipv4'] is not None)
-
@writeable
def arp_resolve (self, retries):
@@ -971,7 +960,7 @@ class Port(object):
return rc
# update the port with L3 full configuration
- rc = self.set_l3_mode(self.get_src_addr()['ipv4'], self.get_dst_addr()['ipv4'], arp_rc['hwsrc'])
+ rc = self.set_l3_mode(self.get_layer_cfg()['ipv4']['src'], self.get_layer_cfg()['ipv4']['dst'], arp_rc['hwsrc'])
if not rc:
return rc
@@ -996,7 +985,7 @@ class Port(object):
"description": info.get('description', 'N/A')[:18],
"src MAC": info['src_mac'],
"src IPv4": info['src_ipv4'],
- "Destination": info['dest'],
+ "Destination": format_text("{0}".format(info['dest']), 'bold', 'red' if info['dest'] == 'unconfigured' else None),
"ARP Resolution": format_text("{0}".format(info['arp']), 'bold', 'red' if info['arp'] == 'unresolved' else None),
"PCI Address": info['pci_addr'],
"NUMA Node": info['numa'],
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 30fdb2dd..16f10026 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
@@ -1,5 +1,6 @@
from .trex_stl_streams import *
from .trex_stl_packet_builder_scapy import *
+from .utils.common import *
# map ports
# will destroy all streams/data on the ports
@@ -8,6 +9,10 @@ def stl_map_ports (client, ports = None):
if ports is None:
ports = client.get_all_ports()
+ unresolved_ports = list_difference(ports, client.get_resolved_ports())
+ if unresolved_ports:
+ raise STLError("Port(s) {0} have unresolved destination addresses".format(unresolved_ports))
+
stl_send_3_pkts(client, ports)
tx_pkts = {}