Committed by
Gerrit Code Review
[ONOS-641] Update RouteEntryTest and RouterTest to include IPv6 as well
Change-Id: I51aad28cc830074597a2a8eea252ca61f6b06586
Showing
2 changed files
with
280 additions
and
16 deletions
... | @@ -19,10 +19,15 @@ import org.hamcrest.Matchers; | ... | @@ -19,10 +19,15 @@ import org.hamcrest.Matchers; |
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | import org.onlab.packet.Ip4Address; | 20 | import org.onlab.packet.Ip4Address; |
21 | import org.onlab.packet.Ip4Prefix; | 21 | import org.onlab.packet.Ip4Prefix; |
22 | +import org.onlab.packet.Ip6Address; | ||
23 | +import org.onlab.packet.Ip6Prefix; | ||
22 | 24 | ||
23 | import static org.hamcrest.Matchers.is; | 25 | import static org.hamcrest.Matchers.is; |
24 | import static org.hamcrest.Matchers.not; | 26 | import static org.hamcrest.Matchers.not; |
25 | import static org.junit.Assert.assertThat; | 27 | import static org.junit.Assert.assertThat; |
28 | +import static org.junit.Assert.assertTrue; | ||
29 | +import java.util.regex.Matcher; | ||
30 | +import java.util.regex.Pattern; | ||
26 | 31 | ||
27 | /** | 32 | /** |
28 | * Unit tests for the RouteEntry class. | 33 | * Unit tests for the RouteEntry class. |
... | @@ -35,17 +40,22 @@ public class RouteEntryTest { | ... | @@ -35,17 +40,22 @@ public class RouteEntryTest { |
35 | public void testConstructor() { | 40 | public void testConstructor() { |
36 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); | 41 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); |
37 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); | 42 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); |
38 | - | ||
39 | RouteEntry routeEntry = new RouteEntry(prefix, nextHop); | 43 | RouteEntry routeEntry = new RouteEntry(prefix, nextHop); |
40 | assertThat(routeEntry.toString(), | 44 | assertThat(routeEntry.toString(), |
41 | is("RouteEntry{prefix=1.2.3.0/24, nextHop=5.6.7.8}")); | 45 | is("RouteEntry{prefix=1.2.3.0/24, nextHop=5.6.7.8}")); |
46 | + | ||
47 | + Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64"); | ||
48 | + Ip6Address nextHop6 = Ip6Address.valueOf("2000::1"); | ||
49 | + RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6); | ||
50 | + assertThat(routeEntry6.toString(), | ||
51 | + is("RouteEntry{prefix=1000::/64, nextHop=2000::1}")); | ||
42 | } | 52 | } |
43 | 53 | ||
44 | /** | 54 | /** |
45 | * Tests invalid class constructor for null IPv4 prefix. | 55 | * Tests invalid class constructor for null IPv4 prefix. |
46 | */ | 56 | */ |
47 | @Test(expected = NullPointerException.class) | 57 | @Test(expected = NullPointerException.class) |
48 | - public void testInvalidConstructorNullPrefix() { | 58 | + public void testInvalidConstructorNullIpv4Prefix() { |
49 | Ip4Prefix prefix = null; | 59 | Ip4Prefix prefix = null; |
50 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); | 60 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); |
51 | 61 | ||
... | @@ -53,10 +63,21 @@ public class RouteEntryTest { | ... | @@ -53,10 +63,21 @@ public class RouteEntryTest { |
53 | } | 63 | } |
54 | 64 | ||
55 | /** | 65 | /** |
66 | + * Tests invalid class constructor for null IPv6 prefix. | ||
67 | + */ | ||
68 | + @Test(expected = NullPointerException.class) | ||
69 | + public void testInvalidConstructorNullIpv6Prefix() { | ||
70 | + Ip6Prefix prefix = null; | ||
71 | + Ip6Address nextHop = Ip6Address.valueOf("2000::1"); | ||
72 | + | ||
73 | + new RouteEntry(prefix, nextHop); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
56 | * Tests invalid class constructor for null IPv4 next-hop. | 77 | * Tests invalid class constructor for null IPv4 next-hop. |
57 | */ | 78 | */ |
58 | @Test(expected = NullPointerException.class) | 79 | @Test(expected = NullPointerException.class) |
59 | - public void testInvalidConstructorNullNextHop() { | 80 | + public void testInvalidConstructorNullIpv4NextHop() { |
60 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); | 81 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); |
61 | Ip4Address nextHop = null; | 82 | Ip4Address nextHop = null; |
62 | 83 | ||
... | @@ -64,16 +85,32 @@ public class RouteEntryTest { | ... | @@ -64,16 +85,32 @@ public class RouteEntryTest { |
64 | } | 85 | } |
65 | 86 | ||
66 | /** | 87 | /** |
88 | + * Tests invalid class constructor for null IPv6 next-hop. | ||
89 | + */ | ||
90 | + @Test(expected = NullPointerException.class) | ||
91 | + public void testInvalidConstructorNullIpv6NextHop() { | ||
92 | + Ip6Prefix prefix = Ip6Prefix.valueOf("1000::/64"); | ||
93 | + Ip6Address nextHop = null; | ||
94 | + | ||
95 | + new RouteEntry(prefix, nextHop); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
67 | * Tests getting the fields of a route entry. | 99 | * Tests getting the fields of a route entry. |
68 | */ | 100 | */ |
69 | @Test | 101 | @Test |
70 | public void testGetFields() { | 102 | public void testGetFields() { |
71 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); | 103 | Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24"); |
72 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); | 104 | Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8"); |
73 | - | ||
74 | RouteEntry routeEntry = new RouteEntry(prefix, nextHop); | 105 | RouteEntry routeEntry = new RouteEntry(prefix, nextHop); |
75 | assertThat(routeEntry.prefix(), is(prefix)); | 106 | assertThat(routeEntry.prefix(), is(prefix)); |
76 | assertThat(routeEntry.nextHop(), is(nextHop)); | 107 | assertThat(routeEntry.nextHop(), is(nextHop)); |
108 | + | ||
109 | + Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64"); | ||
110 | + Ip6Address nextHop6 = Ip6Address.valueOf("2000::1"); | ||
111 | + RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6); | ||
112 | + assertThat(routeEntry6.prefix(), is(prefix6)); | ||
113 | + assertThat(routeEntry6.nextHop(), is(nextHop6)); | ||
77 | } | 114 | } |
78 | 115 | ||
79 | /** | 116 | /** |
... | @@ -105,6 +142,33 @@ public class RouteEntryTest { | ... | @@ -105,6 +142,33 @@ public class RouteEntryTest { |
105 | prefix = Ip4Prefix.valueOf("255.255.255.255/32"); | 142 | prefix = Ip4Prefix.valueOf("255.255.255.255/32"); |
106 | assertThat(RouteEntry.createBinaryString(prefix), | 143 | assertThat(RouteEntry.createBinaryString(prefix), |
107 | is("11111111111111111111111111111111")); | 144 | is("11111111111111111111111111111111")); |
145 | + | ||
146 | + Ip6Prefix prefix6; | ||
147 | + Pattern pattern; | ||
148 | + Matcher matcher; | ||
149 | + | ||
150 | + prefix6 = Ip6Prefix.valueOf("::/0"); | ||
151 | + assertThat(RouteEntry.createBinaryString(prefix6), is("")); | ||
152 | + | ||
153 | + prefix6 = Ip6Prefix.valueOf("2000::1000/112"); | ||
154 | + pattern = Pattern.compile("00100{108}"); | ||
155 | + matcher = pattern.matcher(RouteEntry.createBinaryString(prefix6)); | ||
156 | + assertTrue(matcher.matches()); | ||
157 | + | ||
158 | + prefix6 = Ip6Prefix.valueOf("2000::1000/116"); | ||
159 | + pattern = Pattern.compile("00100{108}0001"); | ||
160 | + matcher = pattern.matcher(RouteEntry.createBinaryString(prefix6)); | ||
161 | + assertTrue(matcher.matches()); | ||
162 | + | ||
163 | + prefix6 = Ip6Prefix.valueOf("2000::2000/116"); | ||
164 | + pattern = Pattern.compile("00100{108}0010"); | ||
165 | + matcher = pattern.matcher(RouteEntry.createBinaryString(prefix6)); | ||
166 | + assertTrue(matcher.matches()); | ||
167 | + | ||
168 | + prefix6 = Ip6Prefix.valueOf("2000::1234/128"); | ||
169 | + pattern = Pattern.compile("00100{108}0001001000110100"); | ||
170 | + matcher = pattern.matcher(RouteEntry.createBinaryString(prefix6)); | ||
171 | + assertTrue(matcher.matches()); | ||
108 | } | 172 | } |
109 | 173 | ||
110 | /** | 174 | /** |
... | @@ -121,6 +185,16 @@ public class RouteEntryTest { | ... | @@ -121,6 +185,16 @@ public class RouteEntryTest { |
121 | RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2); | 185 | RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2); |
122 | 186 | ||
123 | assertThat(routeEntry1, is(routeEntry2)); | 187 | assertThat(routeEntry1, is(routeEntry2)); |
188 | + | ||
189 | + Ip6Prefix prefix3 = Ip6Prefix.valueOf("1000::/64"); | ||
190 | + Ip6Address nextHop3 = Ip6Address.valueOf("2000::2"); | ||
191 | + RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3); | ||
192 | + | ||
193 | + Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64"); | ||
194 | + Ip6Address nextHop4 = Ip6Address.valueOf("2000::2"); | ||
195 | + RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4); | ||
196 | + | ||
197 | + assertThat(routeEntry3, is(routeEntry4)); | ||
124 | } | 198 | } |
125 | 199 | ||
126 | /** | 200 | /** |
... | @@ -142,6 +216,21 @@ public class RouteEntryTest { | ... | @@ -142,6 +216,21 @@ public class RouteEntryTest { |
142 | 216 | ||
143 | assertThat(routeEntry1, Matchers.is(not(routeEntry2))); | 217 | assertThat(routeEntry1, Matchers.is(not(routeEntry2))); |
144 | assertThat(routeEntry1, Matchers.is(not(routeEntry3))); | 218 | assertThat(routeEntry1, Matchers.is(not(routeEntry3))); |
219 | + | ||
220 | + Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64"); | ||
221 | + Ip6Address nextHop4 = Ip6Address.valueOf("2000::1"); | ||
222 | + RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4); | ||
223 | + | ||
224 | + Ip6Prefix prefix5 = Ip6Prefix.valueOf("1000::/65"); | ||
225 | + Ip6Address nextHop5 = Ip6Address.valueOf("2000::1"); | ||
226 | + RouteEntry routeEntry5 = new RouteEntry(prefix5, nextHop5); | ||
227 | + | ||
228 | + Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64"); | ||
229 | + Ip6Address nextHop6 = Ip6Address.valueOf("2000::2"); | ||
230 | + RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6); | ||
231 | + | ||
232 | + assertThat(routeEntry4, Matchers.is(not(routeEntry5))); | ||
233 | + assertThat(routeEntry4, Matchers.is(not(routeEntry6))); | ||
145 | } | 234 | } |
146 | 235 | ||
147 | /** | 236 | /** |
... | @@ -155,5 +244,12 @@ public class RouteEntryTest { | ... | @@ -155,5 +244,12 @@ public class RouteEntryTest { |
155 | 244 | ||
156 | assertThat(routeEntry.toString(), | 245 | assertThat(routeEntry.toString(), |
157 | is("RouteEntry{prefix=1.2.3.0/24, nextHop=5.6.7.8}")); | 246 | is("RouteEntry{prefix=1.2.3.0/24, nextHop=5.6.7.8}")); |
247 | + | ||
248 | + Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64"); | ||
249 | + Ip6Address nextHop6 = Ip6Address.valueOf("2000::1"); | ||
250 | + RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6); | ||
251 | + | ||
252 | + assertThat(routeEntry6.toString(), | ||
253 | + is("RouteEntry{prefix=1000::/64, nextHop=2000::1}")); | ||
158 | } | 254 | } |
159 | } | 255 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import org.junit.Before; | ... | @@ -22,6 +22,8 @@ import org.junit.Before; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
24 | import org.onlab.packet.Ip4Prefix; | 24 | import org.onlab.packet.Ip4Prefix; |
25 | +import org.onlab.packet.Ip6Address; | ||
26 | +import org.onlab.packet.Ip6Prefix; | ||
25 | import org.onlab.packet.IpAddress; | 27 | import org.onlab.packet.IpAddress; |
26 | import org.onlab.packet.IpPrefix; | 28 | import org.onlab.packet.IpPrefix; |
27 | import org.onlab.packet.MacAddress; | 29 | import org.onlab.packet.MacAddress; |
... | @@ -81,6 +83,13 @@ public class RouterTest { | ... | @@ -81,6 +83,13 @@ public class RouterTest { |
81 | DeviceId.deviceId("of:0000000000000004"), | 83 | DeviceId.deviceId("of:0000000000000004"), |
82 | PortNumber.portNumber(1)); | 84 | PortNumber.portNumber(1)); |
83 | 85 | ||
86 | + private static final ConnectPoint SW5_ETH1 = new ConnectPoint( | ||
87 | + DeviceId.deviceId("of:0000000000000005"), | ||
88 | + PortNumber.portNumber(1)); | ||
89 | + | ||
90 | + private static final ConnectPoint SW6_ETH1 = new ConnectPoint( | ||
91 | + DeviceId.deviceId("of:0000000000000006"), | ||
92 | + PortNumber.portNumber(1)); | ||
84 | private Router router; | 93 | private Router router; |
85 | 94 | ||
86 | @Before | 95 | @Before |
... | @@ -132,7 +141,6 @@ public class RouterTest { | ... | @@ -132,7 +141,6 @@ public class RouterTest { |
132 | hostService.startMonitoringIp(host1Address); | 141 | hostService.startMonitoringIp(host1Address); |
133 | expectLastCall().anyTimes(); | 142 | expectLastCall().anyTimes(); |
134 | 143 | ||
135 | - | ||
136 | IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); | 144 | IpAddress host2Address = IpAddress.valueOf("192.168.20.1"); |
137 | Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, | 145 | Host host2 = new DefaultHost(ProviderId.NONE, HostId.NONE, |
138 | MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, | 146 | MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE, |
... | @@ -148,7 +156,7 @@ public class RouterTest { | ... | @@ -148,7 +156,7 @@ public class RouterTest { |
148 | IpAddress host3Address = IpAddress.valueOf("192.168.40.1"); | 156 | IpAddress host3Address = IpAddress.valueOf("192.168.40.1"); |
149 | Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE, | 157 | Host host3 = new DefaultHost(ProviderId.NONE, HostId.NONE, |
150 | MacAddress.valueOf("00:00:00:00:00:03"), VlanId.vlanId((short) 1), | 158 | MacAddress.valueOf("00:00:00:00:00:03"), VlanId.vlanId((short) 1), |
151 | - new HostLocation(SW4_ETH1, 1), | 159 | + new HostLocation(SW3_ETH1, 1), |
152 | Sets.newHashSet(host3Address)); | 160 | Sets.newHashSet(host3Address)); |
153 | 161 | ||
154 | expect(hostService.getHostsByIp(host3Address)) | 162 | expect(hostService.getHostsByIp(host3Address)) |
... | @@ -156,6 +164,41 @@ public class RouterTest { | ... | @@ -156,6 +164,41 @@ public class RouterTest { |
156 | hostService.startMonitoringIp(host3Address); | 164 | hostService.startMonitoringIp(host3Address); |
157 | expectLastCall().anyTimes(); | 165 | expectLastCall().anyTimes(); |
158 | 166 | ||
167 | + IpAddress host4Address = IpAddress.valueOf("1000::1"); | ||
168 | + Host host4 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
169 | + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE, | ||
170 | + new HostLocation(SW4_ETH1, 1), | ||
171 | + Sets.newHashSet(host4Address)); | ||
172 | + | ||
173 | + expect(hostService.getHostsByIp(host4Address)) | ||
174 | + .andReturn(Sets.newHashSet(host4)).anyTimes(); | ||
175 | + hostService.startMonitoringIp(host4Address); | ||
176 | + expectLastCall().anyTimes(); | ||
177 | + | ||
178 | + IpAddress host5Address = IpAddress.valueOf("2000::1"); | ||
179 | + Host host5 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
180 | + MacAddress.valueOf("00:00:00:00:00:05"), VlanId.NONE, | ||
181 | + new HostLocation(SW5_ETH1, 1), | ||
182 | + Sets.newHashSet(host5Address)); | ||
183 | + | ||
184 | + expect(hostService.getHostsByIp(host5Address)) | ||
185 | + .andReturn(Sets.newHashSet(host5)).anyTimes(); | ||
186 | + hostService.startMonitoringIp(host5Address); | ||
187 | + expectLastCall().anyTimes(); | ||
188 | + | ||
189 | + // Next hop on a VLAN | ||
190 | + IpAddress host6Address = IpAddress.valueOf("3000::1"); | ||
191 | + Host host6 = new DefaultHost(ProviderId.NONE, HostId.NONE, | ||
192 | + MacAddress.valueOf("00:00:00:00:00:06"), VlanId.vlanId((short) 1), | ||
193 | + new HostLocation(SW6_ETH1, 1), | ||
194 | + Sets.newHashSet(host6Address)); | ||
195 | + | ||
196 | + expect(hostService.getHostsByIp(host6Address)) | ||
197 | + .andReturn(Sets.newHashSet(host6)).anyTimes(); | ||
198 | + hostService.startMonitoringIp(host6Address); | ||
199 | + expectLastCall().anyTimes(); | ||
200 | + | ||
201 | + | ||
159 | // Called during shutdown | 202 | // Called during shutdown |
160 | hostService.removeListener(anyObject(HostListener.class)); | 203 | hostService.removeListener(anyObject(HostListener.class)); |
161 | 204 | ||
... | @@ -163,10 +206,10 @@ public class RouterTest { | ... | @@ -163,10 +206,10 @@ public class RouterTest { |
163 | } | 206 | } |
164 | 207 | ||
165 | /** | 208 | /** |
166 | - * Tests adding a route entry. | 209 | + * Tests adding a IPv4 route entry. |
167 | */ | 210 | */ |
168 | @Test | 211 | @Test |
169 | - public void testRouteAdd() { | 212 | + public void testIpv4RouteAdd() { |
170 | // Construct a route entry | 213 | // Construct a route entry |
171 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | 214 | IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); |
172 | IpAddress nextHopIp = Ip4Address.valueOf("192.168.10.1"); | 215 | IpAddress nextHopIp = Ip4Address.valueOf("192.168.10.1"); |
... | @@ -175,7 +218,34 @@ public class RouterTest { | ... | @@ -175,7 +218,34 @@ public class RouterTest { |
175 | 218 | ||
176 | // Expected FIB entry | 219 | // Expected FIB entry |
177 | FibEntry fibEntry = new FibEntry(prefix, nextHopIp, | 220 | FibEntry fibEntry = new FibEntry(prefix, nextHopIp, |
178 | - MacAddress.valueOf("00:00:00:00:00:01")); | 221 | + MacAddress.valueOf("00:00:00:00:00:01")); |
222 | + | ||
223 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
224 | + FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); | ||
225 | + | ||
226 | + replay(fibListener); | ||
227 | + | ||
228 | + router.processRouteUpdates(Collections.singletonList( | ||
229 | + new RouteUpdate(RouteUpdate.Type.UPDATE, routeEntry))); | ||
230 | + | ||
231 | + verify(fibListener); | ||
232 | + } | ||
233 | + | ||
234 | + | ||
235 | + /** | ||
236 | + * Tests adding a IPv6 route entry. | ||
237 | + */ | ||
238 | + @Test | ||
239 | + public void testIpv6RouteAdd() { | ||
240 | + // Construct a route entry | ||
241 | + IpPrefix prefix = Ip6Prefix.valueOf("4000::/64"); | ||
242 | + IpAddress nextHopIp = Ip6Address.valueOf("1000::1"); | ||
243 | + | ||
244 | + RouteEntry routeEntry = new RouteEntry(prefix, nextHopIp); | ||
245 | + | ||
246 | + // Expected FIB entry | ||
247 | + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, | ||
248 | + MacAddress.valueOf("00:00:00:00:00:04")); | ||
179 | 249 | ||
180 | fibListener.update(Collections.singletonList(new FibUpdate( | 250 | fibListener.update(Collections.singletonList(new FibUpdate( |
181 | FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); | 251 | FibUpdate.Type.UPDATE, fibEntry)), Collections.emptyList()); |
... | @@ -188,13 +258,14 @@ public class RouterTest { | ... | @@ -188,13 +258,14 @@ public class RouterTest { |
188 | verify(fibListener); | 258 | verify(fibListener); |
189 | } | 259 | } |
190 | 260 | ||
261 | + | ||
191 | /** | 262 | /** |
192 | - * Tests updating a route entry. | 263 | + * Tests updating a IPv4 route entry. |
193 | */ | 264 | */ |
194 | @Test | 265 | @Test |
195 | public void testRouteUpdate() { | 266 | public void testRouteUpdate() { |
196 | // Firstly add a route | 267 | // Firstly add a route |
197 | - testRouteAdd(); | 268 | + testIpv4RouteAdd(); |
198 | 269 | ||
199 | // Route entry with updated next hop for the original prefix | 270 | // Route entry with updated next hop for the original prefix |
200 | RouteEntry routeEntryUpdate = new RouteEntry( | 271 | RouteEntry routeEntryUpdate = new RouteEntry( |
... | @@ -230,12 +301,53 @@ public class RouterTest { | ... | @@ -230,12 +301,53 @@ public class RouterTest { |
230 | } | 301 | } |
231 | 302 | ||
232 | /** | 303 | /** |
233 | - * Tests deleting a route entry. | 304 | + * Tests updating a IPv6 route entry. |
234 | */ | 305 | */ |
235 | @Test | 306 | @Test |
236 | - public void testRouteDelete() { | 307 | + public void testIpv6RouteUpdate() { |
237 | // Firstly add a route | 308 | // Firstly add a route |
238 | - testRouteAdd(); | 309 | + testIpv6RouteAdd(); |
310 | + | ||
311 | + // Route entry with updated next hop for the original prefix | ||
312 | + RouteEntry routeEntryUpdate = new RouteEntry( | ||
313 | + Ip6Prefix.valueOf("4000::/64"), | ||
314 | + Ip6Address.valueOf("2000::1")); | ||
315 | + | ||
316 | + // The old FIB entry will be withdrawn | ||
317 | + FibEntry withdrawFibEntry = new FibEntry( | ||
318 | + Ip6Prefix.valueOf("4000::/64"), null, null); | ||
319 | + | ||
320 | + // A new FIB entry will be added | ||
321 | + FibEntry updateFibEntry = new FibEntry( | ||
322 | + Ip6Prefix.valueOf("4000::/64"), | ||
323 | + Ip6Address.valueOf("2000::1"), | ||
324 | + MacAddress.valueOf("00:00:00:00:00:05")); | ||
325 | + | ||
326 | + reset(fibListener); | ||
327 | + fibListener.update(Collections.singletonList(new FibUpdate( | ||
328 | + FibUpdate.Type.UPDATE, updateFibEntry)), | ||
329 | + Collections.singletonList(new FibUpdate( | ||
330 | + FibUpdate.Type.DELETE, withdrawFibEntry))); | ||
331 | + replay(fibListener); | ||
332 | + | ||
333 | + reset(routingConfigurationService); | ||
334 | + expect(routingConfigurationService.isIpPrefixLocal( | ||
335 | + anyObject(IpPrefix.class))).andReturn(false); | ||
336 | + replay(routingConfigurationService); | ||
337 | + | ||
338 | + router.processRouteUpdates(Collections.singletonList(new RouteUpdate( | ||
339 | + RouteUpdate.Type.UPDATE, routeEntryUpdate))); | ||
340 | + | ||
341 | + verify(fibListener); | ||
342 | + } | ||
343 | + | ||
344 | + /** | ||
345 | + * Tests deleting a IPv4 route entry. | ||
346 | + */ | ||
347 | + @Test | ||
348 | + public void testIpv4RouteDelete() { | ||
349 | + // Firstly add a route | ||
350 | + testIpv4RouteAdd(); | ||
239 | 351 | ||
240 | RouteEntry deleteRouteEntry = new RouteEntry( | 352 | RouteEntry deleteRouteEntry = new RouteEntry( |
241 | Ip4Prefix.valueOf("1.1.1.0/24"), | 353 | Ip4Prefix.valueOf("1.1.1.0/24"), |
... | @@ -257,10 +369,37 @@ public class RouterTest { | ... | @@ -257,10 +369,37 @@ public class RouterTest { |
257 | } | 369 | } |
258 | 370 | ||
259 | /** | 371 | /** |
260 | - * Tests adding a route whose next hop is the local BGP speaker. | 372 | + * Tests deleting a IPv6 route entry. |
261 | */ | 373 | */ |
262 | @Test | 374 | @Test |
263 | - public void testLocalRouteAdd() { | 375 | + public void testIpv6RouteDelete() { |
376 | + // Firstly add a route | ||
377 | + testIpv6RouteAdd(); | ||
378 | + | ||
379 | + RouteEntry deleteRouteEntry = new RouteEntry( | ||
380 | + Ip6Prefix.valueOf("4000::/64"), | ||
381 | + Ip6Address.valueOf("1000::1")); | ||
382 | + | ||
383 | + FibEntry deleteFibEntry = new FibEntry( | ||
384 | + Ip6Prefix.valueOf("4000::/64"), null, null); | ||
385 | + | ||
386 | + reset(fibListener); | ||
387 | + fibListener.update(Collections.emptyList(), Collections.singletonList( | ||
388 | + new FibUpdate(FibUpdate.Type.DELETE, deleteFibEntry))); | ||
389 | + | ||
390 | + replay(fibListener); | ||
391 | + | ||
392 | + router.processRouteUpdates(Collections.singletonList( | ||
393 | + new RouteUpdate(RouteUpdate.Type.DELETE, deleteRouteEntry))); | ||
394 | + | ||
395 | + verify(fibListener); | ||
396 | + } | ||
397 | + | ||
398 | + /** | ||
399 | + * Tests adding a IPv4 route whose next hop is the local BGP speaker. | ||
400 | + */ | ||
401 | + @Test | ||
402 | + public void testIpv4LocalRouteAdd() { | ||
264 | // Construct a route entry, the next hop is the local BGP speaker | 403 | // Construct a route entry, the next hop is the local BGP speaker |
265 | RouteEntry routeEntry = new RouteEntry( | 404 | RouteEntry routeEntry = new RouteEntry( |
266 | Ip4Prefix.valueOf("1.1.1.0/24"), | 405 | Ip4Prefix.valueOf("1.1.1.0/24"), |
... | @@ -284,4 +423,33 @@ public class RouterTest { | ... | @@ -284,4 +423,33 @@ public class RouterTest { |
284 | assertTrue(router.getRoutes4().contains(routeEntry)); | 423 | assertTrue(router.getRoutes4().contains(routeEntry)); |
285 | verify(fibListener); | 424 | verify(fibListener); |
286 | } | 425 | } |
426 | + | ||
427 | + /** | ||
428 | + * Tests adding a IPv6 route whose next hop is the local BGP speaker. | ||
429 | + */ | ||
430 | + @Test | ||
431 | + public void testIpv6LocalRouteAdd() { | ||
432 | + // Construct a route entry, the next hop is the local BGP speaker | ||
433 | + RouteEntry routeEntry = new RouteEntry( | ||
434 | + Ip6Prefix.valueOf("4000::/64"), | ||
435 | + Ip6Address.valueOf("::")); | ||
436 | + | ||
437 | + // No methods on the FIB listener should be called | ||
438 | + replay(fibListener); | ||
439 | + | ||
440 | + reset(routingConfigurationService); | ||
441 | + expect(routingConfigurationService.isIpPrefixLocal( | ||
442 | + anyObject(IpPrefix.class))).andReturn(true); | ||
443 | + replay(routingConfigurationService); | ||
444 | + | ||
445 | + // Call the processRouteUpdates() method in Router class | ||
446 | + RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, | ||
447 | + routeEntry); | ||
448 | + router.processRouteUpdates(Collections.singletonList(routeUpdate)); | ||
449 | + | ||
450 | + // Verify | ||
451 | + assertEquals(1, router.getRoutes6().size()); | ||
452 | + assertTrue(router.getRoutes6().contains(routeEntry)); | ||
453 | + verify(fibListener); | ||
454 | + } | ||
287 | } | 455 | } | ... | ... |
-
Please register or login to post a comment