Skip to content

Commit

Permalink
Add field trial for using different network cost cellular types
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Jonas Oreland authored and Commit Bot committed May 13, 2020
1 parent f331981 commit 2105d64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions rtc_base/network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -95,11 +97,19 @@ uint16_t ComputeNetworkCostByType(int type) {
case rtc::ADAPTER_TYPE_WIFI:
return kNetworkCostLow;
case rtc::ADAPTER_TYPE_CELLULAR:
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 kNetworkCostCellular;
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
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions rtc_base/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 2105d64

Please sign in to comment.