Search in sources :

Example 6 with OpticalConnectivityIntent

use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.

the class OpticalConnectivityIntentCompiler method findFirstAvailableLambda.

/**
 * Find the first available lambda on the given path by checking all the port resources.
 *
 * @param path the path
 * @return list of consecutive and available OChSignals
 */
private List<OchSignal> findFirstAvailableLambda(OpticalConnectivityIntent intent, Path path) {
    if (intent.ochSignal().isPresent()) {
        // create lambdas w.r.t. slotGanularity/slotWidth
        OchSignal ochSignal = intent.ochSignal().get();
        if (ochSignal.gridType() == GridType.FLEX) {
            // multiplier sits in the middle of slots
            int startMultiplier = ochSignal.spacingMultiplier() - (ochSignal.slotGranularity() / 2);
            return IntStream.range(0, ochSignal.slotGranularity()).mapToObj(x -> OchSignal.newFlexGridSlot(startMultiplier + (2 * x))).collect(Collectors.toList());
        } else if (ochSignal.gridType() == GridType.DWDM) {
            int startMultiplier = (int) (1 - ochSignal.slotGranularity() + ochSignal.spacingMultiplier() * ochSignal.channelSpacing().frequency().asHz() / ChannelSpacing.CHL_6P25GHZ.frequency().asHz());
            return IntStream.range(0, ochSignal.slotGranularity()).mapToObj(x -> OchSignal.newFlexGridSlot(startMultiplier + (2 * x))).collect(Collectors.toList());
        }
        // TODO: add support for other gridTypes
        log.error("Grid type: {} not supported for user defined signal intents", ochSignal.gridType());
        return Collections.emptyList();
    }
    Set<OchSignal> lambdas = findCommonLambdas(path);
    if (lambdas.isEmpty()) {
        return Collections.emptyList();
    }
    return findFirstLambda(lambdas, slotCount());
}
Also used : DefaultOchSignalComparator(org.onosproject.net.DefaultOchSignalComparator) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Topology(org.onosproject.net.topology.Topology) Port(org.onosproject.net.Port) Map(java.util.Map) OchPort(org.onosproject.net.optical.OchPort) DefaultLink(org.onosproject.net.DefaultLink) OchSignalType(org.onosproject.net.OchSignalType) ImmutableSet(com.google.common.collect.ImmutableSet) Resources(org.onosproject.net.resource.Resources) Deactivate(org.osgi.service.component.annotations.Deactivate) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) Collection(java.util.Collection) Set(java.util.Set) Resource(org.onosproject.net.resource.Resource) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) List(java.util.List) Stream(java.util.stream.Stream) Annotations(org.onosproject.net.Annotations) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Path(org.onosproject.net.Path) ChannelSpacing(org.onosproject.net.ChannelSpacing) DeviceId(org.onosproject.net.DeviceId) IntStream(java.util.stream.IntStream) GridType(org.onosproject.net.GridType) TopologyEdge(org.onosproject.net.topology.TopologyEdge) AnnotationKeys(org.onosproject.net.AnnotationKeys) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) Logger(org.slf4j.Logger) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) OchSignal(org.onosproject.net.OchSignal) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Weight(org.onlab.graph.Weight) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) OchSignal(org.onosproject.net.OchSignal) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 7 with OpticalConnectivityIntent

use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.

the class OpticalIntentsWebResource method deleteIntent.

