Use consistent naming in vpn suite
[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 Setup
26     SetupUtils.Setup_Utils_For_Setup_And_Teardown
27     DevstackUtils.Devstack Suite Setup
28
29 Basic Vpnservice Suite Teardown
30     # Delete three L3VPNs created using Multiple L3VPN Test
31     Run Keyword And Ignore Error    VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
32     Run Keyword And Ignore Error    VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[1]}
33     Run Keyword And Ignore Error    VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[2]}
34     ${VM_INSTANCES} =    Create List    @{NET_1_VM_INSTANCES}    @{NET_2_VM_INSTANCES}
35     : FOR    ${VmInstance}    IN    @{VM_INSTANCES}
36     \    Run Keyword And Ignore Error    Delete Vm Instance    ${VmInstance}
37     : FOR    ${Port}    IN    @{PORT_LIST}
38     \    Run Keyword And Ignore Error    Delete Port    ${Port}
39     : FOR    ${Subnet}    IN    @{SUBNETS}
40     \    Run Keyword And Ignore Error    Delete SubNet    ${Subnet}
41     : FOR    ${Network}    IN    @{NETWORKS}
42     \    Run Keyword And Ignore Error    Delete Network    ${Network}
43     Run Keyword And Ignore Error    Delete SecurityGroup    ${SECURITY_GROUP}
44     Close All Connections
45
46 VPN Create L3VPN
47     [Arguments]    &{Kwargs}
48     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
49     Run keyword if    "routerid" in ${Kwargs}    Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
50     ...    ELSE    Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
51     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
52     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
53     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_create    mapping=${L3vpn_create_actual_val}    session=session
54
55 VPN Get L3VPN
56     [Arguments]    &{Kwargs}
57     [Documentation]    Will return detailed list of the L3VPN_ID received
58     ${resp} =    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/get_l3vpn    mapping=${Kwargs}    session=session
59     Log    ${resp}
60     [Return]    ${resp}
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=session
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=session
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=session
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=session
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=session
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=session
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]    ${cn1_conn_id}    ${cn2_conn_id}    ${os_conn_id}
196     Stop Packet Capture on Node    ${cn1_conn_id}
197     Stop Packet Capture on Node    ${cn2_conn_id}
198     Stop Packet Capture on Node    ${os_conn_id}
199     Get Test Teardown Debugs
200
201 Verify IPv4 GWMAC Flow Entry On Flow Table
202     [Arguments]    ${group_output}    ${group_id}    ${flow_output}
203     Verify ARP REQUEST in groupTable    ${group_output}    ${groupID[1]}
204     #Verify ARP_RESPONSE_TABLE - 81
205     Should Contain    ${flow_output}    table=${ARP_RESPONSE_TABLE}
206     ${arpResponder_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_RESPONSE_TABLE}
207     Should Contain    ${arpResponder_table}    priority=0 actions=drop
208     : FOR    ${macAdd}    ${ipAdd}    IN ZIP    ${GWMAC_ADDRS}    ${GWIP_ADDRS}
209     \    ${ARP_RESPONSE_IP_MAC_REGEX} =    Set Variable    arp_tpa=${ipAdd},arp_op=1 actions=.*,set_field:${macAdd}->eth_src
210     \    Should Match Regexp    ${arpResponder_table}    ${ARP_RESPONSE_IP_MAC_REGEX}
211
212 Verify IPv6 GWMAC Flow Entry On Flow Table
213     [Arguments]    ${flow_output}
214     Should Contain    ${flow_output}    table=${IPV6_TABLE}
215     ${icmp_ipv6_flows} =    Get Lines Containing String    ${flow_output}    icmp_type=135
216     : FOR    ${ip_addr}    IN    @{GWIP_ADDRS}
217     \    ${rule} =    Set Variable    icmp_type=135,icmp_code=0,nd_target=${ip_addr} actions=CONTROLLER:65535
218     \    Should Match Regexp    ${icmp_ipv6_flows}    ${rule}
219
220 Verify GWMAC Flow Entry On Flow Table
221     [Arguments]    ${cnIp}    ${ipv}=ipv4
222     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
223     ${flow_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
224     ${group_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-groups br-int
225     Should Contain    ${flow_output}    table=${DISPATCHER_TABLE}
226     ${dispatcher_table} =    Get Lines Containing String    ${flow_output}    table=${DISPATCHER_TABLE}
227     Should Contain    ${dispatcher_table}    goto_table:${GWMAC_TABLE}
228     Should Not Contain    ${dispatcher_table}    goto_table:${ARP_RESPONSE_TABLE}
229     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
230     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
231     #Verify GWMAC address present in table 19
232     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
233     \    Should Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
234     #verify Miss entry
235     Should Contain    ${gwmac_table}    actions=resubmit(,17)
236     #Verify ARP_CHECK_TABLE - 43
237     #arp request and response
238     ${arpchk_table} =    Get Lines Containing String    ${flow_output}    table=${ARP_CHECK_TABLE}
239     Should Match Regexp    ${arpchk_table}    ${ARP_RESPONSE_REGEX}
240     ${match} =    Should Match Regexp    ${arpchk_table}    ${ARP_REQUEST_REGEX}
241     ${groupID} =    Split String    ${match}    separator=:
242     BuiltIn.Run Keyword If    '${ipv}' == 'ipv4'    Verify IPv4 GWMAC Flow Entry On Flow Table    ${group_output}    ${group_id}    ${flow_output}
243     ...    ELSE    Verify IPv6 GWMAC Flow Entry On Flow Table    ${flow_output}
244
245 Delete Multiple L3VPNs
246     [Arguments]    @{vpns}
247     [Documentation]    Delete three L3VPNs created using Multiple L3VPN Test
248     : FOR    ${vpn}    IN    ${vpns}
249     \    VPN Delete L3VPN    vpnid=${vpn}