ns3

ns3 初探 概念及关键类

2017-05-24  本文已影响0人  epeeian

1.概念

2.关键类

2.1拓扑生成器关键类

NodeContainer nodes;
nodes.Create(2);

NetDeviceContainer devices;
devices=pointToPoint.Install(nodes);

调用后会有两个节点,每一个节点安装了点到点网络设备,之间有点到点信道。两设备会被配置在一个2ms传输实验的信道上以5M比特每秒速率传输

2.2Application 类

UdpEchoServerApplication 和 UdpEchoClientApplication两个核心类。在这里我们使用生成器对象。

UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

这里有一个C++隐式转换,(nodes.Get (1)作为输入,作为一个未命名的NodeContainer的构造函数的参数,送入Install方法。echoServer.Install会在管理节点的NodeContainer容器索引号为1的机节点安装一个UdpEchoServerApplication 。安装会返回一个容器,包含了指向所有被生成器创建的应用指针。

serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

These times are set using the ApplicationContainer methods Start and Stop.

UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));

The “MaxPackets” Attribute tells the client the maximum number of packets we allow it to send during the simula-
tion. The “Interval” Attribute tells the client how long to wait between packets, and the “PacketSize” Attribute
tells the client how large its packet payloads should be. With this particular combination of Attributes, we are
telling the client to send one 1024-byte packet.

2.3 Simulator类

用全局函数Simulator::Run.
When we previously called the methods,

serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
...
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));

we actually scheduled events in the simulator at 1.0 seconds, 2.0 seconds and two events at 10.0 seconds. When
Simulator::Run is called, the system will begin looking through the list of scheduled events and executing them. The remaining lines of our first ns-3 script, first.cc, do just that:

Simulator::Destroy ();
return 0;
}

上一篇下一篇

猜你喜欢

热点阅读