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