Update Robot Framework format - step 3
[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
18 Library             RequestsLibrary
19 Library             SSHLibrary
20 Library             String
21 Library             ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
22 Resource            ../../../libraries/CompareStream.robot
23 Resource            ../../../libraries/ExaBgpLib.robot
24 Resource            ../../../libraries/KarafKeywords.robot
25 Resource            ../../../libraries/SetupUtils.robot
26 Resource            ../../../libraries/SSHKeywords.robot
27 Resource            ../../../libraries/TemplatedRequests.robot
28 Resource            ../../../variables/Variables.robot
29
30 Suite Setup         Start_Suite
31 Suite Teardown      Stop_Suite
32 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
33
34
35 *** Variables ***
36 ${APP_PEER_NAME}            example-bgp-peer-app
37 ${BGP_CFG_NAME}             exa.cfg
38 ${BGP_PEER_NAME}            example-bgp-peer
39 ${BGP_RR_VAR_FOLDER}        ${BGP_VAR_FOLDER}/route_refresh
40 ${BGP_VAR_FOLDER}           ${CURDIR}/../../../variables/bgpfunctional
41 ${CONFIG_SESSION}           config-session
42 ${DEVICE_NAME}              controller-config
43 ${EXARPCSCRIPT}             ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
44 ${HOLDTIME}                 180
45 ${PROTOCOL_OPENCONFIG}      ${RIB_INSTANCE}
46 ${RIB_INSTANCE}             example-bgp-rib
47 ${MSG_STATE_OFFSET}         24
48
49
50 *** Test Cases ***
51 Configure_App_Peer
52     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
53     &{mapping}    BuiltIn.Create_Dictionary
54     ...    DEVICE_NAME=${DEVICE_NAME}
55     ...    APP_PEER_NAME=${APP_PEER_NAME}
56     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
57     ...    APP_PEER_ID=${ODL_SYSTEM_IP}
58     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
59     ...    IP=${ODL_SYSTEM_IP}
60     TemplatedRequests.Put_As_Xml_Templated
61     ...    ${BGP_VAR_FOLDER}/app_peer
62     ...    mapping=${mapping}
63     ...    session=${CONFIG_SESSION}
64
65 Reconfigure_ODL_To_Accept_Connection
66     [Documentation]    Configures BGP peer module with initiate-connection set to false.
67     &{mapping}    BuiltIn.Create_Dictionary
68     ...    DEVICE_NAME=${DEVICE_NAME}
69     ...    BGP_NAME=${BGP_PEER_NAME}
70     ...    IP=${TOOLS_SYSTEM_IP}
71     ...    HOLDTIME=${HOLDTIME}
72     ...    PEER_PORT=${BGP_TOOL_PORT}
73     ...    INITIATE=false
74     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
75     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
76     ...    PASSIVE_MODE=true
77     TemplatedRequests.Put_As_Xml_Templated
78     ...    ${BGP_VAR_FOLDER}/bgp_peer
79     ...    mapping=${mapping}
80     ...    session=${CONFIG_SESSION}
81
82 Exa_To_Send_Route_Refresh
83     [Documentation]    Exabgp sends route refresh and count received updates
84     [Tags]    critical
85     [Setup]    Configure_Routes_And_Start_ExaBgp    ${BGP_CFG_NAME}
86     BgpRpcClient.exa_clean_received_update_count
87     BgpRpcClient.exa_announce    announce route-refresh ipv4 unicast
88     Comment    From neon onwards there are extra BGP End-Of-RIB message
89     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    2    3
90     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Updates    ${update_count}
91     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
92     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    4    7
93     BuiltIn.Wait_Until_Keyword_Succeeds
94     ...    3x
95     ...    5s
96     ...    Verify_Odl_Operational_State_Count
97     ...    notification_count=0
98     ...    update_count=${update_count}
99     ...    receive_count=2
100     [Teardown]    Deconfigure_Routes_And_Stop_ExaBgp
101
102 Odl_To_Send_Route_Refresh
103     [Documentation]    Sends route refresh request and checks if exabgp receives it
104     [Tags]    critical
105     [Setup]    ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${BGP_CFG_NAME}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
106     BgpRpcClient.exa_clean_received_route_refresh_count
107     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}
108     TemplatedRequests.Post_As_Xml_Templated
109     ...    ${BGP_VAR_FOLDER}/route_refresh
110     ...    mapping=${mapping}
111     ...    session=${CONFIG_SESSION}
112     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Route_Refresh    1
113     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
114     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    4    9
115     BuiltIn.Wait_Until_Keyword_Succeeds
116     ...    3x
117     ...    5s
118     ...    Verify_Odl_Operational_State_Count
119     ...    notification_count=1
120     ...    update_count=${update_count}
121     ...    receive_count=4
122     [Teardown]    ExaBgpLib.Stop_ExaBgp
123
124 Delete_Bgp_Peer_Configuration
125     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
126     &{mapping}    BuiltIn.Create_Dictionary
127     ...    DEVICE_NAME=${DEVICE_NAME}
128     ...    BGP_NAME=${BGP_PEER_NAME}
129     ...    IP=${TOOLS_SYSTEM_IP}
130     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
131     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
132
133 Deconfigure_App_Peer
134     [Documentation]    Revert the BGP configuration to the original state: without application peer
135     &{mapping}    BuiltIn.Create_Dictionary
136     ...    DEVICE_NAME=${DEVICE_NAME}
137     ...    APP_PEER_NAME=${APP_PEER_NAME}
138     ...    IP=${ODL_SYSTEM_IP}
139     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
140     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
141
142
143 *** Keywords ***
144 Start_Suite
145     [Documentation]    Suite setup keyword.
146     SetupUtils.Setup_Utils_For_Setup_And_Teardown
147     ${mininet_conn_id}    SSHLibrary.Open Connection
148     ...    ${TOOLS_SYSTEM_IP}
149     ...    prompt=${DEFAULT_LINUX_PROMPT}
150     ...    timeout=6s
151     Builtin.Set_Suite_Variable    ${mininet_conn_id}
152     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
153     SSHKeywords.Virtual_Env_Create
154     SSHKeywords.Virtual_Env_Install_Package    setuptools==44.0.0
155     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
156     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
157     Upload_Config_Files
158
159 Stop_Suite
160     [Documentation]    Suite teardown keyword
161     SSHKeywords.Virtual_Env_Delete
162     SSHLibrary.Close_All_Connections
163     RequestsLibrary.Delete_All_Sessions
164
165 Upload_Config_Files
166     [Documentation]    Uploads exabgp config files
167     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${BGP_CFG_NAME}    .
168     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
169     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
170     FOR    ${cfgfile}    IN    @{cfgfiles}
171         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
172         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
173         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/enable/g' ${cfgfile}
174         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
175         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
176         Log    ${stdout}
177     END
178
179 Configure_Routes_And_Start_ExaBgp
180     [Documentation]    Setup keyword for exa to odl test case
181     [Arguments]    ${cfg_file}
182     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
183     FOR    ${prefix}    IN    1.1.1.1/32    2.2.2.2/32
184         &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
185         TemplatedRequests.Post_As_Xml_Templated
186         ...    ${BGP_RR_VAR_FOLDER}/route
187         ...    mapping=${mapping}
188         ...    session=${CONFIG_SESSION}
189     END
190     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
191     Comment    From neon onwards there are extra BGP End-Of-RIB message per address family
192     ${update_count}    CompareStream.Set_Variable_If_At_Most_Fluorine    2    4
193     BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s    Verify_ExaBgp_Received_Updates    ${update_count}
194
195 Deconfigure_Routes_And_Stop_ExaBgp
196     [Documentation]    Teardown keyword for exa to odl test case
197     ExaBgpLib.Stop_ExaBgp
198     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
199     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
200     TemplatedRequests.Delete_Templated    ${BGP_RR_VAR_FOLDER}/route    mapping=${mapping}    session=${CONFIG_SESSION}
201
202 Verify_ExaBgp_Received_Updates
203     [Documentation]    Gets number of received update requests and compares with given expected count
204     [Arguments]    ${expcount}
205     ${count_recv}    BgpRpcClient.exa_get_received_update_count
206     BuiltIn.Should Be Equal As Numbers    ${count_recv}    ${expcount}
207
208 Verify_ExaBgp_Received_Route_Refresh
209     [Documentation]    Compares expected count of route request messages on exabgp side
210     [Arguments]    ${expcount}
211     ${count}    BgpRpcClient.exa_get_received_route_refresh_count
212     BuiltIn.Should Be Equal As Numbers    ${count}    ${expcount}
213
214 Verify_Odl_Operational_State_Count
215     [Documentation]    Check notification and update count gained from operatial neighbor state
216     ...    On versions oxygen and above, it verifies these counts also against cli output.
217     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
218     &{mapping}    BuiltIn.Create_Dictionary
219     ...    IP=${TOOLS_SYSTEM_IP}
220     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
221     ...    NOT_COUNT=${notification_count}
222     ...    SEND_COUNT=${update_count}
223     ...    RECV_COUNT=${receive_count}
224     ${ret}    BuiltIn.Wait_Until_Keyword_Succeeds
225     ...    3x
226     ...    5s
227     ...    TemplatedRequests.Get_As_Json_Templated
228     ...    folder=${BGP_RR_VAR_FOLDER}/operational_state
229     ...    mapping=${mapping}
230     ...    session=${CONFIG_SESSION}
231     ...    verify=True
232     BuiltIn.Log    ${ret}
233     BuiltIn.Wait_Until_Keyword_Succeeds
234     ...    3x
235     ...    5s
236     ...    Verify_Cli_Output_Count
237     ...    ${notification_count}
238     ...    ${update_count}
239     ...    ${receive_count}
240
241 Verify_Cli_Output_Count
242     [Documentation]    Checks notification and update count from odl-bgpcep-bgp-cli.
243     ...    odl-bgpcep-bgp-cli is only avaiable on versions oxygen and above.
244     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
245     ${output}    KarafKeywords.Safe_Issue_Command_On_Karaf_Console
246     ...    bgp:operational-state -rib example-bgp-rib -neighbor ${TOOLS_SYSTEM_IP}
247     BuiltIn.Log    ${output}
248     &{mapping}    BuiltIn.Create_Dictionary
249     ...    IP=${TOOLS_SYSTEM_IP}
250     ...    NOT_COUNT=${notification_count}
251     ...    SEND_COUNT=${update_count}
252     ...    DIVIDER=│
253     ...    RECV_COUNT=${receive_count}
254     ${expstate}    TemplatedRequests.Resolve_Text_From_Template_File
255     ...    folder=${BGP_RR_VAR_FOLDER}/operational_cli
256     ...    file_name=update.txt
257     ...    mapping=${mapping}
258     String.Get Line Count    ${output}
259     BuiltIn.Log    ${expstate}
260     ${expected_line_count}    String.Get Line Count    ${expstate}
261     FOR    ${expected_line_pos}    IN RANGE    0    ${expected_line_count-1}
262         ${expected_line_offset}    BuiltIn.Evaluate    ${MSG_STATE_OFFSET} + ${expected_line_pos}
263         ${output_line}    String.Get Line    ${output}    ${expected_line_offset}
264         ${expected_line}    String.Get Line    ${expstate}    ${expected_line_pos}
265         BuiltIn.Should Match    ${output_line}    ${expected_line}
266     END