blob: 8c51624b694f3181c41be0eb8fdbaf8bbac0e1b7 [file] [log] [blame]
package org.onlab.onos.net.flow.instructions;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
/**
* Abstraction of a single traffic treatment step.
*/
public abstract class L2ModificationInstruction implements Instruction {
/**
* Represents the type of traffic treatment.
*/
public enum L2SubType {
/**
* Ether src modification.
*/
ETH_SRC,
/**
* Ether dst modification.
*/
ETH_DST,
/**
* VLAN id modification.
*/
VLAN_ID,
/**
* VLAN priority modification.
*/
VLAN_PCP
}
// TODO: Create factory class 'Instructions' that will have various factory
// to create specific instructions.
public abstract L2SubType subtype();
@Override
public Type type() {
return Type.L2MODIFICATION;
}
/**
* Represents a L2 src/dst modification instruction.
*/
public static final class ModEtherInstruction extends L2ModificationInstruction {
private final L2SubType subtype;
private final MacAddress mac;
public ModEtherInstruction(L2SubType subType, MacAddress addr) {
this.subtype = subType;
this.mac = addr;
}
@Override
public L2SubType subtype() {
return this.subtype;
}
public MacAddress mac() {
return this.mac;
}
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("mac", mac).toString();
}
}
/**
* Represents a VLAN id modification instruction.
*/
public static final class ModVlanIdInstruction extends L2ModificationInstruction {
public final VlanId vlanId;
public ModVlanIdInstruction(VlanId vlanId) {
this.vlanId = vlanId;
}
@Override
public L2SubType subtype() {
return L2SubType.VLAN_ID;
}
public VlanId vlanId() {
return this.vlanId;
}
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("id", vlanId).toString();
}
}
/**
* Represents a VLAN PCP modification instruction.
*/
public static final class ModVlanPcpInstruction extends L2ModificationInstruction {
public final Byte vlanPcp;
public ModVlanPcpInstruction(Byte vlanPcp) {
this.vlanPcp = vlanPcp;
}
@Override
public L2SubType subtype() {
return L2SubType.VLAN_PCP;
}
public Byte vlanPcp() {
return this.vlanPcp;
}
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("pcp", Long.toHexString(vlanPcp)).toString();
}
}
}