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/)

deepa_2111 06-23-2011 11:10 PM

@ Heylos,

I didnt understand. With 100 nodes, even 350J is wrong. Max you can get is 200. I am getting about 199 in all my simulations.
What initial conditions are you talking about ? Try leach_test. That is the starting script (initial conditions)

exidus 06-24-2011 09:40 AM

HI @deepa_2111,
I also made your changes in files \mac\Wireless-Phy.cc (2 places were made a change) and mit\rca\energy.cc (1 place),
but total energy is still higher than 200J with 100 nodes. Did you change other files or something else?
Thank you for your help

deepa_2111 06-24-2011 11:24 PM

@Exidus,

Hey ! Can you please post the changes you made ? Let me check with the code I have now. Please post your changes here

helyos 06-25-2011 05:42 AM

@deepa_2111 I don't understand something. Why if i run ./test for several times i get different energy consumption without changing initial conditions? Is it normal to have always different results?

exidus 06-25-2011 08:11 AM

@deepa_2111

Here are changed files.
File /mac/wireless-phy.cc - changes are commmented with comment change 1 and change 2

Code:

/* -*-        Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-
 *
 * Copyright (c) 1996 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the Computer Systems
 *        Engineering Group at Lawrence Berkeley Laboratory and the Daedalus
 *        research group at UC Berkeley.
 * 4. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Header: /cvsroot/nsnam/ns-2/mac/wireless-phy.cc,v 1.28 2007/09/04 04:32:18 tom_henderson Exp $
 *
 * Ported from CMU/Monarch's code, nov'98 -Padma Haldar.
 * wireless-phy.cc
 */

#include <math.h>

#include <packet.h>

#include <mobilenode.h>
#include <phy.h>
#include <propagation.h>
#include <modulation.h>
#include <omni-antenna.h>
#include <wireless-phy.h>
#include <packet.h>
#include <ip.h>
#include <agent.h>
#include <trace.h>
#include <sys/param.h>  /* for MIN/MAX */

#include "diffusion/diff_header.h"

void Sleep_Timer::expire(Event *) {
        a_->UpdateSleepEnergy();
}


/* ======================================================================
  WirelessPhy Interface
  ====================================================================== */
static class WirelessPhyClass: public TclClass {
public:
        WirelessPhyClass() : TclClass("Phy/WirelessPhy") {}
        TclObject* create(int, const char*const*) {
                return (new WirelessPhy);
        }
} class_WirelessPhy;


WirelessPhy::WirelessPhy() : Phy(), sleep_timer_(this), status_(IDLE)
{
        /*
        *  It sounds like 10db should be the capture threshold.
        *
        *  If a node is presently receiving a packet a a power level
        *  Pa, and a packet at power level Pb arrives, the following
        *  comparion must be made to determine whether or not capture
        *  occurs:
        *
        *    10 * log(Pa) - 10 * log(Pb) > 10db
        *
        *  OR equivalently
        *
        *    Pa/Pb > 10.
        *
        */
#ifdef MIT_uAMPS
  alive_ = 1;          // 0 = dead, 1 = alive
  bandwidth_ = 1000000;                // 100 Mbps
  Efriss_amp_ = 100 * 1e-12;          // Friss amp energy (J/bit/m^2)
  Etwo_ray_amp_ = 0.013 * 1e-12;      // Two-ray amp energy (J/bit/m^4)
  EXcvr_ = 50 * 1e-9;                  // Xcvr energy (J/bit)
  // Use this base threshold to get a "hearing radius" of ~ 1 m
  Pfriss_amp_ = Efriss_amp_ * bandwidth_;      // Friss power (W/m^2)
  Ptwo_ray_amp_ = Etwo_ray_amp_ * bandwidth_;  // Two-ray power (W/m^4)
  PXcvr_ = EXcvr_ * bandwidth_;        // Xcvr power (W)
  sleep_ = 0;                          // 0 = awake, 1 = asleep
  ss_ = 1;                            // amount of spreading
  time_finish_rcv_ = 0;                           
  dist_ = 0;                          // approx. distance to transmitter
  energy_ = 0; 
#else
  bandwidth_ = 2*1e6;                // 2 Mb
  Pt_ = pow(10, 2.45) * 1e-3;        // 24.5 dbm, ~ 281.8mw
#endif       

#ifdef MIT_uAMPS
  /*
  * Set CSThresh_ for receiver sensitivity and RXThresh_ for required SNR.
  */
  CSThresh_ = 1e-10;
  RXThresh_ = 6e-9;
#else
  CSThresh_ = 1.559e-11;
  RXThresh_ = 3.652e-10;
#endif
        bind("CPThresh_", &CPThresh_);
        bind("CSThresh_", &CSThresh_);
        bind("RXThresh_", &RXThresh_);
        //bind("bandwidth_", &bandwidth_);
        bind("Pt_", &Pt_);
        bind("freq_", &freq_);
        bind("L_", &L_);
#ifdef MIT_uAMPS
  bind("alive_",&alive_);
  bind("bandwidth_",&bandwidth_);
  bind("Efriss_amp_", &Efriss_amp_);
  bind("Etwo_ray_amp_", &Etwo_ray_amp_);
  bind("EXcvr_", &EXcvr_);
  bind("sleep_",&sleep_);
  bind("ss_",&ss_);
  bind("dist_",&dist_);
#endif
       
        lambda_ = SPEED_OF_LIGHT / freq_;

        node_ = 0;
        ant_ = 0;
        propagation_ = 0;
        modulation_ = 0;

        // Assume AT&T's Wavelan PCMCIA card -- Chalermek
        //        Pt_ = 8.5872e-4; // For 40m transmission range.
        //      Pt_ = 7.214e-3;  // For 100m transmission range.
        //      Pt_ = 0.2818; // For 250m transmission range.
        //        Pt_ = pow(10, 2.45) * 1e-3;        // 24.5 dbm, ~ 281.8mw
       
        Pt_consume_ = 0.660;  // 1.6 W drained power for transmission
        Pr_consume_ = 0.395;  // 1.2 W drained power for reception

        //        P_idle_ = 0.035; // 1.15 W drained power for idle

        P_idle_ = 0.0;
        P_sleep_ = 0.00;
        T_sleep_ = 10000;
        P_transition_ = 0.00;
        T_transition_ = 0.00; // 2.31 change: Was not initialized earlier
        node_on_=1;
       
        channel_idle_time_ = NOW;
        update_energy_time_ = NOW;
        last_send_time_ = NOW;
       
        sleep_timer_.resched(1.0);

}

int
WirelessPhy::command(int argc, const char*const* argv)
{
        TclObject *obj;

        if (argc==2) {
                if (strcasecmp(argv[1], "NodeOn") == 0) {
                        node_on();

                        if (em() == NULL)
                                return TCL_OK;
                        if (NOW > update_energy_time_) {
                                update_energy_time_ = NOW;
                        }
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "NodeOff") == 0) {
                        node_off();

                        if (em() == NULL)
                                return TCL_OK;
                        if (NOW > update_energy_time_) {
                                em()->DecrIdleEnergy(NOW-update_energy_time_,
                                                    P_idle_);
                                update_energy_time_ = NOW;
                        }
                        return TCL_OK;
                }
        } else if(argc == 3) {
                if (strcasecmp(argv[1], "setTxPower") == 0) {
                        Pt_consume_ = atof(argv[2]);
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "setRxPower") == 0) {
                        Pr_consume_ = atof(argv[2]);
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "setIdlePower") == 0) {
                        P_idle_ = atof(argv[2]);
                        return TCL_OK;
                }else if (strcasecmp(argv[1], "setSleepPower") == 0) {
                        P_sleep_ = atof(argv[2]);
                        return TCL_OK;
                }else if (strcasecmp(argv[1], "setSleepTime") == 0) {
                        T_sleep_ = atof(argv[2]);
                        return TCL_OK;               
                } else if (strcasecmp(argv[1], "setTransitionPower") == 0) {
                        P_transition_ = atof(argv[2]);
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "setTransitionTime") == 0) {
                        T_transition_ = atof(argv[2]);
                        return TCL_OK;
                }else if( (obj = TclObject::lookup(argv[2])) == 0) {
                        fprintf(stderr,"WirelessPhy: %s lookup of %s failed\n",
                                argv[1], argv[2]);
                        return TCL_ERROR;
                }else if (strcmp(argv[1], "propagation") == 0) {
                        assert(propagation_ == 0);
                        propagation_ = (Propagation*) obj;
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "antenna") == 0) {
                        ant_ = (Antenna*) obj;
                        return TCL_OK;
                } else if (strcasecmp(argv[1], "node") == 0) {
                        assert(node_ == 0);
                        node_ = (Node *)obj;
                        return TCL_OK;
                }

