blob: 500ac1c5d7b5726a7c810a492c7457800f7a5339 [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
Jonathan Hart54b406b2015-03-06 16:24:14 -080018import org.onlab.packet.Ethernet;
19import 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,
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -0800268 Ethernet.MPLS_UNICAST);
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,
Yuta HIGUCHI32a53c52015-02-08 01:25:40 -0800279 Ethernet.MPLS_UNICAST);
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 */
alshabib0ad43982015-05-07 13:43:13 -0700288 public static Instruction popMpls(int etherType) {
sangho3f97a17d2015-01-29 22:56:29 -0800289 checkNotNull(etherType, "Ethernet type cannot be null");
alshabibd17abc22015-04-21 18:26:35 -0700290 return new L2ModificationInstruction.PushHeaderInstructions(
291 L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800292 }
293
Saurav Dasfbe25c52015-03-04 11:12:00 -0800294 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800295 * Creates a pop VLAN header instruction.
296 *
297 * @return a L2 modification
Saurav Dasfbe25c52015-03-04 11:12:00 -0800298 */
299 public static Instruction popVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700300 return new L2ModificationInstruction.PopVlanInstruction(
301 L2ModificationInstruction.L2SubType.VLAN_POP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800302 }
303
304 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800305 * Creates a push VLAN header instruction.
306 *
307 * @return a L2 modification
308 */
309 public static Instruction pushVlan() {
alshabibd17abc22015-04-21 18:26:35 -0700310 return new L2ModificationInstruction.PushHeaderInstructions(
311 L2ModificationInstruction.L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN);
Jonathan Hart54b406b2015-03-06 16:24:14 -0800312 }
313
314 /**
alshabibd17abc22015-04-21 18:26:35 -0700315 * Sends the packet to the table id.
Jonathan Hart54b406b2015-03-06 16:24:14 -0800316 *
alshabibd17abc22015-04-21 18:26:35 -0700317 * @param tableId flow rule table id
Thomas Vachuska3e2b6512015-03-05 09:25:03 -0800318 * @return table type transition instruction
Saurav Dasfbe25c52015-03-04 11:12:00 -0800319 */
alshabibd17abc22015-04-21 18:26:35 -0700320 public static Instruction transition(Integer tableId) {
321 checkNotNull(tableId, "Table id cannot be null");
322 return new TableTypeTransition(tableId);
alshabib9af70072015-02-09 14:34:16 -0800323 }
324
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800325 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700326 * Writes metadata to associate with a packet.
327 *
328 * @param metadata the metadata value to write
329 * @param metadataMask the bits to mask for the metadata value
330 * @return metadata instruction
331 */
332 public static Instruction writeMetadata(long metadata, long metadataMask) {
333 return new MetadataInstruction(metadata, metadataMask);
334 }
335
336 /**
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800337 * Drop instruction.
alshabib55a55d92014-09-16 11:59:31 -0700338 */
alshabib55a55d92014-09-16 11:59:31 -0700339 public static final class DropInstruction implements Instruction {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800340
341 private DropInstruction() {}
342
alshabib55a55d92014-09-16 11:59:31 -0700343 @Override
344 public Type type() {
345 return Type.DROP;
346 }
alshabib99b8fdc2014-09-25 14:30:22 -0700347
348 @Override
349 public String toString() {
alshabib346b5b32015-03-06 00:42:16 -0800350 return toStringHelper(type().toString()).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700351 }
alshabib8ca53902014-10-07 13:11:17 -0700352
353 @Override
354 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700355 return Objects.hash(type().ordinal());
alshabib8ca53902014-10-07 13:11:17 -0700356 }
357
358 @Override
359 public boolean equals(Object obj) {
360 if (this == obj) {
361 return true;
362 }
363 if (obj instanceof DropInstruction) {
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800364 return true;
alshabib8ca53902014-10-07 13:11:17 -0700365 }
366 return false;
367 }
alshabib55a55d92014-09-16 11:59:31 -0700368 }
369
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800370 /**
371 * Output Instruction.
sangho8995ac52015-02-04 11:29:03 -0800372 */
alshabib55a55d92014-09-16 11:59:31 -0700373 public static final class OutputInstruction implements Instruction {
374 private final PortNumber port;
375
376 private OutputInstruction(PortNumber port) {
377 this.port = port;
378 }
379
380 public PortNumber port() {
381 return port;
382 }
383
384 @Override
385 public Type type() {
386 return Type.OUTPUT;
387 }
alshabib99b8fdc2014-09-25 14:30:22 -0700388 @Override
389 public String toString() {
390 return toStringHelper(type().toString())
391 .add("port", port).toString();
392 }
alshabib8ca53902014-10-07 13:11:17 -0700393
394 @Override
395 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700396 return Objects.hash(type().ordinal(), port);
alshabib8ca53902014-10-07 13:11:17 -0700397 }
398
399 @Override
400 public boolean equals(Object obj) {
401 if (this == obj) {
402 return true;
403 }
404 if (obj instanceof OutputInstruction) {
405 OutputInstruction that = (OutputInstruction) obj;
Yuta HIGUCHI4ce65292014-11-01 12:09:55 -0700406 return Objects.equals(port, that.port);
alshabib8ca53902014-10-07 13:11:17 -0700407
408 }
409 return false;
410 }
alshabib55a55d92014-09-16 11:59:31 -0700411 }
412
Yuta HIGUCHI6a479642015-02-08 01:28:50 -0800413 /**
414 * Group Instruction.
sangho8995ac52015-02-04 11:29:03 -0800415 */
sangho8995ac52015-02-04 11:29:03 -0800416 public static final class GroupInstruction implements Instruction {
417 private final GroupId groupId;
418
419 private GroupInstruction(GroupId groupId) {
420 this.groupId = groupId;
421 }
422
423 public GroupId groupId() {
424 return groupId;
425 }
426
427 @Override
428 public Type type() {
429 return Type.GROUP;
430 }
alshabib9af70072015-02-09 14:34:16 -0800431
sangho8995ac52015-02-04 11:29:03 -0800432 @Override
433 public String toString() {
434 return toStringHelper(type().toString())
435 .add("group ID", groupId.id()).toString();
436 }
437
438 @Override
439 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700440 return Objects.hash(type().ordinal(), groupId);
sangho8995ac52015-02-04 11:29:03 -0800441 }
442
443 @Override
444 public boolean equals(Object obj) {
445 if (this == obj) {
446 return true;
447 }
448 if (obj instanceof GroupInstruction) {
449 GroupInstruction that = (GroupInstruction) obj;
450 return Objects.equals(groupId, that.groupId);
451
452 }
453 return false;
454 }
455 }
456
Saurav Das86af8f12015-05-25 23:55:33 -0700457 /**
458 * Transition instruction.
459 */
alshabibd17abc22015-04-21 18:26:35 -0700460 public static class TableTypeTransition implements Instruction {
461 private final Integer tableId;
462
463 TableTypeTransition(Integer tableId) {
464 this.tableId = tableId;
alshabib9af70072015-02-09 14:34:16 -0800465 }
466
467 @Override
468 public Type type() {
469 return Type.TABLE;
470 }
471
alshabibd17abc22015-04-21 18:26:35 -0700472 public Integer tableId() {
473 return this.tableId;
alshabib9af70072015-02-09 14:34:16 -0800474 }
475
476 @Override
477 public String toString() {
478 return toStringHelper(type().toString())
alshabibd17abc22015-04-21 18:26:35 -0700479 .add("tableId", this.tableId).toString();
alshabib9af70072015-02-09 14:34:16 -0800480 }
481
482 @Override
483 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700484 return Objects.hash(type().ordinal(), tableId);
alshabib9af70072015-02-09 14:34:16 -0800485 }
486
487 @Override
488 public boolean equals(Object obj) {
489 if (this == obj) {
490 return true;
491 }
492 if (obj instanceof TableTypeTransition) {
493 TableTypeTransition that = (TableTypeTransition) obj;
alshabibd17abc22015-04-21 18:26:35 -0700494 return Objects.equals(tableId, that.tableId);
alshabib9af70072015-02-09 14:34:16 -0800495
496 }
497 return false;
498 }
Saurav Das86af8f12015-05-25 23:55:33 -0700499 }
alshabib9af70072015-02-09 14:34:16 -0800500
Saurav Das86af8f12015-05-25 23:55:33 -0700501 /**
502 * Metadata instruction.
503 */
504 public static class MetadataInstruction implements Instruction {
505 private final long metadata;
506 private final long metadataMask;
507
508 MetadataInstruction(long metadata, long metadataMask) {
509 this.metadata = metadata;
510 this.metadataMask = metadataMask;
511 }
512
513 @Override
514 public Type type() {
515 return Type.METADATA;
516 }
517
518 public long metadata() {
519 return this.metadata;
520 }
521
522 public long metadataMask() {
523 return this.metadataMask;
524 }
525
526 @Override
527 public String toString() {
528 return toStringHelper(type().toString())
529 .add("metadata", Long.toHexString(this.metadata))
530 .add("metadata mask", Long.toHexString(this.metadataMask))
531 .toString();
532 }
533
534 @Override
535 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -0700536 return Objects.hash(type().ordinal(), metadata, metadataMask);
Saurav Das86af8f12015-05-25 23:55:33 -0700537 }
538
539 @Override
540 public boolean equals(Object obj) {
541 if (this == obj) {
542 return true;
543 }
544 if (obj instanceof MetadataInstruction) {
545 MetadataInstruction that = (MetadataInstruction) obj;
546 return Objects.equals(metadata, that.metadata) &&
547 Objects.equals(metadataMask, that.metadataMask);
548
549 }
550 return false;
551 }
alshabib9af70072015-02-09 14:34:16 -0800552 }
alshabib55a55d92014-09-16 11:59:31 -0700553}
alshabib8ca53902014-10-07 13:11:17 -0700554
555