use of org.onosproject.net.flow.instructions.Instructions in project onos by opennetworkinglab.
the class ChannelData method fromFlow.
/**
* Returns a ChannelData representation from a flow rule. The rule must contain
* a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
* Instruction.Type.OUTPUT instruction.
*
* @param rule the flow rule representing the connection
* @return ChannelData representation of the connection
*/
public static ChannelData fromFlow(FlowRule rule) {
checkNotNull(rule);
Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
checkNotNull(in);
PortNumber inPort = ((PortCriterion) in).port();
Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();
PortNumber outPort = null;
List<Instruction> instructions = rule.treatment().allInstructions();
for (Instruction ins : instructions) {
if (ins.type() == Instruction.Type.OUTPUT) {
outPort = ((Instructions.OutputInstruction) ins).port();
}
}
checkNotNull(outPort);
return new ChannelData(inPort, outPort, ochSignal);
}
use of org.onosproject.net.flow.instructions.Instructions in project onos by opennetworkinglab.
the class FlowAnalyzer method analyzeInstruction.
private boolean analyzeInstruction(Instruction i, FlowEntry flow) {
boolean pointsToLiveEntry = false;
Instructions.OutputInstruction output = (Instructions.OutputInstruction) i;
PortNumber port = output.port();
PortNumber outPort = null;
DeviceId egress = null;
boolean hasHost = false;
ConnectPoint portPt = new ConnectPoint(flow.deviceId(), port);
for (Link l : linkService.getEgressLinks(portPt)) {
if (l.dst().elementId() instanceof DeviceId) {
egress = l.dst().deviceId();
outPort = l.dst().port();
} else if (l.dst().elementId() instanceof HostId) {
// the port leads to a host: therefore it is not a dead link
pointsToLiveEntry = true;
hasHost = true;
}
}
if (!topologyService.isInfrastructure(topologyService.currentTopology(), portPt) && egress == null) {
pointsToLiveEntry = true;
hasHost = true;
}
if (hasHost) {
return pointsToLiveEntry;
}
if (egress == null) {
// the port that the flow instructions tells you to send the packet
// to doesn't exist or is a controller port
label.put(flow, "NA");
return pointsToLiveEntry;
}
Iterable<FlowEntry> dstFlowTable = flowRuleService.getFlowEntries(egress);
Set<Criterion> flowCriteria = flow.selector().criteria();
// filter the criteria in order to remove port dependency
Set<Criterion> filteredCriteria = new HashSet<>();
for (Criterion criterion : flowCriteria) {
if (!(criterion instanceof PortCriterion)) {
filteredCriteria.add(criterion);
}
}
// ensure that the in port is equal to the port that it is coming in from
filteredCriteria.add(Criteria.matchInPort(outPort));
for (FlowEntry entry : dstFlowTable) {
if (ignoredFlows.contains(entry)) {
continue;
}
if (filteredCriteria.containsAll(entry.selector().criteria())) {
dfs(entry);
if (!"Black Hole".equals(label.get(entry))) {
// this entry is "live" i.e not a black hole
pointsToLiveEntry = true;
}
}
}
return pointsToLiveEntry;
}
use of org.onosproject.net.flow.instructions.Instructions in project fabric-tna by stratum.
the class FabricInterpreter method mapOutboundPacket.
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
// We support only OUTPUT instructions.
List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
if (treatment.allInstructions().size() != outInstructions.size()) {
// There are other instructions that are not of type OUTPUT.
throw new PiInterpreterException("Treatment not supported: " + treatment);
}
ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
for (Instructions.OutputInstruction outInst : outInstructions) {
if (outInst.port().equals(TABLE)) {
// Logical port. Forward using the switch tables like a regular packet.
builder.add(createPiPacketOperation(packet.data(), 0, true));
} else if (outInst.port().equals(FLOOD)) {
// Logical port. Create a packet operation for each switch port.
final DeviceService deviceService = handler().get(DeviceService.class);
for (Port port : deviceService.getPorts(packet.sendThrough())) {
builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
}
} else if (outInst.port().isLogical()) {
throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
} else {
// Send as-is to given port bypassing all switch tables.
builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
}
}
return builder.build();
}
Aggregations