Praseed Balakrishnan | 2ed6da0 | 2014-09-18 17:02:48 -0700 | [diff] [blame^] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import com.google.common.collect.ComparisonChain; |
| 4 | import org.jboss.netty.buffer.ChannelBuffer; |
| 5 | import org.projectfloodlight.openflow.exceptions.OFParseError; |
| 6 | |
| 7 | import com.google.common.hash.PrimitiveSink; |
| 8 | |
| 9 | |
| 10 | public class CircuitSignalID implements OFValueType<CircuitSignalID> { |
| 11 | static final int length = 6; |
| 12 | |
| 13 | private byte gridType; |
| 14 | private byte channelSpacing ; |
| 15 | private short channelNumber; |
| 16 | private short spectralWidth; |
| 17 | |
| 18 | public static final CircuitSignalID NONE = new CircuitSignalID((byte)0, |
| 19 | (byte)0, |
| 20 | (short)0, |
| 21 | (short)0); |
| 22 | |
| 23 | |
| 24 | public CircuitSignalID(byte gridType, byte channelSpacing, |
| 25 | short channelNumber, |
| 26 | short spectralWidth) |
| 27 | { |
| 28 | this.gridType = gridType; |
| 29 | this.channelSpacing = channelSpacing; |
| 30 | this.channelNumber = channelNumber; |
| 31 | this.spectralWidth = spectralWidth; |
| 32 | |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public int getLength() { |
| 37 | return length; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | public void write6Bytes(ChannelBuffer c) { |
| 42 | c.writeByte(gridType); |
| 43 | c.writeByte(channelSpacing); |
| 44 | c.writeShort(channelNumber); |
| 45 | c.writeShort(spectralWidth); |
| 46 | } |
| 47 | |
| 48 | public static CircuitSignalID read6Bytes(ChannelBuffer c) throws OFParseError { |
| 49 | return new CircuitSignalID((byte)c.readUnsignedByte(), |
| 50 | (byte)c.readUnsignedByte(), |
| 51 | (short)c.readUnsignedShort(), |
| 52 | (short)c.readUnsignedShort()); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public boolean equals(Object o) { |
| 57 | if (this == o) return true; |
| 58 | if (o == null || getClass() != o.getClass()) return false; |
| 59 | |
| 60 | CircuitSignalID that = (CircuitSignalID) o; |
| 61 | |
| 62 | if (channelNumber != that.channelNumber) return false; |
| 63 | if (channelSpacing != that.channelSpacing) return false; |
| 64 | if (gridType != that.gridType) return false; |
| 65 | if (spectralWidth != that.spectralWidth) return false; |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | int result = (int) gridType; |
| 73 | result = 31 * result + (int) channelSpacing; |
| 74 | result = 31 * result + (int) channelNumber; |
| 75 | result = 31 * result + (int) spectralWidth; |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return "CircuitSignalID{" + |
| 82 | "gridType=" + gridType + |
| 83 | ", channelSpacing=" + channelSpacing + |
| 84 | ", channelNumber=" + channelNumber + |
| 85 | ", spectralWidth=" + spectralWidth + |
| 86 | '}'; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public CircuitSignalID applyMask(CircuitSignalID mask) { |
| 91 | return new CircuitSignalID((byte) (this.gridType & mask.gridType), |
| 92 | (byte) (this.channelSpacing & mask |
| 93 | .channelSpacing), |
| 94 | (short) (this.channelNumber & mask |
| 95 | .channelNumber), |
| 96 | (short) (this.spectralWidth & mask |
| 97 | .spectralWidth)); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | @Override |
| 102 | public int compareTo(CircuitSignalID o) { |
| 103 | return ComparisonChain.start() |
| 104 | .compare(gridType,o.gridType) |
| 105 | .compare(channelSpacing,o.channelSpacing) |
| 106 | .compare(channelNumber,o.channelNumber) |
| 107 | .compare(spectralWidth,o.spectralWidth) |
| 108 | .result(); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | @Override |
| 113 | public void putTo(PrimitiveSink sink) { |
| 114 | sink.putByte(gridType); |
| 115 | sink.putByte(channelSpacing); |
| 116 | sink.putShort(channelNumber); |
| 117 | sink.putShort(spectralWidth); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | } |