Anda di halaman 1dari 42

CIS3210 Computer Networks

Performance Evaluation, Simulation Tools

Jason Ernst, University of Guelph - Fall 2011

Housekeeping

A3 Simulation Tools,

Ns2, ns3 both work on the Sunrays under Linux


Ns2 must be run within the source directory

Ns3 can run as is since it requires the waf tool


Compilation takes quite some time, especially if there are many

others using the system at the same time

Housekeeping

Reynolds 114 Reminder from SOCS: No Food / Drink Allowed inside of this lab room

Outline

NS2 Overview NS3 Overview

Setup, Defining Topology, Traffic Models, Routing

NS2 Sample Scenario


Basic Setup of the Simulation Breaking the scenario into multiple files Defining Topology Defining Traffic Models Defining Routing Models

NS2: Basic Setup


Simulator Object: set ns[new Simulator]

Trace file init: set nf [open out.nam w] $ns namtrace-all $nf

NS2: Basic Setup


Finish procedure to cleanup, close trace files: proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 }

NS2: Basic Setup

Event time for starting and stopping simulation

$ns at 5.0 finish $ns run

NS2: Breaking scenario into multiple files

Possible to split up the scenario files Common to split topology generation away from the scenario itself This way if you have two different scenarios which both use that same topology it modular

Ex) One uses TCP, one uses UDP application sources

NS2: Breaking scenario into multiple files

Use the source directive For example, if you want to include the topology.tcl file into your simulation.tcl file:

simulation.tcl

source topology.tcl set ns[new Simulator]

NS2: Define Topology

Simple topologies are trivial:


set n0 [$ns node] set n1 [$ns node] ... $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail

NS2 Define Topologies

Larger Topologies:

Use a loop:

for {set i 0} {$i < 7} {incr i} {


set n($i) [$ns node]

} for {set i 0} {$i < 7} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail }

NS2 Defined Topologies

You could do a large ring of 25 nodes or more for your assignment, but likely not very interesting It is up to you to figure out how to connect the more complicated topologies It may however be interesting to compare a ring against a grid topology if you wish

NS2 Define Wireless Topology


for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 $node_($i) set X_ 0.0 $node_($i) set Y_ 0.0 $node_($i) set Z_ 0.0 } ;# disable random motion

$node_(0) set X_ 0.0 $node_(1) set X_ 200.0 $node_(2) set X_ 400.0 $node_(3) set X_ 600.0 $node_(4) set X_ 800.0

NS2 Wireless Topology

Must also defined physical size of the simulation area:

# Create and configure topography (used for mobile scenarios) set topo [new Topography] # 1000x1000m terrain $topo load_flatgrid 1000 1000

NS2 Defining Traffic Models

From Marc Greiss tutorial

NS2 Defining Traffic Models


Node 4 is where the sinks are attached Note: each one corresponds to one source! (even on same node)

Calls function from previous slide

From Marc Greiss tutorial

NS2 Traffic Models

Other types of traffic models supported:

TCP set null0 [new Agent/TCPSink] $ns attach-agent $n1 $null0


Ex) Traffic on Top of TCP
set ftp [new Application/FTP] $ftp attach-agent $tcp0 set telnet [new Application/Telnet] $telnet attach-agent $tcp0

NS2 Traffic Models

NS2 Defining Routing Model

Set using $ns rtproto type Where type can be:

Static, Session, DV, cost, multi-path

By default, uses static routing which is similar to Dijkstra's algorithm Could compare against DV easily

NS2 Routing with Wireless


Somewhat different setup with wireless $ns_ node-config -addressType hierarchical \ -adhocRouting AODV \ -llType LL \ -macType Mac/802_11 \ -ifqType Queue/DropTail/PriQueue \ -ifqLen 50 \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -topologyInstance \$topo \ -channel Channel/WirelessChannel \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF

Routing configured here, choices: AODV,DSR,DSDV, TORA, etc.

Outline

NS2 Overview NS3 Overview

Setup, Defining Topology, Traffic Models, Routing

NS3 Sample Scenario


Basic Setup of the Simulation Breaking the scenario into multiple files Defining Topology Defining Traffic Models Defining Routing Models

