Search in sources :

Example 6 with OduSignalType

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

the class OchPortHelper method asOchPort.

public static Optional<OchPort> asOchPort(Port port) {
    if (port instanceof OchPort) {
        return Optional.of((OchPort) port);
    }
    try {
        Annotations an = port.annotations();
        OduSignalType signalType = Enum.valueOf(OduSignalType.class, an.value(SIGNAL_TYPE));
        boolean isTunable = Boolean.valueOf(an.value(TUNABLE));
        ObjectNode obj = (ObjectNode) MAPPER.readTree(an.value(LAMBDA));
        OchSignal lambda = OchSignalCodec.decode(obj);
        // DefaultOchPort should filter them, if necessary.
        return Optional.of(new DefaultOchPort(port, signalType, isTunable, lambda));
    // TODO: it'll be better to verify each inputs properly
    // instead of catching all these Exceptions.
    } catch (IOException | NullPointerException | IllegalArgumentException | ClassCastException e) {
        log.warn("{} was not well-formed OCh port.", port, e);
        return Optional.empty();
    }
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) OduSignalType(org.onosproject.net.OduSignalType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OchSignal(org.onosproject.net.OchSignal) DefaultOchPort(org.onosproject.net.optical.impl.DefaultOchPort) IOException(java.io.IOException) OchPort(org.onosproject.net.optical.OchPort) DefaultOchPort(org.onosproject.net.optical.impl.DefaultOchPort)

Example 7 with OduSignalType

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

the class CriteriaTest method testMatchOduSignalTypeMethod.

// OduSignalTypeCriterion class
/**
 * Test the OduSignalType method.
 */
@Test
public void testMatchOduSignalTypeMethod() {
    OduSignalType oduSigType = OduSignalType.ODU2;
    Criterion matchoduSignalType = Criteria.matchOduSignalType(oduSigType);
    OduSignalTypeCriterion oduSignalTypeCriterion = checkAndConvert(matchoduSignalType, Criterion.Type.ODU_SIGTYPE, OduSignalTypeCriterion.class);
    assertThat(oduSignalTypeCriterion.signalType(), is(equalTo(oduSigType)));
}
Also used : OduSignalType(org.onosproject.net.OduSignalType) Test(org.junit.Test)

Example 8 with OduSignalType

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

the class CriterionCodecTest method matchOduSignalTypeTest.

/**
 * Tests Odu Signal Type criterion.
 */
@Test
public void matchOduSignalTypeTest() {
    OduSignalType signalType = OduSignalType.ODU2;
    Criterion criterion = Criteria.matchOduSignalType(signalType);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : OduSignalType(org.onosproject.net.OduSignalType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Example 9 with OduSignalType

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

the class OpticalCircuitIntentCompiler method availableSlotResources.

private List<Resource> availableSlotResources(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) {
    OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType);
    int requestedTsNum = oduSignalType.tributarySlots();
    Set<TributarySlot> commonTributarySlots = findCommonTributarySlotsOnCps(src, dst);
    if (commonTributarySlots.isEmpty()) {
        return Collections.emptyList();
    }
    if (commonTributarySlots.size() < requestedTsNum) {
        return Collections.emptyList();
    }
    Set<TributarySlot> tributarySlots = commonTributarySlots.stream().limit(requestedTsNum).collect(Collectors.toSet());
    final List<ConnectPoint> portsList = ImmutableList.of(src, dst);
    List<Resource> tributarySlotResources = portsList.stream().flatMap(cp -> tributarySlots.stream().map(ts -> Resources.discrete(cp.deviceId(), cp.port()).resource().child(ts))).collect(Collectors.toList());
    if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
        log.debug("Resource allocation for {} on {} and {} failed (resource request: {})", signalType, src, dst, tributarySlotResources);
        return Collections.emptyList();
    }
    return tributarySlotResources;
}
Also used : Arrays(java.util.Arrays) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ResourceService(org.onosproject.net.resource.ResourceService) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Pair(org.apache.commons.lang3.tuple.Pair) Port(org.onosproject.net.Port) TributarySlotQuery(org.onosproject.net.behaviour.TributarySlotQuery) ApplicationId(org.onosproject.core.ApplicationId) OchPort(org.onosproject.net.optical.OchPort) Driver(org.onosproject.net.driver.Driver) OduSignalUtils(org.onosproject.net.OduSignalUtils) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Resources(org.onosproject.net.resource.Resources) Deactivate(org.osgi.service.component.annotations.Deactivate) 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) CltSignalType(org.onosproject.net.CltSignalType) List(java.util.List) OduCltPort(org.onosproject.net.optical.OduCltPort) Stream(java.util.stream.Stream) OduSignalId(org.onosproject.net.OduSignalId) FlowRule(org.onosproject.net.flow.FlowRule) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Dictionary(java.util.Dictionary) IntentSetMultimap(org.onosproject.net.intent.IntentSetMultimap) Tools(org.onlab.util.Tools) ComponentContext(org.osgi.service.component.ComponentContext) AnnotationKeys(org.onosproject.net.AnnotationKeys) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) Criteria(org.onosproject.net.flow.criteria.Criteria) LinkedList(java.util.LinkedList) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OduSignalType(org.onosproject.net.OduSignalType) IntentId(org.onosproject.net.intent.IntentId) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) TributarySlot(org.onosproject.net.TributarySlot) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) MAX_CAPACITY(org.onosproject.net.optical.intent.impl.compiler.OsgiPropertyConstants.MAX_CAPACITY) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) Modified(org.osgi.service.component.annotations.Modified) MAX_CAPACITY_DEFAULT(org.onosproject.net.optical.intent.impl.compiler.OsgiPropertyConstants.MAX_CAPACITY_DEFAULT) Reference(org.osgi.service.component.annotations.Reference) Comparator(java.util.Comparator) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) OduSignalType(org.onosproject.net.OduSignalType) TributarySlot(org.onosproject.net.TributarySlot) Resource(org.onosproject.net.resource.Resource) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 10 with OduSignalType

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

