Skip to content

Commit a42cff3

Browse files
authored
[sonic-mgmt-docker-image] Support ptf dataplane packet poll with multiple ptf nn agents connection (#21070)
When testing sonic with ptf dataplane connecting multiple ptf nn agents, some cases will fail because of packets queue in ptf were not polled thoroughly. This is a bug or missing feature in ptf: p4lang/ptf#207 as a short term quick fix, this PR will patch the ptf-py3 package and unblock our qualification process
1 parent 7e03462 commit a42cff3

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
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 <wendachu@microsoft.com>
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

+2
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ USER root
271271
WORKDIR /azp
272272
COPY start.sh \
273273
0001-Fix-getattr-AttributeError-in-multi-thread-scenario.patch \
274+
0002-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
274275
./
275276
RUN chmod +x start.sh \
276277
&& ln -sf /usr/bin/python3 /usr/bin/python \
277278
&& ln -sf `which pip3` /usr/bin/pip \
278279
&& ln -sf `which pip3` /usr/local/sbin/pip \
280+
&& 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 \
279281
&& 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
280282

281283
USER $user

0 commit comments

Comments
 (0)