use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class IntentKeyImrCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
IntentService service = AbstractShellCommand.get(IntentService.class);
SortedSet<String> strings = delegate.getStrings();
service.getIntents().forEach(intent -> {
if (intent instanceof LinkCollectionIntent || intent instanceof PointToPointIntent) {
strings.add(intent.key().toString());
}
});
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class IntentMonitorAndRerouteManager method generateLinkCollectionIntent.
/**
* Generates a new {@Link LinkCollectionIntent} applying the new path.
* @param links List of links of the new path.
* @param intentKey Key of the intent you want to re-route.
* @param appId Application id that submits initially the intent.
* @return The new intent, if not possibile it will return the old intent already installed.
*/
private ConnectivityIntent generateLinkCollectionIntent(List<Link> links, Key intentKey, ApplicationId appId) {
checkNotNull(links);
checkNotNull(appId);
// Gets the oldIntent already installed
ConnectivityIntent oldIntent = monitoredIntents.get(appId).get(intentKey);
// Flush the statistics of the currently installed intent
flushIntentStatStore(intentKey);
// get the connect point of the old intent
// Left element of the Pair is the ingress, right one is the egress
Pair<Set<FilteredConnectPoint>, Set<FilteredConnectPoint>> cpPair = extractEndConnectPoints(oldIntent);
if (cpPair == null) {
return oldIntent;
}
// Now generate the new intent
LinkCollectionIntent newIntent = LinkCollectionIntent.builder().appId(oldIntent.appId()).key(intentKey).selector(oldIntent.selector()).filteredIngressPoints(ImmutableSet.copyOf(cpPair.getLeft())).filteredEgressPoints(ImmutableSet.copyOf(cpPair.getRight())).treatment(oldIntent.treatment()).priority(oldIntent.priority()).constraints(oldIntent.constraints()).links(ImmutableSet.copyOf(links)).applyTreatmentOnEgress(true).build();
return newIntent;
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class HostToHostIntentCompiler method createLinkCollectionIntent.
private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
// Try to allocate bandwidth
List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
allocateBandwidth(intent, pathCPs);
Link ingressLink = path.links().get(0);
Link egressLink = path.links().get(path.links().size() - 1);
FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
/*
* The path contains also the edge links, these are not necessary
* for the LinkCollectionIntent.
*/
Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageOutputPorts.
/**
* Helper method which handles the proper generation of the ouput actions.
*
* @param outPorts the output ports
* @param deviceId the current device
* @param intent the intent to compile
* @param outLabels the output labels
* @param type the encapsulation type
* @param preCondition the previous state
* @param treatmentBuilder the builder to update with the ouput actions
*/
private void manageOutputPorts(Set<PortNumber> outPorts, DeviceId deviceId, LinkCollectionIntent intent, Map<ConnectPoint, Identifier<?>> outLabels, EncapsulationType type, TrafficSelector.Builder preCondition, TrafficTreatment.Builder treatmentBuilder) {
/*
* We need to order the actions. First the actions
* related to the not-egress points. At the same time we collect
* also the egress points.
*/
List<FilteredConnectPoint> egressPoints = Lists.newArrayList();
for (PortNumber outPort : outPorts) {
Optional<FilteredConnectPoint> filteredEgressPoint = getFilteredConnectPointFromIntent(deviceId, outPort, intent);
if (!filteredEgressPoint.isPresent()) {
/*
* We build a temporary selector for the encapsulation.
*/
TrafficSelector.Builder encapBuilder = DefaultTrafficSelector.builder();
/*
* We retrieve the associated label to the output port.
*/
ConnectPoint cp = new ConnectPoint(deviceId, outPort);
Identifier<?> outLabel = outLabels.get(cp);
/*
* If there are not labels, we cannot handle.
*/
if (outLabel == null) {
throw new IntentCompilationException(String.format(NO_LABELS, cp));
}
/*
* In the core we match using encapsulation.
*/
updateSelectorFromEncapsulation(encapBuilder, type, outLabel);
/*
* We generate the transition.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(preCondition.build(), encapBuilder.build(), getEthType(intent.selector()));
/*
* We add the instruction necessary to the transition.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* Finally we set the output action.
*/
treatmentBuilder.setOutput(outPort);
/*
* The encapsulation modifies the packet. If we are optimizing
* we have to update the state.
*/
if (optimizeTreatments()) {
preCondition = encapBuilder;
}
} else {
egressPoints.add(filteredEgressPoint.get());
}
}
/*
* The idea is to order the egress points. Before we deal
* with the egress points which looks like similar to the
* selector derived from the previous state then the
* the others.
*/
TrafficSelector prevState = preCondition.build();
if (optimizeTreatments()) {
egressPoints = orderedEgressPoints(prevState, egressPoints);
}
/*
* In this case, we have to transit to the final
* state.
*/
generateEgressActions(treatmentBuilder, egressPoints, prevState, intent);
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class LinkCollectionCompiler method generateEgressActions.
/**
* Helper method to generate the egress actions.
*
* @param treatmentBuilder the treatment builder to update
* @param egressPoints the egress points
* @param initialState the initial state of the transition
*/
private void generateEgressActions(TrafficTreatment.Builder treatmentBuilder, List<FilteredConnectPoint> egressPoints, TrafficSelector initialState, LinkCollectionIntent intent) {
TrafficSelector prevState = initialState;
for (FilteredConnectPoint egressPoint : egressPoints) {
/*
* If we are at the egress, we have to transit to the final
* state. First we add the Intent treatment.
*/
intent.treatment().allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* We generate the transition FIP->FEP.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(prevState, egressPoint.trafficSelector(), getEthType(intent.selector()));
/*
* We add the instruction necessary to the transition.
* Potentially we override the intent treatment.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* Finally we set the output action.
*/
treatmentBuilder.setOutput(egressPoint.connectPoint().port());
if (optimizeTreatments()) {
/*
* We update the previous state. In this way instead of
* transiting from FIP->FEP we do FEP->FEP and so on.
*/
prevState = egressPoint.trafficSelector();
}
}
}
Aggregations