Update StreamDict to include argon
[integration/test.git] / csit / libraries / OVSDB.robot
1 *** Settings ***
2 Library     Collections
3 Library     ipaddress
4 Library     OperatingSystem
5 Library     RequestsLibrary
6 Library     SSHLibrary
7 Library     String
8 Resource    ClusterManagement.robot
9 Resource    Utils.robot
10 Resource    ${CURDIR}/TemplatedRequests.robot
11 Resource    ../variables/Variables.robot
12 Resource    ../variables/ovsdb/Variables.robot
13 Resource    ../variables/netvirt/Variables.robot
14
15
16 *** Variables ***
17 ${OVSDB_CONFIG_DIR}     ${CURDIR}/../variables/ovsdb
18
19
20 *** Keywords ***
21 Log Request
22     [Arguments]    ${resp_content}
23     IF    '''${resp_content}''' != '${EMPTY}'
24         ${resp_json} =    RequestsLibrary.To Json    ${resp_content}    pretty_print=True
25     ELSE
26         ${resp_json} =    BuiltIn.Set Variable    ${EMPTY}
27     END
28     BuiltIn.Log    ${resp_json}
29     RETURN    ${resp_json}
30
31 Create OVSDB Node
32     [Arguments]    ${node_ip}    ${port}=${OVSDB_NODE_PORT}
33     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_node.json
34     ${body} =    Replace String    ${body}    127.0.0.1    ${node_ip}
35     ${body} =    Replace String    ${body}    61644    ${port}
36     ${uri} =    Builtin.Set Variable    ${RFC8040_TOPO_OVSDB1_API}
37     BuiltIn.Log    URI is ${uri}
38     BuiltIn.Log    data: ${body}
39     ${resp} =    RequestsLibrary.Post Request    session    ${uri}    data=${body}
40     OVSDB.Log Request    ${resp.text}
41     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
42
43 Connect To Ovsdb Node
44     [Documentation]    This will Initiate the connection to OVSDB node from controller
45     [Arguments]    ${node_ip}    ${port}=${OVSDB_NODE_PORT}
46     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/connect.json
47     ${body} =    String.Replace String    ${body}    127.0.0.1    ${node_ip}
48     ${body} =    String.Replace String    ${body}    61644    ${port}
49     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_API}${node_ip}%3A${port}
50     BuiltIn.Log    URI is ${uri}
51     BuiltIn.Log    data: ${body}
52     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
53     OVSDB.Log Request    ${resp.text}
54     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
55
56 Disconnect From Ovsdb Node
57     [Documentation]    This request will disconnect the OVSDB node from the controller
58     [Arguments]    ${node_ip}    ${port}=${OVSDB_NODE_PORT}
59     ${resp} =    RequestsLibrary.Delete Request    session    ${RFC8040_SOUTHBOUND_NODE_API}${node_ip}%3A${port}
60     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    204
61
62 Add Bridge To Ovsdb Node
63     [Documentation]    This will create a bridge and add it to the OVSDB node.
64     [Arguments]    ${node_id}    ${node_ip}    ${bridge}    ${datapath_id}    ${port}=${OVSDB_NODE_PORT}
65     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_bridge.json
66     ${body} =    String.Replace String    ${body}    ovsdb://127.0.0.1:61644    ovsdb://${node_id}
67     ${body} =    String.Replace String    ${body}    tcp:127.0.0.1:6633    tcp:${ODL_SYSTEM_IP}:6633
68     ${body} =    String.Replace String    ${body}    127.0.0.1    ${node_ip}
69     ${body} =    String.Replace String    ${body}    br01    ${bridge}
70     ${body} =    String.Replace String    ${body}    61644    ${port}
71     ${body} =    String.Replace String    ${body}    0000000000000001    ${datapath_id}
72     ${node_id_} =    BuiltIn.Evaluate    """${node_id}""".replace("/","%2F").replace(":","%3A")
73     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_API}${node_id_}%2Fbridge%2F${bridge}
74     BuiltIn.Log    URI is ${uri}
75     BuiltIn.Log    data: ${body}
76     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
77     OVSDB.Log Request    ${resp.text}
78     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
79
80 Delete Bridge From Ovsdb Node
81     [Documentation]    This request will delete the bridge node from the OVSDB
82     [Arguments]    ${node_id}    ${bridge}
83     ${resp} =    RequestsLibrary.Delete Request
84     ...    session
85     ...    ${RFC8040_SOUTHBOUND_NODE_API}${node_id}%2Fbridge%2F${bridge}
86     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    204
87
88 Add Termination Point
89     [Documentation]    Using the json data body file as a template, a REST config request is made to
90     ...    create a termination-point ${tp_name} on ${bridge} for the given ${node_id}. The ports
91     ...    remote-ip defaults to ${TOOLS_SYSTEM_IP}
92     [Arguments]    ${node_id}    ${bridge}    ${tp_name}    ${remote_ip}=${TOOLS_SYSTEM_IP}
93     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_port.json
94     ${body} =    String.Replace String    ${body}    192.168.0.21    ${remote_ip}
95     ${body} =    String.Replace String    ${body}    vxlanport    ${tp_name}
96     ${node_id_} =    BuiltIn.Evaluate    """${node_id}""".replace("/","%2F").replace(":","%3A")
97     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_API}${node_id_}%2Fbridge%2F${bridge}
98     ${resp} =    RequestsLibrary.Put Request    session    ${uri}/termination-point=${tp_name}    data=${body}
99     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
100
101 Add Vxlan To Bridge
102     [Documentation]    This request will create vxlan port for vxlan tunnel and attach it to the specific bridge
103     [Arguments]    ${node_ip}    ${bridge}    ${vxlan_port}    ${remote_ip}    ${port}=${OVSDB_NODE_PORT}
104     OVSDB.Add Termination Point    ${node_ip}:${port}    ${bridge}    ${vxlan_port}    ${remote_ip}
105
106 Verify OVS Reports Connected
107     [Documentation]    Uses "vsctl show" to check for string "is_connected"
108     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
109     ${output} =    Verify Ovs-vsctl Output    show    is_connected    ${tools_system}
110     RETURN    ${output}
111
112 Verify Ovs-vsctl Output
113     [Documentation]    A wrapper keyword to make it easier to validate ovs-vsctl output, and gives an easy
114     ...    way to check this output in a WUKS. The argument ${should_match} can control if the match should
115     ...    exist (True} or not (False) or don't care (anything but True or False). ${should_match} is True by default
116     [Arguments]    ${vsctl_args}    ${expected_output}    ${ovs_system}=${TOOLS_SYSTEM_IP}    ${should_match}=True
117     ${output} =    Utils.Run Command On Mininet    ${ovs_system}    sudo ovs-vsctl ${vsctl_args}
118     BuiltIn.Log    ${output}
119     IF    "${should_match}" == "True"
120         BuiltIn.Should Contain    ${output}    ${expected_output}
121     END
122     IF    "${should_match}" == "False"
123         BuiltIn.Should Not Contain    ${output}    ${expected_output}
124     END
125     RETURN    ${output}
126
127 Get OVSDB UUID
128     [Documentation]    Queries the topology in the operational datastore and searches for the node that has
129     ...    the ${ovs_system_ip} argument as the "remote-ip". If found, the value returned will be the value of
130     ...    node-id stripped of "ovsdb://uuid/". If not found, ${EMPTY} will be returned.
131     [Arguments]    ${ovs_system_ip}=${TOOLS_SYSTEM_IP}    ${controller_http_session}=session
132     ${uuid} =    Set Variable    ${EMPTY}
133     ${resp} =    RequestsLibrary.Get Request    ${controller_http_session}    ${RFC8040_OPERATIONAL_TOPO_OVSDB1_API}
134     OVSDB.Log Request    ${resp.text}
135     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
136     ${resp_json} =    RequestsLibrary.To Json    ${resp.text}
137     ${topologies} =    Collections.Get From Dictionary    ${resp_json}    network-topology:topology
138     ${topology} =    Collections.Get From List    ${topologies}    0
139     ${node_list} =    Collections.Get From Dictionary    ${topology}    node
140     BuiltIn.Log    ${node_list}
141     # Since bridges are also listed as nodes, but will not have the extra "ovsdb:connection-info data,
142     # we need to use "Run Keyword And Ignore Error" below.
143     FOR    ${node}    IN    @{node_list}
144         ${node_id} =    Collections.Get From Dictionary    ${node}    node-id
145         ${node_uuid} =    String.Replace String    ${node_id}    ovsdb://uuid/    ${EMPTY}
146         ${status}    ${connection_info} =    BuiltIn.Run Keyword And Ignore Error
147         ...    Collections.Get From Dictionary
148         ...    ${node}
149         ...    ovsdb:connection-info
150         ${status}    ${remote_ip} =    BuiltIn.Run Keyword And Ignore Error
151         ...    Collections.Get From Dictionary
152         ...    ${connection_info}
153         ...    remote-ip
154         ${uuid} =    Set Variable If    '${remote_ip}' == '${ovs_system_ip}'    ${node_uuid}    ${uuid}
155     END
156     RETURN    ${uuid}
157
158 Collect OVSDB Debugs
159     [Documentation]    Used to log useful test debugs for OVSDB related system tests.
160     [Arguments]    ${switch}=${INTEGRATION_BRIDGE}
161     ${output} =    Utils.Run Command On Mininet    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl show
162     BuiltIn.Log    ${output}
163     ${output} =    Utils.Run Command On Mininet
164     ...    ${TOOLS_SYSTEM_IP}
165     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch} | cut -d',' -f3-
166     BuiltIn.Log    ${output}
167
168 Clean OVSDB Test Environment
169     [Documentation]    General Use Keyword attempting to sanitize test environment for OVSDB related
170     ...    tests. Not every step will always be neccessary, but should not cause any problems for
171     ...    any new ovsdb test suites.
172     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}
173     Utils.Clean Mininet System    ${tools_system}
174     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl del-manager
175     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
176     Utils.Run Command On Mininet    ${tools_system}    sudo rm -rf /etc/openvswitch/conf.db
177     Utils.Run Command On Mininet    ${tools_system}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
178
179 Restart OVSDB
180     [Documentation]    Restart the OVS node without cleaning the current configuration.
181     [Arguments]    ${ovs_ip}
182     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo systemctl restart openvswitch
183     BuiltIn.Log    ${output}
184
185 Set Controller In OVS Bridge
186     [Documentation]    Sets controller for the OVS bridge ${bridge} using ${controller_opt} and OF version ${ofversion}.
187     [Arguments]    ${tools_system}    ${bridge}    ${controller_opt}    ${ofversion}=13
188     Utils.Run Command On Mininet
189     ...    ${tools_system}
190     ...    sudo ovs-vsctl set bridge ${bridge} protocols=OpenFlow${ofversion}
191     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-controller ${bridge} ${controller_opt}
192
193 Check OVS OpenFlow Connections
194     [Documentation]    Check OVS instance with IP ${tools_system} has ${of_connections} OpenFlow connections.
195     [Arguments]    ${tools_system}    ${of_connections}
196     ${output} =    Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl show
197     BuiltIn.Log    ${output}
198     BuiltIn.Should Contain X Times    ${output}    is_connected    ${of_connections}
199
200 Add Multiple Managers to OVS
201     [Documentation]    Connect OVS to the list of controllers in the ${controller_index_list} or all if no list is provided.
202     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}    ${controller_index_list}=${EMPTY}    ${ovs_mgr_port}=6640
203     ${index_list} =    ClusterManagement.List Indices Or All    given_list=${controller_index_list}
204     Utils.Clean Mininet System    ${tools_system}
205     ${ovs_opt} =    BuiltIn.Set Variable
206     FOR    ${index}    IN    @{index_list}
207         ${ovs_opt} =    BuiltIn.Catenate    ${ovs_opt}    ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ovs_mgr_port}
208         BuiltIn.Log    ${ovs_opt}
209     END
210     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-manager ${ovs_opt}
211     ${output} =    BuiltIn.Wait Until Keyword Succeeds    5s    1s    Verify OVS Reports Connected    ${tools_system}
212     BuiltIn.Log    ${output}
213     ${controller_index} =    Collections.Get_From_List    ${index_list}    0
214     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${controller_index}
215     ${ovsdb_uuid} =    BuiltIn.Wait Until Keyword Succeeds
216     ...    30s
217     ...    2s
218     ...    OVSDB.Get OVSDB UUID
219     ...    controller_http_session=${session}
220     RETURN    ${ovsdb_uuid}
221
222 Get DPID
223     [Documentation]    Returns the dpnid from the system at the given ip address using ovs-ofctl assuming br-int is present.
224     [Arguments]    ${ip}
225     ${output} =    Utils.Run Command On Remote System
226     ...    ${ip}
227     ...    sudo ovs-ofctl show -O Openflow13 ${INTEGRATION_BRIDGE} | head -1 | awk -F "dpid:" '{print $2}'
228     ${dpnid} =    BuiltIn.Convert To Integer    ${output}    16
229     BuiltIn.Log    ${dpnid}
230     RETURN    ${dpnid}
231
232 Get Subnet
233     [Documentation]    Return the subnet from the system at the given ip address and interface
234     [Arguments]    ${ip}
235     ${output} =    Utils.Run Command On Remote System    ${ip}    /usr/sbin/ip addr show | grep ${ip} | cut -d' ' -f6
236     ${interface} =    ipaddress.ip_interface    ${output}
237     ${network} =    BuiltIn.Set Variable    ${interface.network.__str__()}
238     RETURN    ${network}
239
240 Get Ethernet Adapter
241     [Documentation]    Returns the ethernet adapter name from the system at the given ip address using ip addr show.
242     [Arguments]    ${ip}
243     ${adapter} =    Utils.Run Command On Remote System
244     ...    ${ip}
245     ...    /usr/sbin/ip addr show | grep ${ip} | cut -d " " -f 11
246     BuiltIn.Log    ${adapter}
247     RETURN    ${adapter}
248
249 Get Default Gateway
250     [Documentation]    Returns the default gateway at the given ip address using route command.
251     [Arguments]    ${ip}
252     ${gateway} =    Utils.Run Command On Remote System
253     ...    ${ip}
254     ...    /usr/sbin/route -n | grep '^0.0.0.0' | cut -d " " -f 10
255     BuiltIn.Log    ${gateway}
256     RETURN    ${gateway}
257
258 Get Port Number
259     [Documentation]    Get the port number for the given sub-port id
260     [Arguments]    ${subportid}    ${ip_addr}
261     ${command} =    Set Variable
262     ...    sudo ovs-ofctl -O OpenFlow13 show ${INTEGRATION_BRIDGE} | grep ${subportid} | awk '{print$1}'
263     BuiltIn.Log    sudo ovs-ofctl -O OpenFlow13 show ${INTEGRATION_BRIDGE} | grep ${subportid} | awk '{print$1}'
264     ${output} =    Utils.Run Command On Remote System    ${ip_addr}    ${command}
265     ${port_number} =    BuiltIn.Should Match Regexp    ${output}    [0-9]+
266     RETURN    ${port_number}
267
268 Get Port Metadata
269     [Documentation]    Get the Metadata for a given port
270     [Arguments]    ${ip_addr}    ${port}
271     ${cmd} =    Set Variable
272     ...    sudo ovs-ofctl dump-flows -O Openflow13 ${INTEGRATION_BRIDGE} | grep table=0 | grep in_port=${port}
273     ${output} =    Utils.Run Command On Remote System    ${ip_addr}    ${cmd}
274     @{list_any_matches} =    String.Get_Regexp_Matches    ${output}    metadata:(\\w{12})    1
275     ${metadata} =    Builtin.Convert To String    @{list_any_matches}
276     ${output} =    String.Get Substring    ${metadata}    2
277     RETURN    ${output}
278
279 Log Config And Operational Topology
280     [Documentation]    For debugging purposes, this will log both config and operational topo data stores
281     ${resp} =    RequestsLibrary.Get Request    session    ${RFC8040_CONFIG_TOPO_API}
282     OVSDB.Log Request    ${resp.text}
283     ${resp} =    RequestsLibrary.Get Request    session    ${RFC8040_OPERATIONAL_TOPO_API}
284     OVSDB.Log Request    ${resp.text}
285
286 Config and Operational Topology Should Be Empty
287     [Documentation]    This will check that only the expected output is there for both operational and config
288     ...    topology data stores. Empty probably means that only ovsdb:1 is there.
289     ${config_resp} =    RequestsLibrary.Get Request    session    ${RFC8040_CONFIG_TOPO_API}
290     ${operational_resp} =    RequestsLibrary.Get Request    session    ${RFC8040_OPERATIONAL_TOPO_API}
291     BuiltIn.Should Contain    ${config_resp.text}    {"topology-id":"ovsdb:1"}
292     BuiltIn.Should Contain    ${operational_resp.text}    {"topology-id":"ovsdb:1"}
293
294 Modify Multi Port Body
295     [Documentation]    Updates two port names for the given ${bridge} in config store
296     [Arguments]    ${ovs_1_port_name}    ${ovs_2_port_name}    ${bridge}
297     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/bug_7414/create_multiple_ports.json
298     ${ovs_1_ovsdb_uuid} =    Get OVSDB UUID    ${TOOLS_SYSTEM_IP}
299     ${ovs_2_ovsdb_uuid} =    Get OVSDB UUID    ${TOOLS_SYSTEM_2_IP}
300     ${body} =    Replace String    ${body}    OVS_1_UUID    ${ovs_1_ovsdb_uuid}
301     ${body} =    Replace String    ${body}    OVS_2_UUID    ${ovs_2_ovsdb_uuid}
302     ${body} =    Replace String    ${body}    OVS_1_BRIDGE_NAME    ${bridge}
303     ${body} =    Replace String    ${body}    OVS_2_BRIDGE_NAME    ${bridge}
304     ${body} =    Replace String    ${body}    OVS_1_IP    ${TOOLS_SYSTEM_IP}
305     ${body} =    Replace String    ${body}    OVS_2_IP    ${TOOLS_SYSTEM_2_IP}
306     ${body} =    Replace String    ${body}    OVS_1_PORT_NAME    ${ovs_1_port_name}
307     ${body} =    Replace String    ${body}    OVS_2_PORT_NAME    ${ovs_2_port_name}
308     ${uri} =    Builtin.Set Variable    ${RFC8040_TOPO_API}
309     BuiltIn.Log    URI is ${uri}
310     BuiltIn.Log    data: ${body}
311     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
312     OVSDB.Log Request    ${resp.text}
313     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
314     RETURN    ${body}
315
316 Create Qos
317     [Arguments]    ${qos}
318     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_qos.json
319     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_HOST1_API}/ovsdb:qos-entries=${qos}
320     ${body} =    Replace String    ${body}    QOS-1    ${qos}
321     BuiltIn.Log    URI is ${uri}
322     BuiltIn.Log    data: ${body}
323     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
324     OVSDB.Log Request    ${resp.text}
325     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
326
327 Create Queue
328     [Arguments]    ${queue}
329     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/create_qoslinkedqueue.json
330     ${body} =    Replace String    ${body}    QUEUE-1    ${queue}
331     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_HOST1_API}/ovsdb:queues=${queue}
332     BuiltIn.Log    URI is ${uri}
333     BuiltIn.Log    data: ${body}
334     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
335     OVSDB.Log Request    ${resp.text}
336     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
337
338 Update Qos
339     [Arguments]    ${qos}
340     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/update_existingqos.json
341     ${uri} =    BuiltIn.Set Variable    ${RFC8040_SOUTHBOUND_NODE_HOST1_API}/ovsdb:qos-entries=${QOS}
342     BuiltIn.Log    URL is ${uri}
343     BuiltIn.Log    data: ${body}
344     ${resp} =    RequestsLibrary.Put Request    session    ${uri}    data=${body}
345     OVSDB.Log Request    ${resp.text}
346     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
347
348 Create Qos Linked Queue
349     ${body} =    OperatingSystem.Get File    ${OVSDB_CONFIG_DIR}/bug_7160/create_qoslinkedqueue.json
350     ${resp} =    RequestsLibrary.Put Request    session    ${RFC8040_SOUTHBOUND_NODE_HOST1_API}    data=${body}
351     OVSDB.Log Request    ${resp.text}
352     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
353
354 Add OVS Logging
355     [Documentation]    Add higher levels of OVS logging
356     [Arguments]    ${conn_id}
357     SSHLibrary.Switch Connection    ${conn_id}
358     @{modules} =    BuiltIn.Create List
359     ...    bridge:file:dbg
360     ...    connmgr:file:dbg
361     ...    inband:file:dbg
362     ...    ofp_actions:file:dbg
363     ...    ofp_errors:file:dbg
364     ...    ofp_msgs:file:dbg
365     ...    ovsdb_error:file:dbg
366     ...    rconn:file:dbg
367     ...    tunnel:file:dbg
368     ...    vconn:file:dbg
369     FOR    ${module}    IN    @{modules}
370         Utils.Write Commands Until Expected Prompt
371         ...    sudo ovs-appctl --target ovs-vswitchd vlog/set ${module}
372         ...    ${DEFAULT_LINUX_PROMPT_STRICT}
373     END
374     Utils.Write Commands Until Expected Prompt
375     ...    sudo ovs-appctl --target ovs-vswitchd vlog/list
376     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
377
378 Reset OVS Logging
379     [Documentation]    Reset the OVS logging
380     [Arguments]    ${conn_id}
381     SSHLibrary.Switch Connection    ${conn_id}
382     ${output} =    Utils.Write Commands Until Expected Prompt
383     ...    sudo ovs-appctl --target ovs-vswitchd vlog/set :file:info
384     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
385
386 Suite Setup
387     SetupUtils.Setup_Utils_For_Setup_And_Teardown
388     KarafKeywords.Open Controller Karaf Console On Background
389     RequestsLibrary.Create Session
390     ...    session
391     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
392     ...    auth=${AUTH}
393     ...    headers=${HEADERS}
394     OVSDB.Log Config And Operational Topology
395
396 Suite Teardown
397     [Documentation]    Cleans up test environment, close existing sessions.
398     [Arguments]    ${uris}=@{EMPTY}
399     OVSDB.Clean OVSDB Test Environment    ${TOOLS_SYSTEM_IP}
400     FOR    ${uri}    IN    @{uris}
401         RequestsLibrary.Delete Request    session    ${uri}
402     END
403     ${resp} =    RequestsLibrary.Get Request    session    ${RFC8040_CONFIG_TOPO_API}
404     OVSDB.Log Config And Operational Topology
405     RequestsLibrary.Delete All Sessions
406
407 Get DumpFlows And Ovsconfig
408     [Documentation]    Get the OvsConfig and Flow entries from OVS
409     [Arguments]    ${conn_id}    ${bridge}
410     SSHLibrary.Switch Connection    ${conn_id}
411     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
412     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
413     Write Commands Until Expected Prompt
414     ...    sudo ovs-ofctl show ${bridge} -OOpenFlow13
415     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
416     Write Commands Until Expected Prompt
417     ...    sudo ovs-ofctl dump-flows ${bridge} -OOpenFlow13
418     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
419     Write Commands Until Expected Prompt
420     ...    sudo ovs-ofctl dump-groups ${bridge} -OOpenFlow13
421     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
422     Write Commands Until Expected Prompt
423     ...    sudo ovs-ofctl dump-group-stats ${bridge} -OOpenFlow13
424     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
425     Write Commands Until Expected Prompt    sudo ovs-vsctl list interface    ${DEFAULT_LINUX_PROMPT_STRICT}
426
427 Start OVS
428     [Documentation]    start the OVS node.
429     [Arguments]    ${ovs_ip}
430     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
431     BuiltIn.Log    ${output}
432
433 Stop OVS
434     [Documentation]    Stop the OVS node.
435     [Arguments]    ${ovs_ip}
436     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
437     BuiltIn.Log    ${output}
438
439 Get Bridge Data
440     [Documentation]    This keyword returns first bridge name and UUID from list of bridges.
441     ${result} =    SSHLibrary.Execute Command    sudo ovs-vsctl show
442     ${uuid} =    String.Get Line    ${result}    0
443     ${line}    ${bridge_name} =    Builtin.Should Match Regexp    ${result}    Bridge ([\\w-]+)
444     RETURN    ${uuid}    ${bridge_name}
445
446 Delete OVS Controller
447     [Documentation]    Delete controller from OVS
448     [Arguments]    ${ovs_ip}    ${bridge}=${INTEGRATION_BRIDGE}
449     ${del_ctr} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-controller ${bridge}
450     BuiltIn.Log    ${del_ctr}
451
452 Delete OVS Manager
453     [Documentation]    Delete manager from OVS
454     [Arguments]    ${ovs_ip}
455     ${del_mgr} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-manager
456     BuiltIn.Log    ${del_mgr}
457
458 Delete Groups On Bridge
459     [Documentation]    Delete OVS groups from ${br}
460     [Arguments]    ${ovs_ip}    ${br}=${INTEGRATION_BRIDGE}
461     ${del_grp} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-ofctl -O Openflow13 del-groups ${br}
462     BuiltIn.Log    ${del_grp}
463
464 Get Ports From Bridge By Type
465     [Documentation]    Get ${type} ports for a bridge ${br} on node ${ovs_ip}.
466     [Arguments]    ${ovs_ip}    ${br}    ${type}
467     ${ports} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl list-ports ${br} | grep "${type}"
468     ${ports_list} =    String.Split to lines    ${ports}
469     RETURN    ${ports_list}
470
471 Delete Ports On Bridge By Type
472     [Documentation]    List all ports of ${br} and delete ${type} ports
473     [Arguments]    ${ovs_ip}    ${br}    ${type}
474     ${ports_present} =    Get Ports From Bridge By Type    ${ovs_ip}    ${br}    ${type}
475     FOR    ${port}    IN    @{ports_present}
476         ${del-ports} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-port ${br} ${port}
477         BuiltIn.Log    ${del-ports}
478     END
479     ${ports_present_after_delete} =    Get Ports From Bridge By Type    ${ovs_ip}    ${br}    ${type}
480     BuiltIn.Log    ${ports_present_after_delete}
481
482 Get Tunnel Id And Packet Count
483     [Documentation]    Get tunnel id and packet count from specified table id
484     ...    Using regex get the n_packet and the tunnel_id from the table flow.
485     [Arguments]    ${conn_id}    ${table_id}    ${tun_id}    ${mac}=""
486     ${tun_id} =    BuiltIn.Convert To Hex    ${tun_id}    prefix=0x    lowercase=yes
487     IF    "${table_id}" == "${INTERNAL_TUNNEL_TABLE}"
488         ${cmd} =    BuiltIn.Set Variable
489         ...    sudo ovs-ofctl dump-flows br-int -OOpenFlow13 | grep table=${table_id} | grep ${mac} | grep tun_id=${tun_id} | grep goto_table:${ELAN_DMACTABLE}
490     ELSE
491         ${cmd} =    BuiltIn.Set Variable
492         ...    sudo ovs-ofctl dump-flows br-int -OOpenFlow13 | grep table=${table_id} | grep ${mac}
493     END
494     SSHLibrary.Switch Connection    ${conn_id}
495     ${output} =    Utils.Write Commands Until Expected Prompt    ${cmd}    ${DEFAULT_LINUX_PROMPT_STRICT}
496     @{list} =    Split to lines    ${output}
497     ${output} =    Set Variable    ${list}[0]
498     ${output} =    String.Get Regexp Matches
499     ...    ${output}
500     ...    n_packets=([0-9]+),.*set_field:(0x[0-9a-z]+)|n_packets=([0-9]+),.*tun_id=(0x[0-9a-z]+)
501     ...    1
502     ...    2
503     ...    3
504     ...    4
505     ${output} =    BuiltIn.Set Variable    ${output}[0]
506     ${output} =    Convert To List    ${output}
507     IF    "${table_id}" == "${ELAN_DMACTABLE}"
508         ${packet_count}    ${tunnel_id} =    BuiltIn.Set Variable    ${output}[0]    ${output}[1]
509     ELSE IF    "${table_id}" == "${INTERNAL_TUNNEL_TABLE}"
510         ${packet_count}    ${tunnel_id} =    BuiltIn.Set Variable    ${output}[2]    ${output}[3]
511     ELSE IF    "${table_id}" == "${L3_TABLE}"
512         ${packet_count}    ${tunnel_id} =    BuiltIn.Set Variable    ${output}[0]    ${output}[1]
513     ELSE
514         ${packet_count}    ${tunnel_id} =    Set Variable    ${None}    ${None}
515     END
516     ${tunnel_id} =    Convert To Integer    ${tunnel_id}    16
517     RETURN    ${tunnel_id}    ${packet_count}
518
519 Verify Dump Flows For Specific Table
520     [Documentation]    To Verify flows are present for the corresponding table Number
521     [Arguments]    ${compute_ip}    ${table_num}    ${flag}    ${additional_args}=${EMPTY}    @{matching_paras}
522     ${flow_output} =    Utils.Run Command On Remote System
523     ...    ${compute_ip}
524     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${INTEGRATION_BRIDGE}|grep table=${table_num} ${additional_args}
525     Log    ${flow_output}
526     FOR    ${matching_str}    IN    @{matching_paras}
527         IF    ${flag}==True
528             BuiltIn.Should Contain    ${flow_output}    ${matching_str}
529         ELSE
530             BuiltIn.Should Not Contain    ${flow_output}    ${matching_str}
531         END
532     END
533
534 Verify Vni Segmentation Id and Tunnel Id
535     [Documentation]    Get tunnel id and packet count from specified table id and destination port mac address
536     [Arguments]    ${port1}    ${port2}    ${net1}    ${net2}    ${vm1_ip}    ${vm2_ip}
537     ...    ${ip}=""
538     ${port_mac1} =    OpenStackOperations.Get Port Mac    ${port1}
539     ${port_mac2} =    OpenStackOperations.Get Port Mac    ${port2}
540     ${segmentation_id1} =    OpenStackOperations.Get Network Segmentation Id    ${net1}
541     ${segmentation_id2} =    OpenStackOperations.Get Network Segmentation Id    ${net2}
542     ${egress_tun_id}    ${before_count_egress_port1} =    OVSDB.Get Tunnel Id And Packet Count
543     ...    ${OS_CMP1_CONN_ID}
544     ...    ${L3_TABLE}
545     ...    tun_id=${segmentation_id2}
546     ...    mac=${port_mac2}
547     BuiltIn.Should Be Equal As Numbers    ${segmentation_id2}    ${egress_tun_id}
548     ${egress_tun_id}    ${before_count_egress_port2} =    OVSDB.Get Tunnel Id And Packet Count
549     ...    ${OS_CMP2_CONN_ID}
550     ...    ${L3_TABLE}
551     ...    tun_id=${segmentation_id1}
552     ...    mac=${port_mac1}
553     BuiltIn.Should Be Equal As Numbers    ${segmentation_id1}    ${egress_tun_id}
554     ${ingress_tun_id}    ${before_count_ingress_port1} =    OVSDB.Get Tunnel Id And Packet Count
555     ...    ${OS_CMP1_CONN_ID}
556     ...    ${INTERNAL_TUNNEL_TABLE}
557     ...    tun_id=${segmentation_id1}
558     BuiltIn.Should Be Equal As Numbers    ${segmentation_id1}    ${ingress_tun_id}
559     ${ingress_tun_id}    ${before_count_ingress_port2} =    OVSDB.Get Tunnel Id And Packet Count
560     ...    ${OS_CMP2_CONN_ID}
561     ...    ${INTERNAL_TUNNEL_TABLE}
562     ...    tun_id=${segmentation_id2}
563     BuiltIn.Should Be Equal As Numbers    ${segmentation_id2}    ${ingress_tun_id}
564     IF    '${ip}'=='ipv4'
565         ${ping_cmd} =    BuiltIn.Set Variable    ping -c ${DEFAULT_PING_COUNT} ${vm2_ip}
566     ELSE
567         ${ping_cmd} =    BuiltIn.Set Variable    ping6 -c ${DEFAULT_PING_COUNT} ${vm2_ip}
568     END
569     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net1}    ${vm1_ip}    ${ping_cmd}
570     BuiltIn.Should Contain    ${output}    64 bytes
571     BuiltIn.Wait Until Keyword Succeeds
572     ...    60s
573     ...    5s
574     ...    OVSDB.Verify Vni Packet Count After Traffic
575     ...    ${before_count_egress_port1}
576     ...    ${before_count_egress_port2}
577     ...    ${before_count_ingress_port1}
578     ...    ${before_count_ingress_port2}
579     ...    ${segmentation_id1}
580     ...    ${segmentation_id2}
581     ...    ${port_mac1}
582     ...    ${port_mac2}
583
584 Verify Vni Packet Count After Traffic
585     [Documentation]    Verify the packet count after the traffic sent
586     [Arguments]    ${before_count_egress_port1}    ${before_count_egress_port2}    ${before_count_ingress_port1}    ${before_count_ingress_port2}    ${segmentation_id1}    ${segmentation_id2}
587     ...    ${port_mac1}    ${port_mac2}
588     ${tun_id}    ${after_count_egress_port2} =    OVSDB.Get Tunnel Id And Packet Count
589     ...    ${OS_CMP2_CONN_ID}
590     ...    ${L3_TABLE}
591     ...    tun_id=${segmentation_id1}
592     ...    mac=${port_mac1}
593     ${tun_id}    ${after_count_ingress_port2} =    OVSDB.Get Tunnel Id And Packet Count
594     ...    ${OS_CMP2_CONN_ID}
595     ...    ${INTERNAL_TUNNEL_TABLE}
596     ...    tun_id=${segmentation_id2}
597     ${tun_id}    ${after_count_egress_port1} =    OVSDB.Get Tunnel Id And Packet Count
598     ...    ${OS_CMP1_CONN_ID}
599     ...    ${L3_TABLE}
600     ...    tun_id=${segmentation_id2}
601     ...    mac=${port_mac2}
602     ${tun_id}    ${after_count_ingress_port1} =    OVSDB.Get Tunnel Id And Packet Count
603     ...    ${OS_CMP1_CONN_ID}
604     ...    ${INTERNAL_TUNNEL_TABLE}
605     ...    tun_id=${segmentation_id1}
606     ${diff_count_egress_port1} =    BuiltIn.Evaluate    ${after_count_egress_port1} - ${before_count_egress_port1}
607     ${diff_count_ingress_port1} =    BuiltIn.Evaluate    ${after_count_ingress_port1} - ${before_count_ingress_port1}
608     ${diff_count_egress_port2} =    BuiltIn.Evaluate    ${after_count_egress_port2} - ${before_count_egress_port2}
609     ${diff_count_ingress_port2} =    BuiltIn.Evaluate    ${after_count_ingress_port2} - ${before_count_ingress_port2}
610     BuiltIn.Should Be True    ${diff_count_egress_port1} >= ${DEFAULT_PING_COUNT}
611     BuiltIn.Should Be True    ${diff_count_ingress_port1} >= ${DEFAULT_PING_COUNT}
612     BuiltIn.Should Be True    ${diff_count_egress_port2} >= ${DEFAULT_PING_COUNT}
613     BuiltIn.Should Be True    ${diff_count_ingress_port2} >= ${DEFAULT_PING_COUNT}
614
615 Get Flow Entries On Node
616     [Documentation]    Return flow entries on the given Node.
617     [Arguments]    ${conn_id}    ${switch}=${INTEGRATION_BRIDGE}
618     SSHLibrary.Switch Connection    ${conn_id}
619     ${output} =    Utils.Write Commands Until Expected Prompt
620     ...    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch}
621     ...    ${DEFAULT_LINUX_PROMPT_STRICT}
622     BuiltIn.Log    ${output}
623     RETURN    ${output}
624
625 Verify Ovsdb State
626     [Documentation]    Verify ovsdb state for the given DPN
627     [Arguments]    ${dpn_ip}    ${state}=ACTIVE
628     ${output} =    Utils.Run Command On Remote System And Log
629     ...    ${dpn_ip}
630     ...    sudo ovsdb-client dump -f list Open_vSwitch Controller | grep state
631     BuiltIn.Log    ${output}
632     BuiltIn.Should Contain    ${output}    state=${state}
633
634 Verify Flows Are Present On Node
635     [Documentation]    Verify Flows Are Present On The Given Node
636     [Arguments]    ${conn_id}    ${match}
637     ${output} =    OVSDB.Get Flow Entries On Node    ${conn_id}
638     BuiltIn.Should Contain    ${output}    ${match}