Wednesday, 26 February 2014

Handoff in ns2 (Handoff between Wlan and UMTS networks)



Vertical Handoff means handoff is between two network access points or Base Stations that uses the different network access technologies.


Steps of Vertical Handoff



1.System Discovery: 
                              Mobile terminals equipped with multiple interfaces deploy a system discovery agent to determine which networks can be used and the services available in each network. 


2. Handoff decision: 
                               Based on several parameters like RSS, availability of free channel and service charges, the mobile devices determine which network it should connect to.


3. Handoff execution: 
                                The connections are rerouted from the existing network to the new network in a seamless manner.


Input Parameters of Vertical Handoff process


1. Available Bandwidth (BAV): It is the amount of unused bandwidth of the candidate Base Station (BS) or Access point (AP).WLAN have greater bandwidth than cellular Network (UMTS).


2. Speed of mobile terminal (VMT ): It is the velocity with which the mobile terminal (MT) is moving. For high speed MT, UMTS is preferred because of greater coverage area.


3. Number of Users (UN): The QoS of WLAN is UN sensitive. As the number of users increase, the collisions increase and results in poor QoS.


4. Received Signal Strength (RSS): It is the strength of the signal received, as the RSS of the neighboring network rises above the threshold the Vertical Handoff is feasible i.e. the handoff takes place if and only if RSS of the BS or AP is above the threshold.


Handoff in ns2: (TCL scripts)
 

