BGP application peer performance suite
[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 ...
24 ...               Reported bugs:
25 ...               Bug 4689 - Not a reasonable duration of 1M prefix introduction from BGP application peer via restconf
26 ...               Bug 4791 - BGPSessionImpl: Failed to send message Update logged even all UPDATE mesages received by iBGP peer
27 Suite Setup       Setup_Everything
28 Suite Teardown    Teardown_Everything
29 Test Setup        Setup_Test_With_Logging_And_Without_Fast_Failing
30 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
31 Force Tags        critical
32 Library           SSHLibrary    timeout=10s
33 Library           RequestsLibrary
34 Variables         ${CURDIR}/../../../variables/Variables.py
35 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
36 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
37 Resource          ${CURDIR}/../../../libraries/FailFast.robot
38 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
39 Resource          ${CURDIR}/../../../libraries/PrefixCounting.robot
40 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
41
42 *** Variables ***
43 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
44 ${HOLDTIME}       180
45 ${HOLDTIME_APP_PEER_PREFIX_COUNT}    ${HOLDTIME}
46 ${COUNT}          200000
47 ${PREFILL}        100000
48 ${COUNT_APP_PEER_PREFIX_COUNT}    ${COUNT}
49 ${CHECK_PERIOD}    1
50 ${CHECK_PERIOD_APP_PEER_PREFIX_COUNT}    ${CHECK_PERIOD}
51 ${REPETITIONS_APP_PEER_PREFIX_COUNT}    1
52 ${BGP_PEER_LOG_LEVEL}    info
53 ${BGP_APP_PEER_LOG_LEVEL}    info
54 ${CONTROLLER_LOG_LEVEL}    INFO
55 ${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
56 ${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}
57 ${BGP_PEER_OPTIONS}    &>bgp_peer.log
58 ${BGP_APP_PEER_ID}    10.0.0.10
59 ${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}
60 ${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}
61 ${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}
62 ${BGP_APP_PEER_GET_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command get --${BGP_APP_PEER_LOG_LEVEL}
63 ${BGP_APP_PEER_OPTIONS}    &>bgp_app_peer.log
64 ${TEST_DURATION_MULTIPLIER}    30
65 ${last_prefix_count}    -1
66
67 *** Test Cases ***
68 Check_For_Empty_Ipv4_Topology_Before_Starting
69     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
70     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
71
72 Reconfigure_ODL_To_Accept_Connection
73     [Documentation]    Configure BGP peer module with initiate-connection set to false.
74     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_APP_PEER_PREFIX_COUNT}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
75     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
76
77 Reconfigure_ODL_To_Accept_BGP_Application_Peer
78     [Documentation]    Configure BGP application peer module.
79     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer-app', 'IP': '${BGP_APP_PEER_ID}'}
80     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    ${template_as_string}
81
82 Connect_BGP_Peer
83     [Documentation]    Start BGP peer tool
84     SSHLibrary.Switch Connection    bgp_peer_console
85     Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
86     Read_And_Fail_If_Prompt_Is_Seen
87
88 BGP_Application_Peer_Prefill_Routes
89     [Documentation]    Start BGP application peer tool and prefill routes.
90     SSHLibrary.Switch Connection    bgp_app_peer_console
91     Start_Console_Tool    ${BGP_APP_PEER_INITIAL_COMMAND}    ${BGP_APP_PEER_OPTIONS}
92     Wait_Until_Console_Tool_Finish    ${bgp_filling_timeout}
93     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_prefill.log
94
95 Wait_For_Ipv4_Topology_Is_Prefilled
96     [Documentation]    Wait until example-ipv4-topology reaches the target prfix count.
97     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    10s    PrefixCounting.Check_Ipv4_Topology_Count    ${PREFILL}
98     [Teardown]    Report_Failure_Due_To_Bug    4689
99
100 Check_Bgp_Peer_Updates_For_Prefilled_Routes
101     [Documentation]    Count the routes introduced by updates.
102     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
103     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    1s    Check_File_For_Word_Count    bgp_peer.log    total_received_nlri_prefix_counter: ${PREFILL}    2
104     [Teardown]    Report_Failure_Due_To_Bug    4689
105
106 BGP_Application_Peer_Introduce_Single_Routes
107     [Documentation]    Start BGP application peer tool and introduce routes.
108     SSHLibrary.Switch Connection    bgp_app_peer_console
109     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}    ${BGP_APP_PEER_OPTIONS}
110     Wait_Until_Console_Tool_Finish    ${bgp_filling_timeout}
111     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_singles.log
112
113 Wait_For_Ipv4_Topology_Is_Filled
114     [Documentation]    Wait until example-ipv4-topology reaches the target prfix count.
115     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    10s    PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_APP_PEER_PREFIX_COUNT}
116     [Teardown]    Report_Failure_Due_To_Bug    4689
117
118 Check_Bgp_Peer_Updates_For_All_Routes
119     [Documentation]    Count the routes introduced by updates.
120     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
121     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    1s    Check_File_For_Word_Count    bgp_peer.log    total_received_nlri_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}    2
122     [Teardown]    Report_Failure_Due_To_Bug    4689
123
124 Disconnect_BGP_Peer
125     [Documentation]    Stop BGP peer tool
126     SSHLibrary.Switch Connection    bgp_peer_console
127     Stop_Console_Tool
128     Store_File_To_Workspace    bgp_peer.log    bgp_peer_reconnect.log
129
130 Reconnect_BGP_Peer
131     [Documentation]    Start BGP peer tool
132     SSHLibrary.Switch Connection    bgp_peer_console
133     Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
134     Read_And_Fail_If_Prompt_Is_Seen
135
136 Check_Bgp_Peer_Updates_For_Reintroduced_Routes
137     [Documentation]    Count the routes introduced by updates.
138     BuiltIn.Wait Until Keyword Succeeds    ${bgp_filling_timeout}    1s    Check_File_For_Word_Count    bgp_peer.log    total_received_nlri_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}    2
139
140 BGP_Application_Peer_Delete_All_Routes
141     [Documentation]    Start BGP application peer tool and delete all routes.
142     SSHLibrary.Switch Connection    bgp_app_peer_console
143     Start_Console_Tool    ${BGP_APP_PEER_DELETE_ALL_COMMAND}    ${BGP_APP_PEER_OPTIONS}
144     Wait_Until_Console_Tool_Finish    ${bgp_emptying_timeout}
145     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_delete_all.log
146
147 Wait_For_Stable_Topology_After_Deletion
148     [Documentation]    Wait until example-ipv4-topology becomes stable again.
149     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}
150
151 Check_For_Empty_Ipv4_Topology_After_Deleting
152     [Documentation]    Example-ipv4-topology should be empty now.
153     PrefixCounting.Check_Ipv4_Topology_Is_Empty
154
155 Check_Bgp_Peer_Updates_For_Prefix_Withdrawals
156     [Documentation]    Count the routes withdrawn by updates.
157     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
158     BuiltIn.Wait Until Keyword Succeeds    ${bgp_emptying_timeout}    1s    Check_File_For_Word_Count    bgp_peer.log    total_received_withdrawn_prefix_counter: ${COUNT_APP_PEER_PREFIX_COUNT}    2
159     [Teardown]    Report_Failure_Due_To_Bug    4689
160
161 Stop_BGP_Peer
162     [Documentation]    Stop BGP peer tool
163     SSHLibrary.Switch Connection    bgp_peer_console
164     Stop_Console_Tool
165     Store_File_To_Workspace    bgp_peer.log    bgp_peer_reconnect.log
166
167 Delete_Bgp_Peer_Configuration
168     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
169     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
170     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
171
172 Delete_Bgp_Application_Peer_Configuration
173     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
174     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer-app'}
175     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    ${template_as_string}
176
177 Check_Controller_Logs
178     [Documentation]    Check controller's log for errors
179     Check Karaf Log File Does Not Have Messages    ${ODL_SYSTEM_IP}    Failed to send message Update
180     [Teardown]    Report_Failure_Due_To_Bug    4791
181
182 *** Keywords ***
183 Setup_Everything
184     [Documentation]    Setup imported resources, SSH-login to tools system,
185     ...    create HTTP session, put Python tool to tools system.
186     SetupUtils.Setup_Utils_For_Setup_And_Teardown
187     ConfigViaRestconf.Setup_Config_Via_Restconf
188     PrefixCounting.PC_Setup
189     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
190     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
191     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
192     # TODO: Alternatively, create variable in Variables which starts with http.
193     # Both TODOs would probably need to update every suite relying on current Variables.
194     Open_BGP_Peer_Console
195     Open_BGP_Aplicationp_Peer_Console
196     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
197     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/bgp_app_peer.py
198     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/ipv4-routes-template.xml
199     # Calculate the timeout value based on how many routes are going to be pushed.
200     # The offset (20) is set for keeping reasonable timeout for low COUNT values.
201     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER} * ${COUNT_APP_PEER_PREFIX_COUNT} * 3.0 / 10000 + 20
202     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
203     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
204     ${result} =    BuiltIn.Evaluate    str(int(${COUNT_APP_PEER_PREFIX_COUNT}) - int(${PREFILL}))
205     Builtin.Set_Suite_Variable    ${remaining_prefixes}    ${result}
206     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
207     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
208     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
209
210 Teardown_Everything
211     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
212     SSHLibrary.Switch Connection    bgp_peer_console
213     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
214     KillPythonTool.Search_And_Kill_Remote_Python    'bgp_app_peer\.py'
215     ConfigViaRestconf.Teardown_Config_Via_Restconf
216     RequestsLibrary.Delete_All_Sessions
217     SSHLibrary.Close_All_Connections
218
219 Open_BGP_Peer_Console
220     [Documentation]    Create a session for BGP peer.
221     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_peer_console
222     Utils.Flexible_Mininet_Login
223
224 Open_BGP_Aplicationp_Peer_Console
225     [Documentation]    Create a session for BGP peer.
226     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_app_peer_console
227     Utils.Flexible_Mininet_Login
228
229 Start_Console_Tool
230     [Arguments]    ${command}    ${tool_opt}
231     [Documentation]    Start the tool ${command} ${tool_opt}
232     BuiltIn.Log    ${command}
233     ${output}=    SSHLibrary.Write    ${command} ${tool_opt}
234     BuiltIn.Log    ${output}
235
236 Wait_Until_Console_Tool_Finish
237     [Arguments]    ${timeout}
238     [Documentation]    Wait ${timeout} for the tool exit.
239     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
240
241 Stop_Console_Tool
242     [Documentation]    Stop the tool if still running.
243     Utils.Write_Bare_Ctrl_C
244     ${output}=    SSHLibrary.Read    delay=1s
245     BuiltIn.Log    ${output}
246
247 Read_And_Fail_If_Prompt_Is_Seen
248     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
249     ${passed}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${TOOLS_SYSTEM_PROMPT}' in *.    Read_Text_Before_Prompt
250     BuiltIn.Return_From_Keyword_If    ${passed}
251     BGPSpeaker.Dump_BGP_Speaker_Logs
252     Builtin.Fail    The prompt was seen but it was not expected yet
253
254 Read_Text_Before_Prompt
255     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
256     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
257     ${text}=    SSHLibrary.Read_Until_Prompt
258     BuiltIn.Log    ${text}
259
260 Store_File_To_Workspace
261     [Arguments]    ${source_file_name}    ${target_file_name}
262     [Documentation]    Store the ${source_file_name} to the workspace as ${target_file_name}.
263     ${output_log}=    SSHLibrary.Execute_Command    cat ${source_file_name}
264     BuiltIn.Log    ${output_log}
265     Create File    ${target_file_name}    ${output_log}
266
267 Check_File_For_Word_Count
268     [Arguments]    ${file_name}    ${word}    ${expected_count}
269     [Documentation]    Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
270     ${output_log}=    SSHLibrary.Execute_Command    grep -o '${word}' ${file_name} | wc -l
271     BuiltIn.Log    ${output_log}
272     BuiltIn.Should_Be_Equal_As_Strings    ${output_log}    ${expected_count}