summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2024-01-05 06:34:01 +0000
committersongyanchao <[email protected]>2024-01-05 06:34:01 +0000
commit0e9d87a3083386ea2da7ce82d0088e4ac7dc266a (patch)
tree744a5728f2a677876e88e405caf9f2e589bcdb27 /test
parenta157ece86c08b1a157f19213bac719f03c4337ac (diff)
🎈 perf(TSG-17959): Refine msgpack serialization and deserialization functions, along with corresponding test cases.
Refine msgpack serialization and deserialization functions, along with corresponding test cases.
Diffstat (limited to 'test')
-rw-r--r--test/msgpack_test.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/test/msgpack_test.py b/test/msgpack_test.py
index 039c49d..adea563 100644
--- a/test/msgpack_test.py
+++ b/test/msgpack_test.py
@@ -5,6 +5,7 @@ from scapy.all import *
from mrzcpd import Mrzcpd
from common_pkt import *
import ptf.mask as mask
+import msgpack
serialize_conf = """
[device]
@@ -126,11 +127,16 @@ class MpackSerializeTest(BaseTest):
send_packet(self, 0,send_pkt)
# Verify
- hex_data = "8ba4706f727400ab7061636b65745f7479706500a86f6c5f666c61677300a8646174615f6c656e64a7706b745f6c656e64a473696473980000000000cd03e8cd012c00a76375725f736964cd03e8a46865616407a47461696c06a8636170616369747907a67061636b6574c46400010203040500060708090a0800450000560001000040111e48ac110164ac1102c804d200500042f90068656c6c6f20776f726c64000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e"
- binary_data = bytes.fromhex(hex_data)
+ verify_data = {'port': 0, 'packet_type': 0, 'ol_flags': 0, 'data_len': 100, 'pkt_len': 100, 'dir': 0, 'packet_create_from_nf': 0,
+ 'is_ctrlbuf': 0, 'adapter_type': 1, 'adapter_id': 0, 'payload_offset': 0, 'user_0': 0, 'ef_link_id': 0, 'traffic_link_id': 255,
+ 'ef_peer_index': 0, 'port_ingress': 0, 'port_egress': 2, 'session_id': 0, 'cur_sid': 1000, 'sids': [0, 0, 0, 0, 0, 1000, 300, 0],
+ 'head': 7, 'tail': 6, 'capacity': 7,
+ 'packet':send_pkt.__bytes__()}
+ binary_data = msgpack.dumps(verify_data)
verify_pkt = simple_eth_packet(pktlen=14,eth_src="aa:bb:cc:dd:ee:ff",eth_dst="ff:ee:dd:cc:bb:aa",eth_type=0x4d5a) / Raw(load=binary_data)
verify_packets(self, verify_pkt, [2])
+
finally:
mrzcpd.stop()
@@ -249,14 +255,20 @@ class MpackDeserializeTest(BaseTest):
mrzcpd = Mrzcpd(deserialize_conf)
mrzcpd.start()
- hex_data = "8ba4706f727400ab7061636b65745f7479706500a86f6c5f666c61677300a8646174615f6c656e64a7706b745f6c656e64a473696473980000000000cd03e8cd012c00a76375725f736964cd03e8a46865616407a47461696c06a8636170616369747907a67061636b6574c46400010203040500060708090a0800450000560001000040111e48ac110164ac1102c804d200500042f90068656c6c6f20776f726c64000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e"
- binary_data = bytes.fromhex(hex_data)
+ verify_pkt = simple_udp_packet(ip_src="172.17.1.100", ip_dst="172.17.2.200",udp_payload="hello world")
+
+ send_data = {'port': 0, 'packet_type': 0, 'ol_flags': 0, 'data_len': 100, 'pkt_len': 100, 'dir': 0, 'packet_create_from_nf': 0,
+ 'is_ctrlbuf': 0, 'adapter_type': 1, 'adapter_id': 0, 'payload_offset': 0, 'user_0': 0, 'ef_link_id': 0, 'traffic_link_id': 255,
+ 'ef_peer_index': 0, 'port_ingress': 0, 'port_egress': 2, 'session_id': 0, 'cur_sid': 1000, 'sids': [0, 0, 0, 0, 0, 1000, 300, 0],
+ 'head': 7, 'tail': 6, 'capacity': 7,
+ 'packet':verify_pkt.__bytes__()}
+ binary_data = msgpack.dumps(send_data)
send_pkt = simple_eth_packet(pktlen=14,eth_src="aa:bb:cc:dd:ee:ff",eth_dst="ff:ee:dd:cc:bb:aa",eth_type=0x4d5a) / Raw(load=binary_data)
send_packet(self, 2,send_pkt)
# Verify
- verify_pkt = simple_udp_packet(ip_src="172.17.1.100", ip_dst="172.17.2.200",udp_payload="hello world")
verify_packets(self, verify_pkt, [1])
+
finally:
mrzcpd.stop()