X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=csit%2Flibraries%2FTcpdump.robot;h=1f8ddc4d7ae99f42fe51338dcc932522e17bce17;hb=HEAD;hp=b72e28b2d361705b7fd24c7b7a0c73c5189cbe84;hpb=f3b0c1b14487a2ffe7cec2cc8b69e60c12af28f3;p=integration%2Ftest.git diff --git a/csit/libraries/Tcpdump.robot b/csit/libraries/Tcpdump.robot index b72e28b2d3..444a54196b 100644 --- a/csit/libraries/Tcpdump.robot +++ b/csit/libraries/Tcpdump.robot @@ -1,62 +1,65 @@ *** Settings *** -Documentation Library to catch traffic/packets using linux tcpdump command -Library SSHLibrary -Resource SSHKeywords.robot -Resource Utils.robot -Resource RemoteBash.robot -Variables ../variables/Variables.py +Documentation Library to catch traffic/packets using linux tcpdump command + +Library SSHLibrary +Resource SSHKeywords.robot +Resource Utils.robot +Resource RemoteBash.robot +Variables ../variables/Variables.py + *** Variables *** -${dumpalias} tcpdump -${dumppcap} dump.pcap -${dumppcappath} /tmp/${dumppcap} -${dumpcmd} sudo tcpdump -s 0 -w ${dumppcappath} +${dumpalias} tcpdump +${dumppcap} dump.pcap +${dumppcappath} /tmp/${dumppcap} +${dumpcmd} sudo tcpdump -s 0 -w ${dumppcappath} ${dump_default_name} tcpDump + *** Keywords *** Start Tcpdumping + [Documentation] Connects to the remote machine via ssh and starts tcpdump linux command [Arguments] ${system}=${TOOLS_SYSTEM_IP} ${user}=${TOOLS_SYSTEM_USER} ${password}=${TOOLS_SYSTEM_PASSWORD} ${prompt}=${TOOLS_SYSTEM_PROMPT} ${timeout}=5s ${eth}=eth0 ... ${more_params}=${None} - [Documentation] Connects to the remote machine via ssh and starts tcpdump linux command - ${currentcon}= SSHLibrary.Get Connection index=True + ${currentcon} = SSHLibrary.Get Connection index=True SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${timeout} alias=${dumpalias} SSHKeywords.Flexible SSH Login ${user} password=${password} delay=${timeout} SSHLibrary.Write ${dumpcmd} -i ${eth} ${more_params} - Run Keyword If ${currentcon}==${None} Return From Keyword + IF ${currentcon}==${None} RETURN SSHLibrary.Switch Connection ${currentcon} Stop Tcpdumping And Download - [Arguments] ${filename}=${dumppcap}.xz [Documentation] Stops catching packets with tcpdump and download the saved file - ${oldcon}= SSHLibrary.Switch Connection ${dumpalias} + [Arguments] ${filename}=${dumppcap}.xz + ${oldcon} = SSHLibrary.Switch Connection ${dumpalias} RemoteBash.Write_Bare_Ctrl_C SSHLibrary.Read - ${stdout}= SSHLibrary.Execute Command xz -9ekvv ${dumppcappath} + ${stdout} = SSHLibrary.Execute Command xz -9ekvv ${dumppcappath} Log ${stdout} - ${stdout}= SSHLibrary.Execute Command ls -la /tmp + ${stdout} = SSHLibrary.Execute Command ls -la /tmp Log ${stdout} SSHLibrary.Get File ${dumppcappath}.xz ${filename} SSHLibrary.Close Connection - Run Keyword If ${oldcon}==${None} Return From Keyword + IF ${oldcon}==${None} RETURN SSHLibrary.Switch Connection ${oldcon} Start Packet Capture On Node + [Documentation] Connects to the remote machine and starts tcpdump [Arguments] ${node_ip} ${file_Name}=${dump_default_name} ${network_Adapter}=eth0 ${user}=${DEFAULT_USER} ${password}=${EMPTY} ${prompt}=${DEFAULT_LINUX_PROMPT} ... ${prompt_timeout}=${DEFAULT_TIMEOUT} ${filter}=${EMPTY} - [Documentation] Connects to the remote machine and starts tcpdump - ${current_ssh_connection}= SSHLibrary.Get Connection - ${conn_id}= SSHLibrary.Open Connection ${node_ip} prompt=${prompt} timeout=${prompt_timeout} + ${current_ssh_connection} = SSHLibrary.Get Connection + ${conn_id} = SSHLibrary.Open Connection ${node_ip} prompt=${prompt} timeout=${prompt_timeout} SSHKeywords.Flexible SSH Login ${user} ${password} ${cmd} = Set Variable sudo /usr/sbin/tcpdump -vvv -ni ${networkAdapter} ${filter} -w /tmp/${file_Name}.pcap ${stdout} ${stderr} = SSHLibrary.Start Command ${cmd} Log ${stderr} Log ${stdout} + RETURN ${conn_id} [Teardown] SSHKeywords.Restore_Current_SSH_Connection_From_Index ${current_ssh_connection.index} - [Return] ${conn_id} Stop Packet Capture on Node - [Arguments] ${conn_id} [Documentation] This keyword will list the running processes looking for tcpdump and then kill the process with the name tcpdump + [Arguments] ${conn_id} SSHLibrary.Switch Connection ${conn_id} ${stdout} = SSHLibrary.Execute Command sudo ps -elf | grep tcpdump Log ${stdout} @@ -67,21 +70,22 @@ Stop Packet Capture on Node Log ${stdout} ${stdout} = SSHLibrary.Execute Command sudo ls -ls /tmp Log ${stdout} - SSHLibrary. Close Connection Start Packet Capture on Nodes - [Arguments] ${tag}=${EMPTY} ${filter}=${EMPTY} ${ips}=@{EMPTY} [Documentation] Start packet captures on the given list of node ips. ... The captures will be named with the tag and ip. + [Arguments] ${tag}=${EMPTY} ${filter}=${EMPTY} ${ips}=@{EMPTY} @{conn_ids} = BuiltIn.Create List @{EMPTY} - : FOR ${ip} IN @{ips} - \ ${fname} = BuiltIn.Catenate SEPARATOR=__ ${tag} ${ip} - \ ${conn_id} = Tcpdump.Start Packet Capture on Node ${ip} file_Name=${fname} filter=${filter} - \ Collections.Append To List ${conn_ids} ${conn_id} - [Return] @{conn_ids} + FOR ${ip} IN @{ips} + ${fname} = BuiltIn.Catenate SEPARATOR=__ ${tag} ${ip} + ${conn_id} = Tcpdump.Start Packet Capture on Node ${ip} file_Name=${fname} filter=${filter} + Collections.Append To List ${conn_ids} ${conn_id} + END + RETURN @{conn_ids} Stop Packet Capture on Nodes - [Arguments] @{conn_ids}=@{EMPTY} [Documentation] Stop the packet captures on the given list of node connection ids - : FOR ${conn_id} IN @{conn_ids} - \ Stop Packet Capture on Node ${conn_id} + [Arguments] ${conn_ids}=@{EMPTY} + FOR ${conn_id} IN @{conn_ids} + Stop Packet Capture on Node ${conn_id} + END