Support only Fluorine+ distributions
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 010_bgp_functional_l3vpn.robot
1 *** Settings ***
2 Documentation       Functional test suite for bgp - l3vpn-ipv4
3 ...
4 ...                 Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...                 This program and the accompanying materials are made available under the
7 ...                 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...                 This suite tests advertising and receiveing routes with l3vpn content.
11 ...                 It uses odl and exabgp as bgp peers. Routes advertized from odl
12 ...                 are configured via application peer. Routes advertised from exabgp is
13 ...                 statically configured in exabgp config file.
14 ...
15 ...                 For fluorine and further, instead of exabgp, play.py is used. When sending
16 ...                 routes from odl to peer, first route containg route-target argument have to
17 ...                 be send from peer to odl, so odl can identify this peer. Than it sends l3vpn
18 ...                 route containg this argument to odl app peer, and we check that app peer
19 ...                 advertizes this route back to the peer.
20
21 Library             RequestsLibrary
22 Library             SSHLibrary
23 Library             ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
24 Resource            ../../../libraries/BGPcliKeywords.robot
25 Resource            ../../../libraries/BgpOperations.robot
26 Resource            ../../../libraries/BGPSpeaker.robot
27 Resource            ../../../libraries/CompareStream.robot
28 Resource            ../../../libraries/ExaBgpLib.robot
29 Resource            ../../../libraries/SetupUtils.robot
30 Resource            ../../../libraries/SSHKeywords.robot
31 Resource            ../../../libraries/TemplatedRequests.robot
32 Resource            ../../../variables/Variables.robot
33
34 Suite Setup         Start_Suite
35 Suite Teardown      Stop_Suite
36 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
37
38
39 *** Variables ***
40 ${BGP_L3VPN_DIR}                ${BGP_VAR_FOLDER}/l3vpn_ipv4
41 ${BGP_VAR_FOLDER}               ${CURDIR}/../../../variables/bgpfunctional
42 ${CONFIG_SESSION}               config-session
43 ${DEFAULT_BGPCEP_LOG_LEVEL}     INFO
44 ${DEFAULT_EXA_CFG}              exa.cfg
45 ${EXARPCSCRIPT}                 ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
46 ${HOLDTIME}                     180
47 ${L3VPN_EXA_CFG}                bgp-l3vpn-ipv4.cfg
48 ${L3VPN_EXP}                    exa_expected
49 ${L3VPN_RSP}                    bgp_l3vpn_ipv4
50 ${L3VPN_RSPEMPTY}               bgp_l3vpn_ipv4_empty
51 ${OLD_AS_PATH}                  \n"as-path": {},
52 ${NEW_AS_PATH}                  ${EMPTY}
53 ${PLAY_SCRIPT}                  ${CURDIR}/../../../../tools/fastbgp/play.py
54 ${RIB_INSTANCE}                 example-bgp-rib
55 ${RT_CONSTRAIN_DIR}             ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
56
57
58 *** Test Cases ***
59 Configure_App_Peer
60     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
61     &{mapping}    BuiltIn.Create_Dictionary    BGP_RIB=${RIB_INSTANCE}    IP=${ODL_SYSTEM_IP}
62     TemplatedRequests.Put_As_Xml_Templated
63     ...    ${RT_CONSTRAIN_DIR}/app_peer
64     ...    mapping=${mapping}
65     ...    session=${CONFIG_SESSION}
66
67 Reconfigure_ODL_To_Accept_Connection
68     [Documentation]    Configures BGP peer module with initiate-connection set to false.
69     &{mapping}    BuiltIn.Create_Dictionary
70     ...    IP=${TOOLS_SYSTEM_IP}
71     ...    BGP_RIB=${RIB_INSTANCE}
72     ...    HOLDTIME=${HOLDTIME}
73     ...    PEER_PORT=${BGP_TOOL_PORT}
74     ...    INITIATE=false
75     ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
76     ...    PASSIVE_MODE=true
77     TemplatedRequests.Put_As_Xml_Templated
78     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
79     ...    mapping=${mapping}
80     ...    session=${CONFIG_SESSION}
81
82 L3vpn_Ipv4_To_Odl
83     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
84     [Setup]    Setup_Testcase    ${L3VPN_EXA_CFG}
85     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Reported_Data    ${L3VPN_RSP}
86     [Teardown]    Teardown_Simple
87
88 Start_Play
89     [Documentation]    Start Python speaker to connect to ODL. We need to do WUKS until odl really starts to accept incomming bgp connection. The failure happens if the incomming connection comes too quickly after configuring the peer in the previous test case.
90     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
91     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
92     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
93     SSHLibrary.Read
94     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start_Bgp_Peer
95
96 Play_To_Odl_rt_constrain_type_0
97     [Documentation]    This keyword sends route-target route containg route-target argument so odl
98     ...    can identify this peer as appropriate for advertizement when it recieves such route.
99     BgpOperations.Play_To_Odl_Non_Removal_Template    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
100
101 Odl_To_Play_l3vpn_rt_arg
102     [Documentation]    Same as TC before but fluorine and further this l3vpn route also needs to contain route-target argument.
103     BgpOperations.Odl_To_Play_Template    l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}    False
104
105 Kill_Talking_BGP_Speaker
106     [Documentation]    Abort the Python speaker
107     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
108     BGPSpeaker.Kill_BGP_Speaker
109     BGPcliKeywords.Store_File_To_Workspace    play.py.out    010_l3vpn_play.log
110
111 Delete_Bgp_Peer_Configuration
112     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
113     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
114     TemplatedRequests.Delete_Templated
115     ...    ${RT_CONSTRAIN_DIR}/bgp_peer
116     ...    mapping=${mapping}
117     ...    session=${CONFIG_SESSION}
118
119 Deconfigure_App_Peer
120     [Documentation]    Revert the BGP configuration to the original state: without application peer
121     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_INSTANCE}
122     TemplatedRequests.Delete_Templated
123     ...    ${RT_CONSTRAIN_DIR}/app_peer
124     ...    mapping=${mapping}
125     ...    session=${CONFIG_SESSION}
126
127
128 *** Keywords ***
129 Start_Suite
130     [Documentation]    Suite setup keyword.
131     SetupUtils.Setup_Utils_For_Setup_And_Teardown
132     ${tools_system_conn_id}    SSHLibrary.Open_Connection
133     ...    ${TOOLS_SYSTEM_IP}
134     ...    prompt=${DEFAULT_LINUX_PROMPT}
135     ...    timeout=6s
136     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
137     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
138     SSHKeywords.Virtual_Env_Create
139     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
140     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
141     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
142     Upload_Config_Files
143     ${AS_PATH}    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
144     BuiltIn.Set_Suite_Variable    ${AS_PATH}
145
146 Stop_Suite
147     [Documentation]    Suite teardown keyword
148     SSHKeywords.Virtual_Env_Delete
149     SSHLibrary.Close_All_Connections
150     RequestsLibrary.Delete_All_Sessions
151
152 Upload_Config_Files
153     [Documentation]    Uploads exabgp config files and needed scripts
154     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAULT_EXA_CFG}    .
155     SSHLibrary.Put_File    ${BGP_L3VPN_DIR}/${L3VPN_EXA_CFG}    .
156     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
157     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
158     FOR    ${cfgfile}    IN    @{cfgfiles}
159         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
160         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
161         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
162         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
163         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
164         Log    ${stdout}
165     END
166
167 Setup_Testcase
168     [Documentation]    Verifies initial test condition and starts the exabgp
169     [Arguments]    ${cfg_file}
170     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
171     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
172     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
173     ...    ${cfg_file}
174     ...    ${CONFIG_SESSION}
175     ...    ${TOOLS_SYSTEM_IP}
176     ...    connection_retries=${3}
177
178 Teardown_Simple
179     [Documentation]    Testcse teardown with data verification
180     ExaBgpLib.Stop_ExaBgp
181     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
182
183 Verify_ExaBgp_Received_Update
184     [Documentation]    Verification of receiving particular update message
185     [Arguments]    ${exp_update_fn}
186     ${exp_update}    TemplatedRequests.Resolve_Text_From_Template_File
187     ...    ${BGP_L3VPN_DIR}${/}${exp_update_fn}
188     ...    data.json
189     ${rcv_update_dict}    BgpRpcClient.exa_get_update_message    msg_only=${True}
190     ${rcv_update}    BuiltIn.Evaluate    json.dumps(${rcv_update_dict})    modules=json
191     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_update}    ${rcv_update}
192
193 Verify_Empty_Reported_Data
194     [Documentation]    Verfiy empty data response
195     CompareStream.Run_Keyword_If_At_Most_Fluorine
196     ...    TemplatedRequests.Get_As_Json_Templated
197     ...    ${BGP_L3VPN_DIR}${/}${L3VPN_RSPEMPTY}
198     ...    session=${CONFIG_SESSION}
199     ...    verify=True
200     CompareStream.Run_Keyword_If_At_Least_Neon    Verify_Empty_Data_Neon
201
202 Verify_Reported_Data
203     [Documentation]    Verifies expected response
204     [Arguments]    ${exprspdir}
205     &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
206     TemplatedRequests.Get_As_Json_Templated
207     ...    ${BGP_L3VPN_DIR}${/}${exprspdir}
208     ...    mapping=${mapping}
209     ...    session=${CONFIG_SESSION}
210     ...    verify=True
211
212 Start_Bgp_Peer
213     [Documentation]    Starts bgp peer and verifies that the peer runs.
214     BGPSpeaker.Start_BGP_Speaker
215     ...    --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --debug --allf --wfr 1
216     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
217
218 L3vpn_Ipv4_To_App
219     [Documentation]    Testing mpls vpn ipv4 routes reported to odl from exabgp
220     BgpRpcClient.exa_clean_update_message
221     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}    APP_PEER_IP=${ODL_SYSTEM_IP}
222     TemplatedRequests.Post_As_Xml_Templated
223     ...    ${BGP_L3VPN_DIR}/route
224     ...    mapping=${mapping}
225     ...    session=${CONFIG_SESSION}
226     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Update    ${L3VPN_EXP}
227
228 Verify_Empty_Data_Neon
229     [Documentation]    Verify empty data on neon
230     TemplatedRequests.Get_As_Json_Templated
231     ...    ${BGP_L3VPN_DIR}${/}empty_route
232     ...    session=${CONFIG_SESSION}
233     ...    verify=True