creating ExaBgpLib and refactoring bgp functional suites to use it
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 030_bgp_functional_evpn.robot
1 *** Settings ***
2 Documentation     Functional test for bgp - evpn
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 tests advertising and receiveing routes with evpn content.
11 ...               It uses play.py and odl as bgp peers. Routes advertized from odl
12 ...               are configured via application peer. Routes advertised from play.py are
13 ...               stored in *.hex files. These files are used also as expected data which
14 ...               is recevied from odl.
15 Suite Setup       Start_Suite
16 Suite Teardown    Stop_Suite
17 Test Setup        Run Keywords    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
18 ...               AND    Verify Test Preconditions
19 Library           RequestsLibrary
20 Library           SSHLibrary
21 Variables         ${CURDIR}/../../../variables/Variables.py
22 Resource          ${CURDIR}/../../../libraries/Utils.robot
23 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
24 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
25 Library           ${CURDIR}/../../../libraries/BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
26 Resource          ${CURDIR}/../../../libraries/BGPcliKeywords.robot
27 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
28 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
29
30 *** Variables ***
31 ${HOLDTIME}       180
32 ${DEVICE_NAME}    controller-config
33 ${BGP_PEER_NAME}    example-bgp-peer
34 ${RIB_INSTANCE}    example-bgp-rib
35 ${APP_PEER_NAME}    example-bgp-peer-app
36 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpfunctional
37 ${DEFAUTL_RPC_CFG}    exa.cfg
38 ${CONFIG_SESSION}    config-session
39 ${EVPN_VARIABLES_DIR}    ${CURDIR}/../../../variables/bgpfunctional/l2vpn_evpn
40 ${BGP_TOOL_LOG_LEVEL}    debug
41 ${PLAY_SCRIPT}    ${CURDIR}/../../../../tools/fastbgp/play.py
42 ${EVPN_CONF_URL}    /restconf/config/bgp-rib:application-rib/example-app-rib/tables/odl-bgp-evpn:l2vpn-address-family/odl-bgp-evpn:evpn-subsequent-address-family/odl-bgp-evpn:evpn-routes/
43 ${EVPN_RIB_OPER_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/odl-bgp-evpn:l2vpn-address-family/odl-bgp-evpn:evpn-subsequent-address-family/odl-bgp-evpn:evpn-routes
44 ${LOC_RIB_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/odl-bgp-evpn:l2vpn-address-family/odl-bgp-evpn:evpn-subsequent-address-family/odl-bgp-evpn:evpn-routes
45
46 *** Test Cases ***
47 Configure_App_Peer
48     [Documentation]    Configures bgp application peer
49     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
50     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}    RIB_INSTANCE_NAME=${RIB_INSTANCE}    APP_PEER_ID=${ODL_SYSTEM_IP}
51     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
52
53 Reconfigure_ODL_To_Accept_Connection
54     [Documentation]    Configures BGP peer module with initiate-connection set to false.
55     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
56     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
57     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}
58     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
59
60 Start_Bgp_Peer
61     [Documentation]    Start Python speaker to connect to ODL. We need to do WUKS until odl really starts to accept incomming bgp connection. The failure happens if the incomming connection comes too quickly after configuring the peer in the previous test case.
62     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
63     BuiltIn.Wait_Until_Keyword_Succeeds    3x    1s    Start Bgp Peer
64
65 Odl_To_Play_route_es_arb
66     [Template]    Odl_To_Play_Template
67     route_es_arb
68
69 Play_To_Odl_route_es_arb
70     [Template]    Play_To_Odl_Template
71     route_es_arb
72
73 Odl_To_Play_route_es_as
74     [Template]    Odl_To_Play_Template
75     route_es_as
76
77 Play_To_Odl_route_es_as
78     [Template]    Play_To_Odl_Template
79     route_es_as
80
81 Odl_To_Play_route_es_lacp
82     [Template]    Odl_To_Play_Template
83     route_es_lacp
84
85 Play_To_Odl_route_es_lacp
86     [Template]    Play_To_Odl_Template
87     route_es_lacp
88
89 Odl_To_Play_route_es_lan
90     [Template]    Odl_To_Play_Template
91     route_es_lan
92
93 Play_To_Odl_route_es_lan
94     [Template]    Play_To_Odl_Template
95     route_es_lan
96
97 Odl_To_Play_route_es_mac
98     [Template]    Odl_To_Play_Template
99     route_es_mac
100
101 Play_To_Odl_route_es_mac
102     [Template]    Play_To_Odl_Template
103     route_es_mac
104
105 Odl_To_Play_route_es_rou
106     [Template]    Odl_To_Play_Template
107     route_es_rou
108
109 Play_To_Odl_route_es_rou
110     [Template]    Play_To_Odl_Template
111     route_es_rou
112
113 Odl_To_Play_route_eth_arb
114     [Template]    Odl_To_Play_Template
115     route_eth_arb
116
117 Play_To_Odl_route_eth_arb
118     [Template]    Play_To_Odl_Template
119     route_eth_arb
120
121 Odl_To_Play_route_eth_as
122     [Template]    Odl_To_Play_Template
123     route_eth_as
124
125 Play_To_Odl_route_eth_as
126     [Template]    Play_To_Odl_Template
127     route_eth_as
128
129 Odl_To_Play_route_eth_lacp
130     [Template]    Odl_To_Play_Template
131     route_eth_lacp
132
133 Play_To_Odl_route_eth_lacp
134     [Template]    Play_To_Odl_Template
135     route_eth_lacp
136
137 Odl_To_Play_route_eth_lacp_extdef
138     [Template]    Odl_To_Play_Template
139     route_eth_lacp_extdef
140
141 Play_To_Odl_route_eth_lacp_extdef
142     [Template]    Play_To_Odl_Template
143     route_eth_lacp_extdef
144
145 Odl_To_Play_route_eth_lacp_extesilab
146     [Template]    Odl_To_Play_Template
147     route_eth_lacp_extesilab
148
149 Play_To_Odl_route_eth_lacp_extesilab
150     [Template]    Play_To_Odl_Template
151     route_eth_lacp_extesilab
152
153 Odl_To_Play_route_eth_lacp_extesr
154     [Template]    Odl_To_Play_Template
155     route_eth_lacp_extesr
156
157 Play_To_Odl_route_eth_lacp_extesr
158     [Template]    Play_To_Odl_Template
159     route_eth_lacp_extesr
160
161 Odl_To_Play_route_eth_lacp_extl2
162     [Template]    Odl_To_Play_Template
163     route_eth_lacp_extl2
164
165 Play_To_Odl_route_eth_lacp_extl2
166     [Template]    Play_To_Odl_Template
167     route_eth_lacp_extl2
168
169 Odl_To_Play_route_eth_lacp_extmac
170     [Template]    Odl_To_Play_Template
171     route_eth_lacp_extmac
172
173 Play_To_Odl_route_eth_lacp_extmac
174     [Template]    Play_To_Odl_Template
175     route_eth_lacp_extmac
176
177 Odl_To_Play_route_eth_lan
178     [Template]    Odl_To_Play_Template
179     route_eth_lan
180
181 Play_To_Odl_route_eth_lan
182     [Template]    Play_To_Odl_Template
183     route_eth_lan
184
185 Odl_To_Play_route_eth_mac
186     [Template]    Odl_To_Play_Template
187     route_eth_mac
188
189 Play_To_Odl_route_eth_mac
190     [Template]    Play_To_Odl_Template
191     route_eth_mac
192
193 Odl_To_Play_route_eth_rou
194     [Template]    Odl_To_Play_Template
195     route_eth_rou
196
197 Play_To_Odl_route_eth_rou
198     [Template]    Play_To_Odl_Template
199     route_eth_rou
200
201 Odl_To_Play_route_inc_arb
202     [Template]    Odl_To_Play_Template
203     route_inc_arb
204
205 Play_To_Odl_route_inc_arb
206     [Template]    Play_To_Odl_Template
207     route_inc_arb
208
209 Odl_To_Play_route_inc_as
210     [Template]    Odl_To_Play_Template
211     route_inc_as
212
213 Play_To_Odl_route_inc_as
214     [Template]    Play_To_Odl_Template
215     route_inc_as
216
217 Odl_To_Play_route_inc_lacp
218     [Template]    Odl_To_Play_Template
219     route_inc_lacp
220
221 Play_To_Odl_route_inc_lacp
222     [Template]    Play_To_Odl_Template
223     route_inc_lacp
224
225 Odl_To_Play_route_inc_lan
226     [Template]    Odl_To_Play_Template
227     route_inc_lan
228
229 Play_To_Odl_route_inc_lan
230     [Template]    Play_To_Odl_Template
231     route_inc_lan
232
233 Odl_To_Play_route_inc_mac
234     [Template]    Odl_To_Play_Template
235     route_inc_mac
236
237 Play_To_Odl_route_inc_mac
238     [Template]    Play_To_Odl_Template
239     route_inc_mac
240
241 Odl_To_Play_route_inc_rou
242     [Template]    Odl_To_Play_Template
243     route_inc_rou
244
245 Play_To_Odl_route_inc_rou
246     [Template]    Play_To_Odl_Template
247     route_inc_rou
248
249 Odl_To_Play_route_mac_arb
250     [Template]    Odl_To_Play_Template
251     route_mac_arb
252
253 Play_To_Odl_route_mac_arb
254     [Template]    Play_To_Odl_Template
255     route_mac_arb
256
257 Odl_To_Play_route_mac_as
258     [Template]    Odl_To_Play_Template
259     route_mac_as
260
261 Play_To_Odl_route_mac_as
262     [Template]    Play_To_Odl_Template
263     route_mac_as
264
265 Odl_To_Play_route_mac_lacp
266     [Template]    Odl_To_Play_Template
267     route_mac_lacp
268
269 Play_To_Odl_route_mac_lacp
270     [Template]    Play_To_Odl_Template
271     route_mac_lacp
272
273 Odl_To_Play_route_mac_lan
274     [Template]    Odl_To_Play_Template
275     route_mac_lan
276
277 Play_To_Odl_route_mac_lan
278     [Template]    Play_To_Odl_Template
279     route_mac_lan
280
281 Odl_To_Play_route_mac_mac
282     [Template]    Odl_To_Play_Template
283     route_mac_mac
284
285 Play_To_Odl_route_mac_mac
286     [Template]    Play_To_Odl_Template
287     route_mac_mac
288
289 Odl_To_Play_route_mac_rou
290     [Template]    Odl_To_Play_Template
291     route_mac_rou
292
293 Play_To_Odl_route_mac_rou
294     [Template]    Play_To_Odl_Template
295     route_mac_rou
296
297 Kill_Talking_BGP_Speaker
298     [Documentation]    Abort the Python speaker
299     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
300     BGPSpeaker.Kill_BGP_Speaker
301
302 Delete_Bgp_Peer_Configuration
303     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
304     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
305     &{mapping}    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    BGP_NAME=${BGP_PEER_NAME}
306     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
307
308 Deconfigure_App_Peer
309     [Documentation]    Revert the BGP configuration to the original state: without application peer
310     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
311     &{mapping}    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    APP_PEER_NAME=${APP_PEER_NAME}
312     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
313
314 *** Keywords ***
315 Start_Suite
316     [Documentation]    Initialize SetupUtils. Suite setup keyword.
317     SetupUtils.Setup_Utils_For_Setup_And_Teardown
318     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
319     Builtin.Set Suite Variable    ${mininet_conn_id}
320     Utils.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
321     RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
322     SSHLibrary.Put File    ${PLAY_SCRIPT}    .
323     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
324
325 Stop_Suite
326     [Documentation]    Suite teardown keyword
327     SSHLibrary.Close_All_Connections
328     RequestsLibrary.Delete_All_Sessions
329
330 Start_Bgp_Peer
331     [Documentation]    Starts bgp peer and verifies that the peer runs.
332     BGPSpeaker.Start_BGP_Speaker    --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_TOOL_LOG_LEVEL} --evpn --wfr 1
333     BGPcliKeywords.Read_And_Fail_If_Prompt_Is_Seen
334
335 Odl_To_Play_Template
336     [Arguments]    ${totest}
337     ${data_xml}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/${totest}.xml
338     ${data_json}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/${totest}.json
339     ${announce_hex}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/announce_${totest}.hex
340     ${withdraw_hex}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/withdraw_${totest}.hex
341     BuiltIn.Log    ${data_xml}
342     BuiltIn.Log    ${data_json}
343     BuiltIn.Log    ${announce_hex}
344     BuiltIn.Log    ${withdraw_hex}
345     BgpRpcClient.play_clean
346     ${resp}=    RequestsLibrary.Post_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    data=${data_xml}    headers=${HEADERS_XML}
347     BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    204
348     ${resp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    headers=${HEADERS_XML}
349     BuiltIn.Log    ${resp.content}
350     ${aupdate}=    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content
351     BuiltIn.Log    ${aupdate}
352     BuiltIn.Should_Be_Equal_As_Strings    ${aupdate}    ${announce_hex}
353     BgpRpcClient.play_clean
354     Remove_Configured_Routes
355     ${wupdate}=    BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Get_Update_Content
356     BuiltIn.Log    ${wupdate}
357     BuiltIn.Should Be Equal As Strings    ${wupdate}    ${withdraw_hex}
358     [Teardown]    Remove_Configured_Routes
359
360 Play_To_Odl_Template
361     [Arguments]    ${totest}
362     ${data_xml}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/${totest}.xml
363     ${data_json}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/${totest}.json
364     ${announce_hex}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/announce_${totest}.hex
365     ${withdraw_hex}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/withdraw_${totest}.hex
366     ${empty_routes}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/empty_routes.json
367     BuiltIn.Set_Suite_Variable    ${withdraw_hex}
368     BuiltIn.Set_Suite_Variable    ${empty_routes}
369     BuiltIn.Log    ${data_xml}
370     BuiltIn.Log    ${data_json}
371     BuiltIn.Log    ${announce_hex}
372     BuiltIn.Log    ${withdraw_hex}
373     BuiltIn.Log    ${empty_routes}
374     BgpRpcClient.play_clean
375     BgpRpcClient.play_send    ${announce_hex}
376     BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Loc_Rib_Presnece    ${data_json}
377     BgpRpcClient.play_send    ${withdraw_hex}
378     BuiltIn.Wait_Until_Keyword_Succeeds    4x    2s    Loc_Rib_Presnece    ${empty_routes}
379     [Teardown]    Withdraw_Route_And_Verify    ${withdraw_hex}
380
381 Verify_Test_Preconditions
382     ${resp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}
383     BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    404
384     ${empty_routes}=    OperatingSystem.Get_File    ${EVPN_VARIABLES_DIR}/empty_routes.json
385     Loc_Rib_Presnece    ${empty_routes}
386
387 Remove_Configured_Routes
388     [Documentation]    Removes the route if present. First GET is for debug purposes.
389     ${rsp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${LOC_RIB_URL}    headers=${HEADERS}
390     Log    ${rsp.content}
391     ${rsp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}    headers=${HEADERS}
392     Log    ${rsp.content}
393     BuiltIn.Return_From_Keyword_If    "${rsp.status_code}"=="404"
394     ${resp}=    RequestsLibrary.Delete_Request    ${CONFIG_SESSION}    ${EVPN_CONF_URL}
395     BuiltIn.Should_Be_Equal_As_Numbers    ${resp.status_code}    200
396
397 Withdraw_Route_And_Verify
398     [Arguments]    ${withdraw_hex}
399     [Documentation]    Sends withdraw update message from exabgp and verifies route removal from odl's rib
400     BgpRpcClient.play_send    ${withdraw_hex}
401     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Loc Rib Presnece    ${empty_routes}
402
403 Get_Update_Content
404     [Documentation]    Gets received data from odl's peer
405     ${resp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${EVPN_RIB_OPER_URL}    headers=${HEADERS_XML}
406     BuiltIn.Log    ${resp.content}
407     ${update}=    BgpRpcClient.play_get
408     BuiltIn.Should_Not_Be_Equal    ${update}    ${Empty}
409     [Return]    ${update}
410
411 Loc_Rib_Presnece
412     [Arguments]    ${exp_content}
413     [Documentation]    Verifies if loc-rib contains expected data
414     ${rsp}=    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${LOC_RIB_URL}    headers=${HEADERS}
415     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp_content}    ${rsp.content}