Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect controller to deployed BMV2 and retrieve existing P4Info for Helper use + Generic decoder for convert.py #508

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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