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