Merge "Bug 2347: DOMConcurrentDataCommitCoordinator uses wrong phase name"
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / action / OFActionType.java
1 /**
2  *
3  */
4 package org.openflow.protocol.action;
5
6 import java.io.Serializable;
7 import java.lang.reflect.Constructor;
8
9 import org.openflow.protocol.Instantiable;
10
11 /**
12  * List of OpenFlow Action types and mappings to wire protocol value and
13  * derived classes
14  *
15  * @author David Erickson (daviderickson@cs.stanford.edu)
16  */
17 public enum OFActionType implements Serializable{
18     OUTPUT              (0, OFActionOutput.class, new Instantiable<OFAction>() {
19                             @Override
20                             public OFAction instantiate() {
21                                 return new OFActionOutput();
22                             }}),
23     SET_VLAN_VID        (1, OFActionVirtualLanIdentifier.class, new Instantiable<OFAction>() {
24                             @Override
25                             public OFAction instantiate() {
26                                 return new OFActionVirtualLanIdentifier();
27                             }}),
28     SET_VLAN_PCP        (2, OFActionVirtualLanPriorityCodePoint.class, new Instantiable<OFAction>() {
29                             @Override
30                             public OFAction instantiate() {
31                                 return new OFActionVirtualLanPriorityCodePoint();
32                             }}),
33     STRIP_VLAN          (3, OFActionStripVirtualLan.class, new Instantiable<OFAction>() {
34                             @Override
35                             public OFAction instantiate() {
36                                 return new OFActionStripVirtualLan();
37                             }}),
38     SET_DL_SRC          (4, OFActionDataLayerSource.class, new Instantiable<OFAction>() {
39                             @Override
40                             public OFAction instantiate() {
41                                 return new OFActionDataLayerSource();
42                             }}),
43     SET_DL_DST          (5, OFActionDataLayerDestination.class, new Instantiable<OFAction>() {
44                             @Override
45                             public OFAction instantiate() {
46                                 return new OFActionDataLayerDestination();
47                             }}),
48     SET_NW_SRC          (6, OFActionNetworkLayerSource.class, new Instantiable<OFAction>() {
49                             @Override
50                             public OFAction instantiate() {
51                                 return new OFActionNetworkLayerSource();
52                             }}),
53     SET_NW_DST          (7, OFActionNetworkLayerDestination.class, new Instantiable<OFAction>() {
54                             @Override
55                             public OFAction instantiate() {
56                                 return new OFActionNetworkLayerDestination();
57                             }}),
58     SET_NW_TOS          (8, OFActionNetworkTypeOfService.class, new Instantiable<OFAction>() {
59                             @Override
60                             public OFAction instantiate() {
61                                 return new OFActionNetworkTypeOfService();
62                             }}),
63     SET_TP_SRC          (9, OFActionTransportLayerSource.class, new Instantiable<OFAction>() {
64                             @Override
65                             public OFAction instantiate() {
66                                 return new OFActionTransportLayerSource();
67                             }}),
68     SET_TP_DST          (10, OFActionTransportLayerDestination.class, new Instantiable<OFAction>() {
69                             @Override
70                             public OFAction instantiate() {
71                                 return new OFActionTransportLayerDestination();
72                             }}),
73     OPAQUE_ENQUEUE      (11, OFActionEnqueue.class, new Instantiable<OFAction>() {
74                             @Override
75                             public OFAction instantiate() {
76                                 return new OFActionEnqueue();
77                             }}),
78     VENDOR              (0xffff, OFActionVendor.class, new Instantiable<OFAction>() {
79                             @Override
80                             public OFAction instantiate() {
81                                 return new OFActionVendor();
82                             }});
83
84     protected static OFActionType[] mapping;
85
86     protected Class<? extends OFAction> clazz;
87     protected Constructor<? extends OFAction> constructor;
88     protected Instantiable<OFAction> instantiable;
89     protected int minLen;
90     protected short type;
91
92     /**
93      * Store some information about the OpenFlow Action type, including wire
94      * protocol type number, length, and derrived class
95      *
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
99      */
100     OFActionType(int type, Class<? extends OFAction> clazz, Instantiable<OFAction> instantiable) {
101         this.type = (short) type;
102         this.clazz = clazz;
103         this.instantiable = instantiable;
104         try {
105             this.constructor = clazz.getConstructor(new Class[]{});
106         } catch (Exception e) {
107             throw new RuntimeException(
108                     "Failure getting constructor for class: " + clazz, e);
109         }
110         OFActionType.addMapping(this.type, this);
111     }
112
113     /**
114      * Adds a mapping from type value to OFActionType enum
115      *
116      * @param i OpenFlow wire protocol Action type value
117      * @param t type
118      */
119     static public void addMapping(short i, OFActionType t) {
120         if (mapping == null)
121             mapping = new OFActionType[16];
122         // bring higher mappings down to the edge of our array
123         if (i < 0)
124             i = (short) (16 + i);
125         OFActionType.mapping[i] = t;
126     }
127
128     /**
129      * Given a wire protocol OpenFlow type number, return the OFType associated
130      * with it
131      *
132      * @param i wire protocol number
133      * @return OFType enum type
134      */
135
136     static public OFActionType valueOf(short i) {
137         if (i < 0)
138             i = (short) (16+i);
139         return OFActionType.mapping[i];
140     }
141
142     /**
143      * @return Returns the wire protocol value corresponding to this
144      *         OFActionType
145      */
146     public short getTypeValue() {
147         return this.type;
148     }
149
150     /**
151      * @return return the OFAction subclass corresponding to this OFActionType
152      */
153     public Class<? extends OFAction> toClass() {
154         return clazz;
155     }
156
157     /**
158      * Returns the no-argument Constructor of the implementation class for
159      * this OFActionType
160      * @return the constructor
161      */
162     public Constructor<? extends OFAction> getConstructor() {
163         return constructor;
164     }
165
166     /**
167      * Returns a new instance of the OFAction represented by this OFActionType
168      * @return the new object
169      */
170     public OFAction newInstance() {
171         return instantiable.instantiate();
172     }
173
174     /**
175      * @return the instantiable
176      */
177     public Instantiable<OFAction> getInstantiable() {
178         return instantiable;
179     }
180
181     /**
182      * @param instantiable the instantiable to set
183      */
184     public void setInstantiable(Instantiable<OFAction> instantiable) {
185         this.instantiable = instantiable;
186     }
187 }