summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-06 21:16:27 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-06 21:16:27 +0200
commitdf1e9dba223530013f851287a3a3a85abd076727 (patch)
tree3287b2623908a065313cb77cd2902e02cc8efb78 /scripts/automation/trex_control_plane/stl/trex_stl_lib
parent6b3fabf419252d33a5c11a21cef85fdb6c19284c (diff)
STL API: ping_ip returns data + formatted string and status
Regression: add test for IPv6 ping and scan Change-Id: Ic9d15f0b7ea44fcc11336b95c012ceaa04af9e2d Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib')
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_icmp.py16
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_ipv6.py24
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py30
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py2
4 files changed, 62 insertions, 10 deletions
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 612b6a2d..8d4e2f57 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
@@ -14,6 +14,7 @@ class RXServiceICMP(RXServiceAPI):
super(RXServiceICMP, self).__init__(port, layer_mode = RXServiceAPI.LAYER_MODE_L3, *a, **k)
self.ping_ip = ping_ip
self.pkt_size = pkt_size
+ self.result = {}
def get_name (self):
return "PING"
@@ -61,14 +62,21 @@ class RXServiceICMP(RXServiceAPI):
# check seq
if icmp.seq != self.base_pkt['ICMP'].seq:
return None
- return self.port.ok('Reply from {0}: bytes={1}, time={2:.2f}ms, TTL={3}'.format(ip.src, len(pkt['binary']), dt * 1000, ip.ttl))
+ self.result['formatted_string'] = 'Reply from {0}: bytes={1}, time={2:.2f}ms, TTL={3}'.format(ip.src, len(pkt['binary']), dt * 1000, ip.ttl)
+ self.result['src_ip'] = ip.src
+ self.result['rtt'] = dt * 1000
+ self.result['ttl'] = ip.ttl
+ self.result['status'] = 'success'
+ return self.port.ok(self.result)
# unreachable
elif icmp.type == 3:
# check seq
if icmp.payload.seq != self.base_pkt['ICMP'].seq:
return None
- return self.port.ok('Reply from {0}: Destination host unreachable'.format(icmp.src))
+ self.result['formatted_string'] = 'Reply from {0}: Destination host unreachable'.format(icmp.src)
+ self.result['status'] = 'unreachable'
+ return self.port.ok(self.result)
else:
# skip any other types
@@ -79,5 +87,7 @@ class RXServiceICMP(RXServiceAPI):
# return the str of a timeout err
def on_timeout(self):
- return self.port.ok('Request timed out.')
+ self.result['formatted_string'] = 'Request timed out.'
+ self.result['status'] = 'timeout'
+ return self.port.ok(self.result)
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_ipv6.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_ipv6.py
index c2c8ebc1..b76f523c 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_ipv6.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services/trex_stl_rx_service_ipv6.py
@@ -126,6 +126,7 @@ class RXServiceICMPv6(RXServiceIPv6):
super(RXServiceICMPv6, self).__init__(port, *a, **k)
self.pkt_size = pkt_size
self.dst_mac = dst_mac
+ self.result = {}
def get_name(self):
return 'PING6'
@@ -159,21 +160,38 @@ class RXServiceICMPv6(RXServiceIPv6):
node_ip = scapy_pkt.getlayer(IPv6).src
hlim = scapy_pkt.getlayer(IPv6).hlim
dst_ip = scapy_pkt.getlayer(IPv6).dst
-
if dst_ip != self.src_ip: # not our ping
return
dt = pkt['ts'] - start_ts
- return self.port.ok('Reply from {0}: bytes={1}, time={2:.2f}ms, hlim={3}'.format(node_ip, len(pkt['binary']), dt * 1000, hlim))
+ self.result['formatted_string'] = 'Reply from {0}: bytes={1}, time={2:.2f}ms, hlim={3}'.format(node_ip, len(pkt['binary']), dt * 1000, hlim)
+ self.result['src_ip'] = node_ip
+ self.result['rtt'] = dt * 1000
+ self.result['ttl'] = hlim
+ self.result['status'] = 'success'
+ return self.port.ok(self.result)
if scapy_pkt.haslayer('ICMPv6ND_NS') and scapy_pkt.haslayer('ICMPv6NDOptSrcLLAddr'):
node_mac = scapy_pkt.getlayer(ICMPv6NDOptSrcLLAddr).lladdr
node_ip = scapy_pkt.getlayer(IPv6).src
+ dst_ip = scapy_pkt.getlayer(IPv6).dst
+ if dst_ip != self.src_ip: # not our ping
+ return
self.send_intermediate(self.generate_ns_na(node_mac, node_ip))
+ if scapy_pkt.haslayer('ICMPv6DestUnreach'):
+ node_ip = scapy_pkt.getlayer(IPv6).src
+ dst_ip = scapy_pkt.getlayer(IPv6).dst
+ if dst_ip != self.src_ip: # not our ping
+ return
+ self.result['formatted_string'] = 'Reply from {0}: Destination host unreachable'.format(node_ip)
+ self.result['status'] = 'unreachable'
+ return self.port.ok(self.result)
# return the str of a timeout err
def on_timeout(self):
- return self.port.ok('Request timed out.')
+ self.result['formatted_string'] = 'Request timed out.'
+ self.result['status'] = 'timeout'
+ return self.port.ok(self.result)
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 a1290a37..e8feebbd 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
@@ -1916,6 +1916,23 @@ class STLClient(object):
pkt_size - packet size to use
count - how many times to ping
interval_sec - how much time to wait between pings
+
+ :returns:
+ List of replies per 'count'
+
+ Each element is dictionary with following items:
+
+ Always available keys:
+
+ * formatted_string - string, human readable output, for example: 'Request timed out.'
+ * status - string, one of options: 'success', 'unreachable', 'timeout'
+
+ Available only if status is 'success':
+
+ * src_ip - string, IP replying to request
+ * rtt - float, latency of the ping (round trip time)
+ * ttl - int, time to live in IPv4 or hop limit in IPv6
+
:raises:
+ :exc:`STLError`
@@ -1938,6 +1955,7 @@ class STLClient(object):
src_port,
pkt_size))
+ responses_arr = []
# no async messages
with self.logger.supress(level = LoggerApi.VERBOSE_REGULAR_SYNC):
self.logger.log('')
@@ -1954,10 +1972,13 @@ class STLClient(object):
if not rc:
raise STLError(rc)
- self.logger.log(rc.data())
+ responses_arr.append(rc.data())
+ self.logger.log(rc.data()['formatted_string'])
if i != (count - 1):
time.sleep(interval_sec)
+
+ return responses_arr
@@ -3148,9 +3169,10 @@ class STLClient(object):
verbose - log for each request the response
:return:
list of dictionaries per neighbor:
- type - type of device: 'Router' or 'Host'
- mac - MAC address of device
- ipv6 - IPv6 address of device
+
+ * type - type of device: 'Router' or 'Host'
+ * mac - MAC address of device
+ * ipv6 - IPv6 address of device
:raises:
+ :exe:'STLError'
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
index 8d727d6d..7761be4d 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
@@ -926,6 +926,8 @@ class STLProfile(object):
# fetch defaults
defaults = func.__defaults__
+ if defaults is None:
+ return {}
if len(defaults) != (argc - 1):
raise STLError("Module should provide default values for all arguments on get_streams()")