Add field trial for using different network cost cellular types

This field trial will be used to rollout the cellular costs added
in https://webrtc-review.googlesource.com/c/src/+/172582 in
a controlled fashion.

Bug: webrtc:11473
Change-Id: I14fd5cada187ba161124325a7ff69d355ef52b25
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174880
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31233}
This commit is contained in:
Jonas Oreland 2020-05-13 10:15:34 +02:00 committed by Commit Bot
parent f3319816ad
commit 2105d64a02
2 changed files with 23 additions and 8 deletions

View File

@ -35,6 +35,7 @@
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/thread.h"
#include "system_wrappers/include/field_trial.h"
namespace rtc {
namespace {
@ -85,7 +86,8 @@ bool SortNetworks(const Network* a, const Network* b) {
return a->key() < b->key();
}
uint16_t ComputeNetworkCostByType(int type) {
uint16_t ComputeNetworkCostByType(int type,
bool use_differentiated_cellular_costs) {
// TODO(jonaso) : Rollout support for cellular network cost using A/B
// experiment to make sure it does not introduce regressions.
switch (type) {
@ -95,11 +97,19 @@ uint16_t ComputeNetworkCostByType(int type) {
case rtc::ADAPTER_TYPE_WIFI:
return kNetworkCostLow;
case rtc::ADAPTER_TYPE_CELLULAR:
case rtc::ADAPTER_TYPE_CELLULAR_2G:
case rtc::ADAPTER_TYPE_CELLULAR_3G:
case rtc::ADAPTER_TYPE_CELLULAR_4G:
case rtc::ADAPTER_TYPE_CELLULAR_5G:
return kNetworkCostCellular;
case rtc::ADAPTER_TYPE_CELLULAR_2G:
return use_differentiated_cellular_costs ? kNetworkCostCellular2G
: kNetworkCostCellular;
case rtc::ADAPTER_TYPE_CELLULAR_3G:
return use_differentiated_cellular_costs ? kNetworkCostCellular3G
: kNetworkCostCellular;
case rtc::ADAPTER_TYPE_CELLULAR_4G:
return use_differentiated_cellular_costs ? kNetworkCostCellular4G
: kNetworkCostCellular;
case rtc::ADAPTER_TYPE_CELLULAR_5G:
return use_differentiated_cellular_costs ? kNetworkCostCellular5G
: kNetworkCostCellular;
case rtc::ADAPTER_TYPE_ANY:
// Candidates gathered from the any-address/wildcard ports, as backups,
// are given the maximum cost so that if there are other candidates with
@ -930,7 +940,9 @@ Network::Network(const std::string& name,
scope_id_(0),
ignored_(false),
type_(ADAPTER_TYPE_UNKNOWN),
preference_(0) {}
preference_(0),
use_differentiated_cellular_costs_(webrtc::field_trial::IsEnabled(
"WebRTC-UseDifferentiatedCellularCosts")) {}
Network::Network(const std::string& name,
const std::string& desc,
@ -945,7 +957,9 @@ Network::Network(const std::string& name,
scope_id_(0),
ignored_(false),
type_(type),
preference_(0) {}
preference_(0),
use_differentiated_cellular_costs_(webrtc::field_trial::IsEnabled(
"WebRTC-UseDifferentiatedCellularCosts")) {}
Network::Network(const Network&) = default;
@ -1017,7 +1031,7 @@ webrtc::MdnsResponderInterface* Network::GetMdnsResponder() const {
uint16_t Network::GetCost() const {
AdapterType type = IsVpn() ? underlying_type_for_vpn_ : type_;
return ComputeNetworkCostByType(type);
return ComputeNetworkCostByType(type, use_differentiated_cellular_costs_);
}
std::string Network::ToString() const {

View File

@ -462,6 +462,7 @@ class RTC_EXPORT Network {
int preference_;
bool active_ = true;
uint16_t id_ = 0;
bool use_differentiated_cellular_costs_ = false;
friend class NetworkManager;
};