Vous êtes sur la page 1sur 50

NS-3 1

TA: , jhkoo@mwnl.snu.ac.kr shbyeon@mwnl.snu.ac.kr

NS-3 Experiment Plan

Week 1 Linux, vi editor command Introduction and install of NS-3 Structure of NS-3 Output system of NS-3 Week 2 Transport layer (TCP, UDP) Transport layer model in NS-3 Multiple levels of tracing system System performance analysis using tracing system Week 3 MAC protocol simulation (CSMA) LAN topology with switch Week 4 Wireless LAN model in NS-3 Analysis of wired and wireless network topology Week 5 Wireless LAN link adaptation Rate adaptation in NS-3

NS-3 Experiment Plan

Environment

Server: 5 servers ID: Check ID table in next page Default password: last 4 numbers of your student number 5 times Submit: main file, simulation result, report Submit homework to TAs e-mail (Title: [NS-3]) Based on preparation for class Every week
Attendance (10%), Quiz (20%), In-class (30%), Homework (40%)

Homework

Quiz

Assessment

ID Table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2011-23360 2002-12318 2003-11993 2003-12060 2003-12832 2005-11823 2007-11707 2007-11816 2007-15611 2007-11547 2007-11548 2007-11549 2008-11585 2008-11632 2008-11969 ID ns23360 ns12318 ns11993 ns12060 ns12832 ns11823 ns11707 ns11816 ns15611 ns11547 ns11548 ns11549 ns11585 ns11632 ns11969 cwpark auditor1 auditor2 auditor3 auditor4 auditor5 Server 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 5

Server1: 147.46.143.236 Server2: 147.46.143.237 Server3: 147.46.143.238 Server4: 147.46.143.239 Server5: 147.46.243.250

Object of NS-3 Experiment


Object

Network evaluation from simulation

Requisitions

Basic usage of Linux and understanding of C++ Basic knowledge about network

Contents

For NS-3 beginners Basic structure of NS-3 Usage of NS-3 functions and evaluating network topology

Object of NS-3 Experiment


Validation Analysis, Measurement, Simulation

Analytical model

Unrealistic - Requires a lot of assumptions Hard to solve and validate (ex. NP hard problem). Cheap Relatively short run time depending on the algorithm Realistic Expensive Hard to implement the proposed scheme Relatively realistic Relatively cheap (needs only one simulation machine) Easy to implement compared to real measurement Run time depends on the proposed protocol

Real measurement

Simulation

Object of NS-3 Experiment

Analytical model Realistic


Cost Implementation

Real Measurement Very good


Very expensive Hard

Simulation Good
Very cheap Easy

Bad
Very cheap Hard

Week 1
- Introduction to NS-3 -

NS-3
Ns-3 is targeted at networking research.
Discrete event simulator

Packet level simulator

Layered architecture

Wired and wireless network

NS-3 status
Periodic update

Latest version is ns-3.12.1

Supporting platform

FreeBSD, Linux, SunOS, Solaris, Windows (cygwin)

Free, open source software project Website

http://www.nsnam.org/ Can find the doxigen, reference manual, and tutorial

NS-3 components
Ns-3 simulator Pre-processing

Traffic / topology generation Alignment with real systems (sockets, device driver interfaces)

Post-processing

Ns-3 output file (trace file) analysis Throughput, delay, jitter, drop Various tracing system Graph xgraph, gnuplot

NS-3 all-in-one package Directory Structure


ns-allinone-3.12.1

ns-3.12.1

nsc-0.5.2

Pybindgen0.15.0.795

... ...

bindings

build

examples

...

src

error-model

csma

Example simulation scripts

mobility

network

...

...

Starting NS-3 Simulation

Connection to Linux Server


Connect to server using SSH

Use xShell ->

Server IP address in slide 4

Vi setting

@ns3-exp:~$ cp /etc/vim/vimrc .vimrc @ns3-exp:~$ vi .vimrc


set nu syntax on set autoindent set cindent set hls set showmatch set smartindent set tabstop=4

How to Install NS-3


Ns-3 download: http://www.nsnam.org/download.html

ns-allinone-3.12.1.tar.bz2

[root@mwnl ~]# tar xvf ns-allinone-3.12.1.tar.bz2 [root@mwnl ~]# cd ns-allinone-3.12.1

Building

[root@mwnl ~/ns-allinone-3.12.1]# ./build.py

Done !

Setting environment

