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