Remove Interface.close, rename script argument 82/382/2
authorJuraj Sloboda <jsloboda@cisco.com>
Mon, 22 Feb 2016 12:22:23 +0000 (13:22 +0100)
committerGerrit Code Review <gerrit@fd.io>
Tue, 23 Feb 2016 14:12:38 +0000 (14:12 +0000)
Change-Id: I5da20a12f801264821890e6516899344456576a8
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
resources/libraries/python/PacketVerifier.py
resources/libraries/robot/ipv4.robot
resources/traffic_scripts/arp_request.py
resources/traffic_scripts/ipv4_ping_ttl_check.py

index 19d6aaf..9af14e3 100644 (file)
@@ -291,10 +291,6 @@ class Interface(object):
     def recv_pkt(self, timeout=3):
         return self.rxq.recv(timeout, self.sent_packets)
 
     def recv_pkt(self, timeout=3):
         return self.rxq.recv(timeout, self.sent_packets)
 
-    def close(self):
-        #self.rxq._proc.terminate()
-        pass
-
 
 def create_gratuitous_arp_request(src_mac, src_ip):
     """Creates scapy representation of gratuitous ARP request"""
 
 def create_gratuitous_arp_request(src_mac, src_ip):
     """Creates scapy representation of gratuitous ARP request"""
index 4ed0181..d122932 100644 (file)
@@ -68,7 +68,7 @@
 | | ${args}= | Traffic Script Gen Arg | ${to_port} | ${from_port} | ${src_mac}
 | |          | ...                    | ${dst_mac} | ${src_ip} | ${dst_ip}
 | | ${args}= | Catenate | ${args} | --hops ${hops} | --first_hop_mac ${adj_int['mac_address']}
 | | ${args}= | Traffic Script Gen Arg | ${to_port} | ${from_port} | ${src_mac}
 | |          | ...                    | ${dst_mac} | ${src_ip} | ${dst_ip}
 | | ${args}= | Catenate | ${args} | --hops ${hops} | --first_hop_mac ${adj_int['mac_address']}
-| |          | ...      | --is_dst_defined ${is_dst_tg}
+| |          | ...      | --is_dst_tg ${is_dst_tg}
 | | Run Traffic Script On Node | ipv4_ping_ttl_check.py | ${from_node} | ${args}
 
 | Ipv4 icmp echo sweep
 | | Run Traffic Script On Node | ipv4_ping_ttl_check.py | ${from_node} | ${args}
 
 | Ipv4 icmp echo sweep
index 86a4c01..94d5dea 100755 (executable)
@@ -101,8 +101,6 @@ def arp_request_test():
 
     except RuntimeError as ex:
         print 'Error occurred: {}'.format(ex)
 
     except RuntimeError as ex:
         print 'Error occurred: {}'.format(ex)
-    finally:
-        interface.close()
 
     return test_passed
 
 
     return test_passed
 
index 54b6aa1..2f1ea25 100755 (executable)
@@ -21,9 +21,6 @@ from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
 
 def check_ttl(ttl_begin, ttl_end, ttl_diff):
     if ttl_begin != ttl_end + ttl_diff:
 
 def check_ttl(ttl_begin, ttl_end, ttl_diff):
     if ttl_begin != ttl_end + ttl_diff:
-        src_if.close()
-        if dst_if_defined:
-            dst_if.close()
         raise Exception(
             "TTL changed from {} to {} but decrease by {} expected"
             .format(ttl_begin, ttl_end, hops))
         raise Exception(
             "TTL changed from {} to {} but decrease by {} expected"
             .format(ttl_begin, ttl_end, hops))
@@ -39,18 +36,15 @@ def ckeck_packets_equal(pkt_send, pkt_recv):
         Ether(pkt_send_raw).show2()
         print "Received:"
         Ether(pkt_recv_raw).show2()
         Ether(pkt_send_raw).show2()
         print "Received:"
         Ether(pkt_recv_raw).show2()
-        src_if.close()
-        if dst_if_defined:
-            dst_if.close()
         raise Exception("Sent packet doesn't match received packet")
 
 
 args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip',
         raise Exception("Sent packet doesn't match received packet")
 
 
 args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip',
-                         'hops', 'first_hop_mac', 'is_dst_defined'])
+                         'hops', 'first_hop_mac', 'is_dst_tg'])
 
 src_if_name = args.get_arg('tx_if')
 dst_if_name = args.get_arg('rx_if')
 
 src_if_name = args.get_arg('tx_if')
 dst_if_name = args.get_arg('rx_if')
