Search in sources :

Example 41 with Port

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

the class OpticalCircuitIntentCompiler method findAvailableOchPort.

private Optional<OchPort> findAvailableOchPort(ConnectPoint oduPort, OduSignalType ochPortSignalType) {
    // First see if the port mappings are constrained
    ConnectPoint ochCP = staticPort(oduPort);
    if (ochCP != null) {
        OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
        Optional<IntentId> intentId = resourceService.getResourceAllocations(Resources.discrete(ochCP.deviceId(), ochCP.port()).id()).stream().map(ResourceAllocation::consumerId).map(ResourceHelper::getIntentId).flatMap(Tools::stream).findAny();
        if (isAvailable(intentId.orElse(null))) {
            return Optional.of(ochPort);
        }
        return Optional.empty();
    }
    // No port constraints, so find any port that works
    List<Port> ports = deviceService.getPorts(oduPort.deviceId());
    for (Port port : ports) {
        if (!(port instanceof OchPort)) {
            continue;
        }
        // This should be the first allocation on the OCH port
        if (!resourceService.isAvailable(Resources.discrete(oduPort.deviceId(), port.number()).resource())) {
            continue;
        }
        // OchPort is required to have the requested oduSignalType
        if (((OchPort) port).signalType() != ochPortSignalType) {
            continue;
        }
        Optional<IntentId> intentId = resourceService.getResourceAllocations(Resources.discrete(oduPort.deviceId(), port.number()).id()).stream().map(ResourceAllocation::consumerId).map(ResourceHelper::getIntentId).flatMap(Tools::stream).findAny();
        if (isAvailable(intentId.orElse(null))) {
            return Optional.of((OchPort) port);
        }
    }
    return Optional.empty();
}
Also used : Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OduCltPort(org.onosproject.net.optical.OduCltPort) ConnectPoint(org.onosproject.net.ConnectPoint) OchPort(org.onosproject.net.optical.OchPort) IntentId(org.onosproject.net.intent.IntentId)

Example 42 with Port

use of org.onosproject.net.Port 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 43 with Port

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

the class OpticalConnectivityIntentCompiler method staticPort.

private ConnectPoint staticPort(ConnectPoint connectPoint) {
    Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
    String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT);
    // FIXME: need a better way to match the port
    if (staticPort != null) {
        for (Port p : deviceService.getPorts(connectPoint.deviceId())) {
            if (staticPort.equals(p.number().name())) {
                return new ConnectPoint(p.element().id(), p.number());
            }
        }
    }
    return null;
}
Also used : Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 44 with Port

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

the class OpticalOduIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalOduIntent intent, List<Intent> installable) {
    // Check if ports are OduClt ports
    ConnectPoint src = intent.getSrc();
    ConnectPoint dst = intent.getDst();
    Port srcPort = deviceService.getPort(src.deviceId(), src.port());
    Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
    checkArgument(srcPort instanceof OduCltPort);
    checkArgument(dstPort instanceof OduCltPort);
    log.debug("Compiling optical ODU 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 OduClt ports availability
    Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
    Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
    // If ports are not available, compilation fails
    if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
        throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
    }
    List<Resource> intentResources = new ArrayList<>();
    intentResources.add(srcPortResource);
    intentResources.add(dstPortResource);
    // Calculate available light paths
    Set<Path> paths = getOpticalPaths(intent);
    if (paths.isEmpty()) {
        throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
    }
    // Use first path that can be successfully reserved
    for (Path path : paths) {
        // Find available Tributary Slots on both directions of path
        Map<LinkKey, Set<TributarySlot>> slotsMap = findAvailableTributarySlots(intent, path);
        if (slotsMap.isEmpty()) {
            continue;
        }
        List<Resource> tributarySlotResources = convertToResources(slotsMap);
        if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
            continue;
        }
        intentResources.addAll(tributarySlotResources);
        allocateResources(intent, intentResources);
        List<FlowRule> rules = new LinkedList<>();
        // Create rules for forward and reverse path
        rules = createRules(intent, intent.getSrc(), intent.getDst(), path, slotsMap, false);
        if (intent.isBidirectional()) {
            rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
        }
        return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, ImmutableSet.copyOf(path.links()), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
    }
    throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
Also used : Path(org.onosproject.net.Path) LinkKey(org.onosproject.net.LinkKey) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Port(org.onosproject.net.Port) OduCltPort(org.onosproject.net.optical.OduCltPort) OtuPort(org.onosproject.net.optical.OtuPort) OduCltPort(org.onosproject.net.optical.OduCltPort) Resource(org.onosproject.net.resource.Resource) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) LinkedList(java.util.LinkedList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 45 with Port

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

the class OpticalPathIntentCompiler method reversePort.

/**
 * Returns the PortNum of reverse port if annotation is present, otherwise return PortNum of the port itself.
 * In the OpenROADM YANG models it is used the term "partner-port.
 *
 * @param portNumber the port
 * @return the PortNum of reverse port if annotation is present, otherwise PortNum of the port itself.
 */
private PortNumber reversePort(DeviceId deviceId, PortNumber portNumber) {
    Port port = deviceService.getPort(deviceId, portNumber);
    String reversePort = port.annotations().value(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY);
    if (reversePort != null) {
        PortNumber reversePortNumber = PortNumber.portNumber(reversePort);
        return reversePortNumber;
    } else {
        return portNumber;
    }
}
Also used : Port(org.onosproject.net.Port) PortNumber(org.onosproject.net.PortNumber)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28