Committed by
Gerrit Code Review
[onos-2603] - Implement Is Is Administrative area
Change-Id: I28c1b5461dd719af920f6c28f3b8f1e4e05222eb
Showing
1 changed file
with
130 additions
and
0 deletions
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.bgpio.types.attr; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
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; | ||
27 | + | ||
28 | +import com.google.common.base.MoreObjects; | ||
29 | + | ||
30 | +/** | ||
31 | + * Implements BGP attribute Is Is Administrative area. | ||
32 | + */ | ||
33 | +public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType { | ||
34 | + | ||
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 | ||
68 | + * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp | ||
69 | + */ | ||
70 | + public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb) | ||
71 | + throws BGPParseException { | ||
72 | + long isisAdminGrp; | ||
73 | + short lsAttrLength = cb.readShort(); | ||
74 | + | ||
75 | + if ((lsAttrLength != ISIS_ADMIN_DATA_LEN) | ||
76 | + || (cb.readableBytes() < lsAttrLength)) { | ||
77 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
78 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
79 | + 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 | +} |
-
Please register or login to post a comment