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