Match formatting of Bond-related sources to ZeroTier standard (no functional changes)

This commit is contained in:
Joseph Henry 2021-05-03 17:59:31 -07:00
parent 63fd2cbaeb
commit 29e5880d8b
No known key found for this signature in database
GPG key ID: C45B33FF5EBC9344
6 changed files with 971 additions and 654 deletions

File diff suppressed because it is too large Load diff

View file

@ -14,37 +14,36 @@
#ifndef ZT_BOND_HPP #ifndef ZT_BOND_HPP
#define ZT_BOND_HPP #define ZT_BOND_HPP
#include <map> #include "Flow.hpp"
#include "Path.hpp" #include "Path.hpp"
#include "Peer.hpp" #include "Peer.hpp"
#include "../osdep/Link.hpp" #include "Packet.hpp"
#include "Flow.hpp"
#include <list>
#include <map>
namespace ZeroTier { namespace ZeroTier {
class RuntimeEnvironment; class RuntimeEnvironment;
class Link; class Link;
class Peer;
class Bond class Bond {
{
friend class SharedPtr<Bond>; friend class SharedPtr<Bond>;
friend class Peer; friend class Peer;
friend class BondController; friend class BondController;
struct PathQualityComparator struct PathQualityComparator {
bool operator()(const SharedPtr<Path>& a, const SharedPtr<Path>& b)
{ {
bool operator ()(const SharedPtr<Path> & a, const SharedPtr<Path> & b) if (a->_failoverScore == b->_failoverScore) {
{
if(a->_failoverScore == b->_failoverScore) {
return a < b; return a < b;
} }
return a->_failoverScore > b->_failoverScore; return a->_failoverScore > b->_failoverScore;
} }
}; };
public: public:
// TODO: Remove // TODO: Remove
bool _header; bool _header;
int64_t _lastLogTS; int64_t _lastLogTS;
@ -61,7 +60,7 @@ public:
* @param policy Bonding policy * @param policy Bonding policy
* @param peer * @param peer
*/ */
Bond(const RuntimeEnvironment *renv, int policy, const SharedPtr<Peer>& peer); Bond(const RuntimeEnvironment* renv, int policy, const SharedPtr<Peer>& peer);
/** /**
* Constructor. For use when user intends to manually specify parameters * Constructor. For use when user intends to manually specify parameters
@ -70,7 +69,7 @@ public:
* @param policyAlias * @param policyAlias
* @param peer * @param peer
*/ */
Bond(const RuntimeEnvironment *renv, std::string& basePolicy, std::string& policyAlias, const SharedPtr<Peer>& peer); Bond(const RuntimeEnvironment* renv, std::string& basePolicy, std::string& policyAlias, const SharedPtr<Peer>& peer);
/** /**
* Constructor. Creates a bond based off of a user-defined bond template * Constructor. Creates a bond based off of a user-defined bond template
@ -79,12 +78,15 @@ public:
* @param original * @param original
* @param peer * @param peer
*/ */
Bond(const RuntimeEnvironment *renv, SharedPtr<Bond> originalBond, const SharedPtr<Peer>& peer); Bond(const RuntimeEnvironment* renv, SharedPtr<Bond> originalBond, const SharedPtr<Peer>& peer);
/** /**
* @return The human-readable name of the bonding policy * @return The human-readable name of the bonding policy
*/ */
std::string policyAlias() { return _policyAlias; } std::string policyAlias()
{
return _policyAlias;
}
/** /**
* Inform the bond about the path that its peer (owning object) just learned about. * Inform the bond about the path that its peer (owning object) just learned about.
@ -135,8 +137,7 @@ public:
* @param flowId Flow ID * @param flowId Flow ID
* @param now Current time * @param now Current time
*/ */
void recordOutgoingPacket(const SharedPtr<Path> &path, uint64_t packetId, void recordOutgoingPacket(const SharedPtr<Path>& path, uint64_t packetId, uint16_t payloadLength, Packet::Verb verb, int32_t flowId, int64_t now);
uint16_t payloadLength, Packet::Verb verb, int32_t flowId, int64_t now);
/** /**
* Process the contents of an inbound VERB_QOS_MEASUREMENT to gather path quality observations. * Process the contents of an inbound VERB_QOS_MEASUREMENT to gather path quality observations.
@ -146,7 +147,7 @@ public:
* @param rx_id table of packet IDs * @param rx_id table of packet IDs
* @param rx_ts table of holding times * @param rx_ts table of holding times
*/ */
void receivedQoS(const SharedPtr<Path>& path, int64_t now, int count, uint64_t *rx_id, uint16_t *rx_ts); void receivedQoS(const SharedPtr<Path>& path, int64_t now, int count, uint64_t* rx_id, uint16_t* rx_ts);
/** /**
* Process the contents of an inbound VERB_ACK to gather path quality observations. * Process the contents of an inbound VERB_ACK to gather path quality observations.
@ -164,7 +165,7 @@ public:
* @param qosBuffer destination buffer * @param qosBuffer destination buffer
* @return Size of payload * @return Size of payload
*/ */
int32_t generateQoSPacket(const SharedPtr<Path>& path, int64_t now, char *qosBuffer); int32_t generateQoSPacket(const SharedPtr<Path>& path, int64_t now, char* qosBuffer);
/** /**
* Record statistics for an inbound packet. * Record statistics for an inbound packet.
@ -176,8 +177,7 @@ public:
* @param flowId Flow ID * @param flowId Flow ID
* @param now Current time * @param now Current time
*/ */
void recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId, uint16_t payloadLength, void recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId, uint16_t payloadLength, Packet::Verb verb, int32_t flowId, int64_t now);
Packet::Verb verb, int32_t flowId, int64_t now);
/** /**
* Determines the most appropriate path for packet and flow egress. This decision is made by * Determines the most appropriate path for packet and flow egress. This decision is made by
@ -198,7 +198,7 @@ public:
* @param now Current time * @param now Current time
* @return Pointer to newly-created Flow * @return Pointer to newly-created Flow
*/ */
SharedPtr<Flow> createFlow(const SharedPtr<Path> &path, int32_t flowId, unsigned char entropy, int64_t now); SharedPtr<Flow> createFlow(const SharedPtr<Path>& path, int32_t flowId, unsigned char entropy, int64_t now);
/** /**
* Removes flow records that are past a certain age limit. * Removes flow records that are past a certain age limit.
@ -215,7 +215,7 @@ public:
* @param flow Flow to be assigned * @param flow Flow to be assigned
* @param now Current time * @param now Current time
*/ */
bool assignFlowToBondedPath(SharedPtr<Flow> &flow, int64_t now); bool assignFlowToBondedPath(SharedPtr<Flow>& flow, int64_t now);
/** /**
* Determine whether a path change should occur given the remote peer's reported utility and our * Determine whether a path change should occur given the remote peer's reported utility and our
@ -226,7 +226,7 @@ public:
* @param path Path over which the negotiation request was received * @param path Path over which the negotiation request was received
* @param remoteUtility How much utility the remote peer claims to gain by using the declared path * @param remoteUtility How much utility the remote peer claims to gain by using the declared path
*/ */
void processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path> &path, int16_t remoteUtility); void processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path>& path, int16_t remoteUtility);
/** /**
* Determine state of path synchronization and whether a negotiation request * Determine state of path synchronization and whether a negotiation request
@ -235,7 +235,7 @@ public:
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
* @param now Current time * @param now Current time
*/ */
void pathNegotiationCheck(void *tPtr, const int64_t now); void pathNegotiationCheck(void* tPtr, const int64_t now);
/** /**
* Sends a VERB_ACK to the remote peer. * Sends a VERB_ACK to the remote peer.
@ -246,8 +246,7 @@ public:
* @param atAddress * @param atAddress
* @param now Current time * @param now Current time
*/ */
void sendACK(void *tPtr, const SharedPtr<Path> &path,int64_t localSocket, void sendACK(void* tPtr, const SharedPtr<Path>& path, int64_t localSocket, const InetAddress& atAddress, int64_t now);
const InetAddress &atAddress,int64_t now);
/** /**
* Sends a VERB_QOS_MEASUREMENT to the remote peer. * Sends a VERB_QOS_MEASUREMENT to the remote peer.
@ -258,8 +257,7 @@ public:
* @param atAddress * @param atAddress
* @param now Current time * @param now Current time
*/ */
void sendQOS_MEASUREMENT(void *tPtr,const SharedPtr<Path> &path,int64_t localSocket, void sendQOS_MEASUREMENT(void* tPtr, const SharedPtr<Path>& path, int64_t localSocket, const InetAddress& atAddress, int64_t now);
const InetAddress &atAddress,int64_t now);
/** /**
* Sends a VERB_PATH_NEGOTIATION_REQUEST to the remote peer. * Sends a VERB_PATH_NEGOTIATION_REQUEST to the remote peer.
@ -267,7 +265,7 @@ public:
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
* @param path Path over which packet should be sent * @param path Path over which packet should be sent
*/ */
void sendPATH_NEGOTIATION_REQUEST(void *tPtr, const SharedPtr<Path> &path); void sendPATH_NEGOTIATION_REQUEST(void* tPtr, const SharedPtr<Path>& path);
/** /**
* *
@ -281,7 +279,7 @@ public:
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
* @param now Current time * @param now Current time
*/ */
void processActiveBackupTasks(void *tPtr, int64_t now); void processActiveBackupTasks(void* tPtr, int64_t now);
/** /**
* Switches the active link in an active-backup scenario to the next best during * Switches the active link in an active-backup scenario to the next best during
@ -311,64 +309,82 @@ public:
/** /**
* @param latencyInMilliseconds Maximum acceptable latency. * @param latencyInMilliseconds Maximum acceptable latency.
*/ */
void setMaxAcceptableLatency(int16_t latencyInMilliseconds) { void setMaxAcceptableLatency(int16_t latencyInMilliseconds)
{
_maxAcceptableLatency = latencyInMilliseconds; _maxAcceptableLatency = latencyInMilliseconds;
} }
/** /**
* @param latencyInMilliseconds Maximum acceptable (mean) latency. * @param latencyInMilliseconds Maximum acceptable (mean) latency.
*/ */
void setMaxAcceptableMeanLatency(int16_t latencyInMilliseconds) { void setMaxAcceptableMeanLatency(int16_t latencyInMilliseconds)
{
_maxAcceptableMeanLatency = latencyInMilliseconds; _maxAcceptableMeanLatency = latencyInMilliseconds;
} }
/** /**
* @param latencyVarianceInMilliseconds Maximum acceptable packet delay variance (jitter). * @param latencyVarianceInMilliseconds Maximum acceptable packet delay variance (jitter).
*/ */
void setMaxAcceptablePacketDelayVariance(int16_t latencyVarianceInMilliseconds) { void setMaxAcceptablePacketDelayVariance(int16_t latencyVarianceInMilliseconds)
{
_maxAcceptablePacketDelayVariance = latencyVarianceInMilliseconds; _maxAcceptablePacketDelayVariance = latencyVarianceInMilliseconds;
} }
/** /**
* @param lossRatio Maximum acceptable packet loss ratio (PLR). * @param lossRatio Maximum acceptable packet loss ratio (PLR).
*/ */
void setMaxAcceptablePacketLossRatio(float lossRatio) { void setMaxAcceptablePacketLossRatio(float lossRatio)
{
_maxAcceptablePacketLossRatio = lossRatio; _maxAcceptablePacketLossRatio = lossRatio;
} }
/** /**
* @param errorRatio Maximum acceptable packet error ratio (PER). * @param errorRatio Maximum acceptable packet error ratio (PER).
*/ */
void setMaxAcceptablePacketErrorRatio(float errorRatio) { void setMaxAcceptablePacketErrorRatio(float errorRatio)
{
_maxAcceptablePacketErrorRatio = errorRatio; _maxAcceptablePacketErrorRatio = errorRatio;
} }
/** /**
* @param errorRatio Maximum acceptable packet error ratio (PER). * @param errorRatio Maximum acceptable packet error ratio (PER).
*/ */
void setMinAcceptableAllocation(float minAlloc) { void setMinAcceptableAllocation(float minAlloc)
{
_minAcceptableAllocation = minAlloc * 255; _minAcceptableAllocation = minAlloc * 255;
} }
/** /**
* @return Whether the user has defined links for use on this bond * @return Whether the user has defined links for use on this bond
*/ */
inline bool userHasSpecifiedLinks() { return _userHasSpecifiedLinks; } inline bool userHasSpecifiedLinks()
{
return _userHasSpecifiedLinks;
}
/** /**
* @return Whether the user has defined a set of failover link(s) for this bond * @return Whether the user has defined a set of failover link(s) for this bond
*/ */
inline bool userHasSpecifiedFailoverInstructions() { return _userHasSpecifiedFailoverInstructions; }; inline bool userHasSpecifiedFailoverInstructions()
{
return _userHasSpecifiedFailoverInstructions;
};
/** /**
* @return Whether the user has specified a primary link * @return Whether the user has specified a primary link
*/ */
inline bool userHasSpecifiedPrimaryLink() { return _userHasSpecifiedPrimaryLink; } inline bool userHasSpecifiedPrimaryLink()
{
return _userHasSpecifiedPrimaryLink;
}
/** /**
* @return Whether the user has specified link speeds * @return Whether the user has specified link speeds
*/ */
inline bool userHasSpecifiedLinkSpeeds() { return _userHasSpecifiedLinkSpeeds; } inline bool userHasSpecifiedLinkSpeeds()
{
return _userHasSpecifiedLinkSpeeds;
}
/** /**
* Periodically perform maintenance tasks for each active bond. * Periodically perform maintenance tasks for each active bond.
@ -376,7 +392,7 @@ public:
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
* @param now Current time * @param now Current time
*/ */
void processBackgroundTasks(void *tPtr, int64_t now); void processBackgroundTasks(void* tPtr, int64_t now);
/** /**
* Rate limit gate for VERB_ACK * Rate limit gate for VERB_ACK
@ -390,8 +406,9 @@ public:
int numToDrain = _lastAckRateCheck ? (now - _lastAckRateCheck) / ZT_ACK_DRAINAGE_DIVISOR : _ackCutoffCount; int numToDrain = _lastAckRateCheck ? (now - _lastAckRateCheck) / ZT_ACK_DRAINAGE_DIVISOR : _ackCutoffCount;
_lastAckRateCheck = now; _lastAckRateCheck = now;
if (_ackCutoffCount > numToDrain) { if (_ackCutoffCount > numToDrain) {
_ackCutoffCount-=numToDrain; _ackCutoffCount -= numToDrain;
} else { }
else {
_ackCutoffCount = 0; _ackCutoffCount = 0;
} }
return (_ackCutoffCount < ZT_ACK_CUTOFF_LIMIT); return (_ackCutoffCount < ZT_ACK_CUTOFF_LIMIT);
@ -409,8 +426,9 @@ public:
int numToDrain = (now - _lastQoSRateCheck) / ZT_QOS_DRAINAGE_DIVISOR; int numToDrain = (now - _lastQoSRateCheck) / ZT_QOS_DRAINAGE_DIVISOR;
_lastQoSRateCheck = now; _lastQoSRateCheck = now;
if (_qosCutoffCount > numToDrain) { if (_qosCutoffCount > numToDrain) {
_qosCutoffCount-=numToDrain; _qosCutoffCount -= numToDrain;
} else { }
else {
_qosCutoffCount = 0; _qosCutoffCount = 0;
} }
return (_qosCutoffCount < ZT_QOS_CUTOFF_LIMIT); return (_qosCutoffCount < ZT_QOS_CUTOFF_LIMIT);
@ -426,7 +444,8 @@ public:
{ {
if ((now - _lastPathNegotiationReceived) <= ZT_PATH_NEGOTIATION_CUTOFF_TIME) if ((now - _lastPathNegotiationReceived) <= ZT_PATH_NEGOTIATION_CUTOFF_TIME)
++_pathNegotiationCutoffCount; ++_pathNegotiationCutoffCount;
else _pathNegotiationCutoffCount = 0; else
_pathNegotiationCutoffCount = 0;
_lastPathNegotiationReceived = now; _lastPathNegotiationReceived = now;
return (_pathNegotiationCutoffCount < ZT_PATH_NEGOTIATION_CUTOFF_LIMIT); return (_pathNegotiationCutoffCount < ZT_PATH_NEGOTIATION_CUTOFF_LIMIT);
} }
@ -434,130 +453,206 @@ public:
/** /**
* @param interval Maximum amount of time user expects a failover to take on this bond. * @param interval Maximum amount of time user expects a failover to take on this bond.
*/ */
inline void setFailoverInterval(uint32_t interval) { _failoverInterval = interval; } inline void setFailoverInterval(uint32_t interval)
{
_failoverInterval = interval;
}
/** /**
* @param interval Maximum amount of time user expects a failover to take on this bond. * @param interval Maximum amount of time user expects a failover to take on this bond.
*/ */
inline uint32_t getFailoverInterval() { return _failoverInterval; } inline uint32_t getFailoverInterval()
{
return _failoverInterval;
}
/** /**
* @param strategy Strategy that the bond uses to re-assign protocol flows. * @param strategy Strategy that the bond uses to re-assign protocol flows.
*/ */
inline void setFlowRebalanceStrategy(uint32_t strategy) { _flowRebalanceStrategy = strategy; } inline void setFlowRebalanceStrategy(uint32_t strategy)
{
_flowRebalanceStrategy = strategy;
}
/** /**
* @param strategy Strategy that the bond uses to prob for path aliveness and quality * @param strategy Strategy that the bond uses to prob for path aliveness and quality
*/ */
inline void setLinkMonitorStrategy(uint8_t strategy) { _linkMonitorStrategy = strategy; } inline void setLinkMonitorStrategy(uint8_t strategy)
{
_linkMonitorStrategy = strategy;
}
/** /**
* @param abOverflowEnabled Whether "overflow" mode is enabled for this active-backup bond * @param abOverflowEnabled Whether "overflow" mode is enabled for this active-backup bond
*/ */
inline void setOverflowMode(bool abOverflowEnabled) { _abOverflowEnabled = abOverflowEnabled; } inline void setOverflowMode(bool abOverflowEnabled)
{
_abOverflowEnabled = abOverflowEnabled;
}
/** /**
* @return the current up delay parameter * @return the current up delay parameter
*/ */
inline uint16_t getUpDelay() { return _upDelay; } inline uint16_t getUpDelay()
{
return _upDelay;
}
/** /**
* @param upDelay Length of time before a newly-discovered path is admitted to the bond * @param upDelay Length of time before a newly-discovered path is admitted to the bond
*/ */
inline void setUpDelay(int upDelay) { if (upDelay >= 0) { _upDelay = upDelay; } } inline void setUpDelay(int upDelay)
{
if (upDelay >= 0) {
_upDelay = upDelay;
}
}
/** /**
* @return Length of time before a newly-failed path is removed from the bond * @return Length of time before a newly-failed path is removed from the bond
*/ */
inline uint16_t getDownDelay() { return _downDelay; } inline uint16_t getDownDelay()
{
return _downDelay;
}
/** /**
* @param downDelay Length of time before a newly-failed path is removed from the bond * @param downDelay Length of time before a newly-failed path is removed from the bond
*/ */
inline void setDownDelay(int downDelay) { if (downDelay >= 0) { _downDelay = downDelay; } } inline void setDownDelay(int downDelay)
{
if (downDelay >= 0) {
_downDelay = downDelay;
}
}
/** /**
* @return the current monitoring interval for the bond (can be overridden with intervals specific to certain links.) * @return the current monitoring interval for the bond (can be overridden with intervals specific to certain links.)
*/ */
inline uint16_t getBondMonitorInterval() { return _bondMonitorInterval; } inline uint16_t getBondMonitorInterval()
{
return _bondMonitorInterval;
}
/** /**
* Set the current monitoring interval for the bond (can be overridden with intervals specific to certain links.) * Set the current monitoring interval for the bond (can be overridden with intervals specific to certain links.)
* *
* @param monitorInterval How often gratuitous VERB_HELLO(s) are sent to remote peer. * @param monitorInterval How often gratuitous VERB_HELLO(s) are sent to remote peer.
*/ */
inline void setBondMonitorInterval(uint16_t interval) { _bondMonitorInterval = interval; } inline void setBondMonitorInterval(uint16_t interval)
{
_bondMonitorInterval = interval;
}
/** /**
* @param policy Bonding policy for this bond * @param policy Bonding policy for this bond
*/ */
inline void setPolicy(uint8_t policy) { _bondingPolicy = policy; } inline void setPolicy(uint8_t policy)
{
_bondingPolicy = policy;
}
/** /**
* @return the current bonding policy * @return the current bonding policy
*/ */
inline uint8_t getPolicy() { return _bondingPolicy; } inline uint8_t getPolicy()
{
return _bondingPolicy;
}
/** /**
* @return the health status of the bond * @return the health status of the bond
*/ */
inline bool isHealthy() { return _isHealthy; } inline bool isHealthy()
{
return _isHealthy;
}
/** /**
* @return the number of links comprising this bond which are considered alive * @return the number of links comprising this bond which are considered alive
*/ */
inline uint8_t getNumAliveLinks() { return _numAliveLinks; }; inline uint8_t getNumAliveLinks()
{
return _numAliveLinks;
};
/** /**
* @return the number of links comprising this bond * @return the number of links comprising this bond
*/ */
inline uint8_t getNumTotalLinks() { return _numTotalLinks; } inline uint8_t getNumTotalLinks()
{
return _numTotalLinks;
}
/** /**
* *
* @param allowFlowHashing * @param allowFlowHashing
*/ */
inline void setFlowHashing(bool allowFlowHashing) { _allowFlowHashing = allowFlowHashing; } inline void setFlowHashing(bool allowFlowHashing)
{
_allowFlowHashing = allowFlowHashing;
}
/** /**
* @return Whether flow-hashing is currently enabled for this bond. * @return Whether flow-hashing is currently enabled for this bond.
*/ */
bool flowHashingEnabled() { return _allowFlowHashing; } bool flowHashingEnabled()
{
return _allowFlowHashing;
}
/** /**
* *
* @param packetsPerLink * @param packetsPerLink
*/ */
inline void setPacketsPerLink(int packetsPerLink) { _packetsPerLink = packetsPerLink; } inline void setPacketsPerLink(int packetsPerLink)
{
_packetsPerLink = packetsPerLink;
}
/** /**
* @return Number of packets to be sent on each interface in a balance-rr bond * @return Number of packets to be sent on each interface in a balance-rr bond
*/ */
inline int getPacketsPerLink() { return _packetsPerLink; } inline int getPacketsPerLink()
{
return _packetsPerLink;
}
/** /**
* *
* @param linkSelectMethod * @param linkSelectMethod
*/ */
inline void setLinkSelectMethod(uint8_t method) { _abLinkSelectMethod = method; } inline void setLinkSelectMethod(uint8_t method)
{
_abLinkSelectMethod = method;
}
/** /**
* *
* @return * @return
*/ */
inline uint8_t getLinkSelectMethod() { return _abLinkSelectMethod; } inline uint8_t getLinkSelectMethod()
{
return _abLinkSelectMethod;
}
/** /**
* *
* @param allowPathNegotiation * @param allowPathNegotiation
*/ */
inline void setAllowPathNegotiation(bool allowPathNegotiation) { _allowPathNegotiation = allowPathNegotiation; } inline void setAllowPathNegotiation(bool allowPathNegotiation)
{
_allowPathNegotiation = allowPathNegotiation;
}
/** /**
* *
* @return * @return
*/ */
inline bool allowPathNegotiation() { return _allowPathNegotiation; } inline bool allowPathNegotiation()
{
return _allowPathNegotiation;
}
/** /**
* Forcibly rotates the currently active link used in an active-backup bond to the next link in the failover queue * Forcibly rotates the currently active link used in an active-backup bond to the next link in the failover queue
@ -566,11 +661,13 @@ public:
*/ */
bool abForciblyRotateLink(); bool abForciblyRotateLink();
SharedPtr<Peer> getPeer() { return _peer; } SharedPtr<Peer> getPeer()
{
return _peer;
}
private: private:
const RuntimeEnvironment* RR;
const RuntimeEnvironment *RR;
AtomicCounter __refCount; AtomicCounter __refCount;
/** /**
@ -599,7 +696,7 @@ private:
/** /**
* Flows hashed according to port and protocol * Flows hashed according to port and protocol
*/ */
std::map<int32_t,SharedPtr<Flow> > _flows; std::map<int32_t, SharedPtr<Flow> > _flows;
float _qualityWeights[ZT_QOS_WEIGHT_SIZE]; // How much each factor contributes to the "quality" score of a path. float _qualityWeights[ZT_QOS_WEIGHT_SIZE]; // How much each factor contributes to the "quality" score of a path.

