Skip to content

Commit e95a415

Browse files
authored
Merge pull request sonic-net#535 from mssonicbld/cherry/msft-202412/21070
[action] [PR:21070] [sonic-mgmt-docker-image] Support ptf dataplane packet poll with multiple ptf nn agents connection
2 parents 48aad69 + 0a96741 commit e95a415

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
From 688c4d11a00269beaf22eb6f2cccba410bfb2856 Mon Sep 17 00:00:00 2001
2+
From: wenda <[email protected]>
3+
Date: Fri, 6 Dec 2024 07:25:30 +0000
4+
Subject: [PATCH] extend dataplane poll method to support multi ptf nn agents
5+
connections
6+
7+
---
8+
src/ptf/dataplane.py | 31 ++++++++++++++++++++-----------
9+
1 file changed, 20 insertions(+), 11 deletions(-)
10+
11+
diff --git a/src/ptf/dataplane.py b/src/ptf/dataplane.py
12+
index a1c1b3f..009ac2f 100644
13+
--- a/src/ptf/dataplane.py
14+
+++ b/src/ptf/dataplane.py
15+
@@ -738,40 +738,49 @@ class DataPlane(Thread):
16+
)
17+
return bytes
18+
19+
- def oldest_port_number(self, device):
20+
+ def get_oldest_tuple(self, device):
21+
"""
22+
- Returns the port number with the oldest packet,
23+
+ Returns the device number and port number with the oldest packet,
24+
or None if no packets are queued.
25+
+ When device is specified, only returns the oldest packet from that device.
26+
"""
27+
- min_port_number = None
28+
+ min_device_number, min_port_number = None, None
29+
min_time = float("inf")
30+
for port_id, queue in list(self.packet_queues.items()):
31+
- if port_id[0] != device:
32+
+ if device and port_id[0] != device:
33+
continue
34+
if queue and queue[0][1] < min_time:
35+
min_time = queue[0][1]
36+
+ min_device_number = port_id[0]
37+
min_port_number = port_id[1]
38+
- return min_port_number
39+
+ return min_device_number, min_port_number
40+
41+
# Dequeues and yields packets in the order they were received.
42+
# Yields (port, packet, received time).
43+
# If port is not specified yields packets from all ports.
44+
+ # If port and device are both not specified yields packets from all devices and all ports
45+
def packets(self, device, port=None):
46+
while True:
47+
- if port is None:
48+
- rcv_port = self.oldest_port_number(device)
49+
- else:
50+
- rcv_port = port
51+
+ rcv_device, rcv_port = device, port
52+
+ if device is None and port is None:
53+
+ rcv_device, rcv_port = self.get_oldest_tuple(None)
54+
+ elif port is None:
55+
+ _, rcv_port = self.get_oldest_tuple(device)
56+
+ elif device is None:
57+
+ self.logger.error(
58+
+ "ambiguous tuple given. device is None, while port is %s" % (port)
59+
+ )
60+
+ break
61+
62+
if rcv_port == None:
63+
self.logger.debug("Out of packets on all ports")
64+
break
65+
66+
- queue = self.packet_queues[(device, rcv_port)]
67+
+ queue = self.packet_queues[(rcv_device, rcv_port)]
68+
69+
if len(queue) == 0:
70+
self.logger.debug(
71+
- "Out of packets on device %d, port %d", device, rcv_port
72+
+ "Out of packets on device %d, port %d", rcv_device, rcv_port
73+
)
74+
break
75+
76+
--
77+
2.47.0

dockers/docker-sonic-mgmt/Dockerfile.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,13 @@ USER root
269269
WORKDIR /azp
270270
COPY start.sh \
271271
0001-Fix-getattr-AttributeError-in-multi-thread-scenario.patch \
272+
0002-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
272273
./
273274
RUN chmod +x start.sh \
274275
&& ln -sf /usr/bin/python3 /usr/bin/python \
275276
&& ln -sf `which pip3` /usr/bin/pip \
276277
&& ln -sf `which pip3` /usr/local/sbin/pip \
278+
&& 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 \
277279
&& 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
278280

279281
USER $user

0 commit comments

Comments
 (0)