Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions utils/p4runtime_lib/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions utils/p4runtime_lib/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down