2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
21 package org.openflow.protocol.action;
23 import java.lang.reflect.Constructor;
25 import org.openflow.protocol.Instantiable;
28 * List of OpenFlow Action types and mappings to wire protocol value and
31 * @author David Erickson (daviderickson@cs.stanford.edu)
33 public enum OFActionType {
34 OUTPUT (0, OFActionOutput.class, new Instantiable<OFAction>() {
36 public OFAction instantiate() {
37 return new OFActionOutput();
39 SET_VLAN_ID (1, OFActionVirtualLanIdentifier.class, new Instantiable<OFAction>() {
41 public OFAction instantiate() {
42 return new OFActionVirtualLanIdentifier();
44 SET_VLAN_PCP (2, OFActionVirtualLanPriorityCodePoint.class, new Instantiable<OFAction>() {
46 public OFAction instantiate() {
47 return new OFActionVirtualLanPriorityCodePoint();
49 STRIP_VLAN (3, OFActionStripVirtualLan.class, new Instantiable<OFAction>() {
51 public OFAction instantiate() {
52 return new OFActionStripVirtualLan();
54 SET_DL_SRC (4, OFActionDataLayerSource.class, new Instantiable<OFAction>() {
56 public OFAction instantiate() {
57 return new OFActionDataLayerSource();
59 SET_DL_DST (5, OFActionDataLayerDestination.class, new Instantiable<OFAction>() {
61 public OFAction instantiate() {
62 return new OFActionDataLayerDestination();
64 SET_NW_SRC (6, OFActionNetworkLayerSource.class, new Instantiable<OFAction>() {
66 public OFAction instantiate() {
67 return new OFActionNetworkLayerSource();
69 SET_NW_DST (7, OFActionNetworkLayerDestination.class, new Instantiable<OFAction>() {
71 public OFAction instantiate() {
72 return new OFActionNetworkLayerDestination();
74 SET_NW_TOS (8, OFActionNetworkTypeOfService.class, new Instantiable<OFAction>() {
76 public OFAction instantiate() {
77 return new OFActionNetworkTypeOfService();
79 SET_TP_SRC (9, OFActionTransportLayerSource.class, new Instantiable<OFAction>() {
81 public OFAction instantiate() {
82 return new OFActionTransportLayerSource();
84 SET_TP_DST (10, OFActionTransportLayerDestination.class, new Instantiable<OFAction>() {
86 public OFAction instantiate() {
87 return new OFActionTransportLayerDestination();
89 OPAQUE_ENQUEUE (11, OFActionEnqueue.class, new Instantiable<OFAction>() {
91 public OFAction instantiate() {
92 return new OFActionEnqueue();
94 VENDOR (0xffff, OFActionVendor.class, new Instantiable<OFAction>() {
96 public OFAction instantiate() {
97 return new OFActionVendorGeneric();
100 protected static OFActionType[] mapping;
102 protected Class<? extends OFAction> clazz;
103 protected Constructor<? extends OFAction> constructor;
104 protected Instantiable<OFAction> instantiable;
105 protected int minLen;
106 protected short type;
109 * Store some information about the OpenFlow Action type, including wire
110 * protocol type number, length, and derrived class
112 * @param type Wire protocol number associated with this OFType
113 * @param clazz The Java class corresponding to this type of OpenFlow Action
114 * @param instantiable the instantiable for the OFAction this type represents
116 OFActionType(int type, Class<? extends OFAction> clazz, Instantiable<OFAction> instantiable) {
117 this.type = (short) type;
119 this.instantiable = instantiable;
121 this.constructor = clazz.getConstructor(new Class[]{});
122 } catch (Exception e) {
123 throw new RuntimeException(
124 "Failure getting constructor for class: " + clazz, e);
126 OFActionType.addMapping(this.type, this);
130 * Adds a mapping from type value to OFActionType enum
132 * @param i OpenFlow wire protocol Action type value
135 static public void addMapping(short i, OFActionType t) {
137 mapping = new OFActionType[16];
138 // bring higher mappings down to the edge of our array
140 i = (short) (16 + i);
141 OFActionType.mapping[i] = t;
145 * Given a wire protocol OpenFlow type number, return the OFType associated
148 * @param i wire protocol number
149 * @return OFType enum type
152 static public OFActionType valueOf(short i) {
155 return OFActionType.mapping[i];
159 * @return Returns the wire protocol value corresponding to this
162 public short getTypeValue() {
167 * @return return the OFAction subclass corresponding to this OFActionType
169 public Class<? extends OFAction> toClass() {
174 * Returns the no-argument Constructor of the implementation class for
176 * @return the constructor
178 public Constructor<? extends OFAction> getConstructor() {
183 * Returns a new instance of the OFAction represented by this OFActionType
184 * @return the new object
186 public OFAction newInstance() {
187 return instantiable.instantiate();
191 * @return the instantiable
193 public Instantiable<OFAction> getInstantiable() {
198 * @param instantiable the instantiable to set
200 public void setInstantiable(Instantiable<OFAction> instantiable) {
201 this.instantiable = instantiable;