Fix tox errors
[integration/test.git] / csit / suites / bgpcep / bgpingest / bgp_app_peer_prefixcount.robot
1 *** Settings ***
2 Documentation     BGP performance of ingesting from 1 BGP application peer
3 ...
4 ...               Copyright (c) 2015 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 ...               Test suite performs basic BGP performance test cases for
11 ...               BGP application peer. BGP application peer introduces routes -
12 ...               using restconf - in two steps:
13 ...               1. introduces the ${PREFILL} number of routes in one POST request
14 ...               2. POSTs the rest of routes (up to the ${COUNT} number) one by one
15 ...               Test suite checks that the prefixes are propagated to
16 ...               IPv4 topology and announced to BGP peer via updates. Test case
17 ...               where the BGP peer is disconnected and reconnected and all routes
18 ...               are deleted by BGP application peer are performed as well.
19 ...               Brief description how to configure BGP application peer and
20 ...               how to use restconf application peer interface:
21 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:User_Guide#BGP_Application_Peer
22 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:Programmer_Guide#BGP
23 ...               http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#bgp-peering
24 ...               http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#application-peer-configuration
25 ...
26 ...               Reported bugs:
27 ...               Bug 4689 - Not a reasonable duration of 1M prefix introduction from BGP application peer via restconf
28 ...               Bug 4791 - BGPSessionImpl: Failed to send message Update logged even all UPDATE mesages received by iBGP peer
29 Suite Setup       Setup_Everything
30 Suite Teardown    Teardown_Everything
31 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
32 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
33 Force Tags        critical
34 Library           SSHLibrary    timeout=10s
35 Library           RequestsLibrary
36 Resource          ../../../libraries/BGPcliKeywords.robot
37 Resource          ../../../libraries/KarafKeywords.robot
38 Resource          ../../../libraries/KillPythonTool.robot
39 Resource          ../../../libraries/PrefixCounting.robot
40 Resource          ../../../libraries/SetupUtils.robot
41 Resource          ../../../libraries/SSHKeywords.robot
42 Resource          ../../../libraries/TemplatedRequests.robot
43 Resource          ../../../libraries/Utils.robot
44 Resource          ../../../variables/Variables.robot
45
46 *** Variables ***
47 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
48 ${HOLDTIME}       180
49 ${HOLDTIME_APP_PEER_PREFIX_COUNT}    ${HOLDTIME}
50 ${COUNT}          200000
51 ${PREFILL}        100000
52 ${COUNT_APP_PEER_PREFIX_COUNT}    ${COUNT}
53 ${CHECK_PERIOD}    10
54 ${CHECK_PERIOD_APP_PEER_PREFIX_COUNT}    ${CHECK_PERIOD}
55 ${REPETITIONS_APP_PEER_PREFIX_COUNT}    1
56 ${BGP_PEER_LOG_LEVEL}    info
57 ${BGP_APP_PEER_LOG_LEVEL}    info
58 ${ODL_LOG_LEVEL}    INFO
59 ${ODL_BGP_LOG_LEVEL}    DEFAULT
60 ${BGP_PEER_COMMAND}    python play.py --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_PEER_LOG_LEVEL}
61 ${BGP_PEER_OPTIONS}    &>bgp_peer.log
62 ${BGP_APP_PEER_ID}    10.0.0.10
63 ${BGP_APP_PEER_INITIAL_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command post --count ${PREFILL} --prefix 8.0.0.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL} --stream=${ODL_STREAM}
64 ${BGP_APP_PEER_PUT_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command put --count ${PREFILL} --prefix 8.0.0.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL} --stream=${ODL_STREAM}
65 ${BGP_APP_PEER_DELETE_ALL_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command delete-all --${BGP_APP_PEER_LOG_LEVEL} --stream=${ODL_STREAM}
66 ${BGP_APP_PEER_GET_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command get --${BGP_APP_PEER_LOG_LEVEL} --stream=${ODL_STREAM}
67 ${BGP_APP_PEER_OPTIONS}    &>bgp_app_peer.log
68 ${TEST_DURATION_MULTIPLIER}    30
69 ${last_prefix_count}    -1
70 ${DEVICE_NAME}    controller-config
71 ${BGP_PEER_NAME}    example-bgp-peer
72 ${RIB_INSTANCE}    example-bgp-rib
73 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
74
75 *** Test Cases ***
76 Check_For_Empty_Ipv4_Topology_Before_Starting
77     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
78     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
79
80 Reconfigure_ODL_To_Accept_Connection
81     [Documentation]    Configure BGP peer module with initiate-connection set to false.
82     &{mapping}    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME_APP_PEER_PREFIX_COUNT}    PEER_PORT=${BGP_TOOL_PORT}
83     ...    INITIATE=false    BGP_RIB=${RIB_INSTANCE}    PASSIVE_MODE=true    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    RIB_INSTANCE_NAME=${RIB_INSTANCE}
84     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    mapping=${mapping}
85
86 Reconfigure_ODL_To_Accept_BGP_Application_Peer
87     [Documentation]    Configure BGP application peer module.
88     &{mapping}    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=example-bgp-peer-app    RIB_INSTANCE_NAME=${RIB_INSTANCE}    IP=${BGP_APP_PEER_ID}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
89     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    mapping=${mapping}
90
91 Connect_BGP_Peer
92     [Documentation]    Start BGP peer tool
93     SSHLibrary.Switch Connection    bgp_peer_console
94     BGPcliKeywords.Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
95     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
96
97 BGP_Application_Peer_Prefill_Routes
98     [Documentation]    Start BGP application peer tool and prefill routes.
99     SSHLibrary.Switch Connection    bgp_app_peer_console
100     BGPcliKeywords.Start_Console_Tool    ${BGP_APP_PEER_INITIAL_COMMAND} ${script_uri_opt}    ${BGP_APP_PEER_OPTIONS}
101     BGPcliKeywords.Wait_Until_Console_Tool_Finish    ${bgp_filling_timeout}
102     BGPcliKeywords.Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_prefill.log
103
104 Wait_For_Ipv4_Topology_Is_Prefilled
105     [Documentation]    Wait until example-ipv4-topology reaches the target prfix count.
106     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    10s    PrefixCounting.Check_Ipv4_Topology_Count    ${PREFILL}
107
108 Check_Bgp_Peer_Updates_For_Prefilled_Routes
109     [Documentation]    Count the routes introduced by updates.
110     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
111     ${count}    BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    3s    Check_For_String_In_File    bgp_peer.log    total_received_nlri_prefix_counter: ${PREFILL}
112     BuiltIn.Log    ${count}
113
114 BGP_Application_Peer_Introduce_Single_Routes
115     [Documentation]    Start BGP application peer tool and introduce routes.
116     SSHLibrary.Switch Connection    bgp_app_peer_console
117     BGPcliKeywords.Start_Console_Tool    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command add --count ${remaining_prefixes} --prefix 12.0.0.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL} --stream=${ODL_STREAM} ${script_uri_opt}    ${BGP_APP_PEER_OPTIONS}
118     BGPcliKeywords.Wait_Until_Console_Tool_Finish    ${bgp_filling_timeout}
119     BGPcliKeywords.Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_singles.log
120
121 Wait_For_Ipv4_Topology_Is_Filled
122     [Documentation]    Wait until example-ipv4-topology reaches the target prfix count.
123     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    10s    PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_APP_PEER_PREFIX_COUNT}
124
125 Check_Bgp_Peer_Updates_For_All_Routes
126     [Documentation]    Count the routes introduced by updates.
127     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
128     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    3s    Check_For_String_In_File    bgp_peer.log    total_received_nlri_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}
129
130 Disconnect_BGP_Peer
131     [Documentation]    Stop BGP peer tool
132     SSHLibrary.Switch Connection    bgp_peer_console
133     BGPcliKeywords.Stop_Console_Tool
134     BGPcliKeywords.Store_File_To_Workspace    bgp_peer.log    bgp_peer_reconnect.log
135
136 Reconnect_BGP_Peer
137     [Documentation]    Start BGP peer tool
138     SSHLibrary.Switch Connection    bgp_peer_console
139     BGPcliKeywords.Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
140     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
141
142 Check_Bgp_Peer_Updates_For_Reintroduced_Routes
143     [Documentation]    Count the routes introduced by updates.
144     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
145     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    3s    Check_For_String_In_File    bgp_peer.log    total_received_nlri_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}
146
147 BGP_Application_Peer_Delete_All_Routes
148     [Documentation]    Start BGP application peer tool and delete all routes.
149     SSHLibrary.Switch Connection    bgp_app_peer_console
150     BGPcliKeywords.Start_Console_Tool    ${BGP_APP_PEER_DELETE_ALL_COMMAND} --stream=${ODL_STREAM} ${script_uri_opt}    ${BGP_APP_PEER_OPTIONS}
151     BGPcliKeywords.Wait_Until_Console_Tool_Finish    ${bgp_emptying_timeout}
152     BGPcliKeywords.Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_delete_all.log
153
154 Wait_For_Stable_Topology_After_Deletion
155     [Documentation]    Wait until example-ipv4-topology becomes stable again.
156     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_APP_PEER_PREFIX_COUNT}    repetitions=${REPETITIONS_APP_PEER_PREFIX_COUNT}    excluded_count=${COUNT_APP_PEER_PREFIX_COUNT}
157
158 Check_For_Empty_Ipv4_Topology_After_Deleting
159     [Documentation]    Example-ipv4-topology should be empty now.
160     PrefixCounting.Check_Ipv4_Topology_Is_Empty
161
162 Check_Bgp_Peer_Updates_For_Prefix_Withdrawals
163     [Documentation]    Count the routes withdrawn by updates.
164     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
165     BuiltIn.Wait Until Keyword Succeeds    ${bgp_emptying_timeout}    3s    Check_For_String_In_File    bgp_peer.log    total_received_withdrawn_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}
166
167 Stop_BGP_Peer
168     [Documentation]    Stop BGP peer tool
169     SSHLibrary.Switch Connection    bgp_peer_console
170     BGPcliKeywords.Stop_Console_Tool
171     BGPcliKeywords.Store_File_To_Workspace    bgp_peer.log    bgp_peer_reconnect.log
172
173 Delete_Bgp_Peer_Configuration
174     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
175     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
176     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    mapping=${mapping}
177
178 Delete_Bgp_Application_Peer_Configuration
179     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
180     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=example-bgp-peer-app    IP=${BGP_APP_PEER_ID}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
181     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    mapping=${mapping}
182
183 *** Keywords ***
184 Setup_Everything
185     [Documentation]    Setup imported resources, SSH-login to tools system,
186     ...    create HTTP session, put Python tool to tools system.
187     SetupUtils.Setup_Utils_For_Setup_And_Teardown
188     TemplatedRequests.Create_Default_Session
189     PrefixCounting.PC_Setup
190     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
191     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    timeout=125    max_retries=0
192     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
193     # TODO: Alternatively, create variable in Variables which starts with http.
194     # Both TODOs would probably need to update every suite relying on current Variables.
195     Open_BGP_Peer_Console
196     Open_BGP_Aplicationp_Peer_Console
197     SSHKeywords.Require_Python
198     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
199     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
200     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/bgp_app_peer.py
201     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/ipv4-routes-template.xml*
202     # Calculate the timeout value based on how many routes are going to be pushed.
203     # The offset (20) is set for keeping reasonable timeout for low COUNT values.
204     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER} * ${COUNT_APP_PEER_PREFIX_COUNT} * 3.0 / 10000 + 20
205     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
206     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
207     ${result} =    BuiltIn.Evaluate    str(int(${COUNT_APP_PEER_PREFIX_COUNT}) - int(${PREFILL}))
208     Builtin.Set_Suite_Variable    ${remaining_prefixes}    ${result}
209     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${ODL_LOG_LEVEL}
210     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${ODL_BGP_LOG_LEVEL} org.opendaylight.bgpcep
211     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${ODL_BGP_LOG_LEVEL} org.opendaylight.protocol
212     ${script_uri_opt}=    Set Variable    --uri config/bgp-rib:application-rib/${BGP_APP_PEER_ID}/tables/bgp-types:ipv4-address-family/bgp-types:unicast-subsequent-address-family/
213     BuiltIn.Set_Suite_Variable    ${script_uri_opt}
214
215 Teardown_Everything
216     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
217     SSHLibrary.Switch Connection    bgp_peer_console
218     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
219     KillPythonTool.Search_And_Kill_Remote_Python    'bgp_app_peer\.py'
220     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Get_Sysstat_Statistics
221     RequestsLibrary.Delete_All_Sessions
222     SSHLibrary.Close_All_Connections
223
224 Open_BGP_Peer_Console
225     [Documentation]    Create a session for BGP peer.
226     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_peer_console
227     SSHKeywords.Flexible_Mininet_Login
228
229 Open_BGP_Aplicationp_Peer_Console
230     [Documentation]    Create a session for BGP peer.
231     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_app_peer_console
232     SSHKeywords.Flexible_Mininet_Login
233
234 Check_For_String_In_File
235     [Arguments]    ${file_name}    ${string}    ${threshold}=2
236     [Documentation]    Check file for ${string} and returns number of occurences
237     ${matches} =    SSHLibrary.Execute_Command    grep -c '${string}' '${file_name}'
238     ${count} =    Convert To Integer    ${matches}
239     BuiltIn.Should_Be_True    ${count} >= ${threshold}