blob: aad407c8378f628925e591ee797fbf770424a57e [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;
Jonathan Hart3c259162015-10-21 21:31:19 -070025import org.onosproject.net.DeviceId;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070026import org.onosproject.net.IndexedLambda;
27import org.onosproject.net.Lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070028import org.onosproject.net.OchSignal;
Yafit Hadar52d81552015-10-07 12:26:52 +030029import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.PortNumber;
31import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
32import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070033import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Yafit Hadar52d81552015-10-07 12:26:52 +030034import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
36import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080037import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
sangho3f97a17d2015-01-29 22:56:29 -080038import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070039import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
40import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
alshabib10c810b2015-08-18 16:59:04 -070041import org.onosproject.net.meter.MeterId;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080042
Jonathan Hart54b406b2015-03-06 16:24:14 -080043import java.util.Objects;
44
45import static com.google.common.base.MoreObjects.toStringHelper;
46import static com.google.common.base.Preconditions.checkNotNull;
alshabib64231f62014-09-16 17:58:36 -070047
alshabib55a55d92014-09-16 11:59:31 -070048/**
49 * Factory class for creating various traffic treatment instructions.
50 */
51public final class Instructions {
52
alshabib55a55d92014-09-16 11:59:31 -070053 // Ban construction
54 private Instructions() {}
55
56 /**
57 * Creates an output instruction using the specified port number. This can
58 * include logical ports such as CONTROLLER, FLOOD, etc.
59 *
60 * @param number port number
61 * @return output instruction
62 */
63 public static OutputInstruction createOutput(final PortNumber number) {
64 checkNotNull(number, "PortNumber cannot be null");
65 return new OutputInstruction(number);
66 }
67
68 /**
69 * Creates a drop instruction.
Jonathan Hart54b406b2015-03-06 16:24:14 -080070 *
alshabib55a55d92014-09-16 11:59:31 -070071 * @return drop instruction
72 */
Charles Chan7efabeb2015-09-28 15:12:19 -070073 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -070074 public static DropInstruction createDrop() {
75 return new DropInstruction();
76 }
77
78 /**
Charles Chan7efabeb2015-09-28 15:12:19 -070079 * Creates a no action instruction.
80 *
81 * @return no action instruction
82 */
83 public static NoActionInstruction createNoAction() {
84 return new NoActionInstruction();
85 }
86
87 /**
sangho8995ac52015-02-04 11:29:03 -080088 * Creates a group instruction.
89 *
90 * @param groupId Group Id
91 * @return group instruction
92 */
93 public static GroupInstruction createGroup(final GroupId groupId) {
94 checkNotNull(groupId, "GroupId cannot be null");
95 return new GroupInstruction(groupId);
96 }
97
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +020098 /**
99 * Creates a set-queue instruction.
100 *
101 * @param queueId Queue Id
102 * @return set-queue instruction
103 */
104 public static SetQueueInstruction setQueue(final long queueId) {
105 checkNotNull(queueId, "queue ID cannot be null");
106 return new SetQueueInstruction(queueId);
107 }
108
alshabib10c810b2015-08-18 16:59:04 -0700109 public static MeterInstruction meterTraffic(final MeterId meterId) {
110 checkNotNull(meterId, "meter id cannot be null");
111 return new MeterInstruction(meterId);
112 }
113
sangho8995ac52015-02-04 11:29:03 -0800114 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700115 * Creates an L0 modification with the specified OCh signal.
116 *
117 * @param lambda OCh signal
118 * @return an L0 modification
119 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700120 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700121 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700122
123 if (lambda instanceof IndexedLambda) {
124 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
125 } else if (lambda instanceof OchSignal) {
126 return new ModOchSignalInstruction((OchSignal) lambda);
127 } else {
128 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
129 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700130 }
131
132 /**
Yafit Hadar52d81552015-10-07 12:26:52 +0300133 * Creates an L1 modification with the specified ODU signal Id.
134 *
135 * @param oduSignalId ODU Signal Id
136 * @return a L1 modification
137 */
138 public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
139 checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
140 return new ModOduSignalIdInstruction(oduSignalId);
141 }
142 /**
alshabib55a55d92014-09-16 11:59:31 -0700143 * Creates a l2 src 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 modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700149 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700150 return new L2ModificationInstruction.ModEtherInstruction(
151 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700152 }
153
154 /**
155 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800156 *
157 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700158 * @return a L2 modification
159 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700160 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700161 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700162 return new L2ModificationInstruction.ModEtherInstruction(
163 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700164 }
165
166 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800167 * Creates a VLAN ID modification.
168 *
169 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700170 * @return a L2 modification
171 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700172 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700173 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700174 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700175 }
176
alshabib7410fea2014-09-16 13:48:39 -0700177 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800178 * Creates a VLAN PCP modification.
179 *
180 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700181 * @return a L2 modification
182 */
183 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
184 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700185 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700186 }
187
188 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800189 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800190 *
191 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800192 * @return a L2 Modification
193 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100194 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800195 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700196 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800197 }
sangho3f97a17d2015-01-29 22:56:29 -0800198
199 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700200 * Creates a MPLS BOS bit modification.
201 *
202 * @param mplsBos MPLS BOS bit to set (true) or unset (false)
203 * @return a L2 Modification
204 */
205 public static L2ModificationInstruction modMplsBos(boolean mplsBos) {
206 return new L2ModificationInstruction.ModMplsBosInstruction(mplsBos);
207 }
208
209 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800210 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800211 *
212 * @return a L2 Modification
213 */
214 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700215 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800216 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800217
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800218 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800219 * Creates a L3 IPv4 src modification.
220 *
221 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700222 * @return a L3 modification
223 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700224 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800225 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
226 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700227 }
228
229 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800230 * Creates a L3 IPv4 dst modification.
231 *
232 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700233 * @return a L3 modification
234 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700235 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800236 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
237 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
238 }
239
240 /**
241 * Creates a L3 IPv6 src modification.
242 *
243 * @param addr the IPv6 address to modify to
244 * @return a L3 modification
245 */
246 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
247 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
248 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
249 }
250
251 /**
252 * Creates a L3 IPv6 dst modification.
253 *
254 * @param addr the IPv6 address to modify to
255 * @return a L3 modification
256 */
257 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
258 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
259 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
260 }
261
262 /**
263 * Creates a L3 IPv6 Flow Label modification.
264 *
265 * @param flowLabel the IPv6 flow label to modify to (20 bits)
266 * @return a L3 modification
267 */
268 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
269 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700270 }
271
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800272 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800273 * Creates a L3 decrement TTL modification.
274 *
sangho3f97a17d2015-01-29 22:56:29 -0800275 * @return a L3 modification
276 */
277 public static L3ModificationInstruction decNwTtl() {
278 return new ModTtlInstruction(L3SubType.DEC_TTL);
279 }
280
281 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800282 * Creates a L3 copy TTL to outer header modification.
283 *
sangho3f97a17d2015-01-29 22:56:29 -0800284 * @return a L3 modification
285 */
286 public static L3ModificationInstruction copyTtlOut() {
287 return new ModTtlInstruction(L3SubType.TTL_OUT);
288 }
289
290 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800291 * Creates a L3 copy TTL to inner header modification.
292 *
sangho3f97a17d2015-01-29 22:56:29 -0800293 * @return a L3 modification
294 */
295 public static L3ModificationInstruction copyTtlIn() {
296 return new ModTtlInstruction(L3SubType.TTL_IN);
297 }
298
299 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800300 * Creates a push MPLS header instruction.
301 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800302 * @return a L2 modification.
303 */
304 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700305 return new L2ModificationInstruction.PushHeaderInstructions(
306 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700307 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800308 }
309
310 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800311 * Creates a pop MPLS header instruction.
312 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800313 * @return a L2 modification.
314 */
315 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700316 return new L2ModificationInstruction.PushHeaderInstructions(
317 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700318 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800319 }
alshabib7410fea2014-09-16 13:48:39 -0700320
sangho3f97a17d2015-01-29 22:56:29 -0800321 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800322 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800323 *
324 * @param etherType Ethernet type to set
325 * @return a L2 modification.
alshabib7b808c52015-06-26 14:22:24 -0700326 */
327 public static Instruction popMpls(EthType etherType) {
328 checkNotNull(etherType, "Ethernet type cannot be null");
329 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700330 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800331 }
332
Saurav Dasfbe25c52015-03-04 11:12:00 -0800333 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800334 * Creates a pop VLAN header instruction.
335 *
336 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800337 */
338 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700339 return new L2ModificationInstruction.PopVlanInstruction(
340 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800341 }
342
343 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800344 * Creates a push VLAN header instruction.
345 *
346 * @return a L2 modification
347 */
348 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700349 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700350 L2ModificationInstruction.L2SubType.VLAN_PUSH,
351 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800352 }
353
354 /**
alshabibd17abc22015-04-21 18:26:35 -0700355 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800356 *
alshabibd17abc22015-04-21 18:26:35 -0700357 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800358 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800359 */
alshabibd17abc22015-04-21 18:26:35 -0700360 public static Instruction transition(Integer tableId) {
361 checkNotNull(tableId, "Table id cannot be null");
362 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800363 }
364
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800365 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700366 * Writes metadata to associate with a packet.
367 *
368 * @param metadata the metadata value to write
369 * @param metadataMask the bits to mask for the metadata value
370 * @return metadata instruction
371 */
372 public static Instruction writeMetadata(long metadata, long metadataMask) {
373 return new MetadataInstruction(metadata, metadataMask);
374 }
375
376 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700377 * Creates a Tunnel ID modification.
378 *
379 * @param tunnelId the Tunnel ID to modify to
380 * @return a L2 modification
381 */
382 public static L2ModificationInstruction modTunnelId(long tunnelId) {
383 checkNotNull(tunnelId, "Tunnel id cannot be null");
384 return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
385 }
386
387 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700388 * Creates a TCP src modification.
389 *
390 * @param port the TCP port number to modify to
391 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700392 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700393 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700394 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700395 public static L4ModificationInstruction modTcpSrc(short port) {
396 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700397 return new ModTransportPortInstruction(L4SubType.TCP_SRC, TpPort.tpPort(port));
398 }
399
400 /**
401 * Creates a TCP src modification.
402 *
403 * @param port the TCP port number to modify to
404 * @return a L4 modification
405 */
406 public static L4ModificationInstruction modTcpSrc(TpPort port) {
407 checkNotNull(port, "Src TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700408 return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
409 }
410
411 /**
412 * Creates a TCP dst modification.
413 *
414 * @param port the TCP port number to modify to
415 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700416 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700417 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700418 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700419 public static L4ModificationInstruction modTcpDst(short port) {
420 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700421 return new ModTransportPortInstruction(L4SubType.TCP_DST, TpPort.tpPort(port));
422 }
423
424 /**
425 * Creates a TCP dst modification.
426 *
427 * @param port the TCP port number to modify to
428 * @return a L4 modification
429 */
430 public static L4ModificationInstruction modTcpDst(TpPort port) {
431 checkNotNull(port, "Dst TCP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700432 return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
433 }
434
435 /**
436 * Creates a UDP src modification.
437 *
438 * @param port the UDP port number to modify to
439 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700440 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700441 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700442 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700443 public static L4ModificationInstruction modUdpSrc(short port) {
444 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700445 return new ModTransportPortInstruction(L4SubType.UDP_SRC, TpPort.tpPort(port));
446 }
447
448 /**
449 * Creates a UDP src modification.
450 *
451 * @param port the UDP port number to modify to
452 * @return a L4 modification
453 */
454 public static L4ModificationInstruction modUdpSrc(TpPort port) {
455 checkNotNull(port, "Src UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700456 return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
457 }
458
459 /**
460 * Creates a UDP dst modification.
461 *
462 * @param port the UDP port number to modify to
463 * @return a L4 modification
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700464 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700465 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700466 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700467 public static L4ModificationInstruction modUdpDst(short port) {
468 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700469 return new ModTransportPortInstruction(L4SubType.UDP_DST, TpPort.tpPort(port));
470 }
471
472 /**
473 * Creates a UDP dst modification.
474 *
475 * @param port the UDP port number to modify to
476 * @return a L4 modification
477 */
478 public static L4ModificationInstruction modUdpDst(TpPort port) {
479 checkNotNull(port, "Dst UDP port cannot be null");
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700480 return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
481 }
482
483 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700484 * Creates an extension instruction.
485 *
486 * @param extension extension instruction
487 * @param deviceId device ID
488 * @return extension instruction
489 */
490 public static ExtensionInstructionWrapper extension(ExtensionInstruction extension,
491 DeviceId deviceId) {
492 checkNotNull(extension, "Extension instruction cannot be null");
493 checkNotNull(deviceId, "Device ID cannot be null");
494 return new ExtensionInstructionWrapper(extension, deviceId);
495 }
496
497 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800498 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700499 */
Charles Chan7efabeb2015-09-28 15:12:19 -0700500 @Deprecated
alshabib55a55d92014-09-16 11:59:31 -0700501 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800502
503 private DropInstruction() {}
504
alshabib55a55d92014-09-16 11:59:31 -0700505 @Override
506 public Type type() {
507 return Type.DROP;
508 }
alshabib99b8fdc2014-09-25 14:30:22 -0700509
510 @Override
511 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800512 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700513 }
alshabib8ca53902014-10-07 13:11:17 -0700514
515 @Override
516 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700517 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700518 }
519
520 @Override
521 public boolean equals(Object obj) {
522 if (this == obj) {
523 return true;
524 }
525 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800526 return true;
alshabib8ca53902014-10-07 13:11:17 -0700527 }
528 return false;
529 }
alshabib55a55d92014-09-16 11:59:31 -0700530 }
531
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800532 /**
Charles Chan7efabeb2015-09-28 15:12:19 -0700533 * No Action instruction.
534 */
535 public static final class NoActionInstruction implements Instruction {
536
537 private NoActionInstruction() {}
538
539 @Override
540 public Type type() {
541 return Type.NOACTION;
542 }
543
544 @Override
545 public String toString() {
546 return toStringHelper(type().toString()).toString();
547 }
548
549 @Override
550 public int hashCode() {
551 return Objects.hash(type().ordinal());
552 }
553
554 @Override
555 public boolean equals(Object obj) {
556 if (this == obj) {
557 return true;
558 }
559 if (obj instanceof NoActionInstruction) {
560 return true;
561 }
562 return false;
563 }
564 }
565
566 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800567 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800568 */
alshabib55a55d92014-09-16 11:59:31 -0700569 public static final class OutputInstruction implements Instruction {
570 private final PortNumber port;
571
572 private OutputInstruction(PortNumber port) {
573 this.port = port;
574 }
575
576 public PortNumber port() {
577 return port;
578 }
579
580 @Override
581 public Type type() {
582 return Type.OUTPUT;
583 }
alshabib99b8fdc2014-09-25 14:30:22 -0700584 @Override
585 public String toString() {
586 return toStringHelper(type().toString())
587 .add("port", port).toString();
588 }
alshabib8ca53902014-10-07 13:11:17 -0700589
590 @Override
591 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700592 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700593 }
594
595 @Override
596 public boolean equals(Object obj) {
597 if (this == obj) {
598 return true;
599 }
600 if (obj instanceof OutputInstruction) {
601 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700602 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700603
604 }
605 return false;
606 }
alshabib55a55d92014-09-16 11:59:31 -0700607 }
608
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800609 /**
610 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800611 */
sangho8995ac52015-02-04 11:29:03 -0800612 public static final class GroupInstruction implements Instruction {
613 private final GroupId groupId;
614
615 private GroupInstruction(GroupId groupId) {
616 this.groupId = groupId;
617 }
618
619 public GroupId groupId() {
620 return groupId;
621 }
622
623 @Override
624 public Type type() {
625 return Type.GROUP;
626 }
alshabib9af70072015-02-09 14:34:16 -0800627
sangho8995ac52015-02-04 11:29:03 -0800628 @Override
629 public String toString() {
630 return toStringHelper(type().toString())
631 .add("group ID", groupId.id()).toString();
632 }
633
634 @Override
635 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700636 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800637 }
638
639 @Override
640 public boolean equals(Object obj) {
641 if (this == obj) {
642 return true;
643 }
644 if (obj instanceof GroupInstruction) {
645 GroupInstruction that = (GroupInstruction) obj;
646 return Objects.equals(groupId, that.groupId);
647
648 }
649 return false;
650 }
651 }
652
Saurav Das86af8f12015-05-25 23:55:33 -0700653 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200654 * Set-Queue Instruction.
655 */
656 public static final class SetQueueInstruction implements Instruction {
657 private final long queueId;
658
659 private SetQueueInstruction(long queueId) {
660 this.queueId = queueId;
661 }
662
663 public long queueId() {
664 return queueId;
665 }
666
667 @Override
668 public Type type() {
669 return Type.QUEUE;
670 }
671
672 @Override
673 public String toString() {
674 return toStringHelper(type().toString())
675 .add("queueId", queueId).toString();
676 }
677
678 @Override
679 public int hashCode() {
680 return Objects.hash(type().ordinal(), queueId);
681 }
682
683 @Override
684 public boolean equals(Object obj) {
685 if (this == obj) {
686 return true;
687 }
688 if (obj instanceof SetQueueInstruction) {
689 SetQueueInstruction that = (SetQueueInstruction) obj;
690 return Objects.equals(queueId, that.queueId);
691
692 }
693 return false;
694 }
695 }
696
697 /**
alshabib10c810b2015-08-18 16:59:04 -0700698 * A meter instruction.
699 */
700 public static final class MeterInstruction implements Instruction {
701 private final MeterId meterId;
702
703 private MeterInstruction(MeterId meterId) {
704 this.meterId = meterId;
705 }
706
707 public MeterId meterId() {
708 return meterId;
709 }
710
711 @Override
712 public Type type() {
713 return Type.METER;
714 }
715
716 @Override
717 public String toString() {
718 return toStringHelper(type().toString())
719 .add("meter ID", meterId.id()).toString();
720 }
721
722 @Override
723 public int hashCode() {
724 return Objects.hash(type().ordinal(), meterId);
725 }
726
727 @Override
728 public boolean equals(Object obj) {
729 if (this == obj) {
730 return true;
731 }
732 if (obj instanceof MeterInstruction) {
733 MeterInstruction that = (MeterInstruction) obj;
734 return Objects.equals(meterId, that.meterId);
735
736 }
737 return false;
738 }
739 }
740
741 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700742 * Transition instruction.
743 */
alshabibd17abc22015-04-21 18:26:35 -0700744 public static class TableTypeTransition implements Instruction {
745 private final Integer tableId;
746
747 TableTypeTransition(Integer tableId) {
748 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800749 }
750
751 @Override
752 public Type type() {
753 return Type.TABLE;
754 }
755
alshabibd17abc22015-04-21 18:26:35 -0700756 public Integer tableId() {
757 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800758 }
759
760 @Override
761 public String toString() {
762 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700763 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800764 }
765
766 @Override
767 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700768 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800769 }
770
771 @Override
772 public boolean equals(Object obj) {
773 if (this == obj) {
774 return true;
775 }
776 if (obj instanceof TableTypeTransition) {
777 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700778 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800779
780 }
781 return false;
782 }
Saurav Das86af8f12015-05-25 23:55:33 -0700783 }
alshabib9af70072015-02-09 14:34:16 -0800784
Saurav Das86af8f12015-05-25 23:55:33 -0700785 /**
786 * Metadata instruction.
787 */
788 public static class MetadataInstruction implements Instruction {
789 private final long metadata;
790 private final long metadataMask;
791
792 MetadataInstruction(long metadata, long metadataMask) {
793 this.metadata = metadata;
794 this.metadataMask = metadataMask;
795 }
796
797 @Override
798 public Type type() {
799 return Type.METADATA;
800 }
801
802 public long metadata() {
803 return this.metadata;
804 }
805
806 public long metadataMask() {
807 return this.metadataMask;
808 }
809
810 @Override
811 public String toString() {
812 return toStringHelper(type().toString())
813 .add("metadata", Long.toHexString(this.metadata))
814 .add("metadata mask", Long.toHexString(this.metadataMask))
815 .toString();
816 }
817
818 @Override
819 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700820 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700821 }
822
823 @Override
824 public boolean equals(Object obj) {
825 if (this == obj) {
826 return true;
827 }
828 if (obj instanceof MetadataInstruction) {
829 MetadataInstruction that = (MetadataInstruction) obj;
830 return Objects.equals(metadata, that.metadata) &&
831 Objects.equals(metadataMask, that.metadataMask);
832
833 }
834 return false;
835 }
alshabib9af70072015-02-09 14:34:16 -0800836 }
Saurav Das73a7dd42015-08-19 22:20:31 -0700837
Jonathan Hart3c259162015-10-21 21:31:19 -0700838 /**
839 * Extension instruction.
840 */
841 public static class ExtensionInstructionWrapper implements Instruction {
842 private final ExtensionInstruction extensionInstruction;
843 private final DeviceId deviceId;
844
845 ExtensionInstructionWrapper(ExtensionInstruction extension, DeviceId deviceId) {
846 extensionInstruction = extension;
847 this.deviceId = deviceId;
848 }
849
850 public ExtensionInstruction extensionInstruction() {
851 return extensionInstruction;
852 }
853
854 public DeviceId deviceId() {
855 return deviceId;
856 }
857
858 @Override
859 public Type type() {
860 return Type.EXTENSION;
861 }
862
863 @Override
864 public String toString() {
865 return toStringHelper(type().toString())
866 .add("extension", extensionInstruction)
867 .add("deviceId", deviceId)
868 .toString();
869 }
870
871 @Override
872 public int hashCode() {
873 return Objects.hash(type().ordinal(), extensionInstruction, deviceId);
874 }
875
876 @Override
877 public boolean equals(Object obj) {
878 if (this == obj) {
879 return true;
880 }
881 if (obj instanceof ExtensionInstructionWrapper) {
882 ExtensionInstructionWrapper that = (ExtensionInstructionWrapper) obj;
883 return Objects.equals(extensionInstruction, that.extensionInstruction)
884 && Objects.equals(deviceId, that.deviceId);
885
886 }
887 return false;
888 }
889 }
890
alshabib55a55d92014-09-16 11:59:31 -0700891}
alshabib8ca53902014-10-07 13:11:17 -0700892
893