[root@mwnl [root@mwnl [root@mwnl [root@mwnl

~]# ~]# ~]# ~]#

vi vi vi vi

~./waf d optimized configure ~./waf d debug configure ~./waf ~./test.py c core

Simple Example
cd ns-allinone-3.12.1/ns-3.12.1 /ns-3.12.1$ ./waf --run scratch/scratch-simulator Output

Conceptual Overview of NS-3


1. 2. 3. Key Abstractions Simulation Procedure Simulation Example

Key Abstractions

1.Node
Host, end system in the Internet Basic computing device abstraction Represented in C++ by the class Node

2.Application
A User program that generates some activity to be simulated Ns-3 applications run on ns-3 Nodes to drive simulations Represented in C++ by the class Application

3.Channel
Medium connected by nodes over which data flows Represented in C++ by the class Channel Ex) CsmaChannel, PointToPointChannel, WifiChannel

Key Abstractions

4. Net device
Like a specific kind of network cable and a hardware device (Network Interface Cards; NICs) NICs are controlled using the software driver, net devices Represented in C++ by the class NetDevice Provide methods for managing connections to Node and Channel Ex) CsmaNetDevice (work with CsmaChannel) WifiNetDevice (work with WifiChannel)

5. Topology helpers
Topology helpers make ns-3 core operations as easy as possible Create a NetDevice, add an address, install that net device on a Node, configure the nodes protocol stack and connet the NetDevice to a Channel

Key Abstractions
5. Topology Helpers
any Node object

I. NodeContainer: Provide a convenient way to create, manage and access II.PointToPointHelper: Configure and connect PointToPointNetDevice

and PointToPointChannel objects. Set DataRate on NetDevices and Delay on Channel

III.NetDeviceContainer: To Install NetDevice at the nodes and create


Channel between the nodes

IV.InternetStackHelper: To Install an Internet Stack (TCP, UDP, IP, etc.)


on each of the nodes in the node container

V. Ipv4AddressHelper: Manage the allocation of IP address and assign


addresss to the devices using Ipv4InterfaceContainer

NS-3 basic simulation model


Application Application Sockets-like API Application Application

Protocol stack

Packet(s)

Protocol stack

Node
NetDevice NetDevice

Node NetDevice NetDevice

Channel
Channel

Simulation procedure
1. Turning on logging

2. Creating network topology

3. Creating application (traffic)

4. Running simulator

Simulation procedure
-1. Turning on logging -

Define log component

NS_LOG_COMPONENT_DEFINE ( name )

Enable log component

LogComponentEnable ( name, level )

Simulation procedure
- 2.Creating Network Topology -

Topology Helpers

NodeContainer

NodeContainer Ptr<Node> NodeContainer::Create (n) Example)


NodeContainer nodes; nodes.Create (2);

n: # of Nodes

Simulation procedure
- 2.Creating Network Topology PointToPointHelper

void PointToPointHelper::SetDeviceAttribute (name, value) void PointToPointHelper::SetChannelAttribute (name, value) NetDeviceContainer PointToPointHelper::Install (NodeContainer c)

NetDeviceContainer

NetDeviceContainer Ptr<NetDevice>

Example
PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install (nodes);

Simulation procedure
- 3.Creating application (traffic) UdpEchoServerHelper

UdpEchoServerHelper::UdpEchoServerHelper ( port ) ApplicationContainer UdpEchoServerHelper::Install (NodeContainer c ) UdpEchoClientHelper::UdpEchoClientHelper ( ip, port ) void UdpEchoClientHelper::Setattribute ( name, value ) ApplicationContainer UdpEchoClientHelper::Install (NodeContainer c )
UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0));

UdpEchoClientHelper

Example

Simulation procedure
- 4.Running simulator-

Start Simulator

Simulator::Run ();

Destroy Simulator

Simulator::Destroy ();

Simulation example (1/3)


#include #include #include #include "ns3/core-module.h" "ns3/simulator-module.h" "ns3/node-module.h" "ns3/helper-module.h"

using namespace ns3; NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); int main (int argc, char *argv[]) { LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install (nodes);

Simulation example (2/3)


InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Simulator::Run (); Simulator::Destroy (); return 0; }

Smulation example (3/3)


../ns-3.12.1] ./waf -run scratch/example1
Output
Sent 1024 bytes to 10.1.1.2 Received 1024 bytes from 10.1.1.1 Received 1024 bytes from 10.1.1.2

Output Systems
1. Logging Modules 2. Command Line Arguments 3. Tracing System

Logging Module

Output messages from modules Useful when debugging NS_LOG environment variable NS_LOG_FUNCTION level information Verbosity level

NS NS NS NS NS NS NS NS

LOG LOG LOG LOG LOG LOG LOG LOG

ERROR Log error messages; WARN Log warning messages; DEBUG Log relatively rare debugging messages; INFO Log informational messages about program progress; FUNCTION Log a message describing each function called; LOGIC Log messages describing logical flow within a function; ALL Log everything. UNCOND Log the associated message unconditionally.

Logging Module
Example 1

$ export NS_LOG=UdpEchoClientApplication=level_all $ ./waf --run scratch/example1

Output:
build finished successfully (0.404s) UdpEchoClientApplication:UdpEchoClient() UdpEchoClientApplication:SetDataSize(1024) UdpEchoClientApplication:StartApplication() UdpEchoClientApplication:ScheduleTransmit() UdpEchoClientApplication:Send() Sent 1024 bytes to 10.1.1.2 Received 1024 bytes from 10.1.1.1 UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20) Received 1024 bytes from 10.1.1.2 UdpEchoClientApplication:StopApplication() UdpEchoClientApplication:DoDispose() UdpEchoClientApplication:~UdpEchoClient()

Logging Module
Example 2

$ export NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time $ ./waf --run scratch/example1

