Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: webrtc/rtc_base/network_unittest.cc

Issue 2983213002: Relanding: Move "max IPv6 networks" logic to BasicPortAllocator, and fix sorting. (Closed)
Patch Set: Fixing P2PTransportChannelMultihomedTest (was relying on ordering assumptions it shouldn't have beeā€¦ Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/rtc_base/network.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 NetworkManager::NetworkList list; 424 NetworkManager::NetworkList list;
425 manager.GetNetworks(&list); 425 manager.GetNetworks(&list);
426 EXPECT_EQ(original_list.size(), list.size()); 426 EXPECT_EQ(original_list.size(), list.size());
427 // Verify that the original members are in the merged list. 427 // Verify that the original members are in the merged list.
428 for (NetworkManager::NetworkList::iterator it = original_list.begin(); 428 for (NetworkManager::NetworkList::iterator it = original_list.begin();
429 it != original_list.end(); ++it) { 429 it != original_list.end(); ++it) {
430 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), *it)); 430 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), *it));
431 } 431 }
432 } 432 }
433 433
434 // Test that no more than manager.max_ipv6_networks() IPv6 networks get
435 // returned.
436 TEST_F(NetworkTest, TestIPv6MergeNetworkListTrimExcessive) {
437 BasicNetworkManager manager;
438 manager.SignalNetworksChanged.connect(static_cast<NetworkTest*>(this),
439 &NetworkTest::OnNetworksChanged);
440 NetworkManager::NetworkList original_list;
441
442 // Add twice the allowed number of IPv6 networks.
443 for (int i = 0; i < 2 * manager.max_ipv6_networks(); i++) {
444 // Make a network with different prefix length.
445 IPAddress ip;
446 EXPECT_TRUE(IPFromString("2401:fa01:4:1000:be30:faa:fee:faa", &ip));
447 IPAddress prefix = TruncateIP(ip, 64 - i);
448 Network* ipv6_network =
449 new Network("test_eth0", "Test Network Adapter 1", prefix, 64 - i);
450 ipv6_network->AddIP(ip);
451 original_list.push_back(ipv6_network);
452 }
453
454 // Add one IPv4 network.
455 Network* ipv4_network = new Network("test_eth0", "Test Network Adapter 1",
456 IPAddress(0x12345600U), 24);
457 ipv4_network->AddIP(IPAddress(0x12345600U));
458 original_list.push_back(ipv4_network);
459
460 bool changed = false;
461 MergeNetworkList(manager, original_list, &changed);
462 EXPECT_TRUE(changed);
463 NetworkManager::NetworkList list;
464 manager.GetNetworks(&list);
465
466 // List size should be the max allowed IPv6 networks plus one IPv4 network.
467 EXPECT_EQ(manager.max_ipv6_networks() + 1, (int)list.size());
468
469 // Verify that the IPv4 network is in the list.
470 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), ipv4_network));
471 }
472
473 // Tests that when two network lists that describe the same set of networks are 434 // Tests that when two network lists that describe the same set of networks are
474 // merged, that the changed callback is not called, and that the original 435 // merged, that the changed callback is not called, and that the original
475 // objects remain in the result list. 436 // objects remain in the result list.
476 TEST_F(NetworkTest, TestNoChangeMerge) { 437 TEST_F(NetworkTest, TestNoChangeMerge) {
477 BasicNetworkManager manager; 438 BasicNetworkManager manager;
478 manager.SignalNetworksChanged.connect( 439 manager.SignalNetworksChanged.connect(
479 static_cast<NetworkTest*>(this), &NetworkTest::OnNetworksChanged); 440 static_cast<NetworkTest*>(this), &NetworkTest::OnNetworksChanged);
480 NetworkManager::NetworkList original_list; 441 NetworkManager::NetworkList original_list;
481 SetupNetworks(&original_list); 442 SetupNetworks(&original_list);
482 bool changed = false; 443 bool changed = false;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 break; 657 break;
697 } 658 }
698 } 659 }
699 EXPECT_FALSE(ipv6_found); 660 EXPECT_FALSE(ipv6_found);
700 for (NetworkManager::NetworkList::iterator it = list.begin(); 661 for (NetworkManager::NetworkList::iterator it = list.begin();
701 it != list.end(); ++it) { 662 it != list.end(); ++it) {
702 delete (*it); 663 delete (*it);
703 } 664 }
704 } 665 }
705 666
706 TEST_F(NetworkTest, TestNetworkListSorting) { 667 // Test that when network interfaces are sorted and given preference values,
668 // IPv6 comes first.
669 TEST_F(NetworkTest, IPv6NetworksPreferredOverIPv4) {
707 BasicNetworkManager manager; 670 BasicNetworkManager manager;
708 Network ipv4_network1("test_eth0", "Test Network Adapter 1", 671 Network ipv4_network1("test_eth0", "Test Network Adapter 1",
709 IPAddress(0x12345600U), 24); 672 IPAddress(0x12345600U), 24);
710 ipv4_network1.AddIP(IPAddress(0x12345600U)); 673 ipv4_network1.AddIP(IPAddress(0x12345600U));
711 674
712 IPAddress ip; 675 IPAddress ip;
713 IPAddress prefix; 676 IPAddress prefix;
714 EXPECT_TRUE(IPFromString("2400:4030:1:2c00:be30:abcd:efab:cdef", &ip)); 677 EXPECT_TRUE(IPFromString("2400:4030:1:2c00:be30:abcd:efab:cdef", &ip));
715 prefix = TruncateIP(ip, 64); 678 prefix = TruncateIP(ip, 64);
716 Network ipv6_eth1_publicnetwork1_ip1("test_eth1", "Test NetworkAdapter 2", 679 Network ipv6_eth1_publicnetwork1_ip1("test_eth1", "Test NetworkAdapter 2",
717 prefix, 64); 680 prefix, 64);
718 ipv6_eth1_publicnetwork1_ip1.AddIP(ip); 681 ipv6_eth1_publicnetwork1_ip1.AddIP(ip);
719 682
720 NetworkManager::NetworkList list; 683 NetworkManager::NetworkList list;
721 list.push_back(new Network(ipv4_network1)); 684 list.push_back(new Network(ipv4_network1));
722 list.push_back(new Network(ipv6_eth1_publicnetwork1_ip1)); 685 list.push_back(new Network(ipv6_eth1_publicnetwork1_ip1));
723 Network* net1 = list[0]; 686 Network* net1 = list[0];
724 Network* net2 = list[1]; 687 Network* net2 = list[1];
725 688
726 bool changed = false; 689 bool changed = false;
727 MergeNetworkList(manager, list, &changed); 690 MergeNetworkList(manager, list, &changed);
728 ASSERT_TRUE(changed); 691 ASSERT_TRUE(changed);
729 // After sorting IPv6 network should be higher order than IPv4 networks. 692 // After sorting IPv6 network should be higher order than IPv4 networks.
730 EXPECT_TRUE(net1->preference() < net2->preference()); 693 EXPECT_TRUE(net1->preference() < net2->preference());
731 } 694 }
732 695
696 // When two interfaces are equivalent in everything but name, they're expected
697 // to be preference-ordered by name. For example, "eth0" before "eth1".
698 TEST_F(NetworkTest, NetworksSortedByInterfaceName) {
699 BasicNetworkManager manager;
700 Network* eth0 = new Network("test_eth0", "Test Network Adapter 1",
701 IPAddress(0x65432100U), 24);
702 eth0->AddIP(IPAddress(0x65432100U));
703 Network* eth1 = new Network("test_eth1", "Test Network Adapter 2",
704 IPAddress(0x12345600U), 24);
705 eth1->AddIP(IPAddress(0x12345600U));
706 NetworkManager::NetworkList list;
707 // Add them to the list in the opposite of the expected sorted order, to
708 // ensure sorting actually occurs.
709 list.push_back(eth1);
710 list.push_back(eth0);
711
712 bool changed = false;
713 MergeNetworkList(manager, list, &changed);
714 ASSERT_TRUE(changed);
715 // "test_eth0" should be preferred over "test_eth1".
716 EXPECT_TRUE(eth0->preference() > eth1->preference());
717 }
718
733 TEST_F(NetworkTest, TestNetworkAdapterTypes) { 719 TEST_F(NetworkTest, TestNetworkAdapterTypes) {
734 Network wifi("wlan0", "Wireless Adapter", IPAddress(0x12345600U), 24, 720 Network wifi("wlan0", "Wireless Adapter", IPAddress(0x12345600U), 24,
735 ADAPTER_TYPE_WIFI); 721 ADAPTER_TYPE_WIFI);
736 EXPECT_EQ(ADAPTER_TYPE_WIFI, wifi.type()); 722 EXPECT_EQ(ADAPTER_TYPE_WIFI, wifi.type());
737 Network ethernet("eth0", "Ethernet", IPAddress(0x12345600U), 24, 723 Network ethernet("eth0", "Ethernet", IPAddress(0x12345600U), 24,
738 ADAPTER_TYPE_ETHERNET); 724 ADAPTER_TYPE_ETHERNET);
739 EXPECT_EQ(ADAPTER_TYPE_ETHERNET, ethernet.type()); 725 EXPECT_EQ(ADAPTER_TYPE_ETHERNET, ethernet.type());
740 Network cellular("test_cell", "Cellular Adapter", IPAddress(0x12345600U), 24, 726 Network cellular("test_cell", "Cellular Adapter", IPAddress(0x12345600U), 24,
741 ADAPTER_TYPE_CELLULAR); 727 ADAPTER_TYPE_CELLULAR);
742 EXPECT_EQ(ADAPTER_TYPE_CELLULAR, cellular.type()); 728 EXPECT_EQ(ADAPTER_TYPE_CELLULAR, cellular.type());
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 // If the set default address is in a network, GetDefaultLocalAddress will 1131 // If the set default address is in a network, GetDefaultLocalAddress will
1146 // return the best IP in that network. 1132 // return the best IP in that network.
1147 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2); 1133 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2);
1148 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); 1134 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
1149 EXPECT_EQ(static_cast<IPAddress>(ip1), ip); 1135 EXPECT_EQ(static_cast<IPAddress>(ip1), ip);
1150 1136
1151 manager.StopUpdating(); 1137 manager.StopUpdating();
1152 } 1138 }
1153 1139
1154 } // namespace rtc 1140 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/rtc_base/network.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698