Commit a69a3beb authored by caminha's avatar caminha
Browse files

subscription consumer is now random instead of sequential

parent ab8a2021
......@@ -30,6 +30,7 @@
#include <string>
#include <algorithm>
#include <set>
#include "ndn-subscription-consumer.hpp"
#include <ndn-cxx/lp/tags.hpp>
#include "ndn-cxx/util/time.hpp"
......@@ -98,25 +99,30 @@ SubscriptionConsumer::SendPacket()
return;
Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable>();
std::set<uint> pickedPrefixes;
if (randomInterestPrefixes.empty())
{
subscriptionCount = 1;
randomInterestPrefixes.resize(1);
randomInterestPrefixes[0] = m_interestName;
}
auto rng = CreateObject<UniformRandomVariable>();
BOOST_ASSERT_MSG(subscriptionCount > 0 , "Subscription count must be set");
NS_LOG_DEBUG("randomBrokerPrefixes: " << randomInterestPrefixes.size());
NS_LOG_DEBUG("subscriptionCount: " << subscriptionCount);
// globalSubscriptionCount += subscriptionCount;
// NS_LOG_UNCOND("globalSubscriptionCount: " << globalSubscriptionCount);
InterestPrefixes::iterator sub_end = randomInterestPrefixes.begin();
std::advance(sub_end, subscriptionCount);
for (auto it=randomInterestPrefixes.begin(); it<sub_end; it++)
for (int i=0; i<subscriptionCount; i++)
{
uint prefixIdx;
do { prefixIdx = rng->GetInteger(0, randomInterestPrefixes.size()-1); }
while (pickedPrefixes.find(prefixIdx) != pickedPrefixes.end());
pickedPrefixes.insert(prefixIdx);
auto it = randomInterestPrefixes.begin();
std::advance(it, prefixIdx);
shared_ptr<Name> nameWithTransformation = make_shared<Name>(*it);
if ( useParams || !transformationsAndParameters.empty())
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment