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.Objects;
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 Is Is Administrative area.
33 public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType {
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpLinkAttrIsIsAdminstGrp.class);
38 public static final int ATTRLINK_PROTECTIONTYPE = 1088;
39 public static final int ISIS_ADMIN_DATA_LEN = 4;
41 /* ISIS administrative group */
42 private final long isisAdminGrp;
45 * Constructor to initialize the values.
47 * @param isisAdminGrp ISIS protocol admin group
49 public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) {
50 this.isisAdminGrp = isisAdminGrp;
54 * Returns object of this class with specified values.
56 * @param isisAdminGrp ISIS admin group
57 * @return object of BgpLinkAttrIsIsAdminstGrp
59 public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) {
60 return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp);
64 * Reads the BGP link attributes of ISIS administrative group area.
66 * @param cb Channel buffer
67 * @return object of type BgpLinkAttrIsIsAdminstGrp
68 * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp
70 public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb)
71 throws BGPParseException {
73 short lsAttrLength = cb.readShort();
75 if ((lsAttrLength != ISIS_ADMIN_DATA_LEN)
76 || (cb.readableBytes() < lsAttrLength)) {
77 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
78 BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
82 isisAdminGrp = cb.readUnsignedInt();
84 return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp);
88 * Link attributes of ISIS administrative group area.
90 * @return long value of the administrative group area
92 public long linkAttrIsIsAdminGrp() {
97 public short getType() {
98 return ATTRLINK_PROTECTIONTYPE;
102 public int hashCode() {
103 return Objects.hash(isisAdminGrp);
107 public boolean equals(Object obj) {
112 if (obj instanceof BgpLinkAttrIsIsAdminstGrp) {
113 BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj;
114 return Objects.equals(isisAdminGrp, other.isisAdminGrp);
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())
128 .add("isisAdminGrp", isisAdminGrp).toString();