1 package org.openflow.protocol;
3 import java.nio.ByteBuffer;
5 import org.openflow.util.U16;
8 * Represents an ofp_port_status message
9 * @author David Erickson (daviderickson@cs.stanford.edu)
11 public class OFPortStatus extends OFMessage {
12 public static int MINIMUM_LENGTH = 64;
14 public enum OFPortReason {
20 protected byte reason;
21 protected OFPhysicalPort desc;
26 public byte getReason() {
31 * @param reason the reason to set
33 public void setReason(byte reason) {
40 public OFPhysicalPort getDesc() {
45 * @param desc the desc to set
47 public void setDesc(OFPhysicalPort desc) {
51 public OFPortStatus() {
53 this.type = OFType.PORT_STATUS;
54 this.length = U16.t(MINIMUM_LENGTH);
58 public void readFrom(ByteBuffer data) {
60 this.reason = data.get();
61 data.position(data.position() + 7); // skip 7 bytes of padding
62 if (this.desc == null)
63 this.desc = new OFPhysicalPort();
64 this.desc.readFrom(data);
68 public void writeTo(ByteBuffer data) {
70 data.put(this.reason);
71 for (int i = 0; i < 7; ++i)
73 this.desc.writeTo(data);
77 public int hashCode() {
78 final int prime = 313;
79 int result = super.hashCode();
80 result = prime * result + ((desc == null) ? 0 : desc.hashCode());
81 result = prime * result + reason;
86 public boolean equals(Object obj) {
90 if (!super.equals(obj)) {
93 if (!(obj instanceof OFPortStatus)) {
96 OFPortStatus other = (OFPortStatus) obj;
98 if (other.desc != null) {
101 } else if (!desc.equals(other.desc)) {
104 if (reason != other.reason) {