1 # Copyright (c) 2015 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 5 from autotest_lib.client.common_lib import error 6 from autotest_lib.client.common_lib.cros.network import interface 7 from autotest_lib.client.cros import dhcp_handling_rule 8 from autotest_lib.client.cros import dhcp_packet 9 from autotest_lib.client.cros import dhcp_test_base 10 from autotest_lib.client.cros.networking import shill_proxy 11 12 # Length of time the lease from the DHCP server is valid. 13 LEASE_TIME_SECONDS = 60 14 # We'll fill in the subnet and give this address to the client. 15 INTENDED_IP_SUFFIX = "0.0.0.101" 16 # We should be able to complete a DHCP negotiation in this amount of time. 17 DHCP_NEGOTIATION_TIMEOUT_SECONDS = 10 18 19 class network_DhcpFQDN(dhcp_test_base.DhcpTestBase): 20 """Test implemenation of client completing negotiation with FQDN flag.""" 21 22 def test_body(self): 23 """Main body of the test.""" 24 subnet_mask = self.ethernet_pair.interface_subnet_mask 25 intended_ip = dhcp_test_base.DhcpTestBase.rewrite_ip_suffix( 26 subnet_mask, 27 self.server_ip, 28 INTENDED_IP_SUFFIX) 29 # It doesn't matter what is contained in this option value, except that 30 # the DHCP client does not crash decoding it or passing its 31 # interpretation of it back to shill. 32 fqdn_option = '\x03\xff\x00' 33 # This is the pool of information the server will give out to the client 34 # upon request. 35 dhcp_options = { 36 dhcp_packet.OPTION_SERVER_ID : self.server_ip, 37 dhcp_packet.OPTION_SUBNET_MASK : subnet_mask, 38 dhcp_packet.OPTION_IP_LEASE_TIME : LEASE_TIME_SECONDS, 39 dhcp_packet.OPTION_REQUESTED_IP : intended_ip, 40 dhcp_packet.OPTION_FULLY_QUALIFIED_DOMAIN_NAME : fqdn_option 41 } 42 rules = [ 43 dhcp_handling_rule.DhcpHandlingRule_RespondToDiscovery( 44 intended_ip, self.server_ip, dhcp_options, {}), 45 dhcp_handling_rule.DhcpHandlingRule_RespondToRequest( 46 intended_ip, self.server_ip, dhcp_options, {}) 47 ] 48 rules[-1].is_final_handler = True 49 50 # In some DHCP server implementations, the FQDN option is provided in 51 # the DHCP ACK response without the client requesting it. 52 rules[-1].force_reply_options = [ 53 dhcp_packet.OPTION_FULLY_QUALIFIED_DOMAIN_NAME ] 54 55 self.server.start_test(rules, DHCP_NEGOTIATION_TIMEOUT_SECONDS) 56 self.server.wait_for_test_to_finish() 57 if not self.server.last_test_passed: 58 raise error.TestFail('Test server didn\'t get all the messages it ' 59 'was told to expect during negotiation.') 60 61 # This test passes if the DHCP client lives long enough to send 62 # the network configuration to shill. 63 self.wait_for_dhcp_propagation() 64 self.check_dhcp_config(dhcp_options) 65