Search in sources :

Example 1 with OvsdbNodeId

use of org.onosproject.ovsdb.controller.OvsdbNodeId in project onos by opennetworkinglab.

the class OvsdbControllerConfig method getOvsdbClientService.

// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    DeviceService deviceService = handler.get(DeviceService.class);
    DeviceId ofDeviceId = handler.data().deviceId();
    String[] mgmtAddress = deviceService.getDevice(ofDeviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
    String targetIp = mgmtAddress[0];
    TpPort targetPort = null;
    if (mgmtAddress.length > 1) {
        targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
    }
    List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).collect(Collectors.toList());
    if (nodeIds.isEmpty()) {
        // TODO decide what port?
        ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
        // FIXME... connect is async
        delay(1000);
    }
    List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId))).collect(Collectors.toList());
    checkState(!clientServices.isEmpty(), "No clientServices found");
    // FIXME add connection to management address if null --> done ?
    return !clientServices.isEmpty() ? clientServices.get(0) : null;
}
Also used : TpPort(org.onlab.packet.TpPort) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) AnnotationKeys(org.onosproject.net.AnnotationKeys) ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) Collectors(java.util.stream.Collectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Tools.delay(org.onlab.util.Tools.delay) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbConstant(org.onosproject.ovsdb.controller.OvsdbConstant) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) TpPort(org.onlab.packet.TpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Example 2 with OvsdbNodeId

use of org.onosproject.ovsdb.controller.OvsdbNodeId in project onos by opennetworkinglab.

the class OvsdbInterfaceConfig method getOvsdbClient.

private OvsdbClientService getOvsdbClient(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId());
    return ovsController.getOvsdbClient(nodeId);
}
Also used : OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Example 3 with OvsdbNodeId

use of org.onosproject.ovsdb.controller.OvsdbNodeId in project onos by opennetworkinglab.

the class OvsdbPortConfig method changeDeviceIdToNodeId.

// OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
// is used in the core. So DeviceId need be changed to OvsdbNodeId.
private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
    String[] splits = deviceId.toString().split(":");
    if (splits.length < 1) {
        return null;
    }
    IpAddress ipAddress = IpAddress.valueOf(splits[1]);
    return new OvsdbNodeId(ipAddress, 0);
}
Also used : IpAddress(org.onlab.packet.IpAddress) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Example 4 with OvsdbNodeId

use of org.onosproject.ovsdb.controller.OvsdbNodeId in project onos by opennetworkinglab.

the class OvsdbPortConfig method getOvsdbClient.

private OvsdbClientService getOvsdbClient(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId());
    return ovsController.getOvsdbClient(nodeId);
}
Also used : OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Example 5 with OvsdbNodeId

use of org.onosproject.ovsdb.controller.OvsdbNodeId in project onos by opennetworkinglab.

the class OvsdbQueueConfig method changeDeviceIdToNodeId.

// OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
// is used in the core. So DeviceId need be changed to OvsdbNodeId.
private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
    String[] splits = deviceId.toString().split(":");
    if (splits.length < 1) {
        return null;
    }
    IpAddress ipAddress = IpAddress.valueOf(splits[1]);
    return new OvsdbNodeId(ipAddress, 0);
}
Also used : IpAddress(org.onlab.packet.IpAddress) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Aggregations

OvsdbNodeId (org.onosproject.ovsdb.controller.OvsdbNodeId)19 IpAddress (org.onlab.packet.IpAddress)10 OvsdbController (org.onosproject.ovsdb.controller.OvsdbController)8 DeviceId (org.onosproject.net.DeviceId)4 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 TpPort (org.onlab.packet.TpPort)2 Tools.delay (org.onlab.util.Tools.delay)2 AnnotationKeys (org.onosproject.net.AnnotationKeys)2 DeviceService (org.onosproject.net.device.DeviceService)2 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)2 OvsdbConstant (org.onosproject.ovsdb.controller.OvsdbConstant)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ChannelFuture (io.netty.channel.ChannelFuture)1