Search in sources :

Example 16 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OvsdbControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    DriverHandler handler = handler();
    OvsdbClientService clientService = getOvsdbClientService(handler);
    Set<ControllerInfo> controllers = clientService.getControllers(handler().data().deviceId());
    return new ArrayList<>(controllers);
}
Also used : OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 17 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OvsdbControllerConfig method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    DriverHandler handler = handler();
    OvsdbClientService clientService = getOvsdbClientService(handler);
    if (!clientService.getControllers(handler().data().deviceId()).equals(ImmutableSet.copyOf(controllers))) {
        clientService.setControllersWithDeviceId(handler().data().deviceId(), controllers);
    }
}
Also used : OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 18 with DriverHandler

use of org.onosproject.net.driver.DriverHandler 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 19 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OvsdbMirroringConfig method getOvsdbClientService.

/**
 * Helper method which is used for getting OvsdbClientService.
 */
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    DeviceService deviceService = handler.get(DeviceService.class);
    DeviceId deviceId = handler.data().deviceId();
    String[] splits = deviceId.toString().split(":");
    if (splits == null || splits.length < 1) {
        log.warn("Wrong deviceId format");
        return null;
    }
    /**
     * Each type of device has to be managed in a different way.
     */
    switch(splits[0]) {
        case "ovsdb":
            OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
            return ovsController.getOvsdbClient(nodeId);
        case "of":
            String[] mgmtAddress = deviceService.getDevice(deviceId).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, deviceId))).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;
        default:
            log.warn("Unmanaged device type");
    }
    return null;
}
Also used : MirroringConfig(org.onosproject.net.behaviour.MirroringConfig) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) MirroringStatistics(org.onosproject.net.behaviour.MirroringStatistics) AnnotationKeys(org.onosproject.net.AnnotationKeys) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Tools.delay(org.onlab.util.Tools.delay) OvsdbConstant(org.onosproject.ovsdb.controller.OvsdbConstant) IpAddress(org.onlab.packet.IpAddress) MirroringDescription(org.onosproject.net.behaviour.MirroringDescription) TpPort(org.onlab.packet.TpPort) Logger(org.slf4j.Logger) BridgeName(org.onosproject.net.behaviour.BridgeName) Collection(java.util.Collection) MirroringName(org.onosproject.net.behaviour.MirroringName) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) 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 20 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OvsdbMirroringConfig method addMirroring.

/**
 * Adds a mirroring with a given description.
 *
 * @param bridge the bridge name
 * @param mirroringDescription mirroring description
 * @return true if succeeds, or false
 */
@Override
public boolean addMirroring(BridgeName bridge, MirroringDescription mirroringDescription) {
    DriverHandler handler = handler();
    OvsdbClientService ovsdbClient = getOvsdbClientService(handler);
    OvsdbMirror mirror = OvsdbMirror.builder(mirroringDescription).build();
    return ovsdbClient.createMirror(bridge.name(), mirror);
}
Also used : OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5