blob: 8868bf7ca8f44c39d50ef9e9ce0e9cf5b44b6bc8 [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;
Yafit Hadar52d81552015-10-07 12:26:52 +030028import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.PortNumber;
30import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
31import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070032import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Yafit Hadar52d81552015-10-07 12:26:52 +030033import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
35import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080036import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
sangho3f97a17d2015-01-29 22:56:29 -080037import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070038import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
39import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
alshabib10c810b2015-08-18 16:59:04 -070040import org.onosproject.net.meter.MeterId;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080041
Jonathan Hart54b406b2015-03-06 16:24:14 -080042import java.util.Objects;
43
44import static com.google.common.base.MoreObjects.toStringHelper;
45import static com.google.common.base.Preconditions.checkNotNull;
alshabib64231f62014-09-16 17:58:36 -070046
alshabib55a55d92014-09-16 11:59:31 -070047/**
48 * Factory class for creating various traffic treatment instructions.
49 */
50public final class Instructions {
51
alshabib55a55d92014-09-16 11:59:31 -070052 // Ban construction
53 private Instructions() {}
54
55 /**
56 * Creates an output instruction using the specified port number. This can
57 * include logical ports such as CONTROLLER, FLOOD, etc.
58 *
59 * @param number port number
60 * @return output instruction
61 */
62 public static OutputInstruction createOutput(final PortNumber number) {
63 checkNotNull(number, "PortNumber cannot be null");
64 return new OutputInstruction(number);
65 }
66
67 /**
68 * Creates a drop instruction.
Jonathan Hart54b406b2015-03-06 16:24:14 -080069 *
alshabib55a55d92014-09-16 11:59:31 -070070 * @return drop instruction
71 */
Charles Chan7efabeb2015-09-28 15:12:19 -070072 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -070073 public static DropInstruction createDrop() {
74 return new DropInstruction();
75 }
76
77 /**
Charles Chan7efabeb2015-09-28 15:12:19 -070078 * Creates a no action instruction.
79 *
80 * @return no action instruction
81 */
82 public static NoActionInstruction createNoAction() {
83 return new NoActionInstruction();
84 }
85
86 /**
sangho8995ac52015-02-04 11:29:03 -080087 * Creates a group instruction.
88 *
89 * @param groupId Group Id
90 * @return group instruction
91 */
92 public static GroupInstruction createGroup(final GroupId groupId) {
93 checkNotNull(groupId, "GroupId cannot be null");
94 return new GroupInstruction(groupId);
95 }
96
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +020097 /**
98 * Creates a set-queue instruction.
99 *
100 * @param queueId Queue Id
101 * @return set-queue instruction
102 */
103 public static SetQueueInstruction setQueue(final long queueId) {
104 checkNotNull(queueId, "queue ID cannot be null");
105 return new SetQueueInstruction(queueId);
106 }
107
alshabib10c810b2015-08-18 16:59:04 -0700108 public static MeterInstruction meterTraffic(final MeterId meterId) {
109 checkNotNull(meterId, "meter id cannot be null");
110 return new MeterInstruction(meterId);
111 }
112
sangho8995ac52015-02-04 11:29:03 -0800113 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700114 * Creates an L0 modification with the specified OCh signal.
115 *
116 * @param lambda OCh signal
117 * @return an L0 modification
118 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700119 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700120 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700121
122 if (lambda instanceof IndexedLambda) {
123 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
124 } else if (lambda instanceof OchSignal) {
125 return new ModOchSignalInstruction((OchSignal) lambda);
126 } else {
127 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
128 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700129 }
130
131 /**
Yafit Hadar52d81552015-10-07 12:26:52 +0300132 * Creates an L1 modification with the specified ODU signal Id.
133 *
134 * @param oduSignalId ODU Signal Id
135 * @return a L1 modification
136 */
137 public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
138 checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
139 return new ModOduSignalIdInstruction(oduSignalId);
140 }
141 /**
alshabib55a55d92014-09-16 11:59:31 -0700142 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800143 *
144 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700145 * @return a l2 modification
146 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700147 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700148 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700149 return new L2ModificationInstruction.ModEtherInstruction(
150 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700151 }
152
153 /**
154 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800155 *
156 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700157 * @return a L2 modification
158 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700159 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700160 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700161 return new L2ModificationInstruction.ModEtherInstruction(
162 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700163 }
164
165 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800166 * Creates a VLAN ID modification.
167 *
168 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700169 * @return a L2 modification
170 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700171 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700172 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700173 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700174 }
175
alshabib7410fea2014-09-16 13:48:39 -0700176 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800177 * Creates a VLAN PCP modification.
178 *
179 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700180 * @return a L2 modification
181 */
182 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
183 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700184 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700185 }
186
187 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800188 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800189 *
190 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800191 * @return a L2 Modification
192 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100193 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800194 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700195 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800196 }
sangho3f97a17d2015-01-29 22:56:29 -0800197
198 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700199 * Creates a MPLS BOS bit modification.
200 *
201 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
202 * @return a L2 Modification
203 */
204 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
205 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
206 }
207
208 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800209 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800210 *
211 * @return a L2 Modification
212 */
213 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700214 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800215 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800216
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800217 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800218 * Creates a L3 IPv4 src modification.
219 *
220 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700221 * @return a L3 modification
222 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700223 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800224 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
225 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700226 }
227
228 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800229 * Creates a L3 IPv4 dst modification.
230 *
231 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700232 * @return a L3 modification
233 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700234 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800235 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
236 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
237 }
238
239 /**
240 * Creates a L3 IPv6 src modification.
241 *
242 * @param addr the IPv6 address to modify to
243 * @return a L3 modification
244 */
245 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
246 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
247 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
248 }
249
250 /**
251 * Creates a L3 IPv6 dst modification.
252 *
253 * @param addr the IPv6 address to modify to
254 * @return a L3 modification
255 */
256 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
257 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
258 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
259 }
260
261 /**
262 * Creates a L3 IPv6 Flow Label modification.
263 *
264 * @param flowLabel the IPv6 flow label to modify to (20 bits)
265 * @return a L3 modification
266 */
267 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
268 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700269 }
270
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800271 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800272 * Creates a L3 decrement TTL modification.
273 *
sangho3f97a17d2015-01-29 22:56:29 -0800274 * @return a L3 modification
275 */
276 public static L3ModificationInstruction decNwTtl() {
277 return new ModTtlInstruction(L3SubType.DEC_TTL);
278 }
279
280 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800281 * Creates a L3 copy TTL to outer header modification.
282 *
sangho3f97a17d2015-01-29 22:56:29 -0800283 * @return a L3 modification
284 */
285 public static L3ModificationInstruction copyTtlOut() {
286 return new ModTtlInstruction(L3SubType.TTL_OUT);
287 }
288
289 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800290 * Creates a L3 copy TTL to inner header modification.
291 *
sangho3f97a17d2015-01-29 22:56:29 -0800292 * @return a L3 modification
293 */
294 public static L3ModificationInstruction copyTtlIn() {
295 return new ModTtlInstruction(L3SubType.TTL_IN);
296 }
297
298 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800299 * Creates a push MPLS header instruction.
300 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800301 * @return a L2 modification.
302 */
303 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700304 return new L2ModificationInstruction.PushHeaderInstructions(
305 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700306 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800307 }
308
309 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800310 * Creates a pop MPLS header instruction.
311 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800312 * @return a L2 modification.
313 */
314 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700315 return new L2ModificationInstruction.PushHeaderInstructions(
316 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700317 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800318 }
alshabib7410fea2014-09-16 13:48:39 -0700319
sangho3f97a17d2015-01-29 22:56:29 -0800320 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800321 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800322 *
323 * @param etherType Ethernet type to set
324 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700325 */
326 public static Instruction popMpls(EthType etherType) {
327 checkNotNull(etherType, "Ethernet type cannot be null");
328 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700329 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800330 }
331
Saurav Dasfbe25c52015-03-04 11:12:00 -0800332 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800333 * Creates a pop VLAN header instruction.
334 *
335 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800336 */
337 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700338 return new L2ModificationInstruction.PopVlanInstruction(
339 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800340 }
341
342 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800343 * Creates a push VLAN header instruction.
344 *
345 * @return a L2 modification
346 */
347 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700348 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700349 L2ModificationInstruction.L2SubType.VLAN_PUSH,
350 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800351 }
352
353 /**
alshabibd17abc22015-04-21 18:26:35 -0700354 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800355 *
alshabibd17abc22015-04-21 18:26:35 -0700356 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800357 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800358 */
alshabibd17abc22015-04-21 18:26:35 -0700359 public static Instruction transition(Integer tableId) {
360 checkNotNull(tableId, "Table id cannot be null");
361 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800362 }
363
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800364 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700365 * Writes metadata to associate with a packet.
366 *
367 * @param metadata the metadata value to write
368 * @param metadataMask the bits to mask for the metadata value
369 * @return metadata instruction
370 */
371 public static Instruction writeMetadata(long metadata, long metadataMask) {
372 return new MetadataInstruction(metadata, metadataMask);
373 }
374
375 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700376 * Creates a Tunnel ID modification.
377 *
378 * @param tunnelId the Tunnel ID to modify to
379 * @return a L2 modification
380 */
381 public static L2ModificationInstruction modTunnelId(long tunnelId) {
382 checkNotNull(tunnelId, "Tunnel id cannot be null");
383 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
384 }
385
386 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700387 * Creates a TCP src modification.
388 *
389 * @param port the TCP port number to modify to
390 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700391 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700392 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700393 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700394 public static L4ModificationInstruction modTcpSrc(short port) {
395 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700396 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
397 }
398
399 /**
400 * Creates a TCP src modification.
401 *
402 * @param port the TCP port number to modify to
403 * @return a L4 modification
404 */
405 public static L4ModificationInstruction modTcpSrc(TpPort port) {
406 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700407 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
408 }
409
410 /**
411 * Creates a TCP dst modification.
412 *
413 * @param port the TCP port number to modify to
414 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700415 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700416 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700417 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700418 public static L4ModificationInstruction modTcpDst(short port) {
419 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700420 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
421 }
422
423 /**
424 * Creates a TCP dst modification.
425 *
426 * @param port the TCP port number to modify to
427 * @return a L4 modification
428 */
429 public static L4ModificationInstruction modTcpDst(TpPort port) {
430 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700431 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
432 }
433
434 /**
435 * Creates a UDP src modification.
436 *
437 * @param port the UDP port number to modify to
438 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700439 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700440 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700441 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700442 public static L4ModificationInstruction modUdpSrc(short port) {
443 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700444 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
445 }
446
447 /**
448 * Creates a UDP src modification.
449 *
450 * @param port the UDP port number to modify to
451 * @return a L4 modification
452 */
453 public static L4ModificationInstruction modUdpSrc(TpPort port) {
454 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700455 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
456 }
457
458 /**
459 * Creates a UDP dst modification.
460 *
461 * @param port the UDP port number to modify to
462 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700463 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700464 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700465 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700466 public static L4ModificationInstruction modUdpDst(short port) {
467 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700468 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
469 }
470
471 /**
472 * Creates a UDP dst modification.
473 *
474 * @param port the UDP port number to modify to
475 * @return a L4 modification
476 */
477 public static L4ModificationInstruction modUdpDst(TpPort port) {
478 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700479 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
480 }
481
482 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800483 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700484 */
Charles Chan7efabeb2015-09-28 15:12:19 -0700485 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -0700486 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800487
488 private DropInstruction() {}
489
alshabib55a55d92014-09-16 11:59:31 -0700490 @Override
491 public Type type() {
492 return Type.DROP;
493 }
alshabib99b8fdc2014-09-25 14:30:22 -0700494
495 @Override
496 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800497 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700498 }
alshabib8ca53902014-10-07 13:11:17 -0700499
500 @Override
501 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700502 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700503 }
504
505 @Override
506 public boolean equals(Object obj) {
507 if (this == obj) {
508 return true;
509 }
510 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800511 return true;
alshabib8ca53902014-10-07 13:11:17 -0700512 }
513 return false;
514 }
alshabib55a55d92014-09-16 11:59:31 -0700515 }
516
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800517 /**
Charles Chan7efabeb2015-09-28 15:12:19 -0700518 * No Action instruction.
519 */
520 public static final class NoActionInstruction implements Instruction {
521
522 private NoActionInstruction() {}
523
524 @Override
525 public Type type() {
526 return Type.NOACTION;
527 }
528
529 @Override
530 public String toString() {
531 return toStringHelper(type().toString()).toString();
532 }
533
534 @Override
535 public int hashCode() {
536 return Objects.hash(type().ordinal());
537 }
538
539 @Override
540 public boolean equals(Object obj) {
541 if (this == obj) {
542 return true;
543 }
544 if (obj instanceof NoActionInstruction) {
545 return true;
546 }
547 return false;
548 }
549 }
550
551 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800552 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800553 */
alshabib55a55d92014-09-16 11:59:31 -0700554 public static final class OutputInstruction implements Instruction {
555 private final PortNumber port;
556
557 private OutputInstruction(PortNumber port) {
558 this.port = port;
559 }
560
561 public PortNumber port() {
562 return port;
563 }
564
565 @Override
566 public Type type() {
567 return Type.OUTPUT;
568 }
alshabib99b8fdc2014-09-25 14:30:22 -0700569 @Override
570 public String toString() {
571 return toStringHelper(type().toString())
572 .add("port", port).toString();
573 }
alshabib8ca53902014-10-07 13:11:17 -0700574
575 @Override
576 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700577 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700578 }
579
580 @Override
581 public boolean equals(Object obj) {
582 if (this == obj) {
583 return true;
584 }
585 if (obj instanceof OutputInstruction) {
586 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700587 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700588
589 }
590 return false;
591 }
alshabib55a55d92014-09-16 11:59:31 -0700592 }
593
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800594 /**
595 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800596 */
sangho8995ac52015-02-04 11:29:03 -0800597 public static final class GroupInstruction implements Instruction {
598 private final GroupId groupId;
599
600 private GroupInstruction(GroupId groupId) {
601 this.groupId = groupId;
602 }
603
604 public GroupId groupId() {
605 return groupId;
606 }
607
608 @Override
609 public Type type() {
610 return Type.GROUP;
611 }
alshabib9af70072015-02-09 14:34:16 -0800612
sangho8995ac52015-02-04 11:29:03 -0800613 @Override
614 public String toString() {
615 return toStringHelper(type().toString())
616 .add("group ID", groupId.id()).toString();
617 }
618
619 @Override
620 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700621 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800622 }
623
624 @Override
625 public boolean equals(Object obj) {
626 if (this == obj) {
627 return true;
628 }
629 if (obj instanceof GroupInstruction) {
630 GroupInstruction that = (GroupInstruction) obj;
631 return Objects.equals(groupId, that.groupId);
632
633 }
634 return false;
635 }
636 }
637
Saurav Das86af8f12015-05-25 23:55:33 -0700638 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200639 * Set-Queue Instruction.
640 */
641 public static final class SetQueueInstruction implements Instruction {
642 private final long queueId;
643
644 private SetQueueInstruction(long queueId) {
645 this.queueId = queueId;
646 }
647
648 public long queueId() {
649 return queueId;
650 }
651
652 @Override
653 public Type type() {
654 return Type.QUEUE;
655 }
656
657 @Override
658 public String toString() {
659 return toStringHelper(type().toString())
660 .add("queueId", queueId).toString();
661 }
662
663 @Override
664 public int hashCode() {
665 return Objects.hash(type().ordinal(), queueId);
666 }
667
668 @Override
669 public boolean equals(Object obj) {
670 if (this == obj) {
671 return true;
672 }
673 if (obj instanceof SetQueueInstruction) {
674 SetQueueInstruction that = (SetQueueInstruction) obj;
675 return Objects.equals(queueId, that.queueId);
676
677 }
678 return false;
679 }
680 }
681
682 /**
alshabib10c810b2015-08-18 16:59:04 -0700683 * A meter instruction.
684 */
685 public static final class MeterInstruction implements Instruction {
686 private final MeterId meterId;
687
688 private MeterInstruction(MeterId meterId) {
689 this.meterId = meterId;
690 }
691
692 public MeterId meterId() {
693 return meterId;
694 }
695
696 @Override
697 public Type type() {
698 return Type.METER;
699 }
700
701 @Override
702 public String toString() {
703 return toStringHelper(type().toString())
704 .add("meter ID", meterId.id()).toString();
705 }
706
707 @Override
708 public int hashCode() {
709 return Objects.hash(type().ordinal(), meterId);
710 }
711
712 @Override
713 public boolean equals(Object obj) {
714 if (this == obj) {
715 return true;
716 }
717 if (obj instanceof MeterInstruction) {
718 MeterInstruction that = (MeterInstruction) obj;
719 return Objects.equals(meterId, that.meterId);
720
721 }
722 return false;
723 }
724 }
725
726 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700727 * Transition instruction.
728 */
alshabibd17abc22015-04-21 18:26:35 -0700729 public static class TableTypeTransition implements Instruction {
730 private final Integer tableId;
731
732 TableTypeTransition(Integer tableId) {
733 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800734 }
735
736 @Override
737 public Type type() {
738 return Type.TABLE;
739 }
740
alshabibd17abc22015-04-21 18:26:35 -0700741 public Integer tableId() {
742 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800743 }
744
745 @Override
746 public String toString() {
747 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700748 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800749 }
750
751 @Override
752 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700753 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800754 }
755
756 @Override
757 public boolean equals(Object obj) {
758 if (this == obj) {
759 return true;
760 }
761 if (obj instanceof TableTypeTransition) {
762 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700763 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800764
765 }
766 return false;
767 }
Saurav Das86af8f12015-05-25 23:55:33 -0700768 }
alshabib9af70072015-02-09 14:34:16 -0800769
Saurav Das86af8f12015-05-25 23:55:33 -0700770 /**
771 * Metadata instruction.
772 */
773 public static class MetadataInstruction implements Instruction {
774 private final long metadata;
775 private final long metadataMask;
776
777 MetadataInstruction(long metadata, long metadataMask) {
778 this.metadata = metadata;
779 this.metadataMask = metadataMask;
780 }
781
782 @Override
783 public Type type() {
784 return Type.METADATA;
785 }
786
787 public long metadata() {
788 return this.metadata;
789 }
790
791 public long metadataMask() {
792 return this.metadataMask;
793 }
794
795 @Override
796 public String toString() {
797 return toStringHelper(type().toString())
798 .add("metadata", Long.toHexString(this.metadata))
799 .add("metadata mask", Long.toHexString(this.metadataMask))
800 .toString();
801 }
802
803 @Override
804 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700805 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700806 }
807
808 @Override
809 public boolean equals(Object obj) {
810 if (this == obj) {
811 return true;
812 }
813 if (obj instanceof MetadataInstruction) {
814 MetadataInstruction that = (MetadataInstruction) obj;
815 return Objects.equals(metadata, that.metadata) &&
816 Objects.equals(metadataMask, that.metadataMask);
817
818 }
819 return false;
820 }
alshabib9af70072015-02-09 14:34:16 -0800821 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700822
alshabib55a55d92014-09-16 11:59:31 -0700823}
alshabib8ca53902014-10-07 13:11:17 -0700824
825