Add 16-bit network id to the candidate signaling.
Also include that in the stun-ping request as part of the
network-info attribute.
Change the network cost to be 16 bits.

BUG=

Review URL: https://codereview.webrtc.org/1815473002

Cr-Commit-Position: refs/heads/master@{#12110}
diff --git a/webrtc/base/network.cc b/webrtc/base/network.cc
index 4f3b919..4780e2f 100644
--- a/webrtc/base/network.cc
+++ b/webrtc/base/network.cc
@@ -286,6 +286,7 @@
       // This network is new. Place it in the network map.
       merged_list.push_back(net);
       networks_map_[key] = net;
+      net->set_id(next_available_network_id_++);
       // Also, we might have accumulated IPAddresses from the first
       // step, set it here.
       net->SetIPs(kv.second.ips, true);
diff --git a/webrtc/base/network.h b/webrtc/base/network.h
index 680c005..ee22d5e 100644
--- a/webrtc/base/network.h
+++ b/webrtc/base/network.h
@@ -173,6 +173,11 @@
 
   IPAddress default_local_ipv4_address_;
   IPAddress default_local_ipv6_address_;
+  // We use 16 bits to save the bandwidth consumption when sending the network
+  // id over the Internet. It is OK that the 16-bit integer overflows to get a
+  // network id 0 because we only compare the network ids in the old and the new
+  // best connections in the transport channel.
+  uint16_t next_available_network_id_ = 1;
 };
 
 // Basic implementation of the NetworkManager interface that gets list
@@ -339,6 +344,11 @@
   AdapterType type() const { return type_; }
   void set_type(AdapterType type) { type_ = type; }
 
+  // A unique id assigned by the network manager, which may be signaled
+  // to the remote side in the candidate.
+  uint16_t id() const { return id_; }
+  void set_id(uint16_t id) { id_ = id; }
+
   int preference() const { return preference_; }
   void set_preference(int preference) { preference_ = preference; }
 
@@ -372,6 +382,7 @@
   AdapterType type_;
   int preference_;
   bool active_ = true;
+  uint16_t id_ = 0;
 
   friend class NetworkManager;
 };
diff --git a/webrtc/base/network_unittest.cc b/webrtc/base/network_unittest.cc
index 7ad45a3..7133d8b 100644
--- a/webrtc/base/network_unittest.cc
+++ b/webrtc/base/network_unittest.cc
@@ -299,6 +299,8 @@
   EXPECT_EQ(1U, list.size());
   EXPECT_EQ(ipv4_network1.ToString(), list[0]->ToString());
   Network* net1 = list[0];
+  uint16_t net_id1 = net1->id();
+  EXPECT_EQ(1, net_id1);
   list.clear();
 
   // Replace ipv4_network1 with ipv4_network2.
@@ -315,6 +317,9 @@
   EXPECT_EQ(1U, list.size());
   EXPECT_EQ(ipv4_network2.ToString(), list[0]->ToString());
   Network* net2 = list[0];
+  uint16_t net_id2 = net2->id();
+  // Network id will increase.
+  EXPECT_LT(net_id1, net_id2);
   list.clear();
 
   // Add Network2 back.
@@ -332,6 +337,8 @@
   EXPECT_EQ(2U, list.size());
   EXPECT_TRUE((net1 == list[0] && net2 == list[1]) ||
               (net1 == list[1] && net2 == list[0]));
+  EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) ||
+              (net_id1 == list[1]->id() && net_id2 == list[0]->id()));
   list.clear();
 
   // Call MergeNetworkList() again and verify that we don't get update
@@ -350,6 +357,8 @@
   EXPECT_EQ(2U, list.size());
   EXPECT_TRUE((net1 == list[0] && net2 == list[1]) ||
               (net1 == list[1] && net2 == list[0]));
+  EXPECT_TRUE((net_id1 == list[0]->id() && net_id2 == list[1]->id()) ||
+              (net_id1 == list[1]->id() && net_id2 == list[0]->id()));
   list.clear();
 }
 
diff --git a/webrtc/base/networkmonitor.h b/webrtc/base/networkmonitor.h
index d9d6cc4..35ab2b1 100644
--- a/webrtc/base/networkmonitor.h
+++ b/webrtc/base/networkmonitor.h
@@ -46,6 +46,7 @@
   // This is needed because some operating systems (like Android) require a
   // special bind call to put packets on a non-default network interface.
   virtual int BindSocketToNetwork(int socket_fd, const IPAddress& address) = 0;
+  virtual ~NetworkBinderInterface() {}
 };
 
 /*