4 package org.openflow.protocol.action;
6 import java.io.Serializable;
7 import java.lang.reflect.Constructor;
9 import org.openflow.protocol.Instantiable;
12 * List of OpenFlow Action types and mappings to wire protocol value and
15 * @author David Erickson (daviderickson@cs.stanford.edu)
17 public enum OFActionType implements Serializable{
18 OUTPUT (0, OFActionOutput.class, new Instantiable<OFAction>() {
20 public OFAction instantiate() {
21 return new OFActionOutput();
23 SET_VLAN_VID (1, OFActionVirtualLanIdentifier.class, new Instantiable<OFAction>() {
25 public OFAction instantiate() {
26 return new OFActionVirtualLanIdentifier();
28 SET_VLAN_PCP (2, OFActionVirtualLanPriorityCodePoint.class, new Instantiable<OFAction>() {
30 public OFAction instantiate() {
31 return new OFActionVirtualLanPriorityCodePoint();
33 STRIP_VLAN (3, OFActionStripVirtualLan.class, new Instantiable<OFAction>() {
35 public OFAction instantiate() {
36 return new OFActionStripVirtualLan();
38 SET_DL_SRC (4, OFActionDataLayerSource.class, new Instantiable<OFAction>() {
40 public OFAction instantiate() {
41 return new OFActionDataLayerSource();
43 SET_DL_DST (5, OFActionDataLayerDestination.class, new Instantiable<OFAction>() {
45 public OFAction instantiate() {
46 return new OFActionDataLayerDestination();
48 SET_NW_SRC (6, OFActionNetworkLayerSource.class, new Instantiable<OFAction>() {
50 public OFAction instantiate() {
51 return new OFActionNetworkLayerSource();
53 SET_NW_DST (7, OFActionNetworkLayerDestination.class, new Instantiable<OFAction>() {
55 public OFAction instantiate() {
56 return new OFActionNetworkLayerDestination();
58 SET_NW_TOS (8, OFActionNetworkTypeOfService.class, new Instantiable<OFAction>() {
60 public OFAction instantiate() {
61 return new OFActionNetworkTypeOfService();
63 SET_TP_SRC (9, OFActionTransportLayerSource.class, new Instantiable<OFAction>() {
65 public OFAction instantiate() {
66 return new OFActionTransportLayerSource();
68 SET_TP_DST (10, OFActionTransportLayerDestination.class, new Instantiable<OFAction>() {
70 public OFAction instantiate() {
71 return new OFActionTransportLayerDestination();
73 OPAQUE_ENQUEUE (11, OFActionEnqueue.class, new Instantiable<OFAction>() {
75 public OFAction instantiate() {
76 return new OFActionEnqueue();
78 VENDOR (0xffff, OFActionVendor.class, new Instantiable<OFAction>() {
80 public OFAction instantiate() {
81 return new OFActionVendor();
84 protected static OFActionType[] mapping;
86 protected Class<? extends OFAction> clazz;
87 protected Constructor<? extends OFAction> constructor;
88 protected Instantiable<OFAction> instantiable;
93 * Store some information about the OpenFlow Action type, including wire
94 * protocol type number, length, and derrived class
96 * @param type Wire protocol number associated with this OFType
97 * @param clazz The Java class corresponding to this type of OpenFlow Action
98 * @param instantiable the instantiable for the OFAction this type represents
100 OFActionType(int type, Class<? extends OFAction> clazz, Instantiable<OFAction> instantiable) {
101 this.type = (short) type;
103 this.instantiable = instantiable;
105 this.constructor = clazz.getConstructor(new Class[]{});
106 } catch (Exception e) {
107 throw new RuntimeException(
108 "Failure getting constructor for class: " + clazz, e);
110 OFActionType.addMapping(this.type, this);
114 * Adds a mapping from type value to OFActionType enum
116 * @param i OpenFlow wire protocol Action type value
119 static public void addMapping(short i, OFActionType t) {
121 mapping = new OFActionType[16];
122 // bring higher mappings down to the edge of our array
124 i = (short) (16 + i);
125 OFActionType.mapping[i] = t;
129 * Given a wire protocol OpenFlow type number, return the OFType associated
132 * @param i wire protocol number
133 * @return OFType enum type
136 static public OFActionType valueOf(short i) {
139 return OFActionType.mapping[i];
143 * @return Returns the wire protocol value corresponding to this
146 public short getTypeValue() {
151 * @return return the OFAction subclass corresponding to this OFActionType
153 public Class<? extends OFAction> toClass() {
158 * Returns the no-argument Constructor of the implementation class for
160 * @return the constructor
162 public Constructor<? extends OFAction> getConstructor() {
167 * Returns a new instance of the OFAction represented by this OFActionType
168 * @return the new object
170 public OFAction newInstance() {
171 return instantiable.instantiate();
175 * @return the instantiable
177 public Instantiable<OFAction> getInstantiable() {
182 * @param instantiable the instantiable to set
184 public void setInstantiable(Instantiable<OFAction> instantiable) {
185 this.instantiable = instantiable;