Skip to content

Commit 9c8ca3b

Browse files
authored
[sonic-mgmt-docker-image] Add packet mask counters in ptf dataplane (#22307)
Why I did it We need to count packets we care about on ptf dataplane. How I did it Add a specific counter in ptf datplane, user can create counter with packet mask, so ptf dataplane can count packets that matching specific mask. How to verify it Tested on testbed Sent 5 packets for each 100 ports and read counters.
1 parent c2affda commit 9c8ca3b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From a1e0c25218b5bac0adeebcbd95b29618b4cadf3d Mon Sep 17 00:00:00 2001
2+
From: wenda <[email protected]>
3+
Date: Fri, 11 Apr 2025 09:57:23 +0000
4+
Subject: [PATCH] 0003-add-dataplane-mask-counters-to-avoid-dataplane-noise
5+
6+
---
7+
src/ptf/dataplane.py | 17 +++++++++++++++++
8+
1 file changed, 17 insertions(+)
9+
10+
diff --git a/src/ptf/dataplane.py b/src/ptf/dataplane.py
11+
index a5d4664..0aee7ab 100644
12+
--- a/src/ptf/dataplane.py
13+
+++ b/src/ptf/dataplane.py
14+
@@ -574,6 +574,12 @@ class DataPlane(Thread):
15+
# counters of transmited packets
16+
self.tx_counters = defaultdict(int)
17+
18+
+ # rx/tx counters of packets that matching the packet mask
19+
+ # the key of dict is mask
20+
+ # the value is a dict of device number, port number to count
21+
+ self.mask_rx_cnt = {}
22+
+ self.mask_tx_cnt = {}
23+
+
24+
# cvar serves double duty as a regular top level lock and
25+
# as a condition variable
26+
self.cvar = Condition()
27+
@@ -665,6 +671,9 @@ class DataPlane(Thread):
28+
self.logger.debug("Discarding oldest packet to make room")
29+
queue.append((pkt, timestamp))
30+
self.rx_counters[(device_number, port_number)] += 1
31+
+ for mask, cnt in self.mask_rx_cnt.items():
32+
+ if match_exp_pkt(mask, pkt):
33+
+ cnt[(device_number, port_number)] += 1
34+
self.cvar.notify_all()
35+
36+
self.logger.info("Thread exit")
37+
@@ -731,6 +740,9 @@ class DataPlane(Thread):
38+
self.pcap_writer.write(packet, time.time(), device_number, port_number)
39+
bytes = self.ports[(device_number, port_number)].send(packet)
40+
self.tx_counters[(device_number, port_number)] += 1
41+
+ for mask, cnt in self.mask_tx_cnt.items():
42+
+ if match_exp_pkt(mask, packet):
43+
+ cnt[(device_number, port_number)] += 1
44+
if bytes != len(packet):
45+
self.logger.error(
46+
"Unhandled send error, length mismatch %d != %d" % (bytes, len(packet))
47+
@@ -1038,3 +1050,8 @@ class DataPlane(Thread):
48+
self.pcap_writer.close()
49+
self.pcap_writer = None
50+
self.cvar.notify_all()
51+
+
52+
+ def create_mask_counters(self, mask):
53+
+ """Create a new mask counters"""
54+
+ self.mask_rx_cnt[mask] = defaultdict(int)
55+
+ self.mask_tx_cnt[mask] = defaultdict(int)
56+
--
57+
2.49.0

dockers/docker-sonic-mgmt/Dockerfile.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,14 @@ WORKDIR /azp
280280
COPY start.sh \
281281
0001-Fix-getattr-AttributeError-in-multi-thread-scenario.patch \
282282
0002-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
283+
0003-add-dataplane-mask-counters-to-avoid-dataplane-noise.patch \
283284
./
284285
RUN chmod +x start.sh \
285286
&& ln -sf /usr/bin/python3 /usr/bin/python \
286287
&& ln -sf `which pip3` /usr/bin/pip \
287288
&& ln -sf `which pip3` /usr/local/sbin/pip \
288289
&& patch -u -b /usr/local/lib/python3.8/dist-packages/ptf/dataplane.py -i /azp/0002-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
290+
&& patch -u -b /usr/local/lib/python3.8/dist-packages/ptf/dataplane.py -i /azp/0003-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
289291
&& patch -u -b /usr/local/lib/python3.8/dist-packages/ansible/plugins/loader.py -i /azp/0001-Fix-getattr-AttributeError-in-multi-thread-scenario.patch
290292

291293
USER $user

0 commit comments

Comments
 (0)