Remove code for capwap
[integration/test.git] / csit / libraries / Tcpdump.robot
1 *** Settings ***
2 Documentation       Library to catch traffic/packets using linux tcpdump command
3
4 Library             SSHLibrary
5 Resource            SSHKeywords.robot
6 Resource            Utils.robot
7 Resource            RemoteBash.robot
8 Variables           ../variables/Variables.py
9
10
11 *** Variables ***
12 ${dumpalias}            tcpdump
13 ${dumppcap}             dump.pcap
14 ${dumppcappath}         /tmp/${dumppcap}
15 ${dumpcmd}              sudo tcpdump -s 0 -w ${dumppcappath}
16 ${dump_default_name}    tcpDump
17
18
19 *** Keywords ***
20 Start Tcpdumping
21     [Documentation]    Connects to the remote machine via ssh and starts tcpdump linux command
22     [Arguments]    ${system}=${TOOLS_SYSTEM_IP}    ${user}=${TOOLS_SYSTEM_USER}    ${password}=${TOOLS_SYSTEM_PASSWORD}    ${prompt}=${TOOLS_SYSTEM_PROMPT}    ${timeout}=5s    ${eth}=eth0
23     ...    ${more_params}=${None}
24     ${currentcon} =    SSHLibrary.Get Connection    index=True
25     SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${timeout}    alias=${dumpalias}
26     SSHKeywords.Flexible SSH Login    ${user}    password=${password}    delay=${timeout}
27     SSHLibrary.Write    ${dumpcmd} -i ${eth} ${more_params}
28     IF    ${currentcon}==${None}    RETURN
29     SSHLibrary.Switch Connection    ${currentcon}
30
31 Stop Tcpdumping And Download
32     [Documentation]    Stops catching packets with tcpdump and download the saved file
33     [Arguments]    ${filename}=${dumppcap}.xz
34     ${oldcon} =    SSHLibrary.Switch Connection    ${dumpalias}
35     RemoteBash.Write_Bare_Ctrl_C
36     SSHLibrary.Read
37     ${stdout} =    SSHLibrary.Execute Command    xz -9ekvv ${dumppcappath}
38     Log    ${stdout}
39     ${stdout} =    SSHLibrary.Execute Command    ls -la /tmp
40     Log    ${stdout}
41     SSHLibrary.Get File    ${dumppcappath}.xz    ${filename}
42     SSHLibrary.Close Connection
43     IF    ${oldcon}==${None}    RETURN
44     SSHLibrary.Switch Connection    ${oldcon}
45
46 Start Packet Capture On Node
47     [Documentation]    Connects to the remote machine and starts tcpdump
48     [Arguments]    ${node_ip}    ${file_Name}=${dump_default_name}    ${network_Adapter}=eth0    ${user}=${DEFAULT_USER}    ${password}=${EMPTY}    ${prompt}=${DEFAULT_LINUX_PROMPT}
49     ...    ${prompt_timeout}=${DEFAULT_TIMEOUT}    ${filter}=${EMPTY}
50     ${current_ssh_connection} =    SSHLibrary.Get Connection
51     ${conn_id} =    SSHLibrary.Open Connection    ${node_ip}    prompt=${prompt}    timeout=${prompt_timeout}
52     SSHKeywords.Flexible SSH Login    ${user}    ${password}
53     ${cmd} =    Set Variable    sudo /usr/sbin/tcpdump -vvv -ni ${networkAdapter} ${filter} -w /tmp/${file_Name}.pcap
54     ${stdout}    ${stderr} =    SSHLibrary.Start Command    ${cmd}
55     Log    ${stderr}
56     Log    ${stdout}
57     RETURN    ${conn_id}
58     [Teardown]    SSHKeywords.Restore_Current_SSH_Connection_From_Index    ${current_ssh_connection.index}
59
60 Stop Packet Capture on Node
61     [Documentation]    This keyword will list the running processes looking for tcpdump and then kill the process with the name tcpdump
62     [Arguments]    ${conn_id}
63     SSHLibrary.Switch Connection    ${conn_id}
64     ${stdout} =    SSHLibrary.Execute Command    sudo ps -elf | grep tcpdump
65     Log    ${stdout}
66     ${stdout}    ${stderr} =    SSHLibrary.Execute Command    sudo pkill -f tcpdump    return_stderr=True
67     Log    ${stderr}
68     Log    ${stdout}
69     ${stdout} =    SSHLibrary.Execute Command    sudo xz -9ekvv /tmp/*.pcap
70     Log    ${stdout}
71     ${stdout} =    SSHLibrary.Execute Command    sudo ls -ls /tmp
72     Log    ${stdout}
73
74 Start Packet Capture on Nodes
75     [Documentation]    Start packet captures on the given list of node ips.
76     ...    The captures will be named with the tag and ip.
77     [Arguments]    ${tag}=${EMPTY}    ${filter}=${EMPTY}    ${ips}=@{EMPTY}
78     @{conn_ids} =    BuiltIn.Create List    @{EMPTY}
79     FOR    ${ip}    IN    @{ips}
80         ${fname} =    BuiltIn.Catenate    SEPARATOR=__    ${tag}    ${ip}
81         ${conn_id} =    Tcpdump.Start Packet Capture on Node    ${ip}    file_Name=${fname}    filter=${filter}
82         Collections.Append To List    ${conn_ids}    ${conn_id}
83     END
84     RETURN    @{conn_ids}
85
86 Stop Packet Capture on Nodes
87     [Documentation]    Stop the packet captures on the given list of node connection ids
88     [Arguments]    ${conn_ids}=@{EMPTY}
89     FOR    ${conn_id}    IN    @{conn_ids}
90         Stop Packet Capture on Node    ${conn_id}
91     END