#ifdef MIT_uAMPS
    else if (strcasecmp(argv[1], "attach-energy") == 0) {
      energy_ = (EnergyResource*) obj;
      return TCL_OK;
    }
#endif
        }
        return Phy::command(argc,argv);
}
 
void
WirelessPhy::sendDown(Packet *p)
{
        /*
        * Sanity Check
        */

        assert(initialized());
#ifdef MIT_uAMPS
  /*
  * The power for transmission depends on the distance between
  * the transmitter and the receiver.  If this distance is
  * less than the crossover distance:
  *      (c_d)^2 =  16 * PI^2 * L * hr^2 * ht^2
  *              ---------------------------------
  *                          lambda^2
  * the power falls off using the Friss equation.  Otherwise, the
  * power falls off using the two-ray ground reflection model.
  * Therefore, the power for transmission of a bit is:
  *      Pt = Pfriss_amp_*d^2 if d < c_d
  *      Pt = Ptwo_ray_amp_*d^4 if d >= c_d.
  * The total power dissipated per bit is PXcvr_ + Pt.
  */
  hdr_cmn *ch = HDR_CMN(p);
  hdr_rca *rca_hdr = HDR_RCA(p);
  double d = rca_hdr->get_dist();
  double hr, ht;        // height of recv and xmit antennas
  double tX, tY, tZ;    // transmitter location
  double rX, rY, rZ;
  //node_->location();
 ((MobileNode *)node_)->getLoc(&rX, &rY, &rZ);
//rX=0;
//rY=0;
//rZ=0;
  ht = tZ + ant_->getZ();
  hr = ht;              // assume receiving node and antenna at same height
  double crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)
                            / (lambda_ * lambda_));
  if (d < crossover_dist)
    if (d > 1)
      Pt_ = Efriss_amp_ * bandwidth_ * d * d;
    else
      // Pfriss_amp_ is the minimum transmit amplifier power.
      Pt_ = Efriss_amp_ * bandwidth_;
  else
    Pt_ = Etwo_ray_amp_ * bandwidth_ * d * d * d * d;
  PXcvr_ = EXcvr_ * bandwidth_;

/*  if (energy_)
  {
    if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0)
      alive_ = 0;
  }
*/
//Change 1
        if (energy_)
          {
                if(alive_ != 0) // Deepa
                {
                        if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0)
                        {
                                  printf("alive = 0\n");
                                  alive_ = 0;
                        }
                } // Deepa
          }


#endif
       
        if (em()) {
                        //node is off here...
                        if (Is_node_on() != true ) {
                        Packet::free(p);
                        return;
                        }
                        if(Is_node_on() == true && Is_sleeping() == true){
                        em()-> DecrSleepEnergy(NOW-update_energy_time_,
                                                        P_sleep_);
                        update_energy_time_ = NOW;

                        }

        }
        /*
        * Decrease node's energy
        */
        if(em()) {
                if (em()->energy() > 0) {

                    double txtime = hdr_cmn::access(p)->txtime();
                    double start_time = MAX(channel_idle_time_, NOW);
                    double end_time = MAX(channel_idle_time_, NOW+txtime);
                    double actual_txtime = end_time-start_time;

                    if (start_time > update_energy_time_) {
                            em()->DecrIdleEnergy(start_time -
                                                update_energy_time_, P_idle_);
                            update_energy_time_ = start_time;
                    }

                    /* It turns out that MAC sends packet even though, it's
                      receiving some packets.
                   
                    if (txtime-actual_txtime > 0.000001) {
                            fprintf(stderr,"Something may be wrong at MAC\n");
                            fprintf(stderr,"act_tx = %lf, tx = %lf\n", actual_txtime, txtime);
                    }
                    */

                  // Sanity check
                  double temp = MAX(NOW,last_send_time_);

                  /*
                  if (NOW < last_send_time_) {
                          fprintf(stderr,"Argggg !! Overlapping transmission. NOW %lf last %lf temp %lf\n", NOW, last_send_time_, temp);
                  }
                  */
                 
                  double begin_adjust_time = MIN(channel_idle_time_, temp);
                  double finish_adjust_time = MIN(channel_idle_time_, NOW+txtime);
                  double gap_adjust_time = finish_adjust_time - begin_adjust_time;
                  if (gap_adjust_time < 0.0) {
                          fprintf(stderr,"What the heck ! negative gap time.\n");
                  }

                  if ((gap_adjust_time > 0.0) && (status_ == RECV)) {
                          em()->DecrTxEnergy(gap_adjust_time,
                                              Pt_consume_-Pr_consume_);
                  }

                  em()->DecrTxEnergy(actual_txtime,Pt_consume_);
//                  if (end_time > channel_idle_time_) {
//                          status_ = SEND;
//                  }
//
                  status_ = IDLE;

                  last_send_time_ = NOW+txtime;
                  channel_idle_time_ = end_time;
                  update_energy_time_ = end_time;

                  if (em()->energy() <= 0) {
                          em()->setenergy(0);
                          ((MobileNode*)node())->log_energy(0);
                  }

                } else {

                        // log node energy
                        if (em()->energy() > 0) {
                                ((MobileNode *)node_)->log_energy(1);
                        }
//
                        Packet::free(p);
                        return;
                }
        }

        /*
        *  Stamp the packet with the interface arguments
        */
        p->txinfo_.stamp((MobileNode*)node(), ant_->copy(), Pt_, lambda_);
       
        // Send the packet
        channel_->recv(p, this);
}

