blob: 7a612454e3d896695b4f9f53f8ee261439afca4a [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070016package org.onosproject.pcepio.types;
17
18import java.util.Objects;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.onosproject.pcepio.protocol.PcepVersion;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import com.google.common.base.MoreObjects;
25
26/**
27 * Provides CEP LABEL DB VERSION TLV which contains LSP State DB Version (32 Bit ).
28 */
29public class PcepLabelDbVerTlv implements PcepValueType {
30
31 /* PCEP LABEL DB VERSION TLV format
32
33 Reference : draft-ietf-pce-stateful-sync-optimizations-02, section 3.3.1
34 0 1 2 3
35 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
36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 | Type=23 | Length=8 |
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 | LSP State DB Version |
40 | |
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42
43 */
44 protected static final Logger log = LoggerFactory.getLogger(PcepLabelDbVerTlv.class);
45
46 public static final short TYPE = 34;
47 public static final short LENGTH = 8;
48 private final long rawValue;
49
50 /**
51 * constructor to initialize rawValue.
52 *
53 * @param rawValue of Pcep Label Db Version Tlv
54 */
55 public PcepLabelDbVerTlv(final long rawValue) {
56 log.debug("PcepLabelDbVerTlv");
57 this.rawValue = rawValue;
58 }
59
60 /**
61 * Returns newly created PcepLabelDbVerTlv object.
62 *
63 * @param raw LSP State DB Version
64 * @return object of PcepLabelDbVerTlv
65 */
66 public static PcepLabelDbVerTlv of(final long raw) {
67 return new PcepLabelDbVerTlv(raw);
68 }
69
70 @Override
71 public PcepVersion getVersion() {
72 return PcepVersion.PCEP_1;
73 }
74
75 /**
76 * Returns LSP State DB Version.
77 * @return raw value
78 */
79 public long getLong() {
80 return rawValue;
81 }
82
83 @Override
84 public short getLength() {
85 return LENGTH;
86 }
87
88 @Override
89 public short getType() {
90 return TYPE;
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hash(rawValue);
96 }
97
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj) {
101 return true;
102 }
103 if (obj instanceof PceccCapabilityTlv) {
104 PcepLabelDbVerTlv other = (PcepLabelDbVerTlv) obj;
105 return Objects.equals(this.rawValue, other.rawValue);
106 }
107 return false;
108 }
109
110 @Override
111 public int write(ChannelBuffer c) {
112 int iLenStartIndex = c.writerIndex();
113 c.writeShort(TYPE);
114 c.writeShort(LENGTH);
115 c.writeLong(rawValue);
116 return c.writerIndex() - iLenStartIndex;
117 }
118
119 /**
120 * Reads the channel buffer and returns object of PcepLabelDbVerTlv.
121 *
122 * @param c input channel buffer
123 * @return object of PcepLabelDbVerTlv
124 */
125 public static PcepLabelDbVerTlv read(ChannelBuffer c) {
126 return PcepLabelDbVerTlv.of(c.readLong());
127 }
128
129 @Override
130 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700131 return MoreObjects.toStringHelper(getClass())
132 .add("Type", TYPE)
133 .add("Length", LENGTH)
134 .add("Value", rawValue)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700135 .toString();
136 }
137}