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