alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | |
| 3 | import org.onlab.packet.MACAddress; |
| 4 | |
| 5 | /** |
| 6 | * Abstraction of a single traffic treatment step. |
| 7 | * @param <T> the type parameter for the instruction |
| 8 | */ |
| 9 | public abstract class L2ModificationInstruction implements Instruction { |
| 10 | |
| 11 | /** |
| 12 | * Represents the type of traffic treatment. |
| 13 | */ |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame^] | 14 | public enum L2SubType implements SubType { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 15 | /** |
| 16 | * Ether src modification. |
| 17 | */ |
| 18 | L2_SRC, |
| 19 | |
| 20 | /** |
| 21 | * Ether dst modification. |
| 22 | */ |
| 23 | L2_DST, |
| 24 | |
| 25 | /** |
| 26 | * Ethertype modification. |
| 27 | */ |
| 28 | L2_TYPE, |
| 29 | |
| 30 | /** |
| 31 | * VLAN id modification. |
| 32 | */ |
| 33 | VLAN_ID, |
| 34 | |
| 35 | /** |
| 36 | * VLAN priority modification. |
| 37 | */ |
| 38 | VLAN_PCP |
| 39 | } |
| 40 | |
| 41 | // TODO: Create factory class 'Instructions' that will have various factory |
| 42 | // to create specific instructions. |
| 43 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame^] | 44 | @Override |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 45 | public abstract SubType subtype(); |
| 46 | |
| 47 | @Override |
| 48 | public Type type() { |
| 49 | return Type.MODIFICATION; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Represents a L2 src/dst modification instruction. |
| 54 | */ |
| 55 | public static final class ModEtherInstruction extends L2ModificationInstruction { |
| 56 | |
| 57 | private final SubType subtype; |
| 58 | private final MACAddress mac; |
| 59 | |
| 60 | public ModEtherInstruction(SubType subType, MACAddress addr) { |
| 61 | this.subtype = subType; |
| 62 | this.mac = addr; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public SubType subtype() { |
| 67 | return this.subtype; |
| 68 | } |
| 69 | |
| 70 | public MACAddress mac() { |
| 71 | return this.mac; |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Represents a L2 type modification instruction. |
| 78 | */ |
| 79 | public static final class ModEtherTypeInstruction extends L2ModificationInstruction { |
| 80 | |
| 81 | public final short l2Type; |
| 82 | |
| 83 | public ModEtherTypeInstruction(short l2Type) { |
| 84 | this.l2Type = l2Type; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame^] | 89 | return L2SubType.L2_TYPE; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | public short l2Type() { |
| 93 | return this.l2Type; |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Represents a VLAN id modification instruction. |
| 100 | */ |
| 101 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 102 | |
| 103 | public final Short vlanId; |
| 104 | |
| 105 | public ModVlanIdInstruction(Short vlanId) { |
| 106 | this.vlanId = vlanId; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame^] | 111 | return L2SubType.VLAN_ID; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | public Short vlanId() { |
| 115 | return this.vlanId; |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame^] | 120 | /** |
| 121 | * Represents a VLAN PCP modification instruction. |
| 122 | */ |
| 123 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { |
| 124 | |
| 125 | public final Byte vlanPcp; |
| 126 | |
| 127 | public ModVlanPcpInstruction(Byte vlanPcp) { |
| 128 | this.vlanPcp = vlanPcp; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public SubType subtype() { |
| 133 | return L2SubType.VLAN_PCP; |
| 134 | } |
| 135 | |
| 136 | public Byte vlanPcp() { |
| 137 | return this.vlanPcp; |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 142 | |
| 143 | } |