ns-3-workshop

advertisement
Introduction to NS-3
Part - 2
Katsaros Konstantinos
PhD Student
PGSDP Workshop on NS-3
2 April 2012
Overview
 FlowMonitor
 Smart Pointers
 Packet Tags
 Debugging
 Visualization
 Creating a new Module
 Advanced Simulation with NS-3
NSC (Network Simulator Cradle)
MPI (Message Passing Interface)
EMU (Emulation)
Konstantinos Katsaros
2
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
Konstantinos Katsaros
3
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
Konstantinos Katsaros
4
Flow Monitor Example
Create a FlowMonitorHelper object
FlowMonirtorHelper flowmon;
Create a pointer to FlowMonirot class and install probes to all nodes
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Configure histogram parameters
Monitor->SetAttribute (”DelayBinWidth”, DoubleValue(0.001));
Monitor->SetAttribute (”JitterBinWidth”,DoubleValue (0.001));
Run simulation
Simulator::Run ();
Write results into an XML file
monitor->SerializeToXmlFile (”results.xml”,True,True);
Konstantinos Katsaros
5
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 ();
Konstantinos Katsaros
6
Packet Tags
• Small chunks of information
• Any number of tags can be attached a packet
• Tags are keyed by the a structure type itself
E.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
Konstantinos Katsaros
7
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
Konstantinos Katsaros
8
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
Konstantinos Katsaros
9
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
Konstantinos Katsaros
10
NetAnim 3.0 Features
• Animate wired-links and wirelesslinks 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
http://www.nsnam.org/wiki/index.php/NetAnim
Konstantinos Katsaros
11
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
Konstantinos Katsaros
12
NSC
• The Network Simulation Cradle (NSC) is a
framework which allows real world TCP/IP
network stacks to be used inside a
network simulator
http://www.nsnam.org/wiki/index.php/Network_Simulation_Cradle_Integration
Konstantinos Katsaros
13
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
Node 0
SystemId 1
Node 1
SystemId 1
Node 2
SystemId 1
Node 3
SystemId 2
Point-to-point
Link
(simulation
and real world)
Konstantinos Katsaros
Node 4
SystemId 2
14
Node 5
SystemId 2
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”));
Konstantinos Katsaros
15
Acknowledgements
Special thanks to:
Mathieu Lacage
Tom Henderson
Gustavo Carneiro
For borrowing parts of their slides
Konstantinos Katsaros
16
Download