use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.
private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
if (inPortCriterion != null) {
builder.withKey(inPortCriterion);
}
FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
AtomicBoolean emptyCondition = new AtomicBoolean(true);
if (ingressPoint != null) {
// ingress point, use criterion of it
ingressPoint.trafficSelector().criteria().forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
// encapsulation enabled, use encapsulation label and tag.
EncapsulationConstraint encap = encapConstraint.get();
switch(encap.encapType()) {
case VLAN:
builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
emptyCondition.set(false);
break;
case MPLS:
builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
emptyCondition.set(false);
break;
default:
log.warn("No filtering rule found because of unknown encapsulation type.");
break;
}
} else {
// encapsulation not enabled, check if the treatment applied to the ingress or not
if (intent.applyTreatmentOnEgress()) {
// filtering criterion will be changed on egress point, use
// criterion of ingress point
ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
if (ingressPoint == null) {
log.warn("No filtering rule found because no ingress point in the Intent");
} else {
ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
} else {
// filtering criterion will be changed on ingress point, use
// criterion of egress point
FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
if (egressPoint == null) {
log.warn("No filtering rule found because no egress point in the Intent");
} else {
egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
}
}
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
use of org.onosproject.net.flow.TrafficSelector 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.flow.TrafficSelector 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.flow.TrafficSelector in project onos by opennetworkinglab.
the class FlowObjectiveCompositionUtil method composeSequential.
public static ForwardingObjective composeSequential(ForwardingObjective fo1, ForwardingObjective fo2, int priorityMultiplier) {
TrafficSelector revertTrafficSelector = revertTreatmentSelector(fo1.treatment(), fo2.selector());
if (revertTrafficSelector == null) {
return null;
}
TrafficSelector trafficSelector = intersectTrafficSelector(fo1.selector(), revertTrafficSelector);
if (trafficSelector == null) {
return null;
}
TrafficTreatment trafficTreatment = unionTrafficTreatment(fo1.treatment(), fo2.treatment());
return DefaultForwardingObjective.builder().fromApp(fo1.appId()).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withPriority(fo1.priority() * priorityMultiplier + fo2.priority()).withSelector(trafficSelector).withTreatment(trafficTreatment).add();
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class FlowObjectiveCompositionUtil method intersectTrafficSelector.
public static TrafficSelector intersectTrafficSelector(TrafficSelector ts1, TrafficSelector ts2) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Set<Criterion.Type> ts1IntersectTs2 = getTypeSet(ts1);
ts1IntersectTs2.retainAll(getTypeSet(ts2));
for (Criterion.Type type : ts1IntersectTs2) {
Criterion criterion = intersectCriterion(ts1.getCriterion(type), ts2.getCriterion(type));
if (criterion == null) {
return null;
} else {
selectorBuilder.add(criterion);
}
}
Set<Criterion.Type> ts1MinusTs2 = getTypeSet(ts1);
ts1MinusTs2.removeAll(getTypeSet(ts2));
for (Criterion.Type type : ts1MinusTs2) {
selectorBuilder.add(ts1.getCriterion(type));
}
Set<Criterion.Type> ts2MinusTs1 = getTypeSet(ts2);
ts2MinusTs1.removeAll(getTypeSet(ts1));
for (Criterion.Type type : ts2MinusTs1) {
selectorBuilder.add(ts2.getCriterion(type));
}
return selectorBuilder.build();
}
Aggregations