Skip to content

Commit

Permalink
[sonic-mgmt-docker-image] Support ptf dataplane packet poll with mult…
Browse files Browse the repository at this point in the history
…iple ptf nn agents connection

<!--
     Please make sure you've read and understood our contributing guidelines:
     https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

     ** Make sure all your commits include a signature generated with `git commit -s` **

     If this is a bug fix, make sure your description includes "fixes #xxxx", or
     "closes #xxxx" or "resolves #xxxx"

     Please provide the following information:
-->

#### Why I did it
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.
##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
Support poll all devices in ptf dataplane.

#### How to verify it
Run tests using ptf dataplane on testbed

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 201811
- [ ] 201911
- [ ] 202006
- [ ] 202012
- [ ] 202106
- [ ] 202111
- [ ] 202205
- [ ] 202211
- [ ] 202305

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

#### A picture of a cute animal (not mandatory but encouraged)
  • Loading branch information
mssonicbld committed Jan 21, 2025
1 parent afeebee commit 0a96741
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From 688c4d11a00269beaf22eb6f2cccba410bfb2856 Mon Sep 17 00:00:00 2001
From: wenda <[email protected]>
Date: Fri, 6 Dec 2024 07:25:30 +0000
Subject: [PATCH] extend dataplane poll method to support multi ptf nn agents
connections

---
src/ptf/dataplane.py | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/ptf/dataplane.py b/src/ptf/dataplane.py
index a1c1b3f..009ac2f 100644
--- a/src/ptf/dataplane.py
+++ b/src/ptf/dataplane.py
@@ -738,40 +738,49 @@ class DataPlane(Thread):
)
return bytes

- def oldest_port_number(self, device):
+ def get_oldest_tuple(self, device):
"""
- Returns the port number with the oldest packet,
+ Returns the device number and port number with the oldest packet,
or None if no packets are queued.
+ When device is specified, only returns the oldest packet from that device.
"""
- min_port_number = None
+ min_device_number, min_port_number = None, None
min_time = float("inf")
for port_id, queue in list(self.packet_queues.items()):
- if port_id[0] != device:
+ if device and port_id[0] != device:
continue
if queue and queue[0][1] < min_time:
min_time = queue[0][1]
+ min_device_number = port_id[0]
min_port_number = port_id[1]
- return min_port_number
+ return min_device_number, min_port_number

# Dequeues and yields packets in the order they were received.
# Yields (port, packet, received time).
# If port is not specified yields packets from all ports.
+ # If port and device are both not specified yields packets from all devices and all ports
def packets(self, device, port=None):
while True:
- if port is None:
- rcv_port = self.oldest_port_number(device)
- else:
- rcv_port = port
+ rcv_device, rcv_port = device, port
+ if device is None and port is None:
+ rcv_device, rcv_port = self.get_oldest_tuple(None)
+ elif port is None:
+ _, rcv_port = self.get_oldest_tuple(device)
+ elif device is None:
+ self.logger.error(
+ "ambiguous tuple given. device is None, while port is %s" % (port)
+ )
+ break

if rcv_port == None:
self.logger.debug("Out of packets on all ports")
break

- queue = self.packet_queues[(device, rcv_port)]
+ queue = self.packet_queues[(rcv_device, rcv_port)]

if len(queue) == 0:
self.logger.debug(
- "Out of packets on device %d, port %d", device, rcv_port
+ "Out of packets on device %d, port %d", rcv_device, rcv_port
)
break

--
2.47.0
2 changes: 2 additions & 0 deletions dockers/docker-sonic-mgmt/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ USER root
WORKDIR /azp
COPY start.sh \
0001-Fix-getattr-AttributeError-in-multi-thread-scenario.patch \
0002-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch \
./
RUN chmod +x start.sh \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& ln -sf `which pip3` /usr/bin/pip \
&& ln -sf `which pip3` /usr/local/sbin/pip \
&& 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 \
&& 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

USER $user
Expand Down

0 comments on commit 0a96741

Please sign in to comment.