© 2009 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
HomeSource Code Network Simulator ► Wireless▼
AWK file for data filettering.

Description:

    The main thing of the program is how much node you have to give that much node only will create. Here different nodes have different color. There is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. Set node_ ($i) [$ns node] is used to create the nodes. Here we set the initial position for the every node by using initial_node_pos. After that $Val (stop) is used to tell to nodes when the simulation ends.Dsr routing protocol were used here. Here we use some procedure, that is pktDeliveryRatio graph,
for RouteOverhead graph, Misbehaviour_NODE graph. Count file is used to filtering the ack packets, forwarded packets, send packets, receving packets, drop packets.

File name: “test.tcl”

## Create a simulator object(nothing but, a scheduler's object)..
      set ns      [new Simulator]

 

## Create a trace file and nam file..
      set tracefd       [open scheme.tr w]
      set namtrace      [open scheme.nam w]   

## Trace the nam and trace details from the main simulation..
      $ns trace-all $tracefd
      $ns namtrace-all-wireless $namtrace $val(x) $val(y)

## set up topography object..
      set topo    [new Topography]

      $topo load_flatgrid $val(x) $val(y)

      set god_ [create-god $val(nn)]

## Color Descriptions..
      $ns color 1 dodgerblue
      $ns color 2 blue
      $ns color 3 cyan
      $ns color 4 green
      $ns color 5 yellow
       
## Setting The Distance Variables..
# For model 'TwoRayGround'
      set dist(5m)  7.69113e-06
      set dist(9m)  2.37381e-06
      set dist(10m) 1.92278e-06
      set dist(11m) 1.58908e-06
      set dist(12m) 1.33527e-06
      set dist(13m) 1.13774e-06
      set dist(14m) 9.81011e-07
      set dist(15m) 8.54570e-07
      set dist(16m) 7.51087e-07
      set dist(20m) 4.80696e-07
      set dist(25m) 3.07645e-07
      set dist(30m) 2.13643e-07
      set dist(35m) 1.56962e-07
      set dist(40m) 1.56962e-10
      set dist(45m) 1.56962e-11
      set dist(50m) 1.20174e-13
      #Phy/WirelessPhy set CSThresh_ $dist(50m)
      #Phy/WirelessPhy set RXThresh_ $dist(50m)

## Setting node config event with set of inputs..
      puts "Node Configuration Started here...\n \
                   -channel $val(chan) \n \
                   -adhocRouting $val(rp) \n \
                   -llType $val(ll) \n \
                   -macType $val(mac) \n \
                   -ifqType $val(ifq) \n \
                   -ifqLen $val(ifqlen) \n \
                   -antType $val(ant) \n \
                   -propType $val(prop) \n \
                   -phyType $val(netif) \n"
                      

        $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) \
                   -channelType $val(chan) \
                   -topoInstance $topo \
                   -agentTrace ON \
                   -routerTrace ON \
                   -macTrace OFF \
                   -movementTrace ON

      

## Creating node objects..               
      for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]     
      }

for {set i 0} {$i < $val(nn)} {incr i} {
      $node_($i) color darkgreen
      $ns at 0.0 "$node_($i) color darkgreen"
      }

## Provide initial location of mobilenodes..
     

      if {$val(nn) >0} {
            for {set i 1} {$i < $val(nn) } { incr i } {
                  set xx [expr rand()*600];#if{$xx<=200} {set xx [expr 350+(rand()*150)]}
                  set yy [expr rand()*500];#if{$yy<=200} {set yy [expr 350+(rand()*150)]}
                  $node_($i) set X_ $xx
                  $node_($i) set Y_ $yy
                  $node_($i) set Z_ 0.0
            }
      }

## set god distance..
      $god_ set-dist 0 1 2
      $god_ set-dist 0 2 2
      $god_ set-dist 0 3 2
      $god_ set-dist 0 4 1
      $god_ set-dist 0 5 2
      $god_ set-dist 1 2 3
      $god_ set-dist 1 3 3
      $god_ set-dist 1 4 2
      $god_ set-dist 1 5 2
      $god_ set-dist 2 3 3
      $god_ set-dist 2 4 2
      $god_ set-dist 2 5 2
      $god_ set-dist 2 6 4
      $god_ set-dist 3 4 2
      $god_ set-dist 3 5 3
      $god_ set-dist 3 6 3
      $god_ set-dist 4 5 2
      $god_ set-dist 4 6 2

## Define node initial position in nam..
      for {set i 0} {$i < $val(nn)} { incr i } {
      # 30 defines the node size for nam..
            $ns initial_node_pos $node_($i) 30
      }

## Set a TCP connection between node_(0) and node_(1)..
$ns at 1.0 "commn"
proc commn {} {
      global ns node_ rootPath
      set now [$ns now]
      set time 0.6
      set time1 1.0
      source "$rootPath/commn2.tcl";$ns at [expr $now+$time1] "commn"

}