/**
 * Delete the specified optical intent.
 *
 * @param appId application identifier
 * @param keyString   intent key
 * @return 204 NO CONTENT
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("{appId}/{key}")
public Response deleteIntent(@PathParam("appId") String appId, @PathParam("key") String keyString) {
    final ApplicationId app = get(CoreService.class).getAppId(appId);
    nullIsNotFound(app, "Application Id not found");
    IntentService intentService = get(IntentService.class);
    Intent intent = intentService.getIntent(Key.of(keyString, app));
    if (intent == null) {
        intent = intentService.getIntent(Key.of(Long.decode(keyString), app));
    }
    nullIsNotFound(intent, "Intent Id is not found");
    if ((intent instanceof OpticalConnectivityIntent) || (intent instanceof OpticalCircuitIntent)) {
        intentService.withdraw(intent);
    } else {
        throw new IllegalArgumentException("Specified intent is not of type OpticalConnectivityIntent");
    }
    return Response.noContent().build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) CoreService(org.onosproject.core.CoreService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ApplicationId(org.onosproject.core.ApplicationId) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Path(javax.ws.rs.Path) DefaultPath(org.onosproject.net.DefaultPath) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 8 with OpticalConnectivityIntent

use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.

the class OpticalIntentsWebResource method getIntents.

/**
 * Get the optical intents on the network.
 *
 * @return 200 OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
    DeviceService deviceService = get(DeviceService.class);
    IntentService intentService = get(IntentService.class);
    Iterator intentItr = intentService.getIntents().iterator();
    ArrayNode arrayFlows = mapper().createArrayNode();
    while (intentItr.hasNext()) {
        Intent intent = (Intent) intentItr.next();
        if (intent instanceof OpticalConnectivityIntent) {
            OpticalConnectivityIntent opticalConnectivityIntent = (OpticalConnectivityIntent) intent;
            Device srcDevice = deviceService.getDevice(opticalConnectivityIntent.getSrc().deviceId());
            Device dstDevice = deviceService.getDevice(opticalConnectivityIntent.getDst().deviceId());
            String srcDeviceName = srcDevice.annotations().value(AnnotationKeys.NAME);
            String dstDeviceName = dstDevice.annotations().value(AnnotationKeys.NAME);
            ObjectNode objectNode = mapper().createObjectNode();
            objectNode.put("intent id", opticalConnectivityIntent.id().toString());
            objectNode.put("app id", opticalConnectivityIntent.appId().name());
            objectNode.put("state", intentService.getIntentState(opticalConnectivityIntent.key()).toString());
            objectNode.put("src", opticalConnectivityIntent.getSrc().toString());
            objectNode.put("dst", opticalConnectivityIntent.getDst().toString());
            objectNode.put("srcName", srcDeviceName);
            objectNode.put("dstName", dstDeviceName);
            // Only for INSTALLED intents
            if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) {
                // Retrieve associated FlowRuleIntent
                FlowRuleIntent installableIntent = (FlowRuleIntent) intentService.getInstallableIntents(opticalConnectivityIntent.key()).stream().filter(FlowRuleIntent.class::isInstance).findFirst().orElse(null);
                // TODO store utilized ochSignal in the intent resources
                if (installableIntent != null) {
                    OchSignal signal = installableIntent.flowRules().stream().filter(r -> r.selector().criteria().size() == NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE).map(r -> ((OchSignalCriterion) r.selector().getCriterion(Criterion.Type.OCH_SIGID)).lambda()).findFirst().orElse(null);
                    objectNode.put("ochSignal", signal.toString());
                    objectNode.put("centralFreq", signal.centralFrequency().asTHz() + " THz");
                }
                // Retrieve path and print it to REST
                if (installableIntent != null) {
                    String path = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).map(r -> deviceService.getDevice(r.src().deviceId())).map(r -> r.annotations().value(AnnotationKeys.NAME)).collect(Collectors.joining(" -> "));
                    List<Link> pathLinks = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).collect(Collectors.toList());
                    DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, pathLinks, new ScalarWeight(1));
                    objectNode.put("path", defaultPath.toString());
                    objectNode.put("pathName", path + " -> " + dstDeviceName);
                }
            }
            arrayFlows.add(objectNode);
        }
    }
    ObjectNode root = this.mapper().createObjectNode().putPOJO("Intents", arrayFlows);
    return ok(root).build();
}
Also used : AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) IntentState(org.onosproject.net.intent.IntentState) Path(javax.ws.rs.Path) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) MediaType(javax.ws.rs.core.MediaType) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Consumes(javax.ws.rs.Consumes) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Key(org.onosproject.net.intent.Key) List(java.util.List) Response(javax.ws.rs.core.Response) LinkService(org.onosproject.net.link.LinkService) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) AnnotationKeys(org.onosproject.net.AnnotationKeys) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OchSignalCodec(org.onosproject.net.optical.json.OchSignalCodec) ArrayList(java.util.ArrayList) IntentService(org.onosproject.net.intent.IntentService) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Criterion(org.onosproject.net.flow.criteria.Criterion) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) ProviderId(org.onosproject.net.provider.ProviderId) IOException(java.io.IOException) OchSignal(org.onosproject.net.OchSignal) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) InputStream(java.io.InputStream) IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) OchSignal(org.onosproject.net.OchSignal) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ScalarWeight(org.onlab.graph.ScalarWeight) Iterator(java.util.Iterator) DefaultPath(org.onosproject.net.DefaultPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Link(org.onosproject.net.Link) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with OpticalConnectivityIntent

use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.

the class OpticalPathProvisioner method createIntents.

/**
 * Scans the list of cross connection points and returns a list of optical connectivity intents.
 * During the process, save information about packet links to given set.
 *
 * @param crossConnectPoints list of (src, dst) pair between which optical path will be set up
 * @return list of optical connectivity intents
 */
