2 Documentation Library to catch traffic/packets using linux tcpdump command
5 Resource RemoteBash.robot
6 Variables ../variables/Variables.py
11 ${dumppcappath} /tmp/${dumppcap}
12 ${dumpcmd} sudo tcpdump -s 0 -w ${dumppcappath}
13 ${dump_default_name} tcpDump
17 [Arguments] ${system}=${TOOLS_SYSTEM_IP} ${user}=${TOOLS_SYSTEM_USER} ${password}=${TOOLS_SYSTEM_PASSWORD} ${prompt}=${TOOLS_SYSTEM_PROMPT} ${timeout}=5s ${eth}=eth0
18 ... ${more_params}=${None}
19 [Documentation] Connects to the remote machine via ssh and starts tcpdump linux command
20 ${currentcon}= SSHLibrary.Get Connection index=True
21 SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${timeout} alias=${dumpalias}
22 Utils.Flexible SSH Login ${user} password=${password} delay=${timeout}
23 SSHLibrary.Write ${dumpcmd} -i ${eth} ${more_params}
24 Run Keyword If ${currentcon}==${None} Return From Keyword
25 SSHLibrary.Switch Connection ${currentcon}
27 Stop Tcpdumping And Download
28 [Arguments] ${filename}=${dumppcap}.xz
29 [Documentation] Stops catching packets with tcpdump and download the saved file
30 ${oldcon}= SSHLibrary.Switch Connection ${dumpalias}
31 RemoteBash.Write_Bare_Ctrl_C
33 ${stdout}= SSHLibrary.Execute Command xz -9ekvv ${dumppcappath}
35 ${stdout}= SSHLibrary.Execute Command ls -la /tmp
37 SSHLibrary.Get File ${dumppcappath}.xz ${filename}
38 SSHLibrary.Close Connection
39 Run Keyword If ${oldcon}==${None} Return From Keyword
40 SSHLibrary.Switch Connection ${oldcon}
42 Start Packet Capture On Node
43 [Arguments] ${node_ip} ${file_Name}=${dump_default_name} ${network_Adapter}=eth0 ${user}=${DEFAULT_USER} ${password}=${EMPTY} ${prompt}=${DEFAULT_LINUX_PROMPT}
44 ... ${prompt_timeout}=${DEFAULT_TIMEOUT}
45 [Documentation] Connects to the remote machine and starts tcpdump
46 ${current_ssh_connection}= SSHLibrary.Get Connection
47 ${conn_id}= SSHLibrary.Open Connection ${node_ip} prompt=${prompt} timeout=${prompt_timeout}
48 Flexible SSH Login ${user} ${password}
49 ${cmd} = Set Variable sudo /usr/sbin/tcpdump -vvv -ni ${networkAdapter} -w /tmp/${file_Name}.pcap
50 ${stdout} ${stderr} = SSHLibrary.Start Command ${cmd}
53 [Teardown] SSHKeywords.Restore_Current_SSH_Connection_From_Index ${current_ssh_connection.index}
56 Stop Packet Capture on Node
57 [Arguments] ${conn_id}
58 [Documentation] This keyword will list the running processes looking for tcpdump and then kill the process with the name tcpdump
59 SSHLibrary.Switch Connection ${conn_id}
60 ${stdout} = SSHLibrary.Execute Command sudo ps -elf | grep tcpdump
62 ${stdout} ${stderr} = SSHLibrary.Execute Command sudo pkill -f tcpdump return_stderr=True
65 ${stdout} = SSHLibrary.Execute Command sudo xz -9ekvv /tmp/*.pcap
67 ${stdout} = SSHLibrary.Execute Command sudo ls -ls /tmp
69 SSHLibrary. Close Connection