use of org.onosproject.net.DefaultPath 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.DefaultPath in project onos by opennetworkinglab.
the class OpticalPathIntentCompilerTest method setUp.
@Before
public void setUp() {
sut = new OpticalPathIntentCompiler();
coreService = createMock(CoreService.class);
expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
sut.coreService = coreService;
super.setUp();
intent = OpticalPathIntent.builder().appId(appId).src(d1p1).dst(d3p1).path(new DefaultPath(PID, links, ScalarWeight.toWeight(hops))).lambda(createLambda()).signalType(OchSignalType.FIXED_GRID).build();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(OpticalPathIntent.class, sut);
intentExtensionService.unregisterCompiler(OpticalPathIntent.class);
sut.intentManager = intentExtensionService;
replay(coreService, intentExtensionService);
}
use of org.onosproject.net.DefaultPath in project onos by opennetworkinglab.
the class LatencyConstraintTest method setUp.
@Before
public void setUp() {
resourceContext = createMock(ResourceContext.class);
Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).annotations(annotations1).build();
link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).annotations(annotations2).build();
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
}
use of org.onosproject.net.DefaultPath in project onos by opennetworkinglab.
the class WaypointConstraintTest method setUp.
@Before
public void setUp() {
resourceContext = createMock(ResourceContext.class);
link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).build();
link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).build();
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
}
use of org.onosproject.net.DefaultPath in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createSinglePathIntent.
private List<Intent> createSinglePathIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
List<Link> links = new ArrayList<>();
Path onlyPath = getPathOrException(intent, ingressPoint.deviceId(), egressPoint.deviceId());
List<Intent> reusableIntents = null;
if (installable != null) {
reusableIntents = filterInvalidSubIntents(installable, intent);
if (reusableIntents.size() == installable.size()) {
// all old paths are still viable
return installable;
}
}
// return the intents that comprise it.
if (reusableIntents != null && reusableIntents.size() > 1) {
return reusableIntents;
} else {
// Allocate bandwidth if a bandwidth constraint is set
allocateIntentBandwidth(intent, onlyPath);
links.add(createEdgeLink(ingressPoint, true));
links.addAll(onlyPath.links());
links.add(createEdgeLink(egressPoint, false));
return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.weight(), onlyPath.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
}
}
Aggregations