blob: c9f106852a8a43020bef9ec02a0f00637f636adb [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.instructions;
alshabib55a55d92014-09-16 11:59:31 -070017
alshabib7b808c52015-06-26 14:22:24 -070018import org.onlab.packet.EthType;
Jonathan Hart54b406b2015-03-06 16:24:14 -080019import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070022import org.onlab.packet.TpPort;
Jonathan Hart54b406b2015-03-06 16:24:14 -080023import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080024import org.onosproject.core.GroupId;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070025import org.onosproject.net.IndexedLambda;
26import org.onosproject.net.Lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070027import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.PortNumber;
29import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
30import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070031import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
33import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080034import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
sangho3f97a17d2015-01-29 22:56:29 -080035import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070036import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
37import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
alshabib10c810b2015-08-18 16:59:04 -070038import org.onosproject.net.meter.MeterId;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080039
Jonathan Hart54b406b2015-03-06 16:24:14 -080040import java.util.Objects;
41
42import static com.google.common.base.MoreObjects.toStringHelper;
43import static com.google.common.base.Preconditions.checkNotNull;
alshabib64231f62014-09-16 17:58:36 -070044
alshabib55a55d92014-09-16 11:59:31 -070045/**
46 * Factory class for creating various traffic treatment instructions.
47 */
48public final class Instructions {
49
50
51 // Ban construction
52 private Instructions() {}
53
54 /**
55 * Creates an output instruction using the specified port number. This can
56 * include logical ports such as CONTROLLER, FLOOD, etc.
57 *
58 * @param number port number
59 * @return output instruction
60 */
61 public static OutputInstruction createOutput(final PortNumber number) {
62 checkNotNull(number, "PortNumber cannot be null");
63 return new OutputInstruction(number);
64 }
65
66 /**
67 * Creates a drop instruction.
Jonathan Hart54b406b2015-03-06 16:24:14 -080068 *
alshabib55a55d92014-09-16 11:59:31 -070069 * @return drop instruction
70 */
Charles Chan7efabeb2015-09-28 15:12:19 -070071 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -070072 public static DropInstruction createDrop() {
73 return new DropInstruction();
74 }
75
76 /**
Charles Chan7efabeb2015-09-28 15:12:19 -070077 * Creates a no action instruction.
78 *
79 * @return no action instruction
80 */
81 public static NoActionInstruction createNoAction() {
82 return new NoActionInstruction();
83 }
84
85 /**
sangho8995ac52015-02-04 11:29:03 -080086 * Creates a group instruction.
87 *
88 * @param groupId Group Id
89 * @return group instruction
90 */
91 public static GroupInstruction createGroup(final GroupId groupId) {
92 checkNotNull(groupId, "GroupId cannot be null");
93 return new GroupInstruction(groupId);
94 }
95
alshabib10c810b2015-08-18 16:59:04 -070096 public static MeterInstruction meterTraffic(final MeterId meterId) {
97 checkNotNull(meterId, "meter id cannot be null");
98 return new MeterInstruction(meterId);
99 }
100
sangho8995ac52015-02-04 11:29:03 -0800101 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700102 * Creates an L0 modification with the specified OCh signal.
103 *
104 * @param lambda OCh signal
105 * @return an L0 modification
106 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700107 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700108 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700109
110 if (lambda instanceof IndexedLambda) {
111 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
112 } else if (lambda instanceof OchSignal) {
113 return new ModOchSignalInstruction((OchSignal) lambda);
114 } else {
115 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
116 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700117 }
118
119 /**
alshabib55a55d92014-09-16 11:59:31 -0700120 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800121 *
122 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700123 * @return a l2 modification
124 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700125 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700126 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700127 return new L2ModificationInstruction.ModEtherInstruction(
128 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700129 }
130
131 /**
132 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800133 *
134 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700135 * @return a L2 modification
136 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700137 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700138 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700139 return new L2ModificationInstruction.ModEtherInstruction(
140 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700141 }
142
143 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800144 * Creates a VLAN ID modification.
145 *
146 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700147 * @return a L2 modification
148 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700149 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700150 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700151 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700152 }
153
alshabib7410fea2014-09-16 13:48:39 -0700154 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800155 * Creates a VLAN PCP modification.
156 *
157 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700158 * @return a L2 modification
159 */
160 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
161 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700162 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700163 }
164
165 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800166 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800167 *
168 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800169 * @return a L2 Modification
170 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100171 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800172 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700173 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800174 }
sangho3f97a17d2015-01-29 22:56:29 -0800175
176 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700177 * Creates a MPLS BOS bit modification.
178 *
179 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
180 * @return a L2 Modification
181 */
182 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
183 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
184 }
185
186 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800187 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800188 *
189 * @return a L2 Modification
190 */
191 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700192 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800193 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800194
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800195 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800196 * Creates a L3 IPv4 src modification.
197 *
198 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700199 * @return a L3 modification
200 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700201 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800202 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
203 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700204 }
205
206 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800207 * Creates a L3 IPv4 dst modification.
208 *
209 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700210 * @return a L3 modification
211 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700212 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800213 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
214 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
215 }
216
217 /**
218 * Creates a L3 IPv6 src modification.
219 *
220 * @param addr the IPv6 address to modify to
221 * @return a L3 modification
222 */
223 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
224 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
225 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
226 }
227
228 /**
229 * Creates a L3 IPv6 dst modification.
230 *
231 * @param addr the IPv6 address to modify to
232 * @return a L3 modification
233 */
234 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
235 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
236 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
237 }
238
239 /**
240 * Creates a L3 IPv6 Flow Label modification.
241 *
242 * @param flowLabel the IPv6 flow label to modify to (20 bits)
243 * @return a L3 modification
244 */
245 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
246 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700247 }
248
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800249 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800250 * Creates a L3 decrement TTL modification.
251 *
sangho3f97a17d2015-01-29 22:56:29 -0800252 * @return a L3 modification
253 */
254 public static L3ModificationInstruction decNwTtl() {
255 return new ModTtlInstruction(L3SubType.DEC_TTL);
256 }
257
258 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800259 * Creates a L3 copy TTL to outer header modification.
260 *
sangho3f97a17d2015-01-29 22:56:29 -0800261 * @return a L3 modification
262 */
263 public static L3ModificationInstruction copyTtlOut() {
264 return new ModTtlInstruction(L3SubType.TTL_OUT);
265 }
266
267 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800268 * Creates a L3 copy TTL to inner header modification.
269 *
sangho3f97a17d2015-01-29 22:56:29 -0800270 * @return a L3 modification
271 */
272 public static L3ModificationInstruction copyTtlIn() {
273 return new ModTtlInstruction(L3SubType.TTL_IN);
274 }
275
276 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800277 * Creates a push MPLS header instruction.
278 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800279 * @return a L2 modification.
280 */
281 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700282 return new L2ModificationInstruction.PushHeaderInstructions(
283 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700284 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800285 }
286
287 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800288 * Creates a pop MPLS header instruction.
289 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800290 * @return a L2 modification.
291 */
292 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700293 return new L2ModificationInstruction.PushHeaderInstructions(
294 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700295 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800296 }
alshabib7410fea2014-09-16 13:48:39 -0700297
sangho3f97a17d2015-01-29 22:56:29 -0800298 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800299 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800300 *
301 * @param etherType Ethernet type to set
302 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700303 */
304 public static Instruction popMpls(EthType etherType) {
305 checkNotNull(etherType, "Ethernet type cannot be null");
306 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700307 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800308 }
309
Saurav Dasfbe25c52015-03-04 11:12:00 -0800310 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800311 * Creates a pop VLAN header instruction.
312 *
313 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800314 */
315 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700316 return new L2ModificationInstruction.PopVlanInstruction(
317 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800318 }
319
320 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800321 * Creates a push VLAN header instruction.
322 *
323 * @return a L2 modification
324 */
325 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700326 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700327 L2ModificationInstruction.L2SubType.VLAN_PUSH,
328 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800329 }
330
331 /**
alshabibd17abc22015-04-21 18:26:35 -0700332 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800333 *
alshabibd17abc22015-04-21 18:26:35 -0700334 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800335 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800336 */
alshabibd17abc22015-04-21 18:26:35 -0700337 public static Instruction transition(Integer tableId) {
338 checkNotNull(tableId, "Table id cannot be null");
339 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800340 }
341
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800342 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700343 * Writes metadata to associate with a packet.
344 *
345 * @param metadata the metadata value to write
346 * @param metadataMask the bits to mask for the metadata value
347 * @return metadata instruction
348 */
349 public static Instruction writeMetadata(long metadata, long metadataMask) {
350 return new MetadataInstruction(metadata, metadataMask);
351 }
352
353 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700354 * Creates a Tunnel ID modification.
355 *
356 * @param tunnelId the Tunnel ID to modify to
357 * @return a L2 modification
358 */
359 public static L2ModificationInstruction modTunnelId(long tunnelId) {
360 checkNotNull(tunnelId, "Tunnel id cannot be null");
361 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
362 }
363
364 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700365 * Creates a TCP src modification.
366 *
367 * @param port the TCP port number to modify to
368 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700369 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700370 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700371 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700372 public static L4ModificationInstruction modTcpSrc(short port) {
373 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700374 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
375 }
376
377 /**
378 * Creates a TCP src modification.
379 *
380 * @param port the TCP port number to modify to
381 * @return a L4 modification
382 */
383 public static L4ModificationInstruction modTcpSrc(TpPort port) {
384 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700385 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
386 }
387
388 /**
389 * Creates a TCP dst modification.
390 *
391 * @param port the TCP port number to modify to
392 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700393 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700394 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700395 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700396 public static L4ModificationInstruction modTcpDst(short port) {
397 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700398 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
399 }
400
401 /**
402 * Creates a TCP dst modification.
403 *
404 * @param port the TCP port number to modify to
405 * @return a L4 modification
406 */
407 public static L4ModificationInstruction modTcpDst(TpPort port) {
408 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700409 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
410 }
411
412 /**
413 * Creates a UDP src modification.
414 *
415 * @param port the UDP port number to modify to
416 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700417 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700418 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700419 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700420 public static L4ModificationInstruction modUdpSrc(short port) {
421 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700422 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
423 }
424
425 /**
426 * Creates a UDP src modification.
427 *
428 * @param port the UDP port number to modify to
429 * @return a L4 modification
430 */
431 public static L4ModificationInstruction modUdpSrc(TpPort port) {
432 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700433 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
434 }
435
436 /**
437 * Creates a UDP dst modification.
438 *
439 * @param port the UDP port number to modify to
440 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700441 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700442 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700443 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700444 public static L4ModificationInstruction modUdpDst(short port) {
445 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700446 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
447 }
448
449 /**
450 * Creates a UDP dst modification.
451 *
452 * @param port the UDP port number to modify to
453 * @return a L4 modification
454 */
455 public static L4ModificationInstruction modUdpDst(TpPort port) {
456 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700457 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
458 }
459
460 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800461 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700462 */
Charles Chan7efabeb2015-09-28 15:12:19 -0700463 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -0700464 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800465
466 private DropInstruction() {}
467
alshabib55a55d92014-09-16 11:59:31 -0700468 @Override
469 public Type type() {
470 return Type.DROP;
471 }
alshabib99b8fdc2014-09-25 14:30:22 -0700472
473 @Override
474 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800475 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700476 }
alshabib8ca53902014-10-07 13:11:17 -0700477
478 @Override
479 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700480 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700481 }
482
483 @Override
484 public boolean equals(Object obj) {
485 if (this == obj) {
486 return true;
487 }
488 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800489 return true;
alshabib8ca53902014-10-07 13:11:17 -0700490 }
491 return false;
492 }
alshabib55a55d92014-09-16 11:59:31 -0700493 }
494
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800495 /**
Charles Chan7efabeb2015-09-28 15:12:19 -0700496 * No Action instruction.
497 */
498 public static final class NoActionInstruction implements Instruction {
499
500 private NoActionInstruction() {}
501
502 @Override
503 public Type type() {
504 return Type.NOACTION;
505 }
506
507 @Override
508 public String toString() {
509 return toStringHelper(type().toString()).toString();
510 }
511
512 @Override
513 public int hashCode() {
514 return Objects.hash(type().ordinal());
515 }
516
517 @Override
518 public boolean equals(Object obj) {
519 if (this == obj) {
520 return true;
521 }
522 if (obj instanceof NoActionInstruction) {
523 return true;
524 }
525 return false;
526 }
527 }
528
529 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800530 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800531 */
alshabib55a55d92014-09-16 11:59:31 -0700532 public static final class OutputInstruction implements Instruction {
533 private final PortNumber port;
534
535 private OutputInstruction(PortNumber port) {
536 this.port = port;
537 }
538
539 public PortNumber port() {
540 return port;
541 }
542
543 @Override
544 public Type type() {
545 return Type.OUTPUT;
546 }
alshabib99b8fdc2014-09-25 14:30:22 -0700547 @Override
548 public String toString() {
549 return toStringHelper(type().toString())
550 .add("port", port).toString();
551 }
alshabib8ca53902014-10-07 13:11:17 -0700552
553 @Override
554 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700555 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700556 }
557
558 @Override
559 public boolean equals(Object obj) {
560 if (this == obj) {
561 return true;
562 }
563 if (obj instanceof OutputInstruction) {
564 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700565 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700566
567 }
568 return false;
569 }
alshabib55a55d92014-09-16 11:59:31 -0700570 }
571
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800572 /**
573 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800574 */
sangho8995ac52015-02-04 11:29:03 -0800575 public static final class GroupInstruction implements Instruction {
576 private final GroupId groupId;
577
578 private GroupInstruction(GroupId groupId) {
579 this.groupId = groupId;
580 }
581
582 public GroupId groupId() {
583 return groupId;
584 }
585
586 @Override
587 public Type type() {
588 return Type.GROUP;
589 }
alshabib9af70072015-02-09 14:34:16 -0800590
sangho8995ac52015-02-04 11:29:03 -0800591 @Override
592 public String toString() {
593 return toStringHelper(type().toString())
594 .add("group ID", groupId.id()).toString();
595 }
596
597 @Override
598 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700599 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800600 }
601
602 @Override
603 public boolean equals(Object obj) {
604 if (this == obj) {
605 return true;
606 }
607 if (obj instanceof GroupInstruction) {
608 GroupInstruction that = (GroupInstruction) obj;
609 return Objects.equals(groupId, that.groupId);
610
611 }
612 return false;
613 }
614 }
615
Saurav Das86af8f12015-05-25 23:55:33 -0700616 /**
alshabib10c810b2015-08-18 16:59:04 -0700617 * A meter instruction.
618 */
619 public static final class MeterInstruction implements Instruction {
620 private final MeterId meterId;
621
622 private MeterInstruction(MeterId meterId) {
623 this.meterId = meterId;
624 }
625
626 public MeterId meterId() {
627 return meterId;
628 }
629
630 @Override
631 public Type type() {
632 return Type.METER;
633 }
634
635 @Override
636 public String toString() {
637 return toStringHelper(type().toString())
638 .add("meter ID", meterId.id()).toString();
639 }
640
641 @Override
642 public int hashCode() {
643 return Objects.hash(type().ordinal(), meterId);
644 }
645
646 @Override
647 public boolean equals(Object obj) {
648 if (this == obj) {
649 return true;
650 }
651 if (obj instanceof MeterInstruction) {
652 MeterInstruction that = (MeterInstruction) obj;
653 return Objects.equals(meterId, that.meterId);
654
655 }
656 return false;
657 }
658 }
659
660 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700661 * Transition instruction.
662 */
alshabibd17abc22015-04-21 18:26:35 -0700663 public static class TableTypeTransition implements Instruction {
664 private final Integer tableId;
665
666 TableTypeTransition(Integer tableId) {
667 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800668 }
669
670 @Override
671 public Type type() {
672 return Type.TABLE;
673 }
674
alshabibd17abc22015-04-21 18:26:35 -0700675 public Integer tableId() {
676 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800677 }
678
679 @Override
680 public String toString() {
681 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700682 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800683 }
684
685 @Override
686 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700687 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800688 }
689
690 @Override
691 public boolean equals(Object obj) {
692 if (this == obj) {
693 return true;
694 }
695 if (obj instanceof TableTypeTransition) {
696 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700697 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800698
699 }
700 return false;
701 }
Saurav Das86af8f12015-05-25 23:55:33 -0700702 }
alshabib9af70072015-02-09 14:34:16 -0800703
Saurav Das86af8f12015-05-25 23:55:33 -0700704 /**
705 * Metadata instruction.
706 */
707 public static class MetadataInstruction implements Instruction {
708 private final long metadata;
709 private final long metadataMask;
710
711 MetadataInstruction(long metadata, long metadataMask) {
712 this.metadata = metadata;
713 this.metadataMask = metadataMask;
714 }
715
716 @Override
717 public Type type() {
718 return Type.METADATA;
719 }
720
721 public long metadata() {
722 return this.metadata;
723 }
724
725 public long metadataMask() {
726 return this.metadataMask;
727 }
728
729 @Override
730 public String toString() {
731 return toStringHelper(type().toString())
732 .add("metadata", Long.toHexString(this.metadata))
733 .add("metadata mask", Long.toHexString(this.metadataMask))
734 .toString();
735 }
736
737 @Override
738 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700739 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700740 }
741
742 @Override
743 public boolean equals(Object obj) {
744 if (this == obj) {
745 return true;
746 }
747 if (obj instanceof MetadataInstruction) {
748 MetadataInstruction that = (MetadataInstruction) obj;
749 return Objects.equals(metadata, that.metadata) &&
750 Objects.equals(metadataMask, that.metadataMask);
751
752 }
753 return false;
754 }
alshabib9af70072015-02-09 14:34:16 -0800755 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700756
alshabib55a55d92014-09-16 11:59:31 -0700757}
alshabib8ca53902014-10-07 13:11:17 -0700758
759