private List<Intent> createIntents(List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints) {
    List<Intent> intents = new LinkedList<>();
    Iterator<Pair<ConnectPoint, ConnectPoint>> itr = crossConnectPoints.iterator();
    while (itr.hasNext()) {
        // checkArgument at start ensures we'll always have pairs of connect points
        Pair<ConnectPoint, ConnectPoint> next = itr.next();
        ConnectPoint src = next.getLeft();
        ConnectPoint dst = next.getRight();
        Port srcPort = deviceService.getPort(src.deviceId(), src.port());
        Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
        if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
            OduCltPort srcOCPort = (OduCltPort) srcPort;
            OduCltPort dstOCPort = (OduCltPort) dstPort;
            if (!srcOCPort.signalType().equals(dstOCPort.signalType())) {
                continue;
            }
            // Create OTN circuit
            OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOCPort.signalType()).bidirectional(false).build();
            intents.add(circuitIntent);
        } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
            OchPort srcOchPort = (OchPort) srcPort;
            OchPort dstOchPort = (OchPort) dstPort;
            if (!srcOchPort.signalType().equals(dstOchPort.signalType())) {
                continue;
            }
            // Create lightpath
            OpticalConnectivityIntent opticalIntent = OpticalConnectivityIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOchPort.signalType()).bidirectional(false).build();
            intents.add(opticalIntent);
        } else {
            log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
            return Collections.emptyList();
        }
    }
    return intents;
}
Also used : Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OduCltPort(org.onosproject.net.optical.OduCltPort) OduCltPort(org.onosproject.net.optical.OduCltPort) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) LinkedList(java.util.LinkedList) OchPort(org.onosproject.net.optical.OchPort) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with OpticalConnectivityIntent

use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.

the class OpticalPathProvisioner method setupPath.

/*
     * Given a multi-layer path,
     * compute a set of segments which requires
     * OpticalConnectivity(~=OpticalConnectivityIntent or OpticalCircuitPath)
     * to provide packet-layer connectivity.
     */
@Override
public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
    checkNotNull(path);
    log.debug("setupPath({}, {}, {})", path, bandwidth, latency);
    // map of cross connect points (optical port -> packet port)
    Map<ConnectPoint, ConnectPoint> crossConnectPointMap = new HashMap<>();
    // list of (src, dst) pair of optical ports between which optical path should be installed
    List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints = new ArrayList<>();
    // Scan path to find pairs of connect points between which optical intent is installed
    // opticalSrcPort works as a flag parameter to show scanning status
    ConnectPoint opticalSrcPort = null;
    for (Link link : path.links()) {
        if (!isCrossConnectLink(link)) {
            continue;
        }
        if (opticalSrcPort != null) {
            // opticalSrcPort!=null means src port was already found
            // in this case link.src() is optical layer, and link.dst() is packet layer
            // Check if types of src port and dst port matches
            Device srcDevice = checkNotNull(deviceService.getDevice(opticalSrcPort.deviceId()), "Unknown device ID");
            Device dstDevice = checkNotNull(deviceService.getDevice(link.src().deviceId()), "Unknown device ID");
            if (srcDevice.type() != dstDevice.type()) {
                log.error("Unsupported mix of cross connect points : {}, {}", srcDevice.type(), dstDevice.type());
                return null;
            }
            // Update cross connect points map
            crossConnectPointMap.put(link.src(), link.dst());
            // Add optical ports pair to list
            crossConnectPoints.add(Pair.of(opticalSrcPort, link.src()));
            // Reset flag parameter
            opticalSrcPort = null;
        } else {
            // opticalSrcPort==null means src port was not found yet
            // in this case link.src() is packet layer, and link.dst() is optical layer
            // Update cross connect points map
            crossConnectPointMap.put(link.dst(), link.src());
            // Set opticalSrcPort to src of link (optical port)
            opticalSrcPort = link.dst();
        }
    }
    // create intents from cross connect points
    List<Intent> intents = createIntents(crossConnectPoints);
    if (intents.isEmpty()) {
        log.error("No intents produced from {}", crossConnectPoints);
        return null;
    }
    // create set of PacketLinkRealizedByOptical
    Set<PacketLinkRealizedByOptical> packetLinks = createPacketLinkSet(crossConnectPoints, intents, crossConnectPointMap);
    // create OpticalConnectivity object and store information to distributed store
    OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency, packetLinks);
    // store cross connect port usage
    path.links().stream().filter(this::isCrossConnectLink).forEach(usedCrossConnectLinkSet::add);
    // Submit the intents
    for (Intent i : intents) {
        intentService.submit(i);
        log.debug("Submitted an intent: {}", i);
    }
    return connectivity.id();
}
Also used : HashMap(java.util.HashMap) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)20 ConnectPoint (org.onosproject.net.ConnectPoint)13 Intent (org.onosproject.net.intent.Intent)12 Link (org.onosproject.net.Link)10 ArrayList (java.util.ArrayList)7 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)7 List (java.util.List)6 OpticalCircuitIntent (org.onosproject.net.intent.OpticalCircuitIntent)6 LinkedList (java.util.LinkedList)5 Collectors (java.util.stream.Collectors)5 Test (org.junit.Test)5 DefaultPath (org.onosproject.net.DefaultPath)5 IntentService (org.onosproject.net.intent.IntentService)5 OchPort (org.onosproject.net.optical.OchPort)5 ImmutableList (com.google.common.collect.ImmutableList)4 Duration (java.time.Duration)4 Set (java.util.Set)4 ScalarWeight (org.onlab.graph.ScalarWeight)4 Bandwidth (org.onlab.util.Bandwidth)4 DefaultLink (org.onosproject.net.DefaultLink)4