use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class TrafficMonitor method getEgressFlows.
// Counts all entries that egress on the link source port.
private int getEgressFlows(Link link, List<FlowEntry> entries) {
int count = 0;
PortNumber out = link.src().port();
for (FlowEntry entry : entries) {
TrafficTreatment treatment = entry.treatment();
for (Instruction instruction : treatment.allInstructions()) {
if (instruction.type() == Instruction.Type.OUTPUT && ((OutputInstruction) instruction).port().equals(out)) {
count++;
}
}
}
return count;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class FlowModBuilderVer15 method buildActions.
private List<OFAction> buildActions(List<Instruction> treatments, Boolean immediateActions) {
if (treatment == null) {
return Collections.emptyList();
}
boolean tableFound = false;
List<OFAction> actions = new LinkedList<>();
// Meter action handling
if (null != treatment.meters() && immediateActions) {
treatment.meters().forEach(meterInstruction -> {
OFAction meterAction = buildMeterAction(meterInstruction);
actions.add(meterAction);
});
}
for (Instruction i : treatments) {
switch(i.type()) {
case NOACTION:
return Collections.emptyList();
case L0MODIFICATION:
actions.add(buildL0Modification(i));
break;
case L1MODIFICATION:
actions.add(buildL1Modification(i));
break;
case L2MODIFICATION:
actions.add(buildL2Modification(i));
break;
case L3MODIFICATION:
actions.add(buildL3Modification(i));
break;
case L4MODIFICATION:
actions.add(buildL4Modification(i));
break;
case OUTPUT:
Instructions.OutputInstruction out = (Instructions.OutputInstruction) i;
OFActionOutput.Builder action = factory().actions().buildOutput().setPort(OFPort.of((int) out.port().toLong()));
if (out.port().equals(PortNumber.CONTROLLER)) {
action.setMaxLen(OFPCML_NO_BUFFER);
}
actions.add(action.build());
break;
case GROUP:
Instructions.GroupInstruction group = (Instructions.GroupInstruction) i;
OFActionGroup.Builder groupBuilder = factory().actions().buildGroup().setGroup(OFGroup.of(group.groupId().id()));
actions.add(groupBuilder.build());
break;
case QUEUE:
Instructions.SetQueueInstruction queue = (Instructions.SetQueueInstruction) i;
OFActionSetQueue.Builder queueBuilder = factory().actions().buildSetQueue().setQueueId(queue.queueId());
actions.add(queueBuilder.build());
break;
case TABLE:
// FIXME: should not occur here.
tableFound = true;
break;
case EXTENSION:
actions.add(buildExtensionAction(((Instructions.ExtensionInstructionWrapper) i).extensionInstruction()));
break;
default:
log.warn("Instruction type {} not yet implemented.", i.type());
}
}
if (tableFound && actions.isEmpty()) {
// a goto instruction for the next table
return Collections.emptyList();
}
return actions;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class OpenFlowCorePacketContext method sendPacket.
private void sendPacket(Ethernet eth) {
List<Instruction> ins = treatmentBuilder().build().allInstructions();
OFPort p = null;
// TODO: support arbitrary list of treatments must be supported in ofPacketContext
for (Instruction i : ins) {
if (i.type() == Type.OUTPUT) {
p = buildPort(((OutputInstruction) i).port());
// for now...
break;
}
}
if (eth == null) {
ofPktCtx.build(p);
} else {
ofPktCtx.build(eth, p);
}
ofPktCtx.send();
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class OpenFlowPacketProvider method emit.
@Override
public void emit(OutboundPacket packet) {
DeviceId devId = packet.sendThrough();
String scheme = devId.toString().split(":")[0];
if (!scheme.equals(this.id().scheme())) {
throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
}
Dpid dpid = Dpid.dpid(devId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
log.warn("Device {} isn't available?", devId);
return;
}
OFPort inPort;
if (packet.inPort() != null) {
inPort = portDesc(packet.inPort()).getPortNo();
} else {
inPort = OFPort.CONTROLLER;
}
// Ethernet eth = new Ethernet();
// eth.deserialize(packet.data().array(), 0, packet.data().array().length);
OFPortDesc p = null;
for (Instruction inst : packet.treatment().allInstructions()) {
if (inst.type().equals(Instruction.Type.OUTPUT)) {
p = portDesc(((OutputInstruction) inst).port());
OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo(), inPort);
sw.sendMsg(po);
}
}
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class PolatisOpticalUtility method fromFlowRule.
/**
* Transforms a flow FlowRule object to a variable binding.
* @param rule FlowRule object
* @param delete whether it is a delete or edit request
* @return variable binding
*/
public static VariableBinding fromFlowRule(FlowRule rule, boolean delete) {
Set<Criterion> criterions = rule.selector().criteria();
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
long input = inPort.toLong();
List<Instruction> instructions = rule.treatment().immediate();
PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
long output = outPort.toLong();
OID oid = new OID(PORT_PATCH_OID + "." + input);
Variable var = new UnsignedInteger32(delete ? 0 : output);
return new VariableBinding(oid, var);
}
Aggregations