Simulator Pres

download Simulator Pres

of 37

Transcript of Simulator Pres

  • 8/4/2019 Simulator Pres

    1/37

    Simulators for Sensor

    Networks

    Sagnik Bhattacharya

    9/12/2001

  • 8/4/2019 Simulator Pres

    2/37

  • 8/4/2019 Simulator Pres

    3/37

  • 8/4/2019 Simulator Pres

    4/37

    How much effort should we

    put in?

    Build battery and wireless models?

    (Preferably no) Implement routing?

    How much learning is involved?

    Change basic modules or just add our ownmodules?

    -A computer scientist is someone who fixes things that aren't

    broken.

  • 8/4/2019 Simulator Pres

    5/37

  • 8/4/2019 Simulator Pres

    6/37

    GlomoSim

    Specific for mobile wireless networks.

    Built as a set of libraries. The libraries are

    built in Parsec( a C-based discrete eventsimulation language).

    Layered architecture with easy plug-in

    capability.

    -Any program that runs right is obsolete.

  • 8/4/2019 Simulator Pres

    7/37

    Propagation

    model

    Radio

    MAC Layer

    Network

    IP

    Transport

    Application

    Link Layer

    GloMoSim LibraryGloMoSim Library

    Modular, extensible library for

    network models

    Model each layer using abstract

    ordetailed model

    Built-in statistics collection ateach layer

    Cons :

    Fixed protocol layers.

    Application Processing

    Free space, TIREM

    EPLRS, WaveLAN, ...

    IEEE 802.11, 802.3,

    OSPF,AODV,

    IP

    TCP, UDP, RSVP

    RTP Wrapper

    Packet Store/Forward

    Data Plane

    -Windows is NOT a virus. Viruses DO something.

  • 8/4/2019 Simulator Pres

    8/37

    NS - 2

    De facto standard for network simulations Discrete Event Simulator

    Packet-level

    Wired and Wireless Size : (Current release adds around 10%) 100K lines of C++

    70K lines of OTcl

    30K lines of test suites 20K lines of documentation

    -A program is never finished until the programmer dies.

  • 8/4/2019 Simulator Pres

    9/37

    NS Architecture

    Object-oriented (C++, OTcl)

    Scalability + Extensibility

    Control/data separation

    Split C++/OTcl object

    Modular approach

    Fine-grained object composition

    Reusability

    -You are making progress if each mistake is a new one.

  • 8/4/2019 Simulator Pres

    10/37

    C++ and OTcl Separation

    C++ for data Per packet action

    OTcl for control Periodic or triggered action

    + Compromise between composibility and

    speed Learning and debugging

    -To err is human, but to really foul things up requires a computer.

  • 8/4/2019 Simulator Pres

    11/37

    OTcl and C++: The Duality

    C++ OTcl

    Pure C++objects

    Pure OTclobjects

    C++/OTcl split objects

    ns

    -There were computers in Biblical times. Eve had an Apple.

  • 8/4/2019 Simulator Pres

    12/37

    SensorSim

    Extension to NS - 2.

    Provides battery models, radio

    propagation models and sensor channelmodels.

    Provides a lightweight protocol stack.

    Has support for hybrid simulation. To be integrated with NS - 2.

    -There can never be a computer language in which you cannotwrite a bad program.

  • 8/4/2019 Simulator Pres

    13/37

    SensorSim Architecture

    monitor and controlhybrid network

    (local or remote)

    Simulation Machine

    Gateway Machine

    ns

    modified event scheduler

    VR

    V

    VV

    GUIapp

    app

    R

    real sensor apps on

    virtual sensor nodes

    gateway

    socket

    comm

    serial

    comm

    HS InterfaceEthernet RS232

    Proxies for real

    sensor nodes

    GUI Interface

    app

  • 8/4/2019 Simulator Pres

    14/37

    Sensor Node Model in SensorSim

    Node Function Model

    Network Layer

    Micro Sensor Node

    Applications

    Power Model(Energy Consumers and Providers)

    Battery

    Model

    Radio Model

    CPU Model

    Sensor #1 Model

    Sensor #2 Model

    MAC Layer

    Physical Layer

    Sensor Layer

    Wireless Channel Sensor Channel

    Network

    Protocol Stack

    Sensor

    Protocol Stack

    Middleware

    Physical Layer

    State

    Change

    Status

    Check

    -There are two ways to write error-free programs; only the thirdone works.

  • 8/4/2019 Simulator Pres

    15/37

    Power Management Model

    Transmit Receive

    Off

    Idle

    BZR event

    BZR event

    BZR event

    receive

    done

    transmit

    transmit

    done

    Without Power Management

    Transmit Receive

    Sleep

    Off

    Idletransmit

    timeout(3 sec)

    BZR event

    BZR event

    transmit

    transmit

    done

    BZR event

    receive

    done

    receivetimeout

    With Power Management

    -The program is absolutely right; therefore the computer must be

    wrong.

  • 8/4/2019 Simulator Pres

    16/37

    SensorSim Problems

    Still at pre-release stage.

    No Documentation.

    The software currently has a very specificapplication hard-coded.

    It caters to only one base station.

    -The definition of an upgrade: Take old bugs out, put new ones in.

  • 8/4/2019 Simulator Pres

    17/37

    NS-2 primer

    -Reference Manual: Object that raises the monitor to eye level.

    Also used to compensate for that short table leg.

  • 8/4/2019 Simulator Pres

    18/37

    Hello World - Interactive

    Mode % ns% set ns [new Simulator]

    _o3

    % $ns at 1 puts \Hello World!\1

    % $ns at 1.5 exit

    2

    % $ns runHello World!

    72%

    -One person's error is another person's data.

  • 8/4/2019 Simulator Pres

    19/37

    Hello World - Batch Mode

    simple.tclset ns [new Simulator]

    $ns at 1 puts \Hello World!\$ns at 1.5 exit

    $ns run

    74% ns simple.tcl

    Hello World!

    75%

    -Maintenance-free: When it breaks, it can't be fixed...

  • 8/4/2019 Simulator Pres

    20/37

    Basic tclset a 43

    set b 27

    proc test { a b } {

    set c [expr $a + $b]

    set d [expr [expr $a - $b] * $c]for {set k 0} {$k < 10} {incr k} {

    if {$k < 5} {

    puts k < 5, pow = [expr pow($d, $k)]

    } else {

    puts k >= 5, mod = [expr $d % $k]}

    }

    }

    test 43 27 -MACINTOSH stands for Most Applications Crash If Not TheOperating System Hangs.

  • 8/4/2019 Simulator Pres

    21/37

    Basic OTclClass Mom

    Mom instproc greet {} {

    $selfinstvar age_

    puts $age_ years old

    mom: How are youdoing?

    }

    Class Kid -superclass Mom

    Kid instproc greet {} {$selfinstvar age_

    puts $age_ years oldkid: Whats up, dude?

    }

    set mom [new Mom]

    $mom set age_ 45

    set kid [new Kid]

    $kid set age_ 15

    $mom greet

    $kid greet

    -It works! Now if only I could remember what I did...

  • 8/4/2019 Simulator Pres

    22/37

    Elements of ns-2

    Create the event scheduler

    [Turn on tracing]

    Create network Setup routing

    Create transport connection

    Create traffic / Schedule events

    Transmit application-level data

    Start simulation

    -It is easier to write an incorrect program than understand a

    correct one.

  • 8/4/2019 Simulator Pres

    23/37

    Wireless simulation in NS-2

    Very different from wired simulation.

    Central object called GOD(General

    Operations Director) contains global stateinformation.

    Nodes are inherently mobile.

    -I finally made my stupid computer faster; I dropped it out of the

    window, and it went really fast.

  • 8/4/2019 Simulator Pres

    24/37

    An Example Step 1

    # Define Global Variables

    # create simulator

    set ns [new Simulator]

    # define traces

    set tracefd [open simple.tr w]

    $ns_ trace-all $tracefd

    # create a topology in a 100m x 100m area

    set topo [new Topography]

    $topo load_flatgrid 100 100

    -If at first you don't succeed, call it version 1.0.

  • 8/4/2019 Simulator Pres

    25/37

    An Example Step 2

    # Create God

    create-god $val(nn)

    # Create channel

    set chan_1_ [new $val(chan)]

    -For any problem there is a solution that is simple, quick, and

    ultimately worse than the problem.

  • 8/4/2019 Simulator Pres

    26/37

    An Example Step 3$ns_ node-config-adhocRouting $val(rp) \

    -llType $val(ll) \-macType $val(mac) \

    -ifqType $val(ifq) \

    -ifqLen $val(ifqlen) \

    -antType $val(ant) \

    -propType $val(prop) \

    -phyType $val(netif) \-channel $chan_1_ \

    -topoInstance $topo \

    -agentTrace ON \

    -routerTrace ON \

    -macTrace OFF \

    -movementTrace OFF \-energyModel "EnergyModel" \

    -initialEnergy $val(initialenergy) \

    -rxPower $val(receivepower) \

    -txPower $val(transmitpower) \

    -idlePower $val(idlepower)

    -Excuse me for butting in, but I'm interrupt-driven.

  • 8/4/2019 Simulator Pres

    27/37

    An Example Step 4

    # Generating nodes

    for {set i 0} {$i < $val(nn) } {incr i} {

    set node_($i) [$ns_ node]

    }

    # Provide initial (X,Y, for now Z=0) co-ordinatesfor mobilenodes

    $node_(0) set X_ 94.85

    $node_(0) set Y_ 12.75$node_(0) set Z_ 0.0

    $node_(1) set X_ 60.79

    :

    :

    -Computers can figure out all kinds of problems, except the thingsin the world that just don't add up.

  • 8/4/2019 Simulator Pres

    28/37

    An Example Step 5

    #Create two ping agents and attach themto the nodes n0 and n2

    set p0 [new Agent/Ping]

    $ns attach-agent $n0 $p0

    set p1 [new Agent/Ping]

    $ns attach-agent $n2 $p1

    #Connect the two agents

    $ns connect $p0 $p1

    -Computer Science is no more about computers than astronomy is

    about telescopes.

    E. W. Dijkstra

  • 8/4/2019 Simulator Pres

    29/37

    An Example Step 6

    #Schedule events

    $ns_ at 100.0 "puts \"hell-O\" "

    $ns_ at 10.2 "$p0 send"

    $ns_ at 10.4 "$p1 send":

    :

    #Run the Simulationputs "Starting Simulation..."

    $ns_ run

    -Build a system that even a fool can use, and only a fool will use

    it.

  • 8/4/2019 Simulator Pres

    30/37

    Ping Protocol

    Check out the handout.

    To add a new protocol :

    Define packet header (PT_PING)

    Define new agent class as a subclass ofAgent in header file (ping.h)

    Implement at least the following functions: int command ( int argc, const char*const* argc)

    void recv ( Packet * pkt, Handler* h)

    -To err is human, but to really foul things up requires a computer.

  • 8/4/2019 Simulator Pres

    31/37

    NS - 2 (contd.)

    Cons : Comparatively difficult to learn and use.

    Supposedly more useful for getting statisticsfor lower level protocols.

    Originally built for wired networks, laterextended for wireless.

    Supposedly, does not work well for largetopologies.

    -To err is human--and to blame it on a computer is even more so.

  • 8/4/2019 Simulator Pres

    32/37

    NS-2 problems and

    workarounds Large memory footprint

    100 nodes 23MB

    1000 nodes 412 MB Solutions :

    Turn off tracing

    -routerTrace OFF \-macTrace OFF \ Remove packet headers

    remove-all-packet-headers

    add-packet-header DSDV-Bug? That's not a bug, that's a feature.

  • 8/4/2019 Simulator Pres

    33/37

    Scalability of NS-2

    Maximum number of nodes dependsupon the traffic.

    Should be able to up to 500 nodes withreasonable(?) traffic.

    Running time?

    -Every time I type 'win', I loose ...

  • 8/4/2019 Simulator Pres

    34/37

    To use NS..

    Dont worry about Otcl. Its easy..

    Forget about Nam traces.

    Join the ns-usermailing list. Get started as soon as possible. learning to

    use and modify it can take time.

    Just adding new protocols might not do. Someinternal changes might need to be made.

    -A user friendly computer first requires a friendly user.

  • 8/4/2019 Simulator Pres

    35/37

    Conclusion

    Use SensorSim if you can.

    NS-2 can be used for simulation of the

    order of hundreds of nodes. Notpossible with motes.

    Can build more advanced protocols, for

    future motes which might have morememory.

    -ASCII stupid question, get a stupid ANSI!

  • 8/4/2019 Simulator Pres

    36/37

    URLs

    This presentation:

    http://www.cs.virginia.edu/~sb2jb/rese

    arch/ns

    NS-2 home:

    http://www.isi.edu/nsnam/ns

    -Every bug you find is the last one.

  • 8/4/2019 Simulator Pres

    37/37

    Questions?

    -Computer Science: solving today's problems tomorrow.