remove-all-packet-headers  
 add-packet-header MPEG4 MAC_HS RLC LL Mac RTP TCP IP Common Flags  
  set val(x)      1000  
  set val(y)      1000  
 set ns [new Simulator]  
 global ns  
 set f [open out.tr w]  
 $ns trace-all $f  
 set namtrace [open log.nam w]  
 $ns namtrace-all-wireless $namtrace $val(x) $val(y)  
 #set f0 [open proj_simple.tr w]  
 proc finish {} {  
   global ns  
   global f namtrace  
   $ns flush-trace  
   close $f   
  close $namtrace  
   puts " Simulation ended."  
     exec nam log.nam &  
     exit 0  
     exit 0  
 }  
 #for {set i 0} {$i < $val(nn)} {incr i} {  
  #    $ns initial_node_pos $n($i) 30+i*100  
 #}  
 #$ns at 0.0 "$n(0) setdest 76.0 224.0 30000.0"  
 #$ns at 0.0 "$n(0) label node_0"  
 #-----------------------------------------------------------------------------------------------------------------------------  
 $ns set debug_ 0  
 $ns set hsdschEnabled_ 1  
 $ns set hsdsch_rlc_set_ 0  
 $ns set hsdsch_rlc_nif_ 0  
 $ns node-config -UmtsNodeType rnc  
 # Node address is 0.  
 set rnc [$ns create-Umtsnode]  
 $ns node-config -UmtsNodeType bs \  
           -downlinkBW 32kbs \  
           -downlinkTTI 10ms \  
           -uplinkBW 32kbs \  
           -uplinkTTI 10ms \  
    -hs_downlinkTTI 2ms \  
    -hs_downlinkBW 64kbs \  
 # Node address is 1.  
 set bs [$ns create-Umtsnode]  
 $ns setup-Iub $bs $rnc 622Mbit 622Mbit 15ms 15ms DummyDropTail 2000  
 $ns node-config -UmtsNodeType ue \  
           -baseStation $bs \  
           -radioNetworkController $rnc  
 # Node address for ue1 and ue2 is 2 and 3, respectively.  
 set ue1 [$ns create-Umtsnode]  
 set ue2 [$ns create-Umtsnode]  
 # Node address for sgsn0 and ggsn0 is 4 and 5, respectively.  
 set sgsn0 [$ns node]  
 set ggsn0 [$ns node]  
 # Node address for node1 and node2 is 6 and 7, respectively.  
 set node1 [$ns node]  
 set node2 [$ns node]  
 $ns duplex-link $rnc $sgsn0 622Mbit 0.4ms DropTail 1000  
 $ns duplex-link $sgsn0 $ggsn0 622MBit 10ms DropTail 1000  
 $ns duplex-link $ggsn0 $node1 10MBit 15ms DropTail 1000  
 $ns duplex-link $node1 $node2 10MBit 35ms DropTail 1000  
 $rnc add-gateway $sgsn0  
 set tcp0 [new Agent/UDP]  
 $tcp0 set fid_ 0  
 $tcp0 set prio_ 2  
 $ns at 0.0 "$node1 label Node1"  
 $ns at 0.0 "$node2 label Node2"  
 $ns at 0.0 "$ue1 label Umtsnode1"  
 $ns at 0.0 "$ue2 label Umtsnode2"  
 $ns at 0.0 "$bs label Base_Station"  
 $ns at 0.0 "$bs label Base_Station"  
 $ns at 0.0 "$sgsn0 label Node_1"  
 $ns at 0.0 "$ggsn0 label Node_2"  
 $ns at 0.0 "$rnc label Node_0"  
 $node1 set X_ 119.0  
 $node1 set Y_ 38.0  
 $node1 set Z_ 0.0  
 $bs set X_ 31.0  
 $bs set Y_ 35.0  
 $bs set Z_ 0.0  
 $node2 set X_ 138.0  
 $node2 set Y_ 3.0  
 $node2 set Z_ 0.0  
 $ue1 set X_ 7.0  
 $ue1 set Y_ 72.0  
 $ue1 set Z_ 0.0  
 $ue2 set X_ 66.0  
 $ue2 set Y_ 77.0  
 $ue2 set Z_ 0.0  
 $sgsn0 set X_ 71.0  
 $sgsn0 set Y_ 37.0  
 $sgsn0 set Z_ 0.0  
 $ggsn0 set X_ 101.0  
 $ggsn0 set Y_ 2.0  
 $ggsn0 set Z_ 0.0  
 $rnc set X_ 58.0  
 $rnc set Y_ 4.0  
 $rnc set Z_ 0.0  
 $ns attach-agent $rnc $tcp0  
 set ftp0 [new Application/Traffic/CBR]  
 $ftp0 attach-agent $tcp0  
 set sink0 [new Agent/Null]  
 $sink0 set fid_ 0  
 $ns attach-agent $ue1 $sink0  
 $ns connect $tcp0 $sink0  
 $ns node-config -llType UMTS/RLC/UM \  
           -downlinkBW 64kbs \  
           -uplinkBW 64kbs \  
           -downlinkTTI 20ms \  
           -uplinkTTI 20ms \  
    -hs_downlinkTTI 2ms \  
    -hs_downlinkBW 64kbs  
 $ns create-hsdsch $ue1 $sink0  
 $bs setErrorTrace 0 "/home/naveen/idealtrace"  
 $bs setErrorTrace 1 "/home/naveen/idealtrace"  
 $bs loadSnrBlerMatrix "/home/naveen/SNRBLERMatrix"  
 #set dch0 [$ns create-dch $ue1 $sink0]  
 $ue1 trace-inlink $f 1  
 $bs trace-outlink $f 1  
 #$rnc trace-inlink-tcp $f 0  
 # tracing for all hsdpa traffic in downtarget  
 $rnc trace-inlink-tcp $f 0  
 $bs trace-outlink $f 2  
 # per UE  
 $ue1 trace-inlink $f 2  
 $ue1 trace-outlink $f 3  
 $bs trace-inlink $f 3  
 $ue1 trace-inlink-tcp $f 2  
 #______________________________________________________________  
  set val(chan)     Channel/WirelessChannel ;# channel type  
  set val(prop)     Propagation/TwoRayGround ;# radio-propagation model  
  set val(ant)     Antenna/OmniAntenna   ;# Antenna type  
  set val(ll)      LL            ;# Link layer type  
  set val(ifq)     Queue/DropTail/PriQueue ;# Interface queue type  
  set val(ifqlen)    2000           ;# max packet in ifq  
  set val(netif)    Phy/WirelessPhy     ;# network interface type  
  set val(mac)     Mac/802_11        ;# MAC type  
  set val(nn)      51            ;# number of mobilenodes  
  set val(rp)      OPTG          ;# routing protocol  
  set umtsflow "umtsflow"  
  set umts "umts"   
  set topo [new Topography]  
 $topo load_flatgrid $val(x) $val(y)  
 #===========================================================================  
 create-god $val(nn)  
 #===========================================================================  
 set chan_1 [new $val(chan)]  
 $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) \  
          -topoInstance $topo \  
          -agentTrace ON \  
          -routerTrace ON \  
          -macTrace ON \  
          -movementTrace OFF \  
          -channel $chan_1  \  
             -energyModel EnergyModel \  
             -initialEnergy 20 \  
             -txPower 0.09 \  
             -rxPower 0.08 \  
             -idlePower 0.0 \  
             -sensePower 0.0175  
 set n(0) [$ns node]  
 $ns at 0.0 "$n(0) color blue"  
 $n(0) color red  
 $n(0) shape "circle"  
 set n(1) [$ns node]  
 $ns at 0.0 "$n(1) color red"  
 $n(1) color red  
 $n(1) shape "circle"  
 set n(2) [$ns node]  
 $ns at 0.0 "$n(2) color darkgreen"  
 $n(2) color red  
 $n(2) shape "circle"  
 #-------------------  
 set n(7) [$ns node]  
 $ns at 0.0 "$n(7) color red"  
 $n(7) color red  
 $n(7) shape "circle"  
 set n(8) [$ns node]  
 $ns at 0.0 "$n(8) color red"  
 $n(8) color red  
 $n(8) shape "circle"  
 set n(9) [$ns node]  
 $ns at 0.0 "$n(9) color red"  
 $n(9) color red  
 $n(9) shape "circle"  
 set n(10) [$ns node]  
 $ns at 0.0 "$n(10) color red"  
 $n(10) color red  
 $n(10) shape "circle"  
 set n(11) [$ns node]  
 $ns at 0.0 "$n(11) color red"  
 $n(11) color red  
 $n(11) shape "circle"  
 set n(12) [$ns node]  
 $ns at 0.0 "$n(12) color red"  
 $n(12) color red  
 $n(12) shape "circle"  
 set n(13) [$ns node]  
 $ns at 0.0 "$n(13) color red"  
 $n(13) color red  
 $n(13) shape "circle"  
 set n(14) [$ns node]  
 $ns at 0.0 "$n(14) color red"  
 $n(14) color red  
 $n(14) shape "circle"  
 set n(15) [$ns node]  
 $ns at 0.0 "$n(15) color red"  
 $n(15) color red  
 $n(15) shape "circle"  
 set n(16) [$ns node]  
 $ns at 0.0 "$n(16) color red"  
 $n(16) color red  
 $n(16) shape "circle"  
 set n(17) [$ns node]  
 $ns at 0.0 "$n(17) color red"  
 $n(17) color red  
 $n(0) shape "circle"  
 set n(18) [$ns node]  
 $ns at 0.0 "$n(18) color red"  
 $n(18) color red  
 $n(18) shape "circle"  
 set n(19) [$ns node]  
 $ns at 0.0 "$n(19) color red"  
 $n(19) color red  
 $n(19) shape "circle"  
 set n(20) [$ns node]  
 $ns at 0.0 "$n(20) color red"  
 $n(20) color red  
 $n(20) shape "circle"  
 set n(21) [$ns node]  
 $ns at 0.0 "$n(21) color darkgreen"  
 $n(21) color red  
 $n(21) shape "circle"  
 set n(22) [$ns node]  
 $ns at 0.0 "$n(22) color red"  
 $n(22) color red  
 $n(22) shape "circle"  
 set n(23) [$ns node]  
 $ns at 0.0 "$n(23) color red"  
 $n(23) color red  
 $n(23) shape "circle"  
 set n(24) [$ns node]  
 $ns at 0.0 "$n(24) color red"  
 $n(24) color red  
 $n(24) shape "circle"  
 set n(25) [$ns node]  
 $ns at 0.0 "$n(25) color red"  
 $n(25) color red  
 $n(25) shape "circle"  
 set n(26) [$ns node]  
 $ns at 0.0 "$n(26) color darkgreen"  
 $n(26) color red  
 $n(26) shape "circle"  
 set n(27) [$ns node]  
 $ns at 0.0 "$n(27) color red"  
 $n(27) color red  
 $n(27) shape "circle"  
 set n(28) [$ns node]  
 $ns at 0.0 "$n(28) color red"  
 $n(28) color green  
 $n(28) shape "square"  
 set n(29) [$ns node]  
 $ns at 0.0 "$n(29) color red"  
 $n(29) color green  
 $n(29) shape "square"  
 set n(30) [$ns node]  
 $ns at 0.0 "$n(30) color darkgreen"  
 $n(30) color green  
 $n(30) shape "circle"  
 set n(31) [$ns node]  
 $ns at 0.0 "$n(31) color red"  
 $n(31) color green  
 $n(31) shape "circle"  
 set n(32) [$ns node]  
 $ns at 0.0 "$n(32) color red"  
 $n(32) color green  
 $n(32) shape "circle"  
 set n(33) [$ns node]  
 $ns at 0.0 "$n(33) color red"  
 $n(33) color green  
 $n(33) shape "circle"  
 set n(34) [$ns node]  
 $ns at 0.0 "$n(34) color darkgreen"  
 $n(34) color green  
 $n(34) shape "circle"  
 set n(35) [$ns node]  
 $ns at 0.0 "$n(35) color red"  
 $n(35) color green  
 $n(35) shape "square"  
 set n(36) [$ns node]  
 $ns at 0.0 "$n(36) color red"  
 $n(36) color green  
 $n(36) shape "square"  
 set n(37) [$ns node]  
 $ns at 0.0 "$n(37) color red"  
 $n(37) color green  
 $n(37) shape "circle"  
 set n(38) [$ns node]  
 $ns at 0.0 "$n(38) color darkgreen"  
 $n(38) color green  
 $n(38) shape "square"  
 set n(39) [$ns node]  
 $ns at 0.0 "$n(39) color red"  
 $n(39) color green  
 $n(39) shape "square"  
 set n(40) [$ns node]  
 $ns at 0.0 "$n(40) color red"  
 $n(40) color green  
 $n(40) shape "circle"  
 set n(41) [$ns node]  
 $ns at 0.0 "$n(41) color red"  
 $n(41) color green  
 $n(41) shape "circle"  
 set n(42) [$ns node]  
 $ns at 0.0 "$n(42) color red"  
 $n(42) color green  
 $n(42) shape "circle"  
 set n(43) [$ns node]  
 $ns at 0.0 "$n(43) color red"  
 $n(43) color green  
 $n(43) shape "circle"  
 set n(44) [$ns node]  
 $ns at 0.0 "$n(44) color red"  
 $n(44) color green  
 $n(44) shape "circle"  
 set n(45) [$ns node]  
 $ns at 0.0 "$n(45) color darkgreen"  
 $n(45) color green  
 $n(45) shape "square"  
 set n(46) [$ns node]  
 $ns at 0.0 "$n(46) color red"  
 $n(46) color green  
 $n(46) shape "square"  
 set n(47) [$ns node]  
 $ns at 0.0 "$n(47) color red"  
 $n(47) color green  
 $n(47) shape "circle"  
 set n(48) [$ns node]  
 $ns at 0.0 "$n(48) color red"  
 $n(48) color green  
 $n(48) shape "square"  
 set n(50) [$ns node]  
 $ns at 0.0 "$n(50) color darkgreen"  
 $n(50) color green  
 $n(50) shape "square"                                                            
 set n(49) [$ns node]  
 $ns at 0.0 "$n(49) color darkgreen"  
 $n(49) color green  
 $n(49) shape "square"  
 #--------  
 set n(6) [$ns node]  
 $ns at 0.0 "$n(6) color red"  
 $ns at 2.81 "$n(6) color green"  
 $ns at 2.82 "$n(6) color red"  
 $ns at 2.83 "$n(6) color green"  
 $ns at 2.84 "$n(6) color red"  
 $ns at 2.85 "$n(6) color green"  
 $ns at 2.86 "$n(6) color red"  
 $ns at 2.87 "$n(6) color green"  
 $ns at 2.88 "$n(6) color red"  
 $ns at 2.89 "$n(6) color green"  
 $ns at 2.90 "$n(6) color red"  
 $ns at 3.83 "$n(40) color green"  
 $ns at 3.84 "$n(40) color red"  
 $ns at 3.842 "$n(40) color green"  
 $ns at 3.845 "$n(40) color red"  
 $ns at 3.85 "$n(40) color green"  
 $ns at 3.86 "$n(40) color red"  
 $n(6) color red  
 $n(6) shape "circle"  
 $ns at 0.0 "$n(0) label WLAN_NODE1"  
 $ns at 0.0 "$n(1) label WLAN_NODE2"  
 $ns at 0.0 "$n(2) label WLAN_BaseStation"  
 $ns at 0.0 "$n(50) label NODE"  
 $n(0) label-color black  
 $n(1) label-color black  
 $n(2) label-color black  
 for {set i 0} {$i < 3} {incr i} {  
     $ns initial_node_pos $n($i) 10+i*10  
 }  
 $n(0) set X_ 58.0  
 $n(0) set Y_ 136.0  
 $n(0) set Z_ 0.0  
 $n(2) set X_ 34.0  
 $n(2) set Y_ 104.0  
 $n(2) set Z_ 0.0  
 $n(1) set X_ 0.5  
 $n(1) set Y_ 136.0  
 $n(1) set Z_ 0.0  
 $n(6) set X_ 6.0  
 $n(6) set Y_ 94.0  
 $n(6) set Z_ 0.0  
 $ns at 0.0 "$n(0) setdest 58.0 136.0 100000.0"  
 $ns at 0.0 "$n(2) setdest 25.0 111.0 100000.0"  
 $ns at 0.0 "$n(1) setdest 0.5 136.0 100000.0"  
 $ns at 0.0 "$n(6) setdest 6.0 94.0 100000.0"  
 $ns at 2.0 "$n(6) setdest 46.0 76.0 100.0"  
 $ns at 2.6 "$n(6) setdest 46.0 66.0 10.0"  
 #---  
 $ns at 0.0 "$n(7) setdest 300.0 500.0 10000.0"  
 $ns at 0.0 "$n(8) setdest 300.0 700.0 10000.0"  
 $ns at 0.0 "$n(9) setdest 300.0 900.0 10000.0"  
 $ns at 0.0 "$n(10) setdest 500.0 100.0 10000.0"  
 $ns at 0.0 "$n(11) setdest 500.0 300.0 10000.0"  
 $ns at 0.0 "$n(12) setdest 500.0 500.0 10000.0"  
 $ns at 0.0 "$n(13) setdest 500.0 700.0 10000.0"  
 $ns at 0.0 "$n(14) setdest 500.0 900.0 10000.0"  
 $ns at 0.0 "$n(15) setdest 700.0 100.0 10000.0"  
 $ns at 0.0 "$n(16) setdest 700.0 300.0 10000.0"  
 $ns at 0.0 "$n(17) setdest 700.0 500.0 10000.0"  
 $ns at 0.0 "$n(18) setdest 700.0 700.0 10000.0"  
 $ns at 0.0 "$n(19) setdest 700.0 900.0 10000.0"  
 $ns at 0.0 "$n(20) setdest 900.0 100.0 10000.0"  
 $ns at 0.0 "$n(21) setdest 900.0 300.0 10000.0"  
 $ns at 0.0 "$n(22) setdest 900.0 500.0 10000.0"  
 $ns at 0.0 "$n(23) setdest 900.0 700.0 10000.0"  
 $ns at 0.0 "$n(24) setdest 900.0 900.0 10000.0"  
 $ns at 0.0 "$n(25) setdest 579.0 425.0 10000.0"  
 $ns at 0.0 "$n(26) setdest 450.0 10.0 10000.0"  
 $ns at 0.0 "$n(27) setdest 999.0 500.0 10000.0"  
 $ns at 0.0 "$n(28) setdest 999.0 700.0 10000.0"  
 $ns at 0.0 "$n(29) setdest 999.0 300.0 10000.0"  
 $ns at 0.0 "$n(30) setdest 749.0 189.0 10000.0"  
 $ns at 0.0 "$n(31) setdest 850.0 300.0 10000.0"  
 $ns at 0.0 "$n(32) setdest 750.0 500.0 10000.0"  
 $ns at 0.0 "$n(33) setdest 550.0 700.0 10000.0"  
 $ns at 0.0 "$n(34) setdest 550.0 900.0 10000.0"  
 $ns at 0.0 "$n(35) setdest 220.1 257.1 10000.0"  
 $ns at 4.4 "$n(35) setdest 51.1 91.1 100.0"  
 $ns at 0.0 "$n(36) setdest 400.0 10.0 10000.0"  
 $ns at 0.0 "$n(37) setdest 649.0 500.0 10000.0"  
 $ns at 0.0 "$n(38) setdest 419.0 610.0 10000.0"  
 $ns at 0.0 "$n(39) setdest 349.0 300.0 10000.0"  
 $ns at 0.0 "$n(40) setdest 150.0 100.0 10000.0"  
 $ns at 0.0 "$n(41) setdest 250.0 400.0 10000.0"  
 $ns at 0.0 "$n(42) setdest 350.0 550.0 10000.0"  
 $ns at 0.0 "$n(43) setdest 450.0 750.0 10000.0"  
 $ns at 0.0 "$n(44) setdest 550.0 950.0 10000.0"  
 $ns at 0.0 "$n(45) setdest 314.1 135.1 10000.0"  
 $ns at 0.0 "$n(46) setdest 550.0 50.0 10000.0"  
 $ns at 0.0 "$n(47) setdest 784.0 372.0 10000.0"  
 $ns at 0.0 "$n(48) setdest 649.0 750.0 10000.0"  
 $ns at 0.0 "$n(49) setdest 749.0 450.0 10000.0"  
 $ns at 0.0 "$n(50) setdest 8.0 186.0 10000.0"  
 $ns at 4.0 "$n(50) setdest 30.0 147.0 100.0"  
 $ns at 3.1 "$n(8) setdest 100.0 500.0 10.0"  
 $ns at 3.1 "$n(9) setdest 100.0 100.0 10.0"  
 $ns at 3.1 "$n(10) setdest 700.0 300.0 10.0"  
 $ns at 3.1 "$n(11) setdest 700.0 500.0 10.0"  
 $ns at 3.1 "$n(12) setdest 500.0 500.0 10.0"  
 $ns at 3.1 "$n(13) setdest 300.0 500.0 10.0"  
 $ns at 3.1 "$n(14) setdest 300.0 700.0 10.0"  
 $ns at 3.1 "$n(15) setdest 700.0 900.0 10.0"  
 $ns at 3.1 "$n(16) setdest 900.0 500.0 10.0"  
 $ns at 3.1 "$n(17) setdest 500.0 700.0 10.0"  
 $ns at 3.1 "$n(18) setdest 500.0 900.0 10.0"  
 $ns at 3.1 "$n(19) setdest 300.0 900.0 10.0"  
 $ns at 3.1 "$n(20) setdest 900.0 700.0 10.0"  
 $ns at 3.1 "$n(21) setdest 900.0 900.0 10.0"  
 $ns at 3.1 "$n(22) setdest 700.0 700.0 10.0"  
 $ns at 3.1 "$n(23) setdest 100.0 900.0 10.0"  
 $ns at 3.1 "$n(24) setdest 100.0 700.0 10.0"  
 $ns at 3.1 "$n(27) setdest 999.0 500.0 10.0"  
 $ns at 3.1 "$n(28) setdest 999.0 700.0 10.0"  
 $ns at 3.1 "$n(29) setdest 999.0 900.0 10.0"  
 $ns at 3.0 "$n(30) setdest 950.0 100.0 10.0"  
 $ns at 3.0 "$n(31) setdest 850.0 300. 10.0"  
 $ns at 3.0 "$n(32) setdest 750.0 500.0 10.0"  
 $ns at 3.0 "$n(33) setdest 550.0 700.0 10.0"  
 $ns at 3.0 "$n(34) setdest 550.0 900.0 10.0"  
 $ns at 3.0 "$n(35) setdest 50.1 0.1 10.0"  
 $ns at 3.0 "$n(36) setdest 400.0 10.0 10.0"  
 $ns at 3.0 "$n(37) setdest 649.0 500.0 10.0"  
 $ns at 3.0 "$n(38) setdest 549.0 700.0 10.0"  
 $ns at 3.0 "$n(39) setdest 349.0 300.0 10.0"  
 $ns at 2.8 "$n(40) setdest 83.0 111.0 100.0"  
 $ns at 3.5 "$n(40) setdest 95.0 67.0 100.0"  
 $ns at 3.0 "$n(41) setdest 250.0 400.0 10.0"  
 $ns at 3.0 "$n(42) setdest 350.0 550.0 10.0"  
 $ns at 3.0 "$n(43) setdest 450.0 750.0 10.0"  
 $ns at 3.0 "$n(44) setdest 550.0 950.0 10.0"  
 $ns at 3.0 "$n(45) setdest 50.1 50.1 10.0"  
 $ns at 3.0 "$n(46) setdest 550.0 50.0 10.0"  
 $ns at 3.0 "$n(47) setdest 849.0 550.0 10.0"  
 $ns at 3.0 "$n(48) setdest 649.0 750.0 10.0"  
 $ns at 3.0 "$n(49) setdest 749.0 450.0 10.0"  
 #--  
 set sink9 [new Agent/LossMonitor]  
 set sink10 [new Agent/LossMonitor]  
 set sink11 [new Agent/LossMonitor]  
 set sink15 [new Agent/LossMonitor]  
 set sink16 [new Agent/LossMonitor]  
 set sink17 [new Agent/LossMonitor]  
 set sink18 [new Agent/LossMonitor]  
 set sink19 [new Agent/LossMonitor]  
 set sink20 [new Agent/LossMonitor]  
 set sink21 [new Agent/LossMonitor]  
 set sink22 [new Agent/LossMonitor]  
 set sink23 [new Agent/LossMonitor]  
 set sink24 [new Agent/LossMonitor]  
 set sink25 [new Agent/LossMonitor]  
 set sink26 [new Agent/LossMonitor]     
 set sink27 [new Agent/LossMonitor]  
 set sink28 [new Agent/LossMonitor]  
 set sink29 [new Agent/LossMonitor]  
 set sink30 [new Agent/LossMonitor]  
 set sink31 [new Agent/LossMonitor]  
 set sink32 [new Agent/LossMonitor]  
 set sink33 [new Agent/LossMonitor]  
 set sink34 [new Agent/LossMonitor]  
 set sink35 [new Agent/LossMonitor]  
 set sink36 [new Agent/LossMonitor]  
 set sink37 [new Agent/LossMonitor]  
 set sink38 [new Agent/LossMonitor]  
 set sink39 [new Agent/LossMonitor]  
 set sink40 [new Agent/LossMonitor]  
 set sink41 [new Agent/LossMonitor]  
 set sink42 [new Agent/LossMonitor]  
 set sink43 [new Agent/LossMonitor]  
 set sink44 [new Agent/LossMonitor]  
 set sink45 [new Agent/LossMonitor]  
 set sink46 [new Agent/LossMonitor]  
 set sink47 [new Agent/LossMonitor]  
 set sink48 [new Agent/LossMonitor]  
 set sink49 [new Agent/LossMonitor]  
 $ns attach-agent $n(0) $sink9  
 $ns attach-agent $n(1) $sink10  
 $ns attach-agent $n(2) $sink11  
 $ns attach-agent $n(6) $sink15  
 $ns attach-agent $n(16) $sink16  
 $ns attach-agent $n(17) $sink17  
 $ns attach-agent $n(18) $sink18  
 $ns attach-agent $n(19) $sink19  
 $ns attach-agent $n(20) $sink20  
 $ns attach-agent $n(21) $sink21  
 $ns attach-agent $n(22) $sink22  
 $ns attach-agent $n(23) $sink23  
 $ns attach-agent $n(24) $sink24  
 $ns attach-agent $n(25) $sink25  
 $ns attach-agent $n(26) $sink26  
 $ns attach-agent $n(27) $sink27  
 $ns attach-agent $n(28) $sink28  
 $ns attach-agent $n(29) $sink29  
 $ns attach-agent $n(30) $sink30  
 $ns attach-agent $n(31) $sink31  
 $ns attach-agent $n(32) $sink32  
 $ns attach-agent $n(33) $sink33  
 $ns attach-agent $n(34) $sink34  
 $ns attach-agent $n(35) $sink35  
 $ns attach-agent $n(36) $sink36  
 $ns attach-agent $n(37) $sink37  
 $ns attach-agent $n(38) $sink38  
 $ns attach-agent $n(39) $sink39  
 $ns attach-agent $n(40) $sink40  
 $ns attach-agent $n(41) $sink41  
 $ns attach-agent $n(42) $sink42  
 $ns attach-agent $n(43) $sink43  
 $ns attach-agent $n(44) $sink44  
 $ns attach-agent $n(45) $sink45  
 $ns attach-agent $n(46) $sink46  
 $ns attach-agent $n(47) $sink47  
 $ns attach-agent $n(48) $sink48  
 $ns attach-agent $n(49) $sink49  
 set tcp9 [new Agent/TCP]  
 $ns attach-agent $n(0) $tcp9  
 set tcp10 [new Agent/TCP]  
 $ns attach-agent $n(1) $tcp10  
 set tcp11 [new Agent/TCP]  
 $ns attach-agent $n(2) $tcp11set tcp15 [new Agent/TCP]  
 $ns attach-agent $n(6) $tcp15  
 set tcp16 [new Agent/TCP]  
 $ns attach-agent $n(16) $tcp16  
 set tcp17 [new Agent/TCP]  
 $ns attach-agent $n(17) $tcp17  
 set tcp18 [new Agent/TCP]  
 $ns attach-agent $n(18) $tcp18  
 set tcp19 [new Agent/TCP]  
 $ns attach-agent $n(19) $tcp19  
 set tcp20 [new Agent/TCP]  
 $ns attach-agent $n(20) $tcp20  
 set tcp21 [new Agent/TCP]  
 $ns attach-agent $n(21) $tcp21  
 set tcp22 [new Agent/TCP]  
 $ns attach-agent $n(22) $tcp22  
 set tcp23 [new Agent/TCP]  
 $ns attach-agent $n(23) $tcp23  
 set tcp24 [new Agent/TCP]  
 $ns attach-agent $n(24) $tcp24  
 set tcp25 [new Agent/TCP]  
 $ns attach-agent $n(25) $tcp25  
 set tcp26 [new Agent/TCP]  
 $ns attach-agent $n(26) $tcp26  
 set tcp27 [new Agent/TCP]  
 $ns attach-agent $n(27) $tcp27  
 set tcp28 [new Agent/TCP]  
 $ns attach-agent $n(28) $tcp28  
 set tcp29 [new Agent/TCP]  
 $ns attach-agent $n(29) $tcp29  
 set tcp30 [new Agent/TCP]  
 $ns attach-agent $n(30) $tcp30  
 set tcp31 [new Agent/TCP]  
 $ns attach-agent $n(31) $tcp31  
 set tcp32 [new Agent/TCP]  
 $ns attach-agent $n(32) $tcp32  
 set tcp33 [new Agent/TCP]  
 $ns attach-agent $n(33) $tcp33  
 set tcp34 [new Agent/TCP]  
 $ns attach-agent $n(34) $tcp34  
 set tcp35 [new Agent/TCP]  
 $ns attach-agent $n(35) $tcp35  
 set tcp36 [new Agent/TCP]  
 $ns attach-agent $n(36) $tcp36  
 set tcp37 [new Agent/TCP]  
 $ns attach-agent $n(37) $tcp37  
 set tcp38 [new Agent/TCP]  
 $ns attach-agent $n(38) $tcp38  
 set tcp39 [new Agent/TCP]  
 $ns attach-agent $n(39) $tcp39  
 set tcp40 [new Agent/TCP]  
 $ns attach-agent $n(40) $tcp40  
 set tcp41 [new Agent/TCP]  
 $ns attach-agent $n(41) $tcp41  
 set tcp42 [new Agent/TCP]  
 $ns attach-agent $n(42) $tcp42  
 set tcp43 [new Agent/TCP]  
 $ns attach-agent $n(43) $tcp43  
 set tcp44 [new Agent/TCP]  
 $ns attach-agent $n(44) $tcp44  
 set tcp45 [new Agent/TCP]  
 $ns attach-agent $n(45) $tcp45  
 set tcp46 [new Agent/TCP]  
 $ns attach-agent $n(46) $tcp46  
 set tcp47 [new Agent/TCP]  
 $ns attach-agent $n(47) $tcp47  
 set tcp48 [new Agent/TCP]  
 $ns attach-agent $n(48) $tcp48  
 set tcp49 [new Agent/TCP]  
 $ns attach-agent $n(49) $tcp49  
 source umts  
 proc attach-CBR-traffic { node sink size interval } {  
   #Get an instance of the simulator  
   set ns [Simulator instance]  
   #Create a CBR agent and attach it to the node  
   set cbr [new Agent/CBR]  
   $ns attach-agent $node $cbr  
   $cbr set packetSize_ $size  
   $cbr set interval_ $interval  
   #Attach CBR source to sink;  
   $ns connect $cbr $sink  
   return $cbr  
  }  
 #======================================================================================  
 set cbr2112 [attach-CBR-traffic $n(0) $sink11 500 .03]  
 set cbr2113 [attach-CBR-traffic $n(14) $sink34 500 .03]  
 set cbr2114 [attach-CBR-traffic $n(44) $sink34 500 .03]  
 set cbr2115 [attach-CBR-traffic $n(17) $sink49 500 .03]  
 set cbr2116 [attach-CBR-traffic $n(32) $sink49 500 .03]  
 set cbr2117 [attach-CBR-traffic $n(31) $sink21 500 .03]  
 set cbr2118 [attach-CBR-traffic $n(29) $sink21 500 .03]  
 set cbr2119 [attach-CBR-traffic $n(47) $sink49 500 .03]  
 set cbr2120 [attach-CBR-traffic $n(36) $sink26 500 .03]  
 set cbr2121 [attach-CBR-traffic $n(46) $sink26 500 .03]  
 set cbr2122 [attach-CBR-traffic $n(30) $sink15 500 .03]  
 set cbr2123 [attach-CBR-traffic $n(20) $sink30 500 .03]  
 set cbr2124 [attach-CBR-traffic $n(42) $sink38 500 .03]  
 set cbr2125 [attach-CBR-traffic $n(13) $sink38 500 .03]  
 set cbr2126 [attach-CBR-traffic $n(41) $sink45 500 .03]  
 $ns at 0.1 "$cbr2112 start"  
 $ns at 0.192 "$cbr2113 start"  
 $ns at 0.167 "$cbr2114 start"  
 $ns at 0.1001 "$cbr2115 start"  
 $ns at 0.155 "$cbr2116 start"  
 $ns at 0.142 "$cbr2117 start"  
 $ns at 0.131 "$cbr2118 start"  
 $ns at 0.121 "$cbr2119 start"  
 $ns at 0.111 "$cbr2120 start"  
 $ns at 0.1911 "$cbr2121 start"  
 $ns at 0.2111 "$cbr2122 start"  
 $ns at 0.241 "$cbr2123 start"  
 $ns at 0.2 "$cbr2124 start"  
 $ns at 0.21 "$cbr2125 start"  
 $ns at 0.241 "$cbr2125 start"  
 #===================================================================================  
 $ns at 0.0 "$ftp0 start"  
 $ns at 16.0 "$ftp0 stop"  
 $ns at 16.401 "finish"  
 puts " Simulation is running ... please wait ..."  
 $ns run  
