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