use of org.onosproject.net.intent.OpticalConnectivityIntent 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.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method deleteIntent.
/**
* Delete the specified optical intent.
*
* @param appId application identifier
* @param keyString intent key
* @return 204 NO CONTENT
*/
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("{appId}/{key}")
public Response deleteIntent(@PathParam("appId") String appId, @PathParam("key") String keyString) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
nullIsNotFound(app, "Application Id not found");
IntentService intentService = get(IntentService.class);
Intent intent = intentService.getIntent(Key.of(keyString, app));
if (intent == null) {
intent = intentService.getIntent(Key.of(Long.decode(keyString), app));
}
nullIsNotFound(intent, "Intent Id is not found");
if ((intent instanceof OpticalConnectivityIntent) || (intent instanceof OpticalCircuitIntent)) {
intentService.withdraw(intent);
} else {
throw new IllegalArgumentException("Specified intent is not of type OpticalConnectivityIntent");
}
return Response.noContent().build();
}
use of org.onosproject.net.intent.OpticalConnectivityIntent 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.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.
the class OpticalPathProvisioner method createIntents.
/**
* Scans the list of cross connection points and returns a list of optical connectivity intents.
* During the process, save information about packet links to given set.
*
* @param crossConnectPoints list of (src, dst) pair between which optical path will be set up
* @return list of optical connectivity intents
*/
private List<Intent> createIntents(List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints) {
List<Intent> intents = new LinkedList<>();
Iterator<Pair<ConnectPoint, ConnectPoint>> itr = crossConnectPoints.iterator();
while (itr.hasNext()) {
// checkArgument at start ensures we'll always have pairs of connect points
Pair<ConnectPoint, ConnectPoint> next = itr.next();
ConnectPoint src = next.getLeft();
ConnectPoint dst = next.getRight();
Port srcPort = deviceService.getPort(src.deviceId(), src.port());
Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
OduCltPort srcOCPort = (OduCltPort) srcPort;
OduCltPort dstOCPort = (OduCltPort) dstPort;
if (!srcOCPort.signalType().equals(dstOCPort.signalType())) {
continue;
}
// Create OTN circuit
OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOCPort.signalType()).bidirectional(false).build();
intents.add(circuitIntent);
} else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
OchPort srcOchPort = (OchPort) srcPort;
OchPort dstOchPort = (OchPort) dstPort;
if (!srcOchPort.signalType().equals(dstOchPort.signalType())) {
continue;
}
// Create lightpath
OpticalConnectivityIntent opticalIntent = OpticalConnectivityIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOchPort.signalType()).bidirectional(false).build();
intents.add(opticalIntent);
} else {
log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
return Collections.emptyList();
}
}
return intents;
}
use of org.onosproject.net.intent.OpticalConnectivityIntent in project onos by opennetworkinglab.
the class OpticalPathProvisioner method setupPath.
/*
* Given a multi-layer path,
* compute a set of segments which requires
* OpticalConnectivity(~=OpticalConnectivityIntent or OpticalCircuitPath)
* to provide packet-layer connectivity.
*/
@Override
public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
checkNotNull(path);
log.debug("setupPath({}, {}, {})", path, bandwidth, latency);
// map of cross connect points (optical port -> packet port)
Map<ConnectPoint, ConnectPoint> crossConnectPointMap = new HashMap<>();
// list of (src, dst) pair of optical ports between which optical path should be installed
List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints = new ArrayList<>();
// Scan path to find pairs of connect points between which optical intent is installed
// opticalSrcPort works as a flag parameter to show scanning status
ConnectPoint opticalSrcPort = null;
for (Link link : path.links()) {
if (!isCrossConnectLink(link)) {
continue;
}
if (opticalSrcPort != null) {
// opticalSrcPort!=null means src port was already found
// in this case link.src() is optical layer, and link.dst() is packet layer
// Check if types of src port and dst port matches
Device srcDevice = checkNotNull(deviceService.getDevice(opticalSrcPort.deviceId()), "Unknown device ID");
Device dstDevice = checkNotNull(deviceService.getDevice(link.src().deviceId()), "Unknown device ID");
if (srcDevice.type() != dstDevice.type()) {
log.error("Unsupported mix of cross connect points : {}, {}", srcDevice.type(), dstDevice.type());
return null;
}
// Update cross connect points map
crossConnectPointMap.put(link.src(), link.dst());
// Add optical ports pair to list
crossConnectPoints.add(Pair.of(opticalSrcPort, link.src()));
// Reset flag parameter
opticalSrcPort = null;
} else {
// opticalSrcPort==null means src port was not found yet
// in this case link.src() is packet layer, and link.dst() is optical layer
// Update cross connect points map
crossConnectPointMap.put(link.dst(), link.src());
// Set opticalSrcPort to src of link (optical port)
opticalSrcPort = link.dst();
}
}
// create intents from cross connect points
List<Intent> intents = createIntents(crossConnectPoints);
if (intents.isEmpty()) {
log.error("No intents produced from {}", crossConnectPoints);
return null;
}
// create set of PacketLinkRealizedByOptical
Set<PacketLinkRealizedByOptical> packetLinks = createPacketLinkSet(crossConnectPoints, intents, crossConnectPointMap);
// create OpticalConnectivity object and store information to distributed store
OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency, packetLinks);
// store cross connect port usage
path.links().stream().filter(this::isCrossConnectLink).forEach(usedCrossConnectLinkSet::add);
// Submit the intents
for (Intent i : intents) {
intentService.submit(i);
log.debug("Submitted an intent: {}", i);
}
return connectivity.id();
}
Aggregations