Mahesh Poojary S | 5afd06c | 2015-08-21 14:51:04 +0530 | [diff] [blame^] | 1 | package org.onosproject.pcepio.types;
|
| 2 |
|
| 3 | import java.util.Objects;
|
| 4 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 5 | import org.onosproject.pcepio.protocol.PcepVersion;
|
| 6 | import org.slf4j.Logger;
|
| 7 | import org.slf4j.LoggerFactory;
|
| 8 |
|
| 9 | import com.google.common.base.MoreObjects;
|
| 10 |
|
| 11 | /**
|
| 12 | * Provides CEP LABEL DB VERSION TLV which contains LSP State DB Version (32 Bit ).
|
| 13 | */
|
| 14 | public class PcepLabelDbVerTlv implements PcepValueType {
|
| 15 |
|
| 16 | /* PCEP LABEL DB VERSION TLV format
|
| 17 |
|
| 18 | Reference : draft-ietf-pce-stateful-sync-optimizations-02, section 3.3.1
|
| 19 | 0 1 2 3
|
| 20 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 21 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 22 | | Type=23 | Length=8 |
|
| 23 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 24 | | LSP State DB Version |
|
| 25 | | |
|
| 26 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 27 |
|
| 28 | */
|
| 29 | protected static final Logger log = LoggerFactory.getLogger(PcepLabelDbVerTlv.class);
|
| 30 |
|
| 31 | public static final short TYPE = 34;
|
| 32 | public static final short LENGTH = 8;
|
| 33 | private final long rawValue;
|
| 34 |
|
| 35 | /**
|
| 36 | * constructor to initialize rawValue.
|
| 37 | *
|
| 38 | * @param rawValue of Pcep Label Db Version Tlv
|
| 39 | */
|
| 40 | public PcepLabelDbVerTlv(final long rawValue) {
|
| 41 | log.debug("PcepLabelDbVerTlv");
|
| 42 | this.rawValue = rawValue;
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Returns newly created PcepLabelDbVerTlv object.
|
| 47 | *
|
| 48 | * @param raw LSP State DB Version
|
| 49 | * @return object of PcepLabelDbVerTlv
|
| 50 | */
|
| 51 | public static PcepLabelDbVerTlv of(final long raw) {
|
| 52 | return new PcepLabelDbVerTlv(raw);
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | public PcepVersion getVersion() {
|
| 57 | return PcepVersion.PCEP_1;
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Returns LSP State DB Version.
|
| 62 | * @return raw value
|
| 63 | */
|
| 64 | public long getLong() {
|
| 65 | return rawValue;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public short getLength() {
|
| 70 | return LENGTH;
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public short getType() {
|
| 75 | return TYPE;
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | public int hashCode() {
|
| 80 | return Objects.hash(rawValue);
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | public boolean equals(Object obj) {
|
| 85 | if (this == obj) {
|
| 86 | return true;
|
| 87 | }
|
| 88 | if (obj instanceof PceccCapabilityTlv) {
|
| 89 | PcepLabelDbVerTlv other = (PcepLabelDbVerTlv) obj;
|
| 90 | return Objects.equals(this.rawValue, other.rawValue);
|
| 91 | }
|
| 92 | return false;
|
| 93 | }
|
| 94 |
|
| 95 | @Override
|
| 96 | public int write(ChannelBuffer c) {
|
| 97 | int iLenStartIndex = c.writerIndex();
|
| 98 | c.writeShort(TYPE);
|
| 99 | c.writeShort(LENGTH);
|
| 100 | c.writeLong(rawValue);
|
| 101 | return c.writerIndex() - iLenStartIndex;
|
| 102 | }
|
| 103 |
|
| 104 | /**
|
| 105 | * Reads the channel buffer and returns object of PcepLabelDbVerTlv.
|
| 106 | *
|
| 107 | * @param c input channel buffer
|
| 108 | * @return object of PcepLabelDbVerTlv
|
| 109 | */
|
| 110 | public static PcepLabelDbVerTlv read(ChannelBuffer c) {
|
| 111 | return PcepLabelDbVerTlv.of(c.readLong());
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | public String toString() {
|
| 116 | return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
|
| 117 | .toString();
|
| 118 | }
|
| 119 | }
|