blob: cc129c489b4e8f89efc31728c2594d676275c32b [file] [log] [blame]
Thejaswi NK5b9278b2015-10-12 16:59:14 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thejaswi NK5b9278b2015-10-12 16:59:14 +05303 *
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 */
16package org.onosproject.bgpio.types.attr;
17
18import java.util.Arrays;
19
20import org.jboss.netty.buffer.ChannelBuffer;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053021import org.onosproject.bgpio.exceptions.BgpParseException;
22import org.onosproject.bgpio.types.BgpErrorType;
23import org.onosproject.bgpio.types.BgpValueType;
Thejaswi NK5b9278b2015-10-12 16:59:14 +053024import org.onosproject.bgpio.util.Validation;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import com.google.common.base.MoreObjects;
29
30/**
31 * Implements BGP attribute ISIS Area Identifier.
32 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053033public class BgpAttrNodeIsIsAreaId implements BgpValueType {
Thejaswi NK5b9278b2015-10-12 16:59:14 +053034
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpAttrNodeIsIsAreaId.class);
37
38 public static final int ATTRNODE_ISISAREAID = 1027;
39
40 /* IS-IS Area Identifier TLV */
41 private byte[] isisAreaId;
42
43 /**
44 * Constructor to initialize value.
45 *
46 * @param isisAreaId ISIS area Identifier
47 */
48 public BgpAttrNodeIsIsAreaId(byte[] isisAreaId) {
49 this.isisAreaId = Arrays.copyOf(isisAreaId, isisAreaId.length);
50 }
51
52 /**
53 * Returns object of this class with specified values.
54 *
55 * @param isisAreaId ISIS area Identifier
56 * @return object of BgpAttrNodeIsIsAreaId
57 */
58 public static BgpAttrNodeIsIsAreaId of(final byte[] isisAreaId) {
59 return new BgpAttrNodeIsIsAreaId(isisAreaId);
60 }
61
62 /**
63 * Reads the IS-IS Area Identifier.
64 *
65 * @param cb ChannelBuffer
66 * @return object of BgpAttrNodeIsIsAreaId
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053067 * @throws BgpParseException while parsing BgpAttrNodeIsIsAreaId
Thejaswi NK5b9278b2015-10-12 16:59:14 +053068 */
69 public static BgpAttrNodeIsIsAreaId read(ChannelBuffer cb)
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053070 throws BgpParseException {
Thejaswi NK5b9278b2015-10-12 16:59:14 +053071 byte[] isisAreaId;
72
73 short lsAttrLength = cb.readShort();
74
75 if (cb.readableBytes() < lsAttrLength) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053076 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
77 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
Thejaswi NK5b9278b2015-10-12 16:59:14 +053078 lsAttrLength);
79 }
80
81 isisAreaId = new byte[lsAttrLength];
82 cb.readBytes(isisAreaId);
83
84 return BgpAttrNodeIsIsAreaId.of(isisAreaId);
85 }
86
87 /**
88 * Returns ISIS area Identifier.
89 *
90 * @return Area ID
91 */
92 public byte[] attrNodeIsIsAreaId() {
93 return isisAreaId;
94 }
95
96 @Override
97 public short getType() {
98 return ATTRNODE_ISISAREAID;
99 }
100
101 @Override
102 public int hashCode() {
103 return Arrays.hashCode(isisAreaId);
104 }
105
106 @Override
107 public boolean equals(Object obj) {
108 if (this == obj) {
109 return true;
110 }
111
112 if (obj instanceof BgpAttrNodeIsIsAreaId) {
113 BgpAttrNodeIsIsAreaId other = (BgpAttrNodeIsIsAreaId) obj;
114 return Arrays.equals(isisAreaId, other.isisAreaId);
115 }
116 return false;
117 }
118
119 @Override
120 public int write(ChannelBuffer cb) {
121 // TODO This will be implemented in the next version
122 return 0;
123 }
124
125 @Override
126 public String toString() {
127 return MoreObjects.toStringHelper(getClass()).omitNullValues()
128 .add("isisAreaId", isisAreaId).toString();
129 }
Priyanka B02040732015-11-29 11:30:29 +0530130
131 @Override
132 public int compareTo(Object o) {
133 // TODO Auto-generated method stub
134 return 0;
135 }
Thejaswi NK5b9278b2015-10-12 16:59:14 +0530136}