int
WirelessPhy::sendUp(Packet *p)
{
        /*
        * Sanity Check
        */
        assert(initialized());

        PacketStamp s;
        double Pr;
        int pkt_recvd = 0;
#ifdef MIT_uAMPS
  hdr_cmn *ch = HDR_CMN(p);
  hdr_rca *rca_hdr = HDR_RCA(p);
  /*
  * Record when this packet ends and its code.
  */
  int code1 = rca_hdr->get_code();
  cs_end_[code1] = Scheduler::instance().clock() + txtime(p);
  /*
  * If the node is asleep, drop the packet.
  */
  if (sleep_) {
      //printf("Sleeping node... carrier sense ends at %f\n", cs_end_);
      //fflush(stdout);
      pkt_recvd = 0;
      goto DONE;
  }
#endif

        Pr = p->txinfo_.getTxPr();
       
        // if the node is in sleeping mode, drop the packet simply
        if (em()) {
                        if (Is_node_on()!= true){
                        pkt_recvd = 0;
                        goto DONE;
                        }

                        if (Is_sleeping()==true && (Is_node_on() == true)) {
                                pkt_recvd = 0;
                                goto DONE;
                        }
                       
        }
        // if the energy goes to ZERO, drop the packet simply
        if (em()) {
                if (em()->energy() <= 0) {
                        pkt_recvd = 0;
                        goto DONE;
                }
        }

        if(propagation_) {
                s.stamp((MobileNode*)node(), ant_, 0, lambda_);
                Pr = propagation_->Pr(&p->txinfo_, &s, this);
                if (Pr < CSThresh_) {
                        pkt_recvd = 0;
                        goto DONE;
                }
                if (Pr < RXThresh_) {
                        /*
                        * We can detect, but not successfully receive
                        * this packet.
                        */
                        hdr_cmn *hdr = HDR_CMN(p);
                        hdr->error() = 1;
#if DEBUG > 3
                        printf("SM %f.9 _%d_ drop pkt from %d low POWER %e/%e\n",
                              Scheduler::instance().clock(), node()->index(),
                              p->txinfo_.getNode()->index(),
                              Pr,RXThresh);
#endif
                }
        }
        if(modulation_) {
                hdr_cmn *hdr = HDR_CMN(p);
                hdr->error() = modulation_->BitError(Pr);
        }
#ifdef MIT_uAMPS
  /*
  * Only remove energy from nodes that are awake and not currently
  * transmitting a packet.
  */
  if (Scheduler::instance().clock() >= time_finish_rcv_) {
    PXcvr_ = EXcvr_ * bandwidth_;
    /*
    if (energy_)
    {
      if (energy_->remove(pktEnergy((double)0, PXcvr_,ch->size())) != 0)
        alive_ = 0;
    }
    */
   
    //Change 2
        if (energy_)
        {
                if(alive_ != 0) // Deepa
                {
                        if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0)
                        {
                                  printf("alive = 0\n");
                                  alive_ = 0;
                        }
                } // Deepa
        }

    time_finish_rcv_ = Scheduler::instance().clock() + txtime(p);
  }
  /*
  * Determine approximate distance of node transmitting node
  * from received power.
  */
  double hr, ht;        // height of recv and xmit antennas
  double rX, rY, rZ;    // receiver location
  double d1, d2;
  double crossover_dist, Pt, M;
  ((MobileNode *)node_)->getLoc(&rX, &rY, &rZ);

//rX=0,rY=0,rZ=0;
  hr = rZ + ant_->getZ();
  ht = hr;              // assume transmitting node antenna at same height

  crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)
                            / (lambda_ * lambda_));
  Pt = p->txinfo_.getTxPr();
  M = lambda_ / (4 * PI);
  d1 = sqrt( (Pt * M * M) / (L_ * Pr) );
  d2 = sqrt(sqrt( (Pt * hr * hr * ht * ht) / Pr) );
  if (d1 < crossover_dist)
    dist_ = d1;
  else
    dist_ = d2;
  rca_hdr->dist_est() = (int) ceil(dist_);
#endif
       
        /*
        * The MAC layer must be notified of the packet reception
        * now - ie; when the first bit has been detected - so that
        * it can properly do Collision Avoidance / Detection.
        */
        pkt_recvd = 1;

DONE:
        p->txinfo_.getAntenna()->release();

        /* WILD HACK: The following two variables are a wild hack.
          They will go away in the next release...
          They're used by the mac-802_11 object to determine
          capture.  This will be moved into the net-if family of
          objects in the future. */
        p->txinfo_.RxPr = Pr;
        p->txinfo_.CPThresh = CPThresh_;

        /*
        * Decrease energy if packet successfully received
        */
        if(pkt_recvd && em()) {

                double rcvtime = hdr_cmn::access(p)->txtime();
                // no way to reach here if the energy level < 0
               
                double start_time = MAX(channel_idle_time_, NOW);
                double end_time = MAX(channel_idle_time_, NOW+rcvtime);
                double actual_rcvtime = end_time-start_time;

                if (start_time > update_energy_time_) {
                        em()->DecrIdleEnergy(start_time-update_energy_time_,
                                            P_idle_);
                        update_energy_time_ = start_time;
                }
               
                em()->DecrRcvEnergy(actual_rcvtime,Pr_consume_);
/*
  if (end_time > channel_idle_time_) {
  status_ = RECV;
  }
*/
                channel_idle_time_ = end_time;
                update_energy_time_ = end_time;

                status_ = IDLE;

                /*
                  hdr_diff *dfh = HDR_DIFF(p);
                  printf("Node %d receives (%d, %d, %d) energy %lf.\n",
                  node()->address(), dfh->sender_id.addr_,
                  dfh->sender_id.port_, dfh->pk_num, node()->energy());
                */

                // log node energy
                if (em()->energy() > 0) {
                ((MobileNode *)node_)->log_energy(1);
                }

                if (em()->energy() <= 0) { 
                        // saying node died
                        em()->setenergy(0);
                        ((MobileNode*)node())->log_energy(0);
                }
        }
       
        return pkt_recvd;
}

void
WirelessPhy::node_on()
{

        node_on_= TRUE;
        status_ = IDLE;

      if (em() == NULL)
            return;       
          if (NOW > update_energy_time_) {
                  update_energy_time_ = NOW;
          }
}

void
WirelessPhy::node_off()
{

        node_on_= FALSE;
        status_ = SLEEP;

        if (em() == NULL)
            return;
        if (NOW > update_energy_time_) {
            em()->DecrIdleEnergy(NOW-update_energy_time_,
                                P_idle_);
            update_energy_time_ = NOW;
        }
}

void
WirelessPhy::node_wakeup()
{

        if (status_== IDLE)
                return;

        if (em() == NULL)
            return;

        if ( NOW > update_energy_time_ && (status_== SLEEP) ) {
                //the power consumption when radio goes from SLEEP mode to IDLE mode
                em()->DecrTransitionEnergy(T_transition_,P_transition_);
               
                em()->DecrSleepEnergy(NOW-update_energy_time_,
                                      P_sleep_);
                status_ = IDLE;
                update_energy_time_ = NOW;
               
                // log node energy
                if (em()->energy() > 0) {
                        ((MobileNode *)node_)->log_energy(1);
                } else {
                        ((MobileNode *)node_)->log_energy(0); 
                }
        }
}

void
WirelessPhy::node_sleep()
{
//
//        node_on_= FALSE;
//
        if (status_== SLEEP)
                return;

        if (em() == NULL)
            return;

        if ( NOW > update_energy_time_ && (status_== IDLE) ) {
        //the power consumption when radio goes from IDLE mode to SLEEP mode
            em()->DecrTransitionEnergy(T_transition_,P_transition_);

            em()->DecrIdleEnergy(NOW-update_energy_time_,
                                P_idle_);
                status_ = SLEEP;
                update_energy_time_ = NOW;

        // log node energy
                if (em()->energy() > 0) {
                        ((MobileNode *)node_)->log_energy(1);
                } else {
                        ((MobileNode *)node_)->log_energy(0); 
                }
        }
}
//
void
WirelessPhy::dump(void) const
{
        Phy::dump();
        fprintf(stdout,
                "\tPt: %f, Gt: %f, Gr: %f, lambda: %f, L: %f\n",
                Pt_, ant_->getTxGain(0,0,0,lambda_), ant_->getRxGain(0,0,0,lambda_), lambda_, L_);
        //fprintf(stdout, "\tbandwidth: %f\n", bandwidth_);
        fprintf(stdout, "--------------------------------------------------\n");
}


void WirelessPhy::UpdateIdleEnergy()
{
        if (em() == NULL) {
                return;
        }
        if (NOW > update_energy_time_ && (Is_node_on()==TRUE && status_ == IDLE ) ) {
                  em()-> DecrIdleEnergy(NOW-update_energy_time_,
                                        P_idle_);
                  update_energy_time_ = NOW;
        }

        // log node energy
        if (em()->energy() > 0) {
                ((MobileNode *)node_)->log_energy(1);
        } else {
                ((MobileNode *)node_)->log_energy(0); 
        }

//        idle_timer_.resched(10.0);
}