Output:
0s UdpEchoClientApplication:UdpEchoClient() 0s UdpEchoClientApplication:SetDataSize(1024) 2s UdpEchoClientApplication:StartApplication() 2s UdpEchoClientApplication:ScheduleTransmit() 2s UdpEchoClientApplication:Send() 2s UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2 Received 1024 bytes from 10.1.1.1 2.00737s UdpEchoClientApplication:HandleRead(0x9aead30, 0x9aeb378) 2.00737s UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2 10s UdpEchoClientApplication:StopApplication() UdpEchoClientApplication:DoDispose() UdpEchoClientApplication:~UdpEchoClient()

Logging Module
Example 3

$ export NS_LOG=*=level_all|prefix_func|prefix_time $ ./waf --run scratch/example1

It prints out all of the logging ./waf -run scratch/myfirst > log.out 2>&1 2>&1 : stderr > stdout

Adding logging to your code

Example

NS_LOG_INFO (Creating Topology) in your source code $ export NS_LOG=FirstScriptExample=info

Command Line Arguments


Using command line arguments, can change the simulation
parameter

First declare the command line parser in main function


CommandLine cmd; cmd.Parse (argc, argv);

Example

./waf --run "scratch/myfirst PrintHelp ./waf -run scratch/myfirst PrintAttributes=ns3::PointToPointNetDevice ./waf --run scratch/myfirst -ns3::PointToPointNetDevice::DataRate=5Mbps ns3::PointToPointChannel::Delay=2ms

Command Line Arguments


When add your own hooks.

cmd.AddValue in main function

Example
int main (int argc, char *argv[]) { uint32_t nPackets =1; CommandLine cmd; cmd.AddValue("nPackets", "Number of packets to echo", nPackets); Cmd.Parse (argc, argv);

echoClient.SetAttribute (MaxPackets, UintegerValue (nPackets));

./waf --run scratch/myfirst nPackets=2

Tracing System
Tracing is a structured form of simulation output

Tracing System
ASCII Tracing

Trace file similar to that of NS-2

AsciiTraceHelper ascii; pointToPoint.EnableAsciiAll (ascii.CreateFileStream(myfirst.tr)); Simulator::Run (); Simulator::Destroy (); return 0;

Output (myfirst.tr)
+ 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024) - 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024)

Tracing System
Trace file format
00 01 02 03 04 05 06 07 08 09 10 + 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader ( Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header ( tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader ( length: 1032 49153 > 9) Payload (size=1024)

Tracing System
PCAP Tracing

.pcap file format Traffic trace analyze pointToPoint.EnablePcapAll (myfirst);

Reading output with tcpdump


$ tcpdump -nn -tt -r myfirst-0-0.pcap
reading from file myfirst-0-0.pcap, link-type PPP (PPP) 2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length tcpdump -nn -tt -r myfirst-1-0.pcap reading from file myfirst-1-0.pcap, link-type PPP (PPP) 2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length

1024 1024

1024 1024

Tracing System
Reading output with Wireshark http://www.wireshark.org/download.html

Summary of Output System


1. Logging Module

Used to output debug messages based on the pre-defined log component

2. Command Line Argument

Change parameters without direct modification of main source code

3. Tracing System

Used to generate output for checking the operation and measure the system performance Use trace source and trace sink (we study the tracing system further in the 2nd class)

In-Class Assignment
1. Type the code from page 29 to 31 into scratch
folder using vi editor (its form should be ~.cc)

2. You have to change the number of packets to 5

use Command Line Argument

3. Check and verify all the output system that we


covered right before

You have to 1. print out all of the logging into .out file 2. use AsciiTraceHelper 3. use PCAP Trace and 1. Check .pcap file both TCPDUMP and Wireshark

Homework
1. Checking the Protocol: PCAP Tracing
1.

Wireshark Example PCAP Tracing IP header Field .

2. Survey the Vi commands more than 20 commands


1.

You can find some basic commands in next week quiz

3. Explain your example code line by line


1.

2.

Example code should be latest version that contains all the contents we covered in the class Using the logging will be helpful

Report: _hw1.doc(or hwp) E-mail: jhkoo@mwnl.snu.ac.kr Dead line: 10 17 () 23:59 Delay is not allowed

References
Network Simulator

http://www.nsnam.org

NS-3 tutorial

http://www.nsnam.org/tutorials.html

NS-3 manual

Appendix

-Basic Linux Commands-

ls short listing of directory contents mkdir <directory name> make directory cd <path> - change directory rm r <directory name> - remove directory rm <filename> -remove file cp <filename1> <filename2> - copy grep search for a pattern in a file find - find a file

Ex) find ./ -name *.cc exec grep cwnd {} \; -print

tar [option] <filename> - zip/unzip file

Ex) tar xvf abcd1234.tar.gz

Reference: http://www.debianhelp.co.uk/commands.htm

Appendix -Vi editor Screen-based UNIX editor Simple Vi Commands


i : enter insert mode escape : enter command mode dd : delete a line y : copy v : mark p: paste /: search :wq : save and quit

Reference http://www.eng.hawaii.edu/Tutor/vi.html

Vous aimerez peut-être aussi