getting the current time

1,588 views
Skip to first unread message

mn

unread,
May 31, 2017, 11:39:01 AM5/31/17
to ns-3-users
hello. i want to get the current time in ns3 and then i can use it for some works. i know that i should use simulator::now() but i used this command in every part of my code and it always show me 0.0

how can i get the current time during simulation

thank you

Konstantinos

unread,
May 31, 2017, 12:00:03 PM5/31/17
to ns-3-users
Hi,

Simulator::Now() gives you the current simulation time. That's it.
The fact that you get 0.0 as result is probably because the time has not advanced, ie. you call it before the simulation has actually started.

Regards,
K

mn

unread,
May 31, 2017, 12:54:42 PM5/31/17
to ns-3-users
i want to set access point in sleep mode. with this command

    Ptr<WifiNetDevice> wifidevice4 = DynamicCast<WifiNetDevice> (apDevices.Get(0));
    Ptr<WifiPhy> wifiphy3 = wifidevice4->GetPhy();
    Simulator::Schedule(Seconds(68), &WifiPhy::ResumeFromSleep, wifiphy3);
    Simulator::Schedule(Seconds(69), &WifiPhy::SetSleepMode, wifiphy3);

how can i write this with simulator::now();

i want to sleep the ap at the current time

Konstantinos

unread,
May 31, 2017, 12:57:39 PM5/31/17
to ns-3-users
You would replace the Seconds() with Simulator::Now(), but you have to be clear what you mean by the current time.
WHEN is that time? Is is after some event? Then you would need to call that after that event.

mehrdad manoochehri

unread,
May 31, 2017, 1:00:41 PM5/31/17
to ns-3-...@googlegroups.com
i want to sleep the AP after sending probe request by stations and passing some conditions

--
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/I0cD8baDVV8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@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.

mehrdad manoochehri

unread,
Jun 2, 2017, 7:34:40 AM6/2/17
to ns-3-...@googlegroups.com
i took current time in my function and used that to schedule AP when it should be gone to sleep mode. but it is 0. what do i have to do?



Konstantinos

unread,
Jun 2, 2017, 8:17:52 AM6/2/17
to ns-3-users
You explained the condition when you want to send the AP to sleep in the previous post
"i want to sleep the AP after sending probe request by stations and passing some conditions"

Have those conditions been met? 
With the information you gave, 'i took current time in my function and used that to schedule AP when it should be gone to sleep mode. but it is 0", I can't help you further. 
Where is 'your function' ? When is it called? 

Stop thinking with sequential C programming. ns-3 is an event-based object oriented program.
Your 'scenario' file is used to 'drive' the simulation. If you want to have processes during run-time, you need to use (traced) callbacks to catch those events (e.g. reception of probe messages, conditions being met, etc). 

mehrdad manoochehri

unread,
Jun 2, 2017, 8:53:06 AM6/2/17
to ns-3-...@googlegroups.com
probe request will be sent from stations after second 10. and according to my algorithm, function will specify that which AP should be gone to sleep mode. i used trace source to get these information. but i do not know how to run the algorithm after that time according my algorithm

Ranida Hamidouche

unread,
Dec 18, 2018, 6:04:56 AM12/18/18
to ns-3-users
I faced the same problem. Could you tell me how to resolve it ? thank you.
Reply all
Reply to author
Forward
0 new messages