Adjust terminology

This commit is contained in:
Joseph Henry 2020-06-17 14:54:13 -07:00
commit a33a494d60
13 changed files with 440 additions and 442 deletions

View file

@ -54,9 +54,9 @@ Bond::Bond(const RuntimeEnvironment *renv, SharedPtr<Bond> originalBond, const S
void Bond::nominatePath(const SharedPtr<Path>& path, int64_t now)
{
char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "nominatePath: %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "nominatePath: %s %s\n", getLink(path)->ifname().c_str(), pathStr);
Mutex::Lock _l(_paths_m);
if (!RR->bc->slaveAllowed(_policyAlias, getSlave(path))) {
if (!RR->bc->linkAllowed(_policyAlias, getLink(path))) {
return;
}
bool alreadyPresent = false;
@ -72,7 +72,7 @@ void Bond::nominatePath(const SharedPtr<Path>& path, int64_t now)
if (!_paths[i]) {
fprintf(stderr, "notifyOfNewPath(): Setting path %s to idx=%d\n", pathStr, i);
_paths[i] = path;
//_paths[i]->slave = RR->bc->getSlaveBySocket(_policyAlias, path->localSocket());
//_paths[i]->link = RR->bc->getLinkBySocket(_policyAlias, path->localSocket());
_paths[i]->startTrial(now);
break;
}
@ -107,18 +107,18 @@ SharedPtr<Path> Bond::getAppropriatePath(int64_t now, int32_t flowId)
*/
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR) {
if (!_allowFlowHashing) {
//fprintf(stderr, "_rrPacketsSentOnCurrSlave=%d, _numBondedPaths=%d, _rrIdx=%d\n", _rrPacketsSentOnCurrSlave, _numBondedPaths, _rrIdx);
if (_packetsPerSlave == 0) {
//fprintf(stderr, "_rrPacketsSentOnCurrLink=%d, _numBondedPaths=%d, _rrIdx=%d\n", _rrPacketsSentOnCurrLink, _numBondedPaths, _rrIdx);
if (_packetsPerLink == 0) {
// Randomly select a path
return _paths[_bondedIdx[_freeRandomByte % _numBondedPaths]]; // TODO: Optimize
}
if (_rrPacketsSentOnCurrSlave < _packetsPerSlave) {
// Continue to use this slave
++_rrPacketsSentOnCurrSlave;
if (_rrPacketsSentOnCurrLink < _packetsPerLink) {
// Continue to use this link
++_rrPacketsSentOnCurrLink;
return _paths[_bondedIdx[_rrIdx]];
}
// Reset striping counter
_rrPacketsSentOnCurrSlave = 0;
_rrPacketsSentOnCurrLink = 0;
if (_numBondedPaths == 1) {
_rrIdx = 0;
}
@ -170,7 +170,7 @@ SharedPtr<Path> Bond::getAppropriatePath(int64_t now, int32_t flowId)
void Bond::recordIncomingInvalidPacket(const SharedPtr<Path>& path)
{
// char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordIncomingInvalidPacket() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
// char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordIncomingInvalidPacket() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
Mutex::Lock _l(_paths_m);
for (int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (_paths[i] == path) {
@ -182,7 +182,7 @@ void Bond::recordIncomingInvalidPacket(const SharedPtr<Path>& path)
void Bond::recordOutgoingPacket(const SharedPtr<Path> &path, const uint64_t packetId,
uint16_t payloadLength, const Packet::Verb verb, const int32_t flowId, int64_t now)
{
// char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordOutgoingPacket() %s %s, packetId=%llx, payloadLength=%d, verb=%x, flowId=%lx\n", getSlave(path)->ifname().c_str(), pathStr, packetId, payloadLength, verb, flowId);
// char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordOutgoingPacket() %s %s, packetId=%llx, payloadLength=%d, verb=%x, flowId=%lx\n", getLink(path)->ifname().c_str(), pathStr, packetId, payloadLength, verb, flowId);
_freeRandomByte += (unsigned char)(packetId >> 8); // Grab entropy to use in path selection logic
if (!_shouldCollectPathStatistics) {
return;
@ -218,7 +218,7 @@ void Bond::recordOutgoingPacket(const SharedPtr<Path> &path, const uint64_t pack
void Bond::recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId, uint16_t payloadLength,
Packet::Verb verb, int32_t flowId, int64_t now)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordIncomingPacket() %s %s, packetId=%llx, payloadLength=%d, verb=%x, flowId=%lx\n", getSlave(path)->ifname().c_str(), pathStr, packetId, payloadLength, verb, flowId);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "recordIncomingPacket() %s %s, packetId=%llx, payloadLength=%d, verb=%x, flowId=%lx\n", getLink(path)->ifname().c_str(), pathStr, packetId, payloadLength, verb, flowId);
bool isFrame = (verb == Packet::VERB_FRAME || verb == Packet::VERB_EXT_FRAME);
bool shouldRecord = (packetId & (ZT_QOS_ACK_DIVISOR - 1)
&& (verb != Packet::VERB_ACK)
@ -261,7 +261,7 @@ void Bond::recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId,
void Bond::receivedQoS(const SharedPtr<Path>& path, int64_t now, int count, uint64_t *rx_id, uint16_t *rx_ts)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedQoS() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedQoS() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
Mutex::Lock _l(_paths_m);
// Look up egress times and compute latency values for each record
std::map<uint64_t,uint64_t>::iterator it;
@ -273,13 +273,13 @@ void Bond::receivedQoS(const SharedPtr<Path>& path, int64_t now, int count, uint
}
}
path->qosRecordSize.push(count);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedQoS() on path %s %s, count=%d, successful=%d, qosStatsOut.size()=%d\n", getSlave(path)->ifname().c_str(), pathStr, count, path->aknowledgedQoSRecordCountSinceLastCheck, path->qosStatsOut.size());
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedQoS() on path %s %s, count=%d, successful=%d, qosStatsOut.size()=%d\n", getLink(path)->ifname().c_str(), pathStr, count, path->aknowledgedQoSRecordCountSinceLastCheck, path->qosStatsOut.size());
}
void Bond::receivedAck(const SharedPtr<Path>& path, int64_t now, int32_t ackedBytes)
{
Mutex::Lock _l(_paths_m);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedAck() %s %s, (ackedBytes=%d, lastAckReceived=%lld, ackAge=%lld)\n", getSlave(path)->ifname().c_str(), pathStr, ackedBytes, path->lastAckReceived, path->ackAge(now));
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "receivedAck() %s %s, (ackedBytes=%d, lastAckReceived=%lld, ackAge=%lld)\n", getLink(path)->ifname().c_str(), pathStr, ackedBytes, path->lastAckReceived, path->ackAge(now));
path->_lastAckReceived = now;
path->_unackedBytes = (ackedBytes > path->_unackedBytes) ? 0 : path->_unackedBytes - ackedBytes;
int64_t timeSinceThroughputEstimate = (now - path->_lastThroughputEstimation);
@ -300,7 +300,7 @@ void Bond::receivedAck(const SharedPtr<Path>& path, int64_t now, int32_t ackedBy
int32_t Bond::generateQoSPacket(const SharedPtr<Path>& path, int64_t now, char *qosBuffer)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "generateQoSPacket() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "generateQoSPacket() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
int32_t len = 0;
std::map<uint64_t,uint64_t>::iterator it = path->qosStatsIn.begin();
int i=0;
@ -355,10 +355,10 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow> &flow, int64_t now)
//fprintf(stderr, "new entropy = %d\n", entropy);
for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
if (_paths[i] && _paths[i]->bonded()) {
SharedPtr<Slave> slave = RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
_paths[i]->address().toString(curPathStr);
uint8_t probabilitySegment = (_totalBondUnderload > 0) ? _paths[i]->_affinity : _paths[i]->_allocation;
//fprintf(stderr, "i=%2d, entropy=%3d, alloc=%3d, byteload=%4d, segment=%3d, _totalBondUnderload=%3d, ifname=%s, path=%20s\n", i, entropy, _paths[i]->_allocation, _paths[i]->_relativeByteLoad, probabilitySegment, _totalBondUnderload, slave->ifname().c_str(), curPathStr);
//fprintf(stderr, "i=%2d, entropy=%3d, alloc=%3d, byteload=%4d, segment=%3d, _totalBondUnderload=%3d, ifname=%s, path=%20s\n", i, entropy, _paths[i]->_allocation, _paths[i]->_relativeByteLoad, probabilitySegment, _totalBondUnderload, link->ifname().c_str(), curPathStr);
if (entropy <= probabilitySegment) {
idx = i;
//fprintf(stderr, "\t is best path\n");
@ -380,8 +380,8 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow> &flow, int64_t now)
}
}
flow->assignedPath()->address().toString(curPathStr);
SharedPtr<Slave> slave = RR->bc->getSlaveBySocket(_policyAlias, flow->assignedPath()->localSocket());
fprintf(stderr, "assigned (tx) flow %x with peer %llx to path %s on %s (idx=%d)\n", flow->id(), _peer->_id.address().toInt(), curPathStr, slave->ifname().c_str(), idx);
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, flow->assignedPath()->localSocket());
fprintf(stderr, "assigned (tx) flow %x with peer %llx to path %s on %s (idx=%d)\n", flow->id(), _peer->_id.address().toInt(), curPathStr, link->ifname().c_str(), idx);
return true;
}
@ -410,8 +410,8 @@ SharedPtr<Flow> Bond::createFlow(const SharedPtr<Path> &path, int32_t flowId, un
flow->assignPath(path,now);
path->address().toString(curPathStr);
path->_assignedFlowCount++;
SharedPtr<Slave> slave = RR->bc->getSlaveBySocket(_policyAlias, flow->assignedPath()->localSocket());
fprintf(stderr, "assigned (rx) flow %x with peer %llx to path %s on %s\n", flow->id(), _peer->_id.address().toInt(), curPathStr, slave->ifname().c_str());
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, flow->assignedPath()->localSocket());
fprintf(stderr, "assigned (rx) flow %x with peer %llx to path %s on %s\n", flow->id(), _peer->_id.address().toInt(), curPathStr, link->ifname().c_str());
}
/**
* Add a flow when no path was provided. This means that it is an outgoing packet
@ -460,7 +460,7 @@ void Bond::forgetFlowsWhenNecessary(uint64_t age, bool oldest, int64_t now)
void Bond::processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path> &path, int16_t remoteUtility)
{
//fprintf(stderr, "processIncomingPathNegotiationRequest\n");
if (_abSlaveSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
if (_abLinkSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
return;
}
Mutex::Lock _l(_paths_m);
@ -469,18 +469,18 @@ void Bond::processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path> &
if (!_lastPathNegotiationCheck) {
return;
}
SharedPtr<Slave> slave = RR->bc->getSlaveBySocket(_policyAlias, path->localSocket());
SharedPtr<Link> link = RR->bc->getLinkBySocket(_policyAlias, path->localSocket());
if (remoteUtility > _localUtility) {
fprintf(stderr, "peer suggests path, its utility (%d) is greater than ours (%d), we will switch to %s on %s (ls=%llx)\n", remoteUtility, _localUtility, pathStr, slave->ifname().c_str(), path->localSocket());
fprintf(stderr, "peer suggests path, its utility (%d) is greater than ours (%d), we will switch to %s on %s (ls=%llx)\n", remoteUtility, _localUtility, pathStr, link->ifname().c_str(), path->localSocket());
negotiatedPath = path;
}
if (remoteUtility < _localUtility) {
fprintf(stderr, "peer suggests path, its utility (%d) is less than ours (%d), we will NOT switch to %s on %s (ls=%llx)\n", remoteUtility, _localUtility, pathStr, slave->ifname().c_str(), path->localSocket());
fprintf(stderr, "peer suggests path, its utility (%d) is less than ours (%d), we will NOT switch to %s on %s (ls=%llx)\n", remoteUtility, _localUtility, pathStr, link->ifname().c_str(), path->localSocket());
}
if (remoteUtility == _localUtility) {
fprintf(stderr, "peer suggest path, but utility is equal, picking choice made by peer with greater identity.\n");
if (_peer->_id.address().toInt() > RR->node->identity().address().toInt()) {
fprintf(stderr, "peer identity was greater, going with their choice of %s on %s (ls=%llx)\n", pathStr, slave->ifname().c_str(), path->localSocket());
fprintf(stderr, "peer identity was greater, going with their choice of %s on %s (ls=%llx)\n", pathStr, link->ifname().c_str(), path->localSocket());
negotiatedPath = path;
} else {
fprintf(stderr, "our identity was greater, no change\n");
@ -532,8 +532,8 @@ void Bond::pathNegotiationCheck(void *tPtr, const int64_t now)
++_numSentPathNegotiationRequests;
_lastSentPathNegotiationRequest = now;
_paths[maxOutPathIdx]->address().toString(pathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[maxOutPathIdx]->localSocket());
fprintf(stderr, "sending request to use %s on %s, ls=%llx, utility=%d\n", pathStr, slave->ifname().c_str(), _paths[maxOutPathIdx]->localSocket(), _localUtility);
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[maxOutPathIdx]->localSocket());
fprintf(stderr, "sending request to use %s on %s, ls=%llx, utility=%d\n", pathStr, link->ifname().c_str(), _paths[maxOutPathIdx]->localSocket(), _localUtility);
}
}
/**
@ -551,8 +551,8 @@ void Bond::pathNegotiationCheck(void *tPtr, const int64_t now)
void Bond::sendPATH_NEGOTIATION_REQUEST(void *tPtr, const SharedPtr<Path> &path)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendPATH_NEGOTIATION_REQUEST() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
if (_abSlaveSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendPATH_NEGOTIATION_REQUEST() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
if (_abLinkSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
return;
}
Packet outp(_peer->_id.address(),RR->identity.address(),Packet::VERB_PATH_NEGOTIATION_REQUEST);
@ -566,7 +566,7 @@ void Bond::sendPATH_NEGOTIATION_REQUEST(void *tPtr, const SharedPtr<Path> &path)
void Bond::sendACK(void *tPtr,const SharedPtr<Path> &path,const int64_t localSocket,
const InetAddress &atAddress,int64_t now)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendACK() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendACK() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
Packet outp(_peer->_id.address(),RR->identity.address(),Packet::VERB_ACK);
int32_t bytesToAck = 0;
std::map<uint64_t,uint16_t>::iterator it = path->ackStatsIn.begin();
@ -589,7 +589,7 @@ void Bond::sendACK(void *tPtr,const SharedPtr<Path> &path,const int64_t localSoc
void Bond::sendQOS_MEASUREMENT(void *tPtr,const SharedPtr<Path> &path,const int64_t localSocket,
const InetAddress &atAddress,int64_t now)
{
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendQOS() %s %s\n", getSlave(path)->ifname().c_str(), pathStr);
//char pathStr[128];path->address().toString(pathStr);fprintf(stderr, "sendQOS() %s %s\n", getLink(path)->ifname().c_str(), pathStr);
const int64_t _now = RR->node->now();
Packet outp(_peer->_id.address(),RR->identity.address(),Packet::VERB_QOS_MEASUREMENT);
char qosData[ZT_QOS_MAX_PACKET_SIZE];
@ -615,14 +615,14 @@ void Bond::processBackgroundTasks(void *tPtr, const int64_t now)
_lastBackgroundTaskCheck = now;
// Compute dynamic path monitor timer interval
if (_slaveMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC) {
if (_linkMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC) {
int suggestedMonitorInterval = (now - _lastFrame) / 100;
_dynamicPathMonitorInterval = std::min(ZT_PATH_HEARTBEAT_PERIOD, ((suggestedMonitorInterval > _bondMonitorInterval) ? suggestedMonitorInterval : _bondMonitorInterval));
//fprintf(stderr, "_lastFrame=%llu, suggestedMonitorInterval=%d, _dynamicPathMonitorInterval=%d\n",
// (now-_lastFrame), suggestedMonitorInterval, _dynamicPathMonitorInterval);
}
// TODO: Clarify and generalize this logic
if (_slaveMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC) {
if (_linkMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC) {
_shouldCollectPathStatistics = true;
}
@ -632,11 +632,11 @@ void Bond::processBackgroundTasks(void *tPtr, const int64_t now)
_shouldCollectPathStatistics = true;
}
if (_bondingPolicy == ZT_BONDING_POLICY_ACTIVE_BACKUP) {
if (_abSlaveSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_BETTER) {
// Required for judging suitability of primary slave after recovery
if (_abLinkSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_BETTER) {
// Required for judging suitability of primary link after recovery
_shouldCollectPathStatistics = true;
}
if (_abSlaveSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
if (_abLinkSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
// Required for judging suitability of new candidate primary
_shouldCollectPathStatistics = true;
}
@ -696,18 +696,18 @@ void Bond::applyUserPrefs()
if (!_paths[i]) {
continue;
}
SharedPtr<Slave> sl = getSlave(_paths[i]);
SharedPtr<Link> sl = getLink(_paths[i]);
if (sl) {
if (sl->monitorInterval() == 0) { // If no interval was specified for this slave, use more generic bond-wide interval
if (sl->monitorInterval() == 0) { // If no interval was specified for this link, use more generic bond-wide interval
sl->setMonitorInterval(_bondMonitorInterval);
}
RR->bc->setMinReqPathMonitorInterval((sl->monitorInterval() < RR->bc->minReqPathMonitorInterval()) ? sl->monitorInterval() : RR->bc->minReqPathMonitorInterval());
bool bFoundCommonSlave = false;
SharedPtr<Slave> commonSlave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
bool bFoundCommonLink = false;
SharedPtr<Link> commonLink =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
for(unsigned int j=0;j<ZT_MAX_PEER_NETWORK_PATHS;++j) {
if (_paths[j] && _paths[j].ptr() != _paths[i].ptr()) {
if (RR->bc->getSlaveBySocket(_policyAlias, _paths[j]->localSocket()) == commonSlave) {
bFoundCommonSlave = true;
if (RR->bc->getLinkBySocket(_policyAlias, _paths[j]->localSocket()) == commonLink) {
bFoundCommonLink = true;
}
}
}
@ -717,7 +717,7 @@ void Bond::applyUserPrefs()
_paths[i]->_ipvPref = sl->ipvPref();
_paths[i]->_mode = sl->mode();
_paths[i]->_enabled = sl->enabled();
_paths[i]->_onlyPathOnSlave = !bFoundCommonSlave;
_paths[i]->_onlyPathOnLink = !bFoundCommonLink;
}
}
if (_peer) {
@ -739,11 +739,11 @@ void Bond::curateBond(const int64_t now, bool rebuildBond)
}
bool currEligibility = _paths[i]->eligible(now,_ackSendInterval);
//_paths[i]->address().toString(pathStr);
//fprintf(stderr, "\n\n%ld path eligibility (for %s, %s):\n", (RR->node->now() - RR->bc->getBondStartTime()), getSlave(_paths[i])->ifname().c_str(), pathStr);
//fprintf(stderr, "\n\n%ld path eligibility (for %s, %s):\n", (RR->node->now() - RR->bc->getBondStartTime()), getLink(_paths[i])->ifname().c_str(), pathStr);
//_paths[i]->printEligible(now,_ackSendInterval);
if (currEligibility != _paths[i]->_lastEligibilityState) {
_paths[i]->address().toString(pathStr);
//fprintf(stderr, "\n\n%ld path eligibility (for %s, %s) has changed (from %d to %d)\n", (RR->node->now() - RR->bc->getBondStartTime()), getSlave(_paths[i])->ifname().c_str(), pathStr, _paths[i]->lastCheckedEligibility, _paths[i]->eligible(now,_ackSendInterval));
//fprintf(stderr, "\n\n%ld path eligibility (for %s, %s) has changed (from %d to %d)\n", (RR->node->now() - RR->bc->getBondStartTime()), getLink(_paths[i])->ifname().c_str(), pathStr, _paths[i]->lastCheckedEligibility, _paths[i]->eligible(now,_ackSendInterval));
if (currEligibility) {
rebuildBond = true;
}
@ -766,7 +766,7 @@ void Bond::curateBond(const int64_t now, bool rebuildBond)
}
/**
* Curate the set of paths that are part of the bond proper. Selects a single path
* per logical slave according to eligibility and user-specified constraints.
* per logical link according to eligibility and user-specified constraints.
*/
if ((_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR)
|| (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_XOR)
@ -777,68 +777,68 @@ void Bond::curateBond(const int64_t now, bool rebuildBond)
// TODO: Optimize
if (rebuildBond) {
int updatedBondedPathCount = 0;
std::map<SharedPtr<Slave>,int> slaveMap;
std::map<SharedPtr<Link>,int> linkMap;
for (int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
if (_paths[i] && _paths[i]->allowed() && (_paths[i]->eligible(now,_ackSendInterval) || !_numBondedPaths)) {
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
if (!slaveMap.count(slave)) {
slaveMap[slave] = i;
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (!linkMap.count(link)) {
linkMap[link] = i;
}
else {
bool overriden = false;
_paths[i]->address().toString(pathStr);
//fprintf(stderr, " slave representative path already exists! (%s %s)\n", getSlave(_paths[i])->ifname().c_str(), pathStr);
if (_paths[i]->preferred() && !_paths[slaveMap[slave]]->preferred()) {
//fprintf(stderr, " link representative path already exists! (%s %s)\n", getLink(_paths[i])->ifname().c_str(), pathStr);
if (_paths[i]->preferred() && !_paths[linkMap[link]]->preferred()) {
// Override previous choice if preferred
//fprintf(stderr, "overriding since its preferred!\n");
if (_paths[slaveMap[slave]]->_assignedFlowCount) {
_paths[slaveMap[slave]]->_deprecated = true;
if (_paths[linkMap[link]]->_assignedFlowCount) {
_paths[linkMap[link]]->_deprecated = true;
}
else {
_paths[slaveMap[slave]]->_deprecated = true;
_paths[slaveMap[slave]]->setBonded(false);
_paths[linkMap[link]]->_deprecated = true;
_paths[linkMap[link]]->setBonded(false);
}
slaveMap[slave] = i;
linkMap[link] = i;
overriden = true;
}
if ((_paths[i]->preferred() && _paths[slaveMap[slave]]->preferred())
|| (!_paths[i]->preferred() && !_paths[slaveMap[slave]]->preferred())) {
if (_paths[i]->preferenceRank() > _paths[slaveMap[slave]]->preferenceRank()) {
if ((_paths[i]->preferred() && _paths[linkMap[link]]->preferred())
|| (!_paths[i]->preferred() && !_paths[linkMap[link]]->preferred())) {
if (_paths[i]->preferenceRank() > _paths[linkMap[link]]->preferenceRank()) {
// Override if higher preference
//fprintf(stderr, "overriding according to preference preferenceRank!\n");
if (_paths[slaveMap[slave]]->_assignedFlowCount) {
_paths[slaveMap[slave]]->_deprecated = true;
if (_paths[linkMap[link]]->_assignedFlowCount) {
_paths[linkMap[link]]->_deprecated = true;
}
else {
_paths[slaveMap[slave]]->_deprecated = true;
_paths[slaveMap[slave]]->setBonded(false);
_paths[linkMap[link]]->_deprecated = true;
_paths[linkMap[link]]->setBonded(false);
}
slaveMap[slave] = i;
linkMap[link] = i;
}
}
}
}
}
std::map<SharedPtr<Slave>,int>::iterator it = slaveMap.begin();
std::map<SharedPtr<Link>,int>::iterator it = linkMap.begin();
for (int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (!_paths[i]) {
continue;
}
_bondedIdx[i] = ZT_MAX_PEER_NETWORK_PATHS;
if (it != slaveMap.end()) {
if (it != linkMap.end()) {
_bondedIdx[i] = it->second;
_paths[_bondedIdx[i]]->setBonded(true);
++it;
++updatedBondedPathCount;
_paths[_bondedIdx[i]]->address().toString(pathStr);
//fprintf(stderr, "setting i=%d, _bondedIdx[%d]=%d to bonded (%s %s)\n", i, i, _bondedIdx[i], getSlave(_paths[_bondedIdx[i]])->ifname().c_str(), pathStr);
//fprintf(stderr, "setting i=%d, _bondedIdx[%d]=%d to bonded (%s %s)\n", i, i, _bondedIdx[i], getLink(_paths[_bondedIdx[i]])->ifname().c_str(), pathStr);
}
}
_numBondedPaths = updatedBondedPathCount;
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR) {
// Cause a RR reset since the currently used index might no longer be valid
_rrPacketsSentOnCurrSlave = _packetsPerSlave;
_rrPacketsSentOnCurrLink = _packetsPerLink;
}
}
}
@ -847,18 +847,18 @@ void Bond::curateBond(const int64_t now, bool rebuildBond)
void Bond::estimatePathQuality(const int64_t now)
{
char pathStr[128];
uint32_t totUserSpecifiedSlaveSpeed = 0;
if (_numBondedPaths) { // Compute relative user-specified speeds of slaves
uint32_t totUserSpecifiedLinkSpeed = 0;
if (_numBondedPaths) { // Compute relative user-specified speeds of links
for(unsigned int i=0;i<_numBondedPaths;++i) {
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (_paths[i] && _paths[i]->allowed()) {
totUserSpecifiedSlaveSpeed += slave->speed();
totUserSpecifiedLinkSpeed += link->speed();
}
}
for(unsigned int i=0;i<_numBondedPaths;++i) {
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (_paths[i] && _paths[i]->allowed()) {
slave->setRelativeSpeed(round( ((float)slave->speed() / (float)totUserSpecifiedSlaveSpeed) * 255));
link->setRelativeSpeed(round( ((float)link->speed() / (float)totUserSpecifiedLinkSpeed) * 255));
}
}
}
@ -895,11 +895,11 @@ void Bond::estimatePathQuality(const int64_t now)
_paths[i]->_latencyVariance = _paths[i]->latencySamples.stddev();
_paths[i]->_packetErrorRatio = 1.0 - (_paths[i]->packetValiditySamples.count() ? _paths[i]->packetValiditySamples.mean() : 1.0);
if (userHasSpecifiedSlaveSpeeds()) {
if (userHasSpecifiedLinkSpeeds()) {
// Use user-reported metrics
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
if (slave) {
_paths[i]->_throughputMean = slave->speed();
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (link) {
_paths[i]->_throughputMean = link->speed();
_paths[i]->_throughputVariance = 0;
}
}
@ -929,7 +929,7 @@ void Bond::estimatePathQuality(const int64_t now)
maxPLR = plr[i] > maxPLR ? plr[i] : maxPLR;
maxPER = per[i] > maxPER ? per[i] : maxPER;
//fprintf(stdout, "EH %d: lat=%8.3f, ltm=%8.3f, pdv=%8.3f, plr=%5.3f, per=%5.3f, thr=%8f, thm=%5.3f, thv=%5.3f, avl=%5.3f, age=%8.2f, scp=%4d, q=%5.3f, qtot=%5.3f, ac=%d if=%s, path=%s\n",
// i, lat[i], ltm[i], pdv[i], plr[i], per[i], thr[i], thm[i], thv[i], avl[i], age[i], scp[i], quality[i], totQuality, alloc[i], getSlave(_paths[i])->ifname().c_str(), pathStr);
// i, lat[i], ltm[i], pdv[i], plr[i], per[i], thr[i], thm[i], thv[i], avl[i], age[i], scp[i], quality[i], totQuality, alloc[i], getLink(_paths[i])->ifname().c_str(), pathStr);
}
// Convert metrics to relative quantities and apply contribution weights
@ -962,7 +962,7 @@ void Bond::estimatePathQuality(const int64_t now)
//fprintf(stderr, "%lu FIN [%d/%d]: pmi=%5d, lat=%4.3f, ltm=%4.3f, pdv=%4.3f, plr=%4.3f, per=%4.3f, thr=%4.3f, thm=%4.3f, thv=%4.3f, age=%4.3f, scp=%4d, q=%4.3f, qtot=%4.3f, ac=%4d, asf=%3d, if=%s, path=%20s, bond=%d, qosout=%d, plrraw=%d\n",
// ((now - RR->bc->getBondStartTime())), i, _numBondedPaths, _paths[i]->monitorInterval,
// lat[i], ltm[i], pdv[i], plr[i], per[i], thr[i], thm[i], thv[i], age[i], scp[i],
// quality[i], totQuality, alloc[i], _paths[i]->assignedFlowCount, getSlave(_paths[i])->ifname().c_str(), pathStr, _paths[i]->bonded(), _paths[i]->qosStatsOut.size(), _paths[i]->packetLossRatio);
// quality[i], totQuality, alloc[i], _paths[i]->assignedFlowCount, getLink(_paths[i])->ifname().c_str(), pathStr, _paths[i]->bonded(), _paths[i]->qosStatsOut.size(), _paths[i]->packetLossRatio);
}
}
if (numPlottablePaths < 2) {
@ -973,7 +973,7 @@ void Bond::estimatePathQuality(const int64_t now)
for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
if (_paths[i]) {
_paths[i]->address().toString(pathStr);
std::string label = std::string((pathStr)) + " " + getSlave(_paths[i])->ifname();
std::string label = std::string((pathStr)) + " " + getLink(_paths[i])->ifname();
for (int i=0; i<19; ++i) {
fprintf(stdout, "%s, ", label.c_str());
}
@ -987,7 +987,7 @@ void Bond::estimatePathQuality(const int64_t now)
if (_paths[i]) {
_paths[i]->address().toString(pathStr);
fprintf(stdout, "%s, %s, %8.3f, %8.3f, %8.3f, %5.3f, %5.3f, %5.3f, %8f, %5.3f, %5.3f, %d, %5.3f, %d, %d, %d, %d, %d, %d, ",
getSlave(_paths[i])->ifname().c_str(), pathStr, _paths[i]->_latencyMean, lat[i],pdv[i], _paths[i]->_packetLossRatio, plr[i],per[i],thr[i],thm[i],thv[i],(now - _paths[i]->lastIn()),quality[i],alloc[i],
getLink(_paths[i])->ifname().c_str(), pathStr, _paths[i]->_latencyMean, lat[i],pdv[i], _paths[i]->_packetLossRatio, plr[i],per[i],thr[i],thm[i],thv[i],(now - _paths[i]->lastIn()),quality[i],alloc[i],
_paths[i]->_relativeByteLoad, _paths[i]->_assignedFlowCount, _paths[i]->alive(now, true), _paths[i]->eligible(now,_ackSendInterval), _paths[i]->qosStatsOut.size());
}
}*/
@ -1040,7 +1040,7 @@ void Bond::processBalanceTasks(const int64_t now)
}
if (!_paths[i]->eligible(now,_ackSendInterval) && _paths[i]->_shouldReallocateFlows) {
_paths[i]->address().toString(curPathStr);
fprintf(stderr, "%d reallocating flows from dead path %s on %s\n", (RR->node->now() - RR->bc->getBondStartTime()), curPathStr, getSlave(_paths[i])->ifname().c_str());
fprintf(stderr, "%d reallocating flows from dead path %s on %s\n", (RR->node->now() - RR->bc->getBondStartTime()), curPathStr, getLink(_paths[i])->ifname().c_str());
std::map<int32_t,SharedPtr<Flow> >::iterator flow_it = _flows.begin();
while (flow_it != _flows.end()) {
if (flow_it->second->assignedPath() == _paths[i]) {
@ -1066,7 +1066,7 @@ void Bond::processBalanceTasks(const int64_t now)
}
if (_paths[i] && _paths[i]->bonded() && _paths[i]->eligible(now,_ackSendInterval) && (_paths[i]->_allocation < minimumAllocationValue) && _paths[i]->_assignedFlowCount) {
_paths[i]->address().toString(curPathStr);
fprintf(stderr, "%d reallocating flows from under-performing path %s on %s\n", (RR->node->now() - RR->bc->getBondStartTime()), curPathStr, getSlave(_paths[i])->ifname().c_str());
fprintf(stderr, "%d reallocating flows from under-performing path %s on %s\n", (RR->node->now() - RR->bc->getBondStartTime()), curPathStr, getLink(_paths[i])->ifname().c_str());
std::map<int32_t,SharedPtr<Flow> >::iterator flow_it = _flows.begin();
while (flow_it != _flows.end()) {
if (flow_it->second->assignedPath() == _paths[i]) {
@ -1086,7 +1086,7 @@ void Bond::processBalanceTasks(const int64_t now)
*/
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR) {
if (_allowFlowHashing) {
// TODO: Should ideally failover from (idx) to a random slave, this is so that (idx+1) isn't overloaded
// TODO: Should ideally failover from (idx) to a random link, this is so that (idx+1) isn't overloaded
}
else if (!_allowFlowHashing) {
// Nothing
@ -1176,29 +1176,29 @@ void Bond::processActiveBackupTasks(const int64_t now)
SharedPtr<Path> prevActiveBackupPath = _abPath;
SharedPtr<Path> nonPreferredPath;
bool bFoundPrimarySlave = false;
bool bFoundPrimaryLink = false;
/**
* Select initial "active" active-backup slave
* Select initial "active" active-backup link
*/
if (!_abPath) {
fprintf(stderr, "%llu no active backup path yet...\n", ((now - RR->bc->getBondStartTime())));
/**
* [Automatic mode]
* The user has not explicitly specified slaves or their failover schedule,
* The user has not explicitly specified links or their failover schedule,
* the bonding policy will now select the first eligible path and set it as
* its active backup path, if a substantially better path is detected the bonding
* policy will assign it as the new active backup path. If the path fails it will
* simply find the next eligible path.
*/
if (!userHasSpecifiedSlaves()) {
fprintf(stderr, "%llu AB: (auto) user did not specify any slaves. waiting until we know more\n", ((now - RR->bc->getBondStartTime())));
if (!userHasSpecifiedLinks()) {
fprintf(stderr, "%llu AB: (auto) user did not specify any links. waiting until we know more\n", ((now - RR->bc->getBondStartTime())));
for (int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (_paths[i] && _paths[i]->eligible(now,_ackSendInterval)) {
_paths[i]->address().toString(curPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
if (slave) {
fprintf(stderr, "%llu AB: (initial) [%d] found eligible path %s on: %s\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, slave->ifname().c_str());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (link) {
fprintf(stderr, "%llu AB: (initial) [%d] found eligible path %s on: %s\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, link->ifname().c_str());
}
_abPath = _paths[i];
break;
@ -1207,57 +1207,57 @@ void Bond::processActiveBackupTasks(const int64_t now)
}
/**
* [Manual mode]
* The user has specified slaves or failover rules that the bonding policy should adhere to.
* The user has specified links or failover rules that the bonding policy should adhere to.
*/
else if (userHasSpecifiedSlaves()) {
fprintf(stderr, "%llu AB: (manual) no active backup slave, checking local.conf\n", ((now - RR->bc->getBondStartTime())));
if (userHasSpecifiedPrimarySlave()) {
fprintf(stderr, "%llu AB: (manual) user has specified primary slave, looking for it.\n", ((now - RR->bc->getBondStartTime())));
else if (userHasSpecifiedLinks()) {
fprintf(stderr, "%llu AB: (manual) no active backup link, checking local.conf\n", ((now - RR->bc->getBondStartTime())));
if (userHasSpecifiedPrimaryLink()) {
fprintf(stderr, "%llu AB: (manual) user has specified primary link, looking for it.\n", ((now - RR->bc->getBondStartTime())));
for (int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (!_paths[i]) {
continue;
}
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
if (_paths[i]->eligible(now,_ackSendInterval) && slave->primary()) {
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (_paths[i]->eligible(now,_ackSendInterval) && link->primary()) {
if (!_paths[i]->preferred()) {
_paths[i]->address().toString(curPathStr);
fprintf(stderr, "%llu AB: (initial) [%d] found path on primary slave, taking note in case we don't find a preferred path\n", ((now - RR->bc->getBondStartTime())), i);
fprintf(stderr, "%llu AB: (initial) [%d] found path on primary link, taking note in case we don't find a preferred path\n", ((now - RR->bc->getBondStartTime())), i);
nonPreferredPath = _paths[i];
bFoundPrimarySlave = true;
bFoundPrimaryLink = true;
}
if (_paths[i]->preferred()) {
_abPath = _paths[i];
_abPath->address().toString(curPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
if (slave) {
fprintf(stderr, "%llu AB: (initial) [%d] found preferred path %s on primary slave: %s\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, slave->ifname().c_str());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
if (link) {
fprintf(stderr, "%llu AB: (initial) [%d] found preferred path %s on primary link: %s\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, link->ifname().c_str());
}
bFoundPrimarySlave = true;
bFoundPrimaryLink = true;
break;
}
}
}
if (_abPath) {
_abPath->address().toString(curPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _abPath->localSocket());
if (slave) {
fprintf(stderr, "%llu AB: (initial) found preferred primary path: %s on %s\n", ((now - RR->bc->getBondStartTime())), curPathStr, slave->ifname().c_str());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _abPath->localSocket());
if (link) {
fprintf(stderr, "%llu AB: (initial) found preferred primary path: %s on %s\n", ((now - RR->bc->getBondStartTime())), curPathStr, link->ifname().c_str());
}
}
else {
if (bFoundPrimarySlave && nonPreferredPath) {
if (bFoundPrimaryLink && nonPreferredPath) {
fprintf(stderr, "%llu AB: (initial) found a non-preferred primary path\n", ((now - RR->bc->getBondStartTime())));
_abPath = nonPreferredPath;
}
}
if (!_abPath) {
fprintf(stderr, "%llu AB: (initial) designated primary slave is not yet ready\n", ((now - RR->bc->getBondStartTime())));
fprintf(stderr, "%llu AB: (initial) designated primary link is not yet ready\n", ((now - RR->bc->getBondStartTime())));
// TODO: Should fail-over to specified backup or just wait?
}
}
else if (!userHasSpecifiedPrimarySlave()) {
else if (!userHasSpecifiedPrimaryLink()) {
int _abIdx = ZT_MAX_PEER_NETWORK_PATHS;
fprintf(stderr, "%llu AB: (initial) user did not specify primary slave, just picking something\n", ((now - RR->bc->getBondStartTime())));
fprintf(stderr, "%llu AB: (initial) user did not specify primary link, just picking something\n", ((now - RR->bc->getBondStartTime())));
for (int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (_paths[i] && _paths[i]->eligible(now,_ackSendInterval)) {
_abIdx = i;
@ -1269,9 +1269,9 @@ void Bond::processActiveBackupTasks(const int64_t now)
}
else {
_abPath = _paths[_abIdx];
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _abPath->localSocket());
if (slave) {
fprintf(stderr, "%llu AB: (initial) selected non-primary slave idx=%d, %s on %s\n", ((now - RR->bc->getBondStartTime())), _abIdx, pathStr, slave->ifname().c_str());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _abPath->localSocket());
if (link) {
fprintf(stderr, "%llu AB: (initial) selected non-primary link idx=%d, %s on %s\n", ((now - RR->bc->getBondStartTime())), _abIdx, pathStr, link->ifname().c_str());
}
}
}
@ -1281,14 +1281,14 @@ void Bond::processActiveBackupTasks(const int64_t now)
* Update and maintain the active-backup failover queue
*/
if (_abPath) {
// Don't worry about the failover queue until we have an active slave
// Remove ineligible paths from the failover slave queue
// Don't worry about the failover queue until we have an active link
// Remove ineligible paths from the failover link queue
for (std::list<SharedPtr<Path> >::iterator it(_abFailoverQueue.begin()); it!=_abFailoverQueue.end();) {
if ((*it) && !(*it)->eligible(now,_ackSendInterval)) {
(*it)->address().toString(curPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, (*it)->localSocket());
if (slave) {
fprintf(stderr, "%llu AB: (fq) %s on %s is now ineligible, removing from failover queue\n", ((now - RR->bc->getBondStartTime())), curPathStr, slave->ifname().c_str());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, (*it)->localSocket());
if (link) {
fprintf(stderr, "%llu AB: (fq) %s on %s is now ineligible, removing from failover queue\n", ((now - RR->bc->getBondStartTime())), curPathStr, link->ifname().c_str());
}
it = _abFailoverQueue.erase(it);
} else {
@ -1313,7 +1313,7 @@ void Bond::processActiveBackupTasks(const int64_t now)
if (!_paths[i] || !_paths[i]->allowed() || !_paths[i]->eligible(now,_ackSendInterval)) {
continue;
}
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
_paths[i]->address().toString(pathStr);
int failoverScoreHandicap = _paths[i]->_failoverScore;
@ -1322,8 +1322,8 @@ void Bond::processActiveBackupTasks(const int64_t now)
failoverScoreHandicap += ZT_MULTIPATH_FAILOVER_HANDICAP_PREFERRED;
//fprintf(stderr, "%s on %s ----> %d for preferred\n", pathStr, _paths[i]->ifname().c_str(), failoverScoreHandicap);
}
if (slave->primary()) {
// If using "optimize" primary reselect mode, ignore user slave designations
if (link->primary()) {
// If using "optimize" primary reselect mode, ignore user link designations
failoverScoreHandicap += ZT_MULTIPATH_FAILOVER_HANDICAP_PRIMARY;
//fprintf(stderr, "%s on %s ----> %d for primary\n", pathStr, _paths[i]->ifname().c_str(), failoverScoreHandicap);
}
@ -1333,17 +1333,17 @@ void Bond::processActiveBackupTasks(const int64_t now)
_paths[i]->_failoverScore = newHandicap;
//fprintf(stderr, "%s on %s ----> %d for allocation\n", pathStr, _paths[i]->ifname().c_str(), newHandicap);
}
SharedPtr<Slave> failoverSlave;
if (slave->failoverToSlave().length()) {
failoverSlave = RR->bc->getSlaveByName(_policyAlias, slave->failoverToSlave());
SharedPtr<Link> failoverLink;
if (link->failoverToLink().length()) {
failoverLink = RR->bc->getLinkByName(_policyAlias, link->failoverToLink());
}
if (failoverSlave) {
if (failoverLink) {
for (int j=0; j<ZT_MAX_PEER_NETWORK_PATHS; j++) {
if (_paths[j] && getSlave(_paths[j]) == failoverSlave.ptr()) {
if (_paths[j] && getLink(_paths[j]) == failoverLink.ptr()) {
_paths[j]->address().toString(pathStr);
int inheritedHandicap = failoverScoreHandicap - 10;
int newHandicap = _paths[j]->_failoverScore > inheritedHandicap ? _paths[j]->_failoverScore : inheritedHandicap;
//fprintf(stderr, "\thanding down %s on %s ----> %d\n", pathStr, getSlave(_paths[j])->ifname().c_str(), newHandicap);
//fprintf(stderr, "\thanding down %s on %s ----> %d\n", pathStr, getLink(_paths[j])->ifname().c_str(), newHandicap);
if (!_paths[j]->preferred()) {
newHandicap--;
}
@ -1360,7 +1360,7 @@ void Bond::processActiveBackupTasks(const int64_t now)
}
if (!bFoundPathInQueue) {
_paths[i]->address().toString(curPathStr);
fprintf(stderr, "%llu AB: (fq) [%d] added %s on %s to queue\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, getSlave(_paths[i])->ifname().c_str());
fprintf(stderr, "%llu AB: (fq) [%d] added %s on %s to queue\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, getLink(_paths[i])->ifname().c_str());
_abFailoverQueue.push_front(_paths[i]);
}
}
@ -1385,8 +1385,8 @@ void Bond::processActiveBackupTasks(const int64_t now)
if (!_paths[i]->eligible(now,includeRefractoryPeriod)) {
failoverScoreHandicap = -10000;
}
if (getSlave(_paths[i])->primary() && _abSlaveSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
// If using "optimize" primary reselect mode, ignore user slave designations
if (getLink(_paths[i])->primary() && _abLinkSelectMethod != ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE) {
// If using "optimize" primary reselect mode, ignore user link designations
failoverScoreHandicap = ZT_MULTIPATH_FAILOVER_HANDICAP_PRIMARY;
}
if (_paths[i].ptr() == negotiatedPath.ptr()) {
@ -1405,7 +1405,7 @@ void Bond::processActiveBackupTasks(const int64_t now)
}
if (!bFoundPathInQueue) {
_paths[i]->address().toString(curPathStr);
fprintf(stderr, "%llu AB: (fq) [%d] added %s on %s to queue\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, getSlave(_paths[i])->ifname().c_str());
fprintf(stderr, "%llu AB: (fq) [%d] added %s on %s to queue\n", ((now - RR->bc->getBondStartTime())), i, curPathStr, getLink(_paths[i])->ifname().c_str());
_abFailoverQueue.push_front(_paths[i]);
}
}
@ -1428,11 +1428,11 @@ void Bond::processActiveBackupTasks(const int64_t now)
if (_abPath && !_abPath->eligible(now,_ackSendInterval)) { // Implicit ZT_MULTIPATH_RESELECTION_POLICY_FAILURE
_abPath->address().toString(curPathStr); fprintf(stderr, "%llu AB: (failure) failover event!, active backup path (%s) is no-longer eligible\n", ((now - RR->bc->getBondStartTime())), curPathStr);
if (!_abFailoverQueue.empty()) {
fprintf(stderr, "%llu AB: (failure) there are (%lu) slaves in queue to choose from...\n", ((now - RR->bc->getBondStartTime())), _abFailoverQueue.size());
fprintf(stderr, "%llu AB: (failure) there are (%lu) links in queue to choose from...\n", ((now - RR->bc->getBondStartTime())), _abFailoverQueue.size());
dequeueNextActiveBackupPath(now);
_abPath->address().toString(curPathStr); fprintf(stderr, "%llu AB: (failure) switched to %s on %s\n", ((now - RR->bc->getBondStartTime())), curPathStr, getSlave(_abPath)->ifname().c_str());
_abPath->address().toString(curPathStr); fprintf(stderr, "%llu AB: (failure) switched to %s on %s\n", ((now - RR->bc->getBondStartTime())), curPathStr, getLink(_abPath)->ifname().c_str());
} else {
fprintf(stderr, "%llu AB: (failure) nothing available in the slave queue, doing nothing.\n", ((now - RR->bc->getBondStartTime())));
fprintf(stderr, "%llu AB: (failure) nothing available in the link queue, doing nothing.\n", ((now - RR->bc->getBondStartTime())));
}
}
/**
@ -1441,38 +1441,38 @@ void Bond::processActiveBackupTasks(const int64_t now)
if (prevActiveBackupPath != _abPath) {
_lastActiveBackupPathChange = now;
}
if (_abSlaveSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_ALWAYS) {
if (_abPath && !getSlave(_abPath)->primary()
&& getSlave(_abFailoverQueue.front())->primary()) {
if (_abLinkSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_ALWAYS) {
if (_abPath && !getLink(_abPath)->primary()
&& getLink(_abFailoverQueue.front())->primary()) {
fprintf(stderr, "%llu AB: (always) switching to available primary\n", ((now - RR->bc->getBondStartTime())));
dequeueNextActiveBackupPath(now);
}
}
if (_abSlaveSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_BETTER) {
if (_abPath && !getSlave(_abPath)->primary()) {
fprintf(stderr, "%llu AB: (better) active backup has switched to \"better\" primary slave according to re-select policy.\n", ((now - RR->bc->getBondStartTime())));
if (getSlave(_abFailoverQueue.front())->primary()
if (_abLinkSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_BETTER) {
if (_abPath && !getLink(_abPath)->primary()) {
fprintf(stderr, "%llu AB: (better) active backup has switched to \"better\" primary link according to re-select policy.\n", ((now - RR->bc->getBondStartTime())));
if (getLink(_abFailoverQueue.front())->primary()
&& (_abFailoverQueue.front()->_failoverScore > _abPath->_failoverScore)) {
dequeueNextActiveBackupPath(now);
fprintf(stderr, "%llu AB: (better) switched back to user-defined primary\n", ((now - RR->bc->getBondStartTime())));
}
}
}
if (_abSlaveSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE && !_abFailoverQueue.empty()) {
if (_abLinkSelectMethod == ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE && !_abFailoverQueue.empty()) {
/**
* Implement link negotiation that was previously-decided
*/
if (_abFailoverQueue.front()->_negotiated) {
dequeueNextActiveBackupPath(now);
_abPath->address().toString(prevPathStr);
fprintf(stderr, "%llu AB: (optimize) switched to negotiated path %s on %s\n", ((now - RR->bc->getBondStartTime())), prevPathStr, getSlave(_abPath)->ifname().c_str());
fprintf(stderr, "%llu AB: (optimize) switched to negotiated path %s on %s\n", ((now - RR->bc->getBondStartTime())), prevPathStr, getLink(_abPath)->ifname().c_str());
_lastPathNegotiationCheck = now;
}
else {
// Try to find a better path and automatically switch to it -- not too often, though.
if ((now - _lastActiveBackupPathChange) > ZT_MULTIPATH_MIN_ACTIVE_BACKUP_AUTOFLOP_INTERVAL) {
if (!_abFailoverQueue.empty()) {
//fprintf(stderr, "AB: (optimize) there are (%d) slaves in queue to choose from...\n", _abFailoverQueue.size());
//fprintf(stderr, "AB: (optimize) there are (%d) links in queue to choose from...\n", _abFailoverQueue.size());
int newFScore = _abFailoverQueue.front()->_failoverScore;
int prevFScore = _abPath->_failoverScore;
// Establish a minimum switch threshold to prevent flapping
@ -1483,7 +1483,7 @@ void Bond::processActiveBackupTasks(const int64_t now)
_abPath->address().toString(prevPathStr);
dequeueNextActiveBackupPath(now);
_abPath->address().toString(curPathStr);
fprintf(stderr, "%llu AB: (optimize) switched from %s on %s (fs=%d) to %s on %s (fs=%d)\n", ((now - RR->bc->getBondStartTime())), prevPathStr, getSlave(oldPath)->ifname().c_str(), prevFScore, curPathStr, getSlave(_abPath)->ifname().c_str(), newFScore);
fprintf(stderr, "%llu AB: (optimize) switched from %s on %s (fs=%d) to %s on %s (fs=%d)\n", ((now - RR->bc->getBondStartTime())), prevPathStr, getLink(oldPath)->ifname().c_str(), prevFScore, curPathStr, getLink(_abPath)->ifname().c_str(), newFScore);
}
}
}
@ -1527,7 +1527,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
_lastFlowExpirationCheck=0;
_numBondedPaths=0;
_rrPacketsSentOnCurrSlave=0;
_rrPacketsSentOnCurrLink=0;
_rrIdx=0;
_lastFlowRebalance=0;
@ -1537,7 +1537,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
_maxAcceptablePacketDelayVariance = 50;
_maxAcceptablePacketLossRatio = 0.10;
_maxAcceptablePacketErrorRatio = 0.10;
_userHasSpecifiedSlaveSpeeds=0;
_userHasSpecifiedLinkSpeeds=0;
_lastFrame=0;
@ -1553,8 +1553,8 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
switch (policy) {
case ZT_BONDING_POLICY_ACTIVE_BACKUP:
_failoverInterval = 500;
_abSlaveSelectMethod = ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE;
_slaveMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_abLinkSelectMethod = ZT_MULTIPATH_RESELECTION_POLICY_OPTIMIZE;
_linkMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_qualityWeights[ZT_QOS_LAT_IDX] = 0.2f;
_qualityWeights[ZT_QOS_LTM_IDX] = 0.0f;
_qualityWeights[ZT_QOS_PDV_IDX] = 0.2f;
@ -1578,8 +1578,8 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
case ZT_BONDING_POLICY_BALANCE_RR:
_failoverInterval = 500;
_allowFlowHashing = false;
_packetsPerSlave = 1024;
_slaveMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_packetsPerLink = 1024;
_linkMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_qualityWeights[ZT_QOS_LAT_IDX] = 0.4f;
_qualityWeights[ZT_QOS_LTM_IDX] = 0.0f;
_qualityWeights[ZT_QOS_PDV_IDX] = 0.2f;
@ -1598,7 +1598,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
_failoverInterval = 500;
_upDelay = _bondMonitorInterval * 2;
_allowFlowHashing = true;
_slaveMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_linkMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_qualityWeights[ZT_QOS_LAT_IDX] = 0.4f;
_qualityWeights[ZT_QOS_LTM_IDX] = 0.0f;
_qualityWeights[ZT_QOS_PDV_IDX] = 0.2f;
@ -1617,7 +1617,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
case ZT_BONDING_POLICY_BALANCE_AWARE:
_failoverInterval = 3000;
_allowFlowHashing = true;
_slaveMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_linkMonitorStrategy = ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_DYNAMIC;
_qualityWeights[ZT_QOS_LAT_IDX] = 0.4f;
_qualityWeights[ZT_QOS_LTM_IDX] = 0.0f;
_qualityWeights[ZT_QOS_PDV_IDX] = 0.4f;
@ -1641,7 +1641,7 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
_upDelay = templateBond->_upDelay;
fprintf(stderr, "TIMERS: strat=%d, fi= %d, bmi= %d, qos= %d, ack= %d, estimateInt= %d, refractory= %d, ud= %d, dd= %d\n",
_slaveMonitorStrategy,
_linkMonitorStrategy,
_failoverInterval,
_bondMonitorInterval,
_qosSendInterval,
@ -1651,11 +1651,11 @@ void Bond::setReasonableDefaults(int policy, SharedPtr<Bond> templateBond, bool
_upDelay,
_downDelay);
if (templateBond->_slaveMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_PASSIVE
if (templateBond->_linkMonitorStrategy == ZT_MULTIPATH_SLAVE_MONITOR_STRATEGY_PASSIVE
&& templateBond->_failoverInterval != 0) {
fprintf(stderr, "warning: passive path monitoring was specified, this will prevent failovers from happening in a timely manner.\n");
}
_abSlaveSelectMethod = templateBond->_abSlaveSelectMethod;
_abLinkSelectMethod = templateBond->_abLinkSelectMethod;
memcpy(_qualityWeights, templateBond->_qualityWeights, ZT_QOS_WEIGHT_SIZE * sizeof(float));
}
@ -1711,9 +1711,9 @@ bool Bond::relevant() {
|| _peer->identity().address().toInt() == 0x795cbf86fa;
}
SharedPtr<Slave> Bond::getSlave(const SharedPtr<Path>& path)
SharedPtr<Link> Bond::getLink(const SharedPtr<Path>& path)
{
return RR->bc->getSlaveBySocket(_policyAlias, path->localSocket());
return RR->bc->getLinkBySocket(_policyAlias, path->localSocket());
}
void Bond::dumpInfo(const int64_t now)
@ -1726,12 +1726,12 @@ void Bond::dumpInfo(const int64_t now)
return;
}
/*
fprintf(stderr, "---[ bp=%d, id=%llx, dd=%d, up=%d, pmi=%d, specifiedSlaves=%d, _specifiedPrimarySlave=%d, _specifiedFailInst=%d ]\n",
_policy, _peer->identity().address().toInt(), _downDelay, _upDelay, _monitorInterval, _userHasSpecifiedSlaves, _userHasSpecifiedPrimarySlave, _userHasSpecifiedFailoverInstructions);
fprintf(stderr, "---[ bp=%d, id=%llx, dd=%d, up=%d, pmi=%d, specifiedLinks=%d, _specifiedPrimaryLink=%d, _specifiedFailInst=%d ]\n",
_policy, _peer->identity().address().toInt(), _downDelay, _upDelay, _monitorInterval, _userHasSpecifiedLinks, _userHasSpecifiedPrimaryLink, _userHasSpecifiedFailoverInstructions);
if (_bondingPolicy == ZT_BONDING_POLICY_ACTIVE_BACKUP) {
fprintf(stderr, "Paths (bp=%d, stats=%d, primaryReselect=%d) :\n",
_policy, _shouldCollectPathStatistics, _abSlaveSelectMethod);
_policy, _shouldCollectPathStatistics, _abLinkSelectMethod);
}
if (_bondingPolicy == ZT_BONDING_POLICY_BALANCE_RR
|| _bondingPolicy == ZT_BONDING_POLICY_BALANCE_XOR
@ -1748,13 +1748,13 @@ void Bond::dumpInfo(const int64_t now)
for(int i=0; i<ZT_MAX_PEER_NETWORK_PATHS; ++i) {
if (_paths[i]) {
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[i]->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[i]->localSocket());
_paths[i]->address().toString(pathStr);
fprintf(stderr, " %2d: lat=%8.3f, ac=%3d, fail%5s, fscore=%6d, in=%7d, out=%7d, age=%7ld, ack=%7ld, ref=%6d, ls=%llx",
i,
_paths[i]->_latencyMean,
_paths[i]->_allocation,
slave->failoverToSlave().c_str(),
link->failoverToLink().c_str(),
_paths[i]->_failoverScore,
_paths[i]->_packetsIn,
_paths[i]->_packetsOut,
@ -1763,12 +1763,12 @@ void Bond::dumpInfo(const int64_t now)
_paths[i]->_refractoryPeriod,
_paths[i]->localSocket()
);
if (slave->spare()) {
if (link->spare()) {
fprintf(stderr, " SPR.");
} else {
fprintf(stderr, " ");
}
if (slave->primary()) {
if (link->primary()) {
fprintf(stderr, " PRIM.");
} else {
fprintf(stderr, " ");
@ -1808,7 +1808,7 @@ void Bond::dumpInfo(const int64_t now)
} else if (_bondingPolicy == ZT_BONDING_POLICY_ACTIVE_BACKUP) {
fprintf(stderr, " ");
}
fprintf(stderr, "%5s %s\n", slave->ifname().c_str(), pathStr);
fprintf(stderr, "%5s %s\n", link->ifname().c_str(), pathStr);
}
}
@ -1817,12 +1817,12 @@ void Bond::dumpInfo(const int64_t now)
fprintf(stderr, "\nFailover Queue:\n");
for (std::list<SharedPtr<Path> >::iterator it(_abFailoverQueue.begin()); it!=_abFailoverQueue.end();++it) {
(*it)->address().toString(currPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, (*it)->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, (*it)->localSocket());
fprintf(stderr, "\t%8s\tspeed=%7d\trelSpeed=%3d\tipvPref=%3d\tfscore=%9d\t\t%s\n",
slave->ifname().c_str(),
slave->speed(),
slave->relativeSpeed(),
slave->ipvPref(),
link->ifname().c_str(),
link->speed(),
link->relativeSpeed(),
link->ipvPref(),
(*it)->_failoverScore,
currPathStr);
}
@ -1840,15 +1840,15 @@ void Bond::dumpInfo(const int64_t now)
fprintf(stderr, "\nBonded Paths:\n");
for (int i=0; i<_numBondedPaths; ++i) {
_paths[_bondedIdx[i]]->address().toString(currPathStr);
SharedPtr<Slave> slave =RR->bc->getSlaveBySocket(_policyAlias, _paths[_bondedIdx[i]]->localSocket());
SharedPtr<Link> link =RR->bc->getLinkBySocket(_policyAlias, _paths[_bondedIdx[i]]->localSocket());
fprintf(stderr, " [%d]\t%8s\tflows=%3d\tspeed=%7d\trelSpeed=%3d\tipvPref=%3d\tfscore=%9d\t\t%s\n", i,
//fprintf(stderr, " [%d]\t%8s\tspeed=%7d\trelSpeed=%3d\tflowCount=%2d\tipvPref=%3d\tfscore=%9d\t\t%s\n", i,
slave->ifname().c_str(),
link->ifname().c_str(),
_paths[_bondedIdx[i]]->_assignedFlowCount,
slave->speed(),
slave->relativeSpeed(),
link->speed(),
link->relativeSpeed(),
//_paths[_bondedIdx[i]].p->assignedFlows.size(),
slave->ipvPref(),
link->ipvPref(),
_paths[_bondedIdx[i]]->_failoverScore,
currPathStr);
}

View file

@ -18,13 +18,13 @@
#include "Path.hpp"
#include "Peer.hpp"
#include "../osdep/Slave.hpp"
#include "../osdep/Link.hpp"
#include "Flow.hpp"
namespace ZeroTier {
class RuntimeEnvironment;
class Slave;
class Link;
class Bond
{
@ -52,7 +52,7 @@ public:
void dumpInfo(const int64_t now);
bool relevant();
SharedPtr<Slave> getSlave(const SharedPtr<Path>& path);
SharedPtr<Link> getLink(const SharedPtr<Path>& path);
/**
* Constructor. Creates a bond based off of ZT defaults
@ -281,7 +281,7 @@ public:
void processActiveBackupTasks(int64_t now);
/**
* Switches the active slave in an active-backup scenario to the next best during
* Switches the active link in an active-backup scenario to the next best during
* a failover event.
*
* @param now Current time
@ -348,24 +348,24 @@ public:
}
/**
* @return Whether the user has defined slaves for use on this bond
* @return Whether the user has defined links for use on this bond
*/
inline bool userHasSpecifiedSlaves() { return _userHasSpecifiedSlaves; }
inline bool userHasSpecifiedLinks() { return _userHasSpecifiedLinks; }
/**
* @return Whether the user has defined a set of failover slave(s) for this bond
* @return Whether the user has defined a set of failover link(s) for this bond
*/
inline bool userHasSpecifiedFailoverInstructions() { return _userHasSpecifiedFailoverInstructions; };
/**
* @return Whether the user has specified a primary slave
* @return Whether the user has specified a primary link
*/
inline bool userHasSpecifiedPrimarySlave() { return _userHasSpecifiedPrimarySlave; }
inline bool userHasSpecifiedPrimaryLink() { return _userHasSpecifiedPrimaryLink; }
/**
* @return Whether the user has specified slave speeds
* @return Whether the user has specified link speeds
*/
inline bool userHasSpecifiedSlaveSpeeds() { return _userHasSpecifiedSlaveSpeeds; }
inline bool userHasSpecifiedLinkSpeeds() { return _userHasSpecifiedLinkSpeeds; }
/**
* Periodically perform maintenance tasks for each active bond.
@ -441,7 +441,7 @@ public:
/**
* @param strategy Strategy that the bond uses to prob for path aliveness and quality
*/
inline void setSlaveMonitorStrategy(uint8_t strategy) { _slaveMonitorStrategy = strategy; }
inline void setLinkMonitorStrategy(uint8_t strategy) { _linkMonitorStrategy = strategy; }
/**
* @return the current up delay parameter
@ -464,12 +464,12 @@ public:
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 slaves.)
* @return the current monitoring interval for the bond (can be overridden with intervals specific to certain links.)
*/
inline uint16_t getBondMonitorInterval() { return _bondMonitorInterval; }
/**
* Set the current monitoring interval for the bond (can be overridden with intervals specific to certain slaves.)
* 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.
*/
@ -498,21 +498,21 @@ public:
/**
*
* @param packetsPerSlave
* @param packetsPerLink
*/
inline void setPacketsPerSlave(int packetsPerSlave) { _packetsPerSlave = packetsPerSlave; }
inline void setPacketsPerLink(int packetsPerLink) { _packetsPerLink = packetsPerLink; }
/**
*
* @param slaveSelectMethod
* @param linkSelectMethod
*/
inline void setSlaveSelectMethod(uint8_t method) { _abSlaveSelectMethod = method; }
inline void setLinkSelectMethod(uint8_t method) { _abLinkSelectMethod = method; }
/**
*
* @return
*/
inline uint8_t getSlaveSelectMethod() { return _abSlaveSelectMethod; }
inline uint8_t getLinkSelectMethod() { return _abLinkSelectMethod; }
/**
*
@ -568,25 +568,25 @@ private:
// active-backup
SharedPtr<Path> _abPath; // current active path
std::list<SharedPtr<Path> > _abFailoverQueue;
uint8_t _abSlaveSelectMethod; // slave re-selection policy for the primary slave in active-backup
uint8_t _abLinkSelectMethod; // link re-selection policy for the primary link in active-backup
uint64_t _lastActiveBackupPathChange;
// balance-rr
uint8_t _rrIdx; // index to path currently in use during Round Robin operation
uint16_t _rrPacketsSentOnCurrSlave; // number of packets sent on this slave since the most recent path switch.
uint16_t _rrPacketsSentOnCurrLink; // number of packets sent on this link since the most recent path switch.
/**
* How many packets will be sent on a path before moving to the next path
* in the round-robin sequence. A value of zero will cause a random path
* selection for each outgoing packet.
*/
int _packetsPerSlave;
int _packetsPerLink;
// balance-aware
uint64_t _totalBondUnderload;
uint8_t _flowRebalanceStrategy;
// dynamic slave monitoring
uint8_t _slaveMonitorStrategy;
// dynamic link monitoring
uint8_t _linkMonitorStrategy;
uint64_t _lastFrame;
uint32_t _dynamicPathMonitorInterval;
@ -651,14 +651,14 @@ private:
Mutex _flows_m;
/**
* Whether the user has specified slaves for this bond.
* Whether the user has specified links for this bond.
*/
bool _userHasSpecifiedSlaves;
bool _userHasSpecifiedLinks;
/**
* Whether the user has specified a primary slave for this bond.
* Whether the user has specified a primary link for this bond.
*/
bool _userHasSpecifiedPrimarySlave;
bool _userHasSpecifiedPrimaryLink;
/**
* Whether the user has specified failover instructions for this bond.
@ -666,9 +666,9 @@ private:
bool _userHasSpecifiedFailoverInstructions;
/**
* Whether the user has specified slaves speeds for this bond.
* Whether the user has specified links speeds for this bond.
*/
bool _userHasSpecifiedSlaveSpeeds;
bool _userHasSpecifiedLinkSpeeds;
/**
* How frequently (in ms) a VERB_ECHO is sent to a peer to verify that a

View file

@ -27,33 +27,33 @@ BondController::BondController(const RuntimeEnvironment *renv) :
_defaultBondingPolicy = ZT_BONDING_POLICY_NONE;
}
bool BondController::slaveAllowed(std::string &policyAlias, SharedPtr<Slave> slave)
bool BondController::linkAllowed(std::string &policyAlias, SharedPtr<Link> link)
{
bool foundInDefinitions = false;
if (_slaveDefinitions.count(policyAlias)) {
auto it = _slaveDefinitions[policyAlias].begin();
while (it != _slaveDefinitions[policyAlias].end()) {
if (slave->ifname() == (*it)->ifname()) {
if (_linkDefinitions.count(policyAlias)) {
auto it = _linkDefinitions[policyAlias].begin();
while (it != _linkDefinitions[policyAlias].end()) {
if (link->ifname() == (*it)->ifname()) {
foundInDefinitions = true;
break;
}
++it;
}
}
return _slaveDefinitions[policyAlias].empty() || foundInDefinitions;
return _linkDefinitions[policyAlias].empty() || foundInDefinitions;
}
void BondController::addCustomSlave(std::string& policyAlias, SharedPtr<Slave> slave)
void BondController::addCustomLink(std::string& policyAlias, SharedPtr<Link> link)
{
Mutex::Lock _l(_slaves_m);
_slaveDefinitions[policyAlias].push_back(slave);
auto search = _interfaceToSlaveMap[policyAlias].find(slave->ifname());
if (search == _interfaceToSlaveMap[policyAlias].end()) {
slave->setAsUserSpecified(true);
_interfaceToSlaveMap[policyAlias].insert(std::pair<std::string, SharedPtr<Slave>>(slave->ifname(), slave));
Mutex::Lock _l(_links_m);
_linkDefinitions[policyAlias].push_back(link);
auto search = _interfaceToLinkMap[policyAlias].find(link->ifname());
if (search == _interfaceToLinkMap[policyAlias].end()) {
link->setAsUserSpecified(true);
_interfaceToLinkMap[policyAlias].insert(std::pair<std::string, SharedPtr<Link>>(link->ifname(), link));
} else {
fprintf(stderr, "slave already exists=%s\n", slave->ifname().c_str());
// Slave is already defined, overlay user settings
fprintf(stderr, "link already exists=%s\n", link->ifname().c_str());
// Link is already defined, overlay user settings
}
}
@ -115,20 +115,20 @@ SharedPtr<Bond> BondController::createTransportTriggeredBond(const RuntimeEnviro
/**
* Determine if user has specified anything that could affect the bonding policy's decisions
*/
if (_interfaceToSlaveMap.count(bond->policyAlias())) {
std::map<std::string, SharedPtr<Slave> >::iterator it = _interfaceToSlaveMap[bond->policyAlias()].begin();
while (it != _interfaceToSlaveMap[bond->policyAlias()].end()) {
if (_interfaceToLinkMap.count(bond->policyAlias())) {
std::map<std::string, SharedPtr<Link> >::iterator it = _interfaceToLinkMap[bond->policyAlias()].begin();
while (it != _interfaceToLinkMap[bond->policyAlias()].end()) {
if (it->second->isUserSpecified()) {
bond->_userHasSpecifiedSlaves = true;
bond->_userHasSpecifiedLinks = true;
}
if (it->second->isUserSpecified() && it->second->primary()) {
bond->_userHasSpecifiedPrimarySlave = true;
bond->_userHasSpecifiedPrimaryLink = true;
}
if (it->second->isUserSpecified() && it->second->userHasSpecifiedFailoverInstructions()) {
bond->_userHasSpecifiedFailoverInstructions = true;
}
if (it->second->isUserSpecified() && (it->second->speed() > 0)) {
bond->_userHasSpecifiedSlaveSpeeds = true;
bond->_userHasSpecifiedLinkSpeeds = true;
}
++it;
}
@ -138,16 +138,16 @@ SharedPtr<Bond> BondController::createTransportTriggeredBond(const RuntimeEnviro
return SharedPtr<Bond>();
}
SharedPtr<Slave> BondController::getSlaveBySocket(const std::string& policyAlias, uint64_t localSocket)
SharedPtr<Link> BondController::getLinkBySocket(const std::string& policyAlias, uint64_t localSocket)
{
Mutex::Lock _l(_slaves_m);
Mutex::Lock _l(_links_m);
char ifname[16];
_phy->getIfName((PhySocket *) ((uintptr_t)localSocket), ifname, 16);
std::string ifnameStr(ifname);
auto search = _interfaceToSlaveMap[policyAlias].find(ifnameStr);
if (search == _interfaceToSlaveMap[policyAlias].end()) {
SharedPtr<Slave> s = new Slave(ifnameStr, 0, 0, 0, 0, 0, true, ZT_MULTIPATH_SLAVE_MODE_SPARE, "", 0.0);
_interfaceToSlaveMap[policyAlias].insert(std::pair<std::string,SharedPtr<Slave> >(ifnameStr, s));
auto search = _interfaceToLinkMap[policyAlias].find(ifnameStr);
if (search == _interfaceToLinkMap[policyAlias].end()) {
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));
return s;
}
else {
@ -155,14 +155,14 @@ SharedPtr<Slave> BondController::getSlaveBySocket(const std::string& policyAlias
}
}
SharedPtr<Slave> BondController::getSlaveByName(const std::string& policyAlias, const std::string& ifname)
SharedPtr<Link> BondController::getLinkByName(const std::string& policyAlias, const std::string& ifname)
{
Mutex::Lock _l(_slaves_m);
auto search = _interfaceToSlaveMap[policyAlias].find(ifname);
if (search != _interfaceToSlaveMap[policyAlias].end()) {
Mutex::Lock _l(_links_m);
auto search = _interfaceToLinkMap[policyAlias].find(ifname);
if (search != _interfaceToLinkMap[policyAlias].end()) {
return search->second;
}
return SharedPtr<Slave>();
return SharedPtr<Link>();
}
bool BondController::allowedToBind(const std::string& ifname)
@ -172,18 +172,18 @@ bool BondController::allowedToBind(const std::string& ifname)
if (!_defaultBondingPolicy) {
return true; // no restrictions
}
Mutex::Lock _l(_slaves_m);
if (_interfaceToSlaveMap.empty()) {
Mutex::Lock _l(_links_m);
if (_interfaceToLinkMap.empty()) {
return true; // no restrictions
}
std::map<std::string, std::map<std::string, SharedPtr<Slave> > >::iterator policyItr = _interfaceToSlaveMap.begin();
while (policyItr != _interfaceToSlaveMap.end()) {
std::map<std::string, SharedPtr<Slave> >::iterator slaveItr = policyItr->second.begin();
while (slaveItr != policyItr->second.end()) {
if (slaveItr->first == ifname) {
std::map<std::string, std::map<std::string, SharedPtr<Link> > >::iterator policyItr = _interfaceToLinkMap.begin();
while (policyItr != _interfaceToLinkMap.end()) {
std::map<std::string, SharedPtr<Link> >::iterator linkItr = policyItr->second.begin();
while (linkItr != policyItr->second.end()) {
if (linkItr->first == ifname) {
return true;
}
++slaveItr;
++linkItr;
}
++policyItr;
}

View file

@ -19,7 +19,7 @@
#include "SharedPtr.hpp"
#include "../osdep/Phy.hpp"
#include "../osdep/Slave.hpp"
#include "../osdep/Link.hpp"
namespace ZeroTier {
@ -36,9 +36,9 @@ public:
BondController(const RuntimeEnvironment *renv);
/**
* @return Whether this slave is permitted to become a member of a bond.
* @return Whether this link is permitted to become a member of a bond.
*/
bool slaveAllowed(std::string &policyAlias, SharedPtr<Slave> slave);
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.
@ -103,12 +103,12 @@ public:
static int defaultBondingPolicy() { return _defaultBondingPolicy; }
/**
* Add a user-defined slave to a given bonding policy.
* Add a user-defined link to a given bonding policy.
*
* @param policyAlias User-defined custom name for variant of bonding policy
* @param slave Pointer to new slave definition
* @param link Pointer to new link definition
*/
void addCustomSlave(std::string& policyAlias, SharedPtr<Slave> slave);
void addCustomLink(std::string& policyAlias, SharedPtr<Link> link);
/**
* Add a user-defined bonding policy that is based on one of the standard types.
@ -145,22 +145,22 @@ public:
void processBackgroundTasks(void *tPtr, int64_t now);
/**
* Gets a reference to a physical slave 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.
*
* @param policyAlias Policy in use
* @param localSocket Local source socket
* @return Physical slave definition
* @return Physical link definition
*/
SharedPtr<Slave> getSlaveBySocket(const std::string& policyAlias, uint64_t localSocket);
SharedPtr<Link> getLinkBySocket(const std::string& policyAlias, uint64_t localSocket);
/**
* Gets a reference to a physical slave definition given its human-readable system name.
* Gets a reference to a physical link definition given its human-readable system name.
*
* @param policyAlias Policy in use
* @param ifname Alphanumeric human-readable name
* @return Physical slave definition
* @return Physical link definition
*/
SharedPtr<Slave> getSlaveByName(const std::string& policyAlias, const std::string& ifname);
SharedPtr<Link> getLinkByName(const std::string& policyAlias, const std::string& ifname);
/**
* @param ifname Name of interface that we want to know if we can bind to
@ -175,7 +175,7 @@ private:
const RuntimeEnvironment *RR;
Mutex _bonds_m;
Mutex _slaves_m;
Mutex _links_m;
/**
* The last time that the bond controller updated the set of bonds.
@ -213,14 +213,14 @@ private:
std::map<std::string,SharedPtr<Bond> > _bondPolicyTemplates;
/**
* Set of slaves defined for a given bonding policy
* Set of links defined for a given bonding policy
*/
std::map<std::string,std::vector<SharedPtr<Slave> > > _slaveDefinitions;
std::map<std::string,std::vector<SharedPtr<Link> > > _linkDefinitions;
/**
* Set of slave objects mapped to their physical interfaces
* Set of link objects mapped to their physical interfaces
*/
std::map<std::string, std::map<std::string, SharedPtr<Slave> > > _interfaceToSlaveMap;
std::map<std::string, std::map<std::string, SharedPtr<Link> > > _interfaceToLinkMap;
// TODO: Remove
uint64_t bondStartTime;

View file

@ -405,12 +405,12 @@
#define ZT_FLOW_MAX_COUNT (1024*64)
/**
* How often flows are rebalanced across slave interfaces (if at all)
* How often flows are rebalanced across link (if at all)
*/
#define ZT_FLOW_MIN_REBALANCE_INTERVAL 5000
/**
* How often flows are rebalanced across slave interfaces (if at all)
* How often flows are rebalanced across link (if at all)
*/
#define ZT_FLOW_REBALANCE_INTERVAL 5000
@ -428,7 +428,7 @@
/**
* Minimum amount of time (since a previous transition) before the active-backup bonding
* policy is allowed to transition to a different slave. Only valid for active-backup.
* policy is allowed to transition to a different link. Only valid for active-backup.
*/
#define ZT_MULTIPATH_MIN_ACTIVE_BACKUP_AUTOFLOP_INTERVAL 10000

View file

@ -501,14 +501,12 @@ ZT_PeerList *Node::peers() const
p->pathCount = 0;
for(std::vector< SharedPtr<Path> >::iterator path(paths.begin());path!=paths.end();++path) {
memcpy(&(p->paths[p->pathCount].address),&((*path)->address()),sizeof(struct sockaddr_storage));
//memcpy(&(p->paths[p->pathCount].ifname,&((*path)->slave()),32);)
p->paths[p->pathCount].localSocket = (*path)->localSocket();
p->paths[p->pathCount].lastSend = (*path)->lastOut();
p->paths[p->pathCount].lastReceive = (*path)->lastIn();
p->paths[p->pathCount].trustedPathId = RR->topology->getOutboundPathTrust((*path)->address());
p->paths[p->pathCount].expired = 0;
p->paths[p->pathCount].preferred = ((*path) == bestp) ? 1 : 0;
//p->paths[p->pathCount].age = (*path)->age(_now);
p->paths[p->pathCount].scope = (*path)->ipScope();
++p->pathCount;
}

View file

@ -29,7 +29,7 @@
#include "Packet.hpp"
#include "RingBuffer.hpp"
#include "../osdep/Slave.hpp"
#include "../osdep/Link.hpp"
/**
* Maximum return value of preferenceRank()
@ -103,7 +103,7 @@ public:
_downDelay(0),
_ipvPref(0),
_mode(0),
_onlyPathOnSlave(false),
_onlyPathOnLink(false),
_enabled(false),
_bonded(false),
_negotiated(false),
@ -152,7 +152,7 @@ public:
_downDelay(0),
_ipvPref(0),
_mode(0),
_onlyPathOnSlave(false),
_onlyPathOnLink(false),
_enabled(false),
_bonded(false),
_negotiated(false),
@ -431,10 +431,10 @@ public:
}
/**
* @return True if a path is preferred over another on the same physical slave (according to user pref.)
* @return True if a path is preferred over another on the same physical link (according to user pref.)
*/
inline bool preferred() {
return _onlyPathOnSlave
return _onlyPathOnLink
|| (_addr.isV4() && (_ipvPref == 4 || _ipvPref == 46))
|| (_addr.isV6() && (_ipvPref == 6 || _ipvPref == 64));
}
@ -549,22 +549,22 @@ private:
uint32_t _downDelay;
/**
* IP version preference inherited from the physical slave.
* IP version preference inherited from the physical link.
*/
uint8_t _ipvPref;
/**
* Mode inherited from the physical slave.
* Mode inherited from the physical link.
*/
uint8_t _mode;
/**
* IP version preference inherited from the physical slave.
* IP version preference inherited from the physical link.
*/
bool _onlyPathOnSlave;
bool _onlyPathOnLink;
/**
* Enabled state inherited from the physical slave.
* Enabled state inherited from the physical link.
*/
bool _enabled;

View file

@ -55,8 +55,8 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident
_remoteMultipathSupported(false),
_canUseMultipath(false),
_shouldCollectPathStatistics(0),
_lastComputedAggregateMeanLatency(0),
_bondingPolicy(0)
_bondingPolicy(0),
_lastComputedAggregateMeanLatency(0)
{
if (!myIdentity.agree(peerIdentity,_key,ZT_PEER_SECRET_KEY_LENGTH)) {
throw ZT_EXCEPTION_INVALID_ARGUMENT;