NS3: Basic Simulation Setup

Bare minimum includes:

#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 Others depending on if you use wireless, other modules

NS3 Basic Simulation Setup

using namespace ns3; Similar to:

using namespace std;

Saves you having to do ns3::xxx for functions etc. similar to being able to use cout rather than std::cout

NS3 Breaking Simulation Up

Can be managed in the same way any C/C++ source is using #include Should be modular like any C/C++ code Break into functions, header files where necessary

NS3 Defining the Topology

Nodes exist within containers to help refer to them Used to apply actions later to entire groups of nodes

For example, assigning IP addresses to all nodes in a container

NodeContainer nodes; nodes.Create (2);

NS3 Defining the Topology

CSMA & P2P Links

CSMA is like a shared wire, uses collision avoidance no need for routing operating on this P2P connections should be used to connect where routing should be used For a straightforward grid, see ns3source/examples/animation/grid-animation.cc

NS3 Defining the Topology


CSMA

P2P Grid

P2P Hierarchical

NS3 Grid Topology (Wired)

GridHelper:

PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
// Create Grid PointToPointGridHelper grid (5, 5, pointToPoint);

NS3 Grid Topology

NS3 Wireless Grid Topology

Uses a mobility model to set physical co-ordinate positions:

/* Set up mobility model */ mobility.SetPositionAllocator ( "ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (SEPARATIONDISTANCE), "DeltaY", DoubleValue (SEPARATIONDISTANCE), "GridWidth", UintegerValue (XNODES), "LayoutType", StringValue ("RowFirst") ); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install(nodes);

NS3: Installing the Internet Stack

Interface: maps between node and device Install IP addresses & stack on all nodes:

InternetStackHelper internetStack; Ipv4InterfaceContainer interfaces; internetStack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); interfaces = address.Assign (meshRouterDevices);

NS3 Defining Traffic Models

Several types of traffic:

UDPClient / UDPServer
On/Off Client/Server Bulksend

Ping
UDP Echo Client/Server

NS3 Traffic Models

http://www.nsnam.org/tutorials/ns-3-tutorial-tunis-apr09.pdf

NS3 Traffic Models

Sink equivalent in ns2:

UdpServerHelper server(PORT); ApplicationContainer serverapp = server.Install (nodes.Get (0)); serverapp.Start (Seconds (1)); Note: you may find it serverapp.Stop (Seconds (TOTALTIME));

good to start the application after time 0, particularly with wireless simluations

NS3 Traffic Models

Source equivalent in ns2:

UdpClientHelper client (interfaces.GetAddress (0), PORT); client.SetAttribute ("MaxPackets", UintegerValue (MAXPACKETS)); client.SetAttribute ("PacketSize", UintegerValue (PACKETSIZE)); client.SetAttribute ("Interval", TimeValue (Seconds (PACKETINTERVAL))); ApplicationContainer clientapp = client.Install (nodes.Get (1)); clientapp.Start (Seconds (2)); clientapp.Stop (Seconds (TOTALTIME)); Good to start the client,
after the server is already listening

NS3 Traffic Models

Why we need to specify the node & interface on that node (each node may have multiple interfaces)

NS3 Traffic Models

In ns3, you can use a single sink for multiple sources, in ns2 this is not the case, you must have a corresponding sink for each source

NS3 Defining Routing Models


See ns3 source/examples/routing for more details For some types of routing it is as simple as setting the routing model when initializing the InternetStack:

InternetStackHelper internetStack; stack.SetRoutingHelper (aodv); Ipv4InterfaceContainer interfaces; internetStack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); interfaces = address.Assign (meshRouterDevices);

Next Classes

Finish up on Simulation Topics

Generating Data Files Parsing Data files Extracting Results Generating Graphs with GNUPlot, Xgraph Automating Multiple Experiments

Ethics & Networking Next Generation Networks

Delay tolerant networks Wireless mesh networks Wireless sensor networks 3G, 4G, LTE, Mobile Networks Heterogeneous networks Green Communication

References

http://www.evanjones.ca/ns2/

Ns2 / Ns3 documentation

Anda mungkin juga menyukai