Update Robot Framework format - step 1
[integration/test.git] / csit / libraries / VpnOperations.robot
1 *** Settings ***
2 Documentation       Openstack library. This library is useful for tests to create network, subnet, router and vm instances
3
4 Library             SSHLibrary
5 Resource            CompareStream.robot
6 Resource            Utils.robot
7 Resource            TemplatedRequests.robot
8 Resource            KarafKeywords.robot
9 Resource            ../variables/Variables.robot
10 Resource            ../variables/netvirt/Variables.robot
11 Library             Collections
12 Library             String
13 Library             OperatingSystem
14
15
16 *** Variables ***
17 &{ITM_CREATE_DEFAULT}
18 ...                         tunneltype=vxlan
19 ...                         vlanid=0
20 ...                         prefix=1.1.1.1/24
21 ...                         gateway=0.0.0.0
22 ...                         dpnid1=1
23 ...                         portname1=BR1-eth1
24 ...                         ipaddress1=2.2.2.2
25 ...                         dpnid2=2
26 ...                         portname2= BR2-eth1
27 ...                         ipaddress2=3.3.3.3
28 &{L3VPN_CREATE_DEFAULT}
29 ...                         vpnid=4ae8cd92-48ca-49b5-94e1-b2921a261111
30 ...                         name=vpn1
31 ...                         rd=["2200:1"]
32 ...                         exportrt=["2200:1","8800:1"]
33 ...                         importrt=["2200:1","8800:1"]
34 ...                         tenantid=6c53df3a-3456-11e5-a151-feff819cdc9f
35 ${VAR_BASE}                 ${CURDIR}/../variables/vpnservice/
36 ${ODL_FLOWTABLE_L3VPN}      21
37 ${STATE_UP}                 UP
38 ${STATE_DOWN}               DOWN
39 ${STATE_UNKNOWN}            UNKNOWN
40 ${STATE_ENABLE}             ENABLED
41 ${STATE_DISABLE}            DISABLE
42 ${SESSION_TIMEOUT}          10
43
44
45 *** Keywords ***
46 Basic Suite Setup
47     OpenStackOperations.OpenStack Suite Setup
48     TemplatedRequests.Create Default Session    timeout=${SESSION_TIMEOUT}
49
50 Basic Vpnservice Suite Cleanup
51     [Arguments]    ${vpn_instance_ids}=@{EMPTY}    ${vms}=@{EMPTY}    ${networks}=@{EMPTY}    ${subnets}=@{EMPTY}    ${ports}=@{EMPTY}    ${sgs}=@{EMPTY}
52     FOR    ${vpn_instance_id}    IN    @{vpn_instance_ids}
53         BuiltIn.Run Keyword And Ignore Error    VPN Delete L3VPN    vpnid=${vpn_instance_id}
54     END
55     OpenStackOperations.Neutron Cleanup    ${vms}    ${networks}    ${subnets}    ${ports}    ${sgs}
56
57 VPN Create L3VPN
58     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
59     [Arguments]    &{Kwargs}
60     IF    "routerid" in ${Kwargs}
61         Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
62     ELSE
63         Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
64     END
65     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
66     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
67     TemplatedRequests.Post_As_Json_Templated
68     ...    folder=${VAR_BASE}/l3vpn_create
69     ...    mapping=${L3vpn_create_actual_val}
70     ...    session=default
71     ...    http_timeout=${SESSION_TIMEOUT}
72
73 VPN Get L3VPN
74     [Documentation]    Will return detailed list of the L3VPN_ID received
75     [Arguments]    &{Kwargs}
76     ${resp} =    TemplatedRequests.Post_As_Json_Templated
77     ...    folder=${VAR_BASE}/get_l3vpn
78     ...    mapping=${Kwargs}
79     ...    session=default
80     ...    http_timeout=${SESSION_TIMEOUT}
81     Log    ${resp}
82     RETURN    ${resp}
83
84 VPN Get L3VPN ID
85     [Documentation]    Check that sub interface ip has been learnt after ARP request
86     [Arguments]    ${vrf_id}
87     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_REST}
88     BuiltIn.Log    ${resp.text}
89     @{list_any_matches} =    String.Get_Regexp_Matches
90     ...    ${resp.text}
91     ...    \"vpn-instance-name\":\"${VPN_INSTANCE_ID}\",.*"vrf-id":"${vrf_id}",\"vpn-id\":(\\d+)
92     ...    1
93     ${result} =    Evaluate    ${list_any_matches[0]} * 2
94     ${vpn_id_hex} =    BuiltIn.Convert To Hex    ${result}
95     RETURN    ${vpn_id_hex.lower()}
96
97 Verify L3VPN On ODL
98     [Documentation]    To verify L3VPN on ODL for given vpn ids
99     [Arguments]    @{vpns}
100     FOR    ${vpn}    IN    @{vpns}
101         ${resp} =    VpnOperations.VPN Get L3VPN    vpnid=${vpn}
102         BuiltIn.Should Contain    ${resp}    ${vpn}
103     END
104
105 Associate L3VPN To Network
106     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
107     [Arguments]    &{Kwargs}
108     TemplatedRequests.Post_As_Json_Templated
109     ...    folder=${VAR_BASE}/assoc_l3vpn
110     ...    mapping=${Kwargs}
111     ...    session=default
112     ...    http_timeout=${SESSION_TIMEOUT}
113
114 Associate L3VPNs To Networks
115     [Documentation]    Associates multiple networks to L3VPN and verify the same
116     [Arguments]    ${vpnid_list}    ${network_list}
117     FOR    ${network}    ${vpnid}    IN ZIP    ${network_list}    ${vpnid_list}
118         ${network_id} =    OpenStackOperations.Get Net Id    ${network}
119         VpnOperations.Associate L3VPN To Network    networkid=${network_id}    vpnid=${vpnid}
120         ${resp} =    VpnOperations.VPN Get L3VPN    vpnid=${vpnid}
121         BuiltIn.Should Contain    ${resp}    ${network_id}
122     END
123
124 Dissociate L3VPN From Networks
125     [Documentation]    Disssociate the already associated networks from L3VPN
126     [Arguments]    &{Kwargs}
127     TemplatedRequests.Post_As_Json_Templated
128     ...    folder=${VAR_BASE}/dissoc_l3vpn
129     ...    mapping=${Kwargs}
130     ...    session=default
131     ...    http_timeout=${SESSION_TIMEOUT}
132
133 Associate VPN to Router
134     [Documentation]    Associate the created L3VPN to a router-id received as argument
135     [Arguments]    &{Kwargs}
136     CompareStream.Run_Keyword_If_At_Least_Fluorine
137     ...    TemplatedRequests.Post_As_Json_Templated
138     ...    folder=${VAR_BASE}/assoc_two_router_l3vpn
139     ...    mapping=${Kwargs}
140     ...    session=default
141     ...    http_timeout=${SESSION_TIMEOUT}
142     CompareStream.Run_Keyword_If_At_Most_Oxygen
143     ...    TemplatedRequests.Post_As_Json_Templated
144     ...    folder=${VAR_BASE}/assoc_router_l3vpn
145     ...    mapping=${Kwargs}
146     ...    session=default
147     ...    http_timeout=${SESSION_TIMEOUT}
148
149 Dissociate VPN to Router
150     [Documentation]    Dissociate the already associated routers from L3VPN
151     [Arguments]    &{Kwargs}
152     CompareStream.Run_Keyword_If_At_Least_Fluorine
153     ...    TemplatedRequests.Post_As_Json_Templated
154     ...    folder=${VAR_BASE}/dissoc_two_router_l3vpn
155     ...    mapping=${Kwargs}
156     ...    session=default
157     ...    http_timeout=${SESSION_TIMEOUT}
158     CompareStream.Run_Keyword_If_At_Most_Oxygen
159     ...    TemplatedRequests.Post_As_Json_Templated
160     ...    folder=${VAR_BASE}/dissoc_router_l3vpn
161     ...    mapping=${Kwargs}
162     ...    session=default
163     ...    http_timeout=${SESSION_TIMEOUT}
164
165 VPN Delete L3VPN
166     [Documentation]    Delete the created L3VPN
167     [Arguments]    &{Kwargs}
168     TemplatedRequests.Post_As_Json_Templated
169     ...    folder=${VAR_BASE}/l3vpn_delete
170     ...    mapping=${Kwargs}
171     ...    session=default
172     ...    http_timeout=${SESSION_TIMEOUT}
173
174 ITM Create Tunnel
175     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
176     [Arguments]    &{Kwargs}
177     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
178     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
179     TemplatedRequests.Post_As_Json_Templated
180     ...    folder=${VAR_BASE}/itm_create
181     ...    mapping=${Itm_actual_val}
182     ...    session=default
183     ...    http_timeout=${SESSION_TIMEOUT}
184
185 ITM Get Tunnels
186     [Documentation]    Get all Tunnels and return the contents
187     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
188     Log    ${resp.text}
189     Should Be Equal As Strings    ${resp.status_code}    200
190     RETURN    ${resp.text}
191
192 ITM Delete Tunnel
193     [Documentation]    Delete Tunnels created under the transport-zone
194     [Arguments]    ${zone-name}
195     ${resp} =    RequestsLibrary.Delete Request
196     ...    session
197     ...    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
198     Log    ${resp.text}
199     Should Be Equal As Strings    ${resp.status_code}    200
200     RETURN    ${resp.text}
201
202 Verify Flows Are Present For L3VPN
203     [Documentation]    Verify Flows Are Present For L3VPN
204     [Arguments]    ${ip}    ${vm_ips}
205     ${flow_output} =    Run Command On Remote System And Log
206     ...    ${ip}
207     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
208     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
209     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN},
210     Log    ${l3vpn_table}
211     FOR    ${i}    IN    @{vm_ips}
212         ${resp} =    Should Contain    ${l3vpn_table}    ${i}
213     END
214
215 Verify Flows Are Present For L3VPN On All Compute Nodes
216     [Documentation]    Verify Flows Are Present For L3VPN On All Compute Nodes
217     [Arguments]    ${vm_ips}
218     FOR    ${ip}    IN    @{OS_CMP_IPS}
219         BuiltIn.Wait Until Keyword Succeeds
220         ...    30s
221         ...    10s
222         ...    VpnOperations.Verify Flows Are Present For L3VPN
223         ...    ${ip}
224         ...    ${vm_ips}
225     END
226
227 Verify GWMAC Entry On ODL
228     [Documentation]    get ODL GWMAC table entry
229     [Arguments]    ${GWMAC_ADDRS}
230     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_PORT_DATA_URL}
231     Log    ${resp.text}
232     Should Be Equal As Strings    ${resp.status_code}    200
233     FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
234         Should Contain    ${resp.text}    ${macAdd}
235     END
236
237 Verify GWMAC Flow Entry Removed From Flow Table
238     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
239     [Arguments]    ${cnIp}
240     ${flow_output} =    Run Command On Remote System And Log
241     ...    ${cnIp}
242     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
243     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
244     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
245     Log    ${gwmac_table}
246     #Verify GWMAC address present in table 19
247     FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
248         Should Not Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
249     END
250
251 Verify GWMAC Flow Entry Removed From Flow Table On All Compute Nodes
252     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
253     FOR    ${ip}    IN    @{OS_CMP_IPS}
254         BuiltIn.Wait Until Keyword Succeeds    30s    10s    Verify GWMAC Flow Entry Removed From Flow Table    ${ip}
255     END
256
257 Verify ARP REQUEST in groupTable
258     [Documentation]    get flow dump for group ID
259     [Arguments]    ${group_output}    ${Group-ID}
260     Should Contain    ${group_output}    group_id=${Group-ID}
261     ${arp_group} =    Get Lines Containing String    ${group_output}    group_id=${Group-ID}
262     Log    ${arp_group}
263     CompareStream.Run_Keyword_If_At_Most_Oxygen
264     ...    BuiltIn.Should Match Regexp
265     ...    ${arp_group}
266     ...    ${ARP_REQUEST_GROUP_REGEX}
267     CompareStream.Run_Keyword_If_At_Least_Fluorine
268     ...    BuiltIn.Should Match Regexp
269     ...    ${arp_group}
270     ...    ${ARP_REQUEST_GROUP_REGEX_FLUORINE}
271
272 Verify Tunnel Status as UP
273     [Documentation]    Verify that the tunnels are UP
274     IF    ${OS_NODE_CNT} == ${1}    RETURN    ${True}
275     ${output} =    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
276     Log    ${output}
277     Should Contain    ${output}    ${STATE_UP}
278     Should Not Contain    ${output}    ${STATE_DOWN}
279     Should Not Contain    ${output}    ${STATE_UNKNOWN}
280
281 Verify Tunnel Status as DOWN
282     [Documentation]    Verify that the tunnels are DOWN
283     ${output} =    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
284     Log    ${output}
285     Should Contain    ${output}    ${STATE_DOWN}
286     Should Not Contain    ${output}    ${STATE_UP}
287     Should Not Contain    ${output}    ${STATE_UNKNOWN}
288
289 Verify Tunnel Status as UNKNOWN
290     [Documentation]    Verify that the tunnels are in Unknown state
291     ${output} =    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
292     Log    ${output}
293     Should Not Contain    ${output}    ${STATE_UP}
294     Should Not Contain    ${output}    ${STATE_DOWN}
295     Should Contain    ${output}    ${STATE_UNKNOWN}
296
297 Verify VXLAN interface
298     [Documentation]    Verify that the VXLAN interfaces are Enabled
299     ${output} =    Issue Command On Karaf Console    ${VXLAN_SHOW}
300     Log    ${output}
301     Should Contain    ${output}    ${STATE_UP}
302     Should Contain    ${output}    ${STATE_ENABLE}
303     Should Not Contain    ${output}    ${STATE_DISABLE}
304
305 Get Fib Entries
306     [Documentation]    Get Fib table entries from ODL session
307     [Arguments]    ${session}
308     ${resp} =    RequestsLibrary.Get Request    ${session}    ${FIB_ENTRIES_URL}
309     Log    ${resp.text}
310     RETURN    ${resp.text}
311
312 Get Gateway MAC And IP Address
313     [Documentation]    Get Gateway mac and IP Address
314     [Arguments]    ${router_Name}    ${ip_regex}=${IP_REGEX}
315     ${output} =    OpenStack CLI    openstack port list --router ${router_Name}
316     @{MacAddr-list} =    Get Regexp Matches    ${output}    ${MAC_REGEX}
317     @{IpAddr-list} =    Get Regexp Matches    ${output}    ${ip_regex}
318     RETURN    ${MacAddr-list}    ${IpAddr-list}
319
320 Test Teardown With Tcpdump Stop
321     [Arguments]    ${conn_ids}=@{EMPTY}
322     OpenStackOperations.Stop Packet Capture On Nodes    ${conn_ids}
323     Get Test Teardown Debugs
324
325 Verify IPv4 GWMAC Flow Entry On Flow Table
326     [Arguments]    ${group_output}    ${group_id}    ${flow_output}
327     Verify ARP REQUEST in groupTable    ${group_output}    ${groupID[1]}
328     #Verify ARP_RESPONSE_TABLE - 81
329     Should Contain    ${flow_output}    table=${ARP_RESPONSE_TABLE}
330     ${arpResponder_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_RESPONSE_TABLE}
331     Should Contain    ${arpResponder_table}    priority=0 actions=drop
332     FOR    ${macAdd}    ${ipAdd}    IN ZIP    ${GWMAC_ADDRS}    ${GWIP_ADDRS}
333         ${ARP_RESPONSE_IP_MAC_REGEX} =    Set Variable
334         ...    arp_tpa=${ipAdd},arp_op=1 actions=.*,set_field:${macAdd}->eth_src
335         Should Match Regexp    ${arpResponder_table}    ${ARP_RESPONSE_IP_MAC_REGEX}
336     END
337
338 Verify IPv6 GWMAC Flow Entry On Flow Table
339     [Arguments]    ${flow_output}
340     Should Contain    ${flow_output}    table=${IPV6_TABLE}
341     ${icmp_ipv6_flows} =    Get Lines Containing String    ${flow_output}    icmp_type=135
342     FOR    ${ip_addr}    IN    @{GWIP_ADDRS}
343         ${rule} =    Set Variable    icmp_type=135,icmp_code=0,nd_target=${ip_addr} actions=CONTROLLER:65535
344         Should Match Regexp    ${icmp_ipv6_flows}    ${rule}
345     END
346
347 Verify GWMAC Flow Entry On Flow Table
348     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
349     [Arguments]    ${cnIp}    ${ipv}=ipv4
350     ${flow_output} =    Run Command On Remote System
351     ...    ${cnIp}
352     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
353     ${group_output} =    Run Command On Remote System
354     ...    ${cnIp}
355     ...    sudo ovs-ofctl -O OpenFlow13 dump-groups ${INTEGRATION_BRIDGE}
356     Should Contain    ${flow_output}    table=${DISPATCHER_TABLE}
357     ${dispatcher_table} =    Get Lines Containing String    ${flow_output}    table=${DISPATCHER_TABLE}
358     Should Contain    ${dispatcher_table}    goto_table:${GWMAC_TABLE}
359     Should Not Contain    ${dispatcher_table}    goto_table:${ARP_RESPONSE_TABLE}
360     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
361     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
362     #Verify GWMAC address present in table 19
363     FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
364         Should Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
365         #verify Miss entry
366     END
367     Should Contain    ${gwmac_table}    actions=resubmit(,17)
368     #Verify ARP_CHECK_TABLE - 43
369     #arp request and response
370     ${arpchk_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_CHECK_TABLE}
371     CompareStream.Run_Keyword_If_At_Most_Oxygen
372     ...    BuiltIn.Should Match Regexp
373     ...    ${arpchk_table}
374     ...    ${ARP_RESPONSE_REGEX}
375     CompareStream.Run_Keyword_If_At_Least_Fluorine
376     ...    BuiltIn.Should Match Regexp
377     ...    ${arpchk_table}
378     ...    ${ARP_RESPONSE_REGEX_FLUORINE}
379     ${arppunt_table} =    String.Get Lines Containing String    ${flow_output}    table=${ARP_PUNT_TABLE}
380     CompareStream.Run_Keyword_If_At_Least_Fluorine
381     ...    BuiltIn.Should Match Regexp
382     ...    ${arppunt_table}
383     ...    ${ARP_PUNT_RESPONSE_REGEX}
384     ${match} =    Should Match Regexp    ${arpchk_table}    ${ARP_REQUEST_REGEX}
385     ${groupID} =    Split String    ${match}    separator=:
386     IF    '${ipv}' == 'ipv4'
387         Verify IPv4 GWMAC Flow Entry On Flow Table    ${group_output}    ${group_id}    ${flow_output}
388     ELSE
389         Verify IPv6 GWMAC Flow Entry On Flow Table    ${flow_output}
390     END
391
392 Verify GWMAC Flow Entry On Flow Table On All Compute Nodes
393     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
394     [Arguments]    ${ipv}=ipv4
395     FOR    ${ip}    IN    @{OS_CMP_IPS}
396         BuiltIn.Wait Until Keyword Succeeds
397         ...    30s
398         ...    10s
399         ...    VpnOperations.Verify GWMAC Flow Entry On Flow Table
400         ...    ${ip}
401         ...    ${ipv}
402     END
403
404 Delete Multiple L3VPNs
405     [Documentation]    Delete three L3VPNs created using Multiple L3VPN Test
406     [Arguments]    @{vpns}
407     FOR    ${vpn}    IN    @{vpns}
408         VPN Delete L3VPN    vpnid=${vpn}
409     END
410
411 VNI Test Setup
412     IF    "${OPENSTACK_TOPO}" == "1cmb-0ctl-0cmp"    RETURN
413     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
414
415 VNI Test Teardown
416     IF    "${OPENSTACK_TOPO}" == "1cmb-0ctl-0cmp"    RETURN
417     OpenStackOperations.Get Test Teardown Debugs