Outputs and Graphs:














 

Wednesday, 19 February 2014

LTE (Long Term Evaluation ) Network in NS2


Introduction:

LTE is designed for frequency reuse 1 (To maximize spectrum efficiency), which means that all the neighbor cells are using same frequency channels and therefore there is no cell-planning to deal with the interference issues  There is a high probability that a resource block scheduled to cell edge user, is also being transmitted by neighbor cell, resulting in high interference, eventually low throughput or call drops (see figure)  Traffic channel can sustain upto 10% of BLER in low SINR but control channels cannot. Neighbor interference can result in radio link failures at cell edge.  Heterogeneous networks require some sort of interference mitigation, since pico-cells/femto cells and macro-cells are overlapping in many scenarios

LTE in NS2:



---------Steps for patching LTE module in NS-2-------



Step 1:



Download  the LTE patch tk-8.4-lastevent.patch


Step 2:

put the LTE patch in ns-allinone-2.33/tk8.4.18/


Step 3:


cd ns-allinone-2.33/tk8.4.18/


Step 4:

patch -p0 < tk-8.4-lastevent.patch
cd ../


Step 5:

./install


Step 6:

cd ns-2.33/ && mv ns ns233 && make clean && mv Makefile Makefile.org


Step 7:

svn checkout http://lte-model.googlecode.com/svn/trunk/ lte-model-read-only


