Introduction to NS-3 Part - 2
description
Transcript of Introduction to NS-3 Part - 2
![Page 1: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/1.jpg)
Introduction to NS-3Part - 2
Katsaros Konstantinos PhD Student
PGSDP Workshop on NS-32 April 2012
![Page 2: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/2.jpg)
OverviewFlowMonitorSmart PointersPacket TagsDebuggingVisualizationCreating a new ModuleAdvanced Simulation with NS-3
NSC (Network Simulator Cradle)MPI (Message Passing Interface)EMU (Emulation)
K o n s t a n t i n o s K a t s a r o s 2
![Page 3: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/3.jpg)
Flow Monitor• A common problem was identified
– “how to easily extract flow metrics from arbitrary simulations?”• Existing solutions do not solve this problem effectively
• The Flow Monitor solves the problem– Requires significant less programming time than NS-3 callback based tracing– A lot more efficient than ascii tracing
• More data output methods (e.g. database and binary file)
• More options to control level of detail stored in memory
• Monitor multicast/broadcast flows
K o n s t a n t i n o s K a t s a r o s 3
![Page 4: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/4.jpg)
Flow Monitor Measurements• timeFirstTxPacket, timeLastTxPacket begin and end times of the flow from the
point of view of the receiver• timeFirstRxPacket, timeLastRxPacket begin and end times of the flow from the
point of view of the receiver• delaySum, jitterSum sum of delay and jitter values• txBytes, txPackets number of transmitted bytes and packets• rxBytes, rxPackets number of received bytes and packets• lostPackets number of definitely lost packets• timesForwarded the number of times a packet has been reportedly forwarded,
summed for all packets in the flow• delayHistogram, jitterHistogram, packetSizeHistogram Histogram versions
for the delay, jitter, and packet sizes, respectively• packetsDropped, bytesDropped discriminates the losses by a reason code
– DROP NO ROUTE no IPv4 route found for a packet – DROP TTL EXPIRE a packet was dropped due to an IPv4 TTL field decremented and reaching
zero– DROP BAD CHECKSUM a packet had a bad IPv4 header checksum and had to be dropped
K o n s t a n t i n o s K a t s a r o s 4
![Page 5: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/5.jpg)
Flow Monitor ExampleCreate a FlowMonitorHelper objectFlowMonirtorHelper flowmon;
Create a pointer to FlowMonirot class and install probes to all nodesPtr<FlowMonitor> monitor = flowmon.InstallAll();
Configure histogram parametersMonitor->SetAttribute (”DelayBinWidth”, DoubleValue(0.001));Monitor->SetAttribute (”JitterBinWidth”,DoubleValue (0.001));
Run simulationSimulator::Run ();
Write results into an XML filemonitor->SerializeToXmlFile (”results.xml”,True,True);
K o n s t a n t i n o s K a t s a r o s 5
![Page 6: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/6.jpg)
Smart Pointer• NS3 uses reference-counting smart pointers
at its APIs to limit memory leaks– Or “pass by value” or “pass by reference to const”
where appropriate• A “smart pointer” behaves like a normal
pointer (syntax) but does not lose memory when reference count goes to zero
• Use them like built-in pointers: Ptr<MyClass> p = CreateObject<MyClass> ();
p->method ();
K o n s t a n t i n o s K a t s a r o s 6
![Page 7: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/7.jpg)
Packet Tags• Small chunks of information• Any number of tags can be attached a packet• Tags are keyed by the a structure type itselfE.g.:Ptr<Packet> p;MyTag tag;p->AddTag (tag);p->PeekTag (tag);
• New tag types are defined similarly to header types• Tags can be used to:
– Attach context information to a packet– Example: NetDevice attaches destination MAC address when
queueing, retrieves it when dequeuing for transmission– Convey additional information across layers
K o n s t a n t i n o s K a t s a r o s 7
![Page 8: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/8.jpg)
Debugging (1)• Assertions: NS_ASSERT (expression);
– Aborts the program if expression evaluates to false– Includes source file name and line number
• Unconditional Breakpoints: NS_BREAKPOINT ();– Forces an unconditional breakpoint, compiled in
• Debug Logging (not to be confused with tracing!)– Purpose
• Used to trace code execution logic• For debugging, not to extract results!
– Properties• NS_LOG* macros work with C++ IO streams• E.g.: NS_LOG_UNCOND (”I have received ” << p->GetSize () << ” bytes”);• NS_LOG macros evaluate to nothing in optimized builds• When debugging is done, logging does not get in the way of execution
performance
K o n s t a n t i n o s K a t s a r o s 8
![Page 9: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/9.jpg)
Debugging (2)• Logging levels:
– NS_LOG_ERROR (...): serious error messages only– NS_LOG_WARN (...): warning messages– NS_LOG_DEBUG (...): rare ad-hoc debug messages– NS_LOG_INFO (...): informational messages (eg. banners)– NS_LOG_FUNCTION (...):function tracing– NS_LOG_PARAM (...): parameters to functions– NS_LOG_LOGIC (...): control flow tracing within functions
• Logging ”components”– Logging messages organized by components– Usually one component is one .cc source file– NS_LOG_COMPONENT_DEFINE ("OlsrAgent");
• Displaying log messages. Two ways:– Programatically:
• LogComponentEnable("OlsrAgent", LOG_LEVEL_ALL);– From the environment:
• NS_LOG="OlsrAgent" ./my-program
K o n s t a n t i n o s K a t s a r o s 9
![Page 10: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/10.jpg)
Visualization• Not integrated (directly) with ns-3• Ns-3 creates “animation” file, visualizers
use this as input and create the animation.– netanim, pyviz, and nam for ns-3
K o n s t a n t i n o s K a t s a r o s 10
![Page 11: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/11.jpg)
NetAnim 3.0 Features• Animate wired-links and wireless-
links based simulations. • LTE-packets cannot be animated,
but topology will be shown • Complete redesign using the
QGraphics framework • Packet statistics with filter • Node position statistics with node
trajectory (path of a mobile node) plotting
• Improved window re-sizing and zooming
K o n s t a n t i n o s K a t s a r o s 11
http://www.nsnam.org/wiki/index.php/NetAnim
![Page 12: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/12.jpg)
Adding New Module• In order to create a new module in the NS3, just run the create-
module.py script that will create the basic structure of the module (examples, helper, test, model and the appropriate wscript ).
• As of ns-3.13 there is no need to add the module in ns3 wscript, it is done automatically.
Usage:./create-module.py [options] modulename
Then clean the project, configure and re-build it%./waf distclean%./waf configure%./waf
K o n s t a n t i n o s K a t s a r o s 12
![Page 13: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/13.jpg)
NSC• The Network Simulation Cradle (NSC) is a
framework which allows real world TCP/IP network stacks to be used inside a network simulator
K o n s t a n t i n o s K a t s a r o s 13
http://www.nsnam.org/wiki/index.php/Network_Simulation_Cradle_Integration
![Page 14: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/14.jpg)
Distributed Simulation with MPI
MPI: Message Passing Interface Library (and protocol) for distributed applications
MPI simulator (as of ns-3.8) Nodes in the simulation assigned different System Ids Nodes with different System Ids run on different cluster
machines Nodes on different machines may communication using p2p
links only
K o n s t a n t i n o s K a t s a r o s 14
Node 1SystemId 1
Node 2SystemId 1
Node 3SystemId 2
Node 5SystemId 2
Node 4SystemId 2
Point-to-pointLink
(simulationand real world)
Node 0SystemId 1
![Page 15: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/15.jpg)
Emulation• Support moving between simulation and
testbeds or live systems• A real-time scheduler, and support for two
modes of emulation– GlobalValue::Bind (“SimulatorImplementationType”,
StringValue (“ns3::RealTimeSimulatorImpl”));
K o n s t a n t i n o s K a t s a r o s 15
![Page 16: Introduction to NS-3 Part - 2](https://reader036.fdocuments.in/reader036/viewer/2022081419/56816457550346895dd625f2/html5/thumbnails/16.jpg)
AcknowledgementsSpecial thanks to:
Mathieu LacageTom HendersonGustavo CarneiroFor borrowing parts of their slides
K o n s t a n t i n o s K a t s a r o s 16