Performacne improvements via adding a netty-based openflowj and openflow plugin;...
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / OFPortStatus.java
1 /**
2 *    Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3 *    University
4
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
8 *
9 *         http://www.apache.org/licenses/LICENSE-2.0
10 *
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
15 *    under the License.
16 **/
17
18 package org.openflow.protocol;
19
20
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.openflow.util.U16;
23
24 /**
25  * Represents an ofp_port_status message
26  * @author David Erickson (daviderickson@cs.stanford.edu)
27  */
28 public class OFPortStatus extends OFMessage {
29     public static int MINIMUM_LENGTH = 64;
30
31     public enum OFPortReason {
32         OFPPR_ADD,
33         OFPPR_DELETE,
34         OFPPR_MODIFY
35     }
36
37     protected byte reason;
38     protected OFPhysicalPort desc;
39
40     /**
41      * @return the reason
42      */
43     public byte getReason() {
44         return reason;
45     }
46
47     /**
48      * @param reason the reason to set
49      */
50     public void setReason(byte reason) {
51         this.reason = reason;
52     }
53
54     /**
55      * @return the desc
56      */
57     public OFPhysicalPort getDesc() {
58         return desc;
59     }
60
61     /**
62      * @param desc the desc to set
63      */
64     public void setDesc(OFPhysicalPort desc) {
65         this.desc = desc;
66     }
67
68     public OFPortStatus() {
69         super();
70         this.type = OFType.PORT_STATUS;
71         this.length = U16.t(MINIMUM_LENGTH);
72     }
73
74     @Override
75     public void readFrom(ChannelBuffer data) {
76         super.readFrom(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);
82     }
83
84     @Override
85     public void writeTo(ChannelBuffer data) {
86         super.writeTo(data);
87         data.writeByte(this.reason);
88         for (int i = 0; i < 7; ++i)
89             data.writeByte((byte) 0);
90         this.desc.writeTo(data);
91     }
92
93     @Override
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;
99         return result;
100     }
101
102     @Override
103     public boolean equals(Object obj) {
104         if (this == obj) {
105             return true;
106         }
107         if (!super.equals(obj)) {
108             return false;
109         }
110         if (!(obj instanceof OFPortStatus)) {
111             return false;
112         }
113         OFPortStatus other = (OFPortStatus) obj;
114         if (desc == null) {
115             if (other.desc != null) {
116                 return false;
117             }
118         } else if (!desc.equals(other.desc)) {
119             return false;
120         }
121         if (reason != other.reason) {
122             return false;
123         }
124         return true;
125     }
126 }