blob: d8f71a3b7d899a27bbbfbeb293d411ece725ff07 [file] [log] [blame]
Andreas Wundsam40e14f72013-05-06 14:49:08 -07001package org.openflow.types;
2
Yotam Harchol161a5d52013-07-25 17:17:48 -07003import org.jboss.netty.buffer.ChannelBuffer;
4import org.openflow.exceptions.OFParseError;
5
Andreas Wundsam40e14f72013-05-06 14:49:08 -07006/**
7 * A wrapper around the OpenFlow physical port description. The interfaces to
8 * this object are version agnostic.
9 *
10 * @author capveg
11 */
12
Yotam Harchol161a5d52013-07-25 17:17:48 -070013public class OFPhysicalPort implements OFValueType {
14
15 static final int LENGTH = 4;
16
17 private final int port;
18
19 private OFPhysicalPort(int port) {
20 this.port = port;
21 }
22
23 public static OFPhysicalPort of(int port) {
24 return new OFPhysicalPort(port);
25 }
26
27 @Override
28 public int getLength() {
29 return LENGTH;
30 }
Yotam Harchol161a5d52013-07-25 17:17:48 -070031
32 @Override
33 public boolean equals(Object obj) {
34 if (!(obj instanceof OFPhysicalPort))
35 return false;
36 OFPhysicalPort other = (OFPhysicalPort)obj;
37 if (other.port != this.port)
38 return false;
39 return true;
40 }
41
42 @Override
43 public int hashCode() {
44 final int prime = 59;
45 int result = 1;
46 result = prime * result + port;
47 return result;
48 }
49
50 @Override
51 public String toString() {
52 return Integer.toHexString(port);
53 }
54
Yotam Harchold7b84202013-07-26 16:08:10 -070055 public void write4Bytes(ChannelBuffer c) {
56 c.writeInt(this.port);
57 }
Yotam Harchol161a5d52013-07-25 17:17:48 -070058
Yotam Harchold7b84202013-07-26 16:08:10 -070059 public static OFPhysicalPort read4Bytes(ChannelBuffer c) throws OFParseError {
60 return OFPhysicalPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
Yotam Harchol161a5d52013-07-25 17:17:48 -070061 }
Andreas Wundsam40e14f72013-05-06 14:49:08 -070062
63}