Pin python setuptools version to 44.0.0
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 040_bgp_functional_route_ref.robot
1 *** Settings ***
2 Documentation     Functional test for bgp - route refresh
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 sending and receiveing route refresh message.
11 ...               It uses odl and exabgp as bgp peers.
12 ...               Sending route refresh message from odl is initiated via restconf.
13 ...               If route refresh is received by odl, correct advertising of routes
14 ...               is verified. Receiving of route refresh by odl is verified by
15 ...               checking appropriate message counter via odl-bgpcep-bgp-cli and
16 ...               restconf using BGP neighbor operational state
17 Suite Setup       Start_Suite
18 Suite Teardown    Stop_Suite
19 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
20 Library           RequestsLibrary
21 Library           SSHLibrary
22 Library           String
23 Library           ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
24 Resource          ../../../libraries/CompareStream.robot
25 Resource          ../../../libraries/ExaBgpLib.robot
26 Resource          ../../../libraries/KarafKeywords.robot
27 Resource          ../../../libraries/SetupUtils.robot
28 Resource          ../../../libraries/SSHKeywords.robot
29 Resource          ../../../libraries/TemplatedRequests.robot
30 Resource          ../../../variables/Variables.robot
31
32 *** Variables ***
33 ${APP_PEER_NAME}    example-bgp-peer-app
34 ${BGP_CFG_NAME}    exa.cfg
35 ${BGP_PEER_NAME}    example-bgp-peer
36 ${BGP_RR_VAR_FOLDER}    ${BGP_VAR_FOLDER}/route_refresh
37 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
38 ${CONFIG_SESSION}    config-session
39 ${DEVICE_NAME}    controller-config
40 ${EXARPCSCRIPT}    ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
41 ${HOLDTIME}       180
42 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
43 ${RIB_INSTANCE}    example-bgp-rib
44 ${MSG_STATE_OFFSET}    24
45
46 *** Test Cases ***
47 Configure_App_Peer
48     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
49     &{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}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
50     ...    IP=${ODL_SYSTEM_IP}
51     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
52
53 Reconfigure_ODL_To_Accept_Connection
54     [Documentation]    Configures BGP peer module with initiate-connection set to false.
55     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
56     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
57     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
58
59 Exa_To_Send_Route_Refresh
60     [Documentation]    Exabgp sends route refresh and count received updates
61     [Tags]    critical
62     [Setup]    Configure_Routes_And_Start_ExaBgp    ${BGP_CFG_NAME}
63     BgpRpcClient.exa_clean_received_update_count
64     BgpRpcClient.exa_announce    announce route-refresh ipv4 unicast
65     Comment    From neon onwards there are extra BGP End-Of-RIB message
66     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    2    3
67     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Updates    ${update_count}
68     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
69     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    4    7
70     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Odl_Operational_State_Count    notification_count=0    update_count=${update_count}    receive_count=2
71     [Teardown]    Deconfigure_Routes_And_Stop_ExaBgp
72
73 Odl_To_Send_Route_Refresh
74     [Documentation]    Sends route refresh request and checks if exabgp receives it
75     [Tags]    critical
76     [Setup]    ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${BGP_CFG_NAME}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
77     BgpRpcClient.exa_clean_received_route_refresh_count
78     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}
79     TemplatedRequests.Post_As_Xml_Templated    ${BGP_VAR_FOLDER}/route_refresh    mapping=${mapping}    session=${CONFIG_SESSION}
80     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Route_Refresh    1
81     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
82     ${update_count} =    CompareStream.Set_Variable_If_At_Most_Fluorine    4    9
83     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Odl_Operational_State_Count    notification_count=1    update_count=${update_count}    receive_count=4
84     [Teardown]    ExaBgpLib.Stop_ExaBgp
85
86 Delete_Bgp_Peer_Configuration
87     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
88     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
89     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
90
91 Deconfigure_App_Peer
92     [Documentation]    Revert the BGP configuration to the original state: without application peer
93     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    IP=${ODL_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
94     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
95
96 *** Keywords ***
97 Start_Suite
98     [Documentation]    Suite setup keyword.
99     SetupUtils.Setup_Utils_For_Setup_And_Teardown
100     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
101     Builtin.Set_Suite_Variable    ${mininet_conn_id}
102     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
103     SSHKeywords.Virtual_Env_Create
104     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
105     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
106     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
107     Upload_Config_Files
108
109 Stop_Suite
110     [Documentation]    Suite teardown keyword
111     SSHKeywords.Virtual_Env_Delete
112     SSHLibrary.Close_All_Connections
113     RequestsLibrary.Delete_All_Sessions
114
115 Upload_Config_Files
116     [Documentation]    Uploads exabgp config files
117     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${BGP_CFG_NAME}    .
118     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
119     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
120     FOR    ${cfgfile}    IN    @{cfgfiles}
121         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
122         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
123         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/enable/g' ${cfgfile}
124         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
125         ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
126         Log    ${stdout}
127     END
128
129 Configure_Routes_And_Start_ExaBgp
130     [Arguments]    ${cfg_file}
131     [Documentation]    Setup keyword for exa to odl test case
132     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
133     FOR    ${prefix}    IN    1.1.1.1/32    2.2.2.2/32
134         &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
135         TemplatedRequests.Post_As_Xml_Templated    ${BGP_RR_VAR_FOLDER}/route    mapping=${mapping}    session=${CONFIG_SESSION}
136     END
137     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
138     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
139     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    2    4
140     BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s    Verify_ExaBgp_Received_Updates    ${update_count}
141
142 Deconfigure_Routes_And_Stop_ExaBgp
143     [Documentation]    Teardown keyword for exa to odl test case
144     ExaBgpLib.Stop_ExaBgp
145     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
146     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
147     TemplatedRequests.Delete_Templated    ${BGP_RR_VAR_FOLDER}/route    mapping=${mapping}    session=${CONFIG_SESSION}
148
149 Verify_ExaBgp_Received_Updates
150     [Arguments]    ${expcount}
151     [Documentation]    Gets number of received update requests and compares with given expected count
152     ${count_recv}=    BgpRpcClient.exa_get_received_update_count
153     BuiltIn.Should Be Equal As Numbers    ${count_recv}    ${expcount}
154
155 Verify_ExaBgp_Received_Route_Refresh
156     [Arguments]    ${expcount}
157     [Documentation]    Compares expected count of route request messages on exabgp side
158     ${count}=    BgpRpcClient.exa_get_received_route_refresh_count
159     BuiltIn.Should Be Equal As Numbers    ${count}    ${expcount}
160
161 Verify_Odl_Operational_State_Count
162     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
163     [Documentation]    Check notification and update count gained from operatial neighbor state
164     ...    On versions oxygen and above, it verifies these counts also against cli output.
165     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    RIB_INSTANCE_NAME=${RIB_INSTANCE}    NOT_COUNT=${notification_count}    SEND_COUNT=${update_count}    RECV_COUNT=${receive_count}
166     ${ret}=    BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    TemplatedRequests.Get_As_Json_Templated    folder=${BGP_RR_VAR_FOLDER}/operational_state    mapping=${mapping}
167     ...    session=${CONFIG_SESSION}    verify=True
168     BuiltIn.Log    ${ret}
169     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Cli_Output_Count    ${notification_count}    ${update_count}    ${receive_count}
170
171 Verify_Cli_Output_Count
172     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
173     [Documentation]    Checks notification and update count from odl-bgpcep-bgp-cli.
174     ...    odl-bgpcep-bgp-cli is only avaiable on versions oxygen and above.
175     ${output}    KarafKeywords.Safe_Issue_Command_On_Karaf_Console    bgp:operational-state -rib example-bgp-rib -neighbor ${TOOLS_SYSTEM_IP}
176     BuiltIn.Log    ${output}
177     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    NOT_COUNT=${notification_count}    SEND_COUNT=${update_count}    DIVIDER=│    RECV_COUNT=${receive_count}
178     ${expstate}    TemplatedRequests.Resolve_Text_From_Template_File    folder=${BGP_RR_VAR_FOLDER}/operational_cli    file_name=update.txt    mapping=${mapping}
179     String.Get Line Count    ${output}
180     BuiltIn.Log    ${expstate}
181     ${expected_line_count}    String.Get Line Count    ${expstate}
182     FOR    ${expected_line_pos}    IN RANGE    0    ${expected_line_count-1}
183         ${expected_line_offset}    BuiltIn.Evaluate    ${MSG_STATE_OFFSET} + ${expected_line_pos}
184         ${output_line}    String.Get Line    ${output}    ${expected_line_offset}
185         ${expected_line}    String.Get Line    ${expstate}    ${expected_line_pos}
186         BuiltIn.Should Match    ${output_line}    ${expected_line}
187     END