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 | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 15 | public enum L2SubType { |
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 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 27 | * VLAN id modification. |
| 28 | */ |
| 29 | VLAN_ID, |
| 30 | |
| 31 | /** |
| 32 | * VLAN priority modification. |
| 33 | */ |
| 34 | VLAN_PCP |
| 35 | } |
| 36 | |
| 37 | // TODO: Create factory class 'Instructions' that will have various factory |
| 38 | // to create specific instructions. |
| 39 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 40 | public abstract L2SubType subtype(); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 41 | |
| 42 | @Override |
| 43 | public Type type() { |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 44 | return Type.L2MODIFICATION; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Represents a L2 src/dst modification instruction. |
| 49 | */ |
| 50 | public static final class ModEtherInstruction extends L2ModificationInstruction { |
| 51 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 52 | private final L2SubType subtype; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 53 | private final MacAddress mac; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 54 | |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame^] | 55 | public ModEtherInstruction(L2SubType subType, MacAddress addr) { |
| 56 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 57 | this.subtype = subType; |
| 58 | this.mac = addr; |
| 59 | } |
| 60 | |
| 61 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 62 | public L2SubType subtype() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 63 | return this.subtype; |
| 64 | } |
| 65 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 66 | public MacAddress mac() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 67 | return this.mac; |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | /** |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 73 | * Represents a VLAN id modification instruction. |
| 74 | */ |
| 75 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 76 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 77 | public final VlanId vlanId; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 78 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 79 | public ModVlanIdInstruction(VlanId vlanId) { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 80 | this.vlanId = vlanId; |
| 81 | } |
| 82 | |
| 83 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 84 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 85 | return L2SubType.VLAN_ID; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 88 | public VlanId vlanId() { |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 89 | return this.vlanId; |
| 90 | } |
| 91 | |
| 92 | } |
| 93 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Represents a VLAN PCP modification instruction. |
| 96 | */ |
| 97 | public static final class ModVlanPcpInstruction extends L2ModificationInstruction { |
| 98 | |
| 99 | public final Byte vlanPcp; |
| 100 | |
| 101 | public ModVlanPcpInstruction(Byte vlanPcp) { |
| 102 | this.vlanPcp = vlanPcp; |
| 103 | } |
| 104 | |
| 105 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 106 | public L2SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 107 | return L2SubType.VLAN_PCP; |
| 108 | } |
| 109 | |
| 110 | public Byte vlanPcp() { |
| 111 | return this.vlanPcp; |
| 112 | } |
| 113 | |
| 114 | } |
| 115 | |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 116 | |
| 117 | } |