Tutorial jaringan simulator ns-3. Bab 4


bab 1.2
bab 3


4 Ikhtisar konsep
4.1 Abstraksi utama
4.1.1 Node
4.1.2 Aplikasi
4.1.3 Saluran
4.1.4 Perangkat Bersih
4.1.5 Asisten topologi
4.2 Skrip pertama ns-3
4.2.1 Kode boileriler
4.2.2 Plug-in
4.2.3 ns3 namespace
4.2.4 Logging
4.2.5 Fungsi utama
4.2.6 Menggunakan asisten topologi
4.2.7 Menggunakan Aplikasi
4.2.8 Simulator
4.2.9 Membangun skrip Anda
4.3 ns-3 Source code


Bab 4


Tinjauan Konsep


, , nsā€‘3 ā€” . , , , , , .


4.1


, , nsā€‘3.


4.1.1 Node ()


- , , . , nsā€‘3 ā€” , , , . , , ā€” (node).


ns-3 . C++ Node. NodeNode () .


Node , . , , , . ns-3.


4.1.2 Application ()


, . , , , . . . , . , , .


, . nsā€‘3 . , , . Ā« Ā» , nsā€‘3 nsā€‘3 .


nsā€‘3 , , . C++ Application (). Application . , Application - . Application, UdpEchoClientApplication UdpEchoServerApplication. , / ā€‘ .


4.1.3 Channel ()


. , , . Ethernet , Ethernet. nsā€‘3 , . C++ Channel ().


ChannelChannel . - . - . Ethernet- , .


CsmaChannelCsmaChannel, PointToPointChannelPointToPointChannel WifiChannelWifiChannel. CsmaChannel, , . Ethernet- .


4.1.4 Net Device ( )


, , , ( ) , . , . , .


, . Unix ( Linux), device. (device drivers), (NIC) (network device drivers) (net devices). Unix Linux , eth0.


nsā€‘3 , . Ā«Ā» , . , NetDevices.


C++ NetDevice. NetDevice Node Channel; - . NetDevice CsmaNetDevice, PointToPointNetDevice WifiNetDevice. , Ethernet Ethernet, CsmaNetDevice CsmaChannel, PointToPointNetDevice PointToPointChannel, WifiNetDevice ā€” WifiChannel.


4.1.5


- ( ) . nsā€‘3 , NetDevices. Node, NetDevice Channel.


NetDevices , NetDevices , IP- .. nsā€‘3 , , . , NetDevice nsā€‘3, MAC-, Node, , NetDevice Channel. , , (Internetworks). , .


4.2 ns-3


, , nsā€‘3 repos . release


, nsā€‘3 , :
$ ./waf configure --build-profile=release --out=build/release,
$ ./waf build

:


AUTHORS       examples      scratch       utils       waf.bat*
bindings      LICENSE       src           utils.py    waf-tools
build         ns3           test.py*      utils.pyc   wscript
CHANGES.html  README        testpy-output VERSION     wutils.py
doc           RELEASE_NOTES testpy.supp   waf*        wutils.pyc

examples/tutorial. first.cc. , - . , first.cc .


4.2.1 Boilerplate
ā€” emacs. emacs ( ), .


/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */

, , . nsā€‘3, , , . , nsā€‘3, doc/codingstd.txt - : https://www.nsnam.org/develop/contributing-code/coding-style/.


nsā€‘3 , . . emacs, , , emacs.


nsā€‘3 GNU General Public License. GNU nsā€‘3. nsā€‘3 GPL , .


