[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] Really Strange Results



Hello All,

I was modifying energy-model.h and getting really strange results - I was
trying to add other features and I was finding out that it would stop
working - though the code I was adding was not at all complex - nor was it
interfereing with other code.

In order to narrow down what the problem was I kept eliminiating lines of
code until I had only two left -  adding two integers to the set of
protected variables in energy-model.h

The two lines were:

	int number_of_tx_;
	int number_of_rc_;

(around line 160 in the ns2-1.b7 version of energy-model.h)

The scenario I was running would put out quite big nam/tr files (over
20 Megs each) - but with the two lines aboe around 20 K each.

I am including the tcl files along with the modified energy-model.h file.
I would appreciate an explanation as to why adding the above two lines
seems to hose up the system.

Thanks

raju
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 
 *
 * Copyright (c) 1997, 2000 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.
 * 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: /nfs/jade/vint/CVSROOT/ns-2/energy-model.h,v 1.11 2000/08/31 20:11:49 haoboy Exp $
 */

// Contributed by Satish Kumar ([email protected])

#ifndef ns_energy_model_h_
#define ns_energy_model_h_

#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#include "config.h"
#include "trace.h"
#include "rng.h"

const int CHECKFREQ = 1;
const int MAX_WAITING_TIME = 11;

class EnergyModel;

class AdaptiveFidelityEntity : public Handler {
public:  
	AdaptiveFidelityEntity(EnergyModel *nid) : nid_(nid) {} 

	virtual void start();
	virtual void handle(Event *e);

	virtual void adapt_it();
	inline void set_sleeptime(float t) {sleep_time_ = t;}
	inline void set_sleepseed(float t) {sleep_seed_ = t;}

protected:
        EnergyModel *nid_;
	Event intr;
	float  sleep_time_;
	float sleep_seed_;
	float  idle_time_;
};

class SoftNeighborHandler : public Handler {
public:
	SoftNeighborHandler(EnergyModel *nid) {
		nid_ = nid;
	}
	virtual void start();
	virtual void handle(Event *e); 
protected:
	EnergyModel *nid_;
	Event  intr;
};

class MobileNode;
class EnergyModel : public TclObject {
public:
	EnergyModel(MobileNode* n, double energy, double l1, double l2) :
		energy_(energy), initialenergy_(energy), 
		level1_(l1), level2_(l2), node_(n), 
		sleep_mode_(0), total_sleeptime_(0), total_rcvtime_(0), 
		total_sndtime_(0), powersavingflag_(0), 
		last_time_gosleep(0), max_inroute_time_(300), maxttl_(5), 
//		number_of_tx_(0), number_of_rc_(0), 
		adaptivefidelity_(0), node_on_(true) 
	{
		neighbor_list.neighbor_cnt_ = 0;
		neighbor_list.head = NULL;
	}

	inline double energy() const { return energy_; }
	inline double initialenergy() const { return initialenergy_; }
	inline double level1() const { return level1_; }
	inline double level2() const { return level2_; }
	inline void setenergy(double e) { energy_ = e; }

//	inline int number_of_tx() const { return number_of_tx_; }
//	inline int number_of_rc() const { return number_of_rc_; }

	virtual void DecrTxEnergy(double txtime, double P_tx);
	virtual void DecrRcvEnergy(double rcvtime, double P_rcv);
	virtual void DecrIdleEnergy(double idletime, double P_idle);
	inline virtual double MaxTxtime(double P_tx) {
		return(energy_/P_tx);
	}
	inline virtual double MaxRcvtime(double P_rcv) {
		return(energy_/P_rcv);
	}
	inline virtual double MaxIdletime(double P_idle) {
		return(energy_/P_idle);
	}

	void add_neighbor(u_int32_t);      // for adaptive fidelity
	void scan_neighbor();
	inline int getneighbors() { return neighbor_list.neighbor_cnt_; }

	double level1() { return level1_; }
	double level2() { return level2_; }
	inline int sleep() { return sleep_mode_; }
	inline int state() { return state_; }
	inline float state_start_time() { return state_start_time_; }
	inline float& max_inroute_time() { return max_inroute_time_; }
	inline int& adaptivefidelity() { return adaptivefidelity_; }
	inline int& powersavingflag() { return powersavingflag_; }
	inline bool& node_on() { return node_on_; }
	inline float& total_sndtime() { return total_sndtime_; }
	inline float& total_rcvtime() { return total_rcvtime_; }
	inline float& total_sleeptime() { return total_sleeptime_; }
	inline AdaptiveFidelityEntity* afe() { return afe_; }
	inline int& maxttl() { return maxttl_; }

	virtual void set_node_sleep(int);
	virtual void set_node_state(int);
	virtual void add_rcvtime(float t) {total_rcvtime_ += t;}
	virtual void add_sndtime(float t) {total_sndtime_ += t;}

	void start_powersaving();

	// Sleeping state
	enum SleepState { WAITING = 0, POWERSAVING = 1, INROUTE = 2 };

protected:
	double energy_;
	double initialenergy_;
	double level1_;
	double level2_;

	int number_of_tx_;
	int number_of_rc_;

	MobileNode *node_;

	// XXX this structure below can be implemented by ns's LIST
	struct neighbor_list_item {
		u_int32_t id;        		// node id
		int       ttl;    		// time-to-live
		neighbor_list_item *next; 	// pointer to next item
	};

