blob: c2b492ce186852d1dbb90b7f04a4a67835d8b467 [file] [log] [blame]
Honghai Zhangcc411c02016-03-29 17:27:21 -07001/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_NETWORK_ROUTE_H_
12#define RTC_BASE_NETWORK_ROUTE_H_
Honghai Zhangcc411c02016-03-29 17:27:21 -070013
Sebastian Janssone4be6da2018-02-15 16:51:41 +010014#include <stdint.h>
15
Jonas Oreland71fda362020-03-20 16:11:56 +010016#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 Kjellanderec78f1c2017-06-29 07:52:50 +020022// 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.
26namespace rtc {
Honghai Zhangcc411c02016-03-29 17:27:21 -070027
Jonas Oreland71fda362020-03-20 16:11:56 +010028class 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 }
49
50 AdapterType adapter_type() const { return adapter_type_; }
51 uint16_t adapter_id() const { return adapter_id_; }
52 uint16_t network_id() const { return network_id_; }
53 bool uses_turn() const { return uses_turn_; }
54
55 private:
56 AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN;
57 uint16_t adapter_id_ = 0;
58 uint16_t network_id_ = 0;
59 bool uses_turn_ = false;
60};
61
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020062struct NetworkRoute {
Steve Antonea1bb352018-07-23 10:12:37 -070063 bool connected = false;
Jonas Oreland71fda362020-03-20 16:11:56 +010064 RouteEndpoint local;
65 RouteEndpoint remote;
Steve Antonea1bb352018-07-23 10:12:37 -070066 // Last packet id sent on the PREVIOUS route.
67 int last_sent_packet_id = -1;
68 // The overhead in bytes from IP layer and above.
Jonas Oreland71fda362020-03-20 16:11:56 +010069 // This is the maximum of any part of the route.
Steve Antonea1bb352018-07-23 10:12:37 -070070 int packet_overhead = 0;
Jonas Oreland71fda362020-03-20 16:11:56 +010071
72 // Downstream projects depend on the old representation,
73 // populate that until they have been migrated.
74 // TODO(jonaso): remove.
75 uint16_t local_network_id = 0;
76 uint16_t remote_network_id = 0;
77
78 RTC_NO_INLINE inline std::string DebugString() const {
79 rtc::StringBuilder oss;
80 oss << "[ connected: " << connected << " local: [ " << local.adapter_id()
81 << "/" << local.network_id() << " "
82 << AdapterTypeToString(local.adapter_type())
83 << " turn: " << local.uses_turn() << " ] remote: [ "
84 << remote.adapter_id() << "/" << remote.network_id() << " "
85 << AdapterTypeToString(remote.adapter_type())
86 << " turn: " << remote.uses_turn()
87 << " ] packet_overhead_bytes: " << packet_overhead << " ]";
88 return oss.Release();
89 }
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020090};
Jonas Oreland71fda362020-03-20 16:11:56 +010091
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020092} // namespace rtc
Honghai Zhangcc411c02016-03-29 17:27:21 -070093
Steve Anton10542f22019-01-11 09:11:00 -080094#endif // RTC_BASE_NETWORK_ROUTE_H_