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

Re: [ns] Creating new variable in c++ & accessing via TCL??



read ns manual section 3.4.2 'variable bindings'.

- difa

On Wed, 21 Nov 2001, Susan Tsao wrote:

> Hello,
>
> I created a new variable in mac-802_11.*  file, which I like to access
> via
> my TCL script. However, it doesn't work. Can someone please tell me
> what I did wrong?
> ------------------------------------------------------------------------
> ---------------------------------
>
> I created a variable called 'collision_count' which counts the number of
>
> mac-802_11 collisions.  And I like to access this value at the end of my
> simulation.
>
> 3 steps:
>
> 1) Added following line to mac-802_11.h:
>
> 	class Mac802_11 : public Mac {
> 		private:
> 			int  collision_count;      	// added a
> private data memeber
> 	};
>
>
> 2) Changes to mac-802_11.cc:
> 	a) Initialize collison_count =0 in the constructor
> Mac802_11::Mac802_11( )
> 	b) Increment "collision_count"  as follows
>
> 	Mac802_11::collision(Packet *p)  {
>
>    	   if(TX_Time(p) > mhRecv_.expire()) {
>                         mhRecv_.stop();
>                         discard(pktRx_, DROP_MAC_COLLISION);
> 		collision_count+=1;			// **** i  added
> this line
>                         pktRx_ = p;
>                         mhRecv_.start(TX_Time(pktRx_));
>                 }
>                 else {
>                         discard(p, DROP_MAC_COLLISION);
> 		collision_count +=1;			// **** i added
> this line
>                 }
>
> 3) My simulations consists of several wireless node sending packets to a
> base station.
>     And I want to access "colllision_count" at the end of my
> simulations, so I have following
>     in my TCL script.
>
> set macobject [new Mac/802_11]
> $ns_ at $simulation_endtime "count"
>
> proc count {} {
>         global macobject
>         set colcount [$macobject set collision_count]
>         puts "$count"
> }
>
> 4) run my scripts, but it outputs errors:
>
> ns: count: can't read "collision_count": no such variable
>     while executing
> "subst $[subst $var]"
>     (procedure "_o156" line 5)
>     (SplitObject set line 5)
>     invoked from within
> "$macobject set collision_count"
>     (procedure "count" line 3)
>     invoked from within
> "count"
>
>
> Has anyone done something similar to other classes?
> Any help is appreciated!
>
> Thanks.
>
> susan
>
>