Add initial set of gbp-sxp test cases
[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 ${dump_default_name}    tcpDump
13
14 *** Keywords ***
15 Start Tcpdumping
16     [Arguments]    ${system}=${TOOLS_SYSTEM_IP}    ${user}=${TOOLS_SYSTEM_USER}    ${password}=${TOOLS_SYSTEM_PASSWORD}    ${prompt}=${TOOLS_SYSTEM_PROMPT}    ${timeout}=5s    ${eth}=eth0
17     ...    ${more_params}=${None}
18     [Documentation]    Connects to the remote machine via ssh and starts tcpdump linux command
19     ${currentcon}=    SSHLibrary.Get Connection    index=True
20     SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${timeout}    alias=${dumpalias}
21     Utils.Flexible SSH Login    ${user}    password=${password}    delay=${timeout}
22     SSHLibrary.Write    ${dumpcmd} -i ${eth} ${more_params}
23     Run Keyword If    ${currentcon}==${None}    Return From Keyword
24     SSHLibrary.Switch Connection    ${currentcon}
25
26 Stop Tcpdumping And Download
27     [Arguments]    ${filename}=${dumppcap}.xz
28     [Documentation]    Stops catching packets with tcpdump and download the saved file
29     ${oldcon}=    SSHLibrary.Switch Connection    ${dumpalias}
30     Utils.Write_Bare_Ctrl_C
31     SSHLibrary.Read
32     ${stdout}=    SSHLibrary.Execute Command    xz -9ekvv ${dumppcappath}
33     Log    ${stdout}
34     ${stdout}=    SSHLibrary.Execute Command    ls -la /tmp
35     Log    ${stdout}
36     SSHLibrary.Get File    ${dumppcappath}.xz    ${filename}
37     SSHLibrary.Close Connection
38     Run Keyword If    ${oldcon}==${None}    Return From Keyword
39     SSHLibrary.Switch Connection    ${oldcon}
40
41 Start Packet Capture On Node
42     [Arguments]    ${node_ip}    ${file_Name}=${dump_default_name}    ${network_Adapter}=eth0    ${user}=${DEFAULT_USER}    ${password}=${EMPTY}    ${prompt}=${DEFAULT_LINUX_PROMPT}
43     ...    ${prompt_timeout}=${DEFAULT_TIMEOUT}
44     [Documentation]    Connects to the remote machine and starts tcpdump
45     ${current_ssh_connection}=    SSHLibrary.Get Connection
46     ${conn_id}=    SSHLibrary.Open Connection    ${node_ip}    prompt=${prompt}    timeout=${prompt_timeout}
47     Flexible SSH Login    ${user}    ${password}
48     ${cmd} =    Set Variable    sudo /usr/sbin/tcpdump -vvv -ni ${networkAdapter} -w /tmp/${file_Name}.pcap
49     ${stdout}    ${stderr} =    SSHLibrary.Start Command    ${cmd}
50     Log    ${stderr}
51     Log    ${stdout}
52     [Teardown]    SSHKeywords.Restore_Current_SSH_Connection_From_Index    ${current_ssh_connection.index}
53     [Return]    ${conn_id}
54
55 Stop Packet Capture on Node
56     [Arguments]    ${conn_id}
57     [Documentation]    This keyword will list the running processes looking for tcpdump and then kill the process with the name tcpdump
58     SSHLibrary.Switch Connection    ${conn_id}
59     ${stdout} =    SSHLibrary.Execute Command    sudo ps -elf | grep tcpdump
60     Log    ${stdout}
61     ${stdout}    ${stderr} =    SSHLibrary.Execute Command    sudo pkill -f tcpdump    return_stderr=True
62     Log    ${stderr}
63     Log    ${stdout}
64     ${stdout} =    SSHLibrary.Execute Command    sudo xz -9ekvv /tmp/*.pcap
65     Log    ${stdout}
66     ${stdout} =    SSHLibrary.Execute Command    sudo ls -ls /tmp
67     Log    ${stdout}
68     SSHLibrary. Close Connection