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

Conversation

davidjosearaujo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant