c2963e621b07a568372addfd716ab6f1a0617d0f
[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 systemctl restart openvswitch
165     BuiltIn.Log    ${output}
166
167 Set Controller In OVS Bridge
168     [Arguments]    ${tools_system}    ${bridge}    ${controller_opt}    ${ofversion}=13
169     [Documentation]    Sets controller for the OVS bridge ${bridge} using ${controller_opt} and OF version ${ofversion}.
170     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set bridge ${bridge} protocols=OpenFlow${ofversion}
171     Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl set-controller ${bridge} ${controller_opt}
172
173 Check OVS OpenFlow Connections
174     [Arguments]    ${tools_system}    ${of_connections}
175     [Documentation]    Check OVS instance with IP ${tools_system} has ${of_connections} OpenFlow connections.
176     ${output} =    Utils.Run Command On Mininet    ${tools_system}    sudo ovs-vsctl show
177     BuiltIn.Log    ${output}
178     BuiltIn.Should Contain X Times    ${output}    is_connected    ${of_connections}
179
180 Add Multiple Managers to OVS
181     [Arguments]    ${tools_system}=${TOOLS_SYSTEM_IP}    ${controller_index_list}=${EMPTY}    ${ovs_mgr_port}=6640
182     [Documentation]    Connect OVS to the list of controllers in the ${controller_index_list} or all if no list is provided.
183     ${index_list} =    ClusterManagement.List Indices Or All    given_list=${controller_index_list}
184     Utils.Clean Mininet System    ${tools_system}
185     ${ovs_opt} =    BuiltIn.Set Variable
186     : FOR    ${index}    IN    @{index_list}
187     \    ${ovs_opt} =    BuiltIn.Catenate    ${ovs_opt}    ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ovs_mgr_port}
188     \    BuiltIn.Log    ${ovs_opt}
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    ${CONFIG_TOPO_API}
249     OVSDB.Log Request    ${resp.content}
250     ${resp} =    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
251     OVSDB.Log Request    ${resp.content}
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    ${CONFIG_TOPO_API}
257     ${operational_resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
258     BuiltIn.Should Contain    ${config_resp.content}    {"topology-id":"ovsdb:1"}
259     BuiltIn.Should Contain    ${operational_resp.content}    {"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    ${CONFIG_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.content}
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    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:HOST1/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.content}
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    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:HOST1/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.content}
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    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:HOST1/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.content}
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    ${CONFIG_TOPO_API}/topology/ovsdb:1/node/ovsdb:HOST1    data=${body}
318     OVSDB.Log Request    ${resp.content}
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     Utils.Write Commands Until Expected Prompt    sudo ovs-appctl --target ovs-vswitchd vlog/list    ${DEFAULT_LINUX_PROMPT_STRICT}
330
331 Reset OVS Logging
332     [Arguments]    ${conn_id}
333     [Documentation]    Reset the OVS logging
334     SSHLibrary.Switch Connection    ${conn_id}
335     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ovs-appctl --target ovs-vswitchd vlog/set :file:info    ${DEFAULT_LINUX_PROMPT_STRICT}
336
337 Suite Setup
338     SetupUtils.Setup_Utils_For_Setup_And_Teardown
339     KarafKeywords.Open Controller Karaf Console On Background
340     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
341     OVSDB.Log Config And Operational Topology
342
343 Suite Teardown
344     [Arguments]    ${uris}=@{EMPTY}
345     [Documentation]    Cleans up test environment, close existing sessions.
346     OVSDB.Clean OVSDB Test Environment    ${TOOLS_SYSTEM_IP}
347     : FOR    ${uri}    IN    @{uris}
348     \    RequestsLibrary.Delete Request    session    ${uri}
349     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_TOPO_API}
350     OVSDB.Log Config And Operational Topology
351     RequestsLibrary.Delete All Sessions
352
353 Get DumpFlows And Ovsconfig
354     [Arguments]    ${conn_id}    ${bridge}
355     [Documentation]    Get the OvsConfig and Flow entries from OVS
356     SSHLibrary.Switch Connection    ${conn_id}
357     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
358     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
359     Write Commands Until Expected Prompt    sudo ovs-ofctl show ${bridge} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
360     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows ${bridge} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
361     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups ${bridge} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
362     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats ${bridge} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
363     Write Commands Until Expected Prompt    sudo ovs-vsctl list interface    ${DEFAULT_LINUX_PROMPT_STRICT}
364
365 Start OVS
366     [Arguments]    ${ovs_ip}
367     [Documentation]    start the OVS node.
368     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl start
369     BuiltIn.Log    ${output}
370
371 Stop OVS
372     [Arguments]    ${ovs_ip}
373     [Documentation]    Stop the OVS node.
374     ${output} =    Utils.Run Command On Mininet    ${ovs_ip}    sudo /usr/share/openvswitch/scripts/ovs-ctl stop
375     BuiltIn.Log    ${output}
376
377 Get Bridge Data
378     [Documentation]    This keyword returns first bridge name and UUID from list of bridges.
379     ${result} =    SSHLibrary.Execute Command    sudo ovs-vsctl show
380     ${uuid} =    String.Get Line    ${result}    0
381     ${line}    ${bridge_name}    Builtin.Should Match Regexp    ${result}    Bridge ([\\w-]+)
382     [Return]    ${uuid}    ${bridge_name}
383
384 Delete OVS Controller
385     [Arguments]    ${ovs_ip}    ${bridge}=${INTEGRATION_BRIDGE}
386     [Documentation]    Delete controller from OVS
387     ${del_ctr} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-controller ${bridge}
388     BuiltIn.Log    ${del_ctr}
389
390 Delete OVS Manager
391     [Arguments]    ${ovs_ip}
392     [Documentation]    Delete manager from OVS
393     ${del_mgr} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-manager
394     BuiltIn.Log    ${del_mgr}
395
396 Delete Groups On Bridge
397     [Arguments]    ${ovs_ip}    ${br}=${INTEGRATION_BRIDGE}
398     [Documentation]    Delete OVS groups from ${br}
399     ${del_grp} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-ofctl -O Openflow13 del-groups ${br}
400     BuiltIn.Log    ${del_grp}
401
402 Get Ports From Bridge By Type
403     [Arguments]    ${ovs_ip}    ${br}    ${type}
404     [Documentation]    Get ${type} ports for a bridge ${br} on node ${ovs_ip}.
405     ${ports} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl list-ports ${br} | grep "${type}"
406     ${ports_list} =    String.Split to lines    ${ports}
407     [Return]    ${ports_list}
408
409 Delete Ports On Bridge By Type
410     [Arguments]    ${ovs_ip}    ${br}    ${type}
411     [Documentation]    List all ports of ${br} and delete ${type} ports
412     ${ports_present} =    Get Ports From Bridge By Type    ${ovs_ip}    ${br}    ${type}
413     : FOR    ${port}    IN    @{ports_present}
414     \    ${del-ports} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-vsctl del-port ${br} ${port}
415     \    BuiltIn.Log    ${del-ports}
416     ${ports_present_after_delete} =    Get Ports From Bridge By Type    ${ovs_ip}    ${br}    ${type}
417     BuiltIn.Log    ${ports_present_after_delete}
418
419 Get Tunnel Id And Packet Count
420     [Arguments]    ${conn_id}    ${table_id}    ${tun_id}    ${mac}=""
421     [Documentation]    Get tunnel id and packet count from specified table id
422     ...    Using regex get the n_packet and the tunnel_id from the table flow.
423     ${tun_id} =    BuiltIn.Convert To Hex    ${tun_id}    prefix=0x    lowercase=yes
424     ${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}
425     ...    ELSE    BuiltIn.Set Variable    sudo ovs-ofctl dump-flows br-int -OOpenFlow13 | grep table=${table_id} | grep ${mac}
426     SSHLibrary.Switch Connection    ${conn_id}
427     ${output} =    Utils.Write Commands Until Expected Prompt    ${cmd}    ${DEFAULT_LINUX_PROMPT_STRICT}
428     @{list}=    Split to lines    ${output}
429     ${output} =    Set Variable    @{list}[0]
430     ${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
431     ...    4
432     ${output} =    BuiltIn.Set Variable    @{output}[0]
433     ${output}    Convert To List    ${output}
434     ${packet_count}    ${tunnel_id} =    BuiltIn.Run Keyword If    "${table_id}" == "${ELAN_DMACTABLE}"    BuiltIn.Set Variable    @{output}[0]    @{output}[1]
435     ...    ELSE IF    "${table_id}" == "${INTERNAL_TUNNEL_TABLE}"    BuiltIn.Set Variable    @{output}[2]    @{output}[3]
436     ...    ELSE IF    "${table_id}" == "${L3_TABLE}"    BuiltIn.Set Variable    @{output}[0]    @{output}[1]
437     ${tunnel_id} =    Convert To Integer    ${tunnel_id}    16
438     [Return]    ${tunnel_id}    ${packet_count}
439
440 Verify Dump Flows For Specific Table
441     [Arguments]    ${compute_ip}    ${table_num}    ${flag}    ${additional_args}=${EMPTY}    @{matching_paras}
442     [Documentation]    To Verify flows are present for the corresponding table Number
443     ${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}
444     Log    ${flow_output}
445     : FOR    ${matching_str}    IN    @{matching_paras}
446     \    BuiltIn.Run Keyword If    ${flag}==True    BuiltIn.Should Contain    ${flow_output}    ${matching_str}
447     \    ...    ELSE    BuiltIn.Should Not Contain    ${flow_output}    ${matching_str}
448
449 Verify Vni Segmentation Id and Tunnel Id
450     [Arguments]    ${port1}    ${port2}    ${net1}    ${net2}    ${vm1_ip}    ${vm2_ip}
451     ...    ${ip}=""
452     [Documentation]    Get tunnel id and packet count from specified table id and destination port mac address
453     ${port_mac1} =    OpenStackOperations.Get Port Mac    ${port1}
454     ${port_mac2} =    OpenStackOperations.Get Port Mac    ${port2}
455     ${segmentation_id1} =    OpenStackOperations.Get Network Segmentation Id    ${net1}
456     ${segmentation_id2} =    OpenStackOperations.Get Network Segmentation Id    ${net2}
457     ${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}
458     BuiltIn.Should Be Equal As Numbers    ${segmentation_id2}    ${egress_tun_id}
459     ${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}
460     BuiltIn.Should Be Equal As Numbers    ${segmentation_id1}    ${egress_tun_id}
461     ${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}
462     BuiltIn.Should Be Equal As Numbers    ${segmentation_id1}    ${ingress_tun_id}
463     ${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}
464     BuiltIn.Should Be Equal As Numbers    ${segmentation_id2}    ${ingress_tun_id}
465     ${ping_cmd} =    BuiltIn.Run Keyword If    '${ip}'=='ipv4'    BuiltIn.Set Variable    ping -c ${DEFAULT_PING_COUNT} ${vm2_ip}
466     ...    ELSE    BuiltIn.Set Variable    ping6 -c ${DEFAULT_PING_COUNT} ${vm2_ip}
467     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net1}    ${vm1_ip}    ${ping_cmd}
468     BuiltIn.Should Contain    ${output}    64 bytes
469     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}
470     ...    ${before_count_ingress_port2}    ${segmentation_id1}    ${segmentation_id2}    ${port_mac1}    ${port_mac2}
471
472 Verify Vni Packet Count After Traffic
473     [Arguments]    ${before_count_egress_port1}    ${before_count_egress_port2}    ${before_count_ingress_port1}    ${before_count_ingress_port2}    ${segmentation_id1}    ${segmentation_id2}
474     ...    ${port_mac1}    ${port_mac2}
475     [Documentation]    Verify the packet count after the traffic sent
476     ${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}
477     ${tun_id}    ${after_count_ingress_port2} =    OVSDB.Get Tunnel Id And Packet Count    ${OS_CMP2_CONN_ID}    ${INTERNAL_TUNNEL_TABLE}    tun_id=${segmentation_id2}
478     ${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}
479     ${tun_id}    ${after_count_ingress_port1} =    OVSDB.Get Tunnel Id And Packet Count    ${OS_CMP1_CONN_ID}    ${INTERNAL_TUNNEL_TABLE}    tun_id=${segmentation_id1}
480     ${diff_count_egress_port1} =    BuiltIn.Evaluate    ${after_count_egress_port1} - ${before_count_egress_port1}
481     ${diff_count_ingress_port1} =    BuiltIn.Evaluate    ${after_count_ingress_port1} - ${before_count_ingress_port1}
482     ${diff_count_egress_port2} =    BuiltIn.Evaluate    ${after_count_egress_port2} - ${before_count_egress_port2}
483     ${diff_count_ingress_port2} =    BuiltIn.Evaluate    ${after_count_ingress_port2} - ${before_count_ingress_port2}
484     BuiltIn.Should Be True    ${diff_count_egress_port1} >= ${DEFAULT_PING_COUNT}
485     BuiltIn.Should Be True    ${diff_count_ingress_port1} >= ${DEFAULT_PING_COUNT}
486     BuiltIn.Should Be True    ${diff_count_egress_port2} >= ${DEFAULT_PING_COUNT}
487     BuiltIn.Should Be True    ${diff_count_ingress_port2} >= ${DEFAULT_PING_COUNT}
488
489 Get Flow Entries On Node
490     [Arguments]    ${conn_id}    ${switch}=${INTEGRATION_BRIDGE}
491     [Documentation]    Return flow entries on the given Node.
492     SSHLibrary.Switch Connection    ${conn_id}
493     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows ${switch}    ${DEFAULT_LINUX_PROMPT_STRICT}
494     BuiltIn.Log    ${output}
495     [Return]    ${output}