use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class PathCompiler method compile.
/**
* Compiles an intent down to flows.
*
* @param creator how to create the flows
* @param intent intent to process
* @param flows list of generated flows
* @param devices list of devices that correspond to the flows
*/
public void compile(PathCompilerCreateFlow<T> creator, PathIntent intent, List<T> flows, List<DeviceId> devices) {
// Note: right now recompile is not considered
// TODO: implement recompile behavior
List<Link> links = intent.path().links();
Optional<EncapsulationConstraint> encapConstraint = intent.constraints().stream().filter(constraint -> constraint instanceof EncapsulationConstraint).map(x -> (EncapsulationConstraint) x).findAny();
// if no encapsulation or is involved only a single switch use the default behaviour
if (!encapConstraint.isPresent() || links.size() == 2) {
for (int i = 0; i < links.size() - 1; i++) {
ConnectPoint ingress = links.get(i).dst();
ConnectPoint egress = links.get(i + 1).src();
creator.createFlow(intent.selector(), intent.treatment(), ingress, egress, intent.priority(), isLast(links, i), flows, devices);
}
return;
}
encapConstraint.map(EncapsulationConstraint::encapType).map(type -> {
switch(type) {
case VLAN:
manageVlanEncap(creator, flows, devices, intent);
break;
case MPLS:
manageMplsEncap(creator, flows, devices, intent);
break;
default:
}
return 0;
});
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createFailoverTreatmentGroup.
/**
* Creates a new failover group with the initial ports of the links
* from the primary and backup path.
*
* @param links links from the primary path
* @param backupLinks links from the backup path
* @param intent intent from which this call originates
*/
private void createFailoverTreatmentGroup(List<Link> links, List<Link> backupLinks, PointToPointIntent intent) {
List<GroupBucket> buckets = new ArrayList<>();
TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder();
ConnectPoint src = links.get(0).src();
tBuilderIn.setOutput(src.port());
TrafficTreatment.Builder tBuilderIn2 = DefaultTrafficTreatment.builder();
ConnectPoint src2 = backupLinks.get(0).src();
tBuilderIn2.setOutput(src2.port());
buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null));
buckets.add(DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn2.build(), src2.port(), null));
GroupBuckets groupBuckets = new GroupBuckets(buckets);
GroupDescription groupDesc = new DefaultGroupDescription(src.deviceId(), Group.Type.FAILOVER, groupBuckets, makeGroupKey(intent.id()), null, intent.appId());
log.trace("adding failover group {}", groupDesc);
groupService.addGroup(groupDesc);
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createFailoverFlowRules.
/**
* Manufactures flow rule with treatment that is defined by failover
* group and traffic selector determined by ingress port of the intent.
*
* @param intent intent which is being compiled (for appId)
* @return a list of a singular flow rule with fast failover
* outport traffic treatment
*/
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
List<FlowRule> flowRules = new ArrayList<>();
ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
DeviceId deviceId = ingress.deviceId();
// flow rule with failover traffic treatment
TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(ingress.port()).build();
FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
flowRules.add(flowRuleBuilder.withSelector(trafficSelector).withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))).fromApp(intent.appId()).makePermanent().forDevice(deviceId).withPriority(PRIORITY).build());
return flowRules;
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method pathAvailable.
/**
* Checks suggested path availability.
* It checks:
* - single links availability;
* - that first and last device of the path are coherent with ingress and egress devices;
* - links contiguity.
*
* @param intent Intent with suggested path to check
* @return true if the suggested path is available
*/
private boolean pathAvailable(PointToPointIntent intent) {
// Check links availability
List<Link> suggestedPath = intent.suggestedPath();
for (Link link : suggestedPath) {
if (!(link instanceof EdgeLink) && !linkService.getLinks(link.src()).contains(link)) {
return false;
}
}
// Check that first and last device of the path are intent ingress and egress devices
if (!suggestedPath.get(0).src().deviceId().equals(intent.filteredIngressPoint().connectPoint().deviceId())) {
return false;
}
if (!suggestedPath.get(suggestedPath.size() - 1).dst().deviceId().equals(intent.filteredEgressPoint().connectPoint().deviceId())) {
return false;
}
// Check contiguity
List<Pair<Link, Link>> linkPairs = IntStream.range(0, suggestedPath.size() - 1).mapToObj(i -> Pair.of(suggestedPath.get(i), suggestedPath.get(i + 1))).collect(Collectors.toList());
for (Pair<Link, Link> linkPair : linkPairs) {
if (!linkPair.getKey().dst().deviceId().equals(linkPair.getValue().src().deviceId())) {
return false;
}
}
return true;
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class ProtectedTransportIntentCompiler method createSubTransitIntent.
/**
* Creates required Intents required to transit uni-directionally along the Path.
*
* @param intent parent IntentId
* @param path whole path
* @param vid VlanId to use as tunnel labels
* @param resources to be passed down to generated Intents
* @return List of transit Intents, if any is required.
*/
LinkCollectionIntent createSubTransitIntent(Intent intent, Path path, VlanId vid, Collection<NetworkResource> resources) {
checkArgument(path.links().size() > 1);
// transit ingress/egress
ConnectPoint one = path.links().get(0).dst();
ConnectPoint two = path.links().get(path.links().size() - 1).src();
return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(resources).links(ImmutableSet.copyOf(path.links())).filteredIngressPoints(ImmutableSet.of(vlanPort(one, vid))).filteredEgressPoints(ImmutableSet.of(vlanPort(two, vid))).applyTreatmentOnEgress(true).cost(path.cost()).build();
}
Aggregations