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