## Generation of movements-Destination setting..

      $ns at 0.0 "Mobility"
      proc Mobility {} {
            global ns node_ rootPath val
            set ns_ [Simulator instance]
            set time 1.0
            set moveTime 0.5
            set now [$ns now]
            #source "$rootPath/setdest1.tcl"
            source "$rootPath/setdest.tcl"
      $ns_ at [expr $now+$time] "Mobility"
}

#source "$rootPath/annotate.tcl"

## Telling nodes when the simulation ends..
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset";
}

## Ending nam and the simulation..
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 16.01 "puts \"end simulation\" " ;# $ns halt

## Procedure for pktDeliveryRatio graph..
set PktDelRatio 0.98
set MisBehRatio 0
set pdrgraph [open pdratio(Scheme).tr w]

      $ns at 0.1 "PktDelRatio"
      proc PktDelRatio {} {
            global ns rootPath pdrgraph PktDelRatio MisBehRatio pktdelratio misbehratio
            set ns_ [Simulator instance]
            set time 1.2
            set now [$ns_ now]
            source "$rootPath/PDRatio.tcl"
            if {$now<1.2} {set PktDelRatio 0.98;set MisBehRatio 0}
            if {$now>1.2} {
                  set PktDelRatio [expr $PktDelRatio-$pktdelratio]
                  set MisBehRatio [expr $MisBehRatio+$misbehratio]
            }
            puts $pdrgraph "$MisBehRatio $PktDelRatio"
            $ns_ at [expr $now+$time] "PktDelRatio"
            }

## Procedure for RouteOverhead graph..
set RouteOverhead 0.98
set MisBehRatio 0
set rohgraph [open routeOH(Scheme).tr w]

      $ns at 0.1 "Overhead_Cal"
      proc Overhead_Cal {} {
            global ns rootPath rohgraph RouteOverhead MisBehRatio routeoverhead misbehratio
            set ns_ [Simulator instance]
            set time 1.2
            set now [$ns_ now]
            source "$rootPath/RouteOverHead.tcl"
            if {$now<1.2} {set RouteOverhead 0.01;set MisBehRatio 0}
            if {$now>1.2} {
                  set RouteOverhead [expr $RouteOverhead+$routeoverhead]
                  set MisBehRatio [expr $MisBehRatio+$misbehratio]
            }
            puts $rohgraph "$MisBehRatio $RouteOverhead"
            $ns_ at [expr $now+$time] "Overhead_Cal"
            }

## Procedure for Misbehaviour_NODE graph..
      set pktStatus [open PktStatus.tr w]
      proc misbehaviour_Node {} {
            global ns_
            set time 2.0
            set now [$ns_ now]
            set mon [new Monitor list]
            source "./Analysis_node.tcl"
            set nodeAnalysis_INFO [lindex $args(0) $args(1)]
            puts "The receive and forward packet calculation done here..."
            set pkt_recv_time [lindex $Rtime(0)]
            set pkt_forward_time [lindex $Ftime(1)]
            puts $pktStatus "$time $event"
            set event [lindex $pkt_recv_time $pkt_forward_time]
            ## calculate the misbehaviourness for every node... \
            ## Normally the misbehaviour node omit from the routing list...
            ## Remove route node detection..
            source "./remove_RouteList.tcl"
            if {$remove_RouteList_node(0)==$remove_RouteList_node($6)} {
                  puts $removeList "[lindex $totNodeList $remove_RouteList_node($6)]"
                  }
            if {$remove_RouteList_node(0)==node_(2)} {
                  set selectRouteNode node_($goodBehNode(0))
                  }
            if {$remove_RouteList_node(0)==node_(5)} {
                  set selectRouteNode node_($goodBehNode(0))
                  }
            ## Select the RouteNode list for every this procedure call..
            set selectRouteNode 0
            $ns_ at [expr $now+$time] "misbehaviour_Node"
            }

## Procedure for 2Ack call..
      set ackFile [open AckFile.tr w]
      proc 2Ack_CAL {} {
            global ns_
            set time 2.0
            set now [$ns_ now]
            $self instvar avgTime event
            source "./2Ack_CAL.tcl"
            if {$7=="ack"} {
                  put $ackFile [lindex $2 $7] 2Ack.tr > AckFile.tr
            }
            if {$7!="ack"} {
                  put "It is not Ack field"
            }
      }

## Procedure for Throughput..
set edsrgraph [open Scheme(ThruPut).tr w]
set neutgraph [open Neu.tr w]
set edsr 100
set neux 0
      $ns at 0.0 "ThroughPut"
      proc ThroughPut {} {
            global ns_ rootPath edsr dsr neux edsrgraph neutgraph
            set ns_ [Simulator instance]
            set time 1.5
            set now [$ns_ now]
            source "$rootPath/fig.tcl"
            $ns_ at [expr $now+$time] "ThroughPut"
            }

