apmanager: DHCP server support

Start a DHCP server for an AP service when it is configured in server
mode. The server address is configure as "192.168.x.254" where
x is the least significant byte of the service identifier. The DHCP
range is from 192.168.x.1 to 192.168.x.128.

BUG=chromium:438836
TEST=unittests and manual test
Manual test:
Start an AP service using apmanager and verify a DUT can connect
to it with an IP address
CQ-DEPEND=CL:233032,CL:233493

Change-Id: I16a0d03c8eac7f02722c8c8f5185ca75a1edebcb
Reviewed-on: https://chromium-review.googlesource.com/233047
Reviewed-by: Peter Qiu <zqiu@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
diff --git a/mock_dhcp_server_factory.h b/mock_dhcp_server_factory.h
new file mode 100644
index 0000000..c20fd59
--- /dev/null
+++ b/mock_dhcp_server_factory.h
@@ -0,0 +1,39 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APMANAGER_MOCK_DHCP_SERVER_FACTORY_H_
+#define APMANAGER_MOCK_DHCP_SERVER_FACTORY_H_
+
+#include <string>
+
+#include <base/lazy_instance.h>
+#include <gmock/gmock.h>
+
+#include "apmanager/dhcp_server_factory.h"
+
+namespace apmanager {
+
+class MockDHCPServerFactory : public DHCPServerFactory {
+ public:
+  ~MockDHCPServerFactory() override;
+
+  // This is a singleton. Use MockDHCPServerFactory::GetInstance()->Foo().
+  static MockDHCPServerFactory* GetInstance();
+
+  MOCK_METHOD2(CreateDHCPServer,
+               DHCPServer*(uint16_t server_address_index,
+                           const std::string& interface_name));
+
+ protected:
+  MockDHCPServerFactory();
+
+ private:
+  friend struct base::DefaultLazyInstanceTraits<MockDHCPServerFactory>;
+
+  DISALLOW_COPY_AND_ASSIGN(MockDHCPServerFactory);
+};
+
+}  // namespace apmanager
+
+#endif  // APMANAGER_MOCK_DHCP_SERVER_FACTORY_H_