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();
}
}
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)));
}
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));
}
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;
}
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;
}
Aggregations