Commit 58a34311 authored by Renato Caminha Juaçaba Neto's avatar Renato Caminha Juaçaba Neto 🙂
Browse files

Merge branch 'ndnSIM-ns-3.29' of...

Merge branch 'ndnSIM-ns-3.29' of https://icube-forge.unistra.fr/rcaminha/nanoas-proof-of-work into ndnSIM-ns-3.29
parents 3b23a851 44a3f7ca
......@@ -77,7 +77,8 @@ namespace ndn
}
void
ConsumerArranger::setupDirectSubscriptions(const NodeContainer &consumers, const NodeContainer &producers)
ConsumerArranger::setupDirectSubscriptions(const NodeContainer &consumers, const NodeContainer& activatedNodes,
const NodeContainer &producers, const map<Ptr<Node>, uint> cardinalities)
{
AppHelper consumerHelper("ns3::ndn::SubscriptionConsumer");
// consumerHelper.SetAttribute("LifeTime", TimeValue(consumerStopTime - MilliSeconds(500)));
......@@ -99,13 +100,14 @@ namespace ndn
Time subInterval = Minutes(std::pow(2, rsic));
consumerHelper.SetAttribute("SubscriptionInterval", TimeValue(subInterval));
Ptr<Application> app = consumerHelper.Install(consumers.Get(c)).Get(0);
Time starttime = MilliSeconds(rng->GetInteger(300+70*rsic, 320+70*rsic));
app->SetStartTime(starttime);
app->SetStopTime(consumerStopTime);
uint subCount = rng->GetInteger(std::ceil(producers.GetN()/2), producers.GetN());
Ptr<Node> chosenDomain = activatedNodes.Get(rng->GetInteger(0, activatedNodes.GetN()-1));
// NS_LOG_UNCOND("ChosenDomain: " << chosenDomain->GetId());
uint subCount = rng->GetInteger(10, cardinalities.at(chosenDomain));
DynamicCast<SubscriptionConsumer>(app)->setSubscriptionCount(subCount);
// Consumer NAS parameters
......
......@@ -27,7 +27,8 @@ namespace ns3
~ConsumerArranger () {};
void setupPrivateDomains(const NodeContainer &consumers, const NodeContainer &activatedNodes);
void setupDirectSubscriptions(const NodeContainer &consumers, const NodeContainer &producers);
void setupDirectSubscriptions(const NodeContainer &consumers, const NodeContainer& activatedNodes,
const NodeContainer &producers, const map<Ptr<Node>, uint> cardinalities);
const Time&
getConsumerStopTime () const
......
......@@ -8,6 +8,8 @@
#include <set>
#include "logical-topology-creator.h"
#include <numeric>
namespace ns3
{
namespace ndn
......@@ -86,5 +88,29 @@ namespace ndn
return topology;
}
void
LogicalTopologyCreator::measureCardinalities(shared_ptr<LogicalTopology> logicalTopology,
const std::map<Ptr<Node>, NodeContainer>& domains)
{
for (shared_ptr<TreeNode> initial_node : logicalTopology->initial_nodes)
recursiveMeasureCardinalities(initial_node, logicalTopology->cardinalities, domains);
}
uint
LogicalTopologyCreator::recursiveMeasureCardinalities(shared_ptr<TreeNode> curr_node, map<Ptr<Node>, uint>& cardinalities,
const std::map<Ptr<Node>, NodeContainer>& domains)
{
const Ptr<Node> &node = curr_node->node;
if (curr_node->children.empty())
cardinalities[node] = domains.at(node).size();
else
cardinalities[node] = std::accumulate(curr_node->children.begin(), curr_node->children.end(), 0,
[&](const uint &acc, shared_ptr<TreeNode> child) {
return acc + recursiveMeasureCardinalities(child, cardinalities, domains);
});
BOOST_ASSERT(cardinalities[node] > 0);
return cardinalities[node];
}
} /* namespace ndn */
} /* namespace ns3 */
......@@ -34,6 +34,7 @@ namespace ndn
list<shared_ptr<TreeNode>> initial_nodes;
NodeContainer activatedNodes;
list<shared_ptr<TreeNode>> leaves;
map<Ptr<Node>, uint> cardinalities;
};
class LogicalTopologyCreator : public Object
......@@ -47,9 +48,17 @@ namespace ndn
shared_ptr<LogicalTopology>
createLogicalTopology(const NodeContainer& physicalNodes) const;
static void
measureCardinalities(shared_ptr<LogicalTopology>,
const std::map<Ptr<Node>, NodeContainer>&);
protected:
uint16_t nNodes;
Ptr<RandomVariableStream> branchCountRNG;
static uint
recursiveMeasureCardinalities(shared_ptr<TreeNode> curr_node, map<Ptr<Node>, uint>& cardinalities,
const std::map<Ptr<Node>, NodeContainer>& domains);
};
} /* namespace ndn */
......
......@@ -45,13 +45,14 @@ main(int argc, char *argv[])
uint nSystems = 20,
nExtraEdges = 10,
nConsumers = 40,
nProducers = 250,
nMaxProducersPerSystem = 20,
nMaxBranching = 5,
simulationTime = 120,
// randomTransformationCount = 3,
// randomTransformationParamCount = 3,
subscriptionIntervalCount = 4;
double percSystemActivation = 0.9;
double percSystemActivation = 1;
std::string appScenario = "RandomTrees",
subEquivalence = "multiplier";
......@@ -60,6 +61,7 @@ main(int argc, char *argv[])
cmd.AddValue("nSystems", "Number of systems to be created", nSystems);
cmd.AddValue("nExtraEdges", "Number of extra edges to be created between systems", nExtraEdges);
cmd.AddValue("nConsumers", "Number of consumers to be created", nConsumers);
cmd.AddValue("nProducers", "Number of producers to be created", nProducers);
cmd.AddValue("nMaxProducersPerSystem", "Max number of producers per system", nMaxProducersPerSystem);
cmd.AddValue("nMaxBranching", "Max number of children per node in the logical topology", nMaxBranching);
cmd.AddValue("percSystemActivation", "Percentage of systems to be part of the logical topology (between 0 and 1)", percSystemActivation);
......@@ -92,6 +94,7 @@ main(int argc, char *argv[])
outputFile << "nSystems\t" << nSystems << std::endl;
outputFile << "nExtraEdges\t" << nExtraEdges << std::endl;
outputFile << "nConsumers\t" << nConsumers << std::endl;
outputFile << "nProducers\t" << nProducers << std::endl;
outputFile << "nMaxProducersPerSystem\t" << nMaxProducersPerSystem << std::endl;
outputFile << "nMaxBranching\t" << nMaxBranching << std::endl;
outputFile << "percSystemActivation\t" << percSystemActivation << std::endl;
......@@ -130,8 +133,8 @@ main(int argc, char *argv[])
shared_ptr<LogicalTopology> logicalTopology = logicalcreator->createLogicalTopology(physicalTopology->domainRouters);
NS_LOG_DEBUG("Creating producers...");
physicalcreator->createProducers(physicalTopology, logicalTopology->leaves);
physicalcreator->createProducers(nProducers, physicalTopology, logicalTopology);
LogicalTopologyCreator::measureCardinalities(logicalTopology, physicalTopology->domains);
// NDN stack setup //////////////////////////////////////////////////////////////////////
......@@ -151,7 +154,8 @@ main(int argc, char *argv[])
if (appScenario.compare("RandomTrees") == 0)
consumerArranger.setupPrivateDomains(physicalTopology->consumers, logicalTopology->activatedNodes);
else
consumerArranger.setupDirectSubscriptions(physicalTopology->consumers, physicalTopology->producers);
consumerArranger.setupDirectSubscriptions(physicalTopology->consumers, logicalTopology->activatedNodes,
physicalTopology->producers, logicalTopology->cardinalities);
......@@ -174,7 +178,8 @@ main(int argc, char *argv[])
map_of_distances = ndn::GlobalRoutingHelper::CalculateRoutes();
}));
TracesArranger::setup(physicalTopology, logicalTopology, TraceConfigTime, tSimulationTime, appScenario, map_of_distances);
TracesArranger::setup(physicalTopology, logicalTopology, TraceConfigTime,
tSimulationTime, appScenario, map_of_distances);
Simulator::Stop(tSimulationTime);
......
......@@ -121,7 +121,7 @@ namespace ndn {
p2pHelper.Install(newConsumerNode, mediator);
topology->consumers.Add(newConsumerNode);
topology->systems[mediator].Add(newConsumerNode);
topology->domains[mediator].Add(newConsumerNode);
}
return topology;
......@@ -130,24 +130,34 @@ namespace ndn {
void
PhysicalTopologyCreator::createProducers(shared_ptr<PhysicalTopology> topology,
std::list<shared_ptr<TreeNode>> logical_topology_leaves)
PhysicalTopologyCreator::createProducers(uint nProducers, shared_ptr<PhysicalTopology> topology,
shared_ptr<LogicalTopology> logical_topology)
{
for (shared_ptr<TreeNode> intermediary : logical_topology_leaves)
uint nProducersPerDomain = std::floor(nProducers / logical_topology->leaves.size());
uint aFewMoreProducers = nProducers % logical_topology->leaves.size();
auto intermediary = logical_topology->leaves.begin();
while (intermediary != logical_topology->leaves.end())
{
// Creating new producers
uint nProducers = producersPerSystemRNG->GetInteger();
NodeContainer newProducers;
newProducers.Create(nProducers);
if (aFewMoreProducers > 0)
{
newProducers.Create(nProducersPerDomain + 1);
aFewMoreProducers -= 1;
}
else newProducers.Create(nProducersPerDomain);
// Setting up new producers
Ptr<Node> node = (*intermediary)->node;
for (Ptr<Node> producer : newProducers)
{
Names::Add("P" + boost::lexical_cast<std::string>(producer->GetId()), producer);
topology->systems[intermediary->node].Add(producer);
topology->domains[node].Add(producer);
topology->producers.Add(producer);
p2pHelper.Install(intermediary->node, producer);
p2pHelper.Install(node, producer);
}
intermediary++;
}
}
......@@ -172,7 +182,7 @@ namespace ndn {
for (Ptr<Node> producer : newProducers)
{
Names::Add("P" + boost::lexical_cast<std::string>(producer->GetId()), producer);
topology->systems[intermediaryNode].Add(producer);
topology->domains[intermediaryNode].Add(producer);
topology->producers.Add(producer);
p2pHelper.Install(intermediaryNode, producer);
}
......@@ -180,3 +190,4 @@ namespace ndn {
}
} /* namespace ndn */
} /* namespace ns3 */
......@@ -25,7 +25,7 @@ namespace ndn {
{
NodeContainer consumers,
producers, domainRouters;
std::map<Ptr<Node>, NodeContainer> systems;
std::map<Ptr<Node>, NodeContainer> domains;
NodeContainer allNodes() {
return NodeContainer(consumers,
producers, domainRouters);
......@@ -50,8 +50,8 @@ namespace ndn {
create_physical_topology();
void
createProducers(shared_ptr<PhysicalTopology>,
std::list<shared_ptr<TreeNode>> logical_topology_leaves);
createProducers(uint, shared_ptr<PhysicalTopology>,
shared_ptr<LogicalTopology>);
void
createDirectSubscriptionProducers(shared_ptr<PhysicalTopology> topology);
......
......@@ -41,8 +41,8 @@ namespace ndn
if (currNode->children.empty())
{
setupLastIntermediary(currNode, phyTopology->systems[currNode->node], intermediaryStopTime);
const NodeContainer& producerNodes = phyTopology->systems[currNode->node];
setupLastIntermediary(currNode, phyTopology->domains[currNode->node], intermediaryStopTime);
const NodeContainer& producerNodes = phyTopology->domains[currNode->node];
for (auto producerNode = producerNodes.Begin(); producerNode != producerNodes.End(); producerNode++)
setupProducer (*producerNode);
}
......
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