basic iBGP peers functional suite
[integration/test.git] / csit / suites / bgpcep / bgpuser / ibgp_peers_basic.robot
1 *** Settings ***
2 Documentation     Basic tests for iBGP peers.
3 ...
4 ...               Copyright (c) 2015-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 ...               Test suite performs basic iBGP functional test cases for
11 ...               BGP peers in different roles (iBGP, iBGP RR-client):
12 ...
13 ...               Test Case 1: Two iBGP RR-client peers introduce prefixes
14 ...               Expected result: controller forwards updates towards both peers
15 ...
16 ...               Test Case 2: Two iBGP peers: one RR client and one non-client introduces prefixes
17 ...               Expected result: controller forwards updates towards both peers
18 ...
19 ...               Test Case 3: Two iBGP RR non-client peers introduce prefixes
20 ...               Expected result: controller does not forward any update towards peers
21 ...
22 ...               For polices see: https://wiki.opendaylight.org/view/BGP_LS_PCEP:BGP
23 ...
24 ...               Covered bugs:
25 ...               Bug 4791 - BGPSessionImpl: Failed to send message Update logged even all UPDATE mesages received by iBGP peer
26 ...               Bug 4819 - No routes advertised to one of newly configured iBGP RR-client peer
27 Suite Setup       Setup_Everything
28 Suite Teardown    Teardown_Everything
29 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
30 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
31 Library           OperatingSystem
32 Library           RequestsLibrary
33 Library           DateTime
34 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
35 Variables         ${CURDIR}/../../../variables/Variables.py
36 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${ODL_SYSTEM_PROMPT}
37 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
38 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
39 Resource          ${CURDIR}/../../../libraries/FailFast.robot
40 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
41 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
42 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
43 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
44 Resource          ${CURDIR}/../../../libraries/Utils.robot
45 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
46
47 *** Variables ***
48 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
49 ${HOLDTIME}       180
50 ${BGP_PEER_LOG_LEVEL}    debug
51 ${CONTROLLER_LOG_LEVEL}    INFO
52 ${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
53 ${BGP_PEER1_IP}    127.0.0.1
54 ${BGP_PEER2_IP}    127.0.0.2
55 ${BGP_PEER1_FIRST_PREFIX_IP}    8.1.0.0
56 ${BGP_PEER2_FIRST_PREFIX_IP}    8.2.0.0
57 ${PREFIX_LEN}     28
58 ${BGP_PEER1_PREFIX_LEN}    ${PREFIX_LEN}
59 ${BGP_PEER2_PREFIX_LEN}    ${PREFIX_LEN}
60 ${PREFIX_COUNT}    3
61 ${BGP_PEER1_PREFIX_COUNT}    ${PREFIX_COUNT}
62 ${BGP_PEER2_PREFIX_COUNT}    ${PREFIX_COUNT}
63 ${BGP_PEER1_LOG_FILE}    bgp_peer1.log
64 ${BGP_PEER2_LOG_FILE}    bgp_peer2.log
65 ${BGP_PEER1_COMMAND}    python play.py --firstprefix ${BGP_PEER1_FIRST_PREFIX_IP} --prefixlen ${BGP_PEER1_PREFIX_LEN} --amount ${BGP_PEER1_PREFIX_COUNT} --myip=${BGP_PEER1_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_PEER_LOG_LEVEL} --logfile ${BGP_PEER1_LOG_FILE}
66 ${BGP_PEER2_COMMAND}    python play.py --firstprefix ${BGP_PEER2_FIRST_PREFIX_IP} --prefixlen ${BGP_PEER2_PREFIX_LEN} --amount ${BGP_PEER2_PREFIX_COUNT} --myip=${BGP_PEER2_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_PEER_LOG_LEVEL} --logfile ${BGP_PEER2_LOG_FILE}
67 ${BGP_PEER1_OPTIONS}    &>${BGP_PEER1_LOG_FILE}
68 ${BGP_PEER2_OPTIONS}    &>${BGP_PEER2_LOG_FILE}
69 ${DEFAULT_LOG_CHECK_TIMEOUT}    20s
70 ${DEFAULT_LOG_CHECK_PERIOD}    1s
71 ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    10s
72 ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    1s
73
74 *** Test Cases ***
75 TC1_Configure_Two_iBGP_Route_Reflector_Client_Peers
76     [Documentation]    Configure two iBGP peers as routing reflector clients.
77     [Tags]    critical
78     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1', 'IP': '${BGP_PEER1_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'rr-client', 'INITIATE': 'false'}
79     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
80     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2', 'IP': '${BGP_PEER2_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'rr-client', 'INITIATE': 'false'}
81     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
82     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
83     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
84     BuiltIn.Log    ${result}
85     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
86     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
87     BuiltIn.Log    ${result}
88
89 TC1_Connect_BGP_Peer1
90     [Documentation]    Connect BGP peer
91     [Tags]    critical
92     SSHLibrary.Switch Connection    bgp_peer1_console
93     Start_Console_Tool    ${BGP_PEER1_COMMAND}    ${BGP_PEER1_OPTIONS}
94     Read_And_Fail_If_Prompt_Is_Seen
95     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER1_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
96
97 TC1_Connect_BGP_Peer2
98     [Documentation]    Connect BGP peer
99     [Tags]    critical
100     SSHLibrary.Switch Connection    bgp_peer2_console
101     Start_Console_Tool    ${BGP_PEER2_COMMAND}    ${BGP_PEER2_OPTIONS}
102     Read_And_Fail_If_Prompt_Is_Seen
103     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER2_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
104
105 TC1_BGP_Peer1_Check_Log_For_Introduced_Prefixes
106     [Documentation]    Check incomming updates for new routes
107     [Tags]    critical
108     SSHLibrary.Switch Connection    bgp_peer1_console
109     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    nlri_prefix_received:    ${BGP_PEER2_PREFIX_COUNT}
110     Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    nlri_prefix_received: ${BGP_PEER2_FIRST_PREFIX_IP}/${BGP_PEER2_PREFIX_LEN}    1
111     Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    withdrawn_prefix_received:    0
112     [Teardown]    Report_Failure_Due_To_Bug    4819
113
114 TC1_BGP_Peer2_Check_Log_For_Introduced_Prefixes
115     [Documentation]    Check incomming updates for new routes
116     [Tags]    critical
117     SSHLibrary.Switch Connection    bgp_peer2_console
118     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    nlri_prefix_received:    ${BGP_PEER1_PREFIX_COUNT}
119     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    nlri_prefix_received: ${BGP_PEER1_FIRST_PREFIX_IP}/${BGP_PEER1_PREFIX_LEN}    1
120     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received:    0
121     [Teardown]    Report_Failure_Due_To_Bug    4819
122
123 TC1_Disconnect_BGP_Peer1
124     [Documentation]    Stop BGP peer & store logs
125     [Tags]    critical
126     SSHLibrary.Switch Connection    bgp_peer1_console
127     Stop_Console_Tool
128     Store_File_To_Workspace    ${BGP_PEER1_LOG_FILE}    tc1_${BGP_PEER1_LOG_FILE}
129
130 TC1_BGP_Peer2_Check_Log_For_Withdrawn_Prefixes
131     [Documentation]    Check incomming updates for withdrawn routes
132     [Tags]    critical
133     SSHLibrary.Switch Connection    bgp_peer2_console
134     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received:    ${BGP_PEER1_PREFIX_COUNT}
135     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received: ${BGP_PEER1_FIRST_PREFIX_IP}/${BGP_PEER1_PREFIX_LEN}    1
136     [Teardown]    Report_Failure_Due_To_Bug    4819
137
138 TC1_Disconnect_BGP_Peer2
139     [Documentation]    Stop BGP peer & store logs
140     [Tags]    critical
141     SSHLibrary.Switch Connection    bgp_peer2_console
142     Stop_Console_Tool
143     Store_File_To_Workspace    ${BGP_PEER2_LOG_FILE}    tc1_${BGP_PEER2_LOG_FILE}
144
145 TC_1_Check_for_Empty_IPv4_Topology
146     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Does_Not_Contain    prefix
147
148 TC1_Delete_BGP_Peers_Configuration
149     [Documentation]    Delete all previously configured BGP peers.
150     [Tags]    critical
151     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
152     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
153     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
154     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
155
156 TC2_Configure_One_iBGP_Route_Reflector_Client_And_One_iBGP_Non_Client
157     [Documentation]    Configure iBGP peers: 1st one as RR client, 2nd one as RR non-client.
158     [Tags]    critical
159     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1', 'IP': '${BGP_PEER1_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'rr-client', 'INITIATE': 'false'}
160     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
161     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2', 'IP': '${BGP_PEER2_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'ibgp', 'INITIATE': 'false'}
162     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
163     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
164     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
165     BuiltIn.Log    ${result}
166     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
167     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
168     BuiltIn.Log    ${result}
169
170 TC2_Connect_BGP_Peer1
171     [Documentation]    Connect BGP peer
172     [Tags]    critical
173     SSHLibrary.Switch Connection    bgp_peer1_console
174     Start_Console_Tool    ${BGP_PEER1_COMMAND}    ${BGP_PEER1_OPTIONS}
175     Read_And_Fail_If_Prompt_Is_Seen
176     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER1_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
177
178 TC2_Connect_BGP_Peer2
179     [Documentation]    Connect BGP peer
180     [Tags]    critical
181     SSHLibrary.Switch Connection    bgp_peer2_console
182     Start_Console_Tool    ${BGP_PEER2_COMMAND}    ${BGP_PEER2_OPTIONS}
183     Read_And_Fail_If_Prompt_Is_Seen
184     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER2_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
185
186 TC2_BGP_Peer1_Check_Log_For_Introduced_Prefixes
187     [Documentation]    Check incomming updates for new routes
188     [Tags]    critical
189     SSHLibrary.Switch Connection    bgp_peer1_console
190     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    nlri_prefix_received:    ${BGP_PEER2_PREFIX_COUNT}
191     Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    nlri_prefix_received: ${BGP_PEER2_FIRST_PREFIX_IP}/${BGP_PEER2_PREFIX_LEN}    1
192     Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    withdrawn_prefix_received:    0
193
194 TC2_BGP_Peer2_Check_Log_For_Introduced_Prefixes
195     [Documentation]    Check incomming updates for new routes
196     [Tags]    critical
197     SSHLibrary.Switch Connection    bgp_peer2_console
198     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    nlri_prefix_received:    ${BGP_PEER1_PREFIX_COUNT}
199     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    nlri_prefix_received: ${BGP_PEER1_FIRST_PREFIX_IP}/${BGP_PEER1_PREFIX_LEN}    1
200     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received:    0
201     [Teardown]    Report_Failure_Due_To_Bug    4791
202
203 TC2_Disconnect_BGP_Peer1
204     [Documentation]    Stop BGP peer & store logs
205     [Tags]    critical
206     SSHLibrary.Switch Connection    bgp_peer1_console
207     Stop_Console_Tool
208     Store_File_To_Workspace    ${BGP_PEER1_LOG_FILE}    tc2_${BGP_PEER1_LOG_FILE}
209
210 TC2_BGP_Peer2_Check_Log_For_Withdrawn_Prefixes
211     [Documentation]    Check incomming updates for withdrawn routes
212     [Tags]    critical
213     SSHLibrary.Switch Connection    bgp_peer2_console
214     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received:    ${BGP_PEER1_PREFIX_COUNT}
215     Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    withdrawn_prefix_received: ${BGP_PEER1_FIRST_PREFIX_IP}/${BGP_PEER1_PREFIX_LEN}    1
216
217 TC2_Disconnect_BGP_Peer2
218     [Documentation]    Stop BGP peer & store logs
219     [Tags]    critical
220     SSHLibrary.Switch Connection    bgp_peer2_console
221     Stop_Console_Tool
222     Store_File_To_Workspace    ${BGP_PEER2_LOG_FILE}    tc2_${BGP_PEER2_LOG_FILE}
223
224 TC_2_Check_for_Empty_IPv4_Topology
225     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Does_Not_Contain    prefix
226
227 TC2_Delete_BGP_Peers_Configuration
228     [Documentation]    Delete all previously configured BGP peers.
229     [Tags]    critical
230     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
231     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
232     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
233     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
234
235 TC3_Configure_Two_iBGP_Non_Client_Peers
236     [Documentation]    Configure iBGP peers: 1st one as RR client, 2nd one as RR non-client.
237     [Tags]    critical
238     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1', 'IP': '${BGP_PEER1_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'ibgp', 'INITIATE': 'false'}
239     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
240     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2', 'IP': '${BGP_PEER2_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}','PEER_ROLE': 'ibgp', 'INITIATE': 'false'}
241     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
242     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
243     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
244     BuiltIn.Log    ${result}
245     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
246     ${result}=    ConfigViaRestconf.Get_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
247     BuiltIn.Log    ${result}
248
249 TC3_Connect_BGP_Peer1
250     [Documentation]    Connect BGP peer
251     [Tags]    critical
252     SSHLibrary.Switch Connection    bgp_peer1_console
253     Start_Console_Tool    ${BGP_PEER1_COMMAND}    ${BGP_PEER1_OPTIONS}
254     Read_And_Fail_If_Prompt_Is_Seen
255     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER1_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
256
257 TC3_Connect_BGP_Peer2
258     [Documentation]    Connect BGP peer
259     [Tags]    critical
260     SSHLibrary.Switch Connection    bgp_peer2_console
261     Start_Console_Tool    ${BGP_PEER2_COMMAND}    ${BGP_PEER2_OPTIONS}
262     Read_And_Fail_If_Prompt_Is_Seen
263     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Content    {"prefix":"${BGP_PEER2_FIRST_PREFIX_IP}/${PREFIX_LEN}"}
264
265 TC3_BGP_Peer1_Check_Log_For_No_Updates
266     [Documentation]    Check for no updates received by iBGP peer No. 1
267     [Tags]    critical
268     SSHLibrary.Switch Connection    bgp_peer1_console
269     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_LOG_CHECK_TIMEOUT}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER1_LOG_FILE}    total_received_update_message_counter: 0    2
270
271 TC3_Disconnect_BGP_Peer1
272     [Documentation]    Stop BGP peer & store logs
273     [Tags]    critical
274     SSHLibrary.Switch Connection    bgp_peer1_console
275     Stop_Console_Tool
276     Store_File_To_Workspace    ${BGP_PEER1_LOG_FILE}    tc3_${BGP_PEER1_LOG_FILE}
277
278 TC3_BGP_Peer2_Check_Log_For_No_Updates
279     [Documentation]    Consequent check for no updates received by iBGP peer No. 2
280     [Tags]    critical
281     SSHLibrary.Switch Connection    bgp_peer2_console
282     ${log_check_timeout}=    DateTime.Convert_Time    ${DEFAULT_LOG_CHECK_TIMEOUT}    result_format=number
283     BuiltIn.Wait_Until_Keyword_Succeeds    ${log_check_timeout*2}    ${DEFAULT_LOG_CHECK_PERIOD}    Check_File_For_Word_Count    ${BGP_PEER2_LOG_FILE}    total_received_update_message_counter: 0    4
284
285 TC3_Disconnect_BGP_Peer2
286     [Documentation]    Stop BGP peer & store logs
287     [Tags]    critical
288     SSHLibrary.Switch Connection    bgp_peer2_console
289     Stop_Console_Tool
290     Store_File_To_Workspace    ${BGP_PEER2_LOG_FILE}    tc3_${BGP_PEER2_LOG_FILE}
291
292 TC_3_Check_for_Empty_IPv4_Topology
293     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEFAULT_TOPOLOGY_CHECK_TIMEOUT}    ${DEFAULT_TOPOLOGY_CHECK_PERIOD}    Check_Example_IPv4_Topology_Does_Not_Contain    prefix
294
295 TC3_Delete_BGP_Peers_Configuration
296     [Documentation]    Delete all previously configured BGP peers.
297     [Tags]    critical
298     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer1'}
299     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
300     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer2'}
301     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}ibgp_peers    ${template_as_string}
302
303 *** Keywords ***
304 Setup_Everything
305     [Documentation]    SSH-login to mininet machine, create HTTP session,
306     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
307     # TODO: Choose keywords used by more than one test suite to be placed in a common place.
308     SetupUtils.Setup_Utils_For_Setup_And_Teardown
309     SSHLibrary.Set_Default_Configuration    prompt=${ODL_SYSTEM_PROMPT}
310     SSHLibrary.Open_Connection    ${ODL_SYSTEM_IP}    alias=bgp_peer1_console
311     Utils.Flexible_Controller_Login
312     SSHLibrary.Open_Connection    ${ODL_SYSTEM_IP}    alias=bgp_peer2_console
313     Utils.Flexible_Controller_Login
314     SSHKeywords.Require_Python
315     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
316     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
317     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
318     ConfigViaRestconf.Setup_Config_Via_Restconf
319     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
320     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
321     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
322
323 Teardown_Everything
324     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
325     ...    Tear down imported Resources.
326     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
327     ConfigViaRestconf.Teardown_Config_Via_Restconf
328     RequestsLibrary.Delete_All_Sessions
329     SSHLibrary.Close_All_Connections
330
331 Start_Console_Tool
332     [Arguments]    ${command}    ${tool_opt}
333     [Documentation]    Start the tool ${command} ${tool_opt}
334     BuiltIn.Log    ${command}
335     ${output}=    SSHLibrary.Write    ${command} ${tool_opt}
336     BuiltIn.Log    ${output}
337
338 Wait_Until_Console_Tool_Finish
339     [Arguments]    ${timeout}
340     [Documentation]    Wait ${timeout} for the tool exit.
341     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
342
343 Stop_Console_Tool
344     [Documentation]    Stop the tool if still running.
345     Utils.Write_Bare_Ctrl_C
346     BuiltIn.Wait Until Keyword Succeeds    10s    1s    SSHLibrary.Read Until Prompt
347
348 Check_Example_IPv4_Topology_Content
349     [Arguments]    ${string_to_check}=${EMPTY}
350     [Documentation]    Check the example-ipv4-topology content for string
351     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
352     BuiltIn.Log    ${response.status_code}
353     BuiltIn.Log    ${response.text}
354     BuiltIn.Should_Contain    ${response.text}    ${string_to_check}
355
356 Check_Example_IPv4_Topology_Does_Not_Contain
357     [Arguments]    ${string_to_check}
358     [Documentation]    Check the example-ipv4-topology does not contain the string
359     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
360     BuiltIn.Log    ${response.status_code}
361     BuiltIn.Log    ${response.text}
362     BuiltIn.Should_Not_Contain    ${response.text}    ${string_to_check}
363
364 Read_And_Fail_If_Prompt_Is_Seen
365     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
366     ${passed}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${ODL_SYSTEM_PROMPT}' in *.    Read_Text_Before_Prompt
367     BuiltIn.Return_From_Keyword_If    ${passed}
368     BGPSpeaker.Dump_BGP_Speaker_Logs
369     Builtin.Fail    The prompt was seen but it was not expected yet
370
371 Read_Text_Before_Prompt
372     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
373     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
374     ${text}=    SSHLibrary.Read_Until_Prompt
375     BuiltIn.Log    ${text}
376
377 Store_File_To_Workspace
378     [Arguments]    ${source_file_name}    ${target_file_name}
379     [Documentation]    Store the ${source_file_name} to the workspace as ${target_file_name}.
380     ${output_log}=    SSHLibrary.Execute_Command    cat ${source_file_name}
381     BuiltIn.Log    ${output_log}
382     Create File    ${target_file_name}    ${output_log}
383
384 Check_File_For_Word_Count
385     [Arguments]    ${file_name}    ${word}    ${expected_count}
386     [Documentation]    Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
387     ${output_log}=    SSHLibrary.Execute_Command    grep -o '${word}' ${file_name} | wc -l
388     BuiltIn.Log    ${output_log}
389     BuiltIn.Should_Be_Equal_As_Strings    ${output_log}    ${expected_count}
390
391 Check_File_For_Occurence
392     [Arguments]    ${file_name}    ${keyword}    ${value}=''
393     [Documentation]    Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
394     ${output_log}=    SSHLibrary.Execute_Command    grep '${keyword}' ${file_name} | grep -c ${value}
395     ${count}=    Convert To Integer    ${output_log}
396     [Return]    ${count}