1 package org.openflow.codec.protocol.instruction;
3 import java.util.HashMap;
6 import org.openflow.codec.protocol.Instantiable;
7 import org.openflow.codec.util.U16;
10 * Represents struct ofp_instruction_type
15 public enum OFPInstructionType {
16 /* Setup the next table in the lookup pipeline */
17 GOTO_TABLE(1, new Instantiable<OFPInstruction>() {
19 public OFPInstruction instantiate() {
20 return new OFPInstructionGoToTable();
23 /* Setup the metadata field for use later in pipeline */
24 WRITE_METADATA(2, new Instantiable<OFPInstruction>() {
26 public OFPInstruction instantiate() {
27 return new OFPInstructionWriteMetaData();
30 /* Write the action(s) onto the datapath action set */
31 WRITE_ACTIONS(3, new Instantiable<OFPInstruction>() {
33 public OFPInstruction instantiate() {
34 return new OFPInstructionWriteActions();
37 /* Applies the action(s) immediately */
38 APPLY_ACTIONS(4, new Instantiable<OFPInstruction>() {
40 public OFPInstruction instantiate() {
41 return new OFPInstructionApplyActions();
44 /* Clears all actions from the datapath action set */
45 CLEAR_ACTIONS(5, new Instantiable<OFPInstruction>() {
47 public OFPInstruction instantiate() {
48 return new OFPInstructionClearActions();
51 /* Apply meter (rate limiter) */
52 METER(6, new Instantiable<OFPInstruction>() {
54 public OFPInstruction instantiate() {
55 return new OFPInstructionMeter();
58 /* Experimenter instruction */
59 EXPERIMENTER(0xFFFF, new Instantiable<OFPInstruction>() {
61 public OFPInstruction instantiate() {
62 return new OFPInstructionExperimenter();
66 private static Map<Integer, OFPInstructionType> mapping;
70 private Instantiable<OFPInstruction> instantiable;
76 OFPInstructionType(int type, Instantiable<OFPInstruction> instantiable) {
77 this.setTypeValue((short) type);
78 OFPInstructionType.addMapping(type, this);
79 this.instantiable = instantiable;
83 * add mapping to store
86 * @param instructionType
88 private static void addMapping(int type, OFPInstructionType instructionType) {
89 if (null == mapping) {
90 mapping = new HashMap<Integer, OFPInstructionType>();
92 mapping.put(type, instructionType);
96 * get OFPInstructionType correspond to value type
99 * @return OFPInstructionType
101 public static OFPInstructionType valueOf(short type) {
102 return mapping.get(U16.f(type));
106 * get instruction type value
110 public short getTypeValue() {
115 * set instruction type value
119 public void setTypeValue(short type) {
124 * Returns a new instance of the OFPAction represented by this OFPActionType
126 * @return the new object
128 public OFPInstruction newInstance() {
129 return instantiable.instantiate();