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