Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / libraries / TopoprocessingKeywords.robot
1 *** Settings ***
2 Variables       ../variables/Variables.py
3 Variables       ../variables/topoprocessing/Topologies.py
4 Variables       ../variables/topoprocessing/TopologyRequests.py
5 Library         RequestsLibrary
6 Library         SSHLibrary
7 Library         XML
8 Resource        CompareStream.robot
9 Resource        KarafKeywords.robot
10 Resource        SetupUtils.robot
11 Resource        Utils.robot
12
13
14 *** Variables ***
15 ${CONFIGURATION_XML}    ${CURDIR}/../suites/topoprocessing/configuration.xml
16 ${OPERATIONAL_XML}      ${CURDIR}/../suites/topoprocessing/operational.xml
17 ${CONFIGURATION_CFG}    ${CURDIR}/../suites/topoprocessing/configuration.cfg
18 ${OPERATIONAL_CFG}      ${CURDIR}/../suites/topoprocessing/operational.cfg
19 ${REMOTE_XML_FILE}      ${WORKSPACE}/${BUNDLEFOLDER}/etc/opendaylight/karaf/80-topoprocessing-config.xml
20 ${REMOTE_CFG_FILE}      ${WORKSPACE}/${BUNDLEFOLDER}/etc/org.opendaylight.topoprocessing.cfg
21 ${OUTPUT_TOPO_NAME}     topo:1
22 ${OVERLAY_TOPO_URL}     ${TOPOLOGY_URL}/${OUTPUT_TOPO_NAME}
23
24
25 *** Keywords ***
26 Basic Request Put
27     [Documentation]    Send a simple HTTP PUT request to Configurational datastore
28     [Arguments]    ${request}    ${overlay_topology_url}
29     ${resp}    Put Request    session    ${CONFIG_API}/${overlay_topology_url}    data=${request}
30     Log    ${CONFIG_API}/${overlay_topology_url}
31     Should Match    "${resp.status_code}"    "20?"
32     Wait For Karaf Log    Correlation configuration successfully read
33     Wait For Karaf Log    Transaction successfully written
34
35 Basic Request Get
36     [Documentation]    Send a simple HTTP GET request to a given URL
37     [Arguments]    ${overlay_topology_url}
38     ${resp}    Get On Session   session    ${OPERATIONAL_API}/${overlay_topology_url}    expected_status=200
39     RETURN    ${resp}
40
41 Send Basic Delete Request
42     [Documentation]    Sends a HTTP/DELETE request to a given URL
43     [Arguments]    ${url}
44     ${resp}    Delete Request    session    ${CONFIG_API}/${url}
45     Log    Deleting ${CONFIG_API}/${url}
46     RETURN    ${resp}
47
48 Delete Underlay Node
49     [Documentation]    Deletes a node from an underlay topology
50     [Arguments]    ${topology-id}    ${node-id}
51     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/node/${node-id}
52     RETURN    ${resp}
53
54 Delete Underlay Termination Point
55     [Documentation]    Deletes a termination point from an underlay topology
56     [Arguments]    ${topology-id}    ${node-id}    ${tp-id}
57     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/node/${node-id}/termination-point/${tp-id}
58     RETURN    ${resp}
59
60 Delete Underlay Link
61     [Documentation]    Deletes a link from an underlay topology
62     [Arguments]    ${topology-id}    ${link-id}
63     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/link/${link-id}
64     RETURN    ${resp}
65
66 Setup Environment
67     [Documentation]    Setup karaf enviroment for following tests
68     Log    ---- Setup Environment ----
69     SetupUtils.Setup_Utils_For_Setup_And_Teardown
70     Open Connection    ${ODL_SYSTEM_IP}
71     Flexible Controller Login
72     Put File    ${CONFIGURATION_CFG}    ${REMOTE_CFG_FILE}
73     Close Connection
74     Wait Until Keyword Succeeds
75     ...    2x
76     ...    2s
77     ...    Issue Command On Karaf Console
78     ...    log:set DEBUG org.opendaylight.topoprocessing
79     Create Session
80     ...    session
81     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
82     ...    auth=${AUTH}
83     ...    headers=${SEND_ACCEPT_XML_HEADERS}
84     Prepare New Feature Installation
85     Insert Underlay topologies
86
87 Install Features
88     [Documentation]    Install features according to tested distribution
89     [Arguments]    ${features}    ${timeout}=180
90     Install Features for Other Distributions    ${features}    ${timeout}
91
92 Install Features for Beryllium Distribution
93     [Documentation]    Will wait for features to install only once per run
94     [Arguments]    ${features}    ${timeout}
95     Install a Feature    ${features}    timeout=${timeout}
96     Set Global Variable If It Does Not Exist    \${WAIT_FOR_FEATURES_TO_INSTALL}    ${TRUE}
97     IF    ${WAIT_FOR_FEATURES_TO_INSTALL}
98         Wait For Karaf Log    Registering Topology Request Listener    ${timeout}
99         Set Global Variable    \${WAIT_FOR_FEATURES_TO_INSTALL}    ${FALSE}
100     END
101
102 Install Features for Other Distributions
103     [Documentation]    Will wait for features to install only if no topoprocessing feature was installed
104     [Arguments]    ${features}    ${timeout}
105     ${installed_features}    Issue Command On Karaf Console    feature:list -i
106     ${lines}    Get Lines Containing String    ${installed_features}    odl-topoprocessing-framework
107     ${length}    Get Length    ${lines}
108     Install a Feature    ${features}    timeout=${timeout}
109     IF    ${length} == 0
110         Wait For Karaf Log    Registering Topology Request Listener    ${timeout}
111     END
112
113 Clean Environment
114     [Documentation]    Revert startup changes
115     Log    ---- Clean Environment ----
116     Open Connection    ${ODL_SYSTEM_IP}
117     Flexible Controller Login
118     Put File    ${OPERATIONAL_CFG}    ${REMOTE_CFG_FILE}
119     Close Connection
120     Delete All Sessions
121
122 Delete Overlay Topology
123     [Documentation]    Delete overlay topologies from datastore
124     Run Keyword If Test Failed    Print Output Topo
125     Log    ---- Test Teardown ----
126     Log    Deleting overlay topology from ${CONFIG_API}/${OVERLAY_TOPO_URL}
127     ${resp}    Delete Request    session    ${CONFIG_API}/${OVERLAY_TOPO_URL}
128     Should Be Equal As Strings    ${resp.status_code}    200
129
130 Print Output Topo
131     [Documentation]    Waits a while to allow any hanging transactions to finnish and then logs the output topology
132     Log    ---- Output Topo Dump After Cooldown----
133     Sleep    2s
134     ${resp}    Wait Until Keyword Succeeds    5x    250ms    Basic Request Get    ${OVERLAY_TOPO_URL}
135     Log    ${resp.text}
136
137 Refresh Underlay Topologies And Delete Overlay Topology
138     [Documentation]    Deletes given overlay topology from datastore and overwrites the underlaying ones with initial topologies
139     Delete Overlay Topology
140     Insert Underlay Topologies
141
142 Prepare New Feature Installation
143     [Documentation]    Clears karaf logs and CONFIGURATION datastore
144     ${resp}    Delete Request    session    ${CONFIG_API}/network-topology:network-topology
145     ${resp}    Delete Request    session    ${CONFIG_API}/opendaylight-inventory:nodes
146     Issue Command On Karaf Console    log:clear
147
148 Insert Underlay Topologies
149     [Documentation]    Insert underlay topologies used by following tests
150     Log    Inserting underlay topologies
151     # Network underlay topologies
152     FOR    ${index}    IN RANGE    1    7
153         ${resp}    Put Request
154         ...    session
155         ...    ${CONFIG_API}/${TOPOLOGY_URL}/network-topo:${index}
156         ...    data=${NETWORK_UNDERLAY_TOPOLOGY_${index}}
157         Log    ${resp.text}
158         Should Match    "${resp.status_code}"    "20?"
159         # Openflow underlay nodes
160     END
161     ${resp}    Put Request    session    ${CONFIG_API}/opendaylight-inventory:nodes    data=${OPENFLOW_UNDERLAY_NODES}
162     Log    ${resp.text}
163     Should Match    "${resp.status_code}"    "20?"
164     # Openflow underlay topologies
165     FOR    ${index}    IN RANGE    1    7
166         ${resp}    Put Request
167         ...    session
168         ...    ${CONFIG_API}/${TOPOLOGY_URL}/openflow-topo:${index}
169         ...    data=${OPENFLOW_UNDERLAY_TOPOLOGY_${index}}
170         Log    ${resp.text}
171         Should Match    "${resp.status_code}"    "20?"
172     END
173     Issue Command On Karaf Console    log:clear
174     Log    ${resp.text}
175
176 Prepare Unification Inside Topology Request
177     [Documentation]    Prepare topology request for unification inside from template
178     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo1}
179     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
180     ${request_template}    Set Element Text
181     ...    ${request_template}
182     ...    aggregation-only
183     ...    xpath=.//correlations/correlation/type
184     ${request_template}    Set Element Text
185     ...    ${request_template}
186     ...    ${correlation_item}
187     ...    xpath=.//correlation/correlation-item
188     ${request_template}    Set Element Text
189     ...    ${request_template}
190     ...    unification
191     ...    xpath=.//correlation/aggregation/aggregation-type
192     ${request_template}    Set Element Text
193     ...    ${request_template}
194     ...    ${model}
195     ...    xpath=.//correlation/aggregation/mapping[1]/input-model
196     ${request_template}    Set Element Text
197     ...    ${request_template}
198     ...    ${underlay_topo1}
199     ...    xpath=.//correlation/aggregation/mapping[1]/underlay-topology
200     ${request_template}    Element to String    ${request_template}
201     RETURN    ${request_template}
202
203 Prepare Unification Topology Request
204     [Documentation]    Prepare topology request for unification on two topologies from template
205     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo1}    ${underlay_topo2}
206     ${request_template}    Prepare Unification Inside Topology Request
207     ...    ${request_template}
208     ...    ${model}
209     ...    ${correlation_item}
210     ...    ${underlay_topo1}
211     ${request_template}    Set Element Text
212     ...    ${request_template}
213     ...    ${underlay_topo2}
214     ...    xpath=.//correlation/aggregation/mapping[2]/underlay-topology
215     ${request_template}    Set Element Text
216     ...    ${request_template}
217     ...    ${model}
218     ...    xpath=.//correlation/aggregation/mapping[2]/input-model
219     ${request_template}    Element to String    ${request_template}
220     RETURN    ${request_template}
221
222 Prepare Unification Filtration Topology Request
223     [Documentation]    Prepare topology request for unification on two topologies from template
224     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target_field1}    ${underlay_topo1}    ${target_field2}
225     ...    ${underlay_topo2}
226     ${request_template}    Prepare Unification Filtration Inside Topology Request
227     ...    ${request_template}
228     ...    ${model}
229     ...    ${correlation_item}
230     ...    ${target_field1}
231     ...    ${underlay_topo1}
232     ${request_template}    Set Element Text
233     ...    ${request_template}
234     ...    ${underlay_topo2}
235     ...    xpath=.//correlation/aggregation/mapping[2]/underlay-topology
236     Insert Target Field    ${request_template}    2    ${target_field2}    1
237     ${request_template}    Set Element Text
238     ...    ${request_template}
239     ...    ${model}
240     ...    xpath=.//correlation/aggregation/mapping[2]/input-model
241     ${request_template}    Element to String    ${request_template}
242     RETURN    ${request_template}
243
244 Prepare Unification Filtration Inside Topology Request
245     [Documentation]    Prepare topology request for unification filtration inside from template
246     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target-field}    ${underlay_topo}
247     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
248     ${request_template}    Set Element Text
249     ...    ${request_template}
250     ...    filtration-aggregation
251     ...    xpath=.//correlations/correlation/type
252     ${request_template}    Set Element Text
253     ...    ${request_template}
254     ...    ${correlation_item}
255     ...    xpath=.//correlation/correlation-item
256     ${request_template}    Set Element Text
257     ...    ${request_template}
258     ...    unification
259     ...    xpath=.//correlation/aggregation/aggregation-type
260     ${request_template}    Set Element Text
261     ...    ${request_template}
262     ...    ${model}
263     ...    xpath=.//correlation/aggregation/mapping[1]/input-model
264     ${request_template}    Set Element Text
265     ...    ${request_template}
266     ...    ${underlay_topo}
267     ...    xpath=.//correlation/aggregation/mapping[1]/underlay-topology
268     Insert Target Field    ${request_template}    1    ${target-field}    1
269     ${request_template}    Set Element Text
270     ...    ${request_template}
271     ...    ${underlay_topo}
272     ...    xpath=.//correlation/filtration/underlay-topology
273     ${request_template}    Element to String    ${request_template}
274     RETURN    ${request_template}
275
276 Insert Apply Filters
277     [Arguments]    ${request_template}    ${mapping}    ${filter_id}
278     ${request_template}    Add Element
279     ...    ${request_template}
280     ...    ${APPLY_FILTERS}
281     ...    xpath=.//correlation/aggregation/mapping[${mapping}]
282     ${request_template}    Set Element Text
283     ...    ${request_template}
284     ...    ${filter_id}
285     ...    xpath=.//correlation/aggregation/mapping[${mapping}]/apply-filters
286     RETURN    ${request_template}
287
288 Prepare Filtration Topology Request
289     [Documentation]    Prepare topology request for filtration from template
290     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo}
291     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
292     ${request_template}    Set Element Text
293     ...    ${request_template}
294     ...    ${correlation_item}
295     ...    xpath=.//correlation/correlation-item
296     ${request_template}    Set Element Text
297     ...    ${request_template}
298     ...    ${underlay_topo}
299     ...    xpath=.//correlation/filtration/underlay-topology
300     RETURN    ${request_template}
301
302 Insert Target Field
303     [Documentation]    Add target field to request
304     [Arguments]    ${request_template}    ${mapping_index}    ${target_field_path}    ${matching_key}
305     ${target_field_template}    Set Element Text
306     ...    ${TARGET_FIELD}
307     ...    ${target_field_path}
308     ...    xpath=.//target-field-path
309     ${target_field_template}    Set Element Text
310     ...    ${target_field_template}
311     ...    ${matching_key}
312     ...    xpath=.//matching-key
313     ${request_template}    Add Element
314     ...    ${request_template}
315     ...    ${target_field_template}
316     ...    xpath=.//correlation/aggregation/mapping[${mapping_index}]
317     ${request_template}    Element to String    ${request_template}
318     RETURN    ${request_template}
319
320 Insert Filter
321     [Documentation]    Add filter to filtration
322     [Arguments]    ${request_template}    ${filter_template}    ${target_field}
323     ${request_template}    Add Element    ${request_template}    ${filter_template}    xpath=.//correlation/filtration
324     ${model}    Get Element Text    ${request_template}    xpath=.//correlations/output-model
325     ${request_template}    Set Element Text
326     ...    ${request_template}
327     ...    ${model}
328     ...    xpath=.//correlation/filtration/filter/input-model
329     ${request_template}    Set Element Text
330     ...    ${request_template}
331     ...    ${target_field}
332     ...    xpath=.//correlation/filtration/filter/target-field
333     RETURN    ${request_template}
334
335 Insert Filter With ID
336     [Documentation]    Add filter to filtration with specified id
337     [Arguments]    ${request_template}    ${filter_template}    ${target_field}    ${filter_id}
338     ${request_template}    Insert Filter    ${request_template}    ${filter_template}    ${target_field}
339     ${request_template}    Set Element Text
340     ...    ${request_template}
341     ...    ${filter_id}
342     ...    xpath=.//correlation/filtration/filter/filter-id
343     RETURN    ${request_template}
344
345 Set IPV4 Filter
346     [Documentation]    Set filter ipv4 address
347     [Arguments]    ${request_template}    ${ip_address}
348     ${request_template}    Set Element Text
349     ...    ${request_template}
350     ...    ${ip_address}
351     ...    xpath=.//correlation/filtration/filter/ipv4-address-filter/ipv4-address
352     ${request_template}    Element to String    ${request_template}
353     RETURN    ${request_template}
354
355 Set Range Number Filter
356     [Documentation]    Set filter minimum and maximum number values
357     [Arguments]    ${request_template}    ${min_number}    ${max_number}
358     ${request_template}    Set Element Text
359     ...    ${request_template}
360     ...    ${min_number}
361     ...    xpath=.//correlation/filtration/filter/range-number-filter/min-number-value
362     ${request_template}    Set Element Text
363     ...    ${request_template}
364     ...    ${max_number}
365     ...    xpath=.//correlation/filtration/filter/range-number-filter/max-number-value
366     ${request_template}    Element to String    ${request_template}
367     RETURN    ${request_template}
368
369 Set Range String Filter
370     [Documentation]    Set filter minimum and maximum string values
371     [Arguments]    ${request_template}    ${min_value}    ${max_value}
372     ${request_template}    Set Element Text
373     ...    ${request_template}
374     ...    ${min_value}
375     ...    xpath=.//correlation/filtration/filter/range-string-filter/min-string-value
376     ${request_template}    Set Element Text
377     ...    ${request_template}
378     ...    ${max_value}
379     ...    xpath=.//correlation/filtration/filter/range-string-filter/max-string-value
380     ${request_template}    Element to String    ${request_template}
381     RETURN    ${request_template}
382
383 Set Specific Number Filter
384     [Documentation]    Set filter number value
385     [Arguments]    ${request_template}    ${number}
386     ${request_template}    Set Element Text
387     ...    ${request_template}
388     ...    ${number}
389     ...    xpath=.//correlation/filtration/filter/specific-number-filter/specific-number
390     ${request_template}    Element to String    ${request_template}
391     RETURN    ${request_template}
392
393 Set Specific String Filter
394     [Documentation]    Set filter string value
395     [Arguments]    ${request_template}    ${string_value}
396     ${request_template}    Set Element Text
397     ...    ${request_template}
398     ...    ${string_value}
399     ...    xpath=.//correlation/filtration/filter/specific-string-filter/specific-string
400     ${request_template}    Element to String    ${request_template}
401     RETURN    ${request_template}
402
403 Set IPV6 Filter
404     [Documentation]    Set filter ipv6 address
405     [Arguments]    ${request_template}    ${ip_address}
406     ${request_template}    Set Element Text
407     ...    ${request_template}
408     ...    ${ip_address}
409     ...    xpath=.//correlation/filtration/filter/ipv6-address-filter/ipv6-address
410     ${request_template}    Element to String    ${request_template}
411     RETURN    ${request_template}
412
413 Set Script Filter
414     [Documentation]    Set filter script
415     [Arguments]    ${request_template}    ${script_language}    ${script}
416     ${request_template}    Set Element Text
417     ...    ${request_template}
418     ...    ${script_language}
419     ...    xpath=.//correlation/filtration/filter/script-filter/scripting/language
420     ${request_template}    Set Element Text
421     ...    ${request_template}
422     ...    ${script}
423     ...    xpath=.//correlation/filtration/filter/script-filter/scripting/script
424     ${request_template}    Element to String    ${request_template}
425     RETURN    ${request_template}
426
427 Insert Link Computation Inside
428     [Documentation]    Add link computation to request
429     [Arguments]    ${request_template}    ${link_computation_template}    ${input_model}    ${underlay_topology}
430     ${request_template}    Add Element    ${request_template}    ${link_computation_template}    xpath=.
431     ${request_template}    Set Element Text
432     ...    ${request_template}
433     ...    ${input_model}
434     ...    xpath=.//link-computation/node-info/input-model
435     ${request_template}    Set Element Text
436     ...    ${request_template}
437     ...    ${input_model}
438     ...    xpath=.//link-computation/link-info/input-model
439     ${request_template}    Set Element Text
440     ...    ${request_template}
441     ...    ${input_model}
442     ...    xpath=.//link-computation/output-model
443     ${request_template}    Set Element Text
444     ...    ${request_template}
445     ...    ${underlay_topology}
446     ...    xpath=.//link-computation/link-info/link-topology
447     ${request_template}    Set Element Attribute
448     ...    ${request_template}
449     ...    xmlns:n
450     ...    urn:opendaylight:topology:correlation
451     ...    xpath=./link-computation
452     ${request_template}    Element to String    ${request_template}
453     RETURN    ${request_template}
454
455 Insert Link Computation
456     [Documentation]    Add link computation to request
457     [Arguments]    ${request_template}    ${link_computation_template}    ${input_model}    ${underlay_topology_1}    ${underlay_topology_2}
458     ${request_template}    Add Element    ${request_template}    ${link_computation_template}    xpath=.
459     ${request_template}    Set Element Text
460     ...    ${request_template}
461     ...    ${input_model}
462     ...    xpath=.//link-computation/node-info/input-model
463     ${request_template}    Set Element Text
464     ...    ${request_template}
465     ...    ${input_model}
466     ...    xpath=.//link-computation/link-info[1]/input-model
467     ${request_template}    Set Element Text
468     ...    ${request_template}
469     ...    ${input_model}
470     ...    xpath=.//link-computation/link-info[2]/input-model
471     ${request_template}    Set Element Text
472     ...    ${request_template}
473     ...    ${input_model}
474     ...    xpath=.//link-computation/output-model
475     ${request_template}    Set Element Text
476     ...    ${request_template}
477     ...    ${underlay_topology_1}
478     ...    xpath=.//link-computation/link-info[1]/link-topology
479     ${request_template}    Set Element Text
480     ...    ${request_template}
481     ...    ${underlay_topology_2}
482     ...    xpath=.//link-computation/link-info[2]/link-topology
483     ${request_template}    Set Element Attribute
484     ...    ${request_template}
485     ...    xmlns:n
486     ...    urn:opendaylight:topology:correlation
487     ...    xpath=./link-computation
488     ${request_template}    Element to String    ${request_template}
489     RETURN    ${request_template}
490
491 Insert Scripting into Request
492     [Documentation]    Insert Scripting into Request under aggregation node
493     [Arguments]    ${request}    ${language}    ${script}
494     ${request}    Add Element    ${request}    ${SCRIPTING}    xpath=.//correlation/aggregation
495     ${request}    Set Element Text    ${request}    ${script}    xpath=.//correlation/aggregation/scripting/script
496     ${request}    Set Element Text    ${request}    ${language}    xpath=.//correlation/aggregation/scripting/language
497     ${request}    Element to String    ${request}
498     RETURN    ${request}
499
500 Create Isis Node
501     [Documentation]    Create an isis node element with id and ip
502     [Arguments]    ${node-id}    ${ovs-version}=23    ${router-id-ipv4}=10.0.0.1
503     ${request}    Set Element Text    ${NODE_ISIS}    ${node-id}    xpath=.//node-id
504     ${request}    Set Element Text    ${request}    ${ovs-version}    xpath=.//ovs-version
505     ${request}    Set Element Text
506     ...    ${request}
507     ...    ${router-id-ipv4}
508     ...    xpath=.//igp-node-attributes/isis-node-attributes/ted/te-router-id-ipv4
509     ${request}    Element to String    ${request}
510     RETURN    ${request}
511
512 Create Openflow Node
513     [Documentation]    Create an Openflow node element with id and ip
514     [Arguments]    ${node-id}    ${ip-address}=10.0.0.1    ${serial-number}=27
515     ${request}    Set Element Text    ${NODE_OPENFLOW}    ${node-id}    xpath=.//id
516     ${request}    Set Element Text    ${request}    ${ip-address}    xpath=.//ip-address
517     ${request}    Set Element Text    ${request}    ${serial-number}    xpath=.//serial-number
518     ${request}    Element to String    ${request}
519     RETURN    ${request}
520
521 Create OVSDB Termination Point
522     [Documentation]    Create an OVSDB termination point element with id and port
523     [Arguments]    ${tp-id}    ${ofport}
524     ${request}    Set Element Text    ${TERMINATION_POINT_OVSDB}    ${tp-id}    xpath=.//tp-id
525     ${request}    Set Element Text    ${request}    ${ofport}    xpath=.//ofport
526     ${request}    Element to String    ${request}
527     RETURN    ${request}
528
529 Create Openflow Node Connector
530     [Documentation]    Create an Openflow node connector element with id and port number
531     [Arguments]    ${nc-id}    ${port-number}
532     ${request}    Set Element Text    ${NODE_CONNECTOR_OPENFLOW}    ${nc-id}    xpath=.//id
533     ${request}    Set Element Text    ${request}    ${port-number}    xpath=.//port-number
534     ${request}    Element to String    ${request}
535     RETURN    ${request}
536
537 Create Link
538     [Arguments]    ${link-id}    ${source-node}    ${dest-node}    ${name}    ${metric}
539     ${request}    Set Element Text    ${LINK}    ${link-id}    xpath=.//link-id
540     ${request}    Set Element Text    ${request}    ${source-node}    xpath=.//source/source-node
541     ${request}    Set Element Text    ${request}    ${dest-node}    xpath=.//destination/dest-node
542     ${request}    Set Element Text    ${request}    ${name}    xpath=.//igp-link-attributes/name
543     ${request}    Set Element Text    ${request}    ${metric}    xpath=.//igp-link-attributes/metric
544     ${request}    Element to String    ${request}
545     RETURN    ${request}
546
547 Extract Node from Topology
548     [Documentation]    Returns node that contains supporting node with ID specified in argument supp_node_id
549     [Arguments]    ${topology}    ${supp_node_id}
550     ${xpath}    Set Variable    .//node/supporting-node[node-ref='${supp_node_id}']/..
551     ${node}    Get Element    ${topology}    xpath=${xpath}
552     ${node}    Element to String    ${node}
553     RETURN    ${node}
554
555 Extract Termination Point from Topology
556     [Documentation]    Returns termination point that contains supporting termination point from specified topology, node and with specified id
557     [Arguments]    ${model}    ${topology}    ${topo_id}    ${node_id}    ${tp_id}
558     Check Supported Model    ${model}
559     ${xpath}    Set Variable If
560     ...    '${model}' == 'network-topology-model' or '${model}' == 'opendaylight-inventory-model'
561     ...    .//termination-point[tp-ref='/network-topology:network-topology/topology/${topo_id}/node/${node_id}/termination-point/${tp_id}']
562     ...    .//termination-point/supporting-termination-point[tp-ref='${tp_id}']/..
563     ${tp}    Get Element    ${topology}    xpath=${xpath}
564     ${tp}    Element to String    ${tp}
565     RETURN    ${tp}
566
567 Extract Link from Topology
568     [Documentation]    Returns link that contains supporting link
569     [Arguments]    ${model}    ${topology}    ${topo_id}    ${link_id}
570     Check Supported Model    ${model}
571     ${xpath}    Set Variable If
572     ...    '${model}' == 'network-topology-model' or '${model}' == 'opendaylight-inventory-model'
573     ...    .//link/supporting-link[link-ref='/network-topology/topology/${topo_id}/link/${link_id}']/..
574     ...    .//link/supporting-link[tp-ref='${tp_id}']/..
575     ${link}    Get Element    ${topology}    xpath=${xpath}
576     ${link}    Element to String    ${link}
577     RETURN    ${link}
578
579 Check Supported Model
580     [Documentation]    Checks if model is supported.
581     [Arguments]    ${model}
582     IF    '${model}' != 'network-topology-model' and '${model}' != 'i2rs-model' and '${model}' != 'opendaylight-inventory-model'
583         Fail    Not supported model
584     END
585
586 Check Aggregated Node in Topology
587     [Documentation]    Checks number of termination points and concrete supporting nodes in aggregated node and returns overlay node id. Model should be 'network-topology-model', 'opendaylight-inventory-model' or 'i2rs-model'.
588     [Arguments]    ${model}    ${topology}    ${tp_count}    @{supp_node_ids}
589     Check Supported Model    ${model}
590     ${node_id}    Get From List    ${supp_node_ids}    0
591     ${aggregated_node}    Extract Node from Topology    ${topology}    ${node_id}
592     ${supp_node_count}    Get Length    ${supp_node_ids}
593     Should Contain X Times    ${aggregated_node}    <supporting-node>    ${supp_node_count}
594     Should Contain X Times    ${aggregated_node}    <termination-point>    ${tp_count}
595     Should Contain X Times    ${aggregated_node}    <tp-ref>    ${tp_count}
596     FOR    ${supp_node_id}    IN    @{supp_node_ids}
597         Element Text Should Be
598         ...    ${aggregated_node}
599         ...    ${supp_node_id}
600         ...    xpath=.//supporting-node[node-ref='${supp_node_id}']/node-ref
601     END
602     ${overlay_node_id}    Get Element Text    ${aggregated_node}    xpath=./node-id
603     RETURN    ${overlay_node_id}
604
605 Check Aggregated Termination Point in Node
606     [Documentation]    Checks supporting termination points in aggregated termination point. Model should be 'network-topology-model', 'opendaylight-inventory-model' or 'i2rs-model'.
607     [Arguments]    ${model}    ${topology}    ${topology_id}    ${node_id}    ${tp_id}    @{supp_tp_ids}
608     Check Supported Model    ${model}
609     ${tp}    Extract Termination Point from Topology
610     ...    ${model}
611     ...    ${topology}
612     ...    ${topology_id}
613     ...    ${node_id}
614     ...    ${tp_id}
615     ${supp_tp_count}    Get Length    ${supp_tp_ids}
616     Should Contain X Times    ${tp}    <tp-ref>    ${supp_tp_count}
617     FOR    ${supp_tp_id}    IN    @{supp_tp_ids}
618         Should Contain X Times    ${tp}    ${supp_tp_id}</tp-ref>    1
619     END
620
621 Check Filtered Nodes in Topology
622     [Documentation]    Checks nodes in filtered topology
623     [Arguments]    ${topology}    ${tp_count}    @{node_ids}
624     FOR    ${node_id}    IN    @{node_ids}
625         Element Text Should Be
626         ...    ${topology}
627         ...    ${node_id}
628         ...    xpath=.//node/supporting-node[node-ref='${node_id}']/node-ref
629     END
630
631 Check Filtered Termination Points in Node
632     [Documentation]    Checks termination points in filtered topology
633     [Arguments]    ${topology}    ${supp_node_id}    @{supp_tp_ids}
634     ${node}    Extract Node from Topology    ${topology}    ${supp_node_id}
635     ${supp_tp_count}    Get Length    ${supp_tp_ids}
636     Should Contain X Times    ${node}    <supporting-node>    1
637     Should Contain X Times    ${node}    <termination-point>    ${supp_tp_count}
638     Should Contain X Times    ${node}    <tp-ref>    ${supp_tp_count}
639     FOR    ${supp_tp_id}    IN    @{supp_tp_ids}
640         Should Contain X Times    ${node}    ${supp_tp_id}    1
641     END
642
643 Check Filtered Links In Topology
644     [Documentation]    Checks links in filtered topology
645     [Arguments]    ${topology}    @{supp_link_ids}
646     FOR    ${supp_link_id}    IN    @{supp_link_ids}
647         Should Contain X Times    ${topology}    ${supp_link_id}</link-ref>    1
648     END
649
650 Check Overlay Link Source And Destination
651     [Documentation]    Checks if the overlay link's source and destination specified by a supporting link ref matches given source and destination
652     [Arguments]    ${model}    ${topology}    ${topo_id}    ${link_id}    ${expected_source}    ${expected_destination}
653     ${link}    Extract Link from Topology    ${model}    ${topology}    ${topo_id}    ${link_id}
654     ${link_source}    Get Element Text    ${link}    xpath=.//source-node
655     ${link_destination}    Get Element Text    ${link}    xpath=.//dest-node
656     Should Be Equal As Strings    ${link_source}    ${expected_source}
657     Should Be Equal As Strings    ${link_destination}    ${expected_destination}
658
659 Output Topo Should Be Complete
660     [Documentation]    Verifies that the output topology contains the expected amount of essential elements
661     [Arguments]    ${node_count}=-1    ${supporting-node_count}=-1    ${node-ref_count}=-1    ${tp_count}=-1    ${tp-ref_count}=-1    ${link_count}=-1
662     ...    ${link-ref_count}=-1
663     ${resp}    Wait Until Keyword Succeeds    5x    250ms    Basic Request Get    ${OVERLAY_TOPO_URL}
664     Should Contain    ${resp.text}    <topology-id>${OUTPUT_TOPO_NAME}</topology-id>
665     IF    ${node_count}>-1
666         Should Contain X Times    ${resp.text}    <node>    ${node_count}
667     END
668     IF    ${supporting-node_count}>-1
669         Should Contain X Times    ${resp.text}    <supporting-node>    ${supporting-node_count}
670     END
671     IF    ${node-ref_count}>-1
672         Should Contain X Times    ${resp.text}    <node-ref>    ${node-ref_count}
673     END
674     IF    ${link_count}>-1
675         Should Contain X Times    ${resp.text}    <link>    ${link_count}
676     END
677     IF    ${link-ref_count}>-1
678         Should Contain X Times    ${resp.text}    <link-ref>    ${link-ref_count}
679     END
680     IF    ${tp_count}>-1
681         Should Contain X Times    ${resp.text}    <termination-point>    ${tp_count}
682     END
683     IF    ${tp-ref_count}>-1
684         Should Contain X Times    ${resp.text}    <tp-ref>    ${tp-ref_count}
685     END
686     Log    ---- Output Topo ----
687     Log    ${resp.text}
688     RETURN    ${resp}
689
690 Set Global Variable If It Does Not Exist
691     [Arguments]    ${name}    ${value}
692     ${status}    ${message}    Run Keyword And Ignore Error    Variable Should Exist    ${name}
693     IF    "${status}" == "FAIL"    Set Global Variable    ${name}    ${value}