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