2 Documentation Library to catch traffic/packets using linux tcpdump command
5 Variables ../variables/Variables.py
10 ${dumppcappath} /tmp/${dumppcap}
11 ${dumpcmd} sudo tcpdump -s 0 -w ${dumppcappath}
12 ${dump_default_name} tcpDump
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}
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
32 ${stdout}= SSHLibrary.Execute Command xz -9ekvv ${dumppcappath}
34 ${stdout}= SSHLibrary.Execute Command ls -la /tmp
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}
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}
52 [Teardown] SSHKeywords.Restore_Current_SSH_Connection_From_Index ${current_ssh_connection.index}
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
61 ${stdout} ${stderr} = SSHLibrary.Execute Command sudo pkill -f tcpdump return_stderr=True
64 ${stdout} = SSHLibrary.Execute Command sudo xz -9ekvv /tmp/*.pcap
66 ${stdout} = SSHLibrary.Execute Command sudo ls -ls /tmp
68 SSHLibrary. Close Connection