190 likes | 496 Views
network simulator 3. Reporter: Chechieh Lin. Outline. Introduction NS3 vs. NS2 NS-3 Modules Key Abstractions A First ns-3 Script. Introduction. NS-3 is a new simulator, written from scratch Programming languages: C++, Python Manage: Mercurial Compile: Waf
E N D
network simulator 3 Reporter: Chechieh Lin
Outline • Introduction • NS3 vs. NS2 • NS-3 Modules • Key Abstractions • A First ns-3 Script
Introduction • NS-3 is a new simulator, written from scratch • Programming languages: C++, Python • Manage: Mercurial • Compile: Waf • Project started around mid 2006
waf key concepts • For those familiar with autotools: • configure -> ./waf -d [optimized|debug] configure • make -> ./waf • make test -> ./waf check (run unit tests) • Can run programs through a special wafshell • ./waf --run simple-point-to-point ns-3 tutorial March 2008
Random Variables • Currently implemented distributions • Uniform: values uniformly distributed in an interval • Constant: value is always the same (not really random) • Exponential: exponential distribution (poisson process) • ... • Example • import pylab • import ns3 • rng = ns3.NormalVariable(10.0, 5.0) • x = [rng.GetValue() for t in range(100000)] • pylab.hist(x, 100) • pylab.show()
Smart Pointers • Reduce bugs caused by the misuse of pointers while retaining efficiency • Memory Leak
Callback • Allow one piece of code to call a function without any specific inter-module dependency • Example • int (*pfi)(intarg) = 0 • intMyFunction (intarg) {} • pfi = MyFunction • int result = (*pfi) (1234) • int result = pfi (1234)
Tracing • ns-3 provides a simple mechanism for logging and providing some control over output via Log Components • only get the information which from core system required without having to change and recompile the core system.
Packet • Packet objects used vertically in NS-3 to represent: • Units of information sent and received by applications • Information chunks of what will become a real packet • Basic Usage • Create empty packet • Ptr<Packet> packet = Create<Packet> (); • Create packet with 10 ”dummy” bytes • Ptr<Packet> packet = Create<Packet> (10); • Create packet with user data • Ptr<Packet> packet = Create<Packet> (”hello”, 5); • Copy a packet • Ptr<Packet> packet2 = packet1->Copy ()
Simulator • Time is not manipulated directly: the Time class • Time class supports high precision 128 bit time values(nanosecond precision) • Example • Time t1 = Seconds (10); Time t2 = t1 + MilliSeconds (100); std::cout << t2.GetSeconds () << std::endl; // t2 = 10.1 • Time now = Simulator::Now (); • void MyCallback (T1 param1, T2 param2) {...}[...] Simulator::Schedule (Seconds (3), MyCallback, param1, param2);
Key Abstractions • Node • basic computing device abstraction • Application • acquires and uses the resources controlled • run on ns-3 Nodes to drive simulations • Channel • provides methods for managing communication subnetwork objects and connecting nodes • Net Device • provides methods for managing connections to Node and Channel objects • Topology Helpers • combine many distinct operations into an easy to use model for your convenience
The basic model Application Application Application Application Sockets-like API Protocol stack Protocol stack Packet(s) Node Node NetDevice NetDevice NetDevice Channel NetDevice Channel