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