Committed by
Gerrit Code Review
[onos-2613] - Unit testing of BgpPrefixAttrIgpFlags
Change-Id: If1c9dcc0557aa1a12f2393762beed47531f9c474
Showing
2 changed files
with
98 additions
and
26 deletions
... | @@ -30,24 +30,24 @@ import com.google.common.base.MoreObjects; | ... | @@ -30,24 +30,24 @@ import com.google.common.base.MoreObjects; |
30 | /** | 30 | /** |
31 | * Implements BGP prefix IGP Flag attribute. | 31 | * Implements BGP prefix IGP Flag attribute. |
32 | */ | 32 | */ |
33 | -public class BgpPrefixAttrIGPFlags implements BGPValueType { | 33 | +public final class BgpPrefixAttrIgpFlags implements BGPValueType { |
34 | 34 | ||
35 | protected static final Logger log = LoggerFactory | 35 | protected static final Logger log = LoggerFactory |
36 | - .getLogger(BgpPrefixAttrIGPFlags.class); | 36 | + .getLogger(BgpPrefixAttrIgpFlags.class); |
37 | 37 | ||
38 | public static final int ATTR_PREFIX_FLAGBIT = 1152; | 38 | public static final int ATTR_PREFIX_FLAGBIT = 1152; |
39 | public static final int ATTR_PREFIX_FLAG_LEN = 1; | 39 | public static final int ATTR_PREFIX_FLAG_LEN = 1; |
40 | 40 | ||
41 | - public static final int FIRST_BIT = 0x80; | 41 | + public static final byte FIRST_BIT = (byte) 0x80; |
42 | - public static final int SECOND_BIT = 0x40; | 42 | + public static final byte SECOND_BIT = 0x40; |
43 | - public static final int THIRD_BIT = 0x20; | 43 | + public static final byte THIRD_BIT = 0x20; |
44 | - public static final int FOURTH_BIT = 0x01; | 44 | + public static final byte FOURTH_BIT = 0x01; |
45 | 45 | ||
46 | /* Prefix IGP flag bit TLV */ | 46 | /* Prefix IGP flag bit TLV */ |
47 | - private boolean bisisUpDownBit = false; | 47 | + private final boolean bisisUpDownBit; |
48 | - private boolean bOspfNoUnicastBit = false; | 48 | + private final boolean bOspfNoUnicastBit; |
49 | - private boolean bOspfLclAddrBit = false; | 49 | + private final boolean bOspfLclAddrBit; |
50 | - private boolean bOspfNSSABit = false; | 50 | + private final boolean bOspfNSSABit; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Constructor to initialize the value. | 53 | * Constructor to initialize the value. |
... | @@ -57,7 +57,8 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -57,7 +57,8 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
57 | * @param bOspfLclAddrBit OSPF local address Bit | 57 | * @param bOspfLclAddrBit OSPF local address Bit |
58 | * @param bOspfNSSABit OSPF propagate NSSA Bit | 58 | * @param bOspfNSSABit OSPF propagate NSSA Bit |
59 | */ | 59 | */ |
60 | - BgpPrefixAttrIGPFlags(boolean bisisUpDownBit, boolean bOspfNoUnicastBit, | 60 | + BgpPrefixAttrIgpFlags(boolean bisisUpDownBit, |
61 | + boolean bOspfNoUnicastBit, | ||
61 | boolean bOspfLclAddrBit, boolean bOspfNSSABit) { | 62 | boolean bOspfLclAddrBit, boolean bOspfNSSABit) { |
62 | this.bisisUpDownBit = bisisUpDownBit; | 63 | this.bisisUpDownBit = bisisUpDownBit; |
63 | this.bOspfNoUnicastBit = bOspfNoUnicastBit; | 64 | this.bOspfNoUnicastBit = bOspfNoUnicastBit; |
... | @@ -66,13 +67,30 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -66,13 +67,30 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
66 | } | 67 | } |
67 | 68 | ||
68 | /** | 69 | /** |
70 | + * Returns object of this class with specified values. | ||
71 | + * | ||
72 | + * @param bisisUpDownBit IS-IS Up/Down Bit | ||
73 | + * @param bOspfNoUnicastBit OSPF no unicast Bit | ||
74 | + * @param bOspfLclAddrBit OSPF local address Bit | ||
75 | + * @param bOspfNSSABit OSPF propagate NSSA Bit | ||
76 | + * @return object of BgpPrefixAttrIGPFlags | ||
77 | + */ | ||
78 | + public static BgpPrefixAttrIgpFlags of(final boolean bisisUpDownBit, | ||
79 | + final boolean bOspfNoUnicastBit, | ||
80 | + final boolean bOspfLclAddrBit, | ||
81 | + final boolean bOspfNSSABit) { | ||
82 | + return new BgpPrefixAttrIgpFlags(bisisUpDownBit, bOspfNoUnicastBit, | ||
83 | + bOspfLclAddrBit, bOspfNSSABit); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
69 | * Reads the IGP Flags. | 87 | * Reads the IGP Flags. |
70 | * | 88 | * |
71 | * @param cb ChannelBuffer | 89 | * @param cb ChannelBuffer |
72 | * @return object of BgpPrefixAttrIGPFlags | 90 | * @return object of BgpPrefixAttrIGPFlags |
73 | * @throws BGPParseException while parsing BgpPrefixAttrIGPFlags | 91 | * @throws BGPParseException while parsing BgpPrefixAttrIGPFlags |
74 | */ | 92 | */ |
75 | - public static BgpPrefixAttrIGPFlags read(ChannelBuffer cb) | 93 | + public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb) |
76 | throws BGPParseException { | 94 | throws BGPParseException { |
77 | boolean bisisUpDownBit = false; | 95 | boolean bisisUpDownBit = false; |
78 | boolean bOspfNoUnicastBit = false; | 96 | boolean bOspfNoUnicastBit = false; |
... | @@ -90,13 +108,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -90,13 +108,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
90 | 108 | ||
91 | byte nodeFlagBits = cb.readByte(); | 109 | byte nodeFlagBits = cb.readByte(); |
92 | 110 | ||
93 | - bisisUpDownBit = ((nodeFlagBits & (byte) FIRST_BIT) == FIRST_BIT); | 111 | + bisisUpDownBit = ((nodeFlagBits & FIRST_BIT) == FIRST_BIT); |
94 | - bOspfNoUnicastBit = ((nodeFlagBits & (byte) SECOND_BIT) == SECOND_BIT); | 112 | + bOspfNoUnicastBit = ((nodeFlagBits & SECOND_BIT) == SECOND_BIT); |
95 | - bOspfLclAddrBit = ((nodeFlagBits & (byte) THIRD_BIT) == THIRD_BIT); | 113 | + bOspfLclAddrBit = ((nodeFlagBits & THIRD_BIT) == THIRD_BIT); |
96 | - bOspfNSSABit = ((nodeFlagBits & (byte) FOURTH_BIT) == FOURTH_BIT); | 114 | + bOspfNSSABit = ((nodeFlagBits & FOURTH_BIT) == FOURTH_BIT); |
97 | 115 | ||
98 | - return new BgpPrefixAttrIGPFlags(bisisUpDownBit, bOspfNoUnicastBit, | 116 | + return BgpPrefixAttrIgpFlags.of(bisisUpDownBit, bOspfNoUnicastBit, |
99 | - bOspfLclAddrBit, bOspfNSSABit); | 117 | + bOspfLclAddrBit, bOspfNSSABit); |
100 | } | 118 | } |
101 | 119 | ||
102 | /** | 120 | /** |
... | @@ -104,7 +122,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -104,7 +122,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
104 | * | 122 | * |
105 | * @return IS-IS Up/Down Bit set or not | 123 | * @return IS-IS Up/Down Bit set or not |
106 | */ | 124 | */ |
107 | - boolean getisisUpDownBit() { | 125 | + public boolean isisUpDownBit() { |
108 | return bisisUpDownBit; | 126 | return bisisUpDownBit; |
109 | } | 127 | } |
110 | 128 | ||
... | @@ -113,7 +131,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -113,7 +131,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
113 | * | 131 | * |
114 | * @return OSPF no unicast Bit set or not | 132 | * @return OSPF no unicast Bit set or not |
115 | */ | 133 | */ |
116 | - boolean getOspfNoUnicastBit() { | 134 | + public boolean ospfNoUnicastBit() { |
117 | return bOspfNoUnicastBit; | 135 | return bOspfNoUnicastBit; |
118 | } | 136 | } |
119 | 137 | ||
... | @@ -122,7 +140,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -122,7 +140,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
122 | * | 140 | * |
123 | * @return OSPF local address Bit set or not | 141 | * @return OSPF local address Bit set or not |
124 | */ | 142 | */ |
125 | - boolean getOspfLclAddrBit() { | 143 | + public boolean ospfLclAddrBit() { |
126 | return bOspfLclAddrBit; | 144 | return bOspfLclAddrBit; |
127 | } | 145 | } |
128 | 146 | ||
... | @@ -131,7 +149,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -131,7 +149,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
131 | * | 149 | * |
132 | * @return OSPF propagate NSSA Bit set or not | 150 | * @return OSPF propagate NSSA Bit set or not |
133 | */ | 151 | */ |
134 | - boolean getOspfNSSABit() { | 152 | + public boolean ospfNSSABit() { |
135 | return bOspfNSSABit; | 153 | return bOspfNSSABit; |
136 | } | 154 | } |
137 | 155 | ||
... | @@ -158,13 +176,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { | ... | @@ -158,13 +176,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { |
158 | return true; | 176 | return true; |
159 | } | 177 | } |
160 | 178 | ||
161 | - if (obj instanceof BgpPrefixAttrIGPFlags) { | 179 | + if (obj instanceof BgpPrefixAttrIgpFlags) { |
162 | - BgpPrefixAttrIGPFlags other = (BgpPrefixAttrIGPFlags) obj; | 180 | + BgpPrefixAttrIgpFlags other = (BgpPrefixAttrIgpFlags) obj; |
163 | return Objects.equals(bisisUpDownBit, other.bisisUpDownBit) | 181 | return Objects.equals(bisisUpDownBit, other.bisisUpDownBit) |
164 | && Objects.equals(bOspfNoUnicastBit, | 182 | && Objects.equals(bOspfNoUnicastBit, |
165 | other.bOspfNoUnicastBit) | 183 | other.bOspfNoUnicastBit) |
166 | - && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit) | 184 | + && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit) |
167 | - && Objects.equals(bOspfNSSABit, other.bOspfNSSABit); | 185 | + && Objects.equals(bOspfNSSABit, other.bOspfNSSABit); |
168 | } | 186 | } |
169 | return false; | 187 | return false; |
170 | } | 188 | } | ... | ... |
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.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags; | ||
20 | + | ||
21 | +import com.google.common.testing.EqualsTester; | ||
22 | + | ||
23 | +/** | ||
24 | + * Test for BGP prefix IGP Flag attribute. | ||
25 | + */ | ||
26 | +public class BgpPrefixAttrIgpFlagsTest { | ||
27 | + | ||
28 | + private final boolean bisisUpDownBit = true; | ||
29 | + private final boolean bOspfNoUnicastBit = true; | ||
30 | + private final boolean bOspfLclAddrBit = true; | ||
31 | + private final boolean bOspfNSSABit = true; | ||
32 | + | ||
33 | + private final boolean bisisUpDownBit1 = false; | ||
34 | + private final boolean bOspfNoUnicastBit1 = false; | ||
35 | + private final boolean bOspfLclAddrBit1 = false; | ||
36 | + private final boolean bOspfNSSABit1 = false; | ||
37 | + | ||
38 | + private final BgpPrefixAttrIgpFlags data = BgpPrefixAttrIgpFlags | ||
39 | + .of(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, | ||
40 | + bOspfNSSABit); | ||
41 | + private final BgpPrefixAttrIgpFlags sameAsData = BgpPrefixAttrIgpFlags | ||
42 | + .of(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, | ||
43 | + bOspfNSSABit); | ||
44 | + private final BgpPrefixAttrIgpFlags diffData = BgpPrefixAttrIgpFlags | ||
45 | + .of(bisisUpDownBit1, bOspfNoUnicastBit1, bOspfLclAddrBit1, | ||
46 | + bOspfNSSABit1); | ||
47 | + | ||
48 | + @Test | ||
49 | + public void basics() { | ||
50 | + | ||
51 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
52 | + .addEqualityGroup(diffData).testEquals(); | ||
53 | + } | ||
54 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment