2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
18 package org.openflow.protocol;
20 import java.util.Arrays;
22 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.openflow.util.U16;
26 * Represents an ofp_port_mod message
27 * @author David Erickson (daviderickson@cs.stanford.edu)
29 public class OFPortMod extends OFMessage {
30 public static int MINIMUM_LENGTH = 32;
32 protected short portNumber;
33 protected byte[] hardwareAddress;
36 protected int advertise;
40 this.type = OFType.PORT_MOD;
41 this.length = U16.t(MINIMUM_LENGTH);
45 * @return the portNumber
47 public short getPortNumber() {
52 * @param portNumber the portNumber to set
54 public void setPortNumber(short portNumber) {
55 this.portNumber = portNumber;
59 * @return the hardwareAddress
61 public byte[] getHardwareAddress() {
62 return hardwareAddress;
66 * @param hardwareAddress the hardwareAddress to set
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;
78 public int getConfig() {
83 * @param config the config to set
85 public void setConfig(int config) {
92 public int getMask() {
97 * @param mask the mask to set
99 public void setMask(int mask) {
104 * @return the advertise
106 public int getAdvertise() {
111 * @param advertise the advertise to set
113 public void setAdvertise(int advertise) {
114 this.advertise = advertise;
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
131 public void writeTo(ChannelBuffer 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
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;
154 public boolean equals(Object obj) {
158 if (!super.equals(obj)) {
161 if (!(obj instanceof OFPortMod)) {
164 OFPortMod other = (OFPortMod) obj;
165 if (advertise != other.advertise) {
168 if (config != other.config) {
171 if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
174 if (mask != other.mask) {
177 if (portNumber != other.portNumber) {