blob: cf6ace3c5ad5d972f84ce662cb7c629d1680d689 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3* University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package org.openflow.protocol;
19
20import java.util.List;
21
22import org.jboss.netty.buffer.ChannelBuffer;
23import org.openflow.protocol.factory.OFStatisticsFactory;
24import org.openflow.protocol.factory.OFStatisticsFactoryAware;
25import org.openflow.protocol.statistics.OFStatistics;
26import org.openflow.protocol.statistics.OFStatisticsType;
27
28
29/**
30 * Base class for statistics requests/replies
31 *
32 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 27, 2010
33 */
34public abstract class OFStatisticsMessageBase extends OFMessage implements
35 OFStatisticsFactoryAware {
36 public static int MINIMUM_LENGTH = 12;
37
38 protected OFStatisticsFactory statisticsFactory;
39 protected OFStatisticsType statisticType;
40 protected short flags;
41 protected List<OFStatistics> statistics;
42
43 /**
44 * @return the statisticType
45 */
46 public OFStatisticsType getStatisticType() {
47 return statisticType;
48 }
49
50 /**
51 * @param statisticType the statisticType to set
52 */
53 public void setStatisticType(OFStatisticsType statisticType) {
54 this.statisticType = statisticType;
55 }
56
57 /**
58 * @return the flags
59 */
60 public short getFlags() {
61 return flags;
62 }
63
64 /**
65 * @param flags the flags to set
66 */
67 public void setFlags(short flags) {
68 this.flags = flags;
69 }
70
71 /**
72 * @return the statistics
73 */
74 public List<OFStatistics> getStatistics() {
75 return statistics;
76 }
77
78 /**
79 * @param statistics the statistics to set
80 */
81 public void setStatistics(List<OFStatistics> statistics) {
82 this.statistics = statistics;
83 }
84
85 @Override
86 public void setStatisticsFactory(OFStatisticsFactory statisticsFactory) {
87 this.statisticsFactory = statisticsFactory;
88 }
89
90 @Override
91 public void readFrom(ChannelBuffer data) {
92 super.readFrom(data);
93 this.statisticType = OFStatisticsType.valueOf(data.readShort(), this
94 .getType());
95 this.flags = data.readShort();
96 if (this.statisticsFactory == null)
97 throw new RuntimeException("OFStatisticsFactory not set");
98 this.statistics = statisticsFactory.parseStatistics(this.getType(),
99 this.statisticType, data, super.getLengthU() - MINIMUM_LENGTH);
100 }
101
102 @Override
103 public void writeTo(ChannelBuffer data) {
104 super.writeTo(data);
105 data.writeShort(this.statisticType.getTypeValue());
106 data.writeShort(this.flags);
107 if (this.statistics != null) {
108 for (OFStatistics statistic : this.statistics) {
109 statistic.writeTo(data);
110 }
111 }
112 }
113
114 @Override
115 public int hashCode() {
116 final int prime = 317;
117 int result = super.hashCode();
118 result = prime * result + flags;
119 result = prime * result
120 + ((statisticType == null) ? 0 : statisticType.hashCode());
121 result = prime * result
122 + ((statistics == null) ? 0 : statistics.hashCode());
123 return result;
124 }
125
126 @Override
127 public boolean equals(Object obj) {
128 if (this == obj) {
129 return true;
130 }
131 if (!super.equals(obj)) {
132 return false;
133 }
134 if (!(obj instanceof OFStatisticsMessageBase)) {
135 return false;
136 }
137 OFStatisticsMessageBase other = (OFStatisticsMessageBase) obj;
138 if (flags != other.flags) {
139 return false;
140 }
141 if (statisticType == null) {
142 if (other.statisticType != null) {
143 return false;
144 }
145 } else if (!statisticType.equals(other.statisticType)) {
146 return false;
147 }
148 if (statistics == null) {
149 if (other.statistics != null) {
150 return false;
151 }
152 } else if (!statistics.equals(other.statistics)) {
153 return false;
154 }
155 return true;
156 }
157}