BGP validation with Vpnservice
[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 VPN Create L3VPN
26     [Arguments]    &{Kwargs}
27     [Documentation]    Create an L3VPN using the Json using the list of optional arguments received.
28     Run keyword if    "routerid" in ${Kwargs}    Collections.Set_To_Dictionary    ${Kwargs}    router=, "router-id":"${Kwargs['routerid']}"
29     ...    ELSE    Collections.Set_To_Dictionary    ${Kwargs}    router=${empty}
30     &{L3vpn_create_actual_val} =    Collections.Copy_Dictionary    ${L3VPN_CREATE_DEFAULT}
31     Collections.Set_To_Dictionary    ${L3vpn_create_actual_val}    &{Kwargs}
32     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_create    mapping=${L3vpn_create_actual_val}    session=session
33
34 VPN Get L3VPN
35     [Arguments]    &{Kwargs}
36     [Documentation]    Will return detailed list of the L3VPN_ID received
37     ${resp} =    TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/get_l3vpn    mapping=${Kwargs}    session=session
38     Log    ${resp}
39     [Return]    ${resp}
40
41 Associate L3VPN To Network
42     [Arguments]    &{Kwargs}
43     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
44     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_l3vpn    mapping=${Kwargs}    session=session
45
46 Dissociate L3VPN From Networks
47     [Arguments]    &{Kwargs}
48     [Documentation]    Disssociate the already associated networks from L3VPN
49     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_l3vpn    mapping=${Kwargs}    session=session
50
51 Associate VPN to Router
52     [Arguments]    &{Kwargs}
53     [Documentation]    Associate the created L3VPN to a router-id received as argument
54     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/assoc_router_l3vpn    mapping=${Kwargs}    session=session
55
56 Dissociate VPN to Router
57     [Arguments]    &{Kwargs}
58     [Documentation]    Dissociate the already associated routers from L3VPN
59     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/dissoc_router_l3vpn    mapping=${Kwargs}    session=session
60
61 VPN Delete L3VPN
62     [Arguments]    &{Kwargs}
63     [Documentation]    Delete the created L3VPN
64     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/l3vpn_delete    mapping=${Kwargs}    session=session
65
66 ITM Create Tunnel
67     [Arguments]    &{Kwargs}
68     [Documentation]    Creates Tunnel between the two DPNs received in the dictionary argument
69     &{Itm_actual_val} =    Collections.Copy_Dictionary    ${ITM_CREATE_DEFAULT}
70     Collections.Set_To_Dictionary    ${Itm_actual_val}    &{Kwargs}
71     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE}/itm_create    mapping=${Itm_actual_val}    session=session
72
73 ITM Get Tunnels
74     [Documentation]    Get all Tunnels and return the contents
75     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:transport-zones/
76     Log    ${resp.content}
77     Should Be Equal As Strings    ${resp.status_code}    200
78     [Return]    ${resp.content}
79
80 ITM Delete Tunnel
81     [Arguments]    ${zone-name}
82     [Documentation]    Delete Tunnels created under the transport-zone
83     ${resp} =    RequestsLibrary.Delete Request    session    ${CONFIG_API}/itm:transport-zones/transport-zone/${zone-name}/
84     Log    ${resp.content}
85     Should Be Equal As Strings    ${resp.status_code}    200
86     [Return]    ${resp.content}
87
88 Verify Flows Are Present For L3VPN
89     [Arguments]    ${ip}    ${vm_ips}
90     [Documentation]    Verify Flows Are Present For L3VPN
91     ${flow_output}=    Run Command On Remote System    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
92     Log    ${flow_output}
93     Should Contain    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN}
94     ${l3vpn_table} =    Get Lines Containing String    ${flow_output}    table=${ODL_FLOWTABLE_L3VPN},
95     Log    ${l3vpn_table}
96     : FOR    ${i}    IN    @{vm_ips}
97     \    ${resp}=    Should Contain    ${l3vpn_table}    ${i}
98
99 Verify Tunnel Status as UP
100     [Documentation]    Verify that the tunnels are UP
101     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
102     Log    ${output}
103     Should Contain    ${output}    ${STATE_UP}
104     Should Not Contain    ${output}    ${STATE_DOWN}
105     Should Not Contain    ${output}    ${STATE_UNKNOWN}
106
107 Verify Tunnel Status as DOWN
108     [Documentation]    Verify that the tunnels are DOWN
109     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
110     Log    ${output}
111     Should Contain    ${output}    ${STATE_DOWN}
112     Should Not Contain    ${output}    ${STATE_UP}
113     Should Not Contain    ${output}    ${STATE_UNKNOWN}
114
115 Verify Tunnel Status as UNKNOWN
116     [Documentation]    Verify that the tunnels are in Unknown state
117     ${output}=    Issue Command On Karaf Console    ${TEP_SHOW_STATE}
118     Log    ${output}
119     Should Not Contain    ${output}    ${STATE_UP}
120     Should Not Contain    ${output}    ${STATE_DOWN}
121     Should Contain    ${output}    ${STATE_UNKNOWN}
122
123 Verify VXLAN interface
124     [Documentation]    Verify that the VXLAN interfaces are Enabled
125     ${output}=    Issue Command On Karaf Console    ${VXLAN_SHOW}
126     Log    ${output}
127     Should Contain    ${output}    ${STATE_UP}
128     Should Contain    ${output}    ${STATE_ENABLE}
129     Should Not Contain    ${output}    ${STATE_DISABLE}