SlideShare a Scribd company logo
1 of 30
OVERVIEW OF NS-2

 Discrete Event Simulator
 Packet level

 Modeling Network protocols
   Collection   of Various protocols at multiple layers
     TCP(reno, tahoe, vegas, sack)
     MAC(802.11, 802.3, TDMA)

     Ad-hoc Routing (DSDV, DSR, AODV, TORA)

     Sensor Network (diffusion, gaf)

     Multicast protocols, Satellite protocols, and many others

                                                                  1
NS-2 : COMPONENTS
 NS– Simulator
 NAM – Network AniMator
      visual demonstration of NS output
 Preprocessing
   Handwritten TCL  or
   Topology generator
 Post   analysis
   Trace   analysis using Perl/TCL/AWK/MATLAB



                                                 2
USER’S PERSPECTIVE
 From the user’s perspective, NS−2 is an OTcl
 interpreter that takes an OTcl script as input and
 produces a trace file as output.




                                                      3
DISCRETE EVENT SIMULATOR

   ns-2 is an discrete event driven simulation
     Physical activities are translated to events
     Events are queued and processed in the order of their
      scheduled occurrences
     Time progresses as the events are processed



                   Time: 1.5 sec         Time: 1.7 sec

               1                                         2

               Time: 2.0 sec                Time: 1.8 sec


                                                              4
Discrete Event Scheduler

                         time_, uid_, next_, handler_
  head_ ->
  head_ ->
                         handler_ -> handle()

                insert   time_, uid_, next_, handler_
     Event Scheduler



                                                        5
EVENT SCHEDULER
 Non-Real      time schedulers
   Implementations   : List , Heap , Calender
     Calender is default
 Real   time schedulers
   Used     for emulation for direct interaction with real
      NT.
 Basic     use of an event scheduler:
   schedule   simulation events, such as when to start an
      FTP application, when to finish a simulation, or for
      simulation scenario generation prior to a simulation
      run.

                                                              6
NS-2 ENVIRONMENT
  Simulation            1                        2
   Scenario



                     set ns_ [new Simulator]
  Tcl Script         set node_(0) [$ns_ node]
                     set node_(1) [$ns_ node]

                 class MobileNode : public Node
                 {
     C++                 friend class PositionHandler;
                 public:
Implementation            MobileNode();
                                •
                                •
                 }                                  7
TCL INTERPRETER WITH EXTENTS
                Event            ns-2
                Scheduler
                         tclcl




                                 Component
                                 Network
                  otcl
                tcl8.0
 otcl: Object-oriented support

 tclcl: C++ and otcl linkage

 Discrete event scheduler

 Data network (the Internet) components     8
NS-2 Directory Structure

                   sim

tcl8.0    tk8.0    otcl        Tcl         ns-2              nam-1

                        tcl code                       C++ code
                                     tcl         ...
         example
                   ex         test         lib         ...
                   validation test           tcl code core
                                                                     9
NODE ARCHITECTURE
                                 Node



                                                                                   Agent




                                                               Classifier
                                                       Local
                                                                                   Agent


                                          Classifier
              Node entry point
                                                                                   Agent
                                                           Port
                                                       Classifiers: packet demultiplexers.
                                        Addr



                                                                            Link       Link   Link

                                                                                                     10
Agents are either protocol endpoints or related
  objects that generate/fill-in packet fields.
PacketsPACKET STRUCTURE
        (events)
    packet
                  next_
       Size
    determined    accessdata( )                                  - packet size
        at
    simulation
                  bits( )
                                       Size                      - timestamp
    config time                   determined at   cmn header
                                  compile time                   - type
                                       Size                      - UID
                                  determined at   tcp header
                                  compile time                   - interface label
                                       Size
                                  determined at   ip header
                                  compile time

                                       Size
                                  determined at   trace header
                                  compile time


                                                                            11
Links
                    Links: keeps track of “from” and “to” node objects.
                        blocked




Link
entry   Enq Trace        Queue       Deq Trace    Delay        TTL        Rcv Trace
point


                        Drop head    Drp Trace




                                                                                  12
N1                                                                   N2

