Sunteți pe pagina 1din 10

M Y W OR KS

CON TA CT M E

Search

NS2 : How to add new routing protocol

Adding new locale to apk files

AD V ER TIS EM ENT CA TEGO R IES

NS2: Getting node position and energy


by E L M O on AP RIL 5 , 2 01 0 55 C O MMENTS

Android Linux / Unix Network Simulator (NS2) Programming

It has been really long time since my last post my and I am back. Finally, I could make little time to write this post. I believe such information is available in elsewhere. But, I also believe explaining simple method of obtaining node position and current remaining energy would help a lot of people. I strongly suggest scanning the code of WFRP before reading the post further. Alright, lets get on the work. First you have to include mobilenode.h (located in NSROOT/ns-2.xx/common/ ) into wfrp.h file. Add following line after #include <cmutrace.h> 1 # i n c l u d e< m o b i l e n o d e . h > We have to make little more modifications to wfrp.h, thus change the lines from 119 to 122 (wfrp.h) as below 1 2 3 4 5 6 / /N o d eL o c a t i o n d o u b l e p o s x ; d o u b l e p o s y ; / /R e m a i n i n gE n e r g y d o u b l e i E n e r g y ; / /p o s i t i o nx ; / /p o s i t i o ny ;

Research Issues Uncategorized


B L OGR O LL

Mobile Embedded System Lab. LifeMap Project Yohan Chon Hyojeong Shin

ME TA

Log in Entries RSS Comments RSS WordPress.org

At line 153 (wfrp.h) add following code 1 2 3 4 5 / /E n e r g yM a n a g e m e n t v o i d u p d a t e _ e n e r g y ( ) ; / /T h i sn o d e ; M o b i l e N o d e * i N o d e ;

Now we are going to update actual node position and energy. Add following code to line 147 of wfrp.cc : 1 2 3 4 5 / / i n i t i a l i z ee n e r g y i E n e r g y=0 ; / /G e tp o i n t e rt ot h en o d e i N o d e=( M o b i l e N o d e* )( N o d e : : g e t _ n o d e _ b y _ a d d r e s s ( i n d e x ) ) ;

