Migrate Get Requests invocations(libraries)
[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
18 Library             RequestsLibrary
19 Library             SSHLibrary
20 Library             String
21 Library             ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8002    WITH NAME    BgpRpcClient2
22 Library             ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8003    WITH NAME    BgpRpcClient3
23 Library             ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8004    WITH NAME    BgpRpcClient4
24 Resource            ../../../libraries/BGPcliKeywords.robot
25 Resource            ../../../libraries/BgpOperations.robot
26 Resource            ../../../libraries/BGPSpeaker.robot
27 Resource            ../../../libraries/SetupUtils.robot
28 Resource            ../../../libraries/SSHKeywords.robot
29 Resource            ../../../libraries/TemplatedRequests.robot
30 Resource            ../../../libraries/TemplatedRequests.robot
31 Resource            ../../../variables/Variables.robot
32
33 Suite Setup         Start_Suite
34 Suite Teardown      Stop_Suite
35 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
36
37
38 *** Variables ***
39 ${HOLDTIME}                 180
40 ${CONFIG_SESSION}           config-session
41 ${RT_CONSTRAIN_DIR}         ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
42 ${EBGP_DIR}                 ${CURDIR}/../../../variables/bgpfunctional/ebgp_peer
43 ${PLAY_SCRIPT}              ${CURDIR}/../../../../tools/fastbgp/play.py
44 ${RIB_NAME}                 example-bgp-rib
45 ${ODL_2_IP}                 127.0.0.2
46 ${ODL_3_IP}                 127.0.0.3
47 ${ODL_4_IP}                 127.0.0.4
48 @{BGP_PEER_TYPES}           external    internal    internal
49 @{BGP_PEER_AS_NUMBERS}      65000    64496    64496
50 @{ODL_IP_INDICES_ALL}       2    3    4
51 @{L3VPN_RT_CHECK}           false    true    false
52 &{RT_CONSTRAIN_APP_PEER}    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_NAME}
53 &{ADJ_RIB_OUT}              PATH=peer\=bgp:%2F%2F${ODL_3_IP}/adj-rib-out    BGP_RIB=${RIB_NAME}
54
55
56 *** Test Cases ***
57 Reconfigure_ODL_To_Accept_Connection
58     [Documentation]    Configures BGP peer module with initiate-connection set to false.
59     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
60     FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
61         &{ODL_CONFIG} =    BuiltIn.Create_Dictionary
62         ...    IP=${ODL_${i}_IP}
63         ...    TYPE=${type}
64         ...    HOLDTIME=${HOLDTIME}
65         ...    PEER_PORT=${BGP_TOOL_PORT}
66         ...    INITIATE=false
67         ...    BGP_RIB=${RIB_NAME}
68         ...    PASSIVE_MODE=true
69         TemplatedRequests.Put_As_Xml_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
70     END
71
72 Start_Bgp_Peers
73     [Documentation]    Start Python speaker to connect to ODL. We give each speaker time until odl really starts to accept incoming
74     ...    bgp connection. The failure happens if the incoming connection comes too quickly after configuring the peer.
75     [Tags]    local_run
76     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
77     FOR    ${i}    ${as_number}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_AS_NUMBERS}
78         BuiltIn.Log_Many    IP: ${ODL_${i}_IP}    as_number: ${as_number}
79         Start_Bgp_Peer    ${ODL_${i}_IP}    ${as_number}    800${i}    play.py.090.${i}
80     END
81
82 Play_To_Odl_ext_l3vpn_rt_arg
83     [Documentation]    This TC sends route-target route containing route-target argument from node 1 to odl
84     ...    so odl can identify this peer as appropriate for advertizement when it recieves such route.
85     Play_To_Odl_Non_Removal_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
86     &{effective_rib_in} =    BuiltIn.Create_Dictionary
87     ...    PATH=peer\=bgp:%2F%2F${ODL_2_IP}/effective-rib-in
88     ...    BGP_RIB=${RIB_NAME}
89     BuiltIn.Wait_Until_Keyword_Succeeds
90     ...    3x
91     ...    2s
92     ...    TemplatedRequests.Get_As_Json_Templated
93     ...    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib
94     ...    mapping=${effective_rib_in}
95     ...    session=${CONFIG_SESSION}
96     ...    verify=True
97
98 Play_To_Odl_rt_constrain_type_0
99     [Documentation]    Sends RT route from node 2 to odl and then checks that odl advertizes l3vpn route from previous TC.
100     Play_To_Odl_Non_Removal_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
101     &{loc_rib} =    BuiltIn.Create_Dictionary    PATH=loc-rib    BGP_RIB=${RIB_NAME}
102     BuiltIn.Wait_Until_Keyword_Succeeds
103     ...    3x
104     ...    2s
105     ...    TemplatedRequests.Get_As_Json_Templated
106     ...    ${RT_CONSTRAIN_DIR}/rt_constrain_type_0/rib
107     ...    mapping=${loc_rib}
108     ...    session=${CONFIG_SESSION}
109     ...    verify=True
110
111 Check_Presence_Of_l3vpn_Route_In_Node_2_Effective_Rib_In_Table
112     [Documentation]    Checks l3vpn route is present in node 2 effective-rib-in table.
113     BuiltIn.Wait_Until_Keyword_Succeeds
114     ...    3x
115     ...    2s
116     ...    TemplatedRequests.Get_As_Json_Templated
117     ...    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib
118     ...    mapping=${ADJ_RIB_OUT}
119     ...    session=${CONFIG_SESSION}
120     ...    verify=True
121
122 Check_l3vpn_Route_Advertisement_On_Each_Node
123     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
124     ${announce} =    OperatingSystem.Get_File    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/announce_ext_l3vpn_rt_arg.hex
125     ${announce_hex} =    String.Remove_String    ${announce}    \n
126     Check_For_L3VPN_Odl_Avertisement    ${announce_hex}
127
128 Play_To_Odl_rt_constrain_type_1
129     [Documentation]    Sends RT route from node 3 to odl and then checks that odl does not advertize l3vpn route from previous TC,
130     ...    that is that update message is empty.
131     Play_To_Odl_Non_Removal_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
132     &{effective_rib_in} =    BuiltIn.Create_Dictionary
133     ...    PATH=peer\=bgp:%2F%2F${ODL_4_IP}/effective-rib-in
134     ...    BGP_RIB=${RIB_NAME}
135     BuiltIn.Wait_Until_Keyword_Succeeds
136     ...    3x
137     ...    2s
138     ...    TemplatedRequests.Get_As_Json_Templated
139     ...    ${RT_CONSTRAIN_DIR}/rt_constrain_type_1/rib
140     ...    mapping=${effective_rib_in}
141     ...    session=${CONFIG_SESSION}
142     ...    verify=True
143     ${update} =    BgpRpcClient4.play_get
144
145 Play_To_Odl_remove_rt
146     [Documentation]    Removes RT from odl and then checks that second node withdrew l3vpn route and third node did not receive any message.
147     BgpRpcClient3.play_clean
148     Play_To_Odl_Routes_Removal_Template_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
149
150 Play_To_Odl_remove_routes
151     [Documentation]    Removes rt arguments from odl.
152     Play_To_Odl_Routes_Removal_Template_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
153     Play_To_Odl_Routes_Removal_Template_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
154
155 Kill_Talking_BGP_Speakers
156     [Documentation]    Abort all Python speakers.
157     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
158     BGPcliKeywords.Store_File_To_Workspace    play.py.090.2    090_rt_constrain_play_1.log
159     BGPcliKeywords.Store_File_To_Workspace    play.py.090.3    090_rt_constrain_play_2.log
160     BGPcliKeywords.Store_File_To_Workspace    play.py.090.4    090_rt_constrain_play_3.log
161     BGPSpeaker.Kill_All_BGP_Speakers
162
163 Delete_Bgp_Peers_Configuration
164     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
165     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
166     FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
167         &{ODL_CONFIG} =    BuiltIn.Create_Dictionary
168         ...    IP=${ODL_${i}_IP}
169         ...    TYPE=${type}
170         ...    HOLDTIME=${HOLDTIME}
171         ...    PEER_PORT=${BGP_TOOL_PORT}
172         ...    INITIATE=false
173         ...    BGP_RIB=${RIB_NAME}
174         ...    PASSIVE_MODE=true
175         TemplatedRequests.Delete_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
176     END
177
178
179 *** Keywords ***
180 Start_Suite
181     [Documentation]    Initialize SetupUtils. Suite setup keyword.
182     SetupUtils.Setup_Utils_For_Setup_And_Teardown
183     ${conn_id} =    SSHLibrary.Open Connection    ${ODL_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
184     Builtin.Set_Suite_Variable    ${conn_id}
185     SSHKeywords.Flexible_Controller_Login
186     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
187     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
188     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
189
190 Stop_Suite
191     [Documentation]    Suite teardown keyword
192     SSHLibrary.Close_All_Connections
193     RequestsLibrary.Delete_All_Sessions
194
195 Start_Bgp_Peer
196     [Documentation]    Starts bgp peer.
197     [Arguments]    ${ip}    ${as_number}    ${port}    ${filename}
198     ${command} =    BuiltIn.Set_Variable
199     ...    python3 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} &
200     BuiltIn.Log    ${command}
201     ${output} =    SSHLibrary.Write    ${command}
202
203 Play_To_Odl_Non_Removal_BgpRpcClient2
204     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
205     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
206     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
207     BgpRpcClient2.play_send    ${announce_hex}
208
209 Play_To_Odl_Non_Removal_BgpRpcClient3
210     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
211     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
212     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
213     BgpRpcClient3.play_send    ${announce_hex}
214
215 Play_To_Odl_Non_Removal_BgpRpcClient4
216     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
217     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
218     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
219     BgpRpcClient4.play_send    ${announce_hex}
220
221 Play_To_Odl_Routes_Removal_Template_BgpRpcClient2
222     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
223     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
224     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
225     BgpRpcClient2.play_clean
226     BgpRpcClient2.play_send    ${withdraw_hex}
227
228 Play_To_Odl_Routes_Removal_Template_BgpRpcClient3
229     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
230     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
231     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
232     BgpRpcClient3.play_clean
233     BgpRpcClient3.play_send    ${withdraw_hex}
234
235 Play_To_Odl_Routes_Removal_Template_BgpRpcClient4
236     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
237     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
238     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
239     BgpRpcClient4.play_clean
240     BgpRpcClient4.play_send    ${withdraw_hex}
241
242 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient2
243     [Documentation]    Returns hex update message and compares it to hex.
244     [Arguments]    ${hex}    ${option}
245     ${update} =    BgpRpcClient2.play_get
246     IF    "${option}" == "true"
247         BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
248     END
249     IF    "${option}" == "false"
250         BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
251     END
252
253 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient3
254     [Documentation]    Returns hex update message and compares it to hex.
255     [Arguments]    ${hex}    ${option}
256     ${update} =    BgpRpcClient3.play_get
257     IF    "${option}" == "true"
258         BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
259     END
260     IF    "${option}" == "false"
261         BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
262     END
263
264 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient4
265     [Documentation]    Returns hex update message and compares it to hex.
266     [Arguments]    ${hex}    ${option}
267     ${update} =    BgpRpcClient4.play_get
268     IF    "${option}" == "true"
269         BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
270     END
271     IF    "${option}" == "false"
272         BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
273     END
274
275 Check_For_L3VPN_Odl_Avertisement
276     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
277     [Arguments]    ${announce_hex}
278     FOR    ${i}    ${option}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${L3VPN_RT_CHECK}
279         ${keyword_name} =    BuiltIn.Set_Variable    Get_Update_Message_And_Compare_With_Hex_BgpRpcClient${i}
280         BuiltIn.Run_Keyword    ${keyword_name}    ${announce_hex}    ${option}
281     END
282
283 Verify_Reported_Data
284     [Documentation]    Verifies expected response
285     [Arguments]    ${url}    ${exprspfile}
286     ${expresponse} =    OperatingSystem.Get File    ${exprspfile}
287     BuiltIn.Log    expected_response: ${expresponse}
288     ${rsp} =    RequestsLibrary.GET On Session    ${CONFIG_SESSION}    url=${url}
289     BuiltIn.Log    actual_response: ${rsp}
290     BuiltIn.Log    actual_response_content: ${rsp.content}
291     TemplatedRequests.Normalize_Jsons_And_Compare    ${expresponse}    ${rsp.content}
292
293 Verify_Empty_Reported_Data
294     [Documentation]    Verify empty data response
295     TemplatedRequests.Get_As_Json_Templated
296     ...    ${RT_CONSTRAIN_DIR}${/}empty_l3vpn
297     ...    session=${CONFIG_SESSION}
298     ...    mapping=${ADJ_RIB_OUT}
299     ...    verify=True
300
301 Verify_Empty_Data_Neon
302     [Documentation]    Verify empty data on neon
303     TemplatedRequests.Get_As_Json_Templated
304     ...    ${RT_CONSTRAIN_DIR}${/}empty_route
305     ...    session=${CONFIG_SESSION}
306     ...    mapping=${ADJ_RIB_OUT}
307     ...    verify=True