Update Robot Framework format - step 3
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 100_bgp_functional_graceful_restart.robot
1 *** Settings ***
2 Documentation       Functional test for bgp - graceful-restart
3 ...
4 ...                 Copyright (c) 2018 AT&T Intellectual Property. 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 distbmution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9
10 Library             ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8001    WITH NAME    BgpRpcClient1
11 Library             ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8002    WITH NAME    BgpRpcClient2
12 Library             OperatingSystem
13 Library             RequestsLibrary
14 Library             SSHLibrary
15 Library             String
16 Resource            ../../../libraries/BGPcliKeywords.robot
17 Resource            ../../../libraries/BgpOperations.robot
18 Resource            ../../../libraries/BGPSpeaker.robot
19 Resource            ../../../libraries/SetupUtils.robot
20 Resource            ../../../libraries/SSHKeywords.robot
21 Resource            ../../../libraries/TemplatedRequests.robot
22 Resource            ../../../variables/Variables.robot
23
24 Suite Setup         Start_Suite
25 Suite Teardown      Stop_Suite
26 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
27
28
29 *** Variables ***
30 ${HOLDTIME}             180
31 ${RIB_NAME}             example-bgp-rib
32 ${CONFIG_SESSION}       config-session
33 ${PLAY_SCRIPT}          ${CURDIR}/../../../../tools/fastbgp/play.py
34 ${GR_FOLDER}            ${CURDIR}/../../../variables/bgpfunctional/graceful_restart
35 ${PEER1_AS}             65000
36 ${PEER2_AS}             65001
37 ${PEER1_IP}             127.0.0.2
38 ${PEER2_IP}             127.0.0.3
39 ${PEER1_PORT}           8001
40 ${PEER2_PORT}           8002
41 ${FIRST_PREFIX}         8.1.0.0
42 ${SECOND_PREFIX}        8.2.0.0
43 ${NEXT_HOP}             1.1.1.1
44 ${PREFIX_LEN}           28
45
46
47 *** Test Cases ***
48 Verify_Empty_Rib_After_Graceful_Restart_Timer_Expired
49     [Documentation]    Prerequistes: One peer with one route running.
50     ...    Verify peer route is present in odl's loc-rib.
51     ...    Kill bgp speaker. After graceful-restart restart-time runs out, route must not be
52     ...    present in odl's loc-rib.
53     [Setup]    Setup_TC0
54     Verify_Routes    dir=ipv4_1
55     Kill_Talking_BGP_Speakers    log_name=gr_tc0.out
56     Verify_Routes    retry=10x
57     [Teardown]    Teardown_TC    gr_tc0.out
58
59 Verify_Route_Was_Kept_After_Peer_Restart
60     [Documentation]    Prerequistes: One peer with one route was just killed.
61     ...    Restart killed peer with the same route.
62     ...    Verify that route is still present in loc-rib.
63     ...    Verify odl advertised end-of-rib message with appropriate flags.
64     [Setup]    Setup_TC1
65     Start_Bgp_Peer    grace=3    log_name=gr_tc1.out
66     Verify_Routes    dir=ipv4_1
67     Verify_Hex_Message    tc1
68     [Teardown]    Teardown_TC    gr_tc1.out
69
70 Verify_Change_In_Amount_Of_Routes_After_Peer_Restart
71     [Documentation]    Prerequistes: One peer with two routes was just killed.
72     ...    Restart killed peer with just one route. Verify only one route is present in loc-rib.
73     [Setup]    Setup_TC2
74     Start_Bgp_Peer    grace=2    log_name=gr_tc2.out
75     Verify_Routes    dir=ipv4_1
76     [Teardown]    Teardown_TC    gr_tc2.out
77
78 Verify_Odl_Advertisment_Of_New_Route_After_Peer_Restart
79     [Documentation]    Prerequistes: One peer with one route, was just killed. Second is still running with one route.
80     ...    Restart killed peer with two routes. Verify that two routes from restarted peer and one route
81     ...    from second peer is in loc-rib. Verify odl advertised update message to second peer with new route
82     ...    and appropriate end-of-rib message.
83     [Setup]    Setup_TC3
84     Start_Bgp_Peer    amount=2    grace=2
85     Verify_Hex_Message    tc3
86     Verify_Routes    dir=ipv4_2_1
87     [Teardown]    Teardown_TC    gr_tc3.out
88
89 Verify_Odl_Kept_Route_After_Odl_Restart
90     [Documentation]    Prerequistes: One peer with one route running.
91     ...    Graceful-restart odl. Close tcp connection from peer side and reopen it.
92     ...    Send end-of-rib with all 0 flags, and expect the route still in loc-rib.
93     ...    Verify end-of-rib message from odl with all flags set to 1.
94     [Setup]    Setup_TC_PG
95     Post_Graceful_Restart
96     Kill_Talking_BGP_Speakers
97     Start_Bgp_Peer    grace=0    log_name=gr_tc4.out
98     Verify_Hex_Message    tc4
99     Verify_Routes    dir=ipv4_1
100     [Teardown]    Teardown_TC    gr_tc4.out
101
102 Verify_Odl_Accepted_Routes_After_Odl_Restart
103     [Documentation]    Prerequistes: One peer with one route running.
104     ...    Graceful-restart odl. Close tcp connection from peer side and reopen it.
105     ...    Start bgp peer with two routes, and send end-of-rib message with ipv4 flag
106     ...    set to 1. Verify loc-rib and end-of-rib message from odl.
107     [Setup]    Setup_TC_PG
108     Post_Graceful_Restart
109     Kill_Talking_BGP_Speakers
110     Start_Bgp_Peer    amount=2    grace=2    log_name=gr_tc5.out
111     Verify_Hex_Message    tc5
112     Verify_Routes    dir=ipv4_2
113     [Teardown]    Teardown_TC    gr_tc5.out
114
115 Verify_No_Ipv6_Route_Immediately_After_Peer_Was_Killed
116     [Documentation]    Prerequistes: One peer with one ipv4 route and one ipv6 route running.
117     ...    Kill the speaker. And Verify that there is ipv4 route still present, but ipv6 rib should be empty
118     ...    because it had no graceful-restart ability configured.
119     [Setup]    Setup_TC6
120     Kill_Talking_BGP_Speakers
121     Verify_Routes    dir=ipv4_1
122     Verify_Routes    dir=empty_ipv6_route    interval=1s
123     [Teardown]    Teardown_TC    gr_tc6.out
124
125
126 *** Keywords ***
127 Start_Suite
128     [Documentation]    Initialize SetupUtils. Suite setup keyword.
129     ...    Copies play.py script for peer simulation onto ODL VM.
130     ...    Configures peers on odl with graceful-restart enabled.
131     SetupUtils.Setup_Utils_For_Setup_And_Teardown
132     SSHLibrary.Open Connection    ${ODL_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
133     SSHKeywords.Flexible_Controller_Login
134     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
135     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
136     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
137     Configure_BGP_Peers
138
139 Stop_Suite
140     [Documentation]    Delete peer configuration, close all remaining ssh and http sessions.
141     Delete_Bgp_Peers_Configuration
142     SSHLibrary.Close_All_Connections
143     RequestsLibrary.Delete_All_Sessions
144
145 Setup_TC0
146     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
147     ...    Start one bgp peer with one routes.
148     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
149     Start_Bgp_Peer    log_name=gr_tc0.out
150
151 Setup_TC1
152     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
153     ...    Start one bgp peer with one routes, and verify routes is present in loc-rib.
154     ...    Kill bgp speaker (effectively simulating graceful-restart)
155     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
156     Start_Bgp_Peer
157     Verify_Routes    dir=ipv4_1
158     Kill_Talking_BGP_Speakers
159
160 Setup_TC2
161     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
162     ...    Start one bgp peer with two routes, and verify routes are present in loc-rib.
163     ...    Kill bgp speaker (effectively simulating graceful-restart)
164     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
165     Start_Bgp_Peer    amount=2
166     Verify_Routes    dir=ipv4_2
167     Kill_Talking_BGP_Speakers
168
169 Setup_TC3
170     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
171     ...    Start two bgp peers, each with their default values, and verify their respective routes
172     ...    are present in loc-rib, than kill the first bgp speaker (effectively simulating graceful-restart)
173     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
174     Start_Bgp_Peer
175     ...    prefix=${SECOND_PREFIX}
176     ...    myip=${PEER2_IP}
177     ...    port=${PEER2_PORT}
178     ...    as_number=${PEER2_AS}
179     ...    log_name=gr_tc3.out
180     Start_Bgp_Peer    multiple=${EMPTY}
181     Verify_Routes    dir=ipv4_1_1
182     BGPSpeaker.Kill_BGP_Speaker
183
184 Setup_TC_PG
185     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
186     ...    Start one bgp peer, and verify it's route is present in loc-rib.
187     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
188     Start_Bgp_Peer
189     Verify_Routes    dir=ipv4_1
190
191 Setup_TC6
192     [Documentation]    Log Test Case name into karaf log, and make sure it wont fail other TC's.
193     ...    Start one bgp peer with one routes, and send ipv6 route without gr configured.
194     SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
195     Start_Bgp_Peer    log_name=gr_tc6.out    ipv6=${SPACE}--ipv6
196     ${announce_hex} =    OperatingSystem.Get_File    ${GR_FOLDER}${/}ipv6.hex
197     ${announce_hex} =    String.Remove_String    ${announce_hex}    \n
198     Verify_Routes    dir=ipv4_1
199     BgpRpcClient1.play_send    ${announce_hex}
200     Verify_Routes    dir=ipv6_1
201
202 Teardown_TC
203     [Documentation]    In case Test Case failed to close Python Speakers, we close them.
204     ...    Wait until there are no routes present in loc-rib.
205     [Arguments]    ${log_name}=play.py.out
206     Kill_Talking_BGP_Speakers    ${log_name}
207     Verify_Routes    dir=empty_route    retry=10x
208     Verify_Routes    dir=empty_ipv6_route    interval=1s
209
210 Verify_Routes
211     [Documentation]    Verify route based on how many routes are present in rib.
212     [Arguments]    ${dir}=empty_route    ${retry}=5x    ${interval}=3s
213     BuiltIn.Wait_Until_Keyword_Succeeds
214     ...    ${retry}
215     ...    ${interval}
216     ...    TemplatedRequests.Get_As_Json_Templated
217     ...    ${GR_FOLDER}${/}${dir}
218     ...    session=${CONFIG_SESSION}
219     ...    verify=True
220
221 Verify_Hex_Message
222     [Documentation]    Verify hex message advertised from odl.
223     [Arguments]    ${file_dir}    ${peer}=${PEER1_IP}    ${file_name}=${file_dir}.hex
224     ${expected} =    TemplatedRequests.Resolve_Text_From_Template_File    ${GR_FOLDER}${/}${file_dir}    ${file_name}
225     ${actual} =    BuiltIn.Wait_Until_Keyword_Succeeds    5x    3s    Get_Hex_Message    peer=${peer}
226     BgpOperations.Verify_Two_Hex_Messages_Are_Equal    ${expected}    ${actual}
227
228 Get_Hex_Message
229     [Documentation]    Gets open message in case of first peer, and update message in case of second peer.
230     [Arguments]    ${peer}=${PEER1_IP}
231     IF    "${peer}" == "${PEER1_IP}"
232         ${hex} =    BgpRpcClient1.play_get    what=open
233     ELSE
234         ${hex} =    BgpRpcClient2.play_get
235     END
236     BuiltIn.Should_Not_Be_Equal    ${hex}    ${EMPTY}
237     RETURN    ${hex}
238
239 Start_Bgp_Peer
240     [Documentation]    Starts bgp peer.
241     [Arguments]    ${prefix}=${FIRST_PREFIX}    ${amount}=1    ${myip}=${PEER1_IP}    ${port}=${PEER1_PORT}    ${as_number}=${PEER1_AS}    ${grace}=0
242     ...    ${log_name}=play.py.out    ${multiple}=&    ${ipv6}=${EMPTY}
243     ${command} =    BuiltIn.Set_Variable
244     ...    python3 play.py${ipv6} --firstprefix ${prefix} --prefixlen ${PREFIX_LEN} --amount ${amount} --myip ${myip} --myport ${BGP_TOOL_PORT} --peerip ${ODL_SYSTEM_IP} --peerport ${ODL_BGP_PORT} --port ${port} --usepeerip --nexthop ${NEXT_HOP} --asnumber ${as_number} --debug --grace ${grace} --wfr 1 &> ${log_name} ${multiple}
245     BuiltIn.Log    ${command}
246     ${output} =    SSHLibrary.Write    ${command}
247
248 Kill_Talking_BGP_Speakers
249     [Documentation]    Save play.py log into workspace, attempt to dump speaker logs into robot log.
250     ...    Abort all Python speakers.
251     [Arguments]    ${log_name}=play.py.out
252     BuiltIn.Run_Keyword_And_Ignore_Error    BGPcliKeywords.Store_File_To_Workspace    ${log_name}    ${log_name}.log
253     BuiltIn.Run_Keyword_And_Ignore_Error    BGPSpeaker.Dump_BGP_Speaker_Logs
254     BGPSpeaker.Kill_All_BGP_Speakers
255
256 Configure_BGP_Peers
257     [Documentation]    Configure two eBGP peers with graceful-restart enabled
258     [Arguments]    ${folder}=${EMPTY}
259     &{mapping} =    BuiltIn.Create_Dictionary
260     ...    IP=${PEER1_IP}
261     ...    HOLDTIME=${HOLDTIME}
262     ...    PEER_PORT=${BGP_TOOL_PORT}
263     ...    AS_NUMBER=${PEER1_AS}
264     ...    BGP_RIB=${RIB_NAME}
265     TemplatedRequests.Put_As_Xml_Templated
266     ...    ${GR_FOLDER}${/}${folder}peers
267     ...    mapping=${mapping}
268     ...    session=${CONFIG_SESSION}
269     &{mapping} =    BuiltIn.Create_Dictionary
270     ...    IP=${PEER2_IP}
271     ...    HOLDTIME=${HOLDTIME}
272     ...    PEER_PORT=${BGP_TOOL_PORT}
273     ...    AS_NUMBER=${PEER2_AS}
274     ...    BGP_RIB=${RIB_NAME}
275     TemplatedRequests.Put_As_Xml_Templated
276     ...    ${GR_FOLDER}${/}${folder}peers
277     ...    mapping=${mapping}
278     ...    session=${CONFIG_SESSION}
279
280 Delete_Bgp_Peers_Configuration
281     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
282     &{mapping} =    BuiltIn.Create_Dictionary    IP=${PEER1_IP}    BGP_RIB=${RIB_NAME}
283     TemplatedRequests.Delete_Templated    ${GR_FOLDER}${/}peers    mapping=${mapping}    session=${CONFIG_SESSION}
284     &{mapping} =    BuiltIn.Create_Dictionary    IP=${PEER2_IP}    BGP_RIB=${RIB_NAME}
285     TemplatedRequests.Delete_Templated    ${GR_FOLDER}${/}peers    mapping=${mapping}    session=${CONFIG_SESSION}
286
287 Post_Graceful_Restart
288     [Documentation]    Post rpc to odl, effectively restarting it.
289     [Arguments]    ${ip}=${PEER1_IP}
290     &{mapping} =    BuiltIn.Create_Dictionary    IP=${ip}    BGP_RIB=${RIB_NAME}
291     TemplatedRequests.Post_As_Xml_Templated
292     ...    ${GR_FOLDER}${/}restart
293     ...    mapping=${mapping}
294     ...    session=${CONFIG_SESSION}