computer networks ns2

  • View
    219

  • Download
    0

Embed Size (px)

Text of computer networks ns2

  • 8/17/2019 computer networks ns2

    1/20

      EXPERIMENT NO :

    AIM:

    set ns [new Simulator]

    #Open the NAM trace file

    set nf [open o.nam w] $ns namtrace-all $nf

    set totalNodes 3

    for {set i ! {$i " $totalNodes! {incr i! { set node$i% [$ns node] !

    set ser&er  set router ' set client (

    #---------- )reatin* +uple, in----------------#

    $ns duple,-lin $node$ser&er% $node$router% (M/ 0ms +rop1ail $ns duple,-lin $node$router% $node$client% (M/ 0ms +rop1ail

    $ns duple,-lin-op $node$ser&er% $node$router% orient ri*ht $ns duple,-lin-op $node$router% $node$client% orient ri*ht

    #------------a/ellin*----------------#

    $ns at . 2$node$ser&er% la/el Ser&er2$ns at . 2$node$router% la/el outer2 $ns at . 2$node$client% la/el )lient2

    # +efinin* a transport a*ent for sendin* set tcp [new A*ent41)5]

    # Attachin* transport a*ent to sender node $ns attach-a*ent $node$ser&er% $tcp

    # +efinin* a transport a*ent for recei&in* set sin [new A*ent41)5Sin]

  • 8/17/2019 computer networks ns2

    2/20

    # Attachin* transport a*ent to recei&er node $ns attach-a*ent $node$client% $sin

    #)onnectin* sendin* and recei&in* transport a*ents $ns connect $tcp $sin

    #+efinin* Application instance set ftp [new Application4615]

    # Attachin* transport a*ent to application a*ent $ftp attach-a*ent $tcp

    # Settin* flow color $tcp set fid 7

    # data pacet *eneration startin* time $ns at '. 2$ftp start2

    # data pacet *eneration endin* time $ns at 8. 2$ftp stop2

     proc finish {! { *lo/al ns nf $ns flush-trace #)lose the NAM trace file close $nf #9,ecute NAM on the trace file e,ec nam o.nam : e,it 

    ! $ns at '. 2finish2

    $ns run

  • 8/17/2019 computer networks ns2

    3/20

  • 8/17/2019 computer networks ns2

    4/20

    EXPERIMENT NO :

    AIM:

    #)reate a simulator o/;ect

    set ns [new Simulator]

    #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf

    #+efine a

  • 8/17/2019 computer networks ns2

    5/20

  • 8/17/2019 computer networks ns2

    6/20

    EXPERIMENT NO:

    AIM:

    #6ilename= test(.tcl

    #-------9&ent scheduler o/;ect creation--------#

    set ns [new Simulator]

    #----------creatin* trace o/;ects----------------#

    set nt [open test(.tr w] $ns trace-all $nt

    #----------creatin* nam o/;ects----------------#

    set nf [open test(.nam w]

    $ns namtrace-all $nf

    #----------Settin* color >+----------------#

    $ns color ' darma*enta $ns color ( ?ellow $ns color 3 /lue $ns color 7 *reen $ns color 0 /lac

    #---------- )reatin* Networ----------------#

    set totalNodes 3

    for {set i ! {$i " $totalNodes! {incr i! { set node$i% [$ns node] !

    set ser&er  set router ' set client (

    #---------- )reatin* +uple, in----------------#

  • 8/17/2019 computer networks ns2

    7/20

    $ns duple,-lin $node$ser&er% $node$router% (M/ 0ms +rop1ail $ns duple,-lin $node$router% $node$client% (M/ 0ms +rop1ail

    $ns duple,-lin-op $node$ser&er% $node$router% orient ri*ht $ns duple,-lin-op $node$router% $node$client% orient ri*ht

    #------------a/ellin*----------------#

    $ns at . 2$node$ser&er% la/el Ser&er2 $ns at . 2$node$router% la/el outer2 $ns at . 2$node$client% la/el )lient2

    $ns at . 2$node$ser&er% color /lue2

    $ns at . 2$node$client% color /lue2

    $node$ser&er% shape he,a*on $node$client% shape he,a*on

    #------------+ata 1ransfer /etween Nodes----------------#

    # +efinin* a transport a*ent for sendin* set tcp [new A*ent41)5]

    # Attachin* transport a*ent to sender node $ns attach-a*ent $node$ser&er% $tcp

    # +efinin* a transport a*ent for recei&in* set sin [new A*ent41)5Sin]

    # Attachin* transport a*ent to recei&er node $ns attach-a*ent $node$client% $sin

    #)onnectin* sendin* and recei&in* transport a*ents

    $ns connect $tcp $sin

    #+efinin* Application instance set ftp [new Application4615]

    # Attachin* transport a*ent to application a*ent $ftp attach-a*ent $tcp

    # Settin* flow color $tcp set fid 7

    # data pacet *eneration startin* time $ns at '. 2$ftp start2

  • 8/17/2019 computer networks ns2

    8/20

    # data pacet *eneration endin* time $ns at 8. 2$ftp stop2

    #---------finish procedure--------#

     proc finish {! { *lo/al ns nf nt $ns flush-trace close $nf

    close $nt  puts 2runnin* nam...2 e,ec nam test(.nam : e,it 

    !

    #)allin* finish procedure $ns at '. 2finish2 $ns run

  • 8/17/2019 computer networks ns2

    9/20

    EXPERIMENT NO :

    AIM:

    set ns [new Simulator] set nf [open out.nam w] $ns namtrace-all $nf set n [$ns node] set n' [$ns node] set n( [$ns node] set n3 [$ns node] set n7 [$ns node]

    set n0 [$ns node] set n8 [$ns node] set n@ [$ns node] set n [$ns node] set nB [$ns node] set n' [$ns node]

    $ns duple,-lin $n $n0 0M/ (ms +rop1ail

    $ns duple,-lin $n' $n8 0M/ (ms +rop1ail

    $ns duple,-lin $n( $n@ 0M/ (ms +rop1ail

    $ns duple,-lin $n3 $n 0M/ (ms +rop1ail

    $ns duple,-lin $n7 $nB 0M/ (ms +rop1ail

    $ns duple,-lin $n0 $n8 .0M/ 'ms +rop1ail

    $ns duple,-lin $n8 $n@ .0M/ 'ms +rop1ail

    $ns duple,-lin $n@ $n .0M/ 'ms +rop1ail

    $ns duple,-lin $n $nB .0M/ 'ms +rop1ail

    $ns duple,-lin $nB $n' .0M/ 'ms +rop1ail

    set udp [new A*ent4C+5] $ns attach-a*ent $n $udp set c/r [new Application41raffic4)D] $c/r set pacetSiEe 0 $c/r set inter&al .0 $c/r attach-a*ent $udp set null [new A*ent4Null] $ns attach-a*ent $n' $null

  • 8/17/2019 computer networks ns2

    10/20

    $ns connect $udp $null $ns at .0 2$c/r start2 $ns at 7.0 2$c/r stop2 $ns at 0. 2finish2

     proc finish {! { *lo/al ns nf $ns flush-trace close $nf e,ec nam out.nam : e,it 

    !

    $ns at 0. 2finish2 $ns run

  • 8/17/2019 computer networks ns2

    11/20

    EXPERIMENT NO :

    AIM: 1o monitor traffic for in* topolo*? usin* NS(

    #)reate a simulator o/;ect set ns [new Simulator]

    #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf

    #+efine a

  • 8/17/2019 computer networks ns2

    12/20

    # )reate a )D traffic source and attach it to tcp set c/r [new Application41raffic4)D] $c/r set pacetSiEe 0 $c/r set inter&al .'

    $c/r attach-a*ent $tcp

    #Schedule e&ents for the )D a*ents $ns at .0 2$c/r start2 $ns at 7.0 2$c/r stop2

    #)all the finish procedure after 0 seconds of simulation time $ns at 0. 2finish2

    #un the simulation

    $ns run

  • 8/17/2019 computer networks ns2

    13/20

    EXPERIMENT NO :

    AIM:

    1o monitor traffic for Star topolo*? usin* NS(

    #)reate a simulator o/;ect set ns [new Simulator]

    #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf

    #+efine a

  • 8/17/2019 computer networks ns2

    14/20

    $tcp set class ' $ns attach-a*ent $n' $tcp #)reate a 1)5 Sin a*ent a traffic sin% for 1)5 and attach it to node n3 set sin [new A*ent41)5Sin]

    $ns attach-a*ent $n3 $sin #)onnect the traffic sources with the traffic sin $ns connect $tcp $sin

    set tcp' [new A*ent41)5] $tcp' set class ' $ns attach-a*ent $n( $tcp' #)reate a 1)5 Sin a*ent a traffic sin% for 1)5 and attach it to node n3 set sin' [new A*ent41)5Sin] $ns attach-a*ent $n7 $sin' #)onnect the traffic sources with the traffic sin

    $ns connect $tcp' $sin'

    # )reate a )D traffic source and attach it to tcp set c/r [new Application41raffic4)D] $c/r set pacetSiEe 0 $c/r set inter&al .' $c/r attach-a*ent $tcp

    set c/r' [new Application41raffic4)D] $c/r' set pacetSiEe 0 $c/r' set inter&al .' $c/r' attach-a*ent $tcp'

    #Schedule e&ents for the )D a*ents $ns at .0 2$c/r start2 $ns at 7.0 2$c/r stop2

    $ns at .0 2$c/r' start2 $ns at 7.0 2$c/r' stop2

    #)all the finish procedure after 0 seconds of simulation time $ns at 0. 2finish2

    e,ec aw -f throu*hput.aw sample(@.tr G nam.out :

    #un the simulation $ns run

    D9H>N { rec&dSiEe I 

  • 8/17/2019 computer networks ns2

    15/20

    t,siEeI drpSiEeI start1ime I 7 stop1ime I 

    thruI

    !

    { e&ent I $' time I $( nodeid I $3

     ptsiEe I $ le&el I $7

    # Store start time if le&el II JAH1K :: e&ent II JsK % { if time " start1ime% { start1ime I time ! # hdrsiEe I ptsiEe L 7 # ptsiEe -I hdrsiEe # Store transm