1 package org.openflow.protocol.statistics;
3 import java.lang.reflect.Constructor;
5 import org.openflow.protocol.Instantiable;
6 import org.openflow.protocol.OFType;
8 public enum OFStatisticsType {
9 DESC (0, OFDescriptionStatistics.class, OFDescriptionStatistics.class,
10 new Instantiable<OFStatistics>() {
12 public OFStatistics instantiate() {
13 return new OFDescriptionStatistics();
16 new Instantiable<OFStatistics>() {
18 public OFStatistics instantiate() {
19 return new OFDescriptionStatistics();
22 FLOW (1, OFFlowStatisticsRequest.class, OFFlowStatisticsReply.class,
23 new Instantiable<OFStatistics>() {
25 public OFStatistics instantiate() {
26 return new OFFlowStatisticsRequest();
29 new Instantiable<OFStatistics>() {
31 public OFStatistics instantiate() {
32 return new OFFlowStatisticsReply();
35 AGGREGATE (2, OFAggregateStatisticsRequest.class, OFAggregateStatisticsReply.class,
36 new Instantiable<OFStatistics>() {
38 public OFStatistics instantiate() {
39 return new OFAggregateStatisticsRequest();
42 new Instantiable<OFStatistics>() {
44 public OFStatistics instantiate() {
45 return new OFAggregateStatisticsReply();
48 TABLE (3, OFTableStatistics.class, OFTableStatistics.class,
49 new Instantiable<OFStatistics>() {
51 public OFStatistics instantiate() {
52 return new OFTableStatistics();
55 new Instantiable<OFStatistics>() {
57 public OFStatistics instantiate() {
58 return new OFTableStatistics();
61 PORT (4, OFPortStatisticsRequest.class, OFPortStatisticsReply.class,
62 new Instantiable<OFStatistics>() {
64 public OFStatistics instantiate() {
65 return new OFPortStatisticsRequest();
68 new Instantiable<OFStatistics>() {
70 public OFStatistics instantiate() {
71 return new OFPortStatisticsReply();
74 QUEUE (5, OFQueueStatisticsRequest.class, OFQueueStatisticsReply.class,
75 new Instantiable<OFStatistics>() {
77 public OFStatistics instantiate() {
78 return new OFQueueStatisticsRequest();
81 new Instantiable<OFStatistics>() {
83 public OFStatistics instantiate() {
84 return new OFQueueStatisticsReply();
87 VENDOR (0xffff, OFVendorStatistics.class, OFVendorStatistics.class,
88 new Instantiable<OFStatistics>() {
90 public OFStatistics instantiate() {
91 return new OFVendorStatistics();
94 new Instantiable<OFStatistics>() {
96 public OFStatistics instantiate() {
97 return new OFVendorStatistics();
101 static OFStatisticsType[] requestMapping;
102 static OFStatisticsType[] replyMapping;
104 protected Class<? extends OFStatistics> requestClass;
105 protected Constructor<? extends OFStatistics> requestConstructor;
106 protected Instantiable<OFStatistics> requestInstantiable;
107 protected Class<? extends OFStatistics> replyClass;
108 protected Constructor<? extends OFStatistics> replyConstructor;
109 protected Instantiable<OFStatistics> replyInstantiable;
110 protected short type;
113 * Store some information about the OpenFlow Statistic type, including wire
114 * protocol type number, and derived class
116 * @param type Wire protocol number associated with this OFStatisticsType
117 * @param requestClass The Statistics Java class to return when the
118 * containing OFType is STATS_REQUEST
119 * @param replyClass The Statistics Java class to return when the
120 * containing OFType is STATS_REPLY
122 OFStatisticsType(int type, Class<? extends OFStatistics> requestClass,
123 Class<? extends OFStatistics> replyClass,
124 Instantiable<OFStatistics> requestInstantiable,
125 Instantiable<OFStatistics> replyInstantiable) {
126 this.type = (short) type;
127 this.requestClass = requestClass;
129 this.requestConstructor = requestClass.getConstructor(new Class[]{});
130 } catch (Exception e) {
131 throw new RuntimeException(
132 "Failure getting constructor for class: " + requestClass, e);
135 this.replyClass = replyClass;
137 this.replyConstructor = replyClass.getConstructor(new Class[]{});
138 } catch (Exception e) {
139 throw new RuntimeException(
140 "Failure getting constructor for class: " + replyClass, e);
142 this.requestInstantiable = requestInstantiable;
143 this.replyInstantiable = replyInstantiable;
144 OFStatisticsType.addMapping(this.type, OFType.STATS_REQUEST, this);
145 OFStatisticsType.addMapping(this.type, OFType.STATS_REPLY, this);
149 * Adds a mapping from type value to OFStatisticsType enum
151 * @param i OpenFlow wire protocol type
152 * @param t type of containing OFMessage, only accepts STATS_REQUEST or
156 static public void addMapping(short i, OFType t, OFStatisticsType st) {
159 if (t == OFType.STATS_REQUEST) {
160 if (requestMapping == null)
161 requestMapping = new OFStatisticsType[16];
162 OFStatisticsType.requestMapping[i] = st;
163 } else if (t == OFType.STATS_REPLY){
164 if (replyMapping == null)
165 replyMapping = new OFStatisticsType[16];
166 OFStatisticsType.replyMapping[i] = st;
168 throw new RuntimeException(t.toString() + " is an invalid OFType");
173 * Remove a mapping from type value to OFStatisticsType enum
175 * @param i OpenFlow wire protocol type
176 * @param t type of containing OFMessage, only accepts STATS_REQUEST or
179 static public void removeMapping(short i, OFType t) {
182 if (t == OFType.STATS_REQUEST) {
183 requestMapping[i] = null;
184 } else if (t == OFType.STATS_REPLY){
185 replyMapping[i] = null;
187 throw new RuntimeException(t.toString() + " is an invalid OFType");
192 * Given a wire protocol OpenFlow type number, return the OFStatisticsType
195 * @param i wire protocol number
196 * @param t type of containing OFMessage, only accepts STATS_REQUEST or
198 * @return OFStatisticsType enum type
200 static public OFStatisticsType valueOf(short i, OFType t) {
203 if (t == OFType.STATS_REQUEST) {
204 return requestMapping[i];
205 } else if (t == OFType.STATS_REPLY){
206 return replyMapping[i];
208 throw new RuntimeException(t.toString() + " is an invalid OFType");
213 * @return Returns the wire protocol value corresponding to this
216 public short getTypeValue() {
221 * @param t type of containing OFMessage, only accepts STATS_REQUEST or
223 * @return return the OFMessage subclass corresponding to this
226 public Class<? extends OFStatistics> toClass(OFType t) {
227 if (t == OFType.STATS_REQUEST) {
229 } else if (t == OFType.STATS_REPLY){
232 throw new RuntimeException(t.toString() + " is an invalid OFType");
237 * Returns the no-argument Constructor of the implementation class for
238 * this OFStatisticsType, either request or reply based on the supplied
244 public Constructor<? extends OFStatistics> getConstructor(OFType t) {
245 if (t == OFType.STATS_REQUEST) {
246 return requestConstructor;
247 } else if (t == OFType.STATS_REPLY) {
248 return replyConstructor;
250 throw new RuntimeException(t.toString() + " is an invalid OFType");
255 * @return the requestInstantiable
257 public Instantiable<OFStatistics> getRequestInstantiable() {
258 return requestInstantiable;
262 * @param requestInstantiable the requestInstantiable to set
264 public void setRequestInstantiable(
265 Instantiable<OFStatistics> requestInstantiable) {
266 this.requestInstantiable = requestInstantiable;
270 * @return the replyInstantiable
272 public Instantiable<OFStatistics> getReplyInstantiable() {
273 return replyInstantiable;
277 * @param replyInstantiable the replyInstantiable to set
279 public void setReplyInstantiable(Instantiable<OFStatistics> replyInstantiable) {
280 this.replyInstantiable = replyInstantiable;
284 * Returns a new instance of the implementation class for
285 * this OFStatisticsType, either request or reply based on the supplied
291 public OFStatistics newInstance(OFType t) {
292 if (t == OFType.STATS_REQUEST) {
293 return requestInstantiable.instantiate();
294 } else if (t == OFType.STATS_REPLY) {
295 return replyInstantiable.instantiate();
297 throw new RuntimeException(t.toString() + " is an invalid OFType");