logo_imenetwork

RFID module for ns-2 simulator

Rafael Perazzo Barbosa Mota

perazzo at ime,usp,br

Last update: 20/02/2014


HOME


DOCUMENTATION


Setting nodes parameters

set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model: TwoRayGround/FreeSpace
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 1000 ;# max packet in ifq
set val(nn) [lindex $argv 1] ;# number of mobilenodes
set val(rp) DumbAgent ;# routing protocol
#set val(rp) DSDV ;# routing protocol
set val(x) 30 ;# X dimension of topography
set val(y) 30 ;# Y dimension of topography
set val(stop) 60 ;# time of simulation end

set ns [new Simulator]
set tracefd [open [lindex $argv 0] w]
#set namtrace [open rfid.nam w]

#Signal Power (5m)
$val(netif) set Pt_ 0.28
$val(netif) set RXThresh_ 7.64097e-06

$ns use-newtrace
$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)

#create-god $val(nn)
create-god [expr $val(nn)]

set chan_1_ [new $val(chan)]

# configure the nodes
$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 OFF \
-macTrace OFF \
-movementTrace OFF

Setting node positions

for {set i 0} {$i < $val(nn) } { incr i } {
    set n($i) [$ns node]
}

# Provide initial location of mobilenodes..
$n(0) set X_ 10
$n(0) set Y_ 10
$n(0) set Z_ 0.0

#RAMDOM TAGS LOCATION
set rng1 [new RNG]
$rng1 seed 0
set rng2 [new RNG]
$rng2 seed 0

set rng3 [new RNG]
$rng3 seed 0

#puts "[$rng2 uniform 0 20]"
#puts "[$rng3 uniform 10 1000]"
for {set i 1} {$i < $val(nn) } { incr i } {
      $n($i) set X_ [$rng1 uniform 8 12]
      $n($i) set Y_ [$rng2 uniform 8 12]
      #puts "[$rng2 uniform 0 20]"
      $n($i) set Z_ 0.0
}

Creating the Agents

#defining heads
$ns at 0.0 "$n(0) label LEITOR"
#$ns at 0.0 "$n(1) label TAG"

#defining connections
set reader1 [new Agent/RfidReader]
for {set i 1} {$i < $val(nn) } { incr i } {
        set tag($i) [new Agent/RfidTag]
    $tag($i) set tagEPC_ [expr $i*10]
    $tag($i) set time_ 1
    $tag($i) set messages_ 0
    $tag($i) set seed_ [$rng2 uniform 10 1000]
}
#Defining reader parameters
$reader1 set id_ 200 #Reader ID (required)
$reader1 set singularization_ 0 #Deprecated
$reader1 set service_ 2 #2 for Q Algorithm; 3 for Standard DFSA; 4 for NEDFSA (required)
$reader1 set t2_ 0.09 #Time to wait before check collisions (required)
$reader1 set c_ 1 #Q Algorithm constant c: Common values: 0.2, 0.3 , 1. (required)
$reader1 set qValue_ 4 #Initial Q Value or initial Frame Size (required)
$reader1 set Qfp_ 4.0 #Initial Q Value (float point) or initial Frame Size (float point)(required)
$reader1 set estConstant_ 3 #Number of repetitions before stop the estimation procedure
$reader1 set messages_ 0 #0 no debug; 1 debug
$reader1 set estMethod_ 2 #Frame size estimation method (backlog): 0 (lower bound), 1  (Schoute) 2 (Eom-Lee) 3 (2.45) 4 (2.65)
$reader1 set iL_ 4 #Deprecated

#CONNECTION NODES TO AGENTS
for {set i 1} {$i < $val(nn) } { incr i } {
        $ns attach-agent $n($i) $tag($i)
}
$ns attach-agent $n(0) $reader1

#conectando nos
#$ns connect $reader1 $tag1
#$ns connect $reader1 $tag2

for {set i 1} {$i < $val(nn) } { incr i } {
        $ns connect $reader1 $tag($i)
}

Query tags

#standard-query-tags : Q Algorithm
#edfsa-query : Schoute, Lower Bound, Eom-Lee, 2.62, 2.45 (based on estMethod_ above)
#estimation-dfsa-query : NEDFSA
for {set i 0} {$i < $val(stop) } { incr i 101} {
        #$ns at $i "$reader1 standard-query-tags"
    $ns at $i "$reader1 standard-query-tags"
}


Ending simulation

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

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

proc stop {} {
#global ns tracefd namtrace
global ns tracefd
$ns flush-trace
close $tracefd
#close $namtrace
#exec nam rfid.nam &
}
$ns run


View debug messages

Just set the messages_ node propertie  to 1

Ex:
$tag($i) set messages_ 1
$reader1 set messages_ 1
Download full rfid.tcl file


Running the rfid.tcl example

$ ns rfid.tcl rfid.tr 100
(ns <Scenario File> <Trace File> <Number Of Nodes>)

Results

What can you get on trace file ?
The number of used slots, system efficiency, collision slots, idle slots and success slots

$tail -n 1 rfid.tr | awk '{print $25/$19}' #you will see the System Efficiency
$tail -n 1 rfid.tr | awk '{print $19}' #you will see the Total number of used slots

How to run several times to get the mean ?

1) Download this file
2) Extract the file
3) Run: $nohup ./calculate_est.sh 10 100 10 5 &
nohup ./calculate_est.sh <number of initial nodes> <number of final nodes> <step> <number of repetitions>
For example: We ask to simulate an RFID System with 10, 20, 30, ... 100 nodes, repeating for each nodes number 5 times.
You will get as final result a table like this (file results/thr.col.q.4.dat* - this file name can be changed in file results/finish.sh):

Number of nodes Mean (System Efficiency)
Confidence Interval (lower) Confidence Interval (upper) Standard deviation
10



20



30



40



50



60



70



80



90



100



*You will also have the file slots.col.q.4.dat representing the number of used slots instead of the System Efficiency

See an example here.

How to generate a graph using gnuplot ?

1)Download this gnuplot script file here
2) Run: $gnuplot graph.plt
2) See the generated eps files.

Trace format

flag
type
Column (in trace file for awk scripts)
x - For both reader-tag and tag-reader
-/x - Just for tag-reader
x/- Just for reader-tag
x/y - x value for reader-tag and y for tag-reader
Value
s
r
char 1 send
read
-t double 3 time
-Zt int 5 flow type
0 - Reader to tag
1 - Tag to reader
-Zi int 7 Node ID
-Zs int 9 Packet source ID
-Zd int 11 Packet destination ID
-Zc int 13 Command
0 - RC_QUERY
1 - RC_QUERY_ADJUST
2 - RC_QUERY_REPLY
3 - RC_ACK
4 - RC_NAK
5 - TC_REPLY
-Zq int 15 type of service
0 - No service (deprecated)
1 - QoS mechanism (deprecated)
2 - Q algorithm
-Zr double -/17 rng16
Random number generated from Q value (2^Q-1)
-Zv int 17/19 Q value
-Zz int 19/- Frame counter
-Xc int 21/- Collision slot count
-Xi int 23/- Idle slot count
-Xs int 25/- Success slot count
-Ss int 27/- Session number (each new query generates a new session number)


HOME

logo_usp
I would like to thank my advisor Prof. Daniel Macêdo Batista, USP, IME.

Developed by Rafael Perazzo Barbosa Mota (perazzo at ime,usp,br)