/* 
* This program is free software; you can redistribute it and/or modify 
* it under the terms of the GNU General Public License version 2 as 
* published by the Free Software Foundation; 
*
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details. 
* 
* You should have received a copy of the GNU General Public License 
* along with this program; if not, write to the Free Software 
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/

4.2.2


(include).


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"

, , . , , . , , , , , . , , , .


nsā€‘3 ns3 ( ), . ns3/core-module.h nsā€‘3, src/core . . , Waf ns3 build/debug


, nsā€‘3 , :
$ ./waf configure --build-profile=debug --out=build/debug
$ ./waf build

$ ./waf configure --build-profile=optimized --out=build/optimized
$ ./waf build

build/optimized, . Waf . , , ,


$ ./waf -d debug --enable-examples --enable-tests configure

, .


$ ./waf

. , ../../build/debug/ns3, , , , . , .


4.2.3 ns3


first.cc ā€” .


using namespace ns3;

nsā€‘3 C++, ns3. nsā€‘3- , , , . C++ nsā€‘3 () . , , ns3 :: scope nsā€‘3, . , C++ ns3 std using namespace std; cout .


4.2.4


,


NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

Doxygen. - nsā€‘3, Ā«Ā» (Documentation) . , . Ā« Ā», nsā€‘3. Ā«API DocumentationĀ», API nsā€‘3.


. ā€” Ā«Ā» Modules nsā€‘3 nsā€‘3. Modules, nsā€‘3. , . ( , ) nsā€‘3 , , , Core, Debugging tools, Logging. Logging.


Doxygen Logging. NS_LOG_COMPONENT_DEFINE. , Ā« Ā» , . Ā«More...Ā» .


, , NS_LOG_COMPONENT_DEFINE. , , , FirstScriptExample, .


4.2.5


,


int 
main (int argc, char *argv[])
{ 

(). C++, , . . nsā€‘3 C++ . 1 , :


Time::SetResolution (Time::NS);

ā€” , ( ). . , , , , , , . ( , , .)


, EchoClient EchoServer:


LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

Logging, , /, . INFO - . .


. , .


4.2.6


Node nsā€‘3, .


NodeContainer nodes;
nodes.Create (2);

, NodeContainer. Classes Doxygen. Doxygen, Classes. , . nsā€‘3. , ns3 :: NodeContainer. , , .


, . , , , . NodeContainer , Node, . NodeContainer, nodes. Create nodes . Doxygen, nsā€‘3 Node .


, . . , , ā€” . .


PointToPointHelper


, , , . , NetDevice Channel. . , , , , Ethernet . PointToPointHelper nsā€‘3 PointToPointNetDevice PointToPointChannel. :


PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); 
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

,


PointToPointHelper pointToPoint;

PointToPointHelper. ,


pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));

PointToPointHelper Ā«5 /Ā» ( ) Ā«DataRateĀ».


, Ā«DataRateĀ» , PointToPointNetDevice. Doxygen ns3::PointToPointNetDevice GetTypeId , . Ā«DataRateĀ». nsā€‘3 . , .


Ā«DataRateĀ» PointToPointNetDevice, Ā«DelayĀ», PointToPointChannel. ,


pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

PointToPointHelper Ā«2 Ā» ( ) -, .


NetDeviceContainer


NodeContainer, . PointToPointHelper, PointToPointNetDevices PointToPointChannel. , NodeContainer, PointToPointHelper , , . NetDevice, NetDeviceContainer , NodeContainer . ,


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

. , , . Install PointToPointHelper NodeContainer . NetDeviceContainer NodeContainer ( - ) PointToPointNetDevice . PointToPointChannel , PointToPointNetDevices. , PointToPointHelper, .


pointToPoint.Install (nodes) , Ā«-Ā» Ā«-Ā» . .


InternetStackHelper


, . .


InternetStackHelper stack;
stack.Install (nodes);

InternetStackHelper ā€” -, PointToPointHelper . Install NodeContainer . - (TCP, UDP, IP . .) .


Ipv4AddressHelper


IP-. IP-. API ā€” IP- ( ). first.cc,


Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");

, IP- 10.1.1.0, 255.255.255.0. , , , 10.1.1.1, 10.1.1.2 .. , nsā€‘3 IP- , (, ).


,


Ipv4InterfaceContainer interfaces = address.Assign (devices);

. nsā€‘3 IP- , Ipv4Interface. , , , Ipv4Interface. Ipv4InterfaceContainer .


-, IP-. .


4.2.7 Application


nsā€‘3 ā€” Application (). Application nsā€‘3 UdpEchoServerApplication UdpEchoClientApplication. , . UdpEchoServerHelper UdpEchoClientHelper , .


UdpEchoServerHelper


first.cc, UDP , .


UdpEchoServerHelper echoServer (9);

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

UdpEchoServerHelper. , , , . ā€” (). , , . . , , SetAttribute . , , SetAttribute Ā«Ā».


, UdpEchoServerHelper Install. , , - . , Install NodeContainter , Install , .


C++, , node.Get (1) ( ā€” Ptr ) NodeContainer, Install. C++ , , .

, echoServer.Install UdpEchoServerApplication NodeContainer, , 1. Install , ( , NodeContainer, ) .


Ā«startĀ» , Ā«stopĀ». . ApplicationContainer Start Stop. Time. C++, C++ double 1.0 nsā€‘3 Time, Seconds . , , C++ , , , . ,


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

, - ( ) () . , ( ), , .


UdpEchoClientHelper


echo , . UdpEchoClientApplication,
UdpEchoClientHelper.


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));;

- . UdpEchoClientHelper. , ( ) Ā«RemoteAddressĀ» Ā«RemotePortĀ» , .


, Ipv4InterfaceContainer IP-, . IP- . IP- . , () , IP-, , . , .


Ā«MaxPacketsĀ» , . Ā«IntervalĀ» , , Ā«PacketSizeĀ» , . 1024- .


-, - Start Stop, ( ).


4.2.8


. Simulator::Run.


Simulator::Run ();

,


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

1,0 , 2,0 10,0 . Simulator::Run, . 1,0 , - ( , , ). , t = 2,0 , -. , . - , .


, - , .


, (, MaxPackets ), - , . , Stop . , Simulator::Run . .


. Simulator::Destroy. ( nsā€‘3), , , . - ā€” , Simulator::Destroy . nsā€‘3 . nsā€‘3 , first.cc, :


Simulator::Destroy ();
return 0;
}

?


nsā€‘3 ā€” (DE). , . (, , ).


, , IPv6 , .. .. , , . , , . , Stop. Stop Simulator::Stop ( ).


, Simulator::Stop : . ( ) ā€” , . , . , , :


ā€¢ FlowMonitor ā€” ;


ā€¢ RIPng ā€” ;


ā€¢ ..


Simulator::Stop . , nsā€‘3 , RealtimeSimulator , , Simulator::Stop .


Simulator::Stop , . Simulator::Stop. , 11 :


+ Simulator::Stop (Seconds (11.0));
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

, 10 . 11 1 , , , ( 2 ).


Simulator::Stop Simulator::Run; Simulator::Run !


4.2.9


. , , scratch, , Waf. . examples/tutorial/first.cc scratch


$ cd ../.. 
$ cp examples/tutorial/first.cc scratch/myfirst.cc

, waf:


$ ./waf

, .


Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
[614/708] cxx: scratch/myfirst.cc -> build/debug/scratch/myfirst_3.o
[706/708] cxx_link: build/debug/scratch/myfirst_3.o -> build/debug/scratch/myfirst
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (2.357s)

( , scratch, scratch):


$ ./waf --run scratch/myfirst

:


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.418s) Sent 1024 bytes to 10.1.1.2
Received 1024 bytes from 10.1.1.1
Received 1024 bytes from 10.1.1.2

, , , . - , 1024- - 10.1.1.2. . -, , 1024 10.1.1.1. - , -, .


4.3 ns-3


, nsā€‘3, , . - : https://gitlab.com/nsnam/ns-3-dev.git. Mercurial nsā€‘3. ,


summary | shortlog | changelog | graph | tags | files

. :


drwxr-xr-x                               [up]
drwxr-xr-x                               bindings python  files
drwxr-xr-x                               doc              files
drwxr-xr-x                               examples         files
drwxr-xr-x                               ns3              files
drwxr-xr-x                               scratch          files
drwxr-xr-x                               src              files
drwxr-xr-x                               utils            files
-rw-r--r-- 2009-07-01 12:47 +0200 560    .hgignore        file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 1886   .hgtags          file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 1276   AUTHORS          file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 30961  CHANGES.html     file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 17987  LICENSE          file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 3742   README           file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 16171  RELEASE_NOTES    file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 6      VERSION          file | revisions | annotate
-rwxr-xr-x 2009-07-01 12:47 +0200 88110  waf              file | revisions | annotate
-rwxr-xr-x 2009-07-01 12:47 +0200 28     waf.bat          file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 35395  wscript          file | revisions | annotate
-rw-r--r-- 2009-07-01 12:47 +0200 7673   wutils.py        file | revisions | annotate

examples. , . tutorial ā€” first.cc. first.cc , .


src. , . src, src. core, . , ( ) ā€” abort.h. abort.h, abort.h, , . , , src/Applications/helper. Silakan mencari-cari di direktori tree untuk melihat di mana mencari tahu gaya program ns-3.


All Articles