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