blob: 894942c400390dde404c9d41eb13763cc798e934 [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;
alshabib7410fea2014-09-16 13:48:39 -070010import org.onlab.packet.IPAddress;
alshabib55a55d92014-09-16 11:59:31 -070011import org.onlab.packet.MACAddress;
alshabib7b795492014-09-16 14:38:39 -070012import org.onlab.packet.VLANID;
alshabib55a55d92014-09-16 11:59:31 -070013/**
14 * Factory class for creating various traffic treatment instructions.
15 */
16public final class Instructions {
17
18
19 // Ban construction
20 private Instructions() {}
21
22 /**
23 * Creates an output instruction using the specified port number. This can
24 * include logical ports such as CONTROLLER, FLOOD, etc.
25 *
26 * @param number port number
27 * @return output instruction
28 */
29 public static OutputInstruction createOutput(final PortNumber number) {
30 checkNotNull(number, "PortNumber cannot be null");
31 return new OutputInstruction(number);
32 }
33
34 /**
35 * Creates a drop instruction.
36 * @return drop instruction
37 */
38 public static DropInstruction createDrop() {
39 return new DropInstruction();
40 }
41
42 /**
43 * Creates a l2 src modification.
44 * @param addr the mac address to modify to.
45 * @return a l2 modification
46 */
47 public static L2ModificationInstruction modL2Src(MACAddress addr) {
48 checkNotNull(addr, "Src l2 address cannot be null");
alshabib7410fea2014-09-16 13:48:39 -070049 return new ModEtherInstruction(L2SubType.L2_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -070050 }
51
52 /**
53 * Creates a L2 dst modification.
54 * @param addr the mac address to modify to.
55 * @return a L2 modification
56 */
57 public static L2ModificationInstruction modL2Dst(MACAddress addr) {
58 checkNotNull(addr, "Dst l2 address cannot be null");
alshabib7410fea2014-09-16 13:48:39 -070059 return new L2ModificationInstruction.ModEtherInstruction(L2SubType.L2_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -070060 }
61
62 /**
alshabib7410fea2014-09-16 13:48:39 -070063 * Creates a Vlan id modification.
64 * @param vlanId the vlan id to modify to.
65 * @return a L2 modification
66 */
alshabib7b795492014-09-16 14:38:39 -070067 public static L2ModificationInstruction modVlanId(VLANID vlanId) {
alshabib55a55d92014-09-16 11:59:31 -070068 checkNotNull(vlanId, "VLAN id cannot be null");
69 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
70 }
71
alshabib7410fea2014-09-16 13:48:39 -070072 /**
73 * Creates a Vlan pcp modification.
74 * @param vlanPcp the pcp to modify to.
75 * @return a L2 modification
76 */
77 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
78 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
79 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
80 }
81
82 /**
83 * Creates a L3 src modification.
84 * @param addr the ip address to modify to.
85 * @return a L3 modification
86 */
87 public static L3ModificationInstruction modL3Src(IPAddress addr) {
88 checkNotNull(addr, "Src l3 address cannot be null");
89 return new ModIPInstruction(L3SubType.L3_SRC, addr);
90 }
91
92 /**
93 * Creates a L3 dst modification.
94 * @param addr the ip address to modify to.
95 * @return a L3 modification
96 */
97 public static L3ModificationInstruction modL3Dst(IPAddress addr) {
98 checkNotNull(addr, "Dst l3 address cannot be null");
99 return new ModIPInstruction(L3SubType.L3_DST, addr);
100 }
101
alshabib7410fea2014-09-16 13:48:39 -0700102
alshabib55a55d92014-09-16 11:59:31 -0700103 /*
104 * Output instructions
105 */
106
107 public static final class DropInstruction implements Instruction {
108 @Override
109 public Type type() {
110 return Type.DROP;
111 }
112 }
113
114
115 public static final class OutputInstruction implements Instruction {
116 private final PortNumber port;
117
118 private OutputInstruction(PortNumber port) {
119 this.port = port;
120 }
121
122 public PortNumber port() {
123 return port;
124 }
125
126 @Override
127 public Type type() {
128 return Type.OUTPUT;
129 }
alshabib55a55d92014-09-16 11:59:31 -0700130 }
131
132}