15b533e79f47855ea88878022c156266ec8e5fc6
[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     # Delete Vm instances from the given Instance List
35     ${VM_INSTANCES} =    Create List    @{VM_INSTANCES_NET10}    @{VM_INSTANCES_NET20}
36     : FOR    ${VmInstance}    IN    @{VM_INSTANCES}
37     \    Run Keyword And Ignore Error    Delete Vm Instance    ${VmInstance}
38     # Delete Neutron Ports from the given Port List.
39     : FOR    ${Port}    IN    @{PORT_LIST}
40     \    Run Keyword And Ignore Error    Delete Port    ${Port}
41     # Delete Sub Nets from the given Subnet List.
42     : FOR    ${Subnet}    IN    @{SUBNETS}
43     \    Run Keyword And Ignore Error    Delete SubNet    ${Subnet}
44     # Delete Networks in the given Net List
45     : FOR    ${Network}    IN    @{NETWORKS}
46     \    Run Keyword And Ignore Error    Delete Network    ${Network}
47     # Remove security group created earlier
48     Run Keyword And Ignore Error    Delete SecurityGroup    ${SECURITY_GROUP}
49     Close All Connections
50
51 VPN Create L3VPN
52     [Arguments]    &{Kwargs}
53     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
54     Run keyword if    "routerid" in ${Kwargs}    Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
55     ...    ELSE    Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
56     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
57     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
58     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_create    mapping=${L3vpn_create_actual_val}    session=session
59
60 VPN Get L3VPN
61     [Arguments]    &{Kwargs}
62     [Documentation]    Will return detailed list of the L3VPN_ID received
63     ${resp} =    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/get_l3vpn    mapping=${Kwargs}    session=session
64     Log    ${resp}
65     [Return]    ${resp}
66
67 Associate L3VPN To Network
68     [Arguments]    &{Kwargs}
69     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
70     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_l3vpn    mapping=${Kwargs}    session=session
71
72 Dissociate L3VPN From Networks
73     [Arguments]    &{Kwargs}
74     [Documentation]    Disssociate the already associated networks from L3VPN
75     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_l3vpn    mapping=${Kwargs}    session=session
76
77 Associate VPN to Router
78     [Arguments]    &{Kwargs}
79     [Documentation]    Associate the created L3VPN to a router-id received as argument
80     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_router_l3vpn    mapping=${Kwargs}    session=session
81
82 Dissociate VPN to Router
83     [Arguments]    &{Kwargs}
84     [Documentation]    Dissociate the already associated routers from L3VPN
85     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_router_l3vpn    mapping=${Kwargs}    session=session
86
87 VPN Delete L3VPN
88     [Arguments]    &{Kwargs}
89     [Documentation]    Delete the created L3VPN
90     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_delete    mapping=${Kwargs}    session=session
91
92 ITM Create Tunnel
93     [Arguments]    &{Kwargs}
94     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
95     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
96     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
97     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/itm_create    mapping=${Itm_actual_val}    session=session
98
99 ITM Get Tunnels
100     [Documentation]    Get all Tunnels and return the contents
101     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
102     Log    ${resp.content}
103     Should Be Equal As Strings    ${resp.status_code}    200
104     [Return]    ${resp.content}
105
106 ITM Delete Tunnel
107     [Arguments]    ${zone-name}
108     [Documentation]    Delete Tunnels created under the transport-zone
109     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
110     Log    ${resp.content}
111     Should Be Equal As Strings    ${resp.status_code}    200
112     [Return]    ${resp.content}
113
114 Verify Flows Are Present For L3VPN
115     [Arguments]    ${ip}    ${vm_ips}
116     [Documentation]    Verify Flows Are Present For L3VPN
117     ${flow_output}=    Run Command On Remote System    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
118     Log    ${flow_output}
119     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
120     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN},
121     Log    ${l3vpn_table}
122     : FOR    ${i}    IN    @{vm_ips}
123     \    ${resp}=    Should Contain    ${l3vpn_table}    ${i}
124
125 Verify GWMAC Entry On ODL
126     [Arguments]    ${GWMAC_ADDRS}
127     [Documentation]    get ODL GWMAC table entry
128     ${resp} =    RequestsLibrary.Get Request    session    ${VPN_PORT_DATA_URL}
129     Log    ${resp.content}
130     Should Be Equal As Strings    ${resp.status_code}    200
131     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
132     \    Should Contain    ${resp.content}    ${macAdd}
133
134 Verify GWMAC Flow Entry Removed From Flow Table
135     [Arguments]    ${cnIp}
136     [Documentation]    Verify the GWMAC Table, ARP Response table and Dispatcher table.
137     ${flow_output}=    Run Command On Remote System    ${cnIp}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
138     Log    ${flow_output}
139     Should Contain    ${flow_output}    table=${GWMAC_TABLE}
140     ${gwmac_table} =    Get Lines Containing String    ${flow_output}    table=${GWMAC_TABLE}
141     Log    ${gwmac_table}
142     #Verify GWMAC address present in table 19
143     : FOR    ${macAdd}    IN    @{GWMAC_ADDRS}
144     \    Should Not Contain    ${gwmac_table}    dl_dst=${macAdd} actions=goto_table:${L3_TABLE}
145
146 Verify ARP REQUEST in groupTable
147     [Arguments]    ${group_output}    ${Group-ID}
148     [Documentation]    get flow dump for group ID
149     Should Contain    ${group_output}    group_id=${Group-ID}
150     ${arp_group} =    Get Lines Containing String    ${group_output}    group_id=${Group-ID}
151     Log    ${arp_group}
152     Should Match Regexp    ${arp_group}    ${ARP_REQUEST_GROUP_REGEX}
153
154 Verify Tunnel Status as UP
155     [Documentation]    Verify that the tunnels are UP
156     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
157     Log    ${output}
158     Should Contain    ${output}    ${STATE_UP}
159     Should Not Contain    ${output}    ${STATE_DOWN}
160     Should Not Contain    ${output}    ${STATE_UNKNOWN}
161
162 Verify Tunnel Status as DOWN
163     [Documentation]    Verify that the tunnels are DOWN
164     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
165     Log    ${output}
166     Should Contain    ${output}    ${STATE_DOWN}
167     Should Not Contain    ${output}    ${STATE_UP}
168     Should Not Contain    ${output}    ${STATE_UNKNOWN}
169
170 Verify Tunnel Status as UNKNOWN
171     [Documentation]    Verify that the tunnels are in Unknown state
172     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
173     Log    ${output}
174     Should Not Contain    ${output}    ${STATE_UP}
175     Should Not Contain    ${output}    ${STATE_DOWN}
176     Should Contain    ${output}    ${STATE_UNKNOWN}
177
178 Verify VXLAN interface
179     [Documentation]    Verify that the VXLAN interfaces are Enabled
180     ${output}=    Issue Command On Karaf Console    ${VXLAN_SHOW}
181     Log    ${output}
182     Should Contain    ${output}    ${STATE_UP}
183     Should Contain    ${output}    ${STATE_ENABLE}
184     Should Not Contain    ${output}    ${STATE_DISABLE}
185
186 Get Fib Entries
187     [Arguments]    ${session}
188     [Documentation]    Get Fib table entries from ODL session
189     ${resp}    RequestsLibrary.Get Request    ${session}    ${FIB_ENTRIES_URL}
190     Log    ${resp.content}
191     [Return]    ${resp.content}