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