4f2b8ab7615e3ab625e5a4292f2c3219e690c42a
[integration/test.git] / csit / suites / bgpcep / bgpingest / singlepeer_changecount.robot
1 *** Settings ***
2 Documentation     BGP performance of ingesting from 1 iBGP peer, data change counter used.
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 ...
11 ...               This suite uses play.py as single iBGP peer.
12 ...               The suite only looks at example-ipv4-topology, so RIB is not examined.
13 ...
14 ...               This suite requires odl-bgpcep-data-change-counter to be installed so
15 ...               make sure it is added to "install-features" of any jobs that are going
16 ...               to invoke it.
17 ...
18 ...               The suite consists of two halves, differing on which side initiates BGP connection.
19 ...               Data change counter is a lightweight way to detect "work is being done".
20 ...               WaitUtils provide a nice Keyword to wait for stability, but it needs
21 ...               initial value, that is why Store_Change_Count appears just before work-inducing action.
22 ...               The time for Wait_For_Stable_* cases to finish is the main performance metric.
23 ...               After waiting for stability is done, full check on number of prefixes present is performed.
24 ...
25 ...               TODO: Currently, if a bug causes zero increase of data changes,
26 ...               affected test cases will wait for max time. Reconsider.
27 ...               If zero increase is allowed as stable, higher number of repetitions should be required.
28 ...
29 ...               Additionally this test suite is not compatible with Helium and Hydrogen
30 ...               releases as they don't include data change counter feature.
31 ...               Use the other version of the suite (singlepeer_prefixcount.robot) to test them.
32 Suite Setup       Setup_Everything
33 Suite Teardown    Teardown_Everything
34 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
35 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
36 Library           SSHLibrary    timeout=10s
37 Library           RequestsLibrary
38 Variables         ${CURDIR}/../../../variables/Variables.py
39 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
40 Resource          ${CURDIR}/../../../libraries/ChangeCounter.robot
41 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
42 Resource          ${CURDIR}/../../../libraries/FailFast.robot
43 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
44 Resource          ${CURDIR}/../../../libraries/PrefixCounting.robot
45 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
46
47 *** Variables ***
48 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
49 ${HOLDTIME}       180
50 ${HOLDTIME_CHANGE_COUNT}    ${HOLDTIME}
51 ${COUNT}          1000000
52 ${COUNT_CHANGE_COUNT}    ${COUNT}
53 ${CHECK_PERIOD}    1
54 ${CHECK_PERIOD_CHANGE_COUNT}    ${CHECK_PERIOD}
55 ${REPETITIONS_CHANGE_COUNT}    1
56 # TODO: Option names can be better.
57 ${last_change_count}    -1
58
59 *** Test Cases ***
60 Check_For_Empty_Ipv4_Topology_Before_Talking
61     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
62     [Tags]    critical
63     # TODO: Choose which tags to assign and make sure they are assigned correctly.
64     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
65
66 Reconfigure_ODL_To_Accept_Connection
67     [Documentation]    Configure BGP peer module with initiate-connection set to false.
68     ${template_as_string} =    BuiltIn.Set_Variable    {'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
69     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
70
71 Wait_For_Data_Change_Counter_Ready
72     [Documentation]    Data change counter might have been slower to start than ipv4 topology, wait for it.
73     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    ChangeCounter.Get_Change_Count
74
75 Reconfigure_Data_Change_Counter
76     [Documentation]    Configure data change counter to count transactions in example-ipv4-topology instead of example-linkstate-topology.
77     ChangeCounter.Reconfigure_Topology_Name    example-ipv4-topology
78
79 Start_Talking_BGP_speaker
80     [Documentation]    Start Python speaker to connect to ODL.
81     Store_Change_Count
82     # Myport value is needed for checking whether connection at precise port was established.
83     BGPSpeaker.Start_BGP_speaker    --amount ${COUNT_CHANGE_COUNT} --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT}
84
85 Wait_For_Stable_Talking_Ipv4_Topology
86     [Documentation]    Wait until example-ipv4-topology becomes stable. This is done by checking the change counter.
87     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
88
89 Check_Talking_Ipv4_Topology_Count
90     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
91     [Tags]    critical
92     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT}
93
94 Kill_Talking_BGP_Speaker
95     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
96     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
97     Store_Change_Count
98     BGPSpeaker.Kill_BGP_Speaker
99     FailFast.Do_Not_Fail_Fast_From_Now_On
100     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
101     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
102
103 Wait_For_Stable_Ipv4_Topology_After_Talking
104     [Documentation]    Wait until example-ipv4-topology becomes stable again.
105     [Tags]    critical
106     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
107
108 Check_For_Empty_Ipv4_Topology_After_Talking
109     [Documentation]    Example-ipv4-topology should be empty now.
110     [Tags]    critical
111     PrefixCounting.Check_Ipv4_Topology_Is_Empty
112
113 Start_Listening_BGP_Speaker
114     [Documentation]    Start Python speaker in listening mode.
115     BGPSpeaker.Start_BGP_speaker    --amount ${COUNT_CHANGE_COUNT} --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP}
116
117 Reconfigure_ODL_To_Initiate_Connection
118     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
119     Store_Change_Count
120     ${template_as_string} =    BuiltIn.Set_Variable    {'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
121     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
122
123 Wait_For_Stable_Listening_Ipv4_Topology
124     [Documentation]    Wait until example-ipv4-topology becomes stable.
125     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
126
127 Check_Listening_Ipv4_Topology_Count
128     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
129     [Tags]    critical
130     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT}
131
132 Kill_Listening_BGP_Speaker
133     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
134     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
135     Store_Change_Count
136     BGPSpeaker.Kill_BGP_Speaker
137     FailFast.Do_Not_Fail_Fast_From_Now_On
138     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
139     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
140
141 Wait_For_Stable_Ipv4_Topology_After_Listening
142     [Documentation]    Wait until example-ipv4-topology becomes stable again.
143     [Tags]    critical
144     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
145
146 Check_For_Empty_Ipv4_Topology_After_Listening
147     [Documentation]    Example-ipv4-topology should be empty now.
148     [Tags]    critical
149     PrefixCounting.Check_Ipv4_Topology_Is_Empty
150
151 Restore_Data_Change_Counter_Configuration
152     [Documentation]    Configure data change counter back to count transactions affecting example-linkstate-topology.
153     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
154     ChangeCounter.Reconfigure_Topology_Name    example-linkstate-topology
155
156 Delete_Bgp_Peer_Configuration
157     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
158     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
159     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer
160
161 *** Keywords ***
162 Setup_Everything
163     [Documentation]    Setup imported resources, SSH-login to mininet machine,
164     ...    create HTTP session, put Python tool to mininet machine.
165     SetupUtils.Setup_Utils_For_Setup_And_Teardown
166     ConfigViaRestconf.Setup_Config_Via_Restconf
167     ChangeCounter.CC_Setup
168     PrefixCounting.PC_Setup
169     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
170     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
171     Utils.Flexible_Mininet_Login
172     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
173     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
174     # TODO: Alternatively, create variable in Variables which starts with http.
175     # Both TODOs would probably need to update every suite relying on current Variables.
176     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
177     # Calculate the timeout value based on how many routes are going to be pushed
178     ${count} =    Builtin.Convert_To_Integer    ${COUNT_CHANGE_COUNT}
179     # TODO: Replace 20 with some formula from period and repetitions.
180     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${count*3/10000+20}
181     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3/4}
182
183 Teardown_Everything
184     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
185     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
186     ConfigViaRestconf.Teardown_Config_Via_Restconf
187     RequestsLibrary.Delete_All_Sessions
188     SSHLibrary.Close_All_Connections
189
190 Store_Change_Count
191     [Documentation]    Get the count of changes from BGP change counter. Ignore error or store the value.
192     ${status}    ${count} =    BuiltIn.Run_Keyword_And_Ignore_Error    ChangeCounter.Get_Change_Count
193     BuiltIn.Run_Keyword_If    '${status}' == 'PASS'    BuiltIn.Set_Suite_Variable    ${last_change_count}    ${count}