Correctly space expected_status
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 020_bgp_functional_multipath.robot
1 *** Settings ***
2 Documentation       Functional test suite for bgp - n-path and all-path selection
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 n-path and all-path selection policy.
11 ...                 It uses odl and exabgp as bgp peers. Routes advertized from odl
12 ...                 are configured via application peer.
13
14 Library             RequestsLibrary
15 Library             SSHLibrary
16 Resource            ${CURDIR}/../../../variables/Variables.robot
17 Resource            ${CURDIR}/../../../libraries/ExaBgpLib.robot
18 Resource            ${CURDIR}/../../../libraries/Utils.robot
19 Resource            ${CURDIR}/../../../libraries/SetupUtils.robot
20 Resource            ${CURDIR}/../../../libraries/TemplatedRequests.robot
21 Library             ${CURDIR}/../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
22 Resource            ${CURDIR}/../../../libraries/BGPcliKeywords.robot
23 Resource            ${CURDIR}/../../../libraries/SSHKeywords.robot
24 Resource            ${CURDIR}/../../../libraries/CompareStream.robot
25
26 Suite Setup         Start_Suite
27 Suite Teardown      Stop_Suite
28 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
29
30
31 *** Variables ***
32 ${HOLDTIME}                 180
33 ${DEVICE_NAME}              controller-config
34 ${BGP_PEER_NAME}            example-bgp-peer
35 ${RIB_INSTANCE}             example-bgp-rib
36 ${PROTOCOL_OPENCONFIG}      ${RIB_INSTANCE}
37 ${APP_PEER_NAME}            example-bgp-peer-app
38 ${BGP_VAR_FOLDER}           ${CURDIR}/../../../variables/bgpfunctional
39 ${MULT_VAR_FOLDER}          ${BGP_VAR_FOLDER}/multipaths
40 ${DEFAUTL_RPC_CFG}          exa.cfg
41 ${CONFIG_SESSION}           config-session
42 ${EXARPCSCRIPT}             ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
43 ${N_PATHS_VALUE}            2
44 &{DEFAULT_MAPPING}          ODLIP=${ODL_SYSTEM_IP}    EXAIP=${TOOLS_SYSTEM_IP}    NPATHS=${N_PATHS_VALUE}
45 @{PATH_ID_LIST}             1    2    3
46 ${NEXT_HOP_PREF}            100.100.100.
47 ${OPENCONFIG_RIB_URI}
48 ...                         /rests/data/openconfig-network-instance:network-instances/network-instance=global-bgp/openconfig-network-instance:protocols/protocol=openconfig-policy-types%3ABGP,example-bgp-rib
49 ${NPATHS_SELM}              n-paths
50 ${ALLPATHS_SELM}            all-paths
51 ${ADDPATHCAP_SR}            send\\/receive
52 ${ADDPATHCAP_S}             send
53 ${ADDPATHCAP_R}             receive
54 ${ADDPATHCAP_D}             disable
55
56
57 *** Test Cases ***
58 Reconfigure_ODL_To_Accept_Connection
59     [Documentation]    Configures BGP peer module with initiate-connection set to false.
60     &{mapping}    BuiltIn.Create_Dictionary
61     ...    DEVICE_NAME=${DEVICE_NAME}
62     ...    BGP_NAME=${BGP_PEER_NAME}
63     ...    IP=${TOOLS_SYSTEM_IP}
64     ...    HOLDTIME=${HOLDTIME}
65     ...    PEER_PORT=${BGP_TOOL_PORT}
66     ...    INITIATE=false
67     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
68     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
69     ...    PASSIVE_MODE=true
70
71 Odl Allpaths Exa SendReceived
72     [Documentation]    all-paths selected policy selected
73     [Tags]    critical
74     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${ALLPATHS_SELM}    ${ADDPATHCAP_SR}
75     Log_Loc_Rib_Operational
76     Comment    From neon onwards there is extra BGP End-Of-RIB message
77     ${update_messages}    BuiltIn.Set_Variable    4
78     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${update_messages}
79     [Teardown]    Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
80
81 Odl Npaths Exa SendReceived
82     [Documentation]    n-paths policy selected on odl
83     [Tags]    critical
84     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${NPATHS_SELM}    ${ADDPATHCAP_SR}
85     Log_Loc_Rib_Operational
86     Comment    From neon onwards there is extra BGP End-Of-RIB message
87     ${update_messages}    BuiltIn.Set_Variable    3
88     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${update_messages}
89     [Teardown]    Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
90
91 Delete_Bgp_Peer_Configuration
92     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
93     &{mapping}    BuiltIn.Create_Dictionary
94     ...    DEVICE_NAME=${DEVICE_NAME}
95     ...    BGP_NAME=${BGP_PEER_NAME}
96     ...    IP=${TOOLS_SYSTEM_IP}
97     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
98
99
100 *** Keywords ***
101 Start_Suite
102     [Documentation]    Suite setup keyword.
103     SetupUtils.Setup_Utils_For_Setup_And_Teardown
104     ${tools_system_conn_id}    SSHLibrary.Open_Connection
105     ...    ${TOOLS_SYSTEM_IP}
106     ...    prompt=${DEFAULT_LINUX_PROMPT}
107     ...    timeout=6s
108     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
109     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
110     SSHKeywords.Virtual_Env_Create
111     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
112     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
113     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
114     Upload_Config_Files
115     Store_Rib_Configuration
116
117 Stop_Suite
118     [Documentation]    Suite teardown keyword with old rib restoration
119     SSHKeywords.Virtual_Env_Delete
120     TemplatedRequests.Put_As_Xml_To_Uri    ${OPENCONFIG_RIB_URI}    ${rib_old}    session=${CONFIG_SESSION}
121     SSHLibrary.Close_All_Connections
122     RequestsLibrary.Delete_All_Sessions
123
124 Upload_Config_Files
125     [Documentation]    Uploads exabgp config files
126     [Arguments]    ${addpath}=disable
127     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAUTL_RPC_CFG}    .
128     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
129     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
130     FOR    ${cfgfile}    IN    @{cfgfiles}
131         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
132         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
133         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
134         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/${addpath}/g' ${cfgfile}
135         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
136         Log    ${stdout}
137     END
138
139 Configure_Path_Selection_And_App_Peer_And_Connect_Peer
140     [Documentation]    Setup test case keyword. Early after the path selection config the incomming connection
141     ...    from exabgp towards odl may be rejected by odl due to config process not finished yet. Because of that
142     ...    we try to start the tool 3 times in case early attempts fail.
143     [Arguments]    ${odl_path_sel_mode}    ${exa_add_path_value}
144     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
145     Configure_Odl_Peer_With_Path_Selection_Mode    ${odl_path_sel_mode}
146     Configure_App_Peer_With_Routes
147     Upload_Config_Files    addpath=${exa_add_path_value}
148     ExaBgpLib.Start_ExaBgp_And_Verify_Connected
149     ...    ${DEFAUTL_RPC_CFG}
150     ...    ${CONFIG_SESSION}
151     ...    ${TOOLS_SYSTEM_IP}
152     ...    connection_retries=${3}
153
154 Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
155     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
156     TemplatedRequests.Delete_Templated
157     ...    ${MULT_VAR_FOLDER}/bgp_peer
158     ...    mapping=${mapping}
159     ...    session=${CONFIG_SESSION}
160     Deconfigure_App_Peer
161     ExaBgpLib.Stop_ExaBgp
162     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
163
164 Verify_Expected_Update_Count
165     [Documentation]    Verify number of received update messages
166     [Arguments]    ${exp_count}
167     ${tool_count}    BgpRpcClient.exa_get_received_update_count
168     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_count}    ${tool_count}
169
170 Configure_Odl_Peer_With_Path_Selection_Mode
171     [Documentation]    Configures odl peer with path selection mode
172     [Arguments]    ${psm}
173     ${npaths}    BuiltIn.Set_Variable_If    "${psm}"=="${ALLPATHS_SELM}"    0    ${N_PATHS_VALUE}
174     &{mapping}    BuiltIn.Create_Dictionary
175     ...    IP=${TOOLS_SYSTEM_IP}
176     ...    HOLDTIME=${HOLDTIME}
177     ...    PEER_PORT=${BGP_TOOL_PORT}
178     ...    PASSIVE_MODE=true
179     ...    MULTIPATH=${npaths}
180     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
181     TemplatedRequests.Put_As_Xml_Templated
182     ...    ${MULT_VAR_FOLDER}/rib_policies
183     ...    mapping=${mapping}
184     ...    session=${CONFIG_SESSION}
185     TemplatedRequests.Put_As_Xml_Templated
186     ...    ${MULT_VAR_FOLDER}/bgp_peer
187     ...    mapping=${mapping}
188     ...    session=${CONFIG_SESSION}
189
190 Store_Rib_Configuration
191     [Documentation]    Stores rib configuration
192     ${rib_old}    TemplatedRequests.Get_As_Xml_Templated
193     ...    ${MULT_VAR_FOLDER}/rib_config
194     ...    mapping=${DEFAULT_MAPPING}
195     ...    session=${CONFIG_SESSION}
196     BuiltIn.Set_Suite_Variable    ${rib_old}
197
198 Log_Loc_Rib_Operational
199     ${rsp}    RequestsLibrary.Get Request
200     ...    ${CONFIG_SESSION}
201     ...    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/
202     BuiltIn.Log    ${rsp.content}
203
204 Configure_App_Peer_With_Routes
205     [Documentation]    Configure bgp application peer and fill it immediately with routes.
206     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
207     &{mapping}    BuiltIn.Create_Dictionary
208     ...    DEVICE_NAME=${DEVICE_NAME}
209     ...    APP_PEER_NAME=${APP_PEER_NAME}
210     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
211     ...    APP_PEER_ID=${ODL_SYSTEM_IP}
212     ...    IP=${ODL_SYSTEM_IP}
213     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
214     TemplatedRequests.Put_As_Xml_Templated
215     ...    ${BGP_VAR_FOLDER}/app_peer
216     ...    mapping=${mapping}
217     ...    session=${CONFIG_SESSION}
218     FOR    ${pathid}    IN    @{PATH_ID_LIST}
219         &{route_mapping}    BuiltIn.Create_Dictionary
220         ...    NEXTHOP=${NEXT_HOP_PREF}${pathid}
221         ...    LOCALPREF=${pathid}00
222         ...    PATHID=${pathid}
223         ...    APP_RIB=${app_rib}
224         TemplatedRequests.Post_As_Xml_Templated
225         ...    ${MULT_VAR_FOLDER}/route
226         ...    mapping=${route_mapping}
227         ...    session=${CONFIG_SESSION}
228     END
229
230 Deconfigure_App_Peer
231     [Documentation]    Revert the BGP configuration to the original state: without application peer
232     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
233     &{route_mapping}    BuiltIn.Create_Dictionary    APP_RIB=${app_rib}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
234     TemplatedRequests.Delete_Templated
235     ...    ${MULT_VAR_FOLDER}/route
236     ...    mapping=${route_mapping}
237     ...    session=${CONFIG_SESSION}
238     &{mapping}    BuiltIn.Create_Dictionary
239     ...    DEVICE_NAME=${DEVICE_NAME}
240     ...    APP_PEER_NAME=${APP_PEER_NAME}
241     ...    IP=${ODL_SYSTEM_IP}
242     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
243     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}