blob: 9019efbd3b77fab35b4818c7c87deb7ea88aa33a [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 */
alshabib35edb1a2014-09-16 17:44:44 -070015 public enum L2SubType {
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 /**
alshabib55a55d92014-09-16 11:59:31 -070027 * VLAN id modification.
28 */
29 VLAN_ID,
30
31 /**
32 * VLAN priority modification.
33 */
34 VLAN_PCP
35 }
36
37 // TODO: Create factory class 'Instructions' that will have various factory
38 // to create specific instructions.
39
alshabib35edb1a2014-09-16 17:44:44 -070040 public abstract L2SubType subtype();
alshabib55a55d92014-09-16 11:59:31 -070041
42 @Override
43 public Type type() {
alshabib35edb1a2014-09-16 17:44:44 -070044 return Type.L2MODIFICATION;
alshabib55a55d92014-09-16 11:59:31 -070045 }
46
47 /**
48 * Represents a L2 src/dst modification instruction.
49 */
50 public static final class ModEtherInstruction extends L2ModificationInstruction {
51
alshabib35edb1a2014-09-16 17:44:44 -070052 private final L2SubType subtype;
alshabib55a55d92014-09-16 11:59:31 -070053 private final MACAddress mac;
54
alshabib35edb1a2014-09-16 17:44:44 -070055 public ModEtherInstruction(L2SubType subType, MACAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -070056 this.subtype = subType;
57 this.mac = addr;
58 }
59
60 @Override
alshabib35edb1a2014-09-16 17:44:44 -070061 public L2SubType subtype() {
alshabib55a55d92014-09-16 11:59:31 -070062 return this.subtype;
63 }
64
65 public MACAddress mac() {
66 return this.mac;
67 }
68
69 }
70
71 /**
alshabib55a55d92014-09-16 11:59:31 -070072 * Represents a VLAN id modification instruction.
73 */
74 public static final class ModVlanIdInstruction extends L2ModificationInstruction {
75
alshabib7b795492014-09-16 14:38:39 -070076 public final VLANID vlanId;
alshabib55a55d92014-09-16 11:59:31 -070077
alshabib7b795492014-09-16 14:38:39 -070078 public ModVlanIdInstruction(VLANID vlanId) {
alshabib55a55d92014-09-16 11:59:31 -070079 this.vlanId = vlanId;
80 }
81
82 @Override
alshabib35edb1a2014-09-16 17:44:44 -070083 public L2SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -070084 return L2SubType.VLAN_ID;
alshabib55a55d92014-09-16 11:59:31 -070085 }
86
alshabib7b795492014-09-16 14:38:39 -070087 public VLANID vlanId() {
alshabib55a55d92014-09-16 11:59:31 -070088 return this.vlanId;
89 }
90
91 }
92
alshabib7410fea2014-09-16 13:48:39 -070093 /**
94 * Represents a VLAN PCP modification instruction.
95 */
96 public static final class ModVlanPcpInstruction extends L2ModificationInstruction {
97
98 public final Byte vlanPcp;
99
100 public ModVlanPcpInstruction(Byte vlanPcp) {
101 this.vlanPcp = vlanPcp;
102 }
103
104 @Override
alshabib35edb1a2014-09-16 17:44:44 -0700105 public L2SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -0700106 return L2SubType.VLAN_PCP;
107 }
108
109 public Byte vlanPcp() {
110 return this.vlanPcp;
111 }
112
113 }
114
alshabib55a55d92014-09-16 11:59:31 -0700115
116}