38fbc279115dd27e67629057875caf771c6c395f
[onosfw.git] /
1 /*
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
17 package org.onosproject.net.flow.instructions;
18
19 import com.google.common.annotations.Beta;
20 import com.google.common.base.MoreObjects;
21
22 import java.util.Objects;
23
24 /**
25  * Type of extension instructions.
26  */
27 @Beta
28 public final class ExtensionTreatmentType {
29
30     /**
31      * A list of well-known named extension instruction type codes.
32      * These numbers have no impact on the actual OF type id.
33      */
34     public enum ExtensionTreatmentTypes {
35         // TODO fix type numbers to include experimenter id
36         NICIRA_SET_TUNNEL_DST(0),
37         NICIRA_RESUBMIT(1),
38         NICIRA_SET_NSH_SPI(32);
39
40         private ExtensionTreatmentType type;
41
42         /**
43          * Creates a new named extension instruction type.
44          *
45          * @param type type code
46          */
47         ExtensionTreatmentTypes(int type) {
48             this.type = new ExtensionTreatmentType(type);
49         }
50
51         /**
52          * Gets the extension type object for this named type code.
53          *
54          * @return extension type object
55          */
56         public ExtensionTreatmentType type() {
57             return type;
58         }
59     }
60
61     private final int type;
62
63     /**
64      * Creates an extension type with the given int type code.
65      *
66      * @param type type code
67      */
68     public ExtensionTreatmentType(int type) {
69         this.type = type;
70     }
71
72     @Override
73     public int hashCode() {
74         return Objects.hash(type);
75     }
76
77     @Override
78     public boolean equals(Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (obj instanceof ExtensionTreatmentType) {
83             final ExtensionTreatmentType that = (ExtensionTreatmentType) obj;
84             return this.type == that.type;
85         }
86         return false;
87     }
88
89     @Override
90     public String toString() {
91         return MoreObjects.toStringHelper(ExtensionTreatmentType.class)
92                 .add("type", type)
93                 .toString();
94     }
95 }