shill: reduce ARP traffic from LinkMonitor

This is achieved by monitoring the link passively (monitor on ARP requests)
after the link is determined as up via active link monitor (sending
ARP requests and probing for ARP replies). Only switch to active link
monitor when the passive link monitor completes after a preset number
of successful cycles or after a single failed cycle.

ARP traffic will be reduced since the device will not be generating
any ARP requests during passive link monitoring period. This will potentially
delay the detection of link failure up to one passive monitoring cycle
(25 seconds) when the link goes down during passive monitoring.

BUG=chromium:422159
TEST=USE="asan clang" FEATURES=test emerge-$BOARD shill
     Connect DUT to a wireless network, and verify link monitor mode switching
     via debug logs

Change-Id: I4c72a048da18cee7dc5be2cf2b51082cb9ae6716
Reviewed-on: https://chromium-review.googlesource.com/242684
Tested-by: Zeping Qiu <zqiu@chromium.org>
Reviewed-by: Zeping Qiu <zqiu@chromium.org>
Commit-Queue: Zeping Qiu <zqiu@chromium.org>
diff --git a/active_link_monitor.cc b/active_link_monitor.cc
index 85644c0..39d6f92 100644
--- a/active_link_monitor.cc
+++ b/active_link_monitor.cc
@@ -50,7 +50,10 @@
       device_info_(device_info),
       failure_callback_(failure_callback),
       success_callback_(success_callback),
-      arp_client_(new ArpClient(connection->interface_index())),
+      // Connection is not provided when this is used as a mock for testing
+      // purpose.
+      arp_client_(
+          new ArpClient(connection ? connection->interface_index() : 0)),
       test_period_milliseconds_(kDefaultTestPeriodMilliseconds),
       broadcast_failure_count_(0),
       unicast_failure_count_(0),
@@ -68,6 +71,7 @@
 }
 
 bool ActiveLinkMonitor::Start(int test_period) {
+  SLOG(connection_.get(), 2) << "In " << __func__ << ".";
   StopMonitorCycle();
   return StartInternal(test_period);
 }
@@ -309,7 +313,7 @@
   } else if (is_unicast_) {
     destination_mac_address = gateway_mac_address_;
   }
-  LOG(INFO) << "IsGatway " << IsGatewayFound() << " unicast: " << is_unicast_;
+
   ArpPacket request(connection_->local(), connection_->gateway(),
                     local_mac_address_, destination_mac_address);
   if (!arp_client_->TransmitRequest(request)) {