Merge "Updated pom.xml to build documentation only on jenkins merge-job"
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / instruction / OFPInstructionType.java
1 package org.openflow.codec.protocol.instruction;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.openflow.codec.protocol.Instantiable;
7 import org.openflow.codec.util.U16;
8
9 /**
10  * Represents struct ofp_instruction_type
11  *
12  * @author AnilGujele
13  *
14  */
15 public enum OFPInstructionType {
16     /* Setup the next table in the lookup pipeline */
17     GOTO_TABLE(1, new Instantiable<OFPInstruction>() {
18         @Override
19         public OFPInstruction instantiate() {
20             return new OFPInstructionGoToTable();
21         }
22     }),
23     /* Setup the metadata field for use later in pipeline */
24     WRITE_METADATA(2, new Instantiable<OFPInstruction>() {
25         @Override
26         public OFPInstruction instantiate() {
27             return new OFPInstructionWriteMetaData();
28         }
29     }),
30     /* Write the action(s) onto the datapath action set */
31     WRITE_ACTIONS(3, new Instantiable<OFPInstruction>() {
32         @Override
33         public OFPInstruction instantiate() {
34             return new OFPInstructionWriteActions();
35         }
36     }),
37     /* Applies the action(s) immediately */
38     APPLY_ACTIONS(4, new Instantiable<OFPInstruction>() {
39         @Override
40         public OFPInstruction instantiate() {
41             return new OFPInstructionApplyActions();
42         }
43     }),
44     /* Clears all actions from the datapath action set */
45     CLEAR_ACTIONS(5, new Instantiable<OFPInstruction>() {
46         @Override
47         public OFPInstruction instantiate() {
48             return new OFPInstructionClearActions();
49         }
50     }),
51     /* Apply meter (rate limiter) */
52     METER(6, new Instantiable<OFPInstruction>() {
53         @Override
54         public OFPInstruction instantiate() {
55             return new OFPInstructionMeter();
56         }
57     }),
58     /* Experimenter instruction */
59     EXPERIMENTER(0xFFFF, new Instantiable<OFPInstruction>() {
60         @Override
61         public OFPInstruction instantiate() {
62             return new OFPInstructionExperimenter();
63         }
64     });
65
66     private static Map<Integer, OFPInstructionType> mapping;
67
68     private short type;
69
70     private Instantiable<OFPInstruction> instantiable;
71
72     /**
73      *
74      * @param type
75      */
76     OFPInstructionType(int type, Instantiable<OFPInstruction> instantiable) {
77         this.setTypeValue((short) type);
78         OFPInstructionType.addMapping(type, this);
79         this.instantiable = instantiable;
80     }
81
82     /**
83      * add mapping to store
84      *
85      * @param type
86      * @param instructionType
87      */
88     private static void addMapping(int type, OFPInstructionType instructionType) {
89         if (null == mapping) {
90             mapping = new HashMap<Integer, OFPInstructionType>();
91         }
92         mapping.put(type, instructionType);
93     }
94
95     /**
96      * get OFPInstructionType correspond to value type
97      *
98      * @param type
99      * @return OFPInstructionType
100      */
101     public static OFPInstructionType valueOf(short type) {
102         return mapping.get(U16.f(type));
103     }
104
105     /**
106      * get instruction type value
107      *
108      * @return
109      */
110     public short getTypeValue() {
111         return type;
112     }
113
114     /**
115      * set instruction type value
116      *
117      * @param type
118      */
119     public void setTypeValue(short type) {
120         this.type = type;
121     }
122
123     /**
124      * Returns a new instance of the OFPAction represented by this OFPActionType
125      *
126      * @return the new object
127      */
128     public OFPInstruction newInstance() {
129         return instantiable.instantiate();
130     }
131
132 }