eb1058d6dff692a72de3a3a9f10246dc6c75810d
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / OFPErrorType.java
1 package org.openflow.codec.protocol;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.openflow.codec.util.U16;
7
8 /**
9  * enum correspond to ofp_error_type
10  * 
11  * @author AnilGujele
12  * 
13  */
14 public enum OFPErrorType
15 {
16         OFPET_HELLO_FAILED(0), OFPET_BAD_REQUEST(1), OFPET_BAD_ACTION(2), OFPET_BAD_INSTRUCTION(
17                         3), OFPET_BAD_MATCH(4), OFPET_FLOW_MOD_FAILED(5), OFPET_GROUP_MOD_FAILED(
18                         6), OFPET_PORT_MOD_FAILED(7), OFPET_TABLE_MOD_FAILED(8), OFPET_QUEUE_OP_FAILED(
19                         9), OFPET_SWITCH_CONFIG_FAILED(10), OFPET_ROLE_REQUEST_FAILED(11), OFPET_METER_MOD_FAILED(
20                         12), OFPET_TABLE_FEATURES_FAILED(13), OFPET_EXPERIMENTER(0xffff);
21
22         private static Map<Integer, OFPErrorType> mapping;
23
24         private short type;
25
26         OFPErrorType(int type)
27         {
28                 this.type = (short) type;
29                 addMapping(type, this);
30         }
31
32         /**
33          * add mapping for OFPErrorType
34          * 
35          * @param type
36          * @param errorType
37          */
38         private static void addMapping(int type, OFPErrorType errorType)
39         {
40                 if (null == mapping)
41                 {
42                         mapping = new HashMap<Integer, OFPErrorType>();
43                 }
44                 mapping.put(type, errorType);
45         }
46
47         /**
48          * get the OFPErrorType of value
49          * 
50          * @param type
51          * @return
52          */
53         public static OFPErrorType valueOf(short type)
54         {
55                 return mapping.get(U16.f(type));
56         }
57
58         /**
59          * get type value
60          * 
61          * @return
62          */
63         public short getValue()
64         {
65                 return type;
66         }
67
68 }