LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-01-2011, 08:32 AM   #91
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268

@ asrmaster ::

please read the first couple of posts in :: http://www.linuxquestions.org/questi...2-34-a-860250/
(till about post #15, i guess)

@ keepwalking ::
please read post 193 on http://www.linuxquestions.org/questi...79/page13.html.
This question has been asked and solved in this thread itself. Please back track and read the posts. You should get your solution.
 
Old 06-01-2011, 09:31 AM   #92
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268
@ keepwalking (post #87) : LEACH-C comes along with the LEACH package. You just need to change "alg" variable in leach_test
 
Old 06-03-2011, 03:25 AM   #93
helyos
LQ Newbie
 
Registered: May 2011
Posts: 28

Rep: Reputation: 3
@mav3rick With instructions from this thread i have succeed to install leach protocol on Unbuntu 10.04 and ubuntu 9.10 .
In ubuntu 11.04 i had some problems with compilation.

Last edited by helyos; 06-03-2011 at 03:36 AM.
 
Old 06-03-2011, 03:50 AM   #94
helyos
LQ Newbie
 
Registered: May 2011
Posts: 28

Rep: Reputation: 3
@ deepa_2111 I saw in post #13 http://www.linuxquestions.org/questi...2-34-a-860250/ that you have modified Wireless-Phy.cc and energy.cc . Those modification will minimize the final energy used in simulation?

Thank you
 
Old 06-03-2011, 01:12 PM   #95
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268
@ heylos (#94) : Yes, it limits the energy consumption to a max of 2J/node.
Am wondering if this problem existed on ns2.1b as well. If you get to know, please post your findings .
 
Old 06-07-2011, 04:45 AM   #96
keepwalking
Member
 
Registered: Oct 2010
Posts: 46

Rep: Reputation: 0
Hello every body

I testing the LEACH-C protocol and now in the leach-err file I get the following errors:
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)
May you please help me to solve this errors please.
 
Old 06-13-2011, 06:18 AM   #97
keepwalking
Member
 
Registered: Oct 2010
Posts: 46

Rep: Reputation: 0
Hey everyone
thank for helping me with LEACH-C now it working
 
Old 06-15-2011, 01:41 PM   #98
asrmaster
LQ Newbie
 
Registered: Feb 2011
Posts: 5

Rep: Reputation: 0
Hi Deepa,

This problem no exists in the ns-2.1b5. I was reading the files (WirelessPhy.cc and Energy.cc) in the ns-2.1b5 and no have your changes. Performing simulations, I notice that there are differences in the results. And I don't know the cause of these differences.

Quote:
Originally Posted by deepa_2111 View Post
@ heylos (#94) : Yes, it limits the energy consumption to a max of 2J/node.
Am wondering if this problem existed on ns2.1b as well. If you get to know, please post your findings .
 
Old 06-15-2011, 06:54 PM   #99
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268
@ asrmaster,

thanks for your reply.
So, what i think the reason is :: the difference in how the wireless channel is implemented in ns2.1 and ns2.35. I noticed these changes in channel.cc.

I have noticed that even if a node dies, it still continues to transmit. See for e.g. a portion of my leach.out

Code:
BS Received data 24 , 563.55674803407283 from 24 at time 563.59645539547932
This represents data from nodes: 50 24
Node 24 is DEAD!!!!
BS Received data 24 , 563.75834803407281 from 24 at time 563.80031709153309
This represents data from nodes: 50
As you can see, the Cluster Head 24 is dead. But , it still continues to transmit to the BS. This is due to the way the wireless channel is implemented in later versions of ns2. The MIT changes do not affect this particular model, and hence the differences,
 
Old 06-23-2011, 03:16 AM   #100
helyos
LQ Newbie
 
Registered: May 2011
Posts: 28

Rep: Reputation: 3
Hi @deepa_2111 I made yout modificiations form #13 http://www.linuxquestions.org/questi...2-34-a-860250/ and om leach.out i obtain total energy around 350 . It can't be reduced more?

Also i would like to ask you how can be modified the initial conditions? the given nodes etc?

Thank you in advance

Last edited by helyos; 06-23-2011 at 11:54 AM.
 
Old 06-24-2011, 12:10 AM   #101
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268
@ 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)
 
Old 06-24-2011, 10:40 AM   #102
exidus
LQ Newbie
 
Registered: Jun 2011
Posts: 14

Rep: Reputation: Disabled
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
 
Old 06-25-2011, 12:24 AM   #103
deepa_2111
Member
 
Registered: Apr 2011
Distribution: -
Posts: 179

Rep: Reputation: 268Reputation: 268Reputation: 268
@Exidus,

Hey ! Can you please post the changes you made ? Let me check with the code I have now. Please post your changes here
 
Old 06-25-2011, 06:42 AM   #104
helyos
LQ Newbie
 
Registered: May 2011
Posts: 28

Rep: Reputation: 3
@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?
 
Old 06-25-2011, 09:11 AM   #105
exidus
LQ Newbie
 
Registered: Jun 2011
Posts: 14

Rep: Reputation: Disabled
@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.
 
  


Reply

Tags
leach, leach-warning50, ns2, ns2 ns234, pegasis


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 05:23 AM
labview stopped at "init tmp resource files" on FC4 baosheng Linux - Software 2 09-28-2007 12:02 PM
ORiNOCO WLAN card not working - "failed to allocate resource" hauneboo Linux - Laptop and Netbook 1 11-29-2005 10:08 AM
What "kernel opts" allow PC to power down with "turning energy off"? kornerr Linux - General 1 03-10-2005 01:07 PM
nvidia insmod: "Device or resource busy" w/GeForce 4 MX KeithSpook Linux - Hardware 4 03-03-2004 01:21 PM


All times are GMT -5. The time now is 10:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration