use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest method testSingleLongPathCompilation.
/**
* Tests a pair of hosts with 8 hops between them.
*/
@Test
public void testSingleLongPathCompilation() {
HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO);
assertThat(intent, is(notNullValue()));
String[] hops = { HOST_ONE, S1, S2, S3, S4, S5, S6, S7, S8, HOST_TWO };
HostToHostIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(2));
Intent forwardIntent = result.get(0);
assertThat(forwardIntent instanceof LinkCollectionIntent, is(true));
Intent reverseIntent = result.get(1);
assertThat(reverseIntent instanceof LinkCollectionIntent, is(true));
LinkCollectionIntent forwardLCIntent = (LinkCollectionIntent) forwardIntent;
Set<Link> links = forwardLCIntent.links();
assertThat(links, hasSize(7));
Set<FilteredConnectPoint> ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
assertThat(forwardLCIntent.filteredIngressPoints(), is(ingressPoints));
assertThat(links, linksHasPath(S1, S2));
assertThat(links, linksHasPath(S2, S3));
assertThat(links, linksHasPath(S3, S4));
assertThat(links, linksHasPath(S4, S5));
assertThat(links, linksHasPath(S5, S6));
assertThat(links, linksHasPath(S6, S7));
assertThat(links, linksHasPath(S7, S8));
Set<FilteredConnectPoint> egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
assertThat(forwardLCIntent.filteredEgressPoints(), is(egressPoints));
LinkCollectionIntent reverseLCIntent = (LinkCollectionIntent) reverseIntent;
links = reverseLCIntent.links();
assertThat(reverseLCIntent.links(), hasSize(7));
ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
assertThat(reverseLCIntent.filteredIngressPoints(), is(ingressPoints));
assertThat(links, linksHasPath(S2, S1));
assertThat(links, linksHasPath(S3, S2));
assertThat(links, linksHasPath(S4, S3));
assertThat(links, linksHasPath(S5, S4));
assertThat(links, linksHasPath(S6, S5));
assertThat(links, linksHasPath(S7, S6));
assertThat(links, linksHasPath(S8, S7));
egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
assertThat("key is inherited", result.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class TrafficMonitorBase method createTrafficLinks.
protected void createTrafficLinks(Highlights highlights, TrafficLinkMap linkMap, Set<Intent> intents, LinkHighlight.Flavor flavor, boolean showTraffic) {
for (Intent intent : intents) {
List<Intent> installables = services.intent().getInstallableIntents(intent.key());
Iterable<Link> links = null;
if (installables != null) {
for (Intent installable : installables) {
if (installable instanceof PathIntent) {
links = ((PathIntent) installable).path().links();
} else if (installable instanceof FlowRuleIntent) {
Collection<Link> l = new ArrayList<>();
l.addAll(linkResources(installable));
// Add cross connect links
if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent ocIntent = (OpticalConnectivityIntent) intent;
LinkService linkService = services.link();
DeviceService deviceService = services.device();
l.addAll(linkService.getDeviceIngressLinks(ocIntent.getSrc().deviceId()).stream().filter(i -> deviceService.getDevice(i.src().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
l.addAll(linkService.getDeviceEgressLinks(ocIntent.getDst().deviceId()).stream().filter(e -> deviceService.getDevice(e.dst().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
}
links = l;
} else if (installable instanceof FlowObjectiveIntent) {
links = linkResources(installable);
} else if (installable instanceof LinkCollectionIntent) {
links = ((LinkCollectionIntent) installable).links();
} else if (installable instanceof OpticalPathIntent) {
links = ((OpticalPathIntent) installable).path().links();
}
if (links == null) {
links = Lists.newArrayList();
}
links = addEdgeLinksIfNeeded(intent, Lists.newArrayList(links));
boolean isOptical = intent instanceof OpticalConnectivityIntent;
processLinks(linkMap, links, flavor, isOptical, showTraffic);
updateHighlights(highlights, links);
}
}
}
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class IntentsListCommand method detailsFormat.
/**
* Returns detailed information text about a specific intent.
*
* @param intent to print
* @param state of intent
* @return detailed information or "" if {@code state} was null
*/
private StringBuilder detailsFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder();
if (state == null) {
return builder;
}
if (!intent.resources().isEmpty()) {
builder.append('\n').append(format(RESOURCES, intent.resources()));
}
if (intent instanceof ConnectivityIntent) {
ConnectivityIntent ci = (ConnectivityIntent) intent;
if (!ci.selector().criteria().isEmpty()) {
builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
}
if (!ci.treatment().allInstructions().isEmpty()) {
builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
}
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
}
}
if (intent instanceof HostToHostIntent) {
HostToHostIntent pi = (HostToHostIntent) intent;
builder.append('\n').append(format(SRC + HOST, pi.one()));
builder.append('\n').append(format(DST + HOST, pi.two()));
} else if (intent instanceof PointToPointIntent) {
PointToPointIntent pi = (PointToPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof SinglePointToMultiPointIntent) {
SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
} else if (intent instanceof PathIntent) {
PathIntent pi = (PathIntent) intent;
builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
} else if (intent instanceof LinkCollectionIntent) {
LinkCollectionIntent li = (LinkCollectionIntent) intent;
builder.append('\n').append(format("links=%s", li.links()));
builder.append('\n').append(format(CP, li.egressPoints()));
} else if (intent instanceof OpticalCircuitIntent) {
OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
} else if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
} else if (intent instanceof OpticalOduIntent) {
OpticalOduIntent ci = (OpticalOduIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
}
List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
if (showInstallable && installable != null && !installable.isEmpty()) {
builder.append('\n').append(format(INSTALLABLE, installable));
}
return builder;
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageMpIntent.
/**
* Manages the Intents with multiple ingress points creating properly
* the selector builder and the treatment builder.
*
* @param selectorBuilder the selector builder to update
* @param treatmentBuilder the treatment builder to update
* @param intent the intent to compile
* @param inPort the input port of the current device
* @param deviceId the current device
* @param outPorts the output ports of this device
*/
private void manageMpIntent(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, PortNumber inPort, DeviceId deviceId, Set<PortNumber> outPorts) {
/*
* Sanity check
*/
if (intent.filteredEgressPoints().size() != 1) {
throw new IntentCompilationException(WRONG_EGRESS);
}
/*
* We try to understand if the device is one of the ingress points.
*/
Optional<FilteredConnectPoint> filteredIngressPoint = getFilteredConnectPointFromIntent(deviceId, inPort, intent);
/*
* We retrieve from the Intent the unique egress points.
*/
Optional<FilteredConnectPoint> filteredEgressPoint = intent.filteredEgressPoints().stream().findFirst();
/*
* We check if the device is the ingress device
*/
if (filteredIngressPoint.isPresent()) {
/*
* We are at ingress, so basically what we have to do is this:
* apply a set of operations (treatment, FEP) in order to have
* a transition from the initial state to the final state.
*
* We initialize the treatment with the Intent treatment
*/
intent.treatment().allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* We build the final selector, adding the selector
* of the FIP to the Intent selector and potentially
* overriding its matches.
*/
filteredIngressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
/*
* We define the transition FIP->FEP, basically
* the set of the operations we need for reaching
* the final state.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(filteredIngressPoint.get().trafficSelector(), filteredEgressPoint.get().trafficSelector(), getEthType(intent.selector()));
/*
* We add to the treatment the actions necessary for the
* transition, potentially overriding the treatment of the
* Intent. The Intent treatment has always a low priority
* in respect of the FEP.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
} else {
/*
* We are in the core or in the egress switch.
* The packets are in their final state. We need
* to match against this final state.
*
* we derive the final state defined by the intent
* treatment.
*/
updateBuilder(selectorBuilder, intent.treatment());
/*
* We derive the final state defined by the unique
* FEP. We merge the two states.
*/
filteredEgressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
}
/*
* Finally we set the output action.
*/
outPorts.forEach(treatmentBuilder::setOutput);
}
use of org.onosproject.net.intent.LinkCollectionIntent in project onos by opennetworkinglab.
the class LinkCollectionCompiler method getDomainIntents.
/**
* Creates the domain intents that the {@link LinkCollectionIntent} contains.
*
* @param intent the link collection intent
* @param domainService the domain service
* @return the resulting list of domain intents
*/
protected List<Intent> getDomainIntents(LinkCollectionIntent intent, DomainService domainService) {
ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
// TODO: support multi point to multi point
if (intent.filteredIngressPoints().size() != 1 || intent.filteredEgressPoints().size() != 1) {
log.warn("Multiple ingress or egress ports not supported!");
return intentList.build();
}
ImmutableList.Builder<Link> domainLinks = ImmutableList.builder();
// get the initial ingress connection point
FilteredConnectPoint ingress = intent.filteredIngressPoints().iterator().next();
FilteredConnectPoint egress;
DeviceId currentDevice = ingress.connectPoint().deviceId();
// the current domain (or LOCAL)
DomainId currentDomain = domainService.getDomain(currentDevice);
// if we entered a domain store the domain ingress
FilteredConnectPoint domainIngress = LOCAL.equals(currentDomain) ? null : ingress;
// this is necessary because a set is not sorted by default
for (int i = 0; i < intent.links().size(); i++) {
// find the next link
List<Link> nextLinks = getEgressLinks(intent.links(), currentDevice);
// no matching link exists
if (nextLinks.isEmpty()) {
throw new IntentCompilationException("No matching link starting at " + ingress.connectPoint().deviceId());
}
// get the first link
Link nextLink = nextLinks.get(0);
ingress = new FilteredConnectPoint(nextLink.src());
egress = new FilteredConnectPoint(nextLink.dst());
// query the domain for the domain of the link's destination
DomainId dstDomain = domainService.getDomain(egress.connectPoint().deviceId());
if (!currentDomain.equals(dstDomain)) {
// we are leaving the current domain or LOCAL
log.debug("Domain transition from {} to {}.", currentDomain, dstDomain);
if (!LOCAL.equals(currentDomain)) {
// add the domain intent to the intent list
intentList.add(createDomainP2PIntent(intent, domainIngress, ingress, domainLinks.build()));
// TODO: might end up with an unused builder
// reset domain links builder
domainLinks = ImmutableList.builder();
}
// update current domain (might be LOCAL)
currentDomain = dstDomain;
// update the domain's ingress
domainIngress = LOCAL.equals(currentDomain) ? null : egress;
} else {
if (!LOCAL.equals(currentDomain)) {
// we are staying in the same domain, store the traversed link
domainLinks.add(nextLink);
log.debug("{} belongs to the same domain.", egress.connectPoint().deviceId());
}
}
currentDevice = egress.connectPoint().deviceId();
}
// get the egress point
egress = intent.filteredEgressPoints().iterator().next();
// still inside a domain?
if (!LOCAL.equals(currentDomain) && currentDomain.equals(domainService.getDomain(egress.connectPoint().deviceId()))) {
// add intent
intentList.add(createDomainP2PIntent(intent, domainIngress, egress, domainLinks.build()));
}
return intentList.build();
}
Aggregations