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.bgpio.types.attr;
18 import java.util.Arrays;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.bgpio.exceptions.BgpParseException;
22 import org.onosproject.bgpio.types.BgpErrorType;
23 import org.onosproject.bgpio.types.BgpValueType;
24 import org.onosproject.bgpio.util.Validation;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.base.MoreObjects;
31 * Implements BGP attribute ISIS Area Identifier.
33 public class BgpAttrNodeIsIsAreaId implements BgpValueType {
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpAttrNodeIsIsAreaId.class);
38 public static final int ATTRNODE_ISISAREAID = 1027;
40 /* IS-IS Area Identifier TLV */
41 private byte[] isisAreaId;
44 * Constructor to initialize value.
46 * @param isisAreaId ISIS area Identifier
48 public BgpAttrNodeIsIsAreaId(byte[] isisAreaId) {
49 this.isisAreaId = Arrays.copyOf(isisAreaId, isisAreaId.length);
53 * Returns object of this class with specified values.
55 * @param isisAreaId ISIS area Identifier
56 * @return object of BgpAttrNodeIsIsAreaId
58 public static BgpAttrNodeIsIsAreaId of(final byte[] isisAreaId) {
59 return new BgpAttrNodeIsIsAreaId(isisAreaId);
63 * Reads the IS-IS Area Identifier.
65 * @param cb ChannelBuffer
66 * @return object of BgpAttrNodeIsIsAreaId
67 * @throws BgpParseException while parsing BgpAttrNodeIsIsAreaId
69 public static BgpAttrNodeIsIsAreaId read(ChannelBuffer cb)
70 throws BgpParseException {
73 short lsAttrLength = cb.readShort();
75 if (cb.readableBytes() < lsAttrLength) {
76 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
77 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
81 isisAreaId = new byte[lsAttrLength];
82 cb.readBytes(isisAreaId);
84 return BgpAttrNodeIsIsAreaId.of(isisAreaId);
88 * Returns ISIS area Identifier.
92 public byte[] attrNodeIsIsAreaId() {
97 public short getType() {
98 return ATTRNODE_ISISAREAID;
102 public int hashCode() {
103 return Arrays.hashCode(isisAreaId);
107 public boolean equals(Object obj) {
112 if (obj instanceof BgpAttrNodeIsIsAreaId) {
113 BgpAttrNodeIsIsAreaId other = (BgpAttrNodeIsIsAreaId) obj;
114 return Arrays.equals(isisAreaId, other.isisAreaId);
120 public int write(ChannelBuffer cb) {
121 // TODO This will be implemented in the next version
126 public String toString() {
127 return MoreObjects.toStringHelper(getClass()).omitNullValues()
128 .add("isisAreaId", isisAreaId).toString();
132 public int compareTo(Object o) {
133 // TODO Auto-generated method stub