use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.
the class FabricPipeliner method handleVerify.
private ObjectiveError handleVerify(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> bucketsToFlows = getBucketToFlowMapping(nextObjective);
if (bucketsToFlows.isEmpty() && !nextObjective.nextTreatments().isEmpty()) {
log.warn("VERIFY failed due to translation error, bucketsToFlows is empty");
return ObjectiveError.BADPARAMS;
}
if (log.isTraceEnabled()) {
log.trace("Mapping bucketsToFlows {} has been generated ", bucketsToFlows);
}
GroupKey groupKey = nextTranslator.getGroupKey(nextObjective);
if (groupKey == null) {
log.warn("VERIFY failed due to translation error, unable to determine group key");
return ObjectiveError.BADPARAMS;
}
Group groupFromStore = groupService.getGroup(deviceId, groupKey);
if (groupFromStore == null) {
log.warn("VERIFY failed due to missing group in the store");
return ObjectiveError.GROUPMISSING;
}
// Looking for duplicate buckets - remove them by using a set and comparing size after/before
Set<GroupBucket> bucketsFromStore = Sets.newHashSet(groupFromStore.buckets().buckets());
if (groupFromStore.buckets().buckets().size() > bucketsFromStore.size()) {
log.warn("Duplicated buckets detected in device:{}, nextId:{}, before-size" + ":{} after-size:{} .. correcting", deviceId, nextObjective.id(), groupFromStore.buckets().buckets().size(), bucketsFromStore.size());
final GroupBuckets bucketToSet = new GroupBuckets(Lists.newArrayList(bucketsFromStore));
groupService.setBucketsForGroup(deviceId, groupKey, bucketToSet, groupKey, nextObjective.appId());
// Forge temporary the group to avoid race condition with the store
groupFromStore = new DefaultGroup(groupFromStore.id(), deviceId, groupFromStore.type(), bucketToSet);
}
// Looking for buckets missing in the group but defined in the next
Map<GroupBucket, FlowRule> toAdd = Maps.newHashMap();
for (Map.Entry<GroupBucket, FlowRule> entry : bucketsToFlows.entrySet()) {
if (!groupFromStore.buckets().buckets().contains(entry.getKey())) {
toAdd.put(entry.getKey(), entry.getValue());
}
}
// Looking for buckets missing in the next but defined in the group
// FIXME SDFAB-250 we cannot remove associated egress flows
List<GroupBucket> toRemove = Lists.newArrayList();
groupFromStore.buckets().buckets().forEach(bucket -> {
if (!bucketsToFlows.containsKey(bucket)) {
toRemove.add(bucket);
}
});
if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
log.warn("Mismatch detected in device:{}, nextId:{}, groupFromTranslation-size:{} " + "groupFromStore-size:{} toAdd-size:{} toRemove-size: {} .. correcting", deviceId, nextObjective.id(), bucketsToFlows.size(), groupFromStore.buckets().buckets().size(), toAdd.size(), toRemove.size());
}
if (!toAdd.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace("Adding missing buckets {} and flows {}", toAdd.keySet(), toAdd.values());
}
final FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
final FlowRule dummyFlow = getDummyFlow(nextObjective);
toAdd.values().stream().filter(flowRule -> !flowRule.equals(dummyFlow)).forEach(ops::add);
final GroupBuckets bucketsToAdd = new GroupBuckets(Lists.newArrayList(toAdd.keySet()));
groupService.addBucketsToGroup(deviceId, groupKey, bucketsToAdd, groupKey, nextObjective.appId());
flowRuleService.apply(ops.build());
}
if (!toRemove.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace("Removing stale buckets {}", toRemove);
}
final GroupBuckets bucketsToRemove = new GroupBuckets(toRemove);
groupService.removeBucketsFromGroup(deviceId, groupKey, bucketsToRemove, groupKey, nextObjective.appId());
}
return null;
}
use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.
the class FabricPipeliner method getBucketToFlowMapping.
private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
NextObjective newNextObjective;
ObjectiveTranslation result;
FlowRule dummyFlow = getDummyFlow(nextObjective);
FlowRule egFlow;
GroupBucket groupBucket;
GroupDescription group;
for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
result = nextTranslator.translate(newNextObjective);
if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
return Collections.emptyMap();
}
group = result.groups().iterator().next();
egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
return Collections.emptyMap();
}
groupBucket = group.buckets().buckets().iterator().next();
if (egFlow == null) {
mapping.put(groupBucket, dummyFlow);
} else {
mapping.put(groupBucket, egFlow);
}
}
return mapping;
}
use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.
the class NextObjectiveTranslator method nextMpls.
private void nextMpls(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
// Next objective can contain only one mpls push and one mpls label
// instruction. Pipeliner does not support other configurations.
final List<List<ModMplsLabelInstruction>> mplsInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), MPLS_LABEL).stream().map(v -> (ModMplsLabelInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
if (mplsInstructions.isEmpty()) {
// No need to apply next mpls table
return;
}
// We expect one mpls label for each treatment and the label has to be the same
final Set<MplsLabel> mplsLabels = mplsInstructions.stream().flatMap(Collection::stream).map(ModMplsLabelInstruction::label).collect(Collectors.toSet());
if (obj.nextTreatments().size() != mplsInstructions.size() || mplsLabels.size() != 1) {
throw new FabricPipelinerException("Inconsistent MPLS_LABEL instructions, cannot process " + "next_mpls rule. It is required that all " + "treatments have the same MPLS_LABEL instructions.");
}
final TrafficSelector selector = nextIdSelector(obj.id());
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(mplsLabels.iterator().next()).build();
resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS, selector, treatment));
}
use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.
the class AbstractHPPipeline method forward.
@Override
public void forward(ForwardingObjective fwd) {
if (fwd.treatment() != null) {
/* If UNSUPPORTED features included in ForwardingObjective a warning message is generated.
* FlowRule is anyway sent to the device, device will reply with an OFP_ERROR.
* Moreover, checkUnSupportedFeatures function generates further warnings specifying
* each unsupported feature.
*/
if (checkUnSupportedFeatures(fwd.selector(), fwd.treatment())) {
log.warn("HP Driver - specified ForwardingObjective contains UNSUPPORTED FEATURES");
}
// Deal with SPECIFIC and VERSATILE in the same manner.
// Create the FlowRule starting from the ForwardingObjective
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(fwd.selector()).withTreatment(fwd.treatment()).withPriority(fwd.priority()).fromApp(fwd.appId());
// Determine the table to be used depends on selector, treatment and specific switch hardware
ruleBuilder.forTable(tableIdForForwardingObjective(fwd.selector(), fwd.treatment()));
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
log.debug("HP Driver - installing ForwadingObjective arrived with treatment {}", fwd);
installObjective(ruleBuilder, fwd);
} else {
NextObjective nextObjective;
NextGroup next;
TrafficTreatment treatment;
if (fwd.op() == ADD) {
// Give a try to the cache. Doing an operation
// on the store seems to be very expensive.
nextObjective = pendingAddNext.getIfPresent(fwd.nextId());
// We will try with the store
if (nextObjective == null) {
next = flowObjectiveStore.getNextGroup(fwd.nextId());
// the treatment in order to re-build the flow rule.
if (next == null) {
fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.GROUPMISSING));
return;
}
treatment = appKryo.deserialize(next.data());
} else {
pendingAddNext.invalidate(fwd.nextId());
treatment = getTreatment(nextObjective);
if (treatment == null) {
fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.UNSUPPORTED));
return;
}
}
} else {
// We get the NextGroup from the remove operation.
// Doing an operation on the store seems to be very expensive.
next = flowObjectiveStore.getNextGroup(fwd.nextId());
treatment = (next != null) ? appKryo.deserialize(next.data()) : null;
}
// If the treatment is null we cannot re-build the original flow
if (treatment == null) {
fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.GROUPMISSING));
return;
}
// Finally we build the flow rule and push to the flowrule subsystem.
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(fwd.selector()).fromApp(fwd.appId()).withPriority(fwd.priority()).withTreatment(treatment);
/* If UNSUPPORTED features included in ForwardingObjective a warning message is generated.
* FlowRule is anyway sent to the device, device will reply with an OFP_ERROR.
* Moreover, checkUnSupportedFeatures function generates further warnings specifying
* each unsupported feature.
*/
if (checkUnSupportedFeatures(fwd.selector(), treatment)) {
log.warn("HP Driver - specified ForwardingObjective contains UNSUPPORTED FEATURES");
}
// Table to be used depends on the specific switch hardware and ForwardingObjective
ruleBuilder.forTable(tableIdForForwardingObjective(fwd.selector(), treatment));
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
log.debug("HP Driver - installing ForwadingObjective arrived with NULL treatment (intent)");
installObjective(ruleBuilder, fwd);
}
}
use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.
the class FlowObjectiveManagerTest method nextObjective.
/**
* Tests adding a next objective.
*/
@Test
public void nextObjective() {
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
NextObjective next = DefaultNextObjective.builder().withId(manager.allocateNextId()).addTreatment(treatment).withType(NextObjective.Type.BROADCAST).fromApp(NetTestTools.APP_ID).makePermanent().add();
manager.next(id1, next);
TestTools.assertAfter(RETRY_MS, () -> assertThat(nextObjectives, hasSize(1)));
assertThat(forwardingObjectives, hasSize(0));
assertThat(filteringObjectives, hasSize(0));
assertThat(nextObjectives, hasItem("of:d1"));
}
Aggregations