use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class ConfigLambdaQuery method queryLambdas.
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
ConnectPoint cp = new ConnectPoint(data().deviceId(), port);
LambdaConfig cfg = netcfg.getConfig(cp, LambdaConfig.class);
if (cfg == null) {
return ImmutableSet.of();
}
GridType type = cfg.gridType();
Optional<ChannelSpacing> dwdmSpacing = cfg.dwdmSpacing();
int start = cfg.slotStart();
int step = cfg.slotStep();
int end = cfg.slotEnd();
Set<OchSignal> lambdas = new LinkedHashSet<>();
for (int i = start; i <= end; i += step) {
switch(type) {
case DWDM:
lambdas.add(OchSignal.newDwdmSlot(dwdmSpacing.get(), i));
break;
case FLEX:
lambdas.add(OchSignal.newFlexGridSlot(i));
break;
case CWDM:
default:
log.warn("Unsupported grid type: {}", type);
break;
}
}
return lambdas;
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class GnpyManagerTest method testCreateOchSignal.
@Test
public void testCreateOchSignal() throws IOException {
OchSignal signal = manager.createOchSignal(reply);
System.out.println(signal);
assertEquals(signal.gridType(), GridType.DWDM);
assertEquals(signal.slotWidth().asGHz(), 50.000);
assertEquals(-35, signal.spacingMultiplier());
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class AddOpticalIntentCommand method createOchSignal.
private OchSignal createOchSignal() throws IllegalArgumentException {
if (signal == null) {
return null;
}
try {
String[] splitted = signal.split("/");
checkArgument(splitted.length == 4, "signal requires 4 parameters: " + SIGNAL_FORMAT);
int slotGranularity = Integer.parseInt(splitted[0]);
String chSpacing = splitted[1];
ChannelSpacing channelSpacing = checkNotNull(CHANNEL_SPACING_MAP.get(chSpacing), String.format("invalid channel spacing: %s", chSpacing));
int multiplier = Integer.parseInt(splitted[2]);
String gdType = splitted[3].toUpperCase();
GridType gridType = GridType.valueOf(gdType);
return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
} catch (RuntimeException e) {
/* catching RuntimeException as both NullPointerException (thrown by
* checkNotNull) and IllegalArgumentException (thrown by checkArgument)
* are subclasses of RuntimeException.
*/
String msg = String.format("Invalid signal format: %s, expected format is %s.", signal, SIGNAL_FORMAT);
print(msg);
throw new IllegalArgumentException(msg, e);
}
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method decode.
private Intent decode(ObjectNode json) {
JsonNode ingressJson = json.get(INGRESS_POINT);
if (!ingressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
JsonNode egressJson = json.get(EGRESS_POINT);
if (!egressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
JsonNode signalJson = json.get(SIGNAL);
OchSignal signal = null;
if (signalJson != null) {
if (!signalJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
signal = OchSignalCodec.decode((ObjectNode) signalJson);
}
}
String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
CoreService service = getService(CoreService.class);
ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
Key key = null;
DeviceService deviceService = get(DeviceService.class);
JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
DefaultPath suggestedPath = null;
LinkService linkService = get(LinkService.class);
if (suggestedPathJson != null) {
if (!suggestedPathJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
List<Link> listLinks = new ArrayList<>();
for (JsonNode node : linksJson) {
String srcString = node.get("src").asText();
String dstString = node.get("dst").asText();
ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
if (link == null) {
throw new IllegalArgumentException("Not existing link in the suggested path");
}
listLinks.add(link);
}
if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
}
if (!isPathContiguous(listLinks)) {
throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
}
suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
}
}
return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
use of org.onosproject.net.OchSignal 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