diff options
author | Jan Gelety <jgelety@cisco.com> | 2020-03-31 18:19:03 +0200 |
---|---|---|
committer | Jan Gelety <jgelety@cisco.com> | 2020-05-04 07:36:26 +0000 |
commit | a6f1a1511bbede1b86e95d00cfad340897432c92 (patch) | |
tree | 1ba4442cb5254712812de98ccc2815f8dcde2b1c /resources | |
parent | fada1fcb4e27d948bbcb2c6aa7e50347e953c898 (diff) |
VPP-DEV API Coverages: SRv6
Jira: CSIT-1698
Change-Id: I6d9154284990df8877850e4014716510016e485b
Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources')
-rw-r--r-- | resources/libraries/python/SRv6.py | 12 | ||||
-rw-r--r-- | resources/libraries/robot/overlay/srv6.robot | 214 | ||||
-rw-r--r-- | resources/libraries/robot/shared/traffic.robot | 61 | ||||
-rwxr-xr-x | resources/traffic_scripts/srv6_encap.py | 306 |
4 files changed, 510 insertions, 83 deletions
diff --git a/resources/libraries/python/SRv6.py b/resources/libraries/python/SRv6.py index 86dd0028bd..4ff8866bda 100644 --- a/resources/libraries/python/SRv6.py +++ b/resources/libraries/python/SRv6.py @@ -292,10 +292,10 @@ class SRv6: ip_addr = ip_address(ip_addr) prefix = IPUtil.create_prefix_object(ip_addr, int(prefix)) traffic_type = getattr( - SRv6PolicySteeringTypes, u"SR_STEER_IPV4" - ).value if ip_addr.version == 4 else getattr( - SRv6PolicySteeringTypes, u"SR_STEER_IPV6" - ).value + SRv6PolicySteeringTypes, u"SR_STEER_IPV4" + ).value if ip_addr.version == 4 else getattr( + SRv6PolicySteeringTypes, u"SR_STEER_IPV6" + ).value else: raise ValueError(f"Unsupported mode: {mode}") @@ -326,8 +326,8 @@ class SRv6: is missing. """ sw_if_index, prefix, traffic_type = SRv6._get_sr_steer_policy_args( - node, mode, interface, ip_addr, prefix - ) + node, mode, interface, ip_addr, prefix + ) cmd = u"sr_steering_add_del" args = dict( diff --git a/resources/libraries/robot/overlay/srv6.robot b/resources/libraries/robot/overlay/srv6.robot index 6c73ad4bdf..806cab2f4d 100644 --- a/resources/libraries/robot/overlay/srv6.robot +++ b/resources/libraries/robot/overlay/srv6.robot @@ -225,105 +225,142 @@ | | | Show SR LocalSIDs | ${nodes['${dut}']} | | END -| Initialize IPv6 forwarding over SRv6 with encapsulation with '${n}' x SID '${prepos}' decapsulation in 3-node circular topology +| Initialize SRv6 encapsulation with '${n}' x SID '${prepos}' decapsulation | | [Documentation] -| | ... | Set UP state on VPP interfaces in path on nodes in 3-node circular +| | ... | Set UP state on VPP interfaces in path on node(s) in circular | | ... | topology. Get the interface MAC addresses and setup neighbours on all | | ... | VPP interfaces. Setup IPv6 addresses on all interfaces. Set segment | | ... | routing for IPv6 for required number of SIDs and configure IPv6 routes -| | ... | on both DUT nodes. +| | ... | on DUT node(s). +| | +| | ${status} | ${value}= | Run Keyword And Ignore Error +| | ... | Variable Should Exist | ${dut2} +| | ${dut2_status}= | Set Variable If | '${status}' == 'PASS' | ${True} +| | ... | ${False} | | | | VPP Interface Set IP Address | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${dut1_if1_ip6} | ${prefix} | | VPP Interface Set IP Address | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut1_if2_ip6} | ${prefix} -| | VPP Interface Set IP Address +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut2_if1_ip6} | ${prefix} -| | VPP Interface Set IP Address +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${dut2_if2_ip6} | ${prefix} | | Vpp All Ra Suppress Link Layer | ${nodes} | | FOR | ${number} | IN RANGE | 2 | ${dst_addr_nr}+2 | | | ${hexa_nr}= | Convert To Hex | ${number} -| | | VPP Add IP Neighbor | ${dut1} -| | | ... | ${DUT1_${int}1}[0] | ${tg_if1_ip6_subnet}${hexa_nr} +| | | VPP Add IP Neighbor +| | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip6_subnet}${hexa_nr} | | | ... | ${TG_pf1_mac}[0] -| | | VPP Add IP Neighbor | ${dut2} -| | | ... | ${DUT2_${int}2}[0] | ${tg_if2_ip6_subnet}${hexa_nr} +| | | Run Keyword If | ${dut2_status} +| | | ... | VPP Add IP Neighbor +| | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${tg_if2_ip6_subnet}${hexa_nr} | | | ... | ${TG_pf2_mac}[0] | | END -| | VPP Add IP Neighbor +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip6} | | ... | ${DUT2_${int}1_mac}[0] -| | VPP Add IP Neighbor -| | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if2_ip6} -| | ... | ${DUT1_${int}2_mac}[0] +| | Run Keyword Unless | ${dut2_status} +| | ... | VPP Add IP Neighbor +| | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip6} | ${TG_pf2_mac}[0] +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor +| | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if2_ip6}| ${DUT1_${int}2_mac}[0] | | ${sid1}= | Set Variable If | | ... | "${n}" == "1" | ${dut2_sid1} | | ... | "${n}" == "2" | ${dut2_sid1_1} | | ${sid2}= | Set Variable If | | ... | "${n}" == "1" | ${dut1_sid2} | | ... | "${n}" == "2" | ${dut1_sid2_1} -| | Vpp Route Add | ${dut1} | ${sid1} | ${sid_prefix} | gateway=${dut2_if1_ip6} +| | Vpp Route Add +| | ... | ${dut1} | ${sid1} | ${sid_prefix} | gateway=${dut2_if1_ip6} | | ... | interface=${DUT1_${int}2}[0] -| | Vpp Route Add | ${dut2} | ${sid2} | ${sid_prefix} | gateway=${dut1_if2_ip6} +| | Run Keyword If | ${dut2_status} +| | ... | Vpp Route Add +| | ... | ${dut2} | ${sid2} | ${sid_prefix} | gateway=${dut1_if2_ip6} | | ... | interface=${DUT2_${int}1}[0] # Configure SRv6 for direction0 -| | Set SR Encaps Source Address on DUT | ${dut1} | ${dut1_sid1} -| | @{sid_list_dir0}= | Run Keyword If | "${n}" == "1" +| | Set SR Encaps Source Address on DUT +| | ... | ${dut1} | ${dut1_sid1} +| | @{sid_list_dir0}= | Run Keyword If | '${n}' == '1' | | ... | Create List | ${dut2_sid1} -| | ... | ELSE IF | "${n}" == "2" +| | ... | ELSE IF | '${n}' == '2' | | ... | Create List | ${dut2_sid1_1} | ${dut2_sid1_2} -| | Configure SR Policy on DUT | ${dut1} | ${dut1_bsid} | encap -| | ... | @{sid_list_dir0} -| | Configure SR Steer on DUT | ${dut1} | L3 | ${dut1_bsid} -| | ... | ip_addr=${tg_if2_ip6_subnet} | prefix=${sid_prefix} -| | Run Keyword If | "${n}" == "1" -| | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1} | end.dx6 -| | ... | interface=${DUT2_${int}2}[0] | next_hop=${tg_if2_ip6_subnet}2 -| | Run Keyword If | "${n}" == "2" -| | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1_1} | end -| | Run Keyword If | "${n}" == "2" and "${prepos}" != "without" -| | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1_2} | end.dx6 +| | Configure SR Policy on DUT +| | ... | ${dut1} | ${dut1_bsid} | encap | @{sid_list_dir0} +| | Configure SR Steer on DUT +| | ... | ${dut1} | L3 | ${dut1_bsid} | ip_addr=${tg_if2_ip6_subnet} +| | ... | prefix=${sid_prefix} +| | Run Keyword If | ${dut2_status} and '${n}' == '1' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut2} | ${dut2_sid1} | end.dx6 | interface=${DUT2_${int}2}[0] +| | ... | next_hop=${tg_if2_ip6_subnet}2 +| | Run Keyword If | ${dut2_status} and '${n}' == '2' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut2} | ${dut2_sid1_1} | end +| | Run Keyword If +| | ... | ${dut2_status} and '${n}' == '2' and '${prepos}' != 'without' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut2} | ${dut2_sid1_2} | end.dx6 | | ... | interface=${DUT2_${int}2}[0] | next_hop=${tg_if2_ip6_subnet}2 -| | Run Keyword If | "${n}" == "2" and "${prepos}" == "without" -| | ... | Vpp Route Add | ${dut2} | ${dut2_sid1_2} | ${sid_prefix} +| | Run Keyword If +| | ... | ${dut2_status} and '${n}' == '2' and '${prepos}' == 'without' +| | ... | Vpp Route Add +| | ... | ${dut2} | ${dut2_sid1_2} | ${sid_prefix} | | ... | gateway=${tg_if2_ip6_subnet}2 | interface=${DUT2_${int}2}[0] # Configure SRv6 for direction1 -| | Set SR Encaps Source Address on DUT | ${dut2} | ${dut2_sid2} -| | @{sid_list_dir1}= | Run Keyword If | "${n}" == "1" +| | Run Keyword If | ${dut2_status} +| | ... | Set SR Encaps Source Address on DUT +| | ... | ${dut2} | ${dut2_sid2} +| | @{sid_list_dir1}= | Run Keyword If | '${n}' == '1' | | ... | Create List | ${dut1_sid2} -| | ... | ELSE IF | "${n}" == "2" +| | ... | ELSE IF | '${n}' == '2' | | ... | Create List | ${dut1_sid2_1} | ${dut1_sid2_2} -| | Configure SR Policy on DUT | ${dut2} | ${dut2_bsid} | encap -| | ... | @{sid_list_dir1} -| | Configure SR Steer on DUT | ${dut2} | L3 | ${dut2_bsid} -| | ... | ip_addr=${tg_if1_ip6_subnet} | prefix=${sid_prefix} -| | Run Keyword If | "${n}" == "1" -| | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2} | end.dx6 -| | ... | interface=${DUT1_${int}1}[0] | next_hop=${tg_if1_ip6_subnet}2 -| | Run Keyword If | "${n}" == "2" -| | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2_1} | end -| | Run Keyword If | "${n}" == "2" and "${prepos}" != "without" -| | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2_2} | end.dx6 -| | ... | interface=${DUT1_${int}1}[0] | next_hop=${tg_if1_ip6_subnet}2 -| | Run Keyword If | "${n}" == "2" and "${prepos}" == "without" -| | ... | Vpp Route Add | ${dut1} | ${dut1_sid2_2} | ${sid_prefix} +| | Run Keyword If | ${dut2_status} +| | ... | Configure SR Policy on DUT +| | ... | ${dut2} | ${dut2_bsid} | encap | @{sid_list_dir1} +| | Run Keyword If | ${dut2_status} +| | ... | Configure SR Steer on DUT +| | ... | ${dut2} | L3 | ${dut2_bsid} | ip_addr=${tg_if1_ip6_subnet} +| | ... | prefix=${sid_prefix} +| | Run Keyword If | '${n}' == '1' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut1} | ${dut1_sid2} | end.dx6 | interface=${DUT1_${int}1}[0] +| | ... | next_hop=${tg_if1_ip6_subnet}2 +| | Run Keyword If | '${n}' == '2' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut1} | ${dut1_sid2_1} | end +| | Run Keyword If | '${n}' == '2' and '${prepos}' != 'without' +| | ... | Configure SR LocalSID on DUT +| | ... | ${dut1} | ${dut1_sid2_2} | end.dx6 | interface=${DUT1_${int}1}[0] +| | ... | next_hop=${tg_if1_ip6_subnet}2 +| | Run Keyword If | '${n}' == '2' and '${prepos}' == 'without' +| | ... | Vpp Route Add +| | ... | ${dut1} | ${dut1_sid2_2} | ${sid_prefix} | | ... | gateway=${tg_if1_ip6_subnet}2 | interface=${DUT1_${int}1}[0] | | Set interfaces in path up -| Initialize IPv6 forwarding over SRv6 with endpoint to SR-unaware Service Function via '${behavior}' behaviour in 3-node circular topology +| Initialize SRv6 with '${behavior}' SR-unaware Service Function | | [Documentation] | | ... | Create pair of Memif interfaces on all defined VPP nodes. Set UP -| | ... | state on VPP interfaces in path on nodes in 3-node circular topology. +| | ... | state on VPP interfaces in path on node(s) in circular topology. | | ... | Get the interface MAC addresses and setup neighbours on all VPP | | ... | interfaces. Setup IPv6 addresses on all interfaces. Set segment | | ... | routing for IPv6 with defined behaviour function and configure IPv6 -| | ... | routes on both DUT nodes. +| | ... | routes on DUT node(s). | | | | ... | *Note:* | | ... | KW uses test variable rxq_count_int set by KW Add worker threads | | ... | and rxqueues to all DUTs | | +| | ${status} | ${value}= | Run Keyword And Ignore Error +| | ... | Variable Should Exist | ${dut2} +| | ${dut2_status}= | Set Variable If | '${status}' == 'PASS' | ${True} +| | ... | ${False} +| | | | ${sock1}= | Set Variable | memif-DUT1_CNF | | ${sock2}= | Set Variable | memif-DUT2_CNF | | Set up memif interfaces on DUT node | ${dut1} | ${sock1} | ${sock1} @@ -331,11 +368,14 @@ | | ... | ${rxq_count_int} | | VPP Set interface MTU | ${dut1} | ${dut1-memif-1-if1} | | VPP Set interface MTU | ${dut1} | ${dut1-memif-1-if2} -| | Set up memif interfaces on DUT node | ${dut2} | ${sock2} | ${sock2} +| | Run Keyword If | ${dut2_status} +| | ... | Set up memif interfaces on DUT node | ${dut2} | ${sock2} | ${sock2} | | ... | ${1} | dut2-memif-1-if1 | dut2-memif-1-if2 | ${rxq_count_int} | | ... | ${rxq_count_int} -| | VPP Set interface MTU | ${dut2} | ${dut2-memif-1-if1} -| | VPP Set interface MTU | ${dut2} | ${dut2-memif-1-if2} +| | Run Keyword If | ${dut2_status} +| | ... | VPP Set interface MTU | ${dut2} | ${dut2-memif-1-if1} +| | Run Keyword If | ${dut2_status} +| | ... | VPP Set interface MTU | ${dut2} | ${dut2-memif-1-if2} | | FOR | ${dut} | IN | @{duts} | | | Show Memif | ${nodes['${dut}']} | | END @@ -347,40 +387,54 @@ | | ... | ${dut1-memif-1-if1_ip6} | ${mem_prefix} | | VPP Interface Set IP Address | ${dut1} | ${dut1-memif-1-if2} | | ... | ${dut1-memif-1-if2_ip6} | ${mem_prefix} -| | VPP Interface Set IP Address +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut2_if1_ip6} | ${prefix} -| | VPP Interface Set IP Address +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${dut2_if2_ip6} | ${prefix} -| | VPP Interface Set IP Address | ${dut2} | ${dut2-memif-1-if1} +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | ${dut2} | ${dut2-memif-1-if1} | | ... | ${dut2-memif-1-if1_ip6} | ${mem_prefix} -| | VPP Interface Set IP Address | ${dut2} | ${dut2-memif-1-if2} +| | Run Keyword If | ${dut2_status} +| | ... | VPP Interface Set IP Address | ${dut2} | ${dut2-memif-1-if2} | | ... | ${dut2-memif-1-if2_ip6} | ${mem_prefix} | | Vpp All Ra Suppress Link Layer | ${nodes} -| | VPP Add IP Neighbor +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor | | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip6} | | ... | ${DUT2_${int}1_mac}[0] -| | VPP Add IP Neighbor +| | Run Keyword Unless | ${dut2_status} +| | ... | VPP Add IP Neighbor +| | ... | ${dut1} | ${DUT1_${int}2}[0] | ${dut2_if1_ip6} | ${TG_pf2_mac}[0] +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor | | ... | ${dut2} | ${DUT2_${int}1}[0] | ${dut1_if2_ip6} | | ... | ${DUT1_${int}2_mac}[0] | | VPP Add IP Neighbor | | ... | ${dut1} | ${DUT1_${int}1}[0] | ${tg_if1_ip6_subnet}2 | | ... | ${TG_pf1_mac}[0] -| | VPP Add IP Neighbor +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor | | ... | ${dut2} | ${DUT2_${int}2}[0] | ${tg_if2_ip6_subnet}2 | | ... | ${TG_pf2_mac}[0] | | ${dut1-memif-1-if2_mac}= | Get Interface MAC | ${dut1} | memif2 -| | ${dut2-memif-1-if2_mac}= | Get Interface MAC | ${dut2} | memif2 +| | ${dut2-memif-1-if2_mac}= | Run Keyword If | ${dut2_status} +| | ... | Get Interface MAC | ${dut2} | memif2 | | VPP Add IP Neighbor | ${dut1} | | ... | ${dut1-memif-1-if1} | ${dut1_nh} | ${dut1-memif-1-if2_mac} -| | VPP Add IP Neighbor | ${dut2} +| | Run Keyword If | ${dut2_status} +| | ... | VPP Add IP Neighbor | ${dut2} | | ... | ${dut2-memif-1-if1} | ${dut2_nh} | ${dut2-memif-1-if2_mac} | | Vpp Route Add | ${dut1} | ${dut2_sid1} | ${sid_prefix} | | ... | gateway=${dut2_if1_ip6} | interface=${dut1_if2} | | Vpp Route Add | ${dut1} | ${out_sid2_1} | ${sid_prefix} | | ... | gateway=${tg_if1_ip6_subnet}2 | interface=${dut1_if1} -| | Vpp Route Add | ${dut2} | ${dut1_sid2} | ${sid_prefix} +| | Run Keyword If | ${dut2_status} +| | ... | Vpp Route Add | ${dut2} | ${dut1_sid2} | ${sid_prefix} | | ... | gateway=${dut1_if2_ip6} | interface=${dut2_if1} -| | Vpp Route Add | ${dut2} | ${out_sid1_1} | ${sid_prefix} +| | Run Keyword If | ${dut2_status} +| | ... | Vpp Route Add | ${dut2} | ${out_sid1_1} | ${sid_prefix} | | ... | gateway=${tg_if2_ip6_subnet}2 | interface=${dut2_if2} # Configure SRv6 for direction0 on DUT1 | | Set SR Encaps Source Address on DUT | ${dut1} | ${dut1_sid1} @@ -391,40 +445,46 @@ | | Configure SR Steer on DUT | ${dut1} | L3 | ${dut1_bsid} | | ... | ip_addr=${tg_if2_ip6_subnet} | prefix=${sid_prefix} # Configure SRv6 for direction1 on DUT2 -| | Set SR Encaps Source Address on DUT | ${dut2} | ${dut2_sid2} +| | Run Keyword If | ${dut2_status} +| | ... | Set SR Encaps Source Address on DUT | ${dut2} | ${dut2_sid2} | | @{sid_list_dir1}= | Create List | ${dut1_sid2} | ${out_sid2_1} | | ... | ${out_sid2_2} -| | Configure SR Policy on DUT | ${dut2} | ${dut2_bsid} | encap +| | Run Keyword If | ${dut2_status} +| | ... | Configure SR Policy on DUT | ${dut2} | ${dut2_bsid} | encap | | ... | @{sid_list_dir1} -| | Configure SR Steer on DUT | ${dut2} | L3 | ${dut2_bsid} +| | Run Keyword If | ${dut2_status} +| | ... | Configure SR Steer on DUT | ${dut2} | L3 | ${dut2_bsid} | | ... | ip_addr=${tg_if1_ip6_subnet} | prefix=${sid_prefix} # Configure SRv6 for direction0 on DUT2 -| | ${dut2_out_if}= | Get Interface Name | ${dut2} | memif1 -| | ${dut2_in_if}= | Get Interface Name | ${dut2} | memif2 +| | ${dut2_out_if}= | Run Keyword If | ${dut2_status} +| | ... | Get Interface Name | ${dut2} | memif1 +| | ${dut2_in_if}= | Run Keyword If | ${dut2_status} +| | ... | Get Interface Name | ${dut2} | memif2 | | Remove Values From List | ${sid_list_dir0} | ${dut2_sid1} -| | Run Keyword If | "${behavior}" == "static_proxy" +| | Run Keyword If | ${dut2_status} and '${behavior}' == 'static_proxy' | | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1} | end.as | | ... | ${NONE} | ${dut2_nh} | ${NONE} | ${dut2_out_if} | ${dut2_in_if} | | ... | ${dut1_sid1} | @{sid_list_dir0} -| | ... | ELSE IF | "${behavior}" == "dynamic_proxy" +| | ... | ELSE IF | ${dut2_status} and '${behavior}' == 'dynamic_proxy' | | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1} | end.ad | | ... | next_hop=${dut2_nh} | out_if=${dut2_out_if} | in_if=${dut2_in_if} -| | ... | ELSE IF | "${behavior}" == "masquerading" +| | ... | ELSE IF | ${dut2_status} and '${behavior}' == 'masquerading' | | ... | Configure SR LocalSID on DUT | ${dut2} | ${dut2_sid1} | end.am | | ... | next_hop=${dut2_nh} | out_if=${dut2_out_if} | in_if=${dut2_in_if} -| | ... | ELSE | Fail | Unsupported behaviour: ${behavior} +| | ... | ELSE IF | ${dut2_status} +| | ... | Fail | Unsupported behaviour: ${behavior} # Configure SRv6 for direction1 on DUT1 | | ${dut1_out_if}= | Get Interface Name | ${dut1} | memif1 | | ${dut1_in_if}= | Get Interface Name | ${dut1} | memif2 | | Remove Values From List | ${sid_list_dir1} | ${dut1_sid2} -| | Run Keyword If | "${behavior}" == "static_proxy" +| | Run Keyword If | '${behavior}' == 'static_proxy' | | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2} | end.as | | ... | ${NONE} | ${dut1_nh} | ${NONE} | ${dut1_out_if} | ${dut1_in_if} | | ... | ${dut2_sid2} | @{sid_list_dir1} -| | ... | ELSE IF | "${behavior}" == "dynamic_proxy" +| | ... | ELSE IF | '${behavior}' == 'dynamic_proxy' | | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2} | end.ad | | ... | next_hop=${dut1_nh} | out_if=${dut1_out_if} | in_if=${dut1_in_if} -| | ... | ELSE IF | "${behavior}" == "masquerading" +| | ... | ELSE IF | '${behavior}' == 'masquerading' | | ... | Configure SR LocalSID on DUT | ${dut1} | ${dut1_sid2} | end.am | | ... | next_hop=${dut1_nh} | out_if=${dut1_out_if} | in_if=${dut1_in_if} | | ... | ELSE | Fail | Unsupported behaviour: ${behavior} diff --git a/resources/libraries/robot/shared/traffic.robot b/resources/libraries/robot/shared/traffic.robot index cc33969540..0b65c8d892 100644 --- a/resources/libraries/robot/shared/traffic.robot +++ b/resources/libraries/robot/shared/traffic.robot @@ -495,3 +495,64 @@ | | ... | --ot_mode | ${ot_mode} | | Run Traffic Script On Node | lisp/lispgpe_check.py | ${tg_node} | | ... | ${args} + +| Send IPv6 Packet and verify SRv6 encapsulation in received packet +| | [Documentation] | Send IP packet from TG to DUT. Receive IPv6 packet with\ +| | ... | SRv6 extension header from DUT on TG and verify SRv6 encapsulation.\ +| | ... | Send IPv6 packet with SRv6 extension header in opposite direction and\ +| | ... | verify received IP packet. +| | +| | ... | *Arguments:* +| | ... | - node - TG node. Type: dictionary +| | ... | - 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 +| | ... | - src_ip - Source IP address. Type: string +| | ... | - dst_ip - Destination IP address. Type: string +| | ... | - dut_srcsid - Source SID on DUT (dir0). Type: string +| | ... | - dut_dstsid1 - The first destination SID on DUT (dir1). Type: string +| | ... | - tg_srcsid - Source SID on TG (dir1). Type: string +| | ... | - tg_dstsid1 - The first destination SID on TG (dir0). Type: string +| | ... | - dut_dstsid2 - The second destination SID on DUT (dir1). Type: string +| | ... | - tg_dstsid2 - The second destination SID on TG (dir0). Type: string +| | ... | - decap - True if decapsulation expected, false if encapsulated packet +| | ... | expected on receiving interface (Optional). Type: boolean +| | ... | - tg_dstsid3 - The third destination SID on TG (dir0) (Optional). +| | ... | Type: string +| | ... | - dut_dstsid3 - The third destination SID on DUT (dir1) (Optional). +| | ... | Type: string +| | ... | - static_proxy - Switch for SRv6 with endpoint to SR-unaware Service +| | ... | Function via static proxy (Optional). Type: boolean +| | +| | ... | *Example:* +| | ... | \| Send IPv6 Packet and verify SRv6 encapsulation in received packet\ +| | ... | \| ${nodes['TG']} \| eth1 \| eth2 \ +| | ... | \| 52:54:00:d4:d8:22 \| 52:54:00:d4:d8:3e \| 2002:1:: \ +| | ... | \| 2003:2:: \| 2003:1:: \| 2002:2:: \| decap=${False} \ +| | ... | \| tg_dstsid3=2002:4:: \| dut_dstsid3=2003:4:: \ +| | ... | \| static_proxy=${True} \| +| | +| | [Arguments] | ${node} | ${tx_interface} | ${rx_interface} | ${tx_dst_mac} +| | ... | ${rx_src_mac} | ${src_ip} | ${dst_ip} | ${dut_srcsid} +| | ... | ${dut_dstsid1} | ${tg_srcsid} | ${tg_dstsid1} +| | ... | ${dut_dstsid2}=${None} | ${tg_dstsid2}=${None} | ${decap}=${True} +| | ... | ${tg_dstsid3}=${None} | ${dut_dstsid3}=${None} +| | ... | ${static_proxy}=${False} +| | +| | ${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} | ${rx_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 ${src_ip} | --dst_ip ${dst_ip} | --dir0_srcsid ${dut_srcsid} +| | ... | --dir0_dstsid1 ${tg_dstsid1} | --dir0_dstsid2 ${tg_dstsid2} +| | ... | --dir1_srcsid ${tg_srcsid} | --dir1_dstsid1 ${dut_dstsid1} +| | ... | --dir1_dstsid2 ${dut_dstsid2} | --decap ${decap} +| | ... | --dir0_dstsid3 ${tg_dstsid3} | --dir1_dstsid3 ${dut_dstsid3} +| | ... | --static_proxy ${static_proxy} +| | Run Traffic Script On Node | srv6_encap.py | ${node} | ${args} diff --git a/resources/traffic_scripts/srv6_encap.py b/resources/traffic_scripts/srv6_encap.py new file mode 100755 index 0000000000..506a245576 --- /dev/null +++ b/resources/traffic_scripts/srv6_encap.py @@ -0,0 +1,306 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2020 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: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Traffic script for SRv6 verification.""" + +import sys + +from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, IPv6ExtHdrSegmentRouting,\ + ipv6nh +from scapy.layers.l2 import Ether +from scapy.packet import Raw + +from resources.libraries.python.PacketVerifier import RxQueue, TxQueue +from resources.libraries.python.TrafficScriptArg import TrafficScriptArg + + +def check_srv6( + pkt_recv, src_mac, dst_mac, src_ip, dst_ip, dir_srcsid, dir_dstsid1, + dir_dstsid2, dir_dstsid3, segleft_corr, static_proxy=False): + """Check received SRv6 packet. + + :param pkt_recv: Received packet to verify. + :param src_mac: Source MAC address. + :param dst_mac: Destination MAC address. + :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 dir_srcsid: Source SID for SR in desired direction. + :param dir_dstsid1: Destination SID1 in desired direction. + :param dir_dstsid2: Destination SID2 in desired direction. + :param dir_dstsid3: Destination SID3 in desired direction. + :param segleft_corr: Correction for expected segleft value of SRH. + :type pkt_recv: scapy.Ether + :type src_mac: str + :type dst_mac: str + :type src_ip: str + :type dst_ip: str + :type dir_srcsid: str + :type dir_dstsid1: str + :type dir_dstsid2: str + :type dir_dstsid3: str + :type segleft_corr: int + :type static_proxy; bool + :raises RuntimeError: If received packet is invalid. + """ + if pkt_recv[Ether].src != src_mac: + raise RuntimeError( + f"Received frame has invalid source MAC address: " + f"{pkt_recv[Ether].src} should be: {src_mac}" + ) + if pkt_recv[Ether].dst != dst_mac: + raise RuntimeError( + f"Received frame has invalid destination MAC address: " + f"{pkt_recv[Ether].dst} should be: {dst_mac}" + ) + if not pkt_recv.haslayer(IPv6): + raise RuntimeError( + f"Not an IPv6 packet received: {pkt_recv!r}" + ) + ip6_pkt = pkt_recv[IPv6] + if ip6_pkt.src != dir_srcsid: + raise RuntimeError( + f"Outer IPv6 packet has invalid source address: " + f"{ip6_pkt.src} should be: {dir_srcsid}" + ) + dir_dstsids = [dir_dstsid2, dir_dstsid1] if dir_dstsid3 == u"None" \ + else [dir_dstsid3, dir_dstsid2, dir_dstsid1] if not static_proxy \ + else [dir_dstsid3, dir_dstsid2] + segleft = len(dir_dstsids) - segleft_corr if not static_proxy \ + else len(dir_dstsids) - segleft_corr + 1 + if ip6_pkt.dst != dir_dstsids[segleft]: + raise RuntimeError( + f"Outer IPv6 packet has invalid destination address: " + f"{ip6_pkt.dst} should be: {dir_dstsids[segleft]}" + ) + if dir_dstsid2 == u"None": + if ip6_pkt.haslayer(IPv6ExtHdrSegmentRouting): + raise RuntimeError( + f"Segment Routing Header in received packet: {pkt_recv!r}" + ) + if ip6_pkt.nh != 41: # ipv6nh[41] == IPv6 + raise RuntimeError( + f"Outer IPv6 packet has invalid next header: " + f"{ip6_pkt.nh} should be: 41 ({ipv6nh[41]})" + ) + ip6_pkt = ip6_pkt[IPv6][1] + else: + if not pkt_recv.haslayer(IPv6ExtHdrSegmentRouting): + raise RuntimeError( + f"No Segment Routing Header in received packet: {pkt_recv!r}" + ) + if ip6_pkt.nh != 43: # ipv6nh[43] == Routing Header + raise RuntimeError( + f"Outer IPv6 packet has invalid next header: " + f"{pkt_recv[IPv6][0].nh} should be: 43 ({ipv6nh[43]})" + ) + ip6_pkt = ip6_pkt[IPv6ExtHdrSegmentRouting] + if ip6_pkt.addresses != dir_dstsids: + raise RuntimeError( + f"Segment Routing Header has invalid addresses: " + f"{ip6_pkt.addresses} should be: {dir_dstsids}" + ) + if ip6_pkt.segleft != segleft: + raise RuntimeError( + f"Segment Routing Header has invalid segleft value: " + f"{ip6_pkt.segleft} should be: {segleft}" + ) + if ip6_pkt.nh != 41: # ipv6nh[41] == IPv6 + raise RuntimeError( + f"Segment Routing Header has invalid next header: " + f"{ip6_pkt.nh} should be: 41 ({ipv6nh[41]})" + ) + ip6_pkt = ip6_pkt[IPv6] + if ip6_pkt.src != src_ip: + raise RuntimeError( + f"Inner IPv6 packet has invalid source address: " + f"{ip6_pkt.src} should be: {src_ip}" + ) + if ip6_pkt.dst != dst_ip: + raise RuntimeError( + f"Inner IPv6 packet has invalid destination address: " + f"{ip6_pkt.dst} should be: {dst_ip}" + ) + if ip6_pkt.nh != 59: # ipv6nh[59] == No Next Header + raise RuntimeError( + f"Inner IPv6 packet has invalid next header: " + f"{ip6_pkt.nh} should be: 59 ({ipv6nh[59]})" + ) + + +def check_ip(pkt_recv, src_mac, dst_mac, src_ip, dst_ip): + """Check received IPv6 packet. + + :param pkt_recv: Received packet to verify. + :param src_mac: Source MAC address. + :param dst_mac: Destination MAC address. + :param src_ip: Source IP/IPv6 address. + :param dst_ip: Destination IP/IPv6 address. + :type pkt_recv: scapy.Ether + :type src_mac: str + :type dst_mac: str + :type src_ip: str + :type dst_ip: str + :raises RuntimeError: If received packet is invalid. + """ + if pkt_recv[Ether].src != src_mac: + raise RuntimeError( + f"Received frame has invalid source MAC address: " + f"{pkt_recv[Ether].src} should be: {src_mac}" + ) + + if pkt_recv[Ether].dst != dst_mac: + raise RuntimeError( + f"Received frame has invalid destination MAC address: " + f"{pkt_recv[Ether].dst} should be: {dst_mac}" + ) + + if not pkt_recv.haslayer(IPv6): + raise RuntimeError( + f"Not an {IPv6.name} packet received: {pkt_recv!r}" + ) + + if pkt_recv[IPv6].dst != dst_ip: + raise RuntimeError( + f"Received packet has invalid destination address: " + f"{pkt_recv[IPv6.name].dst} should be: {dst_ip}" + ) + + if pkt_recv[IPv6].src != src_ip: + raise RuntimeError( + f"Received packet has invalid destination address: " + f"{pkt_recv[IPv6.name].dst} should be: {src_ip}" + ) + + if pkt_recv[IPv6].nh != 59: # ipv6nh[59] == No Next Header + raise RuntimeError( + f"Received IPv6 packet has invalid next header: " + f"{IPv6.nh} should be: 59 ({ipv6nh[59]})" + ) + + +def main(): + """Send, receive and check IPv6 and IPv6ExtHdrSegmentRouting packets.""" + + args = TrafficScriptArg( + [ + u"tx_src_mac", u"tx_dst_mac", u"rx_src_mac", u"rx_dst_mac", + u"src_ip", u"dst_ip", u"dir0_srcsid", u"dir0_dstsid1", + u"dir0_dstsid2", u"dir1_srcsid", u"dir1_dstsid1", u"dir1_dstsid2", + u"decap", u"dir0_dstsid3", u"dir1_dstsid3", u"static_proxy" + ] + ) + + tx_txq = TxQueue(args.get_arg(u"tx_if")) + tx_rxq = RxQueue(args.get_arg(u"tx_if")) + rx_txq = TxQueue(args.get_arg(u"rx_if")) + rx_rxq = RxQueue(args.get_arg(u"rx_if")) + + tx_src_mac = args.get_arg(u"tx_src_mac") + tx_dst_mac = args.get_arg(u"tx_dst_mac") + rx_src_mac = args.get_arg(u"rx_src_mac") + rx_dst_mac = args.get_arg(u"rx_dst_mac") + src_ip = args.get_arg(u"src_ip") + dst_ip = args.get_arg(u"dst_ip") + + dir0_srcsid = args.get_arg(u"dir0_srcsid") + dir0_dstsid1 = args.get_arg(u"dir0_dstsid1") + dir0_dstsid2 = args.get_arg(u"dir0_dstsid2") + dir1_srcsid = args.get_arg(u"dir1_srcsid") + dir1_dstsid1 = args.get_arg(u"dir1_dstsid1") + dir1_dstsid2 = args.get_arg(u"dir1_dstsid2") + decap = args.get_arg(u"decap") + dir0_dstsid3 = args.get_arg(u"dir0_dstsid3") + dir1_dstsid3 = args.get_arg(u"dir1_dstsid3") + static_proxy = args.get_arg(u"static_proxy") + + ip_pkt = IPv6(src=src_ip, dst=dst_ip) + + sent_packets = list() + tx_pkt_send = (Ether(src=tx_src_mac, dst=tx_dst_mac) / ip_pkt) + tx_pkt_send /= Raw() + size_limit = 78 + if len(tx_pkt_send) < size_limit: + tx_pkt_send[Raw].load += (b"\0" * (size_limit - len(tx_pkt_send))) + 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(f"{IPv6.name} packet Rx timeout") + + 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_srv6( + rx_pkt_recv, rx_src_mac, rx_dst_mac, src_ip, dst_ip, dir0_srcsid, + dir0_dstsid1, dir0_dstsid2, dir0_dstsid3, 1 + ) + + ip_pkt = IPv6(src=dst_ip, dst=src_ip) + ip_pkt /= Raw() + if len(ip_pkt) < (size_limit - 14): + ip_pkt[Raw].load += (b"\0" * (size_limit - 14 - len(ip_pkt))) + + rx_pkt_send = ( + Ether(src=rx_dst_mac, dst=rx_src_mac) / + IPv6(src=dir1_srcsid, dst=dir1_dstsid1) / + IPv6ExtHdrSegmentRouting( + segleft=1 if dir1_dstsid3 == u"None" else 2, + lastentry=1 if dir1_dstsid3 == u"None" else 2, + addresses=[dir1_dstsid2, dir1_dstsid1] + if dir1_dstsid3 == u"None" + else [dir1_dstsid3, dir1_dstsid2, dir1_dstsid1] + ) / + ip_pkt + ) if dir1_dstsid2 != u"None" else ( + Ether(src=rx_dst_mac, dst=rx_src_mac) / + IPv6(src=dir1_srcsid, dst=dir1_dstsid1) / + ip_pkt + ) + rx_txq.send(rx_pkt_send) + + while True: + tx_pkt_recv = tx_rxq.recv(2, ignore=sent_packets) + + if tx_pkt_recv is None: + raise RuntimeError(f"{IPv6.name} packet Rx timeout") + + if tx_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 decap == u"True": + check_ip(tx_pkt_recv, tx_dst_mac, tx_src_mac, dst_ip, src_ip) + else: + check_srv6( + tx_pkt_recv, tx_dst_mac, tx_src_mac, dst_ip, src_ip, dir1_srcsid, + dir1_dstsid1, dir1_dstsid2, dir1_dstsid3, 2, + bool(static_proxy == u"True") + ) + + sys.exit(0) + + +if __name__ == u"__main__": + main() |