In above code g e t _ n o d e _ b y _ a d d r e s s ( n s a d d r _ ti d )is located in $NSROOT/ns2.xx/common/node.h, which obtains pointer to the node according to given address. The class N o d econtains various information about node, including energy model, location, speed, neighbors, etc. Update the wfrp.cc code from the line 530 as below 1 2 3 4 5 6 7 8 v o i d W F R P : : u p d a t e _ p o s i t i o n ( ){ i N o d e > u p d a t e _ p o s i t i o n ( ) ; p o s x=i N o d e > X ( ) ; p o s y=i N o d e > Y ( ) ;

i f d e fD E B U G 9 # 1 0 p r i n t f ( " U( % . 6 f ) :U P D A T EP O S I T I O N ,f o rN o d e% d ,X :% . 4 f a n dY: % . 4 fn " ,C U R R E N T _ T I M E ,i n d e x ,p o s x ,p o s y ) ; 1 1 # e n d i f 1 2 1 3 } 1 4 1 5 v o i d 1 6 W F R P : :u p d a t e _ e n e r g y ( ){ 1 7 i E n e r g y=i N o d e > e n e r g y _ m o d e l ( ) > e n e r g y ( ) ; 1 8 1 9 # i f d e fD E B U G 2 0 p r i n t f ( " U( % . 6 f ) :U P D A T EE N E R G Y ,f o rN o d e% d ,E n e r g y% . 4 fn " , C U R R E N T _ T I M E ,i n d e x ,i E n e r g y ) ; 2 1 # e n d i f 2 2 2 3 } First routine (u p d a t e _ p o s i t i o n ) updates the position at request time and puts X and Y position to posx, posy respectively. Note, i N o d e > u p d a t e _ p o s i t i o n ( )routine is in $NSROOT/ns-2.xx/common/mobilenode.cc. Y ou may also obtain nodes current speed, radio range, and Z position. Second routine (u p d a t e _ e n e r g y ) gets nodes current remaining energy and puts it to iEnergy. For information refer to $NSROOT/ns-2.xx/mobile/energy-model.cc. After completing modification just re-make. For location based routing protocols this might very useful. Leave comments here if you have any problems with the code. Note : energyModel must be set in TCL file, in order to obtain nodes energy or energy model related information.
Tagge d with: Ene rgy location node position NS 2 routing

If you enjoyed this article, please consider sharing it!

55 Responses to ns2: getting node position and energy


scott says:
April 8, 2 01 0 at 5:2 5 pm

so may i know how to i call it from my .tcl file?

smartnode says:
April 9 , 2 01 0 at 1 2 :3 2 am

Call what? clarify your question. Guys, please dont waste my time asking abstract questions. Before posting your comment read it first, can other person understand what you are trying to say. I WILL NEVER ANSWER if your question is NOT EXACT AND CLEAR.

Jayavignesh says:
April 9 , 2 01 0 at 4 :3 1 pm

Thanks for the simple but useful post. I need a clarification to update the energy value of any node if its energy level falls below certain thresholds (66%,33%,10%) of its initial energy value. Updates should not be at periodic intervals but only when it falls below these levels. (P.S i should update only once after it falls below 66% or 33% or 10%) Any suggestions would be of great help!! Thanks & Regards, Jayavignesh

scott says:
April 9 , 2 01 0 at 5:2 0 pm

sorry, i meant: how do i obtain the current energy and position of particular node in my .tcl coding? there must be a function that i can obtain the value to

process.

smartnode says:
April 1 2 , 2 01 0 at 2 :1 2 am

Jayavignesh, you have no option but to use timer. Check beacon timer implementation in WFRP. Scott i donno how to do that. And why would you need that. Daywalker you have to read the post carefully. You are just wastingmy time. My code has no error. Probably, you havent included proper files.

daywalker says:
April 1 2 , 2 01 0 at 1 1 :00 am

Hi i am getting following error after changes.Sir please guide me wfrp/wfrp.cc: In constructor

daywalker says:
April 1 2 , 2 01 0 at 1 1 :01 am

HiI am unable to generate simulation using nam files of your protocolcan u guide?

ranganath says:
April 1 7 , 2 01 0 at 3 :3 9 am

how to give different energy for the nodes in ns2. like node one has energy 1000 and node2 has 500 give me syntax in ns2.

aparna says:
April 1 8, 2 01 0 at 2 :4 5 pm

Hello.., Your code for

smartnode says:
April 1 9 , 2 01 0 at 6 :1 7 pm

Aparna, I am not owner of the code. Why dont you ask your question original author? I havent tried that Guys, dont ask me about codes of other people (if it is not NS2 source tree). I am not able to make time to review their code answer your question.

Neeraj says:
April 2 2 , 2 01 0 at 9 :51 am

where is wfrp.cc or wfrp.h located in ns2. i am using ns-2.30 simulator. kindly help

Maverick says:
April 2 4 , 2 01 0 at 4 :4 9 pm

Forget to mention the System config Ns2 pkg: same as you had used ns-2.34 OS: Fedeora 12 Thanks for consideration

Maverick says:
April 2 5, 2 01 0 at 4 :3 2 am

Hi ppl, Just wanted to updated the soln for the error reported earlier. Well we just had to make an entry for the new protocol in the Makefile.in file i.e. wfrp/wfrp.o in the commonMakefile.in Once you do that u got to fo the following

1. ./Configure 2. Make clean 3. Make depend 4. Make 5. Make install then run wfrp_tcl file. It should run perfectly fine. SmartNode, correct me if i am wrong.

NIT IN says:
April 2 9 , 2 01 0 at 4 :1 0 pm

Sir i am trying for the getting node energy code for the same as per your guide line i am changing the wfrp.cc code Instruction given is to change the wfrp.cc line 530. but what ever file is there having no of lines 511 only. What to do for the same

ahmad says:
May 1 , 2 01 0 at 1 1 :52 pm

dear mr thanks for your very good helping. I learned very things from your site. but I have a question, if it is possible help me: how can I see xgraph output for aodv protocol? please and please if it possible send this question answer for my mail. my mail : a.heidari@live.com

smartnode says:
May 6 , 2 01 0 at 1 2 :54 am

@Maverick: thanks for additional instruction.. @NITIN: if you start adding codes from the top. Then line 530 will appear @ahmad: see this manaul http://www.maddireddy.com/file/btechprj/xgraph.pdf

vp says:
May 1 0, 2 01 0 at 5:1 2 am

sir i want to create a hello flood attack in wsn what i do please help me to solve my problem. thanks you

Anand says:
May 1 0, 2 01 0 at 5:3 7 am

hello Sir I have a small problem. I am working on detection/isolation of selfish/malicious node which drops data packet. I want to logically group nodes of active route found by DSR such that first three node form first group, next three nodes form second group and so on. Also want to know how to explicit send ACK packet for reception of data packets by a node to previous one of active path.

igorblog-712 says:
May 1 5, 2 01 0 at 4 :4 6 am

igorblog-712 ????? ?? PHP ???? http://pnevmostroy.ru/ ?

Kylie Batt says:


May 2 0, 2 01 0 at 4 :3 5 am

? It has been really long time since my last post my and I am back. Finally, I could make little time to write this post..

irvan says:
May 2 8, 2 01 0 at 6 :57 pm

Dear Sir Im irvan from Indonesia, i read your paper about RADV. I want to compare RAODV with AODV. I got RAODVs source code from mr elmurod blog. I think this code had improved with ability in security especially with malicious node existance. I tried to delete it. When i started to simulate (i use RWM, and CBR traffic random generator, setdest and cbrgen) but i cannot found RAODV performances better than AODV. Sir could you explain to me in what scenario of simulation RAODV perform better. Especially based on your paper Thank you very much..i really need your help

Mariam says:
June 1 6 , 2 01 0 at 8:01 pm

Al Salamo Alikom, Dear Elmurod, I have a question, concerning implemented WSN multipath routing protocols on NS-2.34. are there other than AOMDV? I searched for the source code of others like MDSR, MDR, SMR or but in vain, arent there? need your help Jazak Allah kheran Mariam

DLERA says:
June 1 8, 2 01 0 at 3 :2 8 am

I am trying to implement a distributed time synchronization algorithm in Zigbee if you have any suggestion please send me . That algorithm works independent of topology and every node will broadcast its offset and some other parameters . Based on that broadcast other nodes ( which are neighbors to that node)will update their clocks and so on . This is how they synchronize . I want to know how we have to send the packets and where we have to start in a topology . please give me your suggestion . If you want I will give the references also..

Ali Balador says:


July 7 , 2 01 0 at 2 :3 2 am

i could not leave a message in malicious nodes i have a question i decided to simulate misbehaving node in mac layer protocol how can do that? do you any codes for that? please help me Ali Balador (balador.org)

Sons says:
July 1 5, 2 01 0 at 6 :54 pm

Elmurod, Thanks for such informative postings. I am new to the world of NS2 and need a explanation on how to debug the code in ns2 so that i am able to understand the flow of the code i added in the NS2. The code provided by you is working absolutely fine since your instructions were followed appropriately. I need to understand the WFRP initial posting including this on from Concept point of you. Since you are the owner please provide me the links or complete understanding of the source code you have shared for learners like me. Thanking you once again. Sons

Sons says:
July 2 5, 2 01 0 at 1 1 :3 1 am

Can u please provide resources for me to understand the code.. that is direct diffusion. Also, I need to add x graph and routing table to this protocol how can

i go about it. Please guide me Mr. Elmurod. I really hope for a positive response. Your research has not only contributed in triggering my interest in NS2 but one day i am sure under your guidance i will be able be call myself as researcher and expert in NS2. Thanking you once again. Sons.

Hussein Almaqbali says:


July 2 5, 2 01 0 at 8:2 8 pm

Thanks for your great effort to help others.. I would like to as u the following: WFRP::command() in wfrp.cc has id, start, sink, index, log-target .. Q: From where these command are tragger. It is not in tcl file????? Thanks,

Hussein Almaqbali says:


July 2 5, 2 01 0 at 8:3 3 pm

How can we control the transmission power..

kevin says:
August 9 , 2 01 0 at 5:3 9 am

hi, I have another question. I want to implement a new transport protocol in ns2. Is there any difference compare to adding a routing protocol in ns2? Do you have any experience and can share with me? Please give me some reference. Thanks in advance.

Ben Le says:
August 1 1 , 2 01 0 at 4 :2 0 pm

A node can get its own position by your source code. Do you think we can get position of neighboring node without hello message?

smartnode says:
August 2 6 , 2 01 0 at 2 :03 am

Im sorry guys could not approve your comments earlier and could not give response. I was really busy for three months. I will reply one by one, hope it is not too late.

smartnode says:
August 2 6 , 2 01 0 at 2 :1 3 am

@vp check wfrp code it will be helpful. @anand did not get what you are asking. @irvan i guess you got my mail and solved your problem. @mariam i dont have source code for other multipath routing protocols since authors hadnt published @dalera i guess i cant make time for that @ali the idea is similar one i have described in my other post. You just have to make those changes in mac layer. @Sons leave your email ill contact you

foziyetti says:
August 2 6 , 2 01 0 at 5:3 3 am

hello, how could i call update_energy() ? shall i make a new TCL command to call it? thankls

Khan says:
Septem ber 9 , 2 01 0 at 1 :1 2 am

Hi,

When I try you code I get segmentation fault error. Using gdb this error message was given Program received signal SIGSEGV, Segmentation fault. 0x0829acf1 in MobileNode::update_position() () Can you please suggest any solution

Sam says:
Septem ber 1 0, 2 01 0 at 9 :4 8 am

Hi, I want to collect some information regarding transmit power and received power from nodes as an input to an algorithm and then send the output like new transmit power to the nodes I am using Ns2.34 I dont know how to start Your reply will be appreciated

mostafa says:
Septem ber 1 4 , 2 01 0 at 6 :2 1 pm

Hello. At first, I would like to thank you for your useful post. Im studying on routing in vehicular ad-hoc networks . thus, using of node positions are very important for me. for example, I want to calculate the distances between one node to its neighbours. I need to know : 1. how can I use the positions of node and its neighbours in {.cc} file? 2. where I should add my code in {.cc} file (for example, in wfrp.cc file) ?

smartnode says:
Septem ber 1 5, 2 01 0 at 1 :2 3 am

@Khan. I guess the error is not in my code. I havent had that problem. @Sam. Many people asked me that question, you can getting such information depends on what kind of physical layer you are using. And if it is 802.15.4, you can find PHY layer files in wpan folder of NS2 root. @Mostafa. 1. Your question is bit strange. Position of nodes can be obtained as explained in this post. If you want to check if two nodes are neighbor or not, you need to get position of nodes one by one and calculate distance compare with radio range. Also, i guess there should be a function in MobileNode.cc to check distance between nodes. 2. Wherever you want

fatih says:
Septem ber 1 5, 2 01 0 at 2 :2 3 am

Hello, I have ns2.34 installed. I want to learn if i really need to install some patch like mannaism for wsn support. I tried Dr. Zhengs source code from http://wwwee.ccny.cuny.edu/zheng/pub/index.html I didnt install anything just run demo examples inside and they all worked just fine. I guess there is some support to wsn at some level. if so why do we need to install a patch like mannaism? by the way i tried to contact you by email but couldnt find it anywhere. You can reply to my email address. Thank you! smartnode says:
October 1 , 2 01 0 at 1 :1 3 am

Right, you dont have to install anything for wsn support, it is lready there. But did not get other part of your question. What do you mean.

Sam says:
Septem ber 1 7 , 2 01 0 at 2 :59 am

Hi I am using 802.11 and if you know where I can find anything have been done in that area that will be great

Thanks

T arek Mahamed says:


October 3 , 2 01 0 at 8:1 8 pm

please i want the source code for any routing protocol for wsn that implement into ns2

fatih says:
October 6 , 2 01 0 at 7 :1 0 am

If WSN support already included in ns2.34 then why would I want to install a patch like mannaism or sensorsim? Thanks,

Hussein says:
October 2 0, 2 01 0 at 1 :01 am

How I can control transmission power. (build toplogy control protocol).

smartnode says:
October 2 0, 2 01 0 at 1 2 :3 7 pm

@Tarek, Be specific in your question. There are already a number of routing protocols that would work with WSN such as AODV, DirectDiffusion. I am not sure if this what you are asking. @Hussein, if you are trying to control power in a real time then you have to change source code of physical layer. I am not sure there is way to do it in routing layer or you can preset transmission power in your TCL script but the power is not adaptive in real time.

Mostafa says:
Nov em ber 8, 2 01 0 at 7 :3 0 pm

Hello. Thanks for your explanation. As you told, I searched in MobileNode.h and found inline void getLoc(double *x, double *y, double *z) function in it. Then, I modified aodv.{h,cc} files as follow : 1. In aodv.h, I added : MobileNode *node_; nsaddr_t my_id_; double my_x_; double my_y_; void GetLocation(double* , double*); virtual void getLoc(); 2. In aodv.cc, I added : void AODV::getLoc(){ GetLocation(&my_x_, &my_y_); } void AODV::GetLocation(double *x, double *y){ double pos_x_, pos_y_, pos_z_; node_->getLoc(&pos_x_, &pos_y_, &pos_z_); *x=pos_x_; *y=pos_y_; } 3. Then, in printing routing table section , in fprintf(dumpFile, NODE: x=%f n, &my_x_); I tried to print my_x_ variable. Finally, after runing make in ~/ns-2.34 I simulated aodv protocol but it printed 0 for all of my_x_ values, instead of actual x coordinates, for instance: ==================================NODE: 0 25.1192 17 0 255 5 0 0.0000 174759720 my_x_=0.000000 In fact, it didnt work well !! Would you please help me to solve this problem? Regards

David says:
Nov em ber 9 , 2 01 0 at 1 :08 am

when added new protocol it compiles ok, but on runing tcl script it gives following error invalid command name Agent/MAODV while executing Agent/MAODV create _o17 0 invoked from within catch $className create $o $args msg invoked from within if [catch "$className create $o $args" msg] { if [string match "__FAILED_SHADOW_OBJECT_" $msg] { delete $o return } global errorInfo error class $ (procedure new line 3) invoked from within new Agent/MAODV [$node node-addr] (procedure _o3 line 2) (Simulator create-maodv-agent line 2) invoked from within $self create-maodv-agent $node (MAODV arm line 2) invoked from within switch -exact $routingAgent_ { DSDV { set ragent [$self create-dsdv-agent $node] } DSR { $self at 0.0 $node start-dsr } AODV { set ragent [$self cre..." (procedure "_o3" line 14) (Simulator create-wireless-node line 14) invoked from within "_o3 create-wireless-node" ("eval" body line 1) invoked from within "eval $self create-wireless-node $args" (procedure "_o3" line 23) (Simulator node line 23) invoked from within "$ns node" ("for" body line 2) invoked from within "for {set i 0} {$i < [expr {$val(nn)}]} { incr i } { set node_($i) [$ns node] }" (file "wl1.tcl" line 101)

David says:
Nov em ber 9 , 2 01 0 at 1 :1 4 am

i am in Rawalpindi; no one has helped me simulate wormhole using AODV; when i give max-seq no in root reply it gives sementation fault; i could not implement even blackhole pls help to simulate wormhole; its last semester; pls just guid me; i will work day and night

Mostafa says:
Nov em ber 9 , 2 01 0 at 4 :2 9 pm

I called getLoc() function in printing routing table section after rt_print(index) function.

Mostafa says:
Nov em ber 1 2 , 2 01 0 at 3 :51 am

I found my solution. I used your update_position() function with some changes. Thanks.

issac says:
Nov em ber 1 8, 2 01 0 at 8:2 0 pm

hi smartnode, would like to ask if u have implemented secure routing like saodv, aran and sead in ns2 b4? would if mind to share if u have

issac says:
Nov em ber 1 8, 2 01 0 at 8:2 3 pm

any1 can help? i need to implement SAODV in ns2 any1 know how or have the code to share?

Rajesh says:
Nov em ber 2 3 , 2 01 0 at 9 :2 5 pm

Hi im new bee to ns2i want to know how to implement sensor nodes in ns2 please help memy mail id rajesh15munna@gmail.com

Mostafa says:
Nov em ber 2 3 , 2 01 0 at 1 0:09 pm

Hi dear. Im working on Aodv protocol for my thesis and so I need special metric which is the number of path breakages. Actually, I need to get the number of path breakages through trace file. Please help me about that. Best regards.

Yuvraj Singh says:


Nov em ber 2 5, 2 01 0 at 3 :06 am

Hello. Can u help me to develop an intrusion detection system for mobile ad hoc networks for attacks like packet dropping and modification.

smartnode says:
Decem ber 2 9 , 2 01 0 at 1 :2 3 am

Sorry guys, I cant help anyone these days. Too busy to do something on NS2.

2012 Elmurod A. Talipov

S-ar putea să vă placă și