1.概念
- 節(jié)點(diǎn) 基本計(jì)算設(shè)備被抽象為節(jié)點(diǎn)。用C++中node類描述凶朗。可想象成計(jì)算機(jī)显拳,我們要為它添加應(yīng)用程序棚愤,協(xié)議棧,外設(shè)卡及驅(qū)動(dòng)等杂数。
- 應(yīng)用程序 C++A中Application類描述宛畦。
- 信道 用C++中Channel類。管理通信子網(wǎng)對(duì)象和節(jié)點(diǎn)連接至它們的方法耍休。
- 網(wǎng)絡(luò)設(shè)備 相當(dāng)于硬件設(shè)備和軟件驅(qū)動(dòng)的總和刃永。安裝在節(jié)點(diǎn)上。一個(gè)幾點(diǎn)可以通過(guò)多個(gè)網(wǎng)絡(luò)設(shè)備同時(shí)連接到多條信道上羊精。由C++中NetDevice描述。提供管理連接其他節(jié)點(diǎn)和信道對(duì)象的方法囚玫。
- 拓?fù)渖善?把網(wǎng)絡(luò)設(shè)備連接到節(jié)點(diǎn)喧锦,信道,配置ip地址等等抓督。
2.關(guān)鍵類
2.1拓?fù)渖善麝P(guān)鍵類
- NodeContainer類 創(chuàng)建燃少,管理和使用節(jié)點(diǎn)。
NodeContainer nodes;
nodes.Create(2);
PointToPointHelper類
網(wǎng)絡(luò)設(shè)備铃在,信道阵具。配置和連接PointToPointNetDevice和PointToPointChannel對(duì)象。例如設(shè)置5M傳輸速率和2ms的點(diǎn)到點(diǎn)傳輸時(shí)延定铜。NetDeviceContainer類
存放所有被創(chuàng)建的NetDevice對(duì)象列表
NetDeviceContainer devices;
devices=pointToPoint.Install(nodes);
調(diào)用后會(huì)有兩個(gè)節(jié)點(diǎn)阳液,每一個(gè)節(jié)點(diǎn)安裝了點(diǎn)到點(diǎn)網(wǎng)絡(luò)設(shè)備,之間有點(diǎn)到點(diǎn)信道揣炕。兩設(shè)備會(huì)被配置在一個(gè)2ms傳輸實(shí)驗(yàn)的信道上以5M比特每秒速率傳輸
InternetStackHelper類
安裝協(xié)議棧,為每一個(gè)節(jié)點(diǎn)容器中的節(jié)點(diǎn)安裝一個(gè)網(wǎng)絡(luò)協(xié)議棧(TCP, UDP, IP等)
InternetStackHelper stack;
stack.Install(nodes);Ipv4AddressHelper類
Ipv4AddressHelper address;
address.SetBase(''10.1.1.0'',''255.255.255.0'');
Ipv4InterfaceContainer interfaces=address.Assingn(devices);//完成真正地址分配
第一個(gè)10.1.1.1帘皿,后面10.1.1.2等
2.2Application 類
UdpEchoServerApplication 和 UdpEchoClientApplication兩個(gè)核心類。在這里我們使用生成器對(duì)象畸陡。
- UdpEchoServerHelper類
在節(jié)點(diǎn)上設(shè)置一個(gè)UDP回顯服務(wù)應(yīng)用鹰溜。
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
這里有一個(gè)C++隱式轉(zhuǎn)換虽填,(nodes.Get (1)作為輸入,作為一個(gè)未命名的NodeContainer的構(gòu)造函數(shù)的參數(shù)曹动,送入Install方法斋日。echoServer.Install會(huì)在管理節(jié)點(diǎn)的NodeContainer容器索引號(hào)為1的機(jī)節(jié)點(diǎn)安裝一個(gè)UdpEchoServerApplication 。安裝會(huì)返回一個(gè)容器墓陈,包含了指向所有被生成器創(chuàng)建的應(yīng)用指針桑驱。
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
These times are set using the ApplicationContainer methods Start and Stop.
- UdpEchoClientrHelper類
與回顯服務(wù)器類似,用來(lái)管理UdpEchoClientApplication
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類
用全局函數(shù)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 ?rst ns-3 script, first.cc, do just that:
Simulator::Destroy ();
return 0;
}