blob: 4e5d39aba0a06f646fc43bb43bf47426e8c16530 [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
Steffen Gebertba2d3b72015-10-22 11:14:31 +020018import com.google.common.base.MoreObjects;
alshabib7b808c52015-06-26 14:22:24 -070019import org.onlab.packet.EthType;
Jonathan Hart54b406b2015-03-06 16:24:14 -080020import org.onlab.packet.IpAddress;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070023import org.onlab.packet.TpPort;
Jonathan Hart54b406b2015-03-06 16:24:14 -080024import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080025import org.onosproject.core.GroupId;
Jonathan Hart3c259162015-10-21 21:31:19 -070026import org.onosproject.net.DeviceId;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070027import org.onosproject.net.IndexedLambda;
28import org.onosproject.net.Lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070029import org.onosproject.net.OchSignal;
Yafit Hadar52d81552015-10-07 12:26:52 +030030import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.PortNumber;
32import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
33import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070034import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Yafit Hadar52d81552015-10-07 12:26:52 +030035import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
37import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080038import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
sangho3f97a17d2015-01-29 22:56:29 -080039import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070040import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
41import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
alshabib10c810b2015-08-18 16:59:04 -070042import org.onosproject.net.meter.MeterId;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080043
Jonathan Hart54b406b2015-03-06 16:24:14 -080044import java.util.Objects;
45
46import static com.google.common.base.MoreObjects.toStringHelper;
47import static com.google.common.base.Preconditions.checkNotNull;
alshabib64231f62014-09-16 17:58:36 -070048
alshabib55a55d92014-09-16 11:59:31 -070049/**
50 * Factory class for creating various traffic treatment instructions.
51 */
52public final class Instructions {
53
alshabib55a55d92014-09-16 11:59:31 -070054 // Ban construction
55 private Instructions() {}
56
57 /**
58 * Creates an output instruction using the specified port number. This can
59 * include logical ports such as CONTROLLER, FLOOD, etc.
60 *
61 * @param number port number
62 * @return output instruction
63 */
64 public static OutputInstruction createOutput(final PortNumber number) {
65 checkNotNull(number, "PortNumber cannot be null");
66 return new OutputInstruction(number);
67 }
68
69 /**
70 * Creates a drop instruction.
Jonathan Hart54b406b2015-03-06 16:24:14 -080071 *
alshabib55a55d92014-09-16 11:59:31 -070072 * @return drop instruction
73 */
Charles Chan7efabeb2015-09-28 15:12:19 -070074 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -070075 public static DropInstruction createDrop() {
76 return new DropInstruction();
77 }
78
79 /**
Charles Chan7efabeb2015-09-28 15:12:19 -070080 * Creates a no action instruction.
81 *
82 * @return no action instruction
83 */
84 public static NoActionInstruction createNoAction() {
85 return new NoActionInstruction();
86 }
87
88 /**
sangho8995ac52015-02-04 11:29:03 -080089 * Creates a group instruction.
90 *
91 * @param groupId Group Id
92 * @return group instruction
93 */
94 public static GroupInstruction createGroup(final GroupId groupId) {
95 checkNotNull(groupId, "GroupId cannot be null");
96 return new GroupInstruction(groupId);
97 }
98
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +020099 /**
100 * Creates a set-queue instruction.
101 *
102 * @param queueId Queue Id
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200103 * @param port Port number
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200104 * @return set-queue instruction
105 */
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200106 public static SetQueueInstruction setQueue(final long queueId, final PortNumber port) {
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200107 checkNotNull(queueId, "queue ID cannot be null");
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200108 return new SetQueueInstruction(queueId, port);
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200109 }
110
alshabib10c810b2015-08-18 16:59:04 -0700111 public static MeterInstruction meterTraffic(final MeterId meterId) {
112 checkNotNull(meterId, "meter id cannot be null");
113 return new MeterInstruction(meterId);
114 }
115
sangho8995ac52015-02-04 11:29:03 -0800116 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700117 * Creates an L0 modification with the specified OCh signal.
118 *
119 * @param lambda OCh signal
120 * @return an L0 modification
121 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700122 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700123 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700124
125 if (lambda instanceof IndexedLambda) {
126 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
127 } else if (lambda instanceof OchSignal) {
128 return new ModOchSignalInstruction((OchSignal) lambda);
129 } else {
130 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
131 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700132 }
133
134 /**
Yafit Hadar52d81552015-10-07 12:26:52 +0300135 * Creates an L1 modification with the specified ODU signal Id.
136 *
137 * @param oduSignalId ODU Signal Id
138 * @return a L1 modification
139 */
140 public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
141 checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
142 return new ModOduSignalIdInstruction(oduSignalId);
143 }
144 /**
alshabib55a55d92014-09-16 11:59:31 -0700145 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800146 *
147 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700148 * @return a l2 modification
149 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700150 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700151 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700152 return new L2ModificationInstruction.ModEtherInstruction(
153 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700154 }
155
156 /**
157 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800158 *
159 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700160 * @return a L2 modification
161 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700162 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700163 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700164 return new L2ModificationInstruction.ModEtherInstruction(
165 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700166 }
167
168 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800169 * Creates a VLAN ID modification.
170 *
171 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700172 * @return a L2 modification
173 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700174 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700175 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700176 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700177 }
178
alshabib7410fea2014-09-16 13:48:39 -0700179 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800180 * Creates a VLAN PCP modification.
181 *
182 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700183 * @return a L2 modification
184 */
185 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
186 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700187 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700188 }
189
190 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800191 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800192 *
193 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800194 * @return a L2 Modification
195 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100196 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800197 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700198 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800199 }
sangho3f97a17d2015-01-29 22:56:29 -0800200
201 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700202 * Creates a MPLS BOS bit modification.
203 *
204 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
205 * @return a L2 Modification
206 */
207 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
208 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
209 }
210
211 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800212 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800213 *
214 * @return a L2 Modification
215 */
216 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700217 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800218 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800219
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800220 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800221 * Creates a L3 IPv4 src modification.
222 *
223 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700224 * @return a L3 modification
225 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700226 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800227 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
228 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700229 }
230
231 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800232 * Creates a L3 IPv4 dst modification.
233 *
234 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700235 * @return a L3 modification
236 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700237 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800238 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
239 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
240 }
241
242 /**
243 * Creates a L3 IPv6 src modification.
244 *
245 * @param addr the IPv6 address to modify to
246 * @return a L3 modification
247 */
248 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
249 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
250 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
251 }
252
253 /**
254 * Creates a L3 IPv6 dst modification.
255 *
256 * @param addr the IPv6 address to modify to
257 * @return a L3 modification
258 */
259 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
260 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
261 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
262 }
263
264 /**
265 * Creates a L3 IPv6 Flow Label modification.
266 *
267 * @param flowLabel the IPv6 flow label to modify to (20 bits)
268 * @return a L3 modification
269 */
270 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
271 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700272 }
273
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800274 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800275 * Creates a L3 decrement TTL modification.
276 *
sangho3f97a17d2015-01-29 22:56:29 -0800277 * @return a L3 modification
278 */
279 public static L3ModificationInstruction decNwTtl() {
280 return new ModTtlInstruction(L3SubType.DEC_TTL);
281 }
282
283 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800284 * Creates a L3 copy TTL to outer header modification.
285 *
sangho3f97a17d2015-01-29 22:56:29 -0800286 * @return a L3 modification
287 */
288 public static L3ModificationInstruction copyTtlOut() {
289 return new ModTtlInstruction(L3SubType.TTL_OUT);
290 }
291
292 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800293 * Creates a L3 copy TTL to inner header modification.
294 *
sangho3f97a17d2015-01-29 22:56:29 -0800295 * @return a L3 modification
296 */
297 public static L3ModificationInstruction copyTtlIn() {
298 return new ModTtlInstruction(L3SubType.TTL_IN);
299 }
300
301 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800302 * Creates a push MPLS header instruction.
303 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800304 * @return a L2 modification.
305 */
306 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700307 return new L2ModificationInstruction.PushHeaderInstructions(
308 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700309 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800310 }
311
312 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800313 * Creates a pop MPLS header instruction.
314 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800315 * @return a L2 modification.
316 */
317 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700318 return new L2ModificationInstruction.PushHeaderInstructions(
319 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700320 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800321 }
alshabib7410fea2014-09-16 13:48:39 -0700322
sangho3f97a17d2015-01-29 22:56:29 -0800323 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800324 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800325 *
326 * @param etherType Ethernet type to set
327 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700328 */
329 public static Instruction popMpls(EthType etherType) {
330 checkNotNull(etherType, "Ethernet type cannot be null");
331 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700332 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800333 }
334
Saurav Dasfbe25c52015-03-04 11:12:00 -0800335 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800336 * Creates a pop VLAN header instruction.
337 *
338 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800339 */
340 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700341 return new L2ModificationInstruction.PopVlanInstruction(
342 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800343 }
344
345 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800346 * Creates a push VLAN header instruction.
347 *
348 * @return a L2 modification
349 */
350 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700351 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700352 L2ModificationInstruction.L2SubType.VLAN_PUSH,
353 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800354 }
355
356 /**
alshabibd17abc22015-04-21 18:26:35 -0700357 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800358 *
alshabibd17abc22015-04-21 18:26:35 -0700359 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800360 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800361 */
alshabibd17abc22015-04-21 18:26:35 -0700362 public static Instruction transition(Integer tableId) {
363 checkNotNull(tableId, "Table id cannot be null");
364 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800365 }
366
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800367 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700368 * Writes metadata to associate with a packet.
369 *
370 * @param metadata the metadata value to write
371 * @param metadataMask the bits to mask for the metadata value
372 * @return metadata instruction
373 */
374 public static Instruction writeMetadata(long metadata, long metadataMask) {
375 return new MetadataInstruction(metadata, metadataMask);
376 }
377
378 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700379 * Creates a Tunnel ID modification.
380 *
381 * @param tunnelId the Tunnel ID to modify to
382 * @return a L2 modification
383 */
384 public static L2ModificationInstruction modTunnelId(long tunnelId) {
385 checkNotNull(tunnelId, "Tunnel id cannot be null");
386 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
387 }
388
389 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700390 * Creates a TCP src modification.
391 *
392 * @param port the TCP port number to modify to
393 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700394 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700395 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700396 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700397 public static L4ModificationInstruction modTcpSrc(short port) {
398 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700399 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
400 }
401
402 /**
403 * Creates a TCP src modification.
404 *
405 * @param port the TCP port number to modify to
406 * @return a L4 modification
407 */
408 public static L4ModificationInstruction modTcpSrc(TpPort port) {
409 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700410 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
411 }
412
413 /**
414 * Creates a TCP dst modification.
415 *
416 * @param port the TCP port number to modify to
417 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700418 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700419 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700420 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700421 public static L4ModificationInstruction modTcpDst(short port) {
422 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700423 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
424 }
425
426 /**
427 * Creates a TCP dst modification.
428 *
429 * @param port the TCP port number to modify to
430 * @return a L4 modification
431 */
432 public static L4ModificationInstruction modTcpDst(TpPort port) {
433 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700434 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
435 }
436
437 /**
438 * Creates a UDP src modification.
439 *
440 * @param port the UDP port number to modify to
441 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700442 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700443 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700444 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700445 public static L4ModificationInstruction modUdpSrc(short port) {
446 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700447 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
448 }
449
450 /**
451 * Creates a UDP src modification.
452 *
453 * @param port the UDP port number to modify to
454 * @return a L4 modification
455 */
456 public static L4ModificationInstruction modUdpSrc(TpPort port) {
457 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700458 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
459 }
460
461 /**
462 * Creates a UDP dst modification.
463 *
464 * @param port the UDP port number to modify to
465 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700466 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700467 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700468 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700469 public static L4ModificationInstruction modUdpDst(short port) {
470 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700471 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
472 }
473
474 /**
475 * Creates a UDP dst modification.
476 *
477 * @param port the UDP port number to modify to
478 * @return a L4 modification
479 */
480 public static L4ModificationInstruction modUdpDst(TpPort port) {
481 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700482 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
483 }
484
485 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700486 * Creates an extension instruction.
487 *
488 * @param extension extension instruction
489 * @param deviceId device ID
490 * @return extension instruction
491 */
492 public static ExtensionInstructionWrapper extension(ExtensionInstruction extension,
493 DeviceId deviceId) {
494 checkNotNull(extension, "Extension instruction cannot be null");
495 checkNotNull(deviceId, "Device ID cannot be null");
496 return new ExtensionInstructionWrapper(extension, deviceId);
497 }
498
499 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800500 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700501 */
Charles Chan7efabeb2015-09-28 15:12:19 -0700502 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -0700503 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800504
505 private DropInstruction() {}
506
alshabib55a55d92014-09-16 11:59:31 -0700507 @Override
508 public Type type() {
509 return Type.DROP;
510 }
alshabib99b8fdc2014-09-25 14:30:22 -0700511
512 @Override
513 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800514 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700515 }
alshabib8ca53902014-10-07 13:11:17 -0700516
517 @Override
518 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700519 return type().ordinal();
alshabib8ca53902014-10-07 13:11:17 -0700520 }
521
522 @Override
523 public boolean equals(Object obj) {
524 if (this == obj) {
525 return true;
526 }
527 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800528 return true;
alshabib8ca53902014-10-07 13:11:17 -0700529 }
530 return false;
531 }
alshabib55a55d92014-09-16 11:59:31 -0700532 }
533
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800534 /**
Charles Chan7efabeb2015-09-28 15:12:19 -0700535 * No Action instruction.
536 */
537 public static final class NoActionInstruction implements Instruction {
538
539 private NoActionInstruction() {}
540
541 @Override
542 public Type type() {
543 return Type.NOACTION;
544 }
545
546 @Override
547 public String toString() {
548 return toStringHelper(type().toString()).toString();
549 }
550
551 @Override
552 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -0700553 return type().ordinal();
Charles Chan7efabeb2015-09-28 15:12:19 -0700554 }
555
556 @Override
557 public boolean equals(Object obj) {
558 if (this == obj) {
559 return true;
560 }
561 if (obj instanceof NoActionInstruction) {
562 return true;
563 }
564 return false;
565 }
566 }
567
568 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800569 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800570 */
alshabib55a55d92014-09-16 11:59:31 -0700571 public static final class OutputInstruction implements Instruction {
572 private final PortNumber port;
573
574 private OutputInstruction(PortNumber port) {
575 this.port = port;
576 }
577
578 public PortNumber port() {
579 return port;
580 }
581
582 @Override
583 public Type type() {
584 return Type.OUTPUT;
585 }
alshabib99b8fdc2014-09-25 14:30:22 -0700586 @Override
587 public String toString() {
588 return toStringHelper(type().toString())
589 .add("port", port).toString();
590 }
alshabib8ca53902014-10-07 13:11:17 -0700591
592 @Override
593 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700594 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700595 }
596
597 @Override
598 public boolean equals(Object obj) {
599 if (this == obj) {
600 return true;
601 }
602 if (obj instanceof OutputInstruction) {
603 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700604 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700605
606 }
607 return false;
608 }
alshabib55a55d92014-09-16 11:59:31 -0700609 }
610
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800611 /**
612 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800613 */
sangho8995ac52015-02-04 11:29:03 -0800614 public static final class GroupInstruction implements Instruction {
615 private final GroupId groupId;
616
617 private GroupInstruction(GroupId groupId) {
618 this.groupId = groupId;
619 }
620
621 public GroupId groupId() {
622 return groupId;
623 }
624
625 @Override
626 public Type type() {
627 return Type.GROUP;
628 }
alshabib9af70072015-02-09 14:34:16 -0800629
sangho8995ac52015-02-04 11:29:03 -0800630 @Override
631 public String toString() {
632 return toStringHelper(type().toString())
633 .add("group ID", groupId.id()).toString();
634 }
635
636 @Override
637 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700638 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800639 }
640
641 @Override
642 public boolean equals(Object obj) {
643 if (this == obj) {
644 return true;
645 }
646 if (obj instanceof GroupInstruction) {
647 GroupInstruction that = (GroupInstruction) obj;
648 return Objects.equals(groupId, that.groupId);
649
650 }
651 return false;
652 }
653 }
654
Saurav Das86af8f12015-05-25 23:55:33 -0700655 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200656 * Set-Queue Instruction.
657 */
658 public static final class SetQueueInstruction implements Instruction {
659 private final long queueId;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200660 private final PortNumber port;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200661
662 private SetQueueInstruction(long queueId) {
663 this.queueId = queueId;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200664 this.port = null;
665 }
666
667 private SetQueueInstruction(long queueId, PortNumber port) {
668 this.queueId = queueId;
669 this.port = port;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200670 }
671
672 public long queueId() {
673 return queueId;
674 }
675
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200676 public PortNumber port() {
677 return port;
678 }
679
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200680 @Override
681 public Type type() {
682 return Type.QUEUE;
683 }
684
685 @Override
686 public String toString() {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200687 MoreObjects.ToStringHelper toStringHelper = toStringHelper(type().toString());
688 toStringHelper.add("queueId", queueId);
689
690 if (port() != null) {
691 toStringHelper.add("port", port);
692 }
693 return toStringHelper.toString();
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200694 }
695
696 @Override
697 public int hashCode() {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200698 return Objects.hash(type().ordinal(), queueId, port);
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200699 }
700
701 @Override
702 public boolean equals(Object obj) {
703 if (this == obj) {
704 return true;
705 }
706 if (obj instanceof SetQueueInstruction) {
707 SetQueueInstruction that = (SetQueueInstruction) obj;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200708 return Objects.equals(queueId, that.queueId) && Objects.equals(port, that.port);
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200709
710 }
711 return false;
712 }
713 }
714
715 /**
alshabib10c810b2015-08-18 16:59:04 -0700716 * A meter instruction.
717 */
718 public static final class MeterInstruction implements Instruction {
719 private final MeterId meterId;
720
721 private MeterInstruction(MeterId meterId) {
722 this.meterId = meterId;
723 }
724
725 public MeterId meterId() {
726 return meterId;
727 }
728
729 @Override
730 public Type type() {
731 return Type.METER;
732 }
733
734 @Override
735 public String toString() {
736 return toStringHelper(type().toString())
737 .add("meter ID", meterId.id()).toString();
738 }
739
740 @Override
741 public int hashCode() {
742 return Objects.hash(type().ordinal(), meterId);
743 }
744
745 @Override
746 public boolean equals(Object obj) {
747 if (this == obj) {
748 return true;
749 }
750 if (obj instanceof MeterInstruction) {
751 MeterInstruction that = (MeterInstruction) obj;
752 return Objects.equals(meterId, that.meterId);
753
754 }
755 return false;
756 }
757 }
758
759 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700760 * Transition instruction.
761 */
alshabibd17abc22015-04-21 18:26:35 -0700762 public static class TableTypeTransition implements Instruction {
763 private final Integer tableId;
764
765 TableTypeTransition(Integer tableId) {
766 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800767 }
768
769 @Override
770 public Type type() {
771 return Type.TABLE;
772 }
773
alshabibd17abc22015-04-21 18:26:35 -0700774 public Integer tableId() {
775 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800776 }
777
778 @Override
779 public String toString() {
780 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700781 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800782 }
783
784 @Override
785 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700786 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800787 }
788
789 @Override
790 public boolean equals(Object obj) {
791 if (this == obj) {
792 return true;
793 }
794 if (obj instanceof TableTypeTransition) {
795 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700796 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800797
798 }
799 return false;
800 }
Saurav Das86af8f12015-05-25 23:55:33 -0700801 }
alshabib9af70072015-02-09 14:34:16 -0800802
Saurav Das86af8f12015-05-25 23:55:33 -0700803 /**
804 * Metadata instruction.
805 */
806 public static class MetadataInstruction implements Instruction {
807 private final long metadata;
808 private final long metadataMask;
809
810 MetadataInstruction(long metadata, long metadataMask) {
811 this.metadata = metadata;
812 this.metadataMask = metadataMask;
813 }
814
815 @Override
816 public Type type() {
817 return Type.METADATA;
818 }
819
820 public long metadata() {
821 return this.metadata;
822 }
823
824 public long metadataMask() {
825 return this.metadataMask;
826 }
827
828 @Override
829 public String toString() {
830 return toStringHelper(type().toString())
831 .add("metadata", Long.toHexString(this.metadata))
832 .add("metadata mask", Long.toHexString(this.metadataMask))
833 .toString();
834 }
835
836 @Override
837 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700838 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700839 }
840
841 @Override
842 public boolean equals(Object obj) {
843 if (this == obj) {
844 return true;
845 }
846 if (obj instanceof MetadataInstruction) {
847 MetadataInstruction that = (MetadataInstruction) obj;
848 return Objects.equals(metadata, that.metadata) &&
849 Objects.equals(metadataMask, that.metadataMask);
850
851 }
852 return false;
853 }
alshabib9af70072015-02-09 14:34:16 -0800854 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700855
Jonathan Hart3c259162015-10-21 21:31:19 -0700856 /**
857 * Extension instruction.
858 */
859 public static class ExtensionInstructionWrapper implements Instruction {
860 private final ExtensionInstruction extensionInstruction;
861 private final DeviceId deviceId;
862
863 ExtensionInstructionWrapper(ExtensionInstruction extension, DeviceId deviceId) {
864 extensionInstruction = extension;
865 this.deviceId = deviceId;
866 }
867
868 public ExtensionInstruction extensionInstruction() {
869 return extensionInstruction;
870 }
871
872 public DeviceId deviceId() {
873 return deviceId;
874 }
875
876 @Override
877 public Type type() {
878 return Type.EXTENSION;
879 }
880
881 @Override
882 public String toString() {
883 return toStringHelper(type().toString())
884 .add("extension", extensionInstruction)
885 .add("deviceId", deviceId)
886 .toString();
887 }
888
889 @Override
890 public int hashCode() {
891 return Objects.hash(type().ordinal(), extensionInstruction, deviceId);
892 }
893
894 @Override
895 public boolean equals(Object obj) {
896 if (this == obj) {
897 return true;
898 }
899 if (obj instanceof ExtensionInstructionWrapper) {
900 ExtensionInstructionWrapper that = (ExtensionInstructionWrapper) obj;
901 return Objects.equals(extensionInstruction, that.extensionInstruction)
902 && Objects.equals(deviceId, that.deviceId);
903
904 }
905 return false;
906 }
907 }
908
alshabib55a55d92014-09-16 11:59:31 -0700909}
alshabib8ca53902014-10-07 13:11:17 -0700910
911