diff options
author | Thomas Haller <thaller@redhat.com> | 2017-07-07 23:34:41 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-07-25 06:44:12 +0200 |
commit | 22edeb5b691befd796c534cf71901b32f0b7945b (patch) | |
tree | 98cdbd184ae8d73242d267d27f4882094ecbf236 /src/dhcp/tests/test-dhcp-dhclient.c | |
parent | 74816a22374091f1cde34372387f8c6bfcd688dc (diff) | |
download | NetworkManager-22edeb5b691befd796c534cf71901b32f0b7945b.tar.gz |
core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex
Reasons:
- it adds an O(1) lookup index for accessing NMIPxConfig's addresses.
Hence, operations like merge/intersect have now runtime O(n) instead
of O(n^2).
Arguably, we expect low numbers of addresses in general. For low
numbers, the O(n^2) doesn't matter and quite likely in those cases
the previous implementation was just fine -- maybe even faster.
But the simple case works fine either way. It's important to scale
well in the exceptional case.
- the tracked objects can be shared between the various NMPI4Config,
NMIP6Config instances with NMPlatform and everybody else.
- the NMPObject can be treated generically, meaning it enables code to
handle both IPv4 and IPv6, or addresses and routes. See for example
_nm_ip_config_add_obj().
- I want core to evolve to somewhere where we don't keep copies of
NMPlatformIP4Address, et al. instances. Instead they shall all be
shared. I hope this will reduce memory consumption (although tracking a
reference consumes some memory too). Also, it shortcuts nmp_object_equal()
when comparing the same object. Calling nmp_object_equal() on the
identical objects would be a common case after the hash function
pre-evaluates equality.
Diffstat (limited to 'src/dhcp/tests/test-dhcp-dhclient.c')
-rw-r--r-- | src/dhcp/tests/test-dhcp-dhclient.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index c8e225e441..2e68a6e081 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -37,6 +37,8 @@ #define DEBUG 1 +static const int IFINDEX = 5; + static void test_config (const char *orig, const char *expected, @@ -910,7 +912,7 @@ test_read_lease_ip4_config_basic (void) /* Date from before the least expiration */ now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now); g_assert_cmpint (g_slist_length (leases), ==, 2); /* IP4Config #1 */ @@ -920,7 +922,7 @@ test_read_lease_ip4_config_basic (void) /* Address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); expected_addr = nmtst_inet4_from_string ("192.168.1.180"); - addr = nm_ip4_config_get_address (config, 0); + addr = _nmtst_nm_ip4_config_get_address (config, 0); g_assert_cmpint (addr->address, ==, expected_addr); g_assert_cmpint (addr->peer_address, ==, expected_addr); g_assert_cmpint (addr->plen, ==, 24); @@ -943,7 +945,7 @@ test_read_lease_ip4_config_basic (void) /* Address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); expected_addr = nmtst_inet4_from_string ("10.77.52.141"); - addr = nm_ip4_config_get_address (config, 0); + addr = _nmtst_nm_ip4_config_get_address (config, 0); g_assert_cmpint (addr->address, ==, expected_addr); g_assert_cmpint (addr->peer_address, ==, expected_addr); g_assert_cmpint (addr->plen, ==, 8); @@ -985,7 +987,7 @@ test_read_lease_ip4_config_expired (void) /* Date from *after* the lease expiration */ now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now); g_assert (leases == NULL); g_date_time_unref (now); @@ -1008,7 +1010,7 @@ test_read_lease_ip4_config_expect_failure (gconstpointer user_data) /* Date from before the least expiration */ now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1); - leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now); g_assert (leases == NULL); g_date_time_unref (now); |