Professional Documents
Culture Documents
with
Ahmed Abdelsalam
Overview:
• Lecture 1:
• Overview
• Installation and Use
• Simulation example
• Output post-processing
2
Overview - ns-3
• Free and open source discrete event network simulator.
• Available for Linux, OS-X, and Windows “with Cygwin tools”.
• Written in C++, with optional Python interface for visualization and
scripting.
• Built-in helpers to make “scripting” in C++ easy.
• Well documented, manual, tutorial, and many examples.
• Supports different network layers:
– Applications: On/Off, Bulk transfer, HTTP, etc.
– Transport: TCP, UDP.
– Network: IPv4, IPv6, routing.
– Physical: Ethernet, PPP, 802.11, LTE, mobility models.
3
Installation and Use
• Lecture 1:
• Overview
• Installation and Use
• Simulation example
4
Installation and Use
ØRecommended to install ns-3
• Use virtual machine (i.e. VirtualBox https://www.virtualbox.org).
• Install Linux Ubuntu.
• Install the minimum prerequisites requirements.
• ns-3 Installation includes following steps:
• Download;
• Build;
• Validation.
• Detailed instructions:
• http://www.nsnam.org/getting_started.html
• http://www.nsnam.org/wiki/index.php/Installation
• For C++ coding, Eclipse with Mercurial can be a good tool (http://www.eclipse.org).
5
Installation and Use
• Download ns-3 package, unzip it (*for projects, recommend ver. 3.23)
$ wget http://www.nsnam.org/release/ns-allinone-3.23.tar.bz2
$ tar -xjf ns-allinone-3.23.tar.bz2
• Check for prerequisites, and build ns-3 (http://www.nsnam.org/wiki/Installation)
$ cd ns-allinone-3.23/ns-3.23/
$ ./waf configure -–enable-tests -–enable-examples
$ ./waf build
• Validate the build
$ ./waf check
• Test the simulator
$ ./waf --run hello-simulator
Ø Should see “Hello Simulator”
6
Installation and Use
Pre-installed virtual machine “OVA image” (6.5 GB) is distributed during
the class.
üOnce you already downloaded the OVA file, extract the image using this command:
tar -jxvf ns3-projects.tar.bz2 (recommended to keep the original file for backup)
üIn VirtualBox, go to: “File -> Import Appliance” in the menu bar;
üClick the “Open Appliance” button to select ns3-projects.ova file, click “Next”;
üIn the next window see the configuration of the current virtual appliance. You may need
to make changes, then click ”Import”;
üOnce the process is completed, you should see the new VM in your list, called “ns-3-
projects”.
üLinux Password “ns3-123”
7
Simulation Steps:
a) Define what you want to simulate;
b) Define your simulation topology (nodes, channels, network
interfaces, network stack, applications);
c) Scratch your network topology on a sheet of paper;
d) Build the simulation script using a text editor or Eclipse;
e) Run your script using WAF ($ ./waf –run ScriptName);
f) Analyse the output traces.
8
Simulation Structure
9
Simulation Structure
On/off, client-server, bulk transfer
TCP / UDP
IP Address
10
Simulation Structure
Application attributes:
• App Helper Name: type of application to use (BulkSendHelper, OnOffHelper,
DashClientHelper, DashServerHelper, etc.)
• Transport protocol: ns3::TcpSocket / Udp…Helper.
• Remote: address for the receiver app.
• App.Start: time the app should start.
• App.Stop: time the app should end.
• SendSize: size of the application segment to transmit.
• MaxBytes: total number of bytes to be generated by the App.
11
Simulation Structure
TCP Socket attributes:
• TcpL4Protocol::SocketType: type of TCP congestion control (TcpWave, TcpReno,
TcpNewReno, TcpWestwood, TcpTahoe).
• TcpSocket::SndBufSize / TcpSocket::RcvBufSize sender/receiver buffer size (bytes).
• InitialCwnd: number of segments to be transmitted in the initial window.
• ACKs: configure ACK options (i.e. delayed ACK count, SACK, etc.).
• MSS: maximum allowed TCP segment size.
Some TCP versions (i.e. TCPWave) has additional attributes (i.e. Beta, TxTimer)
12
Simulation Structure
IP layer attributes:
• SetBase: network base address to start a range for IP addressing.
• NewNetwork: start addressing for a new network.
• Assign: assign an IP address to a network interface.
• PopulateRoutingTables: enable a global routing between different networks.
13
Simulation Structure
NetDevice & channel attributes:
14
Script Structure
ns3/examples/tutorial/first.cc
Send a Packet
P2P link:
BWND=x / Delay= y
Client Server
Echo the packet back
15
Script Structure
• Authorship and code description:
16
Script Structure
• Includes: to include header files for used modules.
17
Script Structure
• ns-3 namespace: global namespace declaration.
• LOG_COMPONENT: Script definition for logging module.
• LogComponentEnable: Enable different logging levels for each module.
18
Script Structure
• Command Line Arguments: Allows configuration from command line
e.g., $ ./waf --run “first --bandwidth=10Mbps –delay=100ms”
19
Script Structure
Build the Simulation Topology: [1] Nodes
• Most components in ns-3 is managed in containers ü We created two empty nodes
Node 0 Node 1
20
Script Structure
Build the Simulation Topology: [2] Link
• ns-3 has a lot of helpers to make things easy. ü We created two empty nodes
ü We crated a link
• Set the link attributes (bandwidth and delay)
Node 0 Node 1
21
Script Structure
Build the Simulation Topology: [3] Network Devices
• Create NetDevice, Install it in the node, ü We created two empty nodes
ü We crated a link
• Connect the link. ü We connected link to nodes
Node 0 Node 1
22
Script Structure
Build the Simulation Topology: [4] IP Stack
ü We created two empty nodes
ü We crated a link
ü We connected link to nodes
ü Nodes got IP addresses
Node 0 Node 1
10.1.1.1 10.1.1.2
23
Script Structure
Build the Simulation Topology: [5] Application
- Server Application
26
Script Structure
27
Simulation example
• Lecture 1:
• Overview
• Installation and Use
• Simulation example
• Output post-processing
28
Simulation Example Access links
Bottleneck Link
TCP Flow
Node 2
Node 0
(receiver 1)
(sender 1)
Router 0 Router 1
Node 1 Node 3
(sender 2) (receiver 2)
ACKs
29
Simulation Example
• Hardware: See dumbbell-tcp script
• 4 nodes (senders/ receivers) /ns-3.23/scratch/dumbbell-tcp.cc
• 2 Routers
• Access links (Senders – Router0 & Receivers – Router1)
• Bottleneck (Router0 – Router1)
• Net devices (all nodes, multiple devices per node)
• IP Address (multiple networks; we need routing)
• TCP stack (use of different TCP variants)
• Application (multiple bulk transfer flows)
30
Installation and Use
üPractical demo..
31
Simulation example
• Lecture 1:
• Overview
• Installation and Use
• Simulation example
• Output post-processing
32
Output Post-processing
• Several methods can be used for output analysis:
• Printing debug and logging messages
• Using ns-3 standard embedded tracing system to txt files
• Using ns-3 tracing to .pcap files
• ns-3 built-in tools for post-processing
#include <iostream>
#include "ns3/log.h”
int main ()
{
NS_LOG_DEBUG("rtt= " << m_rt->GetEstimate().GetMilliSeconds());
...
std::cout << "The current transmission rate is " << rate << std::endl;
...
}
• Run the simulation like: waf –run ScriptName >& file.txt to save the output to
a text file “file.txt”.