robot lib to catch network traffic
[integration/test.git] / csit / libraries / Tcpdump.robot
1 *** Settings ***
2 Documentation     Library to catch traffic/packets using linux tcpdump command
3 Library           SSHLibrary
4 Resource          Utils.robot
5 Variables         ../variables/Variables.py
6
7 *** Variables ***
8 ${dumpalias}      tcpdump
9 ${dumppcap}       dump.pcap
10 ${dumppcappath}    /tmp/${dumppcap}
11 ${dumpcmd}        sudo tcpdump -s 0 -w ${dumppcappath}
12
13 *** Keywords ***
14 Start Tcpdumping
15     [Arguments]    ${system}=${TOOLS_SYSTEM_IP}    ${user}=${TOOLS_SYSTEM_USER}    ${password}=${TOOLS_SYSTEM_PASSWORD}    ${prompt}=${TOOLS_SYSTEM_PROMPT}    ${timeout}=5s    ${eth}=eth0
16     ...    ${more_params}=${None}
17     [Documentation]    Connects to the remote machine via ssh and starts tcpdump linux command
18     ${currentcon}=    SSHLibrary.Get Connection    index=True
19     SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${timeout}    alias=${dumpalias}
20     Utils.Flexible SSH Login    ${user}    password=${password}    delay=${timeout}
21     SSHLibrary.Write    ${dumpcmd} -i ${eth} ${more_params}
22     Run Keyword If    ${currentcon}==${None}    Return From Keyword
23     SSHLibrary.Switch Connection    ${currentcon}
24
25 Stop Tcpdumping And Download
26     [Arguments]    ${filename}=${dumppcap}.xz
27     [Documentation]    Stops catching packets with tcpdump and download the saved file
28     ${oldcon}=    SSHLibrary.Switch Connection    ${dumpalias}
29     Utils.Write_Bare_Ctrl_C
30     SSHLibrary.Read
31     ${stdout}=    SSHLibrary.Execute Command    xz -9ekvv ${dumppcappath}
32     Log    ${stdout}
33     ${stdout}=    SSHLibrary.Execute Command    ls -la /tmp
34     Log    ${stdout}
35     SSHLibrary.Get File    ${dumppcappath}.xz    ${filename}
36     SSHLibrary.Close Connection
37     Run Keyword If    ${oldcon}==${None}    Return From Keyword
38     SSHLibrary.Switch Connection    ${oldcon}