Step 8:

mkdir project

cd lte-model-read-only/


Step 9:

sh checkin
cd ../


Step 10:

Edit the new Makefile , lines 41, 67, 82 to actual location in ns-allinone-2.33/ns-2.33/ 


Step 11:

    make


TCL Script for LTE network:



 # Define the multicast mechanism  
 set ns [new Simulator -multicast on]  
 # Predefine tracing  
 set f [open out.tr w]  
 $ns trace-all $f  
 #set nf [open out.nam w]  
 #$ns namtrace-all $nf  
 # Set the number of subscribers  
 set number 10  
 # qos_ means whether classfication/scheduling mechanism is used  
 Queue/LTEQueue set qos_ true   
 # flow_control_ is used in the model phase  
 Queue/LTEQueue set flow_control_ false  
 # later HVQ flow control mechanism is used  
 Queue/LTEQueue set HVQ_UE true   
 Queue/LTEQueue set HVQ_eNB false   
 Queue/LTEQueue set HVQ_cell false   
 # Define the LTE topology  
 # UE(i) <--> eNB <--> aGW <--> server  
 # Other configuration parameters see ~ns/tcl/lib/ns-default.tcl  
 # step 1: define the nodes, the order is fixed!!  
 set eNB [$ns node];#node id is 0  
 set aGW [$ns node];#node id is 1  
 set server [$ns node];#node id is 2  
 for { set i 0} {$i<$number} {incr i} {  
  set UE($i) [$ns node];#node id is > 2  
 }  
 # step 2: define the links to connect the nodes  
 for { set i 0} {$i<$number} {incr i} {  
  $ns simplex-link $UE($i) $eNB 10Mb 2ms LTEQueue/ULAirQueue   
  $ns simplex-link $eNB $UE($i) 10Mb 2ms LTEQueue/DLAirQueue   
 }  
 $ns simplex-link $eNB $aGW 1000Mb 2ms LTEQueue/ULS1Queue   
 $ns simplex-link $aGW $eNB 1000Mb 2ms LTEQueue/DLS1Queue   
 # The bandwidth between aGW and server is not the bottleneck.  
 $ns simplex-link $aGW $server 5000Mb 2ms DropTail  
 $ns simplex-link $server $aGW 5000Mb 2ms LTEQueue/DLQueue  
 # step 3: define the traffic, based on TR23.107 QoS concept and architecture  
 #  class id class type simulation application   
 #  -------------------------------------------------  
 #  0: Conversational: Session/RTP/RTPAgent  
 #  1: Streaming: CBR/UdpAgent  
 #  2: Interactive: HTTP/TcpAgent (HTTP/Client, HTTP/Cache, HTTP/Server)  
 #  3: Background: FTP/TcpAgent  
 # step 3.1 define the conversational traffic  
 set mproto DM  
 set mrthandle [$ns mrtproto $mproto {}]  
 for { set i 0} {$i<$number} {incr i} {  
  set s0($i) [new Session/RTP]  
  set s1($i) [new Session/RTP]  
  set group($i) [Node allocaddr]  
  #Adaptive Multi-Rate call bit rates:   
  #AMR: 12.2, 10.2, 7.95, 7.40, 6.70, 5.90, 5.15 and 4.75 kb/s  
  $s0($i) session_bw 12.2kb/s  
  $s1($i) session_bw 12.2kb/s  
  $s0($i) attach-node $UE($i)  
  $s1($i) attach-node $server  
  $ns at 0.4 "$s0($i) join-group $group($i)"  
  $ns at 0.5 "$s0($i) start"  
  $ns at 0.6 "$s0($i) transmit 12.2kb/s"  
  $ns at 0.7 "$s1($i) join-group $group($i)"  
  $ns at 0.8 "$s1($i) start"  
  $ns at 0.9 "$s1($i) transmit 12.2kb/s"  
 }  
 # step 3.2 define the streaming traffic  
 for { set i 0} {$i<$number} {incr i} {  
  set null($i) [new Agent/Null]  
  $ns attach-agent $UE($i) $null($i)  
  set udp($i) [new Agent/UDP]  
  $ns attach-agent $server $udp($i)  
  $ns connect $null($i) $udp($i)  
  $udp($i) set class_ 1  
  set cbr($i) [new Application/Traffic/CBR]  
  $cbr($i) attach-agent $udp($i)  
  $ns at 0.4 "$cbr($i) start"  
  $ns at 40.0 "$cbr($i) stop"  
 }  
 # step 3.3 define the interactive traffic  
 $ns rtproto Session  
 set log [open "http.log" w]  
 # Care must be taken to make sure that every client sees the same set of pages as the servers to which they are attached.  
 set pgp [new PagePool/Math]  
 set tmp [new RandomVariable/Constant] ;# Size generator  
 $tmp set val_ 10240 ;# average page size  
 $pgp ranvar-size $tmp  
 set tmp [new RandomVariable/Exponential] ;# Age generator  
 $tmp set avg_ 4 ;# average page age  
 $pgp ranvar-age $tmp  
 set s [new Http/Server $ns $server]  
 $s set-page-generator $pgp  
 $s log $log  
 set cache [new Http/Cache $ns $aGW]  
 $cache log $log  
 for { set i 0} {$i<$number} {incr i} {  
  set c($i) [new Http/Client $ns $UE($i)]  
  set ctmp($i) [new RandomVariable/Exponential] ;# Poisson process  
  $ctmp($i) set avg_ 1 ;# average request interval  
  $c($i) set-interval-generator $ctmp($i)  
  $c($i) set-page-generator $pgp  
  $c($i) log $log  
 }  
 $ns at 0.4 "start-connection"  
 proc start-connection {} {  
     global ns s cache c number  
  $cache connect $s  
  for { set i 0} {$i<$number} {incr i} {  
      $c($i) connect $cache  
      $c($i) start-session $cache $s  
  }  
 }  
 # step 3.4 define the background traffic  
 # no parameters to be configured by FTP  
 # we can configue TCP and TCPSink parameters here.  
 for { set i 0} {$i<$number} {incr i} {  
  set sink($i) [new Agent/TCPSink]  
  $ns attach-agent $UE($i) $sink($i)  
  set tcp($i) [new Agent/TCP]  
  $ns attach-agent $server $tcp($i)  
  $ns connect $sink($i) $tcp($i)  
  $tcp($i) set class_ 3  
  set ftp($i) [new Application/FTP]  
  $ftp($i) attach-agent $tcp($i)  
  $ns at 0.4 "$ftp($i) start"  
 }  
 # finish tracing  
 $ns at 30 "finish"  
 proc finish {} {  
  global ns f log  
  #global ns f nf log  
  $ns flush-trace  
  flush $log  
  close $log  
  close $f  
  #close $nf  
  #puts "running nam..."  
  #exec nam out.nam &  
  exit 0  
 }  
 # Finally, start the simulation.  
 $ns run  


