use ns as internal time and export time as ns.
--- a/samples/main-simulator.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/samples/main-simulator.cc Mon Sep 04 13:11:34 2006 +0200
@@ -15,20 +15,22 @@
void
MyModel::start (void)
{
- Simulator::schedule (RelTimeS (10.0),
+ Simulator::schedule (Time::rel_s (10.0),
&MyModel::deal_with_event,
this, Simulator::now ().s ());
}
void
MyModel::deal_with_event (double value)
{
- std::cout << "Member method received event at " << Simulator::now ().s () << " started at " << value << std::endl;
+ std::cout << "Member method received event at " << Simulator::now ().s () <<
+ "s started at " << value << "s" << std::endl;
}
static void
random_function (MyModel *model)
{
- std::cout << "random function received event at " << Simulator::now ().s () << std::endl;
+ std::cout << "random function received event at " <<
+ Simulator::now ().s () << "s" << std::endl;
model->start ();
}
@@ -37,7 +39,7 @@
{
MyModel model;
- Simulator::schedule (AbsTimeS (10.0), &random_function, &model);
+ Simulator::schedule (Time::abs_s (10.0), &random_function, &model);
Simulator::run ();
--- a/src/simulator/event-id.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/event-id.cc Mon Sep 04 13:11:34 2006 +0200
@@ -25,13 +25,13 @@
EventId::EventId ()
: m_event_impl (0),
- m_time (0),
+ m_ns (0),
m_uid (0)
{}
-EventId::EventId (EventImpl *impl, uint64_t time, uint32_t uid)
+EventId::EventId (EventImpl *impl, uint64_t ns, uint32_t uid)
: m_event_impl (impl),
- m_time (time),
+ m_ns (ns),
m_uid (uid)
{}
void
@@ -50,9 +50,9 @@
return m_event_impl;
}
uint64_t
-EventId::get_time (void) const
+EventId::get_ns (void) const
{
- return m_time;
+ return m_ns;
}
uint32_t
EventId::get_uid (void) const
--- a/src/simulator/event-id.h Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/event-id.h Mon Sep 04 13:11:34 2006 +0200
@@ -30,7 +30,7 @@
class EventId {
public:
EventId ();
- EventId (EventImpl *impl, uint64_t time, uint32_t uid);
+ EventId (EventImpl *impl, uint64_t ns, uint32_t uid);
void cancel (void);
bool is_expired (void);
public:
@@ -39,11 +39,11 @@
* subclasses of the Scheduler base class.
*/
EventImpl *get_event_impl (void) const;
- uint64_t get_time (void) const;
+ uint64_t get_ns (void) const;
uint32_t get_uid (void) const;
private:
EventImpl *m_event_impl;
- uint64_t m_time;
+ uint64_t m_ns;
uint32_t m_uid;
};
--- a/src/simulator/scheduler-heap.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/scheduler-heap.cc Mon Sep 04 13:11:34 2006 +0200
@@ -197,7 +197,7 @@
m_heap.push_back (std::make_pair (event, key));
bottom_up ();
store_in_event (event, last ());
- return EventId (event, key.m_time, key.m_uid);
+ return EventId (event, key.m_ns, key.m_uid);
}
EventImpl *
@@ -240,7 +240,7 @@
EventImpl *ev = id.get_event_impl ();
uint32_t i = get_from_event (ev);
Scheduler::EventKey key = m_heap[i].second;
- return (key.m_time == id.get_time () &&
+ return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
}
}; // namespace ns3
--- a/src/simulator/scheduler-list.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/scheduler-list.cc Mon Sep 04 13:11:34 2006 +0200
@@ -45,7 +45,7 @@
memcpy ((char *)&(internal_iterator), (char *)&i, sizeof (void *));
EventImpl *ev = i->first;
ev->set_internal_iterator (internal_iterator);
- return EventId (ev, key.m_time, key.m_uid);
+ return EventId (ev, key.m_ns, key.m_uid);
}
SchedulerList::EventsI
SchedulerList::get_iterator (EventId id)
@@ -101,7 +101,7 @@
{
EventsI i = get_iterator (id);
*key = i->second;
- assert (key->m_time == id.get_time () &&
+ assert (key->m_ns == id.get_ns () &&
key->m_uid == id.get_uid ());
EventImpl *ev = i->first;
m_events.erase (i);
@@ -113,7 +113,7 @@
{
EventsI i = get_iterator (id);
Scheduler::EventKey key = i->second;
- return (key.m_time == id.get_time () &&
+ return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
}
--- a/src/simulator/scheduler-map.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/scheduler-map.cc Mon Sep 04 13:11:34 2006 +0200
@@ -66,7 +66,7 @@
std::pair<EventMapI,bool> result = m_list.insert (std::make_pair (key, event));
assert (result.second);
store_in_event (event, result.first);
- return EventId (event, key.m_time, key.m_uid);
+ return EventId (event, key.m_ns, key.m_uid);
}
bool
@@ -113,7 +113,7 @@
{
EventMapI i = get_from_event (id.get_event_impl ());
Scheduler::EventKey key = i->first;
- return (key.m_time == id.get_time () &&
+ return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
}
--- a/src/simulator/scheduler.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/scheduler.cc Mon Sep 04 13:11:34 2006 +0200
@@ -35,9 +35,9 @@
ns3::Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
{
assert (a.m_uid != b.m_uid);
- if (a.m_time < b.m_time) {
+ if (a.m_ns < b.m_ns) {
return true;
- } else if (a.m_time == b.m_time && a.m_uid < b.m_uid) {
+ } else if (a.m_ns == b.m_ns && a.m_uid < b.m_uid) {
return true;
} else {
return false;
--- a/src/simulator/scheduler.h Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/scheduler.h Mon Sep 04 13:11:34 2006 +0200
@@ -32,7 +32,7 @@
class Scheduler {
public:
struct EventKey {
- uint64_t m_time;
+ uint64_t m_ns;
uint32_t m_uid;
};
class EventKeyCompare {
--- a/src/simulator/simulator.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/simulator.cc Mon Sep 04 13:11:34 2006 +0200
@@ -75,7 +75,7 @@
Scheduler *m_events;
uint32_t m_uid;
uint32_t m_current_uid;
- uint64_t m_current_us;
+ uint64_t m_current_ns;
std::ofstream m_log;
std::ifstream m_input_log;
bool m_log_enable;
@@ -91,7 +91,7 @@
m_events = events;
m_uid = 0;
m_log_enable = false;
- m_current_us = 0;
+ m_current_ns = 0;
}
SimulatorPrivate::~SimulatorPrivate ()
@@ -122,10 +122,10 @@
Scheduler::EventKey next_key = m_events->peek_next_key ();
m_events->remove_next ();
TRACE ("handle " << next_ev);
- m_current_us = next_key.m_time;
+ m_current_ns = next_key.m_ns;
m_current_uid = next_key.m_uid;
if (m_log_enable) {
- m_log << "e "<<next_key.m_uid << " " << next_key.m_time << std::endl;
+ m_log << "e "<<next_key.m_uid << " " << next_key.m_ns << std::endl;
}
next_ev->invoke ();
delete next_ev;
@@ -141,7 +141,7 @@
{
assert (!m_events->is_empty ());
Scheduler::EventKey next_key = m_events->peek_next_key ();
- return AbsTimeUs (next_key.m_time);
+ return AbsTimeUs (next_key.m_ns);
}
@@ -149,7 +149,7 @@
SimulatorPrivate::run (void)
{
while (!m_events->is_empty () && !m_stop &&
- (m_stop_at == 0 || m_stop_at > next ().us ())) {
+ (m_stop_at == 0 || m_stop_at > next ().ns ())) {
process_one_event ();
}
m_log.close ();
@@ -164,7 +164,7 @@
void
SimulatorPrivate::stop_at (Time at)
{
- m_stop_at = at.us ();
+ m_stop_at = at.ns ();
}
EventId
SimulatorPrivate::schedule (Time time, EventImpl *event)
@@ -172,18 +172,18 @@
if (time.is_destroy ()) {
m_destroy.push_back (std::make_pair (event, m_uid));
if (m_log_enable) {
- m_log << "id " << m_current_uid << " " << now ().us () << " "
+ m_log << "id " << m_current_uid << " " << now ().ns () << " "
<< m_uid << std::endl;
}
m_uid++;
//XXX
return EventId ();
}
- assert (time.us () >= now ().us ());
- Scheduler::EventKey key = {time.us (), m_uid};
+ assert (time.ns () >= now ().ns ());
+ Scheduler::EventKey key = {time.ns (), m_uid};
if (m_log_enable) {
- m_log << "i "<<m_current_uid<<" "<<now ().us ()<<" "
- <<m_uid<<" "<<time.us () << std::endl;
+ m_log << "i "<<m_current_uid<<" "<<now ().ns ()<<" "
+ <<m_uid<<" "<<time.ns () << std::endl;
}
m_uid++;
return m_events->insert (event, key);
@@ -191,7 +191,7 @@
Time
SimulatorPrivate::now (void) const
{
- return AbsTimeUs (m_current_us);
+ return Time::abs_ns (m_current_ns);
}
void
@@ -201,8 +201,8 @@
EventImpl *impl = m_events->remove (ev, &key);
delete impl;
if (m_log_enable) {
- m_log << "r " << m_current_uid << " " << now ().us () << " "
- << key.m_uid << " " << key.m_time << std::endl;
+ m_log << "r " << m_current_uid << " " << now ().ns () << " "
+ << key.m_uid << " " << key.m_ns << std::endl;
}
}
@@ -218,7 +218,7 @@
SimulatorPrivate::is_expired (EventId ev)
{
if (ev.get_event_impl () != 0 &&
- ev.get_time () <= now ().us () &&
+ ev.get_ns () <= now ().ns () &&
ev.get_uid () < m_current_uid) {
return false;
}
--- a/src/simulator/time.cc Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/time.cc Mon Sep 04 13:11:34 2006 +0200
@@ -24,36 +24,43 @@
namespace ns3 {
Time::Time ()
- : m_us (0),
+ : m_ns (0),
m_is_destroy (true)
{}
Time::Time (Time const &o)
- : m_us (o.m_us),
+ : m_ns (o.m_ns),
m_is_destroy (o.m_is_destroy)
{}
Time &
Time::operator = (Time const &o)
{
- m_us = o.m_us;
+ m_ns = o.m_ns;
m_is_destroy = o.m_is_destroy;
return *this;
}
-Time::Time (uint64_t us)
- : m_us (us),
+Time::Time (uint64_t ns)
+ : m_ns (ns),
m_is_destroy (false)
{}
double
Time::s (void) const
{
- double us = m_us;
- us /= 1000000;
- return us;
+ double ns = m_ns;
+ ns /= 1000000000;
+ return ns;
}
uint64_t
Time::us (void) const
{
- return m_us;
+ uint64_t us = m_ns / 1000;
+ return us;
+}
+
+uint64_t
+Time::ns (void) const
+{
+ return m_ns;
}
bool
@@ -62,34 +69,67 @@
return m_is_destroy;
}
-Time
-operator + (Time const &lhs, uint64_t delta_us)
+Time
+Time::abs_s (double s)
{
- return AbsTimeUs (lhs.us () + delta_us);
+ int64_t ns = (int64_t)(s * 1000000000.0);
+ return Time (ns);
+}
+Time
+Time::abs_us (uint64_t us)
+{
+ int64_t ns = us * 1000;
+ return Time (ns);
+}
+Time
+Time::abs_ns (uint64_t ns)
+{
+ return Time (ns);
}
-Time
-operator + (Time const &lhs, double delta_s)
+Time
+Time::rel_s (double s)
+{
+ int64_t ns = (int64_t)(s * 1000000000.0);
+ return Time (Simulator::now ().ns () + ns);
+}
+Time
+Time::rel_us (uint64_t us)
{
- uint64_t delta_us = (uint64_t)(int64_t)(delta_s * 1000000.0);
- return AbsTimeUs (lhs.us () + delta_us);
+ return Time (Simulator::now ().ns () + us * 1000);
+}
+Time
+Time::rel_ns (uint64_t ns)
+{
+ return Time (Simulator::now ().ns () + ns);
+}
+
+Time
+Time::now (void)
+{
+ return Time (Simulator::now ().ns ());
+}
+Time
+Time::destroy (void)
+{
+ return Time ();
}
AbsTimeS::AbsTimeS (double s)
- : Time ((uint64_t)(int64_t)(s * 1000000.0))
+ : Time ((uint64_t)(int64_t)(s * 1000000000.0))
{}
AbsTimeUs::AbsTimeUs (uint64_t us)
- : Time (us)
+ : Time (us*1000)
{}
RelTimeS::RelTimeS (double s)
- : Time (Simulator::now () + s)
+ : Time (Simulator::now ().ns () + (int64_t)(s * 1000000000.0))
{}
RelTimeUs::RelTimeUs (uint64_t us)
- : Time (Simulator::now () + us)
+ : Time (Simulator::now ().ns () + us*1000)
{}
NowTime::NowTime ()
- : Time (Simulator::now ().us ())
+ : Time (Simulator::now ().ns ())
{}
DestroyTime::DestroyTime ()
--- a/src/simulator/time.h Mon Sep 04 12:51:11 2006 +0200
+++ b/src/simulator/time.h Mon Sep 04 13:11:34 2006 +0200
@@ -31,19 +31,24 @@
Time &operator = (Time const &o);
double s (void) const;
uint64_t us (void) const;
+ uint64_t ns (void) const;
bool is_destroy (void) const;
+ static Time abs_s (double s);
+ static Time abs_us (uint64_t us);
+ static Time abs_ns (uint64_t ns);
+ static Time rel_s (double s);
+ static Time rel_us (uint64_t us);
+ static Time rel_ns (uint64_t ns);
+ static Time now (void);
+ static Time destroy (void);
protected:
- Time (uint64_t us);
+ Time (uint64_t ns);
Time ();
private:
- uint64_t m_us;
+ uint64_t m_ns;
bool m_is_destroy;
};
-Time operator + (Time const &lhs, uint64_t delta);
-Time operator + (Time const &lhs, double delta);
-
-
class AbsTimeS : public Time {
public:
AbsTimeS (double s);