blob: 747a85b56b715185e9a724956f108eecd96449bd [file] [log] [blame]
Jonathan Hart3c259162015-10-21 21:31:19 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16
17package org.onosproject.net.flow.instructions;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21
22import java.util.Objects;
23
24/**
25 * Type of extension instructions.
26 */
27@Beta
28public final class ExtensionType {
29
30 /**
31 * A list of well-known named extension instruction type codes.
32 */
33 public enum ExtensionTypes {
34 // TODO fix type numbers to include experimenter id
35 NICIRA_SET_TUNNEL_DST(31);
36
37 private ExtensionType type;
38
39 /**
40 * Creates a new named extension instruction type.
41 *
42 * @param type type code
43 */
44 ExtensionTypes(int type) {
45 this.type = new ExtensionType(type);
46 }
47
48 /**
49 * Gets the extension type object for this named type code.
50 *
51 * @return extension type object
52 */
53 public ExtensionType type() {
54 return type;
55 }
56 }
57
58 private final int type;
59
60 /**
61 * Creates an extension type with the given int type code.
62 *
63 * @param type type code
64 */
65 public ExtensionType(int type) {
66 this.type = type;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hash(type);
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj) {
77 return true;
78 }
79 if (obj instanceof ExtensionType) {
80 final ExtensionType that = (ExtensionType) obj;
81 return this.type == that.type;
82 }
83 return false;
84 }
85
86 @Override
87 public String toString() {
88 return MoreObjects.toStringHelper(ExtensionType.class)
89 .add("type", type)
90 .toString();
91 }
92}