1+ From 688c4d11a00269beaf22eb6f2cccba410bfb2856 Mon Sep 17 00:00:00 2001
2+ 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
0 commit comments