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