* [dts] [PATCH v5 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 03/22] tests/etag: " Phil Yang
` (22 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_checksum_offload.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_checksum_offload.py b/tests/TestSuite_checksum_offload.py
index 2ff5c2f..6541ba5 100644
--- a/tests/TestSuite_checksum_offload.py
+++ b/tests/TestSuite_checksum_offload.py
@@ -43,7 +43,6 @@ import utils
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
from test_capabilities import DRIVER_TEST_LACK_CAPA
class TestChecksumOffload(TestCase):
@@ -175,13 +174,14 @@ class TestChecksumOffload(TestCase):
self.tester.send_expect("exit()", "#")
- inst = sniff_packets(intf=rx_interface, count=len(packets_sent), filters=[{'layer':'ether', 'config':{'src': sniff_src}}])
+ inst = self.tester.tcpdump_sniff_packets(intf=rx_interface, count=len(packets_sent),
+ filters=[{'layer':'ether', 'config':{'src': sniff_src}}])
for packet_type in packets_sent.keys():
self.tester.scapy_append('sendp([%s], iface="%s")' % (packets_sent[packet_type], tx_interface))
self.tester.scapy_execute()
- p = load_sniff_packets(inst)
+ p = self.tester.load_tcpdump_sniff_packets(inst)
nr_packets=len(p)
reslist = [p[i].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%") for i in range(nr_packets)]
out = string.join(reslist, ",")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 03/22] tests/etag: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 04/22] tests/ipfrag: " Phil Yang
` (21 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_etag.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_etag.py b/tests/TestSuite_etag.py
index 642fb2b..68cca44 100644
--- a/tests/TestSuite_etag.py
+++ b/tests/TestSuite_etag.py
@@ -46,7 +46,7 @@ from exception import VerifyFailure
from scapy.utils import rdpcap
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
VM_CORES_MASK = 'all'
@@ -325,11 +325,11 @@ class TestEtag(TestCase):
pkt_types = {'IP_RAW': {'layer_configs': config_layers}}
intf = self.src_intf
- inst = sniff_packets(intf)
+ inst = self.tester.tcpdump_sniff_packets(intf)
self.check_packet_transmission(pkt_types)
time.sleep(1)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.host_testpmd.execute_cmd('E-tag set insertion off port-tag-id 1000 port 0 vf 0')
# load sniff pcap file, check received packet's content
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 04/22] tests/ipfrag: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 03/22] tests/etag: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (20 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_ipfrag.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/TestSuite_ipfrag.py b/tests/TestSuite_ipfrag.py
index f23dbe1..38e00d7 100644
--- a/tests/TestSuite_ipfrag.py
+++ b/tests/TestSuite_ipfrag.py
@@ -39,7 +39,7 @@ import string
import re
import time
from settings import HEADER_SIZE
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
lpm_table_ipv4 = [
"{IPv4(100,10,0,0), 16, P1}",
@@ -159,7 +159,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
expPkts = 1
val = 2
- inst = sniff_packets(intf=self.rxItf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
# send packet
for times in range(burst):
pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
@@ -169,7 +169,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
pkt.send_pkt(tx_port=self.txItf)
# verify normal packet just by number, verify fragment packet by all elements
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
if flag == 'frag':
idx = 1
@@ -209,7 +209,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
expPkts = 1
val = 2
- inst = sniff_packets(intf=self.rxItf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
# send packet
for times in range(burst):
pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
@@ -219,7 +219,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
pkt.send_pkt(tx_port=self.txItf)
# verify normal packet just by number, verify fragment packet by all elements
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
if flag == 'frag':
idx = 1
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (2 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 04/22] tests/ipfrag: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet Phil Yang
` (19 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_l2fwd_crypto.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_l2fwd_crypto.py b/tests/TestSuite_l2fwd_crypto.py
index d559909..ea35a29 100644
--- a/tests/TestSuite_l2fwd_crypto.py
+++ b/tests/TestSuite_l2fwd_crypto.py
@@ -38,7 +38,7 @@ import sys
import utils
import commands
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets, save_packets
+from packet import Packet, save_packets
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
@@ -501,7 +501,7 @@ class TestL2fwdCrypto(TestCase):
payload = self.__format_hex_to_list(test_vector["input"])
- inst = sniff_packets(self.rx_interface, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=5)
PACKET_COUNT = 65
pkt = Packet()
@@ -512,7 +512,7 @@ class TestL2fwdCrypto(TestCase):
pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
pkt.pktgen.pkt.show()
- pkt_rec = load_sniff_packets(inst)
+ pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
for pkt_r in pkt_rec:
packet_hex = pkt_r.strip_element_layer4("load")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (3 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (18 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_netmap_compat.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tests/TestSuite_netmap_compat.py b/tests/TestSuite_netmap_compat.py
index 5225a27..84136c7 100644
--- a/tests/TestSuite_netmap_compat.py
+++ b/tests/TestSuite_netmap_compat.py
@@ -43,7 +43,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestNetmapCompat(TestCase):
@@ -80,7 +79,7 @@ class TestNetmapCompat(TestCase):
self.rxItf = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
self.scapy_send_packet()
@@ -98,7 +97,7 @@ class TestNetmapCompat(TestCase):
self.dut.send_expect(cmd,"Port %s now in Netmap mode" % self.dut_ports[0], 60)
self.rxItf = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
self.scapy_send_packet()
@@ -117,7 +116,7 @@ class TestNetmapCompat(TestCase):
def get_tcpdump_package(self):
- pkts = load_sniff_packets(self.inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (4 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 08/22] tests/quota_watermark: " Phil Yang
` (17 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_queue_start_stop.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_queue_start_stop.py b/tests/TestSuite_queue_start_stop.py
index 3dd37b3..6cd6831 100644
--- a/tests/TestSuite_queue_start_stop.py
+++ b/tests/TestSuite_queue_start_stop.py
@@ -44,7 +44,7 @@ import os
from test_case import TestCase
from pmd_output import PmdOutput
from settings import FOLDERS
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
+from packet import Packet, strip_pktload
#
#
@@ -99,10 +99,10 @@ class TestQueueStartStop(TestCase):
dmac = self.dut.get_mac_address(txPort)
pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
- inst = sniff_packets(rxitf)
+ inst = self.tester.tcpdump_sniff_packets(rxitf)
pkt.config_layer('ether', {'dst': dmac})
pkt.send_pkt(tx_port=txitf)
- sniff_pkts = load_sniff_packets(inst)
+ sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
if received:
res = strip_pktload(sniff_pkts[0], layer="L4")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 08/22] tests/quota_watermark: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (5 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 09/22] tests/rxtx_callback: " Phil Yang
` (16 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_quota_watermark.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_quota_watermark.py b/tests/TestSuite_quota_watermark.py
index ecacf38..845b27f 100644
--- a/tests/TestSuite_quota_watermark.py
+++ b/tests/TestSuite_quota_watermark.py
@@ -39,7 +39,6 @@ import time
import utils
from test_case import TestCase
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
test_config = {
'frames_to_sent': 15 * 10 ** 6,
@@ -311,9 +310,9 @@ class TestQuotaWatermark(TestCase, IxiaPacketGenerator):
rx_intf = self.tester.get_interface(rev_port)
tx_intf = self.tester.get_interface(send_port)
# send and sniff packet
- rx_inst = sniff_packets(rx_intf, timeout=5)
+ rx_inst = self.tester.tcpdump_sniff_packets(rx_intf, timeout=5)
self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf)
- pkts = load_sniff_packets(rx_inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(rx_inst)
self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected")
return
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 09/22] tests/rxtx_callback: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (6 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 08/22] tests/quota_watermark: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 10/22] tests/scatter: " Phil Yang
` (15 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_rxtx_callbacks.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_rxtx_callbacks.py b/tests/TestSuite_rxtx_callbacks.py
index dd968a4..a654480 100644
--- a/tests/TestSuite_rxtx_callbacks.py
+++ b/tests/TestSuite_rxtx_callbacks.py
@@ -41,7 +41,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestRxtxCallbacks(TestCase):
@@ -77,7 +76,7 @@ class TestRxtxCallbacks(TestCase):
self.iface_port0 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
self.iface_port1 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst_port1 = sniff_packets(self.iface_port1)
+ self.inst_port1 = self.tester.tcpdump_sniff_packets(self.iface_port1)
self.scapy_send_packet(self.iface_port0)
out_port1 = self.get_tcpdump_package(self.inst_port1)
@@ -92,7 +91,7 @@ class TestRxtxCallbacks(TestCase):
self.tester.scapy_execute()
def get_tcpdump_package(self,inst):
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 10/22] tests/scatter: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (7 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 09/22] tests/rxtx_callback: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 11/22] tests/skeleton: " Phil Yang
` (14 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_scatter.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_scatter.py b/tests/TestSuite_scatter.py
index d6aef49..0d38513 100644
--- a/tests/TestSuite_scatter.py
+++ b/tests/TestSuite_scatter.py
@@ -35,7 +35,7 @@ Test Scattered Packets.
"""
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
+from packet import Packet, strip_pktload
import time
#
#
@@ -82,11 +82,11 @@ class TestScatter(TestCase):
"""
dmac = self.dut.get_mac_address(self.port)
- inst = sniff_packets(self.intf)
+ inst = self.tester.tcpdump_sniff_packets(self.intf)
pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize)
pkt.config_layer('ether', {'dst': dmac})
pkt.send_pkt(tx_port=self.intf)
- sniff_pkts = load_sniff_packets(inst)
+ sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
res = ""
if len(sniff_pkts):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 11/22] tests/skeleton: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (8 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 10/22] tests/scatter: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 12/22] tests/userspace_ethtool: " Phil Yang
` (13 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_skeleton.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_skeleton.py b/tests/TestSuite_skeleton.py
index 77f95e1..b56d955 100644
--- a/tests/TestSuite_skeleton.py
+++ b/tests/TestSuite_skeleton.py
@@ -42,7 +42,6 @@ from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestSkeleton(TestCase):
@@ -80,7 +79,7 @@ class TestSkeleton(TestCase):
self.iface_port0 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
self.iface_port1 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst_port1 = sniff_packets(self.iface_port1)
+ self.inst_port1 = self.tester.tcpdump_sniff_packets(self.iface_port1)
self.scapy_send_packet(self.iface_port0)
out_port1 = self.get_tcpdump_package(self.inst_port1)
@@ -95,7 +94,7 @@ class TestSkeleton(TestCase):
self.tester.scapy_execute()
def get_tcpdump_package(self,inst):
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 12/22] tests/userspace_ethtool: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (9 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 11/22] tests/skeleton: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 13/22] tests/vf_daemon: " Phil Yang
` (12 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_userspace_ethtool.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_userspace_ethtool.py b/tests/TestSuite_userspace_ethtool.py
index eccc77b..8ade421 100644
--- a/tests/TestSuite_userspace_ethtool.py
+++ b/tests/TestSuite_userspace_ethtool.py
@@ -39,7 +39,7 @@ import utils
import time
import re
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
import random
from etgen import IxiaPacketGenerator
from settings import HEADER_SIZE
@@ -490,9 +490,9 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
tester_port = self.tester.get_local_port(port)
intf = self.tester.get_interface(tester_port)
# send and sniff packet
- inst = sniff_packets(intf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf, timeout=5)
pkt.send_pkt(tx_port=intf)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == 1, "Packet not forwarded as expected")
src_mac = pkts[0].strip_layer_element("layer2", "src")
self.verify(src_mac == valid_mac, "Forwarded packet not match default mac")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 13/22] tests/vf_daemon: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (10 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 12/22] tests/userspace_ethtool: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 14/22] tests/vf_vlan: " Phil Yang
` (11 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_vf_daemon.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/TestSuite_vf_daemon.py b/tests/TestSuite_vf_daemon.py
index c264911..42a14e5 100644
--- a/tests/TestSuite_vf_daemon.py
+++ b/tests/TestSuite_vf_daemon.py
@@ -8,7 +8,7 @@ from scapy.utils import rdpcap
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
from settings import get_nic_name
import random
@@ -154,7 +154,7 @@ class Testvf_daemon(TestCase):
pkt.config_layer('vlan', {'vlan': vlan_id})
pkt.config_layer('ether', {'dst': dst_mac})
- inst = sniff_packets(self.tester_intf, timeout=30)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=30)
pkt.send_pkt(tx_port=self.tester_intf, count=num)
return inst
@@ -162,7 +162,7 @@ class Testvf_daemon(TestCase):
"""
Load sniff packets, strip and return mac address from dump message
"""
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
macs = []
for pkt in pkts:
mac = pkt.strip_element_layer2(element)
@@ -173,7 +173,7 @@ class Testvf_daemon(TestCase):
"""
Load sniff packets, strip and return vlan id from dump message
"""
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
vlans = []
for pkt in pkts:
vlan = pkt.strip_element_vlan("vlan")
@@ -422,7 +422,7 @@ class Testvf_daemon(TestCase):
self.dut_testpmd.execute_cmd('set tx loopback 0 off')
time.sleep(5)
- inst = sniff_packets(self.tester_intf, timeout=10)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
self.vm1_testpmd.execute_cmd('set burst 5')
self.vm1_testpmd.execute_cmd('start tx_first')
@@ -438,7 +438,7 @@ class Testvf_daemon(TestCase):
self.dut_testpmd.execute_cmd('set tx loopback 0 on')
time.sleep(3)
- inst = sniff_packets(self.tester_intf, timeout=10)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
self.vm1_testpmd.execute_cmd('stop')
self.vm1_testpmd.execute_cmd('start tx_first')
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 14/22] tests/vf_vlan: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (11 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 13/22] tests/vf_daemon: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 15/22] tests/vlan_ethertype_config: remove unused sniff_packets Phil Yang
` (10 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_vf_vlan.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/TestSuite_vf_vlan.py b/tests/TestSuite_vf_vlan.py
index 75d99f2..4c7b42d 100644
--- a/tests/TestSuite_vf_vlan.py
+++ b/tests/TestSuite_vf_vlan.py
@@ -6,7 +6,7 @@ import time
from virt_common import VM
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
from settings import get_nic_name
import random
@@ -173,9 +173,9 @@ class TestVfVlan(TestCase):
pkt = Packet(pkt_type='UDP')
pkt.config_layer('ether', {'dst': self.vf1_mac})
- inst = sniff_packets(self.tester_intf0, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
pkt.send_pkt(tx_port=self.tester_intf1)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts), "Not receive expected packet")
self.vm0_testpmd.quit()
@@ -258,13 +258,13 @@ class TestVfVlan(TestCase):
"ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ")
def tx_and_check(self, tx_vlan=1):
- inst = sniff_packets(self.tester_intf0, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
self.vm0_testpmd.execute_cmd('set burst 1')
self.vm0_testpmd.execute_cmd('start tx_first')
self.vm0_testpmd.execute_cmd('stop')
# strip sniffered vlans
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
vlans = []
for pkt in pkts:
vlan = pkt.strip_element_vlan("vlan")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 15/22] tests/vlan_ethertype_config: remove unused sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (12 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 14/22] tests/vf_vlan: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (9 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused sniff_packets import
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_vlan_ethertype_config.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/tests/TestSuite_vlan_ethertype_config.py b/tests/TestSuite_vlan_ethertype_config.py
index 1fb30fb..8eba49c 100644
--- a/tests/TestSuite_vlan_ethertype_config.py
+++ b/tests/TestSuite_vlan_ethertype_config.py
@@ -43,7 +43,6 @@ import utils
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
from scapy.utils import struct, socket, wrpcap, rdpcap
from scapy.layers.inet import Ether, IP, TCP, UDP, ICMP
from scapy.layers.l2 import Dot1Q, ARP, GRE
@@ -125,7 +124,6 @@ class TestVlanEthertypeConfig(TestCase):
# off
self.dmac = self.dut.get_mac_address(dutRxPortId)
- self.inst = sniff_packets(self.rxItf)
pkt = []
if outer_vid < 0 or outer_tpid <= 0:
pkt = [
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (13 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 15/22] tests/vlan_ethertype_config: remove unused sniff_packets Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 17/22] tests/ipgre: " Phil Yang
` (8 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_vlan.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_vlan.py b/tests/TestSuite_vlan.py
index 0f1833b..b2bda71 100644
--- a/tests/TestSuite_vlan.py
+++ b/tests/TestSuite_vlan.py
@@ -43,7 +43,7 @@ import time
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestVlan(TestCase):
@@ -88,7 +88,7 @@ class TestVlan(TestCase):
netobj.add_vlan(vlan_id = self.vlan)
def get_tcpdump_package(self):
- pkts = load_sniff_packets(self.inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
vlans = []
for packet in pkts:
vlan = packet.strip_element_vlan("vlan")
@@ -110,7 +110,7 @@ class TestVlan(TestCase):
# the package dect mac must is dut tx port id when the port promisc is off
self.dmac = self.dut.get_mac_address(dutRxPortId)
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
# FIXME send a burst with only num packet
if vid == -1:
pkt = Packet(pkt_type='UDP')
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 17/22] tests/ipgre: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (14 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 18/22] tests/hotplug: remove unused packet sniff import Phil Yang
` (7 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_ipgre.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_ipgre.py b/tests/TestSuite_ipgre.py
index 2dccb9c..e400161 100644
--- a/tests/TestSuite_ipgre.py
+++ b/tests/TestSuite_ipgre.py
@@ -44,7 +44,7 @@ import re
import time
import os
-from packet import Packet, sniff_packets, load_sniff_packets, NVGRE, IPPROTO_NVGRE
+from packet import Packet, NVGRE, IPPROTO_NVGRE
from scapy.utils import wrpcap, rdpcap
from scapy.packet import split_layers,bind_layers
@@ -98,11 +98,11 @@ class TestIpgre(TestCase):
if layer_configs:
for layer in layer_configs.keys():
pkt.config_layer(layer, layer_configs[layer])
- inst = sniff_packets(self.tester_iface, count=1, timeout=8)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1, timeout=8)
pkt.send_pkt(tx_port=self.tester_iface)
out = self.dut.get_session_output(timeout=2)
time.sleep(1)
- load_sniff_packets(inst)
+ self.tester.load_tcpdump_sniff_packets(inst)
if self.printFlag: # debug output
print out
for pkt_layer_name in pkt_names:
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 18/22] tests/hotplug: remove unused packet sniff import
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (15 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 17/22] tests/ipgre: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 19/22] tests/keep_alive: " Phil Yang
` (6 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_hotplug.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_hotplug.py b/tests/TestSuite_hotplug.py
index c0e1741..7d63b71 100644
--- a/tests/TestSuite_hotplug.py
+++ b/tests/TestSuite_hotplug.py
@@ -43,7 +43,7 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestPortHotPlug(TestCase):
"""
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 19/22] tests/keep_alive: remove unused packet sniff import
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (16 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 18/22] tests/hotplug: remove unused packet sniff import Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 20/22] tests/link_status_interrupt: " Phil Yang
` (5 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_keep_alive.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/TestSuite_keep_alive.py b/tests/TestSuite_keep_alive.py
index 41c8732..711d8ce 100644
--- a/tests/TestSuite_keep_alive.py
+++ b/tests/TestSuite_keep_alive.py
@@ -43,7 +43,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestKeepAlive(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 20/22] tests/link_status_interrupt: remove unused packet sniff import
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (17 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 19/22] tests/keep_alive: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 21/22] tests/vhost_pmd_xstats: " Phil Yang
` (4 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_link_status_interrupt.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_link_status_interrupt.py b/tests/TestSuite_link_status_interrupt.py
index c31634b..cad6485 100644
--- a/tests/TestSuite_link_status_interrupt.py
+++ b/tests/TestSuite_link_status_interrupt.py
@@ -40,7 +40,7 @@ import string
import time
import re
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestLinkStatusInterrupt(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 21/22] tests/vhost_pmd_xstats: remove unused packet sniff import
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (18 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 20/22] tests/link_status_interrupt: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-04 8:26 ` [dts] [PATCH v5 22/22] tests/ddp_mpls: " Phil Yang
` (3 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_vhost_pmd_xstats.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_vhost_pmd_xstats.py b/tests/TestSuite_vhost_pmd_xstats.py
index 8c800c7..a01ca16 100644
--- a/tests/TestSuite_vhost_pmd_xstats.py
+++ b/tests/TestSuite_vhost_pmd_xstats.py
@@ -46,7 +46,7 @@ from exception import VerifyFailure
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
from qemu_kvm import QEMUKvm
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestVhostPmdXstats(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v5 22/22] tests/ddp_mpls: remove unused packet sniff import
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (19 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 21/22] tests/vhost_pmd_xstats: " Phil Yang
@ 2018-09-04 8:26 ` Phil Yang
2018-09-17 5:12 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang (Arm Technology China)
` (2 subsequent siblings)
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-09-04 8:26 UTC (permalink / raw)
To: dts; +Cc: nd, yong.liu, Phil Yang
From: Phil Yang <phil.yang@arm.com>
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
---
tests/TestSuite_ddp_mpls.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py
index 08d58be..691e958 100644
--- a/tests/TestSuite_ddp_mpls.py
+++ b/tests/TestSuite_ddp_mpls.py
@@ -8,7 +8,6 @@ from scapy.utils import rdpcap
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
from settings import get_nic_name
import random
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (20 preceding siblings ...)
2018-09-04 8:26 ` [dts] [PATCH v5 22/22] tests/ddp_mpls: " Phil Yang
@ 2018-09-17 5:12 ` Phil Yang (Arm Technology China)
2018-09-21 3:09 ` Tu, Lijuan
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
23 siblings, 0 replies; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-09-17 5:12 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), dts; +Cc: nd, yong.liu
Hi,
Any comments for those patches?
Thanks,
Phil Yang
> -----Original Message-----
> From: Phil Yang <phil.yang@arm.com>
> Sent: Tuesday, September 4, 2018 4:26 PM
> To: dts@dpdk.org
> Cc: nd <nd@arm.com>; yong.liu@intel.com; Phil Yang (Arm Technology China)
> <Phil.Yang@arm.com>
> Subject: [PATCH v5 01/22] framework/packet: support packet sniffer to specify
> running machine
>
> From: Phil Yang <phil.yang@arm.com>
>
> By default, the Tester is supposed to be the server which running DTS and the
> packet sniff methods are running on it.
> However, if DTS was not running on the Tester and the Tester is another remote
> server, so packet sniff methods cannot sniff Tester's packets correctly.
>
> This patch adds support for packet sniff methods to specify running machine and
> implements sniff packet methods in class tester.
>
> 1. Add parameter to sniff_packet and load_sniff_pcap methods to specify the
> running machine.
> 2. Remove load_sniff_packets method in packet.py.
> 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> 4. Update tester.check_random_pkts method with
> tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to make
> it execution on the Tester.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Suggested-by: Marvin Liu <yong.liu@intel.com>
> ---
> framework/packet.py | 86 +++++++++++++++++++++++++---------------------------
> -
> framework/tester.py | 48 +++++++++++++++++++++++++++---
> 2 files changed, 84 insertions(+), 50 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index
> 976b82b..1f3f07d 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> """
> sniff all packets for certain port in certain seconds
> """
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> - stderr=subprocess.STDOUT,
> - shell=True)
> + remote_terminate = 0
> +
> + # target[] contain the remote machine info for ssh connection
> + # target[0]: username
> + # target[1]: ip address
> + # target[2]: pass word
> + if target:
> + tcpdump_help_pipe = subprocess.Popen(["ssh",
> + "%s@%s" % (target[0], target[1]),
> + "tcpdump -h"],
> + stderr=subprocess.PIPE,
> + stdout=subprocess.PIPE,
> + shell=False)
> + tcpdump_help = "".join(tuple(tcpdump_help_pipe.communicate()))
> + tcpdump_help_pipe.wait()
> + else:
> + 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:
> @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0, timeout=5, filters=[]):
> else:
> cmd = sniff_cmd % options
>
> - args = shlex.split(cmd)
> + if target:
> + pipe = subprocess.Popen(['ssh',
> + '%s@%s' % (target[0], target[1]), cmd],
> + stdin=subprocess.PIPE,
> + shell=False)
> + remote_terminate = 1
> + else:
> + args = shlex.split(cmd)
> + pipe = subprocess.Popen(args)
>
> - pipe = subprocess.Popen(args)
> index = str(time.time())
> - SNIFF_PIDS[index] = (pipe, intf, timeout)
> + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index=''):
> +def load_sniff_pcap(index='', target=[]):
> """
> Stop sniffer and return pcap file
> """
> child_exit = False
> if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> time_elapse = int(time.time() - float(index))
> while time_elapse < timeout:
> if pipe.poll() is not None:
> @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> time_elapse += 1
>
> if not child_exit:
> + if remote_terminate == 1:
> + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> + '%s@%s' % (target[0], target[1]),
> + 'kill -2 $(pidof tcpdump)'],
> + stderr=subprocess.PIPE,
> + shell=False)
> + stop_tcpdump_pipe.wait()
> +
> pipe.send_signal(signal.SIGINT)
> pipe.wait()
>
> @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> return ""
>
>
> -def load_sniff_packets(index=''):
> - """
> - Stop sniffer and return packet objects
> - """
> - pkts = []
> - child_exit = False
> - if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.poll() is not None:
> - child_exit = True
> - break
> -
> - time.sleep(1)
> - time_elapse += 1
> -
> - if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - try:
> - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet(tx_port=intf)
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> -
> - return pkts
> -
> -
> def load_pcapfile(filename=""):
> pkts = []
> try:
> @@ -983,7 +978,6 @@ if __name__ == "__main__":
> inst = sniff_packets("lo", timeout=5)
> pkt = Packet(pkt_type='UDP')
> pkt.send_pkt(tx_port='lo')
> - pkts = load_sniff_packets(inst)
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> pkt.send_pkt(tx_port='lo')
> diff --git a/framework/tester.py b/framework/tester.py index a775f68..c5b705d
> 100755
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
>
> import re
> import subprocess
> +import os
> from time import sleep
> from settings import NICS, load_global_setting, PERF_SETTING from crb import
> Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> send_f = getattr(module, "send_packets")
> - sniff_f = getattr(module, "sniff_packets")
> - load_f = getattr(module, "load_sniff_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@ class
> Tester(Crb):
>
> # send and sniff packets
> save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout, filters=
> + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> + count=pktnum, timeout=timeout, filters=
> [{'layer': 'network', 'config': {'srcport': '65535'}},
> {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> @@ -627,7 +626,7 @@ class Tester(Crb):
> # Verify all packets
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = load_f(rx_inst[rxport])
> + recv_pkts =
> + self.load_tcpdump_sniff_packets(rx_inst[rxport])
>
> # only report when recevied number not matched
> if len(tx_pkts[txport]) > len(recv_pkts):
> @@ -704,6 +703,47 @@ class Tester(Crb):
> self.proc.kill()
> self.proc = None
>
> + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + """
> + Wrapper for packet module sniff_packets
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + sniff_f = getattr(module, "sniff_packets")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + return sniff_f(intf, count, timeout, filters, target)
> +
> + def load_tcpdump_sniff_pcap(self, index=''):
> + """
> + Wrapper for packet module load_sniff_pcap
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + load_pcap_f = getattr(module, "load_sniff_pcap")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + pcap = load_pcap_f(index, target)
> + self.session.copy_file_from(pcap)
> +
> + return pcap.split(os.sep)[-1]
> +
> + def load_tcpdump_sniff_packets(self, index=''):
> + """
> + Wrapper for packet module load_pcapfile
> + """
> + # load functions in packet module
> + packet = __import__("packet")
> + file = self.load_tcpdump_sniff_pcap(index)
> +
> + return packet.load_pcapfile(file)
> +
> def kill_all(self, killall=False):
> """
> Kill all scapy process or DPDK application on tester.
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (21 preceding siblings ...)
2018-09-17 5:12 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang (Arm Technology China)
@ 2018-09-21 3:09 ` Tu, Lijuan
2018-09-21 3:21 ` Phil Yang (Arm Technology China)
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
23 siblings, 1 reply; 124+ messages in thread
From: Tu, Lijuan @ 2018-09-21 3:09 UTC (permalink / raw)
To: Phil, dts; +Cc: nd, Liu, Yong, Phil Yang
One comments, when we ssh to a server, it might request a password, but we don't handle it.
> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Phil@dpdk.org
> Sent: Tuesday, September 4, 2018 4:26 PM
> To: dts@dpdk.org
> Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> <phil.yang@arm.com>
> Subject: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> From: Phil Yang <phil.yang@arm.com>
>
> By default, the Tester is supposed to be the server which running DTS and the
> packet sniff methods are running on it.
> However, if DTS was not running on the Tester and the Tester is another
> remote server, so packet sniff methods cannot sniff Tester's packets
> correctly.
>
> This patch adds support for packet sniff methods to specify running machine
> and implements sniff packet methods in class tester.
>
> 1. Add parameter to sniff_packet and load_sniff_pcap methods to specify
> the running machine.
> 2. Remove load_sniff_packets method in packet.py.
> 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> 4. Update tester.check_random_pkts method with
> tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
> make it execution on the Tester.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Suggested-by: Marvin Liu <yong.liu@intel.com>
> ---
> framework/packet.py | 86
> +++++++++++++++++++++++++----------------------------
> framework/tester.py | 48 +++++++++++++++++++++++++++---
> 2 files changed, 84 insertions(+), 50 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index
> 976b82b..1f3f07d 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> """
> sniff all packets for certain port in certain seconds
> """
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> -
> stderr=subprocess.STDOUT,
> - shell=True)
> + remote_terminate = 0
> +
> + # target[] contain the remote machine info for ssh connection
> + # target[0]: username
> + # target[1]: ip address
> + # target[2]: pass word
> + if target:
> + tcpdump_help_pipe = subprocess.Popen(["ssh",
> + "%s@%s" % (target[0], target[1]),
> + "tcpdump -h"],
> + stderr=subprocess.PIPE,
> + stdout=subprocess.PIPE,
> + shell=False)
[Lijuan] Action will be blocked if SSH need password.
> + tcpdump_help =
> "".join(tuple(tcpdump_help_pipe.communicate()))
> + tcpdump_help_pipe.wait()
> + else:
> + 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:
> @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0, timeout=5,
> filters=[]):
> else:
> cmd = sniff_cmd % options
>
> - args = shlex.split(cmd)
> + if target:
> + pipe = subprocess.Popen(['ssh',
> + '%s@%s' % (target[0], target[1]), cmd],
> + stdin=subprocess.PIPE,
> + shell=False)
> + remote_terminate = 1
> + else:
> + args = shlex.split(cmd)
> + pipe = subprocess.Popen(args)
>
> - pipe = subprocess.Popen(args)
> index = str(time.time())
> - SNIFF_PIDS[index] = (pipe, intf, timeout)
> + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index=''):
> +def load_sniff_pcap(index='', target=[]):
> """
> Stop sniffer and return pcap file
> """
> child_exit = False
> if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> time_elapse = int(time.time() - float(index))
> while time_elapse < timeout:
> if pipe.poll() is not None:
> @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> time_elapse += 1
>
> if not child_exit:
> + if remote_terminate == 1:
> + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> + '%s@%s' % (target[0],
> target[1]),
> + 'kill -2 $(pidof tcpdump)'],
> + stderr=subprocess.PIPE,
> + shell=False)
> + stop_tcpdump_pipe.wait()
> +
> pipe.send_signal(signal.SIGINT)
> pipe.wait()
>
> @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> return ""
>
>
> -def load_sniff_packets(index=''):
> - """
> - Stop sniffer and return packet objects
> - """
> - pkts = []
> - child_exit = False
> - if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.poll() is not None:
> - child_exit = True
> - break
> -
> - time.sleep(1)
> - time_elapse += 1
> -
> - if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - try:
> - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet(tx_port=intf)
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> -
> - return pkts
> -
> -
> def load_pcapfile(filename=""):
> pkts = []
> try:
> @@ -983,7 +978,6 @@ if __name__ == "__main__":
> inst = sniff_packets("lo", timeout=5)
> pkt = Packet(pkt_type='UDP')
> pkt.send_pkt(tx_port='lo')
> - pkts = load_sniff_packets(inst)
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> pkt.send_pkt(tx_port='lo')
> diff --git a/framework/tester.py b/framework/tester.py index
> a775f68..c5b705d 100755
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
>
> import re
> import subprocess
> +import os
> from time import sleep
> from settings import NICS, load_global_setting, PERF_SETTING from crb
> import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> send_f = getattr(module, "send_packets")
> - sniff_f = getattr(module, "sniff_packets")
> - load_f = getattr(module, "load_sniff_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@
> class Tester(Crb):
>
> # send and sniff packets
> save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> filters=
> + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> + count=pktnum, timeout=timeout, filters=
> [{'layer': 'network', 'config': {'srcport': '65535'}},
> {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> @@ -627,7 +626,7 @@ class Tester(Crb):
> # Verify all packets
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = load_f(rx_inst[rxport])
> + recv_pkts =
> + self.load_tcpdump_sniff_packets(rx_inst[rxport])
>
> # only report when recevied number not matched
> if len(tx_pkts[txport]) > len(recv_pkts):
> @@ -704,6 +703,47 @@ class Tester(Crb):
> self.proc.kill()
> self.proc = None
>
> + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + """
> + Wrapper for packet module sniff_packets
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + sniff_f = getattr(module, "sniff_packets")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + return sniff_f(intf, count, timeout, filters, target)
> +
> + def load_tcpdump_sniff_pcap(self, index=''):
> + """
> + Wrapper for packet module load_sniff_pcap
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + load_pcap_f = getattr(module, "load_sniff_pcap")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + pcap = load_pcap_f(index, target)
> + self.session.copy_file_from(pcap)
> +
> + return pcap.split(os.sep)[-1]
> +
> + def load_tcpdump_sniff_packets(self, index=''):
> + """
> + Wrapper for packet module load_pcapfile
> + """
> + # load functions in packet module
> + packet = __import__("packet")
> + file = self.load_tcpdump_sniff_pcap(index)
> +
> + return packet.load_pcapfile(file)
> +
> def kill_all(self, killall=False):
> """
> Kill all scapy process or DPDK application on tester.
> --
> 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 3:09 ` Tu, Lijuan
@ 2018-09-21 3:21 ` Phil Yang (Arm Technology China)
2018-09-21 3:41 ` Tu, Lijuan
0 siblings, 1 reply; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-09-21 3:21 UTC (permalink / raw)
To: Tu, Lijuan, Phil, dts; +Cc: nd, Liu, Yong
Hi Lijuan,
It also need to follow the DTS setup steps in https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
Since you know where are your DUT and Tester, so you can use tool ssh-copy-id to save local available keys on DUT and Tester.
Thanks,
Phil Yang
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Friday, September 21, 2018 11:09 AM
> To: Phil@dpdk.org; dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang (Arm
> Technology China) <Phil.Yang@arm.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> One comments, when we ssh to a server, it might request a password, but we
> don't handle it.
>
>
> > -----Original Message-----
> > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Phil@dpdk.org
> > Sent: Tuesday, September 4, 2018 4:26 PM
> > To: dts@dpdk.org
> > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > <phil.yang@arm.com>
> > Subject: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > From: Phil Yang <phil.yang@arm.com>
> >
> > By default, the Tester is supposed to be the server which running DTS
> > and the packet sniff methods are running on it.
> > However, if DTS was not running on the Tester and the Tester is
> > another remote server, so packet sniff methods cannot sniff Tester's
> > packets correctly.
> >
> > This patch adds support for packet sniff methods to specify running
> > machine and implements sniff packet methods in class tester.
> >
> > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > specify the running machine.
> > 2. Remove load_sniff_packets method in packet.py.
> > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> > 4. Update tester.check_random_pkts method with
> > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
> > make it execution on the Tester.
> >
> > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > ---
> > framework/packet.py | 86
> > +++++++++++++++++++++++++----------------------------
> > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > 2 files changed, 84 insertions(+), 50 deletions(-)
> >
> > diff --git a/framework/packet.py b/framework/packet.py index
> > 976b82b..1f3f07d 100755
> > --- a/framework/packet.py
> > +++ b/framework/packet.py
> > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > return ""
> >
> >
> > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > """
> > sniff all packets for certain port in certain seconds
> > """
> > param = ""
> > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> > -
> > stderr=subprocess.STDOUT,
> > - shell=True)
> > + remote_terminate = 0
> > +
> > + # target[] contain the remote machine info for ssh connection
> > + # target[0]: username
> > + # target[1]: ip address
> > + # target[2]: pass word
> > + if target:
> > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > + "%s@%s" % (target[0], target[1]),
> > + "tcpdump -h"],
> > + stderr=subprocess.PIPE,
> > + stdout=subprocess.PIPE,
> > + shell=False)
> [Lijuan] Action will be blocked if SSH need password.
> > + tcpdump_help =
> > "".join(tuple(tcpdump_help_pipe.communicate()))
> > + tcpdump_help_pipe.wait()
> > + else:
> > + 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:
> > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0, timeout=5,
> > filters=[]):
> > else:
> > cmd = sniff_cmd % options
> >
> > - args = shlex.split(cmd)
> > + if target:
> > + pipe = subprocess.Popen(['ssh',
> > + '%s@%s' % (target[0], target[1]), cmd],
> > + stdin=subprocess.PIPE,
> > + shell=False)
> > + remote_terminate = 1
> > + else:
> > + args = shlex.split(cmd)
> > + pipe = subprocess.Popen(args)
> >
> > - pipe = subprocess.Popen(args)
> > index = str(time.time())
> > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > time.sleep(1)
> > return index
> >
> >
> > -def load_sniff_pcap(index=''):
> > +def load_sniff_pcap(index='', target=[]):
> > """
> > Stop sniffer and return pcap file
> > """
> > child_exit = False
> > if index in SNIFF_PIDS.keys():
> > - pipe, intf, timeout = SNIFF_PIDS[index]
> > + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> > time_elapse = int(time.time() - float(index))
> > while time_elapse < timeout:
> > if pipe.poll() is not None:
> > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > time_elapse += 1
> >
> > if not child_exit:
> > + if remote_terminate == 1:
> > + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> > + '%s@%s' % (target[0],
> > target[1]),
> > + 'kill -2 $(pidof tcpdump)'],
> > + stderr=subprocess.PIPE,
> > + shell=False)
> > + stop_tcpdump_pipe.wait()
> > +
> > pipe.send_signal(signal.SIGINT)
> > pipe.wait()
> >
> > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > return ""
> >
> >
> > -def load_sniff_packets(index=''):
> > - """
> > - Stop sniffer and return packet objects
> > - """
> > - pkts = []
> > - child_exit = False
> > - if index in SNIFF_PIDS.keys():
> > - pipe, intf, timeout = SNIFF_PIDS[index]
> > - time_elapse = int(time.time() - float(index))
> > - while time_elapse < timeout:
> > - if pipe.poll() is not None:
> > - child_exit = True
> > - break
> > -
> > - time.sleep(1)
> > - time_elapse += 1
> > -
> > - if not child_exit:
> > - pipe.send_signal(signal.SIGINT)
> > - pipe.wait()
> > -
> > - # wait pcap file ready
> > - time.sleep(1)
> > - try:
> > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > - for pkt in cap_pkts:
> > - # packet gen should be scapy
> > - packet = Packet(tx_port=intf)
> > - packet.pktgen.assign_pkt(pkt)
> > - pkts.append(packet)
> > - except:
> > - pass
> > -
> > - return pkts
> > -
> > -
> > def load_pcapfile(filename=""):
> > pkts = []
> > try:
> > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > inst = sniff_packets("lo", timeout=5)
> > pkt = Packet(pkt_type='UDP')
> > pkt.send_pkt(tx_port='lo')
> > - pkts = load_sniff_packets(inst)
> >
> > pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> > pkt.send_pkt(tx_port='lo')
> > diff --git a/framework/tester.py b/framework/tester.py index
> > a775f68..c5b705d 100755
> > --- a/framework/tester.py
> > +++ b/framework/tester.py
> > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> >
> > import re
> > import subprocess
> > +import os
> > from time import sleep
> > from settings import NICS, load_global_setting, PERF_SETTING from
> > crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > module = __import__("packet")
> > pkt_c = getattr(module, "Packet")
> > send_f = getattr(module, "send_packets")
> > - sniff_f = getattr(module, "sniff_packets")
> > - load_f = getattr(module, "load_sniff_packets")
> > compare_f = getattr(module, "compare_pktload")
> > strip_f = getattr(module, "strip_pktload")
> > save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@
> > class Tester(Crb):
> >
> > # send and sniff packets
> > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> > - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> > filters=
> > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > + count=pktnum, timeout=timeout, filters=
> > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > {'layer': 'network', 'config': {'dstport': '65535'}}])
> > rx_inst[rxport] = inst
> > @@ -627,7 +626,7 @@ class Tester(Crb):
> > # Verify all packets
> > prev_id = -1
> > for txport, rxport in portList:
> > - recv_pkts = load_f(rx_inst[rxport])
> > + recv_pkts =
> > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> >
> > # only report when recevied number not matched
> > if len(tx_pkts[txport]) > len(recv_pkts):
> > @@ -704,6 +703,47 @@ class Tester(Crb):
> > self.proc.kill()
> > self.proc = None
> >
> > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> > + """
> > + Wrapper for packet module sniff_packets
> > + """
> > + # load functions in packet module
> > + module = __import__("packet")
> > + sniff_f = getattr(module, "sniff_packets")
> > +
> > + target=[]
> > + target.append(self.get_username())
> > + target.append(self.get_ip_address())
> > + target.append(self.get_password())
> > + return sniff_f(intf, count, timeout, filters, target)
> > +
> > + def load_tcpdump_sniff_pcap(self, index=''):
> > + """
> > + Wrapper for packet module load_sniff_pcap
> > + """
> > + # load functions in packet module
> > + module = __import__("packet")
> > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > +
> > + target=[]
> > + target.append(self.get_username())
> > + target.append(self.get_ip_address())
> > + target.append(self.get_password())
> > + pcap = load_pcap_f(index, target)
> > + self.session.copy_file_from(pcap)
> > +
> > + return pcap.split(os.sep)[-1]
> > +
> > + def load_tcpdump_sniff_packets(self, index=''):
> > + """
> > + Wrapper for packet module load_pcapfile
> > + """
> > + # load functions in packet module
> > + packet = __import__("packet")
> > + file = self.load_tcpdump_sniff_pcap(index)
> > +
> > + return packet.load_pcapfile(file)
> > +
> > def kill_all(self, killall=False):
> > """
> > Kill all scapy process or DPDK application on tester.
> > --
> > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 3:21 ` Phil Yang (Arm Technology China)
@ 2018-09-21 3:41 ` Tu, Lijuan
2018-09-21 6:58 ` Phil Yang (Arm Technology China)
0 siblings, 1 reply; 124+ messages in thread
From: Tu, Lijuan @ 2018-09-21 3:41 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), Phil, dts; +Cc: nd, Liu, Yong
DTS supports either login server by password or utilize authorized login.
For logging by password, we could get some codes like " self.session = SSHPexpect(host, username, password, dut_id) " in SSHConnection module. and we have ip, username, password information in crb.cfg
I think we don't want to force user to utilize authorized login.
> -----Original Message-----
> From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> Sent: Friday, September 21, 2018 11:22 AM
> To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> sniffer to specify running machine
>
> Hi Lijuan,
>
> It also need to follow the DTS setup steps in
> https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
>
> Since you know where are your DUT and Tester, so you can use tool
> ssh-copy-id to save local available keys on DUT and Tester.
>
> Thanks,
> Phil Yang
>
> > -----Original Message-----
> > From: Tu, Lijuan <lijuan.tu@intel.com>
> > Sent: Friday, September 21, 2018 11:09 AM
> > To: Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang (Arm
> > Technology China) <Phil.Yang@arm.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > One comments, when we ssh to a server, it might request a password,
> > but we don't handle it.
> >
> >
> > > -----Original Message-----
> > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Phil@dpdk.org
> > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > To: dts@dpdk.org
> > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > <phil.yang@arm.com>
> > > Subject: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > From: Phil Yang <phil.yang@arm.com>
> > >
> > > By default, the Tester is supposed to be the server which running
> > > DTS and the packet sniff methods are running on it.
> > > However, if DTS was not running on the Tester and the Tester is
> > > another remote server, so packet sniff methods cannot sniff Tester's
> > > packets correctly.
> > >
> > > This patch adds support for packet sniff methods to specify running
> > > machine and implements sniff packet methods in class tester.
> > >
> > > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > > specify the running machine.
> > > 2. Remove load_sniff_packets method in packet.py.
> > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > load_tcpdump_sniff_packets for class tester with the new sniff_packet
> API.
> > > 4. Update tester.check_random_pkts method with
> > > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets
> > > to make it execution on the Tester.
> > >
> > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > ---
> > > framework/packet.py | 86
> > > +++++++++++++++++++++++++----------------------------
> > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > >
> > > diff --git a/framework/packet.py b/framework/packet.py index
> > > 976b82b..1f3f07d 100755
> > > --- a/framework/packet.py
> > > +++ b/framework/packet.py
> > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > return ""
> > >
> > >
> > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > """
> > > sniff all packets for certain port in certain seconds
> > > """
> > > param = ""
> > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> > > -
> > > stderr=subprocess.STDOUT,
> > > - shell=True)
> > > + remote_terminate = 0
> > > +
> > > + # target[] contain the remote machine info for ssh connection
> > > + # target[0]: username
> > > + # target[1]: ip address
> > > + # target[2]: pass word
> > > + if target:
> > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > + "%s@%s" % (target[0], target[1]),
> > > + "tcpdump -h"],
> > > + stderr=subprocess.PIPE,
> > > + stdout=subprocess.PIPE,
> > > + shell=False)
> > [Lijuan] Action will be blocked if SSH need password.
> > > + tcpdump_help =
> > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > + tcpdump_help_pipe.wait()
> > > + else:
> > > + 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:
> > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0, timeout=5,
> > > filters=[]):
> > > else:
> > > cmd = sniff_cmd % options
> > >
> > > - args = shlex.split(cmd)
> > > + if target:
> > > + pipe = subprocess.Popen(['ssh',
> > > + '%s@%s' % (target[0], target[1]), cmd],
> > > + stdin=subprocess.PIPE,
> > > + shell=False)
> > > + remote_terminate = 1
> > > + else:
> > > + args = shlex.split(cmd)
> > > + pipe = subprocess.Popen(args)
> > >
> > > - pipe = subprocess.Popen(args)
> > > index = str(time.time())
> > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > > time.sleep(1)
> > > return index
> > >
> > >
> > > -def load_sniff_pcap(index=''):
> > > +def load_sniff_pcap(index='', target=[]):
> > > """
> > > Stop sniffer and return pcap file
> > > """
> > > child_exit = False
> > > if index in SNIFF_PIDS.keys():
> > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> > > time_elapse = int(time.time() - float(index))
> > > while time_elapse < timeout:
> > > if pipe.poll() is not None:
> > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > time_elapse += 1
> > >
> > > if not child_exit:
> > > + if remote_terminate == 1:
> > > + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> > > + '%s@%s' % (target[0],
> > > target[1]),
> > > + 'kill -2 $(pidof tcpdump)'],
> > > + stderr=subprocess.PIPE,
> > > + shell=False)
> > > + stop_tcpdump_pipe.wait()
> > > +
> > > pipe.send_signal(signal.SIGINT)
> > > pipe.wait()
> > >
> > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > return ""
> > >
> > >
> > > -def load_sniff_packets(index=''):
> > > - """
> > > - Stop sniffer and return packet objects
> > > - """
> > > - pkts = []
> > > - child_exit = False
> > > - if index in SNIFF_PIDS.keys():
> > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > - time_elapse = int(time.time() - float(index))
> > > - while time_elapse < timeout:
> > > - if pipe.poll() is not None:
> > > - child_exit = True
> > > - break
> > > -
> > > - time.sleep(1)
> > > - time_elapse += 1
> > > -
> > > - if not child_exit:
> > > - pipe.send_signal(signal.SIGINT)
> > > - pipe.wait()
> > > -
> > > - # wait pcap file ready
> > > - time.sleep(1)
> > > - try:
> > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > - for pkt in cap_pkts:
> > > - # packet gen should be scapy
> > > - packet = Packet(tx_port=intf)
> > > - packet.pktgen.assign_pkt(pkt)
> > > - pkts.append(packet)
> > > - except:
> > > - pass
> > > -
> > > - return pkts
> > > -
> > > -
> > > def load_pcapfile(filename=""):
> > > pkts = []
> > > try:
> > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > inst = sniff_packets("lo", timeout=5)
> > > pkt = Packet(pkt_type='UDP')
> > > pkt.send_pkt(tx_port='lo')
> > > - pkts = load_sniff_packets(inst)
> > >
> > > pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> > > pkt.send_pkt(tx_port='lo')
> > > diff --git a/framework/tester.py b/framework/tester.py index
> > > a775f68..c5b705d 100755
> > > --- a/framework/tester.py
> > > +++ b/framework/tester.py
> > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > >
> > > import re
> > > import subprocess
> > > +import os
> > > from time import sleep
> > > from settings import NICS, load_global_setting, PERF_SETTING from
> > > crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > > module = __import__("packet")
> > > pkt_c = getattr(module, "Packet")
> > > send_f = getattr(module, "send_packets")
> > > - sniff_f = getattr(module, "sniff_packets")
> > > - load_f = getattr(module, "load_sniff_packets")
> > > compare_f = getattr(module, "compare_pktload")
> > > strip_f = getattr(module, "strip_pktload")
> > > save_f = getattr(module, "save_packets") @@ -606,7 +605,7
> > > @@ class Tester(Crb):
> > >
> > > # send and sniff packets
> > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> timeout=timeout,
> > > filters=
> > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > + count=pktnum, timeout=timeout, filters=
> > > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > > {'layer': 'network', 'config': {'dstport': '65535'}}])
> > > rx_inst[rxport] = inst
> > > @@ -627,7 +626,7 @@ class Tester(Crb):
> > > # Verify all packets
> > > prev_id = -1
> > > for txport, rxport in portList:
> > > - recv_pkts = load_f(rx_inst[rxport])
> > > + recv_pkts =
> > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > >
> > > # only report when recevied number not matched
> > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > self.proc.kill()
> > > self.proc = None
> > >
> > > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5,
> filters=[]):
> > > + """
> > > + Wrapper for packet module sniff_packets
> > > + """
> > > + # load functions in packet module
> > > + module = __import__("packet")
> > > + sniff_f = getattr(module, "sniff_packets")
> > > +
> > > + target=[]
> > > + target.append(self.get_username())
> > > + target.append(self.get_ip_address())
> > > + target.append(self.get_password())
> > > + return sniff_f(intf, count, timeout, filters, target)
> > > +
> > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > + """
> > > + Wrapper for packet module load_sniff_pcap
> > > + """
> > > + # load functions in packet module
> > > + module = __import__("packet")
> > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > +
> > > + target=[]
> > > + target.append(self.get_username())
> > > + target.append(self.get_ip_address())
> > > + target.append(self.get_password())
> > > + pcap = load_pcap_f(index, target)
> > > + self.session.copy_file_from(pcap)
> > > +
> > > + return pcap.split(os.sep)[-1]
> > > +
> > > + def load_tcpdump_sniff_packets(self, index=''):
> > > + """
> > > + Wrapper for packet module load_pcapfile
> > > + """
> > > + # load functions in packet module
> > > + packet = __import__("packet")
> > > + file = self.load_tcpdump_sniff_pcap(index)
> > > +
> > > + return packet.load_pcapfile(file)
> > > +
> > > def kill_all(self, killall=False):
> > > """
> > > Kill all scapy process or DPDK application on tester.
> > > --
> > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 3:41 ` Tu, Lijuan
@ 2018-09-21 6:58 ` Phil Yang (Arm Technology China)
2018-09-21 7:19 ` Tu, Lijuan
0 siblings, 1 reply; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-09-21 6:58 UTC (permalink / raw)
To: Tu, Lijuan, Phil, dts; +Cc: nd, Liu, Yong
Yes. I agreed with that.
I think my patch has also followed this rule.
In the packet.py, I added one more parameter "target" for sniff_packets and load_sniff_pcap to specify the username and IP address.
In the test.py, I passed the Tester's passwd and IP address to these two functions. Thus, it will make sure sniff packet operation done on the Tester.
Thanks,
Phil Yang
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Friday, September 21, 2018 11:42 AM
> To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; Phil@dpdk.org;
> dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> DTS supports either login server by password or utilize authorized login.
> For logging by password, we could get some codes like " self.session =
> SSHPexpect(host, username, password, dut_id) " in SSHConnection module. and
> we have ip, username, password information in crb.cfg I think we don't want to
> force user to utilize authorized login.
>
> > -----Original Message-----
> > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > Sent: Friday, September 21, 2018 11:22 AM
> > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > Hi Lijuan,
> >
> > It also need to follow the DTS setup steps in
> > https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> >
> > Since you know where are your DUT and Tester, so you can use tool
> > ssh-copy-id to save local available keys on DUT and Tester.
> >
> > Thanks,
> > Phil Yang
> >
> > > -----Original Message-----
> > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > Sent: Friday, September 21, 2018 11:09 AM
> > > To: Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang (Arm
> > > Technology China) <Phil.Yang@arm.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > One comments, when we ssh to a server, it might request a password,
> > > but we don't handle it.
> > >
> > >
> > > > -----Original Message-----
> > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Phil@dpdk.org
> > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > To: dts@dpdk.org
> > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > <phil.yang@arm.com>
> > > > Subject: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > > sniffer to specify running machine
> > > >
> > > > From: Phil Yang <phil.yang@arm.com>
> > > >
> > > > By default, the Tester is supposed to be the server which running
> > > > DTS and the packet sniff methods are running on it.
> > > > However, if DTS was not running on the Tester and the Tester is
> > > > another remote server, so packet sniff methods cannot sniff
> > > > Tester's packets correctly.
> > > >
> > > > This patch adds support for packet sniff methods to specify
> > > > running machine and implements sniff packet methods in class tester.
> > > >
> > > > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > > > specify the running machine.
> > > > 2. Remove load_sniff_packets method in packet.py.
> > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > > load_tcpdump_sniff_packets for class tester with the new
> > > > sniff_packet
> > API.
> > > > 4. Update tester.check_random_pkts method with
> > > > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets
> > > > to make it execution on the Tester.
> > > >
> > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > ---
> > > > framework/packet.py | 86
> > > > +++++++++++++++++++++++++----------------------------
> > > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > >
> > > > diff --git a/framework/packet.py b/framework/packet.py index
> > > > 976b82b..1f3f07d 100755
> > > > --- a/framework/packet.py
> > > > +++ b/framework/packet.py
> > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > return ""
> > > >
> > > >
> > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > > """
> > > > sniff all packets for certain port in certain seconds
> > > > """
> > > > param = ""
> > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> > > > -
> > > > stderr=subprocess.STDOUT,
> > > > - shell=True)
> > > > + remote_terminate = 0
> > > > +
> > > > + # target[] contain the remote machine info for ssh connection
> > > > + # target[0]: username
> > > > + # target[1]: ip address
> > > > + # target[2]: pass word
> > > > + if target:
> > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > + "%s@%s" % (target[0], target[1]),
> > > > + "tcpdump -h"],
> > > > + stderr=subprocess.PIPE,
> > > > + stdout=subprocess.PIPE,
> > > > + shell=False)
> > > [Lijuan] Action will be blocked if SSH need password.
> > > > + tcpdump_help =
> > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > + tcpdump_help_pipe.wait()
> > > > + else:
> > > > + 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:
> > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0, timeout=5,
> > > > filters=[]):
> > > > else:
> > > > cmd = sniff_cmd % options
> > > >
> > > > - args = shlex.split(cmd)
> > > > + if target:
> > > > + pipe = subprocess.Popen(['ssh',
> > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > + stdin=subprocess.PIPE,
> > > > + shell=False)
> > > > + remote_terminate = 1
> > > > + else:
> > > > + args = shlex.split(cmd)
> > > > + pipe = subprocess.Popen(args)
> > > >
> > > > - pipe = subprocess.Popen(args)
> > > > index = str(time.time())
> > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > > > time.sleep(1)
> > > > return index
> > > >
> > > >
> > > > -def load_sniff_pcap(index=''):
> > > > +def load_sniff_pcap(index='', target=[]):
> > > > """
> > > > Stop sniffer and return pcap file
> > > > """
> > > > child_exit = False
> > > > if index in SNIFF_PIDS.keys():
> > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> > > > time_elapse = int(time.time() - float(index))
> > > > while time_elapse < timeout:
> > > > if pipe.poll() is not None:
> > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > time_elapse += 1
> > > >
> > > > if not child_exit:
> > > > + if remote_terminate == 1:
> > > > + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> > > > + '%s@%s' % (target[0],
> > > > target[1]),
> > > > + 'kill -2 $(pidof tcpdump)'],
> > > > + stderr=subprocess.PIPE,
> > > > + shell=False)
> > > > + stop_tcpdump_pipe.wait()
> > > > +
> > > > pipe.send_signal(signal.SIGINT)
> > > > pipe.wait()
> > > >
> > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > return ""
> > > >
> > > >
> > > > -def load_sniff_packets(index=''):
> > > > - """
> > > > - Stop sniffer and return packet objects
> > > > - """
> > > > - pkts = []
> > > > - child_exit = False
> > > > - if index in SNIFF_PIDS.keys():
> > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > - time_elapse = int(time.time() - float(index))
> > > > - while time_elapse < timeout:
> > > > - if pipe.poll() is not None:
> > > > - child_exit = True
> > > > - break
> > > > -
> > > > - time.sleep(1)
> > > > - time_elapse += 1
> > > > -
> > > > - if not child_exit:
> > > > - pipe.send_signal(signal.SIGINT)
> > > > - pipe.wait()
> > > > -
> > > > - # wait pcap file ready
> > > > - time.sleep(1)
> > > > - try:
> > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > > - for pkt in cap_pkts:
> > > > - # packet gen should be scapy
> > > > - packet = Packet(tx_port=intf)
> > > > - packet.pktgen.assign_pkt(pkt)
> > > > - pkts.append(packet)
> > > > - except:
> > > > - pass
> > > > -
> > > > - return pkts
> > > > -
> > > > -
> > > > def load_pcapfile(filename=""):
> > > > pkts = []
> > > > try:
> > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > inst = sniff_packets("lo", timeout=5)
> > > > pkt = Packet(pkt_type='UDP')
> > > > pkt.send_pkt(tx_port='lo')
> > > > - pkts = load_sniff_packets(inst)
> > > >
> > > > pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> > > > pkt.send_pkt(tx_port='lo')
> > > > diff --git a/framework/tester.py b/framework/tester.py index
> > > > a775f68..c5b705d 100755
> > > > --- a/framework/tester.py
> > > > +++ b/framework/tester.py
> > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > >
> > > > import re
> > > > import subprocess
> > > > +import os
> > > > from time import sleep
> > > > from settings import NICS, load_global_setting, PERF_SETTING
> > > > from crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > > > module = __import__("packet")
> > > > pkt_c = getattr(module, "Packet")
> > > > send_f = getattr(module, "send_packets")
> > > > - sniff_f = getattr(module, "sniff_packets")
> > > > - load_f = getattr(module, "load_sniff_packets")
> > > > compare_f = getattr(module, "compare_pktload")
> > > > strip_f = getattr(module, "strip_pktload")
> > > > save_f = getattr(module, "save_packets") @@ -606,7 +605,7
> > > > @@ class Tester(Crb):
> > > >
> > > > # send and sniff packets
> > > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > timeout=timeout,
> > > > filters=
> > > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > > + count=pktnum, timeout=timeout, filters=
> > > > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > > > {'layer': 'network', 'config': {'dstport': '65535'}}])
> > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@ class
> > > > Tester(Crb):
> > > > # Verify all packets
> > > > prev_id = -1
> > > > for txport, rxport in portList:
> > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > + recv_pkts =
> > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > >
> > > > # only report when recevied number not matched
> > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > self.proc.kill()
> > > > self.proc = None
> > > >
> > > > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5,
> > filters=[]):
> > > > + """
> > > > + Wrapper for packet module sniff_packets
> > > > + """
> > > > + # load functions in packet module
> > > > + module = __import__("packet")
> > > > + sniff_f = getattr(module, "sniff_packets")
> > > > +
> > > > + target=[]
> > > > + target.append(self.get_username())
> > > > + target.append(self.get_ip_address())
> > > > + target.append(self.get_password())
> > > > + return sniff_f(intf, count, timeout, filters, target)
> > > > +
> > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > + """
> > > > + Wrapper for packet module load_sniff_pcap
> > > > + """
> > > > + # load functions in packet module
> > > > + module = __import__("packet")
> > > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > > +
> > > > + target=[]
> > > > + target.append(self.get_username())
> > > > + target.append(self.get_ip_address())
> > > > + target.append(self.get_password())
> > > > + pcap = load_pcap_f(index, target)
> > > > + self.session.copy_file_from(pcap)
> > > > +
> > > > + return pcap.split(os.sep)[-1]
> > > > +
> > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > + """
> > > > + Wrapper for packet module load_pcapfile
> > > > + """
> > > > + # load functions in packet module
> > > > + packet = __import__("packet")
> > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > +
> > > > + return packet.load_pcapfile(file)
> > > > +
> > > > def kill_all(self, killall=False):
> > > > """
> > > > Kill all scapy process or DPDK application on tester.
> > > > --
> > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 6:58 ` Phil Yang (Arm Technology China)
@ 2018-09-21 7:19 ` Tu, Lijuan
2018-09-21 7:32 ` Phil Yang (Arm Technology China)
0 siblings, 1 reply; 124+ messages in thread
From: Tu, Lijuan @ 2018-09-21 7:19 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), Phil, dts; +Cc: nd, Liu, Yong
I am glad we reach an agreement.
Of course, the parameter "target" have password, but I found no any function would call it.
Only username and ip are used. The target[2] is the password, and is not called.
+ if target:
+ tcpdump_help_pipe = subprocess.Popen(["ssh",
+ "%s@%s" % (target[0], target[1]),
+ "tcpdump -h"],
+ stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ shell=False)
Anything I missed?
> -----Original Message-----
> From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> Sent: Friday, September 21, 2018 2:59 PM
> To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> sniffer to specify running machine
>
> Yes. I agreed with that.
>
> I think my patch has also followed this rule.
> In the packet.py, I added one more parameter "target" for sniff_packets and
> load_sniff_pcap to specify the username and IP address.
> In the test.py, I passed the Tester's passwd and IP address to these two
> functions. Thus, it will make sure sniff packet operation done on the Tester.
>
> Thanks,
> Phil Yang
>
> > -----Original Message-----
> > From: Tu, Lijuan <lijuan.tu@intel.com>
> > Sent: Friday, September 21, 2018 11:42 AM
> > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > DTS supports either login server by password or utilize authorized login.
> > For logging by password, we could get some codes like " self.session =
> > SSHPexpect(host, username, password, dut_id) " in SSHConnection
> > module. and we have ip, username, password information in crb.cfg I
> > think we don't want to force user to utilize authorized login.
> >
> > > -----Original Message-----
> > > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > > Sent: Friday, September 21, 2018 11:22 AM
> > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > Hi Lijuan,
> > >
> > > It also need to follow the DTS setup steps in
> > > https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> > >
> > > Since you know where are your DUT and Tester, so you can use tool
> > > ssh-copy-id to save local available keys on DUT and Tester.
> > >
> > > Thanks,
> > > Phil Yang
> > >
> > > > -----Original Message-----
> > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > Sent: Friday, September 21, 2018 11:09 AM
> > > > To: Phil@dpdk.org; dts@dpdk.org
> > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > (Arm Technology China) <Phil.Yang@arm.com>
> > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > packet sniffer to specify running machine
> > > >
> > > > One comments, when we ssh to a server, it might request a
> > > > password, but we don't handle it.
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of
> > > > > Phil@dpdk.org
> > > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > > To: dts@dpdk.org
> > > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > <phil.yang@arm.com>
> > > > > Subject: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > > > sniffer to specify running machine
> > > > >
> > > > > From: Phil Yang <phil.yang@arm.com>
> > > > >
> > > > > By default, the Tester is supposed to be the server which
> > > > > running DTS and the packet sniff methods are running on it.
> > > > > However, if DTS was not running on the Tester and the Tester is
> > > > > another remote server, so packet sniff methods cannot sniff
> > > > > Tester's packets correctly.
> > > > >
> > > > > This patch adds support for packet sniff methods to specify
> > > > > running machine and implements sniff packet methods in class tester.
> > > > >
> > > > > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > > > > specify the running machine.
> > > > > 2. Remove load_sniff_packets method in packet.py.
> > > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > > > load_tcpdump_sniff_packets for class tester with the new
> > > > > sniff_packet
> > > API.
> > > > > 4. Update tester.check_random_pkts method with
> > > > > tester.tcpdump_sniff_packets and
> > > > > tester.load_tcpdump_sniff_packets to make it execution on the
> Tester.
> > > > >
> > > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > > ---
> > > > > framework/packet.py | 86
> > > > > +++++++++++++++++++++++++----------------------------
> > > > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > > >
> > > > > diff --git a/framework/packet.py b/framework/packet.py index
> > > > > 976b82b..1f3f07d 100755
> > > > > --- a/framework/packet.py
> > > > > +++ b/framework/packet.py
> > > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > > return ""
> > > > >
> > > > >
> > > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > > > """
> > > > > sniff all packets for certain port in certain seconds
> > > > > """
> > > > > param = ""
> > > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > > - tcpdump_help = subprocess.check_output("tcpdump -h; echo
> 0",
> > > > > -
> > > > > stderr=subprocess.STDOUT,
> > > > > - shell=True)
> > > > > + remote_terminate = 0
> > > > > +
> > > > > + # target[] contain the remote machine info for ssh connection
> > > > > + # target[0]: username
> > > > > + # target[1]: ip address
> > > > > + # target[2]: pass word
> > > > > + if target:
> > > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > > + "%s@%s" % (target[0], target[1]),
> > > > > + "tcpdump -h"],
> > > > > + stderr=subprocess.PIPE,
> > > > > + stdout=subprocess.PIPE,
> > > > > + shell=False)
> > > > [Lijuan] Action will be blocked if SSH need password.
> > > > > + tcpdump_help =
> > > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > > + tcpdump_help_pipe.wait()
> > > > > + else:
> > > > > + 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:
> > > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0,
> > > > > timeout=5,
> > > > > filters=[]):
> > > > > else:
> > > > > cmd = sniff_cmd % options
> > > > >
> > > > > - args = shlex.split(cmd)
> > > > > + if target:
> > > > > + pipe = subprocess.Popen(['ssh',
> > > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > > + stdin=subprocess.PIPE,
> > > > > + shell=False)
> > > > > + remote_terminate = 1
> > > > > + else:
> > > > > + args = shlex.split(cmd)
> > > > > + pipe = subprocess.Popen(args)
> > > > >
> > > > > - pipe = subprocess.Popen(args)
> > > > > index = str(time.time())
> > > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > > > > time.sleep(1)
> > > > > return index
> > > > >
> > > > >
> > > > > -def load_sniff_pcap(index=''):
> > > > > +def load_sniff_pcap(index='', target=[]):
> > > > > """
> > > > > Stop sniffer and return pcap file
> > > > > """
> > > > > child_exit = False
> > > > > if index in SNIFF_PIDS.keys():
> > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > + pipe, intf, timeout, remote_terminate =
> > > > > + SNIFF_PIDS[index]
> > > > > time_elapse = int(time.time() - float(index))
> > > > > while time_elapse < timeout:
> > > > > if pipe.poll() is not None:
> > > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > > time_elapse += 1
> > > > >
> > > > > if not child_exit:
> > > > > + if remote_terminate == 1:
> > > > > + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> > > > > + '%s@%s' % (target[0],
> > > > > target[1]),
> > > > > + 'kill -2 $(pidof
> tcpdump)'],
> > > > > + stderr=subprocess.PIPE,
> > > > > + shell=False)
> > > > > + stop_tcpdump_pipe.wait()
> > > > > +
> > > > > pipe.send_signal(signal.SIGINT)
> > > > > pipe.wait()
> > > > >
> > > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > > return ""
> > > > >
> > > > >
> > > > > -def load_sniff_packets(index=''):
> > > > > - """
> > > > > - Stop sniffer and return packet objects
> > > > > - """
> > > > > - pkts = []
> > > > > - child_exit = False
> > > > > - if index in SNIFF_PIDS.keys():
> > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > - time_elapse = int(time.time() - float(index))
> > > > > - while time_elapse < timeout:
> > > > > - if pipe.poll() is not None:
> > > > > - child_exit = True
> > > > > - break
> > > > > -
> > > > > - time.sleep(1)
> > > > > - time_elapse += 1
> > > > > -
> > > > > - if not child_exit:
> > > > > - pipe.send_signal(signal.SIGINT)
> > > > > - pipe.wait()
> > > > > -
> > > > > - # wait pcap file ready
> > > > > - time.sleep(1)
> > > > > - try:
> > > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > > > - for pkt in cap_pkts:
> > > > > - # packet gen should be scapy
> > > > > - packet = Packet(tx_port=intf)
> > > > > - packet.pktgen.assign_pkt(pkt)
> > > > > - pkts.append(packet)
> > > > > - except:
> > > > > - pass
> > > > > -
> > > > > - return pkts
> > > > > -
> > > > > -
> > > > > def load_pcapfile(filename=""):
> > > > > pkts = []
> > > > > try:
> > > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > > inst = sniff_packets("lo", timeout=5)
> > > > > pkt = Packet(pkt_type='UDP')
> > > > > pkt.send_pkt(tx_port='lo')
> > > > > - pkts = load_sniff_packets(inst)
> > > > >
> > > > > pkt = Packet(pkt_type='UDP', pkt_len=1500,
> ran_payload=True)
> > > > > pkt.send_pkt(tx_port='lo')
> > > > > diff --git a/framework/tester.py b/framework/tester.py index
> > > > > a775f68..c5b705d 100755
> > > > > --- a/framework/tester.py
> > > > > +++ b/framework/tester.py
> > > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > > >
> > > > > import re
> > > > > import subprocess
> > > > > +import os
> > > > > from time import sleep
> > > > > from settings import NICS, load_global_setting, PERF_SETTING
> > > > > from crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > > > > module = __import__("packet")
> > > > > pkt_c = getattr(module, "Packet")
> > > > > send_f = getattr(module, "send_packets")
> > > > > - sniff_f = getattr(module, "sniff_packets")
> > > > > - load_f = getattr(module, "load_sniff_packets")
> > > > > compare_f = getattr(module, "compare_pktload")
> > > > > strip_f = getattr(module, "strip_pktload")
> > > > > save_f = getattr(module, "save_packets") @@ -606,7
> > > > > +605,7 @@ class Tester(Crb):
> > > > >
> > > > > # send and sniff packets
> > > > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" %
> txIntf)
> > > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > > timeout=timeout,
> > > > > filters=
> > > > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > > > + count=pktnum, timeout=timeout, filters=
> > > > > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > > > > {'layer': 'network', 'config': {'dstport':
> '65535'}}])
> > > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@ class
> > > > > Tester(Crb):
> > > > > # Verify all packets
> > > > > prev_id = -1
> > > > > for txport, rxport in portList:
> > > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > > + recv_pkts =
> > > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > > >
> > > > > # only report when recevied number not matched
> > > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > > self.proc.kill()
> > > > > self.proc = None
> > > > >
> > > > > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5,
> > > filters=[]):
> > > > > + """
> > > > > + Wrapper for packet module sniff_packets
> > > > > + """
> > > > > + # load functions in packet module
> > > > > + module = __import__("packet")
> > > > > + sniff_f = getattr(module, "sniff_packets")
> > > > > +
> > > > > + target=[]
> > > > > + target.append(self.get_username())
> > > > > + target.append(self.get_ip_address())
> > > > > + target.append(self.get_password())
> > > > > + return sniff_f(intf, count, timeout, filters, target)
> > > > > +
> > > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > > + """
> > > > > + Wrapper for packet module load_sniff_pcap
> > > > > + """
> > > > > + # load functions in packet module
> > > > > + module = __import__("packet")
> > > > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > > > +
> > > > > + target=[]
> > > > > + target.append(self.get_username())
> > > > > + target.append(self.get_ip_address())
> > > > > + target.append(self.get_password())
> > > > > + pcap = load_pcap_f(index, target)
> > > > > + self.session.copy_file_from(pcap)
> > > > > +
> > > > > + return pcap.split(os.sep)[-1]
> > > > > +
> > > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > > + """
> > > > > + Wrapper for packet module load_pcapfile
> > > > > + """
> > > > > + # load functions in packet module
> > > > > + packet = __import__("packet")
> > > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > > +
> > > > > + return packet.load_pcapfile(file)
> > > > > +
> > > > > def kill_all(self, killall=False):
> > > > > """
> > > > > Kill all scapy process or DPDK application on tester.
> > > > > --
> > > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 7:19 ` Tu, Lijuan
@ 2018-09-21 7:32 ` Phil Yang (Arm Technology China)
2018-09-21 8:27 ` Tu, Lijuan
0 siblings, 1 reply; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-09-21 7:32 UTC (permalink / raw)
To: Tu, Lijuan, Phil, dts; +Cc: nd, Liu, Yong
tcpdump_sniff_packet and load_tcpdump_sniff_pcap in class Tester will call those two functions.
def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
"""
Wrapper for packet module sniff_packets
"""
# load functions in packet module
module = __import__("packet")
sniff_f = getattr(module, "sniff_packets")
target=[]
target.append(self.get_username())
target.append(self.get_ip_address())
target.append(self.get_password())
return sniff_f(intf, count, timeout, filters, target)
Please check test.py in this patch.
Thanks,
Phil Yang
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Friday, September 21, 2018 3:19 PM
> To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; Phil@dpdk.org;
> dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> I am glad we reach an agreement.
>
> Of course, the parameter "target" have password, but I found no any function
> would call it.
> Only username and ip are used. The target[2] is the password, and is not called.
> + if target:
> + tcpdump_help_pipe = subprocess.Popen(["ssh",
> + "%s@%s" % (target[0], target[1]),
> + "tcpdump -h"],
> + stderr=subprocess.PIPE,
> + stdout=subprocess.PIPE,
> + shell=False)
> Anything I missed?
>
>
> > -----Original Message-----
> > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > Sent: Friday, September 21, 2018 2:59 PM
> > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > Yes. I agreed with that.
> >
> > I think my patch has also followed this rule.
> > In the packet.py, I added one more parameter "target" for
> > sniff_packets and load_sniff_pcap to specify the username and IP address.
> > In the test.py, I passed the Tester's passwd and IP address to these
> > two functions. Thus, it will make sure sniff packet operation done on the
> Tester.
> >
> > Thanks,
> > Phil Yang
> >
> > > -----Original Message-----
> > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > Sent: Friday, September 21, 2018 11:42 AM
> > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > DTS supports either login server by password or utilize authorized login.
> > > For logging by password, we could get some codes like " self.session
> > > = SSHPexpect(host, username, password, dut_id) " in SSHConnection
> > > module. and we have ip, username, password information in crb.cfg I
> > > think we don't want to force user to utilize authorized login.
> > >
> > > > -----Original Message-----
> > > > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > > > Sent: Friday, September 21, 2018 11:22 AM
> > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > packet sniffer to specify running machine
> > > >
> > > > Hi Lijuan,
> > > >
> > > > It also need to follow the DTS setup steps in
> > > > https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> > > >
> > > > Since you know where are your DUT and Tester, so you can use tool
> > > > ssh-copy-id to save local available keys on DUT and Tester.
> > > >
> > > > Thanks,
> > > > Phil Yang
> > > >
> > > > > -----Original Message-----
> > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > Sent: Friday, September 21, 2018 11:09 AM
> > > > > To: Phil@dpdk.org; dts@dpdk.org
> > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > (Arm Technology China) <Phil.Yang@arm.com>
> > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > packet sniffer to specify running machine
> > > > >
> > > > > One comments, when we ssh to a server, it might request a
> > > > > password, but we don't handle it.
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of
> > > > > > Phil@dpdk.org
> > > > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > > > To: dts@dpdk.org
> > > > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > > <phil.yang@arm.com>
> > > > > > Subject: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > packet sniffer to specify running machine
> > > > > >
> > > > > > From: Phil Yang <phil.yang@arm.com>
> > > > > >
> > > > > > By default, the Tester is supposed to be the server which
> > > > > > running DTS and the packet sniff methods are running on it.
> > > > > > However, if DTS was not running on the Tester and the Tester
> > > > > > is another remote server, so packet sniff methods cannot sniff
> > > > > > Tester's packets correctly.
> > > > > >
> > > > > > This patch adds support for packet sniff methods to specify
> > > > > > running machine and implements sniff packet methods in class tester.
> > > > > >
> > > > > > 1. Add parameter to sniff_packet and load_sniff_pcap methods
> > > > > > to specify the running machine.
> > > > > > 2. Remove load_sniff_packets method in packet.py.
> > > > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > > > > load_tcpdump_sniff_packets for class tester with the new
> > > > > > sniff_packet
> > > > API.
> > > > > > 4. Update tester.check_random_pkts method with
> > > > > > tester.tcpdump_sniff_packets and
> > > > > > tester.load_tcpdump_sniff_packets to make it execution on the
> > Tester.
> > > > > >
> > > > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > > > ---
> > > > > > framework/packet.py | 86
> > > > > > +++++++++++++++++++++++++----------------------------
> > > > > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > > > >
> > > > > > diff --git a/framework/packet.py b/framework/packet.py index
> > > > > > 976b82b..1f3f07d 100755
> > > > > > --- a/framework/packet.py
> > > > > > +++ b/framework/packet.py
> > > > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > > > return ""
> > > > > >
> > > > > >
> > > > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > > > > """
> > > > > > sniff all packets for certain port in certain seconds
> > > > > > """
> > > > > > param = ""
> > > > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > > > - tcpdump_help = subprocess.check_output("tcpdump -h; echo
> > 0",
> > > > > > -
> > > > > > stderr=subprocess.STDOUT,
> > > > > > - shell=True)
> > > > > > + remote_terminate = 0
> > > > > > +
> > > > > > + # target[] contain the remote machine info for ssh connection
> > > > > > + # target[0]: username
> > > > > > + # target[1]: ip address
> > > > > > + # target[2]: pass word
> > > > > > + if target:
> > > > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > > > + "%s@%s" % (target[0], target[1]),
> > > > > > + "tcpdump -h"],
> > > > > > + stderr=subprocess.PIPE,
> > > > > > + stdout=subprocess.PIPE,
> > > > > > + shell=False)
> > > > > [Lijuan] Action will be blocked if SSH need password.
> > > > > > + tcpdump_help =
> > > > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > > > + tcpdump_help_pipe.wait()
> > > > > > + else:
> > > > > > + 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:
> > > > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0,
> > > > > > timeout=5,
> > > > > > filters=[]):
> > > > > > else:
> > > > > > cmd = sniff_cmd % options
> > > > > >
> > > > > > - args = shlex.split(cmd)
> > > > > > + if target:
> > > > > > + pipe = subprocess.Popen(['ssh',
> > > > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > > > + stdin=subprocess.PIPE,
> > > > > > + shell=False)
> > > > > > + remote_terminate = 1
> > > > > > + else:
> > > > > > + args = shlex.split(cmd)
> > > > > > + pipe = subprocess.Popen(args)
> > > > > >
> > > > > > - pipe = subprocess.Popen(args)
> > > > > > index = str(time.time())
> > > > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > > > + SNIFF_PIDS[index] = (pipe, intf, timeout,
> > > > > > + remote_terminate)
> > > > > > time.sleep(1)
> > > > > > return index
> > > > > >
> > > > > >
> > > > > > -def load_sniff_pcap(index=''):
> > > > > > +def load_sniff_pcap(index='', target=[]):
> > > > > > """
> > > > > > Stop sniffer and return pcap file
> > > > > > """
> > > > > > child_exit = False
> > > > > > if index in SNIFF_PIDS.keys():
> > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > + pipe, intf, timeout, remote_terminate =
> > > > > > + SNIFF_PIDS[index]
> > > > > > time_elapse = int(time.time() - float(index))
> > > > > > while time_elapse < timeout:
> > > > > > if pipe.poll() is not None:
> > > > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > > > time_elapse += 1
> > > > > >
> > > > > > if not child_exit:
> > > > > > + if remote_terminate == 1:
> > > > > > + stop_tcpdump_pipe = subprocess.Popen(['ssh',
> > > > > > + '%s@%s' % (target[0],
> > > > > > target[1]),
> > > > > > + 'kill -2 $(pidof
> > tcpdump)'],
> > > > > > + stderr=subprocess.PIPE,
> > > > > > + shell=False)
> > > > > > + stop_tcpdump_pipe.wait()
> > > > > > +
> > > > > > pipe.send_signal(signal.SIGINT)
> > > > > > pipe.wait()
> > > > > >
> > > > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > > > return ""
> > > > > >
> > > > > >
> > > > > > -def load_sniff_packets(index=''):
> > > > > > - """
> > > > > > - Stop sniffer and return packet objects
> > > > > > - """
> > > > > > - pkts = []
> > > > > > - child_exit = False
> > > > > > - if index in SNIFF_PIDS.keys():
> > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > - time_elapse = int(time.time() - float(index))
> > > > > > - while time_elapse < timeout:
> > > > > > - if pipe.poll() is not None:
> > > > > > - child_exit = True
> > > > > > - break
> > > > > > -
> > > > > > - time.sleep(1)
> > > > > > - time_elapse += 1
> > > > > > -
> > > > > > - if not child_exit:
> > > > > > - pipe.send_signal(signal.SIGINT)
> > > > > > - pipe.wait()
> > > > > > -
> > > > > > - # wait pcap file ready
> > > > > > - time.sleep(1)
> > > > > > - try:
> > > > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > > > > - for pkt in cap_pkts:
> > > > > > - # packet gen should be scapy
> > > > > > - packet = Packet(tx_port=intf)
> > > > > > - packet.pktgen.assign_pkt(pkt)
> > > > > > - pkts.append(packet)
> > > > > > - except:
> > > > > > - pass
> > > > > > -
> > > > > > - return pkts
> > > > > > -
> > > > > > -
> > > > > > def load_pcapfile(filename=""):
> > > > > > pkts = []
> > > > > > try:
> > > > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > > > inst = sniff_packets("lo", timeout=5)
> > > > > > pkt = Packet(pkt_type='UDP')
> > > > > > pkt.send_pkt(tx_port='lo')
> > > > > > - pkts = load_sniff_packets(inst)
> > > > > >
> > > > > > pkt = Packet(pkt_type='UDP', pkt_len=1500,
> > ran_payload=True)
> > > > > > pkt.send_pkt(tx_port='lo') diff --git
> > > > > > a/framework/tester.py b/framework/tester.py index
> > > > > > a775f68..c5b705d 100755
> > > > > > --- a/framework/tester.py
> > > > > > +++ b/framework/tester.py
> > > > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > > > >
> > > > > > import re
> > > > > > import subprocess
> > > > > > +import os
> > > > > > from time import sleep
> > > > > > from settings import NICS, load_global_setting, PERF_SETTING
> > > > > > from crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > > > > > module = __import__("packet")
> > > > > > pkt_c = getattr(module, "Packet")
> > > > > > send_f = getattr(module, "send_packets")
> > > > > > - sniff_f = getattr(module, "sniff_packets")
> > > > > > - load_f = getattr(module, "load_sniff_packets")
> > > > > > compare_f = getattr(module, "compare_pktload")
> > > > > > strip_f = getattr(module, "strip_pktload")
> > > > > > save_f = getattr(module, "save_packets") @@ -606,7
> > > > > > +605,7 @@ class Tester(Crb):
> > > > > >
> > > > > > # send and sniff packets
> > > > > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" %
> > txIntf)
> > > > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > > > timeout=timeout,
> > > > > > filters=
> > > > > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > > > > + count=pktnum, timeout=timeout, filters=
> > > > > > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > > > > > {'layer': 'network', 'config': {'dstport':
> > '65535'}}])
> > > > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@ class
> > > > > > Tester(Crb):
> > > > > > # Verify all packets
> > > > > > prev_id = -1
> > > > > > for txport, rxport in portList:
> > > > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > > > + recv_pkts =
> > > > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > > > >
> > > > > > # only report when recevied number not matched
> > > > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > > > self.proc.kill()
> > > > > > self.proc = None
> > > > > >
> > > > > > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5,
> > > > filters=[]):
> > > > > > + """
> > > > > > + Wrapper for packet module sniff_packets
> > > > > > + """
> > > > > > + # load functions in packet module
> > > > > > + module = __import__("packet")
> > > > > > + sniff_f = getattr(module, "sniff_packets")
> > > > > > +
> > > > > > + target=[]
> > > > > > + target.append(self.get_username())
> > > > > > + target.append(self.get_ip_address())
> > > > > > + target.append(self.get_password())
> > > > > > + return sniff_f(intf, count, timeout, filters, target)
> > > > > > +
> > > > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > > > + """
> > > > > > + Wrapper for packet module load_sniff_pcap
> > > > > > + """
> > > > > > + # load functions in packet module
> > > > > > + module = __import__("packet")
> > > > > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > > > > +
> > > > > > + target=[]
> > > > > > + target.append(self.get_username())
> > > > > > + target.append(self.get_ip_address())
> > > > > > + target.append(self.get_password())
> > > > > > + pcap = load_pcap_f(index, target)
> > > > > > + self.session.copy_file_from(pcap)
> > > > > > +
> > > > > > + return pcap.split(os.sep)[-1]
> > > > > > +
> > > > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > > > + """
> > > > > > + Wrapper for packet module load_pcapfile
> > > > > > + """
> > > > > > + # load functions in packet module
> > > > > > + packet = __import__("packet")
> > > > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > > > +
> > > > > > + return packet.load_pcapfile(file)
> > > > > > +
> > > > > > def kill_all(self, killall=False):
> > > > > > """
> > > > > > Kill all scapy process or DPDK application on tester.
> > > > > > --
> > > > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 7:32 ` Phil Yang (Arm Technology China)
@ 2018-09-21 8:27 ` Tu, Lijuan
2018-09-21 12:05 ` Phil Yang (Arm Technology China)
0 siblings, 1 reply; 124+ messages in thread
From: Tu, Lijuan @ 2018-09-21 8:27 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), Phil, dts; +Cc: nd, Liu, Yong
> -----Original Message-----
> From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> Sent: Friday, September 21, 2018 3:32 PM
> To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> sniffer to specify running machine
>
> tcpdump_sniff_packet and load_tcpdump_sniff_pcap in class Tester will call
> those two functions.
>
> def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> """
> Wrapper for packet module sniff_packets
> """
> # load functions in packet module
> module = __import__("packet")
> sniff_f = getattr(module, "sniff_packets")
>
> target=[]
> target.append(self.get_username())
> target.append(self.get_ip_address())
> target.append(self.get_password())
> return sniff_f(intf, count, timeout, filters, target)
[Lijuan] Here It calls sniff_packets which is in packet.py, but sniff_packets don't use target[2] which means password. If I missed, could you figure out which code would call target[2]?
>
> Please check test.py in this patch.
>
> Thanks,
> Phil Yang
>
> > -----Original Message-----
> > From: Tu, Lijuan <lijuan.tu@intel.com>
> > Sent: Friday, September 21, 2018 3:19 PM
> > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > I am glad we reach an agreement.
> >
> > Of course, the parameter "target" have password, but I found no any
> > function would call it.
> > Only username and ip are used. The target[2] is the password, and is not
> called.
> > + if target:
> > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > + "%s@%s" % (target[0], target[1]),
> > + "tcpdump -h"],
> > + stderr=subprocess.PIPE,
> > + stdout=subprocess.PIPE,
> > + shell=False)
> > Anything I missed?
> >
> >
> > > -----Original Message-----
> > > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > > Sent: Friday, September 21, 2018 2:59 PM
> > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > Yes. I agreed with that.
> > >
> > > I think my patch has also followed this rule.
> > > In the packet.py, I added one more parameter "target" for
> > > sniff_packets and load_sniff_pcap to specify the username and IP
> address.
> > > In the test.py, I passed the Tester's passwd and IP address to these
> > > two functions. Thus, it will make sure sniff packet operation done
> > > on the
> > Tester.
> > >
> > > Thanks,
> > > Phil Yang
> > >
> > > > -----Original Message-----
> > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > Sent: Friday, September 21, 2018 11:42 AM
> > > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > > Phil@dpdk.org; dts@dpdk.org
> > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > packet sniffer to specify running machine
> > > >
> > > > DTS supports either login server by password or utilize authorized
> login.
> > > > For logging by password, we could get some codes like "
> > > > self.session = SSHPexpect(host, username, password, dut_id) " in
> > > > SSHConnection module. and we have ip, username, password
> > > > information in crb.cfg I think we don't want to force user to utilize
> authorized login.
> > > >
> > > > > -----Original Message-----
> > > > > From: Phil Yang (Arm Technology China)
> > > > > [mailto:Phil.Yang@arm.com]
> > > > > Sent: Friday, September 21, 2018 11:22 AM
> > > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org;
> > > > > dts@dpdk.org
> > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > packet sniffer to specify running machine
> > > > >
> > > > > Hi Lijuan,
> > > > >
> > > > > It also need to follow the DTS setup steps in
> > > > >
> https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> > > > >
> > > > > Since you know where are your DUT and Tester, so you can use
> > > > > tool ssh-copy-id to save local available keys on DUT and Tester.
> > > > >
> > > > > Thanks,
> > > > > Phil Yang
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > > Sent: Friday, September 21, 2018 11:09 AM
> > > > > > To: Phil@dpdk.org; dts@dpdk.org
> > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > > (Arm Technology China) <Phil.Yang@arm.com>
> > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > packet sniffer to specify running machine
> > > > > >
> > > > > > One comments, when we ssh to a server, it might request a
> > > > > > password, but we don't handle it.
> > > > > >
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of
> > > > > > > Phil@dpdk.org
> > > > > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > > > > To: dts@dpdk.org
> > > > > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > > > <phil.yang@arm.com>
> > > > > > > Subject: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > > packet sniffer to specify running machine
> > > > > > >
> > > > > > > From: Phil Yang <phil.yang@arm.com>
> > > > > > >
> > > > > > > By default, the Tester is supposed to be the server which
> > > > > > > running DTS and the packet sniff methods are running on it.
> > > > > > > However, if DTS was not running on the Tester and the Tester
> > > > > > > is another remote server, so packet sniff methods cannot
> > > > > > > sniff Tester's packets correctly.
> > > > > > >
> > > > > > > This patch adds support for packet sniff methods to specify
> > > > > > > running machine and implements sniff packet methods in class
> tester.
> > > > > > >
> > > > > > > 1. Add parameter to sniff_packet and load_sniff_pcap methods
> > > > > > > to specify the running machine.
> > > > > > > 2. Remove load_sniff_packets method in packet.py.
> > > > > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > > > > > load_tcpdump_sniff_packets for class tester with the new
> > > > > > > sniff_packet
> > > > > API.
> > > > > > > 4. Update tester.check_random_pkts method with
> > > > > > > tester.tcpdump_sniff_packets and
> > > > > > > tester.load_tcpdump_sniff_packets to make it execution on
> > > > > > > the
> > > Tester.
> > > > > > >
> > > > > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > > > > ---
> > > > > > > framework/packet.py | 86
> > > > > > > +++++++++++++++++++++++++----------------------------
> > > > > > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > > > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > > > > >
> > > > > > > diff --git a/framework/packet.py b/framework/packet.py index
> > > > > > > 976b82b..1f3f07d 100755
> > > > > > > --- a/framework/packet.py
> > > > > > > +++ b/framework/packet.py
> > > > > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > > > > return ""
> > > > > > >
> > > > > > >
> > > > > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > > > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > > > > > """
> > > > > > > sniff all packets for certain port in certain seconds
> > > > > > > """
> > > > > > > param = ""
> > > > > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > > > > - tcpdump_help = subprocess.check_output("tcpdump -h;
> echo
> > > 0",
> > > > > > > -
> > > > > > > stderr=subprocess.STDOUT,
> > > > > > > - shell=True)
> > > > > > > + remote_terminate = 0
> > > > > > > +
> > > > > > > + # target[] contain the remote machine info for ssh
> connection
> > > > > > > + # target[0]: username
> > > > > > > + # target[1]: ip address
> > > > > > > + # target[2]: pass word
> > > > > > > + if target:
> > > > > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > > > > + "%s@%s" % (target[0],
> target[1]),
> > > > > > > + "tcpdump -h"],
> > > > > > > + stderr=subprocess.PIPE,
> > > > > > > + stdout=subprocess.PIPE,
> > > > > > > + shell=False)
> > > > > > [Lijuan] Action will be blocked if SSH need password.
> > > > > > > + tcpdump_help =
> > > > > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > > > > + tcpdump_help_pipe.wait()
> > > > > > > + else:
> > > > > > > + 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:
> > > > > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0,
> > > > > > > timeout=5,
> > > > > > > filters=[]):
> > > > > > > else:
> > > > > > > cmd = sniff_cmd % options
> > > > > > >
> > > > > > > - args = shlex.split(cmd)
> > > > > > > + if target:
> > > > > > > + pipe = subprocess.Popen(['ssh',
> > > > > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > > > > + stdin=subprocess.PIPE,
> > > > > > > + shell=False)
> > > > > > > + remote_terminate = 1
> > > > > > > + else:
> > > > > > > + args = shlex.split(cmd)
> > > > > > > + pipe = subprocess.Popen(args)
> > > > > > >
> > > > > > > - pipe = subprocess.Popen(args)
> > > > > > > index = str(time.time())
> > > > > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > > > > + SNIFF_PIDS[index] = (pipe, intf, timeout,
> > > > > > > + remote_terminate)
> > > > > > > time.sleep(1)
> > > > > > > return index
> > > > > > >
> > > > > > >
> > > > > > > -def load_sniff_pcap(index=''):
> > > > > > > +def load_sniff_pcap(index='', target=[]):
> > > > > > > """
> > > > > > > Stop sniffer and return pcap file
> > > > > > > """
> > > > > > > child_exit = False
> > > > > > > if index in SNIFF_PIDS.keys():
> > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > + pipe, intf, timeout, remote_terminate =
> > > > > > > + SNIFF_PIDS[index]
> > > > > > > time_elapse = int(time.time() - float(index))
> > > > > > > while time_elapse < timeout:
> > > > > > > if pipe.poll() is not None:
> > > > > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > > > > time_elapse += 1
> > > > > > >
> > > > > > > if not child_exit:
> > > > > > > + if remote_terminate == 1:
> > > > > > > + stop_tcpdump_pipe =
> subprocess.Popen(['ssh',
> > > > > > > + '%s@%s' %
> (target[0],
> > > > > > > target[1]),
> > > > > > > + 'kill -2 $(pidof
> > > tcpdump)'],
> > > > > > > +
> stderr=subprocess.PIPE,
> > > > > > > + shell=False)
> > > > > > > + stop_tcpdump_pipe.wait()
> > > > > > > +
> > > > > > > pipe.send_signal(signal.SIGINT)
> > > > > > > pipe.wait()
> > > > > > >
> > > > > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > > > > return ""
> > > > > > >
> > > > > > >
> > > > > > > -def load_sniff_packets(index=''):
> > > > > > > - """
> > > > > > > - Stop sniffer and return packet objects
> > > > > > > - """
> > > > > > > - pkts = []
> > > > > > > - child_exit = False
> > > > > > > - if index in SNIFF_PIDS.keys():
> > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > - time_elapse = int(time.time() - float(index))
> > > > > > > - while time_elapse < timeout:
> > > > > > > - if pipe.poll() is not None:
> > > > > > > - child_exit = True
> > > > > > > - break
> > > > > > > -
> > > > > > > - time.sleep(1)
> > > > > > > - time_elapse += 1
> > > > > > > -
> > > > > > > - if not child_exit:
> > > > > > > - pipe.send_signal(signal.SIGINT)
> > > > > > > - pipe.wait()
> > > > > > > -
> > > > > > > - # wait pcap file ready
> > > > > > > - time.sleep(1)
> > > > > > > - try:
> > > > > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > > > > > - for pkt in cap_pkts:
> > > > > > > - # packet gen should be scapy
> > > > > > > - packet = Packet(tx_port=intf)
> > > > > > > - packet.pktgen.assign_pkt(pkt)
> > > > > > > - pkts.append(packet)
> > > > > > > - except:
> > > > > > > - pass
> > > > > > > -
> > > > > > > - return pkts
> > > > > > > -
> > > > > > > -
> > > > > > > def load_pcapfile(filename=""):
> > > > > > > pkts = []
> > > > > > > try:
> > > > > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > > > > inst = sniff_packets("lo", timeout=5)
> > > > > > > pkt = Packet(pkt_type='UDP')
> > > > > > > pkt.send_pkt(tx_port='lo')
> > > > > > > - pkts = load_sniff_packets(inst)
> > > > > > >
> > > > > > > pkt = Packet(pkt_type='UDP', pkt_len=1500,
> > > ran_payload=True)
> > > > > > > pkt.send_pkt(tx_port='lo') diff --git
> > > > > > > a/framework/tester.py b/framework/tester.py index
> > > > > > > a775f68..c5b705d 100755
> > > > > > > --- a/framework/tester.py
> > > > > > > +++ b/framework/tester.py
> > > > > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > > > > >
> > > > > > > import re
> > > > > > > import subprocess
> > > > > > > +import os
> > > > > > > from time import sleep
> > > > > > > from settings import NICS, load_global_setting,
> > > > > > > PERF_SETTING from crb import Crb @@ -560,8 +561,6 @@ class
> Tester(Crb):
> > > > > > > module = __import__("packet")
> > > > > > > pkt_c = getattr(module, "Packet")
> > > > > > > send_f = getattr(module, "send_packets")
> > > > > > > - sniff_f = getattr(module, "sniff_packets")
> > > > > > > - load_f = getattr(module, "load_sniff_packets")
> > > > > > > compare_f = getattr(module, "compare_pktload")
> > > > > > > strip_f = getattr(module, "strip_pktload")
> > > > > > > save_f = getattr(module, "save_packets") @@ -606,7
> > > > > > > +605,7 @@ class Tester(Crb):
> > > > > > >
> > > > > > > # send and sniff packets
> > > > > > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" %
> > > txIntf)
> > > > > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > > > > timeout=timeout,
> > > > > > > filters=
> > > > > > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > > > > > + count=pktnum, timeout=timeout, filters=
> > > > > > > [{'layer': 'network', 'config': {'srcport':
> '65535'}},
> > > > > > > {'layer': 'network', 'config': {'dstport':
> > > '65535'}}])
> > > > > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@
> > > > > > > class
> > > > > > > Tester(Crb):
> > > > > > > # Verify all packets
> > > > > > > prev_id = -1
> > > > > > > for txport, rxport in portList:
> > > > > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > > > > + recv_pkts =
> > > > > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > > > > >
> > > > > > > # only report when recevied number not matched
> > > > > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > > > > self.proc.kill()
> > > > > > > self.proc = None
> > > > > > >
> > > > > > > + def tcpdump_sniff_packets(self, intf, count=0,
> > > > > > > + timeout=5,
> > > > > filters=[]):
> > > > > > > + """
> > > > > > > + Wrapper for packet module sniff_packets
> > > > > > > + """
> > > > > > > + # load functions in packet module
> > > > > > > + module = __import__("packet")
> > > > > > > + sniff_f = getattr(module, "sniff_packets")
> > > > > > > +
> > > > > > > + target=[]
> > > > > > > + target.append(self.get_username())
> > > > > > > + target.append(self.get_ip_address())
> > > > > > > + target.append(self.get_password())
> > > > > > > + return sniff_f(intf, count, timeout, filters,
> > > > > > > + target)
> > > > > > > +
> > > > > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > > > > + """
> > > > > > > + Wrapper for packet module load_sniff_pcap
> > > > > > > + """
> > > > > > > + # load functions in packet module
> > > > > > > + module = __import__("packet")
> > > > > > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > > > > > +
> > > > > > > + target=[]
> > > > > > > + target.append(self.get_username())
> > > > > > > + target.append(self.get_ip_address())
> > > > > > > + target.append(self.get_password())
> > > > > > > + pcap = load_pcap_f(index, target)
> > > > > > > + self.session.copy_file_from(pcap)
> > > > > > > +
> > > > > > > + return pcap.split(os.sep)[-1]
> > > > > > > +
> > > > > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > > > > + """
> > > > > > > + Wrapper for packet module load_pcapfile
> > > > > > > + """
> > > > > > > + # load functions in packet module
> > > > > > > + packet = __import__("packet")
> > > > > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > > > > +
> > > > > > > + return packet.load_pcapfile(file)
> > > > > > > +
> > > > > > > def kill_all(self, killall=False):
> > > > > > > """
> > > > > > > Kill all scapy process or DPDK application on tester.
> > > > > > > --
> > > > > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 8:27 ` Tu, Lijuan
@ 2018-09-21 12:05 ` Phil Yang (Arm Technology China)
2018-09-26 5:15 ` Tu, Lijuan
0 siblings, 1 reply; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-09-21 12:05 UTC (permalink / raw)
To: Tu, Lijuan, Phil, dts; +Cc: nd, Liu, Yong
Hi Lijuan,
Yes, you are right.
I am thinking about pass the password through pipe.communication() when creating popen ssh connection, such like:
tcpdump_help = "".join(tuple(tcpdump_help_pipe.communicate(input=target[2])))
Any other suggestion for this? If you agree with this approach I can re-spin the patch.
Thanks,
Phil Yang
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Friday, September 21, 2018 4:28 PM
> To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; Phil@dpdk.org;
> dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to
> specify running machine
>
>
>
> > -----Original Message-----
> > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > Sent: Friday, September 21, 2018 3:32 PM
> > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> > tcpdump_sniff_packet and load_tcpdump_sniff_pcap in class Tester will
> > call those two functions.
> >
> > def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> > """
> > Wrapper for packet module sniff_packets
> > """
> > # load functions in packet module
> > module = __import__("packet")
> > sniff_f = getattr(module, "sniff_packets")
> >
> > target=[]
> > target.append(self.get_username())
> > target.append(self.get_ip_address())
> > target.append(self.get_password())
> > return sniff_f(intf, count, timeout, filters, target)
> [Lijuan] Here It calls sniff_packets which is in packet.py, but sniff_packets don't
> use target[2] which means password. If I missed, could you figure out which
> code would call target[2]?
> >
> > Please check test.py in this patch.
> >
> > Thanks,
> > Phil Yang
> >
> > > -----Original Message-----
> > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > Sent: Friday, September 21, 2018 3:19 PM
> > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > I am glad we reach an agreement.
> > >
> > > Of course, the parameter "target" have password, but I found no any
> > > function would call it.
> > > Only username and ip are used. The target[2] is the password, and is
> > > not
> > called.
> > > + if target:
> > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > + "%s@%s" % (target[0], target[1]),
> > > + "tcpdump -h"],
> > > + stderr=subprocess.PIPE,
> > > + stdout=subprocess.PIPE,
> > > + shell=False)
> > > Anything I missed?
> > >
> > >
> > > > -----Original Message-----
> > > > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > > > Sent: Friday, September 21, 2018 2:59 PM
> > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > packet sniffer to specify running machine
> > > >
> > > > Yes. I agreed with that.
> > > >
> > > > I think my patch has also followed this rule.
> > > > In the packet.py, I added one more parameter "target" for
> > > > sniff_packets and load_sniff_pcap to specify the username and IP
> > address.
> > > > In the test.py, I passed the Tester's passwd and IP address to
> > > > these two functions. Thus, it will make sure sniff packet
> > > > operation done on the
> > > Tester.
> > > >
> > > > Thanks,
> > > > Phil Yang
> > > >
> > > > > -----Original Message-----
> > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > Sent: Friday, September 21, 2018 11:42 AM
> > > > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > > > Phil@dpdk.org; dts@dpdk.org
> > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > packet sniffer to specify running machine
> > > > >
> > > > > DTS supports either login server by password or utilize
> > > > > authorized
> > login.
> > > > > For logging by password, we could get some codes like "
> > > > > self.session = SSHPexpect(host, username, password, dut_id) " in
> > > > > SSHConnection module. and we have ip, username, password
> > > > > information in crb.cfg I think we don't want to force user to
> > > > > utilize
> > authorized login.
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Phil Yang (Arm Technology China)
> > > > > > [mailto:Phil.Yang@arm.com]
> > > > > > Sent: Friday, September 21, 2018 11:22 AM
> > > > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org;
> > > > > > dts@dpdk.org
> > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > packet sniffer to specify running machine
> > > > > >
> > > > > > Hi Lijuan,
> > > > > >
> > > > > > It also need to follow the DTS setup steps in
> > > > > >
> > https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> > > > > >
> > > > > > Since you know where are your DUT and Tester, so you can use
> > > > > > tool ssh-copy-id to save local available keys on DUT and Tester.
> > > > > >
> > > > > > Thanks,
> > > > > > Phil Yang
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > > > Sent: Friday, September 21, 2018 11:09 AM
> > > > > > > To: Phil@dpdk.org; dts@dpdk.org
> > > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil
> > > > > > > Yang (Arm Technology China) <Phil.Yang@arm.com>
> > > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet:
> > > > > > > support packet sniffer to specify running machine
> > > > > > >
> > > > > > > One comments, when we ssh to a server, it might request a
> > > > > > > password, but we don't handle it.
> > > > > > >
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of
> > > > > > > > Phil@dpdk.org
> > > > > > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > > > > > To: dts@dpdk.org
> > > > > > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil Yang
> > > > > > > > <phil.yang@arm.com>
> > > > > > > > Subject: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > > > packet sniffer to specify running machine
> > > > > > > >
> > > > > > > > From: Phil Yang <phil.yang@arm.com>
> > > > > > > >
> > > > > > > > By default, the Tester is supposed to be the server which
> > > > > > > > running DTS and the packet sniff methods are running on it.
> > > > > > > > However, if DTS was not running on the Tester and the
> > > > > > > > Tester is another remote server, so packet sniff methods
> > > > > > > > cannot sniff Tester's packets correctly.
> > > > > > > >
> > > > > > > > This patch adds support for packet sniff methods to
> > > > > > > > specify running machine and implements sniff packet
> > > > > > > > methods in class
> > tester.
> > > > > > > >
> > > > > > > > 1. Add parameter to sniff_packet and load_sniff_pcap
> > > > > > > > methods to specify the running machine.
> > > > > > > > 2. Remove load_sniff_packets method in packet.py.
> > > > > > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > > > > > > load_tcpdump_sniff_packets for class tester with the new
> > > > > > > > sniff_packet
> > > > > > API.
> > > > > > > > 4. Update tester.check_random_pkts method with
> > > > > > > > tester.tcpdump_sniff_packets and
> > > > > > > > tester.load_tcpdump_sniff_packets to make it execution on
> > > > > > > > the
> > > > Tester.
> > > > > > > >
> > > > > > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > > > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > > > > > ---
> > > > > > > > framework/packet.py | 86
> > > > > > > > +++++++++++++++++++++++++----------------------------
> > > > > > > > framework/tester.py | 48 +++++++++++++++++++++++++++---
> > > > > > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > > > > > >
> > > > > > > > diff --git a/framework/packet.py b/framework/packet.py
> > > > > > > > index 976b82b..1f3f07d 100755
> > > > > > > > --- a/framework/packet.py
> > > > > > > > +++ b/framework/packet.py
> > > > > > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > > > > > return ""
> > > > > > > >
> > > > > > > >
> > > > > > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > > > > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > > > > > > """
> > > > > > > > sniff all packets for certain port in certain seconds
> > > > > > > > """
> > > > > > > > param = ""
> > > > > > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > > > > > - tcpdump_help = subprocess.check_output("tcpdump -h;
> > echo
> > > > 0",
> > > > > > > > -
> > > > > > > > stderr=subprocess.STDOUT,
> > > > > > > > - shell=True)
> > > > > > > > + remote_terminate = 0
> > > > > > > > +
> > > > > > > > + # target[] contain the remote machine info for ssh
> > connection
> > > > > > > > + # target[0]: username
> > > > > > > > + # target[1]: ip address
> > > > > > > > + # target[2]: pass word
> > > > > > > > + if target:
> > > > > > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > > > > > + "%s@%s" % (target[0],
> > target[1]),
> > > > > > > > + "tcpdump -h"],
> > > > > > > > + stderr=subprocess.PIPE,
> > > > > > > > + stdout=subprocess.PIPE,
> > > > > > > > + shell=False)
> > > > > > > [Lijuan] Action will be blocked if SSH need password.
> > > > > > > > + tcpdump_help =
> > > > > > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > > > > > + tcpdump_help_pipe.wait()
> > > > > > > > + else:
> > > > > > > > + 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:
> > > > > > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0,
> > > > > > > > timeout=5,
> > > > > > > > filters=[]):
> > > > > > > > else:
> > > > > > > > cmd = sniff_cmd % options
> > > > > > > >
> > > > > > > > - args = shlex.split(cmd)
> > > > > > > > + if target:
> > > > > > > > + pipe = subprocess.Popen(['ssh',
> > > > > > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > > > > > + stdin=subprocess.PIPE,
> > > > > > > > + shell=False)
> > > > > > > > + remote_terminate = 1
> > > > > > > > + else:
> > > > > > > > + args = shlex.split(cmd)
> > > > > > > > + pipe = subprocess.Popen(args)
> > > > > > > >
> > > > > > > > - pipe = subprocess.Popen(args)
> > > > > > > > index = str(time.time())
> > > > > > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > > > > > + SNIFF_PIDS[index] = (pipe, intf, timeout,
> > > > > > > > + remote_terminate)
> > > > > > > > time.sleep(1)
> > > > > > > > return index
> > > > > > > >
> > > > > > > >
> > > > > > > > -def load_sniff_pcap(index=''):
> > > > > > > > +def load_sniff_pcap(index='', target=[]):
> > > > > > > > """
> > > > > > > > Stop sniffer and return pcap file
> > > > > > > > """
> > > > > > > > child_exit = False
> > > > > > > > if index in SNIFF_PIDS.keys():
> > > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > > + pipe, intf, timeout, remote_terminate =
> > > > > > > > + SNIFF_PIDS[index]
> > > > > > > > time_elapse = int(time.time() - float(index))
> > > > > > > > while time_elapse < timeout:
> > > > > > > > if pipe.poll() is not None:
> > > > > > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > > > > > time_elapse += 1
> > > > > > > >
> > > > > > > > if not child_exit:
> > > > > > > > + if remote_terminate == 1:
> > > > > > > > + stop_tcpdump_pipe =
> > subprocess.Popen(['ssh',
> > > > > > > > + '%s@%s' %
> > (target[0],
> > > > > > > > target[1]),
> > > > > > > > + 'kill -2 $(pidof
> > > > tcpdump)'],
> > > > > > > > +
> > stderr=subprocess.PIPE,
> > > > > > > > + shell=False)
> > > > > > > > + stop_tcpdump_pipe.wait()
> > > > > > > > +
> > > > > > > > pipe.send_signal(signal.SIGINT)
> > > > > > > > pipe.wait()
> > > > > > > >
> > > > > > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > > > > > return ""
> > > > > > > >
> > > > > > > >
> > > > > > > > -def load_sniff_packets(index=''):
> > > > > > > > - """
> > > > > > > > - Stop sniffer and return packet objects
> > > > > > > > - """
> > > > > > > > - pkts = []
> > > > > > > > - child_exit = False
> > > > > > > > - if index in SNIFF_PIDS.keys():
> > > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > > - time_elapse = int(time.time() - float(index))
> > > > > > > > - while time_elapse < timeout:
> > > > > > > > - if pipe.poll() is not None:
> > > > > > > > - child_exit = True
> > > > > > > > - break
> > > > > > > > -
> > > > > > > > - time.sleep(1)
> > > > > > > > - time_elapse += 1
> > > > > > > > -
> > > > > > > > - if not child_exit:
> > > > > > > > - pipe.send_signal(signal.SIGINT)
> > > > > > > > - pipe.wait()
> > > > > > > > -
> > > > > > > > - # wait pcap file ready
> > > > > > > > - time.sleep(1)
> > > > > > > > - try:
> > > > > > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > > > > > > - for pkt in cap_pkts:
> > > > > > > > - # packet gen should be scapy
> > > > > > > > - packet = Packet(tx_port=intf)
> > > > > > > > - packet.pktgen.assign_pkt(pkt)
> > > > > > > > - pkts.append(packet)
> > > > > > > > - except:
> > > > > > > > - pass
> > > > > > > > -
> > > > > > > > - return pkts
> > > > > > > > -
> > > > > > > > -
> > > > > > > > def load_pcapfile(filename=""):
> > > > > > > > pkts = []
> > > > > > > > try:
> > > > > > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > > > > > inst = sniff_packets("lo", timeout=5)
> > > > > > > > pkt = Packet(pkt_type='UDP')
> > > > > > > > pkt.send_pkt(tx_port='lo')
> > > > > > > > - pkts = load_sniff_packets(inst)
> > > > > > > >
> > > > > > > > pkt = Packet(pkt_type='UDP', pkt_len=1500,
> > > > ran_payload=True)
> > > > > > > > pkt.send_pkt(tx_port='lo') diff --git
> > > > > > > > a/framework/tester.py b/framework/tester.py index
> > > > > > > > a775f68..c5b705d 100755
> > > > > > > > --- a/framework/tester.py
> > > > > > > > +++ b/framework/tester.py
> > > > > > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > > > > > >
> > > > > > > > import re
> > > > > > > > import subprocess
> > > > > > > > +import os
> > > > > > > > from time import sleep
> > > > > > > > from settings import NICS, load_global_setting,
> > > > > > > > PERF_SETTING from crb import Crb @@ -560,8 +561,6 @@ class
> > Tester(Crb):
> > > > > > > > module = __import__("packet")
> > > > > > > > pkt_c = getattr(module, "Packet")
> > > > > > > > send_f = getattr(module, "send_packets")
> > > > > > > > - sniff_f = getattr(module, "sniff_packets")
> > > > > > > > - load_f = getattr(module, "load_sniff_packets")
> > > > > > > > compare_f = getattr(module, "compare_pktload")
> > > > > > > > strip_f = getattr(module, "strip_pktload")
> > > > > > > > save_f = getattr(module, "save_packets") @@
> > > > > > > > -606,7
> > > > > > > > +605,7 @@ class Tester(Crb):
> > > > > > > >
> > > > > > > > # send and sniff packets
> > > > > > > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap"
> > > > > > > > %
> > > > txIntf)
> > > > > > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > > > > > timeout=timeout,
> > > > > > > > filters=
> > > > > > > > + inst =
> > > > > > > > + self.tcpdump_sniff_packets(intf=rxIntf,
> > > > > > > > + count=pktnum, timeout=timeout, filters=
> > > > > > > > [{'layer': 'network', 'config': {'srcport':
> > '65535'}},
> > > > > > > > {'layer': 'network', 'config': {'dstport':
> > > > '65535'}}])
> > > > > > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@
> > > > > > > > class
> > > > > > > > Tester(Crb):
> > > > > > > > # Verify all packets
> > > > > > > > prev_id = -1
> > > > > > > > for txport, rxport in portList:
> > > > > > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > > > > > + recv_pkts =
> > > > > > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > > > > > >
> > > > > > > > # only report when recevied number not matched
> > > > > > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > > > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > > > > > self.proc.kill()
> > > > > > > > self.proc = None
> > > > > > > >
> > > > > > > > + def tcpdump_sniff_packets(self, intf, count=0,
> > > > > > > > + timeout=5,
> > > > > > filters=[]):
> > > > > > > > + """
> > > > > > > > + Wrapper for packet module sniff_packets
> > > > > > > > + """
> > > > > > > > + # load functions in packet module
> > > > > > > > + module = __import__("packet")
> > > > > > > > + sniff_f = getattr(module, "sniff_packets")
> > > > > > > > +
> > > > > > > > + target=[]
> > > > > > > > + target.append(self.get_username())
> > > > > > > > + target.append(self.get_ip_address())
> > > > > > > > + target.append(self.get_password())
> > > > > > > > + return sniff_f(intf, count, timeout, filters,
> > > > > > > > + target)
> > > > > > > > +
> > > > > > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > > > > > + """
> > > > > > > > + Wrapper for packet module load_sniff_pcap
> > > > > > > > + """
> > > > > > > > + # load functions in packet module
> > > > > > > > + module = __import__("packet")
> > > > > > > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > > > > > > +
> > > > > > > > + target=[]
> > > > > > > > + target.append(self.get_username())
> > > > > > > > + target.append(self.get_ip_address())
> > > > > > > > + target.append(self.get_password())
> > > > > > > > + pcap = load_pcap_f(index, target)
> > > > > > > > + self.session.copy_file_from(pcap)
> > > > > > > > +
> > > > > > > > + return pcap.split(os.sep)[-1]
> > > > > > > > +
> > > > > > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > > > > > + """
> > > > > > > > + Wrapper for packet module load_pcapfile
> > > > > > > > + """
> > > > > > > > + # load functions in packet module
> > > > > > > > + packet = __import__("packet")
> > > > > > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > > > > > +
> > > > > > > > + return packet.load_pcapfile(file)
> > > > > > > > +
> > > > > > > > def kill_all(self, killall=False):
> > > > > > > > """
> > > > > > > > Kill all scapy process or DPDK application on tester.
> > > > > > > > --
> > > > > > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-21 12:05 ` Phil Yang (Arm Technology China)
@ 2018-09-26 5:15 ` Tu, Lijuan
0 siblings, 0 replies; 124+ messages in thread
From: Tu, Lijuan @ 2018-09-26 5:15 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), Phil, dts; +Cc: nd, Liu, Yong
It seems not work out for me, I tried communicate method, it still stops at the password prompt.
Another idea, we can create a new ssh session to handle the sniff thing. I think this is more convenience to handle the remote thing. It just like bash command.
session_sniff=self.create_session()
session_sniff.send_expect("tcpdump -h")
session_sniff.send_expect("cmd", "#")
self.destroy_session(session_sniff)
> -----Original Message-----
> From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> Sent: Friday, September 21, 2018 8:06 PM
> To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> sniffer to specify running machine
>
> Hi Lijuan,
>
> Yes, you are right.
>
> I am thinking about pass the password through pipe.communication() when
> creating popen ssh connection, such like:
> tcpdump_help =
> "".join(tuple(tcpdump_help_pipe.communicate(input=target[2])))
>
> Any other suggestion for this? If you agree with this approach I can re-spin
> the patch.
>
> Thanks,
> Phil Yang
>
> > -----Original Message-----
> > From: Tu, Lijuan <lijuan.tu@intel.com>
> > Sent: Friday, September 21, 2018 4:28 PM
> > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > Phil@dpdk.org; dts@dpdk.org
> > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > sniffer to specify running machine
> >
> >
> >
> > > -----Original Message-----
> > > From: Phil Yang (Arm Technology China) [mailto:Phil.Yang@arm.com]
> > > Sent: Friday, September 21, 2018 3:32 PM
> > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org; dts@dpdk.org
> > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support packet
> > > sniffer to specify running machine
> > >
> > > tcpdump_sniff_packet and load_tcpdump_sniff_pcap in class Tester
> > > will call those two functions.
> > >
> > > def tcpdump_sniff_packets(self, intf, count=0, timeout=5,
> filters=[]):
> > > """
> > > Wrapper for packet module sniff_packets
> > > """
> > > # load functions in packet module
> > > module = __import__("packet")
> > > sniff_f = getattr(module, "sniff_packets")
> > >
> > > target=[]
> > > target.append(self.get_username())
> > > target.append(self.get_ip_address())
> > > target.append(self.get_password())
> > > return sniff_f(intf, count, timeout, filters, target)
> > [Lijuan] Here It calls sniff_packets which is in packet.py, but
> > sniff_packets don't use target[2] which means password. If I missed,
> > could you figure out which code would call target[2]?
> > >
> > > Please check test.py in this patch.
> > >
> > > Thanks,
> > > Phil Yang
> > >
> > > > -----Original Message-----
> > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > Sent: Friday, September 21, 2018 3:19 PM
> > > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > > Phil@dpdk.org; dts@dpdk.org
> > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > packet sniffer to specify running machine
> > > >
> > > > I am glad we reach an agreement.
> > > >
> > > > Of course, the parameter "target" have password, but I found no
> > > > any function would call it.
> > > > Only username and ip are used. The target[2] is the password, and
> > > > is not
> > > called.
> > > > + if target:
> > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > + "%s@%s" % (target[0], target[1]),
> > > > + "tcpdump -h"],
> > > > + stderr=subprocess.PIPE,
> > > > + stdout=subprocess.PIPE,
> > > > + shell=False)
> > > > Anything I missed?
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Phil Yang (Arm Technology China)
> > > > > [mailto:Phil.Yang@arm.com]
> > > > > Sent: Friday, September 21, 2018 2:59 PM
> > > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org;
> > > > > dts@dpdk.org
> > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > packet sniffer to specify running machine
> > > > >
> > > > > Yes. I agreed with that.
> > > > >
> > > > > I think my patch has also followed this rule.
> > > > > In the packet.py, I added one more parameter "target" for
> > > > > sniff_packets and load_sniff_pcap to specify the username and IP
> > > address.
> > > > > In the test.py, I passed the Tester's passwd and IP address to
> > > > > these two functions. Thus, it will make sure sniff packet
> > > > > operation done on the
> > > > Tester.
> > > > >
> > > > > Thanks,
> > > > > Phil Yang
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > > Sent: Friday, September 21, 2018 11:42 AM
> > > > > > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>;
> > > > > > Phil@dpdk.org; dts@dpdk.org
> > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet: support
> > > > > > packet sniffer to specify running machine
> > > > > >
> > > > > > DTS supports either login server by password or utilize
> > > > > > authorized
> > > login.
> > > > > > For logging by password, we could get some codes like "
> > > > > > self.session = SSHPexpect(host, username, password, dut_id) "
> > > > > > in SSHConnection module. and we have ip, username, password
> > > > > > information in crb.cfg I think we don't want to force user to
> > > > > > utilize
> > > authorized login.
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Phil Yang (Arm Technology China)
> > > > > > > [mailto:Phil.Yang@arm.com]
> > > > > > > Sent: Friday, September 21, 2018 11:22 AM
> > > > > > > To: Tu, Lijuan <lijuan.tu@intel.com>; Phil@dpdk.org;
> > > > > > > dts@dpdk.org
> > > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>
> > > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet:
> > > > > > > support packet sniffer to specify running machine
> > > > > > >
> > > > > > > Hi Lijuan,
> > > > > > >
> > > > > > > It also need to follow the DTS setup steps in
> > > > > > >
> > > https://doc.dpdk.org/dts/gsg/sys_reqs.html#authorized-login-session .
> > > > > > >
> > > > > > > Since you know where are your DUT and Tester, so you can use
> > > > > > > tool ssh-copy-id to save local available keys on DUT and Tester.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Phil Yang
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: Tu, Lijuan <lijuan.tu@intel.com>
> > > > > > > > Sent: Friday, September 21, 2018 11:09 AM
> > > > > > > > To: Phil@dpdk.org; dts@dpdk.org
> > > > > > > > Cc: nd <nd@arm.com>; Liu, Yong <yong.liu@intel.com>; Phil
> > > > > > > > Yang (Arm Technology China) <Phil.Yang@arm.com>
> > > > > > > > Subject: RE: [dts] [PATCH v5 01/22] framework/packet:
> > > > > > > > support packet sniffer to specify running machine
> > > > > > > >
> > > > > > > > One comments, when we ssh to a server, it might request a
> > > > > > > > password, but we don't handle it.
> > > > > > > >
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of
> > > > > > > > > Phil@dpdk.org
> > > > > > > > > Sent: Tuesday, September 4, 2018 4:26 PM
> > > > > > > > > To: dts@dpdk.org
> > > > > > > > > Cc: nd@arm.com; Liu, Yong <yong.liu@intel.com>; Phil
> > > > > > > > > Yang <phil.yang@arm.com>
> > > > > > > > > Subject: [dts] [PATCH v5 01/22] framework/packet:
> > > > > > > > > support packet sniffer to specify running machine
> > > > > > > > >
> > > > > > > > > From: Phil Yang <phil.yang@arm.com>
> > > > > > > > >
> > > > > > > > > By default, the Tester is supposed to be the server
> > > > > > > > > which running DTS and the packet sniff methods are running
> on it.
> > > > > > > > > However, if DTS was not running on the Tester and the
> > > > > > > > > Tester is another remote server, so packet sniff methods
> > > > > > > > > cannot sniff Tester's packets correctly.
> > > > > > > > >
> > > > > > > > > This patch adds support for packet sniff methods to
> > > > > > > > > specify running machine and implements sniff packet
> > > > > > > > > methods in class
> > > tester.
> > > > > > > > >
> > > > > > > > > 1. Add parameter to sniff_packet and load_sniff_pcap
> > > > > > > > > methods to specify the running machine.
> > > > > > > > > 2. Remove load_sniff_packets method in packet.py.
> > > > > > > > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap
> > > > > > > > > and load_tcpdump_sniff_packets for class tester with the
> > > > > > > > > new sniff_packet
> > > > > > > API.
> > > > > > > > > 4. Update tester.check_random_pkts method with
> > > > > > > > > tester.tcpdump_sniff_packets and
> > > > > > > > > tester.load_tcpdump_sniff_packets to make it execution
> > > > > > > > > on the
> > > > > Tester.
> > > > > > > > >
> > > > > > > > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > > > > > > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > > > > > > > ---
> > > > > > > > > framework/packet.py | 86
> > > > > > > > > +++++++++++++++++++++++++----------------------------
> > > > > > > > > framework/tester.py | 48
> +++++++++++++++++++++++++++---
> > > > > > > > > 2 files changed, 84 insertions(+), 50 deletions(-)
> > > > > > > > >
> > > > > > > > > diff --git a/framework/packet.py b/framework/packet.py
> > > > > > > > > index 976b82b..1f3f07d 100755
> > > > > > > > > --- a/framework/packet.py
> > > > > > > > > +++ b/framework/packet.py
> > > > > > > > > @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> > > > > > > > > return ""
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > > > > > > > +def sniff_packets(intf, count=0, timeout=5, filters=[],
> target=[]):
> > > > > > > > > """
> > > > > > > > > sniff all packets for certain port in certain seconds
> > > > > > > > > """
> > > > > > > > > param = ""
> > > > > > > > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > > > > > > > - tcpdump_help = subprocess.check_output("tcpdump -h;
> > > echo
> > > > > 0",
> > > > > > > > > -
> > > > > > > > > stderr=subprocess.STDOUT,
> > > > > > > > > -
> shell=True)
> > > > > > > > > + remote_terminate = 0
> > > > > > > > > +
> > > > > > > > > + # target[] contain the remote machine info for ssh
> > > connection
> > > > > > > > > + # target[0]: username
> > > > > > > > > + # target[1]: ip address
> > > > > > > > > + # target[2]: pass word
> > > > > > > > > + if target:
> > > > > > > > > + tcpdump_help_pipe = subprocess.Popen(["ssh",
> > > > > > > > > + "%s@%s" % (target[0],
> > > target[1]),
> > > > > > > > > + "tcpdump -h"],
> > > > > > > > > + stderr=subprocess.PIPE,
> > > > > > > > > + stdout=subprocess.PIPE,
> > > > > > > > > + shell=False)
> > > > > > > > [Lijuan] Action will be blocked if SSH need password.
> > > > > > > > > + tcpdump_help =
> > > > > > > > > "".join(tuple(tcpdump_help_pipe.communicate()))
> > > > > > > > > + tcpdump_help_pipe.wait()
> > > > > > > > > + else:
> > > > > > > > > + 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:
> > > > > > > > > @@ -850,22 +866,29 @@ def sniff_packets(intf, count=0,
> > > > > > > > > timeout=5,
> > > > > > > > > filters=[]):
> > > > > > > > > else:
> > > > > > > > > cmd = sniff_cmd % options
> > > > > > > > >
> > > > > > > > > - args = shlex.split(cmd)
> > > > > > > > > + if target:
> > > > > > > > > + pipe = subprocess.Popen(['ssh',
> > > > > > > > > + '%s@%s' % (target[0], target[1]), cmd],
> > > > > > > > > + stdin=subprocess.PIPE,
> > > > > > > > > + shell=False)
> > > > > > > > > + remote_terminate = 1
> > > > > > > > > + else:
> > > > > > > > > + args = shlex.split(cmd)
> > > > > > > > > + pipe = subprocess.Popen(args)
> > > > > > > > >
> > > > > > > > > - pipe = subprocess.Popen(args)
> > > > > > > > > index = str(time.time())
> > > > > > > > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > > > > > > > + SNIFF_PIDS[index] = (pipe, intf, timeout,
> > > > > > > > > + remote_terminate)
> > > > > > > > > time.sleep(1)
> > > > > > > > > return index
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -def load_sniff_pcap(index=''):
> > > > > > > > > +def load_sniff_pcap(index='', target=[]):
> > > > > > > > > """
> > > > > > > > > Stop sniffer and return pcap file
> > > > > > > > > """
> > > > > > > > > child_exit = False
> > > > > > > > > if index in SNIFF_PIDS.keys():
> > > > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > > > + pipe, intf, timeout, remote_terminate =
> > > > > > > > > + SNIFF_PIDS[index]
> > > > > > > > > time_elapse = int(time.time() - float(index))
> > > > > > > > > while time_elapse < timeout:
> > > > > > > > > if pipe.poll() is not None:
> > > > > > > > > @@ -876,6 +899,14 @@ def load_sniff_pcap(index=''):
> > > > > > > > > time_elapse += 1
> > > > > > > > >
> > > > > > > > > if not child_exit:
> > > > > > > > > + if remote_terminate == 1:
> > > > > > > > > + stop_tcpdump_pipe =
> > > subprocess.Popen(['ssh',
> > > > > > > > > + '%s@%s' %
> > > (target[0],
> > > > > > > > > target[1]),
> > > > > > > > > + 'kill -2 $(pidof
> > > > > tcpdump)'],
> > > > > > > > > +
> > > stderr=subprocess.PIPE,
> > > > > > > > > + shell=False)
> > > > > > > > > + stop_tcpdump_pipe.wait()
> > > > > > > > > +
> > > > > > > > > pipe.send_signal(signal.SIGINT)
> > > > > > > > > pipe.wait()
> > > > > > > > >
> > > > > > > > > @@ -886,42 +917,6 @@ def load_sniff_pcap(index=''):
> > > > > > > > > return ""
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -def load_sniff_packets(index=''):
> > > > > > > > > - """
> > > > > > > > > - Stop sniffer and return packet objects
> > > > > > > > > - """
> > > > > > > > > - pkts = []
> > > > > > > > > - child_exit = False
> > > > > > > > > - if index in SNIFF_PIDS.keys():
> > > > > > > > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > > > > > > > - time_elapse = int(time.time() - float(index))
> > > > > > > > > - while time_elapse < timeout:
> > > > > > > > > - if pipe.poll() is not None:
> > > > > > > > > - child_exit = True
> > > > > > > > > - break
> > > > > > > > > -
> > > > > > > > > - time.sleep(1)
> > > > > > > > > - time_elapse += 1
> > > > > > > > > -
> > > > > > > > > - if not child_exit:
> > > > > > > > > - pipe.send_signal(signal.SIGINT)
> > > > > > > > > - pipe.wait()
> > > > > > > > > -
> > > > > > > > > - # wait pcap file ready
> > > > > > > > > - time.sleep(1)
> > > > > > > > > - try:
> > > > > > > > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" %
> intf)
> > > > > > > > > - for pkt in cap_pkts:
> > > > > > > > > - # packet gen should be scapy
> > > > > > > > > - packet = Packet(tx_port=intf)
> > > > > > > > > - packet.pktgen.assign_pkt(pkt)
> > > > > > > > > - pkts.append(packet)
> > > > > > > > > - except:
> > > > > > > > > - pass
> > > > > > > > > -
> > > > > > > > > - return pkts
> > > > > > > > > -
> > > > > > > > > -
> > > > > > > > > def load_pcapfile(filename=""):
> > > > > > > > > pkts = []
> > > > > > > > > try:
> > > > > > > > > @@ -983,7 +978,6 @@ if __name__ == "__main__":
> > > > > > > > > inst = sniff_packets("lo", timeout=5)
> > > > > > > > > pkt = Packet(pkt_type='UDP')
> > > > > > > > > pkt.send_pkt(tx_port='lo')
> > > > > > > > > - pkts = load_sniff_packets(inst)
> > > > > > > > >
> > > > > > > > > pkt = Packet(pkt_type='UDP', pkt_len=1500,
> > > > > ran_payload=True)
> > > > > > > > > pkt.send_pkt(tx_port='lo') diff --git
> > > > > > > > > a/framework/tester.py b/framework/tester.py index
> > > > > > > > > a775f68..c5b705d 100755
> > > > > > > > > --- a/framework/tester.py
> > > > > > > > > +++ b/framework/tester.py
> > > > > > > > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > > > > > > > >
> > > > > > > > > import re
> > > > > > > > > import subprocess
> > > > > > > > > +import os
> > > > > > > > > from time import sleep
> > > > > > > > > from settings import NICS, load_global_setting,
> > > > > > > > > PERF_SETTING from crb import Crb @@ -560,8 +561,6 @@
> > > > > > > > > class
> > > Tester(Crb):
> > > > > > > > > module = __import__("packet")
> > > > > > > > > pkt_c = getattr(module, "Packet")
> > > > > > > > > send_f = getattr(module, "send_packets")
> > > > > > > > > - sniff_f = getattr(module, "sniff_packets")
> > > > > > > > > - load_f = getattr(module, "load_sniff_packets")
> > > > > > > > > compare_f = getattr(module, "compare_pktload")
> > > > > > > > > strip_f = getattr(module, "strip_pktload")
> > > > > > > > > save_f = getattr(module, "save_packets") @@
> > > > > > > > > -606,7
> > > > > > > > > +605,7 @@ class Tester(Crb):
> > > > > > > > >
> > > > > > > > > # send and sniff packets
> > > > > > > > > save_f(pkts=pkts,
> filename="/tmp/%s_tx.pcap"
> > > > > > > > > %
> > > > > txIntf)
> > > > > > > > > - inst = sniff_f(intf=rxIntf, count=pktnum,
> > > > > > > timeout=timeout,
> > > > > > > > > filters=
> > > > > > > > > + inst =
> > > > > > > > > + self.tcpdump_sniff_packets(intf=rxIntf,
> > > > > > > > > + count=pktnum, timeout=timeout, filters=
> > > > > > > > > [{'layer': 'network', 'config': {'srcport':
> > > '65535'}},
> > > > > > > > > {'layer': 'network', 'config': {'dstport':
> > > > > '65535'}}])
> > > > > > > > > rx_inst[rxport] = inst @@ -627,7 +626,7 @@
> > > > > > > > > class
> > > > > > > > > Tester(Crb):
> > > > > > > > > # Verify all packets
> > > > > > > > > prev_id = -1
> > > > > > > > > for txport, rxport in portList:
> > > > > > > > > - recv_pkts = load_f(rx_inst[rxport])
> > > > > > > > > + recv_pkts =
> > > > > > > > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > > > > > > > >
> > > > > > > > > # only report when recevied number not
> matched
> > > > > > > > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > > > > > > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > > > > > > > self.proc.kill()
> > > > > > > > > self.proc = None
> > > > > > > > >
> > > > > > > > > + def tcpdump_sniff_packets(self, intf, count=0,
> > > > > > > > > + timeout=5,
> > > > > > > filters=[]):
> > > > > > > > > + """
> > > > > > > > > + Wrapper for packet module sniff_packets
> > > > > > > > > + """
> > > > > > > > > + # load functions in packet module
> > > > > > > > > + module = __import__("packet")
> > > > > > > > > + sniff_f = getattr(module, "sniff_packets")
> > > > > > > > > +
> > > > > > > > > + target=[]
> > > > > > > > > + target.append(self.get_username())
> > > > > > > > > + target.append(self.get_ip_address())
> > > > > > > > > + target.append(self.get_password())
> > > > > > > > > + return sniff_f(intf, count, timeout, filters,
> > > > > > > > > + target)
> > > > > > > > > +
> > > > > > > > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > > > > > > > + """
> > > > > > > > > + Wrapper for packet module load_sniff_pcap
> > > > > > > > > + """
> > > > > > > > > + # load functions in packet module
> > > > > > > > > + module = __import__("packet")
> > > > > > > > > + load_pcap_f = getattr(module,
> > > > > > > > > + "load_sniff_pcap")
> > > > > > > > > +
> > > > > > > > > + target=[]
> > > > > > > > > + target.append(self.get_username())
> > > > > > > > > + target.append(self.get_ip_address())
> > > > > > > > > + target.append(self.get_password())
> > > > > > > > > + pcap = load_pcap_f(index, target)
> > > > > > > > > + self.session.copy_file_from(pcap)
> > > > > > > > > +
> > > > > > > > > + return pcap.split(os.sep)[-1]
> > > > > > > > > +
> > > > > > > > > + def load_tcpdump_sniff_packets(self, index=''):
> > > > > > > > > + """
> > > > > > > > > + Wrapper for packet module load_pcapfile
> > > > > > > > > + """
> > > > > > > > > + # load functions in packet module
> > > > > > > > > + packet = __import__("packet")
> > > > > > > > > + file = self.load_tcpdump_sniff_pcap(index)
> > > > > > > > > +
> > > > > > > > > + return packet.load_pcapfile(file)
> > > > > > > > > +
> > > > > > > > > def kill_all(self, killall=False):
> > > > > > > > > """
> > > > > > > > > Kill all scapy process or DPDK application on tester.
> > > > > > > > > --
> > > > > > > > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine
2018-09-04 8:26 ` [dts] [PATCH v5 01/22] framework/packet: support packet sniffer to specify running machine Phil Yang
` (22 preceding siblings ...)
2018-09-21 3:09 ` Tu, Lijuan
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet Phil Yang
` (22 more replies)
23 siblings, 23 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
By default, the Tester is supposed to be the server which running DTS
and the packet sniff methods are running on it.
However, if DTS was not running on the Tester and the Tester is another
remote server, so packet sniff methods cannot sniff Tester's packets
correctly.
This patch adds support for packet sniff methods to specify running
machine and implements sniff packet methods in class tester.
1. Add parameter to sniff_packet and load_sniff_pcap methods to specify
the running machine.
2. Remove load_sniff_packets method in packet.py.
3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
load_tcpdump_sniff_packets for class tester with the new sniff_packet
API.
4. Update tester.check_random_pkts method with
tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
make it execution on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
framework/packet.py | 100 +++++++++++++++++++++++++++-------------------------
framework/tester.py | 48 ++++++++++++++++++++++---
2 files changed, 95 insertions(+), 53 deletions(-)
diff --git a/framework/packet.py b/framework/packet.py
index 976b82b..517c93d 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -33,7 +33,6 @@
Generic packet create, transmit and analyze module
Base on scapy(python program for packet manipulation)
"""
-
import os
import time
import sys
@@ -61,6 +60,7 @@ from scapy.route import *
from scapy.packet import bind_layers, Raw
from scapy.sendrecv import sendp
from scapy.arch import get_if_hwaddr
+from pexpect import pxssh
# load extension layers
exec_file = os.path.realpath(__file__)
@@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
return ""
-def sniff_packets(intf, count=0, timeout=5, filters=[]):
+def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
"""
sniff all packets for certain port in certain seconds
"""
param = ""
direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
- tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
- stderr=subprocess.STDOUT,
- shell=True)
+ remote_terminate = 0 # session remote terminate flag
+
+ # target[] contain the remote machine info for ssh connection
+ # target[0]: username
+ # target[1]: ip address
+ # target[2]: pass word
+ if target:
+ tcpdump_help_session=pxssh.pxssh()
+ tcpdump_help_session.login(server=target[1], username=target[0],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_help_session.sendline('tcpdump -h')
+ tcpdump_help_session.prompt()
+ tcpdump_help=tcpdump_help_session.before
+ tcpdump_help_session.logout()
+ else:
+ 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:
@@ -850,22 +866,31 @@ def sniff_packets(intf, count=0, timeout=5, filters=[]):
else:
cmd = sniff_cmd % options
- args = shlex.split(cmd)
+ if target:
+ tcpdump_session=pxssh.pxssh()
+ tcpdump_session.login(server=target[1], username=target[0],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_session.sendline(cmd)
+ pipe = tcpdump_session
+ remote_terminate = 1
+ else:
+ args = shlex.split(cmd)
+ pipe = subprocess.Popen(args)
- pipe = subprocess.Popen(args)
index = str(time.time())
- SNIFF_PIDS[index] = (pipe, intf, timeout)
+ SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
time.sleep(1)
return index
-def load_sniff_pcap(index=''):
+def load_sniff_pcap(index='', target=[]):
"""
Stop sniffer and return pcap file
"""
child_exit = False
if index in SNIFF_PIDS.keys():
- pipe, intf, timeout = SNIFF_PIDS[index]
+ pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
time_elapse = int(time.time() - float(index))
while time_elapse < timeout:
if pipe.poll() is not None:
@@ -876,8 +901,22 @@ def load_sniff_pcap(index=''):
time_elapse += 1
if not child_exit:
- pipe.send_signal(signal.SIGINT)
- pipe.wait()
+ if remote_terminate == 1:
+ tcpdump_quit_session=pxssh.pxssh()
+ tcpdump_quit_session.login(server=target[1], username=target[0],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_quit_session.sendline('kill -2 $(pidof tcpdump)')
+ tcpdump_quit_session.prompt()
+ tcpdump_quit_session.logout()
+ # Teminate the tcpdump_session
+ pipe.prompt()
+ pipe.logout()
+ pipe = None
+
+ if pipe is not None:
+ pipe.send_signal(signal.SIGINT)
+ pipe.wait()
# wait pcap file ready
time.sleep(1)
@@ -886,42 +925,6 @@ def load_sniff_pcap(index=''):
return ""
-def load_sniff_packets(index=''):
- """
- Stop sniffer and return packet objects
- """
- pkts = []
- child_exit = False
- if index in SNIFF_PIDS.keys():
- pipe, intf, timeout = SNIFF_PIDS[index]
- time_elapse = int(time.time() - float(index))
- while time_elapse < timeout:
- if pipe.poll() is not None:
- child_exit = True
- break
-
- time.sleep(1)
- time_elapse += 1
-
- if not child_exit:
- pipe.send_signal(signal.SIGINT)
- pipe.wait()
-
- # wait pcap file ready
- time.sleep(1)
- try:
- cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
- for pkt in cap_pkts:
- # packet gen should be scapy
- packet = Packet(tx_port=intf)
- packet.pktgen.assign_pkt(pkt)
- pkts.append(packet)
- except:
- pass
-
- return pkts
-
-
def load_pcapfile(filename=""):
pkts = []
try:
@@ -983,7 +986,6 @@ if __name__ == "__main__":
inst = sniff_packets("lo", timeout=5)
pkt = Packet(pkt_type='UDP')
pkt.send_pkt(tx_port='lo')
- pkts = load_sniff_packets(inst)
pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
pkt.send_pkt(tx_port='lo')
diff --git a/framework/tester.py b/framework/tester.py
index a775f68..c5b705d 100755
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -35,6 +35,7 @@ Interface for bulk traffic generators.
import re
import subprocess
+import os
from time import sleep
from settings import NICS, load_global_setting, PERF_SETTING
from crb import Crb
@@ -560,8 +561,6 @@ class Tester(Crb):
module = __import__("packet")
pkt_c = getattr(module, "Packet")
send_f = getattr(module, "send_packets")
- sniff_f = getattr(module, "sniff_packets")
- load_f = getattr(module, "load_sniff_packets")
compare_f = getattr(module, "compare_pktload")
strip_f = getattr(module, "strip_pktload")
save_f = getattr(module, "save_packets")
@@ -606,7 +605,7 @@ class Tester(Crb):
# send and sniff packets
save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
- inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout, filters=
+ inst = self.tcpdump_sniff_packets(intf=rxIntf, count=pktnum, timeout=timeout, filters=
[{'layer': 'network', 'config': {'srcport': '65535'}},
{'layer': 'network', 'config': {'dstport': '65535'}}])
rx_inst[rxport] = inst
@@ -627,7 +626,7 @@ class Tester(Crb):
# Verify all packets
prev_id = -1
for txport, rxport in portList:
- recv_pkts = load_f(rx_inst[rxport])
+ recv_pkts = self.load_tcpdump_sniff_packets(rx_inst[rxport])
# only report when recevied number not matched
if len(tx_pkts[txport]) > len(recv_pkts):
@@ -704,6 +703,47 @@ class Tester(Crb):
self.proc.kill()
self.proc = None
+ def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
+ """
+ Wrapper for packet module sniff_packets
+ """
+ # load functions in packet module
+ module = __import__("packet")
+ sniff_f = getattr(module, "sniff_packets")
+
+ target=[]
+ target.append(self.get_username())
+ target.append(self.get_ip_address())
+ target.append(self.get_password())
+ return sniff_f(intf, count, timeout, filters, target)
+
+ def load_tcpdump_sniff_pcap(self, index=''):
+ """
+ Wrapper for packet module load_sniff_pcap
+ """
+ # load functions in packet module
+ module = __import__("packet")
+ load_pcap_f = getattr(module, "load_sniff_pcap")
+
+ target=[]
+ target.append(self.get_username())
+ target.append(self.get_ip_address())
+ target.append(self.get_password())
+ pcap = load_pcap_f(index, target)
+ self.session.copy_file_from(pcap)
+
+ return pcap.split(os.sep)[-1]
+
+ def load_tcpdump_sniff_packets(self, index=''):
+ """
+ Wrapper for packet module load_pcapfile
+ """
+ # load functions in packet module
+ packet = __import__("packet")
+ file = self.load_tcpdump_sniff_pcap(index)
+
+ return packet.load_pcapfile(file)
+
def kill_all(self, killall=False):
"""
Kill all scapy process or DPDK application on tester.
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 03/22] tests/etag: " Phil Yang
` (21 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_checksum_offload.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_checksum_offload.py b/tests/TestSuite_checksum_offload.py
index 2ff5c2f..6541ba5 100644
--- a/tests/TestSuite_checksum_offload.py
+++ b/tests/TestSuite_checksum_offload.py
@@ -43,7 +43,6 @@ import utils
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
from test_capabilities import DRIVER_TEST_LACK_CAPA
class TestChecksumOffload(TestCase):
@@ -175,13 +174,14 @@ class TestChecksumOffload(TestCase):
self.tester.send_expect("exit()", "#")
- inst = sniff_packets(intf=rx_interface, count=len(packets_sent), filters=[{'layer':'ether', 'config':{'src': sniff_src}}])
+ inst = self.tester.tcpdump_sniff_packets(intf=rx_interface, count=len(packets_sent),
+ filters=[{'layer':'ether', 'config':{'src': sniff_src}}])
for packet_type in packets_sent.keys():
self.tester.scapy_append('sendp([%s], iface="%s")' % (packets_sent[packet_type], tx_interface))
self.tester.scapy_execute()
- p = load_sniff_packets(inst)
+ p = self.tester.load_tcpdump_sniff_packets(inst)
nr_packets=len(p)
reslist = [p[i].pktgen.pkt.sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%") for i in range(nr_packets)]
out = string.join(reslist, ",")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 03/22] tests/etag: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 04/22] tests/ipfrag: " Phil Yang
` (20 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_etag.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_etag.py b/tests/TestSuite_etag.py
index 642fb2b..68cca44 100644
--- a/tests/TestSuite_etag.py
+++ b/tests/TestSuite_etag.py
@@ -46,7 +46,7 @@ from exception import VerifyFailure
from scapy.utils import rdpcap
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
VM_CORES_MASK = 'all'
@@ -325,11 +325,11 @@ class TestEtag(TestCase):
pkt_types = {'IP_RAW': {'layer_configs': config_layers}}
intf = self.src_intf
- inst = sniff_packets(intf)
+ inst = self.tester.tcpdump_sniff_packets(intf)
self.check_packet_transmission(pkt_types)
time.sleep(1)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.host_testpmd.execute_cmd('E-tag set insertion off port-tag-id 1000 port 0 vf 0')
# load sniff pcap file, check received packet's content
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 04/22] tests/ipfrag: Replace sniff_packet to tester.tcpdump_sniff_packet
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 02/22] tests/checksum_offload: Replace sniff_packet to tester.tcpdump_sniff_packet Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 03/22] tests/etag: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (19 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_ipfrag.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/TestSuite_ipfrag.py b/tests/TestSuite_ipfrag.py
index f23dbe1..38e00d7 100644
--- a/tests/TestSuite_ipfrag.py
+++ b/tests/TestSuite_ipfrag.py
@@ -39,7 +39,7 @@ import string
import re
import time
from settings import HEADER_SIZE
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
lpm_table_ipv4 = [
"{IPv4(100,10,0,0), 16, P1}",
@@ -159,7 +159,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
expPkts = 1
val = 2
- inst = sniff_packets(intf=self.rxItf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
# send packet
for times in range(burst):
pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
@@ -169,7 +169,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
pkt.send_pkt(tx_port=self.txItf)
# verify normal packet just by number, verify fragment packet by all elements
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
if flag == 'frag':
idx = 1
@@ -209,7 +209,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
expPkts = 1
val = 2
- inst = sniff_packets(intf=self.rxItf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf=self.rxItf, timeout=5)
# send packet
for times in range(burst):
pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
@@ -219,7 +219,7 @@ l3fwd_ipv4_route_array[] = {\\\n"
pkt.send_pkt(tx_port=self.txItf)
# verify normal packet just by number, verify fragment packet by all elements
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
if flag == 'frag':
idx = 1
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (2 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 04/22] tests/ipfrag: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet Phil Yang
` (18 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_l2fwd_crypto.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_l2fwd_crypto.py b/tests/TestSuite_l2fwd_crypto.py
index d559909..ea35a29 100644
--- a/tests/TestSuite_l2fwd_crypto.py
+++ b/tests/TestSuite_l2fwd_crypto.py
@@ -38,7 +38,7 @@ import sys
import utils
import commands
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets, save_packets
+from packet import Packet, save_packets
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
@@ -501,7 +501,7 @@ class TestL2fwdCrypto(TestCase):
payload = self.__format_hex_to_list(test_vector["input"])
- inst = sniff_packets(self.rx_interface, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.rx_interface, timeout=5)
PACKET_COUNT = 65
pkt = Packet()
@@ -512,7 +512,7 @@ class TestL2fwdCrypto(TestCase):
pkt.send_pkt(tx_port=self.tx_interface, count=PACKET_COUNT)
pkt.pktgen.pkt.show()
- pkt_rec = load_sniff_packets(inst)
+ pkt_rec = self.tester.load_tcpdump_sniff_packets(inst)
for pkt_r in pkt_rec:
packet_hex = pkt_r.strip_element_layer4("load")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (3 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 05/22] tests/l2fwd_crypto: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (17 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_netmap_compat.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tests/TestSuite_netmap_compat.py b/tests/TestSuite_netmap_compat.py
index 5225a27..84136c7 100644
--- a/tests/TestSuite_netmap_compat.py
+++ b/tests/TestSuite_netmap_compat.py
@@ -43,7 +43,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestNetmapCompat(TestCase):
@@ -80,7 +79,7 @@ class TestNetmapCompat(TestCase):
self.rxItf = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
self.scapy_send_packet()
@@ -98,7 +97,7 @@ class TestNetmapCompat(TestCase):
self.dut.send_expect(cmd,"Port %s now in Netmap mode" % self.dut_ports[0], 60)
self.rxItf = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
self.scapy_send_packet()
@@ -117,7 +116,7 @@ class TestNetmapCompat(TestCase):
def get_tcpdump_package(self):
- pkts = load_sniff_packets(self.inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (4 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 06/22] tests/netmap_compat: replaced sniff_packet to tester.tcpdump_sniff_packet Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 08/22] tests/quota_watermark: " Phil Yang
` (16 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_queue_start_stop.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_queue_start_stop.py b/tests/TestSuite_queue_start_stop.py
index 3dd37b3..6cd6831 100644
--- a/tests/TestSuite_queue_start_stop.py
+++ b/tests/TestSuite_queue_start_stop.py
@@ -44,7 +44,7 @@ import os
from test_case import TestCase
from pmd_output import PmdOutput
from settings import FOLDERS
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
+from packet import Packet, strip_pktload
#
#
@@ -99,10 +99,10 @@ class TestQueueStartStop(TestCase):
dmac = self.dut.get_mac_address(txPort)
pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
- inst = sniff_packets(rxitf)
+ inst = self.tester.tcpdump_sniff_packets(rxitf)
pkt.config_layer('ether', {'dst': dmac})
pkt.send_pkt(tx_port=txitf)
- sniff_pkts = load_sniff_packets(inst)
+ sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
if received:
res = strip_pktload(sniff_pkts[0], layer="L4")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 08/22] tests/quota_watermark: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (5 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 07/22] tests/queue_start_stop: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 09/22] tests/rxtx_callback: " Phil Yang
` (15 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_quota_watermark.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_quota_watermark.py b/tests/TestSuite_quota_watermark.py
index ecacf38..845b27f 100644
--- a/tests/TestSuite_quota_watermark.py
+++ b/tests/TestSuite_quota_watermark.py
@@ -39,7 +39,6 @@ import time
import utils
from test_case import TestCase
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
test_config = {
'frames_to_sent': 15 * 10 ** 6,
@@ -311,9 +310,9 @@ class TestQuotaWatermark(TestCase, IxiaPacketGenerator):
rx_intf = self.tester.get_interface(rev_port)
tx_intf = self.tester.get_interface(send_port)
# send and sniff packet
- rx_inst = sniff_packets(rx_intf, timeout=5)
+ rx_inst = self.tester.tcpdump_sniff_packets(rx_intf, timeout=5)
self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf)
- pkts = load_sniff_packets(rx_inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(rx_inst)
self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected")
return
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 09/22] tests/rxtx_callback: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (6 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 08/22] tests/quota_watermark: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 10/22] tests/scatter: " Phil Yang
` (14 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_rxtx_callbacks.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_rxtx_callbacks.py b/tests/TestSuite_rxtx_callbacks.py
index dd968a4..a654480 100644
--- a/tests/TestSuite_rxtx_callbacks.py
+++ b/tests/TestSuite_rxtx_callbacks.py
@@ -41,7 +41,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestRxtxCallbacks(TestCase):
@@ -77,7 +76,7 @@ class TestRxtxCallbacks(TestCase):
self.iface_port0 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
self.iface_port1 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst_port1 = sniff_packets(self.iface_port1)
+ self.inst_port1 = self.tester.tcpdump_sniff_packets(self.iface_port1)
self.scapy_send_packet(self.iface_port0)
out_port1 = self.get_tcpdump_package(self.inst_port1)
@@ -92,7 +91,7 @@ class TestRxtxCallbacks(TestCase):
self.tester.scapy_execute()
def get_tcpdump_package(self,inst):
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 10/22] tests/scatter: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (7 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 09/22] tests/rxtx_callback: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 11/22] tests/skeleton: " Phil Yang
` (13 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_scatter.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_scatter.py b/tests/TestSuite_scatter.py
index d6aef49..0d38513 100644
--- a/tests/TestSuite_scatter.py
+++ b/tests/TestSuite_scatter.py
@@ -35,7 +35,7 @@ Test Scattered Packets.
"""
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload
+from packet import Packet, strip_pktload
import time
#
#
@@ -82,11 +82,11 @@ class TestScatter(TestCase):
"""
dmac = self.dut.get_mac_address(self.port)
- inst = sniff_packets(self.intf)
+ inst = self.tester.tcpdump_sniff_packets(self.intf)
pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize)
pkt.config_layer('ether', {'dst': dmac})
pkt.send_pkt(tx_port=self.intf)
- sniff_pkts = load_sniff_packets(inst)
+ sniff_pkts = self.tester.load_tcpdump_sniff_packets(inst)
res = ""
if len(sniff_pkts):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 11/22] tests/skeleton: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (8 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 10/22] tests/scatter: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 12/22] tests/userspace_ethtool: " Phil Yang
` (12 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_skeleton.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_skeleton.py b/tests/TestSuite_skeleton.py
index 77f95e1..b56d955 100644
--- a/tests/TestSuite_skeleton.py
+++ b/tests/TestSuite_skeleton.py
@@ -42,7 +42,6 @@ from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestSkeleton(TestCase):
@@ -80,7 +79,7 @@ class TestSkeleton(TestCase):
self.iface_port0 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
self.iface_port1 = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[1]))
- self.inst_port1 = sniff_packets(self.iface_port1)
+ self.inst_port1 = self.tester.tcpdump_sniff_packets(self.iface_port1)
self.scapy_send_packet(self.iface_port0)
out_port1 = self.get_tcpdump_package(self.inst_port1)
@@ -95,7 +94,7 @@ class TestSkeleton(TestCase):
self.tester.scapy_execute()
def get_tcpdump_package(self,inst):
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
dsts = []
for packet in pkts:
dst = packet.strip_element_layer2("dst")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 12/22] tests/userspace_ethtool: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (9 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 11/22] tests/skeleton: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 13/22] tests/vf_daemon: " Phil Yang
` (11 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_userspace_ethtool.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_userspace_ethtool.py b/tests/TestSuite_userspace_ethtool.py
index eccc77b..8ade421 100644
--- a/tests/TestSuite_userspace_ethtool.py
+++ b/tests/TestSuite_userspace_ethtool.py
@@ -39,7 +39,7 @@ import utils
import time
import re
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
import random
from etgen import IxiaPacketGenerator
from settings import HEADER_SIZE
@@ -490,9 +490,9 @@ class TestUserspaceEthtool(TestCase, IxiaPacketGenerator):
tester_port = self.tester.get_local_port(port)
intf = self.tester.get_interface(tester_port)
# send and sniff packet
- inst = sniff_packets(intf, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(intf, timeout=5)
pkt.send_pkt(tx_port=intf)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts) == 1, "Packet not forwarded as expected")
src_mac = pkts[0].strip_layer_element("layer2", "src")
self.verify(src_mac == valid_mac, "Forwarded packet not match default mac")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 13/22] tests/vf_daemon: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (10 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 12/22] tests/userspace_ethtool: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 14/22] tests/vf_vlan: " Phil Yang
` (10 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_vf_daemon.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/TestSuite_vf_daemon.py b/tests/TestSuite_vf_daemon.py
index c264911..42a14e5 100644
--- a/tests/TestSuite_vf_daemon.py
+++ b/tests/TestSuite_vf_daemon.py
@@ -8,7 +8,7 @@ from scapy.utils import rdpcap
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
from settings import get_nic_name
import random
@@ -154,7 +154,7 @@ class Testvf_daemon(TestCase):
pkt.config_layer('vlan', {'vlan': vlan_id})
pkt.config_layer('ether', {'dst': dst_mac})
- inst = sniff_packets(self.tester_intf, timeout=30)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=30)
pkt.send_pkt(tx_port=self.tester_intf, count=num)
return inst
@@ -162,7 +162,7 @@ class Testvf_daemon(TestCase):
"""
Load sniff packets, strip and return mac address from dump message
"""
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
macs = []
for pkt in pkts:
mac = pkt.strip_element_layer2(element)
@@ -173,7 +173,7 @@ class Testvf_daemon(TestCase):
"""
Load sniff packets, strip and return vlan id from dump message
"""
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
vlans = []
for pkt in pkts:
vlan = pkt.strip_element_vlan("vlan")
@@ -422,7 +422,7 @@ class Testvf_daemon(TestCase):
self.dut_testpmd.execute_cmd('set tx loopback 0 off')
time.sleep(5)
- inst = sniff_packets(self.tester_intf, timeout=10)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
self.vm1_testpmd.execute_cmd('set burst 5')
self.vm1_testpmd.execute_cmd('start tx_first')
@@ -438,7 +438,7 @@ class Testvf_daemon(TestCase):
self.dut_testpmd.execute_cmd('set tx loopback 0 on')
time.sleep(3)
- inst = sniff_packets(self.tester_intf, timeout=10)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf, timeout=10)
self.vm1_testpmd.execute_cmd('stop')
self.vm1_testpmd.execute_cmd('start tx_first')
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 14/22] tests/vf_vlan: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (11 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 13/22] tests/vf_daemon: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 15/22] tests/vlan_ethertype_config: remove unused sniff_packets Phil Yang
` (9 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_vf_vlan.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/TestSuite_vf_vlan.py b/tests/TestSuite_vf_vlan.py
index 75d99f2..4c7b42d 100644
--- a/tests/TestSuite_vf_vlan.py
+++ b/tests/TestSuite_vf_vlan.py
@@ -6,7 +6,7 @@ import time
from virt_common import VM
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
from settings import get_nic_name
import random
@@ -173,9 +173,9 @@ class TestVfVlan(TestCase):
pkt = Packet(pkt_type='UDP')
pkt.config_layer('ether', {'dst': self.vf1_mac})
- inst = sniff_packets(self.tester_intf0, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
pkt.send_pkt(tx_port=self.tester_intf1)
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
self.verify(len(pkts), "Not receive expected packet")
self.vm0_testpmd.quit()
@@ -258,13 +258,13 @@ class TestVfVlan(TestCase):
"ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ")
def tx_and_check(self, tx_vlan=1):
- inst = sniff_packets(self.tester_intf0, timeout=5)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_intf0, timeout=5)
self.vm0_testpmd.execute_cmd('set burst 1')
self.vm0_testpmd.execute_cmd('start tx_first')
self.vm0_testpmd.execute_cmd('stop')
# strip sniffered vlans
- pkts = load_sniff_packets(inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(inst)
vlans = []
for pkt in pkts:
vlan = pkt.strip_element_vlan("vlan")
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 15/22] tests/vlan_ethertype_config: remove unused sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (12 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 14/22] tests/vf_vlan: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
` (8 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused sniff_packets
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_vlan_ethertype_config.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/tests/TestSuite_vlan_ethertype_config.py b/tests/TestSuite_vlan_ethertype_config.py
index 1fb30fb..8eba49c 100644
--- a/tests/TestSuite_vlan_ethertype_config.py
+++ b/tests/TestSuite_vlan_ethertype_config.py
@@ -43,7 +43,6 @@ import utils
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
from scapy.utils import struct, socket, wrpcap, rdpcap
from scapy.layers.inet import Ether, IP, TCP, UDP, ICMP
from scapy.layers.l2 import Dot1Q, ARP, GRE
@@ -125,7 +124,6 @@ class TestVlanEthertypeConfig(TestCase):
# off
self.dmac = self.dut.get_mac_address(dutRxPortId)
- self.inst = sniff_packets(self.rxItf)
pkt = []
if outer_vid < 0 or outer_tpid <= 0:
pkt = [
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (13 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 15/22] tests/vlan_ethertype_config: remove unused sniff_packets Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 17/22] tests/ipgre: " Phil Yang
` (7 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_vlan.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_vlan.py b/tests/TestSuite_vlan.py
index 0f1833b..b2bda71 100644
--- a/tests/TestSuite_vlan.py
+++ b/tests/TestSuite_vlan.py
@@ -43,7 +43,7 @@ import time
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestVlan(TestCase):
@@ -88,7 +88,7 @@ class TestVlan(TestCase):
netobj.add_vlan(vlan_id = self.vlan)
def get_tcpdump_package(self):
- pkts = load_sniff_packets(self.inst)
+ pkts = self.tester.load_tcpdump_sniff_packets(self.inst)
vlans = []
for packet in pkts:
vlan = packet.strip_element_vlan("vlan")
@@ -110,7 +110,7 @@ class TestVlan(TestCase):
# the package dect mac must is dut tx port id when the port promisc is off
self.dmac = self.dut.get_mac_address(dutRxPortId)
- self.inst = sniff_packets(self.rxItf)
+ self.inst = self.tester.tcpdump_sniff_packets(self.rxItf)
# FIXME send a burst with only num packet
if vid == -1:
pkt = Packet(pkt_type='UDP')
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 17/22] tests/ipgre: replaced sniff_packets to tester.tcpdump_sniff_packets
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (14 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 16/22] tests/vlan: replaced sniff_packets to tester.tcpdump_sniff_packets Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 18/22] tests/hotplug: remove unused packet sniff import Phil Yang
` (6 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
Make packet sniff run on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_ipgre.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestSuite_ipgre.py b/tests/TestSuite_ipgre.py
index 2dccb9c..e400161 100644
--- a/tests/TestSuite_ipgre.py
+++ b/tests/TestSuite_ipgre.py
@@ -44,7 +44,7 @@ import re
import time
import os
-from packet import Packet, sniff_packets, load_sniff_packets, NVGRE, IPPROTO_NVGRE
+from packet import Packet, NVGRE, IPPROTO_NVGRE
from scapy.utils import wrpcap, rdpcap
from scapy.packet import split_layers,bind_layers
@@ -98,11 +98,11 @@ class TestIpgre(TestCase):
if layer_configs:
for layer in layer_configs.keys():
pkt.config_layer(layer, layer_configs[layer])
- inst = sniff_packets(self.tester_iface, count=1, timeout=8)
+ inst = self.tester.tcpdump_sniff_packets(self.tester_iface, count=1, timeout=8)
pkt.send_pkt(tx_port=self.tester_iface)
out = self.dut.get_session_output(timeout=2)
time.sleep(1)
- load_sniff_packets(inst)
+ self.tester.load_tcpdump_sniff_packets(inst)
if self.printFlag: # debug output
print out
for pkt_layer_name in pkt_names:
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 18/22] tests/hotplug: remove unused packet sniff import
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (15 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 17/22] tests/ipgre: " Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:19 ` [dts] [PATCH v6 19/22] tests/keep_alive: " Phil Yang
` (5 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_hotplug.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_hotplug.py b/tests/TestSuite_hotplug.py
index c0e1741..7d63b71 100644
--- a/tests/TestSuite_hotplug.py
+++ b/tests/TestSuite_hotplug.py
@@ -43,7 +43,7 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestPortHotPlug(TestCase):
"""
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 19/22] tests/keep_alive: remove unused packet sniff import
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (16 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 18/22] tests/hotplug: remove unused packet sniff import Phil Yang
@ 2018-10-16 6:19 ` Phil Yang
2018-10-16 6:20 ` [dts] [PATCH v6 20/22] tests/link_status_interrupt: " Phil Yang
` (4 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:19 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_keep_alive.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/TestSuite_keep_alive.py b/tests/TestSuite_keep_alive.py
index 41c8732..711d8ce 100644
--- a/tests/TestSuite_keep_alive.py
+++ b/tests/TestSuite_keep_alive.py
@@ -43,7 +43,6 @@ from test_case import TestCase
from plotting import Plotting
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
-from packet import Packet, sniff_packets, load_sniff_packets
class TestKeepAlive(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 20/22] tests/link_status_interrupt: remove unused packet sniff import
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (17 preceding siblings ...)
2018-10-16 6:19 ` [dts] [PATCH v6 19/22] tests/keep_alive: " Phil Yang
@ 2018-10-16 6:20 ` Phil Yang
2018-10-16 6:20 ` [dts] [PATCH v6 21/22] tests/vhost_pmd_xstats: " Phil Yang
` (3 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:20 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_link_status_interrupt.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_link_status_interrupt.py b/tests/TestSuite_link_status_interrupt.py
index c31634b..cad6485 100644
--- a/tests/TestSuite_link_status_interrupt.py
+++ b/tests/TestSuite_link_status_interrupt.py
@@ -40,7 +40,7 @@ import string
import time
import re
from test_case import TestCase
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestLinkStatusInterrupt(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 21/22] tests/vhost_pmd_xstats: remove unused packet sniff import
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (18 preceding siblings ...)
2018-10-16 6:20 ` [dts] [PATCH v6 20/22] tests/link_status_interrupt: " Phil Yang
@ 2018-10-16 6:20 ` Phil Yang
2018-10-16 6:20 ` [dts] [PATCH v6 22/22] tests/ddp_mpls: " Phil Yang
` (2 subsequent siblings)
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:20 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_vhost_pmd_xstats.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/TestSuite_vhost_pmd_xstats.py b/tests/TestSuite_vhost_pmd_xstats.py
index 8c800c7..a01ca16 100644
--- a/tests/TestSuite_vhost_pmd_xstats.py
+++ b/tests/TestSuite_vhost_pmd_xstats.py
@@ -46,7 +46,7 @@ from exception import VerifyFailure
from settings import HEADER_SIZE
from etgen import IxiaPacketGenerator
from qemu_kvm import QEMUKvm
-from packet import Packet, sniff_packets, load_sniff_packets
+from packet import Packet
class TestVhostPmdXstats(TestCase):
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v6 22/22] tests/ddp_mpls: remove unused packet sniff import
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (19 preceding siblings ...)
2018-10-16 6:20 ` [dts] [PATCH v6 21/22] tests/vhost_pmd_xstats: " Phil Yang
@ 2018-10-16 6:20 ` Phil Yang
2018-10-18 9:15 ` [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine Tu, Lijuan
2018-10-19 9:25 ` [dts] [PATCH v7] " Phil Yang
22 siblings, 0 replies; 124+ messages in thread
From: Phil Yang @ 2018-10-16 6:20 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
remove unused packet sniff import.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
tests/TestSuite_ddp_mpls.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py
index 08d58be..691e958 100644
--- a/tests/TestSuite_ddp_mpls.py
+++ b/tests/TestSuite_ddp_mpls.py
@@ -8,7 +8,6 @@ from scapy.utils import rdpcap
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from packet import Packet, sniff_packets, load_sniff_packets
from settings import get_nic_name
import random
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (20 preceding siblings ...)
2018-10-16 6:20 ` [dts] [PATCH v6 22/22] tests/ddp_mpls: " Phil Yang
@ 2018-10-18 9:15 ` Tu, Lijuan
2018-10-18 10:00 ` Phil Yang (Arm Technology China)
2018-10-19 9:25 ` [dts] [PATCH v7] " Phil Yang
22 siblings, 1 reply; 124+ messages in thread
From: Tu, Lijuan @ 2018-10-18 9:15 UTC (permalink / raw)
To: phil.yang, dts; +Cc: nd
Hi Phil,
Poll is an attribute of Popen, but not pxssh.
To make sniff function more clear, I prefer to remove the old code instead of keeping them.
As in dts, we always pass the parameter target, the tester information, we could raise exception when finding target is None.
> -----Original Message-----
> From: phil.yang@arm.com [mailto:phil.yang@arm.com]
> Sent: Tuesday, October 16, 2018 2:20 PM
> To: dts@dpdk.org
> Cc: nd@arm.com; Tu, Lijuan <lijuan.tu@intel.com>
> Subject: [PATCH v6 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> By default, the Tester is supposed to be the server which running DTS and the
> packet sniff methods are running on it.
> However, if DTS was not running on the Tester and the Tester is another
> remote server, so packet sniff methods cannot sniff Tester's packets
> correctly.
>
> This patch adds support for packet sniff methods to specify running machine
> and implements sniff packet methods in class tester.
>
> 1. Add parameter to sniff_packet and load_sniff_pcap methods to specify
> the running machine.
> 2. Remove load_sniff_packets method in packet.py.
> 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> 4. Update tester.check_random_pkts method with
> tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
> make it execution on the Tester.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Suggested-by: Marvin Liu <yong.liu@intel.com>
> Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
> ---
> framework/packet.py | 100
> +++++++++++++++++++++++++++-------------------------
> framework/tester.py | 48 ++++++++++++++++++++++---
> 2 files changed, 95 insertions(+), 53 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index
> 976b82b..517c93d 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -33,7 +33,6 @@
> Generic packet create, transmit and analyze module Base on
> scapy(python program for packet manipulation) """
> -
> import os
> import time
> import sys
> @@ -61,6 +60,7 @@ from scapy.route import * from scapy.packet import
> bind_layers, Raw from scapy.sendrecv import sendp from scapy.arch
> import get_if_hwaddr
> +from pexpect import pxssh
>
> # load extension layers
> exec_file = os.path.realpath(__file__)
> @@ -812,15 +812,31 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> """
> sniff all packets for certain port in certain seconds
> """
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> -
> stderr=subprocess.STDOUT,
> - shell=True)
> + remote_terminate = 0 # session remote terminate flag
> +
> + # target[] contain the remote machine info for ssh connection
> + # target[0]: username
> + # target[1]: ip address
> + # target[2]: pass word
> + if target:
> + tcpdump_help_session=pxssh.pxssh()
> + tcpdump_help_session.login(server=target[1], username=target[0],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_help_session.sendline('tcpdump -h')
> + tcpdump_help_session.prompt()
> + tcpdump_help=tcpdump_help_session.before
> + tcpdump_help_session.logout()
> + else:
> + 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:
> @@ -850,22 +866,31 @@ def sniff_packets(intf, count=0, timeout=5,
> filters=[]):
> else:
> cmd = sniff_cmd % options
>
> - args = shlex.split(cmd)
> + if target:
> + tcpdump_session=pxssh.pxssh()
> + tcpdump_session.login(server=target[1], username=target[0],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_session.sendline(cmd)
> + pipe = tcpdump_session
> + remote_terminate = 1
> + else:
> + args = shlex.split(cmd)
> + pipe = subprocess.Popen(args)
>
> - pipe = subprocess.Popen(args)
> index = str(time.time())
> - SNIFF_PIDS[index] = (pipe, intf, timeout)
> + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index=''):
> +def load_sniff_pcap(index='', target=[]):
> """
> Stop sniffer and return pcap file
> """
> child_exit = False
> if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> time_elapse = int(time.time() - float(index))
> while time_elapse < timeout:
> if pipe.poll() is not None:
[Lijuan] Exception happened here because poll is not an attribute of pxssh.
> @@ -876,8 +901,22 @@ def load_sniff_pcap(index=''):
> time_elapse += 1
>
> if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> + if remote_terminate == 1:
> + tcpdump_quit_session=pxssh.pxssh()
> + tcpdump_quit_session.login(server=target[1],
> username=target[0],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_quit_session.sendline('kill -2 $(pidof
> tcpdump)')
> + tcpdump_quit_session.prompt()
> + tcpdump_quit_session.logout()
> + # Teminate the tcpdump_session
> + pipe.prompt()
> + pipe.logout()
> + pipe = None
> +
> + if pipe is not None:
> + pipe.send_signal(signal.SIGINT)
> + pipe.wait()
>
> # wait pcap file ready
> time.sleep(1)
> @@ -886,42 +925,6 @@ def load_sniff_pcap(index=''):
> return ""
>
>
> -def load_sniff_packets(index=''):
> - """
> - Stop sniffer and return packet objects
> - """
> - pkts = []
> - child_exit = False
> - if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.poll() is not None:
> - child_exit = True
> - break
> -
> - time.sleep(1)
> - time_elapse += 1
> -
> - if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - try:
> - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet(tx_port=intf)
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> -
> - return pkts
> -
> -
> def load_pcapfile(filename=""):
> pkts = []
> try:
> @@ -983,7 +986,6 @@ if __name__ == "__main__":
> inst = sniff_packets("lo", timeout=5)
> pkt = Packet(pkt_type='UDP')
> pkt.send_pkt(tx_port='lo')
> - pkts = load_sniff_packets(inst)
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> pkt.send_pkt(tx_port='lo')
> diff --git a/framework/tester.py b/framework/tester.py index
> a775f68..c5b705d 100755
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
>
> import re
> import subprocess
> +import os
> from time import sleep
> from settings import NICS, load_global_setting, PERF_SETTING from crb
> import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> send_f = getattr(module, "send_packets")
> - sniff_f = getattr(module, "sniff_packets")
> - load_f = getattr(module, "load_sniff_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@
> class Tester(Crb):
>
> # send and sniff packets
> save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> filters=
> + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> + count=pktnum, timeout=timeout, filters=
> [{'layer': 'network', 'config': {'srcport': '65535'}},
> {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> @@ -627,7 +626,7 @@ class Tester(Crb):
> # Verify all packets
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = load_f(rx_inst[rxport])
> + recv_pkts =
> + self.load_tcpdump_sniff_packets(rx_inst[rxport])
>
> # only report when recevied number not matched
> if len(tx_pkts[txport]) > len(recv_pkts):
> @@ -704,6 +703,47 @@ class Tester(Crb):
> self.proc.kill()
> self.proc = None
>
> + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + """
> + Wrapper for packet module sniff_packets
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + sniff_f = getattr(module, "sniff_packets")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + return sniff_f(intf, count, timeout, filters, target)
> +
> + def load_tcpdump_sniff_pcap(self, index=''):
> + """
> + Wrapper for packet module load_sniff_pcap
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + load_pcap_f = getattr(module, "load_sniff_pcap")
> +
> + target=[]
> + target.append(self.get_username())
> + target.append(self.get_ip_address())
> + target.append(self.get_password())
> + pcap = load_pcap_f(index, target)
> + self.session.copy_file_from(pcap)
> +
> + return pcap.split(os.sep)[-1]
> +
> + def load_tcpdump_sniff_packets(self, index=''):
> + """
> + Wrapper for packet module load_pcapfile
> + """
> + # load functions in packet module
> + packet = __import__("packet")
> + file = self.load_tcpdump_sniff_pcap(index)
> +
> + return packet.load_pcapfile(file)
> +
> def kill_all(self, killall=False):
> """
> Kill all scapy process or DPDK application on tester.
> --
> 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine
2018-10-18 9:15 ` [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine Tu, Lijuan
@ 2018-10-18 10:00 ` Phil Yang (Arm Technology China)
2018-10-19 9:29 ` Phil Yang (Arm Technology China)
0 siblings, 1 reply; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-10-18 10:00 UTC (permalink / raw)
To: Tu, Lijuan, dts; +Cc: nd
Hi Lijuan,
Agree.
I can sanity the patch in the new version.
Thanks,
Phil Yang
> -----Original Message-----
> From: Tu, Lijuan <lijuan.tu@intel.com>
> Sent: Thursday, October 18, 2018 5:15 PM
> To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; dts@dpdk.org
> Cc: nd <nd@arm.com>
> Subject: RE: [PATCH v6 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> Hi Phil,
> Poll is an attribute of Popen, but not pxssh.
>
> To make sniff function more clear, I prefer to remove the old code instead of
> keeping them.
> As in dts, we always pass the parameter target, the tester information, we could
> raise exception when finding target is None.
>
> > -----Original Message-----
> > From: phil.yang@arm.com [mailto:phil.yang@arm.com]
> > Sent: Tuesday, October 16, 2018 2:20 PM
> > To: dts@dpdk.org
> > Cc: nd@arm.com; Tu, Lijuan <lijuan.tu@intel.com>
> > Subject: [PATCH v6 01/22] framework/packet: support packet sniffer to
> > specify running machine
> >
> > By default, the Tester is supposed to be the server which running DTS
> > and the packet sniff methods are running on it.
> > However, if DTS was not running on the Tester and the Tester is
> > another remote server, so packet sniff methods cannot sniff Tester's
> > packets correctly.
> >
> > This patch adds support for packet sniff methods to specify running
> > machine and implements sniff packet methods in class tester.
> >
> > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > specify the running machine.
> > 2. Remove load_sniff_packets method in packet.py.
> > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> > 4. Update tester.check_random_pkts method with
> > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
> > make it execution on the Tester.
> >
> > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
> > ---
> > framework/packet.py | 100
> > +++++++++++++++++++++++++++-------------------------
> > framework/tester.py | 48 ++++++++++++++++++++++---
> > 2 files changed, 95 insertions(+), 53 deletions(-)
> >
> > diff --git a/framework/packet.py b/framework/packet.py index
> > 976b82b..517c93d 100755
> > --- a/framework/packet.py
> > +++ b/framework/packet.py
> > @@ -33,7 +33,6 @@
> > Generic packet create, transmit and analyze module Base on
> > scapy(python program for packet manipulation) """
> > -
> > import os
> > import time
> > import sys
> > @@ -61,6 +60,7 @@ from scapy.route import * from scapy.packet import
> > bind_layers, Raw from scapy.sendrecv import sendp from scapy.arch
> > import get_if_hwaddr
> > +from pexpect import pxssh
> >
> > # load extension layers
> > exec_file = os.path.realpath(__file__) @@ -812,15 +812,31 @@ def
> > get_filter_cmd(filters=[]):
> > return ""
> >
> >
> > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > """
> > sniff all packets for certain port in certain seconds
> > """
> > param = ""
> > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> > -
> > stderr=subprocess.STDOUT,
> > - shell=True)
> > + remote_terminate = 0 # session remote terminate flag
> > +
> > + # target[] contain the remote machine info for ssh connection
> > + # target[0]: username
> > + # target[1]: ip address
> > + # target[2]: pass word
> > + if target:
> > + tcpdump_help_session=pxssh.pxssh()
> > + tcpdump_help_session.login(server=target[1], username=target[0],
> > + password=target[2],
> > original_prompt='[$#>]',
> > + login_timeout=20)
> > + tcpdump_help_session.sendline('tcpdump -h')
> > + tcpdump_help_session.prompt()
> > + tcpdump_help=tcpdump_help_session.before
> > + tcpdump_help_session.logout()
> > + else:
> > + 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:
> > @@ -850,22 +866,31 @@ def sniff_packets(intf, count=0, timeout=5,
> > filters=[]):
> > else:
> > cmd = sniff_cmd % options
> >
> > - args = shlex.split(cmd)
> > + if target:
> > + tcpdump_session=pxssh.pxssh()
> > + tcpdump_session.login(server=target[1], username=target[0],
> > + password=target[2],
> > original_prompt='[$#>]',
> > + login_timeout=20)
> > + tcpdump_session.sendline(cmd)
> > + pipe = tcpdump_session
> > + remote_terminate = 1
> > + else:
> > + args = shlex.split(cmd)
> > + pipe = subprocess.Popen(args)
> >
> > - pipe = subprocess.Popen(args)
> > index = str(time.time())
> > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > time.sleep(1)
> > return index
> >
> >
> > -def load_sniff_pcap(index=''):
> > +def load_sniff_pcap(index='', target=[]):
> > """
> > Stop sniffer and return pcap file
> > """
> > child_exit = False
> > if index in SNIFF_PIDS.keys():
> > - pipe, intf, timeout = SNIFF_PIDS[index]
> > + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> > time_elapse = int(time.time() - float(index))
> > while time_elapse < timeout:
> > if pipe.poll() is not None:
> [Lijuan] Exception happened here because poll is not an attribute of pxssh.
> > @@ -876,8 +901,22 @@ def load_sniff_pcap(index=''):
> > time_elapse += 1
> >
> > if not child_exit:
> > - pipe.send_signal(signal.SIGINT)
> > - pipe.wait()
> > + if remote_terminate == 1:
> > + tcpdump_quit_session=pxssh.pxssh()
> > + tcpdump_quit_session.login(server=target[1],
> > username=target[0],
> > + password=target[2],
> > original_prompt='[$#>]',
> > + login_timeout=20)
> > + tcpdump_quit_session.sendline('kill -2 $(pidof
> > tcpdump)')
> > + tcpdump_quit_session.prompt()
> > + tcpdump_quit_session.logout()
> > + # Teminate the tcpdump_session
> > + pipe.prompt()
> > + pipe.logout()
> > + pipe = None
> > +
> > + if pipe is not None:
> > + pipe.send_signal(signal.SIGINT)
> > + pipe.wait()
> >
> > # wait pcap file ready
> > time.sleep(1)
> > @@ -886,42 +925,6 @@ def load_sniff_pcap(index=''):
> > return ""
> >
> >
> > -def load_sniff_packets(index=''):
> > - """
> > - Stop sniffer and return packet objects
> > - """
> > - pkts = []
> > - child_exit = False
> > - if index in SNIFF_PIDS.keys():
> > - pipe, intf, timeout = SNIFF_PIDS[index]
> > - time_elapse = int(time.time() - float(index))
> > - while time_elapse < timeout:
> > - if pipe.poll() is not None:
> > - child_exit = True
> > - break
> > -
> > - time.sleep(1)
> > - time_elapse += 1
> > -
> > - if not child_exit:
> > - pipe.send_signal(signal.SIGINT)
> > - pipe.wait()
> > -
> > - # wait pcap file ready
> > - time.sleep(1)
> > - try:
> > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > - for pkt in cap_pkts:
> > - # packet gen should be scapy
> > - packet = Packet(tx_port=intf)
> > - packet.pktgen.assign_pkt(pkt)
> > - pkts.append(packet)
> > - except:
> > - pass
> > -
> > - return pkts
> > -
> > -
> > def load_pcapfile(filename=""):
> > pkts = []
> > try:
> > @@ -983,7 +986,6 @@ if __name__ == "__main__":
> > inst = sniff_packets("lo", timeout=5)
> > pkt = Packet(pkt_type='UDP')
> > pkt.send_pkt(tx_port='lo')
> > - pkts = load_sniff_packets(inst)
> >
> > pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> > pkt.send_pkt(tx_port='lo')
> > diff --git a/framework/tester.py b/framework/tester.py index
> > a775f68..c5b705d 100755
> > --- a/framework/tester.py
> > +++ b/framework/tester.py
> > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> >
> > import re
> > import subprocess
> > +import os
> > from time import sleep
> > from settings import NICS, load_global_setting, PERF_SETTING from
> > crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > module = __import__("packet")
> > pkt_c = getattr(module, "Packet")
> > send_f = getattr(module, "send_packets")
> > - sniff_f = getattr(module, "sniff_packets")
> > - load_f = getattr(module, "load_sniff_packets")
> > compare_f = getattr(module, "compare_pktload")
> > strip_f = getattr(module, "strip_pktload")
> > save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@
> > class Tester(Crb):
> >
> > # send and sniff packets
> > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> > - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> > filters=
> > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > + count=pktnum, timeout=timeout, filters=
> > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > {'layer': 'network', 'config': {'dstport': '65535'}}])
> > rx_inst[rxport] = inst
> > @@ -627,7 +626,7 @@ class Tester(Crb):
> > # Verify all packets
> > prev_id = -1
> > for txport, rxport in portList:
> > - recv_pkts = load_f(rx_inst[rxport])
> > + recv_pkts =
> > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> >
> > # only report when recevied number not matched
> > if len(tx_pkts[txport]) > len(recv_pkts):
> > @@ -704,6 +703,47 @@ class Tester(Crb):
> > self.proc.kill()
> > self.proc = None
> >
> > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> > + """
> > + Wrapper for packet module sniff_packets
> > + """
> > + # load functions in packet module
> > + module = __import__("packet")
> > + sniff_f = getattr(module, "sniff_packets")
> > +
> > + target=[]
> > + target.append(self.get_username())
> > + target.append(self.get_ip_address())
> > + target.append(self.get_password())
> > + return sniff_f(intf, count, timeout, filters, target)
> > +
> > + def load_tcpdump_sniff_pcap(self, index=''):
> > + """
> > + Wrapper for packet module load_sniff_pcap
> > + """
> > + # load functions in packet module
> > + module = __import__("packet")
> > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > +
> > + target=[]
> > + target.append(self.get_username())
> > + target.append(self.get_ip_address())
> > + target.append(self.get_password())
> > + pcap = load_pcap_f(index, target)
> > + self.session.copy_file_from(pcap)
> > +
> > + return pcap.split(os.sep)[-1]
> > +
> > + def load_tcpdump_sniff_packets(self, index=''):
> > + """
> > + Wrapper for packet module load_pcapfile
> > + """
> > + # load functions in packet module
> > + packet = __import__("packet")
> > + file = self.load_tcpdump_sniff_pcap(index)
> > +
> > + return packet.load_pcapfile(file)
> > +
> > def kill_all(self, killall=False):
> > """
> > Kill all scapy process or DPDK application on tester.
> > --
> > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine
2018-10-18 10:00 ` Phil Yang (Arm Technology China)
@ 2018-10-19 9:29 ` Phil Yang (Arm Technology China)
0 siblings, 0 replies; 124+ messages in thread
From: Phil Yang (Arm Technology China) @ 2018-10-19 9:29 UTC (permalink / raw)
To: Phil Yang (Arm Technology China), Tu, Lijuan, dts; +Cc: nd
Hi Lijuan,
I have sent out the 7th version of this single patch. Other patches in this series kept on the 6th version.
Please review it.
Thanks,
Phil Yang
> -----Original Message-----
> From: dts <dts-bounces@dpdk.org> On Behalf Of Phil Yang (Arm Technology
> China)
> Sent: Thursday, October 18, 2018 6:00 PM
> To: Tu, Lijuan <lijuan.tu@intel.com>; dts@dpdk.org
> Cc: nd <nd@arm.com>
> Subject: Re: [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to
> specify running machine
>
> Hi Lijuan,
>
> Agree.
>
> I can sanity the patch in the new version.
>
> Thanks,
> Phil Yang
>
> > -----Original Message-----
> > From: Tu, Lijuan <lijuan.tu@intel.com>
> > Sent: Thursday, October 18, 2018 5:15 PM
> > To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; dts@dpdk.org
> > Cc: nd <nd@arm.com>
> > Subject: RE: [PATCH v6 01/22] framework/packet: support packet sniffer
> > to specify running machine
> >
> > Hi Phil,
> > Poll is an attribute of Popen, but not pxssh.
> >
> > To make sniff function more clear, I prefer to remove the old code
> > instead of keeping them.
> > As in dts, we always pass the parameter target, the tester
> > information, we could raise exception when finding target is None.
> >
> > > -----Original Message-----
> > > From: phil.yang@arm.com [mailto:phil.yang@arm.com]
> > > Sent: Tuesday, October 16, 2018 2:20 PM
> > > To: dts@dpdk.org
> > > Cc: nd@arm.com; Tu, Lijuan <lijuan.tu@intel.com>
> > > Subject: [PATCH v6 01/22] framework/packet: support packet sniffer
> > > to specify running machine
> > >
> > > By default, the Tester is supposed to be the server which running
> > > DTS and the packet sniff methods are running on it.
> > > However, if DTS was not running on the Tester and the Tester is
> > > another remote server, so packet sniff methods cannot sniff Tester's
> > > packets correctly.
> > >
> > > This patch adds support for packet sniff methods to specify running
> > > machine and implements sniff packet methods in class tester.
> > >
> > > 1. Add parameter to sniff_packet and load_sniff_pcap methods to
> > > specify the running machine.
> > > 2. Remove load_sniff_packets method in packet.py.
> > > 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> > > load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> > > 4. Update tester.check_random_pkts method with
> > > tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets
> > > to make it execution on the Tester.
> > >
> > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > Suggested-by: Marvin Liu <yong.liu@intel.com>
> > > Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
> > > ---
> > > framework/packet.py | 100
> > > +++++++++++++++++++++++++++-------------------------
> > > framework/tester.py | 48 ++++++++++++++++++++++---
> > > 2 files changed, 95 insertions(+), 53 deletions(-)
> > >
> > > diff --git a/framework/packet.py b/framework/packet.py index
> > > 976b82b..517c93d 100755
> > > --- a/framework/packet.py
> > > +++ b/framework/packet.py
> > > @@ -33,7 +33,6 @@
> > > Generic packet create, transmit and analyze module Base on
> > > scapy(python program for packet manipulation) """
> > > -
> > > import os
> > > import time
> > > import sys
> > > @@ -61,6 +60,7 @@ from scapy.route import * from scapy.packet
> > > import bind_layers, Raw from scapy.sendrecv import sendp from
> > > scapy.arch import get_if_hwaddr
> > > +from pexpect import pxssh
> > >
> > > # load extension layers
> > > exec_file = os.path.realpath(__file__) @@ -812,15 +812,31 @@ def
> > > get_filter_cmd(filters=[]):
> > > return ""
> > >
> > >
> > > -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> > > +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> > > """
> > > sniff all packets for certain port in certain seconds
> > > """
> > > param = ""
> > > direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> > > - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> > > -
> > > stderr=subprocess.STDOUT,
> > > - shell=True)
> > > + remote_terminate = 0 # session remote terminate flag
> > > +
> > > + # target[] contain the remote machine info for ssh connection
> > > + # target[0]: username
> > > + # target[1]: ip address
> > > + # target[2]: pass word
> > > + if target:
> > > + tcpdump_help_session=pxssh.pxssh()
> > > + tcpdump_help_session.login(server=target[1], username=target[0],
> > > + password=target[2],
> > > original_prompt='[$#>]',
> > > + login_timeout=20)
> > > + tcpdump_help_session.sendline('tcpdump -h')
> > > + tcpdump_help_session.prompt()
> > > + tcpdump_help=tcpdump_help_session.before
> > > + tcpdump_help_session.logout()
> > > + else:
> > > + 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:
> > > @@ -850,22 +866,31 @@ def sniff_packets(intf, count=0, timeout=5,
> > > filters=[]):
> > > else:
> > > cmd = sniff_cmd % options
> > >
> > > - args = shlex.split(cmd)
> > > + if target:
> > > + tcpdump_session=pxssh.pxssh()
> > > + tcpdump_session.login(server=target[1], username=target[0],
> > > + password=target[2],
> > > original_prompt='[$#>]',
> > > + login_timeout=20)
> > > + tcpdump_session.sendline(cmd)
> > > + pipe = tcpdump_session
> > > + remote_terminate = 1
> > > + else:
> > > + args = shlex.split(cmd)
> > > + pipe = subprocess.Popen(args)
> > >
> > > - pipe = subprocess.Popen(args)
> > > index = str(time.time())
> > > - SNIFF_PIDS[index] = (pipe, intf, timeout)
> > > + SNIFF_PIDS[index] = (pipe, intf, timeout, remote_terminate)
> > > time.sleep(1)
> > > return index
> > >
> > >
> > > -def load_sniff_pcap(index=''):
> > > +def load_sniff_pcap(index='', target=[]):
> > > """
> > > Stop sniffer and return pcap file
> > > """
> > > child_exit = False
> > > if index in SNIFF_PIDS.keys():
> > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > + pipe, intf, timeout, remote_terminate = SNIFF_PIDS[index]
> > > time_elapse = int(time.time() - float(index))
> > > while time_elapse < timeout:
> > > if pipe.poll() is not None:
> > [Lijuan] Exception happened here because poll is not an attribute of pxssh.
> > > @@ -876,8 +901,22 @@ def load_sniff_pcap(index=''):
> > > time_elapse += 1
> > >
> > > if not child_exit:
> > > - pipe.send_signal(signal.SIGINT)
> > > - pipe.wait()
> > > + if remote_terminate == 1:
> > > + tcpdump_quit_session=pxssh.pxssh()
> > > + tcpdump_quit_session.login(server=target[1],
> > > username=target[0],
> > > + password=target[2],
> > > original_prompt='[$#>]',
> > > + login_timeout=20)
> > > + tcpdump_quit_session.sendline('kill -2 $(pidof
> > > tcpdump)')
> > > + tcpdump_quit_session.prompt()
> > > + tcpdump_quit_session.logout()
> > > + # Teminate the tcpdump_session
> > > + pipe.prompt()
> > > + pipe.logout()
> > > + pipe = None
> > > +
> > > + if pipe is not None:
> > > + pipe.send_signal(signal.SIGINT)
> > > + pipe.wait()
> > >
> > > # wait pcap file ready
> > > time.sleep(1)
> > > @@ -886,42 +925,6 @@ def load_sniff_pcap(index=''):
> > > return ""
> > >
> > >
> > > -def load_sniff_packets(index=''):
> > > - """
> > > - Stop sniffer and return packet objects
> > > - """
> > > - pkts = []
> > > - child_exit = False
> > > - if index in SNIFF_PIDS.keys():
> > > - pipe, intf, timeout = SNIFF_PIDS[index]
> > > - time_elapse = int(time.time() - float(index))
> > > - while time_elapse < timeout:
> > > - if pipe.poll() is not None:
> > > - child_exit = True
> > > - break
> > > -
> > > - time.sleep(1)
> > > - time_elapse += 1
> > > -
> > > - if not child_exit:
> > > - pipe.send_signal(signal.SIGINT)
> > > - pipe.wait()
> > > -
> > > - # wait pcap file ready
> > > - time.sleep(1)
> > > - try:
> > > - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> > > - for pkt in cap_pkts:
> > > - # packet gen should be scapy
> > > - packet = Packet(tx_port=intf)
> > > - packet.pktgen.assign_pkt(pkt)
> > > - pkts.append(packet)
> > > - except:
> > > - pass
> > > -
> > > - return pkts
> > > -
> > > -
> > > def load_pcapfile(filename=""):
> > > pkts = []
> > > try:
> > > @@ -983,7 +986,6 @@ if __name__ == "__main__":
> > > inst = sniff_packets("lo", timeout=5)
> > > pkt = Packet(pkt_type='UDP')
> > > pkt.send_pkt(tx_port='lo')
> > > - pkts = load_sniff_packets(inst)
> > >
> > > pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> > > pkt.send_pkt(tx_port='lo')
> > > diff --git a/framework/tester.py b/framework/tester.py index
> > > a775f68..c5b705d 100755
> > > --- a/framework/tester.py
> > > +++ b/framework/tester.py
> > > @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
> > >
> > > import re
> > > import subprocess
> > > +import os
> > > from time import sleep
> > > from settings import NICS, load_global_setting, PERF_SETTING from
> > > crb import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> > > module = __import__("packet")
> > > pkt_c = getattr(module, "Packet")
> > > send_f = getattr(module, "send_packets")
> > > - sniff_f = getattr(module, "sniff_packets")
> > > - load_f = getattr(module, "load_sniff_packets")
> > > compare_f = getattr(module, "compare_pktload")
> > > strip_f = getattr(module, "strip_pktload")
> > > save_f = getattr(module, "save_packets") @@ -606,7 +605,7
> > > @@ class Tester(Crb):
> > >
> > > # send and sniff packets
> > > save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> > > - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> > > filters=
> > > + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> > > + count=pktnum, timeout=timeout, filters=
> > > [{'layer': 'network', 'config': {'srcport': '65535'}},
> > > {'layer': 'network', 'config': {'dstport': '65535'}}])
> > > rx_inst[rxport] = inst
> > > @@ -627,7 +626,7 @@ class Tester(Crb):
> > > # Verify all packets
> > > prev_id = -1
> > > for txport, rxport in portList:
> > > - recv_pkts = load_f(rx_inst[rxport])
> > > + recv_pkts =
> > > + self.load_tcpdump_sniff_packets(rx_inst[rxport])
> > >
> > > # only report when recevied number not matched
> > > if len(tx_pkts[txport]) > len(recv_pkts):
> > > @@ -704,6 +703,47 @@ class Tester(Crb):
> > > self.proc.kill()
> > > self.proc = None
> > >
> > > + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> > > + """
> > > + Wrapper for packet module sniff_packets
> > > + """
> > > + # load functions in packet module
> > > + module = __import__("packet")
> > > + sniff_f = getattr(module, "sniff_packets")
> > > +
> > > + target=[]
> > > + target.append(self.get_username())
> > > + target.append(self.get_ip_address())
> > > + target.append(self.get_password())
> > > + return sniff_f(intf, count, timeout, filters, target)
> > > +
> > > + def load_tcpdump_sniff_pcap(self, index=''):
> > > + """
> > > + Wrapper for packet module load_sniff_pcap
> > > + """
> > > + # load functions in packet module
> > > + module = __import__("packet")
> > > + load_pcap_f = getattr(module, "load_sniff_pcap")
> > > +
> > > + target=[]
> > > + target.append(self.get_username())
> > > + target.append(self.get_ip_address())
> > > + target.append(self.get_password())
> > > + pcap = load_pcap_f(index, target)
> > > + self.session.copy_file_from(pcap)
> > > +
> > > + return pcap.split(os.sep)[-1]
> > > +
> > > + def load_tcpdump_sniff_packets(self, index=''):
> > > + """
> > > + Wrapper for packet module load_pcapfile
> > > + """
> > > + # load functions in packet module
> > > + packet = __import__("packet")
> > > + file = self.load_tcpdump_sniff_pcap(index)
> > > +
> > > + return packet.load_pcapfile(file)
> > > +
> > > def kill_all(self, killall=False):
> > > """
> > > Kill all scapy process or DPDK application on tester.
> > > --
> > > 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* [dts] [PATCH v7] framework/packet: support packet sniffer to specify running machine
2018-10-16 6:19 ` [dts] [PATCH v6 " Phil Yang
` (21 preceding siblings ...)
2018-10-18 9:15 ` [dts] [PATCH v6 01/22] framework/packet: support packet sniffer to specify running machine Tu, Lijuan
@ 2018-10-19 9:25 ` Phil Yang
2018-10-23 9:44 ` Tu, Lijuan
22 siblings, 1 reply; 124+ messages in thread
From: Phil Yang @ 2018-10-19 9:25 UTC (permalink / raw)
To: dts; +Cc: nd, lijuan.tu
By default, the Tester is supposed to be the server which running DTS
and the packet sniff methods are running on it.
However, if DTS was not running on the Tester and the Tester is another
remote server, so packet sniff methods cannot sniff Tester's packets
correctly.
This patch adds support for packet sniff methods to specify running
machine and implements sniff packet methods in class tester.
1. Add parameter to sniff_packet and load_sniff_pcap methods to specify
the running machine.
2. Remove load_sniff_packets method in packet.py.
3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
load_tcpdump_sniff_packets for class tester with the new sniff_packet
API.
4. Update tester.check_random_pkts method with
tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
make it execution on the Tester.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Suggested-by: Marvin Liu <yong.liu@intel.com>
Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
---
framework/packet.py | 97 +++++++++++++++++++++++++----------------------------
framework/tester.py | 48 +++++++++++++++++++++++---
2 files changed, 89 insertions(+), 56 deletions(-)
diff --git a/framework/packet.py b/framework/packet.py
index 976b82b..d5b8517 100755
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -33,7 +33,6 @@
Generic packet create, transmit and analyze module
Base on scapy(python program for packet manipulation)
"""
-
import os
import time
import sys
@@ -61,6 +60,7 @@ from scapy.route import *
from scapy.packet import bind_layers, Raw
from scapy.sendrecv import sendp
from scapy.arch import get_if_hwaddr
+from pexpect import pxssh
# load extension layers
exec_file = os.path.realpath(__file__)
@@ -812,15 +812,26 @@ def get_filter_cmd(filters=[]):
return ""
-def sniff_packets(intf, count=0, timeout=5, filters=[]):
+def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
"""
sniff all packets for certain port in certain seconds
"""
param = ""
direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
- tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
- stderr=subprocess.STDOUT,
- shell=True)
+
+ try:
+ tcpdump_help_session=pxssh.pxssh()
+ tcpdump_help_session.login(server=target[0], username=target[1],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_help_session.sendline('tcpdump -h')
+ tcpdump_help_session.prompt()
+ tcpdump_help=tcpdump_help_session.before
+ tcpdump_help_session.logout()
+ except pxssh.ExceptionPxssh as e:
+ print ('pxssh failed on login.')
+ print (e)
+
for line in tcpdump_help.split('\n'):
m = re.match(direct_param, line)
if m:
@@ -850,16 +861,24 @@ def sniff_packets(intf, count=0, timeout=5, filters=[]):
else:
cmd = sniff_cmd % options
- args = shlex.split(cmd)
+ try:
+ tcpdump_session=pxssh.pxssh()
+ tcpdump_session.login(server=target[0], username=target[1],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_session.sendline(cmd)
+ pipe = tcpdump_session
+ except pxssh.ExceptionPxssh as e:
+ print ('pxssh failed on login.')
+ print (e)
- pipe = subprocess.Popen(args)
index = str(time.time())
SNIFF_PIDS[index] = (pipe, intf, timeout)
time.sleep(1)
return index
-def load_sniff_pcap(index=''):
+def load_sniff_pcap(index='', target=[]):
"""
Stop sniffer and return pcap file
"""
@@ -868,58 +887,36 @@ def load_sniff_pcap(index=''):
pipe, intf, timeout = SNIFF_PIDS[index]
time_elapse = int(time.time() - float(index))
while time_elapse < timeout:
- if pipe.poll() is not None:
+ if pipe.prompt(timeout=1):
child_exit = True
break
- time.sleep(1)
time_elapse += 1
if not child_exit:
- pipe.send_signal(signal.SIGINT)
- pipe.wait()
-
- # wait pcap file ready
- time.sleep(1)
- return "/tmp/sniff_%s.pcap" % intf
-
- return ""
-
-
-def load_sniff_packets(index=''):
- """
- Stop sniffer and return packet objects
- """
- pkts = []
- child_exit = False
- if index in SNIFF_PIDS.keys():
- pipe, intf, timeout = SNIFF_PIDS[index]
- time_elapse = int(time.time() - float(index))
- while time_elapse < timeout:
- if pipe.poll() is not None:
+ try:
+ # Stop Tcpdump on the target server
+ tcpdump_quit_session=pxssh.pxssh()
+ tcpdump_quit_session.login(server=target[0], username=target[1],
+ password=target[2], original_prompt='[$#>]',
+ login_timeout=20)
+ tcpdump_quit_session.sendline('kill -2 $(pidof tcpdump)')
+ tcpdump_quit_session.prompt()
+ tcpdump_quit_session.logout()
child_exit = True
- break
+ except pxssh.ExceptionPxssh as e:
+ print ('pxssh failed on login.')
+ print (e)
- time.sleep(1)
- time_elapse += 1
-
- if not child_exit:
- pipe.send_signal(signal.SIGINT)
- pipe.wait()
+ # Close the Tcpdump_session
+ pipe.prompt()
+ pipe.logout()
# wait pcap file ready
time.sleep(1)
- try:
- cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
- for pkt in cap_pkts:
- # packet gen should be scapy
- packet = Packet(tx_port=intf)
- packet.pktgen.assign_pkt(pkt)
- pkts.append(packet)
- except:
- pass
+ return "/tmp/sniff_%s.pcap" % intf
- return pkts
+ return ""
def load_pcapfile(filename=""):
@@ -978,12 +975,8 @@ def strip_pktload(pkt=None, layer="L2"):
###############################################################################
###############################################################################
if __name__ == "__main__":
- inst = sniff_packets("lo", timeout=5, filters=[{'layer': 'ether',
- 'config': {'dst': 'FF:FF:FF:FF:FF:FF'}}])
- inst = sniff_packets("lo", timeout=5)
pkt = Packet(pkt_type='UDP')
pkt.send_pkt(tx_port='lo')
- pkts = load_sniff_packets(inst)
pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
pkt.send_pkt(tx_port='lo')
diff --git a/framework/tester.py b/framework/tester.py
index a775f68..4e651a1 100755
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -35,6 +35,7 @@ Interface for bulk traffic generators.
import re
import subprocess
+import os
from time import sleep
from settings import NICS, load_global_setting, PERF_SETTING
from crb import Crb
@@ -560,8 +561,6 @@ class Tester(Crb):
module = __import__("packet")
pkt_c = getattr(module, "Packet")
send_f = getattr(module, "send_packets")
- sniff_f = getattr(module, "sniff_packets")
- load_f = getattr(module, "load_sniff_packets")
compare_f = getattr(module, "compare_pktload")
strip_f = getattr(module, "strip_pktload")
save_f = getattr(module, "save_packets")
@@ -606,7 +605,7 @@ class Tester(Crb):
# send and sniff packets
save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
- inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout, filters=
+ inst = self.tcpdump_sniff_packets(intf=rxIntf, count=pktnum, timeout=timeout, filters=
[{'layer': 'network', 'config': {'srcport': '65535'}},
{'layer': 'network', 'config': {'dstport': '65535'}}])
rx_inst[rxport] = inst
@@ -627,7 +626,7 @@ class Tester(Crb):
# Verify all packets
prev_id = -1
for txport, rxport in portList:
- recv_pkts = load_f(rx_inst[rxport])
+ recv_pkts = self.load_tcpdump_sniff_packets(rx_inst[rxport])
# only report when recevied number not matched
if len(tx_pkts[txport]) > len(recv_pkts):
@@ -704,6 +703,47 @@ class Tester(Crb):
self.proc.kill()
self.proc = None
+ def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
+ """
+ Wrapper for packet module sniff_packets
+ """
+ # load functions in packet module
+ module = __import__("packet")
+ sniff_f = getattr(module, "sniff_packets")
+
+ target=[]
+ target.append(self.get_ip_address())
+ target.append(self.get_username())
+ target.append(self.get_password())
+ return sniff_f(intf, count, timeout, filters, target)
+
+ def load_tcpdump_sniff_pcap(self, index=''):
+ """
+ Wrapper for packet module load_sniff_pcap
+ """
+ # load functions in packet module
+ module = __import__("packet")
+ load_pcap_f = getattr(module, "load_sniff_pcap")
+
+ target=[]
+ target.append(self.get_ip_address())
+ target.append(self.get_username())
+ target.append(self.get_password())
+ pcap = load_pcap_f(index, target)
+ self.session.copy_file_from(pcap)
+
+ return pcap.split(os.sep)[-1]
+
+ def load_tcpdump_sniff_packets(self, index=''):
+ """
+ Wrapper for packet module load_pcapfile
+ """
+ # load functions in packet module
+ packet = __import__("packet")
+ file = self.load_tcpdump_sniff_pcap(index)
+
+ return packet.load_pcapfile(file)
+
def kill_all(self, killall=False):
"""
Kill all scapy process or DPDK application on tester.
--
2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread
* Re: [dts] [PATCH v7] framework/packet: support packet sniffer to specify running machine
2018-10-19 9:25 ` [dts] [PATCH v7] " Phil Yang
@ 2018-10-23 9:44 ` Tu, Lijuan
0 siblings, 0 replies; 124+ messages in thread
From: Tu, Lijuan @ 2018-10-23 9:44 UTC (permalink / raw)
To: phil.yang, dts; +Cc: nd
Applied, thanks
> -----Original Message-----
> From: phil.yang@arm.com [mailto:phil.yang@arm.com]
> Sent: Friday, October 19, 2018 5:25 PM
> To: dts@dpdk.org
> Cc: nd@arm.com; Tu, Lijuan <lijuan.tu@intel.com>
> Subject: [PATCH v7] framework/packet: support packet sniffer to specify
> running machine
>
> By default, the Tester is supposed to be the server which running DTS and the
> packet sniff methods are running on it.
> However, if DTS was not running on the Tester and the Tester is another
> remote server, so packet sniff methods cannot sniff Tester's packets
> correctly.
>
> This patch adds support for packet sniff methods to specify running machine
> and implements sniff packet methods in class tester.
>
> 1. Add parameter to sniff_packet and load_sniff_pcap methods to specify
> the running machine.
> 2. Remove load_sniff_packets method in packet.py.
> 3. Add tcpdump_sniff_packets, load_tcpdump_sniff_pcap and
> load_tcpdump_sniff_packets for class tester with the new sniff_packet API.
> 4. Update tester.check_random_pkts method with
> tester.tcpdump_sniff_packets and tester.load_tcpdump_sniff_packets to
> make it execution on the Tester.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Suggested-by: Marvin Liu <yong.liu@intel.com>
> Suggested-by: Tu Lijuan <lijuan.tu@intel.com>
> ---
> framework/packet.py | 97
> +++++++++++++++++++++++++----------------------------
> framework/tester.py | 48 +++++++++++++++++++++++---
> 2 files changed, 89 insertions(+), 56 deletions(-)
>
> diff --git a/framework/packet.py b/framework/packet.py index
> 976b82b..d5b8517 100755
> --- a/framework/packet.py
> +++ b/framework/packet.py
> @@ -33,7 +33,6 @@
> Generic packet create, transmit and analyze module Base on
> scapy(python program for packet manipulation) """
> -
> import os
> import time
> import sys
> @@ -61,6 +60,7 @@ from scapy.route import * from scapy.packet import
> bind_layers, Raw from scapy.sendrecv import sendp from scapy.arch
> import get_if_hwaddr
> +from pexpect import pxssh
>
> # load extension layers
> exec_file = os.path.realpath(__file__)
> @@ -812,15 +812,26 @@ def get_filter_cmd(filters=[]):
> return ""
>
>
> -def sniff_packets(intf, count=0, timeout=5, filters=[]):
> +def sniff_packets(intf, count=0, timeout=5, filters=[], target=[]):
> """
> sniff all packets for certain port in certain seconds
> """
> param = ""
> direct_param = r"(\s+)\[ (\S+) in\|out\|inout \]"
> - tcpdump_help = subprocess.check_output("tcpdump -h; echo 0",
> -
> stderr=subprocess.STDOUT,
> - shell=True)
> +
> + try:
> + tcpdump_help_session=pxssh.pxssh()
> + tcpdump_help_session.login(server=target[0],
> username=target[1],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_help_session.sendline('tcpdump -h')
> + tcpdump_help_session.prompt()
> + tcpdump_help=tcpdump_help_session.before
> + tcpdump_help_session.logout()
> + except pxssh.ExceptionPxssh as e:
> + print ('pxssh failed on login.')
> + print (e)
> +
> for line in tcpdump_help.split('\n'):
> m = re.match(direct_param, line)
> if m:
> @@ -850,16 +861,24 @@ def sniff_packets(intf, count=0, timeout=5,
> filters=[]):
> else:
> cmd = sniff_cmd % options
>
> - args = shlex.split(cmd)
> + try:
> + tcpdump_session=pxssh.pxssh()
> + tcpdump_session.login(server=target[0], username=target[1],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_session.sendline(cmd)
> + pipe = tcpdump_session
> + except pxssh.ExceptionPxssh as e:
> + print ('pxssh failed on login.')
> + print (e)
>
> - pipe = subprocess.Popen(args)
> index = str(time.time())
> SNIFF_PIDS[index] = (pipe, intf, timeout)
> time.sleep(1)
> return index
>
>
> -def load_sniff_pcap(index=''):
> +def load_sniff_pcap(index='', target=[]):
> """
> Stop sniffer and return pcap file
> """
> @@ -868,58 +887,36 @@ def load_sniff_pcap(index=''):
> pipe, intf, timeout = SNIFF_PIDS[index]
> time_elapse = int(time.time() - float(index))
> while time_elapse < timeout:
> - if pipe.poll() is not None:
> + if pipe.prompt(timeout=1):
> child_exit = True
> break
>
> - time.sleep(1)
> time_elapse += 1
>
> if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> -
> - # wait pcap file ready
> - time.sleep(1)
> - return "/tmp/sniff_%s.pcap" % intf
> -
> - return ""
> -
> -
> -def load_sniff_packets(index=''):
> - """
> - Stop sniffer and return packet objects
> - """
> - pkts = []
> - child_exit = False
> - if index in SNIFF_PIDS.keys():
> - pipe, intf, timeout = SNIFF_PIDS[index]
> - time_elapse = int(time.time() - float(index))
> - while time_elapse < timeout:
> - if pipe.poll() is not None:
> + try:
> + # Stop Tcpdump on the target server
> + tcpdump_quit_session=pxssh.pxssh()
> + tcpdump_quit_session.login(server=target[0],
> username=target[1],
> + password=target[2],
> original_prompt='[$#>]',
> + login_timeout=20)
> + tcpdump_quit_session.sendline('kill -2 $(pidof
> tcpdump)')
> + tcpdump_quit_session.prompt()
> + tcpdump_quit_session.logout()
> child_exit = True
> - break
> + except pxssh.ExceptionPxssh as e:
> + print ('pxssh failed on login.')
> + print (e)
>
> - time.sleep(1)
> - time_elapse += 1
> -
> - if not child_exit:
> - pipe.send_signal(signal.SIGINT)
> - pipe.wait()
> + # Close the Tcpdump_session
> + pipe.prompt()
> + pipe.logout()
>
> # wait pcap file ready
> time.sleep(1)
> - try:
> - cap_pkts = rdpcap("/tmp/sniff_%s.pcap" % intf)
> - for pkt in cap_pkts:
> - # packet gen should be scapy
> - packet = Packet(tx_port=intf)
> - packet.pktgen.assign_pkt(pkt)
> - pkts.append(packet)
> - except:
> - pass
> + return "/tmp/sniff_%s.pcap" % intf
>
> - return pkts
> + return ""
>
>
> def load_pcapfile(filename=""):
> @@ -978,12 +975,8 @@ def strip_pktload(pkt=None, layer="L2"):
>
> ##############################################################
> #################
>
> ##############################################################
> #################
> if __name__ == "__main__":
> - inst = sniff_packets("lo", timeout=5, filters=[{'layer': 'ether',
> - 'config': {'dst': 'FF:FF:FF:FF:FF:FF'}}])
> - inst = sniff_packets("lo", timeout=5)
> pkt = Packet(pkt_type='UDP')
> pkt.send_pkt(tx_port='lo')
> - pkts = load_sniff_packets(inst)
>
> pkt = Packet(pkt_type='UDP', pkt_len=1500, ran_payload=True)
> pkt.send_pkt(tx_port='lo')
> diff --git a/framework/tester.py b/framework/tester.py index
> a775f68..4e651a1 100755
> --- a/framework/tester.py
> +++ b/framework/tester.py
> @@ -35,6 +35,7 @@ Interface for bulk traffic generators.
>
> import re
> import subprocess
> +import os
> from time import sleep
> from settings import NICS, load_global_setting, PERF_SETTING from crb
> import Crb @@ -560,8 +561,6 @@ class Tester(Crb):
> module = __import__("packet")
> pkt_c = getattr(module, "Packet")
> send_f = getattr(module, "send_packets")
> - sniff_f = getattr(module, "sniff_packets")
> - load_f = getattr(module, "load_sniff_packets")
> compare_f = getattr(module, "compare_pktload")
> strip_f = getattr(module, "strip_pktload")
> save_f = getattr(module, "save_packets") @@ -606,7 +605,7 @@
> class Tester(Crb):
>
> # send and sniff packets
> save_f(pkts=pkts, filename="/tmp/%s_tx.pcap" % txIntf)
> - inst = sniff_f(intf=rxIntf, count=pktnum, timeout=timeout,
> filters=
> + inst = self.tcpdump_sniff_packets(intf=rxIntf,
> + count=pktnum, timeout=timeout, filters=
> [{'layer': 'network', 'config': {'srcport': '65535'}},
> {'layer': 'network', 'config': {'dstport': '65535'}}])
> rx_inst[rxport] = inst
> @@ -627,7 +626,7 @@ class Tester(Crb):
> # Verify all packets
> prev_id = -1
> for txport, rxport in portList:
> - recv_pkts = load_f(rx_inst[rxport])
> + recv_pkts =
> + self.load_tcpdump_sniff_packets(rx_inst[rxport])
>
> # only report when recevied number not matched
> if len(tx_pkts[txport]) > len(recv_pkts):
> @@ -704,6 +703,47 @@ class Tester(Crb):
> self.proc.kill()
> self.proc = None
>
> + def tcpdump_sniff_packets(self, intf, count=0, timeout=5, filters=[]):
> + """
> + Wrapper for packet module sniff_packets
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + sniff_f = getattr(module, "sniff_packets")
> +
> + target=[]
> + target.append(self.get_ip_address())
> + target.append(self.get_username())
> + target.append(self.get_password())
> + return sniff_f(intf, count, timeout, filters, target)
> +
> + def load_tcpdump_sniff_pcap(self, index=''):
> + """
> + Wrapper for packet module load_sniff_pcap
> + """
> + # load functions in packet module
> + module = __import__("packet")
> + load_pcap_f = getattr(module, "load_sniff_pcap")
> +
> + target=[]
> + target.append(self.get_ip_address())
> + target.append(self.get_username())
> + target.append(self.get_password())
> + pcap = load_pcap_f(index, target)
> + self.session.copy_file_from(pcap)
> +
> + return pcap.split(os.sep)[-1]
> +
> + def load_tcpdump_sniff_packets(self, index=''):
> + """
> + Wrapper for packet module load_pcapfile
> + """
> + # load functions in packet module
> + packet = __import__("packet")
> + file = self.load_tcpdump_sniff_pcap(index)
> +
> + return packet.load_pcapfile(file)
> +
> def kill_all(self, killall=False):
> """
> Kill all scapy process or DPDK application on tester.
> --
> 2.7.4
^ permalink raw reply [flat|nested] 124+ messages in thread