double WirelessPhy::getDist(double Pr, double Pt, double Gt, double Gr,
                            double hr, double ht, double L, double lambda)
{
        if (propagation_) {
                return propagation_->getDist(Pr, Pt, Gt, Gr, hr, ht, L,
                                            lambda);
        }
        return 0;
}

//
void WirelessPhy::UpdateSleepEnergy()
{
        if (em() == NULL) {
                return;
        }
        if (NOW > update_energy_time_ && ( Is_node_on()==TRUE  && Is_sleeping() == true) ) {
                  em()-> DecrSleepEnergy(NOW-update_energy_time_,
                                        P_sleep_);
                  update_energy_time_ = NOW;
                // log node energy
                if (em()->energy() > 0) {
                        ((MobileNode *)node_)->log_energy(1);
                } else {
                        ((MobileNode *)node_)->log_energy(0); 
                }
        }
       
        //A hack to make states consistent with those of in Energy Model for AF
        int static s=em()->sleep();
        if(em()->sleep()!=s){

                s=em()->sleep();       
                if(s==1)
                        node_sleep();
                else
                        node_wakeup();                       
//                printf("\n AF hack %d\n",em()->sleep());       
        }       
       
        sleep_timer_.resched(10.0);
}

#ifdef MIT_uAMPS
double
WirelessPhy::pktEnergy(double pt, double pxcvr, int nbytes)
{

  /*
  * Energy (in Joules) is power (in Watts=Joules/sec) divided by
  * bandwidth (in bits/sec) multiplied by the number of bytes, times 8 bits.
  */
  // If data has been spread, power per DATA bit should be the same
  // as if there was no spreading ==> divide transmit power
  // by spreading factor.
  double bits = (double) nbytes * 8;
  pt /= ss_;
  double j = bits * (pt + pxcvr) / bandwidth_;
  return(j);
}

#endif

File /mit/rca/energy.cc - comment change 1

Code:

/*************************************************************************
 *
 * This code was developed as part of the MIT SPIN project. (June, 1999)
 *
 *************************************************************************/


#include <stdlib.h>
#include <mit/rca/energy.h>

#define SUCCESS 0
#define SUCCESS_STRING "success"
#define FAIL -1
#define FAIL_STRING "fail"
#define ALARM 1
#define ALARM_STRING "alarm"

static class EnergyResourceClass : public TclClass {
public:
  EnergyResourceClass() : TclClass("Resource/Energy") {}
  TclObject* create(int, const char*const*) {
    return (new EnergyResource);
  }
} class_EnergyResource;

EnergyResource::EnergyResource()
{
  energy_level_ = 0;
  alarm_level_ = 0;
  bind("energyLevel_",&energy_level_);
  bind("alarmLevel_",&alarm_level_);
  bind("expended_",&expended_);
}

int EnergyResource::command(int argc, const char*const* argv)
{
  Tcl& tcl = Tcl::instance();

  if (argc == 2) {
    if (strcmp(argv[1], "query") == 0) {
      double val = EnergyResource::query();
      tcl.resultf("%f",val);
      return TCL_OK;
    }
  }
  else
  if (argc == 3) {
    if (strcmp(argv[1], "add") == 0) {
      EnergyResource::add(atof(argv[2]));
      return TCL_OK;
    }
    else
    if (strcmp(argv[1], "remove") == 0) {
      int val = EnergyResource::remove(atof(argv[2]));
      tcl.resultf("%s",EnergyResource::resulttostring(val));
      return TCL_OK;
    }
    else
    if (strcmp(argv[1], "acquire") == 0) {
      double val = EnergyResource::acquire(atof(argv[2]));
      tcl.resultf("%f",EnergyResource::resulttostring((int)val));
      return TCL_OK;
    }
  }
  return Resource::command(argc, argv);
}

void EnergyResource::add(double amount)
{
  energy_level_ += amount;
}

//CHANGE 1
int EnergyResource::remove(double amount)
{
  double new_level = energy_level_ - amount;

  //energy_level_ = new_level;
  //expended_ += amount;

  //change
  if(new_level >= 0 )
  {
          energy_level_ = new_level;
          expended_ += amount;
  } // Deepa

 
  if (new_level < 0)
    {
      return FAIL;
    }
  if (new_level < alarm_level_)
    {
      return ALARM;
    }
  return SUCCESS;
}

int EnergyResource::acquire(double amount)
{
  if ((energy_level_ - alarm_level_) < amount)
    {
      return FAIL;
    }

  return SUCCESS;
}

char *EnergyResource::resulttostring(int result)
{
  switch (result)
    {
    case SUCCESS:
      return SUCCESS_STRING;

    case FAIL:
      return FAIL_STRING;

    case ALARM:
      return ALARM_STRING;

    default:
      return NULL;
    }
  return NULL;
}

Is it necessary to do commands make clean and make after I change .cc files? Because I do this after changes but it did not help.
Thanks.

deepa_2111 06-26-2011 07:47 AM

@ Heylos,
Yes that is norma. Because, on each run of ./test, the clusters formed are different, and hence the entire output will be different.

@ Exidus,
Let us try debugging this step by step.
1. after every change to '.cc' or '.h' files, you have to do a 'make' (at times i do a 'make clean', 'make depend' and 'make' also).
2. try reducing the number of nodes (in ./leach_test), and in energy.cc, put a 'printf' to check the 'amount' value in int EnergyResource::remove(double amount){}
3. What is your leach.alive file like ? what outputs do you get there ?

exidus 06-27-2011 06:38 AM

@ deepa_2111
I reduced number of nodes to 50 and created a new topology file for 50 nodes with genscen.
In file energy.cc i added this
Code:

