Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 090_bgp_functional_rt_constrain_validation.robot
1 *** Settings ***
2 Documentation     Functional test for bgp - route-target-constrain safi
3 ...
4 ...               Copyright (c) 2018 AT&T Intellectual Property. 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 distbmution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...               This suite tests advertising rt-constrain routes to odl. For advertising from peer,
11 ...               play.py is used, sending hex messages to odl.
12 ...               There are 3 peers: ebgp and two ibgps. First peer sends l3vpn route with specific RT to odl, second peer
13 ...               sends RT route and third peer only establishes connection. Then it is checked that odl advertizes l3vpn route
14 ...               to second peer. Third peer sends wildcard RT route and it is checked that odl doesn't advertize l3vpn route
15 ...               to it. Then second peer removes RT and it is checked that second peer withdrew RT route and that odl withdrew
16 ...               l3vpn route from it.
17 Suite Setup       Start_Suite
18 Suite Teardown    Stop_Suite
19 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
20 Library           RequestsLibrary
21 Library           SSHLibrary
22 Library           String
23 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8002    WITH NAME    BgpRpcClient2
24 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8003    WITH NAME    BgpRpcClient3
25 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8004    WITH NAME    BgpRpcClient4
26 Resource          ../../../libraries/BGPcliKeywords.robot
27 Resource          ../../../libraries/BgpOperations.robot
28 Resource          ../../../libraries/BGPSpeaker.robot
29 Resource          ../../../libraries/SetupUtils.robot
30 Resource          ../../../libraries/SSHKeywords.robot
31 Resource          ../../../libraries/TemplatedRequests.robot
32 Resource          ../../../libraries/TemplatedRequests.robot
33 Resource          ../../../variables/Variables.robot
34
35 *** Variables ***
36 ${HOLDTIME}       180
37 ${CONFIG_SESSION}    config-session
38 ${RT_CONSTRAIN_DIR}    ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
39 ${EBGP_DIR}       ${CURDIR}/../../../variables/bgpfunctional/ebgp_peer
40 ${PLAY_SCRIPT}    ${CURDIR}/../../../../tools/fastbgp/play.py
41 ${RIB_NAME}       example-bgp-rib
42 ${ODL_2_IP}       127.0.0.2
43 ${ODL_3_IP}       127.0.0.3
44 ${ODL_4_IP}       127.0.0.4
45 ${OLD_AS_PATH}    \n"as-path": {},
46 ${NEW_AS_PATH}    ${EMPTY}
47 @{BGP_PEER_TYPES}    external    internal    internal
48 @{BGP_PEER_AS_NUMBERS}    65000    64496    64496
49 @{ODL_IP_INDICES_ALL}    2    3    4
50 @{L3VPN_RT_CHECK}    false    true    false
51 &{RT_CONSTRAIN_APP_PEER}    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_NAME}
52 &{ADJ_RIB_OUT}    PATH=peer/bgp:%2F%2F${ODL_3_IP}/adj-rib-out    BGP_RIB=${RIB_NAME}
53
54 *** Test Cases ***
55 Reconfigure_ODL_To_Accept_Connection
56     [Documentation]    Configures BGP peer module with initiate-connection set to false.
57     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
58     FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
59         &{ODL_CONFIG}=    BuiltIn.Create_Dictionary    IP=${ODL_${i}_IP}    TYPE=${type}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
60         ...    INITIATE=false    BGP_RIB=${RIB_NAME}    PASSIVE_MODE=true
61         TemplatedRequests.Put_As_Xml_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
62     END
63
64 Start_Bgp_Peers
65     [Documentation]    Start Python speaker to connect to ODL. We give each speaker time until odl really starts to accept incoming
66     ...    bgp connection. The failure happens if the incoming connection comes too quickly after configuring the peer.
67     [Tags]    local_run
68     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
69     FOR    ${i}    ${as_number}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_AS_NUMBERS}
70         BuiltIn.Log_Many    IP: ${ODL_${i}_IP}    as_number: ${as_number}
71         Start_Bgp_Peer    ${ODL_${i}_IP}    ${as_number}    800${i}    play.py.090.${i}
72     END
73
74 Play_To_Odl_ext_l3vpn_rt_arg
75     [Documentation]    This TC sends route-target route containing route-target argument from node 1 to odl
76     ...    so odl can identify this peer as appropriate for advertizement when it recieves such route.
77     Play_To_Odl_Non_Removal_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
78     &{effective_rib_in}    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${ODL_2_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
79     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib    mapping=${effective_rib_in}    session=${CONFIG_SESSION}
80     ...    verify=True
81
82 Play_To_Odl_rt_constrain_type_0
83     [Documentation]    Sends RT route from node 2 to odl and then checks that odl advertizes l3vpn route from previous TC.
84     Play_To_Odl_Non_Removal_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
85     &{loc_rib}    BuiltIn.Create_Dictionary    PATH=loc-rib    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
86     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/rt_constrain_type_0/rib    mapping=${loc_rib}    session=${CONFIG_SESSION}
87     ...    verify=True
88
89 Check_Presence_Of_l3vpn_Route_In_Node_2_Effective_Rib_In_Table
90     [Documentation]    Checks l3vpn route is present in node 2 effective-rib-in table.
91     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib    mapping=${ADJ_RIB_OUT}    session=${CONFIG_SESSION}
92     ...    verify=True
93
94 Check_l3vpn_Route_Advertisement_On_Each_Node
95     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
96     ${announce} =    OperatingSystem.Get_File    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/announce_ext_l3vpn_rt_arg.hex
97     ${announce_hex} =    String.Remove_String    ${announce}    \n
98     Check_For_L3VPN_Odl_Avertisement    ${announce_hex}
99
100 Play_To_Odl_rt_constrain_type_1
101     [Documentation]    Sends RT route from node 3 to odl and then checks that odl does not advertize l3vpn route from previous TC,
102     ...    that is that update message is empty.
103     Play_To_Odl_Non_Removal_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
104     &{effective_rib_in} =    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${ODL_4_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
105     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/rt_constrain_type_1/rib    mapping=${effective_rib_in}    session=${CONFIG_SESSION}
106     ...    verify=True
107     ${update} =    BgpRpcClient4.play_get
108     Comment    From neon onwards there is extra BGP End-Of-RIB message
109     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Should_Be_Equal    ${update}    ${Empty}
110
111 Play_To_Odl_remove_rt
112     [Documentation]    Removes RT from odl and then checks that second node withdrew l3vpn route and third node did not receive any message.
113     BgpRpcClient3.play_clean
114     Play_To_Odl_Routes_Removal_Template_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
115     Comment    From neon onwards there is extra BGP End-Of-RIB message
116     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
117     ${update} =    BgpRpcClient4.play_get
118     Comment    From neon onwards there is extra BGP End-Of-RIB message
119     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Should_Be_Equal    ${update}    ${Empty}
120
121 Play_To_Odl_remove_routes
122     [Documentation]    Removes rt arguments from odl.
123     Play_To_Odl_Routes_Removal_Template_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
124     Play_To_Odl_Routes_Removal_Template_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
125
126 Kill_Talking_BGP_Speakers
127     [Documentation]    Abort all Python speakers.
128     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
129     BGPcliKeywords.Store_File_To_Workspace    play.py.090.2    090_rt_constrain_play_1.log
130     BGPcliKeywords.Store_File_To_Workspace    play.py.090.3    090_rt_constrain_play_2.log
131     BGPcliKeywords.Store_File_To_Workspace    play.py.090.4    090_rt_constrain_play_3.log
132     BGPSpeaker.Kill_All_BGP_Speakers
133
134 Delete_Bgp_Peers_Configuration
135     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
136     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
137     FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
138         &{ODL_CONFIG} =    BuiltIn.Create_Dictionary    IP=${ODL_${i}_IP}    TYPE=${type}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
139         ...    INITIATE=false    BGP_RIB=${RIB_NAME}    PASSIVE_MODE=true
140         TemplatedRequests.Delete_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
141     END
142
143 *** Keywords ***
144 Start_Suite
145     [Documentation]    Initialize SetupUtils. Suite setup keyword.
146     SetupUtils.Setup_Utils_For_Setup_And_Teardown
147     ${conn_id} =    SSHLibrary.Open Connection    ${ODL_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
148     Builtin.Set_Suite_Variable    ${conn_id}
149     SSHKeywords.Flexible_Controller_Login
150     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
151     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
152     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
153     ${AS_PATH} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
154     BuiltIn.Set_Suite_Variable    ${AS_PATH}
155
156 Stop_Suite
157     [Documentation]    Suite teardown keyword
158     SSHLibrary.Close_All_Connections
159     RequestsLibrary.Delete_All_Sessions
160
161 Start_Bgp_Peer
162     [Arguments]    ${ip}    ${as_number}    ${port}    ${filename}
163     [Documentation]    Starts bgp peer.
164     ${command} =    BuiltIn.Set_Variable    python play.py --amount 0 --myip=${ip} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --asnumber=${as_number} --peerport=${ODL_BGP_PORT} --port=${port} --usepeerip --debug --allf --wfr 1 &> ${filename} &
165     BuiltIn.Log    ${command}
166     ${output} =    SSHLibrary.Write    ${command}
167
168 Play_To_Odl_Non_Removal_BgpRpcClient2
169     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
170     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
171     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
172     BgpRpcClient2.play_send    ${announce_hex}
173
174 Play_To_Odl_Non_Removal_BgpRpcClient3
175     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
176     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
177     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
178     BgpRpcClient3.play_send    ${announce_hex}
179
180 Play_To_Odl_Non_Removal_BgpRpcClient4
181     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
182     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
183     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
184     BgpRpcClient4.play_send    ${announce_hex}
185
186 Play_To_Odl_Routes_Removal_Template_BgpRpcClient2
187     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
188     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
189     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
190     BgpRpcClient2.play_clean
191     BgpRpcClient2.play_send    ${withdraw_hex}
192
193 Play_To_Odl_Routes_Removal_Template_BgpRpcClient3
194     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
195     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
196     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
197     BgpRpcClient3.play_clean
198     BgpRpcClient3.play_send    ${withdraw_hex}
199
200 Play_To_Odl_Routes_Removal_Template_BgpRpcClient4
201     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
202     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
203     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
204     BgpRpcClient4.play_clean
205     BgpRpcClient4.play_send    ${withdraw_hex}
206
207 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient2
208     [Arguments]    ${hex}    ${option}
209     [Documentation]    Returns hex update message and compares it to hex.
210     ${update} =    BgpRpcClient2.play_get
211     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
212     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
213
214 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient3
215     [Arguments]    ${hex}    ${option}
216     [Documentation]    Returns hex update message and compares it to hex.
217     ${update} =    BgpRpcClient3.play_get
218     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
219     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
220
221 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient4
222     [Arguments]    ${hex}    ${option}
223     [Documentation]    Returns hex update message and compares it to hex.
224     ${update} =    BgpRpcClient4.play_get
225     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
226     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
227
228 Check_For_L3VPN_Odl_Avertisement
229     [Arguments]    ${announce_hex}
230     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
231     FOR    ${i}    ${option}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${L3VPN_RT_CHECK}
232         ${keyword_name}=    BuiltIn.Set_Variable    Get_Update_Message_And_Compare_With_Hex_BgpRpcClient${i}
233         BuiltIn.Run_Keyword    ${keyword_name}    ${announce_hex}    ${option}
234     END
235
236 Verify_Reported_Data
237     [Arguments]    ${url}    ${exprspfile}
238     [Documentation]    Verifies expected response
239     ${expresponse} =    OperatingSystem.Get File    ${exprspfile}
240     BuiltIn.Log    expected_response: ${expresponse}
241     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${url}
242     BuiltIn.Log    actual_response: ${rsp}
243     BuiltIn.Log    actual_response_content: ${rsp.content}
244     TemplatedRequests.Normalize_Jsons_And_Compare    ${expresponse}    ${rsp.content}
245
246 Verify_Empty_Reported_Data
247     [Documentation]    Verify empty data response
248     TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}${/}empty_l3vpn    session=${CONFIG_SESSION}    mapping=${ADJ_RIB_OUT}    verify=True
249
250 Verify_Empty_Data_Neon
251     [Documentation]    Verify empty data on neon
252     TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}${/}empty_route    session=${CONFIG_SESSION}    mapping=${ADJ_RIB_OUT}    verify=True