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