blob: da86e13c1c3d2ada9983808d823725d8c194053d [file] [log] [blame]
alshabib55a55d92014-09-16 11:59:31 -07001package org.onlab.onos.net.flow.instructions;
2
3import org.onlab.packet.MACAddress;
alshabib7b795492014-09-16 14:38:39 -07004import 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;
59 private final MACAddress mac;
60
61 public ModEtherInstruction(SubType subType, MACAddress addr) {
62 this.subtype = subType;
63 this.mac = addr;
64 }
65
66 @Override
67 public SubType subtype() {
68 return this.subtype;
69 }
70
71 public MACAddress mac() {
72 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
alshabib7b795492014-09-16 14:38:39 -0700104 public final VLANID vlanId;
alshabib55a55d92014-09-16 11:59:31 -0700105
alshabib7b795492014-09-16 14:38:39 -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
alshabib7b795492014-09-16 14:38:39 -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}