Download - ns-3 Training
![Page 1: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/1.jpg)
ns-3 Training
Computer and Communication Network LabDepartment of Electrical Engineering
National Sun Yat-Sen University
5/19/2014
![Page 2: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/2.jpg)
Topics Getting Started ns-3
What is ns-3? Installation
A First ns-3 Script Two tutorial examples
A simple example for this project Complete the remaining parts
2
![Page 3: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/3.jpg)
Getting Started ns-3
• Please read the following documents• ns-3 overview
• http://www.nsnam.org/docs/ns-3-overview.ppt• http://www.nsnam.org/docs/ns-3-overview.pdf
• ns-3 Tutorial• http://www.nsnam.org/docs/release/3.13/tutorial/ns-3-tutorial.pdf
• ns-3 Manual• http://www.nsnam.org/docs/release/3.13/manual/ns-3-manual.pdf
![Page 4: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/4.jpg)
What is ns-3? ns-3 is a discrete-event network simulator for
Internet systems ns-3 allows researchers to study Internet protocols
and large-scale systems in a controlled environment ns-3 is a new simulator (not backwards-compatible
with ns-2) ns-3 is a free, open source software project
organized around research community development and maintenance the target user community is networking researchers
and educators4
![Page 5: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/5.jpg)
Extensible Software Core Written in C++ with optional Python interface
extensively documented API (doxygen):
http://www.nsnam.org/doxygen-release/index.html5
![Page 6: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/6.jpg)
Node Basics An ns-3 Node is a husk of a computer to which
applications, stacks, and NICs are added
6
![Page 7: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/7.jpg)
Tracing and Statistics Tracing is a structured form of simulation output Example (from ns-2):
Problem: Tracing needs vary widely would like to change tracing output without editing the
core would like to support multiple outputs 7
![Page 8: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/8.jpg)
ns-3 Has A New Tracing Model ns-3 solution: decouple trace sources from trace
sinks
Benefit: Customizable trace sinks8
![Page 9: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/9.jpg)
Downloading ns-3 http://www.nsnam.org/
Latest release: ns-3.16 (2012/12/21)
9
![Page 10: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/10.jpg)
Problems under Windows Cygwin or MinGW
If you do use Cygwin or MinGW and use Logitech products it can cause Cygwin or MinGW DLLs to die in mysterious
way
Note that NSC is not supported on OSX or Cygwin. Network Simulation Cradle
10
![Page 11: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/11.jpg)
Building ns-3 (1/5)
11
# ./build.py
![Page 12: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/12.jpg)
Building ns-3 (2/5)
12
# ./waf -d optimized configure ns-3 uses the waf build system
![Page 13: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/13.jpg)
Building ns-3 (3/5)
13
# ./waf -d debug configure
![Page 14: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/14.jpg)
Building ns-3 (4/5)
14
# ./test.py -c core
![Page 15: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/15.jpg)
Building ns-3 (5/5)
15
![Page 16: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/16.jpg)
Running a Script
16
./waf --run hello-simulator
![Page 17: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/17.jpg)
Building Your Script
17
# cp examples/tutorial/first.cc scratch/myfirst.cc ./waf
![Page 18: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/18.jpg)
Building Your Script
18
# ./waf --run scratch/myfirst
![Page 19: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/19.jpg)
A First ns-3 Script
• /ns-allinone-3.10/ns-3.10/examples/tutorial• first.cc• third.cc
![Page 20: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/20.jpg)
Boilerplate The first line in the file is an emacs mode line.
The ns-3 simulator is licensed using the GNU General Public License.
20
![Page 21: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/21.jpg)
Module Includes The code proper starts with a number of include
statements.
../../build/debug/ns3
21
![Page 22: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/22.jpg)
Ns3 Namespace The next line in the first.cc script is a namespace
declaration.
Logging
22
![Page 23: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/23.jpg)
Main Functions The next lines of the script you will find are,
23
ns3 提供的 log 訊息分成了以下幾個等級:1.NS_LOG_ERROR — Log error messages; 2.NS_LOG_WARN — Log warning messages; 3.NS_LOG_DEBUG — Log relatively rare, ad-hoc debugging messages; 4.NS_LOG_INFO — Log informational messages about program progress; 5.NS_LOG_FUNCTION — Log a message describing each function called; 6.NS_LOG_LOGIC – Log messages describing logical flow within a function; 7.NS_LOG_ALL — Log everything. 8.NS_LOG_UNCOND – Log the associated message unconditionally.
![Page 24: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/24.jpg)
Topology Helpers Create the ns-3 Node objects that will represent
the computers in the simulation.
We are constructing a point to point link
24
![Page 25: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/25.jpg)
Topology Helpers We will need to have a list of all of the NetDevice
objects that are created
25
![Page 26: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/26.jpg)
Internet Stack Helper Protocol stacks installed on our nodes
TCP, UDP, IP, etc.
Ipv4AddressHelper
make the association between an IP address and a device
26
![Page 27: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/27.jpg)
Applications Two specializations of the core ns-3 class
Application called UdpEchoServerApplication UdpEchoClientApplication
UdpEchoServerHelper
27
![Page 28: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/28.jpg)
Applications UdpEchoClientHelper
28
![Page 29: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/29.jpg)
Simulator What we need to do at this point is to actually
run the simulation.
scheduled events in the simulator at 1.0 seconds, 2.0 seconds and two events at 10.0 seconds
29
![Page 30: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/30.jpg)
Building Your Script Drop your script into the scratch directory
Now build your first example script using waf
30
![Page 31: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/31.jpg)
Building Your Script You can now run the example
31
![Page 32: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/32.jpg)
Building a Wireless Network Topology Add the Wifi and the mobility modules
The network topology illustration follows:
32
![Page 33: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/33.jpg)
Building a Wireless Network Topology For enabling or disabling logging components
and for changing the number of devices created
33
![Page 34: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/34.jpg)
Building a Wireless Network Topology Part of the Wifi network
Configure the PHY and channel helpers
Yet Another Network Simulator M. Lacage and T. R. Henderson, “Yet Another Network
Simulator,” WNS2 ns-2: The IP Network Simulator, Italy, 2006. http://cutebugs.net/files/wns2-yans.pdf
34
![Page 35: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/35.jpg)
Building a Wireless Network Topology Create a channel object and associate it to our
PHY layer object manager
NqosWifiMacHelper object to set MAC parameters
rate control algorithm AARF (Adaptive Auto-Rate Fallback ) algorithm 35
![Page 36: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/36.jpg)
Building a Wireless Network Topology The SSID of the infrastructure network
Create the wifi devices of these stations
36
![Page 37: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/37.jpg)
Building a Wireless Network Topology Configure the AP (access point) node
Shares the same set of PHY-level Attributes (and channel) as the stations
37
![Page 38: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/38.jpg)
Building a Wireless Network Topology Set some Attributes controlling the “position
allocator” functionality
38
The number of objects layed out on a line.
![Page 39: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/39.jpg)
Building a Wireless Network Topology Need to tell them how to move
RandomWalk2dMobilityModel random direction random speed
Rectangle (double _xMin, double _xMax, double _yMin, double _yMax)
39
![Page 40: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/40.jpg)
Building a Wireless Network Topology Want the access point to remain in a fixed
position during the simulation
Protocol stacks
40
![Page 41: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/41.jpg)
Building a Wireless Network Topology assign IP addresses to the device interfaces
41
![Page 42: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/42.jpg)
Building a Wireless Network Topology Enable internetwork routing
Create just enough tracing to cover all three networks
42
![Page 43: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/43.jpg)
Building a Wireless Network Topology Run the simulation, clean up and then exit the
program
Output
43
![Page 44: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/44.jpg)
Read the pcap files
44
![Page 45: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/45.jpg)
Plot figures
45
![Page 46: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/46.jpg)
An Example of MANET
• Reference • /ns-allinone-3.10/ns-3.10/examples/wireless/wifi-
hidden-terminal.cc
![Page 47: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/47.jpg)
Codes (1/7)
47
![Page 48: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/48.jpg)
Codes (2/7)
48
![Page 49: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/49.jpg)
Codes (3/7)
49
![Page 50: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/50.jpg)
Codes (4/7)
50
![Page 51: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/51.jpg)
Codes (5/7)
51
![Page 52: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/52.jpg)
Codes (6/7)
52
![Page 53: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/53.jpg)
Codes (7/7)
53
![Page 54: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/54.jpg)
Result
54
![Page 55: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/55.jpg)
Need to do…… (1/3) Transmission range of a node
ns3::RangePropagationLossModel MaxRange
Node moving speed ns3::RandomWaypointMobilityModel
Speed Pause
Node data rate ns3::ConstantRateWifiManager 55
![Page 56: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/56.jpg)
Need to do…… (2/3) RTS retry limit
ns3::UanMacRc RetryRate
Buffer size ns3::TcpSocket
SndBufSize
AODV hello periods ns3::aodv::RoutingProtocol
HelloInterval 56
![Page 57: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/57.jpg)
Need to do…… (3/3) Uniform distribution in a square with 500 meters
ns3::RandomRectanglePositionAllocator
ns3::UniformVariable
57
![Page 58: ns-3 Training](https://reader030.vdocuments.site/reader030/viewer/2022033107/56815acb550346895dc89da9/html5/thumbnails/58.jpg)
Q & A
58