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