编译、运行脚本和Command Line命令行参数设置
来源:互联网 发布:雷蛇键盘 mac 编辑:程序博客网 时间:2024/04/26 06:38
出处:http://blog.csdn.net/finded/article/details/45337725
7. 编译和运行脚本主要步骤
1) 将编写的脚本复制到ns-3.22/scratch目录下(可以在ubuntu窗口界面直接复制)
进入ns3目录: /ns-3.22
$ cp examples/tutorial/first.cc scratch/myfirst.cc将脚本复制到scratch目录下
2) 构建(编译)
$ ./waf
3) 运行
$ ./waf --run scratch/myfirst
(可能会有运行权限问题,可在root下运行)
7.1 ns3中first.cc例子注释
7.2 CommandLine命令行参数
仿真一般是为了收集各种不同条件下的数据,常常需要改变一些变量。NS-3提供了Command Line参数接口,可以在运行时对脚本中的变量进行设置,免去了每次更改变量后要重新编译和构建脚本的麻烦。
1) 修改已有属性变量
在脚本中添加语句
int main (int argc, char *argv[])
{
...
CommandLine cmd;
cmd.Parse (argc, argv);//将命令行输入的参数作为类CommandLine的参数进行分析
...
}
这样可以在shell中使用某些附加参数如PrintHelp:
$~/ns-3.2.1 > ./waf --run "scratch/example --PrintHelp"
这条命令将会列出example当前可用的命令参数:
Entering directory '/home/craigdo/repos/ns-3-dev/build'
Compilation finished successfully
--PrintHelp: Print this help message.
--PrintGroups: Print the list of groups.
--PrintTypeIds: Print all TypeIds.
--PrintGroup=[group]: Print all TypeIds of group.
--PrintAttributes=[typeid]: Print all attributes of typeid.
--PrintGlobals: Print the list of globals.
从输出中(倒数第二行)我们知道可以打印某些类的属性:
$~/ns-3.2.1 > ./waf --run "scratch/example --PrintAttributes=ns3::PointToPointNetDevice"
这条命令将会列出类型为PointToPointNetDevice的设备的属性:
--ns3::PointToPointNetDevice::DataRate=[32768bps]:
The default data rate for point topoint links
知道了属性名称,我们也可以使用命令更改这个属性:前提须把脚本中赋值语句注释/删除
$~/ns-3.2.1>./waf--run"scratch/example --ns3::PointToPointNetDevice::DataRate=5Mbps"
2) 添加自己的变量
使用CommandLine::AddValue添加自己的变量,通过钩挂自己的变量将其与命令行相关联,使之成为CommandLine可以使用的参数,
在脚本中main函数开始添加
CommandLinecmd;
cmd.AddValue("nPackets","Number of packets to echo", nPackets); //(属性名称,属性说明,变量)
cmd.Parse(argc,argv);
这样在shell中我们可以在命令中更改这个属性:
$~/ns-3.2.1 > ./waf --run "scratch/example --nPackets=2"
参考文献:
[1] http://blog.sina.com.cn/s/articlelist_1923709774_8_1.html
[2] ns-3project. ns-3 Software Tutorial. ns-3 project. 2015年2月26日
[3] ns-3project. ns-3 Reference Manual. ns-3 project. 2015年2月26日
[4]《ns-3网络模拟器基础及应用》,人民邮电出版社,马春光 姚建盛,2014年1月
部分参考网络资料,未一一列举,敬请原谅!
- 编译、运行脚本和Command Line命令行参数设置
- (二)NS3如何编译、运行脚本和 Command Line命令行参数设置
- 使用NDK编译并运行C++11的Command line命令行程序
- NS3 Command Line Arguments 使用命令行参数改变脚本
- 如何从Terminal Command Line编译并运行Scope
- npm command-line npm命令行
- TexturePacker命令行使用(command line)
- odoo shell (command line) 命令行
- dos命令行编译和运行
- 运行期修改可执行文件的路径和Command Line
- 各种编译环境中如何为C++添加命令行参数(Command-line parameter)
- ios 命令行编译 Build an iPhone app from the command line
- 各种编译环境中如何为C++添加命令行参数(Command-line parameter)
- 如何在Windows下开发Python:在cmd下运行Python脚本+如何使用Python Shell(command line模式和GUI模式)+如何使用Python IDE
- 7.4.命令行参数(Command-Line Arguments)
- MySQL Command Line[mysql命令行常用命令]
- Xcode Command Line Tools(命令行工具)
- learn the command line 命令行随记
- mysql tinyint类型返回如何返回数值
- Android性能优化之巧用软引用与弱引用优化内存使用
- svn 项目转移到 git 码云
- 基于TCP协议的简易C/S通信
- 插值与拟合
- 编译、运行脚本和Command Line命令行参数设置
- Android系统架构
- Java并发包中常用类
- 一个
- 51Nod 1289大鱼吃小鱼(栈)
- MySQL定时器Events
- 基础笔记(三):网络协议之Tcp、Http
- 传统架构与Hadoop的区别
- Android性能优化之利用LeakCanary检测内存泄漏及解决办法