int EnergyResource::remove(double amount)
{
  double new_level = energy_level_ - amount;
  printf("Amount energy: %f \n", amount);
.
.
.

Is it like that you meant? My leach.alive file looks like this:
Code:

10 0 1
10 1 1
10 2 1
10 3 1
10 4 1
10 5 1
10 6 1
10 7 1
10 8 1
10 9 1
10 10 1
10 11 1
10 12 1
10 13 1
10 14 1
10 15 1
10 16 1
10 17 1
10 18 1
10 19 1
10 20 1
10 21 1
10 22 1
10 23 1
10 24 1
10 25 1
10 26 1
10 27 1
10 28 1
10 29 1
10 30 1
10 31 1
10 32 1
10 33 1
10 34 1
10 35 1
10 36 1
10 37 1
10 38 1
10 39 1
10 40 1
10 41 1
10 42 1
10 43 1
10 44 1
10 45 1
10 46 1
10 47 1
10 48 1
10 49 1
20 0 1
20 1 1
20 2 1
20 3 1
20 4 1
20 5 1
20 6 1
20 7 1
20 8 1
20 9 1
20 10 1
20 11 1
20 12 1
20 13 1
20 14 1
20 15 1
20 16 1
20 17 1
20 18 1
20 19 1
20 20 1
20 21 1
20 22 1
20 23 1
20 24 1
20 25 1
20 26 1
20 27 1
20 28 1
20 29 1
20 30 1
20 31 1
20 32 1
20 33 1
20 34 1
20 35 1
20 36 1
20 37 1
20 38 1
20 39 1
20 40 1
20 41 1
20 42 1
20 43 1
20 44 1
20 45 1
20 46 1
20 47 1
20 48 1
20 49 1
30 0 1
30 1 1
30 2 1
30 3 1
30 4 1
30 5 1
30 6 1
30 7 1
30 8 1
30 9 1
30 10 1
30 11 1
30 12 1
30 13 1
30 14 1
30 15 1
30 16 1
30 17 1
30 18 1
30 19 1
30 20 1
30 21 1
30 22 1
30 23 1
30 24 1
30 25 1
30 26 1
30 27 1
30 28 1
30 29 1
30 30 1
30 31 1
30 32 1
30 33 1
30 34 1
30 35 1
30 36 1
30 37 1
30 38 1
30 39 1
30 40 1
30 41 1
30 42 1
30 43 1
30 44 1
30 45 1
30 46 1
30 47 1
30 48 1
30 49 1
40 0 1
40 1 1
40 2 1
40 3 1
40 4 1
40 5 1
40 6 1
40 7 1
40 8 1
40 9 1
40 10 1
40 11 1
40 12 1
40 13 1
40 14 1
40 15 1
40 16 1
40 17 1
40 18 1
40 19 1
40 20 1
40 21 1
40 22 1
40 23 1
40 24 1
40 25 1
40 26 1
40 27 1
40 28 1
40 29 1
40 30 1
40 31 1
40 32 1
40 33 1
40 34 1
40 35 1
40 36 1
40 37 1
40 38 1
40 39 1
40 40 1
40 41 1
40 42 1
40 43 1
40 44 1
40 45 1
40 46 1
40 47 1
40 48 1
40 49 1
50 0 1
50 1 1
50 2 1
50 3 1
50 4 1
50 5 1
50 6 1
50 7 1
50 8 1
50 9 1
50 10 1
50 11 1
50 12 1
50 13 1
50 14 1
50 15 1
50 16 1
50 17 1
50 18 1
50 19 1
50 20 1
50 21 1
50 22 1
50 23 1
50 24 1
50 25 1
50 26 1
50 27 1
50 28 1
50 29 1
50 30 1
50 31 1
50 32 1
50 33 1
50 34 1
50 35 1
50 36 1
50 37 1
50 38 1
50 39 1
50 40 1
50 41 1
50 42 1
50 43 1
50 44 1
50 45 1
50 46 1
50 47 1
50 48 1
50 49 1
60 0 1
60 1 1
60 2 1
60 3 1
60 4 1
60 5 1
60 6 1
60 7 1
60 8 1
60 9 1
60 10 1
60 11 1
60 12 1
60 13 1
60 14 1
60 15 1
60 16 1
60 17 1
60 18 1
60 19 1
60 20 1
60 21 1
60 22 1
60 23 1
60 24 1
60 25 1
60 26 1
60 27 1
60 28 1
60 29 1
60 30 1
60 31 1
60 32 1
60 33 1
60 34 1
60 35 1
60 36 1
60 37 1
60 38 1
60 39 1
60 40 1
60 41 1
60 42 1
60 43 1
60 44 1
60 45 1
60 46 1
60 47 1
60 48 1
60 49 1
70 0 1
70 1 1
70 2 1
70 3 1
70 4 0
70 5 1
70 6 1
70 7 1
70 8 1
70 9 1
70 10 1
70 11 1
70 12 1
70 13 1
70 14 1
70 15 1
70 16 1
70 17 1
70 18 1
70 19 1
70 20 1
70 21 1
70 22 1
70 23 1
70 24 1
70 25 1
70 26 1
70 27 1
70 28 1
70 29 1
70 30 1
70 31 1
70 32 1
70 33 1
70 34 1
70 35 1
70 36 1
70 37 1
70 38 1
70 39 1
70 40 1
70 41 1
70 42 1
70 43 1
70 44 1
70 45 1
70 46 1
70 47 1
70 48 1
70 49 1
80 0 1
80 1 1
80 2 1
80 3 1
80 4 0
80 5 1
80 6 1
80 7 1
80 8 1
80 9 1
80 10 1
80 11 1
80 12 1
80 13 1
80 14 1
80 15 1
80 16 1
80 17 1
80 18 1
80 19 1
80 20 1
80 21 1
80 22 1
80 23 1
80 24 1
80 25 1
80 26 1
80 27 1
80 28 1
80 29 1
80 30 1
80 31 1
80 32 1
80 33 1
80 34 1
80 35 1
80 36 1
80 37 1
80 38 1
80 39 1
80 40 1
80 41 1
80 42 1
80 43 1
80 44 1
80 45 1
80 46 1
80 47 1
80 48 1
80 49 1
90 0 1
90 1 1
90 2 1
90 3 1
90 4 0
90 5 1
90 6 1
90 7 1
90 8 1
90 9 1
90 10 1
90 11 1
90 12 1
90 13 1
90 14 1
90 15 1
90 16 1
90 17 1
90 18 1
90 19 1
90 20 1
90 21 1
90 22 1
90 23 1
90 24 1
90 25 1
90 26 1
90 27 1
90 28 1
90 29 1
90 30 1
90 31 1
90 32 1
90 33 1
90 34 1
90 35 1
90 36 1
90 37 1
90 38 1
90 39 1
90 40 1
90 41 1
90 42 1
90 43 1
90 44 1
90 45 1
90 46 1
90 47 1
90 48 1
90 49 1
100 0 1
100 1 1
100 2 1
100 3 1
100 4 0
100 5 1
100 6 1
100 7 1
100 8 1
100 9 1
100 10 1
100 11 1
100 12 1
100 13 1
100 14 1
100 15 1
100 16 1
100 17 1
100 18 1
100 19 1
100 20 1
100 21 1
100 22 1
100 23 1
100 24 1
100 25 1
100 26 1
100 27 1
100 28 1
100 29 1
100 30 1
100 31 1
100 32 1
100 33 1
100 34 1
100 35 1
100 36 1
100 37 1
100 38 1
100 39 1
100 40 1
100 41 1
100 42 1
100 43 1
100 44 1
100 45 1
100 46 1
100 47 1
100 48 1
100 49 1
110 0 1
110 1 1
110 2 1
110 3 1
110 4 0
110 5 1
110 6 1
110 7 1
110 8 1
110 9 1
110 10 1
110 11 1
110 12 1
110 13 1
110 14 1
110 15 1
110 16 1
110 17 1
110 18 1
110 19 1
110 20 1
110 21 1
110 22 1
110 23 1
110 24 1
110 25 1
110 26 1
110 27 1
110 28 1
110 29 1
110 30 1
110 31 1
110 32 1
110 33 1
110 34 1
110 35 1
110 36 1
110 37 1
110 38 1
110 39 1
110 40 1
110 41 1
110 42 1
110 43 1
110 44 1
110 45 1
110 46 1
110 47 1
110 48 1
110 49 1
120 0 1
120 1 1
120 2 1
120 3 1
120 4 0
120 5 1
120 6 1
120 7 1
120 8 1
120 9 1
120 10 1
120 11 1
120 12 1
120 13 1
120 14 1
120 15 1
120 16 1
120 17 1
120 18 1
120 19 1
120 20 1
120 21 1
120 22 1
120 23 1
120 24 1
120 25 1
120 26 1
120 27 1
120 28 1
120 29 1
120 30 1
120 31 1
120 32 1
120 33 1
120 34 1
120 35 1
120 36 1
120 37 1
120 38 1
120 39 1
120 40 1
120 41 1
120 42 1
120 43 1
120 44 1
120 45 1
120 46 1
120 47 1
120 48 1
120 49 1
130 0 1
130 1 1
130 2 1
130 3 1
130 4 0
130 5 1
130 6 1
130 7 1
130 8 1
130 9 1
130 10 1
130 11 1
130 12 1
130 13 1
130 14 1
130 15 1
130 16 1
130 17 1
130 18 1
130 19 1
130 20 1
130 21 1
130 22 1
130 23 1
130 24 1
130 25 1
130 26 1
130 27 1
130 28 1
130 29 1
130 30 1
130 31 1
130 32 1
130 33 1
130 34 1
130 35 1
130 36 1
130 37 1
130 38 1
130 39 1
130 40 1
130 41 1
130 42 1
130 43 1
130 44 1
130 45 1
130 46 1
130 47 1
130 48 1
130 49 1
140 0 1
140 1 1
140 2 1
140 3 1
140 4 0
140 5 1
140 6 1
140 7 1
140 8 1
140 9 1
140 10 1
140 11 1
140 12 0
140 13 1
140 14 1
140 15 1
140 16 1
140 17 1
140 18 1
140 19 1
140 20 1
140 21 1
140 22 1
140 23 1
140 24 1
140 25 1
140 26 1
140 27 1
140 28 1
140 29 1
140 30 1
140 31 1
140 32 1
140 33 1
140 34 1
140 35 1
140 36 1
140 37 1
140 38 1
140 39 1
140 40 1
140 41 1
140 42 1
140 43 1
140 44 1
140 45 1
140 46 1
140 47 1
140 48 1
140 49 1
150 0 1
150 1 1
150 2 1
150 3 1
150 4 0
150 5 1
150 6 1
150 7 1
150 8 1
150 9 1
150 10 1
150 11 1
150 12 0
150 13 1
150 14 1
150 15 1
150 16 1
150 17 1
150 18 1
150 19 1
150 20 1
150 21 1
150 22 1
150 23 1
150 24 1
150 25 1
150 26 1
150 27 1
150 28 1
150 29 1
150 30 1
150 31 1
150 32 1
150 33 1
150 34 1
150 35 1
150 36 1
150 37 1
150 38 1
150 39 1
150 40 1
150 41 1
150 42 1
150 43 1
150 44 1
150 45 1
150 46 1
150 47 1
150 48 1
150 49 1
160 0 1
160 1 1
160 2 1
160 3 1
160 4 0
160 5 1
160 6 1
160 7 1
160 8 1
160 9 1
160 10 1
160 11 1
160 12 0
160 13 1
160 14 1
160 15 1
160 16 1
160 17 1
160 18 1
160 19 1
160 20 1
160 21 1
160 22 1
160 23 1
160 24 1
160 25 1
160 26 1
160 27 1
160 28 1
160 29 1
160 30 1
160 31 1
160 32 1
160 33 1
160 34 1
160 35 1
160 36 1
160 37 1
160 38 1
160 39 1
160 40 1
160 41 1
160 42 1
160 43 1
160 44 1
160 45 1
160 46 1
160 47 1
160 48 1
160 49 1
170 0 1
170 1 1
170 2 1
170 3 1
170 4 0
170 5 1
170 6 1
170 7 1
170 8 1
170 9 1
170 10 1
170 11 1
170 12 0
170 13 1
170 14 1
170 15 1
170 16 1
170 17 1
170 18 1
170 19 1
170 20 1
170 21 0
170 22 1
170 23 1
170 24 1
170 25 1
170 26 1
170 27 1
170 28 1
170 29 1
170 30 1
170 31 1
170 32 1
170 33 1
170 34 1
170 35 1
170 36 1
170 37 1
170 38 1
170 39 1
170 40 1
170 41 1
170 42 1
170 43 1
170 44 1
170 45 1
170 46 1
170 47 1
170 48 1
170 49 1
180 0 1
180 1 1
180 2 1
180 3 1
180 4 0
180 5 1
180 6 1
180 7 1
180 8 1
180 9 1
180 10 1
180 11 1
180 12 0
180 13 1
180 14 1
180 15 1
180 16 1
180 17 1
180 18 1
180 19 1
180 20 1
180 21 0
180 22 1
180 23 1
180 24 1
180 25 1
180 26 1
180 27 1
180 28 1
180 29 1
180 30 1
180 31 1
180 32 1
180 33 1
180 34 1
180 35 1
180 36 1
180 37 1
180 38 1
180 39 1
180 40 1
180 41 1
180 42 1
180 43 1
180 44 1
180 45 1
180 46 1
180 47 1
180 48 1
180 49 1
190 0 1
190 1 1
190 2 1
190 3 0
190 4 0
190 5 1
190 6 1
190 7 1
190 8 1
190 9 1
190 10 1
190 11 1
190 12 0
190 13 1
190 14 0
190 15 1
190 16 1
190 17 1
190 18 1
190 19 1
190 20 1
190 21 0
190 22 1
190 23 1
190 24 0
190 25 1
190 26 1
190 27 1
190 28 1
190 29 0
190 30 1
190 31 1
190 32 1
190 33 1
190 34 1
190 35 1
190 36 1
190 37 1
190 38 1
190 39 0
190 40 1
190 41 1
190 42 1
190 43 1
190 44 0
190 45 0
190 46 1
190 47 1
190 48 0
190 49 1
200 0 1
200 1 1
200 2 1
200 3 0
200 4 0
200 5 1
200 6 1
200 7 1
200 8 1
200 9 1
200 10 1
200 11 1
200 12 0
200 13 1
200 14 0
200 15 1
200 16 1
200 17 1
200 18 1
200 19 1
200 20 1
200 21 0
200 22 1
200 23 1
200 24 0
200 25 1
200 26 1
200 27 1
200 28 1
200 29 0
200 30 1
200 31 1
200 32 1
200 33 1
200 34 1
200 35 1
200 36 1
200 37 1
200 38 1
200 39 0
200 40 1
200 41 1
200 42 1
200 43 1
200 44 0
200 45 0
200 46 1
200 47 1
200 48 0
200 49 1
210 0 1
210 1 1
210 2 1
210 3 0
210 4 0
210 5 1
210 6 1
210 7 1
210 8 0
210 9 1
210 10 1
210 11 1
210 12 0
210 13 1
210 14 0
210 15 1
210 16 0
210 17 1
210 18 1
210 19 0
210 20 1
210 21 0
210 22 1
210 23 1
210 24 0
210 25 1
210 26 1
210 27 1
210 28 1
210 29 0
210 30 1
210 31 1
210 32 1
210 33 1
210 34 1
210 35 1
210 36 1
210 37 1
210 38 1
210 39 0
210 40 1
210 41 1
210 42 1
210 43 1
210 44 0
210 45 0
210 46 1
210 47 1
210 48 0
210 49 0
220 0 0
220 1 1
220 2 1
220 3 0
220 4 0
220 5 1
220 6 1
220 7 1
220 8 0
220 9 1
220 10 1
220 11 1
220 12 0
220 13 1
220 14 0
220 15 1
220 16 0
220 17 1
220 18 1
220 19 0
220 20 1
220 21 0
220 22 1
220 23 1
220 24 0
220 25 1
220 26 1
220 27 1
220 28 1
220 29 0
220 30 1
220 31 1
220 32 1
220 33 1
220 34 1
220 35 1
220 36 1
220 37 1
220 38 1
220 39 0
220 40 1
220 41 1
220 42 1
220 43 1
220 44 0
220 45 0
220 46 1
220 47 1
220 48 0
220 49 0
230 0 0
230 1 1
230 2 1
230 3 0
230 4 0
230 5 1
230 6 1
230 7 1
230 8 0
230 9 1
230 10 1
230 11 1
230 12 0
230 13 0
230 14 0
230 15 1
230 16 0
230 17 1
230 18 0
230 19 0
230 20 1
230 21 0
230 22 1
230 23 1
230 24 0
230 25 1
230 26 1
230 27 1
230 28 0
230 29 0
230 30 1
230 31 1
230 32 1
230 33 1
230 34 1
230 35 1
230 36 1
230 37 0
230 38 1
230 39 0
230 40 0
230 41 1
230 42 1
230 43 1
230 44 0
230 45 0
230 46 0
230 47 1
230 48 0
230 49 0
240 0 0
240 1 0
240 2 1
240 3 0
240 4 0
240 5 1
240 6 1
240 7 1
240 8 0
240 9 1
240 10 1
240 11 1
240 12 0
240 13 0
240 14 0
240 15 1
240 16 0
240 17 1
240 18 0
240 19 0
240 20 1
240 21 0
240 22 1
240 23 1
240 24 0
240 25 1
240 26 1
240 27 1
240 28 0
240 29 0
240 30 1
240 31 1
240 32 1
240 33 1
240 34 1
240 35 1
240 36 1
240 37 0
240 38 1
240 39 0
240 40 0
240 41 1
240 42 1
240 43 1
240 44 0
240 45 0
240 46 0
240 47 1
240 48 0
240 49 0
250 0 0
250 1 0
250 2 1
250 3 0
250 4 0
250 5 1
250 6 0
250 7 1
250 8 0
250 9 1
250 10 1
250 11 0
250 12 0
250 13 0
250 14 0
250 15 0
250 16 0
250 17 1
250 18 0
250 19 0
250 20 1
250 21 0
250 22 1
250 23 1
250 24 0
250 25 1
250 26 1
250 27 1
250 28 0
250 29 0
250 30 1
250 31 1
250 32 0
250 33 0
250 34 1
250 35 1
250 36 1
250 37 0
250 38 1
250 39 0
250 40 0
250 41 0
250 42 1
250 43 1
250 44 0
250 45 0
250 46 0
250 47 1
250 48 0
250 49 0
260 0 0
260 1 0
260 2 1
260 3 0
260 4 0
260 5 1
260 6 0
260 7 1
260 8 0
260 9 1
260 10 1
260 11 0
260 12 0
260 13 0
260 14 0
260 15 0
260 16 0
260 17 1
260 18 0
260 19 0
260 20 0
260 21 0
260 22 1
260 23 1
260 24 0
260 25 1
260 26 1
260 27 0
260 28 0
260 29 0
260 30 0
260 31 1
260 32 0
260 33 0
260 34 0
260 35 1
260 36 1
260 37 0
260 38 1
260 39 0
260 40 0
260 41 0
260 42 1
260 43 1
260 44 0
260 45 0
260 46 0
260 47 1
260 48 0
260 49 0
270 0 0
270 1 0
270 2 0
270 3 0
270 4 0
270 5 1
270 6 0
270 7 1
270 8 0
270 9 0
270 10 0
270 11 0
270 12 0
270 13 0
270 14 0
270 15 0
270 16 0
270 17 0
270 18 0
270 19 0
270 20 0
270 21 0
270 22 0
270 23 1
270 24 0
270 25 1
270 26 1
270 27 0
270 28 0
270 29 0
270 30 0
270 31 1
270 32 0
270 33 0
270 34 0
270 35 1
270 36 0
270 37 0
270 38 0
270 39 0
270 40 0
270 41 0
270 42 1
270 43 0
270 44 0
270 45 0
270 46 0
270 47 1
270 48 0
270 49 0
280 0 0
280 1 0
280 2 0
280 3 0
280 4 0
280 5 1
280 6 0
280 7 1
280 8 0
280 9 0
280 10 0
280 11 0
280 12 0
280 13 0
280 14 0
280 15 0
280 16 0
280 17 0
280 18 0
280 19 0
280 20 0
280 21 0
280 22 0
280 23 1
280 24 0
280 25 1
280 26 1
280 27 0
280 28 0
280 29 0
280 30 0
280 31 0
280 32 0
280 33 0
280 34 0
280 35 1
280 36 0
280 37 0
280 38 0
280 39 0
280 40 0
280 41 0
280 42 1
280 43 0
280 44 0
280 45 0
280 46 0
280 47 0
280 48 0
280 49 0
290 0 0
290 1 0
290 2 0
290 3 0
290 4 0
290 5 1
290 6 0
290 7 0
290 8 0
290 9 0
290 10 0
290 11 0
290 12 0
290 13 0
290 14 0
290 15 0
290 16 0
290 17 0
290 18 0
290 19 0
290 20 0
290 21 0
290 22 0
290 23 1
290 24 0
290 25 1
290 26 1
290 27 0
290 28 0
290 29 0
290 30 0
290 31 0
290 32 0
290 33 0
290 34 0
290 35 1
290 36 0
290 37 0
290 38 0
290 39 0
290 40 0
290 41 0
290 42 0
290 43 0
290 44 0
290 45 0
290 46 0
290 47 0
290 48 0
290 49 0
294.49999999999847 0 0
294.49999999999847 1 0
294.49999999999847 2 0
294.49999999999847 3 0
294.49999999999847 4 0
294.49999999999847 5 1
294.49999999999847 6 0
294.49999999999847 7 0
294.49999999999847 8 0
294.49999999999847 9 0
294.49999999999847 10 0
294.49999999999847 11 0
294.49999999999847 12 0
294.49999999999847 13 0
294.49999999999847 14 0
294.49999999999847 15 0
294.49999999999847 16 0
294.49999999999847 17 0
294.49999999999847 18 0
294.49999999999847 19 0
294.49999999999847 20 0
294.49999999999847 21 0
294.49999999999847 22 0
294.49999999999847 23 1
294.49999999999847 24 0
294.49999999999847 25 0
294.49999999999847 26 1
294.49999999999847 27 0
294.49999999999847 28 0
294.49999999999847 29 0
294.49999999999847 30 0
294.49999999999847 31 0
294.49999999999847 32 0
294.49999999999847 33 0
294.49999999999847 34 0
294.49999999999847 35 1
294.49999999999847 36 0
294.49999999999847 37 0
294.49999999999847 38 0
294.49999999999847 39 0
294.49999999999847 40 0
294.49999999999847 41 0
294.49999999999847 42 0
294.49999999999847 43 0
294.49999999999847 44 0
294.49999999999847 45 0
294.49999999999847 46 0
294.49999999999847 47 0
294.49999999999847 48 0
294.49999999999847 49 0

Total energy is about 265J.

deepa_2111 06-28-2011 06:45 AM

@ Exidus,

yes ! now, try printing out the value of amount, and note what happens when 'new_level' falls below 0.

exidus 06-28-2011 09:01 AM

@ deepa_2111

I dont know how to print out the value of amount. Can you help me with this?
I noticed that total energy from leach.out is a sum of energy from all nodes from file leach.energy at the end of simulation. Every node has this number higher than 2.

deepa_2111 06-28-2011 09:07 AM

@ Exidus,
That is the problem. the simulation is counting the nodes' energy even after it dies.
After uncommenting the print statement, rebuild. and then run. check leach.out file. The printed values will be there.

helyos 06-29-2011 03:09 AM

@exidus Can you please tell me the steps to reduce the number of nodes to 50 and create a new topology file for 50 nodes with genscen?

exidus 06-30-2011 08:06 AM

@deepa_2111
I still can not find values of amount in leach.out.

@helyos
1. You can create a new topology file with a file mit/uAmps/genscen. Change these lines in this file
Code:

set outf [open "your_new_file.txt" w]
set num_nodes 100 // set number what you want. E.g 50

2. Then run command ns genscen and you will see new topology file your_new_file.txt
3. Change lines in the file leach_test
Code:

topology_file="mit/uAMPS/sims/your_new_file.txt"
and

Code:

# Number of nodes.  WARNING!  This should be 1 higher then the number
#  of nodes generated in the scenario.
nn=51

4. Now you can run simulation with 50 nodes.

helyos 06-30-2011 10:14 AM

Thank you @exidus . I will try.

deepa_2111 06-30-2011 11:17 PM

look at the bottom of the page ... it shoud be there.
Have you integrated all the changes from the MIT Code ?

helyos 07-03-2011 08:53 AM

Can be the output of LEACH seen in nam(network animator) somehow?

exidus 07-07-2011 04:26 AM

Sorry about the late reply.

@deepa_2111
I see only data which are send, total energy, total data and total alive in leach.out file, but I cant see amount energy.
Can you please send me email with your changed MIT files on tomas.takacs@gmail.com ?
Thanks

@helyos
I think no.

exidus 07-19-2011 06:20 AM

Hi guys.
I have one question. Is here somebody who tried to simulate a protocol PEGASIS in ns2? Thanks for answer.

@deepa_2111
Can you please send me your changed MIT files. Thanks a lot.

ssohrab2003 07-20-2011 03:36 PM

Permission denied
 
I run the steps of installing Leach protocol, but I face the below error when I run this command : ./test

error is : bash: ./test: Permission denied

what I should to do for solve this problem?

Thank you for your time and reply.

knudfl 07-20-2011 03:51 PM

Post # 118 @ssohrab2003 : Welcome to LQ.

Well, if the file isn't executable, it can be run with : 'sh test'.

I guess, you wouldn't have come as far as to using the 'test' script,
if you had no /bin/bash.

ssohrab2003 07-20-2011 05:41 PM

Permission denied leach protocol in ns2
 
Thank you for your reply,

How can I have bash file? I couldn't found it in the bin folder.

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?

farab 09-03-2011 02:36 PM

@ jimctu
I searched the mit directory by simple "grep dst_" and I found there are 3 files use this old method:

ns-bsapp.tcl
ns-leach.tcl
ns-mte.tcl

To get rid off this warning open them with any text editor like gedit, ctrl+h search dst_ and replace with dst_addr_
They are located in mit/uAMPS.

jimctu 09-04-2011 04:26 PM

Thank you Farab! Now the warnings are gone...
but I still get that energy consumption above 200J even though I have made the changes suggested by deepa =T
there was another thing that should have been done to solve this?

farab 09-04-2011 04:41 PM

Quote:

Originally Posted by jimctu (Post 4461436)
Thank you Farab! Now the warnings are gone...
but I still get that energy consumption above 200J even though I have made the changes suggested by deepa =T
there was another thing that should have been done to solve this?

Do you mean the energy in lines like this in leach.out?

At 525.70000000005098:
Total Energy = 290.75993866236303
Total Data = 50473
Total Alive = 4

jimctu 09-04-2011 04:59 PM

yes! Exactly this Farab...it shouldn't be below 200J? As my network configuration has 100 nodes with 2J each.

farab 09-05-2011 12:05 AM

I think this is not the sum of the nodes energy. maybe it shows the total energy consumed by network as it shows the total data transfered in line after. or maybe it considered the ack packes from BS too.
I dont know...
have you ns-2.27 or ns-2.25 installed? if yes test the result there.

monazEssam 09-05-2011 05:39 AM

@exidus:
Thanks for you support to me but i still have a question we are running the leach using the test file in ns2.34 folder and in this file "wireless-demo-csci694.tcl" file is used where in it the Number of nodes is 100 nodes and the trace file used is "694demo.tr "

but in the test file , the "./leach_test" is run and if you open it you will find it use "tcl/ex/wireless.tcl" as its tcl file and if you open "tcl/ex/wireless.tcl" file you will find the number of nodes is 51 nodes and the trace file is "out.tr"

so I got confused about which tcl and trace files should i take in my consideration when i run the leach ?

farab 09-05-2011 04:07 PM

Quote:

Originally Posted by monazEssam (Post 4461894)
@exidus:
Thanks for you support to me but i still have a question we are running the leach using the test file in ns2.34 folder and in this file "wireless-demo-csci694.tcl" file is used where in it the Number of nodes is 100 nodes and the trace file used is "694demo.tr "

but in the test file , the "./leach_test" is run and if you open it you will find it use "tcl/ex/wireless.tcl" as its tcl file and if you open "tcl/ex/wireless.tcl" file you will find the number of nodes is 51 nodes and the trace file is "out.tr"

so I got confused about which tcl and trace files should i take in my consideration when i run the leach ?

Your should always run leach by "./leach_test" and if you take a look at leach_test itself, you see for example the number of node (nn) or other parameters that will push to "tcl/ex/wireless.tcl" and force it to ignore its preset values and use these parameters instead.
finally your simulation result is in : /mit/leach_sims
I have made some awk and script and graphs for energy consummation and number and alive nodes that I can share them with anyone who interested in.

jimctu 09-05-2011 04:41 PM

I don't now farab...
tomorrow I'll have a look at how the energy consumption is made...
but i still think there is something wrong with this...

by the way, can you send me your awk scripts? =)