View file

@ -11,25 +11,25 @@
*/ */
/****/ /****/
#include "../osdep/OSUtils.hpp"
#include "Constants.hpp"
#include "BondController.hpp" #include "BondController.hpp"
#include "Peer.hpp"
#include "../osdep/OSUtils.hpp"
#include "Bond.hpp"
#include "Node.hpp"
#include "RuntimeEnvironment.hpp"
namespace ZeroTier { namespace ZeroTier {
int BondController::_minReqPathMonitorInterval; int BondController::_minReqPathMonitorInterval;
uint8_t BondController::_defaultBondingPolicy; uint8_t BondController::_defaultBondingPolicy;
BondController::BondController(const RuntimeEnvironment *renv) : BondController::BondController(const RuntimeEnvironment* renv) : RR(renv)
RR(renv)
{ {
bondStartTime = RR->node->now(); bondStartTime = RR->node->now();
_defaultBondingPolicy = ZT_BONDING_POLICY_NONE; _defaultBondingPolicy = ZT_BONDING_POLICY_NONE;
} }
bool BondController::linkAllowed(std::string &policyAlias, SharedPtr<Link> link) bool BondController::linkAllowed(std::string& policyAlias, SharedPtr<Link> link)
{ {
bool foundInDefinitions = false; bool foundInDefinitions = false;
if (_linkDefinitions.count(policyAlias)) { if (_linkDefinitions.count(policyAlias)) {
@ -52,14 +52,14 @@ void BondController::addCustomLink(std::string& policyAlias, SharedPtr<Link> lin
auto search = _interfaceToLinkMap[policyAlias].find(link->ifname()); auto search = _interfaceToLinkMap[policyAlias].find(link->ifname());
if (search == _interfaceToLinkMap[policyAlias].end()) { if (search == _interfaceToLinkMap[policyAlias].end()) {
link->setAsUserSpecified(true); link->setAsUserSpecified(true);
_interfaceToLinkMap[policyAlias].insert(std::pair<std::string, SharedPtr<Link>>(link->ifname(), link)); _interfaceToLinkMap[policyAlias].insert(std::pair<std::string, SharedPtr<Link> >(link->ifname(), link));
} }
} }
bool BondController::addCustomPolicy(const SharedPtr<Bond>& newBond) bool BondController::addCustomPolicy(const SharedPtr<Bond>& newBond)
{ {
Mutex::Lock _l(_bonds_m); Mutex::Lock _l(_bonds_m);
if (!_bondPolicyTemplates.count(newBond->policyAlias())) { if (! _bondPolicyTemplates.count(newBond->policyAlias())) {
_bondPolicyTemplates[newBond->policyAlias()] = newBond; _bondPolicyTemplates[newBond->policyAlias()] = newBond;
return true; return true;
} }
@ -69,7 +69,7 @@ bool BondController::addCustomPolicy(const SharedPtr<Bond>& newBond)
bool BondController::assignBondingPolicyToPeer(int64_t identity, const std::string& policyAlias) bool BondController::assignBondingPolicyToPeer(int64_t identity, const std::string& policyAlias)
{ {
Mutex::Lock _l(_bonds_m); Mutex::Lock _l(_bonds_m);
if (!_policyTemplateAssignments.count(identity)) { if (! _policyTemplateAssignments.count(identity)) {
_policyTemplateAssignments[identity] = policyAlias; _policyTemplateAssignments[identity] = policyAlias;
return true; return true;
} }
@ -82,37 +82,40 @@ SharedPtr<Bond> BondController::getBondByPeerId(int64_t identity)
return _bonds.count(identity) ? _bonds[identity] : SharedPtr<Bond>(); return _bonds.count(identity) ? _bonds[identity] : SharedPtr<Bond>();
} }
SharedPtr<Bond> BondController::createTransportTriggeredBond(const RuntimeEnvironment *renv, const SharedPtr<Peer>& peer) SharedPtr<Bond> BondController::createTransportTriggeredBond(const RuntimeEnvironment* renv, const SharedPtr<Peer>& peer)
{ {
Mutex::Lock _l(_bonds_m); Mutex::Lock _l(_bonds_m);
int64_t identity = peer->identity().address().toInt(); int64_t identity = peer->identity().address().toInt();
Bond *bond = nullptr; Bond* bond = nullptr;
char traceMsg[128]; char traceMsg[128];
if (!_bonds.count(identity)) { if (! _bonds.count(identity)) {
std::string policyAlias; std::string policyAlias;
if (!_policyTemplateAssignments.count(identity)) { if (! _policyTemplateAssignments.count(identity)) {
if (_defaultBondingPolicy) { if (_defaultBondingPolicy) {
sprintf(traceMsg, "%s (bond) Creating new default %s bond to peer %llx", sprintf(traceMsg, "%s (bond) Creating new default %s bond to peer %llx", OSUtils::humanReadableTimestamp().c_str(), getPolicyStrByCode(_defaultBondingPolicy).c_str(), (unsigned long long)identity);
OSUtils::humanReadableTimestamp().c_str(), getPolicyStrByCode(_defaultBondingPolicy).c_str(), identity); RR->t->bondStateMessage(NULL, traceMsg); RR->t->bondStateMessage(NULL, traceMsg);
bond = new Bond(renv, _defaultBondingPolicy, peer); bond = new Bond(renv, _defaultBondingPolicy, peer);
} }
if (!_defaultBondingPolicy && _defaultBondingPolicyStr.length()) { if (! _defaultBondingPolicy && _defaultBondingPolicyStr.length()) {
sprintf(traceMsg, "%s (bond) Creating new default custom %s bond to peer %llx", sprintf(traceMsg, "%s (bond) Creating new default custom %s bond to peer %llx", OSUtils::humanReadableTimestamp().c_str(), _defaultBondingPolicyStr.c_str(), (unsigned long long)identity);
OSUtils::humanReadableTimestamp().c_str(), _defaultBondingPolicyStr.c_str(), identity);
RR->t->bondStateMessage(NULL, traceMsg); RR->t->bondStateMessage(NULL, traceMsg);
bond = new Bond(renv, _bondPolicyTemplates[_defaultBondingPolicyStr].ptr(), peer); bond = new Bond(renv, _bondPolicyTemplates[_defaultBondingPolicyStr].ptr(), peer);
} }
} }
else { else {
if (!_bondPolicyTemplates[_policyTemplateAssignments[identity]]) { if (! _bondPolicyTemplates[_policyTemplateAssignments[identity]]) {
sprintf(traceMsg, "%s (bond) Creating new bond. Assignment for peer %llx was specified as %s but the bond definition was not found. Using default %s", sprintf(
OSUtils::humanReadableTimestamp().c_str(), identity, _policyTemplateAssignments[identity].c_str(), getPolicyStrByCode(_defaultBondingPolicy).c_str()); traceMsg,
"%s (bond) Creating new bond. Assignment for peer %llx was specified as %s but the bond definition was not found. Using default %s",
OSUtils::humanReadableTimestamp().c_str(),
(unsigned long long)identity,
_policyTemplateAssignments[identity].c_str(),
getPolicyStrByCode(_defaultBondingPolicy).c_str());
RR->t->bondStateMessage(NULL, traceMsg); RR->t->bondStateMessage(NULL, traceMsg);
bond = new Bond(renv, _defaultBondingPolicy, peer); bond = new Bond(renv, _defaultBondingPolicy, peer);
} }
else { else {
sprintf(traceMsg, "%s (bond) Creating new default bond %s to peer %llx", sprintf(traceMsg, "%s (bond) Creating new default bond %s to peer %llx", OSUtils::humanReadableTimestamp().c_str(), _defaultBondingPolicyStr.c_str(), (unsigned long long)identity);
OSUtils::humanReadableTimestamp().c_str(), _defaultBondingPolicyStr.c_str(), identity);
RR->t->bondStateMessage(NULL, traceMsg); RR->t->bondStateMessage(NULL, traceMsg);
bond = new Bond(renv, _bondPolicyTemplates[_policyTemplateAssignments[identity]].ptr(), peer); bond = new Bond(renv, _bondPolicyTemplates[_policyTemplateAssignments[identity]].ptr(), peer);
} }
@ -150,12 +153,12 @@ SharedPtr<Link> BondController::getLinkBySocket(const std::string& policyAlias,
{ {
Mutex::Lock _l(_links_m); Mutex::Lock _l(_links_m);
char ifname[16]; char ifname[16];
_phy->getIfName((PhySocket *) ((uintptr_t)localSocket), ifname, 16); _phy->getIfName((PhySocket*)((uintptr_t)localSocket), ifname, 16);
std::string ifnameStr(ifname); std::string ifnameStr(ifname);
auto search = _interfaceToLinkMap[policyAlias].find(ifnameStr); auto search = _interfaceToLinkMap[policyAlias].find(ifnameStr);
if (search == _interfaceToLinkMap[policyAlias].end()) { if (search == _interfaceToLinkMap[policyAlias].end()) {
SharedPtr<Link> s = new Link(ifnameStr, 0, 0, 0, 0, 0, true, ZT_MULTIPATH_SLAVE_MODE_SPARE, "", 0.0); SharedPtr<Link> s = new Link(ifnameStr, 0, 0, 0, 0, 0, true, ZT_MULTIPATH_SLAVE_MODE_SPARE, "", 0.0);
_interfaceToLinkMap[policyAlias].insert(std::pair<std::string,SharedPtr<Link> >(ifnameStr, s)); _interfaceToLinkMap[policyAlias].insert(std::pair<std::string, SharedPtr<Link> >(ifnameStr, s));
return s; return s;
} }
else { else {
@ -199,10 +202,10 @@ bool BondController::allowedToBind(const std::string& ifname)
*/ */
} }
void BondController::processBackgroundTasks(void *tPtr, const int64_t now) void BondController::processBackgroundTasks(void* tPtr, const int64_t now)
{ {
Mutex::Lock _l(_bonds_m); Mutex::Lock _l(_bonds_m);
std::map<int64_t,SharedPtr<Bond> >::iterator bondItr = _bonds.begin(); std::map<int64_t, SharedPtr<Bond> >::iterator bondItr = _bonds.begin();
while (bondItr != _bonds.end()) { while (bondItr != _bonds.end()) {
bondItr->second->processBackgroundTasks(tPtr, now); bondItr->second->processBackgroundTasks(tPtr, now);
++bondItr; ++bondItr;

View file

@ -14,46 +14,54 @@
#ifndef ZT_BONDCONTROLLER_HPP #ifndef ZT_BONDCONTROLLER_HPP
#define ZT_BONDCONTROLLER_HPP #define ZT_BONDCONTROLLER_HPP
#include "../osdep/Link.hpp"
#include "../osdep/Phy.hpp"
#include "SharedPtr.hpp"
#include <map> #include <map>
#include <vector> #include <vector>
#include "SharedPtr.hpp"
#include "../osdep/Phy.hpp"
#include "../osdep/Link.hpp"
namespace ZeroTier { namespace ZeroTier {
class RuntimeEnvironment; class RuntimeEnvironment;
class Bond; class Bond;
class Peer; class Peer;
class Mutex;
class BondController class BondController {
{
friend class Bond; friend class Bond;
public: public:
BondController(const RuntimeEnvironment* renv);
BondController(const RuntimeEnvironment *renv);
/** /**
* @return Whether this link is permitted to become a member of a bond. * @return Whether this link is permitted to become a member of a bond.
*/ */
bool linkAllowed(std::string &policyAlias, SharedPtr<Link> link); bool linkAllowed(std::string& policyAlias, SharedPtr<Link> link);
/** /**
* @return The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements. * @return The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements.
*/ */
int minReqPathMonitorInterval() { return _minReqPathMonitorInterval; } int minReqPathMonitorInterval()
{
return _minReqPathMonitorInterval;
}
/** /**
* @param minReqPathMonitorInterval The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements. * @param minReqPathMonitorInterval The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements.
*/ */
static void setMinReqPathMonitorInterval(int minReqPathMonitorInterval) { _minReqPathMonitorInterval = minReqPathMonitorInterval; } static void setMinReqPathMonitorInterval(int minReqPathMonitorInterval)
{
_minReqPathMonitorInterval = minReqPathMonitorInterval;
}
/** /**
* @return Whether the bonding layer is currently set up to be used. * @return Whether the bonding layer is currently set up to be used.
*/ */
bool inUse() { return !_bondPolicyTemplates.empty() || _defaultBondingPolicy; } bool inUse()
{
return ! _bondPolicyTemplates.empty() || _defaultBondingPolicy;
}
/** /**
* @param basePolicyName Bonding policy name (See ZeroTierOne.h) * @param basePolicyName Bonding policy name (See ZeroTierOne.h)
@ -61,11 +69,21 @@ public:
*/ */
static int getPolicyCodeByStr(const std::string& basePolicyName) static int getPolicyCodeByStr(const std::string& basePolicyName)
{ {
if (basePolicyName == "active-backup") { return 1; } if (basePolicyName == "active-backup") {
if (basePolicyName == "broadcast") { return 2; } return 1;
if (basePolicyName == "balance-rr") { return 3; } }
if (basePolicyName == "balance-xor") { return 4; } if (basePolicyName == "broadcast") {
if (basePolicyName == "balance-aware") { return 5; } return 2;
}
if (basePolicyName == "balance-rr") {
return 3;
}
if (basePolicyName == "balance-xor") {
return 4;
}
if (basePolicyName == "balance-aware") {
return 5;
}
return 0; // "none" return 0; // "none"
} }
@ -75,11 +93,21 @@ public:
*/ */
static std::string getPolicyStrByCode(int policy) static std::string getPolicyStrByCode(int policy)
{ {
if (policy == 1) { return "active-backup"; } if (policy == 1) {
if (policy == 2) { return "broadcast"; } return "active-backup";
if (policy == 3) { return "balance-rr"; } }
if (policy == 4) { return "balance-xor"; } if (policy == 2) {
if (policy == 5) { return "balance-aware"; } return "broadcast";
}
if (policy == 3) {
return "balance-rr";
}
if (policy == 4) {
return "balance-xor";
}
if (policy == 5) {
return "balance-aware";
}
return "none"; return "none";
} }
@ -88,19 +116,28 @@ public:
* *
* @param bp Bonding policy * @param bp Bonding policy
*/ */
void setBondingLayerDefaultPolicy(uint8_t bp) { _defaultBondingPolicy = bp; } void setBondingLayerDefaultPolicy(uint8_t bp)
{
_defaultBondingPolicy = bp;
}
/** /**
* Sets the default (custom) bonding policy for new or undefined bonds. * Sets the default (custom) bonding policy for new or undefined bonds.
* *
* @param alias Human-readable string alias for bonding policy * @param alias Human-readable string alias for bonding policy
*/ */
void setBondingLayerDefaultPolicyStr(std::string alias) { _defaultBondingPolicyStr = alias; } void setBondingLayerDefaultPolicyStr(std::string alias)
{
_defaultBondingPolicyStr = alias;
}
/** /**
* @return The default bonding policy * @return The default bonding policy
*/ */
static int defaultBondingPolicy() { return _defaultBondingPolicy; } static int defaultBondingPolicy()
{
return _defaultBondingPolicy;
}
/** /**
* Add a user-defined link to a given bonding policy. * Add a user-defined link to a given bonding policy.
@ -142,7 +179,7 @@ public:
* @param peer Remote peer that this bond services * @param peer Remote peer that this bond services
* @return A pointer to the newly created Bond * @return A pointer to the newly created Bond
*/ */
SharedPtr<Bond> createTransportTriggeredBond(const RuntimeEnvironment *renv, const SharedPtr<Peer>& peer); SharedPtr<Bond> createTransportTriggeredBond(const RuntimeEnvironment* renv, const SharedPtr<Peer>& peer);
/** /**
* Periodically perform maintenance tasks for the bonding layer. * Periodically perform maintenance tasks for the bonding layer.
@ -150,7 +187,7 @@ public:
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call * @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
* @param now Current time * @param now Current time
*/ */
void processBackgroundTasks(void *tPtr, int64_t now); void processBackgroundTasks(void* tPtr, int64_t now);
/** /**
* Gets a reference to a physical link definition given a policy alias and a local socket. * Gets a reference to a physical link definition given a policy alias and a local socket.
@ -175,12 +212,14 @@ public:
*/ */
bool allowedToBind(const std::string& ifname); bool allowedToBind(const std::string& ifname);
uint64_t getBondStartTime() { return bondStartTime; } uint64_t getBondStartTime()
{
return bondStartTime;
}
private: private:
Phy<BondController*>* _phy;
Phy<BondController *> *_phy; const RuntimeEnvironment* RR;
const RuntimeEnvironment *RR;
Mutex _bonds_m; Mutex _bonds_m;
Mutex _links_m; Mutex _links_m;
@ -208,22 +247,22 @@ private:
/** /**
* All currently active bonds. * All currently active bonds.
*/ */
std::map<int64_t,SharedPtr<Bond> > _bonds; std::map<int64_t, SharedPtr<Bond> > _bonds;
/** /**
* Map of peers to custom bonding policies * Map of peers to custom bonding policies
*/ */
std::map<int64_t,std::string> _policyTemplateAssignments; std::map<int64_t, std::string> _policyTemplateAssignments;
/** /**
* User-defined bonding policies (can be assigned to a peer) * User-defined bonding policies (can be assigned to a peer)
*/ */
std::map<std::string,SharedPtr<Bond> > _bondPolicyTemplates; std::map<std::string, SharedPtr<Bond> > _bondPolicyTemplates;
/** /**
* Set of links defined for a given bonding policy * Set of links defined for a given bonding policy
*/ */
std::map<std::string,std::vector<SharedPtr<Link> > > _linkDefinitions; std::map<std::string, std::vector<SharedPtr<Link> > > _linkDefinitions;
/** /**
* Set of link objects mapped to their physical interfaces * Set of link objects mapped to their physical interfaces

View file

@ -22,20 +22,14 @@ namespace ZeroTier {
/** /**
* A protocol flow that is identified by the origin and destination port. * A protocol flow that is identified by the origin and destination port.
*/ */
struct Flow struct Flow {
{
/** /**
* @param flowId Given flow ID * @param flowId Given flow ID
* @param now Current time * @param now Current time
*/ */
Flow(int32_t flowId, int64_t now) : Flow(int32_t flowId, int64_t now) : _flowId(flowId), _bytesInPerUnitTime(0), _bytesOutPerUnitTime(0), _lastActivity(now), _lastPathReassignment(0), _assignedPath(SharedPtr<Path>())
_flowId(flowId), {
_bytesInPerUnitTime(0), }
_bytesOutPerUnitTime(0),
_lastActivity(now),
_lastPathReassignment(0),
_assignedPath(SharedPtr<Path>())
{}
/** /**
* Reset flow statistics * Reset flow statistics
@ -49,36 +43,54 @@ struct Flow
/** /**
* @return The Flow's ID * @return The Flow's ID
*/ */
int32_t id() { return _flowId; } int32_t id()
{
return _flowId;
}
/** /**
* @return Number of incoming bytes processed on this flow per unit time * @return Number of incoming bytes processed on this flow per unit time
*/ */
int64_t bytesInPerUnitTime() { return _bytesInPerUnitTime; } int64_t bytesInPerUnitTime()
{
return _bytesInPerUnitTime;
}
/** /**
* Record number of incoming bytes on this flow * Record number of incoming bytes on this flow
* *
* @param bytes Number of incoming bytes * @param bytes Number of incoming bytes
*/ */
void recordIncomingBytes(uint64_t bytes) { _bytesInPerUnitTime += bytes; } void recordIncomingBytes(uint64_t bytes)
{
_bytesInPerUnitTime += bytes;
}
/** /**
* @return Number of outgoing bytes processed on this flow per unit time * @return Number of outgoing bytes processed on this flow per unit time
*/ */
int64_t bytesOutPerUnitTime() { return _bytesOutPerUnitTime; } int64_t bytesOutPerUnitTime()
{
return _bytesOutPerUnitTime;
}
/** /**
* Record number of outgoing bytes on this flow * Record number of outgoing bytes on this flow
* *
* @param bytes * @param bytes
*/ */
void recordOutgoingBytes(uint64_t bytes) { _bytesOutPerUnitTime += bytes; } void recordOutgoingBytes(uint64_t bytes)
{
_bytesOutPerUnitTime += bytes;
}
/** /**
* @return The total number of bytes processed on this flow * @return The total number of bytes processed on this flow
*/ */
uint64_t totalBytes() { return _bytesInPerUnitTime + _bytesOutPerUnitTime; } uint64_t totalBytes()
{
return _bytesInPerUnitTime + _bytesOutPerUnitTime;
}
/** /**
* How long since a packet was sent or received in this flow * How long since a packet was sent or received in this flow
@ -86,24 +98,34 @@ struct Flow
* @param now Current time * @param now Current time
* @return The age of the flow in terms of last recorded activity * @return The age of the flow in terms of last recorded activity
*/ */
int64_t age(int64_t now) { return now - _lastActivity; } int64_t age(int64_t now)
{
return now - _lastActivity;
}
/** /**
* Record that traffic was processed on this flow at the given time. * Record that traffic was processed on this flow at the given time.
* *
* @param now Current time * @param now Current time
*/ */
void updateActivity(int64_t now) { _lastActivity = now; } void updateActivity(int64_t now)
{
_lastActivity = now;
}
/** /**
* @return Path assigned to this flow * @return Path assigned to this flow
*/ */
SharedPtr<Path> assignedPath() { return _assignedPath; } SharedPtr<Path> assignedPath()
{
return _assignedPath;
}
/** /**
* @param path Assigned path over which this flow should be handled * @param path Assigned path over which this flow should be handled
*/ */
void assignPath(const SharedPtr<Path> &path, int64_t now) { void assignPath(const SharedPtr<Path>& path, int64_t now)
{
_assignedPath = path; _assignedPath = path;
_lastPathReassignment = now; _lastPathReassignment = now;
} }

View file

@ -14,19 +14,20 @@
#ifndef ZT_LINK_HPP #ifndef ZT_LINK_HPP
#define ZT_LINK_HPP #define ZT_LINK_HPP
#include <string>
#include "../node/AtomicCounter.hpp" #include "../node/AtomicCounter.hpp"
#include "../node/SharedPtr.hpp"
#include <string>
namespace ZeroTier { namespace ZeroTier {
class Link class Link {
{
friend class SharedPtr<Link>; friend class SharedPtr<Link>;
public: public:
Link()
Link() {} {
}
/** /**
* *
@ -38,123 +39,165 @@ public:
* @param failoverToLinkStr * @param failoverToLinkStr
* @param userSpecifiedAlloc * @param userSpecifiedAlloc
*/ */
Link(std::string& ifnameStr, Link(std::string& ifnameStr, uint8_t ipvPref, uint32_t speed, uint32_t linkMonitorInterval, uint32_t upDelay, uint32_t downDelay, bool enabled, uint8_t mode, std::string failoverToLinkStr, float userSpecifiedAlloc)
uint8_t ipvPref, : _ifnameStr(ifnameStr)
uint32_t speed, , _ipvPref(ipvPref)
uint32_t linkMonitorInterval, , _speed(speed)
uint32_t upDelay, , _relativeSpeed(0)
uint32_t downDelay, , _linkMonitorInterval(linkMonitorInterval)
bool enabled, , _upDelay(upDelay)
uint8_t mode, , _downDelay(downDelay)
std::string failoverToLinkStr, , _enabled(enabled)
float userSpecifiedAlloc) : , _mode(mode)
_ifnameStr(ifnameStr), , _failoverToLinkStr(failoverToLinkStr)
_ipvPref(ipvPref), , _userSpecifiedAlloc(userSpecifiedAlloc)
_speed(speed), , _isUserSpecified(false)
_relativeSpeed(0), {
_linkMonitorInterval(linkMonitorInterval), }
_upDelay(upDelay),
_downDelay(downDelay),
_enabled(enabled),
_mode(mode),
_failoverToLinkStr(failoverToLinkStr),
_userSpecifiedAlloc(userSpecifiedAlloc),
_isUserSpecified(false)
{}
/** /**
* @return The string representation of this link's underlying interface's system name. * @return The string representation of this link's underlying interface's system name.
*/ */
inline std::string ifname() { return _ifnameStr; } inline std::string ifname()
{
return _ifnameStr;
}
/** /**
* @return Whether this link is designated as a primary. * @return Whether this link is designated as a primary.
*/ */
inline bool primary() { return _mode == ZT_MULTIPATH_SLAVE_MODE_PRIMARY; } inline bool primary()
{
return _mode == ZT_MULTIPATH_SLAVE_MODE_PRIMARY;
}
/** /**
* @return Whether this link is designated as a spare. * @return Whether this link is designated as a spare.
*/ */
inline bool spare() { return _mode == ZT_MULTIPATH_SLAVE_MODE_SPARE; } inline bool spare()
{
return _mode == ZT_MULTIPATH_SLAVE_MODE_SPARE;
}
/** /**
* @return The name of the link interface that should be used in the event of a failure. * @return The name of the link interface that should be used in the event of a failure.
*/ */
inline std::string failoverToLink() { return _failoverToLinkStr; } inline std::string failoverToLink()
{
return _failoverToLinkStr;
}
/** /**
* @return Whether this link interface was specified by the user or auto-detected. * @return Whether this link interface was specified by the user or auto-detected.
*/ */
inline bool isUserSpecified() { return _isUserSpecified; } inline bool isUserSpecified()
{
return _isUserSpecified;
}
/** /**
* Signify that this link was specified by the user and not the result of auto-detection. * Signify that this link was specified by the user and not the result of auto-detection.
* *
* @param isUserSpecified * @param isUserSpecified
*/ */
inline void setAsUserSpecified(bool isUserSpecified) { _isUserSpecified = isUserSpecified; } inline void setAsUserSpecified(bool isUserSpecified)
{
_isUserSpecified = isUserSpecified;
}
/** /**
* @return Whether or not the user has specified failover instructions. * @return Whether or not the user has specified failover instructions.
*/ */
inline bool userHasSpecifiedFailoverInstructions() { return _failoverToLinkStr.length(); } inline bool userHasSpecifiedFailoverInstructions()
{
return _failoverToLinkStr.length();
}
/** /**
* @return The speed of the link relative to others in the bond. * @return The speed of the link relative to others in the bond.
*/ */
inline uint8_t relativeSpeed() { return _relativeSpeed; } inline uint8_t relativeSpeed()
{
return _relativeSpeed;
}
/** /**
* Sets the speed of the link relative to others in the bond. * Sets the speed of the link relative to others in the bond.
* *
* @param relativeSpeed The speed relative to the rest of the link. * @param relativeSpeed The speed relative to the rest of the link.
*/ */
inline void setRelativeSpeed(uint8_t relativeSpeed) { _relativeSpeed = relativeSpeed; } inline void setRelativeSpeed(uint8_t relativeSpeed)
{
_relativeSpeed = relativeSpeed;
}
/** /**
* Sets the speed of the link relative to others in the bond. * Sets the speed of the link relative to others in the bond.
* *
* @param relativeSpeed * @param relativeSpeed
*/ */
inline void setMonitorInterval(uint32_t interval) { _linkMonitorInterval = interval; } inline void setMonitorInterval(uint32_t interval)
{
_linkMonitorInterval = interval;
}
/** /**
* @return The absolute speed of the link (as specified by the user.) * @return The absolute speed of the link (as specified by the user.)
*/ */
inline uint32_t monitorInterval() { return _linkMonitorInterval; } inline uint32_t monitorInterval()
{
return _linkMonitorInterval;
}
/** /**
* @return The absolute speed of the link (as specified by the user.) * @return The absolute speed of the link (as specified by the user.)
*/ */
inline uint32_t speed() { return _speed; } inline uint32_t speed()
{
return _speed;
}
/** /**
* @return The address preference for this link (as specified by the user.) * @return The address preference for this link (as specified by the user.)
*/ */
inline uint8_t ipvPref() { return _ipvPref; } inline uint8_t ipvPref()
{
return _ipvPref;
}
/** /**
* @return The mode (e.g. primary/spare) for this link (as specified by the user.) * @return The mode (e.g. primary/spare) for this link (as specified by the user.)
*/ */
inline uint8_t mode() { return _mode; } inline uint8_t mode()
{
return _mode;
}
/** /**
* @return The upDelay parameter for all paths on this link. * @return The upDelay parameter for all paths on this link.
*/ */
inline uint32_t upDelay() { return _upDelay; } inline uint32_t upDelay()
{
return _upDelay;
}
/** /**
* @return The downDelay parameter for all paths on this link. * @return The downDelay parameter for all paths on this link.
*/ */
inline uint32_t downDelay() { return _downDelay; } inline uint32_t downDelay()
{
return _downDelay;
}
/** /**
* @return Whether this link is enabled or disabled * @return Whether this link is enabled or disabled
*/ */
inline uint8_t enabled() { return _enabled; } inline uint8_t enabled()
{
private: return _enabled;
}
private:
/** /**
* String representation of underlying interface's system name * String representation of underlying interface's system name
*/ */