blob: f7991c8d8c3e5256b69c898a2693b39c56d8010d [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
Jonas Oreland5b6a4d82020-03-24 07:36:52 +010055 bool operator==(const RouteEndpoint& other) const;
56
Jonas Oreland71fda362020-03-20 16:11:56 +010057 private:
58 AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN;
59 uint16_t adapter_id_ = 0;
60 uint16_t network_id_ = 0;
61 bool uses_turn_ = false;
62};
63
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020064struct NetworkRoute {
Steve Antonea1bb352018-07-23 10:12:37 -070065 bool connected = false;
Jonas Oreland71fda362020-03-20 16:11:56 +010066 RouteEndpoint local;
67 RouteEndpoint remote;
Steve Antonea1bb352018-07-23 10:12:37 -070068 // Last packet id sent on the PREVIOUS route.
69 int last_sent_packet_id = -1;
70 // The overhead in bytes from IP layer and above.
Jonas Oreland71fda362020-03-20 16:11:56 +010071 // This is the maximum of any part of the route.
Steve Antonea1bb352018-07-23 10:12:37 -070072 int packet_overhead = 0;
Jonas Oreland71fda362020-03-20 16:11:56 +010073
Jonas Oreland71fda362020-03-20 16:11:56 +010074 RTC_NO_INLINE inline std::string DebugString() const {
75 rtc::StringBuilder oss;
76 oss << "[ connected: " << connected << " local: [ " << local.adapter_id()
77 << "/" << local.network_id() << " "
78 << AdapterTypeToString(local.adapter_type())
79 << " turn: " << local.uses_turn() << " ] remote: [ "
80 << remote.adapter_id() << "/" << remote.network_id() << " "
81 << AdapterTypeToString(remote.adapter_type())
82 << " turn: " << remote.uses_turn()
83 << " ] packet_overhead_bytes: " << packet_overhead << " ]";
84 return oss.Release();
85 }
Jonas Oreland5b6a4d82020-03-24 07:36:52 +010086
87 bool operator==(const NetworkRoute& other) const;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020088};
Jonas Oreland71fda362020-03-20 16:11:56 +010089
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020090} // namespace rtc
Honghai Zhangcc411c02016-03-29 17:27:21 -070091
Steve Anton10542f22019-01-11 09:11:00 -080092#endif // RTC_BASE_NETWORK_ROUTE_H_