• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from autotest_lib.client.common_lib import error
6from autotest_lib.client.cros import dhcp_handling_rule
7from autotest_lib.client.cros import dhcp_packet
8from autotest_lib.client.cros import dhcp_test_base
9
10# dhcpcd has a 20 second minimal accepted lease time
11LEASE_TIME_SECONDS = 20
12# We'll fill in the subnet and give this address to the client.
13INTENDED_IP_SUFFIX = "0.0.0.101"
14
15class network_DhcpRenewWithOptionSubset(dhcp_test_base.DhcpTestBase):
16    """Tests DHCP renewal process in the connection manager."""
17    def test_body(self):
18        subnet_mask = self.ethernet_pair.interface_subnet_mask
19        intended_ip = dhcp_test_base.DhcpTestBase.rewrite_ip_suffix(
20                subnet_mask,
21                self.server_ip,
22                INTENDED_IP_SUFFIX)
23        # Two real name servers, and a bogus one to be unpredictable.
24        dns_servers = ["8.8.8.8", "8.8.4.4", "192.168.87.88"]
25        domain_name = "corp.google.com"
26        dns_search_list = [
27                "corgie.google.com",
28                "lies.google.com",
29                "that.is.a.tasty.burger.google.com",
30                ]
31        # This is the pool of information the server will give out to the client
32        # upon request.
33        minimal_options = {
34                dhcp_packet.OPTION_SERVER_ID : self.server_ip,
35                dhcp_packet.OPTION_SUBNET_MASK : subnet_mask,
36                dhcp_packet.OPTION_IP_LEASE_TIME : LEASE_TIME_SECONDS,
37                dhcp_packet.OPTION_REQUESTED_IP : intended_ip,
38                dhcp_packet.OPTION_DNS_SERVERS : dns_servers,
39        }
40        dhcp_options = minimal_options.copy()
41        dhcp_options.update({
42                dhcp_packet.OPTION_DOMAIN_NAME : domain_name,
43                dhcp_packet.OPTION_DNS_DOMAIN_SEARCH_LIST : dns_search_list,
44                })
45        self.negotiate_and_check_lease(dhcp_options)
46
47        # At renewal time, respond without the search list, and with a
48        # different domain name from the original lease.
49        changed_options = {
50                dhcp_packet.OPTION_DOMAIN_NAME : "mail.google.com",
51        }
52        renew_options = minimal_options.copy()
53        renew_options.update(changed_options)
54        rules = [
55                dhcp_handling_rule.DhcpHandlingRule_RespondToRequest(
56                        intended_ip,
57                        self.server_ip,
58                        renew_options,
59                        {},
60                        should_respond=True,
61                        # Per RFC-2131, the server identifier must be false
62                        # during REBOOT.
63                        expect_server_ip_set=False)
64                ]
65        rules[-1].is_final_handler = True
66        self.server.start_test(
67                rules, dhcp_test_base.DHCP_NEGOTIATION_TIMEOUT_SECONDS)
68
69        # Trigger lease renewal on the client.
70        interface_name = self.ethernet_pair.peer_interface_name
71        self.get_interface_ipconfig_objects(interface_name)[0].Refresh()
72
73        self.server.wait_for_test_to_finish()
74        if not self.server.last_test_passed:
75            raise error.TestFail("Test server didn't get a renewal request.")
76
77        # Check to make sure the system retained the search list from the
78        # initial lease, but also has the domain name from the ACK of the
79        # DHCPREQUEST.
80        dhcp_options.update(changed_options)
81        self.check_dhcp_config(dhcp_options)
82