use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalOduIntentCompiler method compile.
@Override
public List<Intent> compile(OpticalOduIntent intent, List<Intent> installable) {
// Check if ports are OduClt ports
ConnectPoint src = intent.getSrc();
ConnectPoint dst = intent.getDst();
Port srcPort = deviceService.getPort(src.deviceId(), src.port());
Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
checkArgument(srcPort instanceof OduCltPort);
checkArgument(dstPort instanceof OduCltPort);
log.debug("Compiling optical ODU 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 OduClt ports availability
Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
// If ports are not available, compilation fails
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
List<Resource> intentResources = new ArrayList<>();
intentResources.add(srcPortResource);
intentResources.add(dstPortResource);
// Calculate available light paths
Set<Path> paths = getOpticalPaths(intent);
if (paths.isEmpty()) {
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
// Use first path that can be successfully reserved
for (Path path : paths) {
// Find available Tributary Slots on both directions of path
Map<LinkKey, Set<TributarySlot>> slotsMap = findAvailableTributarySlots(intent, path);
if (slotsMap.isEmpty()) {
continue;
}
List<Resource> tributarySlotResources = convertToResources(slotsMap);
if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
continue;
}
intentResources.addAll(tributarySlotResources);
allocateResources(intent, intentResources);
List<FlowRule> rules = new LinkedList<>();
// Create rules for forward and reverse path
rules = createRules(intent, intent.getSrc(), intent.getDst(), path, slotsMap, false);
if (intent.isBidirectional()) {
rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
}
return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, ImmutableSet.copyOf(path.links()), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
}
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompiler method compile.
private List<Intent> compile(OpticalCircuitIntent intent, ConnectPoint src, ConnectPoint dst, Optional<OpticalConnectivityIntent> existingConnectivity, List<Resource> resources, boolean supportsMultiplexing) {
OpticalConnectivityIntent connectivityIntent;
List<Resource> required;
if (existingConnectivity.isPresent()) {
connectivityIntent = existingConnectivity.get();
required = resources;
} else {
// Find OCh ports with available resources
Pair<OchPort, OchPort> ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType());
if (ochPorts == null) {
throw new OpticalIntentCompilationException("Unable to find suitable OCH ports for intent " + intent);
}
ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number());
ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number());
// Create optical connectivity intent
// In this case the channel and path optionally specified in this circuit intent
// are used to create the connectivity intent
connectivityIntent = OpticalConnectivityIntent.builder().appId(appId).src(srcCP).dst(dstCP).priority(OPTICAL_CONNECTIVITY_INTENT_PRIORITY).signalType(ochPorts.getLeft().signalType()).bidirectional(intent.isBidirectional()).ochSignal(intent.ochSignal()).suggestedPath(intent.suggestedPath()).resourceGroup(intent.resourceGroup()).build();
if (!supportsMultiplexing) {
required = resources;
} else {
List<Resource> slots = availableSlotResources(srcCP, dstCP, intent.getSignalType());
if (slots.isEmpty()) {
throw new OpticalIntentCompilationException("Unable to find Tributary Slots for intent " + intent);
}
required = ImmutableList.<Resource>builder().addAll(resources).addAll(slots).build();
}
}
if (resourceService.allocate(intent.key(), required).isEmpty()) {
throw new OpticalIntentCompilationException("Unable to allocate resources for intent " + intent + ": resources=" + required);
}
intentService.submit(connectivityIntent);
// Save circuit to connectivity intent mapping
intentSetMultimap.allocateMapping(connectivityIntent.id(), intent.id());
FlowRuleIntent circuitIntent = createFlowRule(intent, connectivityIntent, required.stream().flatMap(x -> Tools.stream(x.valueAs(TributarySlot.class))).collect(Collectors.toSet()));
return ImmutableList.of(circuitIntent);
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalPathIntentCompiler method compile.
@Override
public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable) {
log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst());
// Create rules for forward and reverse path
List<FlowRule> rules = createRules(intent);
if (intent.isBidirectional()) {
rules.addAll(createReverseRules(intent));
}
return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
}
use of org.onosproject.net.intent.FlowRuleIntent 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.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompilerTest method test10GbeMultiplexOverOdu2.
/**
* Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
* - All TributarySlots are used
*/
@Test
public void test10GbeMultiplexOverOdu2() {
// Use driver with TributarySlotQuery Behaviour
sut.driverService = new MockDriverServiceWithTs();
ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
intent = OpticalCircuitIntent.builder().appId(APP_ID).key(KEY1).src(oduCltSrcCP).dst(oduCltDstCP).signalType(D1P3.signalType()).bidirectional(false).build();
sut.activate(null);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(device1.id())).findFirst().get();
// validate SRC selector
TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
selectorBuilder1.matchInPort(oduCltSrcCP.port());
selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
assertThat(rule1.selector(), is(selectorBuilder1.build()));
// validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
treatmentBuilder1.setOutput(ochSrcCP.port());
assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(device2.id())).findFirst().get();
// validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
selectorBuilder2.matchInPort(ochDstCP.port());
selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
assertThat(rule2.selector(), is(selectorBuilder2.build()));
// validate DST treatment
assertThat(rule2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()));
rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", intent.priority(), rule.priority()));
sut.deactivate();
}
Aggregations