d67f5fc43dbf5866958697e36afb2bc214f64a6a
[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 Suite Setup       Start_Suite
14 Suite Teardown    Stop_Suite
15 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
16 Library           RequestsLibrary
17 Library           SSHLibrary
18 Variables         ${CURDIR}/../../../variables/Variables.py
19 Resource          ${CURDIR}/../../../libraries/ExaBgpLib.robot
20 Resource          ${CURDIR}/../../../libraries/Utils.robot
21 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
22 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
23 Library           ${CURDIR}/../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
24 Resource          ${CURDIR}/../../../libraries/BGPcliKeywords.robot
25 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
26
27 *** Variables ***
28 ${HOLDTIME}       180
29 ${DEVICE_NAME}    controller-config
30 ${BGP_PEER_NAME}    example-bgp-peer
31 ${RIB_INSTANCE}    example-bgp-rib
32 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
33 ${APP_PEER_NAME}    example-bgp-peer-app
34 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
35 ${MULT_VAR_FOLDER}    ${BGP_VAR_FOLDER}/multipaths
36 ${DEFAUTL_RPC_CFG}    exa.cfg
37 ${CONFIG_SESSION}    config-session
38 ${EXARPCSCRIPT}    ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
39 ${N_PATHS_VALUE}    2
40 &{DEFAULT_MAPPING}    ODLIP=${ODL_SYSTEM_IP}    EXAIP=${TOOLS_SYSTEM_IP}    NPATHS=${N_PATHS_VALUE}
41 @{PATH_ID_LIST}    1    2    3
42 ${PATH_ID_LIST_LEN}    3
43 ${NEXT_HOP_PREF}    100.100.100.
44 ${RIB_URI}        /restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/odl-bgp-rib-impl-cfg:rib-impl/example-bgp-rib
45 ${OPENCONFIG_RIB_URI}    /restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/example-bgp-rib
46 ${NPATHS_SELM}    n-paths
47 ${ALLPATHS_SELM}    all-paths
48 ${ADDPATHCAP_SR}    send\\/receive
49 ${ADDPATHCAP_S}    send
50 ${ADDPATHCAP_R}    receive
51 ${ADDPATHCAP_D}    disable
52
53 *** Test Cases ***
54 Reconfigure_ODL_To_Accept_Connection
55     [Documentation]    Configures BGP peer module with initiate-connection set to false.
56     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
57     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
58
59 Odl Allpaths Exa SendReceived
60     [Documentation]    all-paths selected policy selected
61     [Tags]    critical
62     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${ALLPATHS_SELM}    ${ADDPATHCAP_SR}
63     Log_Loc_Rib_Operational
64     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${PATH_ID_LIST_LEN}
65     [Teardown]    Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
66
67 Odl Npaths Exa SendReceived
68     [Documentation]    n-paths policy selected on odl
69     [Tags]    critical
70     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${NPATHS_SELM}    ${ADDPATHCAP_SR}
71     Log_Loc_Rib_Operational
72     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${N_PATHS_VALUE}
73     [Teardown]    Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
74
75 Delete_Bgp_Peer_Configuration
76     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
77     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
78
79 *** Keywords ***
80 Start_Suite
81     [Documentation]    Suite setup keyword.
82     SetupUtils.Setup_Utils_For_Setup_And_Teardown
83     ${tools_system_conn_id}=    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
84     Builtin.Set_Suite_Variable    ${tools_system_conn_id}
85     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
86     SSHKeywords.Virtual_Env_Create
87     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
88     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
89     Upload_Config_Files
90     Store_Rib_Configuration
91
92 Stop_Suite
93     [Documentation]    Suite teardown keyword with old rib restoration
94     SSHKeywords.Virtual_Env_Delete
95     TemplatedRequests.Put_As_Xml_To_Uri    ${OPENCONFIG_RIB_URI}    ${rib_old}    session=${CONFIG_SESSION}
96     SSHLibrary.Close_All_Connections
97     RequestsLibrary.Delete_All_Sessions
98
99 Upload_Config_Files
100     [Arguments]    ${addpath}=disable
101     [Documentation]    Uploads exabgp config files
102     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAUTL_RPC_CFG}    .
103     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
104     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
105     : FOR    ${cfgfile}    IN    @{cfgfiles}
106     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
107     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
108     \    SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/enable/g' ${cfgfile}
109     \    SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/${addpath}/g' ${cfgfile}
110     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
111     \    Log    ${stdout}
112
113 Configure_Path_Selection_And_App_Peer_And_Connect_Peer
114     [Arguments]    ${odl_path_sel_mode}    ${exa_add_path_value}
115     [Documentation]    Setup test case keyword. Early after the path selection config the incomming connection
116     ...    from exabgp towards odl may be rejected by odl due to config process not finished yet. Because of that
117     ...    we try to start the tool 3 times in case early attempts fail.
118     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
119     Configure_Odl_Peer_With_Path_Selection_Mode    ${odl_path_sel_mode}
120     Configure_App_Peer_With_Routes
121     Upload_Config_Files    addpath=${exa_add_path_value}
122     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${DEFAUTL_RPC_CFG}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}    connection_retries=${3}
123
124 Remove_Odl_And_App_Peer_Configuration_And_Stop_ExaBgp
125     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
126     TemplatedRequests.Delete_Templated    ${MULT_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
127     Deconfigure_App_Peer
128     ExaBgpLib.Stop_ExaBgp
129     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
130
131 Verify_Expected_Update_Count
132     [Arguments]    ${exp_count}
133     [Documentation]    Verify number of received update messages
134     ${tool_count}=    BgpRpcClient.exa_get_received_update_count
135     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_count}    ${tool_count}
136
137 Configure_Path_Selection_Mode
138     [Arguments]    ${psm}
139     [Documentation]    Configure path selection mode and get rib information for potential debug purposes
140     &{mapping}    BuiltIn.Create_Dictionary    PATHSELMODE=${psm}
141     TemplatedRequests.Get_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
142     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_psm    mapping=${mapping}    session=${CONFIG_SESSION}
143
144 Configure_Odl_Peer_With_Path_Selection_Mode
145     [Arguments]    ${psm}
146     [Documentation]    Configures odl peer with path selection mode
147     ${npaths}=    BuiltIn.Set_Variable_If    "${psm}"=="${ALLPATHS_SELM}"    0    ${N_PATHS_VALUE}
148     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}    PASSIVE_MODE=true    MULTIPATH=${npaths}
149     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
150     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
151     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
152
153 Configure_Odl_With_Multipaths
154     [Documentation]    Configures odl to support n-paths or all-paths selection
155     ${mapping}=    BuiltIn.Set Variable    ${DEFAULT_MAPPING}
156     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_n_paths    mapping=${mapping}    session=${CONFIG_SESSION}
157     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_all_paths    mapping=${mapping}    session=${CONFIG_SESSION}
158     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/service_psmf    mapping=${mapping}    session=${CONFIG_SESSION}
159     Configure_Path_Selection_Mode    n-paths
160     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/service_bpsm    mapping=${mapping}    session=${CONFIG_SESSION}
161     Store_Rib_Configuration
162     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
163
164 Store_Rib_Configuration
165     [Documentation]    Stores rib configuration
166     ${rib_old}=    TemplatedRequests.Get_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${DEFAULT_MAPPING}    session=${CONFIG_SESSION}
167     BuiltIn.Set_Suite_Variable    ${rib_old}
168
169 Log_Loc_Rib_Operational
170     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/
171     BuiltIn.Log    ${rsp.content}
172
173 Configure_App_Peer_With_Routes
174     [Documentation]    Configure bgp application peer and fill it immediately with routes.
175     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
176     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    RIB_INSTANCE_NAME=${RIB_INSTANCE}    APP_PEER_ID=${ODL_SYSTEM_IP}    IP=${ODL_SYSTEM_IP}
177     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
178     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
179     : FOR    ${pathid}    IN    @{PATH_ID_LIST}
180     \    &{route_mapping}    BuiltIn.Create_Dictionary    NEXTHOP=${NEXT_HOP_PREF}${pathid}    LOCALPREF=${pathid}00    PATHID=${pathid}    APP_RIB=${app_rib}
181     \    TemplatedRequests.Post_As_Xml_Templated    ${MULT_VAR_FOLDER}/route    mapping=${route_mapping}    session=${CONFIG_SESSION}
182
183 Deconfigure_App_Peer
184     [Documentation]    Revert the BGP configuration to the original state: without application peer
185     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
186     &{route_mapping}    BuiltIn.Create_Dictionary    APP_RIB=${app_rib}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
187     TemplatedRequests.Delete_Templated    ${MULT_VAR_FOLDER}/route    mapping=${route_mapping}    session=${CONFIG_SESSION}
188     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    IP=${ODL_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
189     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}