ndnSIM学习笔记(二)

要进行自己的仿真实验的话,编译时的“--enable-examples”需要去掉,改为

./waf configure -d optimized
./waf

要进行仿真的文件需放入“ndnSIM/ns-3/scratch”文件夹内,保存为.cc格式文件。

为方便进行研究,从“ns-3/src/ndnSIM/examples”实例文件夹内选取“ndn-simple.cpp”文件,存入到上述scratch文件夹内并存为.cc文件,接下来就可以在调试模式里进行仿真、调试操作。

ndn-simple文件的拓扑结构如下图所示,是一个最基础的ndn网络:


节点数为3个,分为消费者(consumer)、转发节点(router)、以及生产者(producer)。

使用ConsumerCbr模拟消费者,以每秒10个的频率向生产者发送请求(interests)。

使用Producer类模拟生产者,以最高1Mbps的速率满足所有接收到的interest。

每个节点的转发表(FIB)都使用默认路由填充,并使用原始ndnSIM的内容存储结构。

以下开始进行代码分析。

一个普遍的方案(scenario)格式为:

// scenario.cc
#include "xx.h"

namespace ns3{
int main (xx xx,xx xx..)
  {
    // 设置节点间链接和通道的默认参数
    ..
    //读取可选的命令行参数
    ..
    //创建节点
    ..
    //选择转发策略
    ..
    //安装应用程序(consumer等)
    Simulator::Stop(Seconds(20.0));  //设置时间  
    simulator::run();
    simulator::destroy();
return 0;
  }

}
int main (xx xx,xx xx)
{
  return ns3::main (xx,xx);
}

1.设置节点间链接和通道的默认参数

Config :: SetDefault (“ns3 :: PointToPointNetDevice :: DataRate” , StringValue (“1Mbps” )); //链路速率
Config :: SetDefault (“ns3 :: PointToPointChannel :: Delay” , StringValue (“10ms” )); //链路时延
Config :: SetDefault (“ns3 :: QueueBase :: MaxPackets” , UintegerValue (20));//队列最大包数量

2.读取可选的命令行参数

 CommandLine cmd;
 cmd.Parse(argc, argv);

3.创建节点

  NodeContainer nodes;
  nodes.Create(3);

4.使用链接连接节点

  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

5.在所有节点上安装ndn堆栈

  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);//此处使用默认创建方式
  ndnHelper.InstallAll();

6.选择转发策略

ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast"); //最长前缀匹配策略

7.安装应用程序

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");   //使用consumercbr类
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");                      //选择策略
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 每秒10个请求
  consumerHelper.Install(nodes.Get(0));                        // 选择节点

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(2)); // 选择节点


明白每个部分内容代表的含义后,即可进行修改调试等操作,如:


以上即为借助分析ndn-simple文件学习仿真文件语句的过程。

下篇将进一步分析路由转发机制、路由策略等细节问题,以及PIT表与FIB表的修改操作。


版权声明:本文为gaonjzzz原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。