use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class PacketManager method pushRule.
/**
* Pushes packet intercept flow rules to the device.
*
* @param device the device to push the rules to
* @param request the packet request
*/
private void pushRule(Device device, PacketRequest request) {
if (!device.type().equals(Device.Type.SWITCH)) {
return;
}
if (!deviceService.isAvailable(device.id())) {
return;
}
ForwardingObjective forwarding = createBuilder(request).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install packet request {} to {}: {}", request, device.id(), error);
}
});
objectiveService.forward(device.id(), forwarding);
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
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, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS, selector, treatment));
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method compile.
@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();
Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
computePorts(intent, inputPorts, outputPorts);
if (encapConstraint.isPresent()) {
labels = labelAllocator.assignLabelToPorts(intent.links(), intent.key(), encapConstraint.get().encapType(), encapConstraint.get().suggestedIdentifier());
}
ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
if (this.isDomainProcessingEnabled(intent)) {
intentList.addAll(this.getDomainIntents(intent, domainService));
}
List<Objective> objectives = new ArrayList<>();
List<DeviceId> devices = new ArrayList<>();
for (DeviceId deviceId : outputPorts.keySet()) {
// add only objectives that are not inside of a domain
if (LOCAL.equals(domainService.getDomain(deviceId))) {
List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId), labels);
deviceObjectives.forEach(objective -> {
objectives.add(objective);
devices.add(deviceId);
});
}
}
// if any objectives have been created
if (!objectives.isEmpty()) {
intentList.add(new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources(), intent.resourceGroup()));
}
return intentList.build();
}
use of org.onosproject.net.flowobjective.Objective 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.Objective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method createSimpleNextObjective.
private List<Objective> createSimpleNextObjective(ForwardingInstructions instructions, LinkCollectionIntent intent) {
List<Objective> objectives = Lists.newArrayList();
ForwardingObjective forwardingObjective;
NextObjective nextObjective;
Integer nextId = flowObjectiveService.allocateNextId();
forwardingObjective = buildForwardingObjective(instructions.selector(), nextId, intent.priority());
DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder();
nextObjective = nxBuilder.withId(nextId).withMeta(instructions.selector()).addTreatment(instructions.treatment()).withType(NextObjective.Type.SIMPLE).fromApp(appId).makePermanent().withPriority(intent.priority()).add();
objectives.add(forwardingObjective);
objectives.add(nextObjective);
return objectives;
}
Aggregations