2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
18 package org.openflow.protocol;
20 import java.lang.reflect.Constructor;
23 * List of OpenFlow types and mappings to wire protocol value and derived
26 * @author Rob Sherwood (rob.sherwood@stanford.edu)
27 * @author David Erickson (daviderickson@cs.stanford.edu)
31 HELLO (0, OFHello.class, new Instantiable<OFMessage>() {
33 public OFMessage instantiate() {
36 ERROR (1, OFError.class, new Instantiable<OFMessage>() {
38 public OFMessage instantiate() {
41 ECHO_REQUEST (2, OFEchoRequest.class, new Instantiable<OFMessage>() {
43 public OFMessage instantiate() {
44 return new OFEchoRequest();
46 ECHO_REPLY (3, OFEchoReply.class, new Instantiable<OFMessage>() {
48 public OFMessage instantiate() {
49 return new OFEchoReply();
51 VENDOR (4, OFVendor.class, new Instantiable<OFMessage>() {
53 public OFMessage instantiate() {
54 return new OFVendor();
56 FEATURES_REQUEST (5, OFFeaturesRequest.class, new Instantiable<OFMessage>() {
58 public OFMessage instantiate() {
59 return new OFFeaturesRequest();
61 FEATURES_REPLY (6, OFFeaturesReply.class, new Instantiable<OFMessage>() {
63 public OFMessage instantiate() {
64 return new OFFeaturesReply();
66 GET_CONFIG_REQUEST (7, OFGetConfigRequest.class, new Instantiable<OFMessage>() {
68 public OFMessage instantiate() {
69 return new OFGetConfigRequest();
71 GET_CONFIG_REPLY (8, OFGetConfigReply.class, new Instantiable<OFMessage>() {
73 public OFMessage instantiate() {
74 return new OFGetConfigReply();
76 SET_CONFIG (9, OFSetConfig.class, new Instantiable<OFMessage>() {
78 public OFMessage instantiate() {
79 return new OFSetConfig();
81 PACKET_IN (10, OFPacketIn.class, new Instantiable<OFMessage>() {
83 public OFMessage instantiate() {
84 return new OFPacketIn();
86 FLOW_REMOVED (11, OFFlowRemoved.class, new Instantiable<OFMessage>() {
88 public OFMessage instantiate() {
89 return new OFFlowRemoved();
91 PORT_STATUS (12, OFPortStatus.class, new Instantiable<OFMessage>() {
93 public OFMessage instantiate() {
94 return new OFPortStatus();
96 PACKET_OUT (13, OFPacketOut.class, new Instantiable<OFMessage>() {
98 public OFMessage instantiate() {
99 return new OFPacketOut();
101 FLOW_MOD (14, OFFlowMod.class, new Instantiable<OFMessage>() {
103 public OFMessage instantiate() {
104 return new OFFlowMod();
106 PORT_MOD (15, OFPortMod.class, new Instantiable<OFMessage>() {
108 public OFMessage instantiate() {
109 return new OFPortMod();
111 STATS_REQUEST (16, OFStatisticsRequest.class, new Instantiable<OFMessage>() {
113 public OFMessage instantiate() {
114 return new OFStatisticsRequest();
116 STATS_REPLY (17, OFStatisticsReply.class, new Instantiable<OFMessage>() {
118 public OFMessage instantiate() {
119 return new OFStatisticsReply();
121 BARRIER_REQUEST (18, OFBarrierRequest.class, new Instantiable<OFMessage>() {
123 public OFMessage instantiate() {
124 return new OFBarrierRequest();
126 BARRIER_REPLY (19, OFBarrierReply.class, new Instantiable<OFMessage>() {
128 public OFMessage instantiate() {
129 return new OFBarrierReply();
131 QUEUE_GET_CONFIG_REQUEST (20, OFQueueGetConfigRequest.class, new Instantiable<OFMessage>() {
133 public OFMessage instantiate() {
134 return new OFQueueGetConfigRequest();
136 QUEUE_GET_CONFIG_REPLY (21, OFQueueGetConfigReply.class, new Instantiable<OFMessage>() {
138 public OFMessage instantiate() {
139 return new OFQueueGetConfigReply();
142 static OFType[] mapping;
144 protected Class<? extends OFMessage> clazz;
145 protected Constructor<? extends OFMessage> constructor;
146 protected Instantiable<OFMessage> instantiable;
150 * Store some information about the OpenFlow type, including wire protocol
151 * type number, length, and derived class
153 * @param type Wire protocol number associated with this OFType
154 * @param clazz The Java class corresponding to this type of OpenFlow
156 * @param instantiator An Instantiator<OFMessage> implementation that creates an
157 * instance of the specified OFMessage
159 OFType(int type, Class<? extends OFMessage> clazz, Instantiable<OFMessage> instantiator) {
160 this.type = (byte) type;
162 this.instantiable = instantiator;
164 this.constructor = clazz.getConstructor(new Class[]{});
165 } catch (Exception e) {
166 throw new RuntimeException(
167 "Failure getting constructor for class: " + clazz, e);
169 OFType.addMapping(this.type, this);
173 * Adds a mapping from type value to OFType enum
175 * @param i OpenFlow wire protocol type
178 static public void addMapping(byte i, OFType t) {
180 mapping = new OFType[32];
181 OFType.mapping[i] = t;
185 * Remove a mapping from type value to OFType enum
187 * @param i OpenFlow wire protocol type
189 static public void removeMapping(byte i) {
190 OFType.mapping[i] = null;
194 * Given a wire protocol OpenFlow type number, return the OFType associated
197 * @param i wire protocol number
198 * @return OFType enum type
201 static public OFType valueOf(Byte i) {
202 return OFType.mapping[i];
206 * @return Returns the wire protocol value corresponding to this OFType
208 public byte getTypeValue() {
213 * @return return the OFMessage subclass corresponding to this OFType
215 public Class<? extends OFMessage> toClass() {
220 * Returns the no-argument Constructor of the implementation class for
222 * @return the constructor
224 public Constructor<? extends OFMessage> getConstructor() {
229 * Returns a new instance of the OFMessage represented by this OFType
230 * @return the new object
232 public OFMessage newInstance() {
233 return instantiable.instantiate();
237 * @return the instantiable
239 public Instantiable<OFMessage> getInstantiable() {
244 * @param instantiable the instantiable to set
246 public void setInstantiable(Instantiable<OFMessage> instantiable) {
247 this.instantiable = instantiable;