Bond.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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_BOND_HPP
  14. #define ZT_BOND_HPP
  15. #include <map>
  16. #include "Path.hpp"
  17. #include "Peer.hpp"
  18. #include "../osdep/Link.hpp"
  19. #include "Flow.hpp"
  20. namespace ZeroTier {
  21. class RuntimeEnvironment;
  22. class Link;
  23. class Bond
  24. {
  25. friend class SharedPtr<Bond>;
  26. friend class Peer;
  27. friend class BondController;
  28. struct PathQualityComparator
  29. {
  30. bool operator ()(const SharedPtr<Path> & a, const SharedPtr<Path> & b)
  31. {
  32. if(a->_failoverScore == b->_failoverScore) {
  33. return a < b;
  34. }
  35. return a->_failoverScore > b->_failoverScore;
  36. }
  37. };
  38. public:
  39. // TODO: Remove
  40. bool _header;
  41. int64_t _lastLogTS;
  42. int64_t _lastPrintTS;
  43. void dumpInfo(const int64_t now);
  44. bool relevant();
  45. SharedPtr<Link> getLink(const SharedPtr<Path>& path);
  46. /**
  47. * Constructor. Creates a bond based off of ZT defaults
  48. *
  49. * @param renv Runtime environment
  50. * @param policy Bonding policy
  51. * @param peer
  52. */
  53. Bond(const RuntimeEnvironment *renv, int policy, const SharedPtr<Peer>& peer);
  54. /**
  55. * Constructor. For use when user intends to manually specify parameters
  56. *
  57. * @param basePolicy
  58. * @param policyAlias
  59. * @param peer
  60. */
  61. Bond(const RuntimeEnvironment *renv, std::string& basePolicy, std::string& policyAlias, const SharedPtr<Peer>& peer);
  62. /**
  63. * Constructor. Creates a bond based off of a user-defined bond template
  64. *
  65. * @param renv Runtime environment
  66. * @param original
  67. * @param peer
  68. */
  69. Bond(const RuntimeEnvironment *renv, SharedPtr<Bond> originalBond, const SharedPtr<Peer>& peer);
  70. /**
  71. * @return The human-readable name of the bonding policy
  72. */
  73. std::string policyAlias() { return _policyAlias; }
  74. /**
  75. * Inform the bond about the path that its peer (owning object) just learned about.
  76. * If the path is allowed to be used, it will be inducted into the bond on a trial
  77. * period where link statistics will be collected to judge its quality.
  78. *
  79. * @param path Newly-learned Path which should now be handled by the Bond
  80. * @param now Current time
  81. */
  82. void nominatePath(const SharedPtr<Path>& path, int64_t now);
  83. /**
  84. * Propagate and memoize often-used bonding preferences for each path
  85. */
  86. void applyUserPrefs();
  87. /**
  88. * Check path states and perform bond rebuilds if needed.
  89. *
  90. * @param now Current time
  91. * @param rebuild Whether or not the bond should be reconstructed.
  92. */
  93. void curateBond(const int64_t now, bool rebuild);
  94. /**
  95. * Periodically perform statistical summaries of quality metrics for all paths.
  96. *
  97. * @param now Current time
  98. */
  99. void estimatePathQuality(int64_t now);
  100. /**
  101. * Record an invalid incoming packet. This packet failed
  102. * MAC/compression/cipher checks and will now contribute to a
  103. * Packet Error Ratio (PER).
  104. *
  105. * @param path Path over which packet was received
  106. */
  107. void recordIncomingInvalidPacket(const SharedPtr<Path>& path);
  108. /**
  109. * Record statistics on outbound an packet.
  110. *
  111. * @param path Path over which packet is being sent
  112. * @param packetId Packet ID
  113. * @param payloadLength Packet data length
  114. * @param verb Packet verb
  115. * @param flowId Flow ID
  116. * @param now Current time
  117. */
  118. void recordOutgoingPacket(const SharedPtr<Path> &path, uint64_t packetId,
  119. uint16_t payloadLength, Packet::Verb verb, int32_t flowId, int64_t now);
  120. /**
  121. * Process the contents of an inbound VERB_QOS_MEASUREMENT to gather path quality observations.
  122. *
  123. * @param now Current time
  124. * @param count Number of records
  125. * @param rx_id table of packet IDs
  126. * @param rx_ts table of holding times
  127. */
  128. void receivedQoS(const SharedPtr<Path>& path, int64_t now, int count, uint64_t *rx_id, uint16_t *rx_ts);
  129. /**
  130. * Process the contents of an inbound VERB_ACK to gather path quality observations.
  131. *
  132. * @param path Path over which packet was received
  133. * @param now Current time
  134. * @param ackedBytes Number of bytes ACKed by this VERB_ACK
  135. */
  136. void receivedAck(const SharedPtr<Path>& path, int64_t now, int32_t ackedBytes);
  137. /**
  138. * Generate the contents of a VERB_QOS_MEASUREMENT packet.
  139. *
  140. * @param now Current time
  141. * @param qosBuffer destination buffer
  142. * @return Size of payload
  143. */
  144. int32_t generateQoSPacket(const SharedPtr<Path>& path, int64_t now, char *qosBuffer);
  145. /**
  146. * Record statistics for an inbound packet.
  147. *
  148. * @param path Path over which packet was received
  149. * @param packetId Packet ID
  150. * @param payloadLength Packet data length
  151. * @param verb Packet verb
  152. * @param flowId Flow ID
  153. * @param now Current time
  154. */
  155. void recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId, uint16_t payloadLength,
  156. Packet::Verb verb, int32_t flowId, int64_t now);
  157. /**
  158. * Determines the most appropriate path for packet and flow egress. This decision is made by
  159. * the underlying bonding policy as well as QoS-related statistical observations of path quality.
  160. *
  161. * @param now Current time
  162. * @param flowId Flow ID
  163. * @return Pointer to suggested Path
  164. */
  165. SharedPtr<Path> getAppropriatePath(int64_t now, int32_t flowId);
  166. /**
  167. * Creates a new flow record
  168. *
  169. * @param path Path over which flow shall be handled
  170. * @param flowId Flow ID
  171. * @param entropy A byte of entropy to be used by the bonding algorithm
  172. * @param now Current time
  173. * @return Pointer to newly-created Flow
  174. */
  175. SharedPtr<Flow> createFlow(const SharedPtr<Path> &path, int32_t flowId, unsigned char entropy, int64_t now);
  176. /**
  177. * Removes flow records that are past a certain age limit.
  178. *
  179. * @param age Age threshold to be forgotten
  180. * @param oldest Whether only the oldest shall be forgotten
  181. * @param now Current time
  182. */
  183. void forgetFlowsWhenNecessary(uint64_t age, bool oldest, int64_t now);
  184. /**
  185. * Assigns a new flow to a bonded path
  186. *
  187. * @param flow Flow to be assigned
  188. * @param now Current time
  189. */
  190. bool assignFlowToBondedPath(SharedPtr<Flow> &flow, int64_t now);
  191. /**
  192. * Determine whether a path change should occur given the remote peer's reported utility and our
  193. * local peer's known utility. This has the effect of assigning inbound and outbound traffic to
  194. * the same path.
  195. *
  196. * @param now Current time
  197. * @param path Path over which the negotiation request was received
  198. * @param remoteUtility How much utility the remote peer claims to gain by using the declared path
  199. */
  200. void processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path> &path, int16_t remoteUtility);
  201. /**
  202. * Determine state of path synchronization and whether a negotiation request
  203. * shall be sent to the peer.
  204. *
  205. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  206. * @param now Current time
  207. */
  208. void pathNegotiationCheck(void *tPtr, const int64_t now);
  209. /**
  210. * Sends a VERB_ACK to the remote peer.
  211. *
  212. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  213. * @param path Path over which packet should be sent
  214. * @param localSocket Local source socket
  215. * @param atAddress
  216. * @param now Current time
  217. */
  218. void sendACK(void *tPtr, const SharedPtr<Path> &path,int64_t localSocket,
  219. const InetAddress &atAddress,int64_t now);
  220. /**
  221. * Sends a VERB_QOS_MEASUREMENT to the remote peer.
  222. *
  223. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  224. * @param path Path over which packet should be sent
  225. * @param localSocket Local source socket
  226. * @param atAddress
  227. * @param now Current time
  228. */
  229. void sendQOS_MEASUREMENT(void *tPtr,const SharedPtr<Path> &path,int64_t localSocket,
  230. const InetAddress &atAddress,int64_t now);
  231. /**
  232. * Sends a VERB_PATH_NEGOTIATION_REQUEST to the remote peer.
  233. *
  234. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  235. * @param path Path over which packet should be sent
  236. */
  237. void sendPATH_NEGOTIATION_REQUEST(void *tPtr, const SharedPtr<Path> &path);
  238. /**
  239. *
  240. * @param now Current time
  241. */
  242. void processBalanceTasks(int64_t now);
  243. /**
  244. * Perform periodic tasks unique to active-backup
  245. *
  246. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  247. * @param now Current time
  248. */
  249. void processActiveBackupTasks(void *tPtr, int64_t now);
  250. /**
  251. * Switches the active link in an active-backup scenario to the next best during
  252. * a failover event.
  253. *
  254. * @param now Current time
  255. */
  256. void dequeueNextActiveBackupPath(uint64_t now);
  257. /**
  258. * Set bond parameters to reasonable defaults, these may later be overwritten by
  259. * user-specified parameters.
  260. *
  261. * @param policy Bonding policy
  262. * @param templateBond
  263. */
  264. void setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool useTemplate);
  265. /**
  266. * Check and assign user-specified quality weights to this bond.
  267. *
  268. * @param weights Set of user-specified weights
  269. * @param len Length of weight vector
  270. */
  271. void setUserQualityWeights(float weights[], int len);
  272. /**
  273. * @param latencyInMilliseconds Maximum acceptable latency.
  274. */
  275. void setMaxAcceptableLatency(int16_t latencyInMilliseconds) {
  276. _maxAcceptableLatency = latencyInMilliseconds;
  277. }
  278. /**
  279. * @param latencyInMilliseconds Maximum acceptable (mean) latency.
  280. */
  281. void setMaxAcceptableMeanLatency(int16_t latencyInMilliseconds) {
  282. _maxAcceptableMeanLatency = latencyInMilliseconds;
  283. }
  284. /**
  285. * @param latencyVarianceInMilliseconds Maximum acceptable packet delay variance (jitter).
  286. */
  287. void setMaxAcceptablePacketDelayVariance(int16_t latencyVarianceInMilliseconds) {
  288. _maxAcceptablePacketDelayVariance = latencyVarianceInMilliseconds;
  289. }
  290. /**
  291. * @param lossRatio Maximum acceptable packet loss ratio (PLR).
  292. */
  293. void setMaxAcceptablePacketLossRatio(float lossRatio) {
  294. _maxAcceptablePacketLossRatio = lossRatio;
  295. }
  296. /**
  297. * @param errorRatio Maximum acceptable packet error ratio (PER).
  298. */
  299. void setMaxAcceptablePacketErrorRatio(float errorRatio) {
  300. _maxAcceptablePacketErrorRatio = errorRatio;
  301. }
  302. /**
  303. * @param errorRatio Maximum acceptable packet error ratio (PER).
  304. */
  305. void setMinAcceptableAllocation(float minAlloc) {
  306. _minAcceptableAllocation = minAlloc * 255;
  307. }
  308. /**
  309. * @return Whether the user has defined links for use on this bond
  310. */
  311. inline bool userHasSpecifiedLinks() { return _userHasSpecifiedLinks; }
  312. /**
  313. * @return Whether the user has defined a set of failover link(s) for this bond
  314. */
  315. inline bool userHasSpecifiedFailoverInstructions() { return _userHasSpecifiedFailoverInstructions; };
  316. /**
  317. * @return Whether the user has specified a primary link
  318. */
  319. inline bool userHasSpecifiedPrimaryLink() { return _userHasSpecifiedPrimaryLink; }
  320. /**
  321. * @return Whether the user has specified link speeds
  322. */
  323. inline bool userHasSpecifiedLinkSpeeds() { return _userHasSpecifiedLinkSpeeds; }
  324. /**
  325. * Periodically perform maintenance tasks for each active bond.
  326. *
  327. * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
  328. * @param now Current time
  329. */
  330. void processBackgroundTasks(void *tPtr, int64_t now);
  331. /**
  332. * Rate limit gate for VERB_ACK
  333. *
  334. * @param now Current time
  335. * @return Whether the incoming packet should be rate-gated
  336. */
  337. inline bool rateGateACK(const int64_t now)
  338. {
  339. _ackCutoffCount++;
  340. int numToDrain = _lastAckRateCheck ? (now - _lastAckRateCheck) / ZT_ACK_DRAINAGE_DIVISOR : _ackCutoffCount;
  341. _lastAckRateCheck = now;
  342. if (_ackCutoffCount > numToDrain) {
  343. _ackCutoffCount-=numToDrain;
  344. } else {
  345. _ackCutoffCount = 0;
  346. }
  347. return (_ackCutoffCount < ZT_ACK_CUTOFF_LIMIT);
  348. }
  349. /**
  350. * Rate limit gate for VERB_QOS_MEASUREMENT
  351. *
  352. * @param now Current time
  353. * @return Whether the incoming packet should be rate-gated
  354. */
  355. inline bool rateGateQoS(const int64_t now)
  356. {
  357. _qosCutoffCount++;
  358. int numToDrain = (now - _lastQoSRateCheck) / ZT_QOS_DRAINAGE_DIVISOR;
  359. _lastQoSRateCheck = now;
  360. if (_qosCutoffCount > numToDrain) {
  361. _qosCutoffCount-=numToDrain;
  362. } else {
  363. _qosCutoffCount = 0;
  364. }
  365. return (_qosCutoffCount < ZT_QOS_CUTOFF_LIMIT);
  366. }
  367. /**
  368. * Rate limit gate for VERB_PATH_NEGOTIATION_REQUEST
  369. *
  370. * @param now Current time
  371. * @return Whether the incoming packet should be rate-gated
  372. */
  373. inline bool rateGatePathNegotiation(const int64_t now)
  374. {
  375. if ((now - _lastPathNegotiationReceived) <= ZT_PATH_NEGOTIATION_CUTOFF_TIME)
  376. ++_pathNegotiationCutoffCount;
  377. else _pathNegotiationCutoffCount = 0;
  378. _lastPathNegotiationReceived = now;
  379. return (_pathNegotiationCutoffCount < ZT_PATH_NEGOTIATION_CUTOFF_LIMIT);
  380. }
  381. /**
  382. * @param interval Maximum amount of time user expects a failover to take on this bond.
  383. */
  384. inline void setFailoverInterval(uint32_t interval) { _failoverInterval = interval; }
  385. /**
  386. * @param interval Maximum amount of time user expects a failover to take on this bond.
  387. */
  388. inline uint32_t getFailoverInterval() { return _failoverInterval; }
  389. /**
  390. * @param strategy Strategy that the bond uses to re-assign protocol flows.
  391. */
  392. inline void setFlowRebalanceStrategy(uint32_t strategy) { _flowRebalanceStrategy = strategy; }
  393. /**
  394. * @param strategy Strategy that the bond uses to prob for path aliveness and quality
  395. */
  396. inline void setLinkMonitorStrategy(uint8_t strategy) { _linkMonitorStrategy = strategy; }
  397. /**
  398. * @param abOverflowEnabled Whether "overflow" mode is enabled for this active-backup bond
  399. */
  400. inline void setOverflowMode(bool abOverflowEnabled) { _abOverflowEnabled = abOverflowEnabled; }
  401. /**
  402. * @return the current up delay parameter
  403. */
  404. inline uint16_t getUpDelay() { return _upDelay; }
  405. /**
  406. * @param upDelay Length of time before a newly-discovered path is admitted to the bond
  407. */
  408. inline void setUpDelay(int upDelay) { if (upDelay >= 0) { _upDelay = upDelay; } }
  409. /**
  410. * @return Length of time before a newly-failed path is removed from the bond
  411. */
  412. inline uint16_t getDownDelay() { return _downDelay; }
  413. /**
  414. * @param downDelay Length of time before a newly-failed path is removed from the bond
  415. */
  416. inline void setDownDelay(int downDelay) { if (downDelay >= 0) { _downDelay = downDelay; } }
  417. /**
  418. * @return the current monitoring interval for the bond (can be overridden with intervals specific to certain links.)
  419. */
  420. inline uint16_t getBondMonitorInterval() { return _bondMonitorInterval; }
  421. /**
  422. * Set the current monitoring interval for the bond (can be overridden with intervals specific to certain links.)
  423. *
  424. * @param monitorInterval How often gratuitous VERB_HELLO(s) are sent to remote peer.
  425. */
  426. inline void setBondMonitorInterval(uint16_t interval) { _bondMonitorInterval = interval; }
  427. /**
  428. * @param policy Bonding policy for this bond
  429. */
  430. inline void setPolicy(uint8_t policy) { _bondingPolicy = policy; }
  431. /**
  432. * @return the current bonding policy
  433. */
  434. inline uint8_t getPolicy() { return _bondingPolicy; }
  435. /**
  436. * @return the health status of the bond
  437. */
  438. inline bool isHealthy() { return _isHealthy; }
  439. /**
  440. * @return the number of links comprising this bond which are considered alive
  441. */
  442. inline uint8_t getNumAliveLinks() { return _numAliveLinks; };
  443. /**
  444. * @return the number of links comprising this bond
  445. */
  446. inline uint8_t getNumTotalLinks() { return _numTotalLinks; }
  447. /**
  448. *
  449. * @param allowFlowHashing
  450. */
  451. inline void setFlowHashing(bool allowFlowHashing) { _allowFlowHashing = allowFlowHashing; }
  452. /**
  453. * @return Whether flow-hashing is currently enabled for this bond.
  454. */
  455. bool flowHashingEnabled() { return _allowFlowHashing; }
  456. /**
  457. *
  458. * @param packetsPerLink
  459. */
  460. inline void setPacketsPerLink(int packetsPerLink) { _packetsPerLink = packetsPerLink; }
  461. /**
  462. * @return Number of packets to be sent on each interface in a balance-rr bond
  463. */
  464. inline int getPacketsPerLink() { return _packetsPerLink; }
  465. /**
  466. *
  467. * @param linkSelectMethod
  468. */
  469. inline void setLinkSelectMethod(uint8_t method) { _abLinkSelectMethod = method; }
  470. /**
  471. *
  472. * @return
  473. */
  474. inline uint8_t getLinkSelectMethod() { return _abLinkSelectMethod; }
  475. /**
  476. *
  477. * @param allowPathNegotiation
  478. */
  479. inline void setAllowPathNegotiation(bool allowPathNegotiation) { _allowPathNegotiation = allowPathNegotiation; }
  480. /**
  481. *
  482. * @return
  483. */
  484. inline bool allowPathNegotiation() { return _allowPathNegotiation; }
  485. /**
  486. * Forcibly rotates the currently active link used in an active-backup bond to the next link in the failover queue
  487. *
  488. * @return True if this operation succeeded, false if otherwise
  489. */
  490. bool abForciblyRotateLink();
  491. SharedPtr<Peer> getPeer() { return _peer; }
  492. private:
  493. const RuntimeEnvironment *RR;
  494. AtomicCounter __refCount;
  495. /**
  496. * Custom name given by the user to this bond type.
  497. */
  498. std::string _policyAlias;
  499. /**
  500. * Paths that this bond has been made aware of but that are not necessarily
  501. * part of the bond proper.
  502. */
  503. SharedPtr<Path> _paths[ZT_MAX_PEER_NETWORK_PATHS];
  504. /**
  505. * Set of indices corresponding to paths currently included in the bond proper. This
  506. * may only be updated during a call to curateBond(). The reason for this is so that
  507. * we can simplify the high frequency packet egress logic.
  508. */
  509. int _bondedIdx[ZT_MAX_PEER_NETWORK_PATHS];
  510. /**
  511. * Number of paths currently included in the _bondedIdx set.
  512. */
  513. int _numBondedPaths;
  514. /**
  515. * Flows hashed according to port and protocol
  516. */
  517. std::map<int32_t,SharedPtr<Flow> > _flows;
  518. float _qualityWeights[ZT_QOS_WEIGHT_SIZE]; // How much each factor contributes to the "quality" score of a path.
  519. uint8_t _bondingPolicy;
  520. uint32_t _upDelay;
  521. uint32_t _downDelay;
  522. // active-backup
  523. SharedPtr<Path> _abPath; // current active path
  524. std::list<SharedPtr<Path> > _abFailoverQueue;
  525. uint8_t _abLinkSelectMethod; // link re-selection policy for the primary link in active-backup
  526. bool _abOverflowEnabled;
  527. // balance-rr
  528. uint8_t _rrIdx; // index to path currently in use during Round Robin operation
  529. uint16_t _rrPacketsSentOnCurrLink; // number of packets sent on this link since the most recent path switch.
  530. /**
  531. * How many packets will be sent on a path before moving to the next path
  532. * in the round-robin sequence. A value of zero will cause a random path
  533. * selection for each outgoing packet.
  534. */
  535. int _packetsPerLink;
  536. // balance-aware
  537. uint64_t _totalBondUnderload;
  538. uint8_t _flowRebalanceStrategy;
  539. // dynamic link monitoring
  540. uint8_t _linkMonitorStrategy;
  541. uint32_t _dynamicPathMonitorInterval;
  542. // path negotiation
  543. int16_t _localUtility;
  544. SharedPtr<Path> negotiatedPath;
  545. uint8_t _numSentPathNegotiationRequests;
  546. unsigned int _pathNegotiationCutoffCount;
  547. bool _allowPathNegotiation;
  548. /**
  549. * Timers and intervals
  550. */
  551. uint32_t _failoverInterval;
  552. uint32_t _qosSendInterval;
  553. uint32_t _ackSendInterval;
  554. uint32_t throughputMeasurementInterval;
  555. uint32_t _qualityEstimationInterval;
  556. /**
  557. * Acceptable quality thresholds
  558. */
  559. float _maxAcceptablePacketLossRatio;
  560. float _maxAcceptablePacketErrorRatio;
  561. uint16_t _maxAcceptableLatency;
  562. uint16_t _maxAcceptableMeanLatency;
  563. uint16_t _maxAcceptablePacketDelayVariance;
  564. uint8_t _minAcceptableAllocation;
  565. /**
  566. * Link state reporting
  567. */
  568. bool _isHealthy;
  569. uint8_t _numAliveLinks;
  570. uint8_t _numTotalLinks;
  571. /**
  572. * Default initial punishment inflicted on misbehaving paths. Punishment slowly
  573. * drains linearly. For each eligibility change the remaining punishment is doubled.
  574. */
  575. uint32_t _defaultPathRefractoryPeriod;
  576. /**
  577. * Whether the current bonding policy requires computation of path statistics
  578. */
  579. bool _shouldCollectPathStatistics;
  580. /**
  581. * Free byte of entropy that is updated on every packet egress event.
  582. */
  583. unsigned char _freeRandomByte;
  584. /**
  585. * Remote peer that this bond services
  586. */
  587. SharedPtr<Peer> _peer;
  588. /**
  589. * Rate-limit cutoffs
  590. */
  591. uint16_t _qosCutoffCount;
  592. uint16_t _ackCutoffCount;
  593. /**
  594. * Recent event timestamps
  595. */
  596. uint64_t _lastAckRateCheck;
  597. uint64_t _lastQoSRateCheck;
  598. uint64_t _lastQualityEstimation;
  599. uint64_t _lastCheckUserPreferences;
  600. uint64_t _lastBackgroundTaskCheck;
  601. uint64_t _lastBondStatusLog;
  602. uint64_t _lastPathNegotiationReceived;
  603. uint64_t _lastPathNegotiationCheck;
  604. uint64_t _lastSentPathNegotiationRequest;
  605. uint64_t _lastFlowStatReset;
  606. uint64_t _lastFlowExpirationCheck;
  607. uint64_t _lastFlowRebalance;
  608. uint64_t _lastFrame;
  609. uint64_t _lastActiveBackupPathChange;
  610. Mutex _paths_m;
  611. Mutex _flows_m;
  612. /**
  613. * Whether the user has specified links for this bond.
  614. */
  615. bool _userHasSpecifiedLinks;
  616. /**
  617. * Whether the user has specified a primary link for this bond.
  618. */
  619. bool _userHasSpecifiedPrimaryLink;
  620. /**
  621. * Whether the user has specified failover instructions for this bond.
  622. */
  623. bool _userHasSpecifiedFailoverInstructions;
  624. /**
  625. * Whether the user has specified links speeds for this bond.
  626. */
  627. bool _userHasSpecifiedLinkSpeeds;
  628. /**
  629. * How frequently (in ms) a VERB_ECHO is sent to a peer to verify that a
  630. * path is still active. A value of zero (0) will disable active path
  631. * monitoring; as result, all monitoring will be a function of traffic.
  632. */
  633. uint16_t _bondMonitorInterval;
  634. /**
  635. * Whether or not flow hashing is allowed.
  636. */
  637. bool _allowFlowHashing;
  638. };
  639. } // namespace ZeroTier
  640. #endif