Outputs:


                                                  Topology Creation:












Data Transmission:








Wednesday, 12 February 2014

Forgery Image Detection (Image Authentication) in Matlab



Introduction:

Nowadays, digital images and video are gradually replacing their conventional analog counterparts .This is quite understandable because digital format is easy to edit, modify, and exploit. Digital images and videos can be readily shared via computer networks and conveniently processed for queries in databases. Also, digital storage does not age or degrade with usage. On the other hand, thanks to powerful editing programs, it is very easy even for an amateur to maliciously modify digital media and create "perfect" forgeries. It is usually much more complicated to tamper with analog tapes and images.

Robust authentication scheme:

here is a scheme to ensure the authenticity of digital images is presented. Their authentication technique is able to detect malicious tamperingof images even if they have been incidentally distorted by common image processingoperations.

Code:


Step 1: (Gaussian window function)
 function [window]=gaussian_window()  
 % gaussian window  
 N_window=7;   % window length  
 sigma=1;      
 [x, y] = meshgrid(-(ceil(sigma*2)):4*sigma/(N_window-1):ceil(sigma*2));  
 window = (1/(2*pi*sigma^2)).*exp(-0.5.*(x.^2+y.^2)./sigma^2);  
 return  

Step 2: (Function to calculate Variance)


 function [var_map] = getVarianceMap(im,Bayer,dim)  
   
 % extend pattern over all image  
   
 pattern = kron(ones(dim(1)/2,dim(2)/2), Bayer);  
   
   
 % separate acquired and interpolate pixels for a 7x7 window  
   
 mask = [1, 0, 1, 0, 1, 0, 1;  
     0, 1, 0, 1, 0, 1, 0;  
     1, 0, 1, 0, 1, 0, 1;  
     0, 1, 0, 1, 0, 1, 0;  
     1, 0, 1, 0, 1, 0, 1;  
     0, 1, 0, 1, 0, 1, 0;  
     1, 0, 1, 0, 1, 0, 1];  
   
 % gaussian window fo mean and variance  
   
 window = gaussian_window().*mask;  
 mc = sum(sum(window));  
 vc = 1 - (sum(sum((window.^2))));  
 window_mean = window./mc;  
   
 % local variance of acquired pixels  
   
 acquired = im.*(pattern);  
 mean_map_acquired = imfilter(acquired,window_mean,'replicate').*pattern;  
 sqmean_map_acquired = imfilter(acquired.^2,window_mean,'replicate').*pattern;  
 var_map_acquired = (sqmean_map_acquired - (mean_map_acquired.^2))/vc;  
   
 % local variance of interpolated pixels  
   
 interpolated = im.*(1-pattern);  
 mean_map_interpolated = imfilter(interpolated,window_mean,'replicate').*(1-pattern);  
 sqmean_map_interpolated = imfilter(interpolated.^2,window_mean,'replicate').*(1-pattern);  
 var_map_interpolated = (sqmean_map_interpolated - (mean_map_interpolated.^2))/vc;  
   
   
 var_map = var_map_acquired + var_map_interpolated;  
   
   
 return  

