Update Robot Framework format - step 3
[integration/test.git] / csit / suites / bgpcep / bgpingest / manypeers_peercount.robot
1 *** Settings ***
2 Documentation       BGP performance of ingesting from many iBGP rrc peers, iBGPs receive updates.
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 uses play.py processes as iBGP rrc peers.
11 ...                 This is analogue of single peer performance suite, which uses many peers.
12 ...                 Each peer is of ibgp rrc type, and they contribute to the same example-bgp-rib,
13 ...                 and thus to the same single example-ipv4-topology.
14 ...                 The suite looks at example-ipv4-topology and checks BGP peers log for received updates.
15 ...
16 ...                 ODL distinguishes peers by their IP addresses.
17 ...                 Currently, this suite requires python utils to be started on ODL System,
18 ...                 to guarantee IP address block is available for them to bind to.
19 ...
20 ...                 Brief description how to configure BGP peer can be found here:
21 ...                 https://wiki.opendaylight.org/view/BGP_LS_PCEP:User_Guide#BGP_Peer
22 ...                 http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#bgp-peering
23
24 Library             DateTime
25 Library             RequestsLibrary
26 Library             SSHLibrary    timeout=10s
27 Resource            ../../../libraries/BGPSpeaker.robot
28 Resource            ../../../libraries/FailFast.robot
29 Resource            ../../../libraries/KarafKeywords.robot
30 Resource            ../../../libraries/KillPythonTool.robot
31 Resource            ../../../libraries/PrefixCounting.robot
32 Resource            ../../../libraries/SetupUtils.robot
33 Resource            ../../../libraries/SSHKeywords.robot
34 Resource            ../../../libraries/TemplatedRequests.robot
35 Resource            ../../../libraries/Utils.robot
36 Resource            ../../../variables/Variables.robot
37
38 Suite Setup         Setup_Everything
39 Suite Teardown      Teardown_Everything
40 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
41 Test Teardown       SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
42
43
44 *** Variables ***
45 ${BGP_TOOL_LOG_LEVEL}                                   info
46 ${BGP_PEERS_LOG_FILE_NAME}                              bgp_peer.log
47 ${BGP_VARIABLES_FOLDER}                                 ${CURDIR}/../../../variables/bgpuser/
48 ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}                   60
49 # With AdjRibsOut, the amount of data present is on the same scale as 600k ingest with single peer.
50 ${COUNT}
51 ...                                                     300000
52 ${COUNT_PREFIX_COUNT_MANY_RRC}                          ${COUNT}
53 ${FIRST_PEER_IP}                                        127.0.0.1
54 ${HOLDTIME}                                             180
55 ${HOLDTIME_PREFIX_COUNT_MANY_RRC}                       ${HOLDTIME}
56 ${KARAF_LOG_LEVEL}                                      INFO
57 ${KARAF_BGPCEP_LOG_LEVEL}                               ${KARAF_LOG_LEVEL}
58 ${KARAF_PROTOCOL_LOG_LEVEL}                             ${KARAF_BGPCEP_LOG_LEVEL}
59 ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}                   2
60 ${REPETITIONS_PREFIX_COUNT_MANY_RRC}                    2
61 ${TEST_DURATION_MULTIPLIER}                             1
62 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY_RRC}       ${TEST_DURATION_MULTIPLIER}
63 ${RIB_INSTANCE}                                         example-bgp-rib
64 ${PROTOCOL_OPENCONFIG}                                  ${RIB_INSTANCE}
65 ${DEVICE_NAME}                                          controller-config
66
67
68 *** Test Cases ***
69 Check_For_Empty_Ipv4_Topology_Before_Talking
70     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
71     [Tags]    critical
72     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
73     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
74
75 Reconfigure_ODL_To_Accept_Connections
76     [Documentation]    Configure BGP peer modules with initiate-connection set to false.
77     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
78     FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
79         ${peer_name} =    BuiltIn.Set_Variable    example-bgp-peer-${index}
80         ${peer_ip} =    BuiltIn.Evaluate    str(ipaddr.IPAddress('${FIRST_PEER_IP}') + ${index} - 1)    modules=ipaddr
81         &{mapping} =    BuiltIn.Create_Dictionary
82         ...    DEVICE_NAME=${DEVICE_NAME}
83         ...    NAME=${peer_name}
84         ...    IP=${peer_ip}
85         ...    HOLDTIME=${HOLDTIME_PREFIX_COUNT_MANY_RRC}
86         ...    PEER_PORT=${BGP_TOOL_PORT}
87         ...    PEER_ROLE=rr-client
88         ...    INITIATE=false
89         ...    BGP_RIB=${RIB_INSTANCE}
90         ...    PASSIVE_MODE=true
91         ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
92         ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
93         ...    RR_CLIENT=true
94         TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    mapping=${mapping}
95     END
96
97 Start_Talking_BGP_Manager
98     [Documentation]    Start Python manager to connect speakers to ODL.
99     BGPSpeaker.Start_BGP_Manager
100     ...    --amount=${COUNT_PREFIX_COUNT_MANY_RRC} --multiplicity=${MULTIPLICITY_PREFIX_COUNT_MANY_RRC} --myip=${FIRST_PEER_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --logfile=${BGP_PEERS_LOG_FILE_NAME} --${BGP_TOOL_LOG_LEVEL}
101
102 Wait_For_Ipv4_Topology
103     [Documentation]    Wait until example-ipv4-topology reaches the target prefix count.
104     [Tags]    critical
105     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
106     BuiltIn.Log    max. ${bgp_filling_timeout}s    console=yes
107     Init_Check_Ipv4_Topology_Keyword    ${COUNT_PREFIX_COUNT_MANY_RRC}    ${REPETITIONS_PREFIX_COUNT_MANY_RRC}
108     ${message} =    BuiltIn.Wait_Until_Keyword_Succeeds
109     ...    ${bgp_filling_timeout}
110     ...    ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}
111     ...    Check_Ipv4_Topology
112     BuiltIn.Should_Be_Equal_As_Strings    ${message}    Target value reached.
113
114 Check_Logs_For_Updates
115     [Documentation]    Check BGP peer logs for received updates.
116     [Tags]    critical
117     ${timeout} =    BuiltIn.Set_Variable    ${bgp_filling_timeout}
118     FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
119         ${bgp_peer_label} =    BuiltIn.Set_Variable    BGP-Dummy-${index}
120         ${expected_prefixcount} =    BuiltIn.Evaluate
121         ...    ${COUNT_PREFIX_COUNT_MANY_RRC} - ${COUNT_PREFIX_COUNT_MANY_RRC} // ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}
122         ${expected_string} =    BuiltIn.Set_Variable    total_received_nlri_prefix_counter: ${expected_prefixcount}
123         BuiltIn.Wait_Until_Keyword_Succeeds
124         ...    ${timeout}
125         ...    1s
126         ...    Check_File_For_Occurence
127         ...    ${BGP_PEERS_LOG_FILE_NAME}
128         ...    ${bgp_peer_label}
129         ...    ${expected_string}
130         ...    2
131         ${timeout} =    BuiltIn.Set_Variable    20s
132         # FIXME: Calculation of ${expected_prefixcount} correct just when the ${COUNT_PREFIX_COUNT_MANY_RRC} is a multiplication of ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}
133     END
134
135 Kill_Talking_BGP_Speakers
136     [Documentation]    Abort the Python speakers. Also, attempt to stop failing fast.
137     [Tags]    critical
138     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
139     BGPSpeaker.Kill_BGP_Speaker
140     FailFast.Do_Not_Fail_Fast_From_Now_On
141     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
142     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
143
144 Wait_For_Stable_Ipv4_Topology_After_Talking
145     [Documentation]    Wait until example-ipv4-topology becomes stable again.
146     [Tags]    critical
147     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
148     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable
149     ...    timeout=${bgp_emptying_timeout}
150     ...    period=${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}
151     ...    repetitions=${REPETITIONS_PREFIX_COUNT_MANY_RRC}
152     ...    excluded_count=${COUNT_PREFIX_COUNT_MANY_RRC}
153
154 Check_For_Empty_Ipv4_Topology_After_Talking
155     [Documentation]    Example-ipv4-topology should be empty now.
156     [Tags]    critical
157     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
158     PrefixCounting.Check_Ipv4_Topology_Is_Empty
159
160 Delete_Bgp_Peer_Configuration
161     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
162     [Tags]    critical
163     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
164     FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
165         ${peer_name} =    BuiltIn.Set_Variable    example-bgp-peer-${index}
166         ${peer_ip} =    BuiltIn.Evaluate    str(ipaddr.IPAddress('${FIRST_PEER_IP}') + ${index} - 1)    modules=ipaddr
167         &{mapping} =    BuiltIn.Create_Dictionary
168         ...    DEVICE_NAME=${DEVICE_NAME}
169         ...    NAME=${peer_name}
170         ...    IP=${peer_ip}
171         ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
172         TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    mapping=${mapping}
173     END
174
175
176 *** Keywords ***
177 Setup_Everything
178     [Documentation]    Setup imported resources, SSH-login to ODL system,
179     ...    create HTTP session, put Python tool to ODL system.
180     SetupUtils.Setup_Utils_For_Setup_And_Teardown
181     TemplatedRequests.Create_Default_Session
182     PrefixCounting.PC_Setup
183     RequestsLibrary.Create_Session
184     ...    operational
185     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
186     ...    auth=${AUTH}
187     ...    timeout=125
188     ...    max_retries=0
189     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
190     # TODO: Alternatively, create variable in Variables which starts with http.
191     # Both TODOs would probably need to update every suite relying on current Variables.
192     SSHLibrary.Set_Default_Configuration    prompt=${ODL_SYSTEM_PROMPT}
193     SSHLibrary.Open_Connection    ${ODL_SYSTEM_IP}
194     SSHKeywords.Flexible_Controller_Login
195     SSHKeywords.Require_Python
196     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
197     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
198     # Calculate the timeout value based on how many routes are going to be pushed.
199     ${period} =    DateTime.Convert_Time    ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}    result_format=number
200     ${timeout} =    BuiltIn.Evaluate
201     ...    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC} * ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY_RRC} * (${COUNT_PREFIX_COUNT_MANY_RRC} * 6.0 / 10000 + ${period} * (${REPETITIONS_PREFIX_COUNT_MANY_RRC} + 1)) + 20
202     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
203     ${timeout} =    BuiltIn.Evaluate
204     ...    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY_RRC} * (${COUNT_PREFIX_COUNT_MANY_RRC} * 2.0 / 10000 + ${period} * (${REPETITIONS_PREFIX_COUNT_MANY_RRC} + 1)) + 20
205     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${timeout}
206     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
207
208 Teardown_Everything
209     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
210     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
211     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
212     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Get_Sysstat_Statistics
213     RequestsLibrary.Delete_All_Sessions
214     SSHLibrary.Close_All_Connections
215
216 Init_Check_Ipv4_Topology_Keyword
217     [Documentation]    Initialise test variables for Check_Ipv4_Topology keyword.
218     [Arguments]    ${expected_count}=0    ${deadlock_cycles}=-1
219     ${deadlock_cycles} =    Convert To Integer    ${deadlock_cycles}
220     BuiltIn.Set_Test_Variable    ${deadlock_cycles}
221     BuiltIn.Set_Test_Variable    ${ipv4_topology_deadlock_countdown}    ${deadlock_cycles}
222     BuiltIn.Set_Test_Variable    ${expected_count}
223     BuiltIn.Set_Test_Variable    ${ipv4_topology_last_count}    -1
224
225 Check_Ipv4_Topology
226     [Documentation]    Check and log the IPv4 topology count. PASS if ${expected_count} or ${actual_count} not changed for ${deadlock_cycles} keyword calls.
227     ${actual_count} =    PrefixCounting.Get_Ipv4_Topology_Count
228     ${ipv4_topology_deadlock_countdown} =    BuiltIn.Set_Variable_If
229     ...    (${actual_count} == ${ipv4_topology_last_count}) and (${ipv4_topology_deadlock_countdown} >= 0)
230     ...    ${ipv4_topology_deadlock_countdown - 1}
231     ...    ${deadlock_cycles}
232     ${hour}    ${min}    ${sec} =    BuiltIn.Get_Time    hour min sec
233     BuiltIn.Set_Test_Variable    ${ipv4_topology_deadlock_countdown}
234     BuiltIn.Set_Test_Variable    ${ipv4_topology_last_count}    ${actual_count}
235     BuiltIn.Log
236     ...    ${hour}:${min}:${sec} actual/expected prefix count is ${actual_count}/${expected_count} (countdown:${ipv4_topology_deadlock_countdown})
237     ...    console=yes
238     IF    ${ipv4_topology_deadlock_countdown} == 0
239         RETURN    Deadlock detected (ipv4-topology not changed for ${deadlock_cycles} cycles)
240     END
241     BuiltIn.Should_Be_Equal_As_Integers    ${actual_count}    ${expected_count}
242     RETURN    Target value reached.
243
244 Check_File_For_Occurence
245     [Documentation]    Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
246     [Arguments]    ${file_name}    ${keyword}    ${value}=''    ${threshold}=1
247     ${output_log} =    SSHLibrary.Execute_Command    grep '${keyword}' '${file_name}' | grep -c '${value}'
248     ${count} =    Convert To Integer    ${output_log}
249     BuiltIn.Should_Be_True    ${count} >= ${threshold}
250     RETURN    ${count}