Skip to content

Commit fb8cbb6

Browse files
Merge pull request zerotier#2354 from zerotier/jh-misc-multipath-patches
Multipath improvements
2 parents 763caae + bf7dddb commit fb8cbb6

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

node/Bond.cpp

+26-15
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ SharedPtr<Path> Bond::getAppropriatePath(int64_t now, int32_t flowId)
373373
*/
374374
if (_policy == ZT_BOND_POLICY_ACTIVE_BACKUP) {
375375
if (_abPathIdx != ZT_MAX_PEER_NETWORK_PATHS && _paths[_abPathIdx].p) {
376+
//fprintf(stderr, "trying to send via (_abPathIdx=%d) %s\n", _abPathIdx, pathToStr(_paths[_abPathIdx].p).c_str());
376377
return _paths[_abPathIdx].p;
377378
}
378379
}
@@ -1032,6 +1033,13 @@ void Bond::curateBond(int64_t now, bool rebuildBond)
10321033
bool satisfiedUpDelay = (now - _paths[i].lastAliveToggle) >= _upDelay;
10331034
// How long since the last QoS was received (Must be less than ZT_PEER_PATH_EXPIRATION since the remote peer's _qosSendInterval isn't known)
10341035
bool acceptableQoSAge = (_paths[i].lastQoSReceived == 0 && inTrial) || ((now - _paths[i].lastQoSReceived) < ZT_PEER_EXPIRED_PATH_TRIAL_PERIOD);
1036+
1037+
// Allow active-backup to operate without the receipt of QoS records
1038+
// This may be expanded to the other modes as an option
1039+
if (_policy == ZT_BOND_POLICY_ACTIVE_BACKUP) {
1040+
acceptableQoSAge = true;
1041+
}
1042+
10351043
currEligibility = _paths[i].allowed() && ((acceptableAge && satisfiedUpDelay && acceptableQoSAge) || inTrial);
10361044

10371045
if (currEligibility) {
@@ -1043,12 +1051,11 @@ void Bond::curateBond(int64_t now, bool rebuildBond)
10431051
*/
10441052
if (currEligibility != _paths[i].eligible) {
10451053
if (currEligibility == 0) {
1046-
log("link %s is no longer eligible", pathToStr(_paths[i].p).c_str());
1054+
log("link %s is no longer eligible (reason: allowed=%d, age=%d, ud=%d, qos=%d, trial=%d)", pathToStr(_paths[i].p).c_str(), _paths[i].allowed(), acceptableAge, satisfiedUpDelay, acceptableQoSAge, inTrial);
10471055
}
10481056
if (currEligibility == 1) {
10491057
log("link %s is eligible", pathToStr(_paths[i].p).c_str());
10501058
}
1051-
debug("\t[%d] allowed=%d, age=%d, qa=%d, ud=%d, trial=%d", i, _paths[i].allowed(), acceptableAge, acceptableQoSAge, satisfiedUpDelay, inTrial);
10521059
dumpPathStatus(now, i);
10531060
if (currEligibility) {
10541061
rebuildBond = true;
@@ -1496,7 +1503,8 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
14961503
{
14971504
int prevActiveBackupPathIdx = _abPathIdx;
14981505
int nonPreferredPathIdx = ZT_MAX_PEER_NETWORK_PATHS;
1499-
bool bFoundPrimaryLink = false;
1506+
bool foundPathOnPrimaryLink = false;
1507+
bool foundPreferredPath = false;
15001508

15011509
if (_abPathIdx != ZT_MAX_PEER_NETWORK_PATHS && ! _paths[_abPathIdx].p) {
15021510
_abPathIdx = ZT_MAX_PEER_NETWORK_PATHS;
@@ -1559,24 +1567,25 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
15591567
if (! _paths[i].preferred()) {
15601568
// Found path on primary link, take note in case we don't find a preferred path
15611569
nonPreferredPathIdx = i;
1562-
bFoundPrimaryLink = true;
1570+
foundPathOnPrimaryLink = true;
15631571
}
15641572
if (_paths[i].preferred()) {
15651573
_abPathIdx = i;
1566-
bFoundPrimaryLink = true;
1574+
foundPathOnPrimaryLink = true;
15671575
if (_paths[_abPathIdx].p) {
15681576
SharedPtr<Link> abLink = RR->bc->getLinkBySocket(_policyAlias, _paths[_abPathIdx].p->localSocket());
15691577
if (abLink) {
1570-
log("found preferred primary link %s", pathToStr(_paths[_abPathIdx].p).c_str());
1578+
log("found preferred primary link (_abPathIdx=%d), %s", _abPathIdx, pathToStr(_paths[_abPathIdx].p).c_str());
1579+
foundPreferredPath = true;
15711580
}
15721581
break; // Found preferred path on primary link
15731582
}
15741583
}
15751584
}
15761585
}
15771586
}
1578-
if (bFoundPrimaryLink && (nonPreferredPathIdx != ZT_MAX_PEER_NETWORK_PATHS)) {
1579-
log("found non-preferred primary link");
1587+
if (!foundPreferredPath && foundPathOnPrimaryLink && (nonPreferredPathIdx != ZT_MAX_PEER_NETWORK_PATHS)) {
1588+
log("found non-preferred primary link (_abPathIdx=%d)", _abPathIdx);
15801589
_abPathIdx = nonPreferredPathIdx;
15811590
}
15821591
}
@@ -1614,10 +1623,10 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
16141623
}
16151624
if (_paths[(*it)].p && ! _paths[(*it)].eligible) {
16161625
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, _paths[(*it)].p->localSocket());
1617-
it = _abFailoverQueue.erase(it);
16181626
if (link) {
1619-
log("link %s is ineligible, removing from failover queue (%zu links remain in queue)", pathToStr(_paths[_abPathIdx].p).c_str(), _abFailoverQueue.size());
1627+
log("link %s is ineligible, removing from failover queue (%zu links remain in queue)", pathToStr(_paths[(*it)].p).c_str(), _abFailoverQueue.size());
16201628
}
1629+
it = _abFailoverQueue.erase(it);
16211630
continue;
16221631
}
16231632
else {
@@ -1684,7 +1693,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
16841693
}
16851694
}
16861695
if (! bFoundPathInQueue) {
1687-
_abFailoverQueue.push_front(i);
1696+
_abFailoverQueue.push_back(i);
16881697
log("add link %s to failover queue (%zu links in queue)", pathToStr(_paths[i].p).c_str(), _abFailoverQueue.size());
16891698
addPathToBond(i, 0);
16901699
}
@@ -1734,13 +1743,14 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
17341743
}
17351744
}
17361745
if (! bFoundPathInQueue) {
1737-
_abFailoverQueue.push_front(i);
1746+
_abFailoverQueue.push_back(i);
17381747
log("add link %s to failover queue (%zu links in queue)", pathToStr(_paths[i].p).c_str(), _abFailoverQueue.size());
17391748
addPathToBond(i, 0);
17401749
}
17411750
}
17421751
}
17431752
}
1753+
/*
17441754
// Sort queue based on performance
17451755
if (! _abFailoverQueue.empty()) {
17461756
for (int i = 0; i < _abFailoverQueue.size(); i++) {
@@ -1752,7 +1762,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
17521762
}
17531763
_abFailoverQueue[hole_position] = value_to_insert;
17541764
}
1755-
}
1765+
}*/
17561766

