Commit 78329724 authored by caminha's avatar caminha
Browse files

added data stread trace

parent 36cbde05
......@@ -8,6 +8,8 @@
#include "traces-arranger.h"
#include <ctype.h>
#include <map>
#include "ns3/ndnSIM/NFD/core/scope-prefix.hpp"
namespace ns3
{
......@@ -118,6 +120,7 @@ namespace ndn
Time PrintStreamHitTime = tSimulationTime-MilliSeconds(1);
Simulator::Schedule(PrintStreamHitTime, &TracesArranger::writeStreamHitTrace, physicalTopology);
Simulator::Schedule(PrintStreamHitTime, &TracesArranger::writeConsumerMetricsFiles, physicalTopology);
Simulator::Schedule(PrintStreamHitTime, &TracesArranger::writeDataSpreadFile);
}
void
......@@ -147,13 +150,12 @@ namespace ndn
else
{
Ptr<SubscriptionConsumer> app = DynamicCast<SubscriptionConsumer>((*consumer)->GetApplication(0));
size_t subCount = app->getSubscriptionCount();
for (uint i=0; i<subCount; i++)
for (auto pickedPrefix : app->getPickedPrefixes())
{
Name producerName = prefixes[i];
Name producerName = prefixes[pickedPrefix];
uint32_t producerId = getNodeIdFromName(producerName);
uint32_t current_distance = maps_of_distances.at(cid).at(producerId);
streamsDistancesFile << consumer_name << '\t' << i << '\t' << current_distance << std::endl;
streamsDistancesFile << consumer_name << '\t' << pickedPrefix << '\t' << current_distance << std::endl;
}
}
}
......@@ -161,6 +163,49 @@ namespace ndn
streamsDistancesFile.close();
}
void
TracesArranger::writeDataSpreadFile ()
{
std::map<Name::Component, uint> spreadCounts;
for (auto node = NodeList::Begin(); node != NodeList::End(); node++)
{
Ptr<L3Protocol> l3Protocol = (*node)->GetObject<L3Protocol>();
if (l3Protocol != nullptr)
{
Ptr<ContentStore> contentStore = l3Protocol->GetObject<ContentStore>();
if (contentStore != nullptr)
{
std::set<Name::Component> nodesCountedComponents;
for (auto csEntry = contentStore->Begin(); csEntry != contentStore->End(); csEntry = contentStore->Next(csEntry))
{
if (!nfd::scope_prefix::LOCALHOST.isPrefixOf(csEntry->GetName()))
{
auto component = csEntry->GetName().at(0);
if (nodesCountedComponents.find(component) != nodesCountedComponents.end())
continue;
if(spreadCounts.find(component) != spreadCounts.end())
spreadCounts[component] += 1;
else
spreadCounts[component] = 1;
nodesCountedComponents.insert(component);
}
}
}
}
}
ofstream dataSpreadFile;
dataSpreadFile.open("data-spread.trace", ios::trunc);
BOOST_ASSERT_MSG(dataSpreadFile.is_open(), "Failed to open output file!!!");
dataSpreadFile << "DataSource\tCount" << std::endl;
for(auto spreadCount : spreadCounts)
dataSpreadFile << spreadCount.first << "\t" << spreadCount.second << std::endl;
dataSpreadFile.close();
}
uint32_t
TracesArranger::getNodeIdFromName(const Name& name)
{
......
......@@ -53,6 +53,8 @@ namespace ndn
printLogicalTreesDistancesRecursively(shared_ptr<TreeNode> curr_node, const Ptr<Node>& node,
const std::map<uint32_t, std::map<uint32_t, uint32_t>>& maps_of_distances,
ofstream& streamsDistancesFile, uint currDistance = 0);
static void
writeDataSpreadFile ();
};
} /* namespace ndn */
......
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