覆盖默认属性
使用命令行参数系统的第一步是声明命令行解析器。这是非常简单(在您的主程序中)如下代码所做,
int
main (int argc, char*argv[])
{
...
CommandLine cmd;
cmd.Parse (argc, argv);
...
}
执行:
./waf --run "scratch/myfirst --PrintHelp"
则会输出
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (0.413s)
TcpL4Protocol:TcpStateMachine()
CommandLine:HandleArgument(): Handle arg name=PrintHelp value=
--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.
myfirst.cc中的代码
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
改为
PointToPointHelper pointToPoint;
//删掉两行
启用UDP Echo Server应用程序的一些日志记录,然后打开时间前缀。
export 'NS_LOG=UdpEchoServerApplication=level_all|prefix_time'
输出:
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (0.405s)
0s UdpEchoServerApplication:UdpEchoServer()
1s UdpEchoServerApplication:StartApplication()
Sent 1024 bytes to 10.1.1.2
2.25732s Received 1024 bytes from 10.1.1.1
2.25732s Echoing packet
Received 1024 bytes from 10.1.1.2
10s UdpEchoServerApplication:StopApplication()
UdpEchoServerApplication:DoDispose()
UdpEchoServerApplication:~UdpEchoServer()
//而之前为
2.00369s UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1
再执行
./waf --run "scratch/myfirst
--ns3::PointToPointNetDevice::DataRate=5Mbps
--ns3::PointToPointChannel::Delay=2ms"
则打印出的内容与之前相同,时间相同。