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