Beispiel #1
0
    def WriteTableEntry(self, update_type, table, match_key, action_data):
        global dev_id
        request = p4runtime_pb2.WriteRequest()
        request.device_id = dev_id
        request.election_id.low = 1

        update = request.updates.add()
        update.type = update_type
        update.entity.table_entry.table_id = table
        update.entity.table_entry.is_default_action = 1
        update.entity.table_entry.action.action.action_id = 1

        matches = update.entity.table_entry.match.add()
        matches.field_id = 1
        matches.exact.value = bytes(match_key)

        act = update.entity.table_entry.action.action.params.add()
        act.param_id = 2
        act.value = bytes(action_data)

        ServerConfig.print_debug("Sending table write request to server:")
        ServerConfig.print_debug(request)
        try:
            self.stub.Write(request)
        except grpc.RpcError as error:
            ServerConfig.print_debug("An error ocurred during a 'write' execution!")
            ServerConfig.print_debug("{}: {}".format(error.code().name, error.details()))

        return
Beispiel #2
0
    def WriteRegisterEntry(self, register_id, index, value):
        global dev_id
        request = p4runtime_pb2.WriteRequest()
        request.device_id = dev_id
        request.election_id.low = 1

        update = request.updates.add()
        update.type = p4runtime_pb2.Update.MODIFY
        update.entity.register_entry.register_id = register_id
        update.entity.register_entry.index.index = index
        update.entity.register_entry.data.enum_value = bytes(value)

        ServerConfig.print_debug("Sending register write request to server:")
        ServerConfig.print_debug(request)
        try:
            self.stub.Write(request)
        except grpc.RpcError as error:
            ServerConfig.print_debug("An error ocurred during a 'write' execution!")
            ServerConfig.print_debug("{}: {}\n".format(error.code().name, error.details()))

        return