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