blob: 9703e1c1c709ee9e146282e2b90ccb8fe25eae2f [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;
22import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080023import org.onosproject.core.GroupId;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070024import org.onosproject.net.IndexedLambda;
25import org.onosproject.net.Lambda;
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070026import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.PortNumber;
28import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
29import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070030import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
32import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080033import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
sangho3f97a17d2015-01-29 22:56:29 -080034import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080035
Jonathan Hart54b406b2015-03-06 16:24:14 -080036import java.util.Objects;
37
38import static com.google.common.base.MoreObjects.toStringHelper;
39import static com.google.common.base.Preconditions.checkNotNull;
alshabib64231f62014-09-16 17:58:36 -070040
alshabib55a55d92014-09-16 11:59:31 -070041/**
42 * Factory class for creating various traffic treatment instructions.
43 */
44public final class Instructions {
45
46
47 // Ban construction
48 private Instructions() {}
49
50 /**
51 * Creates an output instruction using the specified port number. This can
52 * include logical ports such as CONTROLLER, FLOOD, etc.
53 *
54 * @param number port number
55 * @return output instruction
56 */
57 public static OutputInstruction createOutput(final PortNumber number) {
58 checkNotNull(number, "PortNumber cannot be null");
59 return new OutputInstruction(number);
60 }
61
62 /**
63 * Creates a drop instruction.
Jonathan Hart54b406b2015-03-06 16:24:14 -080064 *
alshabib55a55d92014-09-16 11:59:31 -070065 * @return drop instruction
66 */
67 public static DropInstruction createDrop() {
68 return new DropInstruction();
69 }
70
71 /**
sangho8995ac52015-02-04 11:29:03 -080072 * Creates a group instruction.
73 *
74 * @param groupId Group Id
75 * @return group instruction
76 */
77 public static GroupInstruction createGroup(final GroupId groupId) {
78 checkNotNull(groupId, "GroupId cannot be null");
79 return new GroupInstruction(groupId);
80 }
81
82 /**
Marc De Leenheer49087752014-10-23 13:54:09 -070083 * Creates a l0 modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -080084 *
85 * @param lambda the lambda to modify to
Marc De Leenheer49087752014-10-23 13:54:09 -070086 * @return a l0 modification
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070087 * @deprecated in Cardinal Release. Use {@link #modL0Lambda(Lambda)} instead.
Marc De Leenheer49087752014-10-23 13:54:09 -070088 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070089 @Deprecated
Marc De Leenheer49087752014-10-23 13:54:09 -070090 public static L0ModificationInstruction modL0Lambda(short lambda) {
91 checkNotNull(lambda, "L0 lambda cannot be null");
92 return new ModLambdaInstruction(L0SubType.LAMBDA, lambda);
93 }
94
95 /**
Sho SHIMIZUe9e12752015-05-05 14:45:40 -070096 * Creates an L0 modification with the specified OCh signal.
97 *
98 * @param lambda OCh signal
99 * @return an L0 modification
100 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700101 public static L0ModificationInstruction modL0Lambda(Lambda lambda) {
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700102 checkNotNull(lambda, "L0 OCh signal cannot be null");
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -0700103
104 if (lambda instanceof IndexedLambda) {
105 return new ModLambdaInstruction(L0SubType.LAMBDA, (short) ((IndexedLambda) lambda).index());
106 } else if (lambda instanceof OchSignal) {
107 return new ModOchSignalInstruction((OchSignal) lambda);
108 } else {
109 throw new UnsupportedOperationException(String.format("Unsupported type: %s", lambda));
110 }
Sho SHIMIZUe9e12752015-05-05 14:45:40 -0700111 }
112
113 /**
alshabib55a55d92014-09-16 11:59:31 -0700114 * Creates a l2 src modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800115 *
116 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700117 * @return a l2 modification
118 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700119 public static L2ModificationInstruction modL2Src(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700120 checkNotNull(addr, "Src l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700121 return new L2ModificationInstruction.ModEtherInstruction(
122 L2ModificationInstruction.L2SubType.ETH_SRC, addr);
alshabib55a55d92014-09-16 11:59:31 -0700123 }
124
125 /**
126 * Creates a L2 dst modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800127 *
128 * @param addr the mac address to modify to
alshabib55a55d92014-09-16 11:59:31 -0700129 * @return a L2 modification
130 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700131 public static L2ModificationInstruction modL2Dst(MacAddress addr) {
alshabib55a55d92014-09-16 11:59:31 -0700132 checkNotNull(addr, "Dst l2 address cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700133 return new L2ModificationInstruction.ModEtherInstruction(
134 L2ModificationInstruction.L2SubType.ETH_DST, addr);
alshabib55a55d92014-09-16 11:59:31 -0700135 }
136
137 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800138 * Creates a VLAN ID modification.
139 *
140 * @param vlanId the VLAN ID to modify to
alshabib7410fea2014-09-16 13:48:39 -0700141 * @return a L2 modification
142 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700143 public static L2ModificationInstruction modVlanId(VlanId vlanId) {
alshabib55a55d92014-09-16 11:59:31 -0700144 checkNotNull(vlanId, "VLAN id cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700145 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
alshabib55a55d92014-09-16 11:59:31 -0700146 }
147
alshabib7410fea2014-09-16 13:48:39 -0700148 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800149 * Creates a VLAN PCP modification.
150 *
151 * @param vlanPcp the PCP to modify to
alshabib7410fea2014-09-16 13:48:39 -0700152 * @return a L2 modification
153 */
154 public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
155 checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700156 return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
alshabib7410fea2014-09-16 13:48:39 -0700157 }
158
159 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800160 * Creates a MPLS label modification.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800161 *
162 * @param mplsLabel MPLS label to set
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800163 * @return a L2 Modification
164 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100165 public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800166 checkNotNull(mplsLabel, "MPLS label cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700167 return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800168 }
sangho3f97a17d2015-01-29 22:56:29 -0800169
170 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800171 * Creates a MPLS decrement TTL modification.
sangho3f97a17d2015-01-29 22:56:29 -0800172 *
173 * @return a L2 Modification
174 */
175 public static L2ModificationInstruction decMplsTtl() {
alshabibd17abc22015-04-21 18:26:35 -0700176 return new L2ModificationInstruction.ModMplsTtlInstruction();
sangho3f97a17d2015-01-29 22:56:29 -0800177 }
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800178
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800179 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800180 * Creates a L3 IPv4 src modification.
181 *
182 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700183 * @return a L3 modification
184 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700185 public static L3ModificationInstruction modL3Src(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800186 checkNotNull(addr, "Src l3 IPv4 address cannot be null");
187 return new ModIPInstruction(L3SubType.IPV4_SRC, addr);
alshabib7410fea2014-09-16 13:48:39 -0700188 }
189
190 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800191 * Creates a L3 IPv4 dst modification.
192 *
193 * @param addr the IPv4 address to modify to
alshabib7410fea2014-09-16 13:48:39 -0700194 * @return a L3 modification
195 */
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -0700196 public static L3ModificationInstruction modL3Dst(IpAddress addr) {
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800197 checkNotNull(addr, "Dst l3 IPv4 address cannot be null");
198 return new ModIPInstruction(L3SubType.IPV4_DST, addr);
199 }
200
201 /**
202 * Creates a L3 IPv6 src modification.
203 *
204 * @param addr the IPv6 address to modify to
205 * @return a L3 modification
206 */
207 public static L3ModificationInstruction modL3IPv6Src(IpAddress addr) {
208 checkNotNull(addr, "Src l3 IPv6 address cannot be null");
209 return new ModIPInstruction(L3SubType.IPV6_SRC, addr);
210 }
211
212 /**
213 * Creates a L3 IPv6 dst modification.
214 *
215 * @param addr the IPv6 address to modify to
216 * @return a L3 modification
217 */
218 public static L3ModificationInstruction modL3IPv6Dst(IpAddress addr) {
219 checkNotNull(addr, "Dst l3 IPv6 address cannot be null");
220 return new ModIPInstruction(L3SubType.IPV6_DST, addr);
221 }
222
223 /**
224 * Creates a L3 IPv6 Flow Label modification.
225 *
226 * @param flowLabel the IPv6 flow label to modify to (20 bits)
227 * @return a L3 modification
228 */
229 public static L3ModificationInstruction modL3IPv6FlowLabel(int flowLabel) {
230 return new ModIPv6FlowLabelInstruction(flowLabel);
alshabib7410fea2014-09-16 13:48:39 -0700231 }
232
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800233 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800234 * Creates a L3 decrement TTL modification.
235 *
sangho3f97a17d2015-01-29 22:56:29 -0800236 * @return a L3 modification
237 */
238 public static L3ModificationInstruction decNwTtl() {
239 return new ModTtlInstruction(L3SubType.DEC_TTL);
240 }
241
242 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800243 * Creates a L3 copy TTL to outer header modification.
244 *
sangho3f97a17d2015-01-29 22:56:29 -0800245 * @return a L3 modification
246 */
247 public static L3ModificationInstruction copyTtlOut() {
248 return new ModTtlInstruction(L3SubType.TTL_OUT);
249 }
250
251 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800252 * Creates a L3 copy TTL to inner header modification.
253 *
sangho3f97a17d2015-01-29 22:56:29 -0800254 * @return a L3 modification
255 */
256 public static L3ModificationInstruction copyTtlIn() {
257 return new ModTtlInstruction(L3SubType.TTL_IN);
258 }
259
260 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800261 * Creates a push MPLS header instruction.
262 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800263 * @return a L2 modification.
264 */
265 public static Instruction pushMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700266 return new L2ModificationInstruction.PushHeaderInstructions(
267 L2ModificationInstruction.L2SubType.MPLS_PUSH,
alshabib7b808c52015-06-26 14:22:24 -0700268 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800269 }
270
271 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800272 * Creates a pop MPLS header instruction.
273 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800274 * @return a L2 modification.
275 */
276 public static Instruction popMpls() {
alshabibd17abc22015-04-21 18:26:35 -0700277 return new L2ModificationInstruction.PushHeaderInstructions(
278 L2ModificationInstruction.L2SubType.MPLS_POP,
alshabib7b808c52015-06-26 14:22:24 -0700279 EthType.EtherType.MPLS_UNICAST.ethType());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800280 }
alshabib7410fea2014-09-16 13:48:39 -0700281
sangho3f97a17d2015-01-29 22:56:29 -0800282 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800283 * Creates a pop MPLS header instruction with a particular ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800284 *
285 * @param etherType Ethernet type to set
286 * @return a L2 modification.
287 */
alshabib7b808c52015-06-26 14:22:24 -0700288 @Deprecated
alshabib0ad43982015-05-07 13:43:13 -0700289 public static Instruction popMpls(int etherType) {
sangho3f97a17d2015-01-29 22:56:29 -0800290 checkNotNull(etherType, "Ethernet type cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700291 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700292 L2ModificationInstruction.L2SubType.MPLS_POP, new EthType(etherType));
293 }
294
295
296 /**
297 * Creates a pop MPLS header instruction with a particular ethertype.
298 *
299 * @param etherType Ethernet type to set
300 * @return a L2 modification.
301 */
302 public static Instruction popMpls(EthType etherType) {
303 checkNotNull(etherType, "Ethernet type cannot be null");
304 return new L2ModificationInstruction.PushHeaderInstructions(
alshabibd17abc22015-04-21 18:26:35 -0700305 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800306 }
307
Saurav Dasfbe25c52015-03-04 11:12:00 -0800308 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800309 * Creates a pop VLAN header instruction.
310 *
311 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800312 */
313 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700314 return new L2ModificationInstruction.PopVlanInstruction(
315 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800316 }
317
318 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800319 * Creates a push VLAN header instruction.
320 *
321 * @return a L2 modification
322 */
323 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700324 return new L2ModificationInstruction.PushHeaderInstructions(
alshabib7b808c52015-06-26 14:22:24 -0700325 L2ModificationInstruction.L2SubType.VLAN_PUSH,
326 EthType.EtherType.VLAN.ethType());
Jonathan Hart54b406b2015-03-06 16:24:14 -0800327 }
328
329 /**
alshabibd17abc22015-04-21 18:26:35 -0700330 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800331 *
alshabibd17abc22015-04-21 18:26:35 -0700332 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800333 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800334 */
alshabibd17abc22015-04-21 18:26:35 -0700335 public static Instruction transition(Integer tableId) {
336 checkNotNull(tableId, "Table id cannot be null");
337 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800338 }
339
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800340 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700341 * Writes metadata to associate with a packet.
342 *
343 * @param metadata the metadata value to write
344 * @param metadataMask the bits to mask for the metadata value
345 * @return metadata instruction
346 */
347 public static Instruction writeMetadata(long metadata, long metadataMask) {
348 return new MetadataInstruction(metadata, metadataMask);
349 }
350
351 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800352 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700353 */
alshabib55a55d92014-09-16 11:59:31 -0700354 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800355
356 private DropInstruction() {}
357
alshabib55a55d92014-09-16 11:59:31 -0700358 @Override
359 public Type type() {
360 return Type.DROP;
361 }
alshabib99b8fdc2014-09-25 14:30:22 -0700362
363 @Override
364 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800365 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700366 }
alshabib8ca53902014-10-07 13:11:17 -0700367
368 @Override
369 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700370 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700371 }
372
373 @Override
374 public boolean equals(Object obj) {
375 if (this == obj) {
376 return true;
377 }
378 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800379 return true;
alshabib8ca53902014-10-07 13:11:17 -0700380 }
381 return false;
382 }
alshabib55a55d92014-09-16 11:59:31 -0700383 }
384
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800385 /**
386 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800387 */
alshabib55a55d92014-09-16 11:59:31 -0700388 public static final class OutputInstruction implements Instruction {
389 private final PortNumber port;
390
391 private OutputInstruction(PortNumber port) {
392 this.port = port;
393 }
394
395 public PortNumber port() {
396 return port;
397 }
398
399 @Override
400 public Type type() {
401 return Type.OUTPUT;
402 }
alshabib99b8fdc2014-09-25 14:30:22 -0700403 @Override
404 public String toString() {
405 return toStringHelper(type().toString())
406 .add("port", port).toString();
407 }
alshabib8ca53902014-10-07 13:11:17 -0700408
409 @Override
410 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700411 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700412 }
413
414 @Override
415 public boolean equals(Object obj) {
416 if (this == obj) {
417 return true;
418 }
419 if (obj instanceof OutputInstruction) {
420 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700421 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700422
423 }
424 return false;
425 }
alshabib55a55d92014-09-16 11:59:31 -0700426 }
427
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800428 /**
429 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800430 */
sangho8995ac52015-02-04 11:29:03 -0800431 public static final class GroupInstruction implements Instruction {
432 private final GroupId groupId;
433
434 private GroupInstruction(GroupId groupId) {
435 this.groupId = groupId;
436 }
437
438 public GroupId groupId() {
439 return groupId;
440 }
441
442 @Override
443 public Type type() {
444 return Type.GROUP;
445 }
alshabib9af70072015-02-09 14:34:16 -0800446
sangho8995ac52015-02-04 11:29:03 -0800447 @Override
448 public String toString() {
449 return toStringHelper(type().toString())
450 .add("group ID", groupId.id()).toString();
451 }
452
453 @Override
454 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700455 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800456 }
457
458 @Override
459 public boolean equals(Object obj) {
460 if (this == obj) {
461 return true;
462 }
463 if (obj instanceof GroupInstruction) {
464 GroupInstruction that = (GroupInstruction) obj;
465 return Objects.equals(groupId, that.groupId);
466
467 }
468 return false;
469 }
470 }
471
Saurav Das86af8f12015-05-25 23:55:33 -0700472 /**
473 * Transition instruction.
474 */
alshabibd17abc22015-04-21 18:26:35 -0700475 public static class TableTypeTransition implements Instruction {
476 private final Integer tableId;
477
478 TableTypeTransition(Integer tableId) {
479 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800480 }
481
482 @Override
483 public Type type() {
484 return Type.TABLE;
485 }
486
alshabibd17abc22015-04-21 18:26:35 -0700487 public Integer tableId() {
488 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800489 }
490
491 @Override
492 public String toString() {
493 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700494 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800495 }
496
497 @Override
498 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700499 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800500 }
501
502 @Override
503 public boolean equals(Object obj) {
504 if (this == obj) {
505 return true;
506 }
507 if (obj instanceof TableTypeTransition) {
508 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700509 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800510
511 }
512 return false;
513 }
Saurav Das86af8f12015-05-25 23:55:33 -0700514 }
alshabib9af70072015-02-09 14:34:16 -0800515
Saurav Das86af8f12015-05-25 23:55:33 -0700516 /**
517 * Metadata instruction.
518 */
519 public static class MetadataInstruction implements Instruction {
520 private final long metadata;
521 private final long metadataMask;
522
523 MetadataInstruction(long metadata, long metadataMask) {
524 this.metadata = metadata;
525 this.metadataMask = metadataMask;
526 }
527
528 @Override
529 public Type type() {
530 return Type.METADATA;
531 }
532
533 public long metadata() {
534 return this.metadata;
535 }
536
537 public long metadataMask() {
538 return this.metadataMask;
539 }
540
541 @Override
542 public String toString() {
543 return toStringHelper(type().toString())
544 .add("metadata", Long.toHexString(this.metadata))
545 .add("metadata mask", Long.toHexString(this.metadataMask))
546 .toString();
547 }
548
549 @Override
550 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700551 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700552 }
553
554 @Override
555 public boolean equals(Object obj) {
556 if (this == obj) {
557 return true;
558 }
559 if (obj instanceof MetadataInstruction) {
560 MetadataInstruction that = (MetadataInstruction) obj;
561 return Objects.equals(metadata, that.metadata) &&
562 Objects.equals(metadataMask, that.metadataMask);
563
564 }
565 return false;
566 }
alshabib9af70072015-02-09 14:34:16 -0800567 }
alshabib55a55d92014-09-16 11:59:31 -0700568}
alshabib8ca53902014-10-07 13:11:17 -0700569
570