4c2298d31539c5432d2d64173649f5027faefa0c
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / OFPPortMod.java
1 package org.openflow.codec.protocol;
2
3 import java.util.Arrays;
4
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.util.U16;
7
8 /**
9  * Represents an ofp_port_mod message
10  *
11  * @author David Erickson (daviderickson@cs.stanford.edu)
12  */
13 public class OFPPortMod extends OFPMessage {
14     public static int MINIMUM_LENGTH = 40;
15
16     protected int portNumber;
17     protected byte[] hardwareAddress;
18     protected int config;
19     protected int mask;
20     protected int advertise;
21
22     public OFPPortMod() {
23         super();
24         this.type = OFPType.PORT_MOD;
25         this.length = U16.t(MINIMUM_LENGTH);
26     }
27
28     /**
29      * @return the portNumber
30      */
31     public int getPortNumber() {
32         return portNumber;
33     }
34
35     /**
36      * @param portNumber
37      *            the portNumber to set
38      */
39     public void setPortNumber(int portNumber) {
40         this.portNumber = portNumber;
41     }
42
43     /**
44      * @return the hardwareAddress
45      */
46     public byte[] getHardwareAddress() {
47         return hardwareAddress;
48     }
49
50     /**
51      * @param hardwareAddress
52      *            the hardwareAddress to set
53      */
54     public void setHardwareAddress(byte[] hardwareAddress) {
55         if (hardwareAddress.length != OFPPort.OFP_ETH_ALEN)
56             throw new RuntimeException("Hardware address must have length " + OFPPort.OFP_ETH_ALEN);
57         this.hardwareAddress = hardwareAddress;
58     }
59
60     /**
61      * @return the config
62      */
63     public int getConfig() {
64         return config;
65     }
66
67     /**
68      * @param config
69      *            the config to set
70      */
71     public void setConfig(int config) {
72         this.config = config;
73     }
74
75     /**
76      * @return the mask
77      */
78     public int getMask() {
79         return mask;
80     }
81
82     /**
83      * @param mask
84      *            the mask to set
85      */
86     public void setMask(int mask) {
87         this.mask = mask;
88     }
89
90     /**
91      * @return the advertise
92      */
93     public int getAdvertise() {
94         return advertise;
95     }
96
97     /**
98      * @param advertise
99      *            the advertise to set
100      */
101     public void setAdvertise(int advertise) {
102         this.advertise = advertise;
103     }
104
105     @Override
106     public void readFrom(IDataBuffer data) {
107         super.readFrom(data);
108         this.portNumber = data.getInt();
109         data.getInt(); // pad
110         if (this.hardwareAddress == null)
111             this.hardwareAddress = new byte[OFPPort.OFP_ETH_ALEN];
112         data.get(this.hardwareAddress);
113         data.getShort(); // pad
114         this.config = data.getInt();
115         this.mask = data.getInt();
116         this.advertise = data.getInt();
117         data.getShort(); // pad
118         data.get(); // pad
119     }
120
121     @Override
122     public void writeTo(IDataBuffer data) {
123         super.writeTo(data);
124         data.putInt(this.portNumber);
125         data.putInt(0); // pad
126         data.put(this.hardwareAddress);
127         data.putShort((short) 0); // pad
128         data.putInt(this.config);
129         data.putInt(this.mask);
130         data.putInt(this.advertise);
131         data.putShort((short) 0); // pad
132         data.put((byte) 0); // pad
133     }
134
135     @Override
136     public int hashCode() {
137         final int prime = 311;
138         int result = super.hashCode();
139         result = prime * result + advertise;
140         result = prime * result + config;
141         result = prime * result + Arrays.hashCode(hardwareAddress);
142         result = prime * result + mask;
143         result = prime * result + portNumber;
144         return result;
145     }
146
147     @Override
148     public boolean equals(Object obj) {
149         if (this == obj) {
150             return true;
151         }
152         if (!super.equals(obj)) {
153             return false;
154         }
155         if (!(obj instanceof OFPPortMod)) {
156             return false;
157         }
158         OFPPortMod other = (OFPPortMod) obj;
159         if (advertise != other.advertise) {
160             return false;
161         }
162         if (config != other.config) {
163             return false;
164         }
165         if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
166             return false;
167         }
168         if (mask != other.mask) {
169             return false;
170         }
171         if (portNumber != other.portNumber) {
172             return false;
173         }
174         return true;
175     }
176 }