use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FabricUtils method isValidSrMetadata.
/**
* Check metadata passed from SegmentRouting app.
*
* @param obj the objective containing the metadata
* @return true if the objective contains valid metadata, false otherwise
*/
public static boolean isValidSrMetadata(Objective obj) {
long meta = 0;
if (obj instanceof FilteringObjective) {
FilteringObjective filtObj = (FilteringObjective) obj;
if (filtObj.meta() == null) {
return true;
}
Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
if (metaIns == null) {
return true;
}
meta = metaIns.metadata() & metaIns.metadataMask();
} else if (obj instanceof ForwardingObjective) {
ForwardingObjective fwdObj = (ForwardingObjective) obj;
if (fwdObj.meta() == null) {
return true;
}
MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
if (metaCrit == null) {
return true;
}
meta = metaCrit.metadata();
}
return meta != 0 && ((meta ^ METADATA_MASK) <= METADATA_MASK);
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FabricUtils method isSrMetadataSet.
/**
* Verify if a given flag has been set into the metadata.
*
* @param obj the objective containing the metadata
* @param flag the flag to verify
* @return true if the flag is set, false otherwise
*/
public static boolean isSrMetadataSet(Objective obj, long flag) {
long meta = 0;
if (obj instanceof FilteringObjective) {
FilteringObjective filtObj = (FilteringObjective) obj;
if (filtObj.meta() == null) {
return false;
}
Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
if (metaIns == null) {
return false;
}
meta = metaIns.metadata() & metaIns.metadataMask();
} else if (obj instanceof ForwardingObjective) {
ForwardingObjective fwdObj = (ForwardingObjective) obj;
if (fwdObj.meta() == null) {
return false;
}
MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
if (metaCrit == null) {
return false;
}
meta = metaCrit.metadata();
}
return (meta & flag) == flag;
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method createRules.
@Override
protected List<Objective> createRules(LinkCollectionIntent intent, DeviceId deviceId, Set<PortNumber> inPorts, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> labels) {
List<Objective> objectives = new ArrayList<>(inPorts.size() * 2);
/*
* Looking for the encapsulation constraint
*/
Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
inPorts.forEach(inPort -> {
ForwardingInstructions instructions = this.createForwardingInstruction(encapConstraint, intent, inPort, outPorts, deviceId, labels);
Set<TrafficTreatment> treatmentsWithDifferentPort = Sets.newHashSet();
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
for (Instruction inst : instructions.treatment().allInstructions()) {
if (inst.type() == OUTPUT) {
treatmentBuilder.add(inst);
treatmentsWithDifferentPort.add(treatmentBuilder.build());
treatmentBuilder = DefaultTrafficTreatment.builder();
} else {
treatmentBuilder.add(inst);
}
}
EthCriterion ethDst = (EthCriterion) intent.selector().getCriterion(Criterion.Type.ETH_DST);
boolean broadcastObjective = ethDst != null && (ethDst.mac().isBroadcast() || ethDst.mac().isMulticast());
FilteringObjective filteringObjective = buildFilteringObjective(intent, instructions.selector(), deviceId, inPort);
if (filteringObjective != null) {
objectives.add(filteringObjective);
}
if (treatmentsWithDifferentPort.size() < 2 && !broadcastObjective) {
objectives.addAll(createSimpleNextObjective(instructions, intent));
} else {
objectives.addAll(createBroadcastObjective(instructions, treatmentsWithDifferentPort, intent));
}
});
return objectives;
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class InOrderFlowObjectiveManager method dequeue.
/**
* Dequeue flow objective. Execute the next flow objective in the queue, if any.
*
* @param deviceId Device ID
* @param obj Flow objective
* @param error ObjectiveError that triggers this dequeue. Null if this is not triggered by an error.
*/
private synchronized void dequeue(DeviceId deviceId, Objective obj, ObjectiveError error) {
List<Objective> remaining;
int priority = obj.priority();
LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG;
Tools.log(log, logLevel, "Dequeue {}", obj);
if (obj instanceof FilteringObjective) {
FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key());
if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
filtObjQueueHead.invalidate(k);
}
filtObjQueue.remove(k, obj);
remaining = filtObjQueue.get(k);
} else if (obj instanceof ForwardingObjective) {
ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector());
if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
fwdObjQueueHead.invalidate(k);
}
fwdObjQueue.remove(k, obj);
remaining = fwdObjQueue.get(k);
} else if (obj instanceof NextObjective) {
if (error != null) {
// Remove pendingForwards and pendingNexts if next objective failed
Set<PendingFlowObjective> removedForwards = pendingForwards.remove(obj.id());
List<PendingFlowObjective> removedNexts = pendingNexts.remove(obj.id());
if (removedForwards != null) {
removedForwards.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
}
if (removedNexts != null) {
removedNexts.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
}
}
NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id());
if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
nextObjQueueHead.invalidate(k);
}
nextObjQueue.remove(k, obj);
remaining = nextObjQueue.get(k);
} else {
log.error("Unknown flow objective instance: {}", obj.getClass().getName());
return;
}
log.trace("{} queue size {}", obj.getClass().getSimpleName(), remaining.size());
// Submit the next one in the queue, if any
if (remaining.size() > 0) {
execute(deviceId, remaining.get(0));
}
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FlowObjectiveCompositionManager method filter.
@Override
public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
checkPermission(FLOWRULE_WRITE);
List<FilteringObjective> filteringObjectives = this.deviceCompositionTreeMap.get(deviceId).updateFilter(filteringObjective);
for (FilteringObjective tmp : filteringObjectives) {
executorService.execute(new ObjectiveInstaller(deviceId, tmp));
}
}
Aggregations