Node                                                                   Node




                                                                                                      Classifier
                              Classifier


                      Local                                                                   Local
                                               Agent                                                                   Agent




                                                                                 Classifier
         Classifier




                                                Application                                                             Application
                          Port                                                                    Port
       Addr                                                                    Addr

                                                    Link

                                                    Link
                Enq Trace                   Queue          Deq Trace   Delay                  TTL                  Rcv Trace

                                           Drop head       Drp Trace




                                                                                                                                      13
NS-2 : C++ / OTCL
   NS-2 Code contains two sets of languages, namely C++
    and OTcl.

 C++ is used for the creation of objects
  because of speed and efficiency.
 OTcl is used as a front-end to setup the
  simulator, configure objects and
  schedule events because of its ease of
  use.

                                                           14
Why two languages? (Tcl & C++)
   C++: Detailed protocol simulations require
    systems programming language
     byte manipulation, packet processing, algorithm
      implementation
     Run time speed is important
     Turn around time (run simulation, find bug, fix
      bug, recompile, re-run) is slower
   Tcl: Simulation of slightly varying parameters
    or configurations
     quickly  exploring a number of scenarios
     iteration time (change the model and re-run) is
      more important                                    15
Tcl or C++?
   Tcl
     Simple    Configuration, Setup, Scenario
     If it’s something that can be done without
      modifying existing Tcl module.
   C++
     Anything   that requires processing each
      packet
     Needs to change behavior of existing
      module
                                                   16
NS-2 Directory Structure

                   sim

tcl8.0    tk8.0    otcl        Tcl         ns-2              nam-1

                        tcl code                       C++ code
                                     tcl         ...
         example
                   ex         test         lib         ...
                   validation test           tcl code core
                                                                     17
Making Changes in C++ Space
    Existing code
      recompile
    Addition
      change   Makefile and recompile




                                         18
Making Changes in otcl Space
   Existing code
     recompile
     source
   Addition
     source
     change    Makefile (NS_TCL_LIB), tcl/ns-
      lib.tcl (source) and recompile
                                                 19
INSTALLATION
   Unix variants
     Download   NS-allinone-2.27 package
     Contains
        TCL/TK 8.4.5
        oTCL 1.8

        Tclcl 1.15

        Ns2

        Nam -1




                                            20
CODE FOR SIMPLE TOPOLOGY
 Creating     a Simulator Object
     set   ns [new Simulator]
   Setting up files for trace & NAM
     set trace_nam [open out.nam w]
     set trace_all [open all.tr w]
   Tracing files using their commands
     $ns namtrace-all $trace_nam
     $ns trace-all $trace_all


                                         21
CODE FOR SIMPLE TOPOLOGY
   Closing trace file and starting NAM
     proc   finish { } {
        global ns trace_nam trace_all
        $ns flush-trace

        close $trace_nam

        close $trace_all

        exec nam out.nam &

        exit 0 }




                                          22
CODE FOR SIMPLE TOPOLOGY
   Creating LINK & NODE topology
     Creating   NODES
        set n1 [$ns node]
        set n2 [$ns node]

        set n3 [$ns node]

        set n4 [$ns node]

        set r1 [$ns node]

        set r2 [$ns node]




                                      23
CODE FOR SIMPLE TOPOLOGY
   Creating LINKS
     $ns duplex-link $N1 $R1 2Mb 5ms DropTail
     set DuplexLink0 [$ns link $N1 $R1]
     $ns duplex-link $N2 $R1 2Mb 5ms DropTail
     set DuplexLink1 [$ns link $N2 $R1]
     $ns duplex-link $R1 $R2 1Mb 10ms DropTail
     set DuplexLink2 [$ns link $R1 $R2]
     $ns duplex-link $R2 $N3 2Mb 5ms DropTail
     set DuplexLink3 [$ns link $R2 $N3]
     $ns duplex-link $R2 $N4 2Mb 5ms DropTail
     set DuplexLink4 [$ns link $R2 $N4]


                                                  24
CODE FOR SIMPLE TOPOLOGY
   Orientation of links
       $ns duplex-link-op $N1 $R1 orient right-down
     $ns duplex-link-op $N2 $R1 orient right-up
     $ns duplex-link-op $R1 $R2 orient right
     $ns duplex-link-op $R2 $N3 orient right-up
     $ns duplex-link-op $R2 $N4 orient right-down




                                                       25