Step 3: (Output)





Wednesday, 5 February 2014

Face Recognition using Local Sparse Representaion in Matlab



The Below tutorial is regarding Face Recognition  Implementation using Local sparse representation in matlab.


Step 1:


           Create GUI in matlab using the below code.



function varargout = FR_Processed_histogram(varargin)

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @FR_Processed_histogram_OpeningFcn, ...

                   'gui_OutputFcn',  @FR_Processed_histogram_OutputFcn, ...

                   'gui_LayoutFcn',  [] , ...

                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

%--------------------------------------------------------------------------
% --- Executes just before FR_Processed_histogram is made visible.
function FR_Processed_histogram_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FR_Processed_histogram (see VARARGIN)

% Choose default command line output for FR_Processed_histogram
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes FR_Processed_histogram wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;

total_sub = 40;
train_img = 200;
sub_img = 10;
max_hist_level = 256;
bin_num = 9;
form_bin_num = 29;
%--------------------------------------------------------------------------
% --- Outputs from this function are returned to the command line.
function varargout = FR_Processed_histogram_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

%--------------------------------------------------------------------------
% --- Executes on button press in train_button.  
function train_button_Callback(hObject, eventdata, handles)
% hObject    handle to train_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global train_processed_bin;
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;

train_processed_bin(form_bin_num,train_img) = 0;
K = 1;
train_hist_img = zeros(max_hist_level, train_img);

