d14c1d7a16f2ba43d25c810d688cdb132dd5b9d5
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / table / OFPTableFeaturePropType.java
1 package org.openflow.codec.protocol.statistics.table;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.openflow.codec.protocol.Instantiable;
7 import org.openflow.codec.util.U16;
8
9 public enum OFPTableFeaturePropType {
10
11     INSTRUCTIONS(0, new Instantiable<OFPTableFeaturePropHeader>() {
12         @Override
13         public OFPTableFeaturePropHeader instantiate() {
14             return new OFPTableFeaturePropInstructions();
15         }
16     }), INSTRUCTIONS_MISS(1, new Instantiable<OFPTableFeaturePropHeader>() {
17         @Override
18         public OFPTableFeaturePropHeader instantiate() {
19             return new OFPTableFeaturePropInstructionsMiss();
20         }
21     }), NEXT_TABLES(2, new Instantiable<OFPTableFeaturePropHeader>() {
22         @Override
23         public OFPTableFeaturePropHeader instantiate() {
24             return new OFPTableFeaturePropNextTables();
25         }
26     }), NEXT_TABLES_MISS(3, new Instantiable<OFPTableFeaturePropHeader>() {
27         @Override
28         public OFPTableFeaturePropHeader instantiate() {
29             return new OFPTableFeaturePropNextTablesMiss();
30         }
31     }), WRITE_ACTIONS(4, new Instantiable<OFPTableFeaturePropHeader>() {
32         @Override
33         public OFPTableFeaturePropHeader instantiate() {
34             return new OFPTableFeaturePropWriteActions();
35         }
36     }), WRITE_ACTIONS_MISS(5, new Instantiable<OFPTableFeaturePropHeader>() {
37         @Override
38         public OFPTableFeaturePropHeader instantiate() {
39             return new OFPTableFeaturePropWriteActionsMiss();
40         }
41     }), APPLY_ACTIONS(6, new Instantiable<OFPTableFeaturePropHeader>() {
42         @Override
43         public OFPTableFeaturePropHeader instantiate() {
44             return new OFPTableFeaturePropApplyActions();
45         }
46     }), APPLY_ACTIONS_MISS(7, new Instantiable<OFPTableFeaturePropHeader>() {
47         @Override
48         public OFPTableFeaturePropHeader instantiate() {
49             return new OFPTableFeaturePropApplyActionsMiss();
50         }
51     }), MATCH(8, new Instantiable<OFPTableFeaturePropHeader>() {
52         @Override
53         public OFPTableFeaturePropHeader instantiate() {
54             return new OFPTableFeaturePropMatch();
55         }
56     }), WILDCARDS(10, new Instantiable<OFPTableFeaturePropHeader>() {
57         @Override
58         public OFPTableFeaturePropHeader instantiate() {
59             return new OFPTableFeaturePropWildcards();
60         }
61     }), WRITE_SETFIELD(12, new Instantiable<OFPTableFeaturePropHeader>() {
62         @Override
63         public OFPTableFeaturePropHeader instantiate() {
64             return new OFPTableFeaturePropWriteSetField();
65         }
66     }), WRITE_SETFIELD_MISS(13, new Instantiable<OFPTableFeaturePropHeader>() {
67         @Override
68         public OFPTableFeaturePropHeader instantiate() {
69             return new OFPTableFeaturePropWriteSetFieldMiss();
70         }
71     }), APPLY_SETFIELD(14, new Instantiable<OFPTableFeaturePropHeader>() {
72         @Override
73         public OFPTableFeaturePropHeader instantiate() {
74             return new OFPTableFeaturePropApplySetField();
75         }
76     }), APPLY_SETFIELD_MISS(15, new Instantiable<OFPTableFeaturePropHeader>() {
77         @Override
78         public OFPTableFeaturePropHeader instantiate() {
79             return new OFPTableFeaturePropApplySetFieldMiss();
80         }
81     }),
82
83     EXPERIMENTER(0xFFFE, new Instantiable<OFPTableFeaturePropHeader>() {
84         @Override
85         public OFPTableFeaturePropHeader instantiate() {
86             return new OFPTableFeaturePropExperimenter();
87         }
88     }),
89
90     EXPERIMENTER_MISS(0xFFFF, new Instantiable<OFPTableFeaturePropHeader>() {
91         @Override
92         public OFPTableFeaturePropHeader instantiate() {
93             return new OFPTableFeaturePropExperimenterMiss();
94         }
95     });
96
97     private static Map<Integer, OFPTableFeaturePropType> mapping;
98
99     private short type;
100
101     private Instantiable<OFPTableFeaturePropHeader> instantiable;
102
103     /**
104      *
105      * @param type
106      */
107     OFPTableFeaturePropType(int type, Instantiable<OFPTableFeaturePropHeader> instantiable) {
108         this.setTypeValue((short) type);
109         OFPTableFeaturePropType.addMapping(type, this);
110         this.instantiable = instantiable;
111     }
112
113     /**
114      * add mapping to store
115      *
116      * @param type
117      * @param TableFeatureType
118      */
119     private static void addMapping(int type, OFPTableFeaturePropType TableFeatureType) {
120         if (null == mapping) {
121             mapping = new HashMap<Integer, OFPTableFeaturePropType>();
122         }
123         mapping.put(type, TableFeatureType);
124     }
125
126     /**
127      * get OFTableFeatureType correspond to value type
128      *
129      * @param type
130      * @return OFTableFeatureType
131      */
132     public static OFPTableFeaturePropType valueOf(short type) {
133         return mapping.get(U16.f(type));
134     }
135
136     /**
137      * get TableFeatureProp type value
138      *
139      * @return
140      */
141     public short getTypeValue() {
142         return type;
143     }
144
145     /**
146      * set TableFeatureProp type value
147      *
148      * @param type
149      */
150     public void setTypeValue(short type) {
151         this.type = type;
152     }
153
154     /**
155      * Returns a new instance of the OFPTableFeaturePropHeader represented by
156      * this OFPTableFeaturePropType
157      *
158      * @return the new object
159      */
160     public OFPTableFeaturePropHeader newInstance() {
161         return instantiable.instantiate();
162     }
163
164 }