enable tcpdump on port 6653 in suite setup
[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 Associate L3VPN To Network
53     [Arguments]    &{Kwargs}
54     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
55     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
56
57 Dissociate L3VPN From Networks
58     [Arguments]    &{Kwargs}
59     [Documentation]    Disssociate the already associated networks from L3VPN
60     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
61
62 Associate VPN to Router
63     [Arguments]    &{Kwargs}
64     [Documentation]    Associate the created L3VPN to a router-id received as argument
65     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
66
67 Dissociate VPN to Router
68     [Arguments]    &{Kwargs}
69     [Documentation]    Dissociate the already associated routers from L3VPN
70     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_router_l3vpn    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
71
72 VPN Delete L3VPN
73     [Arguments]    &{Kwargs}
74     [Documentation]    Delete the created L3VPN
75     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_delete    mapping=${Kwargs}    session=default    http_timeout=${SESSION_TIMEOUT}
76
77 ITM Create Tunnel
78     [Arguments]    &{Kwargs}
79     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
80     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
81     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
82     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/itm_create    mapping=${Itm_actual_val}    session=default    http_timeout=${SESSION_TIMEOUT}
83
84 ITM Get Tunnels
85     [Documentation]    Get all Tunnels and return the contents
86     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
87     Log    ${resp.content}
88     Should Be Equal As Strings    ${resp.status_code}    200
89     [Return]    ${resp.content}
90
91 ITM Delete Tunnel
92     [Arguments]    ${zone-name}
93     [Documentation]    Delete Tunnels created under the transport-zone
94     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
95     Log    ${resp.content}
96     Should Be Equal As Strings    ${resp.status_code}    200
97     [Return]    ${resp.content}
98
99 Verify Flows Are Present For L3VPN
100     [Arguments]    ${ip}    ${vm_ips}
101     [Documentation]    Verify Flows Are Present For L3VPN
102     ${flow_output}=    Run Command On Remote System And Log    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
103     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
104     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN},
105     Log    ${l3vpn_table}
106     : FOR    ${i}    IN    @{vm_ips}
107     \    ${resp}=    Should Contain    ${l3vpn_table}    ${i}
108
109 Verify GWMAC Entry On ODL
110     [Arguments]    ${GWMAC_ADDRS}
111     [Documentation]    get ODL GWMAC table entry
112     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_PORT_DATA_URL}
113     Log    ${resp.content}
114     Should Be Equal As Strings    ${resp.status_code}    200
115     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
116     \    Should Contain    ${resp.content}    ${macAdd}
117
118 Verify GWMAC Flow Entry Removed From Flow Table
119     [Arguments]    ${cnIp}
120     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
121     ${flow_output}=    Run Command On Remote System And Log    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
122     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
123     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
124     Log    ${gwmac_table}
125     #Verify GWMAC address present in table 19
126     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
127     \    Should Not Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
128
129 Verify ARP REQUEST in groupTable
130     [Arguments]    ${group_output}    ${Group-ID}
131     [Documentation]    get flow dump for group ID
132     Should Contain    ${group_output}    group_id=${Group-ID}
133     ${arp_group} =    Get Lines Containing String    ${group_output}    group_id=${Group-ID}
134     Log    ${arp_group}
135     Should Match Regexp    ${arp_group}    ${ARP_REQUEST_GROUP_REGEX}
136
137 Verify Tunnel Status as UP
138     [Documentation]    Verify that the tunnels are UP
139     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
140     Log    ${output}
141     Should Contain    ${output}    ${STATE_UP}
142     Should Not Contain    ${output}    ${STATE_DOWN}
143     Should Not Contain    ${output}    ${STATE_UNKNOWN}
144
145 Verify Tunnel Status as DOWN
146     [Documentation]    Verify that the tunnels are DOWN
147     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
148     Log    ${output}
149     Should Contain    ${output}    ${STATE_DOWN}
150     Should Not Contain    ${output}    ${STATE_UP}
151     Should Not Contain    ${output}    ${STATE_UNKNOWN}
152
153 Verify Tunnel Status as UNKNOWN
154     [Documentation]    Verify that the tunnels are in Unknown state
155     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
156     Log    ${output}
157     Should Not Contain    ${output}    ${STATE_UP}
158     Should Not Contain    ${output}    ${STATE_DOWN}
159     Should Contain    ${output}    ${STATE_UNKNOWN}
160
161 Verify VXLAN interface
162     [Documentation]    Verify that the VXLAN interfaces are Enabled
163     ${output}=    Issue Command On Karaf Console    ${VXLAN_SHOW}
164     Log    ${output}
165     Should Contain    ${output}    ${STATE_UP}
166     Should Contain    ${output}    ${STATE_ENABLE}
167     Should Not Contain    ${output}    ${STATE_DISABLE}
168
169 Get Fib Entries
170     [Arguments]    ${session}
171     [Documentation]    Get Fib table entries from ODL session
172     ${resp}    RequestsLibrary.Get Request    ${session}    ${FIB_ENTRIES_URL}
173     Log    ${resp.content}
174     [Return]    ${resp.content}
175
176 Get Gateway MAC And IP Address
177     [Arguments]    ${router_Name}    ${ip_regex}=${IP_REGEX}
178     [Documentation]    Get Gateway mac and IP Address
179     ${output} =    Write Commands Until Prompt    neutron router-port-list ${router_Name}    30s
180     @{MacAddr-list} =    Get Regexp Matches    ${output}    ${MAC_REGEX}
181     @{IpAddr-list} =    Get Regexp Matches    ${output}    ${ip_regex}
182     [Return]    ${MacAddr-list}    ${IpAddr-list}
183
184 Test Teardown With Tcpdump Stop
185     [Arguments]    ${conn_ids}=@{EMPTY}
186     OpenStackOperations.Stop Packet Capture On Nodes    ${conn_ids}
187     Get Test Teardown Debugs
188
189 Verify IPv4 GWMAC Flow Entry On Flow Table
190     [Arguments]    ${group_output}    ${group_id}    ${flow_output}
191     Verify ARP REQUEST in groupTable    ${group_output}    ${groupID[1]}
192     #Verify ARP_RESPONSE_TABLE - 81
193     Should Contain    ${flow_output}    table=${ARP_RESPONSE_TABLE}
194     ${arpResponder_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_RESPONSE_TABLE}
195     Should Contain    ${arpResponder_table}    priority=0 actions=drop
196     : FOR    ${macAdd}    ${ipAdd}    IN ZIP    ${GWMAC_ADDRS}    ${GWIP_ADDRS}
197     \    ${ARP_RESPONSE_IP_MAC_REGEX} =    Set Variable    arp_tpa=${ipAdd},arp_op=1 actions=.*,set_field:${macAdd}->eth_src
198     \    Should Match Regexp    ${arpResponder_table}    ${ARP_RESPONSE_IP_MAC_REGEX}
199
200 Verify IPv6 GWMAC Flow Entry On Flow Table
201     [Arguments]    ${flow_output}
202     Should Contain    ${flow_output}    table=${IPV6_TABLE}
203     ${icmp_ipv6_flows} =    Get Lines Containing String    ${flow_output}    icmp_type=135
204     : FOR    ${ip_addr}    IN    @{GWIP_ADDRS}
205     \    ${rule} =    Set Variable    icmp_type=135,icmp_code=0,nd_target=${ip_addr} actions=CONTROLLER:65535
206     \    Should Match Regexp    ${icmp_ipv6_flows}    ${rule}
207
208 Verify GWMAC Flow Entry On Flow Table
209     [Arguments]    ${cnIp}    ${ipv}=ipv4
210     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
211     ${flow_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
212     ${group_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-groups br-int
213     Should Contain    ${flow_output}    table=${DISPATCHER_TABLE}
214     ${dispatcher_table} =    Get Lines Containing String    ${flow_output}    table=${DISPATCHER_TABLE}
215     Should Contain    ${dispatcher_table}    goto_table:${GWMAC_TABLE}
216     Should Not Contain    ${dispatcher_table}    goto_table:${ARP_RESPONSE_TABLE}
217     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
218     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
219     #Verify GWMAC address present in table 19
220     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
221     \    Should Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
222     #verify Miss entry
223     Should Contain    ${gwmac_table}    actions=resubmit(,17)
224     #Verify ARP_CHECK_TABLE - 43
225     #arp request and response
226     ${arpchk_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_CHECK_TABLE}
227     Should Match Regexp    ${arpchk_table}    ${ARP_RESPONSE_REGEX}
228     ${match} =    Should Match Regexp    ${arpchk_table}    ${ARP_REQUEST_REGEX}
229     ${groupID} =    Split String    ${match}    separator=:
230     BuiltIn.Run Keyword If    '${ipv}' == 'ipv4'    Verify IPv4 GWMAC Flow Entry On Flow Table    ${group_output}    ${group_id}    ${flow_output}
231     ...    ELSE    Verify IPv6 GWMAC Flow Entry On Flow Table    ${flow_output}
232
233 Delete Multiple L3VPNs
234     [Arguments]    @{vpns}
235     [Documentation]    Delete three L3VPNs created using Multiple L3VPN Test
236     : FOR    ${vpn}    IN    ${vpns}
237     \    VPN Delete L3VPN    vpnid=${vpn}