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;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.openflow.util.U16;
25 * Represents an ofp_port_status message
26 * @author David Erickson (daviderickson@cs.stanford.edu)
28 public class OFPortStatus extends OFMessage {
29 public static int MINIMUM_LENGTH = 64;
31 public enum OFPortReason {
37 protected byte reason;
38 protected OFPhysicalPort desc;
43 public byte getReason() {
48 * @param reason the reason to set
50 public void setReason(byte reason) {
57 public OFPhysicalPort getDesc() {
62 * @param desc the desc to set
64 public void setDesc(OFPhysicalPort desc) {
68 public OFPortStatus() {
70 this.type = OFType.PORT_STATUS;
71 this.length = U16.t(MINIMUM_LENGTH);
75 public void readFrom(ChannelBuffer data) {
77 this.reason = data.readByte();
78 data.readerIndex(data.readerIndex() + 7); // skip 7 bytes of padding
79 if (this.desc == null)
80 this.desc = new OFPhysicalPort();
81 this.desc.readFrom(data);
85 public void writeTo(ChannelBuffer data) {
87 data.writeByte(this.reason);
88 for (int i = 0; i < 7; ++i)
89 data.writeByte((byte) 0);
90 this.desc.writeTo(data);
94 public int hashCode() {
95 final int prime = 313;
96 int result = super.hashCode();
97 result = prime * result + ((desc == null) ? 0 : desc.hashCode());
98 result = prime * result + reason;
103 public boolean equals(Object obj) {
107 if (!super.equals(obj)) {
110 if (!(obj instanceof OFPortStatus)) {
113 OFPortStatus other = (OFPortStatus) obj;
115 if (other.desc != null) {
118 } else if (!desc.equals(other.desc)) {
121 if (reason != other.reason) {