blob: 876e856700788c8a8d64b4ab37fe8febf87b5da7 [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.Arrays;
21
22import org.jboss.netty.buffer.ChannelBuffer;
23import org.openflow.util.U16;
24
25/**
26 * Represents an ofp_port_mod message
27 * @author David Erickson (daviderickson@cs.stanford.edu)
28 */
29public class OFPortMod extends OFMessage {
30 public static int MINIMUM_LENGTH = 32;
31
32 protected short portNumber;
33 protected byte[] hardwareAddress;
34 protected int config;
35 protected int mask;
36 protected int advertise;
37
38 public OFPortMod() {
39 super();
40 this.type = OFType.PORT_MOD;
41 this.length = U16.t(MINIMUM_LENGTH);
42 }
43
44 /**
45 * @return the portNumber
46 */
47 public short getPortNumber() {
48 return portNumber;
49 }
50
51 /**
52 * @param portNumber the portNumber to set
53 */
54 public void setPortNumber(short portNumber) {
55 this.portNumber = portNumber;
56 }
57
58 /**
59 * @return the hardwareAddress
60 */
61 public byte[] getHardwareAddress() {
62 return hardwareAddress;
63 }
64
65 /**
66 * @param hardwareAddress the hardwareAddress to set
67 */
68 public void setHardwareAddress(byte[] hardwareAddress) {
69 if (hardwareAddress.length != OFPhysicalPort.OFP_ETH_ALEN)
70 throw new RuntimeException("Hardware address must have length "
71 + OFPhysicalPort.OFP_ETH_ALEN);
72 this.hardwareAddress = hardwareAddress;
73 }
74
75 /**
76 * @return the config
77 */
78 public int getConfig() {
79 return config;
80 }
81
82 /**
83 * @param config the config to set
84 */
85 public void setConfig(int config) {
86 this.config = config;
87 }
88
89 /**
90 * @return the mask
91 */
92 public int getMask() {
93 return mask;
94 }
95
96 /**
97 * @param mask the mask to set
98 */
99 public void setMask(int mask) {
100 this.mask = mask;
101 }
102
103 /**
104 * @return the advertise
105 */
106 public int getAdvertise() {
107 return advertise;
108 }
109
110 /**
111 * @param advertise the advertise to set
112 */
113 public void setAdvertise(int advertise) {
114 this.advertise = advertise;
115 }
116
117 @Override
118 public void readFrom(ChannelBuffer data) {
119 super.readFrom(data);
120 this.portNumber = data.readShort();
121 if (this.hardwareAddress == null)
122 this.hardwareAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
123 data.readBytes(this.hardwareAddress);
124 this.config = data.readInt();
125 this.mask = data.readInt();
126 this.advertise = data.readInt();
127 data.readInt(); // pad
128 }
129
130 @Override
131 public void writeTo(ChannelBuffer data) {
132 super.writeTo(data);
133 data.writeShort(this.portNumber);
134 data.writeBytes(this.hardwareAddress);
135 data.writeInt(this.config);
136 data.writeInt(this.mask);
137 data.writeInt(this.advertise);
138 data.writeInt(0); // pad
139 }
140
141 @Override
142 public int hashCode() {
143 final int prime = 311;
144 int result = super.hashCode();
145 result = prime * result + advertise;
146 result = prime * result + config;
147 result = prime * result + Arrays.hashCode(hardwareAddress);
148 result = prime * result + mask;
149 result = prime * result + portNumber;
150 return result;
151 }
152
153 @Override
154 public boolean equals(Object obj) {
155 if (this == obj) {
156 return true;
157 }
158 if (!super.equals(obj)) {
159 return false;
160 }
161 if (!(obj instanceof OFPortMod)) {
162 return false;
163 }
164 OFPortMod other = (OFPortMod) obj;
165 if (advertise != other.advertise) {
166 return false;
167 }
168 if (config != other.config) {
169 return false;
170 }
171 if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
172 return false;
173 }
174 if (mask != other.mask) {
175 return false;
176 }
177 if (portNumber != other.portNumber) {
178 return false;
179 }
180 return true;
181 }
182}