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