[ns] (A naive solution) how to set different transmit range for different node

Phenix phenix_yw at hhu.edu.cn
Mon Jan 5 22:19:17 PST 2009


Hi All,

    After hacking threshold.cc, I've known the formula used to calculate 
receive
threshold (ATTENTION: threshold.cc only generates RXThresh_, NOT Pt_). I 
modified
TwoRayGround formula in threshold.cc, as below :

                     Pr * d^4 * L
          Pt = ---------------------------
                 Gt * Gr * (ht^2 * hr^2)

Pr is replace with RXThresh_ whose value is 3.652e-10.
If a distance is given, Pt can be calculated by above formula.
e.g.
      Tx Range           Pt_
       100m             0.00721383
       150m             0.03652
       200m             0.115421
       250m             0.28179
       300m             0.58432
        ...              ...
I attached modified threshold.cc renamed threshold_Pt.cc .
After compiling it, you can use like this:
./threshold_Pt  -m TwoRayGround <Required TxRange>

But unluckily, if the tx range is smaller than crossover_dist (always should 
be 86.1425m),
the generated Pt_ value is incorrect either using Friis or TwoRay.
If you know why, please let me know.

I've developed a simple tcl script in order to validate transmit range
with different Pt_ value. I attached this script named TxRangeTest.tcl.
The routing protocol used in the script is MFlood, which is just a simple
flooding algorithm. Trace format has been changed a little, like:

     s 1.000000000 1   1.00 200.00 AGT  --- 0 cbr 512  [0 0 0 0] -------  
[1:0 0:0 32 0] [0] 0 0
     r 1.004860003 0   0.00 200.00 AGT  --- 0 MFlood 532 [mflood 1.000000000 
1.00 200.00 ]
  The trace format of cbr packet can be referred to NS2 manual. The explain 
of trace format about
MFlood packet is below:

        event = $1;
	curr_time = $2;
	curr_node_id = $3;
	curr_position_x = $4;
	curr_position_y = $5;
	trace_type = $6;

	pkt_seq = $8;
	pkt_type = $9;
	pkt_generate_time = $12;

	prev_hop_position_x = $13;
	prev_hop_position_y = $14;

   Finally, a AWT file is used to calculate the transmit range.
#========================================================================
BEGIN {
	RecvNum = 0;
	final_curr_position_x = 0;
	final_curr_position_y = 0;

	final_prev_hop_position_x = 0;
	final_prev_hop_position_y = 0;
}

{
	event = $1;
	curr_time = $2;
	curr_node_id = $3;
	curr_position_x = $4;
	curr_position_y = $5;
	trace_type = $6;

	pkt_seq = $8;
	pkt_type = $9;
	pkt_generate_time = $12;

	prev_hop_position_x = $13;
	prev_hop_position_y = $14;

 	if ( event == "r" && curr_node_id == 0 && trace_type == "AGT"  )
	{
    	RecvNum++;
	#	printf(" %3d    [Time : %f]    N0(%.2f,%.2f)  <----  N1(%.2f,%.2f)\n",
	#		   RecvNum,
	#		   curr_time,
	#		   curr_position_x,
	#		   curr_position_y,
	#		   prev_hop_position_x,
	#		   prev_hop_position_y);

		final_curr_position_x = curr_position_x;
		final_curr_position_y = curr_position_y;

		final_prev_hop_position_x = prev_hop_position_x;
		final_prev_hop_position_y = prev_hop_position_y;
	}

}

END{
	dx = final_prev_hop_position_x - final_curr_position_x ;
	dy = final_prev_hop_position_y - final_curr_position_y ;
	tx_range = sqrt(dx * dx + dy * dy) ;

	printf(" \nNum of Recv pkts : %d \n", RecvNum);
	printf(" \nTx Range of Node 1: %f \n", tx_range);
}

This is just a reference. You should do some changes according to
your trace file if you use other routing protocol.

Regards,
Phenix

--------------------------------------------------
From: "kavan sheth" <shethkavan at gmail.com>
Sent: Sunday, January 04, 2009 1:24 PM
To: "Phenix" <phenix_yw at hhu.edu.cn>
Subject: Re: [ns] how to set different transmit range for different node

