Tidied updated tests.
[integration/test.git] / csit / libraries / VtnMaKeywords.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Library           String
4 Library           DateTime
5 Library           Collections
6 Library           json
7 Library           RequestsLibrary
8 Variables         ../variables/Variables.py
9 Resource          ./Utils.robot
10
11 *** Variables ***
12 ${vlan_topo_10}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom vlan_vtn_test.py --topo vlantopo
13 ${vlan_topo_13}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom vlan_vtn_test.py --topo vlantopo --switch ovsk,protocols=OpenFlow13
14 ${VERSION_VTN}    controller/nb/v2/vtn/version
15 ${VTN_INVENTORY}    restconf/operational/vtn-inventory:vtn-nodes
16 ${DUMPFLOWS_OF10}    dpctl dump-flows -O OpenFlow10
17 ${DUMPFLOWS_OF13}    dpctl dump-flows -O OpenFlow13
18 ${index}          7
19 @{inet_actions}    nw_src=10.0.0.1    nw_dst=10.0.0.3
20 @{BRIDGE1_DATAFLOW}    "reason":"PORTMAPPED"    "virtual-node-path":{"bridge-name":"vBridge1","tenant-name":"Tenant1","interface-name":"if2"}
21 @{BRIDGE2_DATAFLOW}    "reason":"PORTMAPPED"    "virtual-node-path":{"bridge-name":"vBridge2","tenant-name":"Tenant1","interface-name":"if3"}
22 ${vlanmap_bridge1}    200
23 ${vlanmap_bridge2}    300
24 @{VLANMAP_BRIDGE1_DATAFLOW}    "reason":"VLANMAPPED"    "virtual-node-path":{"bridge-name":"vBridge1_vlan","tenant-name":"Tenant1","vlan-map-id":"ANY.200"}
25 @{VLANMAP_BRIDGE2_DATAFLOW}    "reason":"VLANMAPPED"    "virtual-node-path":{"bridge-name":"vBridge2_vlan","tenant-name":"Tenant1","vlan-map-id":"ANY.300"}
26 ${out_before_pathpolicy}    output:2
27 ${out_after_pathpolicy}    output:3
28 ${pathpolicy_topo_13}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow13
29 ${pathpolicy_topo_10}    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow10
30 @{PATHMAP_ATTR}    "index":"1"    "condition":"flowcond_path"    "policy":"1"
31 ${policy_id}      1
32 ${in_port}        1
33 ${dscp_action}    set_field:32->nw_tos_shifted
34 ${dscp_flow}      mod_nw_tos:128
35 @{icmp_action}    nw_src=10.0.0.1    nw_dst=10.0.0.3
36 @{PATHPOLICY_ATTR}    "id":1    "port-desc":"openflow:4,2,s4-eth2"
37 ${custom}         ${CURDIR}/${CREATE_PATHPOLICY_TOPOLOGY_FILE_PATH}
38
39 *** Keywords ***
40 Start SuiteVtnMa
41     [Documentation]    Start VTN Manager Rest Config Api Test Suite
42     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
43     BuiltIn.Wait_Until_Keyword_Succeeds    30    3    Fetch vtn list
44     Start Suite
45
46 Start SuiteVtnMaTest
47     [Documentation]    Start VTN Manager Test Suite
48     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
49
50 Stop SuiteVtnMa
51     [Documentation]    Stop VTN Manager Test Suite
52     Delete All Sessions
53     Stop Suite
54
55 Stop SuiteVtnMaTest
56     [Documentation]    Stop VTN Manager Test Suite
57     Delete All Sessions
58
59 Fetch vtn list
60     [Documentation]    Check if VTN Manager is up.
61     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn:vtns
62     Should Be Equal As Strings    ${resp.status_code}    200
63
64 Fetch vtn switch inventory
65     [Arguments]    ${sw_name}
66     [Documentation]    Check if Switch is detected.
67     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-inventory:vtn-nodes/vtn-node/${sw_name}
68     Should Be Equal As Strings    ${resp.status_code}    200
69
70 Add a Vtn
71     [Arguments]    ${vtn_name}
72     [Documentation]    Create a vtn with specified parameters.
73     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn:update-vtn    data={"input": {"tenant-name":${vtn_name}, "update-mode": "CREATE","operation": "SET", "description": "creating vtn", "idle-timeout":300, "hard-timeout":0}}
74     Should Be Equal As Strings    ${resp.status_code}    200
75
76 Add a vBridge
77     [Arguments]    ${vtn_name}    ${vbr_name}
78     [Documentation]    Create a vBridge in a VTN
79     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vbridge:update-vbridge    data={"input": {"update-mode": "CREATE","operation":"SET", "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "description": "vbrdige created"}}
80     Should Be Equal As Strings    ${resp.status_code}    200
81
82 Add a interface
83     [Arguments]    ${vtn_name}    ${vbr_name}    ${interface_name}
84     [Documentation]    Create a interface into a vBridge of a VTN
85     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vinterface:update-vinterface    data={"input": {"update-mode":"CREATE","operation":"SET", "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "description": "vbrdige interfacecreated", "enabled":"true", "interface-name": ${interface_name}}}
86     Should Be Equal As Strings    ${resp.status_code}    200
87
88 Add a portmap
89     [Arguments]    ${vtn_name}    ${vbr_name}    ${interface_name}    ${node_id}    ${port_id}
90     [Documentation]    Create a portmap for a interface of a vbridge
91     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-port-map:set-port-map    data={"input": { "tenant-name":${vtn_name}, "bridge-name":${vbr_name}, "interface-name": ${interface_name}, "node":"${node_id}", "port-name":"${port_id}"}}
92     Should Be Equal As Strings    ${resp.status_code}    200
93
94 Delete a Vtn
95     [Arguments]    ${vtn_name}
96     [Documentation]    Delete a vtn with specified parameters.
97     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn:remove-vtn    data={"input": {"tenant-name":${vtn_name}}}
98     Should Be Equal As Strings    ${resp.status_code}    200
99
100 Add a vlanmap
101     [Arguments]    ${vtn_name}    ${vbr_name}    ${vlan_id}
102     [Documentation]    Create a vlanmap
103     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-vlan-map:add-vlan-map    data={"input": {"tenant-name":${vtn_name},"bridge-name":${vbr_name},"vlan-id":${vlan_id}}}
104     Should Be Equal As Strings    ${resp.status_code}    200
105
106 Verify Data Flows
107     [Arguments]    ${vtn_name}    ${vBridge_name}
108     [Documentation]    Verify the reason and physical data flows for the specified vtn and vbridge
109     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-impl:vtn-flows/vtn-flow-table/${vtn_name}
110     Run Keyword If    '${vBridge_name}' == 'vBridge1'    DataFlowsForBridge    ${resp}    @{BRIDGE1_DATAFLOW}
111     ...    ELSE IF    '${vBridge_name}' == 'vBridge2'    DataFlowsForBridge    ${resp}    @{BRIDGE2_DATAFLOW}
112     ...    ELSE IF    '${vBridge_name}' == 'vBridge1_vlan'    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE1_DATAFLOW}
113     ...    ELSE    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE2_DATAFLOW}
114
115 Start PathSuiteVtnMaTest
116     [Documentation]    Start VTN Manager Test Suite and Mininet
117     Start SuiteVtnMaTest
118     Start Mininet    ${TOOLS_SYSTEM_IP}    ${pathpolicy_topo_13}    ${custom}
119
120 Start PathSuiteVtnMaTestOF10
121     [Documentation]    Start VTN Manager Test Suite and Mininet in Open Flow 10 Specification
122     Start SuiteVtnMaTest
123     Start Mininet    ${TOOLS_SYSTEM_IP}    ${pathpolicy_topo_10}    ${custom}
124
125 Stop PathSuiteVtnMaTest
126     [Documentation]    Cleanup/Shutdown work at the completion of all tests.
127     Delete All Sessions
128     Stop Mininet    ${mininet_conn_id}
129
130 DataFlowsForBridge
131     [Arguments]    ${resp}    @{BRIDGE_DATAFLOW}
132     [Documentation]    Verify whether the required attributes exists.
133     : FOR    ${dataflowElement}    IN    @{BRIDGE_DATAFLOW}
134     \    should Contain    ${resp.content}    ${dataflowElement}
135
136 Add a pathmap
137     [Arguments]    ${pathmap_data}
138     [Documentation]    Create a pathmap for a vtn
139     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-map:set-path-map    data=${pathmap_data}
140     Should Be Equal As Strings    ${resp.status_code}    200
141
142 Get a pathmap
143     [Documentation]    Get a pathmap for a vtn.
144     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-path-map:global-path-maps
145     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
146     \    should Contain    ${resp.content}    ${pathElement}
147
148 Add a pathpolicy
149     [Arguments]    ${pathpolicy_data}
150     [Documentation]    Create a pathpolicy for a vtn
151     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-policy:set-path-policy    data=${pathpolicy_data}
152     Should Be Equal As Strings    ${resp.status_code}    200
153
154 Get a pathpolicy
155     [Arguments]    ${pathpolicy_id}
156     [Documentation]    Get a pathpolicy for a vtn.
157     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-path-policy:vtn-path-policies/vtn-path-policy/${pathpolicy_id}
158     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
159     \    should Contain    ${resp.content}    ${pathpolicyElement}
160
161 Delete a pathmap
162     [Arguments]    ${tenant_path}
163     [Documentation]    Remove a pathmap for a vtn
164     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-map:remove-path-map    data={"input":{"tenant-name":"${tenant_path}","map-index":["${policy_id}"]}}
165     Should Be Equal As Strings    ${resp.status_code}    200
166
167 Delete a pathpolicy
168     [Arguments]    ${policy_id}
169     [Documentation]    Delete a pathpolicy for a vtn
170     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-path-policy:remove-path-policy    data={"input":{"id":"${policy_id}"}}
171     Should Be Equal As Strings    ${resp.status_code}    200
172
173 Verify flowEntryPathPolicy
174     [Arguments]    ${of_version}    ${port}    ${output}
175     [Documentation]    Checking Flows on switch S1 and switch S3 after applying path policy
176     ${DUMPFLOWS}=    Set Variable If    "${of_version}"=="OF10"    ${DUMPFLOWS_OF10}    ${DUMPFLOWS_OF13}
177     write    ${DUMPFLOWS}
178     ${result}    Read Until    mininet>
179     Should Contain    ${result}    in_port=${port}    actions=${output}
180
181 Add a macmap
182     [Arguments]    ${vtn_name}    ${vBridge_name}    ${src_add}    ${dst_add}
183     [Documentation]    Create a macmap for a vbridge
184     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-mac-map:set-mac-map    data={"input":{"operation":"SET","allowed-hosts":["${dst_add}@0","${src_add}@0"],"tenant-name":"${vtn_name}","bridge-name":"${vBridge_name}"}}
185     Should Be Equal As Strings    ${resp.status_code}    200
186
187 Get DynamicMacAddress
188     [Arguments]    ${h}
189     [Documentation]    Get Dynamic mac address of Host
190     write    ${h} ifconfig -a | grep HWaddr
191     ${source}    Read Until    mininet>
192     ${HWaddress}=    Split String    ${source}    ${SPACE}
193     ${sourceHWaddr}=    Get from List    ${HWaddress}    ${index}
194     ${sourceHWaddress}=    Convert To Lowercase    ${sourceHWaddr}
195     Return From Keyword    ${sourceHWaddress}    # Also [Return] would work here.
196
197 Mininet Ping Should Succeed
198     [Arguments]    ${host1}    ${host2}
199     [Documentation]    Ping hosts to check connectivity
200     Write    ${host1} ping -c 1 ${host2}
201     ${result}    Read Until    mininet>
202     Should Contain    ${result}    64 bytes
203
204 Mininet Ping Should Not Succeed
205     [Arguments]    ${host1}    ${host2}
206     [Documentation]    Ping hosts when there is no connectivity and check hosts is unreachable
207     Write    ${host1} ping -c 3 ${host2}
208     ${result}    Read Until    mininet>
209     Should Not Contain    ${result}    64 bytes
210
211 Start vlan_topo
212     [Arguments]    ${OF}
213     [Documentation]    Create custom topology for vlan functionality
214     Clean Mininet System
215     ${mininet_conn_id1}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
216     Set Suite Variable    ${mininet_conn_id1}
217     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
218     Execute Command    sudo ovs-vsctl set-manager ptcp:6644
219     Put File    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
220     Run Keyword If    '${OF}' == 'OF13'    Write    ${vlan_topo_13}
221     ...    ELSE IF    '${OF}' == 'OF10'    Write    ${vlan_topo_10}
222     ${result}    Read Until    mininet>
223
224 Get flow
225     [Arguments]    ${vtn_name}
226     [Documentation]    Get data flow.
227     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-impl:vtn-flows/vtn-flow-table/${vtn_name}
228     Should Be Equal As Strings    ${resp.status_code}    200
229
230 Remove a portmap
231     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}
232     [Documentation]    Remove a portmap for a interface of a vbridge
233     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-port-map:remove-port-map    data={"input": {"tenant-name":${vtn_name},"bridge-name":${vBridge_name},"interface-name":${interface_name}}}
234     Should Be Equal As Strings    ${resp.status_code}    200
235
236 Verify FlowMacAddress
237     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
238     [Documentation]    Verify the source and destination mac address.
239     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
240     ...    ELSE    VerifyFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
241
242 Verify Flows On OpenFlow
243     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
244     [Documentation]    Verify the mac addresses on the specified open flow.
245     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
246     Should Be Equal As Strings    ${booleanValue}    True
247
248 Verify RemovedFlowMacAddress
249     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
250     [Documentation]    Verify the removed source and destination mac address.
251     Run Keyword If    '${OF_VERSION}' == 'OF10'    Verify Removed Flows On OpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
252     ...    ELSE    VerifyRemovedFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
253
254 Verify Removed Flows On OpenFlow
255     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
256     [Documentation]    Verify the removed mac addresses on the specified open flow.
257     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
258     Should Not Be Equal As Strings    ${booleanValue}    True
259
260 Verify macaddress
261     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
262     [Documentation]    Verify the source and destination mac address after ping in the dumpflows
263     write    ${host1} ifconfig -a | grep HWaddr
264     ${sourcemacaddr}    Read Until    mininet>
265     ${macaddress}=    Split String    ${sourcemacaddr}    ${SPACE}
266     ${sourcemacaddr}=    Get from List    ${macaddress}    ${index}
267     ${sourcemacaddress}=    Convert To Lowercase    ${sourcemacaddr}
268     write    ${host2} ifconfig -a | grep HWaddr
269     ${destmacaddr}    Read Until    mininet>
270     ${macaddress}=    Split String    ${destmacaddr}    ${SPACE}
271     ${destmacaddr}=    Get from List    ${macaddress}    ${index}
272     ${destmacaddress}=    Convert To Lowercase    ${destmacaddr}
273     write    ${DUMPFLOWS}
274     ${result}    Read Until    mininet>
275     Should Contain    ${result}    ${sourcemacaddress}
276     Should Contain    ${result}    ${destmacaddress}
277
278 Verify flowactions
279     [Arguments]    ${actions}    ${DUMPFLOWS}
280     [Documentation]    Verify the flowfilter actions after ping in the dumpflows
281     write    ${DUMPFLOWS}
282     ${result}    Read Until    mininet>
283     Should Contain    ${result}    ${actions}
284
285 Add a vtn flowfilter
286     [Arguments]    ${vtn_name}    ${vtnflowfilter_data}
287     [Documentation]    Create a flowfilter for a vtn
288     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": "${vtn_name}",${vtnflowfilter_data}}}
289     Should Be Equal As Strings    ${resp.status_code}    200
290
291 Add a vbr flowfilter
292     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vbrflowfilter_data}
293     [Documentation]    Create a flowfilter for a vbr
294     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": "${vtn_name}", "bridge-name": "${vBridge_name}", ${vbrflowfilter_data}}}
295     Should Be Equal As Strings    ${resp.status_code}    200
296
297 Add a vbrif flowfilter
298     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${vbrif_flowfilter_data}
299     [Documentation]    Create a flowfilter for a vbrif
300     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-filter:set-flow-filter    data={"input": {"tenant-name": ${vtn_name}, "bridge-name": "${vBridge_name}","interface-name":"${interface_name}",${vbrif_flowfilter_data}}}
301     Should Be Equal As Strings    ${resp.status_code}    200
302
303 Verify Flow Entries for Flowfilter
304     [Arguments]    ${dumpflows}    @{flowfilter_actions}
305     [Documentation]    Verify switch flow entry using flowfilter for a vtn
306     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry    ${dumpflows}    @{flowfilter_actions}
307     Should Be Equal As Strings    ${booleanValue}    True
308
309 Verify Removed Flow Entry for Inet Drop Flowfilter
310     [Arguments]    ${dumpflows}    @{flowfilter_actions}
311     [Documentation]    Verify removed switch flow entry using flowfilter drop for a vtn
312     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry    ${dumpflows}    @{flowfilter_actions}
313     Should Be Equal As Strings    ${booleanValue}    True
314
315 Verify Actions on Flow Entry
316     [Arguments]    ${dumpflows}    @{flowfilter_actions}
317     [Documentation]    check flow action elements by giving dumpflows in mininet
318     write    ${dumpflows}
319     ${result}    Read Until    mininet>
320     : FOR    ${flowElement}    IN    @{flowfilter_actions}
321     \    should Contain    ${result}    ${flowElement}
322
323 Add a flowcondition
324     [Arguments]    ${flowcond_name}    ${flowconditiondata}
325     [Documentation]    Create a flowcondition using Restconfig Api
326     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-condition:set-flow-condition    data={"input":{"operation":"SET","present":"false","name":"${flowcond_name}",${flowconditiondata}}}
327     Should Be Equal As Strings    ${resp.status_code}    200
328
329 Get flowconditions
330     [Documentation]    Retrieve the list of flowconditions created
331     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-condition:vtn-flow-conditions
332     Should Be Equal As Strings    ${resp.status_code}    200
333
334 Get flowcondition
335     [Arguments]    ${flowcond_name}    ${retrieve}
336     [Documentation]    Retrieve the flowcondition by name and to check the removed flowcondition we added "retrieve" argument to differentiate the status code,
337     ...    since after removing flowcondition name the status will be different compare to status code when the flowcondition name is present.
338     ${resp}=    RequestsLibrary.Get Request    session    restconf/operational/vtn-flow-condition:vtn-flow-conditions/vtn-flow-condition/${flowcond_name}
339     Run Keyword If    '${retrieve}' == 'retrieve'    Should Be Equal As Strings    ${resp.status_code}    200
340     ...    ELSE    Should Not Be Equal As Strings    ${resp.status_code}    200
341
342 Remove flowcondition
343     [Arguments]    ${flowcond_name}
344     [Documentation]    Remove the flowcondition by name
345     ${resp}=    RequestsLibrary.Post Request    session    restconf/operations/vtn-flow-condition:remove-flow-condition    data={"input":{"name":"${flowcond_name}"}}
346     Should Be Equal As Strings    ${resp.status_code}    200