Merge branch 'dev' of github.com:zerotier/ZeroTierOne into dev

This commit is contained in:
Grant Limberg 2020-11-23 14:54:39 -08:00
commit a1b72f0e1a
No known key found for this signature in database
GPG key ID: 2BA62CCABBB4095A
7 changed files with 401 additions and 55 deletions

View file

@ -233,12 +233,10 @@ void Bond::recordOutgoingPacket(const SharedPtr<Path> &path, const uint64_t pack
}
}
}
if (_allowFlowHashing) {
if (_allowFlowHashing && (flowId != ZT_QOS_NO_FLOW)) {
Mutex::Lock _l(_flows_m);
if (_flows.count(flowId)) {
_flows[flowId]->recordOutgoingBytes(payloadLength);
}
if (_allowFlowHashing && (flowId != ZT_QOS_NO_FLOW)) {
Mutex::Lock _l(_flows_m);
if (_flows.count(flowId)) {
_flows[flowId]->recordOutgoingBytes(payloadLength);
}
}
}
@ -416,6 +414,16 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow> &flow, int64_t now)
return false;
}
}
if (_bondingPolicy == ZT_BONDING_POLICY_ACTIVE_BACKUP) {
if (_abOverflowEnabled) {
flow->assignPath(_abPath, now);
} else {
sprintf(traceMsg, "%s (bond) Unable to assign outgoing flow %x to peer %llx, no active overflow link",
OSUtils::humanReadableTimestamp().c_str(), flow->id(), _peer->_id.address().toInt());
RR->t->bondStateMessage(NULL, traceMsg);
return false;
}
}
flow->assignedPath()->address().toString(curPathStr);
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, flow->assignedPath()->localSocket());
sprintf(traceMsg, "%s (bond) Assigned outgoing flow %x to peer %llx to link %s/%s, %lu active flow(s)",
@ -1164,18 +1172,13 @@ void Bond::processBalanceTasks(const int64_t now)
* Tasks specific to (Balance Round Robin)
*/
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR) {
if (_allowFlowHashing) {
// TODO: Should ideally failover from (idx) to a random link, this is so that (idx+1) isn't overloaded
}
else if (!_allowFlowHashing) {
// Nothing
}
// Nothing
}
/**
* Tasks specific to (Balance XOR)
*/
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_XOR) {
// Nothing specific for XOR
// Nothing
}
/**
* Tasks specific to (Balance Aware)
@ -1247,6 +1250,29 @@ void Bond::dequeueNextActiveBackupPath(const uint64_t now)
}
}
bool Bond::abForciblyRotateLink()
{
char traceMsg[256];
char prevPathStr[128];
char curPathStr[128];
if (_bondingPolicy == ZT_BONDING_POLICY_ACTIVE_BACKUP) {
SharedPtr<Path> prevPath = _abPath;
_abPath->address().toString(prevPathStr);
dequeueNextActiveBackupPath(RR->node->now());
_abPath->address().toString(curPathStr);
sprintf(traceMsg, "%s (active-backup) Forcibly rotating peer %llx link from %s/%s to %s/%s",
OSUtils::humanReadableTimestamp().c_str(),
_peer->_id.address().toInt(),
getLink(prevPath)->ifname().c_str(),
prevPathStr,
getLink(_abPath)->ifname().c_str(),
curPathStr);
RR->t->bondStateMessage(NULL, traceMsg);
return true;
}
return false;
}
void Bond::processActiveBackupTasks(void *tPtr, const int64_t now)
{
char traceMsg[256];
@ -1309,9 +1335,9 @@ void Bond::processActiveBackupTasks(void *tPtr, const int64_t now)
}
}
/**
* [Manual mode]
* The user has specified links or failover rules that the bonding policy should adhere to.
*/
* [Manual mode]
* The user has specified links or failover rules that the bonding policy should adhere to.
*/
else if (userHasSpecifiedLinks()) {
if (userHasSpecifiedPrimaryLink()) {
//sprintf(traceMsg, "%s (active-backup) Checking local.conf for user-specified primary link\n", OSUtils::humanReadableTimestamp().c_str());
@ -1514,7 +1540,7 @@ void Bond::processActiveBackupTasks(void *tPtr, const int64_t now)
if (!bFoundPathInQueue) {
_abFailoverQueue.push_front(_paths[i]);
_paths[i]->address().toString(curPathStr);
sprintf(traceMsg, "%s (active-backup) Added link %s/%s to peer %llx, there are %zu links in the queue",
sprintf(traceMsg, "%s (active-backup) Added link %s/%s to peer %llx to failover queue, there are %zu links in the queue",
OSUtils::humanReadableTimestamp().c_str(), getLink(_paths[i])->ifname().c_str(), curPathStr, _peer->_id.address().toInt(), _abFailoverQueue.size());
RR->t->bondStateMessage(NULL, traceMsg);
}
@ -1754,7 +1780,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
them onto the defaults that were previously set */
if (useTemplate) {
_policyAlias = templateBond->_policyAlias;
_failoverInterval = templateBond->_failoverInterval;
_failoverInterval = templateBond->_failoverInterval >= 250 ? templateBond->_failoverInterval : _failoverInterval;
_downDelay = templateBond->_downDelay;
_upDelay = templateBond->_upDelay;
if (templateBond->_linkMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_PASSIVE

View file

@ -436,6 +436,11 @@ public:
*/
inline void setFailoverInterval(uint32_t interval) { _failoverInterval = interval; }
/**
* @param interval Maximum amount of time user expects a failover to take on this bond.
*/
inline uint32_t getFailoverInterval() { return _failoverInterval; }
/**
* @param strategy Strategy that the bond uses to re-assign protocol flows.
*/
@ -446,6 +451,11 @@ public:
*/
inline void setLinkMonitorStrategy(uint8_t strategy) { _linkMonitorStrategy = strategy; }
/**
* @param abOverflowEnabled Whether "overflow" mode is enabled for this active-backup bond
*/
inline void setOverflowMode(bool abOverflowEnabled) { _abOverflowEnabled = abOverflowEnabled; }
/**
* @return the current up delay parameter
*/
@ -520,6 +530,11 @@ public:
*/
inline void setPacketsPerLink(int packetsPerLink) { _packetsPerLink = packetsPerLink; }
/**
* @return Number of packets to be sent on each interface in a balance-rr bond
*/
inline int getPacketsPerLink() { return _packetsPerLink; }
/**
*
* @param linkSelectMethod
@ -544,6 +559,15 @@ public:
*/
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
*
* @return True if this operation succeeded, false if otherwise
*/
bool abForciblyRotateLink();
SharedPtr<Peer> getPeer() { return _peer; }
private:
const RuntimeEnvironment *RR;
@ -587,6 +611,7 @@ private:
SharedPtr<Path> _abPath; // current active path
std::list<SharedPtr<Path> > _abFailoverQueue;
uint8_t _abLinkSelectMethod; // link re-selection policy for the primary link in active-backup
bool _abOverflowEnabled;
// balance-rr
uint8_t _rrIdx; // index to path currently in use during Round Robin operation

View file

@ -76,6 +76,12 @@ bool BondController::assignBondingPolicyToPeer(int64_t identity, const std::stri
return false;
}
SharedPtr<Bond> BondController::getBondByPeerId(int64_t identity)
{
Mutex::Lock _l(_bonds_m);
return _bonds.count(identity) ? _bonds[identity] : SharedPtr<Bond>();
}
SharedPtr<Bond> BondController::createTransportTriggeredBond(const RuntimeEnvironment *renv, const SharedPtr<Peer>& peer)
{
Mutex::Lock _l(_bonds_m);

View file

@ -127,6 +127,14 @@ public:
*/
bool assignBondingPolicyToPeer(int64_t identity, const std::string& policyAlias);
/**
* Get pointer to bond by a given peer ID
*
* @param peer Remote peer ID
* @return A pointer to the Bond
*/
SharedPtr<Bond> getBondByPeerId(int64_t identity);
/**
* Add a new bond to the bond controller.
*

View file

@ -467,6 +467,32 @@ public:
_packetsOut = 0;
}
/**
* The mean latency (computed from a sliding window.)
*/
float latencyMean() { return _latencyMean; }
/**
* Packet delay variance (computed from a sliding window.)
*/
float latencyVariance() { return _latencyVariance; }
/**
* The ratio of lost packets to received packets.
*/
float packetLossRatio() { return _packetLossRatio; }
/**
* The ratio of packets that failed their MAC/CRC checks to those that did not.
*/
float packetErrorRatio() { return _packetErrorRatio; }
/**
*
*/
uint8_t allocation() { return _allocation; }
private:
volatile int64_t _lastOut;