You are on page 1of 47

Network Simulation

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

ns-3 has a the same


conceptual structure of
real network

9
Simulation Structure
On/off, client-server, bulk transfer

TCP / UDP

IP Address

Network devices (Ethernet, wireless)

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:

• DataRate: transmission rate (bandwidth) of the network device.


• Delay: physical speed-of-light delay for the communication channel between two nodes.
• DropTailQueue: A FIFO packet queue that drops tail-end packets on overflow.
• ErrorModel: used to indicate that a packet/bit should be considered to be errored by the
receiver network device, according to a specific error model.

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

ü We created two empty nodes


ü We crated a link
ü We connected link to nodes
Node 0 Node 1 ü Nodes got IP addresses
10.1.1.1 ü Server App & UDP Socket
10.1.1.2
24
Script Structure
Build the Simulation Topology: [5] Add Application
- Client Application, and client’s attributes

ü We created two empty nodes


ü We crated a link
ü We connected link to nodes
ü Nodes got IP addresses
Node 0 Node 1
ü Server App & UDP Socket
10.1.1.1 10.1.1.2 ü Client App & UDP Socket
25
Script Structure
Set start, stop time for your script:

ü We created two empty nodes


ü We crated a link
ü We connected link to nodes
ü Nodes got IP addresses
ü Server App & UDP Socket
ü Client App & UDP Socket
ü Simulation is ready to run

26
Script Structure

Run the script, see output..

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

Multimedia Processing and Communication (MPC) 33


Output Post-processing
1) Print debug and logging messages:
• Print messages can placed anywhere in the source code or the script files

#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;
...
}

Multimedia Processing and Communication (MPC) 34


Output Post-processing
1) Print debug and logging messages:
• Using NS_LOG_X, ns3-logining should be enabled in the script, where “X”
indicates the log level (i.e. info, warn, debug, or all)
LogComponentEnable("dumbbell-tcp", LOG_LEVEL_ALL);
LogComponentEnable("BulkSendApplication", LOG_LEVEL_INFO);
LogComponentEnable("TcpNewReno", LOG_LEVEL_DEBUG);

• Run the simulation like: waf –run ScriptName >& file.txt to save the output to
a text file “file.txt”.

Multimedia Processing and Communication (MPC) 35


Output Post-processing
2) ns-3 embedded tracing to txt files:
• ns-3 has multiple wrapper functions/classes for tracing (see our example
dumbbell-tcp.cc)
#include "ns3/ascii-trace.h”
AsciiTraceHelper ascii;
bottleneck.EnableAsciiAll (ascii.CreateFileStream (”bottleneck-dumbbell-tcp.tr"));
FwLink.EnableAsciiAll (ascii.CreateFileStream (”bottleneck-dumbbell-tcp.tr"));
ReLink.EnableAsciiAll (ascii.CreateFileStream (”bottleneck-dumbbell-tcp.tr"));

• Output is saved in “tr files”. Can be opened by any text editors.


• Bash commands i.e. (grep / awk / sed) are useful tools to process trace files.

Multimedia Processing and Communication (MPC) 36


Output Post-processing
3) ns-3 embedded tracing to PCAP files:
• ns-3 allows traces into “PCAP files”. (see dumbblle-tcp.cc example)
#include "ns3/pcap-trace.h
bottleneck.EnablePcapAll ("dumbbell-tcp", true);
FwLink.EnablePcapAll ("dumbbell-tcp", true);
ReLink.EnablePcapAll ("dumbbell-tcp", true);
• PCAP files are generated on the working directory using the following naming
format: ScriptName-NodeNumber-InterfaceNumber.pcap
• Wireshark or tcpdump can be used to open PCAP files.

Multimedia Processing and Communication (MPC) 37


Output Post-processing
Sample Wireshark plots: (statistics-> I/O Graph or statistics-> TCP StreamGraphs)

Multimedia Processing and Communication (MPC) 38


Output Post-processing
4) ns-3 built-in modules for post-processing
• ns-3 contains several modules to to provide a flexible way to measure
the performance of network protocols (i.e. Flow Monitor)
https://www.nsnam.org/docs/models/html/flow-monitor.html
• It uses a probes inside each node to track each packet and allows a
detailed analysis of the traffic.
• For examples, see (examples/tcp/tcp-variants-comparison.cc)
• Output are generated into XML formatted report about flow statistics.

Multimedia Processing and Communication (MPC) 39


Output Post-processing
Making Plots:
• gnuplot or xmgrace tools can be used to generate plots from ns-3
trace files;
• Define the parameters you are interested to plot and identify the
trace files that contains these parameters;
• Use bash commands such as: grep, awk, and sed to extract the traced
parameters;
• Use xmgrace / gnuplot to draw the target plot.

Multimedia Processing and Communication (MPC) 40


Output Post-processing
Making Plots: Example

• Running dumbbell-tcp script, plot the CWND of TCPNewReno for the


first source node.
üCWND can be traced by TCP tracing functions (to .tr file)
üCWND can be printed using our log messages in TCPNewReno code.
üCWND can be analyzed from the traced .pcap file

Multimedia Processing and Communication (MPC) 41


Output Post-processing
Making Plots: Example
• .trace_cwnd.tr file contains two columns (simulation time, cwnd
value)
• Easy to plot (i.e. xmgrace trace_cwnd.tr)

Multimedia Processing and Communication (MPC) 42


Output Post-processing
Making Plots: Example
• We have the simulation log file file.txt BUT it contains mixed info.

Multimedia Processing and Communication (MPC) 43


Output Post-processing
Making Plots: Example
• You may use grep to filter the target rows:
i.e.: cat file.txt | grep “node 2] TcpNewReno CWND”

Multimedia Processing and Communication (MPC) 44


Output Post-processing
Making Plots: Example
• Then, you may add awk command to filter the columns:
i.e.: cat file.txt | grep “node 2] TcpNewReno CWND” | awk ‘{print $1, $6}’ > cwnd.txt

Then use xmgrace cwnd.txt

Multimedia Processing and Communication (MPC) 45


Output Post-processing
Making Plots:

üDemo, tracing & plotting example..

Multimedia Processing and Communication (MPC) 46


Question ?

You might also like