blob: 8c51624b694f3181c41be0eb8fdbaf8bbac0e1b7 [file] [log] [blame]
alshabib55a55d92014-09-16 11:59:31 -07001package org.onlab.onos.net.flow.instructions;
2
alshabib99b8fdc2014-09-25 14:30:22 -07003import static com.google.common.base.MoreObjects.toStringHelper;
4
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07005import org.onlab.packet.MacAddress;
6import org.onlab.packet.VlanId;
alshabib55a55d92014-09-16 11:59:31 -07007
8/**
9 * Abstraction of a single traffic treatment step.
alshabib55a55d92014-09-16 11:59:31 -070010 */
11public abstract class L2ModificationInstruction implements Instruction {
12
13 /**
14 * Represents the type of traffic treatment.
15 */
alshabib35edb1a2014-09-16 17:44:44 -070016 public enum L2SubType {
alshabib55a55d92014-09-16 11:59:31 -070017 /**
18 * Ether src modification.
19 */
alshabib99b8fdc2014-09-25 14:30:22 -070020 ETH_SRC,
alshabib55a55d92014-09-16 11:59:31 -070021
22 /**
23 * Ether dst modification.
24 */
alshabib99b8fdc2014-09-25 14:30:22 -070025 ETH_DST,
alshabib55a55d92014-09-16 11:59:31 -070026
27 /**
alshabib55a55d92014-09-16 11:59:31 -070028 * 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
alshabib35edb1a2014-09-16 17:44:44 -070041 public abstract L2SubType subtype();
alshabib55a55d92014-09-16 11:59:31 -070042
43 @Override
44 public Type type() {
alshabib35edb1a2014-09-16 17:44:44 -070045 return Type.L2MODIFICATION;
alshabib55a55d92014-09-16 11:59:31 -070046 }
47
48 /**
49 * Represents a L2 src/dst modification instruction.
50 */
51 public static final class ModEtherInstruction extends L2ModificationInstruction {
52
alshabib35edb1a2014-09-16 17:44:44 -070053 private final L2SubType subtype;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070054 private final MacAddress mac;
alshabib55a55d92014-09-16 11:59:31 -070055
alshabib64231f62014-09-16 17:58:36 -070056 public ModEtherInstruction(L2SubType subType, MacAddress addr) {
57
alshabib55a55d92014-09-16 11:59:31 -070058 this.subtype = subType;
59 this.mac = addr;
60 }
61
62 @Override
alshabib35edb1a2014-09-16 17:44:44 -070063 public L2SubType subtype() {
alshabib55a55d92014-09-16 11:59:31 -070064 return this.subtype;
65 }
66
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070067 public MacAddress mac() {
alshabib55a55d92014-09-16 11:59:31 -070068 return this.mac;
69 }
70
alshabib99b8fdc2014-09-25 14:30:22 -070071 @Override
72 public String toString() {
73 return toStringHelper(subtype().toString())
74 .add("mac", mac).toString();
75 }
76
77
alshabib55a55d92014-09-16 11:59:31 -070078 }
79
80 /**
alshabib55a55d92014-09-16 11:59:31 -070081 * Represents a VLAN id modification instruction.
82 */
83 public static final class ModVlanIdInstruction extends L2ModificationInstruction {
84
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070085 public final VlanId vlanId;
alshabib55a55d92014-09-16 11:59:31 -070086
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070087 public ModVlanIdInstruction(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -070088 this.vlanId = vlanId;
89 }
90
91 @Override
alshabib35edb1a2014-09-16 17:44:44 -070092 public L2SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -070093 return L2SubType.VLAN_ID;
alshabib55a55d92014-09-16 11:59:31 -070094 }
95
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070096 public VlanId vlanId() {
alshabib55a55d92014-09-16 11:59:31 -070097 return this.vlanId;
98 }
99
alshabib99b8fdc2014-09-25 14:30:22 -0700100 @Override
101 public String toString() {
102 return toStringHelper(subtype().toString())
103 .add("id", vlanId).toString();
104 }
105
alshabib55a55d92014-09-16 11:59:31 -0700106 }
107
alshabib7410fea2014-09-16 13:48:39 -0700108 /**
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
alshabib35edb1a2014-09-16 17:44:44 -0700120 public L2SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -0700121 return L2SubType.VLAN_PCP;
122 }
123
124 public Byte vlanPcp() {
125 return this.vlanPcp;
126 }
127
alshabib99b8fdc2014-09-25 14:30:22 -0700128 @Override
129 public String toString() {
130 return toStringHelper(subtype().toString())
131 .add("pcp", Long.toHexString(vlanPcp)).toString();
132 }
133
alshabib7410fea2014-09-16 13:48:39 -0700134 }
135
alshabib55a55d92014-09-16 11:59:31 -0700136
137}