Dualstack support for L3VPN two router solution
[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 Library           SSHLibrary
4 Resource          CompareStream.robot
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 *** Variables ***
15 &{ITM_CREATE_DEFAULT}    tunneltype=vxlan    vlanid=0    prefix=1.1.1.1/24    gateway=0.0.0.0    dpnid1=1    portname1=BR1-eth1    ipaddress1=2.2.2.2
16 ...               dpnid2=2    portname2= BR2-eth1    ipaddress2=3.3.3.3
17 &{L3VPN_CREATE_DEFAULT}    vpnid=4ae8cd92-48ca-49b5-94e1-b2921a261111    name=vpn1    rd=["2200:1"]    exportrt=["2200:1","8800:1"]    importrt=["2200:1","8800:1"]    tenantid=6c53df3a-3456-11e5-a151-feff819cdc9f
18 ${VAR_BASE}       ${CURDIR}/../variables/vpnservice/
19 ${ODL_FLOWTABLE_L3VPN}    21
20 ${STATE_UP}       UP
21 ${STATE_DOWN}     DOWN
22 ${STATE_UNKNOWN}    UNKNOWN
23 ${STATE_ENABLE}    ENABLED
24 ${STATE_DISABLE}    DISABLE
25 ${SESSION_TIMEOUT}    10
26
27 *** Keywords ***
28 Basic Suite Setup
29     OpenStackOperations.OpenStack Suite Setup
30     TemplatedRequests.Create Default Session    timeout=${SESSION_TIMEOUT}
31
32 Basic Vpnservice Suite Cleanup
33     [Arguments]    ${vpn_instance_ids}=@{EMPTY}    ${vms}=@{EMPTY}    ${networks}=@{EMPTY}    ${subnets}=@{EMPTY}    ${ports}=@{EMPTY}    ${sgs}=@{EMPTY}
34     : FOR    ${vpn_instance_id}    IN    @{vpn_instance_ids}
35     \    BuiltIn.Run Keyword And Ignore Error    VPN Delete L3VPN    vpnid=${vpn_instance_id}
36     OpenStackOperations.Neutron Cleanup    ${vms}    ${networks}    ${subnets}    ${ports}    ${sgs}
37
38 VPN Create L3VPN
39     [Arguments]    &{Kwargs}
40     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
41     Run keyword if    "routerid" in ${Kwargs}    Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
42     ...    ELSE    Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
43     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
44     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
45     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_create    mapping=${L3vpn_create_actual_val}    session=default    http_timeout=${SESSION_TIMEOUT}
46
47 VPN Get L3VPN
48     [Arguments]    &{Kwargs}
49     [Documentation]    Will return detailed list of the L3VPN_ID received
50     ${resp} =    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/get_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
51     Log    ${resp}
52     [Return]    ${resp}
53
54 VPN Get L3VPN ID
55     [Arguments]    ${vrf_id}
56     [Documentation]    Check that sub interface ip has been learnt after ARP request
57     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_REST}
58     BuiltIn.Log    ${resp.content}
59     @{list_any_matches} =    String.Get_Regexp_Matches    ${resp.content}    \"vpn-instance-name\":\"${VPN_INSTANCE_ID}\",.*"vrf-id":"${vrf_id}",\"vpn-id\":(\\d+)    1
60     ${result} =    Evaluate    ${list_any_matches[0]} * 2
61     ${vpn_id_hex} =    BuiltIn.Convert To Hex    ${result}
62     [Return]    ${vpn_id_hex.lower()}
63
64 Associate L3VPN To Network
65     [Arguments]    &{Kwargs}
66     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
67     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
68
69 Dissociate L3VPN From Networks
70     [Arguments]    &{Kwargs}
71     [Documentation]    Disssociate the already associated networks from L3VPN
72     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
73
74 Associate VPN to Router
75     [Arguments]    &{Kwargs}
76     [Documentation]    Associate the created L3VPN to a router-id received as argument
77     CompareStream.Run_Keyword_If_At_Least_Fluorine    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_two_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
78     CompareStream.Run_Keyword_If_At_Most_Oxygen    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
79
80 Dissociate VPN to Router
81     [Arguments]    &{Kwargs}
82     [Documentation]    Dissociate the already associated routers from L3VPN
83     CompareStream.Run_Keyword_If_At_Least_Fluorine    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_two_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
84     CompareStream.Run_Keyword_If_At_Most_Oxygen    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
85
86 VPN Delete L3VPN
87     [Arguments]    &{Kwargs}
88     [Documentation]    Delete the created L3VPN
89     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_delete    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
90
91 ITM Create Tunnel
92     [Arguments]    &{Kwargs}
93     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
94     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
95     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
96     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/itm_create    mapping=${Itm_actual_val}    session=default    http_timeout=${SESSION_TIMEOUT}
97
98 ITM Get Tunnels
99     [Documentation]    Get all Tunnels and return the contents
100     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
101     Log    ${resp.content}
102     Should Be Equal As Strings    ${resp.status_code}    200
103     [Return]    ${resp.content}
104
105 ITM Delete Tunnel
106     [Arguments]    ${zone-name}
107     [Documentation]    Delete Tunnels created under the transport-zone
108     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
109     Log    ${resp.content}
110     Should Be Equal As Strings    ${resp.status_code}    200
111     [Return]    ${resp.content}
112
113 Verify Flows Are Present For L3VPN
114     [Arguments]    ${ip}    ${vm_ips}
115     [Documentation]    Verify Flows Are Present For L3VPN
116     ${flow_output}=    Run Command On Remote System And Log    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
117     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
118     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN},
119     Log    ${l3vpn_table}
120     : FOR    ${i}    IN    @{vm_ips}
121     \    ${resp}=    Should Contain    ${l3vpn_table}    ${i}
122
123 Verify GWMAC Entry On ODL
124     [Arguments]    ${GWMAC_ADDRS}
125     [Documentation]    get ODL GWMAC table entry
126     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_PORT_DATA_URL}
127     Log    ${resp.content}
128     Should Be Equal As Strings    ${resp.status_code}    200
129     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
130     \    Should Contain    ${resp.content}    ${macAdd}
131
132 Verify GWMAC Flow Entry Removed From Flow Table
133     [Arguments]    ${cnIp}
134     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
135     ${flow_output}=    Run Command On Remote System And Log    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
136     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
137     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
138     Log    ${gwmac_table}
139     #Verify GWMAC address present in table 19
140     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
141     \    Should Not Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
142
143 Verify ARP REQUEST in groupTable
144     [Arguments]    ${group_output}    ${Group-ID}
145     [Documentation]    get flow dump for group ID
146     Should Contain    ${group_output}    group_id=${Group-ID}
147     ${arp_group} =    Get Lines Containing String    ${group_output}    group_id=${Group-ID}
148     Log    ${arp_group}
149     CompareStream.Run_Keyword_If_At_Most_Oxygen    BuiltIn.Should Match Regexp    ${arp_group}    ${ARP_REQUEST_GROUP_REGEX}
150     CompareStream.Run_Keyword_If_At_Least_Fluorine    BuiltIn.Should Match Regexp    ${arp_group}    ${ARP_REQUEST_GROUP_REGEX_FLUORINE}
151
152 Verify Tunnel Status as UP
153     [Documentation]    Verify that the tunnels are UP
154     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
155     Log    ${output}
156     Should Contain    ${output}    ${STATE_UP}
157     Should Not Contain    ${output}    ${STATE_DOWN}
158     Should Not Contain    ${output}    ${STATE_UNKNOWN}
159
160 Verify Tunnel Status as DOWN
161     [Documentation]    Verify that the tunnels are DOWN
162     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
163     Log    ${output}
164     Should Contain    ${output}    ${STATE_DOWN}
165     Should Not Contain    ${output}    ${STATE_UP}
166     Should Not Contain    ${output}    ${STATE_UNKNOWN}
167
168 Verify Tunnel Status as UNKNOWN
169     [Documentation]    Verify that the tunnels are in Unknown state
170     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
171     Log    ${output}
172     Should Not Contain    ${output}    ${STATE_UP}
173     Should Not Contain    ${output}    ${STATE_DOWN}
174     Should Contain    ${output}    ${STATE_UNKNOWN}
175
176 Verify VXLAN interface
177     [Documentation]    Verify that the VXLAN interfaces are Enabled
178     ${output}=    Issue Command On Karaf Console    ${VXLAN_SHOW}
179     Log    ${output}
180     Should Contain    ${output}    ${STATE_UP}
181     Should Contain    ${output}    ${STATE_ENABLE}
182     Should Not Contain    ${output}    ${STATE_DISABLE}
183
184 Get Fib Entries
185     [Arguments]    ${session}
186     [Documentation]    Get Fib table entries from ODL session
187     ${resp}    RequestsLibrary.Get Request    ${session}    ${FIB_ENTRIES_URL}
188     Log    ${resp.content}
189     [Return]    ${resp.content}
190
191 Get Gateway MAC And IP Address
192     [Arguments]    ${router_Name}    ${ip_regex}=${IP_REGEX}
193     [Documentation]    Get Gateway mac and IP Address
194     ${output} =    OpenStack CLI    openstack port list --router ${router_Name}
195     @{MacAddr-list} =    Get Regexp Matches    ${output}    ${MAC_REGEX}
196     @{IpAddr-list} =    Get Regexp Matches    ${output}    ${ip_regex}
197     [Return]    ${MacAddr-list}    ${IpAddr-list}
198
199 Test Teardown With Tcpdump Stop
200     [Arguments]    ${conn_ids}=@{EMPTY}
201     OpenStackOperations.Stop Packet Capture On Nodes    ${conn_ids}
202     Get Test Teardown Debugs
203
204 Verify IPv4 GWMAC Flow Entry On Flow Table
205     [Arguments]    ${group_output}    ${group_id}    ${flow_output}
206     Verify ARP REQUEST in groupTable    ${group_output}    ${groupID[1]}
207     #Verify ARP_RESPONSE_TABLE - 81
208     Should Contain    ${flow_output}    table=${ARP_RESPONSE_TABLE}
209     ${arpResponder_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_RESPONSE_TABLE}
210     Should Contain    ${arpResponder_table}    priority=0 actions=drop
211     : FOR    ${macAdd}    ${ipAdd}    IN ZIP    ${GWMAC_ADDRS}    ${GWIP_ADDRS}
212     \    ${ARP_RESPONSE_IP_MAC_REGEX} =    Set Variable    arp_tpa=${ipAdd},arp_op=1 actions=.*,set_field:${macAdd}->eth_src
213     \    Should Match Regexp    ${arpResponder_table}    ${ARP_RESPONSE_IP_MAC_REGEX}
214
215 Verify IPv6 GWMAC Flow Entry On Flow Table
216     [Arguments]    ${flow_output}
217     Should Contain    ${flow_output}    table=${IPV6_TABLE}
218     ${icmp_ipv6_flows} =    Get Lines Containing String    ${flow_output}    icmp_type=135
219     : FOR    ${ip_addr}    IN    @{GWIP_ADDRS}
220     \    ${rule} =    Set Variable    icmp_type=135,icmp_code=0,nd_target=${ip_addr} actions=CONTROLLER:65535
221     \    Should Match Regexp    ${icmp_ipv6_flows}    ${rule}
222
223 Verify GWMAC Flow Entry On Flow Table
224     [Arguments]    ${cnIp}    ${ipv}=ipv4
225     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
226     ${flow_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}
227     ${group_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-groups ${INTEGRATION_BRIDGE}
228     Should Contain    ${flow_output}    table=${DISPATCHER_TABLE}
229     ${dispatcher_table} =    Get Lines Containing String    ${flow_output}    table=${DISPATCHER_TABLE}
230     Should Contain    ${dispatcher_table}    goto_table:${GWMAC_TABLE}
231     Should Not Contain    ${dispatcher_table}    goto_table:${ARP_RESPONSE_TABLE}
232     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
233     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
234     #Verify GWMAC address present in table 19
235     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
236     \    Should Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
237     #verify Miss entry
238     Should Contain    ${gwmac_table}    actions=resubmit(,17)
239     #Verify ARP_CHECK_TABLE - 43
240     #arp request and response
241     ${arpchk_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_CHECK_TABLE}
242     CompareStream.Run_Keyword_If_At_Most_Oxygen    BuiltIn.Should Match Regexp    ${arpchk_table}    ${ARP_RESPONSE_REGEX}
243     CompareStream.Run_Keyword_If_At_Least_Fluorine    BuiltIn.Should Match Regexp    ${arpchk_table}    ${ARP_RESPONSE_REGEX_FLUORINE}
244     ${arppunt_table} =    String.Get Lines Containing String    ${flow_output}    table=${ARP_PUNT_TABLE}
245     CompareStream.Run_Keyword_If_At_Least_Fluorine    BuiltIn.Should Match Regexp    ${arppunt_table}    ${ARP_PUNT_RESPONSE_REGEX}
246     ${match} =    Should Match Regexp    ${arpchk_table}    ${ARP_REQUEST_REGEX}
247     ${groupID} =    Split String    ${match}    separator=:
248     BuiltIn.Run Keyword If    '${ipv}' == 'ipv4'    Verify IPv4 GWMAC Flow Entry On Flow Table    ${group_output}    ${group_id}    ${flow_output}
249     ...    ELSE    Verify IPv6 GWMAC Flow Entry On Flow Table    ${flow_output}
250
251 Delete Multiple L3VPNs
252     [Arguments]    @{vpns}
253     [Documentation]    Delete three L3VPNs created using Multiple L3VPN Test
254     : FOR    ${vpn}    IN    ${vpns}
255     \    VPN Delete L3VPN    vpnid=${vpn}