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" 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