X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=third-party%2Fopenflowj%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fprotocol%2Faction%2FOFActionType.java;fp=third-party%2Fopenflowj%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fprotocol%2Faction%2FOFActionType.java;h=211752e0ea25af533aa837af36861f3360b03cda;hp=0000000000000000000000000000000000000000;hb=42210c03b0a4c54706320ba9f55794c0abd4d201;hpb=7576b38152b393793b1c9ec3df0ff86685f95236;ds=sidebyside diff --git a/third-party/openflowj/src/main/java/org/openflow/protocol/action/OFActionType.java b/third-party/openflowj/src/main/java/org/openflow/protocol/action/OFActionType.java new file mode 100644 index 0000000000..211752e0ea --- /dev/null +++ b/third-party/openflowj/src/main/java/org/openflow/protocol/action/OFActionType.java @@ -0,0 +1,187 @@ +/** + * + */ +package org.openflow.protocol.action; + +import java.io.Serializable; +import java.lang.reflect.Constructor; + +import org.openflow.protocol.Instantiable; + +/** + * List of OpenFlow Action types and mappings to wire protocol value and + * derived classes + * + * @author David Erickson (daviderickson@cs.stanford.edu) + */ +public enum OFActionType implements Serializable{ + OUTPUT (0, OFActionOutput.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionOutput(); + }}), + SET_VLAN_VID (1, OFActionVirtualLanIdentifier.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionVirtualLanIdentifier(); + }}), + SET_VLAN_PCP (2, OFActionVirtualLanPriorityCodePoint.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionVirtualLanPriorityCodePoint(); + }}), + STRIP_VLAN (3, OFActionStripVirtualLan.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionStripVirtualLan(); + }}), + SET_DL_SRC (4, OFActionDataLayerSource.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionDataLayerSource(); + }}), + SET_DL_DST (5, OFActionDataLayerDestination.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionDataLayerDestination(); + }}), + SET_NW_SRC (6, OFActionNetworkLayerSource.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionNetworkLayerSource(); + }}), + SET_NW_DST (7, OFActionNetworkLayerDestination.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionNetworkLayerDestination(); + }}), + SET_NW_TOS (8, OFActionNetworkTypeOfService.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionNetworkTypeOfService(); + }}), + SET_TP_SRC (9, OFActionTransportLayerSource.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionTransportLayerSource(); + }}), + SET_TP_DST (10, OFActionTransportLayerDestination.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionTransportLayerDestination(); + }}), + OPAQUE_ENQUEUE (11, OFActionEnqueue.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionEnqueue(); + }}), + VENDOR (0xffff, OFActionVendor.class, new Instantiable() { + @Override + public OFAction instantiate() { + return new OFActionVendor(); + }}); + + protected static OFActionType[] mapping; + + protected Class clazz; + protected Constructor constructor; + protected Instantiable instantiable; + protected int minLen; + protected short type; + + /** + * Store some information about the OpenFlow Action type, including wire + * protocol type number, length, and derrived class + * + * @param type Wire protocol number associated with this OFType + * @param clazz The Java class corresponding to this type of OpenFlow Action + * @param instantiable the instantiable for the OFAction this type represents + */ + OFActionType(int type, Class clazz, Instantiable instantiable) { + this.type = (short) type; + this.clazz = clazz; + this.instantiable = instantiable; + try { + this.constructor = clazz.getConstructor(new Class[]{}); + } catch (Exception e) { + throw new RuntimeException( + "Failure getting constructor for class: " + clazz, e); + } + OFActionType.addMapping(this.type, this); + } + + /** + * Adds a mapping from type value to OFActionType enum + * + * @param i OpenFlow wire protocol Action type value + * @param t type + */ + static public void addMapping(short i, OFActionType t) { + if (mapping == null) + mapping = new OFActionType[16]; + // bring higher mappings down to the edge of our array + if (i < 0) + i = (short) (16 + i); + OFActionType.mapping[i] = t; + } + + /** + * Given a wire protocol OpenFlow type number, return the OFType associated + * with it + * + * @param i wire protocol number + * @return OFType enum type + */ + + static public OFActionType valueOf(short i) { + if (i < 0) + i = (short) (16+i); + return OFActionType.mapping[i]; + } + + /** + * @return Returns the wire protocol value corresponding to this + * OFActionType + */ + public short getTypeValue() { + return this.type; + } + + /** + * @return return the OFAction subclass corresponding to this OFActionType + */ + public Class toClass() { + return clazz; + } + + /** + * Returns the no-argument Constructor of the implementation class for + * this OFActionType + * @return the constructor + */ + public Constructor getConstructor() { + return constructor; + } + + /** + * Returns a new instance of the OFAction represented by this OFActionType + * @return the new object + */ + public OFAction newInstance() { + return instantiable.instantiate(); + } + + /** + * @return the instantiable + */ + public Instantiable getInstantiable() { + return instantiable; + } + + /** + * @param instantiable the instantiable to set + */ + public void setInstantiable(Instantiable instantiable) { + this.instantiable = instantiable; + } +}