	struct {
		int neighbor_cnt_;   // how many neighbors in this list
		neighbor_list_item *head; 
	} neighbor_list;
	SoftNeighborHandler *snh_;

      	int sleep_mode_;	 // = 1: radio is turned off
	float total_sleeptime_;  // total time of radio in off mode
       	float total_rcvtime_;	 // total time in receiving data
	float total_sndtime_;	 // total time in sending data
	int powersavingflag_;    // Is BECA activated ?
	float last_time_gosleep; // time when radio is turned off
	float max_inroute_time_; // maximum time that a node can remaining
				 // active 
	int maxttl_;		 // how long a node can keep its neighbor
				 // list. For AFECA only.
	int state_;		 // used for AFECA state 
	float state_start_time_; // starting time of one AFECA state
	int adaptivefidelity_;   // Is AFECA activated ?
       	AdaptiveFidelityEntity *afe_;

	bool node_on_;   	 // on-off status of this node -- Chalermek
};


#endif // ns_energy_model_h

# Copyright (c) 1999 Regents of the University of Southern 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.
# 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.
# wireless1.tcl
# A simple example for wireless simulation

# ======================================================================
# Define options
# ======================================================================

set val(chan)       Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        Queue/DropTail/PriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(x)              670   ;# X dimension of the topography
set val(y)              670   ;# Y dimension of the topography
set val(ifqlen)         50            ;# max packet in ifq
set val(seed)           0.0
set val(adhocRouting)   DSR
set val(nn)             10             ;# how many nodes are simulated
set opt(energymodel)    EnergyModel     ;
set opt(initialenergy)  30            ;# Initial energy in Joules
set val(cp)             "cbr-10-test" 
set opt(sc)             "scen-10-test" 
set val(stop)           400.0           ;# simulation time

# =====================================================================
# Main Program
# ======================================================================

#
# Initialize Global Variables
#

# create simulator instance

set ns_		[new Simulator]

# setup topography object

set topo	[new Topography]

# create trace object for ns and nam

set tracefd	[open wireless-gw-out.tr w]
set namtrace    [open wireless-gw-out.nam w]

$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

# define topology
$topo load_flatgrid $val(x) $val(y)

#
# Create God
#
set god_ [create-god $val(nn)]


#
# define how node should be created
#

#global node setting

$ns_ node-config -adhocRouting $val(adhocRouting) \
                 -llType $val(ll) \
                 -macType $val(mac) \
                 -ifqType $val(ifq) \
                 -ifqLen $val(ifqlen) \
                 -antType $val(ant) \
                 -propType $val(prop) \
                 -phyType $val(netif) \
                 -channelType $val(chan) \
		 -energyModel $opt(energymodel) \
		 -rxPower 0.3 \
		 -txPower 0.6 \
		 -initialEnergy $opt(initialenergy) \
		 -topoInstance $topo \
		 -agentTrace OFF \
                 -routerTrace OFF \
                 -macTrace ON 

#
#  Create the specified number of nodes [$val(nn)] and "attach" them
#  to the channel. 

for {set i 0} {$i < $val(nn) } {incr i} {
	set node_($i) [$ns_ node]	
	$node_($i) random-motion 0		;# disable random motion
}


# 
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)

# 
# Define traffic model
#
puts "Loading scenario file..."
source $opt(sc)

# Define node initial position in nam

for {set i 0} {$i < $val(nn)} {incr i} {

    # 20 defines the node size in nam, must adjust it according to your scenario
    # The function must be called after mobility model is defined
    
    $ns_ initial_node_pos $node_($i) 20
}


#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(stop).0 "$node_($i) reset";
}

$ns_ at  $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"

puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $opt(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"

puts "Starting Simulation..."
$ns_ run






set god_ [God instance]
$ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 170.519203111152 3.371785899154"
$ns_ at 51.000000000000 "$node_(1) setdest 221.826585497093 80.855495003839 14.909259208114"
$ns_ at 33.000000000000 "$node_(0) setdest 89.663708107313 283.494644426442 19.153832288917"
$god_ set-dist 1 2 2
$god_ set-dist 0 2 3
$god_ set-dist 0 1 1
$node_(2) set Z_ 0.000000000000
$node_(2) set Y_ 199.373306816804
$node_(2) set X_ 591.256560093833
$node_(1) set Z_ 0.000000000000
$node_(1) set Y_ 345.357731779204
$node_(1) set X_ 257.046298323157
$node_(0) set Z_ 0.000000000000
$node_(0) set Y_ 239.438009831261
$node_(0) set X_ 83.364418416244

$node_(4) set Z_ 0.000000000000
$node_(4) set Y_ 100
$node_(4) set X_ 100

$node_(5) set Z_ 0.000000000000
$node_(5) set Y_ 200
$node_(5) set X_ 200

$node_(6) set Z_ 0.000000000000
$node_(6) set Y_ 300
$node_(6) set X_ 300

$node_(7) set Z_ 0.000000000000
$node_(7) set Y_ 400
$node_(7) set X_ 400

$node_(8) set Z_ 0.000000000000
$node_(8) set Y_ 550
$node_(8) set X_ 550

$node_(9) set Z_ 0.000000000000
$node_(9) set Y_ 150
$node_(9) set X_ 350

#
# 0 connecting to 8 at time 127.93667922166023
#
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(8) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 4.0
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 127.93667922166023 "$cbr_(0) start"

set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(9) $tcp
$ns_ attach-agent $node_(8) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 150.00000000000000 "$ftp start"