LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to integrate the "Resource/Energy" leach class into NS-2.34? (https://www.linuxquestions.org/questions/linux-software-2/how-to-integrate-the-resource-energy-leach-class-into-ns-2-34-a-870368/)

knudfl 07-21-2011 03:51 AM

# 120 : Please read http://linuxsilo.net/docs/smart-questions_en.html
I.e. please tell, which Linux OS, you are using, like CentOS6, Fedora 11 etc.

And look for bash with the which command : which bash

I assume you already have used one of these commands : ./install , make.
Then bash is most possibly in use too.

And by the way, did the 'sh test' command work ? ?

..

monazEssam 08-14-2011 04:36 PM

having the same error
 
Hellow everyody
me too i had the same error melokuhle had when i tried to setup the leach on ns2.34 using above steps:
trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope
trace/cmu-trace.cc: At global scope:
trace/cmu-trace.cc:1523: error: no ‘void CMUTrace::format_rca(Packet*, int)’ member function declared in class ‘CMUTrace’
make: *** [trace/cmu-trace.

Can anyone help me asap please as i need it badly

monazEssam 08-14-2011 04:40 PM

Dears,
I had the same problem mealokuhle had when i tried to install leach on ns2.34 using above steps, the errors are:
trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope
trace/cmu-trace.cc: At global scope:
trace/cmu-trace.cc:1523: error: no ‘void CMUTrace::format_rca(Packet*, int)’ member function declared in class ‘CMUTrace’
make: *** [trace/cmu-trace.

can anyone help plz asap as i need it badly
thanks in advance

exidus 08-15-2011 03:59 AM

@monazEssam

Hi,
you must have these pieces of code (lines between #ifdef and #endif) in file trace/cmu-trace.cc

Code:

...
        case PT_ARP:
                format_arp(p, offset);
                break;
#ifdef MIT_uAMPS
        case PT_RCA:
                format_rca(p,offset);
                break;
#endif
        default:
...

and append this to end of file

Code:

#ifdef MIT_uAMPS
void
CMUTrace::format_rca(Packet *p, int offset)
{
    struct hdr_rca *rca_hdr = HDR_RCA(p);
    char op = (char) type_;

    switch (rca_hdr->msg_type())
      {
      case ADV:
        op = ADV_CHAR;
        break;

      case REQ:
        op = REQ_CHAR;
        break;

      case DATA:
        op = DATA_CHAR;
        break;

      default:
        //printf("format_rca:  Warning, unknown meta-data type %d\n",rca_hdr->msg_type());
        op = (char) type_;
        break;
      }

    sprintf(pt_->buffer() + offset, "------- [%c %d %d %d] ",
        op,
        rca_hdr->rca_src(),
        rca_hdr->rca_link_dst(),
        rca_hdr->rca_mac_dst()
        );
    return;
}
#endif

This may help you

monazEssam 08-16-2011 05:26 AM

Thanks exidus, it's working now, the make file executed without errors but when i type ./test and try to run the .nam file i found there are only 3 nodes and there is no connection between them, so i need to know how can i see the simulation of the leach i mean i need to see the clusters and cluster heads formed and sending we receiving the packets after the clusters formed

also if i want to add something to the packets sent and received in leach , where should i add my code?

monazEssam 08-16-2011 05:47 AM

Dears,
I got this error in leach.err file when i run the test file:
can't read "env(RCA_LIBRARY)": no such variable
while executing
"source $env(RCA_LIBRARY)/ns-ranode.tcl"
(file "mit/uAMPS/sims/uamps.tcl" line 9)
invoked from within
"source.orig mit/uAMPS/sims/uamps.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig[list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig[list $fileName]
..."
(procedure "source" line 8)
invoked from within
"source mit/uAMPS/sims/uamps.tcl"
(file "tcl/mobility/leach.tcl" line 18)
invoked from within
"source.orig tcl/mobility/leach.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig[list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig[list $fileName]
..."
(procedure "source" line 8)
invoked from within
"source tcl/mobility/$opt(rp).tcl"
(file "tcl/ex/wireless.tcl" line 187)

Can anyone help?

exidus 08-17-2011 07:22 AM

@monazEssam

Answer for your problem is in post #58
You must change path to sources in file /mit/uAMPS/sims/umaps.tcl

For example you must change all 7 sources from this:
source $env(RCA_LIBRARY)/ns-ranode.tcl
to this
source /your_path_to_ns2/ns-2.34/mit/rca/ns-ranode.tcl

monazEssam 08-19-2011 06:30 PM

@exidus: thank you exidus for your support to me. thanks GOD the leach now is running without errors but i have 2 questions:

The first question is:
there are some files in mit/leach_sims i don't know their structure and can't understand their content and i tried to search for them in leach files to know when and where they are filled but i can't find anything:
Leach.Data
leach.alive
Leach.save1
Leach.save2

the second question that i want to add a security to all leach packets/messages. i mean i want to encrypt all sent messages in leach protocol before they are sent and decrypt them on receiving, could you tell me where exactly(in which files) i can add my code for encryption & decryption at each sent and receive function in leach protocol

thanks in advance

monazEssam 08-21-2011 04:34 AM

Dears,
i want to know the name of the trace file i should analyze it when running the leach using ./test as i found alto of .tr (like out.tr, 694demo.tr and leach.tr ) files and i don't know which one i should analyze it for leach performance

also the name file names 694demo.nam when i run it , it simulated 2 nodes with no connection , while in leach_test file the used topology is :topology_file="mit/uAMPS/sims/100nodes.txt". which contains 100 nodes not only 3 and i can't see the clusters formation in the nam simulation, how can i see it?

Thanks in advance,
Mona Essam

monazEssam 08-23-2011 06:51 AM

dears,
Has anyone an awk script for energy consumption, throuhput and the packets delay for leach trace files?

subzero155 08-23-2011 12:44 PM

Leach
 
HI,

I am trying to add LEACH to NS2.35 on Cygwin by following these steps but I am getting this error when I make:
Code:

queue/priqueue.cc: In member function `virtual void PriQueue::recv(Packet*, Hand
ler*)':
queue/priqueue.cc:94: error: `PT_MDART' was not declared in this scope
make: *** [queue/priqueue.o] Error 1

Any ideas why?

Thanks

Quote:

Originally Posted by MayTamer (Post 4310131)
I suppose that ns-2.34 is installed with the compiler gcc-4.3.
The home directory of ns-2.34 is "/opt/ns-allinone-2.34"
1- download the package "ns-234-leach.tar.gz" into the directory "/opt/ns-allinone-2.34/ns-2.34".
https://docs.google.com/uc?id=0BzLWx...CNWG1NQK&hl=en
2- download the bash file "leach-setup.sh" into the directory "/opt/ns-allinone-2.34/ns-2.34".
https://docs.google.com/uc?id=0BzLWx...CJSU5ZYG&hl=en
3- If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the file "leach-setup.sh".
4- move to the directory "/opt/ns-allinone-2.34/ns-2.34" and patch the file "leach-setup.sh"
wsn@ubuntu:~$ cd /opt/ns-allinone-2.34/ns-2.34/
wsn@ubuntu:/opt/ns-allinone-2.34/ns-2.34$ bash leach-setup.sh
5- If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the follwoing two files:
- "Makefile" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".
- "Makefile.in" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".
6. Edit both “Makefile” & “Makefile.in” as following:
CC = gcc-4.3
CPP = g++-4.3
7- run the following commands
wsn@ubuntu:/opt/ns-allinone-2.34/ns-2.34$./configure
wsn@ubuntu:/opt/ns-allinone-2.34/ns-2.34$make clean
wsn@ubuntu:/opt/ns-allinone-2.34/ns-2.34$make
7- If the previous commands passed successfully then you are ready to test your "Leach" by running ./test:
wsn@ubuntu:/opt/ns-allinone-2.34/ns-2.34$./test
8. check the file "leach.err", if no error reported then go to "leach.out" and enjoy your results!


exidus 08-25-2011 04:37 AM

@monazEssam

1. Main output file is leach.out. There are information about which file is a cluster head, which node send a message etc. You can see total spend energz at the end of file. Can you check a number of total energy at the end of simulation when you simulate 100 nodes?

2. If you want to add security to leach packets, I think that a good place for it will be a files mit/rca/rcagent.cc and mit/uAMPS/bsagent.cc. There are function for sending and receiving packets. But I am not sure if my idea is correct.

3. Trace file is for leach_test file is leach.tr in ns-2.34 directory. I think that nam file is not created for leach_test.

subzero155 08-25-2011 06:52 AM

Leach
 
Thank you. I have managed to implement LEACH on ns2.34. However, I don't know how to use the test output files such as leach.energy and leach.data, etc. Is there any recommended resource that explains them?

Regards


Quote:

Originally Posted by exidus (Post 4452925)
@monazEssam

1. Main output file is leach.out. There are information about which file is a cluster head, which node send a message etc. You can see total spend energz at the end of file. Can you check a number of total energy at the end of simulation when you simulate 100 nodes?

2. If you want to add security to leach packets, I think that a good place for it will be a files mit/rca/rcagent.cc and mit/uAMPS/bsagent.cc. There are function for sending and receiving packets. But I am not sure if my idea is correct.

3. Trace file is for leach_test file is leach.tr in ns-2.34 directory. I think that nam file is not created for leach_test.


farab 08-25-2011 12:19 PM

It worked Thanks all.

---------- Post added 08-25-11 at 08:49 PM ----------

Thanks a lot all mates. I have created a simple how to, called: "Installing NS and LEACH on ubuntu" in PDF format and I want to share my experinces collected from this usefull site:

Code:

I suppose that you have:

1. Ubuntu installed on your machine and I suggest ubuntu 10.10.

2. ns-2.34 is installed in "/opt/ns-allinone-2.34" this is path is optional but it could be easier if this path changed because the default directory of LEACH is "/opt/ns-allinone-2.34/ns-2.34".

3. The gcc-4.3 compiler. If not, First you MUST install gcc-4.3 and g++-4.3. It seems gcc-4.2 and g++-4.2 will work but I suggest 4.3:
                Add following lines to end of the  /etc/apt/sources.list by:
               
                sudo gedit /etc/apt/sources.list

deb http://76.73.4.58/ubuntu/ maverick-updates main
deb http://76.73.4.58/ubuntu/ maverick universe
deb http://security.ubuntu.com/ubuntu maverick-security main
deb http://security.ubuntu.com/ubuntu maverick-security universe

                Now save the file and close, then refresh your catalog by:

                sudo apt-get update

                Now gcc-4.3 and g++-4.3 will be available. install them:

                sudo apt-get install gcc-4.3 and g++-4.3

                If you prefer 4.2, simlpy add 'hardy' instead of  'maverick'. And:
               
                sudo apt-get install gcc-4.2 and g++-4.2


Download and install LEACH

1- download the package "ns-234-leach.tar.gz" into the directory "/opt/ns-allinone-2.34/ns-2.34".
        https://docs.google.com/uc?id=0BzLWx...CNWG1NQK&hl=en

2- download the bash file "leach-setup.sh" into the directory "/opt/ns-allinone-2.34/ns-2.34".
        https://docs.google.com/uc?id=0BzLWx...CJSU5ZYG&hl=en

3- If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the file "leach-setup.sh".

4- move to the directory "/opt/ns-allinone-2.34/ns-2.34" and patch the file "leach-setup.sh"
        farab@ubuntu:~$ cd /opt/ns-allinone-2.34/ns-2.34/

        farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$ bash leach-setup.sh

5- If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the follwoing two files:
        - "Makefile" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".
        - "Makefile.in" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".

6. Edit both “Makefile” & “Makefile.in” as following:
        CC = gcc-4.3
        CPP = g++-4.3

7. You need to add a declaration of format_rca in cmu-trace.h found in the directory "yourpath/ns-allinone-2.34/ns-2.34/”.

        void    format_imep(Packet *p, int offset);
        void    format_aodv(Packet *p, int offset);
        void    format_aomdv(Packet *p, int offset);
#ifdef MIT_uAMPS
        void    format_rca(Packet *p, int offset);
#endif

        // This holds all the tracers added at run-time
        static PacketTracer *pktTrc_;

};

And the flowing lins to end of that:

#ifdef MIT_uAMPS
#define ADV_CHAR            'A'
#define REQ_CHAR            'R'
#define DATA_CHAR            'D'
#endif
8. Then, modify the uamps.tcl in the /opt/ns-allinone-2.34/ns-2.34/mit/uAMPS/sims/ folder and replace:
        $env(uAMPS_LIBRARY) with  yourpath/ns-allinone-2.34/ns-2.34/mit/rca
and
        $env(uAMPS_LIBRARY) with  yourpath/ns-allinone-2.34/ns-2.34/mit/uAMPS

9. You need to set the variables in \tcl\lib\ns-default.tcl

# ------------------------------------------------------
Phy/WirelessPhy set alive_ 1
Phy/WirelessPhy set Efriss_amp_ 100e-12
Phy/WirelessPhy set Etwo_ray_amp_ 0.013e-12

Phy/WirelessPhy set EXcvr_ 50e-9
Phy/WirelessPhy set sleep_ 0
Phy/WirelessPhy set ss_ 1
Phy/WirelessPhy set dist_ 0
# ------------------------------------------------------

once u modify the .tcl, make sure you do a 'make clean' and a 'make depend'

10. run the following commands:

        farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$./configure
        farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$make clean
        farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$make
              farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$sudo chmod 777 -R ns-allinone-2.34

If the previous commands passed successfully then you are ready to test your "Leach" by running ./test:
        farab@ubuntu:/opt/ns-allinone-2.34/ns-2.34$./test
check the file "leach.err", if no error reported then go to "leach.out" and enjoy your results!


jimctu 09-03-2011 11:54 AM

Hi everyone, I followed the tips here and got ns-2.34 + leach working (I guess hehehe) but my leach.out has some warnings?
Code:

Warning dst_ is no longer being supported in NS. dst_ 0xffffffff
Use dst_addr_ and dst_port_ instead

some one knows where I change it and which one I have to use?


All times are GMT -5. The time now is 07:33 AM.