1 package org.openflow.protocol;
3 import java.nio.ByteBuffer;
4 import java.util.Arrays;
6 import org.openflow.util.U16;
9 * Represents an ofp_port_mod message
10 * @author David Erickson (daviderickson@cs.stanford.edu)
12 public class OFPortMod extends OFMessage {
13 public static int MINIMUM_LENGTH = 32;
15 protected short portNumber;
16 protected byte[] hardwareAddress;
19 protected int advertise;
23 this.type = OFType.PORT_MOD;
24 this.length = U16.t(MINIMUM_LENGTH);
28 * @return the portNumber
30 public short getPortNumber() {
35 * @param portNumber the portNumber to set
37 public void setPortNumber(short portNumber) {
38 this.portNumber = portNumber;
42 * @return the hardwareAddress
44 public byte[] getHardwareAddress() {
45 return hardwareAddress;
49 * @param hardwareAddress the hardwareAddress to set
51 public void setHardwareAddress(byte[] hardwareAddress) {
52 if (hardwareAddress.length != OFPhysicalPort.OFP_ETH_ALEN)
53 throw new RuntimeException("Hardware address must have length "
54 + OFPhysicalPort.OFP_ETH_ALEN);
55 this.hardwareAddress = hardwareAddress;
61 public int getConfig() {
66 * @param config the config to set
68 public void setConfig(int config) {
75 public int getMask() {
80 * @param mask the mask to set
82 public void setMask(int mask) {
87 * @return the advertise
89 public int getAdvertise() {
94 * @param advertise the advertise to set
96 public void setAdvertise(int advertise) {
97 this.advertise = advertise;
101 public void readFrom(ByteBuffer data) {
102 super.readFrom(data);
103 this.portNumber = data.getShort();
104 if (this.hardwareAddress == null)
105 this.hardwareAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
106 data.get(this.hardwareAddress);
107 this.config = data.getInt();
108 this.mask = data.getInt();
109 this.advertise = data.getInt();
110 data.getInt(); // pad
114 public void writeTo(ByteBuffer data) {
116 data.putShort(this.portNumber);
117 data.put(this.hardwareAddress);
118 data.putInt(this.config);
119 data.putInt(this.mask);
120 data.putInt(this.advertise);
121 data.putInt(0); // pad
125 public int hashCode() {
126 final int prime = 311;
127 int result = super.hashCode();
128 result = prime * result + advertise;
129 result = prime * result + config;
130 result = prime * result + Arrays.hashCode(hardwareAddress);
131 result = prime * result + mask;
132 result = prime * result + portNumber;
137 public boolean equals(Object obj) {
141 if (!super.equals(obj)) {
144 if (!(obj instanceof OFPortMod)) {
147 OFPortMod other = (OFPortMod) obj;
148 if (advertise != other.advertise) {
151 if (config != other.config) {
154 if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
157 if (mask != other.mask) {
160 if (portNumber != other.portNumber) {