the class OpticalOduIntentCompiler method findTributarySlots.

private Map<LinkKey, Set<TributarySlot>> findTributarySlots(OpticalOduIntent intent, Set<LinkKey> links) {
    OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(intent.getSignalType());
    int requestedTsNum = oduSignalType.tributarySlots();
    Map<LinkKey, Set<TributarySlot>> slotsMap = new HashMap<>();
    for (LinkKey link : links) {
        Set<TributarySlot> common = findCommonTributarySlotsOnCps(link.src(), link.dst());
        if (common.isEmpty() || (common.size() < requestedTsNum)) {
            log.debug("Failed to find TributarySlots on link {} requestedTsNum={}", link, requestedTsNum);
            // failed to find enough available TributarySlots on a link
            return Collections.emptyMap();
        }
        slotsMap.put(link, common.stream().limit(requestedTsNum).collect(Collectors.toSet()));
    }
    return slotsMap;
}
Also used : OduSignalType(org.onosproject.net.OduSignalType) LinkKey(org.onosproject.net.LinkKey) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) TributarySlot(org.onosproject.net.TributarySlot) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

OduSignalType (org.onosproject.net.OduSignalType)12 OchPort (org.onosproject.net.optical.OchPort)6 Port (org.onosproject.net.Port)5 ConnectPoint (org.onosproject.net.ConnectPoint)4 TributarySlot (org.onosproject.net.TributarySlot)4 DeviceService (org.onosproject.net.device.DeviceService)4 OduCltPort (org.onosproject.net.optical.OduCltPort)4 CltSignalType (org.onosproject.net.CltSignalType)3 OduSignalId (org.onosproject.net.OduSignalId)3 Intent (org.onosproject.net.intent.Intent)3 OpticalCircuitIntent (org.onosproject.net.intent.OpticalCircuitIntent)3 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Test (org.junit.Test)2 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)2 Device (org.onosproject.net.Device)2 OchSignal (org.onosproject.net.OchSignal)2 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)2