From da6f216dcaa206aff47e26370999baa0c350455e Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Tue, 5 Nov 2024 17:25:36 +0000 Subject: [PATCH] check p4 flow table for test case verification --- .../functional/ptf/p4_dash_utils.py | 25 +++++++++++++++++++ .../functional/ptf/saidashdpapp_sanity.py | 4 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/test/test-cases/functional/ptf/p4_dash_utils.py b/test/test-cases/functional/ptf/p4_dash_utils.py index 581f10120..267da900c 100644 --- a/test/test-cases/functional/ptf/p4_dash_utils.py +++ b/test/test-cases/functional/ptf/p4_dash_utils.py @@ -175,3 +175,28 @@ def tearDown(self, *args, **kwargs): setattr(cls, "tearDown", tearDown) return cls + +class P4Table(): + def __init__(self): + channel = grpc.insecure_channel('localhost:9559') + self.stub = p4runtime_pb2_grpc.P4RuntimeStub(channel) + + def read(self, table_id): + entry = p4runtime_pb2.TableEntry() + entry.table_id = table_id + + req = p4runtime_pb2.ReadRequest() + req.device_id = 0 + entity = req.entities.add() + entity.table_entry.CopyFrom(entry) + for response in self.stub.Read(req): + for entity in response.entities: + yield entity.table_entry + + def print_flow_table(self): + p4info = P4info(self.stub) + p4info_flow_entry = p4info.get_table("dash_ingress.conntrack_lookup_stage.flow_entry") + + for entry in self.read(p4info_flow_entry.preamble.id): + print(entry) + diff --git a/test/test-cases/functional/ptf/saidashdpapp_sanity.py b/test/test-cases/functional/ptf/saidashdpapp_sanity.py index fc9f5a125..2b2aefae2 100644 --- a/test/test-cases/functional/ptf/saidashdpapp_sanity.py +++ b/test/test-cases/functional/ptf/saidashdpapp_sanity.py @@ -195,6 +195,7 @@ def trafficUdpTest(self): send_packet(self, 0, vxlan_pkt) print("\tVerifying packet in dpapp port...") verify_packet(self, self.pkt_exp, 0) + P4Table().print_flow_table() print ("SaiThriftDpappUdpPktTest OK") def trafficTcpTest(self): @@ -238,10 +239,11 @@ def trafficTcpTest(self): inner_frame=inner_exp_pkt) self.pkt_exp = vxlan_exp_pkt - print("\tSending outbound packet...") + print("\tSending outbound packet TCP SYN ...") send_packet(self, 0, vxlan_pkt) print("\tVerifying packet in dpapp port...") verify_packet(self, self.pkt_exp, 0) + P4Table().print_flow_table() # customer packet: tcp FIN inner_pkt = simple_tcp_packet(eth_dst="02:02:02:02:02:02",