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