Search in sources :

Example 21 with DeviceService

use of org.onosproject.net.device.DeviceService 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 22 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class TapiDeviceLambdaQuery method queryLambdas.

@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    RestSBController controller = checkNotNull(handler().get(RestSBController.class));
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = did();
    Device dev = deviceService.getDevice(deviceId);
    if (dev == null) {
        log.error("Device {} does not exist", deviceId);
        return ImmutableSet.of();
    }
    Port p = deviceService.getPort(dev.id(), port);
    if (p == null) {
        log.error("Port {} does not exist", port);
        return ImmutableSet.of();
    }
    String uuid = p.annotations().value(UUID);
    try {
        InputStream inputStream = controller.get(deviceId, SIP_REQUEST_DATA_API + uuid, MediaType.APPLICATION_JSON_TYPE);
        log.debug("Service interface point UUID: {}", uuid);
        JsonNode sipAttributes = new ObjectMapper().readTree(inputStream);
        JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
        // This creates a hashset of OChSignals representing the spectrum availability at the target port.
        return TapiDeviceHelper.getOchSignal(mcPool);
    } catch (IOException e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableSet.of();
    }
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) InputStream(java.io.InputStream) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class DefaultTributarySlotQuery method queryTributarySlots.

@Override
public Set<TributarySlot> queryTributarySlots(PortNumber port) {
    // currently return all slots by default.
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);
    if (p == null) {
        return Collections.emptySet();
    }
    switch(p.type()) {
        case OCH:
            return queryOchTributarySlots(p);
        case OTU:
            return queryOtuTributarySlots(p);
        default:
            return Collections.emptySet();
    }
}
Also used : OtuPort(org.onosproject.net.optical.OtuPort) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) DeviceService(org.onosproject.net.device.DeviceService)

Example 24 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class OFOpticalSwitch13LambdaQuery method queryLambdas.

@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);
    // Only OMS ports expose lambda resources
    if (p == null || !p.type().equals(Port.Type.OMS)) {
        return Collections.emptySet();
    }
    short lambdaCount = ((OmsPort) p).totalChannels();
    // OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
    return IntStream.rangeClosed(1, lambdaCount).mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x)).collect(GuavaCollectors.toImmutableSet());
}
Also used : IntStream(java.util.stream.IntStream) LambdaQuery(org.onosproject.net.behaviour.LambdaQuery) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) GuavaCollectors(org.onlab.util.GuavaCollectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) OchSignal(org.onosproject.net.OchSignal) OmsPort(org.onosproject.net.optical.OmsPort) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) Port(org.onosproject.net.Port) ChannelSpacing(org.onosproject.net.ChannelSpacing) Collections(java.util.Collections) OmsPort(org.onosproject.net.optical.OmsPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

Example 25 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class OpenRoadmNetconfHandlerBehaviour method getDevice.

/**
 * Get the device instance for which the methods apply.
 *
 * @return The device instance
 */
protected Device getDevice() {
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(did());
    return device;
}
Also used : Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceService(org.onosproject.net.device.DeviceService)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14