ndn挖坑记(二)

如何使用ndnSIM运行自己的仿真实验

基本要点

仿真场景可以在NS-3目录下的scratch/ or src/ndnSIM/examples两个文件夹中编写,或者选择一个独立的库来编写仿真仿真场景。

如果直接在上面编写,有个不好的地方就是编译速度慢和代码可能难以区分是自己写的还是模拟器自带的,所以官网上推荐是使用独立的库来编写自己的仿真场景。

话虽如此,当我使用独立库调用可视化模块的时候既不报错也不显示就有点懵逼了,所以最后我还是将代码放在ndnSIM/ns-3/scratch下了。
具体而言,将自己的文件保存为.cc放入其中即可。

https://ndnsim.net/current/examples.html 官网例子中可以看到如果需要建立一个仿真场景,需要做的事情有主要下面几个:

  1. 设置链路状态(包括链路之间的连接)
  2. 定义拓扑结构
  3. 设置CS
  4. 在节点上安装ndnSIM的网络堆栈
  5. 安装consumer和producer
  6. 设置FIB
  7. 设置前向转发策略
  8. 运行仿真场景

开始动手

设置一个和 教程ndn-grid.cpp一样的例子

10Mbps links/10ms delays
3x3拓扑结构
一个consumer,一个producer
FIB使用GlobalRoutingHelper进行设置
前向转发策略使用bestRoute

运行
./waf configure -d optimized
./waf

BUG记录

记录一下使用第三方库时出现的错误,出现在运行阶段

 File "/ndnSIM/scenario/.waf-2.0.14-a8a9afc5d151494252697f8fa4ba3fbc/waflib/Scripting.py", line 119, in waf_entry_point
    run_commands()
  File "/ndnSIM/scenario/.waf-2.0.14-a8a9afc5d151494252697f8fa4ba3fbc/waflib/Scripting.py", line 181, in run_commands
    run_command('shutdown')
  File "/ndnSIM/scenario/.waf-2.0.14-a8a9afc5d151494252697f8fa4ba3fbc/waflib/Scripting.py", line 170, in run_command
    ctx.execute()
  File "/ndnSIM/scenario/.waf-2.0.14-a8a9afc5d151494252697f8fa4ba3fbc/waflib/Context.py", line 85, in execute
    self.recurse([os.path.dirname(g_module.root_path)])
  File "/ndnSIM/scenario/.waf-2.0.14-a8a9afc5d151494252697f8fa4ba3fbc/waflib/Context.py", line 126, in recurse
    user_function(self)
  File "/ndnSIM/scenario/wscript", line 114, in shutdown
    return subprocess.call (argv)
  File "/usr/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception

解决方法,修改目录下的wscript下的subprocess.cal中的参数,改为subprocess.call (argv,shell=True)因为默认模式下的subprocess.call不支持使用shell运行命令行。

原文地址:https://www.cnblogs.com/FlyerBird/p/11885020.html