knudfl 09-05-2011 11:36 PM

# 142 @farab
Quote:

I have made some awk and script and graphs for energy consummation and number
and alive nodes that I can share them with anyone who interested in.
Suggest : Put the scripts in a folder ( leach-scripts ) and tar
the folder ( tar -cf ).
... And upload the "leach-scripts.tar" to Google Docs ( Shared ),
so everybody can download the scripts.

( Please include a text file in the folder telling what they are used for.)

Thank you.
.

farab 09-06-2011 01:55 AM

Here is all trace file of LEACH protocol on ubuntu 11.04.

Notes:

1. You shold have "Evince" installed as document reader for .eps files.
2. You shold have Last version of "xgraph". You can download it here: http://xgraph.org/linux/xgraph_1.39.tar.gz
root login and extract xgraph_1.39.tar.gz into /usr/bin.
more info: http://xgraph.org.
3. Simply run "energy", "alive" and "dead" by "./" or "sh" in terminal or double click and select "Run".
4. You can copy them to your leach_sims folder and test them on your result of simulation.
5. More updates is on the way.
6. farabf33@gmail.com for any questions.

jimctu 09-06-2011 08:43 AM

I noticed something weird...
when I modify any leach file I should go to the ns-2.34 and I do a make clean and make commands
but I think the changes I made are not being executed...there is anything else it must be done after you change the files?

