Browse Source

Added call to computeAggregateAllocation() in multipath mode=1 to give realtime allocation output

Joseph Henry 6 years ago
parent
commit
3c7e25ed58
2 changed files with 12 additions and 4 deletions
  1. 11 3
      node/Peer.cpp
  2. 1 1
      node/Peer.hpp

+ 11 - 3
node/Peer.cpp

@@ -275,7 +275,7 @@ void Peer::recordIncomingPacket(void *tPtr, const SharedPtr<Path> &path, const u
 	}
 }
 
-void Peer::computeAggregateProportionalAllocation(int64_t now)
+void Peer::computeAggregateAllocation(int64_t now)
 {
 	float maxStability = 0;
 	float totalRelativeQuality = 0;
@@ -318,7 +318,13 @@ void Peer::computeAggregateProportionalAllocation(int64_t now)
 	// Convert set of relative performances into an allocation set
 	for(uint16_t i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
 		if (_paths[i].p) {
-			_paths[i].p->updateComponentAllocationOfAggregateLink((unsigned char)((_paths[i].p->relativeQuality() / totalRelativeQuality) * 255));
+
+			if (RR->node->getMultipathMode() == ZT_MULTIPATH_RANDOM) {
+				_paths[i].p->updateComponentAllocationOfAggregateLink(((float)_pathChoiceHist.countValue(i) / (float)_pathChoiceHist.count()) * 255);
+			}
+			if (RR->node->getMultipathMode() == ZT_MULTIPATH_PROPORTIONALLY_BALANCED) {
+				_paths[i].p->updateComponentAllocationOfAggregateLink((unsigned char)((_paths[i].p->relativeQuality() / totalRelativeQuality) * 255));
+			}
 		}
 	}
 }
@@ -415,6 +421,7 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
 	int numAlivePaths = 0;
 	int numStalePaths = 0;
 	if (RR->node->getMultipathMode() == ZT_MULTIPATH_RANDOM) {
+		computeAggregateAllocation(now); /* This call is algorithmically inert but gives us a value to show in the status output */
 		int alivePaths[ZT_MAX_PEER_NETWORK_PATHS];
 		int stalePaths[ZT_MAX_PEER_NETWORK_PATHS];
 		memset(&alivePaths, -1, sizeof(alivePaths));
@@ -434,6 +441,7 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
 		unsigned int r = _freeRandomByte;
 		if (numAlivePaths > 0) {
 			int rf = r % numAlivePaths;
+			_pathChoiceHist.push(alivePaths[rf]); // Record which path we chose
 			return _paths[alivePaths[rf]].p;
 		}
 		else if(numStalePaths > 0) {
@@ -449,7 +457,7 @@ SharedPtr<Path> Peer::getAppropriatePath(int64_t now, bool includeExpired)
 	if (RR->node->getMultipathMode() == ZT_MULTIPATH_PROPORTIONALLY_BALANCED) {
 		if ((now - _lastAggregateAllocation) >= ZT_PATH_QUALITY_COMPUTE_INTERVAL) {
 			_lastAggregateAllocation = now;
-			computeAggregateProportionalAllocation(now);
+			computeAggregateAllocation(now);
 		}
 		// Randomly choose path according to their allocations
 		float rf = _freeRandomByte;

+ 1 - 1
node/Peer.hpp

@@ -194,7 +194,7 @@ public:
 	 *
 	 * @param now Current time
 	 */
-	void computeAggregateProportionalAllocation(int64_t now);
+	void computeAggregateAllocation(int64_t now);
 
 	/**
 	 * @return The aggregate link Packet Delay Variance (PDV)