Services network reporting.

Added a network ID to each services object, to identify the network
(gateway) that the service is connected to. Network ID is generated by
hashing a random salt value, together with gateway's IP and MAC address.
At the time when the device is connected to a network, report the number
of services that are connected to the same network.

BUG=chromium:359302
CQ-DEPEND=CL:194942
TEST=unittest, manual
Manual Test
1. Configure airport extreme router with two BSSes bss1 "cros airport extreme wpa2"
   and bss2 "cros aiport extreme wpa2 5GHz".
2. Connect a peppy device to bss1, then connect it to bss2.
3. Verify the ip address stays the same when connected to bss2.
4. Verify the ConnectionId for both BSSes is the same in
   "/var/cache/shill/default_profile".
5. Verify histogram for Network.Shill.ServicesOnSameNetwork
   exist in "chrome://histogram", and there is 1 entry for value 2.

Change-Id: I01c446b58be96cb0613a7d5336248838a6e865a9
Reviewed-on: https://chromium-review.googlesource.com/194857
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
diff --git a/manager_unittest.cc b/manager_unittest.cc
index 0561c5f..fb44c26 100644
--- a/manager_unittest.cc
+++ b/manager_unittest.cc
@@ -2627,6 +2627,33 @@
   EXPECT_TRUE(manager()->default_service_callbacks_.empty());
 }
 
+TEST_F(ManagerTest, ReportServicesOnSameNetwork) {
+  int connection_id1 = 100;
+  int connection_id2 = 200;
+  scoped_refptr<MockService> mock_service1 =
+      new NiceMock<MockService>(control_interface(), dispatcher(),
+                                metrics(), manager());
+  mock_service1->set_connection_id(connection_id1);
+  scoped_refptr<MockService> mock_service2 =
+      new NiceMock<MockService>(control_interface(), dispatcher(),
+                                metrics(), manager());
+  mock_service2->set_connection_id(connection_id1);
+  scoped_refptr<MockService> mock_service3 =
+      new NiceMock<MockService>(control_interface(), dispatcher(),
+                                metrics(), manager());
+  mock_service3->set_connection_id(connection_id2);
+
+  manager()->RegisterService(mock_service1);
+  manager()->RegisterService(mock_service2);
+  manager()->RegisterService(mock_service3);
+
+  EXPECT_CALL(*metrics(), NotifyServicesOnSameNetwork(2));
+  manager()->ReportServicesOnSameNetwork(connection_id1);
+
+  EXPECT_CALL(*metrics(), NotifyServicesOnSameNetwork(1));
+  manager()->ReportServicesOnSameNetwork(connection_id2);
+}
+
 TEST_F(ManagerTest, AvailableTechnologies) {
   mock_devices_.push_back(new NiceMock<MockDevice>(control_interface(),
                                                    dispatcher(),