From ff2de52a115cc429a403e5e4c7013f710b96f176 Mon Sep 17 00:00:00 2001 From: Abhinav kumar <126642111+Abhinavcode13@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:50:26 +0530 Subject: [PATCH] Added ModifyTableEntry method to P4Runtime API wrapper for modifying table entries with optional dry run mode --- utils/p4runtime_lib/switch.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/p4runtime_lib/switch.py b/utils/p4runtime_lib/switch.py index d02fee885..576a9223d 100644 --- a/utils/p4runtime_lib/switch.py +++ b/utils/p4runtime_lib/switch.py @@ -99,6 +99,18 @@ def WriteTableEntry(self, table_entry, dry_run=False): else: self.client_stub.Write(request) + def ModifyTableEntry(self, table_entry, dry_run=False): + request = p4runtime_pb2.WriteRequest() + request.device_id = self.device_id + request.election_id.low = 1 + update = request.updates.add() + update.type = p4runtime_pb2.Update.MODIFY + update.entity.table_entry.CopyFrom(table_entry) + if dry_run: + print("P4Runtime Modify: ", request) + else: + self.client_stub.Write(request) + def ReadTableEntries(self, table_id=None, dry_run=False): request = p4runtime_pb2.ReadRequest() request.device_id = self.device_id