Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | import org.openflow.exceptions.OFParseError; |
| 5 | |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 6 | /** |
| 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 Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame^] | 13 | public class OFPhysicalPort implements OFValueType<OFPhysicalPort> { |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 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 Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 31 | |
| 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 Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 55 | public void write4Bytes(ChannelBuffer c) { |
| 56 | c.writeInt(this.port); |
| 57 | } |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 58 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 59 | public static OFPhysicalPort read4Bytes(ChannelBuffer c) throws OFParseError { |
| 60 | return OFPhysicalPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF)); |
Yotam Harchol | 161a5d5 | 2013-07-25 17:17:48 -0700 | [diff] [blame] | 61 | } |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 62 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame^] | 63 | @Override |
| 64 | public OFPhysicalPort applyMask(OFPhysicalPort mask) { |
| 65 | return OFPhysicalPort.of(this.port & mask.port); |
| 66 | } |
| 67 | |
| 68 | public int getPortNumber() { |
| 69 | return port; |
| 70 | } |
Andreas Wundsam | 40e14f7 | 2013-05-06 14:49:08 -0700 | [diff] [blame] | 71 | } |