Path.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_PATH_HPP
  14. #define ZT_PATH_HPP
  15. #include <stdint.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <stdexcept>
  19. #include <algorithm>
  20. #include "Constants.hpp"
  21. #include "InetAddress.hpp"
  22. #include "SharedPtr.hpp"
  23. #include "AtomicCounter.hpp"
  24. #include "Utils.hpp"
  25. #include "Packet.hpp"
  26. #include "RingBuffer.hpp"
  27. #include "../osdep/Link.hpp"
  28. /**
  29. * Maximum return value of preferenceRank()
  30. */
  31. #define ZT_PATH_MAX_PREFERENCE_RANK ((ZT_INETADDRESS_MAX_SCOPE << 1) | 1)
  32. namespace ZeroTier {
  33. class RuntimeEnvironment;
  34. /**
  35. * A path across the physical network
  36. */
  37. class Path
  38. {
  39. friend class SharedPtr<Path>;
  40. friend class Bond;
  41. public:
  42. /**
  43. * Efficient unique key for paths in a Hashtable
  44. */
  45. class HashKey
  46. {
  47. public:
  48. HashKey() {}
  49. HashKey(const int64_t l,const InetAddress &r)
  50. {
  51. if (r.ss_family == AF_INET) {
  52. _k[0] = (uint64_t)reinterpret_cast<const struct sockaddr_in *>(&r)->sin_addr.s_addr;
  53. _k[1] = (uint64_t)reinterpret_cast<const struct sockaddr_in *>(&r)->sin_port;
  54. _k[2] = (uint64_t)l;
  55. } else if (r.ss_family == AF_INET6) {
  56. memcpy(_k,reinterpret_cast<const struct sockaddr_in6 *>(&r)->sin6_addr.s6_addr,16);
  57. _k[2] = ((uint64_t)reinterpret_cast<const struct sockaddr_in6 *>(&r)->sin6_port << 32) ^ (uint64_t)l;
  58. } else {
  59. memcpy(_k,&r,std::min(sizeof(_k),sizeof(InetAddress)));
  60. _k[2] += (uint64_t)l;
  61. }
  62. }
  63. inline unsigned long hashCode() const { return (unsigned long)(_k[0] + _k[1] + _k[2]); }
  64. inline bool operator==(const HashKey &k) const { return ( (_k[0] == k._k[0]) && (_k[1] == k._k[1]) && (_k[2] == k._k[2]) ); }
  65. inline bool operator!=(const HashKey &k) const { return (!(*this == k)); }
  66. private:
  67. uint64_t _k[3];
  68. };
  69. Path() :
  70. _lastOut(0),
  71. _lastIn(0),
  72. _lastTrustEstablishedPacketReceived(0),
  73. _localSocket(-1),
  74. _latency(0xffff),
  75. _addr(),
  76. _ipScope(InetAddress::IP_SCOPE_NONE),
  77. _lastAckReceived(0),
  78. _lastAckSent(0),
  79. _lastQoSMeasurement(0),
  80. _lastThroughputEstimation(0),
  81. _lastRefractoryUpdate(0),
  82. _lastAliveToggle(0),
  83. _lastEligibilityState(false),
  84. _lastTrialBegin(0),
  85. _refractoryPeriod(0),
  86. _monitorInterval(0),
  87. _upDelay(0),
  88. _downDelay(0),
  89. _ipvPref(0),
  90. _mode(0),
  91. _onlyPathOnLink(false),
  92. _enabled(false),
  93. _bonded(false),
  94. _negotiated(false),
  95. _deprecated(false),
  96. _shouldReallocateFlows(false),
  97. _assignedFlowCount(0),
  98. _latencyMean(0),
  99. _latencyVariance(0),
  100. _packetLossRatio(0),
  101. _packetErrorRatio(0),
  102. _throughputMean(0),
  103. _throughputMax(0),
  104. _throughputVariance(0),
  105. _allocation(0),
  106. _byteLoad(0),
  107. _relativeByteLoad(0),
  108. _affinity(0),
  109. _failoverScore(0),
  110. _unackedBytes(0),
  111. _packetsReceivedSinceLastAck(0),
  112. _packetsReceivedSinceLastQoS(0),
  113. _bytesAckedSinceLastThroughputEstimation(0),
  114. _packetsIn(0),
  115. _packetsOut(0)
  116. {}
  117. Path(const int64_t localSocket,const InetAddress &addr) :
  118. _lastOut(0),
  119. _lastIn(0),
  120. _lastTrustEstablishedPacketReceived(0),
  121. _localSocket(localSocket),
  122. _latency(0xffff),
  123. _addr(addr),
  124. _ipScope(addr.ipScope()),
  125. _lastAckReceived(0),
  126. _lastAckSent(0),
  127. _lastQoSMeasurement(0),
  128. _lastThroughputEstimation(0),
  129. _lastRefractoryUpdate(0),
  130. _lastAliveToggle(0),
  131. _lastEligibilityState(false),
  132. _lastTrialBegin(0),
  133. _refractoryPeriod(0),
  134. _monitorInterval(0),
  135. _upDelay(0),
  136. _downDelay(0),
  137. _ipvPref(0),
  138. _mode(0),
  139. _onlyPathOnLink(false),
  140. _enabled(false),
  141. _bonded(false),
  142. _negotiated(false),
  143. _deprecated(false),
  144. _shouldReallocateFlows(false),
  145. _assignedFlowCount(0),
  146. _latencyMean(0),
  147. _latencyVariance(0),
  148. _packetLossRatio(0),
  149. _packetErrorRatio(0),
  150. _throughputMean(0),
  151. _throughputMax(0),
  152. _throughputVariance(0),
  153. _allocation(0),
  154. _byteLoad(0),
  155. _relativeByteLoad(0),
  156. _affinity(0),
  157. _failoverScore(0),
  158. _unackedBytes(0),
  159. _packetsReceivedSinceLastAck(0),
  160. _packetsReceivedSinceLastQoS(0),
  161. _bytesAckedSinceLastThroughputEstimation(0),
  162. _packetsIn(0),
  163. _packetsOut(0)
  164. {}
  165. /**
  166. * Called when a packet is received from this remote path, regardless of content
  167. *
  168. * @param t Time of receive
  169. */
  170. inline void received(const uint64_t t)
  171. {
  172. if (!alive(t,_bonded)) {
  173. _lastAliveToggle = _lastIn;
  174. }
  175. _lastIn = t;
  176. }
  177. /**
  178. * Set time last trusted packet was received (done in Peer::received())
  179. */
  180. inline void trustedPacketReceived(const uint64_t t) { _lastTrustEstablishedPacketReceived = t; }
  181. /**
  182. * Send a packet via this path (last out time is also updated)
  183. *
  184. * @param RR Runtime environment
  185. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  186. * @param data Packet data
  187. * @param len Packet length
  188. * @param now Current time
  189. * @return True if transport reported success
  190. */
  191. bool send(const RuntimeEnvironment *RR,void *tPtr,const void *data,unsigned int len,int64_t now);
  192. /**
  193. * Manually update last sent time
  194. *
  195. * @param t Time of send
  196. */
  197. inline void sent(const int64_t t) { _lastOut = t; }
  198. /**
  199. * Update path latency with a new measurement
  200. *
  201. * @param l Measured latency
  202. */
  203. inline void updateLatency(const unsigned int l, int64_t now)
  204. {
  205. unsigned int pl = _latency;
  206. if (pl < 0xffff) {
  207. _latency = (pl + l) / 2;
  208. }
  209. else {
  210. _latency = l;
  211. }
  212. }
  213. /**
  214. * @return Local socket as specified by external code
  215. */
  216. inline int64_t localSocket() const { return _localSocket; }
  217. /**
  218. * @return Physical address
  219. */
  220. inline const InetAddress &address() const { return _addr; }
  221. /**
  222. * @return IP scope -- faster shortcut for address().ipScope()
  223. */
  224. inline InetAddress::IpScope ipScope() const { return _ipScope; }
  225. /**
  226. * @return True if path has received a trust established packet (e.g. common network membership) in the past ZT_TRUST_EXPIRATION ms
  227. */
  228. inline bool trustEstablished(const int64_t now) const { return ((now - _lastTrustEstablishedPacketReceived) < ZT_TRUST_EXPIRATION); }
  229. /**
  230. * @return Preference rank, higher == better
  231. */
  232. inline unsigned int preferenceRank() const
  233. {
  234. // This causes us to rank paths in order of IP scope rank (see InetAdddress.hpp) but
  235. // within each IP scope class to prefer IPv6 over IPv4.
  236. return ( ((unsigned int)_ipScope << 1) | (unsigned int)(_addr.ss_family == AF_INET6) );
  237. }
  238. /**
  239. * Check whether this address is valid for a ZeroTier path
  240. *
  241. * This checks the address type and scope against address types and scopes
  242. * that we currently support for ZeroTier communication.
  243. *
  244. * @param a Address to check
  245. * @return True if address is good for ZeroTier path use
  246. */
  247. static inline bool isAddressValidForPath(const InetAddress &a)
  248. {
  249. if ((a.ss_family == AF_INET)||(a.ss_family == AF_INET6)) {
  250. switch(a.ipScope()) {
  251. /* Note: we don't do link-local at the moment. Unfortunately these
  252. * cause several issues. The first is that they usually require a
  253. * device qualifier, which we don't handle yet and can't portably
  254. * push in PUSH_DIRECT_PATHS. The second is that some OSes assign
  255. * these very ephemerally or otherwise strangely. So we'll use
  256. * private, pseudo-private, shared (e.g. carrier grade NAT), or
  257. * global IP addresses. */
  258. case InetAddress::IP_SCOPE_PRIVATE:
  259. case InetAddress::IP_SCOPE_PSEUDOPRIVATE:
  260. case InetAddress::IP_SCOPE_SHARED:
  261. case InetAddress::IP_SCOPE_GLOBAL:
  262. if (a.ss_family == AF_INET6) {
  263. // TEMPORARY HACK: for now, we are going to blacklist he.net IPv6
  264. // tunnels due to very spotty performance and low MTU issues over
  265. // these IPv6 tunnel links.
  266. const uint8_t *ipd = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr);
  267. if ((ipd[0] == 0x20)&&(ipd[1] == 0x01)&&(ipd[2] == 0x04)&&(ipd[3] == 0x70))
  268. return false;
  269. }
  270. return true;
  271. default:
  272. return false;
  273. }
  274. }
  275. return false;
  276. }
  277. /**
  278. * @return Latency or 0xffff if unknown
  279. */
  280. inline unsigned int latency() const { return _latency; }
  281. /**
  282. * @return Path quality -- lower is better
  283. */
  284. inline long quality(const int64_t now) const
  285. {
  286. const int l = (long)_latency;
  287. const int age = (long)std::min((now - _lastIn),(int64_t)(ZT_PATH_HEARTBEAT_PERIOD * 10)); // set an upper sanity limit to avoid overflow
  288. return (((age < (ZT_PATH_HEARTBEAT_PERIOD + 5000)) ? l : (l + 0xffff + age)) * (long)((ZT_INETADDRESS_MAX_SCOPE - _ipScope) + 1));
  289. }
  290. /**
  291. * @param bonded Whether this path is part of a bond.
  292. */
  293. inline void setBonded(bool bonded) { _bonded = bonded; }
  294. /**
  295. * @return True if this path is currently part of a bond.
  296. */
  297. inline bool bonded() { return _bonded; }
  298. /**
  299. * @return True if this path is alive (receiving heartbeats)
  300. */
  301. inline bool alive(const int64_t now, bool bondingEnabled = false) const {
  302. return (bondingEnabled && _monitorInterval) ? ((now - _lastIn) < (_monitorInterval * 3)) : ((now - _lastIn) < (ZT_PATH_HEARTBEAT_PERIOD + 5000));
  303. }
  304. /**
  305. * @return True if this path needs a heartbeat
  306. */
  307. inline bool needsHeartbeat(const int64_t now) const { return ((now - _lastOut) >= ZT_PATH_HEARTBEAT_PERIOD); }
  308. /**
  309. * @return True if this path needs a heartbeat in accordance to the user-specified path monitor frequency
  310. */
  311. inline bool needsGratuitousHeartbeat(const int64_t now) { return allowed() && (_monitorInterval > 0) && ((now - _lastOut) >= _monitorInterval); }
  312. /**
  313. * @return Last time we sent something
  314. */
  315. inline int64_t lastOut() const { return _lastOut; }
  316. /**
  317. * @return Last time we received anything
  318. */
  319. inline int64_t lastIn() const { return _lastIn; }
  320. /**
  321. * @return the age of the path in terms of receiving packets
  322. */
  323. inline int64_t age(int64_t now) { return (now - _lastIn); }
  324. /**
  325. * @return Time last trust-established packet was received
  326. */
  327. inline int64_t lastTrustEstablishedPacketReceived() const { return _lastTrustEstablishedPacketReceived; }
  328. /**
  329. * @return Time since last VERB_ACK was received
  330. */
  331. inline int64_t ackAge(int64_t now) { return _lastAckReceived ? now - _lastAckReceived : 0; }
  332. /**
  333. * Set or update a refractory period for the path.
  334. *
  335. * @param punishment How much a path should be punished
  336. * @param pathFailure Whether this call is the result of a recent path failure
  337. */
  338. inline void adjustRefractoryPeriod(int64_t now, uint32_t punishment, bool pathFailure) {
  339. if (pathFailure) {
  340. unsigned int suggestedRefractoryPeriod = _refractoryPeriod ? punishment + (_refractoryPeriod * 2) : punishment;
  341. _refractoryPeriod = std::min(suggestedRefractoryPeriod, (unsigned int)ZT_MULTIPATH_MAX_REFRACTORY_PERIOD);
  342. _lastRefractoryUpdate = 0;
  343. } else {
  344. uint32_t drainRefractory = 0;
  345. if (_lastRefractoryUpdate) {
  346. drainRefractory = (now - _lastRefractoryUpdate);
  347. } else {
  348. drainRefractory = (now - _lastAliveToggle);
  349. }
  350. _lastRefractoryUpdate = now;
  351. if (_refractoryPeriod > drainRefractory) {
  352. _refractoryPeriod -= drainRefractory;
  353. } else {
  354. _refractoryPeriod = 0;
  355. _lastRefractoryUpdate = 0;
  356. }
  357. }
  358. }
  359. /**
  360. * Determine the current state of eligibility of the path.
  361. *
  362. * @param includeRefractoryPeriod Whether current punishment should be taken into consideration
  363. * @return True if this path can be used in a bond at the current time
  364. */
  365. inline bool eligible(uint64_t now, int ackSendInterval, bool includeRefractoryPeriod = false) {
  366. if (includeRefractoryPeriod && _refractoryPeriod) {
  367. return false;
  368. }
  369. bool acceptableAge = age(now) < ((_monitorInterval * 4) + _downDelay); // Simple RX age (driven by packets of any type and gratuitous VERB_HELLOs)
  370. bool acceptableAckAge = ackAge(now) < (ackSendInterval); // Whether the remote peer is actually responding to our outgoing traffic or simply sending stuff to us
  371. bool notTooEarly = (now - _lastAliveToggle) >= _upDelay; // Whether we've waited long enough since the link last came online
  372. bool inTrial = (now - _lastTrialBegin) < _upDelay; // Whether this path is still in its trial period
  373. bool currEligibility = allowed() && (((acceptableAge || acceptableAckAge) && notTooEarly) || inTrial);
  374. return currEligibility;
  375. }
  376. /**
  377. * Record when this path first entered the bond. Each path is given a trial period where it is admitted
  378. * to the bond without requiring observations to prove its performance or reliability.
  379. */
  380. inline void startTrial(uint64_t now) { _lastTrialBegin = now; }
  381. /**
  382. * @return True if a path is permitted to be used in a bond (according to user pref.)
  383. */
  384. inline bool allowed() {
  385. return _enabled
  386. && (!_ipvPref
  387. || ((_addr.isV4() && (_ipvPref == 4 || _ipvPref == 46 || _ipvPref == 64))
  388. || ((_addr.isV6() && (_ipvPref == 6 || _ipvPref == 46 || _ipvPref == 64)))));
  389. }
  390. /**
  391. * @return True if a path is preferred over another on the same physical link (according to user pref.)
  392. */
  393. inline bool preferred() {
  394. return _onlyPathOnLink
  395. || (_addr.isV4() && (_ipvPref == 4 || _ipvPref == 46))
  396. || (_addr.isV6() && (_ipvPref == 6 || _ipvPref == 64));
  397. }
  398. /**
  399. * @param now Current time
  400. * @return Whether an ACK (VERB_ACK) packet needs to be emitted at this time
  401. */
  402. inline bool needsToSendAck(int64_t now, int ackSendInterval) {
  403. return ((now - _lastAckSent) >= ackSendInterval ||
  404. (_packetsReceivedSinceLastAck == ZT_QOS_TABLE_SIZE)) && _packetsReceivedSinceLastAck;
  405. }
  406. /**
  407. * @param now Current time
  408. * @return Whether a QoS (VERB_QOS_MEASUREMENT) packet needs to be emitted at this time
  409. */
  410. inline bool needsToSendQoS(int64_t now, int qosSendInterval) {
  411. return ((_packetsReceivedSinceLastQoS >= ZT_QOS_TABLE_SIZE) ||
  412. ((now - _lastQoSMeasurement) > qosSendInterval)) && _packetsReceivedSinceLastQoS;
  413. }
  414. /**
  415. * Reset packet counters
  416. */
  417. inline void resetPacketCounts()
  418. {
  419. _packetsIn = 0;
  420. _packetsOut = 0;
  421. }
  422. /**
  423. * The mean latency (computed from a sliding window.)
  424. */
  425. float latencyMean() { return _latencyMean; }
  426. /**
  427. * Packet delay variance (computed from a sliding window.)
  428. */
  429. float latencyVariance() { return _latencyVariance; }
  430. /**
  431. * The ratio of lost packets to received packets.
  432. */
  433. float packetLossRatio() { return _packetLossRatio; }
  434. /**
  435. * The ratio of packets that failed their MAC/CRC checks to those that did not.
  436. */
  437. float packetErrorRatio() { return _packetErrorRatio; }
  438. /**
  439. *
  440. */
  441. uint8_t allocation() { return _allocation; }
  442. private:
  443. volatile int64_t _lastOut;
  444. volatile int64_t _lastIn;
  445. volatile int64_t _lastTrustEstablishedPacketReceived;
  446. int64_t _localSocket;
  447. volatile unsigned int _latency;
  448. InetAddress _addr;
  449. InetAddress::IpScope _ipScope; // memoize this since it's a computed value checked often
  450. AtomicCounter __refCount;
  451. std::map<uint64_t,uint64_t> qosStatsOut; // id:egress_time
  452. std::map<uint64_t,uint64_t> qosStatsIn; // id:now
  453. std::map<uint64_t,uint16_t> ackStatsIn; // id:len
  454. RingBuffer<int,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> qosRecordSize;
  455. RingBuffer<float,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> qosRecordLossSamples;
  456. RingBuffer<uint64_t,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> throughputSamples;
  457. RingBuffer<bool,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> packetValiditySamples;
  458. RingBuffer<float,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> _throughputVarianceSamples;
  459. RingBuffer<uint16_t,ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE> latencySamples;
  460. /**
  461. * Last time that a VERB_ACK was received on this path.
  462. */
  463. uint64_t _lastAckReceived;
  464. /**
  465. * Last time that a VERB_ACK was sent out on this path.
  466. */
  467. uint64_t _lastAckSent;
  468. /**
  469. * Last time that a VERB_QOS_MEASUREMENT was sent out on this path.
  470. */
  471. uint64_t _lastQoSMeasurement;
  472. /**
  473. * Last time that the path's throughput was estimated.
  474. */
  475. uint64_t _lastThroughputEstimation;
  476. /**
  477. * The last time that the refractory period was updated.
  478. */
  479. uint64_t _lastRefractoryUpdate;
  480. /**
  481. * The last time that the path was marked as "alive".
  482. */
  483. uint64_t _lastAliveToggle;
  484. /**
  485. * State of eligibility at last check. Used for determining state changes.
  486. */
  487. bool _lastEligibilityState;
  488. /**
  489. * Timestamp indicating when this path's trial period began.
  490. */
  491. uint64_t _lastTrialBegin;
  492. /**
  493. * Amount of time that this path will be prevented from becoming a member of a bond.
  494. */
  495. uint32_t _refractoryPeriod;
  496. /**
  497. * Monitor interval specific to this path or that was inherited from the bond controller.
  498. */
  499. int32_t _monitorInterval;
  500. /**
  501. * Up delay interval specific to this path or that was inherited from the bond controller.
  502. */
  503. uint32_t _upDelay;
  504. /**
  505. * Down delay interval specific to this path or that was inherited from the bond controller.
  506. */
  507. uint32_t _downDelay;
  508. /**
  509. * IP version preference inherited from the physical link.
  510. */
  511. uint8_t _ipvPref;
  512. /**
  513. * Mode inherited from the physical link.
  514. */
  515. uint8_t _mode;
  516. /**
  517. * IP version preference inherited from the physical link.
  518. */
  519. bool _onlyPathOnLink;
  520. /**
  521. * Enabled state inherited from the physical link.
  522. */
  523. bool _enabled;
  524. /**
  525. * Whether this path is currently part of a bond.
  526. */
  527. bool _bonded;
  528. /**
  529. * Whether this path was intentionally negotiated by either peer.
  530. */
  531. bool _negotiated;
  532. /**
  533. * Whether this path has been deprecated due to performance issues. Current traffic flows
  534. * will be re-allocated to other paths in the most non-disruptive manner (if possible),
  535. * and new traffic will not be allocated to this path.
  536. */
  537. bool _deprecated;
  538. /**
  539. * Whether flows should be moved from this path. Current traffic flows will be re-allocated
  540. * immediately.
  541. */
  542. bool _shouldReallocateFlows;
  543. /**
  544. * The number of flows currently assigned to this path.
  545. */
  546. uint16_t _assignedFlowCount;
  547. /**
  548. * The mean latency (computed from a sliding window.)
  549. */
  550. float _latencyMean;
  551. /**
  552. * Packet delay variance (computed from a sliding window.)
  553. */
  554. float _latencyVariance;
  555. /**
  556. * The ratio of lost packets to received packets.
  557. */
  558. float _packetLossRatio;
  559. /**
  560. * The ratio of packets that failed their MAC/CRC checks to those that did not.
  561. */
  562. float _packetErrorRatio;
  563. /**
  564. * The estimated mean throughput of this path.
  565. */
  566. uint64_t _throughputMean;
  567. /**
  568. * The maximum observed throughput of this path.
  569. */
  570. uint64_t _throughputMax;
  571. /**
  572. * The variance in the estimated throughput of this path.
  573. */
  574. float _throughputVariance;
  575. /**
  576. * The relative quality of this path to all others in the bond, [0-255].
  577. */
  578. uint8_t _allocation;
  579. /**
  580. * How much load this path is under.
  581. */
  582. uint64_t _byteLoad;
  583. /**
  584. * How much load this path is under (relative to other paths in the bond.)
  585. */
  586. uint8_t _relativeByteLoad;
  587. /**
  588. * Relative value expressing how "deserving" this path is of new traffic.
  589. */
  590. uint8_t _affinity;
  591. /**
  592. * Score that indicates to what degree this path is preferred over others that
  593. * are available to the bonding policy. (specifically for active-backup)
  594. */
  595. uint32_t _failoverScore;
  596. /**
  597. * Number of bytes thus far sent that have not been acknowledged by the remote peer.
  598. */
  599. int64_t _unackedBytes;
  600. /**
  601. * Number of packets received since the last VERB_ACK was sent to the remote peer.
  602. */
  603. int32_t _packetsReceivedSinceLastAck;
  604. /**
  605. * Number of packets received since the last VERB_QOS_MEASUREMENT was sent to the remote peer.
  606. */
  607. int32_t _packetsReceivedSinceLastQoS;
  608. /**
  609. * Bytes acknowledged via incoming VERB_ACK since the last estimation of throughput.
  610. */
  611. uint64_t _bytesAckedSinceLastThroughputEstimation;
  612. /**
  613. * Counters used for tracking path load.
  614. */
  615. int _packetsIn;
  616. int _packetsOut;
  617. };
  618. } // namespace ZeroTier
  619. #endif