2 Documentation Library containing Keywords used for SXP testing
5 Library RequestsLibrary
7 Resource KarafKeywords.robot
8 Resource TemplatedRequests.robot
10 Resource ../variables/Variables.robot
14 ${REST_CONTEXT} /restconf/operations/sxp-controller
19 [Documentation] Post request to Controller and checks response
20 [Arguments] ${session} ${path} ${data} ${rest_context}=${REST_CONTEXT}
21 ${resp} = RequestsLibrary.Post Request
23 ... ${rest_context}:${path}
25 ... headers=${HEADERS_XML}
30 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
31 ${content} = BuiltIn.Evaluate json.loads('''${resp.text}''') json
32 ${output} = collections.Get From Dictionary ${content} output
33 ${result} = collections.Get From Dictionary ${output} result
34 BuiltIn.Should Be True ${result} RPC result is False
37 [Documentation] Add node via RPC to ODL
38 [Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${node}
39 ... ${ssl_stores}=${EMPTY} ${retry_open_timer}=1
40 ${data} = Sxp.Add Node Xml ${node} ${port} ${password} ${version} ${ip}
41 ... keystores=${ssl_stores} retry_open_timer=${retry_open_timer}
42 Post To Controller ${session} add-node ${data}
45 [Documentation] Delete connection via RPC from node
46 [Arguments] ${node} ${session}=session
47 ${data} = Sxp.Delete Node Xml ${node}
48 Post To Controller ${session} delete-node ${data}
51 [Documentation] Add connection via RPC to node
52 [Arguments] ${version} ${mode} ${ip} ${port} ${node}=127.0.0.1 ${password}=${EMPTY}
53 ... ${session}=session ${domain}=global ${security_mode}=${EMPTY}
54 ${data} = Sxp.Add Connection Xml ${version} ${mode} ${ip} ${port} ${node}
55 ... ${password} ${domain} security_mode=${security_mode}
56 Post To Controller ${session} add-connection ${data}
59 [Documentation] Gets all connections via RPC from node
60 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
61 ${data} = Sxp.Get Connections From Node Xml ${node} ${domain}
62 ${resp} = RequestsLibrary.Post Request
64 ... ${REST_CONTEXT}:get-connections
66 ... headers=${HEADERS_XML}
67 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
71 [Documentation] Delete connection via RPC from node
72 [Arguments] ${ip} ${port} ${node}=127.0.0.1 ${session}=session ${domain}=global
73 ${data} = Sxp.Delete Connections Xml ${ip} ${port} ${node} ${domain}
74 Post To Controller ${session} delete-connection ${data}
77 [Documentation] Delete all connections via RPC from node
78 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global
79 ${resp} = Get Connections ${node} ${session} ${domain}
80 @{connections} = Sxp.Parse Connections ${resp}
81 FOR ${connection} IN @{connections}
83 ... ${connection['peer-address']}
84 ... ${connection['tcp-port']}
91 [Documentation] Verify that connection is ON
92 [Arguments] ${version} ${mode} ${ip} ${port}=64999 ${node}=127.0.0.1 ${state}=on
93 ... ${session}=session ${domain}=global
94 ${resp} = Get Connections ${node} ${session} ${domain}
95 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
98 [Documentation] Based on ODL version decide if bindings will be added with or without origin type (introduced in Fluorine)
99 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global ${origin}=LOCAL
100 Add Bindings Fluorine
108 Add Bindings Fluorine
109 [Documentation] Add/Update one or more bindings with origin type via RPC to Master DB of the node
110 [Arguments] ${sgt} ${prefixes} ${node} ${session} ${domain} ${origin}
111 ${data} = Sxp.Add Bindings Xml Fluorine ${node} ${domain} ${sgt} ${prefixes} ${origin}
112 Post To Controller ${session} add-bindings ${data}
115 [Documentation] Gets all binding via RPC from Master DB of node
116 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=all
117 ${data} = Sxp.Get Bindings From Node Xml ${node} ${scope} ${domain}
118 ${resp} = TemplatedRequests.Post_To_Uri
119 ... ${REST_CONTEXT}:get-node-bindings
121 ... accept=${ACCEPT_JSON}
122 ... content_type=${HEADERS_XML}
123 ... session=${session}
127 [Documentation] Delete all bindings via RPC from Master DB of node
128 [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=local
129 ${resp} = Get Bindings ${node} ${session} ${domain} ${scope}
130 @{bindings} = Sxp.Parse Bindings ${resp}
131 FOR ${binding} IN @{bindings}
132 @{prefixes_list} = collections.Get From Dictionary ${binding} ip-prefix
133 ${prefixes} = BuiltIn.Catenate SEPARATOR=, @{prefixes_list}
134 Delete Bindings ${binding['sgt']} ${prefixes} ${node} ${domain} ${session}
138 [Documentation] Delete one or more bindings via RPC from Master DB of node
139 [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${domain}=global ${session}=session
140 ${data} = Sxp.Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes}
141 Post To Controller ${session} delete-bindings ${data}
144 [Documentation] Adds new PeerGroup via RPC to Node
145 [Arguments] ${name} ${peers}= ${node}=127.0.0.1 ${session}=session
146 ${data} = Sxp.Add Peer Group Xml ${name} ${peers} ${node}
147 Post To Controller ${session} add-peer-group ${data}
150 [Documentation] Delete PeerGroup via RPC from Node
151 [Arguments] ${name} ${node}=127.0.0.1 ${session}=session
152 ${data} = Sxp.Delete Peer Group Xml ${name} ${node}
153 Post To Controller ${session} delete-peer-group ${data}
156 [Documentation] Gets all PeerGroups via RPC from node
157 [Arguments] ${node}=127.0.0.1 ${session}=session
158 ${data} = Sxp.Get Peer Groups From Node Xml ${node}
159 ${resp} = RequestsLibrary.Post Request
161 ... ${REST_CONTEXT}:get-peer-groups
163 ... headers=${HEADERS_XML}
164 BuiltIn.Should be Equal As Strings ${resp.status_code} 200
168 [Documentation] Delete all PeerGroups via RPC from node
169 [Arguments] ${node}=127.0.0.1 ${session}=session
170 ${resp} = Get Peer Groups ${node} ${session}
171 @{prefixes} = Sxp.Parse Peer Groups ${resp}
172 FOR ${group} IN @{prefixes}
173 Delete Peer Group ${group['name']} ${node} ${session}
177 [Documentation] Add Filter via RPC from Node
178 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
179 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
180 Post To Controller ${session} add-filter ${data}
183 [Documentation] Update Filter via RPC
184 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${session}=session ${policy}=auto-update
185 ${data} = Prepare Add/Update Filter Data ${name} ${type} ${entries} ${node} ${policy}
186 Post To Controller ${session} update-filter ${data}
188 Prepare Add/Update Filter Data
189 [Documentation] Prepare XML payload for add-filter and update-filter RPCs. Payloads for both RPCs are the same.
190 [Arguments] ${name} ${type} ${entries} ${node}=127.0.0.1 ${policy}=auto-update
191 ${data} = Add Filter Xml
200 [Documentation] Add Domain Filter via RPC from Node
201 [Arguments] ${name} ${domains} ${entries} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
202 ${data} = Sxp.Add Domain Filter Xml ${name} ${domains} ${entries} ${node} ${filter_name}
203 Post To Controller ${session} add-domain-filter ${data}
206 [Documentation] Delete Filter via RPC from Node
207 [Arguments] ${name} ${type} ${node}=127.0.0.1 ${session}=session
208 ${data} = Sxp.Delete Filter Xml ${name} ${type} ${node}
209 Post To Controller ${session} delete-filter ${data}
212 [Documentation] Delete Filter via RPC from Node
213 [Arguments] ${name} ${node}=127.0.0.1 ${filter_name}=base-domain-filter ${session}=session
214 ${data} = Sxp.Delete Domain Filter Xml ${name} ${node} ${filter_name}
215 Post To Controller ${session} delete-domain-filter ${data}
217 Should Contain Binding
218 [Documentation] Tests if data contains specified binding
219 [Arguments] ${resp} ${sgt} ${prefix}
220 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
221 BuiltIn.Should Be True ${out} Doesn't have ${sgt} ${prefix}
223 Should Not Contain Binding
224 [Documentation] Tests if data doesn't contains specified binding
225 [Arguments] ${resp} ${sgt} ${prefix}
226 ${out} = Sxp.Find Binding ${resp} ${sgt} ${prefix}
227 BuiltIn.Should Not Be True ${out} Should't have ${sgt} ${prefix}
229 Should Contain Connection
230 [Documentation] Test if data contains specified connection
231 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
232 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
234 BuiltIn.Should Be True ${out} Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
236 Should Not Contain Connection
237 [Documentation] Test if data doesn't contains specified connection
238 [Arguments] ${resp} ${ip} ${port} ${mode} ${version} ${state}=none
239 ${out} = Sxp.Find Connection ${resp} ${version} ${mode} ${ip} ${port}
241 BuiltIn.Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version}
243 Bindings Should Contain
244 [Documentation] Retrieves bindings and verifies they contain given binding
245 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
246 ${resp} = Get Bindings domain=${domain} scope=${scope}
247 Should Contain Binding ${resp} ${sgt} ${prefix}
249 Bindings Should Not Contain
250 [Documentation] Retrieves bindings and verifies they do not contain given binding
251 [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all
252 ${resp} = Get Bindings domain=${domain} scope=${scope}
253 Should Not Contain Binding ${resp} ${sgt} ${prefix}
255 Connections Should Contain
256 [Documentation] Retrieves connections and verifies they contain given connection
257 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
258 ${resp} = Get Connections
259 Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
261 Connections Should Not Contain
262 [Documentation] Retrieves connections and verifies they do not contain given connection
263 [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none
264 ${resp} = Get Connections
265 Should Not Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state}
267 Setup Topology Complex
268 [Arguments] ${version}=version4 ${password}=none
269 FOR ${node} IN RANGE 2 6
270 Add Connection ${version} both 127.0.0.1 64999 127.0.0.${node}
272 Add Connection ${version} both 127.0.0.${node} 64999 127.0.0.1
274 BuiltIn.Wait Until Keyword Succeeds 15 1 Verify Connection ${version} both
276 Add Bindings ${node}0 10.10.10.${node}0/32 127.0.0.${node}
277 Add Bindings ${node}0 10.10.${node}0.0/24 127.0.0.${node}
278 Add Bindings ${node}0 10.${node}0.0.0/16 127.0.0.${node}
279 Add Bindings ${node}0 ${node}0.0.0.0/8 127.0.0.${node}
281 Add Bindings 10 10.10.10.10/32 127.0.0.1
282 Add Bindings 10 10.10.10.0/24 127.0.0.1
283 Add Bindings 10 10.10.0.0/16 127.0.0.1
284 Add Bindings 10 10.0.0.0/8 127.0.0.1
286 Verify Snapshot Was Pushed
287 [Documentation] Will succeed if the ${snapshot_string} is found in the karaf logs
288 [Arguments] ${snapshot_string}=22-sxp-controller-one-node.xml
289 ${output} = Utils.Run Command On Controller
291 ... cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
292 BuiltIn.Should Not Be Equal As Strings ${output} 0
295 [Documentation] Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
296 [Arguments] ${domain_name} ${sgt}=None ${prefixes}=None ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session
306 [Documentation] Add Domain with bindings (with origin) via RPC
307 [Arguments] ${domain_name} ${sgt} ${prefixes} ${origin} ${node} ${session}
308 ${data} = Sxp.Add Domain Xml Fluorine ${node} ${domain_name} ${sgt} ${prefixes} ${origin}
309 Post To Controller ${session} add-domain ${data}
312 [Documentation] Delete Domain via RPC
313 [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session
314 ${data} = Sxp.Delete Domain Xml ${node} ${domain_name}
315 Post To Controller ${session} delete-domain ${data}
318 [Documentation] Add Bindings to Node specified by range
319 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
320 ${prefixes} = Sxp.Prefix Range ${start} ${size}
321 Add Bindings ${sgt} ${prefixes} ${node}
323 Delete Bindings Range
324 [Documentation] Delete Bindings to Node specified by range
325 [Arguments] ${sgt} ${start} ${size} ${node}=127.0.0.1
326 ${prefixes} = Sxp.Prefix Range ${start} ${size}
327 Delete Bindings ${sgt} ${prefixes} ${node}
330 [Documentation] Check if Node contains Bindings specified by range
331 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
332 ${resp} = Get Bindings ${node}
333 FOR ${num} IN RANGE ${start} ${end}
334 ${ip} = Sxp.Get Ip From Number ${num}
335 Should Contain Binding ${resp} ${sgt} ${ip}/32
338 Check Binding Range Negative
339 [Documentation] Check if Node does not contains Bindings specified by range
340 [Arguments] ${sgt} ${start} ${end} ${node}=127.0.0.1
341 ${resp} = Get Bindings ${node}
342 FOR ${num} IN RANGE ${start} ${end}
343 ${ip} = Sxp.Get Ip From Number ${num}
344 Should Not Contain Binding ${resp} ${sgt} ${ip}/32
347 Setup SXP Environment
348 [Documentation] Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
349 [Arguments] ${node_range}=1
350 RequestsLibrary.Create Session
352 ... http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
354 ... timeout=${DEFAULT_TIMEOUT_HTTP}
356 FOR ${num} IN RANGE 1 ${node_range}+1
357 ${node} = Sxp.Get Ip From Number ${num}
358 Add Node ${node} retry_open_timer=${num}
359 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Node Started ${node} system=${ODL_SYSTEM_IP}
363 [Documentation] Verify that SxpNode has data writen to Operational datastore and is running
364 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
365 ${resp} = RequestsLibrary.Get Request
367 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
368 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
369 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
370 BuiltIn.Should Be Equal As Strings ${rc} 0
373 [Documentation] Verify that SxpNode has data removed from Operational datastore and is not running
374 [Arguments] ${node} ${port}=64999 ${system}=${node} ${session}=session ${ip}=${node}
375 ${resp} = RequestsLibrary.Get Request
377 ... /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
378 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
379 ${rc} = Get Node Running Status ${node} ${port} ${system} ${session} ${ip}
380 BuiltIn.Should Be Equal As Strings ${rc} 1
382 Get Node Running Status
383 [Documentation] Get status if node is running by checking that netty server is running
384 [Arguments] ${node} ${port} ${system} ${session} ${ip}
385 ${rc} = Utils.Run Command On Remote System
387 ... netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1
388 ... ${ODL_SYSTEM_USER}
389 ... ${ODL_SYSTEM_PASSWORD}
390 ... prompt=${ODL_SYSTEM_PROMPT}
393 Clean SXP Environment
394 [Documentation] Destroy created sessions
395 [Arguments] ${node_range}=1
396 FOR ${num} IN RANGE 1 ${node_range}+1
397 ${ip} = Sxp.Get Ip From Number ${num}
399 BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Node Stopped ${ip} system=${ODL_SYSTEM_IP}
401 RequestsLibrary.Delete All Sessions
403 Get Routing Configuration From Controller
404 [Documentation] Get Routing configuration from config DS
405 [Arguments] ${session}
406 ${resp} = RequestsLibrary.Get Request
408 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
409 ... headers=${ACCEPT_XML}
410 ${data} = BuiltIn.Set Variable If "${resp.status_code}" == "200" ${resp.text} ${EMPTY}
413 Put Routing Configuration To Controller
414 [Documentation] Put Routing configuration to Config DS
415 [Arguments] ${data} ${session}
416 ${resp} = RequestsLibrary.Put Request
418 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
420 ... headers=${HEADERS_XML}
422 BuiltIn.Should Match "${resp.status_code}" "20?"
424 Clean Routing Configuration To Controller
425 [Documentation] Delete Routing configuration from Config DS
426 [Arguments] ${session}
427 ${resp} = RequestsLibrary.Get Request
429 ... /restconf/config/sxp-cluster-route:sxp-cluster-route/
430 ... headers=${ACCEPT_XML}
431 IF "${resp.status_code}" == "200"
432 RequestsLibrary.Delete Request ${session} /restconf/config/sxp-cluster-route:sxp-cluster-route/