SXP: Make cluster routing suite more readable
[integration/test.git] / csit / libraries / OvsManager.robot
index 22299d4a1cee89ad8ae1d38b5af5bcd911eb8341..f3852fd9d8dae1549234c65febfec40bd5947556 100644 (file)
@@ -48,8 +48,12 @@ Execute OvsVsctl Show Command
     Log    ${output}
 
 Set Bridge Controllers
-    [Arguments]    ${bridge}    ${controllers}    ${disconnected}=${False}
+    [Arguments]    ${bridge}    ${controllers}    ${ofversion}=13    ${disconnected}=${False}
     [Documentation]    Adds controller to the bridge
+    ${cmd}=    BuiltIn.Set Variable    ${lcmd_prefix} ovs-vsctl set bridge ${bridge} protocols=OpenFlow${ofversion}
+    SSHLibrary.Write    ${cmd}
+    ${output}=    SSHLibrary.Read_Until    ${lprompt}
+    Log    ${output}
     ${cmd}=    BuiltIn.Set Variable    ${lcmd_prefix} ovs-vsctl set-controller ${bridge}
     : FOR    ${cntl}    IN    @{controllers}
     \    ${cmd}=    BuiltIn.Set Variable If    ${disconnected}==${False}    ${cmd} tcp:${cntl}:6653    ${cmd} tcp:${cntl}:6654
@@ -202,3 +206,34 @@ OvsManager__Enable_Slaves_For_Switch
     \    ${role}=    Collections.Get From Dictionary    ${cntl_value}    role
     \    ${connected}=    Collections.Get From Dictionary    ${cntl_value}    is_connected
     \    Run Keyword If    ${connected}==${False}    Reconnect Switch To Controller And Verify Connected    ${switch}    ${cntl_id}    verify_connected=${verify_connected}
+
+Get Dump Flows Count
+    [Arguments]    ${conn_id}    ${acl_sr_table_id}    ${port_mac}=""
+    [Documentation]    Count the number of dump flows for a given table id
+    ...    and grep with port_mac if provided
+    ${cmd} =    BuiltIn.Set Variable    sudo ovs-ofctl dump-flows br-int -OOpenFlow13 | grep table=${acl_sr_table_id} | grep ${port_mac} | wc -l
+    SSHLibrary.Switch Connection    ${conn_id}
+    ${output} =    Utils.Write Commands Until Expected Prompt    ${cmd}    ${DEFAULT_LINUX_PROMPT_STRICT}
+    @{list} =    String.Split String    ${output}
+    [Return]    ${list[0]}
+
+Get Packet Count From Table
+    [Arguments]    ${system_ip}    ${br_name}    ${table_no}    ${addtioanal_args}=${EMPTY}
+    [Documentation]    Return packet count for the specific table no.
+    ${flow_output} =    Utils.Run Command On Remote System    ${system_ip}    sudo ovs-ofctl dump-flows -O Openflow13 ${br_name} | grep ${table_no} ${addtioanal_args}
+    @{output} =    String.Split String    ${flow_output}    \r\n
+    ${flow} =    Collections.Get From List    ${output}    0
+    ${packetcountlist} =    String.Get Regexp Matches    ${flow}    n_packets=([0-9]+),    1
+    ${packetcount} =    Collections.Get From List    ${packetcountlist}    0
+    [Return]    ${packetcount}
+
+Get Packet Count In Table For IP
+    [Arguments]    ${os_compute_ip}    ${table_no}    ${ip_address}    ${additional_args}=${EMPTY}
+    [Documentation]    Capture packetcount for IP in Table
+    ${cmd} =    BuiltIn.Set Variable    sudo ovs-ofctl dump-flows br-int -OOpenFlow13 | grep table=${table_no} | grep ${ip_address} ${additional_args}
+    ${output} =    Utils.Run Command On Remote System And Log    ${os_compute_ip}    ${cmd}
+    @{output_list} =    String.Split String    ${output}    \r\n
+    ${flow} =    Collections.Get From List    ${output_list}    0
+    ${packetcount_list} =    String.Get Regexp Matches    ${flow}    n_packets=([0-9]+)    1
+    ${count} =    Collections.Get From List    ${packetcount_list}    0
+    [Return]    ${count}