> Hi Phenix,
>
>   As far as I know threshold.cc generates particular transmission
> power(Pt_) based on the propagation model and distance specified by
> you. different propagation model have different equations for
> receiving power based on its characteristics. different equations are
> given in the threshold.cc. you can know more by studying this
> threshold.cc
>
> Kavan
>
> On 1/3/09, Phenix <phenix_yw at hhu.edu.cn> wrote:
>>
>> Hi Sidney,
>>
>> After times of trials, I've succeeded in letting different nodes own
>> different
>> Tx Range by configuring different value of Pt_ for each node. I get
>> different
>> values of Pt_ from a script:
>>    # The transimssion radio range
>>      Pt_ 6.9872e-4    ;# ?m
>>      Pt_ 8.5872e-4    ;# 40m
>>      Pt_ 1.33826e-3   ;# 50m
>>      Pt_ 7.214e-3     ;# 100m
>>      Pt_ 0.2818       ;# 250m
>>
>> And in my script, I have test range of 250m and 40m. It really works 
>> well.
>> But It's a pity that I don't know how to obtain these values. The tool
>> threshold
>> (~ns/lidep-utils/propagation/threshold.cc) only generate RXThresh_ other
>> than Pt_.
>>
>> Is there somebody knowing how to get value of Pt_?
>>
>>
>> [Here is my test script]
>>
>> # ======================================================================
>> # Define options
>> # ======================================================================
>> set val(ifqlen)         50                         ;# max packet in ifq
>> set val(nn)             2                          ;# number of 
>> mobilenodes
>> set val(rp)            MFlood                      ;# routing
>> protocol,DumbAgent
>> set val(chan)       Channel/WirelessChannel
>> set val(prop)       Propagation/TwoRayGround
>> set val(netif)      Phy/WirelessPhy
>> set val(mac)        Mac/802_11
>> set val(ifq)        Queue/DropTail/PriQueue
>> set val(ll)         LL
>> set val(ant)        Antenna/OmniAntenna
>> set val(stop)     150
>>
>> # Initialize the SharedMedia interface with parameters to make
>> # it work like the 914MHz Lucent WaveLAN DSSS radio interface
>> Phy/WirelessPhy set CPThresh_ 10.0
>> Phy/WirelessPhy set CSThresh_ 1.559e-11
>> Phy/WirelessPhy set RXThresh_ 3.652e-10
>> Phy/WirelessPhy set Rb_ 2*1e6
>> Phy/WirelessPhy set freq_ 914e+6
>> Phy/WirelessPhy set L_ 1.0
>>
>> # Pt_
>> set txpower_(0)  0.2818       ;# 250m
>> set txpower_(1)  8.5872e-4    ;# 40m
>> set txpower_(2)  7.214e-3     ;# 100m
>>
>> # ======================================================================
>> # Main Program
>> # ======================================================================
>>
>> #ns-random 0
>>
>> # Initialize Global Variables
>> set ns_ [new Simulator]
>> set tracefd [open mflood_txRange.tr w]
>> $ns_ trace-all $tracefd
>>
>> set namtrace    [open mflood_txRange.nam w]
>> $ns_ namtrace-all-wireless $namtrace 1000 500
>>
>> # set up topography
>> set topo [new Topography]
>> $topo load_flatgrid 1000 500
>>
>> # Create God
>> create-god $val(nn)
>>
>>
>> # Create the specified number of mobilenodes [$val(nn)] and "attach" them
>> # to the channel.
>> # configure node
>> set channel [new Channel/WirelessChannel]
>> $channel set errorProbability_ 0.0
>>
>>         $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) \
>>     -channel $channel \
>>     -topoInstance $topo \
>>     -agentTrace ON \
>>     -routerTrace OFF\
>>     -macTrace OFF \
>>     -movementTrace OFF
>>
>>  for {set i 0} {$i < $val(nn) } {incr i} {
>>   Phy/WirelessPhy set Pt_ $txpower_($i)
>>   set node_($i) [$ns_ node]
>>   $node_($i) random-motion 0;
>>  }
>>
>> # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
>> #
>> #          N_0 <-- d ---> N_2
>> #          src            dst
>>
>> $node_(0) set X_ 0.0
>> $node_(0) set Y_ 200.0
>> $node_(0) set Z_ 0.0
>>
>> $node_(1) set X_ 1.0
>> $node_(1) set Y_ 200.0
>> $node_(1) set Z_ 0.0
>>
>> $ns_ at 1.5 "$node_(1) setdest 255.0 200.0 2.0"
>>
>> # Define node initial position in nam
>> for {set i 0} {$i < $val(nn)} {incr i} {
>>     $ns_ initial_node_pos $node_($i) 20
>> }
>>
>> set udp_(0) [new Agent/UDP]
>> set udp_(1) [new Agent/UDP]
>> $ns_ attach-agent $node_(0) $udp_(0)
>> $ns_ attach-agent $node_(1) $udp_(1)
>>
>> set null_(0) [new Agent/Null]
>> set null_(1) [new Agent/Null]
>> $ns_ attach-agent $node_(1) $null_(0)
>> $ns_ attach-agent $node_(0) $null_(1)
>>
>> $ns_ connect $udp_(0) $null_(0)
>> $ns_ connect $udp_(1) $null_(1)
>>
>> for {set i 0} {$i < $val(nn)} {incr i} {
>>  set cbr_($i) [new Application/Traffic/CBR]
>>  $cbr_($i) set packetSize_ 512
>>  $cbr_($i) set interval_ 2
>>  $cbr_($i) set random_ 1
>>  $cbr_($i) attach-agent $udp_($i)
>>
>> }
>> $ns_ at 1.0 "$cbr_(0) start"
>> $ns_ at 1.1 "$cbr_(1) start"
>>
>> # Tell nodes when the simulation ends
>> for {set i 0} {$i < $val(nn) } {incr i} {
>>     $ns_ at $val(stop).0 "$node_($i) reset";
>> }
>> $ns_ at $val(stop).0 "stop"
>> $ns_ at $val(stop).01 "puts \"NS EXITING...\" ; $ns_ halt"
>> proc stop {} {
>>     global ns_ tracefd namtrace
>>     $ns_ flush-trace
>>     close $tracefd
>>  close $namtrace
>> }
>>
>> puts "Starting Simulation..."
>> $ns_ run
>>
>>
>>
>>
>> Regards,
>> Phenix
>>
>>
>> From: Sidney Doria
>> Sent: Saturday, January 03, 2009 12:01 AM
>> To: Phenix
>> Subject: Re: [ns] how to set different transmit range for different node
>>
>>
>> Hi Phenix,
>>
>>
>> In the TCL file, there's a loop for node creation. So, you can break this
>> node in a manual creation, each node with specific characteristics.
>>
>>
>> Sidney Doria
>>
>>
>> UFCG / BRAZIL
>>
>>
>> 2009/1/2 Phenix <phenix_yw at hhu.edu.cn>
>>
>>
>>
>>   Hi all,
>>
>>   I'd like how to set different transmit range for different node in 
>> MANET.
>>
>>   eg.
>>    Three nodes,N0,N1 and N2 are in a line:
>>      (N0)             (N1)        (N2)
>>        |---  200m -----| ---120m---|
>>     The transmit range of N0,N1 and N2 is respectively  250m,150m,200m.
>>   So packets can be passed:
>>        N0 --> N1 <---> N2
>>
>>     Let me know how to set different transmit range please.
>>   Thank you in advance!
>>
>>   Regards,
>>   Phenix
>>
>>
>>
>>
>>
>> --
>> Sidney Doria
>> Redes ad hoc móveis
>> Doutorado em Computação
>> UFCG
>> Brasil
>>
>> "Nessa jornada, o conhecimento será o seu escudo..."
>> (Mestre dos Magos no episódio do grimoire de ouro)
>>
> 


More information about the Ns-users mailing list