use of org.onlab.graph.ScalarWeight 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.onlab.graph.ScalarWeight in project onos by opennetworkinglab.
the class OpticalPathProvisionerTest method testSetupPath.
/**
* Checks setupPath method works.
*/
@Test
public void testSetupPath() {
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
Path path = new DefaultPath(PROVIDER_ID, links, new ScalarWeight(0));
OpticalConnectivityId cid = target.setupPath(path, bandwidth, latency);
assertNotNull(cid);
// Checks intents are installed as expected
assertEquals(1, intentService.submitted.size());
assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
assertEquals(CP31, connIntent.getSrc());
assertEquals(CP52, connIntent.getDst());
}
use of org.onlab.graph.ScalarWeight 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.onlab.graph.ScalarWeight in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method compile.
@Override
public List<Intent> compile(PointToPointIntent intent, List<Intent> installable) {
log.trace("compiling {} {}", intent, installable);
ConnectPoint ingressPoint = intent.filteredIngressPoint().connectPoint();
ConnectPoint egressPoint = intent.filteredEgressPoint().connectPoint();
// Idea: use suggested path as primary and another path from path service as protection
if (intent.suggestedPath() != null && intent.suggestedPath().size() > 0) {
Path path = new DefaultPath(PID, intent.suggestedPath(), new ScalarWeight(1));
// Check intent constraints against suggested path and suggested path availability
if (checkPath(path, intent.constraints()) && pathAvailable(intent)) {
allocateIntentBandwidth(intent, path);
return asList(createLinkCollectionIntent(ImmutableSet.copyOf(intent.suggestedPath()), DEFAULT_COST, intent));
}
}
if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
return createZeroHopLinkCollectionIntent(intent);
}
// proceed with no protected paths
if (!ProtectionConstraint.requireProtectedPath(intent)) {
return createUnprotectedLinkCollectionIntent(intent);
}
try {
// attempt to compute and implement backup path
return createProtectedIntent(ingressPoint, egressPoint, intent, installable);
} catch (PathNotFoundException e) {
log.warn("Could not find disjoint Path for {}", intent);
// no disjoint path extant -- maximum one path exists between devices
return createSinglePathIntent(ingressPoint, egressPoint, intent, installable);
}
}
Aggregations