4 package org.openflow.codec.protocol.queue;
6 import java.lang.reflect.Constructor;
7 import java.util.HashMap;
10 import org.openflow.codec.protocol.Instantiable;
11 import org.openflow.codec.util.U16;
14 * List of OpenFlow Queue Property types and mappings to wire protocol value and
17 * @author David Erickson (daviderickson@cs.stanford.edu)
19 public class OFPQueuePropertyType {
21 public static OFPQueuePropertyType MIN_RATE = new OFPQueuePropertyType(1, "MIN_RATE",
22 OFPQueuePropertyMinRate.class, new Instantiable<OFPQueueProperty>() {
24 public OFPQueueProperty instantiate() {
25 return new OFPQueuePropertyMinRate();
28 public static OFPQueuePropertyType MAX_RATE = new OFPQueuePropertyType(2, "MAX_RATE",
29 OFPQueuePropertyMaxRate.class, new Instantiable<OFPQueueProperty>() {
31 public OFPQueueProperty instantiate() {
32 return new OFPQueuePropertyMaxRate();
35 public static OFPQueuePropertyType EXPERIMENTER = new OFPQueuePropertyType(0xffff, "EXPERIMENTER",
36 OFPQueuePropertyExperimenter.class, new Instantiable<OFPQueueProperty>() {
38 public OFPQueueProperty instantiate() {
39 return new OFPQueuePropertyExperimenter();
43 protected static Map<Integer, OFPQueuePropertyType> mapping;
45 protected Class<? extends OFPQueueProperty> clazz;
46 protected Constructor<? extends OFPQueueProperty> constructor;
47 protected Instantiable<OFPQueueProperty> instantiable;
49 protected String name;
53 * Store some information about the OpenFlow Queue Property type, including
54 * wire protocol type number, length, and derived class
57 * Wire protocol number associated with this OFPQueuePropertyType
59 * The name of this type
61 * The Java class corresponding to this type of OpenFlow Queue
64 * the instantiable for the OFPQueueProperty this type represents
66 OFPQueuePropertyType(int type, String name, Class<? extends OFPQueueProperty> clazz,
67 Instantiable<OFPQueueProperty> instantiable) {
68 this.type = (short) type;
71 this.instantiable = instantiable;
73 this.constructor = clazz.getConstructor(new Class[] {});
74 } catch (Exception e) {
75 throw new RuntimeException("Failure getting constructor for class: " + clazz, e);
77 OFPQueuePropertyType.addMapping(type, this);
81 * Adds a mapping from type value to OFPQueuePropertyType enum
84 * OpenFlow wire protocol Action type value
88 static public void addMapping(int i, OFPQueuePropertyType t) {
90 mapping = new HashMap<Integer, OFPQueuePropertyType>();
91 OFPQueuePropertyType.mapping.put(i, t);
95 * Given a wire protocol OpenFlow type number, return the OFPType associated
99 * wire protocol number
100 * @return OFPType enum type
103 static public OFPQueuePropertyType valueOf(short i) {
104 return OFPQueuePropertyType.mapping.get(U16.f(i));
108 * @return Returns the wire protocol value corresponding to this
109 * OFPQueuePropertyType
111 public short getTypeValue() {
116 * @return return the OFPQueueProperty subclass corresponding to this
117 * OFPQueuePropertyType
119 public Class<? extends OFPQueueProperty> toClass() {
124 * Returns the no-argument Constructor of the implementation class for this
125 * OFPQueuePropertyType
127 * @return the constructor
129 public Constructor<? extends OFPQueueProperty> getConstructor() {
134 * Returns a new instance of the OFPQueueProperty represented by this
135 * OFPQueuePropertyType
137 * @return the new object
139 public OFPQueueProperty newInstance() {
140 return instantiable.instantiate();
144 * @return the instantiable
146 public Instantiable<OFPQueueProperty> getInstantiable() {
151 * @param instantiable
152 * the instantiable to set
154 public void setInstantiable(Instantiable<OFPQueueProperty> instantiable) {
155 this.instantiable = instantiable;
158 public String getName() {
163 public String toString() {