blob: fa391a9776a3b9e1cbf4ff3114023691279e0cd0 [file] [log] [blame]
Thejaswi N K0b516ba2015-11-11 01:14:01 +05301/*
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 */
16package org.onosproject.bgpio.types.attr;
17
18import java.util.Objects;
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 N K0b516ba2015-11-11 01:14:01 +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 Is Is Administrative area.
32 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053033public final class BgpLinkAttrIsIsAdminstGrp implements BgpValueType {
Thejaswi N K0b516ba2015-11-11 01:14:01 +053034
35 protected static final Logger log = LoggerFactory
36 .getLogger(BgpLinkAttrIsIsAdminstGrp.class);
37
38 public static final int ATTRLINK_PROTECTIONTYPE = 1088;
39 public static final int ISIS_ADMIN_DATA_LEN = 4;
40
41 /* ISIS administrative group */
42 private final long isisAdminGrp;
43
44 /**
45 * Constructor to initialize the values.
46 *
47 * @param isisAdminGrp ISIS protocol admin group
48 */
49 public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) {
50 this.isisAdminGrp = isisAdminGrp;
51 }
52
53 /**
54 * Returns object of this class with specified values.
55 *
56 * @param isisAdminGrp ISIS admin group
57 * @return object of BgpLinkAttrIsIsAdminstGrp
58 */
59 public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) {
60 return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp);
61 }
62
63 /**
64 * Reads the BGP link attributes of ISIS administrative group area.
65 *
66 * @param cb Channel buffer
67 * @return object of type BgpLinkAttrIsIsAdminstGrp
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053068 * @throws BgpParseException while parsing BgpLinkAttrIsIsAdminstGrp
Thejaswi N K0b516ba2015-11-11 01:14:01 +053069 */
70 public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb)
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053071 throws BgpParseException {
Thejaswi N K0b516ba2015-11-11 01:14:01 +053072 long isisAdminGrp;
73 short lsAttrLength = cb.readShort();
74
75 if ((lsAttrLength != ISIS_ADMIN_DATA_LEN)
76 || (cb.readableBytes() < lsAttrLength)) {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053077 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
78 BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
Thejaswi N K0b516ba2015-11-11 01:14:01 +053079 lsAttrLength);
80 }
81
82 isisAdminGrp = cb.readUnsignedInt();
83
84 return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp);
85 }
86
87 /**
88 * Link attributes of ISIS administrative group area.
89 *
90 * @return long value of the administrative group area
91 */
92 public long linkAttrIsIsAdminGrp() {
93 return isisAdminGrp;
94 }
95
96 @Override
97 public short getType() {
98 return ATTRLINK_PROTECTIONTYPE;
99 }
100
101 @Override
102 public int hashCode() {
103 return Objects.hash(isisAdminGrp);
104 }
105
106 @Override
107 public boolean equals(Object obj) {
108 if (this == obj) {
109 return true;
110 }
111
112 if (obj instanceof BgpLinkAttrIsIsAdminstGrp) {
113 BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj;
114 return Objects.equals(isisAdminGrp, other.isisAdminGrp);
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())
128 .add("isisAdminGrp", isisAdminGrp).toString();
129 }
130}