1 package org.openflow.codec.protocol;
3 import java.util.Arrays;
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.util.U16;
9 * Represents an ofp_port_mod message
11 * @author David Erickson (daviderickson@cs.stanford.edu)
13 public class OFPPortMod extends OFPMessage {
14 public static int MINIMUM_LENGTH = 40;
16 protected int portNumber;
17 protected byte[] hardwareAddress;
20 protected int advertise;
24 this.type = OFPType.PORT_MOD;
25 this.length = U16.t(MINIMUM_LENGTH);
29 * @return the portNumber
31 public int getPortNumber() {
37 * the portNumber to set
39 public void setPortNumber(int portNumber) {
40 this.portNumber = portNumber;
44 * @return the hardwareAddress
46 public byte[] getHardwareAddress() {
47 return hardwareAddress;
51 * @param hardwareAddress
52 * the hardwareAddress to set
54 public void setHardwareAddress(byte[] hardwareAddress) {
55 if (hardwareAddress.length != OFPPort.OFP_ETH_ALEN)
56 throw new RuntimeException("Hardware address must have length " + OFPPort.OFP_ETH_ALEN);
57 this.hardwareAddress = hardwareAddress;
63 public int getConfig() {
71 public void setConfig(int config) {
78 public int getMask() {
86 public void setMask(int mask) {
91 * @return the advertise
93 public int getAdvertise() {
99 * the advertise to set
101 public void setAdvertise(int advertise) {
102 this.advertise = advertise;
106 public void readFrom(IDataBuffer data) {
107 super.readFrom(data);
108 this.portNumber = data.getInt();
109 data.getInt(); // pad
110 if (this.hardwareAddress == null)
111 this.hardwareAddress = new byte[OFPPort.OFP_ETH_ALEN];
112 data.get(this.hardwareAddress);
113 data.getShort(); // pad
114 this.config = data.getInt();
115 this.mask = data.getInt();
116 this.advertise = data.getInt();
117 data.getShort(); // pad
122 public void writeTo(IDataBuffer data) {
124 data.putInt(this.portNumber);
125 data.putInt(0); // pad
126 data.put(this.hardwareAddress);
127 data.putShort((short) 0); // pad
128 data.putInt(this.config);
129 data.putInt(this.mask);
130 data.putInt(this.advertise);
131 data.putShort((short) 0); // pad
132 data.put((byte) 0); // pad
136 public int hashCode() {
137 final int prime = 311;
138 int result = super.hashCode();
139 result = prime * result + advertise;
140 result = prime * result + config;
141 result = prime * result + Arrays.hashCode(hardwareAddress);
142 result = prime * result + mask;
143 result = prime * result + portNumber;
148 public boolean equals(Object obj) {
152 if (!super.equals(obj)) {
155 if (!(obj instanceof OFPPortMod)) {
158 OFPPortMod other = (OFPPortMod) obj;
159 if (advertise != other.advertise) {
162 if (config != other.config) {
165 if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
168 if (mask != other.mask) {
171 if (portNumber != other.portNumber) {