use of org.onosproject.net.flow.instructions.L2ModificationInstruction in project onos by opennetworkinglab.
the class FlowObjectiveCompositionUtil method revertTreatmentSelector.
public static TrafficSelector revertTreatmentSelector(TrafficTreatment trafficTreatment, TrafficSelector trafficSelector) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Map<Criterion.Type, Criterion> criterionMap = new HashMap<>();
for (Criterion criterion : trafficSelector.criteria()) {
criterionMap.put(criterion.type(), criterion);
}
for (Instruction instruction : trafficTreatment.allInstructions()) {
switch(instruction.type()) {
case OUTPUT:
break;
case GROUP:
break;
case L0MODIFICATION:
{
L0ModificationInstruction l0 = (L0ModificationInstruction) instruction;
switch(l0.subtype()) {
case OCH:
if (criterionMap.containsKey(Criterion.Type.OCH_SIGID)) {
if (((OchSignalCriterion) criterionMap.get((Criterion.Type.OCH_SIGID))).lambda().equals(((L0ModificationInstruction.ModOchSignalInstruction) l0).lambda())) {
criterionMap.remove(Criterion.Type.OCH_SIGID);
} else {
return null;
}
}
default:
break;
}
break;
}
case L1MODIFICATION:
{
L1ModificationInstruction l1 = (L1ModificationInstruction) instruction;
switch(l1.subtype()) {
case ODU_SIGID:
if (criterionMap.containsKey(Criterion.Type.ODU_SIGID)) {
if (((OduSignalIdCriterion) criterionMap.get((Criterion.Type.ODU_SIGID))).oduSignalId().equals(((L1ModificationInstruction.ModOduSignalIdInstruction) l1).oduSignalId())) {
criterionMap.remove(Criterion.Type.ODU_SIGID);
} else {
return null;
}
}
default:
break;
}
break;
}
case L2MODIFICATION:
{
L2ModificationInstruction l2 = (L2ModificationInstruction) instruction;
switch(l2.subtype()) {
case ETH_SRC:
if (criterionMap.containsKey(Criterion.Type.ETH_SRC)) {
if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_SRC))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
criterionMap.remove(Criterion.Type.ETH_SRC);
} else {
return null;
}
} else {
break;
}
case ETH_DST:
if (criterionMap.containsKey(Criterion.Type.ETH_DST)) {
if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_DST))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
criterionMap.remove(Criterion.Type.ETH_DST);
} else {
return null;
}
} else {
break;
}
case VLAN_ID:
if (criterionMap.containsKey(Criterion.Type.VLAN_VID)) {
if (((VlanIdCriterion) criterionMap.get((Criterion.Type.VLAN_VID))).vlanId().equals(((L2ModificationInstruction.ModVlanIdInstruction) l2).vlanId())) {
criterionMap.remove(Criterion.Type.VLAN_VID);
} else {
return null;
}
} else {
break;
}
case VLAN_PCP:
if (criterionMap.containsKey(Criterion.Type.VLAN_PCP)) {
if (((VlanPcpCriterion) criterionMap.get((Criterion.Type.VLAN_PCP))).priority() == ((L2ModificationInstruction.ModVlanPcpInstruction) l2).vlanPcp()) {
criterionMap.remove(Criterion.Type.VLAN_PCP);
} else {
return null;
}
} else {
break;
}
case MPLS_LABEL:
if (criterionMap.containsKey(Criterion.Type.MPLS_LABEL)) {
if (((MplsCriterion) criterionMap.get((Criterion.Type.MPLS_LABEL))).label().equals(((L2ModificationInstruction.ModMplsLabelInstruction) l2).label())) {
criterionMap.remove(Criterion.Type.ETH_DST);
} else {
return null;
}
} else {
break;
}
default:
break;
}
break;
}
case TABLE:
break;
case L3MODIFICATION:
{
L3ModificationInstruction l3 = (L3ModificationInstruction) instruction;
switch(l3.subtype()) {
case IPV4_SRC:
if (criterionMap.containsKey(Criterion.Type.IPV4_SRC)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV4_SRC);
} else {
return null;
}
} else {
break;
}
case IPV4_DST:
if (criterionMap.containsKey(Criterion.Type.IPV4_DST)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV4_DST);
} else {
return null;
}
} else {
break;
}
case IPV6_SRC:
if (criterionMap.containsKey(Criterion.Type.IPV6_SRC)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV6_SRC);
} else {
return null;
}
} else {
break;
}
case IPV6_DST:
if (criterionMap.containsKey(Criterion.Type.IPV6_DST)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV6_DST);
} else {
return null;
}
} else {
break;
}
case IPV6_FLABEL:
if (criterionMap.containsKey(Criterion.Type.IPV6_FLABEL)) {
if (((IPv6FlowLabelCriterion) criterionMap.get(Criterion.Type.IPV6_FLABEL)).flowLabel() == (((L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3).flowLabel())) {
criterionMap.remove(Criterion.Type.IPV4_SRC);
} else {
return null;
}
} else {
break;
}
default:
break;
}
break;
}
case METADATA:
break;
default:
break;
}
}
for (Criterion criterion : criterionMap.values()) {
selectorBuilder.add(criterion);
}
return selectorBuilder.build();
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer10 method buildL2Modification.
private OFAction buildL2Modification(Instruction i) {
L2ModificationInstruction l2m = (L2ModificationInstruction) i;
ModEtherInstruction eth;
switch(l2m.subtype()) {
case ETH_DST:
eth = (ModEtherInstruction) l2m;
return factory().actions().setDlDst(MacAddress.of(eth.mac().toLong()));
case ETH_SRC:
eth = (ModEtherInstruction) l2m;
return factory().actions().setDlSrc(MacAddress.of(eth.mac().toLong()));
case VLAN_ID:
ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
return factory().actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId().toShort()));
case VLAN_PCP:
ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
return factory().actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
case VLAN_POP:
return factory().actions().stripVlan();
case VLAN_PUSH:
return null;
default:
log.warn("Unimplemented action type {}.", l2m.subtype());
break;
}
return null;
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer13 method buildL2Modification.
protected OFAction buildL2Modification(Instruction i) {
L2ModificationInstruction l2m = (L2ModificationInstruction) i;
ModEtherInstruction eth;
OFOxm<?> oxm = null;
switch(l2m.subtype()) {
case ETH_DST:
eth = (ModEtherInstruction) l2m;
oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
break;
case ETH_SRC:
eth = (ModEtherInstruction) l2m;
oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
break;
case VLAN_ID:
ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
break;
case VLAN_PCP:
ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
break;
case MPLS_PUSH:
ModMplsHeaderInstruction pushHeaderInstructions = (ModMplsHeaderInstruction) l2m;
return factory().actions().pushMpls(EthType.of(pushHeaderInstructions.ethernetType().toShort()));
case MPLS_POP:
ModMplsHeaderInstruction popHeaderInstructions = (ModMplsHeaderInstruction) l2m;
return factory().actions().popMpls(EthType.of(popHeaderInstructions.ethernetType().toShort()));
case MPLS_LABEL:
ModMplsLabelInstruction mplsLabel = (ModMplsLabelInstruction) l2m;
oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label().toInt()));
break;
case MPLS_BOS:
ModMplsBosInstruction mplsBos = (ModMplsBosInstruction) l2m;
oxm = factory().oxms().mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE);
break;
case DEC_MPLS_TTL:
return factory().actions().decMplsTtl();
case VLAN_POP:
return factory().actions().popVlan();
case VLAN_PUSH:
ModVlanHeaderInstruction pushVlanInstruction = (ModVlanHeaderInstruction) l2m;
return factory().actions().pushVlan(EthType.of(pushVlanInstruction.ethernetType().toShort()));
case TUNNEL_ID:
ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
break;
default:
log.warn("Unimplemented action type {}.", l2m.subtype());
break;
}
if (oxm != null) {
return factory().actions().buildSetField().setField(oxm).build();
}
return null;
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction in project onos by opennetworkinglab.
the class EncodeInstructionCodecHelper method encodeL2.
/**
* Encode an L2 modification instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodeL2(ObjectNode result) {
L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
result.put(InstructionCodec.SUBTYPE, l2Instruction.subtype().name());
switch(l2Instruction.subtype()) {
case ETH_SRC:
case ETH_DST:
final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = (L2ModificationInstruction.ModEtherInstruction) l2Instruction;
result.put(InstructionCodec.MAC, modEtherInstruction.mac().toString());
break;
case VLAN_ID:
final L2ModificationInstruction.ModVlanIdInstruction modVlanIdInstruction = (L2ModificationInstruction.ModVlanIdInstruction) l2Instruction;
result.put(InstructionCodec.VLAN_ID, modVlanIdInstruction.vlanId().toShort());
break;
case VLAN_PCP:
final L2ModificationInstruction.ModVlanPcpInstruction modVlanPcpInstruction = (L2ModificationInstruction.ModVlanPcpInstruction) l2Instruction;
result.put(InstructionCodec.VLAN_PCP, modVlanPcpInstruction.vlanPcp());
break;
case VLAN_PUSH:
final L2ModificationInstruction.ModVlanHeaderInstruction pushVlanInstruction = (L2ModificationInstruction.ModVlanHeaderInstruction) l2Instruction;
result.put(InstructionCodec.ETHERNET_TYPE, toHexEthernetType(pushVlanInstruction.ethernetType().toString()));
break;
case VLAN_POP:
break;
case MPLS_LABEL:
final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = (L2ModificationInstruction.ModMplsLabelInstruction) l2Instruction;
result.put(InstructionCodec.MPLS_LABEL, modMplsLabelInstruction.label().toInt());
break;
case MPLS_PUSH:
final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstructions = (L2ModificationInstruction.ModMplsHeaderInstruction) l2Instruction;
result.put(InstructionCodec.ETHERNET_TYPE, pushHeaderInstructions.ethernetType().toShort());
break;
case TUNNEL_ID:
final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = (L2ModificationInstruction.ModTunnelIdInstruction) l2Instruction;
result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId());
break;
case MPLS_BOS:
final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction = (L2ModificationInstruction.ModMplsBosInstruction) l2Instruction;
result.put(InstructionCodec.MPLS_BOS, modMplsBosInstruction.mplsBos());
break;
case MPLS_POP:
final L2ModificationInstruction.ModMplsHeaderInstruction popHeaderInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) l2Instruction;
result.put(InstructionCodec.ETHERNET_TYPE, toHexEthernetType(popHeaderInstruction.ethernetType().toString()));
break;
case DEC_MPLS_TTL:
break;
default:
log.info("Cannot convert L2 subtype of {}", l2Instruction.subtype());
break;
}
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction in project onos by opennetworkinglab.
the class OfdpaPipelineTraceable method translateInstruction.
// Applies an instruction to the packet in the form of a selector
private TrafficSelector.Builder translateInstruction(TrafficSelector.Builder newSelector, Instruction instruction) {
log.debug("Translating instruction {}", instruction);
log.debug("New Selector {}", newSelector.build());
// TODO add as required
Criterion criterion = null;
if (instruction.type() == Instruction.Type.L2MODIFICATION) {
L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
switch(l2Instruction.subtype()) {
case VLAN_ID:
ModVlanIdInstruction vlanIdInstruction = (ModVlanIdInstruction) instruction;
VlanId id = vlanIdInstruction.vlanId();
criterion = Criteria.matchVlanId(id);
break;
case VLAN_POP:
criterion = Criteria.matchVlanId(VlanId.NONE);
break;
case MPLS_PUSH:
L2ModificationInstruction.ModMplsHeaderInstruction mplsEthInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
criterion = Criteria.matchEthType(mplsEthInstruction.ethernetType().toShort());
// When pushing MPLS adding metadata to remember the original ethtype
if (isHardwareSwitch()) {
TrafficSelector temporaryPacket = newSelector.build();
Criterion ethCriterion = temporaryPacket.getCriterion(Criterion.Type.ETH_TYPE);
if (ethCriterion != null) {
TrafficSelector.Builder tempSelector = DefaultTrafficSelector.builder(temporaryPacket);
// Store the old ether type for the
tempSelector.matchMetadata(((EthTypeCriterion) ethCriterion).ethType().toShort());
newSelector = tempSelector;
}
}
break;
case MPLS_POP:
L2ModificationInstruction.ModMplsHeaderInstruction mplsPopInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
criterion = Criteria.matchEthType(mplsPopInstruction.ethernetType().toShort());
// When popping MPLS we remove label and BOS
TrafficSelector temporaryPacket = newSelector.build();
if (temporaryPacket.getCriterion(Criterion.Type.MPLS_LABEL) != null) {
TrafficSelector.Builder noMplsSelector = DefaultTrafficSelector.builder();
temporaryPacket.criteria().stream().filter(c -> !c.type().equals(Criterion.Type.MPLS_LABEL) && !c.type().equals(Criterion.Type.MPLS_BOS)).forEach(noMplsSelector::add);
newSelector = noMplsSelector;
}
break;
case MPLS_LABEL:
L2ModificationInstruction.ModMplsLabelInstruction mplsLabelInstruction = (L2ModificationInstruction.ModMplsLabelInstruction) instruction;
criterion = Criteria.matchMplsLabel(mplsLabelInstruction.label());
newSelector.matchMplsBos(true);
break;
case ETH_DST:
L2ModificationInstruction.ModEtherInstruction modEtherDstInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
criterion = Criteria.matchEthDst(modEtherDstInstruction.mac());
break;
case ETH_SRC:
L2ModificationInstruction.ModEtherInstruction modEtherSrcInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
criterion = Criteria.matchEthSrc(modEtherSrcInstruction.mac());
break;
default:
log.debug("Unsupported L2 Instruction");
break;
}
} else {
log.debug("Unsupported Instruction");
}
if (criterion != null) {
log.debug("Adding criterion {}", criterion);
newSelector.add(criterion);
}
return newSelector;
}
Aggregations