Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / OFPortStatus.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4
5 import org.openflow.util.U16;
6
7 /**
8  * Represents an ofp_port_status message
9  * @author David Erickson (daviderickson@cs.stanford.edu)
10  */
11 public class OFPortStatus extends OFMessage {
12     public static int MINIMUM_LENGTH = 64;
13
14     public enum OFPortReason {
15         OFPPR_ADD,
16         OFPPR_DELETE,
17         OFPPR_MODIFY
18     }
19
20     protected byte reason;
21     protected OFPhysicalPort desc;
22
23     /**
24      * @return the reason
25      */
26     public byte getReason() {
27         return reason;
28     }
29
30     /**
31      * @param reason the reason to set
32      */
33     public void setReason(byte reason) {
34         this.reason = reason;
35     }
36
37     /**
38      * @return the desc
39      */
40     public OFPhysicalPort getDesc() {
41         return desc;
42     }
43
44     /**
45      * @param desc the desc to set
46      */
47     public void setDesc(OFPhysicalPort desc) {
48         this.desc = desc;
49     }
50
51     public OFPortStatus() {
52         super();
53         this.type = OFType.PORT_STATUS;
54         this.length = U16.t(MINIMUM_LENGTH);
55     }
56
57     @Override
58     public void readFrom(ByteBuffer data) {
59         super.readFrom(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);
65     }
66
67     @Override
68     public void writeTo(ByteBuffer data) {
69         super.writeTo(data);
70         data.put(this.reason);
71         for (int i = 0; i < 7; ++i)
72             data.put((byte) 0);
73         this.desc.writeTo(data);
74     }
75
76     @Override
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;
82         return result;
83     }
84
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj) {
88             return true;
89         }
90         if (!super.equals(obj)) {
91             return false;
92         }
93         if (!(obj instanceof OFPortStatus)) {
94             return false;
95         }
96         OFPortStatus other = (OFPortStatus) obj;
97         if (desc == null) {
98             if (other.desc != null) {
99                 return false;
100             }
101         } else if (!desc.equals(other.desc)) {
102             return false;
103         }
104         if (reason != other.reason) {
105             return false;
106         }
107         return true;
108     }
109 }