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 cross-connect object.
* @param behaviour the parent driver handler
* @param rule FlowRule object
* @return cross connect object
*/
public static CrossConnects fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
// TrafficSelector
Set<Criterion> criterions = rule.selector().criteria();
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// TrafficTreatment
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);
DefaultCrossConnects crossConnects = new DefaultCrossConnects();
DefaultPair p = new DefaultPair();
p.ingress(new PortFormat(inPort.toLong()));
p.egress(new PortFormat(outPort.toLong()));
crossConnects.addToPair(p);
return crossConnects;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class DefaultNicFlowRule method populate.
/**
* Parses FlowRule's traffic selector and treatment
* and keeps relevant information for this NIC rule.
*/
private void populate() {
this.ethTypeCriterion = (EthTypeCriterion) this.selector().getCriterion(ETH_TYPE);
this.ethSrcAddrCriterion = (EthCriterion) this.selector().getCriterion(ETH_SRC);
this.ethDstAddrCriterion = (EthCriterion) this.selector().getCriterion(ETH_DST);
this.ipv4ProtoCriterion = (IPProtocolCriterion) this.selector().getCriterion(IP_PROTO);
this.ipv4SrcAddrCriterion = (IPCriterion) this.selector().getCriterion(IPV4_SRC);
this.ipv4DstAddrCriterion = (IPCriterion) this.selector().getCriterion(IPV4_DST);
this.ipv4SrcMaskCriterion = (IPCriterion) this.selector().getCriterion(IPV4_SRC);
this.ipv4DstMaskCriterion = (IPCriterion) this.selector().getCriterion(IPV4_DST);
this.udpSrcPortCriterion = (UdpPortCriterion) this.selector().getCriterion(UDP_SRC);
this.udpDstPortCriterion = (UdpPortCriterion) this.selector().getCriterion(UDP_DST);
this.tcpSrcPortCriterion = (TcpPortCriterion) this.selector().getCriterion(TCP_SRC);
this.tcpDstPortCriterion = (TcpPortCriterion) this.selector().getCriterion(TCP_DST);
this.actions = new HashSet<NicRuleAction>();
// TODO: Expand this translator with more actions
for (Instruction instr : this.treatment().allInstructions()) {
if (instr.type() == NOACTION) {
this.actions.add(new NicRuleAction(NicRuleAction.Action.DROP));
} else if (instr.type() == QUEUE) {
SetQueueInstruction queueInstruction = (SetQueueInstruction) instr;
this.actions.add(new NicRuleAction(NicRuleAction.Action.QUEUE, queueInstruction.queueId()));
this.interfaceNumber = queueInstruction.port().toLong();
} else if (instr.type() == METER) {
MeterInstruction meterInstruction = (MeterInstruction) instr;
this.actions.add(new NicRuleAction(NicRuleAction.Action.METER, meterInstruction.meterId().id()));
}
}
// This action provides basic rule match counters
this.actions.add(new NicRuleAction(NicRuleAction.Action.COUNT));
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class CorsaPipelineV39 method processNextTreatment.
@Override
protected CorsaTrafficTreatment processNextTreatment(TrafficTreatment treatment) {
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
treatment.immediate().stream().filter(i -> {
switch(i.type()) {
case L2MODIFICATION:
L2ModificationInstruction l2i = (L2ModificationInstruction) i;
return l2i.subtype() == VLAN_ID || l2i.subtype() == VLAN_POP || l2i.subtype() == ETH_DST || l2i.subtype() == ETH_SRC;
case OUTPUT:
return true;
default:
return false;
}
}).forEach(i -> tb.add(i));
TrafficTreatment t = tb.build();
boolean isPresentModVlanId = false;
boolean isPresentModEthSrc = false;
boolean isPresentModEthDst = false;
boolean isPresentOutpuPort = false;
for (Instruction instruction : t.immediate()) {
switch(instruction.type()) {
case L2MODIFICATION:
L2ModificationInstruction l2i = (L2ModificationInstruction) instruction;
if (l2i instanceof L2ModificationInstruction.ModVlanIdInstruction) {
isPresentModVlanId = true;
}
if (l2i instanceof L2ModificationInstruction.ModEtherInstruction) {
L2ModificationInstruction.L2SubType subType = l2i.subtype();
if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC)) {
isPresentModEthSrc = true;
} else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST)) {
isPresentModEthDst = true;
}
}
break;
case OUTPUT:
isPresentOutpuPort = true;
break;
default:
}
}
CorsaTrafficTreatmentType type = CorsaTrafficTreatmentType.ACTIONS;
/**
* These are the allowed groups for CorsaPipelinev39
*/
if (isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) {
type = CorsaTrafficTreatmentType.GROUP;
} else if ((!isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && !isPresentModEthDst && isPresentOutpuPort)) {
type = CorsaTrafficTreatmentType.GROUP;
TrafficTreatment.Builder tb2 = DefaultTrafficTreatment.builder(t);
tb2.add(Instructions.popVlan());
t = tb2.build();
}
CorsaTrafficTreatment corsaTreatment = new CorsaTrafficTreatment(type, t);
return corsaTreatment;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class CorsaPipelineV3 method processNextTreatment.
@Override
protected CorsaTrafficTreatment processNextTreatment(TrafficTreatment treatment) {
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
treatment.immediate().stream().filter(i -> {
switch(i.type()) {
case L2MODIFICATION:
L2ModificationInstruction l2i = (L2ModificationInstruction) i;
return l2i instanceof L2ModificationInstruction.ModVlanIdInstruction || l2i instanceof L2ModificationInstruction.ModEtherInstruction;
case OUTPUT:
return true;
default:
return false;
}
}).forEach(i -> tb.add(i));
TrafficTreatment t = tb.build();
boolean isPresentModVlanId = false;
boolean isPresentModEthSrc = false;
boolean isPresentModEthDst = false;
boolean isPresentOutpuPort = false;
for (Instruction instruction : t.immediate()) {
switch(instruction.type()) {
case L2MODIFICATION:
L2ModificationInstruction l2i = (L2ModificationInstruction) instruction;
if (l2i instanceof L2ModificationInstruction.ModVlanIdInstruction) {
isPresentModVlanId = true;
}
if (l2i instanceof L2ModificationInstruction.ModEtherInstruction) {
L2ModificationInstruction.L2SubType subType = l2i.subtype();
if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC)) {
isPresentModEthSrc = true;
} else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST)) {
isPresentModEthDst = true;
}
}
break;
case OUTPUT:
isPresentOutpuPort = true;
break;
default:
}
}
CorsaTrafficTreatmentType type = CorsaTrafficTreatmentType.ACTIONS;
/**
* This represents the allowed group for CorsaPipelinev3
*/
if (isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) {
type = CorsaTrafficTreatmentType.GROUP;
}
CorsaTrafficTreatment corsaTreatment = new CorsaTrafficTreatment(type, t);
return corsaTreatment;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getChannelAttenuation.
/**
* Gets specified channel attenuation.
*
* @param portNum the port number
* @param och channel signal
* @return atteuation in 0.01 dB
*/
private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry == null) {
return null;
}
List<Instruction> instructions = flowEntry.treatment().allInstructions();
for (Instruction ins : instructions) {
if (ins.type() != Instruction.Type.EXTENSION) {
continue;
}
ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
return (long) ((OplinkAttenuation) ext).getAttenuation();
}
}
return null;
}
Aggregations