1 package org.openflow.codec.protocol;
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.protocol.factory.OFPStatisticsFactory;
7 import org.openflow.codec.protocol.factory.OFPStatisticsFactoryAware;
8 import org.openflow.codec.protocol.statistics.OFPMultipartTypes;
9 import org.openflow.codec.protocol.statistics.OFPStatistics;
12 * Base class for Multipart requests/replies
14 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 27, 2010
17 public abstract class OFPMultipartMessageBase extends OFPMessage implements OFPStatisticsFactoryAware {
18 public static int MINIMUM_LENGTH = 16;
20 protected OFPStatisticsFactory statisticsFactory;
21 protected OFPMultipartTypes multipartType;
22 protected short flags;
23 protected List<OFPStatistics> statistics;
26 * @return the multipartType
28 public OFPMultipartTypes getMultipartType() {
33 * @param multipartType
34 * the multipartType to set
36 public void setMultipartType(OFPMultipartTypes multipartType) {
37 this.multipartType = multipartType;
43 public short getFlags() {
51 public void setFlags(short flags) {
56 * @return the statistics
58 public List<OFPStatistics> getStatistics() {
64 * the statistics to set
66 public void setStatistics(List<OFPStatistics> statistics) {
67 this.statistics = statistics;
71 public void setStatisticsFactory(OFPStatisticsFactory statisticsFactory) {
72 this.statisticsFactory = statisticsFactory;
76 public void readFrom(IDataBuffer data) {
78 this.multipartType = OFPMultipartTypes.valueOf(data.getShort(), this.getType());
79 this.flags = data.getShort();
81 if (this.statisticsFactory == null)
82 throw new RuntimeException("OFPStatisticsFactory not set");
83 this.statistics = statisticsFactory.parseStatistics(this.getType(), this.multipartType, data,
84 super.getLengthU() - MINIMUM_LENGTH);
88 public void writeTo(IDataBuffer data) {
90 data.putShort(this.multipartType.getTypeValue());
91 data.putShort(this.flags);
92 data.putInt(0); // pad
93 if (this.statistics != null) {
94 for (OFPStatistics statistic : this.statistics) {
95 statistic.writeTo(data);
101 public int hashCode() {
102 final int prime = 317;
103 int result = super.hashCode();
104 result = prime * result + flags;
105 result = prime * result + ((multipartType == null) ? 0 : multipartType.hashCode());
106 result = prime * result + ((statistics == null) ? 0 : statistics.hashCode());
111 public boolean equals(Object obj) {
115 if (!super.equals(obj)) {
118 if (!(obj instanceof OFPMultipartMessageBase)) {
121 OFPMultipartMessageBase other = (OFPMultipartMessageBase) obj;
122 if (flags != other.flags) {
125 if (multipartType == null) {
126 if (other.multipartType != null) {
129 } else if (!multipartType.equals(other.multipartType)) {
132 if (statistics == null) {
133 if (other.statistics != null) {
136 } else if (!statistics.equals(other.statistics)) {