Committed by
Gerrit Code Review
[onos-2613] - Unit testing of BgpAttrRouterIdV6
Change-Id: I46f2a821bf80237e74e4732d2315f477b1890480
Showing
2 changed files
with
71 additions
and
9 deletions
... | @@ -31,15 +31,15 @@ import com.google.common.base.MoreObjects; | ... | @@ -31,15 +31,15 @@ import com.google.common.base.MoreObjects; |
31 | /** | 31 | /** |
32 | * Implements BGP attribute IPv6 router ID. | 32 | * Implements BGP attribute IPv6 router ID. |
33 | */ | 33 | */ |
34 | -public class BgpAttrRouterIdV6 implements BGPValueType { | 34 | +public final class BgpAttrRouterIdV6 implements BGPValueType { |
35 | 35 | ||
36 | protected static final Logger log = LoggerFactory | 36 | protected static final Logger log = LoggerFactory |
37 | .getLogger(BgpAttrRouterIdV6.class); | 37 | .getLogger(BgpAttrRouterIdV6.class); |
38 | 38 | ||
39 | - public short sType; | 39 | + private final short sType; |
40 | 40 | ||
41 | /* IPv4 Router-ID of Node */ | 41 | /* IPv4 Router-ID of Node */ |
42 | - private Ip6Address ip6RouterId; | 42 | + private final Ip6Address ip6RouterId; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Constructor to initialize the value. | 45 | * Constructor to initialize the value. |
... | @@ -47,16 +47,28 @@ public class BgpAttrRouterIdV6 implements BGPValueType { | ... | @@ -47,16 +47,28 @@ public class BgpAttrRouterIdV6 implements BGPValueType { |
47 | * @param ip6RouterId IPV6 address of the router ID | 47 | * @param ip6RouterId IPV6 address of the router ID |
48 | * @param sType TLV type | 48 | * @param sType TLV type |
49 | */ | 49 | */ |
50 | - BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) { | 50 | + private BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) { |
51 | this.ip6RouterId = ip6RouterId; | 51 | this.ip6RouterId = ip6RouterId; |
52 | this.sType = sType; | 52 | this.sType = sType; |
53 | } | 53 | } |
54 | 54 | ||
55 | /** | 55 | /** |
56 | + * Returns object of this class with specified values. | ||
57 | + * | ||
58 | + * @param ip6RouterId IPV6 address of the router ID | ||
59 | + * @param sType TLV type | ||
60 | + * @return object of BgpAttrRouterIdV6 | ||
61 | + */ | ||
62 | + public static BgpAttrRouterIdV6 of(final Ip6Address ip6RouterId, | ||
63 | + final short sType) { | ||
64 | + return new BgpAttrRouterIdV6(ip6RouterId, sType); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
56 | * Reads the IPv6 Router-ID. | 68 | * Reads the IPv6 Router-ID. |
57 | * | 69 | * |
58 | * @param cb ChannelBuffer | 70 | * @param cb ChannelBuffer |
59 | - * @param sType type | 71 | + * @param sType TLV type |
60 | * @return object of BgpAttrRouterIdV6 | 72 | * @return object of BgpAttrRouterIdV6 |
61 | * @throws BGPParseException while parsing BgpAttrRouterIdV6 | 73 | * @throws BGPParseException while parsing BgpAttrRouterIdV6 |
62 | */ | 74 | */ |
... | @@ -67,7 +79,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { | ... | @@ -67,7 +79,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { |
67 | 79 | ||
68 | short lsAttrLength = cb.readShort(); | 80 | short lsAttrLength = cb.readShort(); |
69 | 81 | ||
70 | - if (16 != lsAttrLength) { | 82 | + if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) { |
71 | Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | 83 | Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, |
72 | BGPErrorType.ATTRIBUTE_LENGTH_ERROR, | 84 | BGPErrorType.ATTRIBUTE_LENGTH_ERROR, |
73 | lsAttrLength); | 85 | lsAttrLength); |
... | @@ -76,7 +88,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { | ... | @@ -76,7 +88,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { |
76 | ipBytes = new byte[lsAttrLength]; | 88 | ipBytes = new byte[lsAttrLength]; |
77 | cb.readBytes(ipBytes); | 89 | cb.readBytes(ipBytes); |
78 | ip6RouterId = Ip6Address.valueOf(ipBytes); | 90 | ip6RouterId = Ip6Address.valueOf(ipBytes); |
79 | - return new BgpAttrRouterIdV6(ip6RouterId, sType); | 91 | + return BgpAttrRouterIdV6.of(ip6RouterId, sType); |
80 | } | 92 | } |
81 | 93 | ||
82 | /** | 94 | /** |
... | @@ -84,7 +96,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { | ... | @@ -84,7 +96,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { |
84 | * | 96 | * |
85 | * @return Router ID | 97 | * @return Router ID |
86 | */ | 98 | */ |
87 | - Ip6Address getAttrRouterId() { | 99 | + public Ip6Address attrRouterId() { |
88 | return ip6RouterId; | 100 | return ip6RouterId; |
89 | } | 101 | } |
90 | 102 | ||
... | @@ -113,7 +125,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { | ... | @@ -113,7 +125,7 @@ public class BgpAttrRouterIdV6 implements BGPValueType { |
113 | 125 | ||
114 | @Override | 126 | @Override |
115 | public int write(ChannelBuffer cb) { | 127 | public int write(ChannelBuffer cb) { |
116 | - // TODO Auto-generated method stub | 128 | + // TODO This will be implemented in the next version |
117 | return 0; | 129 | return 0; |
118 | } | 130 | } |
119 | 131 | ... | ... |
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.bgp; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | +import org.onlab.packet.Ip6Address; | ||
20 | +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6; | ||
21 | + | ||
22 | +import com.google.common.testing.EqualsTester; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for BGP attribute node router ID. | ||
26 | + */ | ||
27 | +public class BgpAttrRouterIdV6Test { | ||
28 | + | ||
29 | + private final short sType = 1; | ||
30 | + private final Ip6Address ip6RouterId = Ip6Address | ||
31 | + .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); | ||
32 | + | ||
33 | + private final short sType1 = 2; | ||
34 | + private final Ip6Address ip6RouterId1 = Ip6Address | ||
35 | + .valueOf("2004:0db8:0a0b:12f0:0000:0000:0000:0004"); | ||
36 | + | ||
37 | + private final BgpAttrRouterIdV6 data = BgpAttrRouterIdV6.of(ip6RouterId, | ||
38 | + sType); | ||
39 | + private final BgpAttrRouterIdV6 sameAsData = BgpAttrRouterIdV6 | ||
40 | + .of(ip6RouterId, sType); | ||
41 | + private final BgpAttrRouterIdV6 diffData = BgpAttrRouterIdV6 | ||
42 | + .of(ip6RouterId1, sType1); | ||
43 | + | ||
44 | + @Test | ||
45 | + public void basics() { | ||
46 | + | ||
47 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
48 | + .addEqualityGroup(diffData).testEquals(); | ||
49 | + } | ||
50 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment