e09be1804507aff2b0b1522f59b97fc4785b032b
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / action / OFPBucketCounter.java
1 package org.openflow.codec.protocol.action;
2
3 import java.io.Serializable;
4
5 import org.openflow.codec.io.IDataBuffer;
6
7 /**
8  * Represents an ofp_bucket_counter structure
9  *
10  * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
11  *
12  */
13 public class OFPBucketCounter implements Cloneable, Serializable {
14     public static int MINIMUM_LENGTH = 16;
15
16     protected long packet_count;
17     protected long byte_count;
18
19     public OFPBucketCounter() {
20
21     }
22
23     public long getPacket_count() {
24         return packet_count;
25     }
26
27     public OFPBucketCounter setPacket_count(long packet_count) {
28         this.packet_count = packet_count;
29         return this;
30     }
31
32     public long getByte_count() {
33         return byte_count;
34     }
35
36     public OFPBucketCounter setByte_count(long byte_count) {
37         this.byte_count = byte_count;
38         return this;
39     }
40
41     public String toString() {
42         return "ofbucketcounter" + ";packet_count=" + this.getPacket_count() + ";byte_count=" + this.getByte_count();
43     }
44
45     /**
46      * Given the output from toString(), create a new OFPBucketCounter
47      *
48      * @param val
49      * @return
50      */
51     public static OFPBucketCounter fromString(String val) {
52         String tokens[] = val.split(";");
53         if (!tokens[0].equals("ofbucket"))
54             throw new IllegalArgumentException("expected 'ofbucketcounter' but got '" + tokens[0] + "'");
55         String packet_token[] = tokens[1].split("=");
56         String byte_token[] = tokens[2].split("=");
57         OFPBucketCounter bucketCounter = new OFPBucketCounter();
58         bucketCounter.setPacket_count(Long.valueOf(packet_token[1]));
59         bucketCounter.setByte_count(Long.valueOf(byte_token[2]));
60         return bucketCounter;
61     }
62
63     public void readFrom(IDataBuffer data) {
64         this.packet_count = data.getLong();
65         this.byte_count = data.getLong();
66     }
67
68     public void writeTo(IDataBuffer data) {
69         data.putLong(packet_count);
70         data.putLong(byte_count);
71     }
72
73     @Override
74     public int hashCode() {
75         final int prime = 347;
76         int result = 1;
77         result = prime * result + (int) (packet_count ^ (packet_count >>> 32));
78         result = prime * result + (int) (byte_count ^ (byte_count >>> 32));
79         return result;
80     }
81
82     @Override
83     public boolean equals(Object obj) {
84         if (this == obj) {
85             return true;
86         }
87         if (obj == null) {
88             return false;
89         }
90         if (!(obj instanceof OFPBucketCounter)) {
91             return false;
92         }
93         OFPBucketCounter other = (OFPBucketCounter) obj;
94         if (packet_count != other.packet_count) {
95             return false;
96         }
97         if (byte_count != other.byte_count) {
98             return false;
99         }
100         return true;
101     }
102
103     /*
104      * (non-Javadoc)
105      *
106      * @see java.lang.Object#clone()
107      */
108     @Override
109     public OFPBucketCounter clone() throws CloneNotSupportedException {
110         return (OFPBucketCounter) super.clone();
111     }
112
113 }