[dts] [PATCH v2 2/6] framework packet: only sniff coming packet when tcpdump support

Yong Liu yong.liu at intel.com
Tue Jan 19 02:38:07 CET 2016


Newer version tcpdump support capture packet by direction. This feature
will help us distinguish coming packets and outgoing packets. And will be
helpful when only one nic available on tester.

Signed-off-by: Marvin Liu <yong.liu at intel.com>

diff --git a/framework/packet.py b/framework/packet.py
index 6d16a9e..aaa1dd0 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -639,8 +639,20 @@ def sniff_packets(intf, count=0, timeout=5):
     """
     sniff all packets for certain port in certain seconds
     """
-    sniff_cmd = 'tcpdump -i %(INTF)s -w %(FILE)s'
-    options = {'INTF': intf, 'COUNT': count,
+    param = ""
+    direct_param = r"(\s+)\[ -(\w) in\|out\|inout \]"
+    tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
+                        stderr=subprocess.STDOUT, shell=True)
+    for line in tcpdump_help.split('\n'):
+        m = re.match(direct_param, line)
+        if m:
+            param = "-" + m.group(2) + " in"
+
+    if len(param) == 0:
+        print "tcpdump not support direction chioce!!!"
+
+    sniff_cmd = 'tcpdump -i %(INTF)s %(IN_PARAM)s -w %(FILE)s'
+    options = {'INTF': intf, 'COUNT': count, 'IN_PARAM': param,
                'FILE': '/tmp/sniff_%s.pcap' % intf}
     if count:
         sniff_cmd += ' -c %(COUNT)d'
-- 
1.9.3



More information about the dts mailing list