diff options
author | Jan Gelety <jgelety@cisco.com> | 2019-10-30 04:52:03 +0100 |
---|---|---|
committer | Peter Mikus <pmikus@cisco.com> | 2019-11-11 11:51:40 +0000 |
commit | a4cad14b7e0b7e94f9e80b1a45cd86b3bc09d0a0 (patch) | |
tree | 9ec0286524c2335dd526586c197ed333dbd7c4f4 /resources | |
parent | d5e00a369ffef5edf929ef5b03b7c544021b2e41 (diff) |
FIX: do not use ping in vpp-device tests
Change-Id: Ic11f863e7ffad70d45e6e8dc39c70efc62cecc96
Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources')
-rw-r--r-- | resources/libraries/python/TrafficScriptExecutor.py | 4 | ||||
-rw-r--r-- | resources/libraries/robot/crypto/ipsec.robot | 43 | ||||
-rw-r--r-- | resources/libraries/robot/l2/l2_traffic.robot | 79 | ||||
-rw-r--r-- | resources/libraries/robot/shared/traffic.robot | 53 | ||||
-rwxr-xr-x | resources/traffic_scripts/ipsec.py | 207 | ||||
-rwxr-xr-x | resources/traffic_scripts/send_ip_check_headers.py | 11 |
6 files changed, 201 insertions, 196 deletions
diff --git a/resources/libraries/python/TrafficScriptExecutor.py b/resources/libraries/python/TrafficScriptExecutor.py index 7b5368fa9f..abd97e6fc6 100644 --- a/resources/libraries/python/TrafficScriptExecutor.py +++ b/resources/libraries/python/TrafficScriptExecutor.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -68,6 +68,8 @@ class TrafficScriptExecutor(object): if ret_code != 0: if "RuntimeError: ICMP echo Rx timeout" in stderr: raise RuntimeError("ICMP echo Rx timeout") + elif "RuntimeError: IP packet Rx timeout" in stderr: + raise RuntimeError("IP packet Rx timeout") elif "RuntimeError: DHCP REQUEST Rx timeout" in stderr: raise RuntimeError("DHCP REQUEST Rx timeout") elif "RuntimeError: DHCP DISCOVER Rx timeout" in stderr: diff --git a/resources/libraries/robot/crypto/ipsec.robot b/resources/libraries/robot/crypto/ipsec.robot index f7d065ee4a..a37c18db77 100644 --- a/resources/libraries/robot/crypto/ipsec.robot +++ b/resources/libraries/robot/crypto/ipsec.robot @@ -49,17 +49,12 @@ | Configure path for IPSec test | | [Documentation] | Setup path for IPsec testing TG<-->DUT1. | | ... -| | ... | _NOTE:_ This KW sets following test case variable: -| | ... | - dut_lo - DUT loopback interface. Type: string -| | ... | | ... | *Example:* | | ... | \| Configure path for IPSec test \| | | ... -| | ${dut1_lo1}= | Vpp Create Loopback | ${dut1} | | Set Interface State | ${dut1} | ${dut1_if1} | up -| | Set Interface State | ${dut1} | ${dut1_lo1} | up +| | Set Interface State | ${dut1} | ${dut1_if2} | up | | Vpp Node Interfaces Ready Wait | ${dut1} -| | Set Test Variable | ${dut1_lo1} | Configure topology for IPv4 IPsec testing | | [Documentation] | Setup topology for IPv4 IPsec testing. @@ -75,18 +70,20 @@ | | ... | | Configure path for IPSec test | | VPP Interface Set IP Address -| | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip4} | ${ip4_plen} +| | ... | ${dut1} | ${dut1_if1} | ${dut_if1_ip4} | ${ip4_plen} | | VPP Interface Set IP Address -| | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip4} | ${ip4_plen} +| | ... | ${dut1} | ${dut1_if2} | ${dut_if2_ip4} | ${ip4_plen} | | VPP Add IP Neighbor -| | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip4} | ${tg_if1_mac} +| | ... | ${dut1} | ${dut1_if1} | ${tg_if1_ip4} | ${tg_if1_mac} +| | VPP Add IP Neighbor +| | ... | ${dut1} | ${dut1_if2} | ${tg_if2_ip4} | ${tg_if2_mac} | | Vpp Route Add -| | ... | ${dut1} | ${tg_lo_ip4} | ${ip4_plen} | gateway=${tg_if_ip4} +| | ... | ${dut1} | ${tg_host_ip4} | ${ip4_plen} | gateway=${tg_if1_ip4} | | ... | interface=${dut1_if1} -| | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip4} -| | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip4} -| | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip4} -| | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip4} +| | Set Test Variable | ${dut_tun_ip} | ${dut_if1_ip4} +| | Set Test Variable | ${tg_tun_ip} | ${tg_if1_ip4} +| | Set Test Variable | ${tg_src_ip} | ${tg_host_ip4} +| | Set Test Variable | ${tg_dst_ip} | ${tg_if2_ip4} | Configure topology for IPv6 IPsec testing | | [Documentation] | Setup topology fo IPv6 IPsec testing. @@ -102,19 +99,21 @@ | | ... | | Configure path for IPSec test | | VPP Interface Set IP Address -| | ... | ${dut1} | ${dut1_if1} | ${dut_if_ip6} | ${ip6_plen} +| | ... | ${dut1} | ${dut1_if1} | ${dut_if1_ip6} | ${ip6_plen} | | VPP Interface Set IP Address -| | ... | ${dut1} | ${dut1_lo1} | ${dut_lo_ip6} | ${ip6_plen} +| | ... | ${dut1} | ${dut1_if2} | ${dut_if2_ip6} | ${ip6_plen} +| | VPP Add IP Neighbor +| | ... | ${dut1} | ${dut1_if1} | ${tg_if1_ip6} | ${tg_if1_mac} | | VPP Add IP Neighbor -| | ... | ${dut1} | ${dut1_if1} | ${tg_if_ip6} | ${tg_if1_mac} +| | ... | ${dut1} | ${dut1_if2} | ${tg_if2_ip6} | ${tg_if2_mac} | | Vpp All RA Suppress Link Layer | ${nodes} | | Vpp Route Add -| | ... | ${dut1} | ${tg_lo_ip6} | ${ip6_plen_rt} | gateway=${tg_if_ip6} +| | ... | ${dut1} | ${tg_host_ip6} | ${ip6_plen_rt} | gateway=${tg_if1_ip6} | | ... | interface=${dut1_if1} -| | Set Test Variable | ${dut_tun_ip} | ${dut_if_ip6} -| | Set Test Variable | ${dut_src_ip} | ${dut_lo_ip6} -| | Set Test Variable | ${tg_tun_ip} | ${tg_if_ip6} -| | Set Test Variable | ${tg_src_ip} | ${tg_lo_ip6} +| | Set Test Variable | ${dut_tun_ip} | ${dut_if1_ip6} +| | Set Test Variable | ${tg_tun_ip} | ${tg_if1_ip6} +| | Set Test Variable | ${tg_src_ip} | ${tg_host_ip6} +| | Set Test Variable | ${tg_dst_ip} | ${tg_if2_ip6} | Configure manual keyed connection for IPSec | | [Documentation] | Setup IPsec manual keyed connection on VPP node. diff --git a/resources/libraries/robot/l2/l2_traffic.robot b/resources/libraries/robot/l2/l2_traffic.robot index bca801778e..93506d585e 100644 --- a/resources/libraries/robot/l2/l2_traffic.robot +++ b/resources/libraries/robot/l2/l2_traffic.robot @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -18,8 +18,8 @@ | ... | through L2 network. *** Keywords *** -| Send ICMP packet and verify received packet -| | [Documentation] | Send ICMPv4/ICMPv6 echo request from source interface to \ +| Send IP packet and verify received packet +| | [Documentation] | Send IPv4/IPv6 packet from source interface to \ | | ... | destination interface. Packet can be set with Dot1q or | | ... | Dot1ad tag(s) when required. | | ... @@ -46,47 +46,34 @@ | | ... | | ... | _NOTE:_ Default IP is IPv4 | | ... -| | ... | \| Send ICMP packet and verify received packet \| ${nodes['TG']} \ +| | ... | \| Send IP packet and verify received packet \| ${nodes['TG']} \ | | ... | \| ${tg_to_dut_if1} \| ${tg_to_dut_if2} \| -| | ... | \| Send ICMP packet and verify received packet \| ${nodes['TG']} \ +| | ... | \| Send IP packet and verify received packet \| ${nodes['TG']} \ | | ... | \| ${tg_to_dut1} \| ${tg_to_dut2} \| encaps=Dot1q \| vlan1=100 \| -| | ... | \| Send ICMP packet and verify received packet \| ${nodes['TG']} \ +| | ... | \| Send IP packet and verify received packet \| ${nodes['TG']} \ | | ... | \| ${tg_to_dut1} \| ${tg_to_dut2} \| encaps=Dot1ad \| vlan1=110 \ | | ... | \| vlan2=220 \| -| | ... | \| Send ICMP packet and verify received packet \| ${nodes['TG']} \ +| | ... | \| Send IP packet and verify received packet \| ${nodes['TG']} \ | | ... | \| ${tg_to_dut1} \| ${tg_to_dut2} \| encaps=Dot1q \| vlan1=110 \ | | ... | \| encaps_rx=Dot1q \| -| | ... | \| Send ICMP packet and verify received packet \| ${nodes['TG']} \ +| | ... | \| Send IP packet and verify received packet \| ${nodes['TG']} \ | | ... | \| ${tg_to_dut1} \| ${tg_to_dut2} \| encaps=Dot1q \| vlan1=110 \ | | ... | \| encaps_rx=Dot1q \| vlan1_rx=120 \| | | ... -| | [Arguments] | ${tg_node} | ${src_int} | ${dst_int} -| | ... | ${src_ip}=192.168.100.1 | ${dst_ip}=192.168.100.2 | ${encaps}=${EMPTY} -| | ... | ${vlan1}=${EMPTY} | ${vlan2}=${EMPTY} | ${encaps_rx}=${EMPTY} -| | ... | ${vlan1_rx}=${EMPTY} | ${vlan2_rx}=${EMPTY} -| | ... -| | ${src_mac}= | Get Interface Mac | ${tg_node} | ${src_int} -| | ${dst_mac}= | Get Interface Mac | ${tg_node} | ${dst_int} -| | ${src_int_name}= | Get interface name | ${tg_node} | ${src_int} -| | ${dst_int_name}= | Get interface name | ${tg_node} | ${dst_int} -| | ${args}= | Traffic Script Gen Arg | ${dst_int_name} | ${src_int_name} -| | ... | ${src_mac} | ${dst_mac} | ${src_ip} | ${dst_ip} -| | ${args}= | Run Keyword If | '${encaps}' == '${EMPTY}' -| | | ... | Set Variable | ${args} -| | ... | ELSE | Catenate | ${args} | --encaps ${encaps} | --vlan1 ${vlan1} -| | ${args}= | Run Keyword If | '${vlan2}' == '${EMPTY}' -| | | ... | Set Variable | ${args} -| | ... | ELSE | Catenate | ${args} | --vlan2 ${vlan2} -| | ${args}= | Run Keyword If | '${encaps_rx}' == '${EMPTY}' -| | | ... | Set Variable | ${args} -| | ... | ELSE | Catenate | ${args} | --encaps_rx ${encaps_rx} -| | ${args}= | Run Keyword If | '${vlan1_rx}' == '${EMPTY}' -| | | ... | Set Variable | ${args} -| | ... | ELSE | Catenate | ${args} | --vlan1_rx ${vlan1_rx} -| | ${args}= | Run Keyword If | '${vlan2_rx}' == '${EMPTY}' -| | | ... | Set Variable | ${args} -| | ... | ELSE | Catenate | ${args} | --vlan2_rx ${vlan2_rx} -| | Run Traffic Script On Node | send_ip_icmp.py | ${tg_node} | ${args} +| | [Arguments] | ${tg_node} | ${tx_src_port} | ${rx_dst_port} +| | ... | ${src_ip}=192.168.100.1 | ${dst_ip}=192.168.100.2 +| | ... | ${encaps}=${EMPTY} | ${vlan1}=${EMPTY} | ${vlan2}=${EMPTY} +| | ... | ${encaps_rx}=${EMPTY} | ${vlan1_rx}=${EMPTY} | ${vlan2_rx}=${EMPTY} +| | ... +| | ${tx_src_mac}= | Get Interface Mac | ${tg_node} | ${tx_src_port} +| | ${rx_dst_mac}= | Get Interface Mac | ${tg_node} | ${rx_dst_port} +| | Then Send packet and verify headers +| | ... | ${tg} | 192.168.0.1 | 192.168.0.2 +| | ... | ${tx_src_port} | ${tx_src_mac} | ${rx_dst_mac} +| | ... | ${rx_dst_port} | ${tx_src_mac} | ${rx_dst_mac} +| | ... | encaps_tx=${encaps} | vlan_tx=${vlan1} | vlan_outer_tx=${vlan2} +| | ... | encaps_rx=${encaps_rx} | vlan_rx=${vlan1_rx} +| | ... | vlan_outer_rx=${vlan2_rx} | ICMP packet transmission should fail | | [Documentation] | Send ICMPv4/ICMPv6 echo request from source interface to @@ -121,11 +108,11 @@ | | ${dst_int_name}= | Get interface name | ${tg_node} | ${dst_int} | | ${args}= | Traffic Script Gen Arg | ${dst_int_name} | ${src_int_name} | | ... | ${src_mac} | ${dst_mac} | ${src_ip} | ${dst_ip} -| | Run Keyword And Expect Error | ICMP echo Rx timeout | +| | Run Keyword And Expect Error | IP echo Rx timeout | | | ... | Run Traffic Script On Node | send_ip_icmp.py | ${tg_node} | ${args} -| Send ICMPv4 bidirectionally and verify received packets -| | [Documentation] | Send ICMPv4 echo request from both directions, +| Send IPv4 bidirectionally and verify received packets +| | [Documentation] | Send IPv4 packets from both directions, | | ... | from interface1 to interface2 and from interface2 to interface1. | | ... | | ... | *Arguments:* @@ -142,19 +129,19 @@ | | ... | | ... | *Example:* | | ... -| | ... | \| Send ICMPv4 bidirectionally and verify received packets \ +| | ... | \| Send IPv4 bidirectionally and verify received packets \ | | ... | \| ${nodes['TG']} \| ${tg_to_dut_if1} \| ${tg_to_dut_if2} \| | | ... | | [Arguments] | ${tg_node} | ${int1} | ${int2} | ${src_ip}=192.168.100.1 | | | ... | ${dst_ip}=192.168.100.2 | | ... -| | Send ICMP packet and verify received packet +| | Send IP packet and verify received packet | | ... | ${tg_node} | ${int1} | ${int2} | ${src_ip} | ${dst_ip} -| | Send ICMP packet and verify received packet +| | Send IP packet and verify received packet | | ... | ${tg_node} | ${int2} | ${int1} | ${dst_ip} | ${src_ip} -| Send ICMPv6 bidirectionally and verify received packets -| | [Documentation] | Send ICMPv6 echo request from both directions, +| Send IPv6 bidirectionally and verify received packets +| | [Documentation] | Send IPv6 packets from both directions, | | ... | from interface1 to interface2 and from interface2 to interface1. | | ... | | ... | *Arguments:* @@ -171,13 +158,13 @@ | | ... | | ... | *Example:* | | ... -| | ... | \| Send ICMPv6 bidirectionally and verify received packets \ +| | ... | \| Send IPv6 bidirectionally and verify received packets \ | | ... | \| ${nodes['TG']} \| ${tg_to_dut_if1} \| ${tg_to_dut_if2} \| | | ... | | [Arguments] | ${tg_node} | ${int1} | ${int2} | ${src_ip}=3ffe:63::1 | | | ... | ${dst_ip}=3ffe:63::2 | | ... -| | Send ICMP packet and verify received packet +| | Send IP packet and verify received packet | | ... | ${tg_node} | ${int1} | ${int2} | ${src_ip} | ${dst_ip} -| | Send ICMP packet and verify received packet +| | Send IP packet and verify received packet | | ... | ${tg_node} | ${int2} | ${int1} | ${dst_ip} | ${src_ip} diff --git a/resources/libraries/robot/shared/traffic.robot b/resources/libraries/robot/shared/traffic.robot index 5d11618f62..df74017f6a 100644 --- a/resources/libraries/robot/shared/traffic.robot +++ b/resources/libraries/robot/shared/traffic.robot @@ -40,7 +40,7 @@ | | ... | - tx_src_port - Interface of TG-if1. Type: string | | ... | - tx_src_mac - MAC address of TG-if1. Type: string | | ... | - tx_dst_mac - MAC address of DUT-if1. Type: string -| | ... | - rx_port - Interface of TG-if1. Type: string +| | ... | - rx_dst_port - Interface of TG-if1. Type: string | | ... | - rx_src_mac - MAC address of DUT1-if2. Type: string | | ... | - rx_dst_mac - MAC address of TG-if2. Type: string | | ... | - encaps_tx - Expected encapsulation on TX side: Dot1q or Dot1ad @@ -66,14 +66,14 @@ | | ... | \| eth3 \| 08:00:27:4d:ca:7a \| 08:00:27:7d:fd:10 \| | | ... | | [Arguments] | ${tg_node} | ${src_ip} | ${dst_ip} | ${tx_src_port} -| | ... | ${tx_src_mac} | ${tx_dst_mac} | ${rx_port} | ${rx_src_mac} +| | ... | ${tx_src_mac} | ${tx_dst_mac} | ${rx_dst_port} | ${rx_src_mac} | | ... | ${rx_dst_mac} | ${encaps_tx}=${EMPTY} | ${vlan_tx}=${EMPTY} | | ... | ${vlan_outer_tx}=${EMPTY} | ${encaps_rx}=${EMPTY} | | ... | ${vlan_rx}=${EMPTY} | ${vlan_outer_rx}=${EMPTY} -| | ... | ${traffic_script}=send_icmp_check_headers +| | ... | ${traffic_script}=send_ip_check_headers | | ... | | ${tx_port_name}= | Get interface name | ${tg_node} | ${tx_src_port} -| | ${rx_port_name}= | Get interface name | ${tg_node} | ${rx_port} +| | ${rx_port_name}= | Get interface name | ${tg_node} | ${rx_dst_port} | | ${args}= | Catenate | --tg_src_mac ${tx_src_mac} | | ... | --tg_dst_mac ${rx_dst_mac} | --dut_if1_mac ${tx_dst_mac} | | ... | --dut_if2_mac ${rx_src_mac} | --src_ip ${src_ip} | --dst_ip ${dst_ip} @@ -133,8 +133,8 @@ | | ... | --tg_dst_mac ${rx_dst_mac} | --dut_if1_mac ${tx_dst_mac} | | ... | --dut_if2_mac ${rx_src_mac} | --src_ip ${src_ip} | --dst_ip ${dst_ip} | | ... | --tx_if ${tx_port_name} | --rx_if ${rx_port_name} -| | Run Keyword And Expect Error | ICMP echo Rx timeout | -| | ... | Run Traffic Script On Node | send_icmp_check_headers.py +| | Run Keyword And Expect Error | IP packet Rx timeout | +| | ... | Run Traffic Script On Node | send_ip_check_headers.py | | ... | ${tg_node} | ${args} | Send packet and verify ARP request @@ -845,8 +845,12 @@ | | ... | | ... | *Arguments:* | | ... | - node - TG node. Type: dictionary -| | ... | - interface - TG Interface. Type: string -| | ... | - dst_mac - Destination MAC. Type: string +| | ... | - tx_interface - TG Interface 1. Type: string +| | ... | - rx_interface - TG Interface 2. Type: string +| | ... | - tx_dst_mac - Destination MAC for TX interface / DUT interface 1 MAC. +| | ... | Type: string +| | ... | - rx_src_mac - Source MAC for RX interface / DUT interface 2 MAC. +| | ... | Type: string | | ... | - crypto_alg - Encrytion algorithm. Type: enum | | ... | - crypto_key - Encryption key. Type: string | | ... | - integ_alg - Integrity algorithm. Type: enum @@ -862,20 +866,25 @@ | | ... | \| ${encr_alg}= \| Crypto Alg AES CBC 128 \| | | ... | \| ${auth_alg}= \| Integ Alg SHA1 96 \| | | ... | \| Send IPsec Packet and verify ESP encapsulation in received packet\ -| | ... | \| ${nodes['TG']} \| eth1 \ -| | ... | \| 52:54:00:d4:d8:22 \| ${encr_alg} \| sixteenbytes_key \ -| | ... | \| ${auth_alg} \| twentybytessecretkey \| ${1001} \| ${1000} \ -| | ... | \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \| 192.168.100.3 \| -| | ... -| | [Arguments] | ${node} | ${interface} | ${dst_mac} | ${crypto_alg} -| | ... | ${crypto_key} | ${integ_alg} | ${integ_key} | ${l_spi} -| | ... | ${r_spi} | ${l_ip} | ${r_ip} | ${l_tunnel}=${None} -| | ... | ${r_tunnel}=${None} -| | ... -| | ${src_mac}= | Get Interface Mac | ${node} | ${interface} -| | ${if_name}= | Get Interface Name | ${node} | ${interface} -| | ${args}= | Traffic Script Gen Arg | ${if_name} | ${if_name} | ${src_mac} -| | ... | ${dst_mac} | ${l_ip} | ${r_ip} +| | ... | \| ${nodes['TG']} \| eth1 \| eth2 \ +| | ... | \| 52:54:00:d4:d8:22 \| 52:54:00:d4:d8:3e \| ${encr_alg} \ +| | ... | \| sixteenbytes_key \| ${auth_alg} \| twentybytessecretkey \ +| | ... | \| ${1001} \| ${1000} \| 192.168.3.3 \| 192.168.4.4 \| 192.168.100.2 \ +| | ... | \| 192.168.100.3 \| +| | ... +| | [Arguments] | ${node} | ${tx_interface} | ${rx_interface} | ${tx_dst_mac} +| | ... | ${rx_src_mac} | ${crypto_alg} | ${crypto_key} | ${integ_alg} +| | ... | ${integ_key} | ${l_spi} | ${r_spi} | ${l_ip} | ${r_ip} +| | ... | ${l_tunnel}=${None} | ${r_tunnel}=${None} +| | ... +| | ${tx_src_mac}= | Get Interface Mac | ${node} | ${tx_interface} +| | ${tx_if_name}= | Get Interface Name | ${node} | ${tx_interface} +| | ${rx_dst_mac}= | Get Interface Mac | ${node} | ${tx_interface} +| | ${rx_if_name}= | Get Interface Name | ${node} | ${rx_interface} +| | ${args}= | Catenate | --rx_if ${rx_if_name} | --tx_if ${tx_if_name} +| | ... | --tx_src_mac ${tx_src_mac} | --tx_dst_mac ${tx_dst_mac} +| | ... | --rx_src_mac ${rx_src_mac} | --rx_dst_mac ${rx_dst_mac} +| | ... | --src_ip ${l_ip} | --dst_ip ${r_ip} | | ${crypto_alg_str}= | Get Crypto Alg Scapy Name | ${crypto_alg} | | ${integ_alg_str}= | Get Integ Alg Scapy Name | ${integ_alg} | | ${args}= | Catenate | ${args} | --crypto_alg ${crypto_alg_str} diff --git a/resources/traffic_scripts/ipsec.py b/resources/traffic_scripts/ipsec.py index 1561738c60..b853b6c09f 100755 --- a/resources/traffic_scripts/ipsec.py +++ b/resources/traffic_scripts/ipsec.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -23,9 +23,8 @@ import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import Ether -from scapy.layers.inet import ICMP, IP +from scapy.layers.inet import IP from scapy.layers.inet6 import IPv6, ICMPv6ND_NS -from scapy.layers.inet6 import ICMPv6EchoRequest, ICMPv6EchoReply from scapy.layers.ipsec import SecurityAssociation, ESP from ipaddress import ip_address @@ -33,114 +32,113 @@ from resources.libraries.python.TrafficScriptArg import TrafficScriptArg from resources.libraries.python.PacketVerifier import RxQueue, TxQueue -def check_ipv4(pkt_recv, dst_tun, src_ip, dst_ip, sa_in): - """Check received IPv4 IPsec packet. +def check_ipsec(pkt_recv, ip_layer, dst_tun, src_ip, dst_ip, sa_in): + """Check received IPsec packet. :param pkt_recv: Received packet to verify. + :param ip_layer: Scapy IP layer. :param dst_tun: IPsec tunnel destination address. - :param src_ip: Source address of original IPv4 packet. - :param dst_ip: Destination address of original IPv4 packet. + :param src_ip: Source IP/IPv6 address of original IP/IPv6 packet. + :param dst_ip: Destination IP/IPv6 address of original IP/IPv6 packet. :param sa_in: IPsec SA for packet decryption. :type pkt_recv: scapy.Ether + :type ip_layer: scapy.layers.inet.IP or scapy.layers.inet6.IPv6 :type dst_tun: str :type src_ip: str :type dst_ip: str :type sa_in: scapy.layers.ipsec.SecurityAssociation :raises RuntimeError: If received packet is invalid. """ - if not pkt_recv.haslayer(IP): - raise RuntimeError( - 'Not an IPv4 packet received: {0}'.format(pkt_recv.__repr__())) + if not pkt_recv.haslayer(ip_layer): + raise RuntimeError('Not an {ip} packet received: {pkt}'.format( + ip=ip_layer.name, pkt=pkt_recv.__repr__())) - if pkt_recv['IP'].dst != dst_tun: + if pkt_recv[ip_layer.name].dst != dst_tun: raise RuntimeError( - 'Received packet has invalid destination address: {0} ' - 'should be: {1}'.format(pkt_recv['IP'].dst, dst_tun)) + 'Received packet has invalid destination address: {rec_ip} ' + 'should be: {exp_ip}'.format( + rec_ip=pkt_recv[ip_layer.name].dst, exp_ip=dst_tun)) if not pkt_recv.haslayer(ESP): raise RuntimeError( - 'Not an ESP packet received: {0}'.format(pkt_recv.__repr__())) + 'Not an ESP packet received: {pkt}'.format(pkt=pkt_recv.__repr__())) - ip_pkt = pkt_recv[IP] + ip_pkt = pkt_recv[ip_layer] d_pkt = sa_in.decrypt(ip_pkt) - if d_pkt[IP].dst != dst_ip: + if d_pkt[ip_layer].dst != dst_ip: raise RuntimeError( - 'Decrypted packet has invalid destination address: {0} ' - 'should be: {1}'.format(d_pkt['IP'].dst, dst_ip)) + 'Decrypted packet has invalid destination address: {rec_ip} ' + 'should be: {exp_ip}'.format( + rec_ip=d_pkt[ip_layer].dst, exp_ip=dst_ip)) - if d_pkt[IP].src != src_ip: + if d_pkt[ip_layer].src != src_ip: raise RuntimeError( - 'Decrypted packet has invalid source address: {0} should be: {1}' - .format(d_pkt['IP'].src, src_ip)) + 'Decrypted packet has invalid source address: {rec_ip} should be: ' + '{exp_ip}'.format(rec_ip=d_pkt[ip_layer].src, exp_ip=src_ip)) - if not d_pkt.haslayer(ICMP): + if ip_layer == IP and d_pkt[ip_layer.name].proto != 61: raise RuntimeError( - 'Decrypted packet does not have ICMP layer: {0}'.format( - d_pkt.__repr__())) + 'Decrypted packet has invalid IP protocol: {rec_proto} ' + 'should be: 61'.format(rec_proto=d_pkt[ip_layer.name].proto)) -def check_ipv6(pkt_recv, dst_tun, src_ip, dst_ip, sa_in): - """Check received IPv6 IPsec packet. +def check_ip(pkt_recv, ip_layer, src_ip, dst_ip): + """Check received IP/IPv6 packet. :param pkt_recv: Received packet to verify. - :param dst_tun: IPsec tunnel destination address. - :param src_ip: Source address of original IPv6 packet. - :param dst_ip: Destination address of original IPv6 packet. - :param sa_in: IPsec SA for packet decryption. + :param ip_layer: Scapy IP layer. + :param src_ip: Source IP/IPv6 address. + :param dst_ip: Destination IP/IPv6 address. :type pkt_recv: scapy.Ether - :type dst_tun: str + :type ip_layer: scapy.layers.inet.IP or scapy.layers.inet6.IPv6 :type src_ip: str :type dst_ip: str - :type sa_in: scapy.layers.ipsec.SecurityAssociation :raises RuntimeError: If received packet is invalid. """ - if not pkt_recv.haslayer(IPv6): - raise RuntimeError( - 'Not an IPv6 packet received: {0}'.format(pkt_recv.__repr__())) - - if pkt_recv[IPv6].dst != dst_tun: - raise RuntimeError( - 'Received packet has invalid destination address: {0} ' - 'should be: {1}'.format(pkt_recv['IPv6'].dst, dst_tun)) + if not pkt_recv.haslayer(ip_layer): + raise RuntimeError('Not an {ip} packet received: {pkt}'.format( + ip=ip_layer.name, pkt=pkt_recv.__repr__())) - if not pkt_recv.haslayer(ESP): - raise RuntimeError( - 'Not an ESP packet received: {0}'.format(pkt_recv.__repr__())) - - ip_pkt = pkt_recv[IPv6] - d_pkt = sa_in.decrypt(ip_pkt) - - if d_pkt[IPv6].dst != dst_ip: + if pkt_recv[ip_layer.name].dst != dst_ip: raise RuntimeError( - 'Decrypted packet has invalid destination address {0}: ' - 'should be: {1}'.format(d_pkt['IPv6'].dst, dst_ip)) + 'Received packet has invalid destination address: {rec_ip} ' + 'should be: {exp_ip}'.format( + rec_ip=pkt_recv[ip_layer.name].dst, exp_ip=dst_ip)) - if d_pkt[IPv6].src != src_ip: + if pkt_recv[ip_layer.name].src != src_ip: raise RuntimeError( - 'Decrypted packet has invalid source address: {0} should be: {1}' - .format(d_pkt['IPv6'].src, src_ip)) + 'Received packet has invalid destination address: {rec_ip} ' + 'should be: {exp_ip}'.format( + rec_ip=pkt_recv[ip_layer.name].dst, exp_ip=src_ip)) - if not d_pkt.haslayer(ICMPv6EchoReply): + if ip_layer == IP and pkt_recv[ip_layer.name].proto != 61: raise RuntimeError( - 'Decrypted packet does not have ICMP layer: {0}'.format( - d_pkt.__repr__())) + 'Received packet has invalid IP protocol: {rec_proto} ' + 'should be: 61'.format(rec_proto=pkt_recv[ip_layer.name].proto)) # pylint: disable=too-many-locals # pylint: disable=too-many-statements def main(): """Send and receive IPsec packet.""" - args = TrafficScriptArg(['src_mac', 'dst_mac', 'src_ip', 'dst_ip', - 'crypto_alg', 'crypto_key', 'integ_alg', - 'integ_key', 'l_spi', 'r_spi'], - ['src_tun', 'dst_tun']) - - rxq = RxQueue(args.get_arg('rx_if')) - txq = TxQueue(args.get_arg('tx_if')) - src_mac = args.get_arg('src_mac') - dst_mac = args.get_arg('dst_mac') + args = TrafficScriptArg( + ['tx_src_mac', 'tx_dst_mac', 'rx_src_mac', 'rx_dst_mac', 'src_ip', + 'dst_ip','crypto_alg', 'crypto_key', 'integ_alg', 'integ_key', + 'l_spi', 'r_spi'], + ['src_tun', 'dst_tun'] + ) + + tx_txq = TxQueue(args.get_arg('tx_if')) + tx_rxq = RxQueue(args.get_arg('tx_if')) + rx_txq = TxQueue(args.get_arg('rx_if')) + rx_rxq = RxQueue(args.get_arg('rx_if')) + + tx_src_mac = args.get_arg('tx_src_mac') + tx_dst_mac = args.get_arg('tx_dst_mac') + rx_src_mac = args.get_arg('rx_src_mac') + rx_dst_mac = args.get_arg('rx_dst_mac') src_ip = args.get_arg('src_ip') dst_ip = args.get_arg('dst_ip') crypto_alg = args.get_arg('crypto_alg') @@ -152,23 +150,18 @@ def main(): src_tun = args.get_arg('src_tun') dst_tun = args.get_arg('dst_tun') - is_ipv4 = True - if 6 == ip_address(unicode(src_ip)).version: - is_ipv4 = False + if ip_address(unicode(src_ip)).version == 6: + ip_layer = IPv6 + else: + ip_layer = IP - tunnel_out = None - tunnel_in = None + tunnel_out = ip_layer(src=src_tun, dst=dst_tun) if src_tun and dst_tun \ + else None + tunnel_in = ip_layer(src=dst_tun, dst=src_tun) if src_tun and dst_tun \ + else None - if src_tun and dst_tun: - if is_ipv4: - tunnel_out = IP(src=src_tun, dst=dst_tun) - tunnel_in = IP(src=dst_tun, dst=src_tun) - else: - tunnel_out = IPv6(src=src_tun, dst=dst_tun) - tunnel_in = IPv6(src=dst_tun, dst=src_tun) - else: + if not (src_tun and dst_tun): src_tun = src_ip - dst_tun = dst_ip sa_in = SecurityAssociation(ESP, spi=r_spi, crypt_algo=crypto_alg, crypt_key=crypto_key, auth_algo=integ_alg, @@ -178,41 +171,55 @@ def main(): crypt_key=crypto_key, auth_algo=integ_alg, auth_key=integ_key, tunnel_header=tunnel_out) - sent_packets = [] - - if is_ipv4: - ip_pkt = (IP(src=src_ip, dst=dst_ip) / - ICMP()) - ip_pkt = IP(str(ip_pkt)) - else: - ip_pkt = (IPv6(src=src_ip, dst=dst_ip) / - ICMPv6EchoRequest()) - ip_pkt = IPv6(str(ip_pkt)) + ip_pkt = ip_layer(src=src_ip, dst=dst_ip, proto=61) if ip_layer == IP \ + else ip_layer(src=src_ip, dst=dst_ip) + ip_pkt = ip_layer(str(ip_pkt)) e_pkt = sa_out.encrypt(ip_pkt) - pkt_send = (Ether(src=src_mac, dst=dst_mac) / - e_pkt) + tx_pkt_send = (Ether(src=tx_src_mac, dst=tx_dst_mac) / + e_pkt) + + sent_packets = list() + sent_packets.append(tx_pkt_send) + tx_txq.send(tx_pkt_send) + + while True: + rx_pkt_recv = rx_rxq.recv(2) + + if rx_pkt_recv is None: + raise RuntimeError( + '{ip} packet Rx timeout'.format(ip=ip_layer.name)) + + if rx_pkt_recv.haslayer(ICMPv6ND_NS): + # read another packet in the queue if the current one is ICMPv6ND_NS + continue + else: + # otherwise process the current packet + break + + check_ip(rx_pkt_recv, ip_layer, src_ip, dst_ip) - sent_packets.append(pkt_send) - txq.send(pkt_send) + rx_ip_pkt = ip_layer(src=dst_ip, dst=src_ip, proto=61) if ip_layer == IP \ + else ip_layer(src=dst_ip, dst=src_ip) + rx_pkt_send = (Ether(src=rx_dst_mac, dst=rx_src_mac) / + rx_ip_pkt) + + rx_txq.send(rx_pkt_send) while True: - pkt_recv = rxq.recv(2, sent_packets) + tx_pkt_recv = tx_rxq.recv(2, sent_packets) - if pkt_recv is None: + if tx_pkt_recv is None: raise RuntimeError('ESP packet Rx timeout') - if pkt_recv.haslayer(ICMPv6ND_NS): + if rx_pkt_recv.haslayer(ICMPv6ND_NS): # read another packet in the queue if the current one is ICMPv6ND_NS continue else: # otherwise process the current packet break - if is_ipv4: - check_ipv4(pkt_recv, src_tun, dst_ip, src_ip, sa_in) - else: - check_ipv6(pkt_recv, src_tun, dst_ip, src_ip, sa_in) + check_ipsec(tx_pkt_recv, ip_layer, src_tun, dst_ip, src_ip, sa_in) sys.exit(0) diff --git a/resources/traffic_scripts/send_ip_check_headers.py b/resources/traffic_scripts/send_ip_check_headers.py index 816c0053e9..7c4f2bd002 100755 --- a/resources/traffic_scripts/send_ip_check_headers.py +++ b/resources/traffic_scripts/send_ip_check_headers.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Traffic script that sends an IP ICMPv4/ICMPv6 packet from one interface +"""Traffic script that sends an IP IPv4/IPv6 packet from one interface to the other. Source and destination IP addresses and source and destination MAC addresses are checked in received packet. """ @@ -22,7 +22,7 @@ import sys import ipaddress from robot.api import logger from scapy.layers.inet import IP -from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, ICMPv6ND_NS +from scapy.layers.inet6 import IPv6, ICMPv6ND_NS from scapy.layers.l2 import Ether, Dot1Q from resources.libraries.python.PacketVerifier import RxQueue, TxQueue @@ -46,7 +46,7 @@ def valid_ipv6(ip): def main(): - """Send IP ICMP packet from one traffic generator interface to the other.""" + """Send IP/IPv6 packet from one traffic generator interface to the other.""" args = TrafficScriptArg( ['tg_src_mac', 'tg_dst_mac', 'src_ip', 'dst_ip', 'dut_if1_mac', 'dut_if2_mac'], @@ -97,8 +97,9 @@ def main(): ether = rxq.recv(2, ignore=sent_packets) else: ether = rxq.recv(2) + if ether is None: - raise RuntimeError('ICMP echo Rx timeout') + raise RuntimeError('IP packet Rx timeout') if ether.haslayer(ICMPv6ND_NS): # read another packet in the queue if the current one is ICMPv6ND_NS |