-dst_if_defined = True if args.get_arg('is_dst_defined') == 'True' else False
+is_dst_tg = True if args.get_arg('is_dst_tg') == 'True' else False
 
 src_mac = args.get_arg('src_mac')
 first_hop_mac = args.get_arg('first_hop_mac')
 
 src_mac = args.get_arg('src_mac')
 first_hop_mac = args.get_arg('first_hop_mac')
@@ -59,12 +53,12 @@ src_ip = args.get_arg('src_ip')
 dst_ip = args.get_arg('dst_ip')
 hops = int(args.get_arg('hops'))
 
 dst_ip = args.get_arg('dst_ip')
 hops = int(args.get_arg('hops'))
 
-if dst_if_defined and (src_if_name == dst_if_name):
+if is_dst_tg and (src_if_name == dst_if_name):
     raise Exception("Source interface name equals destination interface name")
 
 src_if = Interface(src_if_name)
 src_if.send_pkt(str(create_gratuitous_arp_request(src_mac, src_ip)))
     raise Exception("Source interface name equals destination interface name")
 
 src_if = Interface(src_if_name)
 src_if.send_pkt(str(create_gratuitous_arp_request(src_mac, src_ip)))
-if dst_if_defined:
+if is_dst_tg:
     dst_if = Interface(dst_if_name)
     dst_if.send_pkt(str(create_gratuitous_arp_request(dst_mac, dst_ip)))
 
     dst_if = Interface(dst_if_name)
     dst_if.send_pkt(str(create_gratuitous_arp_request(dst_mac, dst_ip)))
 
@@ -73,16 +67,10 @@ pkt_req_send = (Ether(src=src_mac, dst=first_hop_mac) /
                       ICMP())
 src_if.send_pkt(pkt_req_send)
 
                       ICMP())
 src_if.send_pkt(pkt_req_send)
 
-if dst_if_defined:
-    try:
-        pkt_req_recv = dst_if.recv_pkt()
-        if pkt_req_recv is None:
-            raise Exception('Timeout waiting for packet')
-    except:
-        src_if.close()
-        if dst_if_defined:
-            dst_if.close()
-        raise
+if is_dst_tg:
+    pkt_req_recv = dst_if.recv_pkt()
+    if pkt_req_recv is None:
+        raise Exception('Timeout waiting for packet')
 
     check_ttl(pkt_req_send[IP].ttl, pkt_req_recv[IP].ttl, hops)
     pkt_req_send_mod = pkt_req_send.copy()
 
     check_ttl(pkt_req_send[IP].ttl, pkt_req_recv[IP].ttl, hops)
     pkt_req_send_mod = pkt_req_send.copy()
@@ -95,23 +83,13 @@ if dst_if_defined:
                            ICMP(type=0))  # echo-reply
     dst_if.send_pkt(pkt_resp_send)
 
                            ICMP(type=0))  # echo-reply
     dst_if.send_pkt(pkt_resp_send)
 
-try:
-    pkt_resp_recv = src_if.recv_pkt()
-    if pkt_resp_recv is None:
-        raise Exception('Timeout waiting for packet')
-except:
-    src_if.close()
-    if dst_if_defined:
-        dst_if.close()
-    raise
+pkt_resp_recv = src_if.recv_pkt()
+if pkt_resp_recv is None:
+    raise Exception('Timeout waiting for packet')
 
 
-if dst_if_defined:
+if is_dst_tg:
     check_ttl(pkt_resp_send[IP].ttl, pkt_resp_recv[IP].ttl, hops)
     pkt_resp_send_mod = pkt_resp_send.copy()
     pkt_resp_send_mod[IP].ttl = pkt_resp_recv[IP].ttl
     del pkt_resp_send_mod[IP].chksum  # update checksum
     ckeck_packets_equal(pkt_resp_send_mod[IP], pkt_resp_recv[IP])
     check_ttl(pkt_resp_send[IP].ttl, pkt_resp_recv[IP].ttl, hops)
     pkt_resp_send_mod = pkt_resp_send.copy()
     pkt_resp_send_mod[IP].ttl = pkt_resp_recv[IP].ttl
     del pkt_resp_send_mod[IP].chksum  # update checksum
     ckeck_packets_equal(pkt_resp_send_mod[IP], pkt_resp_recv[IP])
-
-src_if.close()
-if dst_if_defined:
-    dst_if.close()