IEnumerator GenerationRoutine() { float randomStartDelay = Random.Range(0f, .25f); yield return(new WaitForSeconds(randomStartDelay)); float generationTime = MulticastManager.getInstanceOf().interestGenerationRate; int interestMax = MulticastManager.getInstanceOf().interestGenerationCount; int count = 0; StartCoroutine(ListenRoutine()); while (count < interestMax) { for (int i = 0; i < interest_window; i++) { Packet message = new Packet("/test/interest/" + count, Time.time, this.gameObject, Packet.PacketType.Interest); DuplicateMapEntry entry = new DuplicateMapEntry { count = 0, wasSent = false, sentBeforeDuplicates = false, entryTime = Time.time }; duplicateMap.Add(message.name, entry); suppressMap.Add(message.name, false); if (checkQueue(message)) { logMessage("Found in queue:" + message.name); interestsSuppressed += 1; duplicateMap[message.name].count += 1; } else if (dataRecv.Contains(message.name)) { logMessage("Data for " + name + " already recv"); interestsSuppressed += 1; } else { if (m_supress > 0) { StartCoroutine(SuppressionRoutine(message)); } else { logMessage(Time.time + ":" + message.sender.name + " expresses interest " + message.name); sendInterest(message); duplicateMap[message.name].count += 1; duplicateMap[message.name].wasSent = true; duplicateMap[message.name].sentBeforeDuplicates = true; } } count += 1; latestSequence = count; } yield return(new WaitForSeconds(generationTime)); } }
IEnumerator WaitForRound() { int round = MulticastManager.getInstanceOf().currentRound; int[] rounds = new int[MulticastManager.getInstanceOf().interestGenerationCount]; int i = 0; while (round < MulticastManager.getInstanceOf().interestGenerationCount) { yield return(new WaitForSeconds(MulticastManager.getInstanceOf().interestGenerationRate)); interestsRound = currentCount; if (interestsRound == 1) { roundsWithAWinner += 1; } rounds[i++] = interestsRound; currentCount = 0; round += 1; } }
private void Awake() { instance = this; }
/** * This routine kick starts our node to start sending blocks of interests. * */ IEnumerator GenerationRoutine() { //Wait for a random amount of time so nodes don't all start at the same time. float randomStartDelay = Random.Range(0f, .25f); yield return(new WaitForSeconds(randomStartDelay)); float generationTime = MulticastManager.getInstanceOf().interestGenerationRate; int interestMax = MulticastManager.getInstanceOf().interestGenerationCount; int interestCount = 0; StartCoroutine(DecisionEvent()); //Schedule the Decision Event while (interestCount < interestMax) { for (int i = 0; i < interest_window; i++) { //Create an interest and create a strategy info object for it Packet message = new Packet("/test/interest/" + interestCount, Time.time, this.gameObject, Packet.PacketType.Interest); StrategyInfoEntry entry = new StrategyInfoEntry { duplicates = 0, sentTime = -1f, sentBeforeDuplicates = false, entryTime = Time.time }; StrategyInfo.Add(message.name, entry); //Look ahead case. Did we see this interest in the past? if (checkQueue(message)) { logMessage("Found in queue:" + message.name); interestsSuppressed += 1; StrategyInfo[message.name].sentTime = Time.time; StrategyInfo[message.name].isFinished = true; StrategyInfo[message.name].wasSuppressed = true; } //See if the interest reply is already cached else if (dataRecv.Contains(message.name)) { logMessage("Data for " + name + " already recv"); interestsSuppressed += 1; StrategyInfo[message.name].sentTime = Time.time; StrategyInfo[message.name].isFinished = true; StrategyInfo[message.name].wasSuppressed = true; } else { if (m_supress > 0) { //Schedule the suppression event StartCoroutine(SuppressionEvent(message)); } else { //Send this interest immediately. logMessage(Time.time + ":" + message.sender.name + " expresses interest " + message.name); sendInterest(message); StrategyInfo[message.name].duplicates += 1; StrategyInfo[message.name].sentTime = Time.time; StrategyInfo[message.name].sentBeforeDuplicates = true; StrategyInfo[message.name].isFinished = true; } } interestCount += 1; } //Wait some amount of time before sending the next block of interests. yield return(new WaitForSeconds(generationTime)); } //Print delay statistics now that this node is finished List <float> delays = new List <float>(); foreach (string key in StrategyInfo.Keys) { float interestDelay = StrategyInfo[key].sentTime - StrategyInfo[key].entryTime; if (StrategyInfo[key].sentTime == -1f) { interestDelay = 0f; //interest was suppressed. Treat as no delay in the interest. } delays.Add(interestDelay); } string delayString = ""; foreach (float delay in delays) { delayString += ("," + delay); } print(gameObject.name + ":" + delayString); }