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