From dcd0ed81f3660b403d5a2868367314f94d1fcde5 Mon Sep 17 00:00:00 2001 From: Wenda Chu <32250288+w1nda@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:28:30 +0800 Subject: [PATCH 1/3] Create 0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch --- ...-poll-method-to-support-multi-ptf-nn.patch | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch diff --git a/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch b/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch new file mode 100644 index 000000000000..81d1e3179e2b --- /dev/null +++ b/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch @@ -0,0 +1,69 @@ +From c46fb401ab3d90c1829071b4b0933defbc6135dc Mon Sep 17 00:00:00 2001 +From: wenda +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 | 22 ++++++++++++---------- + 1 file changed, 12 insertions(+), 10 deletions(-) + +diff --git a/src/ptf/dataplane.py b/src/ptf/dataplane.py +index a1c1b3f..df9f39f 100644 +--- a/src/ptf/dataplane.py ++++ b/src/ptf/dataplane.py +@@ -738,40 +738,42 @@ class DataPlane(Thread): + ) + return bytes + +- def oldest_port_number(self, device): ++ def get_oldest(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. + def packets(self, device, port=None): + while True: +- if port is None: +- rcv_port = self.oldest_port_number(device) +- else: ++ if device is None: ++ rcv_device, rcv_port = self.get_oldest(None) ++ if port is not None: + rcv_port = port + + 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 From 0d1be9f74d8acde7f553bb7ab8977b10f5f16fe9 Mon Sep 17 00:00:00 2001 From: Wenda Chu <32250288+w1nda@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:28:46 +0800 Subject: [PATCH 2/3] Update series --- src/ptf-py3.patch/series | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ptf-py3.patch/series b/src/ptf-py3.patch/series index 9bbcdfcbfda7..4ed0564a639d 100644 --- a/src/ptf-py3.patch/series +++ b/src/ptf-py3.patch/series @@ -1,3 +1,4 @@ 0001-Remove-ord-in-get_mac-to-avoid-TypeError.patch 0002-Fill-byte-formatted-client-mac-address-in-DHCP-Disco.patch 0003-Avoid-local-version-scheme-by-setuptools-scm.patch +0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch From 9e01ba53ac394e453552ceceda0771e07b0bcc85 Mon Sep 17 00:00:00 2001 From: Wenda Chu <32250288+w1nda@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:49:02 +0800 Subject: [PATCH 3/3] Update 0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch --- ...-poll-method-to-support-multi-ptf-nn.patch | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch b/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch index 81d1e3179e2b..b4917468735d 100644 --- a/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch +++ b/src/ptf-py3.patch/0004-extend-dataplane-poll-method-to-support-multi-ptf-nn.patch @@ -1,23 +1,23 @@ -From c46fb401ab3d90c1829071b4b0933defbc6135dc Mon Sep 17 00:00:00 2001 +From 688c4d11a00269beaf22eb6f2cccba410bfb2856 Mon Sep 17 00:00:00 2001 From: wenda 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 | 22 ++++++++++++---------- - 1 file changed, 12 insertions(+), 10 deletions(-) + 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..df9f39f 100644 +index a1c1b3f..009ac2f 100644 --- a/src/ptf/dataplane.py +++ b/src/ptf/dataplane.py -@@ -738,40 +738,42 @@ class DataPlane(Thread): +@@ -738,40 +738,49 @@ class DataPlane(Thread): ) return bytes - def oldest_port_number(self, device): -+ def get_oldest(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, @@ -41,15 +41,23 @@ index a1c1b3f..df9f39f 100644 # 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: -+ if device is None: -+ rcv_device, rcv_port = self.get_oldest(None) -+ if port is not None: - rcv_port = port +- 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")