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