Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 3 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 4 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 5 | /** |
| 6 | * The class representing the Flow Entry error state. |
| 7 | */ |
| 8 | public class FlowEntryErrorState { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 9 | private short type; // The error type (e.g., see OF-1.3.1 spec, pp. 95) |
| 10 | private short code; // The error code (e.g., see OF-1.3.1 spec, pp. 95) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * Default constructor. |
| 14 | */ |
| 15 | public FlowEntryErrorState() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 16 | this.type = 0; |
| 17 | this.code = 0; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Constructor for a given error type and code. |
| 22 | * |
| 23 | * @param type the error type to use. |
| 24 | * @param code the error code to use. |
| 25 | */ |
| 26 | public FlowEntryErrorState(short type, short code) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | this.type = type; |
| 28 | this.code = code; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Get the error type. |
| 33 | * |
| 34 | * @return the error type. |
| 35 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 36 | @JsonProperty("type") |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 37 | public short type() { |
| 38 | return type; |
| 39 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 42 | * Set the error type. |
| 43 | * |
| 44 | * @param type the error type to use. |
| 45 | */ |
| 46 | @JsonProperty("type") |
| 47 | public void setType(short type) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | this.type = type; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 52 | * Get the error code. |
| 53 | * |
| 54 | * @return the error code. |
| 55 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 56 | @JsonProperty("code") |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 57 | public short code() { |
| 58 | return code; |
| 59 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 62 | * Set the error code. |
| 63 | * |
| 64 | * @param code the error code to use. |
| 65 | */ |
| 66 | @JsonProperty("code") |
| 67 | public void setCode(short code) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 68 | this.code = code; |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 72 | * Set the values of the error type and code. |
| 73 | * |
Ray Milkey | 5df613b | 2014-04-15 10:50:56 -0700 | [diff] [blame] | 74 | * @param newType the error type to use. |
| 75 | * @param newCode the error code to use. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 76 | */ |
Ray Milkey | 5df613b | 2014-04-15 10:50:56 -0700 | [diff] [blame] | 77 | public void setValue(short newType, short newCode) { |
| 78 | type = newType; |
| 79 | code = newCode; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Convert the error type and code to a string. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | * <p/> |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 85 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 86 | * [type=1 code=2] |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 87 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 88 | * @return the error type and code as a string. |
| 89 | */ |
| 90 | @Override |
| 91 | public String toString() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | String ret = "[type=" + this.type + " code=" + code + "]"; |
| 93 | return ret; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 94 | } |
| 95 | } |