17571767
/**
17581768
* Short-circuit if we have no queued paths
@@ -1902,7 +1912,7 @@ void Bond::setBondParameters(int policy, SharedPtr<Bond> templateBond, bool useT
19021912
* Policy defaults
19031913
*/
19041914
_abPathIdx = ZT_MAX_PEER_NETWORK_PATHS;
1905-
_abLinkSelectMethod = ZT_BOND_RESELECTION_POLICY_OPTIMIZE;
1915+
_abLinkSelectMethod = ZT_BOND_RESELECTION_POLICY_ALWAYS;
19061916
_rrPacketsSentOnCurrLink = 0;
19071917
_rrIdx = 0;
19081918
_packetsPerLink = 64;
@@ -2021,7 +2031,8 @@ void Bond::dumpInfo(int64_t now, bool force)
20212031
_lastSummaryDump = now;
20222032
float overhead = (_overheadBytes / (timeSinceLastDump / 1000.0f) / 1000.0f);
20232033
_overheadBytes = 0;
2024-
log("bond: bp=%d, fi=%" PRIu64 ", mi=%d, ud=%d, dd=%d, flows=%zu, leaf=%d, overhead=%f KB/s, links=(%d/%d)",
2034+
log("bond: ready=%d, bp=%d, fi=%" PRIu64 ", mi=%d, ud=%d, dd=%d, flows=%zu, leaf=%d, overhead=%f KB/s, links=(%d/%d)",
2035+
isReady(),
20252036
_policy,
20262037
_failoverInterval,
20272038
_monitorInterval,

node/Bond.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ class Bond {
11441144
__attribute__((format(printf, 2, 3)))
11451145
#endif
11461146
{
1147+
//if (_peerId != 0x0 && _peerId != 0x0) { return; }
11471148
#ifdef ZT_TRACE
11481149
time_t rawtime;
11491150
struct tm* timeinfo;
@@ -1175,6 +1176,7 @@ class Bond {
11751176
__attribute__((format(printf, 2, 3)))
11761177
#endif
11771178
{
1179+
//if (_peerId != 0x0 && _peerId != 0x0) { return; }
11781180
#ifdef ZT_DEBUG
11791181
time_t rawtime;
11801182
struct tm* timeinfo;

node/IncomingPacket.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ bool IncomingPacket::_doACK(const RuntimeEnvironment* RR, void* tPtr, const Shar
334334
bool IncomingPacket::_doQOS_MEASUREMENT(const RuntimeEnvironment* RR, void* tPtr, const SharedPtr<Peer>& peer)
335335
{
336336
Metrics::pkt_qos_in++;
337-
SharedPtr<Bond> bond = peer->bond();
338337
if (! peer->rateGateQoS(RR->node->now(), _path)) {
339338
return true;
340339
}

service/OneService.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,7 @@ class OneServiceImpl : public OneService
25102510
}
25112511
_node->bondController()->addCustomLink(customPolicyStr, new Link(linkNameStr,ipvPref,mtu,capacity,enabled,linkMode,failoverToStr));
25122512
}
2513-
std::string linkSelectMethodStr(OSUtils::jsonString(customPolicy["activeReselect"],"optimize"));
2513+
std::string linkSelectMethodStr(OSUtils::jsonString(customPolicy["activeReselect"],"always"));
25142514
if (linkSelectMethodStr == "always") {
25152515
newTemplateBond->setLinkSelectMethod(ZT_BOND_RESELECTION_POLICY_ALWAYS);
25162516
}

0 commit comments

Comments
 (0)