af73b55ced5dd3fcd13ae6c54ff96e503995a9da
[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=${CONTROLLER} --custom vlan_vtn_test.py --topo vlantopo
13 ${vlan_topo_13}    sudo mn --controller=remote,ip=${CONTROLLER} --custom vlan_vtn_test.py --topo vlantopo --switch ovsk,protocols=OpenFlow13
14 ${REST_CONTEXT_VTNS}    controller/nb/v2/vtn/default/vtns
15 ${REST_CONTEXT}    controller/nb/v2/vtn/default
16 ${VERSION_VTN}    controller/nb/v2/vtn/version
17 ${VTN_INVENTORY}    restconf/operational/vtn-inventory:vtn-nodes
18 ${DUMPFLOWS_OF10}    dpctl dump-flows -O OpenFlow10
19 ${DUMPFLOWS_OF13}    dpctl dump-flows -O OpenFlow13
20 ${index}          7
21 @{FLOWELMENTS}    nw_src=10.0.0.1    nw_dst=10.0.0.3    actions=drop
22 @{BRIDGE1_DATAFLOW}    "reason":"PORTMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge1","interface":"if2"}
23 @{BRIDGE2_DATAFLOW}    "reason":"PORTMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge2","interface":"if3"}
24 ${vlanmap_bridge1}    {"vlan": "200"}
25 ${vlanmap_bridge2}    {"vlan": "300"}
26 @{VLANMAP_BRIDGE1_DATAFLOW}    "reason":"VLANMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge1_vlan"}
27 @{VLANMAP_BRIDGE2_DATAFLOW}    "reason":"VLANMAPPED"    "path":{"tenant":"Tenant1","bridge":"vBridge2_vlan"}
28 ${pathpolicy_topo_13}    sudo mn --controller=remote,ip=${CONTROLLER} --custom topo-3sw-2host_multipath.py --topo pathpolicytopo --switch ovsk,protocols=OpenFlow13
29 ${pathpolicy_topo_10}    sudo mn --controller=remote,ip=${CONTROLLER} --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 @{PATHPOLICY_ATTR}    "id":"1"    "type":"OF"    "name":"s4-eth2"
33 ${custom}         ${CURDIR}/${CREATE_PATHPOLICY_TOPOLOGY_FILE_PATH}
34
35 *** Keywords ***
36 Start SuiteVtnMa
37     [Documentation]    Start VTN Manager Init Test Suite
38     Create Session    session    http://${CONTROLLER}:${RESTPORT}    auth=${AUTH}    headers=${HEADERS}
39     BuiltIn.Wait_Until_Keyword_Succeeds    30    3    Fetch vtn list
40     Start Suite
41
42 Stop SuiteVtnMa
43     [Documentation]    Stop VTN Manager Test Suite
44     Delete All Sessions
45     Stop Suite
46
47 Start SuiteVtnMaTest
48     [Documentation]    Start VTN Manager Test Suite
49     Create Session    session    http://${CONTROLLER}:${RESTPORT}    auth=${AUTH}    headers=${HEADERS}
50
51 Stop SuiteVtnMaTest
52     [Documentation]    Stop VTN Manager Test Suite
53     Delete All Sessions
54
55 Fetch vtn list
56     [Documentation]    Check if VTN Manager is up.
57     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}
58     Should Be Equal As Strings    ${resp.status_code}    200
59
60 Fetch vtn switch inventory
61     [Arguments]    ${sw_name}
62     [Documentation]    Check if Switch is detected.
63     ${resp}=    RequestsLibrary.Get    session    ${VTN_INVENTORY}/vtn-inventory:vtn-node/${sw_name}
64     Should Be Equal As Strings    ${resp.status_code}    200
65
66 Add a vtn
67     [Arguments]    ${vtn_name}    ${vtn_data}
68     [Documentation]    Create a vtn with specified parameters.
69     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}    data=${vtn_data}
70     Should Be Equal As Strings    ${resp.status_code}    201
71
72 Delete a vtn
73     [Arguments]    ${vtn_name}
74     [Documentation]    Create a vtn with specified parameters.
75     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}
76     Should Be Equal As Strings    ${resp.status_code}    200
77
78 Add a vBridge
79     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vBridge_data}
80     [Documentation]    Create a vBridge in a VTN
81     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}    data=${vBridge_data}
82     Should Be Equal As Strings    ${resp.status_code}    201
83
84 Add a interface
85     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${interface_data}
86     [Documentation]    Create a interface into a vBridge of a VTN
87     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}    data=${interface_data}
88     Should Be Equal As Strings    ${resp.status_code}    201
89
90 Add a portmap
91     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${portmap_data}
92     [Documentation]    Create a portmap for a interface of a vbridge
93     ${json_data}=    json.dumps    ${portmap_data}
94     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/portmap    data=${json_data}    headers=${HEADERS}
95     Should Be Equal As Strings    ${resp.status_code}    200
96
97 Verify Data Flows
98     [Arguments]    ${vtn_name}    ${vBridge_name}
99     [Documentation]    Verify the reason and physical data flows for the specified vtn and vbridge
100     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flows/detail
101     Run Keyword If    '${vBridge_name}' == 'vBridge1'    DataFlowsForBridge    ${resp}    @{BRIDGE1_DATAFLOW}
102     ...    ELSE IF    '${vBridge_name}' == 'vBridge2'    DataFlowsForBridge    ${resp}    @{BRIDGE2_DATAFLOW}
103     ...    ELSE IF    '${vBridge_name}' == 'vBridge1_vlan'    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE1_DATAFLOW}
104     ...    ELSE    DataFlowsForBridge    ${resp}    @{VLANMAP_BRIDGE2_DATAFLOW}
105
106 DataFlowsForBridge
107     [Arguments]    ${resp}    @{BRIDGE_DATAFLOW}
108     [Documentation]    Verify whether the required attributes exists.
109     : FOR    ${dataflowElement}    IN    @{BRIDGE_DATAFLOW}
110     \    should Contain    ${resp.content}    ${dataflowElement}
111
112 Add a pathmap
113     [Arguments]    ${pathmap_data}
114     [Documentation]    Create a pathmap for a vtn
115     ${json_data}=    json.dumps    ${pathmap_data}
116     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/pathmaps/${policy_id}    data=${pathmap_data}    headers=${HEADERS}
117     Should Be Equal As Strings    ${resp.status_code}    201
118
119 Get a pathmap
120     [Documentation]    Get a pathmap for a vtn.
121     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathmaps
122     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
123     \    should Contain    ${resp.content}    ${pathElement}
124
125 Add a pathpolicy
126     [Arguments]    ${pathpolicy_data}
127     [Documentation]    Create a pathpolicy for a vtn
128     ${json_data}=    json.dumps    ${pathpolicy_data}
129     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/pathpolicies/${policy_id}    data=${pathpolicy_data}    headers=${HEADERS}
130     Should Be Equal As Strings    ${resp.status_code}    201
131
132 Get a pathpolicy
133     [Documentation]    Get a pathpolicy for a vtn.
134     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathpolicies/${policy_id}
135     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
136     \    should Contain    ${resp.content}    ${pathpolicyElement}
137
138 Verify flowEntryBeforePathPolicy
139     [Arguments]    ${OF_VERSION}
140     [Documentation]    Checking Flows on switch S1 and switch S3 before applying path policy
141     ${DUMPFLOWS}=    Set Variable If    "${OF_VERSION}"=="OF10"    ${DUMPFLOWS_OF10}    ${DUMPFLOWS_OF13}
142     write    ${DUMPFLOWS}
143     ${result}    Read Until    mininet>
144     @{list_to_verify}    Create List    in_port=1    actions=output:2    actions=output:3
145     : FOR    ${flowverifyElement}    IN    @{list_to_verify}
146     \    should Contain    ${result}    ${flowverifyElement}
147
148 Verify flowEntryAfterPathPolicy
149     [Arguments]    ${OF_VERSION}
150     [Documentation]    Checking Flows on switch S1 and switch S3 after applying path policy
151     ${DUMPFLOWS}=    Set Variable If    "${OF_VERSION}"=="OF10"    ${DUMPFLOWS_OF10}    ${DUMPFLOWS_OF13}
152     write    ${DUMPFLOWS}
153     ${result}    Read Until    mininet>
154     @{list_to_verify}    Create List    in_port=1    actions=output:3    in_port=2
155     : FOR    ${flowverifyElement}    IN    @{list_to_verify}
156     \    should Contain    ${result}    ${flowverifyElement}
157
158 Start PathSuiteVtnMaTest
159     [Documentation]    Start VTN Manager Test Suite and Mininet
160     Start SuiteVtnMaTest
161     Start Mininet    ${MININET}    ${pathpolicy_topo_13}    ${custom}
162
163 Start PathSuiteVtnMaTestOF10
164     [Documentation]    Start VTN Manager Test Suite and Mininet in Open Flow 10 Specification
165     Start SuiteVtnMaTest
166     Start Mininet    ${MININET}    ${pathpolicy_topo_10}    ${custom}
167
168 Stop PathSuiteVtnMaTest
169     [Documentation]    Cleanup/Shutdown work at the completion of all tests.
170     Delete All Sessions
171     Stop Mininet    ${mininet_conn_id}
172
173 Delete a pathmap
174     [Documentation]    Delete a pathmap for a vtn
175     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/pathmaps/1
176     Should Be Equal As Strings    ${resp.status_code}    200
177
178 Get a pathmap after delete
179     [Documentation]    Get a pathmap for a vtn.
180     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathmaps
181     : FOR    ${pathElement}    IN    @{PATHMAP_ATTR}
182     \    should Not Contain    ${resp.content}    ${pathElement}
183
184 Delete a pathpolicy
185     [Documentation]    Delete a pathpolicy for a vtn
186     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/pathpolicies/1
187     Should Be Equal As Strings    ${resp.status_code}    200
188
189 Get a pathpolicy after delete
190     [Documentation]    Get a pathpolicy for a vtn after delete.
191     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT}/pathpolicies/${policy_id}
192     : FOR    ${pathpolicyElement}    IN    @{PATHPOLICY_ATTR}
193     \    should Not Contain    ${resp.content}    ${pathpolicyElement}
194
195 Add a macmap
196     [Arguments]    ${vtn_name}    ${vBridge_name}    ${macmap_data}
197     [Documentation]    Create a macmap for a vbridge
198     ${json_data}=    json.dumps    ${macmap_data}
199     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/macmap/allow    data=${macmap_data}    headers=${HEADERS}
200     Should Be Equal As Strings    ${resp.status_code}    201
201
202 Get DynamicMacAddress
203     [Arguments]    ${h}
204     [Documentation]    Get Dynamic mac address of Host
205     write    ${h} ifconfig -a | grep HWaddr
206     ${source}    Read Until    mininet>
207     ${HWaddress}=    Split String    ${source}    ${SPACE}
208     ${sourceHWaddr}=    Get from List    ${HWaddress}    ${index}
209     ${sourceHWaddress}=    Convert To Lowercase    ${sourceHWaddr}
210     Return From Keyword    ${sourceHWaddress}    # Also [Return] would work here.
211
212 Add a vBridgeMacMapping
213     [Arguments]    ${tenant_name}    ${Bridge_name}    ${bridge_macmap_data}
214     [Documentation]    Create a vbridge macmap for a bridge
215     ${json_data}=    json.dumps    ${bridge_macmap_data}
216     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${tenant_name}/vbridges/${Bridge_name}/macmap/allow    data=${json_data}    headers=${HEADERS}
217     Should Be Equal As Strings    ${resp.status_code}    201
218
219 Mininet Ping Should Succeed
220     [Arguments]    ${host1}    ${host2}
221     Write    ${host1} ping -c 10 ${host2}
222     ${result}    Read Until    mininet>
223     Should Contain    ${result}    64 bytes
224
225 Mininet Ping Should Not Succeed
226     [Arguments]    ${host1}    ${host2}
227     Write    ${host1} ping -c 10 ${host2}
228     ${result}    Read Until    mininet>
229     Should Not Contain    ${result}    64 bytes
230
231 Delete a interface
232     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}
233     [Documentation]    Delete a interface with specified parameters.
234     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}
235     Should Be Equal As Strings    ${resp.status_code}    200
236
237 Start vlan_topo
238     [Arguments]    ${OF}
239     Clean Mininet System
240     ${mininet_conn_id1}=    Open Connection    ${MININET}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
241     Set Suite Variable    ${mininet_conn_id1}
242     Login With Public Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
243     Execute Command    sudo ovs-vsctl set-manager ptcp:6644
244     Put File    ${CURDIR}/${CREATE_VLAN_TOPOLOGY_FILE_PATH}
245     Run Keyword If    '${OF}' == 'OF13'    Write    ${vlan_topo_13}
246     ...    ELSE IF    '${OF}' == 'OF10'    Write    ${vlan_topo_10}
247     ${result}    Read Until    mininet>
248
249 Add a vlanmap
250     [Arguments]    ${vtn_name}    ${vBridge_name}    ${vlanmap_data}
251     [Documentation]    Create a vlanmap
252     ${resp}=    RequestsLibrary.Post    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/vlanmaps/    data=${vlanmap_data}    headers=${HEADERS}
253     Should Be Equal As Strings    ${resp.status_code}    201
254
255 Get flow
256     [Arguments]    ${vtn_name}
257     [Documentation]    Get data flow.
258     ${resp}=    RequestsLibrary.Get    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flows/detail
259     Should Be Equal As Strings    ${resp.status_code}    200
260
261 Remove a portmap
262     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${portmap_data}
263     [Documentation]    Remove a portmap for a interface of a vbridge
264     ${json_data}=    json.dumps    ${portmap_data}
265     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/portmap    data=${json_data}    headers=${HEADERS}
266     Should Be Equal As Strings    ${resp.status_code}    200
267
268 Verify FlowMacAddress
269     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
270     Run Keyword If    '${OF_VERSION}' == 'OF10'    VerifyFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
271     ...    ELSE    VerifyFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
272
273 VerifyFlowsOnOpenFlow
274     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
275     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
276     Should Be Equal As Strings    ${booleanValue}    True
277
278 Verify RemovedFlowMacAddress
279     [Arguments]    ${host1}    ${host2}    ${OF_VERSION}
280     Run Keyword If    '${OF_VERSION}' == 'OF10'    VerifyRemovedFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF10}
281     ...    ELSE    VerifyRemovedFlowsOnOpenFlow    ${host1}    ${host2}    ${DUMPFLOWS_OF13}
282
283 VerifyRemovedFlowsOnOpenFlow
284     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
285     ${booleanValue}=    Run Keyword And Return Status    Verify macaddress    ${host1}    ${host2}    ${DUMPFLOWS}
286     Should Not Be Equal As Strings    ${booleanValue}    True
287
288 Verify macaddress
289     [Arguments]    ${host1}    ${host2}    ${DUMPFLOWS}
290     write    ${host1} ifconfig -a | grep HWaddr
291     ${sourcemacaddr}    Read Until    mininet>
292     ${macaddress}=    Split String    ${sourcemacaddr}    ${SPACE}
293     ${sourcemacaddr}=    Get from List    ${macaddress}    ${index}
294     ${sourcemacaddress}=    Convert To Lowercase    ${sourcemacaddr}
295     write    ${host2} ifconfig -a | grep HWaddr
296     ${destmacaddr}    Read Until    mininet>
297     ${macaddress}=    Split String    ${destmacaddr}    ${SPACE}
298     ${destmacaddr}=    Get from List    ${macaddress}    ${index}
299     ${destmacaddress}=    Convert To Lowercase    ${destmacaddr}
300     write    ${DUMPFLOWS}
301     ${result}    Read Until    mininet>
302     Should Contain    ${result}    ${sourcemacaddress}
303     Should Contain    ${result}    ${destmacaddress}
304
305 Add a flowcondition
306     [Arguments]    ${cond_name}    ${flowcond_data}
307     [Documentation]    Create a flowcondition for a interface of a vbridge
308     ${json_data}=    json.dumps    ${flowcond_data}
309     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT}/flowconditions/${cond_name}    data=${json_data}    headers=${HEADERS}
310     Should Be Equal As Strings    ${resp.status_code}    201
311
312 Delete a flowcondition
313     [Arguments]    ${cond_name}
314     [Documentation]    Delete a flowcondition for a interface of a vbridge
315     ${resp}=    RequestsLibrary.Delete    session    ${REST_CONTEXT}/flowconditions/${cond_name}
316     Should Be Equal As Strings    ${resp.status_code}    200
317
318 Add a flowfilter
319     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
320     [Documentation]    Create a flowfilter for a vtn
321     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
322     Should Be Equal As Strings    ${resp.status_code}    201
323
324 Add a flowfilter_vtn
325     [Arguments]    ${vtn_name}    ${flowfilter_data}    ${ff_index}
326     [Documentation]    Create a flowfilter for a vtn
327     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/flowfilters/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
328     Should Be Equal As Strings    ${resp.status_code}    201
329
330 Add a flowfilter_vbr
331     [Arguments]    ${vtn_name}    ${vBridge_name}    ${flowfilter_data}    ${ff_index}
332     [Documentation]    Create a flowfilter for a vbr
333     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
334     Should Be Equal As Strings    ${resp.status_code}    201
335
336 Update a flowfilter
337     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
338     [Documentation]    Create a flowfilter for a vtn
339     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
340     Should Be Equal As Strings    ${resp.status_code}    200
341
342 Add a flowfilter for drop
343     [Arguments]    ${vtn_name}    ${vBridge_name}    ${interface_name}    ${flowfilter_data}    ${ff_index}
344     [Documentation]    Create a flowfilter for a vtn
345     ${resp}=    RequestsLibrary.Put    session    ${REST_CONTEXT_VTNS}/${vtn_name}/vbridges/${vBridge_name}/interfaces/${interface_name}/flowfilters/IN/${ff_index}    data=${flowfilter_data}    headers=${HEADERS}
346     Should Be Equal As Strings    ${resp.status_code}    200
347
348 Verify Flow Entry for Inet Flowfilter
349     [Documentation]    Verify switch flow entry using flowfilter for a vtn
350     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry
351     Should Not Be Equal As Strings    ${booleanValue}    True
352
353 Verify Removed Flow Entry for Inet Drop Flowfilter
354     [Documentation]    Verify removed switch flow entry using flowfilter drop for a vtn
355     ${booleanValue}=    Run Keyword And Return Status    Verify Actions on Flow Entry
356     Should Be Equal As Strings    ${booleanValue}    True
357
358 Verify Actions on Flow Entry
359     write    ${DUMPFLOWS_OF13}
360     ${result}    Read Until    mininet>
361     : FOR    ${flowElement}    IN    @{FLOWELMENTS}
362     \    should Contain    ${result}    ${flowElement}