Refactor IPv4 utils
[csit.git] / resources / libraries / robot / ipv4.robot
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 *** Settings ***
14 | Resource | resources/libraries/robot/default.robot
15 | Resource | resources/libraries/robot/counters.robot
16 | Library | resources.libraries.python.IPv4Util.IPv4Util
17 | Library | resources.libraries.python.IPv4Setup.IPv4Setup
18 | Library | resources.libraries.python.TrafficScriptExecutor
19 | Variables | resources/libraries/python/IPv4NodeAddress.py | ${nodes}
20
21 *** Keywords ***
22
23 | Setup IPv4 adresses on all DUT nodes in topology
24 | | [Documentation] | Setup IPv4 address on all DUTs in topology
25 | | [Arguments] | ${nodes} | ${nodes_addr}
26 | | VPP nodes setup ipv4 addresses | ${nodes} | ${nodes_addr}
27
28 | Routes are set up for IPv4 testing
29 | | ${gateway}= | Get IPv4 address of node "${nodes['DUT2']}" interface "${nodes['DUT2']['interfaces']['port3']['name']}" from "${nodes_ipv4_addr}"
30 | | ${subnet} = | Get IPv4 subnet of node "${nodes['DUT2']}" interface "${nodes['DUT2']['interfaces']['port1']['name']}" from "${nodes_ipv4_addr}"
31 | | ${prefix_length} = | Get IPv4 address prefix of node "${nodes['DUT2']}" interface "${nodes['DUT2']['interfaces']['port1']['name']}" from "${nodes_ipv4_addr}"
32 | | Node "${nodes['DUT1']}" routes to IPv4 network "${subnet}" with prefix length "${prefix_length}" using interface "${nodes['DUT1']['interfaces']['port3']['name']}" via "${gateway}"
33 | | ${gateway} = | Get IPv4 address of node "${nodes['DUT1']}" interface "${nodes['DUT1']['interfaces']['port3']['name']}" from "${nodes_ipv4_addr}"
34 | | ${subnet} = | Get IPv4 subnet of node "${nodes['DUT1']}" interface "${nodes['DUT1']['interfaces']['port1']['name']}" from "${nodes_ipv4_addr}"
35 | | ${prefix_length} = | Get IPv4 address prefix of node "${nodes['DUT1']}" interface "${nodes['DUT1']['interfaces']['port1']['name']}" from "${nodes_ipv4_addr}"
36 | | Node "${nodes['DUT2']}" routes to IPv4 network "${subnet}" with prefix length "${prefix_length}" using interface "${nodes['DUT2']['interfaces']['port3']['name']}" via "${gateway}"
37
38 | Setup DUT nodes for IPv4 testing
39 | | Interfaces needed for IPv4 testing are in "up" state
40 | | Setup IPv4 adresses on all DUT nodes in topology | ${nodes} | ${nodes_ipv4_addr}
41 | | Setup ARP on all DUTs | ${nodes}
42 | | Routes are set up for IPv4 testing
43
44 | Setup nodes for IPv4 testing
45 | | Setup IPv4 adresses on all DUT nodes in topology | ${nodes} | ${nodes_ipv4_addr}
46 | | Setup ARP on all DUTs | ${nodes} | ${nodes_ipv4_addr}
47 | | Routes are set up for IPv4 testing
48
49 | TG interface "${tg_port}" can route to node "${node}" interface "${port}" "${hops}" hops away using IPv4
50 | | Node "${nodes['TG']}" interface "${tg_port}" can route to node "${node}" interface "${port}" "${hops}" hops away using IPv4
51
52 | Node "${from_node}" interface "${from_port}" can route to node "${to_node}" interface "${to_port}" "${hops}" hops away using IPv4
53 | | ${src_ip}= | Get IPv4 address of node "${from_node}" interface "${from_port}" from "${nodes_ipv4_addr}"
54 | | ${dst_ip}= | Get IPv4 address of node "${to_node}" interface "${to_port}" from "${nodes_ipv4_addr}"
55 | | ${src_mac}= | Get interface mac | ${from_node} | ${from_port}
56 | | ${dst_mac}= | Get interface mac | ${to_node} | ${to_port}
57 | | ${is_dst_tg}= | Is TG node | ${to_node}
58 | | ${adj_node} | ${adj_int}= | Get adjacent node and interface | ${nodes} | ${from_node} | ${from_port}
59 | | ${args}= | Traffic Script Gen Arg | ${to_port} | ${from_port} | ${src_mac}
60 | |          | ...                    | ${dst_mac} | ${src_ip} | ${dst_ip}
61 | | ${args}= | Catenate | ${args} | --hops ${hops} | --first_hop_mac ${adj_int['mac_address']}
62 | |          | ...      | --is_dst_defined ${is_dst_tg}
63 | | Run Traffic Script On Node | ipv4_ping_ttl_check.py | ${from_node} | ${args}
64
65 | Ipv4 icmp echo sweep
66 | | [Documentation] | Type of the src_node must be TG and dst_node must be DUT
67 | | [Arguments] | ${src_node} | ${dst_node} | ${src_port} | ${dst_port}
68 | | ${src_ip}= | Get IPv4 address of node "${src_node}" interface "${src_port}" from "${nodes_ipv4_addr}"
69 | | ${dst_ip}= | Get IPv4 address of node "${dst_node}" interface "${dst_port}" from "${nodes_ipv4_addr}"
70 | | ${src_mac}= | Get Interface Mac | ${src_node} | ${src_port}
71 | | ${dst_mac}= | Get Interface Mac | ${dst_node} | ${dst_port}
72 | | ${args}= | Traffic Script Gen Arg | ${src_port} | ${src_port} | ${src_mac}
73 | |          | ...                    | ${dst_mac} | ${src_ip} | ${dst_ip}
74 | # TODO: end_size is currently minimum MTU size for Ethernet minus IPv4 and
75 | # ICMP echo header size (1500 - 20 - 8),
76 | # MTU info is not in VAT sw_interface_dump output
77 | | ${args}= | Set Variable | ${args} --start_size 0 --end_size 1472 --step 1
78 | | Run Traffic Script On Node | ipv4_sweep_ping.py | ${src_node} | ${args}
79
80 | Send ARP request and validate response
81 | | [Arguments] | ${tg_node} | ${vpp_node}
82 | | ${link_name}= | Get first active connecting link between node "${tg_node}" and "${vpp_node}"
83 | | ${src_if}= | Get interface by link name | ${tg_node} | ${link_name}
84 | | ${dst_if}= | Get interface by link name | ${vpp_node} | ${link_name}
85 | | ${src_ip}= | Get IPv4 address of node "${tg_node}" interface "${src_if}" from "${nodes_ipv4_addr}"
86 | | ${dst_ip}= | Get IPv4 address of node "${vpp_node}" interface "${dst_if}" from "${nodes_ipv4_addr}"
87 | | ${src_mac}= | Get node link mac | ${tg_node} | ${link_name}
88 | | ${dst_mac}= | Get node link mac | ${vpp_node} | ${link_name}
89 | | ${args}= | Traffic Script Gen Arg | ${src_if} | ${src_if} | ${src_mac}
90 | |          | ...                    | ${dst_mac} | ${src_ip} | ${dst_ip}
91 | | Run Traffic Script On Node | arp_request.py | ${tg_node} | ${args}
92