Many iBGP routing reflector clients
[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 Suite Setup       Setup_Everything
20 Suite Teardown    Teardown_Everything
21 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
22 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
23 Library           DateTime
24 Library           RequestsLibrary
25 Library           SSHLibrary    timeout=10s
26 Variables         ${CURDIR}/../../../variables/Variables.py
27 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
28 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
29 Resource          ${CURDIR}/../../../libraries/FailFast.robot
30 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
31 Resource          ${CURDIR}/../../../libraries/PrefixCounting.robot
32 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
33 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
34
35 *** Variables ***
36 ${BGP_TOOL_LOG_LEVEL}    info
37 ${BGP_PEERS_LOG_FILE_NAME}    bgp_peer.log
38 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
39 ${CHECK_PERIOD}    10
40 ${CHECK_PERIOD_PREFIX_COUNT}    ${CHECK_PERIOD}
41 ${CHECK_PERIOD_PREFIX_COUNT_MANY}    ${CHECK_PERIOD_PREFIX_COUNT}
42 ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}    ${CHECK_PERIOD_PREFIX_COUNT_MANY}
43 ${COUNT}          1000000
44 ${COUNT_PREFIX_COUNT}    ${COUNT}
45 ${COUNT_PREFIX_COUNT_MANY}    ${COUNT_PREFIX_COUNT}
46 ${COUNT_PREFIX_COUNT_MANY_RRC}    ${COUNT_PREFIX_COUNT_MANY}
47 ${FIRST_PEER_IP}    127.0.0.1
48 ${HOLDTIME}       180
49 ${HOLDTIME_PREFIX_COUNT}    ${HOLDTIME}
50 ${HOLDTIME_PREFIX_COUNT_MANY}    ${HOLDTIME_PREFIX_COUNT}
51 ${HOLDTIME_PREFIX_COUNT_MANY_RRC}    ${HOLDTIME_PREFIX_COUNT_MANY}
52 ${KARAF_LOG_LEVEL}    INFO
53 ${KARAF_BGPCEP_LOG_LEVEL}    ${KARAF_LOG_LEVEL}
54 ${KARAF_PROTOCOL_LOG_LEVEL}    ${KARAF_BGPCEP_LOG_LEVEL}
55 ${MULTIPLICITY}    10
56 ${MULTIPLICITY_PREFIX_COUNT}    ${MULTIPLICITY}
57 ${MULTIPLICITY_PREFIX_COUNT_MANY}    ${MULTIPLICITY_PREFIX_COUNT}
58 ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}    ${MULTIPLICITY_PREFIX_COUNT_MANY}
59 ${REPETITIONS}    1
60 ${REPETITIONS_PREFIX_COUNT}    ${REPETITIONS}
61 ${REPETITIONS_PREFIX_COUNT_MANY}    ${REPETITIONS_PREFIX_COUNT}
62 ${REPETITIONS_PREFIX_COUNT_MANY_RRC}    ${REPETITIONS_PREFIX_COUNT_MANY}
63 ${TEST_DURATION_MULTIPLIER}    1
64 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT}    ${TEST_DURATION_MULTIPLIER}
65 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY}    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT}
66 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY_RRC}    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY}
67 # TODO: Option names can be better.
68 # TODO: TODOs can be better.
69
70 *** Test Cases ***
71 Check_For_Empty_Ipv4_Topology_Before_Talking
72     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
73     [Tags]    critical
74     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
75     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
76
77 Reconfigure_ODL_To_Accept_Connections
78     [Documentation]    Configure BGP peer modules with initiate-connection set to false.
79     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
80     : FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
81     \    ${peer_name} =    BuiltIn.Set_Variable    example-bgp-peer-${index}
82     \    ${peer_ip} =    BuiltIn.Evaluate    str(ipaddr.IPAddress('${FIRST_PEER_IP}') + ${index} - 1)    modules=ipaddr
83     \    ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': '${peer_name}', 'IP': '${peer_ip}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'HOLDTIME': '${HOLDTIME_PREFIX_COUNT_MANY_RRC}', 'PEER_ROLE': 'rr-client', 'INITIATE': 'false'}
84     \    ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
85
86 Start_Talking_BGP_Manager
87     [Documentation]    Start Python manager to connect speakers to ODL.
88     BGPSpeaker.Start_BGP_Manager    --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}
89
90 Wait_For_Ipv4_Topology
91     [Documentation]    Wait until example-ipv4-topology reaches the target prefix count.
92     [Tags]    critical
93     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
94     BuiltIn.Log    ${bgp_filling_timeout}s    console=yes
95     BuiltIn.Wait_Until_Keyword_Succeeds    ${bgp_filling_timeout}    ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}    Check_Ipv4_Topology    ${COUNT_PREFIX_COUNT_MANY_RRC}
96     [Teardown]    Report_Failure_Due_To_Bug    5185
97
98 Check_Logs_For_Updates
99     [Documentation]    Check BGP peer logs for received updates.
100     [Tags]    critical
101     ${timeout} =    BuiltIn.Set_Variable    ${bgp_filling_timeout}
102     : FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
103     \    ${bgp_peer_label} =    BuiltIn.Set_Variable    BGP-Dummy-${index}
104     \    ${expected_prefixcount} =    BuiltIn.Evaluate    ${COUNT_PREFIX_COUNT_MANY_RRC} - ${COUNT_PREFIX_COUNT_MANY_RRC} / ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}
105     \    ${expected_string} =    BuiltIn.Set_Variable    total_received_nlri_prefix_counter: ${expected_prefixcount}
106     \    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    1s    Check_File_For_Occurence    ${BGP_PEERS_LOG_FILE_NAME}    ${bgp_peer_label}
107     \    ...    ${expected_string}    2
108     \    ${timeout} =    BuiltIn.Set_Variable    20s
109     # FIXME: Calculation of ${expected_prefixcount} correct just when the ${COUNT_PREFIX_COUNT_MANY_RRC} is a multiplication of ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}
110
111 Kill_Talking_BGP_Speakers
112     [Documentation]    Abort the Python speakers. Also, attempt to stop failing fast.
113     [Tags]    critical
114     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
115     BGPSpeaker.Kill_BGP_Speaker
116     FailFast.Do_Not_Fail_Fast_From_Now_On
117     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
118     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
119
120 Wait_For_Stable_Ipv4_Topology_After_Talking
121     [Documentation]    Wait until example-ipv4-topology becomes stable again.
122     [Tags]    critical
123     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
124     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}    repetitions=${REPETITIONS_PREFIX_COUNT_MANY_RRC}    excluded_count=${COUNT_PREFIX_COUNT_MANY_RRC}
125     [Teardown]    Report_Failure_Due_To_Bug    5097
126
127 Check_For_Empty_Ipv4_Topology_After_Talking
128     [Documentation]    Example-ipv4-topology should be empty now.
129     [Tags]    critical
130     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
131     PrefixCounting.Check_Ipv4_Topology_Is_Empty
132     [Teardown]    Report_Failure_Due_To_Bug    5097
133
134 Delete_Bgp_Peer_Configuration
135     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
136     [Tags]    critical
137     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
138     : FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_PREFIX_COUNT_MANY_RRC}+1
139     \    ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer-${index}'}
140     \    ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLESFOLDER}${/}ibgp_peers    ${template_as_string}
141
142 *** Keywords ***
143 Setup_Everything
144     [Documentation]    Setup imported resources, SSH-login to ODL system,
145     ...    create HTTP session, put Python tool to ODL system.
146     SetupUtils.Setup_Utils_For_Setup_And_Teardown
147     ConfigViaRestconf.Setup_Config_Via_Restconf
148     PrefixCounting.PC_Setup
149     SSHLibrary.Set_Default_Configuration    prompt=${ODL_SYSTEM_PROMPT}
150     SSHLibrary.Open_Connection    ${ODL_SYSTEM_IP}
151     Utils.Flexible_Controller_Login
152     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
153     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
154     # TODO: Alternatively, create variable in Variables which starts with http.
155     # Both TODOs would probably need to update every suite relying on current Variables.
156     SSHKeywords.Require_Python
157     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
158     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
159     # Calculate the timeout value based on how many routes are going to be pushed.
160     ${period} =    DateTime.Convert_Time    ${CHECK_PERIOD_PREFIX_COUNT_MANY_RRC}    result_format=number
161     ${timeout} =    BuiltIn.Evaluate    ${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
162     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
163     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_MANY_RRC} * (${COUNT_PREFIX_COUNT_MANY_RRC} * 2.0 / 10000 + ${period} * (${REPETITIONS_PREFIX_COUNT_MANY_RRC} + 1)) + 20
164     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${timeout}
165     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
166
167 Teardown_Everything
168     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
169     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
170     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
171     ConfigViaRestconf.Teardown_Config_Via_Restconf
172     RequestsLibrary.Delete_All_Sessions
173     SSHLibrary.Close_All_Connections
174
175 Check_Ipv4_Topology
176     [Arguments]    ${expected_count}=0
177     [Documentation]    Check and log the IPv4 topology count
178     ${current_time} =    DateTime.Get_Current_Date    exclude_millis=True
179     ${actual_count} =    PrefixCounting.Get_Ipv4_Topology_Count
180     BuiltIn.Log    ${current_time}: actual (expected) prefix count is ${actual_count} (${expected_count})    console=yes
181     BuiltIn.Should_Be_Equal_As_Strings    ${actual_count}    ${expected_count}
182
183 Check_File_For_Occurence
184     [Arguments]    ${file_name}    ${keyword}    ${value}=''    ${threshold}=1
185     [Documentation]    Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
186     ${output_log}=    SSHLibrary.Execute_Command    grep '${keyword}' '${file_name}' | grep -c '${value}'
187     ${count}=    Convert To Integer    ${output_log}
188     BuiltIn.Should_Be_True    ${count} >= ${threshold}
189     [Return]    ${count}