2 Documentation Functional test for bgp - route-target-constrain safi
4 ... Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
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
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
37 ${CONFIG_SESSION} config-session
38 ${RT_CONSTRAIN_DIR} ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
39 ${L3VPN_RIB_URI} ${CURDIR}/../../../variables/bgpfunctional/rt_constrain/ext_l3vpn_rt_arg/rib
40 ${L3VPN_IPV4_DIR} ${CURDIR}/../../../variables/bgpfunctional/l3vpn_ipv4
41 ${L3VPN_RSPEMPTY} ${L3VPN_IPV4_DIR}/bgp-l3vpn-ipv4-empty.json
42 ${EBGP_DIR} ${CURDIR}/../../../variables/bgpfunctional/ebgp_peer
43 ${PLAY_SCRIPT} ${CURDIR}/../../../../tools/fastbgp/play.py
44 ${RIB_NAME} example-bgp-rib
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 &{LOC_RIB} PATH=loc-rib BGP_RIB=${RIB_NAME}
53 &{RT_CONSTRAIN_APP_PEER} IP=${ODL_SYSTEM_IP} BGP_RIB=${RIB_NAME}
54 &{ADJ_RIB_OUT} PATH=peer/bgp:%2F%2F${ODL_3_IP}/adj-rib-out BGP_RIB=${RIB_NAME}
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 IP=${ODL_${i}_IP} TYPE=${type} HOLDTIME=${HOLDTIME} PEER_PORT=${BGP_TOOL_PORT}
62 \ ... INITIATE=false BGP_RIB=${RIB_NAME} PASSIVE_MODE=true
63 \ TemplatedRequests.Put_As_Xml_Templated ${EBGP_DIR} mapping=${ODL_CONFIG} session=${CONFIG_SESSION}
66 [Documentation] Start Python speaker to connect to ODL. We give each speaker time until odl really starts to accept incoming
67 ... bgp connection. The failure happens if the incoming connection comes too quickly after configuring the peer.
69 [Setup] SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
70 : FOR ${i} ${as_number} IN ZIP ${ODL_IP_INDICES_ALL} ${BGP_PEER_AS_NUMBERS}
71 \ BuiltIn.Log Many IP: ${ODL_${i}_IP} as_number: ${as_number}
72 \ Start_Bgp_Peer ${ODL_${i}_IP} ${as_number} 800${i} play.py.090.${i}
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}
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}
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 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}
88 Check_Presence_Of_l3vpn_Route_In_Node_2_Effective_Rib_In_Table
89 [Documentation] Checks l3vpn route is present in node 2 effective-rib-in table.
90 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}
93 Check_l3vpn_Route_Advertisement_On_Each_Node
94 [Documentation] Checks that each node received or did not receive update message containing given hex message.
95 ${announce}= OperatingSystem.Get_File ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/announce_ext_l3vpn_rt_arg.hex
96 ${announce_hex}= String.Remove_String ${announce} \n
97 Check_For_L3VPN_Odl_Avertisement ${announce_hex}
99 Play_To_Odl_rt_constrain_type_1
100 [Documentation] Sends RT route from node 3 to odl and then checks that odl does not advertize l3vpn route from previous TC,
101 ... that is that update message is empty.
102 Play_To_Odl_Non_Removal_BgpRpcClient4 rt_constrain_type_1 ${RT_CONSTRAIN_DIR}
103 &{EFFECTIVE_RIB_IN}= BuiltIn.Create Dictionary PATH=peer/bgp:%2F%2F${ODL_4_IP}/effective-rib-in BGP_RIB=${RIB_NAME}
104 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 ${update}= BgpRpcClient4.play_get
107 BuiltIn.Should_Be_Equal ${update} ${Empty}
109 Play_To_Odl_remove_rt
110 [Documentation] Removes RT from odl and then checks that second node withdrew l3vpn route and third node did not receive any message.
111 BgpRpcClient3.play_clean
112 Play_To_Odl_Routes_Removal_Template_BgpRpcClient3 rt_constrain_type_0 ${RT_CONSTRAIN_DIR}
113 ${uri}= Resolve_Text_From_File ${L3VPN_RIB_URI} location.uri mapping=${ADJ_RIB_OUT}
114 BuiltIn.Wait_Until_Keyword_Succeeds 3x 2s Verify_Reported_Data ${uri} ${L3VPN_RSPEMPTY}
115 ${update}= BgpRpcClient4.play_get
116 BuiltIn.Should_Be_Equal ${update} ${Empty}
118 Play_To_Odl_remove_routes
119 [Documentation] Removes rt arguments from odl.
120 Play_To_Odl_Routes_Removal_Template_BgpRpcClient2 ext_l3vpn_rt_arg ${RT_CONSTRAIN_DIR}
121 Play_To_Odl_Routes_Removal_Template_BgpRpcClient4 rt_constrain_type_1 ${RT_CONSTRAIN_DIR}
123 Kill_Talking_BGP_Speakers
124 [Documentation] Abort all Python speakers.
125 [Setup] SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
126 BGPcliKeywords.Store_File_To_Workspace play.py.090.2 090_rt_constrain_play_1.log
127 BGPcliKeywords.Store_File_To_Workspace play.py.090.3 090_rt_constrain_play_2.log
128 BGPcliKeywords.Store_File_To_Workspace play.py.090.4 090_rt_constrain_play_3.log
129 BGPSpeaker.Kill_All_BGP_Speakers
131 Delete_Bgp_Peers_Configuration
132 [Documentation] Revert the BGP configuration to the original state: without any configured peers.
133 [Setup] SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
134 : FOR ${i} ${type} IN ZIP ${ODL_IP_INDICES_ALL} ${BGP_PEER_TYPES}
135 \ &{ODL_CONFIG}= BuiltIn.Create Dictionary IP=${ODL_${i}_IP} TYPE=${type} HOLDTIME=${HOLDTIME} PEER_PORT=${BGP_TOOL_PORT}
136 \ ... INITIATE=false BGP_RIB=${RIB_NAME} PASSIVE_MODE=true
137 \ TemplatedRequests.Delete_Templated ${EBGP_DIR} mapping=${ODL_CONFIG} session=${CONFIG_SESSION}
141 [Documentation] Initialize SetupUtils. Suite setup keyword.
142 SetupUtils.Setup_Utils_For_Setup_And_Teardown
143 ${conn_id} = SSHLibrary.Open Connection ${ODL_SYSTEM_IP} prompt=${DEFAULT_LINUX_PROMPT} timeout=6s
144 Builtin.Set_Suite_Variable ${conn_id}
145 SSHKeywords.Flexible_Controller_Login
146 RequestsLibrary.Create_Session ${CONFIG_SESSION} http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH}
147 SSHLibrary.Put_File ${PLAY_SCRIPT} .
148 SSHKeywords.Assure_Library_Ipaddr target_dir=.
151 [Documentation] Suite teardown keyword
152 SSHLibrary.Close_All_Connections
153 RequestsLibrary.Delete_All_Sessions
156 [Arguments] ${ip} ${as_number} ${port} ${filename}
157 [Documentation] Starts bgp peer.
158 ${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} &
159 BuiltIn.Log ${command}
160 ${output}= SSHLibrary.Write ${command}
162 Play_To_Odl_Non_Removal_BgpRpcClient2
163 [Arguments] ${totest} ${dir} ${ipv}=ipv4
164 [Documentation] Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
165 ${announce_hex}= OperatingSystem.Get_File ${dir}/${totest}/announce_${totest}.hex
166 BgpRpcClient2.play_send ${announce_hex}
168 Play_To_Odl_Non_Removal_BgpRpcClient3
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 BgpRpcClient3.play_send ${announce_hex}
174 Play_To_Odl_Non_Removal_BgpRpcClient4
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 BgpRpcClient4.play_send ${announce_hex}
180 Play_To_Odl_Routes_Removal_Template_BgpRpcClient2
181 [Arguments] ${totest} ${dir} ${ipv}=ipv4
182 [Documentation] Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
183 ${withdraw_hex} = OperatingSystem.Get_File ${dir}/${totest}/withdraw_${totest}.hex
184 BgpRpcClient2.play_clean
185 BgpRpcClient2.play_send ${withdraw_hex}
187 Play_To_Odl_Routes_Removal_Template_BgpRpcClient3
188 [Arguments] ${totest} ${dir} ${ipv}=ipv4
189 [Documentation] Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
190 ${withdraw_hex} = OperatingSystem.Get_File ${dir}/${totest}/withdraw_${totest}.hex
191 BgpRpcClient3.play_clean
192 BgpRpcClient3.play_send ${withdraw_hex}
194 Play_To_Odl_Routes_Removal_Template_BgpRpcClient4
195 [Arguments] ${totest} ${dir} ${ipv}=ipv4
196 [Documentation] Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
197 ${withdraw_hex} = OperatingSystem.Get_File ${dir}/${totest}/withdraw_${totest}.hex
198 BgpRpcClient4.play_clean
199 BgpRpcClient4.play_send ${withdraw_hex}
201 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient2
202 [Arguments] ${hex} ${option}
203 [Documentation] Returns hex update message and compares it to hex.
204 ${update}= BgpRpcClient2.play_get
205 BuiltIn.Run_Keyword_If "${option}"=="true" BuiltIn.Should_Be_Equal_As_Strings ${update} ${hex}
206 BuiltIn.Run_Keyword_If "${option}"=="false" BuiltIn.Should_Not_Be_Equal_As_Strings ${update} ${hex}
208 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient3
209 [Arguments] ${hex} ${option}
210 [Documentation] Returns hex update message and compares it to hex.
211 ${update}= BgpRpcClient3.play_get
212 BuiltIn.Run_Keyword_If "${option}"=="true" BuiltIn.Should_Be_Equal_As_Strings ${update} ${hex}
213 BuiltIn.Run_Keyword_If "${option}"=="false" BuiltIn.Should_Not_Be_Equal_As_Strings ${update} ${hex}
215 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient4
216 [Arguments] ${hex} ${option}
217 [Documentation] Returns hex update message and compares it to hex.
218 ${update}= BgpRpcClient4.play_get
219 BuiltIn.Run_Keyword_If "${option}"=="true" BuiltIn.Should_Be_Equal_As_Strings ${update} ${hex}
220 BuiltIn.Run_Keyword_If "${option}"=="false" BuiltIn.Should_Not_Be_Equal_As_Strings ${update} ${hex}
222 Check_For_L3VPN_Odl_Avertisement
223 [Arguments] ${announce_hex}
224 [Documentation] Checks that each node received or did not receive update message containing given hex message.
225 : FOR ${i} ${option} IN ZIP ${ODL_IP_INDICES_ALL} ${L3VPN_RT_CHECK}
226 \ ${keyword_name}= BuiltIn.Set_Variable Get_Update_Message_And_Compare_With_Hex_BgpRpcClient${i}
227 \ BuiltIn.Run_Keyword ${keyword_name} ${announce_hex} ${option}
229 Resolve_Text_From_File
230 [Arguments] ${folder} ${file_name} ${mapping}={}
231 [Documentation] Read and Log contents of file ${folder}/${file_name}, remove endline,
232 ... perform safe substitution, return result.
233 ${file_path}= BuiltIn.Set_Variable ${folder}${/}${file_name}
234 ${template} = OperatingSystem.Get_File ${file_path}
235 BuiltIn.Log ${template}
236 ${final_text} = BuiltIn.Evaluate string.Template('''${template}'''.rstrip()).safe_substitute(${mapping}) modules=string
237 [Return] ${final_text}
240 [Arguments] ${url} ${exprspfile}
241 [Documentation] Verifies expected response
242 ${expresponse}= OperatingSystem.Get File ${exprspfile}
243 BuiltIn.Log expected_response: ${expresponse}
244 ${rsp}= RequestsLibrary.Get_Request ${CONFIG_SESSION} ${url}
245 BuiltIn.Log actual_response: ${rsp}
246 BuiltIn.Log actual_response_content: ${rsp.content}
247 TemplatedRequests.Normalize_Jsons_And_Compare ${expresponse} ${rsp.content}