blob: 5490de27dd9a13b6e494bd9083cf8f89fda27d76 [file] [log] [blame]
alshabib55a55d92014-09-16 11:59:31 -07001package org.onlab.onos.net.flow.instructions;
2
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07003import org.onlab.packet.MacAddress;
4import org.onlab.packet.VlanId;
alshabib55a55d92014-09-16 11:59:31 -07005
6/**
7 * Abstraction of a single traffic treatment step.
8 * @param <T> the type parameter for the instruction
9 */
10public abstract class L2ModificationInstruction implements Instruction {
11
12 /**
13 * Represents the type of traffic treatment.
14 */
alshabib7410fea2014-09-16 13:48:39 -070015 public enum L2SubType implements SubType {
alshabib55a55d92014-09-16 11:59:31 -070016 /**
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
alshabib7410fea2014-09-16 13:48:39 -070045 @Override
alshabib55a55d92014-09-16 11:59:31 -070046 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 Koshibea9c199f2014-09-16 16:21:40 -070059 private final MacAddress mac;
alshabib55a55d92014-09-16 11:59:31 -070060
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070061 public ModEtherInstruction(SubType subType, MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -070062 this.subtype = subType;
63 this.mac = addr;
64 }
65
66 @Override
67 public SubType subtype() {
68 return this.subtype;
69 }
70
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070071 public MacAddress mac() {
alshabib55a55d92014-09-16 11:59:31 -070072 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() {
alshabib7410fea2014-09-16 13:48:39 -070090 return L2SubType.L2_TYPE;
alshabib55a55d92014-09-16 11:59:31 -070091 }
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 Koshibea9c199f2014-09-16 16:21:40 -0700104 public final VlanId vlanId;
alshabib55a55d92014-09-16 11:59:31 -0700105
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700106 public ModVlanIdInstruction(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700107 this.vlanId = vlanId;
108 }
109
110 @Override
111 public SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -0700112 return L2SubType.VLAN_ID;
alshabib55a55d92014-09-16 11:59:31 -0700113 }
114
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700115 public VlanId vlanId() {
alshabib55a55d92014-09-16 11:59:31 -0700116 return this.vlanId;
117 }
118
119 }
120
alshabib7410fea2014-09-16 13:48:39 -0700121 /**
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
alshabib55a55d92014-09-16 11:59:31 -0700143
144}