Committed by
Gerrit Code Review
[Emu][onos-2603] - Implement LinkState Link attributes-Link Name
Change-Id: I3bc3c59f8afef2f46148c061f454e8830628513a
Showing
1 changed file
with
119 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.Arrays; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
23 | +import org.onosproject.bgpio.types.BGPErrorType; | ||
24 | +import org.onosproject.bgpio.types.BGPValueType; | ||
25 | +import org.onosproject.bgpio.util.Validation; | ||
26 | +import org.slf4j.Logger; | ||
27 | +import org.slf4j.LoggerFactory; | ||
28 | + | ||
29 | +import com.google.common.base.MoreObjects; | ||
30 | + | ||
31 | +/** | ||
32 | + * Implements BGP link name attribute. | ||
33 | + */ | ||
34 | +public class BgpLinkAttrName implements BGPValueType { | ||
35 | + | ||
36 | + protected static final Logger log = LoggerFactory | ||
37 | + .getLogger(BgpLinkAttrName.class); | ||
38 | + | ||
39 | + public static final int ATTRLINK_NAME = 1098; | ||
40 | + | ||
41 | + /* Link Name */ | ||
42 | + private byte[] linkName; | ||
43 | + | ||
44 | + /** | ||
45 | + * Constructor to initialize the values. | ||
46 | + * | ||
47 | + * @param linkName link name | ||
48 | + */ | ||
49 | + BgpLinkAttrName(byte[] linkName) { | ||
50 | + this.linkName = Arrays.copyOf(linkName, linkName.length); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Reads the BGP link attributes Name. | ||
55 | + * | ||
56 | + * @param cb Channel buffer | ||
57 | + * @return object of type BgpLinkAttrName | ||
58 | + * @throws BGPParseException while parsing BgpLinkAttrName | ||
59 | + */ | ||
60 | + public static BgpLinkAttrName read(ChannelBuffer cb) | ||
61 | + throws BGPParseException { | ||
62 | + byte[] linkName; | ||
63 | + short lsAttrLength = cb.readShort(); | ||
64 | + | ||
65 | + if (cb.readableBytes() < lsAttrLength) { | ||
66 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
67 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
68 | + lsAttrLength); | ||
69 | + } | ||
70 | + | ||
71 | + linkName = new byte[lsAttrLength]; | ||
72 | + cb.readBytes(linkName); | ||
73 | + return new BgpLinkAttrName(linkName); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Returns the link name. | ||
78 | + * | ||
79 | + * @return link name | ||
80 | + */ | ||
81 | + byte[] getAttrLinkName() { | ||
82 | + return linkName; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public short getType() { | ||
87 | + return ATTRLINK_NAME; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public int hashCode() { | ||
92 | + return Objects.hash(linkName); | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public boolean equals(Object obj) { | ||
97 | + if (this == obj) { | ||
98 | + return true; | ||
99 | + } | ||
100 | + | ||
101 | + if (obj instanceof BgpLinkAttrName) { | ||
102 | + BgpLinkAttrName other = (BgpLinkAttrName) obj; | ||
103 | + return Objects.equals(linkName, other.linkName); | ||
104 | + } | ||
105 | + return false; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public int write(ChannelBuffer cb) { | ||
110 | + // TODO This will be implemented in the next version | ||
111 | + return 0; | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public String toString() { | ||
116 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
117 | + .add("linkName", linkName).toString(); | ||
118 | + } | ||
119 | +} |
-
Please register or login to post a comment