Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 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 { |
| 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) |
| 11 | |
| 12 | /** |
| 13 | * Default constructor. |
| 14 | */ |
| 15 | public FlowEntryErrorState() { |
| 16 | this.type = 0; |
| 17 | this.code = 0; |
| 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) { |
| 27 | this.type = type; |
| 28 | this.code = code; |
| 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") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 37 | public short type() { return type; } |
| 38 | |
| 39 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 40 | * Set the error type. |
| 41 | * |
| 42 | * @param type the error type to use. |
| 43 | */ |
| 44 | @JsonProperty("type") |
| 45 | public void setType(short type) { |
| 46 | this.type = type; |
| 47 | } |
| 48 | |
| 49 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 50 | * Get the error code. |
| 51 | * |
| 52 | * @return the error code. |
| 53 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 54 | @JsonProperty("code") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 55 | public short code() { return code; } |
| 56 | |
| 57 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 58 | * Set the error code. |
| 59 | * |
| 60 | * @param code the error code to use. |
| 61 | */ |
| 62 | @JsonProperty("code") |
| 63 | public void setCode(short code) { |
| 64 | this.code = code; |
| 65 | } |
| 66 | |
| 67 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 68 | * Set the values of the error type and code. |
| 69 | * |
| 70 | * @param type the error type to use. |
| 71 | * @param code the error code to use. |
| 72 | */ |
| 73 | public void setValue(short type, short code) { |
| 74 | this.type = type; |
| 75 | this.code = code; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Convert the error type and code to a string. |
| 80 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 81 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 82 | * [type=1 code=2] |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 83 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 84 | * @return the error type and code as a string. |
| 85 | */ |
| 86 | @Override |
| 87 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 88 | String ret = "[type=" + this.type + " code=" + code + "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 89 | return ret; |
| 90 | } |
| 91 | } |