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