use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class PolatisInternalConnectivity method filterUsedPorts.
private Set<PortNumber> filterUsedPorts(Set<PortNumber> ports, Collection<FlowEntry> flowEntries) {
if (ports.isEmpty() || flowEntries.isEmpty()) {
return ports;
}
for (FlowEntry flowEntry : flowEntries) {
PortNumber inputPort = ((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port();
ports.remove(inputPort);
PortNumber outputPort = ((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port();
ports.remove(outputPort);
log.debug("Cross-connection {}-{} removed from output port list", inputPort, outputPort);
}
log.debug("Ports after filtering out used ones: " + ports);
return ports;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method versatileTreatmentBuilder.
@Override
protected TrafficTreatment.Builder versatileTreatmentBuilder(ForwardingObjective fwd) {
// XXX driver does not currently do type checking as per Tables 65-67 in
// OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
for (Instruction ins : fwd.treatment().allInstructions()) {
if (ins instanceof OutputInstruction) {
OutputInstruction o = (OutputInstruction) ins;
if (PortNumber.CONTROLLER.equals(o.port())) {
ttBuilder.transition(PUNT_TABLE);
} else {
log.warn("Only allowed treatments in versatile forwarding " + "objectives are punts to the controller");
}
} else if (ins instanceof NoActionInstruction) {
// No action is allowed and nothing needs to be done
} else {
log.warn("Cannot process instruction in versatile fwd {}", ins);
}
}
if (fwd.treatment().clearedDeferred()) {
ttBuilder.wipeDeferred();
}
}
if (fwd.nextId() != null) {
// Override case
NextGroup next = getGroupForNextObjective(fwd.nextId());
if (next == null) {
fail(fwd, ObjectiveError.BADPARAMS);
return null;
}
List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
// we only need the top level group's key to point the flow to it
Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
if (group == null) {
log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.GROUPMISSING);
return null;
}
ttBuilder.deferred().group(group.id());
}
return ttBuilder;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method versatileTreatmentBuilder.
/**
* Helper function to create traffic treatment builder for versatile forwarding objectives.
*
* @param fwd original forwarding objective
* @return treatment builder for the flow rule, or null if there is an error.
*/
protected TrafficTreatment.Builder versatileTreatmentBuilder(ForwardingObjective fwd) {
// XXX driver does not currently do type checking as per Tables 65-67 in
// OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
for (Instruction ins : fwd.treatment().allInstructions()) {
if (ins instanceof OutputInstruction) {
OutputInstruction o = (OutputInstruction) ins;
if (PortNumber.CONTROLLER.equals(o.port())) {
ttBuilder.add(o);
} else {
log.warn("Only allowed treatments in versatile forwarding " + "objectives are punts to the controller");
}
} else if (ins instanceof NoActionInstruction) {
// No action is allowed and nothing needs to be done
} else {
log.warn("Cannot process instruction in versatile fwd {}", ins);
}
}
if (fwd.treatment().clearedDeferred()) {
ttBuilder.wipeDeferred();
}
}
if (fwd.nextId() != null) {
// Override case
NextGroup next = getGroupForNextObjective(fwd.nextId());
if (next == null) {
fail(fwd, ObjectiveError.BADPARAMS);
return null;
}
List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
// we only need the top level group's key to point the flow to it
Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
if (group == null) {
log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.GROUPMISSING);
return null;
}
ttBuilder.deferred().group(group.id());
}
return ttBuilder;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchOutputInstruction.
// TODO: need to add matchModVlanHeaderInstruction
/**
* Matches the contents of an output instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchOutputInstruction(JsonNode instructionJson, Description description) {
final String jsonType = instructionJson.get("type").textValue();
OutputInstruction instructionToMatch = (OutputInstruction) instruction;
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
if (instructionJson.get("port").isLong() || instructionJson.get("port").isInt()) {
final long jsonPort = instructionJson.get("port").asLong();
if (instructionToMatch.port().toLong() != (jsonPort)) {
description.appendText("port was " + jsonPort);
return false;
}
} else if (instructionJson.get("port").isTextual()) {
final String jsonPort = instructionJson.get("port").textValue();
if (!instructionToMatch.port().toString().equals(jsonPort)) {
description.appendText("port was " + jsonPort);
return false;
}
} else {
final String jsonPort = instructionJson.get("port").toString();
description.appendText("Unmatching types ");
description.appendText("instructionToMatch " + instructionToMatch.port().toString());
description.appendText("jsonPort " + jsonPort);
}
return true;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class SoftRouterPipeline method processVersatile.
/**
* SoftRouter has a single versatile table - the filter table.
* This table can be used to filter entries that reach the next table (FIB table).
* It can also be used to punt packets to the controller and/or bypass
* the FIB table to forward out of a port.
*
* @param fwd The forwarding objective of type versatile
* @return A collection of flow rules meant to be delivered to the flowrule
* subsystem. May return empty collection in case of failures.
*/
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
log.debug("Received versatile fwd: to next:{}", fwd.nextId());
Collection<FlowRule> flowrules = new ArrayList<>();
if (fwd.nextId() == null && fwd.treatment() == null) {
log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
return Collections.emptySet();
}
int tableId = FILTER_TABLE;
// so that it only takes effect if the packet misses the FIB rules
if (fwd.treatment() != null && containsPunt(fwd.treatment()) && fwd.selector() != null && matchesIp(fwd.selector()) && !matchesControlTraffic(fwd.selector())) {
tableId = FIB_TABLE;
}
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
fwd.treatment().immediate().forEach(ins -> ttBuilder.add(ins));
}
// convert nextId to flow actions
if (fwd.nextId() != null) {
// only acceptable value is output to port
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next == null) {
log.error("next-id {} does not exist in store", fwd.nextId());
return Collections.emptySet();
}
TrafficTreatment nt = appKryo.deserialize(next.data());
if (nt == null) {
log.error("Error in deserializing next-id {}", fwd.nextId());
return Collections.emptySet();
}
for (Instruction ins : nt.allInstructions()) {
if (ins instanceof OutputInstruction) {
ttBuilder.add(ins);
}
}
}
FlowRule rule = DefaultFlowRule.builder().withSelector(fwd.selector()).withTreatment(ttBuilder.build()).forTable(tableId).makePermanent().forDevice(deviceId).fromApp(fwd.appId()).withPriority(fwd.priority()).build();
flowrules.add(rule);
return flowrules;
}
Aggregations