blob: f71ad2e7ce57cb73a944733d783f49fb4a900aa9 [file] [log] [blame]
alshabib55a55d92014-09-16 11:59:31 -07001package org.onlab.onos.net.flow.instructions;
2
3import org.onlab.packet.MACAddress;
4
5/**
6 * Abstraction of a single traffic treatment step.
7 * @param <T> the type parameter for the instruction
8 */
9public abstract class L2ModificationInstruction implements Instruction {
10
11 /**
12 * Represents the type of traffic treatment.
13 */
14 public enum SubType {
15 /**
16 * Ether src modification.
17 */
18 L2_SRC,
19
20 /**
21 * Ether dst modification.
22 */
23 L2_DST,
24
25 /**
26 * Ethertype modification.
27 */
28 L2_TYPE,
29
30 /**
31 * VLAN id modification.
32 */
33 VLAN_ID,
34
35 /**
36 * VLAN priority modification.
37 */
38 VLAN_PCP
39 }
40
41 // TODO: Create factory class 'Instructions' that will have various factory
42 // to create specific instructions.
43
44 /**
45 * Returns the subtype of the modification instruction.
46 * @return type of instruction
47 */
48 public abstract SubType subtype();
49
50 @Override
51 public Type type() {
52 return Type.MODIFICATION;
53 }
54
55 /**
56 * Represents a L2 src/dst modification instruction.
57 */
58 public static final class ModEtherInstruction extends L2ModificationInstruction {
59
60 private final SubType subtype;
61 private final MACAddress mac;
62
63 public ModEtherInstruction(SubType subType, MACAddress addr) {
64 this.subtype = subType;
65 this.mac = addr;
66 }
67
68 @Override
69 public SubType subtype() {
70 return this.subtype;
71 }
72
73 public MACAddress mac() {
74 return this.mac;
75 }
76
77 }
78
79 /**
80 * Represents a L2 type modification instruction.
81 */
82 public static final class ModEtherTypeInstruction extends L2ModificationInstruction {
83
84 public final short l2Type;
85
86 public ModEtherTypeInstruction(short l2Type) {
87 this.l2Type = l2Type;
88 }
89
90 @Override
91 public SubType subtype() {
92 return SubType.L2_TYPE;
93 }
94
95 public short l2Type() {
96 return this.l2Type;
97 }
98
99 }
100
101 /**
102 * Represents a VLAN id modification instruction.
103 */
104 public static final class ModVlanIdInstruction extends L2ModificationInstruction {
105
106 public final Short vlanId;
107
108 public ModVlanIdInstruction(Short vlanId) {
109 this.vlanId = vlanId;
110 }
111
112 @Override
113 public SubType subtype() {
114 return SubType.VLAN_ID;
115 }
116
117 public Short vlanId() {
118 return this.vlanId;
119 }
120
121 }
122
123
124}