2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.pcepio.types;
18 import java.util.Objects;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.pcepio.protocol.PcepVersion;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.MoreObjects;
26 import com.google.common.base.MoreObjects.ToStringHelper;
29 * Provides ISIS Area Identifier.
31 public class ISISAreaIdentifierTlv implements PcepValueType {
33 /* Reference :[I-D.ietf-idr- ls-distribution]/3.3.1.2
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=[TBD24] | Length |
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 // Area Identifier (variable) //
40 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 protected static final Logger log = LoggerFactory.getLogger(ISISAreaIdentifierTlv.class);
45 public static final short TYPE = 107; //TODO:NEED TO HANDLE TBD24
46 private short hLength;
48 private final byte[] rawValue;
51 * Constructor to initialize rawValue.
53 * @param rawValue ISIS-Area-Identifier
54 * @param hLength length
56 public ISISAreaIdentifierTlv(byte[] rawValue, short hLength) {
57 log.debug("ISISAreaIdentifierTlv");
58 this.rawValue = rawValue;
60 this.hLength = (short) rawValue.length;
62 this.hLength = hLength;
67 * Returns newly created ISISAreaIdentifierTlv object.
69 * @param raw ISIS-Area-Identifier
70 * @param hLength length
71 * @return object of ISISAreaIdentifierTlv
73 public static ISISAreaIdentifierTlv of(final byte[] raw, short hLength) {
74 return new ISISAreaIdentifierTlv(raw, hLength);
78 * Returns value of ISIS-Area-Identifier.
80 * @return byte array of rawValue
82 public byte[] getValue() {
87 public PcepVersion getVersion() {
88 return PcepVersion.PCEP_1;
92 public short getType() {
97 public short getLength() {
102 public int hashCode() {
103 return Objects.hash(rawValue);
107 public boolean equals(Object obj) {
111 if (obj instanceof ISISAreaIdentifierTlv) {
112 ISISAreaIdentifierTlv other = (ISISAreaIdentifierTlv) obj;
113 return Objects.equals(hLength, other.hLength) && Objects.equals(rawValue, other.rawValue);
119 public int write(ChannelBuffer c) {
120 int iLenStartIndex = c.writerIndex();
122 c.writeShort(hLength);
123 c.writeBytes(rawValue);
124 return c.writerIndex() - iLenStartIndex;
128 * Reads the channel buffer and returns object of ISISAreaIdentifierTlv.
130 * @param c input channel buffer
131 * @param hLength length
132 * @return object of ISISAreaIdentifierTlv
134 public static PcepValueType read(ChannelBuffer c, short hLength) {
135 byte[] iISISAreaIdentifier = new byte[hLength];
136 c.readBytes(iISISAreaIdentifier, 0, hLength);
137 return new ISISAreaIdentifierTlv(iISISAreaIdentifier, hLength);
141 public String toString() {
142 ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
144 toStrHelper.add("Type", TYPE);
145 toStrHelper.add("Length", hLength);
147 StringBuffer result = new StringBuffer();
148 for (byte b : rawValue) {
149 result.append(String.format("%02X ", b));
151 toStrHelper.add("Value", result);
153 return toStrHelper.toString();