Fix bgp_route_refresh line ending
[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           ../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
23 Resource          ../../../libraries/CompareStream.robot
24 Resource          ../../../libraries/ExaBgpLib.robot
25 Resource          ../../../libraries/KarafKeywords.robot
26 Resource          ../../../libraries/SetupUtils.robot
27 Resource          ../../../libraries/SSHKeywords.robot
28 Resource          ../../../libraries/TemplatedRequests.robot
29 Resource          ../../../variables/Variables.robot
30
31 *** Variables ***
32 ${APP_PEER_NAME}    example-bgp-peer-app
33 ${BGP_CFG_NAME}    exa.cfg
34 ${BGP_PEER_NAME}    example-bgp-peer
35 ${BGP_RR_VAR_FOLDER}    ${BGP_VAR_FOLDER}/route_refresh
36 ${BGP_VAR_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
37 ${CONFIG_SESSION}    config-session
38 ${DEVICE_NAME}    controller-config
39 ${EXARPCSCRIPT}    ${CURDIR}/../../../../tools/exabgp_files/exarpc.py
40 ${HOLDTIME}       180
41 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
42 ${RIB_INSTANCE}    example-bgp-rib
43
44 *** Test Cases ***
45 Configure_App_Peer
46     [Documentation]    Configures bgp application peer. Openconfig is used for carbon and above.
47     &{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}
48     ...    IP=${ODL_SYSTEM_IP}
49     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
50
51 Reconfigure_ODL_To_Accept_Connection
52     [Documentation]    Configures BGP peer module with initiate-connection set to false.
53     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
54     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
55     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
56
57 Exa_To_Send_Route_Refresh
58     [Documentation]    Exabgp sends route refresh and count received updates
59     [Tags]    critical
60     [Setup]    Configure_Routes_And_Start_ExaBgp    ${BGP_CFG_NAME}
61     BgpRpcClient.exa_clean_received_update_count
62     BgpRpcClient.exa_announce    announce route-refresh ipv4 unicast
63     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Updates    ${nr_configured_routes}
64     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Odl_Operational_State_Count    notification_count=0    update_count=${nr_configured_routes}    receive_count=4
65     [Teardown]    Deconfigure_Routes_And_Stop_ExaBgp
66
67 Odl_To_Send_Route_Refresh
68     [Documentation]    Sends route refresh request and checks if exabgp receives it
69     [Tags]    critical
70     [Setup]    ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${BGP_CFG_NAME}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
71     BgpRpcClient.exa_clean_received_route_refresh_count
72     &{mapping}    BuiltIn.Create_Dictionary    BGP_PEER_IP=${TOOLS_SYSTEM_IP}
73     TemplatedRequests.Post_As_Xml_Templated    ${BGP_VAR_FOLDER}/route_refresh    mapping=${mapping}    session=${CONFIG_SESSION}
74     BuiltIn.Wait_Until_Keyword_Succeeds    5x    2s    Verify_ExaBgp_Received_Route_Refresh    1
75     ${receive_count} =    CompareStream.Set_Variable_If_At_Least_Neon    6    4
76     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Odl_Operational_State_Count    notification_count=1    update_count=4    receive_count=${receive_count}
77     [Teardown]    ExaBgpLib.Stop_ExaBgp
78
79 Delete_Bgp_Peer_Configuration
80     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
81     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
82     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
83
84 Deconfigure_App_Peer
85     [Documentation]    Revert the BGP configuration to the original state: without application peer
86     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    IP=${ODL_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
87     TemplatedRequests.Delete_Templated    ${BGP_VAR_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
88
89 *** Keywords ***
90 Start_Suite
91     [Documentation]    Suite setup keyword.
92     SetupUtils.Setup_Utils_For_Setup_And_Teardown
93     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
94     Builtin.Set_Suite_Variable    ${mininet_conn_id}
95     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
96     SSHKeywords.Virtual_Env_Create
97     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
98     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
99     Upload_Config_Files
100
101 Stop_Suite
102     [Documentation]    Suite teardown keyword
103     SSHKeywords.Virtual_Env_Delete
104     SSHLibrary.Close_All_Connections
105     RequestsLibrary.Delete_All_Sessions
106
107 Upload_Config_Files
108     [Documentation]    Uploads exabgp config files
109     SSHLibrary.Put_File    ${BGP_VAR_FOLDER}/${BGP_CFG_NAME}    .
110     SSHLibrary.Put_File    ${EXARPCSCRIPT}    .
111     @{cfgfiles}=    SSHLibrary.List_Files_In_Directory    .    *.cfg
112     : FOR    ${cfgfile}    IN    @{cfgfiles}
113     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
114     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
115     \    SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/enable/g' ${cfgfile}
116     \    SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
117     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
118     \    Log    ${stdout}
119
120 Configure_Routes_And_Start_ExaBgp
121     [Arguments]    ${cfg_file}
122     [Documentation]    Setup keyword for exa to odl test case
123     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
124     : FOR    ${prefix}    IN    1.1.1.1/32    2.2.2.2/32
125     \    &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
126     \    TemplatedRequests.Post_As_Xml_Templated    ${BGP_RR_VAR_FOLDER}/route    mapping=${mapping}    session=${CONFIG_SESSION}
127     BuiltIn.Set_Suite_Variable    ${nr_configured_routes}    2
128     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}
129     BuiltIn.Wait_Until_Keyword_Succeeds    3x    3s    Verify_ExaBgp_Received_Updates    ${nr_configured_routes}
130
131 Deconfigure_Routes_And_Stop_ExaBgp
132     [Documentation]    Teardown keyword for exa to odl test case
133     ExaBgpLib.Stop_ExaBgp
134     ${app_rib}    Set Variable    ${ODL_SYSTEM_IP}
135     &{mapping}    BuiltIn.Create_Dictionary    PREFIX=${prefix}    APP_RIB=${app_rib}
136     TemplatedRequests.Delete_Templated    ${BGP_RR_VAR_FOLDER}/route    mapping=${mapping}    session=${CONFIG_SESSION}
137
138 Verify_ExaBgp_Received_Updates
139     [Arguments]    ${expcount}
140     [Documentation]    Gets number of received update requests and compares with given expected count
141     ${count_recv}=    BgpRpcClient.exa_get_received_update_count
142     BuiltIn.Should Be Equal As Numbers    ${count_recv}    ${expcount}
143
144 Verify_ExaBgp_Received_Route_Refresh
145     [Arguments]    ${expcount}
146     [Documentation]    Compares expected count of route request messages on exabgp side
147     ${count}=    BgpRpcClient.exa_get_received_route_refresh_count
148     BuiltIn.Should Be Equal As Numbers    ${count}    ${expcount}
149
150 Verify_Odl_Operational_State_Count
151     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
152     [Documentation]    Check notification and update count gained from operatial neighbor state
153     ...    On versions oxygen and above, it verifies these counts also against cli output.
154     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    RIB_INSTANCE_NAME=${RIB_INSTANCE}    NOT_COUNT=${notification_count}    UPD_COUNT=${update_count}    RCV_COUNT=${receive_count}
155     ${ret}=    BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    TemplatedRequests.Get_As_Json_Templated    folder=${BGP_RR_VAR_FOLDER}/operational_state    mapping=${mapping}
156     ...    session=${CONFIG_SESSION}    verify=True
157     BuiltIn.Log    ${ret}
158     BuiltIn.Wait_Until_Keyword_Succeeds    3x    5s    Verify_Cli_Output_Count    ${notification_count}    ${update_count}    ${receive_count}
159
160 Verify_Cli_Output_Count
161     [Arguments]    ${notification_count}    ${update_count}    ${receive_count}
162     [Documentation]    Checks notification and update count from odl-bgpcep-bgp-cli.
163     ...    odl-bgpcep-bgp-cli is only avaiable on versions oxygen and above.
164     ${output}    KarafKeywords.Safe_Issue_Command_On_Karaf_Console    bgp:operational-state -rib example-bgp-rib -neighbor ${TOOLS_SYSTEM_IP}
165     BuiltIn.Log    ${output}
166     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    NOT_COUNT=${notification_count}    UPD_COUNT=${update_count}    DIVIDER=│    RCV_COUNT=${receive_count}
167     ${expstate}    TemplatedRequests.Resolve_Text_From_Template_File    folder=${BGP_RR_VAR_FOLDER}/operational_cli    file_name=update.txt    mapping=${mapping}
168     BuiltIn.Should_Contain    ${output}    ${expstate}