4 package org.openflow.codec.protocol.action;
6 import java.io.Serializable;
7 import java.lang.reflect.Constructor;
8 import java.util.HashMap;
11 import org.openflow.codec.protocol.Instantiable;
14 * List of OpenFlow Action types and mappings to wire protocol value and derived
17 * @author David Erickson (daviderickson@cs.stanford.edu)
18 * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
20 public enum OFPActionType implements Serializable {
21 OUTPUT(0, OFPActionOutput.class, new Instantiable<OFPAction>() {
23 public OFPAction instantiate() {
24 return new OFPActionOutput();
26 }), COPY_TTL_OUT(11, OFPActionCopyTimeToLiveOut.class, new Instantiable<OFPAction>() {
28 public OFPAction instantiate() {
29 return new OFPActionCopyTimeToLiveOut();
31 }), COPY_TTL_IN(12, OFPActionCopyTimeToLiveIn.class, new Instantiable<OFPAction>() {
33 public OFPAction instantiate() {
34 return new OFPActionCopyTimeToLiveIn();
36 }), SET_MPLS_TTL(15, OFPActionMplsTimeToLive.class, new Instantiable<OFPAction>() {
38 public OFPAction instantiate() {
39 return new OFPActionMplsTimeToLive();
41 }), DEC_MPLS_TTL(16, OFPActionDecMplsTimeToLive.class, new Instantiable<OFPAction>() {
43 public OFPAction instantiate() {
44 return new OFPActionDecMplsTimeToLive();
46 }), PUSH_VLAN(17, OFPActionPushVLAN.class, new Instantiable<OFPAction>() {
48 public OFPAction instantiate() {
49 return new OFPActionPushVLAN();
51 }), POP_VLAN(18, OFPActionPopVLAN.class, new Instantiable<OFPAction>() {
53 public OFPAction instantiate() {
54 return new OFPActionPopVLAN();
56 }), PUSH_MPLS(19, OFPActionPushMpls.class, new Instantiable<OFPAction>() {
58 public OFPAction instantiate() {
59 return new OFPActionPushMpls();
61 }), POP_MPLS(20, OFPActionPopMpls.class, new Instantiable<OFPAction>() {
63 public OFPAction instantiate() {
64 return new OFPActionPopMpls();
66 }), SET_QUEUE(21, OFPActionSetQueue.class, new Instantiable<OFPAction>() {
68 public OFPAction instantiate() {
69 return new OFPActionSetQueue();
71 }), GROUP(22, OFPActionGroup.class, new Instantiable<OFPAction>() {
73 public OFPAction instantiate() {
74 return new OFPActionGroup();
76 }), SET_NW_TTL(23, OFPActionNetworkTimeToLive.class, new Instantiable<OFPAction>() {
78 public OFPAction instantiate() {
79 return new OFPActionNetworkTimeToLive();
81 }), DEC_NW_TTL(24, OFPActionDecNetworkTimeToLive.class, new Instantiable<OFPAction>() {
83 public OFPAction instantiate() {
84 return new OFPActionDecNetworkTimeToLive();
86 }), SET_FIELD(25, OFPActionSetField.class, new Instantiable<OFPAction>() {
88 public OFPAction instantiate() {
89 return new OFPActionSetField();
91 }), PUSH_PBB(26, OFPActionPushPbb.class, new Instantiable<OFPAction>() {
93 public OFPAction instantiate() {
94 return new OFPActionPushPbb();
96 }), POP_PBB(27, OFPActionPopPbb.class, new Instantiable<OFPAction>() {
98 public OFPAction instantiate() {
99 return new OFPActionPopPbb();
103 EXPERIMENTER(0xffff, OFPActionExperimenterHeader.class, new Instantiable<OFPAction>() {
105 public OFPAction instantiate() {
106 return new OFPActionExperimenterHeader();
110 protected static HashMap<Short, OFPActionType> mapping;
112 protected Class<? extends OFPAction> clazz;
113 protected Constructor<? extends OFPAction> constructor;
114 protected Instantiable<OFPAction> instantiable;
115 protected int minLen;
116 protected short type;
119 * Store some information about the OpenFlow Action type, including wire
120 * protocol type number, length, and derrived class
123 * Wire protocol number associated with this OFPType
125 * The Java class corresponding to this type of OpenFlow Action
126 * @param instantiable
127 * the instantiable for the OFPAction this type represents
129 OFPActionType(int type, Class<? extends OFPAction> clazz, Instantiable<OFPAction> instantiable) {
130 this.type = (short) type;
132 this.instantiable = instantiable;
134 this.constructor = clazz.getConstructor(new Class[] {});
135 } catch (Exception e) {
136 throw new RuntimeException("Failure getting constructor for class: " + clazz, e);
138 OFPActionType.addMapping(this.type, this);
142 * Adds a mapping from type value to OFPActionType enum
145 * OpenFlow wire protocol Action type value
149 static public void addMapping(short i, OFPActionType t) {
151 mapping = new HashMap<Short, OFPActionType>();
152 // bring higher mappings down to the edge of our map
154 i = (short) (30 + i);
159 * Given a wire protocol OpenFlow type number, return the OFPType associated
163 * wire protocol number
164 * @return OFPType enum type
167 static public OFPActionType valueOf(short i) {
169 i = (short) (30 + i);
170 return OFPActionType.mapping.get(i);
174 * @return Returns the wire protocol value corresponding to this
177 public short getTypeValue() {
182 * @return return the OFPAction subclass corresponding to this OFPActionType
184 public Class<? extends OFPAction> toClass() {
189 * Returns the no-argument Constructor of the implementation class for this
192 * @return the constructor
194 public Constructor<? extends OFPAction> getConstructor() {
199 * Returns a new instance of the OFPAction represented by this OFPActionType
201 * @return the new object
203 public OFPAction newInstance() {
204 return instantiable.instantiate();
208 * @return the instantiable
210 public Instantiable<OFPAction> getInstantiable() {
215 * @param instantiable
216 * the instantiable to set
218 public void setInstantiable(Instantiable<OFPAction> instantiable) {
219 this.instantiable = instantiable;