use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class AdvaTerminalDeviceDiscovery method parseLogicalChannel.
/**
* Parses a component XML doc into a PortDescription.
*
* @param channel subtree to parse. It must be a component ot type PORT.
* case we need to check transceivers or optical channels.
*
* @return PortDescription or null if component does not have onos-index
*/
private PortDescription parseLogicalChannel(HierarchicalConfiguration channel) {
HierarchicalConfiguration config = channel.configurationAt("config");
String logicalChannelIndex = config.getString("index");
String description = config.getString("description");
String rateClass = config.getString("rate-class");
log.info("Parsing Component {} type {} speed {}", logicalChannelIndex, description, rateClass);
Map<String, String> annotations = new HashMap<>();
annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
// Store all properties as port properties
// e.g. xe1/1
Pattern clientPattern = Pattern.compile("(\\d*)/(\\d*)/c(\\d)");
Pattern linePattern = Pattern.compile("(\\d*)/(\\d*)/n(\\d)");
Matcher clientMatch = clientPattern.matcher(description);
Matcher lineMatch = linePattern.matcher(description);
Pattern portSpeedPattern = Pattern.compile("TRIB_RATE_([0-9.]*)G");
Matcher portSpeedMatch = portSpeedPattern.matcher(rateClass);
Builder builder = DefaultPortDescription.builder();
if (portSpeedMatch.find()) {
Long speed = Long.parseLong(portSpeedMatch.group(1));
builder.portSpeed(speed * 1000);
}
if (clientMatch.find()) {
Long num = Long.parseLong(clientMatch.group(1));
Long portNum = 100 + num;
String connectionId = "connection:" + num.toString();
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, description);
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
builder.withPortNumber(PortNumber.portNumber(portNum));
builder.type(Type.PACKET);
builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
} else if (lineMatch.find()) {
Long num = (Long.parseLong(lineMatch.group(1)) - 1) * 2 + Long.parseLong(lineMatch.group(2));
Long portNum = 200 + num;
String connectionId = "connection:" + num.toString();
description = description.substring(0, description.length() - 6);
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, "optch " + description);
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNum), true, // TODO Client signal to be discovered
OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
} else {
log.warn("Unexpected component description: {}", description);
return null;
}
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method getIntents.
/**
* Get the optical intents on the network.
*
* @return 200 OK
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
DeviceService deviceService = get(DeviceService.class);
IntentService intentService = get(IntentService.class);
Iterator intentItr = intentService.getIntents().iterator();
ArrayNode arrayFlows = mapper().createArrayNode();
while (intentItr.hasNext()) {
Intent intent = (Intent) intentItr.next();
if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent opticalConnectivityIntent = (OpticalConnectivityIntent) intent;
Device srcDevice = deviceService.getDevice(opticalConnectivityIntent.getSrc().deviceId());
Device dstDevice = deviceService.getDevice(opticalConnectivityIntent.getDst().deviceId());
String srcDeviceName = srcDevice.annotations().value(AnnotationKeys.NAME);
String dstDeviceName = dstDevice.annotations().value(AnnotationKeys.NAME);
ObjectNode objectNode = mapper().createObjectNode();
objectNode.put("intent id", opticalConnectivityIntent.id().toString());
objectNode.put("app id", opticalConnectivityIntent.appId().name());
objectNode.put("state", intentService.getIntentState(opticalConnectivityIntent.key()).toString());
objectNode.put("src", opticalConnectivityIntent.getSrc().toString());
objectNode.put("dst", opticalConnectivityIntent.getDst().toString());
objectNode.put("srcName", srcDeviceName);
objectNode.put("dstName", dstDeviceName);
// Only for INSTALLED intents
if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) {
// Retrieve associated FlowRuleIntent
FlowRuleIntent installableIntent = (FlowRuleIntent) intentService.getInstallableIntents(opticalConnectivityIntent.key()).stream().filter(FlowRuleIntent.class::isInstance).findFirst().orElse(null);
// TODO store utilized ochSignal in the intent resources
if (installableIntent != null) {
OchSignal signal = installableIntent.flowRules().stream().filter(r -> r.selector().criteria().size() == NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE).map(r -> ((OchSignalCriterion) r.selector().getCriterion(Criterion.Type.OCH_SIGID)).lambda()).findFirst().orElse(null);
objectNode.put("ochSignal", signal.toString());
objectNode.put("centralFreq", signal.centralFrequency().asTHz() + " THz");
}
// Retrieve path and print it to REST
if (installableIntent != null) {
String path = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).map(r -> deviceService.getDevice(r.src().deviceId())).map(r -> r.annotations().value(AnnotationKeys.NAME)).collect(Collectors.joining(" -> "));
List<Link> pathLinks = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).collect(Collectors.toList());
DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, pathLinks, new ScalarWeight(1));
objectNode.put("path", defaultPath.toString());
objectNode.put("pathName", path + " -> " + dstDeviceName);
}
}
arrayFlows.add(objectNode);
}
}
ObjectNode root = this.mapper().createObjectNode().putPOJO("Intents", arrayFlows);
return ok(root).build();
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class OpticalConnectivityIntentCompiler method findFirstLambda.
/**
* Returns list of consecutive resources in given set of lambdas.
*
* @param lambdas list of lambdas
* @param count number of consecutive lambdas to return
* @return list of consecutive lambdas
*/
private List<OchSignal> findFirstLambda(Set<OchSignal> lambdas, int count) {
// Sort available lambdas
List<OchSignal> lambdaList = new ArrayList<>(lambdas);
lambdaList.sort(new DefaultOchSignalComparator());
// Means there is only exactly one set of lambdas available
if (lambdaList.size() == count) {
return lambdaList;
}
// Look ahead by count and ensure spacing multiplier is as expected (i.e., no gaps)
for (int i = 0; i < lambdaList.size() - count; i++) {
if (lambdaList.get(i).spacingMultiplier() + 2 * count == lambdaList.get(i + count).spacingMultiplier()) {
return lambdaList.subList(i, i + count);
}
}
return Collections.emptyList();
}
use of org.onosproject.net.OchSignal 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.OchSignal 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;
}
}
Aggregations