FINAL TOPOLOGY GENERATED




                           26
TRAFFIC TOPOLOGY AIMED AT




                            27
GENERATING TRAFFIC
   Attaching AGENT TCP to NODE 1
     set TCP1 [new Agent/TCP]
     $ns attach-agent $N1 $TCP1
   Attaching AGENT TCP to NODE 2
     set TCP2 [new Agent/TCP]
     $ns attach-agent $N2 $TCP2
   Attaching AGENT TCP to NODE 3
     set TCP3 [new Agent/TCPSink]
     $ns attach-agent $N2 $TCP3
   Attaching AGENT TCP to NODE 4
     set TCP4 [new Agent/TCPSink]
     $ns attach-agent $N2 $TCP4




                                      28
GENERATING TRAFFIC
   Attaching Application (FTP)
     set FTP0 [new Application/FTP]
     set FTP1 [new Application/FTP]
     $FTP0 attach-agent $TCP0
     $FTP1 attach-agent $TCP1




                                       29
30

More Related Content

What's hot

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
Shaikhul Islam Chowdhury
 
Network emulator
Network emulatorNetwork emulator
Network emulator
jeromy fu
 

What's hot (20)

Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Ns2
Ns2Ns2
Ns2
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Session 1 introduction to ns2
Session 1   introduction to ns2Session 1   introduction to ns2
Session 1 introduction to ns2
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Network Simulation
Network SimulationNetwork Simulation
Network Simulation
 
Extending ns
Extending nsExtending ns
Extending ns
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
Ns fundamentals 1
Ns fundamentals 1Ns fundamentals 1
Ns fundamentals 1
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
Network emulator
Network emulatorNetwork emulator
Network emulator
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
2011.jtr.pbasanta.
2011.jtr.pbasanta.2011.jtr.pbasanta.
2011.jtr.pbasanta.
 

Similar to Ns2

study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 
Tcpip (Dharmender Kumar) 09990478253
Tcpip (Dharmender Kumar)   09990478253Tcpip (Dharmender Kumar)   09990478253
Tcpip (Dharmender Kumar) 09990478253
guestda14e85
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
Antonio Garrote Hernández
 

Similar to Ns2 (20)

study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
Memory, IPC and L4Re
Memory, IPC and L4ReMemory, IPC and L4Re
Memory, IPC and L4Re
 
Webinar: General Technical Overview of MongoDB
Webinar: General Technical Overview of MongoDBWebinar: General Technical Overview of MongoDB
Webinar: General Technical Overview of MongoDB
 
LTTng-UST: Efficient System-Wide User-Space Tracing
LTTng-UST: Efficient System-Wide User-Space TracingLTTng-UST: Efficient System-Wide User-Space Tracing
LTTng-UST: Efficient System-Wide User-Space Tracing
 
No Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time JavaNo Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time Java
 
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
Openflow勉強会 「OpenFlowコントローラを取り巻く状況とその実装」
 
Tcpip (Dharmender Kumar) 09990478253
Tcpip (Dharmender Kumar)   09990478253Tcpip (Dharmender Kumar)   09990478253
Tcpip (Dharmender Kumar) 09990478253
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫る
 
CloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫るCloudStackユーザ会〜仮想ルータの謎に迫る
CloudStackユーザ会〜仮想ルータの謎に迫る
 
Nsby examples
Nsby examplesNsby examples
Nsby examples
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
 
Arvindsujeeth scaladays12
Arvindsujeeth scaladays12Arvindsujeeth scaladays12
Arvindsujeeth scaladays12
 
Tremashark
TremasharkTremashark
Tremashark
 
rtnetlink
rtnetlinkrtnetlink
rtnetlink
 
No sql & dq2 tracer service
No sql & dq2 tracer serviceNo sql & dq2 tracer service
No sql & dq2 tracer service
 
OpenStack and OpenFlow Demos
OpenStack and OpenFlow DemosOpenStack and OpenFlow Demos
OpenStack and OpenFlow Demos
 
Multicore
MulticoreMulticore
Multicore
 
