blob: 7a8f67b2c611e923942cc3adf1f2f06c8b76a15e [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavov8e5bab22013-04-02 04:19:41 +00003import java.math.BigInteger;
4
HIGUCHI Yutaf086d8a2013-06-12 15:26:35 -07005import net.onrc.onos.ofcontroller.util.serializers.FlowEntryIdDeserializer;
6import net.onrc.onos.ofcontroller.util.serializers.FlowEntryIdSerializer;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
8import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -08009import org.codehaus.jackson.map.annotate.JsonDeserialize;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010import org.codehaus.jackson.map.annotate.JsonSerialize;
11
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012/**
13 * The class representing a Flow Entry ID.
14 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080015@JsonDeserialize(using=FlowEntryIdDeserializer.class)
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080016@JsonSerialize(using=FlowEntryIdSerializer.class)
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017public class FlowEntryId {
18 private long value;
19
20 /**
21 * Default constructor.
22 */
23 public FlowEntryId() {
24 this.value = 0;
25 }
26
27 /**
28 * Constructor from an integer value.
29 *
30 * @param value the value to use.
31 */
32 public FlowEntryId(long value) {
33 this.value = value;
34 }
35
36 /**
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080037 * Constructor from a string.
38 *
39 * @param value the value to use.
40 */
41 public FlowEntryId(String value) {
Pavlin Radoslavov8e5bab22013-04-02 04:19:41 +000042 //
43 // Use the help of BigInteger to parse strings representing
44 // large unsigned hex long values.
45 //
46 char c = 0;
47 if (value.length() > 2)
48 c = value.charAt(1);
49 if ((c == 'x') || (c == 'X'))
50 this.value = new BigInteger(value.substring(2), 16).longValue();
51 else
52 this.value = Long.decode(value);
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080053 }
54
55 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080056 * Get the value of the Flow Entry ID.
57 *
58 * @return the value of the Flow Entry ID.
59 */
60 public long value() { return value; }
61
62 /**
63 * Set the value of the Flow Entry ID.
64 *
65 * @param value the value to set.
66 */
67 public void setValue(long value) {
68 this.value = value;
69 }
70
71 /**
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080072 * Convert the Flow Entry ID value to a hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080073 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080074 * @return the Flow Entry ID value to a hexadecimal string.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080075 */
76 @Override
77 public String toString() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080078 return "0x" + Long.toHexString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080079 }
80}