2 Documentation Library containing Keywords used for SXP testing
5 Library RequestsLibrary
7 Resource CompareStream.robot
8 Resource KarafKeywords.robot
9 Resource TemplatedRequests.robot
11 Resource ../variables/Variables.robot
15 ${REST_CONTEXT} /restconf/operations/sxp-controller
20 [Documentation] Post request to Controller and checks response
21 [Arguments] ${session} ${path} ${data} ${rest_context}=${REST_CONTEXT}
22 ${resp} = RequestsLibrary.Post Request
24 ... ${rest_context}:${path}
26 ... headers=${HEADERS_XML}
31 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
32 ${content} = BuiltIn.Evaluate json.loads('''${resp.text}''') json
33 ${output} = collections.Get From Dictionary ${content} output
34 ${result} = collections.Get From Dictionary ${output} result
35 BuiltIn.Should Be True ${result} RPC result is False
38 [Documentation] Add node via RPC to ODL
39 [Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${node}
40 ... ${ssl_stores}=${EMPTY} ${retry_open_timer}=1
41 ${data} = Sxp.Add Node Xml ${node} ${port} ${password} ${version} ${ip}
42 ... keystores=${ssl_stores} retry_open_timer=${retry_open_timer}
43 Post To Controller ${session} add-node ${data}
46 [Documentation] Delete connection via RPC from node
47 [Arguments] ${node} ${session}=session
48 ${data} = Sxp.Delete Node Xml ${node}
49 Post To Controller ${session} delete-node ${data}
52 [Documentation] Add connection via RPC to node
53 [Arguments] ${version} ${mode} ${ip} ${port} ${node}=127.0.0.1 ${password}=${EMPTY}
54 ... ${session}=session ${domain}=global ${security_mode}=${EMPTY}
55 ${data} = Sxp.Add Connection Xml ${version} ${mode} ${ip} ${port} ${node}
56 ... ${password} ${domain} security_mode=${security_mode}
57 Post To Controller ${session} add-connection ${data}
60 [Documentation] Gets all connections via RPC from node
61 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
62 ${data} = Sxp.Get Connections From Node Xml ${node} ${domain}
63 ${resp} = RequestsLibrary.Post Request
65 ... ${REST_CONTEXT}:get-connections
67 ... headers=${HEADERS_XML}
68 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
72 [Documentation] Delete connection via RPC from node
73 [Arguments] ${ip} ${port} ${node}=127.0.0.1 ${session}=session ${domain}=global
74 ${data} = Sxp.Delete Connections Xml ${ip} ${port} ${node} ${domain}
75 Post To Controller ${session} delete-connection ${data}
78 [Documentation] Delete all connections via RPC from node
79 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
80 ${resp} = Get Connections ${node} ${session} ${domain}
81 @{connections} = Sxp.Parse Connections ${resp}
82 FOR ${connection} IN @{connections}
84 ... ${connection['peer-address']}
85 ... ${connection['tcp-port']}
92 [Documentation] Verify that connection is ON
93 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
94 ... ${session}=session ${domain}=global
95 ${resp} = Get Connections ${node} ${session} ${domain}
96 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
99 [Documentation] Based on ODL version decide if bindings will be added with or without origin type (introduced in Fluorine)
100 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global ${origin}=LOCAL
101 CompareStream.Run_Keyword_If_At_Least_Fluorine
102 ... Add Bindings Fluorine
109 CompareStream.Run_Keyword_If_At_Most_Oxygen
110 ... Add Bindings Oxygen
117 Add Bindings Fluorine
118 [Documentation] Add/Update one or more bindings with origin type via RPC to Master DB of the node
119 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain} ${origin}
120 ${data} = Sxp.Add Bindings Xml Fluorine ${node} ${domain} ${sgt} ${prefixes} ${origin}
121 Post To Controller ${session} add-bindings ${data}
124 [Documentation] Add/Update one or more bindings without origin type via RPC to Master DB of the node
125 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain}
126 ${data} = Sxp.Add Bindings Xml Oxygen ${node} ${domain} ${sgt} ${prefixes}
127 Post To Controller ${session} add-bindings ${data}
130 [Documentation] Gets all binding via RPC from Master DB of node
131 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
132 ${data} = Sxp.Get Bindings From Node Xml ${node} ${scope} ${domain}
133 ${resp} = TemplatedRequests.Post_To_Uri
134 ... ${REST_CONTEXT}:get-node-bindings
136 ... accept=${ACCEPT_JSON}
137 ... content_type=${HEADERS_XML}
138 ... session=${session}
142 [Documentation] Delete all bindings via RPC from Master DB of node
143 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=local
144 ${resp} = Get Bindings ${node} ${session} ${domain} ${scope}
145 @{bindings} = Sxp.Parse Bindings ${resp}
146 FOR ${binding} IN @{bindings}
147 @{prefixes_list} = collections.Get From Dictionary ${binding} ip-prefix
148 ${prefixes} = BuiltIn.Catenate SEPARATOR=, @{prefixes_list}
149 Delete Bindings ${binding['sgt']} ${prefixes} ${node} ${domain} ${session}
153 [Documentation] Delete one or more bindings via RPC from Master DB of node
154 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${domain}=global ${session}=session
155 ${data} = Sxp.Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
156 Post To Controller ${session} delete-bindings ${data}
159 [Documentation] Adds new PeerGroup via RPC to Node
160 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
161 ${data} = Sxp.Add Peer Group Xml ${name} ${peers} ${node}
162 Post To Controller ${session} add-peer-group ${data}
165 [Documentation] Delete PeerGroup via RPC from Node
166 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
167 ${data} = Sxp.Delete Peer Group Xml ${name} ${node}
168 Post To Controller ${session} delete-peer-group ${data}
171 [Documentation] Gets all PeerGroups via RPC from node
172 [Arguments] ${node}=127.0.0.1 ${session}=session
173 ${data} = Sxp.Get Peer Groups From Node Xml ${node}
174 ${resp} = RequestsLibrary.Post Request
176 ... ${REST_CONTEXT}:get-peer-groups
178 ... headers=${HEADERS_XML}
179 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
183 [Documentation] Delete all PeerGroups via RPC from node
184 [Arguments] ${node}=127.0.0.1 ${session}=session
185 ${resp} = Get Peer Groups ${node} ${session}
186 @{prefixes} = Sxp.Parse Peer Groups ${resp}
187 FOR ${group} IN @{prefixes}
188 Delete Peer Group ${group['name']} ${node} ${session}
192 [Documentation] Add Filter via RPC from Node
193 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
194 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
195 Post To Controller ${session} add-filter ${data}
198 [Documentation] Update Filter via RPC
199 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
200 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
201 Post To Controller ${session} update-filter ${data}
203 Prepare Add/Update Filter Data
204 [Documentation] Prepare XML payload for add-filter and update-filter RPCs. Payloads for both RPCs are the same.
205 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${policy}=auto-update
206 ${data} = CompareStream.Run_Keyword_If_At_Least_Else
223 [Documentation] Add Domain Filter via RPC from Node
224 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
225 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
226 Post To Controller ${session} add-domain-filter ${data}
229 [Documentation] Delete Filter via RPC from Node
230 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
231 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
232 Post To Controller ${session} delete-filter ${data}
235 [Documentation] Delete Filter via RPC from Node
236 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
237 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
238 Post To Controller ${session} delete-domain-filter ${data}
240 Should Contain Binding
241 [Documentation] Tests if data contains specified binding
242 [Arguments] ${resp} ${sgt} ${prefix}
243 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
244 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
246 Should Not Contain Binding
247 [Documentation] Tests if data doesn't contains specified binding
248 [Arguments] ${resp} ${sgt} ${prefix}
249 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
250 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
252 Should Contain Connection
253 [Documentation] Test if data contains specified connection
254 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
255 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
257 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
259 Should Not Contain Connection
260 [Documentation] Test if data doesn't contains specified connection
261 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
262 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
264 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
266 Bindings Should Contain
267 [Documentation] Retrieves bindings and verifies they contain given binding
268 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
269 ${resp} = Get Bindings domain=${domain} scope=${scope}
270 Should Contain Binding ${resp} ${sgt} ${prefix}
272 Bindings Should Not Contain
273 [Documentation] Retrieves bindings and verifies they do not contain given binding
274 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
275 ${resp} = Get Bindings domain=${domain} scope=${scope}
276 Should Not Contain Binding ${resp} ${sgt} ${prefix}
278 Connections Should Contain
279 [Documentation] Retrieves connections and verifies they contain given connection
280 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
281 ${resp} = Get Connections
282 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
284 Connections Should Not Contain
285 [Documentation] Retrieves connections and verifies they do not contain given connection
286 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
287 ${resp} = Get Connections
288 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
290 Setup Topology Complex
291 [Arguments] ${version}=version4 ${password}=none
292 FOR ${node} IN RANGE 2 6
293 Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
295 Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
297 BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
299 Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
300 Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
301 Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
302 Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
304 Add Bindings 10 10.10.10.10/32 127.0.0.1
305 Add Bindings 10 10.10.10.0/24 127.0.0.1
306 Add Bindings 10 10.10.0.0/16 127.0.0.1
307 Add Bindings 10 10.0.0.0/8 127.0.0.1
309 Verify Snapshot Was Pushed
310 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
311 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
312 ${output} = Utils.Run Command On Controller
314 ... cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
315 BuiltIn.Should Not Be Equal As Strings ${output} 0
318 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
319 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
320 CompareStream.Run_Keyword_If_At_Least_Fluorine
321 ... Add Domain Fluorine
328 CompareStream.Run_Keyword_If_At_Most_Oxygen
329 ... Add Domain Oxygen
337 [Documentation] Add Domain with bindings (with origin) via RPC
338 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
339 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
340 Post To Controller ${session} add-domain ${data}
343 [Documentation] Add Domain with bindings (without origin) via RPC
344 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
345 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
346 Post To Controller ${session} add-domain ${data}
349 [Documentation] Delete Domain via RPC
350 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
351 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
352 Post To Controller ${session} delete-domain ${data}
355 [Documentation] Add Bindings to Node specified by range
356 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
357 ${prefixes} = Sxp.Prefix Range ${start} ${size}
358 Add Bindings ${sgt} ${prefixes} ${node}
360 Delete Bindings Range
361 [Documentation] Delete Bindings to Node specified by range
362 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
363 ${prefixes} = Sxp.Prefix Range ${start} ${size}
364 Delete Bindings ${sgt} ${prefixes} ${node}
367 [Documentation] Check if Node contains Bindings specified by range
368 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
369 ${resp} = Get Bindings ${node}
370 FOR ${num} IN RANGE ${start} ${end}
371 ${ip} = Sxp.Get Ip From Number ${num}
372 Should Contain Binding ${resp} ${sgt} ${ip}/32
375 Check Binding Range Negative
376 [Documentation] Check if Node does not contains Bindings specified by range
377 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
378 ${resp} = Get Bindings ${node}
379 FOR ${num} IN RANGE ${start} ${end}
380 ${ip} = Sxp.Get Ip From Number ${num}
381 Should Not Contain Binding ${resp} ${sgt} ${ip}/32
384 Setup SXP Environment
385 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
386 [Arguments] ${node_range}=1
387 RequestsLibrary.Create Session
389 ... http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
391 ... timeout=${DEFAULT_TIMEOUT_HTTP}
393 FOR ${num} IN RANGE 1 ${node_range}+1
394 ${node} = Sxp.Get Ip From Number ${num}
395 Add Node ${node} retry_open_timer=${num}
396 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
400 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
401 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
402 ${resp} = RequestsLibrary.Get Request
404 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
405 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
406 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
407 BuiltIn.Should Be Equal As Strings ${rc} 0
410 [Documentation] Verify that SxpNode has data removed from Operational datastore and is not running
411 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
412 ${resp} = RequestsLibrary.Get Request
414 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
415 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
416 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
417 BuiltIn.Should Be Equal As Strings ${rc} 1
419 Get Node Running Status
420 [Documentation] Get status if node is running by checking that netty server is running
421 [Arguments] ${node} ${port} ${system} ${session} ${ip}
422 ${rc} = Utils.Run Command On Remote System
424 ... netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1
425 ... ${ODL_SYSTEM_USER}
426 ... ${ODL_SYSTEM_PASSWORD}
427 ... prompt=${ODL_SYSTEM_PROMPT}
430 Clean SXP Environment
431 [Documentation] Destroy created sessions
432 [Arguments] ${node_range}=1
433 FOR ${num} IN RANGE 1 ${node_range}+1
434 ${ip} = Sxp.Get Ip From Number ${num}
436 BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Node Stopped ${ip} system=${ODL_SYSTEM_IP}
438 RequestsLibrary.Delete All Sessions
440 Get Routing Configuration From Controller
441 [Documentation] Get Routing configuration from config DS
442 [Arguments] ${session}
443 ${resp} = RequestsLibrary.Get Request
445 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
446 ... headers=${ACCEPT_XML}
447 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.text} ${EMPTY}
450 Put Routing Configuration To Controller
451 [Documentation] Put Routing configuration to Config DS
452 [Arguments] ${data} ${session}
453 ${resp} = RequestsLibrary.Put Request
455 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
457 ... headers=${HEADERS_XML}
459 BuiltIn.Should Match "${resp.status_code}" "20?"
461 Clean Routing Configuration To Controller
462 [Documentation] Delete Routing configuration from Config DS
463 [Arguments] ${session}
464 ${resp} = RequestsLibrary.Get Request
466 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
467 ... headers=${ACCEPT_XML}
468 IF "${resp.status_code}" == "200"
469 RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/