Search in sources :

Example 51 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class ConfigLambdaQuery method queryLambdas.

@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
    ConnectPoint cp = new ConnectPoint(data().deviceId(), port);
    LambdaConfig cfg = netcfg.getConfig(cp, LambdaConfig.class);
    if (cfg == null) {
        return ImmutableSet.of();
    }
    GridType type = cfg.gridType();
    Optional<ChannelSpacing> dwdmSpacing = cfg.dwdmSpacing();
    int start = cfg.slotStart();
    int step = cfg.slotStep();
    int end = cfg.slotEnd();
    Set<OchSignal> lambdas = new LinkedHashSet<>();
    for (int i = start; i <= end; i += step) {
        switch(type) {
            case DWDM:
                lambdas.add(OchSignal.newDwdmSlot(dwdmSpacing.get(), i));
                break;
            case FLEX:
                lambdas.add(OchSignal.newFlexGridSlot(i));
                break;
            case CWDM:
            default:
                log.warn("Unsupported grid type: {}", type);
                break;
        }
    }
    return lambdas;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ChannelSpacing(org.onosproject.net.ChannelSpacing) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) OchSignal(org.onosproject.net.OchSignal) LambdaConfig(org.onosproject.driver.optical.config.LambdaConfig) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) GridType(org.onosproject.net.GridType)

Example 52 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class GnpyManagerTest method testCreateOchSignal.

@Test
public void testCreateOchSignal() throws IOException {
    OchSignal signal = manager.createOchSignal(reply);
    System.out.println(signal);
    assertEquals(signal.gridType(), GridType.DWDM);
    assertEquals(signal.slotWidth().asGHz(), 50.000);
    assertEquals(-35, signal.spacingMultiplier());
}
Also used : OchSignal(org.onosproject.net.OchSignal) Test(org.junit.Test)

Example 53 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class AddOpticalIntentCommand method createOchSignal.

private OchSignal createOchSignal() throws IllegalArgumentException {
    if (signal == null) {
        return null;
    }
    try {
        String[] splitted = signal.split("/");
        checkArgument(splitted.length == 4, "signal requires 4 parameters: " + SIGNAL_FORMAT);
        int slotGranularity = Integer.parseInt(splitted[0]);
        String chSpacing = splitted[1];
        ChannelSpacing channelSpacing = checkNotNull(CHANNEL_SPACING_MAP.get(chSpacing), String.format("invalid channel spacing: %s", chSpacing));
        int multiplier = Integer.parseInt(splitted[2]);
        String gdType = splitted[3].toUpperCase();
        GridType gridType = GridType.valueOf(gdType);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } catch (RuntimeException e) {
        /* catching RuntimeException as both NullPointerException (thrown by
             * checkNotNull) and IllegalArgumentException (thrown by checkArgument)
             * are subclasses of RuntimeException.
             */
        String msg = String.format("Invalid signal format: %s, expected format is %s.", signal, SIGNAL_FORMAT);
        print(msg);
        throw new IllegalArgumentException(msg, e);
    }
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) OchSignal(org.onosproject.net.OchSignal) ConnectPoint(org.onosproject.net.ConnectPoint) GridType(org.onosproject.net.GridType)

Example 54 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class OpticalIntentsWebResource method decode.

private Intent decode(ObjectNode json) {
    JsonNode ingressJson = json.get(INGRESS_POINT);
    if (!ingressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
    JsonNode egressJson = json.get(EGRESS_POINT);
    if (!egressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
    JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
    boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
    JsonNode signalJson = json.get(SIGNAL);
    OchSignal signal = null;
    if (signalJson != null) {
        if (!signalJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            signal = OchSignalCodec.decode((ObjectNode) signalJson);
        }
    }
    String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
    CoreService service = getService(CoreService.class);
    ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
    Key key = null;
    DeviceService deviceService = get(DeviceService.class);
    JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
    DefaultPath suggestedPath = null;
    LinkService linkService = get(LinkService.class);
    if (suggestedPathJson != null) {
        if (!suggestedPathJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
            List<Link> listLinks = new ArrayList<>();
            for (JsonNode node : linksJson) {
                String srcString = node.get("src").asText();
                String dstString = node.get("dst").asText();
                ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
                ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
                Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
                if (link == null) {
                    throw new IllegalArgumentException("Not existing link in the suggested path");
                }
                listLinks.add(link);
            }
            if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
                throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
            }
            if (!isPathContiguous(listLinks)) {
                throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
            }
            suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
            log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
        }
    }
    return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) OchSignal(org.onosproject.net.OchSignal) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) ScalarWeight(org.onlab.graph.ScalarWeight) DefaultPath(org.onosproject.net.DefaultPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) LinkService(org.onosproject.net.link.LinkService) Key(org.onosproject.net.intent.Key) Link(org.onosproject.net.Link)