for Z=1:1:total_sub 
  for X=1:2:sub_img    %%%train on odd number of images of each subject
    
    I = imread( strcat('ORL\S',int2str(Z),'\',int2str(X),'.bmp') );        
    [rows cols] = size(I);
    
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               train_hist_img(max_hist_level, K) =  train_hist_img(max_hist_level, K) + 1;                            
           else
               train_hist_img(I(i,j), K) = train_hist_img(I(i,j), K) + 1;                         
           end
       end   
    end   
     K = K + 1;        
  end  
 end  

[r c] = size(train_hist_img);
sum = 0;
for i=1:1:c
    K = 1;
   for j=1:1:r        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + train_hist_img(j,i);            
            train_processed_bin(K,i) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + train_hist_img(j,i);            
        end
    end
    train_processed_bin(K,i) = sum/bin_num;
end

display ('Training Done')
save 'train'  train_processed_bin;

%--------------------------------------------------------------------------
% --- Executes on button press in Testing_button.    
function Testing_button_Callback(hObject, eventdata, handles)
% hObject    handle to Testing_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global train_img max_hist_level bin_num form_bin_num;
global train_processed_bin;
global filename pathname I

load 'train'
test_hist_img(max_hist_level) = 0;
test_processed_bin(form_bin_num) = 0;


 [rows cols] = size(I);
  
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               test_hist_img(max_hist_level) =  test_hist_img(max_hist_level) + 1;                            
           else
               test_hist_img(I(i,j)) = test_hist_img(I(i,j)) + 1;                         
           end
       end   
    end   
    
  [r c] = size(test_hist_img);
  sum = 0;

    K = 1;
    for j=1:1:c        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + test_hist_img(j);            
            test_processed_bin(K) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + test_hist_img(j);            
        end
    end
  
 test_processed_bin(K) = sum/bin_num;
    
sum = 0;
K = 1;

    for y=1:1:train_img
        for z=1:1:form_bin_num        
          sum = sum + abs( test_processed_bin(z) - train_processed_bin(z,y) );  
        end         
        img_bin_hist_sum(K,1) = sum;
        sum = 0;
        K = K + 1;
    end

    [temp M] = min(img_bin_hist_sum);
    M = ceil(M/5);
    getString_start=strfind(pathname,'S');
    getString_start=getString_start(end)+1;
    getString_end=strfind(pathname,'\');
    getString_end=getString_end(end)-1;
    subjectindex=str2num(pathname(getString_start:getString_end));
    if (subjectindex == M)
      axes (handles.axes3)
      %image no: 5 is shown for visualization purpose
      imshow(imread(strcat('ORL\S',num2str(M),'\5.bmp')))    
      msgbox ( 'Correctly Recognized');
    else
     display ([ 'Error==>  Testing Image of Subject >>' num2str(subjectindex) '  matches with the image of subject >> '  num2str(M)])
     axes (handles.axes3)
     %image no: 5 is shown for visualization purpose
     imshow(imread(strcat('ORL\S',num2str(M),'\5.bmp')))    
     msgbox ( 'Recognized');
    end
display('Testing Done')

Step 2:


Run the matlab function and add the database images to path and train the images using train button.




Step 3:


      Now Select the input image button to locate input image.





          

Step 4:




             Click the Testing button to get the recognized images from database.



Note:
          You should download the database before running the code. Instruction to download the database is in the comment section of the file.

Saturday, 1 February 2014

Create Wimax network in ns2 with different Traffic services



Note:

Before Trying this example make sure that your Ns2 works fine with wimax nist Package. 

Step 1:

Create wimax.tcl file and paste the below code into your wimax.tcl



#====================================================
# Test script to evaluate datarate in 802.16 networks.

#check input parameters
if {$argc != 3} {
puts ""
puts "Wrong Number of Arguments! 3 arguments for this script"
puts "Usage: ns datarate.tcl modulation cyclic_prefix "
        puts "modulation: OFDM_BPSK_1_2, OFDM_QPSK_1_2, OFDM_QPSK_3_4"
        puts "            OFDM_16QAM_1_2, OFDM_16QAM_3_4, OFDM_64QAM_2_3, OFDM_64QAM_3_4"
        puts "cyclic_prefix: 0.25, 0.125, 0.0625, 0.03125"
        puts "rtPS scheduler: NIST_RR, RR, mSIR, WRR, TRS_RR, TRS_mSIR"
exit
}

# set global variables
set output_dir .
set traffic_start 20
set traffic_stop  100
set simulation_stop 100

# Configure Wimax
Mac/802_16 set debug_ 0
Mac/802_16 set frame_duration_ 0.020

#define coverage area for base station: 20m coverage
Phy/WirelessPhy/OFDM set g_ [lindex $argv 1]
Phy/WirelessPhy set Pt_ 0.025
Phy/WirelessPhy set RXThresh_ 2.025e-12 ;# 500m radius
Phy/WirelessPhy set CSThresh_ [expr 0.9*[Phy/WirelessPhy set RXThresh_]]

# Parameter for wireless nodes
set opt(chan)           Channel/WirelessChannel    ;# channel type
set opt(prop)           Propagation/TwoRayGround   ;# radio-propagation model
set opt(netif)          Phy/WirelessPhy/OFDM       ;# network interface type
set opt(mac)            Mac/802_16                 ;# MAC type
set opt(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
set opt(ll)             LL                         ;# link layer type
set opt(ant)            Antenna/OmniAntenna        ;# antenna model
set opt(ifqlen)         50                 ;# max packet in ifq
set opt(adhocRouting)   DSDV                       ;# routing protocol

set opt(x) 1100   ;# X dimension of the topography
set opt(y) 1100   ;# Y dimension of the topography

#defines function for flushing and closing files
proc finish {} {
        global ns tf output_dir nb_mn
        $ns flush-trace
        close $tf
exit 0
}

#create the simulator
set ns [new Simulator]
$ns use-newtrace

#create the topography
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
#puts "Topology created"

#open file for trace
set tf [open $output_dir/8MN_out.res w]
$ns trace-all $tf
#puts "Output file configured"

# set up for hierarchical routing (needed for routing over a basestation)
$ns node-config -addressType hierarchical
AddrParams set domain_num_ 2           ;# domain number
lappend cluster_num 1 1             ;# cluster number for each domain
AddrParams set cluster_num_ $cluster_num
#lappend eilastlevel 1 2  ;# number of nodes for each cluster (1 for sink and one for MS + BS
lappend eilastlevel 1 29

AddrParams set nodes_num_ $eilastlevel
puts "Configuration of hierarchical addressing done"

# Create God
create-god 30

#creates the sink node in first address space.
set sinkNode [$ns node 0.0.0]
puts "sink node created"

#creates the Access Point (Base station)
$ns node-config -adhocRouting $opt(adhocRouting) \
                 -llType $opt(ll) \
                 -macType $opt(mac) \
                 -ifqType $opt(ifq) \
                 -ifqLen $opt(ifqlen) \
                 -antType $opt(ant) \
                 -propType $opt(prop)    \
                 -phyType $opt(netif) \
                 -channel [new $opt(chan)] \
                 -topoInstance $topo \
                 -wiredRouting ON \
                 -agentTrace OFF \
                 -routerTrace OFF \
                 -macTrace ON  \
                 -movementTrace OFF

#puts "Configuration of base station"

set bstation [$ns node 1.0.0]
$bstation random-motion 0
#provide some co-ord (fixed) to base station node
$bstation set X_ 550.0
$bstation set Y_ 550.0
$bstation set Z_ 0.0
set clas [new SDUClassifier/Dest]
[$bstation set mac_(0)] add-classifier $clas


#set the scheduler for the node. Must be changed to -shed [new $opt(sched)]
set bs_sched [new WimaxScheduler/BS]
$bs_sched set-default-modulation [lindex $argv 0]     ;#OFDM_BPSK_1_2
[$bstation set mac_(0)] set-scheduler $bs_sched
[$bstation set mac_(0)] set-channel 0
puts "Base-Station node created"


# create the link between sink node and base station
$ns duplex-link $sinkNode $bstation 100Mb 1ms DropTail
######################


########################################################

#set the bumber of UGS connections
set nb_UGS 5

#### interval_ of the CBR traffic ####
set interval_ugs(1) 0.15
set interval_ugs(2) 0.2
set interval_ugs(3) 0.25
set interval_ugs(4) 0.27
set interval_ugs(5) 0.3

set interval_ugs(6) 0.04
set interval_ugs(7) 0.05
set interval_ugs(8) 0.1
set interval_ugs(9) 0.1
######################################


#### SNR of the UGS connections#########
set SNR_ugs(1) 9.5
set SNR_ugs(2) 12.5
set SNR_ugs(3) 16.5
set SNR_ugs(4) 20.5
set SNR_ugs(5) 22.5

set SNR_ugs(6) 12.5
set SNR_ugs(7) 12.5
set SNR_ugs(8) 12.5
set SNR_ugs(9) 12.5
########################################

$ns node-config -wiredRouting OFF \
                -macTrace ON   ;# Mobile nodes cannot do routing.

for {set j 1} {$j < [expr $nb_UGS + 1]} {incr j} {
set wl_node_ugs($j) [$ns node 1.0.[expr $j]] ;# create the node with given @.

$wl_node_ugs($j) random-motion 0 ;# disable random motion
$wl_node_ugs($j) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
#compute position of the node
$wl_node_ugs($j) set X_ [expr 450 + 5 * $j]
$wl_node_ugs($j) set Y_ [expr 450]
$wl_node_ugs($j) set Z_ 0.0

#puts "wireless node $j created"

set clas [new SDUClassifier/Dest]
[$wl_node_ugs($j) set mac_(0)] add-classifier $clas
#set the scheduler for the node. Must be changed to -shed [new $opt(sched)]
set ss_sched [new WimaxScheduler/SS]
[$wl_node_ugs($j) set mac_(0)] set-scheduler $ss_sched
[$wl_node_ugs($j) set mac_(0)] set-channel 0


#Create a UDP agent and attach it to wl_node$j
set udp_ugs($j) [new Agent/UDP]
$udp_ugs($j) set packetSize_ 1000
$ns attach-agent $wl_node_ugs($j) $udp_ugs($j)


# Create a CBR traffic source and attach it to udp4
set cbr_ugs($j) [new Application/Traffic/CBR]
$cbr_ugs($j) set packetSize_ 1000
$cbr_ugs($j) set interval_ $interval_ugs($j)
$cbr_ugs($j) attach-agent $udp_ugs($j)

# Create the Null agent to sink traffic
set null_ugs($j) [new Agent/Null]
$ns attach-agent $sinkNode $null_ugs($j)

# Attach the 2 agents
$ns connect $udp_ugs($j) $null_ugs($j)
$udp_ugs($j) set fid_ $j


## add-flow TrafficPriority MaximumSustainedTrafficRate MinimumReservedTrafficRate ServiceFlowSchedulingType
##ServiceFlowSchedulingType: 0=>SERVICE_UGS, 1=>SERVICE_rtPS, 2=>SERVICE_nrtPS, 3=>SERVICE_BE
$ss_sched add-flow 5 [expr 30 + [$cbr_ugs($j) set packetSize_] * [Mac/802_16 set frame_duration_] / [$cbr_ugs($j) set interval_]] 0 0

##set-PeerNode-SNR PeerNode SNR
$ns at 1.5 "$bs_sched set-PeerNode-SNR [expr $j] $SNR_ugs($j)"

##set-PeerNode-UGSPeriodicity PeerNode Periodicity (periodicity of the reservation, every k frames)
$ns at 1.5 "$bs_sched set-PeerNode-UGSPeriodicity [expr $j] 1"

#Schedule start/stop of traffic
$ns at $traffic_start "$cbr_ugs($j) start"
$ns at $traffic_stop "$cbr_ugs($j) stop"

}
####################

################################################
## rtPS connections
# The identity of the first rtPS connection is k, the second is k+1, and so on
set first_rtPS 101

#set the bumber of rtPS connections
set nb_rtPS 9


#set the number of symbols reserved for unicast request opportunities
$bs_sched set-SymbolNumberForUnicastRequest 3


set rtPS_scheduler_ [lindex $argv 2]

#bs_sched set-rtPSscheduling scheduling
$bs_sched set-rtPSscheduling $rtPS_scheduler_


proc send_next_packet_VBR {udp_ size_ interval_} {
  global ns traffic_stop
$udp_ send [expr round([$size_ value])]
#$udp_ send 1000 # constant if CBR

if {[$ns now] < [expr $traffic_stop - $interval_]} {
  $ns at [expr [$ns now] + $interval_] "send_next_packet_VBR $udp_ $size_ $interval_"
}

}


# seed the default RNG
global defaultRNG
$defaultRNG seed 9999

#### interval_ ########
set interval_rtPS(1) 0.01
set interval_rtPS(2) 0.04
set interval_rtPS(3) 0.05
set interval_rtPS(4) 0.02
set interval_rtPS(5) 0.05
set interval_rtPS(6) 0.04
set interval_rtPS(7) 0.03
set interval_rtPS(8) 0.02
set interval_rtPS(9) 0.03
#######################


#### SNR ############
set SNR_rtPS(1) 7.0
set SNR_rtPS(2) 7.5
set SNR_rtPS(3) 9.0
set SNR_rtPS(4) 12.0
set SNR_rtPS(5) 17.0
set SNR_rtPS(6) 17.5
set SNR_rtPS(7) 20.0
set SNR_rtPS(8) 24.0
set SNR_rtPS(9) 25.5
#####################
#### WRR ########################
# set the weights if using WRR
if {$rtPS_scheduler_ == "WRR"} {
set WRR_rtPS(1) 1
set WRR_rtPS(2) 1
set WRR_rtPS(3) 1
set WRR_rtPS(4) 2
set WRR_rtPS(5) 2
set WRR_rtPS(6) 3
set WRR_rtPS(7) 3

set WRR_rtPS(8) 4
set WRR_rtPS(9) 4
}
##################################

##################
#set-TRSparameters-SNR-Tr-Tp-L SNRth Tr Tp L
$bs_sched set-TRSparameters-SNR-Tr-Tp-L 8.5 2 3 4
##################

$ns node-config -wiredRouting OFF \
                -macTrace ON   ;# Mobile nodes cannot do routing.

for {set j $first_rtPS} {$j < [expr $first_rtPS + $nb_rtPS]} {incr j} {
set wl_node_rtPS($j) [$ns node 1.0.[expr $nb_UGS + $j + 1 - $first_rtPS]] ;# create the node with given @.

$wl_node_rtPS($j) random-motion 0 ;# disable random motion
$wl_node_rtPS($j) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
#compute position of the node
$wl_node_rtPS($j) set X_ [expr 550 + 5 * [expr $j + 1 - $first_rtPS]]
$wl_node_rtPS($j) set Y_ [expr 650]
$wl_node_rtPS($j) set Z_ 0.0

#puts "wireless node $j created"

set clas [new SDUClassifier/Dest]
[$wl_node_rtPS($j) set mac_(0)] add-classifier $clas
#set the scheduler for the node. Must be changed to -shed [new $opt(sched)]
set ss_sched [new WimaxScheduler/SS]
[$wl_node_rtPS($j) set mac_(0)] set-scheduler $ss_sched
[$wl_node_rtPS($j) set mac_(0)] set-channel 0


#Create a UDP agent and attach it to wl_node$j
set udp_rtPS($j) [new Agent/UDP]
$ns attach-agent $wl_node_rtPS($j) $udp_rtPS($j)

# Create the Null agent to sink traffic
set null_rtPS($j) [new Agent/Null]
$ns attach-agent $sinkNode $null_rtPS($j)

# Attach the 2 agents
$ns connect $udp_rtPS($j) $null_rtPS($j)
$udp_rtPS($j) set fid_ $j

set interval_rtPS($j) $interval_rtPS([expr $j + 1 - $first_rtPS])


## exponential distribution
#set sizeRNG_rtPS($j) [new RNG]

#set size_rtPS($j) [new RandomVariable/Exponential]
#$size_rtPS($j) set avg_ 1000
#$size_rtPS($j) use-rng $sizeRNG_rtPS($j)

# uniform distribution
set sizeRNG_rtPS($j) [new RNG]

set size_rtPS($j) [new RandomVariable/Uniform]
$size_rtPS($j) set min_ 500
$size_rtPS($j) set max_ 1500
$size_rtPS($j) use-rng $sizeRNG_rtPS($j)


## add-flow TrafficPriority MaximumSustainedTrafficRate MinimumReservedTrafficRate ServiceFlowSchedulingType
##ServiceFlowSchedulingType: 0=>SERVICE_UGS, 1=>SERVICE_rtPS, 2=>SERVICE_nrtPS, 3=>SERVICE_BE
$ss_sched add-flow 5 0 0 1

##set-PeerNode-SNR PeerNode SNR
$ns at 1.5 "$bs_sched set-PeerNode-SNR [expr $nb_UGS + $j + 1 - $first_rtPS] $SNR_rtPS([expr $j + 1 - $first_rtPS])"

##set-PeerNode-UnicastRequestPeriodicity PeerNode Periodicity
$ns at 1.5 "$bs_sched set-PeerNode-UnicastRequestPeriodicity [expr $nb_UGS + $j + 1 - $first_rtPS] 2"


if {$rtPS_scheduler_ == "WRR"} {
  # set-PeerNode-WRRschedulingForrtPS PeerNode Weight
  $ns at 1.5 "$bs_sched set-PeerNode-WRRschedulingForrtPS [expr $nb_UGS + $j + 1 - $first_rtPS] $WRR_rtPS([expr $j + 1 - $first_rtPS])"
}



$ns at [expr 15.0 + [expr $j + 1 - $first_rtPS] * 0] "send_next_packet_VBR $udp_rtPS($j) $size_rtPS($j) $interval_rtPS($j)"

#puts "n[expr $nb_UGS + $j + 1 - $first_rtPS] starts at [expr 15.0 + [expr $j + 1 - $first_rtPS] * 0]"

}


####################################################################
set first_BE 301

$ns node-config -wiredRouting OFF \
                -macTrace ON   ;# Mobile nodes cannot do routing.

set wl_node_BE($first_BE) [$ns node 1.0.[expr $nb_UGS + $nb_rtPS + 1]] ;# create the node with given @.
$wl_node_BE($first_BE) random-motion 0 ;# disable random motion
$wl_node_BE($first_BE) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
#compute position of the node
$wl_node_BE($first_BE) set X_ 559.0
$wl_node_BE($first_BE) set Y_ 617.0
$wl_node_BE($first_BE) set Z_ 0.0

puts "wireless node _BE $first_BE created"

set clas [new SDUClassifier/Dest]
[$wl_node_BE($first_BE) set mac_(0)] add-classifier $clas
#set the scheduler for the node. Must be changed to -shed [new $opt(sched)]
set ss_sched [new WimaxScheduler/SS]
[$wl_node_BE($first_BE) set mac_(0)] set-scheduler $ss_sched
[$wl_node_BE($first_BE) set mac_(0)] set-channel 0


##set-PeerNode-SNR PeerNode SNR
$ns at 1.3 "$bs_sched set-PeerNode-SNR [expr $nb_UGS + $nb_rtPS + 1] 12.3"

##set-BwRequestSendingPeriod BwRequestSendingPeriod_
$ss_sched set-BwRequestSendingPeriod 10

## add-flow TrafficPriority MaximumSustainedTrafficRate MinimumReservedTrafficRate ServiceFlowSchedulingType
##ServiceFlowSchedulingType: 0 => SERVICE_UGS, 1 => SERVICE_rtPS, 2 => SERVICE_nrtPS, 3 => SERVICE_BE
$ss_sched add-flow 1 0 0 3

#set data_to_send_BE($first_BE) 30000
#$ns at $traffic_start "$ss_sched set-BandwidthBEconnections $data_to_send_BE($first_BE)"
#$ns at $traffic_start "uplink_ftp_tcp_data $wl_node_BE($first_BE) $first_BE $data_to_send_BE($first_BE)"

$ns at 13.0 "uplink_ftp_tcp $wl_node_BE($first_BE) $first_BE"
#################################################################################

####################################################################
$ns node-config -wiredRouting OFF \
                -macTrace ON   ;# Mobile nodes cannot do routing.

set wl_node_BE([expr $first_BE + 1]) [$ns node 1.0.[expr $nb_UGS + $nb_rtPS + 2]] ;# create the node with given @.
$wl_node_BE([expr $first_BE + 1]) random-motion 0 ;# disable random motion
$wl_node_BE([expr $first_BE + 1]) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
#compute position of the node
$wl_node_BE([expr $first_BE + 1]) set X_ 465.0
$wl_node_BE([expr $first_BE + 1]) set Y_ 523.0
$wl_node_BE([expr $first_BE + 1]) set Z_ 0.0

puts "wireless node [expr $first_BE + 1] created"

set clas [new SDUClassifier/Dest]
[$wl_node_BE([expr $first_BE + 1]) set mac_(0)] add-classifier $clas
#set the scheduler for the node. Must be changed to -shed [new $opt(sched)]
set ss_sched [new WimaxScheduler/SS]
[$wl_node_BE([expr $first_BE + 1]) set mac_(0)] set-scheduler $ss_sched
[$wl_node_BE([expr $first_BE + 1]) set mac_(0)] set-channel 0


##set-PeerNode-SNR PeerNode SNR
$ns at 1.3 "$bs_sched set-PeerNode-SNR [expr $nb_UGS + $nb_rtPS + 2] 12.32"

##set-BwRequestSendingPeriod BwRequestSendingPeriod_
$ss_sched set-BwRequestSendingPeriod 10

## add-flow TrafficPriority MaximumSustainedTrafficRate MinimumReservedTrafficRate ServiceFlowSchedulingType
##ServiceFlowSchedulingType: 0 => SERVICE_UGS, 1 => SERVICE_rtPS, 2 => SERVICE_nrtPS, 3 => SERVICE_BE
$ss_sched add-flow 1 0 0 3

#set data_to_send_BE([expr $first_BE + 1]) 30000
#$ns at $traffic_start "uplink_ftp_tcp_data $wl_node_BE([expr $first_BE + 1]) [expr $first_BE + 1] $data_to_send_BE([expr $first_BE + 1])"

$ns at 13.0 "uplink_ftp_tcp $wl_node_BE([expr $first_BE + 1]) [expr $first_BE + 1]"
#################################################################################

proc uplink_ftp_tcp_data {wl_node fid data_to_send} {
global ns sinkNode
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $wl_node $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $sinkNode $sink
$ns connect $tcp $sink
$tcp set fid_ $fid
$tcp set packetSize_ 1000

#setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ftp set packetSize_ 1000

$ftp send $data_to_send
}



proc uplink_ftp_tcp {wl_node fid} {
global ns sinkNode
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $wl_node $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $sinkNode $sink
$ns connect $tcp $sink
$tcp set fid_ $fid
$tcp set packetSize_ 1000

#setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ftp set packetSize_ 1000

$ftp start
}

################procedure : Record ####################
set f0 [open 1_out.tr w]

proc record {} {
global f0 cbr
set ns [Simulator instance]
set time 0.05
set now [$ns now]
set packetSize [$cbr set packetSize_]
set rate [$cbr set rate_]
set seqno [$cbr set seqno_]
puts $f0 "$now paketSize $packetSize rate $rate seqno $seqno"
$ns at [expr $now + $time] "record"
}

##$ns at $traffic_start "record"
########################################################
$ns at $simulation_stop "finish"
puts "Starts simulation"
$ns run
puts "Simulation done."

#=============================================
Step 2:

Execute nam out.nam from your terminal window to see output.

The outputs like below,

                                     
                                             The Terminal output:


                                          The Trace File output is:





The Nam Output is: