Connect controller to deployed BMV2 and retrieve existing P4Info for Helper use + Generic decoder for convert.py
Forwarding Pipeline P4Info retrieval + Generic decoder
Forwarding Pipeline P4Info retrieval
Current difficulty
Currently, reconfiguring an already running BMV2 is not possible because de p4info object is created and kept when the device is first configured by the connecting controller, but what if we want to connect to a running device and not re-program it?
Added functionality
The P4Runtime allows us to retrieve the P4Info object, and this will allow us to use the Helper to read and write to the device.
So a small function was added to the switch.py which allows us to retrieve the P4Info object.
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
Generic decoder
Current difficulty
If connecting to an already running device, we might not know what type of entries this already has in its table, which can make it difficult to decode the values in its match fields.
Added functionality
Added a more generic decode function to convert.py that checks if the value is either a MAC, IP or a numeric value, and decodes it accordingly.
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")