Example 55 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class OpticalConnectivityIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalConnectivityIntent intent, List<Intent> installable) {
    // Check if source and destination are optical OCh ports
    ConnectPoint src = intent.getSrc();
    ConnectPoint dst = intent.getDst();
    checkArgument(deviceService.getPort(src.deviceId(), src.port()) instanceof OchPort);
    checkArgument(deviceService.getPort(dst.deviceId(), dst.port()) instanceof OchPort);
    List<Resource> resources = new LinkedList<>();
    log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
    // Release of intent resources here is only a temporary solution for handling the
    // case of recompiling due to intent restoration (when intent state is FAILED).
    // TODO: try to release intent resources in IntentManager.
    resourceService.release(intent.key());
    // Check OCh port availability
    // If ports are not available, compilation fails
    // Else add port to resource reservation list
    Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
    Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
    if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
        log.error("Ports for the intent are not available. Intent: {}", intent);
        throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
    }
    resources.add(srcPortResource);
    resources.add(dstPortResource);
    // If there is a suggestedPath, use this path without further checking, otherwise trigger path computation
    Stream<Path> paths;
    if (intent.suggestedPath().isPresent()) {
        paths = Stream.of(intent.suggestedPath().get());
    } else {
        paths = getOpticalPaths(intent);
    }
    // Find first path that has the required resources
    Optional<Map.Entry<Path, List<OchSignal>>> found = paths.map(path -> Maps.immutableEntry(path, findFirstAvailableLambda(intent, path))).filter(entry -> !entry.getValue().isEmpty()).filter(entry -> convertToResources(entry.getKey(), entry.getValue()).stream().allMatch(resourceService::isAvailable)).findFirst();
    // Allocate resources and create optical path intent
    if (found.isPresent()) {
        log.debug("Suitable lightpath FOUND for intent {}", intent);
        resources.addAll(convertToResources(found.get().getKey(), found.get().getValue()));
        allocateResources(intent, resources);
        OchSignal ochSignal = OchSignal.toFixedGrid(found.get().getValue(), ChannelSpacing.CHL_50GHZ);
        return ImmutableList.of(createIntent(intent, found.get().getKey(), ochSignal));
    } else {
        log.error("Unable to find suitable lightpath for intent {}", intent);
        throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) 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) Resource(org.onosproject.net.resource.Resource) OchSignal(org.onosproject.net.OchSignal) ConnectPoint(org.onosproject.net.ConnectPoint) OchPort(org.onosproject.net.optical.OchPort) LinkedList(java.util.LinkedList)

Aggregations

OchSignal (org.onosproject.net.OchSignal)63 PortNumber (org.onosproject.net.PortNumber)17 ChannelSpacing (org.onosproject.net.ChannelSpacing)16 GridType (org.onosproject.net.GridType)14 DeviceId (org.onosproject.net.DeviceId)12 ConnectPoint (org.onosproject.net.ConnectPoint)11 DeviceService (org.onosproject.net.device.DeviceService)10 HashMap (java.util.HashMap)9 Set (java.util.Set)9 IntStream (java.util.stream.IntStream)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Logger (org.slf4j.Logger)8 ArrayList (java.util.ArrayList)7 Port (org.onosproject.net.Port)7 Collectors (java.util.stream.Collectors)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)6 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)6 Collections (java.util.Collections)5 List (java.util.List)5 Frequency (org.onlab.util.Frequency)5