CSIT-25 DHCPv4 proxy tests
[csit.git] / resources / libraries / robot / dhcp_client.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
14 *** Settings ***
15 | Library  | Collections
16 | Resource | resources/libraries/robot/default.robot
17 | Library  | resources.libraries.python.Dhcp.DhcpClient
18 | Library  | resources.libraries.python.TrafficScriptExecutor
19 | Documentation | DHCP Client specific keywords.
20
21 *** Keywords ***
22 | Check DHCP DISCOVER header
23 | | [Documentation] | Check if DHCP DISCOVER message contains all required
24 | | ... | fields.
25 | | ...
26 | | ... | *Arguments:*
27 | | ... | - tg_node - TG node. Type: dictionary
28 | | ... | - interface - TG interface where listen for DHCP DISCOVER message.
29 | | ... |   Type: string
30 | | ... | - src_mac - DHCP client MAC address. Type: string
31 | | ... | - hostname - DHCP client hostname (Optional, Default="", if not
32 | | ... |   specified, the hostname is not checked). Type: string
33 | | ...
34 | | ... | *Return:*
35 | | ... | - No value returned.
36 | | ...
37 | | ... | *Example:*
38 | | ...
39 | | ... | \| Check DHCP DISCOVER header \| ${nodes['TG']} \
40 | | ... | \| eth2 \| 08:00:27:66:b8:57 \|
41 | | ... | \| Check DHCP DISCOVER header \| ${nodes['TG']} \
42 | | ... | \| eth2 \| 08:00:27:66:b8:57 \| client-hostname \|
43 | | ...
44 | | [Arguments] | ${tg_node} | ${interface} | ${src_mac} | ${hostname}=${EMPTY}
45 | | ${interface_name}= | Get interface name | ${tg_node} | ${interface}
46 | | ${args}= | Catenate | --rx_if | ${interface_name} | --rx_src_mac | ${src_mac}
47 | | ${args}= | Run Keyword If | "${hostname}" == "" | Set Variable | ${args}
48 | | ...      | ELSE | Catenate | ${args} | --hostname | ${hostname}
49 | | Run Traffic Script On Node | dhcp/check_dhcp_discover.py
50 | | ... | ${tg_node} | ${args}
51
52
53 | Check DHCP REQUEST after OFFER
54 | | [Documentation] | Check if DHCP REQUEST message contains all required
55 | | ... | fields. DHCP REQUEST should be send by a client after DHCP OFFER
56 | | ... | message sent by a server.
57 | | ...
58 | | ... | *Arguments:*
59 | | ... | - tg_node - TG node. Type: dictionary
60 | | ... | - tg_interface - TG interface where listen for DHCP DISCOVER,
61 | | ... |   send DHCP OFFER and listen for DHCP REQUEST messages. Type: string
62 | | ... | - server_mac - DHCP server MAC address. Type: string
63 | | ... | - server_ip - DHCP server IP address. Type: string
64 | | ... | - client_mac - DHCP client MAC address. Type: string
65 | | ... | - client_ip - IP address that should be offered to client.
66 | | ... |   Type: string
67 | | ... | - client_mask - IP netmask that should be offered to client.
68 | | ... |   Type: string
69 | | ... | - hostname - DHCP client hostname (Optional, Default="", if not
70 | | ... |   specified, the hostname is not checked). Type: string
71 | | ... | - offer_xid - Transaction ID (Optional, Default="", if not specified
72 | | ... |   xid field in DHCP OFFER is same as in DHCP DISCOVER message).
73 | | ... |   Type: integer
74 | | ...
75 | | ... | *Return:*
76 | | ... | - No value returned.
77 | | ...
78 | | ... | *Raises:*
79 | | ... | - DHCP REQUEST Rx timeout - if no DHCP REQUEST is received.
80 | | ...
81 | | ... | *Example:*
82 | | ...
83 | | ... | \| Check DHCP REQUEST after OFFER \| ${nodes['TG']} \
84 | | ... | \| eth2 \| 08:00:27:66:b8:57 \| 192.168.23.1 \
85 | | ... | \| 08:00:27:46:2b:4c \| 192.168.23.10 \| 255.255.255.0 \|
86 | | ...
87 | | ... | \| Run Keyword And Expect Error \| DHCP REQUEST Rx timeout \
88 | | ... | \| Check DHCP REQUEST after OFFER \
89 | | ... | \| ${nodes['TG']} \| eth2 \| 08:00:27:66:b8:57 \| 192.168.23.1 \
90 | | ... | \| 08:00:27:46:2b:4c \| 192.168.23.10 \| 255.255.255.0 \
91 | | ... | \| offer_xid=11113333 \|
92 | | ...
93 | | [Arguments] | ${tg_node} | ${tg_interface} | ${server_mac} | ${server_ip}
94 | | ... | ${client_mac} | ${client_ip} | ${client_mask}
95 | | ... | ${hostname}=${EMPTY} | ${offer_xid}=${EMPTY}
96 | | ${tg_interface_name}= | Get interface name | ${tg_node} | ${tg_interface}
97 | | ${args}= | Catenate | --rx_if | ${tg_interface_name} | --server_mac
98 | | ... | ${server_mac} | --server_ip | ${server_ip} | --client_mac
99 | | ... | ${client_mac} | --client_ip | ${client_ip} | --client_mask
100 | | ... | ${client_mask}
101 | | ${args}= | Run Keyword If | "${hostname}" == "" | Set Variable | ${args}
102 | | ...      | ELSE | Catenate | ${args} | --hostname | ${hostname}
103 | | ${args}= | Run Keyword If | "${offer_xid}" == "" | Set Variable | ${args}
104 | | ...      | ELSE | Catenate | ${args} | --offer_xid | ${offer_xid}
105 | | Run Traffic Script On Node | dhcp/check_dhcp_request.py
106 | | ... | ${tg_node} | ${args}
107
108
109 | Send IP configuration to client via DHCP
110 | | [Documentation] | Run script that sends IP configuration to the DHCP client.
111 | | ...
112 | | ... | *Arguments:*
113 | | ... | - tg_node - TG node. Type: dictionary
114 | | ... | - tg_interface - TG interface where listen for DHCP DISCOVER,
115 | | ... |   send DHCP OFFER and DHCP ACK after DHCP REQUEST messages.
116 | | ... |   Type: string
117 | | ... | - server_mac - DHCP server MAC address. Type: string
118 | | ... | - server_ip - DHCP server IP address. Type: string
119 | | ... | - client_ip - IP address that is offered to client. Type: string
120 | | ... | - client_mask - IP netmask that is offered to client. Type: string
121 | | ... | - lease_time - IP lease time in seconds. Type: integer
122 | | ...
123 | | ... | *Return:*
124 | | ... | - No value returned.
125 | | ...
126 | | ... | *Example:*
127 | | ...
128 | | ... | \| Send IP configuration to client via DHCP \| ${nodes['TG']} \
129 | | ... | \| eth2 \| 08:00:27:66:b8:57 \| 192.168.23.1 \
130 | | ... | \| 192.168.23.10 \| 255.255.255.0 \| 86400 \|
131 | | ...
132 | | [Arguments] | ${tg_node} | ${tg_interface}
133 | | ... | ${server_mac} | ${server_ip} | ${client_ip} | ${client_mask}
134 | | ... | ${lease_time}
135 | | ${tg_interface_name}= | Get interface name | ${tg_node} | ${tg_interface}
136 | | ${args}= | Catenate | --rx_if | ${tg_interface_name}
137 | | ... | --server_mac | ${server_mac} | --server_ip | ${server_ip}
138 | | ... | --client_ip | ${client_ip} | --client_mask | ${client_mask}
139 | | ... | --lease_time | ${lease_time}
140 | | Run Traffic Script On Node | dhcp/check_dhcp_request_ack.py
141 | | ... | ${tg_node} | ${args}
142
143 | Send DHCP Messages
144 | | [Documentation] | Send and receive DHCP messages between client
145 | | ...             | and server through DHCP proxy.
146 | | ...
147 | | ... | *Arguments:*
148 | | ... | - tg_node - TG node. Type: dictionary
149 | | ... | - tg_interface1 - TG interface. Type: string
150 | | ... | - tg_interface2 - TG interface. Type: string
151 | | ... | - server_ip - DHCP server IP address. Type: string
152 | | ... | - server_mac - DHCP server MAC address. Type: string
153 | | ... | - client_ip - Client IP address. Type: string
154 | | ... | - client_mac - Client MAC address. Type: string
155 | | ... | - proxy_ip - DHCP proxy IP address. Type: string
156 | | ...
157 | | ... | *Return:*
158 | | ... | - No value returned.
159 | | ...
160 | | ... | *Example:*
161 | | ...
162 | | ... | \| Send DHCP Messages \| ${nodes['TG']} \
163 | | ... | \| eth3 \| eth4 \| 192.168.0.100 \| 08:00:27:cc:4f:54 \
164 | | ... | \| 172.16.0.2 \| 08:00:27:64:18:d2 \| 172.16.0.1 \|
165 | | ...
166 | | [Arguments] | ${tg_node} | ${tg_interface1} | ${tg_interface2}
167 | | ... | ${server_ip} | ${server_mac} | ${client_ip} | ${client_mac}
168 | | ... | ${proxy_ip} |
169 | | ${tg_interface_name1}= | Get interface name | ${tg_node} | ${tg_interface1}
170 | | ${tg_interface_name2}= | Get interface name | ${tg_node} | ${tg_interface2}
171 | | ${args}= | Catenate | --tx_if | ${tg_interface_name1}
172 | | ...                 | --rx_if | ${tg_interface_name2}
173 | | ...                 | --server_ip | ${server_ip}
174 | | ...                 | --server_mac | ${server_mac}
175 | | ...                 | --client_ip | ${client_ip}
176 | | ...                 | --client_mac | ${client_mac}
177 | | ...                 | --proxy_ip | ${proxy_ip}
178 | | Run Traffic Script On Node | dhcp/send_dhcp_messages.py
179 | | ... | ${tg_node} | ${args}
180
181 | Send DHCP DISCOVER
182 | | [Documentation] | Send and receive DHCP DISCOVER.
183 | | ...
184 | | ... | *Arguments:*
185 | | ... | - tg_node - TG node. Type: dictionary
186 | | ... | - tg_interface1 - TG interface. Type: string
187 | | ... | - tg_interface2 - TG interface. Type: string
188 | | ... | - tx_src_ip - Source address of DHCP DISCOVER packet. Type: string
189 | | ... | - tx_dst_ip - Destination address of DHCP DISCOVER packet. Type: string
190 | | ...
191 | | ... | *Return:*
192 | | ... | - No value returned.
193 | | ...
194 | | ... | *Example:*
195 | | ...
196 | | ... | \| Send DHCP DISCOVER \| ${nodes['TG']} \
197 | | ... | \| eth3 \| eth4 \| 0.0.0.0 \| 255.255.255.255 \|
198 | | ...
199 | | [Arguments] | ${tg_node} | ${tg_interface1} | ${tg_interface2}
200 | | ... | ${tx_src_ip} | ${tx_dst_ip} |
201 | | ${tg_interface_name1}= | Get interface name | ${tg_node} | ${tg_interface1}
202 | | ${tg_interface_name2}= | Get interface name | ${tg_node} | ${tg_interface2}
203 | | ${args}= | Catenate | --tx_if | ${tg_interface_name1}
204 | | ...                 | --rx_if | ${tg_interface_name2}
205 | | ...                 | --tx_src_ip | ${tx_src_ip}
206 | | ...                 | --tx_dst_ip | ${tx_dst_ip}
207 | | Run Traffic Script On Node | dhcp/send_dhcp_discover.py
208 | | ... | ${tg_node} | ${args}
209
210 | Send DHCP DISCOVER should fail
211 | | [Documentation] | Send and receive DHCP DISCOVER should fail.
212 | | ...
213 | | ... | *Arguments:*
214 | | ... | - tg_node - TG node. Type: dictionary
215 | | ... | - tg_interface1 - TG interface. Type: string
216 | | ... | - tg_interface2 - TG interface. Type: string
217 | | ... | - tx_src_ip - Source address of DHCP DISCOVER packet. Type: string
218 | | ... | - tx_dst_ip - Destination address of DHCP DISCOVER packet. Type: string
219 | | ...
220 | | ... | *Return:*
221 | | ... | - No value returned.
222 | | ...
223 | | ... | *Example:*
224 | | ...
225 | | ... | \| Send DHCP DISCOVER should fail \| ${nodes['TG']} \
226 | | ... | \| eth3 \| eth4 \| 0.0.0.0 \| 255.255.255.255 \|
227 | | ...
228 | | [Arguments] | ${tg_node} | ${tg_interface1} | ${tg_interface2}
229 | | ... | ${tx_src_ip} | ${tx_dst_ip} |
230 | | ${tg_interface_name1}= | Get interface name | ${tg_node} | ${tg_interface1}
231 | | ${tg_interface_name2}= | Get interface name | ${tg_node} | ${tg_interface2}
232 | | ${args}= | Catenate | --tx_if | ${tg_interface_name1}
233 | | ...                 | --rx_if | ${tg_interface_name2}
234 | | ...                 | --tx_src_ip | ${tx_src_ip}
235 | | ...                 | --tx_dst_ip | ${tx_dst_ip}
236 | | Run Keyword And Expect Error | DHCP DISCOVER timeout
237 | | ... | Run Traffic Script On Node | dhcp/send_dhcp_discover.py
238 | | ... | ${tg_node} | ${args}