通过ndnSIM平台内建输出程序 trace helpers 获取的数据只需稍加处理即可得到节点吞吐量、丢包率、时延和缓存命中率等指标,具体过程可以参考:ndnSIM 仿真数据获取 仿真结果 平台内建输出程序 trace helpers 的使用_ndnsim tracer-CSDN博客
如该教程所说,两种方式都能获取仿真数据:
- 打印输出运行日志,并在其中配置需要查看的数据,具体方式可以查看教程:ndnSIM 如何打印 运行日志 获取日志 调试 获取实验数据_ndnsim运行日志-CSDN博客
- 通过平台内建输出程序获取,即使用 trace helpers 来对仿真结果进行跟踪,生成数据文件txt
下面分别介绍这两种获取的数据如何生成实验结果图,可以放在论文中:
Trace helpers 平台内建输出程序
该方法得到的数据均为txt文件,其中的格式和字段含义可以参考教程(ndnSIM 仿真数据获取 仿真结果 平台内建输出程序 trace helpers 的使用_ndnsim tracer-CSDN博客)中的表格内容。
因此,对该txt进行处理即可得到实验结果图。
1.吞吐量(Example of packet-level trace helpers)
此示例(ndn-tree-tracers.cpp)演示了数据包级跟踪助手的基本用法。
在这种情况下,我们将使用树状拓扑,其中使用者安装在叶节点上,而生产者位于树的根目录中:
拓扑结构如下图:
相应的拓扑文件(topo-tree.txt):
# topo-tree.txt
router
#node city y x mpi-partition
leaf-1 NA 80 40 1
leaf-2 NA 80 20 3
leaf-3 NA 80 0 2
leaf-4 NA 80 -20 4
rtr-1 NA 60 20 1
rtr-2 NA 60 0 2
root NA 40 10 0
link
# from to capacity metric delay queue
leaf-1 rtr-1 10Mbps 1 1ms 100
leaf-2 rtr-1 10Mbps 1 1ms 100
leaf-3 rtr-2 10Mbps 1 1ms 100
leaf-4 rtr-2 10Mbps 1 1ms 100
rtr-1 root 10Mbps 1 1ms 100
rtr-2 root 10Mbps 1 1ms 100
使用跟踪助手的示例模拟(ndn-tree-tracers.cpp)场景:
// ndn-tree-tracers.cpp
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/ndnSIM-module.h"
namespace ns3 {
int
main(int argc, char* argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
AnnotatedTopologyReader topologyReader("", 1);
topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
topologyReader.Read();
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
// Installing global routing interface on all nodes
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// Getting containers for the consumer/producer
Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
Ptr<Node> producer = Names::Find<Node>("root");
for (int i = 0; i < 4; i++) {
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
// Each consumer will express unique interests /root/<leaf-name>/<seq-no>
consumerHelper.SetPrefix("/root/" + Names::FindName(consumers[i]));
consumerHelper.Install(consumers[i]);
}
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
// Register /root prefix with global routing controller and
// install producer that will satisfy Interests in /root namespace
ndnGlobalRoutingHelper.AddOrigins("/root", producer);
producerHelper.SetPrefix("/root");
producerHelper.Install(producer);
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
Simulator::Stop(Seconds(20.0));
ndn::L3RateTracer::InstallAll("rate-trace.txt", Seconds(0.5));
Simulator::Run();
Simulator::Destroy();
return 0;
}
} // namespace ns3
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}
成功运行将直接在当前文件中创建rate-trace.txt文件,可以手动对其进行分析或将其用作某些图形/统计信息包的输入。
# Copyright (c) 2012,2015 Alexander Afanasyev <alexander.afanasyev@ucla.edu>
# install.packages('ggplot2')
library(ggplot2)
# install.packages('scales')
library(scales)
# install.packages('doBy')
library(doBy)
#########################
# Rate trace processing #
#########################
data = read.table("rate-trace.txt", header=T)
data$Node = factor(data$Node)
data$FaceId <- factor(data$FaceId)
data$Kilobits <- data$Kilobytes * 8
data$Type = factor(data$Type)
# exlude irrelevant types
data = subset(data, Type %in% c("InInterests", "OutInterests", "InData", "OutData"))
# combine stats from all faces
data.combined = summaryBy(. ~ Time + Node + Type, data=data, FUN=sum)
data.root = subset (data.combined, Node == "root")
data.leaves = subset(data.combined, Node %in% c("leaf-1", "leaf-2", "leaf-3", "leaf-4&#