## Stop procedure..

proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace

## Filtering the ack pkts from total simulation..
      exec grep "ack" "Scheme.tr" > tempack.doc
      #exec grep "0 1 0 800" tempdrop.tr > "$dropPath/drop1.tr"

## Filtering the dropped pkts from total simulation..
      exec grep "^D" "Scheme.tr" > tempdrop.doc
     

## Filtering the forwarded pkts from total simulation..
      exec grep "^f" "Scheme.tr" > tempforward.doc
     
## Filtering the received pkts from total simulation..
      exec grep "^r" "Scheme.tr" > temprxve.doc
     

## Filtering the sent pkts from total simulation..
      exec grep "^s" "Scheme.tr" > tempsend.doc
          exec nam  scheme.nam &
exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y ThruPut edsr(tput).tr &
exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y Total_Drop edsr(drop).tr &
    exit 0
}

$ns run

# rootpath
#commn

set interval 0.1

if {$now>=1.0 && $now<3.0} {
set tcp(1) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(4) 2]
set ftp(1) [$tcp(1) attach-app FTP]
$ftp(1) set packetSize_ 1000 
$ftp(1) set interval_ .05
$ns at $now "$ftp(1) start"
$ns at [expr $now+$time] "$ftp(1) stop"
}

if {$now>=3.0 && $now<4.0} {
set tcp(1) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(5) 2]
set ftp(1) [$tcp(1) attach-app FTP]
$ftp(1) set packetSize_ 1000 
$ftp(1) set interval_ .05
$ns at $now "$ftp(1) start"
$ns at [expr $now+$time] "$ftp(1) stop"

set tcp(2) [$ns create-connection TCP/Newreno $node_(5) TCPSink $node_(4) 2]
set ftp(2) [$tcp(2) attach-app FTP]
$ftp(2) set packetSize_ 1000 
$ftp(2) set interval_ .05
$ns at $now "$ftp(2) start"
$ns at [expr $now+$time] "$ftp(2) stop"

set tcp(3) [$ns create-connection TCP/Newreno $node_(5) TCPSink $node_(4) 2]
set ftp(3) [$tcp(3) attach-app FTP]
$ftp(3) set packetSize_ 1000 
$ftp(3) set interval_ .05
#$ns at $now "$ftp(3) start"
#$ns at [expr $now+$time] "$ftp(3) stop"

set tcp(4) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(4) 2]
set ftp(4) [$tcp(4) attach-app FTP]
$ftp(4) set packetSize_ 1000 
$ftp(4) set interval_ .05
#$ns at $now "$ftp(4) start"
#$ns at [expr $now+$time] "$ftp(4) stop"
}
#anno
$ns at 1.1025 "$ns trace-annotate \"Time: 1.1025 Pkt Transfer Path thru node_(2)..\""
$ns at 1.28 "$ns trace-annotate \"Time: 1.2812 TrustValue Calculation..\""
$ns at 1.28 "$ns trace-annotate \"Time: 1.2812 node_(2) act as misbehaviour..\""

# RouteOverhead
Class RouteOverhead_ -superclass Agent/TCP/Newreno

RouteOverhead_ instproc init {routeOverhead_ misBehRatio_} {
$self instvar routeOverhead
$self instvar misBehRatio
set routeOverhead $routeOverhead_
set misBehRatio $misBehRatio_
}

# fig.tcl

#set edsr 100
#set dsr 90
#set neux 0
     
      if {$now<=6.5} {
            set Aflow [expr rand()*8];if {$Aflow<5} {set Aflow [expr 8+(rand()*3)]}
            #puts "$Aflow [expr $edsr-$Aflow]"
            set edsr [expr $edsr-$Aflow]
            puts $edsrgraph "$now $edsr"
            puts $neutgraph "$now $neux"
      }
# setdest.tcl
$ns at $now "$node_(0) setdest 2.0 145.0 20.0"
      $ns at $now "$node_(1) setdest 94.0 321.0 20.0"
      $ns at $now "$node_(2) setdest 242.0 192.0 20.0"

#### Counting the no of pkts
Filename: count.txt
awk 'BEGIN {print "_________________\nCounting RxvePkts"}'
awk -f "/home/rootpath/count.awk" "/home/tamil/ rootpath /temprxve.doc"
awk 'BEGIN {print "_________________\nCounting ForwardPkts"}'
awk -f "/home/ rootpath /scheme/count.awk" "/home/tamil/ rootpath /tempsend.doc"
awk 'BEGIN {print "_________________\nCounting SendPkts"}'
awk -f "/home/ rootpath /scheme/count.awk" "/home/tamil/ rootpath /tempforward.doc"
awk 'BEGIN {print "_________________\nCounting AckPkts"}'
awk -f "/home/ rootpath /count.awk" "/home/ rootpath /scheme/tempack.doc"

 # How to run
$ ns test.tcl
count.txt

# output

 

 


bottom