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 | |
Praseed Balakrishnan | db949d4 | 2014-12-02 14:28:20 -0800 | [diff] [blame] | 40 | public byte getGridType() { |
| 41 | return gridType; |
| 42 | } |
| 43 | |
| 44 | public byte getChannelSpacing() { |
| 45 | return channelSpacing; |
| 46 | } |
| 47 | |
| 48 | public short getChannelNumber() { |
| 49 | return channelNumber; |
| 50 | } |
| 51 | |
| 52 | public short getSpectralWidth() { |
| 53 | return spectralWidth; |
| 54 | } |
Praseed Balakrishnan | 2ed6da0 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 55 | |
| 56 | public void write6Bytes(ChannelBuffer c) { |
| 57 | c.writeByte(gridType); |
| 58 | c.writeByte(channelSpacing); |
| 59 | c.writeShort(channelNumber); |
| 60 | c.writeShort(spectralWidth); |
| 61 | } |
| 62 | |
| 63 | public static CircuitSignalID read6Bytes(ChannelBuffer c) throws OFParseError { |
| 64 | return new CircuitSignalID((byte)c.readUnsignedByte(), |
| 65 | (byte)c.readUnsignedByte(), |
| 66 | (short)c.readUnsignedShort(), |
| 67 | (short)c.readUnsignedShort()); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean equals(Object o) { |
| 72 | if (this == o) return true; |
| 73 | if (o == null || getClass() != o.getClass()) return false; |
| 74 | |
| 75 | CircuitSignalID that = (CircuitSignalID) o; |
| 76 | |
| 77 | if (channelNumber != that.channelNumber) return false; |
| 78 | if (channelSpacing != that.channelSpacing) return false; |
| 79 | if (gridType != that.gridType) return false; |
| 80 | if (spectralWidth != that.spectralWidth) return false; |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int hashCode() { |
| 87 | int result = (int) gridType; |
| 88 | result = 31 * result + (int) channelSpacing; |
| 89 | result = 31 * result + (int) channelNumber; |
| 90 | result = 31 * result + (int) spectralWidth; |
| 91 | return result; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public String toString() { |
| 96 | return "CircuitSignalID{" + |
| 97 | "gridType=" + gridType + |
| 98 | ", channelSpacing=" + channelSpacing + |
| 99 | ", channelNumber=" + channelNumber + |
| 100 | ", spectralWidth=" + spectralWidth + |
| 101 | '}'; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public CircuitSignalID applyMask(CircuitSignalID mask) { |
| 106 | return new CircuitSignalID((byte) (this.gridType & mask.gridType), |
| 107 | (byte) (this.channelSpacing & mask |
| 108 | .channelSpacing), |
| 109 | (short) (this.channelNumber & mask |
| 110 | .channelNumber), |
| 111 | (short) (this.spectralWidth & mask |
| 112 | .spectralWidth)); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | @Override |
| 117 | public int compareTo(CircuitSignalID o) { |
| 118 | return ComparisonChain.start() |
| 119 | .compare(gridType,o.gridType) |
| 120 | .compare(channelSpacing,o.channelSpacing) |
| 121 | .compare(channelNumber,o.channelNumber) |
| 122 | .compare(spectralWidth,o.spectralWidth) |
| 123 | .result(); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | @Override |
| 128 | public void putTo(PrimitiveSink sink) { |
| 129 | sink.putByte(gridType); |
| 130 | sink.putByte(channelSpacing); |
| 131 | sink.putShort(channelNumber); |
| 132 | sink.putShort(spectralWidth); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | } |