use of org.onosproject.net.intent.FlowRuleIntent 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.FlowRuleIntent in project onos by opennetworkinglab.
the class PathIntentCompiler method compile.
@Override
public List<Intent> compile(PathIntent intent, List<Intent> installable) {
List<FlowRule> rules = new LinkedList<>();
List<DeviceId> devices = new LinkedList<>();
compile(this, intent, rules, devices);
return ImmutableList.of(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), intent.type(), intent.resourceGroup()));
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method setPathsToRemove.
/**
* Sets instance variables erasePrimary and eraseBackup. If erasePrimary,
* the primary path is no longer viable and related intents will be deleted.
* If eraseBackup, the backup path is no longer viable and related intents
* will be deleted.
*
* @param intent intent whose resources are found to be disabled/inactive:
* if intent is part of primary path, primary path set for removal;
* if intent is part of backup path, backup path set for removal;
* if bad intent is of type failover, the ingress point is down,
* and both paths are rendered inactive.
* @return true if both primary and backup paths are to be removed
*/
private boolean setPathsToRemove(Intent intent) {
if (intent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) intent;
PathIntent.ProtectionType type = frIntent.type();
if (type == PathIntent.ProtectionType.PRIMARY || type == PathIntent.ProtectionType.FAILOVER) {
erasePrimary = true;
}
if (type == PathIntent.ProtectionType.BACKUP || type == PathIntent.ProtectionType.FAILOVER) {
eraseBackup = true;
}
}
return erasePrimary && eraseBackup;
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createProtectedIntent.
// FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
log.trace("createProtectedIntent");
DisjointPath path = getDisjointPath(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;
}
}
List<Intent> intentList = new ArrayList<>();
// primary path intent
List<Link> links = new ArrayList<>();
links.addAll(path.links());
links.add(createEdgeLink(egressPoint, false));
// backup path intent
List<Link> backupLinks = new ArrayList<>();
backupLinks.addAll(path.backup().links());
backupLinks.add(createEdgeLink(egressPoint, false));
/*
* One of the old paths is still entirely intact. This old path has
* already been made primary, so we must add a backup path intent
* and modify the failover group treatment accordingly.
*/
if (reusableIntents != null && reusableIntents.size() > 1) {
/*
* Ensures that the egress port on source device is different than
* that of existing path so that failover group will be useful
* (would not be useful if both output ports in group bucket were
* the same). Does not necessarily ensure that the new backup path
* is entirely disjoint from the old path.
*/
PortNumber primaryPort = getPrimaryPort(intent);
if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) {
reusableIntents.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.BACKUP));
updateFailoverGroup(intent, links);
return reusableIntents;
} else {
reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
updateFailoverGroup(intent, backupLinks);
return reusableIntents;
}
}
intentList.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
// add contents appropriately.
if (groupService.getGroup(ingressPoint.deviceId(), makeGroupKey(intent.id())) == null) {
// manufactured fast failover flow rule intent
createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), intent.key(), createFailoverFlowRules(intent), asList(ingressPoint.deviceId()), PathIntent.ProtectionType.FAILOVER, intent.resourceGroup());
intentList.add(frIntent);
} else {
updateFailoverGroup(intent, links);
updateFailoverGroup(intent, backupLinks);
}
return intentList;
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class LinkCollectionOptimizationTest method testOptimizationCoLocatedPointsTrivialForSp.
/**
* We test the proper optimization of sp2mp with trivial selector,
* trivial treatment, vlan encapsulation and co-located
* ingress/egress points.
*/
@Test
public void testOptimizationCoLocatedPointsTrivialForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11), new FilteredConnectPoint(d2p10), new FilteredConnectPoint(d3p10))).build();
sut.activate();
/*
* We use the FIRST_FIT to simplify tests.
*/
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.iterator().next();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).popVlan().setOutput(d1p11.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).popVlan().setOutput(d2p10.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p1.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().setOutput(d3p10.port()).build()));
sut.deactivate();
}
Aggregations