Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef RTC_BASE_NETWORK_ROUTE_H_ |
| 12 | #define RTC_BASE_NETWORK_ROUTE_H_ |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 13 | |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 16 | #include <string> |
| 17 | |
| 18 | #include "rtc_base/network_constants.h" |
| 19 | #include "rtc_base/strings/string_builder.h" |
| 20 | #include "rtc_base/system/inline.h" |
| 21 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 22 | // TODO(honghaiz): Make a directory that describes the interfaces and structs |
| 23 | // the media code can rely on and the network code can implement, and both can |
| 24 | // depend on that, but not depend on each other. Then, move this file to that |
| 25 | // directory. |
| 26 | namespace rtc { |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 27 | |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 28 | class RouteEndpoint { |
| 29 | public: |
| 30 | RouteEndpoint() {} // Used by tests. |
| 31 | RouteEndpoint(AdapterType adapter_type, |
| 32 | uint16_t adapter_id, |
| 33 | uint16_t network_id, |
| 34 | bool uses_turn) |
| 35 | : adapter_type_(adapter_type), |
| 36 | adapter_id_(adapter_id), |
| 37 | network_id_(network_id), |
| 38 | uses_turn_(uses_turn) {} |
| 39 | |
| 40 | RouteEndpoint(const RouteEndpoint&) = default; |
| 41 | RouteEndpoint& operator=(const RouteEndpoint&) = default; |
| 42 | |
| 43 | // Used by tests. |
| 44 | static RouteEndpoint CreateWithNetworkId(uint16_t network_id) { |
| 45 | return RouteEndpoint(ADAPTER_TYPE_UNKNOWN, |
| 46 | /* adapter_id = */ 0, network_id, |
| 47 | /* uses_turn = */ false); |
| 48 | } |
Christoffer Rodbro | 1c7a658 | 2020-03-26 21:48:25 | [diff] [blame] | 49 | RouteEndpoint CreateWithTurn(bool uses_turn) const { |
| 50 | return RouteEndpoint(adapter_type_, adapter_id_, network_id_, uses_turn); |
| 51 | } |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 52 | |
| 53 | AdapterType adapter_type() const { return adapter_type_; } |
| 54 | uint16_t adapter_id() const { return adapter_id_; } |
| 55 | uint16_t network_id() const { return network_id_; } |
| 56 | bool uses_turn() const { return uses_turn_; } |
| 57 | |
Jonas Oreland | 5b6a4d8 | 2020-03-24 06:36:52 | [diff] [blame] | 58 | bool operator==(const RouteEndpoint& other) const; |
| 59 | |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 60 | private: |
| 61 | AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN; |
| 62 | uint16_t adapter_id_ = 0; |
| 63 | uint16_t network_id_ = 0; |
| 64 | bool uses_turn_ = false; |
| 65 | }; |
| 66 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 67 | struct NetworkRoute { |
Steve Anton | ea1bb35 | 2018-07-23 17:12:37 | [diff] [blame] | 68 | bool connected = false; |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 69 | RouteEndpoint local; |
| 70 | RouteEndpoint remote; |
Steve Anton | ea1bb35 | 2018-07-23 17:12:37 | [diff] [blame] | 71 | // Last packet id sent on the PREVIOUS route. |
| 72 | int last_sent_packet_id = -1; |
| 73 | // The overhead in bytes from IP layer and above. |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 74 | // This is the maximum of any part of the route. |
Steve Anton | ea1bb35 | 2018-07-23 17:12:37 | [diff] [blame] | 75 | int packet_overhead = 0; |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 76 | |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 77 | RTC_NO_INLINE inline std::string DebugString() const { |
| 78 | rtc::StringBuilder oss; |
| 79 | oss << "[ connected: " << connected << " local: [ " << local.adapter_id() |
| 80 | << "/" << local.network_id() << " " |
| 81 | << AdapterTypeToString(local.adapter_type()) |
| 82 | << " turn: " << local.uses_turn() << " ] remote: [ " |
| 83 | << remote.adapter_id() << "/" << remote.network_id() << " " |
| 84 | << AdapterTypeToString(remote.adapter_type()) |
| 85 | << " turn: " << remote.uses_turn() |
| 86 | << " ] packet_overhead_bytes: " << packet_overhead << " ]"; |
| 87 | return oss.Release(); |
| 88 | } |
Jonas Oreland | 5b6a4d8 | 2020-03-24 06:36:52 | [diff] [blame] | 89 | |
| 90 | bool operator==(const NetworkRoute& other) const; |
Per K | 1d2f85d | 2024-10-23 12:11:41 | [diff] [blame] | 91 | bool operator!=(const NetworkRoute& other) { return !operator==(other); } |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 92 | }; |
Jonas Oreland | 71fda36 | 2020-03-20 15:11:56 | [diff] [blame] | 93 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 94 | } // namespace rtc |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 95 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 96 | #endif // RTC_BASE_NETWORK_ROUTE_H_ |