4 package org.openflow.protocol.queue;
6 import java.lang.reflect.Constructor;
8 import org.openflow.protocol.Instantiable;
11 * List of OpenFlow Queue Property types and mappings to wire protocol value and
14 * @author David Erickson (daviderickson@cs.stanford.edu)
16 public class OFQueuePropertyType {
17 public static OFQueuePropertyType NONE = new OFQueuePropertyType(0, "NONE",
18 OFQueueProperty.class, new Instantiable<OFQueueProperty>() {
20 public OFQueueProperty instantiate() {
21 return new OFQueueProperty();
25 public static OFQueuePropertyType MIN_RATE = new OFQueuePropertyType(1, "MIN_RATE",
26 OFQueuePropertyMinRate.class, new Instantiable<OFQueueProperty>() {
28 public OFQueueProperty instantiate() {
29 return new OFQueuePropertyMinRate();
33 protected static OFQueuePropertyType[] mapping;
35 protected Class<? extends OFQueueProperty> clazz;
36 protected Constructor<? extends OFQueueProperty> constructor;
37 protected Instantiable<OFQueueProperty> instantiable;
39 protected String name;
43 * Store some information about the OpenFlow Queue Property type, including wire
44 * protocol type number, length, and derived class
46 * @param type Wire protocol number associated with this OFQueuePropertyType
47 * @param name The name of this type
48 * @param clazz The Java class corresponding to this type of OpenFlow Queue Property
49 * @param instantiable the instantiable for the OFQueueProperty this type represents
51 OFQueuePropertyType(int type, String name, Class<? extends OFQueueProperty> clazz, Instantiable<OFQueueProperty> instantiable) {
52 this.type = (short) type;
55 this.instantiable = instantiable;
57 this.constructor = clazz.getConstructor(new Class[]{});
58 } catch (Exception e) {
59 throw new RuntimeException(
60 "Failure getting constructor for class: " + clazz, e);
62 OFQueuePropertyType.addMapping(this.type, this);
66 * Adds a mapping from type value to OFQueuePropertyType enum
68 * @param i OpenFlow wire protocol Action type value
71 static public void addMapping(short i, OFQueuePropertyType t) {
73 mapping = new OFQueuePropertyType[16];
74 OFQueuePropertyType.mapping[i] = t;
78 * Given a wire protocol OpenFlow type number, return the OFType associated
81 * @param i wire protocol number
82 * @return OFType enum type
85 static public OFQueuePropertyType valueOf(short i) {
86 return OFQueuePropertyType.mapping[i];
90 * @return Returns the wire protocol value corresponding to this
93 public short getTypeValue() {
98 * @return return the OFQueueProperty subclass corresponding to this OFQueuePropertyType
100 public Class<? extends OFQueueProperty> toClass() {
105 * Returns the no-argument Constructor of the implementation class for
106 * this OFQueuePropertyType
107 * @return the constructor
109 public Constructor<? extends OFQueueProperty> getConstructor() {
114 * Returns a new instance of the OFQueueProperty represented by this OFQueuePropertyType
115 * @return the new object
117 public OFQueueProperty newInstance() {
118 return instantiable.instantiate();
122 * @return the instantiable
124 public Instantiable<OFQueueProperty> getInstantiable() {
129 * @param instantiable the instantiable to set
131 public void setInstantiable(Instantiable<OFQueueProperty> instantiable) {
132 this.instantiable = instantiable;
135 public String getName() {
140 public String toString() {