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