creating Normalize_Jsons_With_Bits_And_Compare to TemplatedRequests
[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 Library           RequestsLibrary
16 Library           SSHLibrary
17 Variables         ${CURDIR}/../../../variables/Variables.py
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/KarafKeywords.robot
24 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
25
26 *** Variables ***
27 ${HOLDTIME}       180
28 ${DEVICE_NAME}    controller-config
29 ${BGP_PEER_NAME}    example-bgp-peer
30 ${RIB_INSTANCE}    example-bgp-rib
31 ${APP_PEER_NAME}    example-bgp-peer-app
32 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
33 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
34 ${MULT_VAR_FOLDER}    ${BGP_VAR_FOLDER}/multipaths
35 ${DEFAUTL_RPC_CFG}    exa.cfg
36 ${CONFIG_SESSION}    config-session
37 ${EXARPCSCRIPT}    ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
38 ${N_PATHS_VALUE}    2
39 &{DEFAULT_MAPPING}    ODLIP=${ODL_SYSTEM_IP}    EXAIP=${TOOLS_SYSTEM_IP}    NPATHS=${N_PATHS_VALUE}
40 @{PATH_ID_LIST}    1    2    3
41 ${PATH_ID_LIST_LEN}    3
42 ${NEXT_HOP_PREF}    100.100.100.
43 ${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
44 ${PEER_CHECK_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/peer/bgp:%2F%2F
45 ${NPATHS_SELM}    n-paths
46 ${ALLPATHS_SELM}    all-paths
47 ${ADDPATHCAP_SR}    send\\/receive
48 ${ADDPATHCAP_S}    send
49 ${ADDPATHCAP_R}    receive
50 ${ADDPATHCAP_D}    disable
51
52 *** Test Cases ***
53 Reconfigure_ODL_To_Accept_Connection
54     [Documentation]    Configure BGP peer module with initiate-connection set to false.
55     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
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}
58     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
59
60 Odl Allpaths Exa SendReceived
61     [Documentation]    all-paths selected policy selected
62     [Tags]    critical
63     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${ALLPATHS_SELM}    ${ADDPATHCAP_SR}
64     Log_Loc_Rib_Operational
65     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${PATH_ID_LIST_LEN}
66     [Teardown]    Remove_App_Peer_Configuration_And_Stop_Tool
67
68 Odl Npaths Exa SendReceived
69     [Documentation]    n-paths policy selected on odl
70     [Tags]    critical
71     [Setup]    Configure_Path_Selection_And_App_Peer_And_Connect_Peer    ${NPATHS_SELM}    ${ADDPATHCAP_SR}
72     Log_Loc_Rib_Operational
73     BuiltIn.Wait_Until_Keyword_Succeeds    6x    2s    Verify_Expected_Update_Count    ${N_PATHS_VALUE}
74     [Teardown]    Remove_App_Peer_Configuration_And_Stop_Tool
75
76 Delete_Bgp_Peer_Configuration
77     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
78     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
79     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}
80     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
81
82 *** Keywords ***
83 Start_Suite
84     [Documentation]    Suite setup keyword
85     SetupUtils.Setup_Utils_For_Setup_And_Teardown
86     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
87     Builtin.Set Suite Variable    ${mininet_conn_id}
88     Utils.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
89     SSHKeywords.Virtual_Env_Create
90     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
91     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
92     Upload_Config_Files
93     Configure_Odl_With_Multipaths
94
95 Stop_Suite
96     [Documentation]    Suite teardown keyword with ord rib restoration
97     SSHKeywords.Virtual_Env_Delete
98     TemplatedRequests.Put_As_Xml_To_Uri    ${RIB_URI}    ${rib_old}    session=${CONFIG_SESSION}
99     SSHLibrary.Close_All_Connections
100     RequestsLibrary.Delete_All_Sessions
101
102 Upload_Config_Files
103     [Arguments]    ${addpath}=disable
104     [Documentation]    Uploads exabgp config files
105     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${DEFAUTL_RPC_CFG}    .
106     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
107     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
108     : FOR    ${cfgfile}    IN    @{cfgfiles}
109     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
110     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
111     \    SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/enable/g' ${cfgfile}
112     \    SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/${addpath}/g' ${cfgfile}
113     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
114     \    Log    ${stdout}
115
116 Configure_Path_Selection_And_App_Peer_And_Connect_Peer
117     [Arguments]    ${odl_path_sel_mode}    ${exa_add_path_value}
118     [Documentation]    Setup test case keyword. Early after the path selection config the incomming connection
119     ...    from exabgp towards odl may be rejected by odl due to config process not finished yet. Because of that
120     ...    we try to start the tool 3 times in case early attempts fail.
121     KarafKeywords.Log_Testcase_Start_To_Controller_Karaf
122     Configure_Path_Selection_Mode    ${odl_path_sel_mode}
123     Configure_App_Peer_With_Routes
124     Upload_Config_Files    addpath=${exa_add_path_value}
125     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start_Tool_And_Verify_Connected    ${DEFAUTL_RPC_CFG}
126
127 Start_Tool
128     [Arguments]    ${cfg_file}    ${mapping}={}
129     [Documentation]    Start the tool ${cmd} ${cfg_file}
130     ${start_cmd}    BuiltIn.Set_Variable    ${cmd} ${cfg_file}
131     BuiltIn.Log    ${start_cmd}
132     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
133     ${output}=    SSHLibrary.Write    ${start_cmd}
134     BuiltIn.Log    ${output}
135
136 Verify_Tools_Connection
137     [Arguments]    ${connected}=${True}
138     [Documentation]    Checks peer presence in operational datastore
139     ${exp_status_code}=    BuiltIn.Set_Variable_If    ${connected}    ${200}    ${404}
140     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${PEER_CHECK_URL}${TOOLS_SYSTEM_IP}
141     BuiltIn.Log    ${rsp.content}
142     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_status_code}    ${rsp.status_code}
143
144 Start_Tool_And_Verify_Connected
145     [Arguments]    ${cfg_file}
146     [Documentation]    Start the tool and verify its connection
147     Start_Tool    ${cfg_file}
148     BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s    Verify_Tools_Connection    connected=${True}
149
150 Stop_Tool
151     [Documentation]    Stop the tool by sending ctrl+c
152     ${output}=    SSHLibrary.Read
153     BuiltIn.Log    ${output}
154     Utils.Write_Bare_Ctrl_C
155     ${output}=    SSHLibrary.Read_Until_Prompt
156     BuiltIn.Log    ${output}
157     SSHKeywords.Virtual_Env_Deactivate_On_Current_Session    log_output=${True}
158
159 Remove_App_Peer_Configuration_And_Stop_Tool
160     Deconfigure_App_Peer
161     Stop_Tool
162     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
163
164 Verify_Expected_Update_Count
165     [Arguments]    ${exp_count}
166     [Documentation]    Verify number of received update messages
167     ${tool_count}=    BgpRpcClient.exa_get_received_update_count
168     BuiltIn.Should_Be_Equal_As_Numbers    ${exp_count}    ${tool_count}
169
170 Configure_Path_Selection_Mode
171     [Arguments]    ${psm}
172     [Documentation]    Configure path selection mode and get rib information for potential debug purposes
173     &{mapping}    BuiltIn.Create_Dictionary    PATHSELMODE=${psm}
174     TemplatedRequests.Get_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
175     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_psm    mapping=${mapping}    session=${CONFIG_SESSION}
176
177 Configure_Odl_With_Multipaths
178     [Documentation]    Configures odl to support n-paths or all-paths selection
179     ${mapping}=    BuiltIn.Set Variable    ${DEFAULT_MAPPING}
180     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_n_paths    mapping=${mapping}    session=${CONFIG_SESSION}
181     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/module_all_paths    mapping=${mapping}    session=${CONFIG_SESSION}
182     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/service_psmf    mapping=${mapping}    session=${CONFIG_SESSION}
183     Configure_Path_Selection_Mode    n-paths
184     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/service_bpsm    mapping=${mapping}    session=${CONFIG_SESSION}
185     ${rib_old}=    TemplatedRequests.Get_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
186     BuiltIn.Set_Suite_Variable    ${rib_old}
187     TemplatedRequests.Put_As_Xml_Templated    ${MULT_VAR_FOLDER}/rib    mapping=${mapping}    session=${CONFIG_SESSION}
188
189 Log_Loc_Rib_Operational
190     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/
191     BuiltIn.Log    ${rsp.content}
192
193 Configure_App_Peer_With_Routes
194     [Documentation]    Configure bgp application peer and fill it immediately with routes.
195     &{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}
196     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
197     : FOR    ${pathid}    IN    @{PATH_ID_LIST}
198     \    &{route_mapping}    BuiltIn.Create_Dictionary    NEXTHOP=${NEXT_HOP_PREF}${pathid}    LOCALPREF=${pathid}00    PATHID=${pathid}
199     \    TemplatedRequests.Post_As_Xml_Templated    ${MULT_VAR_FOLDER}/route    mapping=${route_mapping}    session=${CONFIG_SESSION}
200
201 Deconfigure_App_Peer
202     [Documentation]    Revert the BGP configuration to the original state: without application peer
203     &{route_mapping}    BuiltIn.Create_Dictionary
204     TemplatedRequests.Delete_Templated    ${MULT_VAR_FOLDER}/route    mapping=${route_mapping}    session=${CONFIG_SESSION}
205     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}
206     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}