when I tried to run the Leach-c, I got this error:

Code:


can't read "env(uAMPS_LIBRARY)": no such variable
    while executing
"source $env(uAMPS_LIBRARY)/ns-leach.tcl"
    (file "tcl/mobility/leach-c.tcl" line 7)
    invoked from within
"source.orig tcl/mobility/leach-c.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)

so I changed the file leach-c.tcl that was like this

Code:

source $env(uAMPS_LIBRARY)/ns-leach.tcl
to

Code:

source mit/uAMPS/ns-leach.tcl
source mit/uAMPS/ns-leach-c.tcl

it should have solved my problem, but I still keep getting the same error above, even after I changed the file and there is no more env(uAMPS_LIBRARY) on it.

monazEssam 09-06-2011 01:35 PM

@farab
thanks for your replay, i want u to send me the awk file for computing the average consumption in leach and if you have any other awk scripts on my Email: monaz.essam@gmail.com

also i have another question, I'd like to use some encryption functions from cryptopp library but i can't add it to the NS2, so can anyone plz help me with specified steps what should i do to add this library to ns2?

plzzz if anyone can help, replay me as soon as possible as i need it badly

thanks in advance

exidus 09-07-2011 02:57 PM

@jimctu

I had a problem with energy comsumption too and I have already done changes from deepa too. I found out that if you change .cc or .h file, then it is necessary to do these commands:
make clean
make depend
make

sudo make install

After this you can see changes. I hope that this will be helpful for you.

jimctu 09-07-2011 07:12 PM

Thank you Exidus!
forgot the make install...
now it worked perfectly! =D

farab 09-09-2011 02:47 PM

Quote:

Originally Posted by jimctu (Post 4464404)
Thank you Exidus!
forgot the make install...
now it worked perfectly! =D

could you please tell me how did you force it to reduce energy comsumption and wich files you edited?
thank you...


All times are GMT -5. The time now is 10:31 AM.