1 / 69

Network Simulator 2 - Introduction for Beginners - 2008. 03. 18 CNLAB

ns - 2 seminar. Network Simulator 2 - Introduction for Beginners - 2008. 03. 18 CNLAB. Scope.  Basic Requirements for Using ns-2 1) C++ 2) Tcl & OTcl 3) Object Orientation concepts 4) ns-2 Mechanisms ( ns-2 Core & Utilities)

janina
Download Presentation

Network Simulator 2 - Introduction for Beginners - 2008. 03. 18 CNLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ns-2 seminar Network Simulator 2 - Introduction for Beginners - 2008. 03. 18 CNLAB

  2. Scope  Basic Requirements for Using ns-2 1) C++ 2) Tcl & OTcl 3) Object Orientation concepts 4) ns-2 Mechanisms (ns-2 Core & Utilities) 5) Application-specific Implementation Architectures . Wired ~ to Wireless world . Lower Layer ~ to Higher Layer . Variety of architectural specifics

  3. Scope  Introduction  Some Basic Concepts - Architectural Views - Plumbing & Duality - Tcl basics  OTcl Linkage Architecture  Object Orientation in OTcl  Elemental Procedures in ns-2 programming - Network creation - Agents & others

  4. Introduction  Ns has began as a variant of the REAL network simulator in 1989, and has evolved substantially in the past few years.  In 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. - VINT : Virtual InterNet Testbed http://www.isi.edu/nsnam/ns/  The latest version :ns-2.32 [2007] : hundreds * 1000 LOC

  5. Introduction  Related Research area - functionality & application - Network Layer . Routing : unicast, multicast, MPLS . QoS : IntServ / DiffServ . Queuing Disciplines - Transport . TCP . Reliable multicast . Congestion control - Application . Web Caching . Multimedia . Traffic Sources - Wireless world . Mobile IP . Ad hoc routing . Sensor MAC

  6. Introduction  NS-2 Directory ns-allinone Tcl8.x TK8.x OTcl tclcl ns-2 nam-1 . . . tcl C++ code ... ex test mcast lib examples validation tests OTcl code

  7. Introduction  What is NS-2 ? - Discrete Event Simulator -Packet-level - Link layer and up - Wired and Wireless worlds  Languages - Tcl (Tool Command Language) - OTcl (MIT Object-oriented Tcl) - C++ - Some others

  8. Introduction  Tcl Interpreter with Extents - OTcl : Object-oriented support, extending Tcl/Tk - TclCL : C++ and OTcl Linkage (interface) - Discrete Event Scheduler (ordered list of events) - Data Network (the Internet) Components Event Scheduler ns-2 tclcl Network Component Users Otcl tcl8.x

  9. Basic Concepts – Architectural View  Object-oriented (C++, OTcl) • - Reusability • - Maintenance  Scalability + Extensibility - Control / “Data” separation . OTcl for control (scenarios) . C++ for “data” - Split OTcl / C++ objects  Duality Needs Linkage  Modular approach - Fine-grained Object composition

  10. Basic Concepts – Architectural View  Simplified User’s View of NS - NS-2 is basically the Tcl & OTcl Interpreter with network simulation object libraries.

  11. Basic Concepts – Architectural View  Layered View of the NS [an example] - OTcl : Application, Scenario, or Upper Layer - C++ : Lower Layer or Protocol/Packet Layer

  12. Basic Concepts – Architectural View  Components domain Relationship View of the NS - NS-2 is written in C++ with OTcl Interpreter as the Front-End. - Simulator objects are implemented in the Compiled hierarchy (C++ domain), but instantiated through the Interpreter.

  13. Basic Concepts - Architecture  Nodes

  14. n0 n1 Port Classifier Multicast Node dmux_ Addr Classifier classifier_ Node entry Node entry dmux_ entry_ entry_ Multicast Classifier classifier_ multiclassifier_ Basic Concepts - Architecture  Nodes Unicast Node Classifier : Address, Multicast, Multipath

  15. n0 n1 duplex link n1 entry_ head_ enqT_ queue_ deqT_ link_ ttl_ drophead_ drpT_ tracing simplex link Basic Concepts - Architecture  Links

  16. n0 n1 Port Classifier Addr Classifier n1 entry_ 0 Node entry head_ dmux_ enqT_ queue_ deqT_ link_ ttl_ 1 entry_ classifier_ drophead_ drpT_ Basic Concepts - Architecture  Nodes & Links

  17. n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 1 dmux_ dmux_ 1 0 entry_ entry_ classifier_ classifier_ Link n1-n0 Basic Concepts - Architecture  Routing Link n0-n1

  18. dst_=0.0 dst_=1.0 Agent/TCP Agent/TCPSink agents_ agents_ 0 1 1 0 Basic Concepts - Architecture  Transport n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 0 dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

  19. Application/FTP dst_=0.0 dst_=1.0 0 1 1 0 Basic Concepts - Architecture  Application : Traffic Generator n0 n1 Port Classifier Port Classifier Agent/TCPSink Addr Classifier Addr Classifier Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

  20. Basic Concepts - Architecture  Object Hierarchy TclObject NsObject other objects Classifier Connector Queue Delay Agent Trace AddrClassifier McastClasifier DropTail RED TCP Enq Deq Drop ... Reno SACK

  21. Basic Concepts - Architecture  Some differences between NS-2 & Real network - Node : no queue, above network layer, no lower layer on the basic Node (not in mobile node) - Link : Compound object with Queues - No physical media, but simulated environment - No real data or payload transmissions, except in special applications (web), which uses special transport. - Normally, the ultimate Packet Transmissions are done by calling the next object’s method (recv( )).

  22. Basic Concepts - Plumbing  Network Topology Setupusing - Network Objects : Nodes & Links *cf) NsObject - Plumbing Library functions  Plumbing : for Network Setup • - Plumbing Data Paths among the Network Objects • by setting the “Neighbor” pointers of an Object to • the Address of an appropriate object. • - Plumbing modules are implemented as member • functions of the base Simulator object. • - neighbor_,target_ variables are key to plumbing • transmission : target_recv( )

  23. Basic Concepts - Duality TclCL linkage Pure C++ objects Pure OTcl objects C++ / OTcl split objects C++ OTcl ns OTcl & C++ Share Class Hierarchy

  24. Basic Concepts - Duality  C++ / OTcl Separation - C++ for “Data” . Per Packet action : Packet Headers accessed - OTcl for Control . Periodic or Triggered action (~ Scenario scheduling) . Network(Topology) Creation : Application procedure - Tradeoff between Composability and Speed (+) - Learning/debugging are more difficult (-)  Separation on Dual planes need Linkage to compose

  25. Basic Concepts - Duality  OTcl : Interpreted hierarchy - Create Network - Create Connection (wired) - Create Traffic  C++ : Compiled hierarchy - Packet processing methods - OTcl command Interpreter . object::command( ) method : one of the linkage

  26. Basic Concepts - Duality  Otcl domain set tcp [new Agent/TCP] $tcpadvance 10  C++ domain int TcpAgent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcmp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]); …… return(TCL_OK); } } return (Agent::command(argc, argv); }

  27. Basic Concepts – Tcl/OTcl  Tcl / OTcl Basics - proc command : define a global procedure . proc create_topology { - set command : assign a value to a variable . set count 10 . $self set count 10 - Substitutions . Command substitution : brackets as command - set cnt [ $self set count ] cnt = 10 - set cnt [ expr $cnt + $cnt ] set cnt to 20 . Variable substitution : ex) $count  10 $ns at [ $ns now ] “$selfsend $class $rate"

  28. C++ / OTcl Linkage - snapshot view  Export C++ class to Otcl [Create C++ object from OTcl] •Creating a new network object class in C++, & also an instance of this object in Otcl, needs a Linkage object derived from the TclClass (C++ domain).  Export C++ class variables to OTcl •Thenew network object class in C++ may have some parameter variables, also to be configured from Otcl. Export C++ Object Control Commands to OTcl •Giving the control of new C++ object to Otcl, via the Otcl command interpreter: command() function.  Execute an OTcl command from C++ •Execute an OTcl command from the new C++ object.

  29. C++ / OTcl Linkage

  30. C++ / OTcl Linkage - TclObject  TclObject : base class - Basic hierarchy in ns-2 for split objects - Mirrored in both C++ & OTcl - NsObject : the superclass of all network component objects that handle packets   Connector, Classifier subclasses - Connector : having only one output data path - Classifier : having multiple output data path (Router) - Node : Compoundobject ~ Node Entry, Classifier objects - Link : ’’ ~ Queue, Delay, TTL objects..

  31. C++ / OTcl Linkage - TclObject  TclObject : Hierarchy and Shadowing C++ class hierarchy OTcl class hierarchy TclObject TclObject Agent static TcpClass : public TclClass { public: TcpClass():TclClass(“Agent/Tcp"){} TclObject* create(int,const char*const*) { return (new TcpAgent());} }; Agent TcpAgent Agent/TCP _o123 *tcp Agent/TCP OTcl shadow object Agent/TCP C++ object

  32. C++/OTcl Linkage - TclObject  TclObject Creation & Deletion - Global Procedures : new{ }, delete{ } - Example : set tcp [ new Agent/TCP ] … delete $tcp

  33. Agent/TCP constructor parent constructor TclObject constructor invoke parent constructor create C++ object which C++ obj to create? – TclClass complete initialization complete initialization create OTcl shadow object parent (Agent) constructor AgentTCP constructor TclObject (C++) constructor invoke parent constructor invoke parent constructor do nothing, return bind variables and return bind variables and return C++ / OTcl Linkage – TclObject set tcp [newAgent/TCP] invoke parent constructor OTcl C++

  34. C++/OTcl Linkage - TclObject::bind()  Linking C++ member variable to OTcl object variable • Bound variables can be configured from Both C++/OTcl.  C++ domain TcpAgent::TcpAgent( ) { // Constructor bind(“window_”, &wnd); … … } // other type : bind_time(), bind_bool(), bind_bw()  OTcl domain set tcp [new Agent/TCP] $tcp set window_ 200

  35. C++ / OTcl Linkage - TclObject::command()  Export C++ Object Control Commands to OTcl int MyAgent::command(int argc, const char*const* argv ) { if (argc == 2) { if (strcmp(argv[1], “call-my-func”) == 0) { MyPrivFunc( )); return (TCL_OK); } } return (Agent::command(argc, argv)); } - Effect : Implement OTcl methods in C++ - Trap point : OTcl method cmd{ }

  36. C++ / OTcl Linkage - TclObject::command() OTcl space no such procedure $tcp send TclObject::unknown{} $tcp cmd send C++ space TcpAgent::command() match “send”? Yes No Invoke parent: return Agent::command() process and return

  37. mirroring OTcl C++ TclObject TclObject NsObject ?? Agent Agent TcpAgent Agent/TCP C++ / OTcl Linkage – TclClass • Static class TcpClass : public TclClass { • public: • TcpClass() : TclClass(“Agent/TCP”) { } • TclObject* create(int, const char*const*) { • return (new TcpAgent( ) ); • } • } class_tcp;

  38. C++ / OTcl Linkage – TclClass  Class TclClass ( inC++ ) - This compiled class is pure virtual class : only 2 functions •Construct the interpreted class hierarchy to mirror the compiled class hierarchy. •Method toCreate instances of the associated TclObject. - For the static variableclass_tcp, ns-2 will execute the constructor of TcpClass. The constructor specifies the interpreted class explicitly as “Agent/TCP”. - This sets up the related methods and the interpreted class hierarchy in the Otcl space. Next slide - This class isassociated with the class TcpAgent, and when the user issues “new …”, TcpClass::create( ) is invoked.  TcpAgent is created.

  39. C++ / OTcl Linkage – TclClass  Interpreted Class Hierarchy construction (more) - When the object constructor is executed, the TclClass constructor stores the name of the class, and inserts this object into Linked List of TclClass objects. - During initialization, TclClass::bind() is invoked. - For each object in the List, bind() invokes register{… } with the class name as its argument. - register{ } establishes the class hierarchy, creating the class required. class TcpAgent : public Agent { public: TcpAgent( ); // Constructor protected: int command(int argc, const char* const* argv); int xxx_; };

  40. C++ / OTcl Linkage – Tcl  Singleton class with a handle to Tcl interpreter  Usage - Invoke OTcl procedure from C++ : 4 methods - Obtain OTcl evaluation results : tcl.result( ) - Pass a result string to OTcl : tcl.result(*s), tcl.resultf(*s)

  41. C++ / OTcl Linkage – Tcl  Execute an OTcl command from C++ Tcl& tcl = Tcl::instance(); tcl.eval (“puts \ “Message from MyPrivFunc\””); or char wrk[128]; sprintf(wrk, “$s recv %d”, name(), result); tcl.eval (wrk); tcl.evalc (“puts \ “Message from MyPrivFunc\””); tcl.evalf (“puts \ “ my_var1 = %d\””, my_var1); tcl.evalf (“puts \ “ my_var2 = %d\””, my_var2);

  42. C++ / OTcl Linkage - summary  TclObject - Unifies Interpreted (OTcl) and Compiled (C++) class hierarchies - Seamless access (Method call and Variable access) between OTcl and C++  TclClass - The mechanism that makes TclObject work - Interpreted hierarchy & shadowing methods  Tcl - Primitives ( in C++ ) to access Tcl interpreter

  43. Object Orientation in OTcl  Some Differences between C++ & OTcl - OTcl Class vs. C++ Class architecture . OTcl attaches methods to Object or Class (evolving) . C++ has single Class Declaration - C++/OTcl Split Objects . Implement methods in either language . Define instance variables in either C++ or Otcl  Through in different Syntax & Forms

  44. Object Orientation in OTcl  Class structures comparison Class Link Link instproc init { src dst } { $self next $self instvar fromNode_ toNode_ … set fromNode_ $src set toNode_ $dst ………… } Link instproc head { } { $self instvar head_ return $head_ } class PingAgent : public Agent { public: PingAgent( ); int command(int argc, const char* const* argv); void recv (Packet*, Handler*); protected: int off_ping_; };

  45. Object Orientation in OTcl  Some Differences between C++ / OTcl - instvar : to define/access member variable - instproc : to define member function (procedure) - OTcl init{ } vs. C++ Constructor( ) - $self this - Syntax checking in Tcl/OTcl . No new line from “{”+ body, but only after “{” . if {, } elseif {, …

  46. OTcl Basics Class Mom Mom instproc greet {} { $selfinstvar age_ puts “$age_ years old mom: How are you doing?” } Class Kid -superclass Mom Kid instproc greet {} { $selfinstvar age_ puts “$age_ years old kid: What’s up, dude?” } set mom [new Mom] $mom set age_ 45 set kid [new Kid] $kid set age_ 15 $mom greet $kid greet 45 years old mom: How are you doing? 15 years old kid: What's up, dude?

  47. Elemental Tcl Procedures in ns-2 programming - Creating the Event Scheduler - [Turn on tracing] - Creating network - Setup routing - Insert errors - Creating connection(Agents) - Creating traffic - Configuring Algorithmic Scenario specific to this App …. - Start ns simulation

  48. Example Procedures # Application code Tcl/OTcl Script. set end 200.0 set warmup 20.0 # For Stable data timing set linkrate 5Mb # May be Adjusted. set ns [new Simulator] # ns Created : First line of App create_topology # Creating topology... create_agents # Creating agents... create_sources # Creating traffic sources... create_conditioners # Creating conditioners... configure_scheduler # Configuring Queue Scheduler... $ns at $end "end" $ns run # Starting simulation...

  49. Creating Event Scheduler  Create event scheduler set ns [new Simulator]  Scheduling Events $ns at <time> “<event>” <event> : any legitimate ns/tcl commands  Start scheduler $ns run

  50. Register Event Deque Object B Object A Dispatch Dispatch Event Scheduling Event Queue Target object Event (Packet) Time Scheduler

More Related