1 package org.openflow.protocol;
3 import java.nio.ByteBuffer;
6 import org.openflow.protocol.factory.OFStatisticsFactory;
7 import org.openflow.protocol.factory.OFStatisticsFactoryAware;
8 import org.openflow.protocol.statistics.OFStatistics;
9 import org.openflow.protocol.statistics.OFStatisticsType;
13 * Base class for statistics requests/replies
15 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 27, 2010
17 public abstract class OFStatisticsMessageBase extends OFMessage implements
18 OFStatisticsFactoryAware {
19 public static int MINIMUM_LENGTH = 12;
21 protected OFStatisticsFactory statisticsFactory;
22 protected OFStatisticsType statisticType;
23 protected short flags;
24 protected List<OFStatistics> statistics;
27 * @return the statisticType
29 public OFStatisticsType getStatisticType() {
34 * @param statisticType the statisticType to set
36 public void setStatisticType(OFStatisticsType statisticType) {
37 this.statisticType = statisticType;
43 public short getFlags() {
48 * @param flags the flags to set
50 public void setFlags(short flags) {
55 * @return the statistics
57 public List<OFStatistics> getStatistics() {
62 * @param statistics the statistics to set
64 public void setStatistics(List<OFStatistics> statistics) {
65 this.statistics = statistics;
69 public void setStatisticsFactory(OFStatisticsFactory statisticsFactory) {
70 this.statisticsFactory = statisticsFactory;
74 public void readFrom(ByteBuffer data) {
76 this.statisticType = OFStatisticsType.valueOf(data.getShort(), this
78 this.flags = data.getShort();
79 if (this.statisticsFactory == null)
80 throw new RuntimeException("OFStatisticsFactory not set");
81 this.statistics = statisticsFactory.parseStatistics(this.getType(),
82 this.statisticType, data, super.getLengthU() - MINIMUM_LENGTH);
86 public void writeTo(ByteBuffer data) {
88 data.putShort(this.statisticType.getTypeValue());
89 data.putShort(this.flags);
90 if (this.statistics != null) {
91 for (OFStatistics statistic : this.statistics) {
92 statistic.writeTo(data);
98 public int hashCode() {
99 final int prime = 317;
100 int result = super.hashCode();
101 result = prime * result + flags;
102 result = prime * result
103 + ((statisticType == null) ? 0 : statisticType.hashCode());
104 result = prime * result
105 + ((statistics == null) ? 0 : statistics.hashCode());
110 public boolean equals(Object obj) {
114 if (!super.equals(obj)) {
117 if (!(obj instanceof OFStatisticsMessageBase)) {
120 OFStatisticsMessageBase other = (OFStatisticsMessageBase) obj;
121 if (flags != other.flags) {
124 if (statisticType == null) {
125 if (other.statisticType != null) {
128 } else if (!statisticType.equals(other.statisticType)) {
131 if (statistics == null) {
132 if (other.statistics != null) {
135 } else if (!statistics.equals(other.statistics)) {