blob: c1ad946695081b3451e4d69e239d994c8cf9dfed [file] [log] [blame]
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +09001/*
2 * Copyright (C) 2013 The Android Open Source Project
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
17package android.net;
18
Hugo Benichi3054e102017-08-08 13:06:04 +090019import static android.system.OsConstants.IFA_F_DADFAILED;
20import static android.system.OsConstants.IFA_F_DEPRECATED;
21import static android.system.OsConstants.IFA_F_OPTIMISTIC;
22import static android.system.OsConstants.IFA_F_PERMANENT;
23import static android.system.OsConstants.IFA_F_TEMPORARY;
24import static android.system.OsConstants.IFA_F_TENTATIVE;
25import static android.system.OsConstants.RT_SCOPE_HOST;
26import static android.system.OsConstants.RT_SCOPE_LINK;
27import static android.system.OsConstants.RT_SCOPE_SITE;
28import static android.system.OsConstants.RT_SCOPE_UNIVERSE;
29import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.assertFalse;
31import static org.junit.Assert.assertNotEquals;
32import static org.junit.Assert.assertNotNull;
33import static org.junit.Assert.assertTrue;
34import static org.junit.Assert.fail;
35
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090036import java.net.Inet4Address;
37import java.net.Inet6Address;
38import java.net.InetAddress;
39import java.net.InterfaceAddress;
40import java.net.NetworkInterface;
41import java.net.SocketException;
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090042import java.util.Arrays;
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090043import java.util.Collections;
44import java.util.Comparator;
45import java.util.List;
46
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090047import android.os.Parcel;
Hugo Benichi3054e102017-08-08 13:06:04 +090048import android.support.test.filters.SmallTest;
49import android.support.test.runner.AndroidJUnit4;
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090050
Hugo Benichi3054e102017-08-08 13:06:04 +090051import org.junit.runner.RunWith;
52import org.junit.Test;
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090053
Hugo Benichi3054e102017-08-08 13:06:04 +090054@RunWith(AndroidJUnit4.class)
55@SmallTest
56public class LinkAddressTest {
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090057
58 private static final String V4 = "192.0.2.1";
59 private static final String V6 = "2001:db8::1";
60 private static final InetAddress V4_ADDRESS = NetworkUtils.numericToInetAddress(V4);
61 private static final InetAddress V6_ADDRESS = NetworkUtils.numericToInetAddress(V6);
62
Hugo Benichi3054e102017-08-08 13:06:04 +090063 @Test
Lorenzo Colittif3e0e302014-06-13 16:55:54 +090064 public void testConstants() {
65 // RT_SCOPE_UNIVERSE = 0, but all the other constants should be nonzero.
Hugo Benichi3054e102017-08-08 13:06:04 +090066 assertNotEquals(0, RT_SCOPE_HOST);
67 assertNotEquals(0, RT_SCOPE_LINK);
68 assertNotEquals(0, RT_SCOPE_SITE);
Lorenzo Colittif3e0e302014-06-13 16:55:54 +090069
Hugo Benichi3054e102017-08-08 13:06:04 +090070 assertNotEquals(0, IFA_F_DEPRECATED);
71 assertNotEquals(0, IFA_F_PERMANENT);
72 assertNotEquals(0, IFA_F_TENTATIVE);
Lorenzo Colittif3e0e302014-06-13 16:55:54 +090073 }
74
Hugo Benichi3054e102017-08-08 13:06:04 +090075 @Test
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090076 public void testConstructors() throws SocketException {
77 LinkAddress address;
78
79 // Valid addresses work as expected.
80 address = new LinkAddress(V4_ADDRESS, 25);
81 assertEquals(V4_ADDRESS, address.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +090082 assertEquals(25, address.getPrefixLength());
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090083 assertEquals(0, address.getFlags());
84 assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
Hugo Benichi3054e102017-08-08 13:06:04 +090085 assertTrue(address.isIPv4());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090086
87 address = new LinkAddress(V6_ADDRESS, 127);
88 assertEquals(V6_ADDRESS, address.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +090089 assertEquals(127, address.getPrefixLength());
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090090 assertEquals(0, address.getFlags());
91 assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
Hugo Benichi3054e102017-08-08 13:06:04 +090092 assertTrue(address.isIPv6());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090093
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090094 // Nonsensical flags/scopes or combinations thereof are acceptable.
95 address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +090096 assertEquals(V6_ADDRESS, address.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +090097 assertEquals(64, address.getPrefixLength());
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +090098 assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags());
99 assertEquals(RT_SCOPE_LINK, address.getScope());
Hugo Benichi3054e102017-08-08 13:06:04 +0900100 assertTrue(address.isIPv6());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900101
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900102 address = new LinkAddress(V4 + "/23", 123, 456);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900103 assertEquals(V4_ADDRESS, address.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +0900104 assertEquals(23, address.getPrefixLength());
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900105 assertEquals(123, address.getFlags());
106 assertEquals(456, address.getScope());
Hugo Benichi3054e102017-08-08 13:06:04 +0900107 assertTrue(address.isIPv4());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900108
109 // InterfaceAddress doesn't have a constructor. Fetch some from an interface.
110 List<InterfaceAddress> addrs = NetworkInterface.getByName("lo").getInterfaceAddresses();
111
112 // We expect to find 127.0.0.1/8 and ::1/128, in any order.
113 LinkAddress ipv4Loopback, ipv6Loopback;
114 assertEquals(2, addrs.size());
115 if (addrs.get(0).getAddress() instanceof Inet4Address) {
116 ipv4Loopback = new LinkAddress(addrs.get(0));
117 ipv6Loopback = new LinkAddress(addrs.get(1));
118 } else {
119 ipv4Loopback = new LinkAddress(addrs.get(1));
120 ipv6Loopback = new LinkAddress(addrs.get(0));
121 }
122
123 assertEquals(NetworkUtils.numericToInetAddress("127.0.0.1"), ipv4Loopback.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +0900124 assertEquals(8, ipv4Loopback.getPrefixLength());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900125
126 assertEquals(NetworkUtils.numericToInetAddress("::1"), ipv6Loopback.getAddress());
Lorenzo Colitti48a7da02014-06-09 22:58:46 +0900127 assertEquals(128, ipv6Loopback.getPrefixLength());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900128
129 // Null addresses are rejected.
130 try {
131 address = new LinkAddress(null, 24);
132 fail("Null InetAddress should cause IllegalArgumentException");
133 } catch(IllegalArgumentException expected) {}
134
135 try {
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900136 address = new LinkAddress((String) null, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900137 fail("Null string should cause IllegalArgumentException");
138 } catch(IllegalArgumentException expected) {}
139
140 try {
141 address = new LinkAddress((InterfaceAddress) null);
142 fail("Null string should cause NullPointerException");
143 } catch(NullPointerException expected) {}
144
145 // Invalid prefix lengths are rejected.
146 try {
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900147 address = new LinkAddress(V4_ADDRESS, -1);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900148 fail("Negative IPv4 prefix length should cause IllegalArgumentException");
149 } catch(IllegalArgumentException expected) {}
150
151 try {
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900152 address = new LinkAddress(V6_ADDRESS, -1);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900153 fail("Negative IPv6 prefix length should cause IllegalArgumentException");
154 } catch(IllegalArgumentException expected) {}
155
156 try {
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900157 address = new LinkAddress(V4_ADDRESS, 33);
158 fail("/33 IPv4 prefix length should cause IllegalArgumentException");
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900159 } catch(IllegalArgumentException expected) {}
160
161 try {
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900162 address = new LinkAddress(V4 + "/33", IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
163 fail("/33 IPv4 prefix length should cause IllegalArgumentException");
164 } catch(IllegalArgumentException expected) {}
165
166
167 try {
168 address = new LinkAddress(V6_ADDRESS, 129, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900169 fail("/129 IPv6 prefix length should cause IllegalArgumentException");
170 } catch(IllegalArgumentException expected) {}
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900171
172 try {
173 address = new LinkAddress(V6 + "/129", IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
174 fail("/129 IPv6 prefix length should cause IllegalArgumentException");
175 } catch(IllegalArgumentException expected) {}
176
177 // Multicast addresses are rejected.
178 try {
179 address = new LinkAddress("224.0.0.2/32");
180 fail("IPv4 multicast address should cause IllegalArgumentException");
181 } catch(IllegalArgumentException expected) {}
182
183 try {
184 address = new LinkAddress("ff02::1/128");
185 fail("IPv6 multicast address should cause IllegalArgumentException");
186 } catch(IllegalArgumentException expected) {}
187 }
188
Hugo Benichi3054e102017-08-08 13:06:04 +0900189 @Test
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900190 public void testAddressScopes() {
191 assertEquals(RT_SCOPE_HOST, new LinkAddress("::/128").getScope());
192 assertEquals(RT_SCOPE_HOST, new LinkAddress("0.0.0.0/32").getScope());
193
194 assertEquals(RT_SCOPE_LINK, new LinkAddress("::1/128").getScope());
195 assertEquals(RT_SCOPE_LINK, new LinkAddress("127.0.0.5/8").getScope());
196 assertEquals(RT_SCOPE_LINK, new LinkAddress("fe80::ace:d00d/64").getScope());
197 assertEquals(RT_SCOPE_LINK, new LinkAddress("169.254.5.12/16").getScope());
198
199 assertEquals(RT_SCOPE_SITE, new LinkAddress("fec0::dead/64").getScope());
200
201 assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("10.1.2.3/21").getScope());
202 assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("192.0.2.1/25").getScope());
203 assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("2001:db8::/64").getScope());
204 assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("5000::/127").getScope());
205 }
206
207 private void assertIsSameAddressAs(LinkAddress l1, LinkAddress l2) {
208 assertTrue(l1 + " unexpectedly does not have same address as " + l2,
209 l1.isSameAddressAs(l2));
210 assertTrue(l2 + " unexpectedly does not have same address as " + l1,
211 l2.isSameAddressAs(l1));
212 }
213
214 private void assertIsNotSameAddressAs(LinkAddress l1, LinkAddress l2) {
215 assertFalse(l1 + " unexpectedly has same address as " + l2,
216 l1.isSameAddressAs(l2));
217 assertFalse(l2 + " unexpectedly has same address as " + l1,
218 l1.isSameAddressAs(l2));
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900219 }
220
221 private void assertLinkAddressesEqual(LinkAddress l1, LinkAddress l2) {
222 assertTrue(l1 + " unexpectedly not equal to " + l2, l1.equals(l2));
223 assertTrue(l2 + " unexpectedly not equal to " + l1, l2.equals(l1));
224 assertEquals(l1.hashCode(), l2.hashCode());
225 }
226
227 private void assertLinkAddressesNotEqual(LinkAddress l1, LinkAddress l2) {
228 assertFalse(l1 + " unexpectedly equal to " + l2, l1.equals(l2));
229 assertFalse(l2 + " unexpectedly equal to " + l1, l2.equals(l1));
230 }
231
Hugo Benichi3054e102017-08-08 13:06:04 +0900232 @Test
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900233 public void testEqualsAndSameAddressAs() {
234 LinkAddress l1, l2, l3;
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900235
236 l1 = new LinkAddress("2001:db8::1/64");
237 l2 = new LinkAddress("2001:db8::1/64");
238 assertLinkAddressesEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900239 assertIsSameAddressAs(l1, l2);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900240
241 l2 = new LinkAddress("2001:db8::1/65");
242 assertLinkAddressesNotEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900243 assertIsNotSameAddressAs(l1, l2);
244
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900245 l2 = new LinkAddress("2001:db8::2/64");
246 assertLinkAddressesNotEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900247 assertIsNotSameAddressAs(l1, l2);
248
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900249
250 l1 = new LinkAddress("192.0.2.1/24");
251 l2 = new LinkAddress("192.0.2.1/24");
252 assertLinkAddressesEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900253 assertIsSameAddressAs(l1, l2);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900254
255 l2 = new LinkAddress("192.0.2.1/23");
256 assertLinkAddressesNotEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900257 assertIsNotSameAddressAs(l1, l2);
258
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900259 l2 = new LinkAddress("192.0.2.2/24");
260 assertLinkAddressesNotEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900261 assertIsNotSameAddressAs(l1, l2);
262
263
264 // Check equals() and isSameAddressAs() on identical addresses with different flags.
265 l1 = new LinkAddress(V6_ADDRESS, 64);
266 l2 = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_UNIVERSE);
267 assertLinkAddressesEqual(l1, l2);
268 assertIsSameAddressAs(l1, l2);
269
270 l2 = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_UNIVERSE);
271 assertLinkAddressesNotEqual(l1, l2);
272 assertIsSameAddressAs(l1, l2);
273
274 // Check equals() and isSameAddressAs() on identical addresses with different scope.
275 l1 = new LinkAddress(V4_ADDRESS, 24);
276 l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_UNIVERSE);
277 assertLinkAddressesEqual(l1, l2);
278 assertIsSameAddressAs(l1, l2);
279
280 l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_HOST);
281 assertLinkAddressesNotEqual(l1, l2);
282 assertIsSameAddressAs(l1, l2);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900283
284 // Addresses with the same start or end bytes aren't equal between families.
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900285 l1 = new LinkAddress("32.1.13.184/24");
286 l2 = new LinkAddress("2001:db8::1/24");
287 l3 = new LinkAddress("::2001:db8/24");
288
289 byte[] ipv4Bytes = l1.getAddress().getAddress();
290 byte[] l2FirstIPv6Bytes = Arrays.copyOf(l2.getAddress().getAddress(), 4);
291 byte[] l3LastIPv6Bytes = Arrays.copyOfRange(l3.getAddress().getAddress(), 12, 16);
292 assertTrue(Arrays.equals(ipv4Bytes, l2FirstIPv6Bytes));
293 assertTrue(Arrays.equals(ipv4Bytes, l3LastIPv6Bytes));
294
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900295 assertLinkAddressesNotEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900296 assertIsNotSameAddressAs(l1, l2);
297
298 assertLinkAddressesNotEqual(l1, l3);
299 assertIsNotSameAddressAs(l1, l3);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900300
301 // Because we use InetAddress, an IPv4 address is equal to its IPv4-mapped address.
302 // TODO: Investigate fixing this.
303 String addressString = V4 + "/24";
304 l1 = new LinkAddress(addressString);
305 l2 = new LinkAddress("::ffff:" + addressString);
306 assertLinkAddressesEqual(l1, l2);
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900307 assertIsSameAddressAs(l1, l2);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900308 }
309
Hugo Benichi3054e102017-08-08 13:06:04 +0900310 @Test
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900311 public void testHashCode() {
Hugo Benichi3054e102017-08-08 13:06:04 +0900312 LinkAddress l1, l2;
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900313
Hugo Benichi3054e102017-08-08 13:06:04 +0900314 l1 = new LinkAddress(V4_ADDRESS, 23);
315 l2 = new LinkAddress(V4_ADDRESS, 23, 0, RT_SCOPE_HOST);
316 assertNotEquals(l1.hashCode(), l2.hashCode());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900317
Hugo Benichi3054e102017-08-08 13:06:04 +0900318 l1 = new LinkAddress(V6_ADDRESS, 128);
319 l2 = new LinkAddress(V6_ADDRESS, 128, IFA_F_TENTATIVE, RT_SCOPE_UNIVERSE);
320 assertNotEquals(l1.hashCode(), l2.hashCode());
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900321 }
322
323 private LinkAddress passThroughParcel(LinkAddress l) {
324 Parcel p = Parcel.obtain();
325 LinkAddress l2 = null;
326 try {
327 l.writeToParcel(p, 0);
328 p.setDataPosition(0);
329 l2 = LinkAddress.CREATOR.createFromParcel(p);
330 } finally {
331 p.recycle();
332 }
333 assertNotNull(l2);
334 return l2;
335 }
336
337 private void assertParcelingIsLossless(LinkAddress l) {
338 LinkAddress l2 = passThroughParcel(l);
339 assertEquals(l, l2);
340 }
341
Hugo Benichi3054e102017-08-08 13:06:04 +0900342 @Test
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900343 public void testParceling() {
344 LinkAddress l;
345
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900346 l = new LinkAddress(V6_ADDRESS, 64, 123, 456);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900347 assertParcelingIsLossless(l);
348
Lorenzo Colitti4ea70b72013-11-15 18:43:52 +0900349 l = new LinkAddress(V4 + "/28", IFA_F_PERMANENT, RT_SCOPE_LINK);
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900350 assertParcelingIsLossless(l);
351 }
Erik Klinec17b5282014-10-20 19:46:56 +0900352
353 private void assertGlobalPreferred(LinkAddress l, String msg) {
354 assertTrue(msg, l.isGlobalPreferred());
355 }
356
357 private void assertNotGlobalPreferred(LinkAddress l, String msg) {
358 assertFalse(msg, l.isGlobalPreferred());
359 }
360
Hugo Benichi3054e102017-08-08 13:06:04 +0900361 @Test
Erik Klinec17b5282014-10-20 19:46:56 +0900362 public void testIsGlobalPreferred() {
363 LinkAddress l;
364
365 l = new LinkAddress(V4_ADDRESS, 32, 0, RT_SCOPE_UNIVERSE);
366 assertGlobalPreferred(l, "v4,global,noflags");
367
368 l = new LinkAddress("10.10.1.7/23", 0, RT_SCOPE_UNIVERSE);
369 assertGlobalPreferred(l, "v4-rfc1918,global,noflags");
370
371 l = new LinkAddress("10.10.1.7/23", 0, RT_SCOPE_SITE);
372 assertNotGlobalPreferred(l, "v4-rfc1918,site-local,noflags");
373
374 l = new LinkAddress("127.0.0.7/8", 0, RT_SCOPE_HOST);
375 assertNotGlobalPreferred(l, "v4-localhost,node-local,noflags");
376
377 l = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_UNIVERSE);
378 assertGlobalPreferred(l, "v6,global,noflags");
379
380 l = new LinkAddress(V6_ADDRESS, 64, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
381 assertGlobalPreferred(l, "v6,global,permanent");
382
383 // IPv6 ULAs are not acceptable "global preferred" addresses.
384 l = new LinkAddress("fc12::1/64", 0, RT_SCOPE_UNIVERSE);
385 assertNotGlobalPreferred(l, "v6,ula1,noflags");
386
387 l = new LinkAddress("fd34::1/64", 0, RT_SCOPE_UNIVERSE);
388 assertNotGlobalPreferred(l, "v6,ula2,noflags");
389
390 l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_UNIVERSE);
391 assertGlobalPreferred(l, "v6,global,tempaddr");
392
393 l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY|IFA_F_DADFAILED),
394 RT_SCOPE_UNIVERSE);
395 assertNotGlobalPreferred(l, "v6,global,tempaddr+dadfailed");
396
397 l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY|IFA_F_DEPRECATED),
398 RT_SCOPE_UNIVERSE);
399 assertNotGlobalPreferred(l, "v6,global,tempaddr+deprecated");
400
401 l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_SITE);
402 assertNotGlobalPreferred(l, "v6,site-local,tempaddr");
403
404 l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_LINK);
405 assertNotGlobalPreferred(l, "v6,link-local,tempaddr");
406
407 l = new LinkAddress(V6_ADDRESS, 64, IFA_F_TEMPORARY, RT_SCOPE_HOST);
408 assertNotGlobalPreferred(l, "v6,node-local,tempaddr");
409
410 l = new LinkAddress("::1/128", IFA_F_PERMANENT, RT_SCOPE_HOST);
411 assertNotGlobalPreferred(l, "v6-localhost,node-local,permanent");
412
413 l = new LinkAddress(V6_ADDRESS, 64, (IFA_F_TEMPORARY|IFA_F_TENTATIVE),
414 RT_SCOPE_UNIVERSE);
415 assertNotGlobalPreferred(l, "v6,global,tempaddr+tentative");
416
417 l = new LinkAddress(V6_ADDRESS, 64,
418 (IFA_F_TEMPORARY|IFA_F_TENTATIVE|IFA_F_OPTIMISTIC),
419 RT_SCOPE_UNIVERSE);
420 assertGlobalPreferred(l, "v6,global,tempaddr+optimistic");
421 }
Lorenzo Colitti64eb7fd2013-11-27 15:03:10 +0900422}