[ns] Why NAM doesn't dispaly the packet dropped because of collision?

2007-07-21 Thread Huang Wei

Hi all,

I've been doing wireless simulations these days. I want to show NAM to my
colleagues to help them to better know about how RTS/CTS reduce the chance
of collisions. But I found NAM doesn't display the packet dropped because of
collisions. Why? Here is a line of the trace file and the NAM trace file for
a packet dropped because of collision:

Trace File Info:
d -t 2.267517062 -Hs 2 -Hd -2 -Ni 2 -Nx 700.00 -Ny 200.00 -Nz 0.00 -Ne
-1.00 -Nl MAC -Nw COL -Ma 5fe -Md 2 -Ms 0 -Mt 0

NAM Trace File Info:
d -t 2.267517062 -s 2 -d -1 -p RTS -e 44 -c 2 -a 0 -i 0 -k MAC

Why doesn't NAM display this dropping action?


And to be specific, following is my TCL scripts.

set opt(RTS) 1
set opt(Time) 20

# ==
# Default Script valions
# ==

set val(chan)   Channel/WirelessChannel;#Channel Type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation
model
set val(netif)  Phy/WirelessPhy;# network interface type
set val(mac)Mac/802_11 ;# 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) 50 ;# max packet in ifq
set val(nn) 3  ;# number of mobilenodes
set val(rp) DSDV   ;# routing protocol
#set val(rp)DSR   ;# routing protocol
set val(x)  1000
set val(y)  500
set val(stoptime) $opt(Time)

# ==

# Initialize Global Variables
set ns_ [new Simulator]


$ns_ use-newtrace

if {!$opt(RTS)} {
#set RTSThreshold_ to 3000(Larger than any packet size of up level),
so RTS wolud never be sent.
Mac/802_11 set RTSThreshold_  3000   ;# bytes
puts Mac/802_11 RTSThreshold_: [Mac/802_11 set RTSThreshold_],
RTS/CTS is turned off
set tracefd [open col-hidden.tr w]
set namtrace [open col-hidden.nam w]
} else {
set tracefd [open rts-hidden.tr w]
set namtrace [open rts-hidden.nam w]
}

$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
create-god $val(nn)

# New API to config node: 
# 1. Create channel (or multiple-channels);
# 2. Specify channel in node-config (instead of channelType);
# 3. Create nodes for simulations.

# Create channel #1 and #2
set chan_1_ [new $val(chan)]
set chan_2_ [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_ 

set node_(0) [$ns_ node]
set node_(1) [$ns_ node]
set node_(2) [$ns_ node]

$node_(0) random-motion 0
$node_(1) random-motion 0
$node_(2) random-motion 0

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

$node_(0) set X_ 500.0
$node_(0) set Y_ 200.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 300.0
$node_(1) set Y_ 200.0
$node_(1) set Z_ 0.0
$node_(1) label hidden_to_node2

$node_(2) set X_ 700.0
$node_(2) set Y_ 200.0
$node_(2) set Z_ 0.0
$node_(2) label hidden_to_node1



for {set i 0} {$i  $val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 30
}

# Setup traffic flow between nodes 0 and 1
# TCP connections between node_(0) and node_(1)

set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(1) $tcp1
$ns_ attach-agent $node_(0) $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at 0.1 $ftp1 start 


# Setup traffic flow between nodes 0 and 2
# udp connections between node_(0) and node_(2)
#set udp [new Agent/UDP]
#set null [new Agent/Null]
#$ns_ attach-agent $node_(2) $udp
#$ns_ attach-agent $node_(0) $null
#$ns_ connect $udp $null
#set cbr [new Application/Traffic/CBR]
#$cbr attach-agent $udp
#$ns_ at 0.1 $cbr start 

set tcp2 [new Agent/TCP]
$tcp2 set class_ 2
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $node_(2) $tcp2
$ns_ attach-agent $node_(0) $sink2
$ns_ connect $tcp2 $sink2
set ftp2 

[ns] How does agent's target_ got initialized?

2006-12-25 Thread Huang Wei

Hi, all. Wish everyone a merry Christmas and a happy new year!

I was going through the source code of ns and got confused when I wanted to
find out how 'target_' of class agent, which is derived from class
connector, gets initialized? I know in Connector::command(), command
target is defined to do so. But where does this got invoked?
In function simulator's attach-agent{}, it calls node's attach{}. But in
attach target command is not invoked. Finally I find the target_ was
initialized after invoking Node's function:add-target { agent port }. But,
how? 
I don't understand the code of this function:

Node instproc add-target { agent port } {
$self instvar ptnotif_
# Replaces the following line from old ns (2.1b7 and earlier)
#   $self add-target $agent $port
foreach m [$self set ptnotif_] {
$m attach $agent $port
}
}

It seems that the expression $m attach $agent $port does not invoke the
function Node instproc attach { agent { port  } }(Because I got it to
print information and if it is called it will print). What is this attach?
And how is target_ of agent finally got initialized?

Thanks.

HuangWei




[ns] How can I get the link object?

2006-11-24 Thread Huang Wei

Hello, everyone.

I first set up two nodes and a duplex link between them, and I want to get the 
link object using this script:
-
#Create 2 nodes
for {set i 1} {$i3} {incr i} {
set n([expr $i]) [$ns node]
}

#Create a duplex link between the nodes
$ns duplex-link $n(1) $n(2) 1Mb 10ms SynDropTail

#Get the queue object and do configuration
set thelink [$ns get-link $n(1) $n(2)]
-
But I got those errors:

error get-node-id-by-addr:Cannot find node with given address
(procedure _o3 line 10)
(Simulator get-node-id-by-addr line 10)
invoked from within
$self get-node-id-by-addr $addr
(procedure _o3 line 4)
(Simulator get-link line 4)
invoked from within
$ns get-link $n(1) $n(2)
invoked from within
set thelink [$ns get-link $n(1) $n(2)]
(file c2.tcl line 30)

WHY???
Somebody tell me why, please!
Thanks a lot!

HuangWei

[ns] How Connector::drop_ initialized?

2006-11-23 Thread Huang Wei

Hi, all.

We know in function Connector::drop(Packet* p), if drop_ is not zero then it 
will pass the packet to the object using drop_-recv(p).
I set up a simple simulation and I have not do any initialization to the drop_. 
But I use printf in Connector::drop(Packet* p). The result shows that drop_ is 
not zero. Why? 
I want to know where and when it was initialized? And which NSObject does it 
point to?
Thanks a lot!

HuangWei
BUPT PRC