Add network cost as part of the connection ranking.
For now, the network cost is purely based on the network type (cellular has cost 0xFFFF and everything else has cost 0).
Add cost to the candidate signaling and the stun request signaling (which is needed for peer reflexive candidates).
BUG=webrtc:4325

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

Cr-Commit-Position: refs/heads/master@{#11642}
diff --git a/webrtc/api/webrtcsdp.cc b/webrtc/api/webrtcsdp.cc
index 5fd200a..a308a08 100644
--- a/webrtc/api/webrtcsdp.cc
+++ b/webrtc/api/webrtcsdp.cc
@@ -126,6 +126,7 @@
 static const char kAttributeCandidateUfrag[] = "ufrag";
 static const char kAttributeCandidatePwd[] = "pwd";
 static const char kAttributeCandidateGeneration[] = "generation";
+static const char kAttributeCandidateNetworkCost[] = "network-cost";
 static const char kAttributeFingerprint[] = "fingerprint";
 static const char kAttributeSetup[] = "setup";
 static const char kAttributeFmtp[] = "fmtp";
@@ -1062,6 +1063,7 @@
   std::string username;
   std::string password;
   uint32_t generation = 0;
+  uint32_t network_cost = 0;
   for (size_t i = current_position; i + 1 < fields.size(); ++i) {
     // RFC 5245
     // *(SP extension-att-name SP extension-att-value)
@@ -1073,6 +1075,10 @@
       username = fields[++i];
     } else if (fields[i] == kAttributeCandidatePwd) {
       password = fields[++i];
+    } else if (fields[i] == kAttributeCandidateNetworkCost) {
+      if (!GetValueFromString(first_line, fields[++i], &network_cost, error)) {
+        return false;
+      }
     } else {
       // Skip the unknown extension.
       ++i;
@@ -1084,6 +1090,7 @@
                          generation, foundation);
   candidate->set_related_address(related_address);
   candidate->set_tcptype(tcptype);
+  candidate->set_network_cost(std::min(network_cost, cricket::kMaxNetworkCost));
   return true;
 }
 
@@ -1758,6 +1765,9 @@
     if (include_ufrag && !it->username().empty()) {
       os << " " << kAttributeCandidateUfrag << " " << it->username();
     }
+    if (it->network_cost() > 0) {
+      os << " " << kAttributeCandidateNetworkCost << " " << it->network_cost();
+    }
 
     AddLine(os.str(), message);
   }