How to tell Simulator::Schedule to use updated parameters ?

28 views
Skip to first unread message

Shashank

unread,
Apr 26, 2016, 1:29:32 PM4/26/16
to ns-3-users
Consider the example

void func1(){
   p1
++;
   p2
-- ;
}


int main () {


//---//

p1
= 1, p2 =1


System:Schedule( t1, &func1 , obj1)

System:Schedule(t2, &func2 , obj2, p1,p2 )   // when func2 is called it takes intial values of p1,p2 = 1
                                             
// I want it to take the updated values p1 =2 p2 = 0...
//---//.

}




Consider the function func1 changes the values of parameters p1 and p2 during the execution. Now I want to make the next event of func2 to use the updated values of p1 and p2. How can i do this ?  The simulator uses the initial values of the parameters p1 and p2 when the event is scheduled. 
 
I'm trying to implement LEACH protocol using lr-wpan module. In that, when a node receives advertisement it 'updates' the packet to send. The send function is scheduled before hand but the packet isn't the correct one. After updating the packet it appropriately sends to the right source. This problem is identical to the above example. 

Thanks in advance

Tommaso Pecorella

unread,
Apr 26, 2016, 2:43:24 PM4/26/16
to ns-3-users
Hi,

simply put, you can't. However, the point is: you're doing it wrong, that's why you're stuck. You think procedurally, and you should think in OO.
The p1 and p2 variables should be member variables (m_p1, m_p2) and func2 should use them once it's called (assuming that func1 and func2, m_p1 and m_p2 are members of the same class).

Of course I should (at this point) ask you for forgiveness. I shouldn't explain these basic concepts, right ?

T.

Shashank Sheshan

unread,
Apr 26, 2016, 11:51:23 PM4/26/16
to ns-3-...@googlegroups.com
Hey, thanks for the reply. Yes the functions and variables are members of same class. I've found that i need to pass the parameters by reference and not by value.  

Thanks.

PS : Its really nice that people reply quick in this group. Really helps a lot to keep working on NS3 .

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/8t4fCfVdPus/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages