blob: 26981e5e6872e19dfcba2643a9c5394f8321a979 [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
alshabib10c810b2015-08-18 16:59:04 -070097 public static MeterInstruction meterTraffic(final MeterId meterId) {
98 checkNotNull(meterId, "meter id cannot be null");
99 return new MeterInstruction(meterId);
100 }
101
sangho8995ac52015-02-04 11:29:03 -0800102 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700103 * Creates an L0 modification with the specified OCh signal.
104 *
105 * @param lambda OCh signal
106 * @return an L0 modification
107 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700108 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700109 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700110
111 if (lambda instanceof IndexedLambda) {
112 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
113 } else if (lambda instanceof OchSignal) {
114 return new ModOchSignalInstruction((OchSignal) lambda);
115 } else {
116 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
117 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700118 }
119
120 /**
Yafit Hadar52d81552015-10-07 12:26:52 +0300121 * Creates an L1 modification with the specified ODU signal Id.
122 *
123 * @param oduSignalId ODU Signal Id
124 * @return a L1 modification
125 */
126 public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
127 checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
128 return new ModOduSignalIdInstruction(oduSignalId);
129 }
130 /**
alshabib55a55d92014-09-16 11:59:31 -0700131 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800132 *
133 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700134 * @return a l2 modification
135 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700136 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700137 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700138 return new L2ModificationInstruction.ModEtherInstruction(
139 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700140 }
141
142 /**
143 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800144 *
145 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700146 * @return a L2 modification
147 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700148 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700149 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700150 return new L2ModificationInstruction.ModEtherInstruction(
151 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700152 }
153
154 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800155 * Creates a VLAN ID modification.
156 *
157 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700158 * @return a L2 modification
159 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700160 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700161 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700162 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700163 }
164
alshabib7410fea2014-09-16 13:48:39 -0700165 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800166 * Creates a VLAN PCP modification.
167 *
168 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700169 * @return a L2 modification
170 */
171 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
172 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700173 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700174 }
175
176 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800177 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800178 *
179 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800180 * @return a L2 Modification
181 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100182 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800183 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700184 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800185 }
sangho3f97a17d2015-01-29 22:56:29 -0800186
187 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700188 * Creates a MPLS BOS bit modification.
189 *
190 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
191 * @return a L2 Modification
192 */
193 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
194 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
195 }
196
197 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800198 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800199 *
200 * @return a L2 Modification
201 */
202 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700203 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800204 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800205
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800206 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800207 * Creates a L3 IPv4 src modification.
208 *
209 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700210 * @return a L3 modification
211 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700212 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800213 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
214 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700215 }
216
217 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800218 * Creates a L3 IPv4 dst 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 modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800224 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
225 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
226 }
227
228 /**
229 * Creates a L3 IPv6 src modification.
230 *
231 * @param addr the IPv6 address to modify to
232 * @return a L3 modification
233 */
234 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
235 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
236 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
237 }
238
239 /**
240 * Creates a L3 IPv6 dst modification.
241 *
242 * @param addr the IPv6 address to modify to
243 * @return a L3 modification
244 */
245 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
246 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
247 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
248 }
249
250 /**
251 * Creates a L3 IPv6 Flow Label modification.
252 *
253 * @param flowLabel the IPv6 flow label to modify to (20 bits)
254 * @return a L3 modification
255 */
256 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
257 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700258 }
259
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800260 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800261 * Creates a L3 decrement TTL modification.
262 *
sangho3f97a17d2015-01-29 22:56:29 -0800263 * @return a L3 modification
264 */
265 public static L3ModificationInstruction decNwTtl() {
266 return new ModTtlInstruction(L3SubType.DEC_TTL);
267 }
268
269 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800270 * Creates a L3 copy TTL to outer header modification.
271 *
sangho3f97a17d2015-01-29 22:56:29 -0800272 * @return a L3 modification
273 */
274 public static L3ModificationInstruction copyTtlOut() {
275 return new ModTtlInstruction(L3SubType.TTL_OUT);
276 }
277
278 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800279 * Creates a L3 copy TTL to inner header modification.
280 *
sangho3f97a17d2015-01-29 22:56:29 -0800281 * @return a L3 modification
282 */
283 public static L3ModificationInstruction copyTtlIn() {
284 return new ModTtlInstruction(L3SubType.TTL_IN);
285 }
286
287 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800288 * Creates a push MPLS header instruction.
289 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800290 * @return a L2 modification.
291 */
292 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700293 return new L2ModificationInstruction.PushHeaderInstructions(
294 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700295 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800296 }
297
298 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800299 * Creates a pop MPLS header instruction.
300 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800301 * @return a L2 modification.
302 */
303 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700304 return new L2ModificationInstruction.PushHeaderInstructions(
305 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700306 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800307 }
alshabib7410fea2014-09-16 13:48:39 -0700308
sangho3f97a17d2015-01-29 22:56:29 -0800309 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800310 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800311 *
312 * @param etherType Ethernet type to set
313 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700314 */
315 public static Instruction popMpls(EthType etherType) {
316 checkNotNull(etherType, "Ethernet type cannot be null");
317 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700318 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800319 }
320
Saurav Dasfbe25c52015-03-04 11:12:00 -0800321 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800322 * Creates a pop VLAN header instruction.
323 *
324 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800325 */
326 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700327 return new L2ModificationInstruction.PopVlanInstruction(
328 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800329 }
330
331 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800332 * Creates a push VLAN header instruction.
333 *
334 * @return a L2 modification
335 */
336 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700337 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700338 L2ModificationInstruction.L2SubType.VLAN_PUSH,
339 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800340 }
341
342 /**
alshabibd17abc22015-04-21 18:26:35 -0700343 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800344 *
alshabibd17abc22015-04-21 18:26:35 -0700345 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800346 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800347 */
alshabibd17abc22015-04-21 18:26:35 -0700348 public static Instruction transition(Integer tableId) {
349 checkNotNull(tableId, "Table id cannot be null");
350 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800351 }
352
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800353 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700354 * Writes metadata to associate with a packet.
355 *
356 * @param metadata the metadata value to write
357 * @param metadataMask the bits to mask for the metadata value
358 * @return metadata instruction
359 */
360 public static Instruction writeMetadata(long metadata, long metadataMask) {
361 return new MetadataInstruction(metadata, metadataMask);
362 }
363
364 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700365 * Creates a Tunnel ID modification.
366 *
367 * @param tunnelId the Tunnel ID to modify to
368 * @return a L2 modification
369 */
370 public static L2ModificationInstruction modTunnelId(long tunnelId) {
371 checkNotNull(tunnelId, "Tunnel id cannot be null");
372 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
373 }
374
375 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700376 * Creates a TCP src modification.
377 *
378 * @param port the TCP port number to modify to
379 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700380 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700381 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700382 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700383 public static L4ModificationInstruction modTcpSrc(short port) {
384 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700385 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
386 }
387
388 /**
389 * Creates a TCP src modification.
390 *
391 * @param port the TCP port number to modify to
392 * @return a L4 modification
393 */
394 public static L4ModificationInstruction modTcpSrc(TpPort port) {
395 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700396 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
397 }
398
399 /**
400 * Creates a TCP dst modification.
401 *
402 * @param port the TCP port number to modify to
403 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700404 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700405 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700406 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700407 public static L4ModificationInstruction modTcpDst(short port) {
408 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700409 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
410 }
411
412 /**
413 * Creates a TCP dst modification.
414 *
415 * @param port the TCP port number to modify to
416 * @return a L4 modification
417 */
418 public static L4ModificationInstruction modTcpDst(TpPort port) {
419 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700420 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
421 }
422
423 /**
424 * Creates a UDP src modification.
425 *
426 * @param port the UDP port number to modify to
427 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700428 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700429 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700430 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700431 public static L4ModificationInstruction modUdpSrc(short port) {
432 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700433 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
434 }
435
436 /**
437 * Creates a UDP src modification.
438 *
439 * @param port the UDP port number to modify to
440 * @return a L4 modification
441 */
442 public static L4ModificationInstruction modUdpSrc(TpPort port) {
443 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700444 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
445 }
446
447 /**
448 * Creates a UDP dst modification.
449 *
450 * @param port the UDP port number to modify to
451 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700452 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700453 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700454 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700455 public static L4ModificationInstruction modUdpDst(short port) {
456 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700457 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
458 }
459
460 /**
461 * Creates a UDP dst modification.
462 *
463 * @param port the UDP port number to modify to
464 * @return a L4 modification
465 */
466 public static L4ModificationInstruction modUdpDst(TpPort port) {
467 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700468 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
469 }
470
471 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800472 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700473 */
Charles Chan7efabeb2015-09-28 15:12:19 -0700474 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -0700475 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800476
477 private DropInstruction() {}
478
alshabib55a55d92014-09-16 11:59:31 -0700479 @Override
480 public Type type() {
481 return Type.DROP;
482 }
alshabib99b8fdc2014-09-25 14:30:22 -0700483
484 @Override
485 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800486 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700487 }
alshabib8ca53902014-10-07 13:11:17 -0700488
489 @Override
490 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700491 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700492 }
493
494 @Override
495 public boolean equals(Object obj) {
496 if (this == obj) {
497 return true;
498 }
499 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800500 return true;
alshabib8ca53902014-10-07 13:11:17 -0700501 }
502 return false;
503 }
alshabib55a55d92014-09-16 11:59:31 -0700504 }
505
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800506 /**
Charles Chan7efabeb2015-09-28 15:12:19 -0700507 * No Action instruction.
508 */
509 public static final class NoActionInstruction implements Instruction {
510
511 private NoActionInstruction() {}
512
513 @Override
514 public Type type() {
515 return Type.NOACTION;
516 }
517
518 @Override
519 public String toString() {
520 return toStringHelper(type().toString()).toString();
521 }
522
523 @Override
524 public int hashCode() {
525 return Objects.hash(type().ordinal());
526 }
527
528 @Override
529 public boolean equals(Object obj) {
530 if (this == obj) {
531 return true;
532 }
533 if (obj instanceof NoActionInstruction) {
534 return true;
535 }
536 return false;
537 }
538 }
539
540 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800541 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800542 */
alshabib55a55d92014-09-16 11:59:31 -0700543 public static final class OutputInstruction implements Instruction {
544 private final PortNumber port;
545
546 private OutputInstruction(PortNumber port) {
547 this.port = port;
548 }
549
550 public PortNumber port() {
551 return port;
552 }
553
554 @Override
555 public Type type() {
556 return Type.OUTPUT;
557 }
alshabib99b8fdc2014-09-25 14:30:22 -0700558 @Override
559 public String toString() {
560 return toStringHelper(type().toString())
561 .add("port", port).toString();
562 }
alshabib8ca53902014-10-07 13:11:17 -0700563
564 @Override
565 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700566 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700567 }
568
569 @Override
570 public boolean equals(Object obj) {
571 if (this == obj) {
572 return true;
573 }
574 if (obj instanceof OutputInstruction) {
575 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700576 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700577
578 }
579 return false;
580 }
alshabib55a55d92014-09-16 11:59:31 -0700581 }
582
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800583 /**
584 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800585 */
sangho8995ac52015-02-04 11:29:03 -0800586 public static final class GroupInstruction implements Instruction {
587 private final GroupId groupId;
588
589 private GroupInstruction(GroupId groupId) {
590 this.groupId = groupId;
591 }
592
593 public GroupId groupId() {
594 return groupId;
595 }
596
597 @Override
598 public Type type() {
599 return Type.GROUP;
600 }
alshabib9af70072015-02-09 14:34:16 -0800601
sangho8995ac52015-02-04 11:29:03 -0800602 @Override
603 public String toString() {
604 return toStringHelper(type().toString())
605 .add("group ID", groupId.id()).toString();
606 }
607
608 @Override
609 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700610 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800611 }
612
613 @Override
614 public boolean equals(Object obj) {
615 if (this == obj) {
616 return true;
617 }
618 if (obj instanceof GroupInstruction) {
619 GroupInstruction that = (GroupInstruction) obj;
620 return Objects.equals(groupId, that.groupId);
621
622 }
623 return false;
624 }
625 }
626
Saurav Das86af8f12015-05-25 23:55:33 -0700627 /**
alshabib10c810b2015-08-18 16:59:04 -0700628 * A meter instruction.
629 */
630 public static final class MeterInstruction implements Instruction {
631 private final MeterId meterId;
632
633 private MeterInstruction(MeterId meterId) {
634 this.meterId = meterId;
635 }
636
637 public MeterId meterId() {
638 return meterId;
639 }
640
641 @Override
642 public Type type() {
643 return Type.METER;
644 }
645
646 @Override
647 public String toString() {
648 return toStringHelper(type().toString())
649 .add("meter ID", meterId.id()).toString();
650 }
651
652 @Override
653 public int hashCode() {
654 return Objects.hash(type().ordinal(), meterId);
655 }
656
657 @Override
658 public boolean equals(Object obj) {
659 if (this == obj) {
660 return true;
661 }
662 if (obj instanceof MeterInstruction) {
663 MeterInstruction that = (MeterInstruction) obj;
664 return Objects.equals(meterId, that.meterId);
665
666 }
667 return false;
668 }
669 }
670
671 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700672 * Transition instruction.
673 */
alshabibd17abc22015-04-21 18:26:35 -0700674 public static class TableTypeTransition implements Instruction {
675 private final Integer tableId;
676
677 TableTypeTransition(Integer tableId) {
678 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800679 }
680
681 @Override
682 public Type type() {
683 return Type.TABLE;
684 }
685
alshabibd17abc22015-04-21 18:26:35 -0700686 public Integer tableId() {
687 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800688 }
689
690 @Override
691 public String toString() {
692 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700693 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800694 }
695
696 @Override
697 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700698 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800699 }
700
701 @Override
702 public boolean equals(Object obj) {
703 if (this == obj) {
704 return true;
705 }
706 if (obj instanceof TableTypeTransition) {
707 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700708 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800709
710 }
711 return false;
712 }
Saurav Das86af8f12015-05-25 23:55:33 -0700713 }
alshabib9af70072015-02-09 14:34:16 -0800714
Saurav Das86af8f12015-05-25 23:55:33 -0700715 /**
716 * Metadata instruction.
717 */
718 public static class MetadataInstruction implements Instruction {
719 private final long metadata;
720 private final long metadataMask;
721
722 MetadataInstruction(long metadata, long metadataMask) {
723 this.metadata = metadata;
724 this.metadataMask = metadataMask;
725 }
726
727 @Override
728 public Type type() {
729 return Type.METADATA;
730 }
731
732 public long metadata() {
733 return this.metadata;
734 }
735
736 public long metadataMask() {
737 return this.metadataMask;
738 }
739
740 @Override
741 public String toString() {
742 return toStringHelper(type().toString())
743 .add("metadata", Long.toHexString(this.metadata))
744 .add("metadata mask", Long.toHexString(this.metadataMask))
745 .toString();
746 }
747
748 @Override
749 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700750 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700751 }
752
753 @Override
754 public boolean equals(Object obj) {
755 if (this == obj) {
756 return true;
757 }
758 if (obj instanceof MetadataInstruction) {
759 MetadataInstruction that = (MetadataInstruction) obj;
760 return Objects.equals(metadata, that.metadata) &&
761 Objects.equals(metadataMask, that.metadataMask);
762
763 }
764 return false;
765 }
alshabib9af70072015-02-09 14:34:16 -0800766 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700767
alshabib55a55d92014-09-16 11:59:31 -0700768}
alshabib8ca53902014-10-07 13:11:17 -0700769
770