diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2017-02-06 21:16:27 +0200 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2017-02-06 21:16:27 +0200 |
commit | df1e9dba223530013f851287a3a3a85abd076727 (patch) | |
tree | 3287b2623908a065313cb77cd2902e02cc8efb78 /scripts/automation/trex_control_plane/stl/trex_stl_lib/rx_services | |
parent | 6b3fabf419252d33a5c11a21cef85fdb6c19284c (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/rx_services')
2 files changed, 34 insertions, 6 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) |