示例#1
0
def buildSetPipelineRequest(p4info, device_config, device_id):
    request = p4runtime_pb2.SetForwardingPipelineConfigRequest()
    config = request.configs.add()
    config.device_id = device_id
    config.p4info.CopyFrom(p4info)
    config.p4_device_config = device_config.SerializeToString()
    request.action = p4runtime_pb2.SetForwardingPipelineConfigRequest.VERIFY_AND_COMMIT
    return request
示例#2
0
 def SetForwardingPipelineConfig(self, p4info, dry_run=False, **kwargs):
     device_config = self.buildDeviceConfig(**kwargs)
     request = p4runtime_pb2.SetForwardingPipelineConfigRequest()
     request.device_id = self.device_id
     config = request.config
     config.p4info.CopyFrom(p4info)
     config.p4_device_config = device_config.SerializeToString()
     request.action = p4runtime_pb2.SetForwardingPipelineConfigRequest.VERIFY_AND_COMMIT
     if dry_run:
         print "P4 Runtime SetForwardingPipelineConfig:", request
     else:
         self.client_stub.SetForwardingPipelineConfig(request)
 def set_forwarding_pipeline(self):
     device_config = p4config_pb2.P4DeviceConfig()
     device_config.reassign = True
     with open(self.bmv2_json) as f:
         device_config.device_data = f.read()
     request = p4runtime_pb2.SetForwardingPipelineConfigRequest()
     request.election_id.CopyFrom(self.election_id)
     request.device_id = self.device_id
     config = request.config
     config.p4info.CopyFrom(self.p4info)
     config.p4_device_config = device_config.SerializeToString()
     request.action = p4runtime_pb2.SetForwardingPipelineConfigRequest.VERIFY_AND_COMMIT
     self.client_stub.SetForwardingPipelineConfig(request)
     return
示例#4
0
def update_config(config_path, p4info_path, grpc_addr, device_id):
    '''
    Performs a SetForwardingPipelineConfig on the device with provided
    P4Info and binary device config
    '''
    channel = grpc.insecure_channel(grpc_addr)
    stub = p4runtime_pb2.P4RuntimeStub(channel)

    info("Sending P4 config")
    request = p4runtime_pb2.SetForwardingPipelineConfigRequest()
    request.device_id = device_id
    config = request.config
    with open(p4info_path, 'r') as p4info_f:
        google.protobuf.text_format.Merge(p4info_f.read(), config.p4info)
    with open(config_path, 'rb') as config_f:
        config.p4_device_config = config_f.read()
    request.action = p4runtime_pb2.SetForwardingPipelineConfigRequest.VERIFY_AND_COMMIT
    try:
        response = stub.SetForwardingPipelineConfig(request)
    except Exception as e:
        error("Error during SetForwardingPipelineConfig")
        error(str(e))
        return False
    return True