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