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} = Add Filter Xml
215 [Documentation] Add Domain Filter via RPC from Node
216 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
217 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
218 Post To Controller ${session} add-domain-filter ${data}
221 [Documentation] Delete Filter via RPC from Node
222 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
223 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
224 Post To Controller ${session} delete-filter ${data}
227 [Documentation] Delete Filter via RPC from Node
228 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
229 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
230 Post To Controller ${session} delete-domain-filter ${data}
232 Should Contain Binding
233 [Documentation] Tests if data contains specified binding
234 [Arguments] ${resp} ${sgt} ${prefix}
235 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
236 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
238 Should Not Contain Binding
239 [Documentation] Tests if data doesn't contains specified binding
240 [Arguments] ${resp} ${sgt} ${prefix}
241 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
242 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
244 Should Contain Connection
245 [Documentation] Test if data contains specified connection
246 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
247 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
249 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
251 Should Not Contain Connection
252 [Documentation] Test if data doesn't contains specified connection
253 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
254 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
256 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
258 Bindings Should Contain
259 [Documentation] Retrieves bindings and verifies they contain given binding
260 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
261 ${resp} = Get Bindings domain=${domain} scope=${scope}
262 Should Contain Binding ${resp} ${sgt} ${prefix}
264 Bindings Should Not Contain
265 [Documentation] Retrieves bindings and verifies they do not contain given binding
266 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
267 ${resp} = Get Bindings domain=${domain} scope=${scope}
268 Should Not Contain Binding ${resp} ${sgt} ${prefix}
270 Connections Should Contain
271 [Documentation] Retrieves connections and verifies they contain given connection
272 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
273 ${resp} = Get Connections
274 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
276 Connections Should Not Contain
277 [Documentation] Retrieves connections and verifies they do not contain given connection
278 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
279 ${resp} = Get Connections
280 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
282 Setup Topology Complex
283 [Arguments] ${version}=version4 ${password}=none
284 FOR ${node} IN RANGE 2 6
285 Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
287 Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
289 BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
291 Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
292 Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
293 Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
294 Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
296 Add Bindings 10 10.10.10.10/32 127.0.0.1
297 Add Bindings 10 10.10.10.0/24 127.0.0.1
298 Add Bindings 10 10.10.0.0/16 127.0.0.1
299 Add Bindings 10 10.0.0.0/8 127.0.0.1
301 Verify Snapshot Was Pushed
302 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
303 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
304 ${output} = Utils.Run Command On Controller
306 ... cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
307 BuiltIn.Should Not Be Equal As Strings ${output} 0
310 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
311 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
312 CompareStream.Run_Keyword_If_At_Least_Fluorine
313 ... Add Domain Fluorine
320 CompareStream.Run_Keyword_If_At_Most_Oxygen
321 ... Add Domain Oxygen
329 [Documentation] Add Domain with bindings (with origin) via RPC
330 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
331 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
332 Post To Controller ${session} add-domain ${data}
335 [Documentation] Add Domain with bindings (without origin) via RPC
336 [Arguments] ${domain_name} ${sgt} ${prefixes} ${node} ${session}
337 ${data} = Sxp.Add Domain Xml Oxygen ${node} ${domain_name} ${sgt} ${prefixes}
338 Post To Controller ${session} add-domain ${data}
341 [Documentation] Delete Domain via RPC
342 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
343 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
344 Post To Controller ${session} delete-domain ${data}
347 [Documentation] Add Bindings to Node specified by range
348 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
349 ${prefixes} = Sxp.Prefix Range ${start} ${size}
350 Add Bindings ${sgt} ${prefixes} ${node}
352 Delete Bindings Range
353 [Documentation] Delete Bindings to Node specified by range
354 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
355 ${prefixes} = Sxp.Prefix Range ${start} ${size}
356 Delete Bindings ${sgt} ${prefixes} ${node}
359 [Documentation] Check if Node contains Bindings specified by range
360 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
361 ${resp} = Get Bindings ${node}
362 FOR ${num} IN RANGE ${start} ${end}
363 ${ip} = Sxp.Get Ip From Number ${num}
364 Should Contain Binding ${resp} ${sgt} ${ip}/32
367 Check Binding Range Negative
368 [Documentation] Check if Node does not contains Bindings specified by range
369 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
370 ${resp} = Get Bindings ${node}
371 FOR ${num} IN RANGE ${start} ${end}
372 ${ip} = Sxp.Get Ip From Number ${num}
373 Should Not Contain Binding ${resp} ${sgt} ${ip}/32
376 Setup SXP Environment
377 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
378 [Arguments] ${node_range}=1
379 RequestsLibrary.Create Session
381 ... http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
383 ... timeout=${DEFAULT_TIMEOUT_HTTP}
385 FOR ${num} IN RANGE 1 ${node_range}+1
386 ${node} = Sxp.Get Ip From Number ${num}
387 Add Node ${node} retry_open_timer=${num}
388 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
392 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
393 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
394 ${resp} = RequestsLibrary.Get Request
396 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
397 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
398 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
399 BuiltIn.Should Be Equal As Strings ${rc} 0
402 [Documentation] Verify that SxpNode has data removed from Operational datastore and is not running
403 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
404 ${resp} = RequestsLibrary.Get Request
406 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
407 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
408 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
409 BuiltIn.Should Be Equal As Strings ${rc} 1
411 Get Node Running Status
412 [Documentation] Get status if node is running by checking that netty server is running
413 [Arguments] ${node} ${port} ${system} ${session} ${ip}
414 ${rc} = Utils.Run Command On Remote System
416 ... netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1
417 ... ${ODL_SYSTEM_USER}
418 ... ${ODL_SYSTEM_PASSWORD}
419 ... prompt=${ODL_SYSTEM_PROMPT}
422 Clean SXP Environment
423 [Documentation] Destroy created sessions
424 [Arguments] ${node_range}=1
425 FOR ${num} IN RANGE 1 ${node_range}+1
426 ${ip} = Sxp.Get Ip From Number ${num}
428 BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Node Stopped ${ip} system=${ODL_SYSTEM_IP}
430 RequestsLibrary.Delete All Sessions
432 Get Routing Configuration From Controller
433 [Documentation] Get Routing configuration from config DS
434 [Arguments] ${session}
435 ${resp} = RequestsLibrary.Get Request
437 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
438 ... headers=${ACCEPT_XML}
439 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.text} ${EMPTY}
442 Put Routing Configuration To Controller
443 [Documentation] Put Routing configuration to Config DS
444 [Arguments] ${data} ${session}
445 ${resp} = RequestsLibrary.Put Request
447 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
449 ... headers=${HEADERS_XML}
451 BuiltIn.Should Match "${resp.status_code}" "20?"
453 Clean Routing Configuration To Controller
454 [Documentation] Delete Routing configuration from Config DS
455 [Arguments] ${session}
456 ${resp} = RequestsLibrary.Get Request
458 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
459 ... headers=${ACCEPT_XML}
460 IF "${resp.status_code}" == "200"
461 RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/