robot lib to catch network traffic 81/31581/4
authorPeter Gubka <pgubka@cisco.com>
Fri, 18 Dec 2015 08:11:45 +0000 (09:11 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 19 Feb 2016 00:37:09 +0000 (00:37 +0000)
this library is primarily to be used in sandbox for debug
purposes, because the job config must be modified to save
additional files

typical usage would be
*** Test Cases ***
Catch Test
    Start Tcpdumping
    <more keywords>
    Stop Tcpdumping And Download  [filaname.pcap]

Change-Id: I263cda801d9b2266fad9594073f19ba825e3ffcb
Signed-off-by: Peter Gubka <pgubka@cisco.com>
csit/libraries/Tcpdump.robot [new file with mode: 0644]

diff --git a/csit/libraries/Tcpdump.robot b/csit/libraries/Tcpdump.robot
new file mode 100644 (file)
index 0000000..0e282a6
--- /dev/null
@@ -0,0 +1,38 @@
+*** Settings ***
+Documentation     Library to catch traffic/packets using linux tcpdump command
+Library           SSHLibrary
+Resource          Utils.robot
+Variables         ../variables/Variables.py
+
+*** Variables ***
+${dumpalias}      tcpdump
+${dumppcap}       dump.pcap
+${dumppcappath}    /tmp/${dumppcap}
+${dumpcmd}        sudo tcpdump -s 0 -w ${dumppcappath}
+
+*** Keywords ***
+Start Tcpdumping
+    [Arguments]    ${system}=${TOOLS_SYSTEM_IP}    ${user}=${TOOLS_SYSTEM_USER}    ${password}=${TOOLS_SYSTEM_PASSWORD}    ${prompt}=${TOOLS_SYSTEM_PROMPT}    ${timeout}=5s    ${eth}=eth0
+    ...    ${more_params}=${None}
+    [Documentation]    Connects to the remote machine via ssh and starts tcpdump linux command
+    ${currentcon}=    SSHLibrary.Get Connection    index=True
+    SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${timeout}    alias=${dumpalias}
+    Utils.Flexible SSH Login    ${user}    password=${password}    delay=${timeout}
+    SSHLibrary.Write    ${dumpcmd} -i ${eth} ${more_params}
+    Run Keyword If    ${currentcon}==${None}    Return From Keyword
+    SSHLibrary.Switch Connection    ${currentcon}
+
+Stop Tcpdumping And Download
+    [Arguments]    ${filename}=${dumppcap}.xz
+    [Documentation]    Stops catching packets with tcpdump and download the saved file
+    ${oldcon}=    SSHLibrary.Switch Connection    ${dumpalias}
+    Utils.Write_Bare_Ctrl_C
+    SSHLibrary.Read
+    ${stdout}=    SSHLibrary.Execute Command    xz -9ekvv ${dumppcappath}
+    Log    ${stdout}
+    ${stdout}=    SSHLibrary.Execute Command    ls -la /tmp
+    Log    ${stdout}
+    SSHLibrary.Get File    ${dumppcappath}.xz    ${filename}
+    SSHLibrary.Close Connection
+    Run Keyword If    ${oldcon}==${None}    Return From Keyword
+    SSHLibrary.Switch Connection    ${oldcon}