Committed by
Gerrit Code Review
[Emu][onos-2603] - Implement LinkState attributes Router ID
Change-Id: Ie6be0f01a61b66063b11c8cac4c824fba4f4a2a3
Showing
2 changed files
with
248 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.onlab.packet.Ip4Address; | ||
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 attribute node router ID. | ||
33 | + */ | ||
34 | +public class BgpAttrRouterIdV4 implements BGPValueType { | ||
35 | + | ||
36 | + protected static final Logger log = LoggerFactory | ||
37 | + .getLogger(BgpAttrRouterIdV4.class); | ||
38 | + | ||
39 | + public short sType; | ||
40 | + | ||
41 | + /* IPv4 Router-ID of Node */ | ||
42 | + private Ip4Address ip4RouterId; | ||
43 | + | ||
44 | + /** | ||
45 | + * Constructor to initialize the value. | ||
46 | + * | ||
47 | + * @param ip4RouterId IPV4 address of router | ||
48 | + * @param sType TLV type | ||
49 | + */ | ||
50 | + BgpAttrRouterIdV4(Ip4Address ip4RouterId, short sType) { | ||
51 | + this.ip4RouterId = ip4RouterId; | ||
52 | + this.sType = sType; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Reads the IPv4 Router-ID. | ||
57 | + * | ||
58 | + * @param cb ChannelBuffer | ||
59 | + * @return object of BgpAttrRouterIdV4 | ||
60 | + * @throws BGPParseException while parsing BgpAttrNodeRouterId | ||
61 | + */ | ||
62 | + public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType) | ||
63 | + throws BGPParseException { | ||
64 | + byte[] ipBytes; | ||
65 | + Ip4Address ip4RouterId; | ||
66 | + | ||
67 | + short lsAttrLength = cb.readShort(); | ||
68 | + | ||
69 | + if (4 != lsAttrLength) { | ||
70 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
71 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
72 | + lsAttrLength); | ||
73 | + } | ||
74 | + | ||
75 | + ipBytes = new byte[lsAttrLength]; | ||
76 | + cb.readBytes(ipBytes); | ||
77 | + ip4RouterId = Ip4Address.valueOf(ipBytes); | ||
78 | + return new BgpAttrRouterIdV4(ip4RouterId, sType); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns the IPV4 router ID. | ||
83 | + * | ||
84 | + * @return Router ID | ||
85 | + */ | ||
86 | + Ip4Address getAttrRouterId() { | ||
87 | + return ip4RouterId; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public short getType() { | ||
92 | + return sType; | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public int hashCode() { | ||
97 | + return Objects.hash(ip4RouterId); | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public boolean equals(Object obj) { | ||
102 | + if (this == obj) { | ||
103 | + return true; | ||
104 | + } | ||
105 | + | ||
106 | + if (obj instanceof BgpAttrRouterIdV4) { | ||
107 | + BgpAttrRouterIdV4 other = (BgpAttrRouterIdV4) obj; | ||
108 | + return Objects.equals(ip4RouterId, other.ip4RouterId); | ||
109 | + } | ||
110 | + return false; | ||
111 | + } | ||
112 | + | ||
113 | + @Override | ||
114 | + public int write(ChannelBuffer cb) { | ||
115 | + // TODO Auto-generated method stub | ||
116 | + return 0; | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public String toString() { | ||
121 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
122 | + .add("ip4RouterId", ip4RouterId).toString(); | ||
123 | + } | ||
124 | +} |
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.onlab.packet.Ip6Address; | ||
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 attribute IPv6 router ID. | ||
33 | + */ | ||
34 | +public class BgpAttrRouterIdV6 implements BGPValueType { | ||
35 | + | ||
36 | + protected static final Logger log = LoggerFactory | ||
37 | + .getLogger(BgpAttrRouterIdV6.class); | ||
38 | + | ||
39 | + public short sType; | ||
40 | + | ||
41 | + /* IPv4 Router-ID of Node */ | ||
42 | + private Ip6Address ip6RouterId; | ||
43 | + | ||
44 | + /** | ||
45 | + * Constructor to initialize the value. | ||
46 | + * | ||
47 | + * @param ip6RouterId IPV6 address of the router ID | ||
48 | + * @param sType TLV type | ||
49 | + */ | ||
50 | + BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) { | ||
51 | + this.ip6RouterId = ip6RouterId; | ||
52 | + this.sType = sType; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Reads the IPv6 Router-ID. | ||
57 | + * | ||
58 | + * @param cb ChannelBuffer | ||
59 | + * @return object of BgpAttrRouterIdV6 | ||
60 | + * @throws BGPParseException while parsing BgpAttrRouterIdV6 | ||
61 | + */ | ||
62 | + public static BgpAttrRouterIdV6 read(ChannelBuffer cb, short sType) | ||
63 | + throws BGPParseException { | ||
64 | + byte[] ipBytes; | ||
65 | + Ip6Address ip6RouterId; | ||
66 | + | ||
67 | + short lsAttrLength = cb.readShort(); | ||
68 | + | ||
69 | + if (16 != lsAttrLength) { | ||
70 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
71 | + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | ||
72 | + lsAttrLength); | ||
73 | + } | ||
74 | + | ||
75 | + ipBytes = new byte[lsAttrLength]; | ||
76 | + cb.readBytes(ipBytes); | ||
77 | + ip6RouterId = Ip6Address.valueOf(ipBytes); | ||
78 | + return new BgpAttrRouterIdV6(ip6RouterId, sType); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns IPV6 router ID. | ||
83 | + * | ||
84 | + * @return Router ID | ||
85 | + */ | ||
86 | + Ip6Address getAttrRouterId() { | ||
87 | + return ip6RouterId; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public short getType() { | ||
92 | + return sType; | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public int hashCode() { | ||
97 | + return Objects.hash(ip6RouterId); | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public boolean equals(Object obj) { | ||
102 | + if (this == obj) { | ||
103 | + return true; | ||
104 | + } | ||
105 | + | ||
106 | + if (obj instanceof BgpAttrRouterIdV6) { | ||
107 | + BgpAttrRouterIdV6 other = (BgpAttrRouterIdV6) obj; | ||
108 | + return Objects.equals(ip6RouterId, other.ip6RouterId); | ||
109 | + } | ||
110 | + return false; | ||
111 | + } | ||
112 | + | ||
113 | + @Override | ||
114 | + public int write(ChannelBuffer cb) { | ||
115 | + // TODO Auto-generated method stub | ||
116 | + return 0; | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public String toString() { | ||
121 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
122 | + .add("ip6RouterId", ip6RouterId).toString(); | ||
123 | + } | ||
124 | +} |
-
Please register or login to post a comment