blob: ee2a74fd229a3cece1a18b796274da7dabaf040f [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 */
71 public static DropInstruction createDrop() {
72 return new DropInstruction();
73 }
74
75 /**
sangho8995ac52015-02-04 11:29:03 -080076 * Creates a group instruction.
77 *
78 * @param groupId Group Id
79 * @return group instruction
80 */
81 public static GroupInstruction createGroup(final GroupId groupId) {
82 checkNotNull(groupId, "GroupId cannot be null");
83 return new GroupInstruction(groupId);
84 }
85
alshabib10c810b2015-08-18 16:59:04 -070086 public static MeterInstruction meterTraffic(final MeterId meterId) {
87 checkNotNull(meterId, "meter id cannot be null");
88 return new MeterInstruction(meterId);
89 }
90
sangho8995ac52015-02-04 11:29:03 -080091 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070092 * Creates an L0 modification with the specified OCh signal.
93 *
94 * @param lambda OCh signal
95 * @return an L0 modification
96 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070097 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070098 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070099
100 if (lambda instanceof IndexedLambda) {
101 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
102 } else if (lambda instanceof OchSignal) {
103 return new ModOchSignalInstruction((OchSignal) lambda);
104 } else {
105 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
106 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700107 }
108
109 /**
alshabib55a55d92014-09-16 11:59:31 -0700110 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800111 *
112 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700113 * @return a l2 modification
114 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700115 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700116 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700117 return new L2ModificationInstruction.ModEtherInstruction(
118 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700119 }
120
121 /**
122 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800123 *
124 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700125 * @return a L2 modification
126 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700127 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700128 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700129 return new L2ModificationInstruction.ModEtherInstruction(
130 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700131 }
132
133 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800134 * Creates a VLAN ID modification.
135 *
136 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700137 * @return a L2 modification
138 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700139 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700140 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700141 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700142 }
143
alshabib7410fea2014-09-16 13:48:39 -0700144 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800145 * Creates a VLAN PCP modification.
146 *
147 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700148 * @return a L2 modification
149 */
150 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
151 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700152 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700153 }
154
155 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800156 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800157 *
158 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800159 * @return a L2 Modification
160 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100161 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800162 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700163 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800164 }
sangho3f97a17d2015-01-29 22:56:29 -0800165
166 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700167 * Creates a MPLS BOS bit modification.
168 *
169 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
170 * @return a L2 Modification
171 */
172 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
173 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
174 }
175
176 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800177 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800178 *
179 * @return a L2 Modification
180 */
181 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700182 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800183 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800184
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800185 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800186 * Creates a L3 IPv4 src modification.
187 *
188 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700189 * @return a L3 modification
190 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700191 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800192 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
193 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700194 }
195
196 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800197 * Creates a L3 IPv4 dst modification.
198 *
199 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700200 * @return a L3 modification
201 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700202 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800203 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
204 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
205 }
206
207 /**
208 * Creates a L3 IPv6 src modification.
209 *
210 * @param addr the IPv6 address to modify to
211 * @return a L3 modification
212 */
213 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
214 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
215 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
216 }
217
218 /**
219 * Creates a L3 IPv6 dst modification.
220 *
221 * @param addr the IPv6 address to modify to
222 * @return a L3 modification
223 */
224 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
225 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
226 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
227 }
228
229 /**
230 * Creates a L3 IPv6 Flow Label modification.
231 *
232 * @param flowLabel the IPv6 flow label to modify to (20 bits)
233 * @return a L3 modification
234 */
235 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
236 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700237 }
238
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800239 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800240 * Creates a L3 decrement TTL modification.
241 *
sangho3f97a17d2015-01-29 22:56:29 -0800242 * @return a L3 modification
243 */
244 public static L3ModificationInstruction decNwTtl() {
245 return new ModTtlInstruction(L3SubType.DEC_TTL);
246 }
247
248 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800249 * Creates a L3 copy TTL to outer header modification.
250 *
sangho3f97a17d2015-01-29 22:56:29 -0800251 * @return a L3 modification
252 */
253 public static L3ModificationInstruction copyTtlOut() {
254 return new ModTtlInstruction(L3SubType.TTL_OUT);
255 }
256
257 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800258 * Creates a L3 copy TTL to inner header modification.
259 *
sangho3f97a17d2015-01-29 22:56:29 -0800260 * @return a L3 modification
261 */
262 public static L3ModificationInstruction copyTtlIn() {
263 return new ModTtlInstruction(L3SubType.TTL_IN);
264 }
265
266 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800267 * Creates a push MPLS header instruction.
268 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800269 * @return a L2 modification.
270 */
271 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700272 return new L2ModificationInstruction.PushHeaderInstructions(
273 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700274 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800275 }
276
277 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800278 * Creates a pop MPLS header instruction.
279 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800280 * @return a L2 modification.
281 */
282 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700283 return new L2ModificationInstruction.PushHeaderInstructions(
284 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700285 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800286 }
alshabib7410fea2014-09-16 13:48:39 -0700287
sangho3f97a17d2015-01-29 22:56:29 -0800288 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800289 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800290 *
291 * @param etherType Ethernet type to set
292 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700293 */
294 public static Instruction popMpls(EthType etherType) {
295 checkNotNull(etherType, "Ethernet type cannot be null");
296 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700297 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800298 }
299
Saurav Dasfbe25c52015-03-04 11:12:00 -0800300 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800301 * Creates a pop VLAN header instruction.
302 *
303 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800304 */
305 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700306 return new L2ModificationInstruction.PopVlanInstruction(
307 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800308 }
309
310 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800311 * Creates a push VLAN header instruction.
312 *
313 * @return a L2 modification
314 */
315 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700316 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700317 L2ModificationInstruction.L2SubType.VLAN_PUSH,
318 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800319 }
320
321 /**
alshabibd17abc22015-04-21 18:26:35 -0700322 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800323 *
alshabibd17abc22015-04-21 18:26:35 -0700324 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800325 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800326 */
alshabibd17abc22015-04-21 18:26:35 -0700327 public static Instruction transition(Integer tableId) {
328 checkNotNull(tableId, "Table id cannot be null");
329 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800330 }
331
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800332 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700333 * Writes metadata to associate with a packet.
334 *
335 * @param metadata the metadata value to write
336 * @param metadataMask the bits to mask for the metadata value
337 * @return metadata instruction
338 */
339 public static Instruction writeMetadata(long metadata, long metadataMask) {
340 return new MetadataInstruction(metadata, metadataMask);
341 }
342
343 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700344 * Creates a Tunnel ID modification.
345 *
346 * @param tunnelId the Tunnel ID to modify to
347 * @return a L2 modification
348 */
349 public static L2ModificationInstruction modTunnelId(long tunnelId) {
350 checkNotNull(tunnelId, "Tunnel id cannot be null");
351 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
352 }
353
354 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700355 * Creates a TCP src modification.
356 *
357 * @param port the TCP port number to modify to
358 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700359 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700360 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700361 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700362 public static L4ModificationInstruction modTcpSrc(short port) {
363 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700364 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
365 }
366
367 /**
368 * Creates a TCP src modification.
369 *
370 * @param port the TCP port number to modify to
371 * @return a L4 modification
372 */
373 public static L4ModificationInstruction modTcpSrc(TpPort port) {
374 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700375 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
376 }
377
378 /**
379 * Creates a TCP dst modification.
380 *
381 * @param port the TCP port number to modify to
382 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700383 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700384 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700385 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700386 public static L4ModificationInstruction modTcpDst(short port) {
387 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700388 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
389 }
390
391 /**
392 * Creates a TCP dst modification.
393 *
394 * @param port the TCP port number to modify to
395 * @return a L4 modification
396 */
397 public static L4ModificationInstruction modTcpDst(TpPort port) {
398 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700399 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
400 }
401
402 /**
403 * Creates a UDP src modification.
404 *
405 * @param port the UDP port number to modify to
406 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700407 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700408 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700409 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700410 public static L4ModificationInstruction modUdpSrc(short port) {
411 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700412 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
413 }
414
415 /**
416 * Creates a UDP src modification.
417 *
418 * @param port the UDP port number to modify to
419 * @return a L4 modification
420 */
421 public static L4ModificationInstruction modUdpSrc(TpPort port) {
422 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700423 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
424 }
425
426 /**
427 * Creates a UDP dst modification.
428 *
429 * @param port the UDP port number to modify to
430 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700431 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700432 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700433 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700434 public static L4ModificationInstruction modUdpDst(short port) {
435 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700436 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
437 }
438
439 /**
440 * Creates a UDP dst modification.
441 *
442 * @param port the UDP port number to modify to
443 * @return a L4 modification
444 */
445 public static L4ModificationInstruction modUdpDst(TpPort port) {
446 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700447 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
448 }
449
450 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800451 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700452 */
alshabib55a55d92014-09-16 11:59:31 -0700453 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800454
455 private DropInstruction() {}
456
alshabib55a55d92014-09-16 11:59:31 -0700457 @Override
458 public Type type() {
459 return Type.DROP;
460 }
alshabib99b8fdc2014-09-25 14:30:22 -0700461
462 @Override
463 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800464 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700465 }
alshabib8ca53902014-10-07 13:11:17 -0700466
467 @Override
468 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700469 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700470 }
471
472 @Override
473 public boolean equals(Object obj) {
474 if (this == obj) {
475 return true;
476 }
477 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800478 return true;
alshabib8ca53902014-10-07 13:11:17 -0700479 }
480 return false;
481 }
alshabib55a55d92014-09-16 11:59:31 -0700482 }
483
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800484 /**
485 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800486 */
alshabib55a55d92014-09-16 11:59:31 -0700487 public static final class OutputInstruction implements Instruction {
488 private final PortNumber port;
489
490 private OutputInstruction(PortNumber port) {
491 this.port = port;
492 }
493
494 public PortNumber port() {
495 return port;
496 }
497
498 @Override
499 public Type type() {
500 return Type.OUTPUT;
501 }
alshabib99b8fdc2014-09-25 14:30:22 -0700502 @Override
503 public String toString() {
504 return toStringHelper(type().toString())
505 .add("port", port).toString();
506 }
alshabib8ca53902014-10-07 13:11:17 -0700507
508 @Override
509 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700510 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700511 }
512
513 @Override
514 public boolean equals(Object obj) {
515 if (this == obj) {
516 return true;
517 }
518 if (obj instanceof OutputInstruction) {
519 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700520 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700521
522 }
523 return false;
524 }
alshabib55a55d92014-09-16 11:59:31 -0700525 }
526
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800527 /**
528 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800529 */
sangho8995ac52015-02-04 11:29:03 -0800530 public static final class GroupInstruction implements Instruction {
531 private final GroupId groupId;
532
533 private GroupInstruction(GroupId groupId) {
534 this.groupId = groupId;
535 }
536
537 public GroupId groupId() {
538 return groupId;
539 }
540
541 @Override
542 public Type type() {
543 return Type.GROUP;
544 }
alshabib9af70072015-02-09 14:34:16 -0800545
sangho8995ac52015-02-04 11:29:03 -0800546 @Override
547 public String toString() {
548 return toStringHelper(type().toString())
549 .add("group ID", groupId.id()).toString();
550 }
551
552 @Override
553 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700554 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800555 }
556
557 @Override
558 public boolean equals(Object obj) {
559 if (this == obj) {
560 return true;
561 }
562 if (obj instanceof GroupInstruction) {
563 GroupInstruction that = (GroupInstruction) obj;
564 return Objects.equals(groupId, that.groupId);
565
566 }
567 return false;
568 }
569 }
570
Saurav Das86af8f12015-05-25 23:55:33 -0700571 /**
alshabib10c810b2015-08-18 16:59:04 -0700572 * A meter instruction.
573 */
574 public static final class MeterInstruction implements Instruction {
575 private final MeterId meterId;
576
577 private MeterInstruction(MeterId meterId) {
578 this.meterId = meterId;
579 }
580
581 public MeterId meterId() {
582 return meterId;
583 }
584
585 @Override
586 public Type type() {
587 return Type.METER;
588 }
589
590 @Override
591 public String toString() {
592 return toStringHelper(type().toString())
593 .add("meter ID", meterId.id()).toString();
594 }
595
596 @Override
597 public int hashCode() {
598 return Objects.hash(type().ordinal(), meterId);
599 }
600
601 @Override
602 public boolean equals(Object obj) {
603 if (this == obj) {
604 return true;
605 }
606 if (obj instanceof MeterInstruction) {
607 MeterInstruction that = (MeterInstruction) obj;
608 return Objects.equals(meterId, that.meterId);
609
610 }
611 return false;
612 }
613 }
614
615 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700616 * Transition instruction.
617 */
alshabibd17abc22015-04-21 18:26:35 -0700618 public static class TableTypeTransition implements Instruction {
619 private final Integer tableId;
620
621 TableTypeTransition(Integer tableId) {
622 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800623 }
624
625 @Override
626 public Type type() {
627 return Type.TABLE;
628 }
629
alshabibd17abc22015-04-21 18:26:35 -0700630 public Integer tableId() {
631 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800632 }
633
634 @Override
635 public String toString() {
636 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700637 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800638 }
639
640 @Override
641 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700642 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800643 }
644
645 @Override
646 public boolean equals(Object obj) {
647 if (this == obj) {
648 return true;
649 }
650 if (obj instanceof TableTypeTransition) {
651 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700652 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800653
654 }
655 return false;
656 }
Saurav Das86af8f12015-05-25 23:55:33 -0700657 }
alshabib9af70072015-02-09 14:34:16 -0800658
Saurav Das86af8f12015-05-25 23:55:33 -0700659 /**
660 * Metadata instruction.
661 */
662 public static class MetadataInstruction implements Instruction {
663 private final long metadata;
664 private final long metadataMask;
665
666 MetadataInstruction(long metadata, long metadataMask) {
667 this.metadata = metadata;
668 this.metadataMask = metadataMask;
669 }
670
671 @Override
672 public Type type() {
673 return Type.METADATA;
674 }
675
676 public long metadata() {
677 return this.metadata;
678 }
679
680 public long metadataMask() {
681 return this.metadataMask;
682 }
683
684 @Override
685 public String toString() {
686 return toStringHelper(type().toString())
687 .add("metadata", Long.toHexString(this.metadata))
688 .add("metadata mask", Long.toHexString(this.metadataMask))
689 .toString();
690 }
691
692 @Override
693 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700694 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700695 }
696
697 @Override
698 public boolean equals(Object obj) {
699 if (this == obj) {
700 return true;
701 }
702 if (obj instanceof MetadataInstruction) {
703 MetadataInstruction that = (MetadataInstruction) obj;
704 return Objects.equals(metadata, that.metadata) &&
705 Objects.equals(metadataMask, that.metadataMask);
706
707 }
708 return false;
709 }
alshabib9af70072015-02-09 14:34:16 -0800710 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700711
alshabib55a55d92014-09-16 11:59:31 -0700712}
alshabib8ca53902014-10-07 13:11:17 -0700713
714