blob: ada96a5db16a3396d1ed377c1721f934916ada60 [file] [log] [blame]
alshabib55a55d92014-09-16 11:59:31 -07001package org.onlab.onos.net.flow.instructions;
2
3import static com.google.common.base.Preconditions.checkNotNull;
4
5import org.onlab.onos.net.PortNumber;
alshabib7410fea2014-09-16 13:48:39 -07006import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType;
alshabib55a55d92014-09-16 11:59:31 -07007import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
alshabib7410fea2014-09-16 13:48:39 -07008import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType;
9import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070010import org.onlab.packet.IpPrefix;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070011import org.onlab.packet.MacAddress;
12import org.onlab.packet.VlanId;
alshabib64231f62014-09-16 17:58:36 -070013
alshabib55a55d92014-09-16 11:59:31 -070014/**
15 * Factory class for creating various traffic treatment instructions.
16 */
17public final class Instructions {
18
19
20 // Ban construction
21 private Instructions() {}
22
23 /**
24 * Creates an output instruction using the specified port number. This can
25 * include logical ports such as CONTROLLER, FLOOD, etc.
26 *
27 * @param number port number
28 * @return output instruction
29 */
30 public static OutputInstruction createOutput(final PortNumber number) {
31 checkNotNull(number, "PortNumber cannot be null");
32 return new OutputInstruction(number);
33 }
34
35 /**
36 * Creates a drop instruction.
37 * @return drop instruction
38 */
39 public static DropInstruction createDrop() {
40 return new DropInstruction();
41 }
42
43 /**
44 * Creates a l2 src modification.
45 * @param addr the mac address to modify to.
46 * @return a l2 modification
47 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070048 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -070049 checkNotNull(addr, "Src l2 address cannot be null");
alshabib7410fea2014-09-16 13:48:39 -070050 return new ModEtherInstruction(L2SubType.L2_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -070051 }
52
53 /**
54 * Creates a L2 dst modification.
55 * @param addr the mac address to modify to.
56 * @return a L2 modification
57 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070058 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -070059 checkNotNull(addr, "Dst l2 address cannot be null");
alshabib7410fea2014-09-16 13:48:39 -070060 return new L2ModificationInstruction.ModEtherInstruction(L2SubType.L2_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -070061 }
62
63 /**
alshabib7410fea2014-09-16 13:48:39 -070064 * Creates a Vlan id modification.
65 * @param vlanId the vlan id to modify to.
66 * @return a L2 modification
67 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070068 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -070069 checkNotNull(vlanId, "VLAN id cannot be null");
70 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
71 }
72
alshabib7410fea2014-09-16 13:48:39 -070073 /**
74 * Creates a Vlan pcp modification.
75 * @param vlanPcp the pcp to modify to.
76 * @return a L2 modification
77 */
78 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
79 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
80 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
81 }
82
83 /**
84 * Creates a L3 src modification.
85 * @param addr the ip address to modify to.
86 * @return a L3 modification
87 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070088 public static L3ModificationInstruction modL3Src(IpPrefix addr) {
alshabib7410fea2014-09-16 13:48:39 -070089 checkNotNull(addr, "Src l3 address cannot be null");
90 return new ModIPInstruction(L3SubType.L3_SRC, addr);
91 }
92
93 /**
94 * Creates a L3 dst modification.
95 * @param addr the ip address to modify to.
96 * @return a L3 modification
97 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070098 public static L3ModificationInstruction modL3Dst(IpPrefix addr) {
alshabib7410fea2014-09-16 13:48:39 -070099 checkNotNull(addr, "Dst l3 address cannot be null");
100 return new ModIPInstruction(L3SubType.L3_DST, addr);
101 }
102
alshabib7410fea2014-09-16 13:48:39 -0700103
alshabib55a55d92014-09-16 11:59:31 -0700104 /*
105 * Output instructions
106 */
107
108 public static final class DropInstruction implements Instruction {
109 @Override
110 public Type type() {
111 return Type.DROP;
112 }
113 }
114
115
116 public static final class OutputInstruction implements Instruction {
117 private final PortNumber port;
118
119 private OutputInstruction(PortNumber port) {
120 this.port = port;
121 }
122
123 public PortNumber port() {
124 return port;
125 }
126
127 @Override
128 public Type type() {
129 return Type.OUTPUT;
130 }
alshabib55a55d92014-09-16 11:59:31 -0700131 }
132
133}