use of org.onosproject.net.optical.OchPort in project onos by opennetworkinglab.
the class RoadmUtil method createOchSignalFromWavelength.
public static OchSignal createOchSignalFromWavelength(double wavelength, DeviceService deviceService, DeviceId deviceId, PortNumber portNumber) {
if (wavelength == 0L) {
return null;
}
Port port = deviceService.getPort(deviceId, portNumber);
Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
if (ochPortOpt.isPresent()) {
OchPort ochPort = ochPortOpt.get();
GridType gridType = ochPort.lambda().gridType();
ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
int slotGranularity = ochPort.lambda().slotGranularity();
int multiplier = getMultiplier(wavelength, gridType, channelSpacing);
return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
} else {
return null;
}
}
use of org.onosproject.net.optical.OchPort in project onos by opennetworkinglab.
the class PortWaveLengthCommand method createOchSignalFromWavelength.
private OchSignal createOchSignalFromWavelength(DeviceService deviceService, ConnectPoint cp) {
long wavelength = Long.parseLong(parameter);
if (wavelength == 0L) {
return null;
}
Port port = deviceService.getPort(cp);
Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
if (ochPortOpt.isPresent()) {
OchPort ochPort = ochPortOpt.get();
GridType gridType = ochPort.lambda().gridType();
ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
int slotGranularity = ochPort.lambda().slotGranularity();
int multiplier = getMultplier(wavelength, gridType, channelSpacing);
return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
} else {
print("[ERROR] connect point %s is not OChPort", cp);
return null;
}
}
use of org.onosproject.net.optical.OchPort 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.optical.OchPort in project onos by opennetworkinglab.
the class OpticalPortsListCommand method printPorts.
@Override
protected void printPorts(DeviceService service, Device device) {
List<Port> ports = new ArrayList<>(service.getPorts(device.id()));
ports.sort((p1, p2) -> Long.signum(p1.number().toLong() - p2.number().toLong()));
for (Port port : ports) {
if (!isIncluded(port)) {
continue;
}
String portName = port.number().toString();
String portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
String portType = port.type().toString().toLowerCase();
switch(port.type()) {
case OCH:
if (port instanceof OchPort) {
OchPort och = (OchPort) port;
print(FMT_OCH, portName, portIsEnabled, portType, och.signalType().toString(), och.isTunable() ? "yes" : "no", annotations(och.unhandledAnnotations()));
break;
}
print("WARN: OchPort but not on OpticalDevice or ill-formed");
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
break;
case ODUCLT:
if (port instanceof OduCltPort) {
OduCltPort oduCltPort = (OduCltPort) port;
print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType, oduCltPort.signalType().toString(), annotations(oduCltPort.unhandledAnnotations()));
break;
}
print("WARN: OduCltPort but not on OpticalDevice or ill-formed");
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
break;
case OMS:
if (port instanceof OmsPort) {
OmsPort oms = (OmsPort) port;
print(FMT_OMS, portName, portIsEnabled, portType, oms.minFrequency().asHz() / Frequency.ofGHz(1).asHz(), oms.maxFrequency().asHz() / Frequency.ofGHz(1).asHz(), oms.grid().asHz() / Frequency.ofGHz(1).asHz(), oms.totalChannels(), annotations(oms.unhandledAnnotations()));
break;
}
print("WARN: OmsPort but not on OpticalDevice or ill-formed");
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
break;
case OTU:
if (port instanceof OtuPort) {
OtuPort otuPort = (OtuPort) port;
print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType, otuPort.signalType().toString(), annotations(otuPort.unhandledAnnotations()));
break;
}
print("WARN: OtuPort but not on OpticalDevice or ill-formed");
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
break;
default:
// do not print non-optical ports
break;
}
}
}
use of org.onosproject.net.optical.OchPort 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);
}
}
Aggregations