Tos tutorial
Tos tutorialTos tutorial
Tos tutorial
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Ns2

  • 1. OVERVIEW OF NS-2  Discrete Event Simulator  Packet level  Modeling Network protocols  Collection of Various protocols at multiple layers  TCP(reno, tahoe, vegas, sack)  MAC(802.11, 802.3, TDMA)  Ad-hoc Routing (DSDV, DSR, AODV, TORA)  Sensor Network (diffusion, gaf)  Multicast protocols, Satellite protocols, and many others 1
  • 2. NS-2 : COMPONENTS  NS– Simulator  NAM – Network AniMator  visual demonstration of NS output  Preprocessing  Handwritten TCL or  Topology generator  Post analysis  Trace analysis using Perl/TCL/AWK/MATLAB 2
  • 3. USER’S PERSPECTIVE  From the user’s perspective, NS−2 is an OTcl interpreter that takes an OTcl script as input and produces a trace file as output. 3
  • 4. DISCRETE EVENT SIMULATOR  ns-2 is an discrete event driven simulation  Physical activities are translated to events  Events are queued and processed in the order of their scheduled occurrences  Time progresses as the events are processed Time: 1.5 sec Time: 1.7 sec 1 2 Time: 2.0 sec Time: 1.8 sec 4
  • 5. Discrete Event Scheduler time_, uid_, next_, handler_ head_ -> head_ -> handler_ -> handle() insert time_, uid_, next_, handler_ Event Scheduler 5
  • 6. EVENT SCHEDULER  Non-Real time schedulers  Implementations : List , Heap , Calender  Calender is default  Real time schedulers  Used for emulation for direct interaction with real NT.  Basic use of an event scheduler:  schedule simulation events, such as when to start an FTP application, when to finish a simulation, or for simulation scenario generation prior to a simulation run. 6
  • 7. NS-2 ENVIRONMENT Simulation 1 2 Scenario set ns_ [new Simulator] Tcl Script set node_(0) [$ns_ node] set node_(1) [$ns_ node] class MobileNode : public Node { C++ friend class PositionHandler; public: Implementation MobileNode(); • • } 7
  • 8. TCL INTERPRETER WITH EXTENTS Event ns-2 Scheduler tclcl Component Network otcl tcl8.0  otcl: Object-oriented support  tclcl: C++ and otcl linkage  Discrete event scheduler  Data network (the Internet) components 8
  • 9. NS-2 Directory Structure sim tcl8.0 tk8.0 otcl Tcl ns-2 nam-1 tcl code C++ code tcl ... example ex test lib ... validation test tcl code core 9
  • 10. NODE ARCHITECTURE Node Agent Classifier Local Agent Classifier Node entry point Agent Port Classifiers: packet demultiplexers. Addr Link Link Link 10 Agents are either protocol endpoints or related objects that generate/fill-in packet fields.
  • 11. PacketsPACKET STRUCTURE (events) packet next_ Size determined accessdata( ) - packet size at simulation bits( ) Size - timestamp config time determined at cmn header compile time - type Size - UID determined at tcp header compile time - interface label Size determined at ip header compile time Size determined at trace header compile time 11
  • 12. Links Links: keeps track of “from” and “to” node objects. blocked Link entry Enq Trace Queue Deq Trace Delay TTL Rcv Trace point Drop head Drp Trace 12
  • 13. N1 N2 Node Node Classifier Classifier Local Local Agent Agent Classifier Classifier Application Application Port Port Addr Addr Link Link Enq Trace Queue Deq Trace Delay TTL Rcv Trace Drop head Drp Trace 13
  • 14. NS-2 : C++ / OTCL  NS-2 Code contains two sets of languages, namely C++ and OTcl.  C++ is used for the creation of objects because of speed and efficiency.  OTcl is used as a front-end to setup the simulator, configure objects and schedule events because of its ease of use. 14
  • 15. Why two languages? (Tcl & C++)  C++: Detailed protocol simulations require systems programming language  byte manipulation, packet processing, algorithm implementation  Run time speed is important  Turn around time (run simulation, find bug, fix bug, recompile, re-run) is slower  Tcl: Simulation of slightly varying parameters or configurations  quickly exploring a number of scenarios  iteration time (change the model and re-run) is more important 15
  • 16. Tcl or C++?  Tcl  Simple Configuration, Setup, Scenario  If it’s something that can be done without modifying existing Tcl module.  C++  Anything that requires processing each packet  Needs to change behavior of existing module 16
  • 17. NS-2 Directory Structure sim tcl8.0 tk8.0 otcl Tcl ns-2 nam-1 tcl code C++ code tcl ... example ex test lib ... validation test tcl code core 17
  • 18. Making Changes in C++ Space  Existing code  recompile  Addition  change Makefile and recompile 18
  • 19. Making Changes in otcl Space  Existing code  recompile  source  Addition  source  change Makefile (NS_TCL_LIB), tcl/ns- lib.tcl (source) and recompile 19
  • 20. INSTALLATION  Unix variants  Download NS-allinone-2.27 package  Contains  TCL/TK 8.4.5  oTCL 1.8  Tclcl 1.15  Ns2  Nam -1 20
  • 21. CODE FOR SIMPLE TOPOLOGY  Creating a Simulator Object  set ns [new Simulator]  Setting up files for trace & NAM  set trace_nam [open out.nam w]  set trace_all [open all.tr w]  Tracing files using their commands  $ns namtrace-all $trace_nam  $ns trace-all $trace_all 21
  • 22. CODE FOR SIMPLE TOPOLOGY  Closing trace file and starting NAM  proc finish { } {  global ns trace_nam trace_all  $ns flush-trace  close $trace_nam  close $trace_all  exec nam out.nam &  exit 0 } 22
  • 23. CODE FOR SIMPLE TOPOLOGY  Creating LINK & NODE topology  Creating NODES  set n1 [$ns node]  set n2 [$ns node]  set n3 [$ns node]  set n4 [$ns node]  set r1 [$ns node]  set r2 [$ns node] 23
  • 24. CODE FOR SIMPLE TOPOLOGY  Creating LINKS  $ns duplex-link $N1 $R1 2Mb 5ms DropTail  set DuplexLink0 [$ns link $N1 $R1]  $ns duplex-link $N2 $R1 2Mb 5ms DropTail  set DuplexLink1 [$ns link $N2 $R1]  $ns duplex-link $R1 $R2 1Mb 10ms DropTail  set DuplexLink2 [$ns link $R1 $R2]  $ns duplex-link $R2 $N3 2Mb 5ms DropTail  set DuplexLink3 [$ns link $R2 $N3]  $ns duplex-link $R2 $N4 2Mb 5ms DropTail  set DuplexLink4 [$ns link $R2 $N4] 24
  • 25. CODE FOR SIMPLE TOPOLOGY  Orientation of links  $ns duplex-link-op $N1 $R1 orient right-down  $ns duplex-link-op $N2 $R1 orient right-up  $ns duplex-link-op $R1 $R2 orient right  $ns duplex-link-op $R2 $N3 orient right-up  $ns duplex-link-op $R2 $N4 orient right-down 25
  • 28. GENERATING TRAFFIC  Attaching AGENT TCP to NODE 1  set TCP1 [new Agent/TCP]  $ns attach-agent $N1 $TCP1  Attaching AGENT TCP to NODE 2  set TCP2 [new Agent/TCP]  $ns attach-agent $N2 $TCP2  Attaching AGENT TCP to NODE 3  set TCP3 [new Agent/TCPSink]  $ns attach-agent $N2 $TCP3  Attaching AGENT TCP to NODE 4  set TCP4 [new Agent/TCPSink]  $ns attach-agent $N2 $TCP4 28
  • 29. GENERATING TRAFFIC  Attaching Application (FTP)  set FTP0 [new Application/FTP]  set FTP1 [new Application/FTP]  $FTP0 attach-agent $TCP0  $FTP1 attach-agent $TCP1 29
  • 30. 30

Editor's Notes

  1. This section talks about the discrete event schedulers of NS. As described in the Overview section, the main users of an event scheduler are network components that simulate packet-handling delay or that need timers. Figure shows each network object using an event scheduler. Note that a network object that issues an event is the one who handles the event later at scheduled time. Also note that the data path between network objects is different from the event path. Actually, packets are handed from one network object to another using send(Packet* p) {target_->recv(p)}; method of the sender and recv(Packet*, Handler* h = 0) method of the receiver