Disable stale marking feature test
[integration/test.git] / csit / libraries / MininetKeywords.robot
index 2b4155c9d8165adb79d8f9c028e9659a59bc6216..2528d7882f3750dee9a157a35a96a286fe38c96f 100644 (file)
@@ -58,6 +58,12 @@ Start Mininet Multiple Controllers
     SSHLibrary.Read Until    mininet>
     [Return]    ${mininet_conn_id}
 
+Start Mininet Multiple Hosts
+    [Arguments]    ${hosts}    ${mininet}=${TOOLS_SYSTEM_IP}    ${controller}=${ODL_SYSTEM_IP}    ${mininet_timeout}=${DEFAULT_TIMEOUT}
+    [Documentation]    Start mininet 1 switch with ${hosts} hosts attached.
+    Log    Start Mininet Linear
+    MininetKeywords.StartMininet Single Controller    options=--topo single,${hosts} --mac --switch ovsk,protocols=OpenFlow13    timeout=${mininet_timeout}
+
 Start Mininet Linear
     [Arguments]    ${switches}    ${mininet}=${TOOLS_SYSTEM_IP}    ${controller}=${ODL_SYSTEM_IP}    ${mininet_timeout}=${DEFAULT_TIMEOUT}
     [Documentation]    Start mininet linear topology with ${switches} nodes.
@@ -76,9 +82,9 @@ Start Mininet Full Mesh
     SSHLibrary.Read Until    ${TOOLS_SYSTEM_PROMPT}
     Log    Start Mininet Full Mesh
     SSHLibrary.Write    sudo mn --controller=remote,ip=${controller} --custom switch.py --topo demotopo --switch ovsk,protocols=OpenFlow13
-    Read Until    mininet>
+    SSHLibrary.Read Until    mininet>
     Log    Check OVS configuratiom
-    Write    sh ovs-vsctl show
+    SSHLibrary.Write    sh ovs-vsctl show
     ${output}=    Read Until    mininet>
     # Ovsdb connection is sometimes lost after mininet is started. Checking if the connection is alive before proceeding.
     Should Not Contain    ${output}    database connection failed
@@ -114,6 +120,19 @@ Stop Mininet And Exit Multiple Sessions
     : FOR    ${mininet_conn}    IN    @{mininet_conn_list}
     \    MininetKeywords.Stop Mininet And Exit    ${mininet_conn}
 
+Disconnect Cluster Mininet
+    [Arguments]    ${action}=break    ${member_index_list}=${EMPTY}
+    [Documentation]    Break and restore controller to mininet connection via iptables.
+    ${index_list} =    ClusterManagement.List_Indices_Or_All    given_list=${member_index_list}
+    : FOR    ${index}    IN    @{index_list}
+    \    ${rule} =    BuiltIn.Set Variable    OUTPUT -p all --source ${ODL_SYSTEM_${index}_IP} --destination ${TOOLS_SYSTEM_IP} -j DROP
+    \    ${command} =    BuiltIn.Set Variable If    '${action}'=='restore'    sudo /sbin/iptables -D ${rule}    sudo /sbin/iptables -I ${rule}
+    \    Log To Console    ${ODL_SYSTEM_${index}_IP}
+    \    Utils.Run Command On Controller    ${ODL_SYSTEM_${index}_IP}    cmd=${command}
+    \    ${command} =    BuiltIn.Set Variable    sudo /sbin/iptables -L -n
+    \    ${output} =    Utils.Run Command On Controller    cmd=${command}
+    \    BuiltIn.Log    ${output}
+
 Verify Aggregate Flow From Mininet Session
     [Arguments]    ${mininet_conn}=${EMPTY}    ${flow_count}=0    ${time_out}=0s
     [Documentation]    Verify flow count per switch
@@ -132,13 +151,44 @@ Check Flows In Mininet
 Verify Mininet Ping
     [Arguments]    ${host1}    ${host2}
     [Documentation]    Send ping from mininet and verify connectivity.
-    Write    ${host1} ping -w 3 ${host2}
-    ${result}=    Read Until    mininet>
+    SSHLibrary.Write    ${host1} ping -w 3 ${host2}
+    ${result}=    SSHLibrary.Read Until    mininet>
     Should Contain    ${result}    64 bytes
 
 Verify Mininet No Ping
     [Arguments]    ${host1}    ${host2}
     [Documentation]    Send ping from mininet and verify no conectivity.
-    Write    ${host1} ping -w 3 ${host2}
-    ${result}=    Read Until    mininet>
+    SSHLibrary.Write    ${host1} ping -w 3 ${host2}
+    ${result}=    SSHLibrary.Read Until    mininet>
     Should Contain    ${result}    100% packet loss
+
+Ping All Hosts
+    [Arguments]    @{host_list}
+    [Documentation]    Do one round of ping from one host to all other hosts in mininet.
+    ...    Note that a single ping failure will exit the loop and return a non zero value.
+    ${source}=    Get From List    ${host_list}    ${0}
+    : FOR    ${h}    IN    @{host_list}
+    \    ${status}=    Ping Two Hosts    ${source}    ${h}    1
+    \    Exit For Loop If    ${status}!=${0}
+    [Return]    ${status}
+
+Ping Two Hosts
+    [Arguments]    ${host1}    ${host2}    ${pingcount}=2
+    [Documentation]    Ping between mininet hosts. Must be used only after a mininet session is in place.
+    ...    Returns non zero value if there is 100% packet loss.
+    SSHLibrary.Write    ${host1} ping -c ${pingcount} ${host2}
+    ${out}=    SSHLibrary.Read Until    mininet>
+    ${ret}=    String.Get Lines Matching Regexp    ${out}    .*100% packet loss.*
+    ${len}=    Get Length    ${ret}
+    [Return]    ${len}
+
+Get Mininet Hosts
+    [Documentation]    Get all the hosts from mininet
+    ${host_list}=    Create List
+    SSHLibrary.Write    nodes
+    ${out}=    SSHLibrary.Read Until    mininet>
+    @{words}=    String.Split String    ${out}    ${SPACE}
+    : FOR    ${item}    IN    @{words}
+    \    ${h}=    String.Get Lines Matching Regexp    ${item}    h[0-9]*
+    \    Run Keyword If    '${h}' != '${EMPTY}'    Append To List    ${host_list}    ${h}
+    [Return]    ${host_list}