1 package org.openflow.protocol;
3 import java.lang.reflect.Constructor;
6 * List of OpenFlow types and mappings to wire protocol value and derived
9 * @author Rob Sherwood (rob.sherwood@stanford.edu)
10 * @author David Erickson (daviderickson@cs.stanford.edu)
14 HELLO (0, OFHello.class, new Instantiable<OFMessage>() {
16 public OFMessage instantiate() {
19 ERROR (1, OFError.class, new Instantiable<OFMessage>() {
21 public OFMessage instantiate() {
24 ECHO_REQUEST (2, OFEchoRequest.class, new Instantiable<OFMessage>() {
26 public OFMessage instantiate() {
27 return new OFEchoRequest();
29 ECHO_REPLY (3, OFEchoReply.class, new Instantiable<OFMessage>() {
31 public OFMessage instantiate() {
32 return new OFEchoReply();
34 VENDOR (4, OFVendor.class, new Instantiable<OFMessage>() {
36 public OFMessage instantiate() {
37 return new OFVendor();
39 FEATURES_REQUEST (5, OFFeaturesRequest.class, new Instantiable<OFMessage>() {
41 public OFMessage instantiate() {
42 return new OFFeaturesRequest();
44 FEATURES_REPLY (6, OFFeaturesReply.class, new Instantiable<OFMessage>() {
46 public OFMessage instantiate() {
47 return new OFFeaturesReply();
49 GET_CONFIG_REQUEST (7, OFGetConfigRequest.class, new Instantiable<OFMessage>() {
51 public OFMessage instantiate() {
52 return new OFGetConfigRequest();
54 GET_CONFIG_REPLY (8, OFGetConfigReply.class, new Instantiable<OFMessage>() {
56 public OFMessage instantiate() {
57 return new OFGetConfigReply();
59 SET_CONFIG (9, OFSetConfig.class, new Instantiable<OFMessage>() {
61 public OFMessage instantiate() {
62 return new OFSetConfig();
64 PACKET_IN (10, OFPacketIn.class, new Instantiable<OFMessage>() {
66 public OFMessage instantiate() {
67 return new OFPacketIn();
69 FLOW_REMOVED (11, OFFlowRemoved.class, new Instantiable<OFMessage>() {
71 public OFMessage instantiate() {
72 return new OFFlowRemoved();
74 PORT_STATUS (12, OFPortStatus.class, new Instantiable<OFMessage>() {
76 public OFMessage instantiate() {
77 return new OFPortStatus();
79 PACKET_OUT (13, OFPacketOut.class, new Instantiable<OFMessage>() {
81 public OFMessage instantiate() {
82 return new OFPacketOut();
84 FLOW_MOD (14, OFFlowMod.class, new Instantiable<OFMessage>() {
86 public OFMessage instantiate() {
87 return new OFFlowMod();
89 PORT_MOD (15, OFPortMod.class, new Instantiable<OFMessage>() {
91 public OFMessage instantiate() {
92 return new OFPortMod();
94 STATS_REQUEST (16, OFStatisticsRequest.class, new Instantiable<OFMessage>() {
96 public OFMessage instantiate() {
97 return new OFStatisticsRequest();
99 STATS_REPLY (17, OFStatisticsReply.class, new Instantiable<OFMessage>() {
101 public OFMessage instantiate() {
102 return new OFStatisticsReply();
104 BARRIER_REQUEST (18, OFBarrierRequest.class, new Instantiable<OFMessage>() {
106 public OFMessage instantiate() {
107 return new OFBarrierRequest();
109 BARRIER_REPLY (19, OFBarrierReply.class, new Instantiable<OFMessage>() {
111 public OFMessage instantiate() {
112 return new OFBarrierReply();
114 QUEUE_CONFIG_REQUEST (20, OFMessage.class, new Instantiable<OFMessage>() {
116 public OFMessage instantiate() {
117 return new OFQueueConfigRequest();
119 QUEUE_CONFIG_REPLY (21, OFMessage.class, new Instantiable<OFMessage>() {
121 public OFMessage instantiate() {
122 return new OFQueueConfigReply();
125 static OFType[] mapping;
127 protected Class<? extends OFMessage> clazz;
128 protected Constructor<? extends OFMessage> constructor;
129 protected Instantiable<OFMessage> instantiable;
133 * Store some information about the OpenFlow type, including wire protocol
134 * type number, length, and derived class
136 * @param type Wire protocol number associated with this OFType
137 * @param requestClass The Java class corresponding to this type of OpenFlow
139 * @param instantiator An Instantiator<OFMessage> implementation that creates an
140 * instance of the specified OFMessage
142 OFType(int type, Class<? extends OFMessage> clazz, Instantiable<OFMessage> instantiator) {
143 this.type = (byte) type;
145 this.instantiable = instantiator;
147 this.constructor = clazz.getConstructor(new Class[]{});
148 } catch (Exception e) {
149 throw new RuntimeException(
150 "Failure getting constructor for class: " + clazz, e);
152 OFType.addMapping(this.type, this);
156 * Adds a mapping from type value to OFType enum
158 * @param i OpenFlow wire protocol type
161 public static void addMapping(byte i, OFType t) {
163 mapping = new OFType[32];
164 OFType.mapping[i] = t;
168 * Remove a mapping from type value to OFType enum
170 * @param i OpenFlow wire protocol type
172 public static void removeMapping(byte i) {
173 OFType.mapping[i] = null;
177 * Given a wire protocol OpenFlow type number, return the OFType associated
180 * @param i wire protocol number
181 * @return OFType enum type
184 public static OFType valueOf(Byte i) {
185 return OFType.mapping[i];
189 * @return Returns the wire protocol value corresponding to this OFType
191 public byte getTypeValue() {
196 * @return return the OFMessage subclass corresponding to this OFType
198 public Class<? extends OFMessage> toClass() {
203 * Returns the no-argument Constructor of the implementation class for
205 * @return the constructor
207 public Constructor<? extends OFMessage> getConstructor() {
212 * Returns a new instance of the OFMessage represented by this OFType
213 * @return the new object
215 public OFMessage newInstance() {
216 return instantiable.instantiate();
220 * @return the instantiable
222 public Instantiable<OFMessage> getInstantiable() {
227 * @param instantiable the instantiable to set
229 public void setInstantiable(Instantiable<OFMessage> instantiable) {
230 this.instantiable = instantiable;