blob: 578b9710d0919cdf295ba423e35e884db6239e20 [file] [log] [blame]
Patrik Höglunde2d6a062017-10-05 14:53:33 +02001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef RTC_BASE_NETWORK_CONSTANTS_H_
12#define RTC_BASE_NETWORK_CONSTANTS_H_
13
14#include <stdint.h>
15
Jonas Oreland71fda362020-03-20 16:11:56 +010016#include <string>
17
Patrik Höglunde2d6a062017-10-05 14:53:33 +020018namespace rtc {
19
Jonas Oreland08d18062020-04-02 07:19:12 +020020constexpr uint16_t kNetworkCostMax = 999;
21constexpr uint16_t kNetworkCostCellular2G = 980;
22constexpr uint16_t kNetworkCostCellular3G = 910;
23constexpr uint16_t kNetworkCostCellular = 900;
24constexpr uint16_t kNetworkCostCellular4G = 500;
25constexpr uint16_t kNetworkCostCellular5G = 250;
26constexpr uint16_t kNetworkCostUnknown = 50;
27constexpr uint16_t kNetworkCostLow = 10;
28constexpr uint16_t kNetworkCostMin = 0;
29
Jonas Orelandb477fc72021-08-23 12:16:33 +020030// Add 1 to network cost of underlying network type
31// so that e.g a "plain" WIFI is prefered over a VPN over WIFI
32// everything else being equal.
33constexpr uint16_t kNetworkCostVpn = 1;
34
Jonas Oreland08d18062020-04-02 07:19:12 +020035// alias
36constexpr uint16_t kNetworkCostHigh = kNetworkCostCellular;
Patrik Höglunde2d6a062017-10-05 14:53:33 +020037
38enum AdapterType {
39 // This enum resembles the one in Chromium net::ConnectionType.
40 ADAPTER_TYPE_UNKNOWN = 0,
41 ADAPTER_TYPE_ETHERNET = 1 << 0,
42 ADAPTER_TYPE_WIFI = 1 << 1,
Jonas Oreland08d18062020-04-02 07:19:12 +020043 ADAPTER_TYPE_CELLULAR = 1 << 2, // This is CELLULAR of unknown type.
Patrik Höglunde2d6a062017-10-05 14:53:33 +020044 ADAPTER_TYPE_VPN = 1 << 3,
Qingsi Wang9f1de692018-06-28 15:38:09 -070045 ADAPTER_TYPE_LOOPBACK = 1 << 4,
46 // ADAPTER_TYPE_ANY is used for a network, which only contains a single "any
47 // address" IP address (INADDR_ANY for IPv4 or in6addr_any for IPv6), and can
48 // use any/all network interfaces. Whereas ADAPTER_TYPE_UNKNOWN is used
49 // when the network uses a specific interface/IP, but its interface type can
50 // not be determined or not fit in this enum.
51 ADAPTER_TYPE_ANY = 1 << 5,
Jonas Oreland08d18062020-04-02 07:19:12 +020052 ADAPTER_TYPE_CELLULAR_2G = 1 << 6,
53 ADAPTER_TYPE_CELLULAR_3G = 1 << 7,
54 ADAPTER_TYPE_CELLULAR_4G = 1 << 8,
55 ADAPTER_TYPE_CELLULAR_5G = 1 << 9
Patrik Höglunde2d6a062017-10-05 14:53:33 +020056};
57
Jonas Oreland71fda362020-03-20 16:11:56 +010058std::string AdapterTypeToString(AdapterType type);
59
Jonas Oreland30019052022-01-28 14:11:44 +010060// Useful for testing!
61constexpr AdapterType kAllAdapterTypes[] = {
62 ADAPTER_TYPE_UNKNOWN, ADAPTER_TYPE_ETHERNET,
63 ADAPTER_TYPE_WIFI, ADAPTER_TYPE_CELLULAR,
64 ADAPTER_TYPE_VPN, ADAPTER_TYPE_LOOPBACK,
65 ADAPTER_TYPE_ANY, ADAPTER_TYPE_CELLULAR_2G,
66 ADAPTER_TYPE_CELLULAR_3G, ADAPTER_TYPE_CELLULAR_4G,
67 ADAPTER_TYPE_CELLULAR_5G,
68};
69
Patrik Höglunde2d6a062017-10-05 14:53:33 +020070} // namespace rtc
71
72#endif // RTC_BASE_NETWORK_CONSTANTS_H_