Re: [ovs-dev] [PATCH 1/3] tests: sendpkt: Allow different input formats.

2024-06-05 Thread Eelco Chaudron



On 31 May 2024, at 23:45, Ilya Maximets wrote:

> We require python 3, so instead of manually parsing bytes on input we
> can use built-in bytes.fromhex().  This function ignores whitespaces,
> so we can use different input formats - the old style space-separated
> bytes as well as pure hex strings provided by ovs-ofctl compose-packet
> and ovs-pcap.
>
> Signed-off-by: Ilya Maximets 

Thanks for cleaning this up! This patch looks good to me.

Acked-by: Eelco Chaudron 

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH 1/3] tests: sendpkt: Allow different input formats.

2024-06-03 Thread Simon Horman
On Fri, May 31, 2024 at 11:45:10PM +0200, Ilya Maximets wrote:
> We require python 3, so instead of manually parsing bytes on input we
> can use built-in bytes.fromhex().  This function ignores whitespaces,
> so we can use different input formats - the old style space-separated
> bytes as well as pure hex strings provided by ovs-ofctl compose-packet
> and ovs-pcap.
> 
> Signed-off-by: Ilya Maximets 

Acked-by: Simon Horman 

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH 1/3] tests: sendpkt: Allow different input formats.

2024-05-31 Thread Ilya Maximets
We require python 3, so instead of manually parsing bytes on input we
can use built-in bytes.fromhex().  This function ignores whitespaces,
so we can use different input formats - the old style space-separated
bytes as well as pure hex strings provided by ovs-ofctl compose-packet
and ovs-pcap.

Signed-off-by: Ilya Maximets 
---
 tests/sendpkt.py | 26 --
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/tests/sendpkt.py b/tests/sendpkt.py
index 49ac45275..7cbea5165 100755
--- a/tests/sendpkt.py
+++ b/tests/sendpkt.py
@@ -48,28 +48,10 @@ if len(args) < 2:
 if options.packet_type != "eth":
 parser.error('invalid argument to "-t"/"--type". Allowed value is "eth".')
 
-# store the hex bytes with 0x appended at the beginning
-# if not present in the user input and validate the hex bytes
-hex_list = []
-for a in args[1:]:
-if a[:2] != "0x":
-hex_byte = "0x" + a
-else:
-hex_byte = a
-try:
-temp = int(hex_byte, 0)
-except:
-parser.error("invalid hex byte " + a)
-
-if temp > 0xff:
-parser.error("hex byte " + a + " cannot be greater than 0xff!")
-
-hex_list.append(temp)
-
-if sys.version_info < (3, 0):
-pkt = "".join(map(chr, hex_list))
-else:
-pkt = bytes(hex_list)
+# Strip '0x' prefixes from hex input, combine into a single string and
+# convert to bytes.
+hex_str = "".join([a[2:] if a.startswith("0x") else a for a in args[1:]])
+pkt = bytes.fromhex(hex_str)
 
 try:
 sockfd = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
-- 
2.45.0

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev