From fc78227ac96afb81a34f3eb9a3efe1949646997f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ara=C3=BAjo?= Date: Tue, 11 Apr 2023 19:01:39 +0100 Subject: [PATCH 1/2] decode functionality for convert.py --- utils/p4runtime_lib/convert.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/p4runtime_lib/convert.py b/utils/p4runtime_lib/convert.py index 671b9107c..abf59bf1e 100644 --- a/utils/p4runtime_lib/convert.py +++ b/utils/p4runtime_lib/convert.py @@ -77,6 +77,16 @@ def encode(x, bitwidth): assert(len(encoded_bytes) == byte_len) return encoded_bytes + +def decode(enc_val): + decode_functions = [decodeIPv4, decodeMac, decodeNum] + for func in decode_functions: + try: + return func(enc_val) + except: + pass + raise Exception("Encoded value format not compatible") + if __name__ == '__main__': # TODO These tests should be moved out of main eventually mac = "aa:bb:cc:dd:ee:ff" From 0aa19909adb3983802d4c3cb0a56421765f156c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ara=C3=BAjo?= Date: Tue, 11 Apr 2023 19:02:57 +0100 Subject: [PATCH 2/2] Get configured Pipeline to use on already deployed BMV2 --- utils/p4runtime_lib/switch.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/p4runtime_lib/switch.py b/utils/p4runtime_lib/switch.py index d02fee885..93311b3cd 100644 --- a/utils/p4runtime_lib/switch.py +++ b/utils/p4runtime_lib/switch.py @@ -84,6 +84,17 @@ def SetForwardingPipelineConfig(self, p4info, dry_run=False, **kwargs): else: self.client_stub.SetForwardingPipelineConfig(request) + def GetForwardingPipelineConfig(self): + try: + request = p4runtime_pb2.GetForwardingPipelineConfigRequest() + request.device_id = self.device_id + response = self.client_stub.GetForwardingPipelineConfig(request) + return response.config.p4info + except grpc._channel._InactiveRpcError as e: + if(e.code() == grpc.StatusCode.FAILED_PRECONDITION): + print(e.debug_error_string()) + return None + def WriteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id