From a23934a4b7111304a9d35d93c6a318f5e179866a Mon Sep 17 00:00:00 2001 From: Guillaume Seguin Date: Sat, 14 Nov 2009 17:47:05 +0100 Subject: [PATCH] Make applications generate traffic within their associated context/node --- examples/emulation/emu-ping.cc | 4 +- examples/ipv6/radvd-two-prefix.cc | 4 +- examples/ipv6/radvd.cc | 4 +- examples/stats/wifi-example-sim.cc | 4 +- examples/tutorial/fifth.cc | 4 +- examples/wireless/wifi-simple-adhoc.cc | 7 +- examples/wireless/wifi-simple-infra.cc | 5 +- examples/wireless/wifi-simple-interference.cc | 10 +-- src/core/object.cc | 18 +++++ src/core/object.h | 20 ++++++ src/devices/wifi/nqap-wifi-mac.cc | 27 ++++++-- src/devices/wifi/nqap-wifi-mac.h | 2 + src/devices/wifi/qap-wifi-mac.cc | 27 ++++++-- src/devices/wifi/qap-wifi-mac.h | 2 + src/helper/application-container.cc | 4 +- .../random-direction-2d-mobility-model.cc | 19 ++++-- .../random-direction-2d-mobility-model.h | 4 +- src/mobility/random-walk-2d-mobility-model.cc | 13 ++-- src/mobility/random-walk-2d-mobility-model.h | 5 +- .../random-waypoint-mobility-model.cc | 19 +++--- src/mobility/random-waypoint-mobility-model.h | 5 +- src/node/application.cc | 68 +++++++++---------- src/node/application.h | 34 +++------- src/node/node-list.cc | 1 + src/node/node.cc | 18 +++++ src/node/node.h | 1 + src/routing/list-routing/ipv4-list-routing.cc | 13 ++++ src/routing/list-routing/ipv4-list-routing.h | 1 + src/routing/olsr/olsr-routing-protocol.cc | 4 +- src/routing/olsr/olsr-routing-protocol.h | 4 +- 30 files changed, 225 insertions(+), 126 deletions(-) diff --git a/examples/emulation/emu-ping.cc b/examples/emulation/emu-ping.cc index 0a9fc0b4f..d4ae019d8 100644 --- a/examples/emulation/emu-ping.cc +++ b/examples/emulation/emu-ping.cc @@ -186,8 +186,8 @@ main (int argc, char *argv[]) Ptr app = CreateObject (); app->SetAttribute ("Remote", Ipv4AddressValue (remoteIp)); node->AddApplication (app); - app->Start (Seconds (1.0)); - app->Stop (Seconds (5.0)); + app->SetStartTime (Seconds (1.0)); + app->SetStopTime (Seconds (5.0)); // // Give the application a name. This makes life much easier when constructing diff --git a/examples/ipv6/radvd-two-prefix.cc b/examples/ipv6/radvd-two-prefix.cc index f382ba52c..bea674c40 100644 --- a/examples/ipv6/radvd-two-prefix.cc +++ b/examples/ipv6/radvd-two-prefix.cc @@ -183,8 +183,8 @@ int main (int argc, char** argv) radvd->AddConfiguration (routerInterface2); r->AddApplication (radvd); - radvd->Start (Seconds (1.0)); - radvd->Stop (Seconds (2.0)); + radvd->SetStartTime (Seconds (1.0)); + radvd->SetStopTime (Seconds (2.0)); /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */ uint32_t packetSize = 1024; diff --git a/examples/ipv6/radvd.cc b/examples/ipv6/radvd.cc index e6be2af22..dbe05ff87 100644 --- a/examples/ipv6/radvd.cc +++ b/examples/ipv6/radvd.cc @@ -123,8 +123,8 @@ int main (int argc, char** argv) radvd->AddConfiguration (routerInterface2); r->AddApplication (radvd); - radvd->Start (Seconds (1.0)); - radvd->Stop (Seconds (10.0)); + radvd->SetStartTime (Seconds (1.0)); + radvd->SetStopTime (Seconds (10.0)); /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */ uint32_t packetSize = 1024; diff --git a/examples/stats/wifi-example-sim.cc b/examples/stats/wifi-example-sim.cc index 71ed007cd..4a8dec963 100644 --- a/examples/stats/wifi-example-sim.cc +++ b/examples/stats/wifi-example-sim.cc @@ -167,12 +167,12 @@ int main(int argc, char *argv[]) { Ptr appSource = NodeList::GetNode(0); Ptr sender = CreateObject(); appSource->AddApplication(sender); - sender->Start(Seconds(1)); + sender->SetStartTime(Seconds(1)); Ptr appSink = NodeList::GetNode(1); Ptr receiver = CreateObject(); appSink->AddApplication(receiver); - receiver->Start(Seconds(0)); + receiver->SetStartTime(Seconds(0)); // Config::Set("/NodeList/*/ApplicationList/*/$Sender/Destination", // Ipv4AddressValue("192.168.0.2")); diff --git a/examples/tutorial/fifth.cc b/examples/tutorial/fifth.cc index 75e8f48b0..3687cec2a 100644 --- a/examples/tutorial/fifth.cc +++ b/examples/tutorial/fifth.cc @@ -210,8 +210,8 @@ main (int argc, char *argv[]) Ptr app = CreateObject (); app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps")); nodes.Get (0)->AddApplication (app); - app->Start (Seconds (1.)); - app->Stop (Seconds (20.)); + app->SetStartTime (Seconds (1.)); + app->SetStopTime (Seconds (20.)); devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeCallback (&RxDrop)); diff --git a/examples/wireless/wifi-simple-adhoc.cc b/examples/wireless/wifi-simple-adhoc.cc index 0a2dcbd79..5336fde31 100644 --- a/examples/wireless/wifi-simple-adhoc.cc +++ b/examples/wireless/wifi-simple-adhoc.cc @@ -80,7 +80,7 @@ static void GenerateTraffic (Ptr socket, uint32_t pktSize, { socket->Send (Create (pktSize)); Simulator::Schedule (pktInterval, &GenerateTraffic, - socket, pktSize,pktCount-1, pktInterval); + socket, pktSize,pktCount-1, pktInterval); } else { @@ -187,8 +187,9 @@ int main (int argc, char *argv[]) // Output what we are doing NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss ); - Simulator::Schedule (Seconds (1.0), &GenerateTraffic, - source, packetSize, numPackets, interPacketInterval); + Simulator::ScheduleWithContext (source->GetNode ()->GetId (), + Seconds (1.0), &GenerateTraffic, + source, packetSize, numPackets, interPacketInterval); Simulator::Run (); Simulator::Destroy (); diff --git a/examples/wireless/wifi-simple-infra.cc b/examples/wireless/wifi-simple-infra.cc index 5422f6a84..d9e31328b 100644 --- a/examples/wireless/wifi-simple-infra.cc +++ b/examples/wireless/wifi-simple-infra.cc @@ -200,8 +200,9 @@ int main (int argc, char *argv[]) // Output what we are doing NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss ); - Simulator::Schedule (Seconds (1.0), &GenerateTraffic, - source, packetSize, numPackets, interPacketInterval); + Simulator::ScheduleWithContext (source->GetNode ()->GetId (), + Seconds (1.0), &GenerateTraffic, + source, packetSize, numPackets, interPacketInterval); Simulator::Stop (Seconds (30.0)); Simulator::Run (); diff --git a/examples/wireless/wifi-simple-interference.cc b/examples/wireless/wifi-simple-interference.cc index 93d2d98e4..e62472fe9 100644 --- a/examples/wireless/wifi-simple-interference.cc +++ b/examples/wireless/wifi-simple-interference.cc @@ -245,11 +245,13 @@ int main (int argc, char *argv[]) // Output what we are doing NS_LOG_UNCOND ("Primary packet RSS=" << Prss << " dBm and interferer RSS=" << Irss << " dBm at time offset=" << delta << " ms"); - Simulator::Schedule (Seconds (startTime), &GenerateTraffic, - source, PpacketSize, numPackets, interPacketInterval); + Simulator::ScheduleWithContext (source->GetNode ()->GetId (), + Seconds (startTime), &GenerateTraffic, + source, PpacketSize, numPackets, interPacketInterval); - Simulator::Schedule (Seconds (startTime + delta/1000000.0), &GenerateTraffic, - interferer, IpacketSize, numPackets, interPacketInterval); + Simulator::ScheduleWithContext (interferer->GetNode ()->GetId (), + Seconds (startTime + delta/1000000.0), &GenerateTraffic, + interferer, IpacketSize, numPackets, interPacketInterval); Simulator::Run (); Simulator::Destroy (); diff --git a/src/core/object.cc b/src/core/object.cc index 79f6bce00..34c35fc50 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -81,6 +81,7 @@ Object::GetTypeId (void) Object::Object () : m_tid (Object::GetTypeId ()), m_disposed (false), + m_started (false), m_aggregates ((struct Aggregates *)malloc (sizeof (struct Aggregates))), m_getObjectCount (0) { @@ -113,6 +114,7 @@ Object::~Object () Object::Object (const Object &o) : m_tid (o.m_tid), m_disposed (false), + m_started (false), m_aggregates ((struct Aggregates *)malloc (sizeof (struct Aggregates))), m_getObjectCount (0) { @@ -158,6 +160,17 @@ Object::DoGetObject (TypeId tid) const } return 0; } +void +Object::Start (void) +{ + uint32_t n = m_aggregates->n; + for (uint32_t i = 0; i < n; i++) + { + Object *current = m_aggregates->buffer[i]; + current->DoStart (); + current->m_started = true; + } +} void Object::Dispose (void) { @@ -264,6 +277,11 @@ Object::DoDispose (void) NS_ASSERT (!m_disposed); } +void +Object::DoStart (void) +{ + NS_ASSERT (!m_started); +} bool Object::Check (void) const diff --git a/src/core/object.h b/src/core/object.h index 4488b351e..f9d6edaed 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -140,6 +140,12 @@ public: */ AggregateIterator GetAggregateIterator (void) const; + /** + * Execute starting code of an object. What this method does is really up + * to the user. + */ + void Start (void); + protected: /** * This function is called by the AggregateObject on all the objects connected in the listed chain. @@ -148,6 +154,15 @@ protected: * additional/special behavior when aggregated to another object. */ virtual void NotifyNewAggregate (); + /** + * This method is called only once by Object::Start. If the user + * calls Object::Start multiple times, DoStart is called only the + * first time. + * + * Subclasses are expected to override this method and _chain up_ + * to their parent's implementation once they are done. + */ + virtual void DoStart (void); /** * This method is called by Object::Dispose or by the object's * destructor, whichever comes first. @@ -250,6 +265,11 @@ private: * has run, false otherwise. */ bool m_disposed; + /** + * Set to true once the DoStart method has run, + * false otherwise + */ + bool m_started; /** * a pointer to an array of 'aggregates'. i.e., a pointer to * each object aggregated to this object is stored in this diff --git a/src/devices/wifi/nqap-wifi-mac.cc b/src/devices/wifi/nqap-wifi-mac.cc index 07e5ec7b1..21f8974d9 100644 --- a/src/devices/wifi/nqap-wifi-mac.cc +++ b/src/devices/wifi/nqap-wifi-mac.cc @@ -90,6 +90,8 @@ NqapWifiMac::NqapWifiMac () m_dca->SetManager (m_dcfManager); m_dca->SetTxOkCallback (MakeCallback (&NqapWifiMac::TxOk, this)); m_dca->SetTxFailedCallback (MakeCallback (&NqapWifiMac::TxFailed, this)); + + m_enableBeaconGeneration = false; } NqapWifiMac::~NqapWifiMac () { @@ -110,6 +112,7 @@ NqapWifiMac::DoDispose (void) m_dca = 0; m_beaconDca = 0; m_stationManager = 0; + m_enableBeaconGeneration = false; m_beaconEvent.Cancel (); WifiMac::DoDispose (); } @@ -118,20 +121,21 @@ void NqapWifiMac::SetBeaconGeneration (bool enable) { NS_LOG_FUNCTION (this << enable); - if (enable) + if (!enable) + { + m_beaconEvent.Cancel (); + } + else if (enable && !m_enableBeaconGeneration) { m_beaconEvent = Simulator::ScheduleNow (&NqapWifiMac::SendOneBeacon, this); } - else - { - m_beaconEvent.Cancel (); - } + m_enableBeaconGeneration = enable; } bool NqapWifiMac::GetBeaconGeneration (void) const { - return m_beaconEvent.IsRunning (); + return m_enableBeaconGeneration; } Time NqapWifiMac::GetBeaconInterval (void) const @@ -594,4 +598,15 @@ NqapWifiMac::FinishConfigureStandard (enum WifiPhyStandard standard) } +void +NqapWifiMac::DoStart (void) +{ + m_beaconEvent.Cancel (); + if (m_enableBeaconGeneration) + { + m_beaconEvent = Simulator::ScheduleNow (&NqapWifiMac::SendOneBeacon, this); + } + WifiMac::DoStart (); +} + } // namespace ns3 diff --git a/src/devices/wifi/nqap-wifi-mac.h b/src/devices/wifi/nqap-wifi-mac.h index 414248571..a1704886f 100644 --- a/src/devices/wifi/nqap-wifi-mac.h +++ b/src/devices/wifi/nqap-wifi-mac.h @@ -112,6 +112,7 @@ private: void SetBeaconGeneration (bool enable); bool GetBeaconGeneration (void) const; virtual void DoDispose (void); + virtual void DoStart (void); NqapWifiMac (const NqapWifiMac & ctor_arg); NqapWifiMac &operator = (const NqapWifiMac &o); Ptr GetDcaTxop (void) const; @@ -123,6 +124,7 @@ private: Ptr m_phy; Callback,Mac48Address, Mac48Address> m_upCallback; Time m_beaconInterval; + bool m_enableBeaconGeneration; DcfManager *m_dcfManager; MacRxMiddle *m_rxMiddle; diff --git a/src/devices/wifi/qap-wifi-mac.cc b/src/devices/wifi/qap-wifi-mac.cc index 7c5e51c29..e66fdf5bc 100644 --- a/src/devices/wifi/qap-wifi-mac.cc +++ b/src/devices/wifi/qap-wifi-mac.cc @@ -109,6 +109,8 @@ QapWifiMac::QapWifiMac () SetQueue (AC_VI); SetQueue (AC_BE); SetQueue (AC_BK); + + m_enableBeaconGeneration = false; } QapWifiMac::~QapWifiMac () @@ -129,6 +131,7 @@ QapWifiMac::DoDispose () m_low = 0; m_phy = 0; m_beaconDca = 0; + m_enableBeaconGeneration = false; m_beaconEvent.Cancel (); m_stationManager = 0; for (Queues::iterator i = m_queues.begin (); i != m_queues.end (); ++i) @@ -142,20 +145,21 @@ void QapWifiMac::SetBeaconGeneration (bool enable) { NS_LOG_FUNCTION (this << enable); - if (enable) - { - m_beaconEvent = Simulator::ScheduleNow (&QapWifiMac::SendOneBeacon, this); - } - else + if (!enable) { m_beaconEvent.Cancel (); } + else if (enable && !m_enableBeaconGeneration) + { + m_beaconEvent = Simulator::ScheduleNow (&QapWifiMac::SendOneBeacon, this); + } + m_enableBeaconGeneration = enable; } bool QapWifiMac::GetBeaconGeneration (void) const { - return m_beaconEvent.IsRunning (); + return m_enableBeaconGeneration; } Time @@ -772,4 +776,15 @@ QapWifiMac::FinishConfigureStandard (enum WifiPhyStandard standard) } } +void +QapWifiMac::DoStart (void) +{ + m_beaconEvent.Cancel (); + if (m_enableBeaconGeneration) + { + m_beaconEvent = Simulator::ScheduleNow (&QapWifiMac::SendOneBeacon, this); + } + WifiMac::DoStart (); +} + } //namespace ns3 diff --git a/src/devices/wifi/qap-wifi-mac.h b/src/devices/wifi/qap-wifi-mac.h index 1c789e96f..c83391376 100644 --- a/src/devices/wifi/qap-wifi-mac.h +++ b/src/devices/wifi/qap-wifi-mac.h @@ -92,6 +92,7 @@ private: typedef std::list, AmsduSubframeHeader> >::const_iterator DeaggregatedMsdusCI; virtual void DoDispose (void); + virtual void DoStart (void); void Receive (Ptr packet, WifiMacHeader const*hdr); void ForwardUp (Ptr packet, Mac48Address from, Mac48Address to); void ForwardDown (Ptr packet, Mac48Address from, Mac48Address to); @@ -130,6 +131,7 @@ private: Ssid m_ssid; EventId m_beaconEvent; Time m_beaconInterval; + bool m_enableBeaconGeneration; Callback, Mac48Address, Mac48Address> m_forwardUp; }; diff --git a/src/helper/application-container.cc b/src/helper/application-container.cc index 041b0ee6c..a63eaf105 100644 --- a/src/helper/application-container.cc +++ b/src/helper/application-container.cc @@ -85,7 +85,7 @@ ApplicationContainer::Start (Time start) for (Iterator i = Begin (); i != End (); ++i) { Ptr app = *i; - app->Start (start); + app->SetStartTime (start); } } void @@ -94,7 +94,7 @@ ApplicationContainer::Stop (Time stop) for (Iterator i = Begin (); i != End (); ++i) { Ptr app = *i; - app->Stop (stop); + app->SetStopTime (stop); } } diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index d11312cc6..2a8595f78 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -55,11 +55,6 @@ RandomDirection2dMobilityModel::GetTypeId (void) return tid; } - -RandomDirection2dMobilityModel::RandomDirection2dMobilityModel () -{ - m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); -} void RandomDirection2dMobilityModel::DoDispose (void) { @@ -67,7 +62,14 @@ RandomDirection2dMobilityModel::DoDispose (void) MobilityModel::DoDispose (); } void -RandomDirection2dMobilityModel::Start (void) +RandomDirection2dMobilityModel::DoStart (void) +{ + DoStartPrivate (); + MobilityModel::DoStart (); +} + +void +RandomDirection2dMobilityModel::DoStartPrivate (void) { double direction = m_direction.GetValue (0, 2 * PI); SetDirectionAndSpeed (direction); @@ -79,6 +81,7 @@ RandomDirection2dMobilityModel::BeginPause (void) m_helper.Update (); m_helper.Pause (); Time pause = Seconds (m_pause.GetValue ()); + m_event.Cancel (); m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this); NotifyCourseChange (); } @@ -97,6 +100,7 @@ RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction) m_helper.Unpause (); Vector next = m_bounds.CalculateIntersection (position, vector); Time delay = Seconds (CalculateDistance (position, next) / speed); + m_event.Cancel (); m_event = Simulator::Schedule (delay, &RandomDirection2dMobilityModel::BeginPause, this); NotifyCourseChange (); @@ -136,7 +140,8 @@ RandomDirection2dMobilityModel::DoSetPosition (const Vector &position) { m_helper.SetPosition (position); Simulator::Remove (m_event); - m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); + m_event.Cancel (); + m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::DoStartPrivate, this); } Vector RandomDirection2dMobilityModel::DoGetVelocity (void) const diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index ecea0288f..bf8cc01c1 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -45,14 +45,14 @@ class RandomDirection2dMobilityModel : public MobilityModel public: static TypeId GetTypeId (void); - RandomDirection2dMobilityModel (); private: - void Start (void); void ResetDirectionAndSpeed (void); void BeginPause (void); void SetDirectionAndSpeed (double direction); void InitializeDirectionAndSpeed (void); + void DoStartPrivate (void); virtual void DoDispose (void); + virtual void DoStart (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); virtual Vector DoGetVelocity (void) const; diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index e426a6575..11b5a3a55 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -72,13 +72,15 @@ RandomWalk2dMobilityModel::GetTypeId (void) return tid; } -RandomWalk2dMobilityModel::RandomWalk2dMobilityModel () +void +RandomWalk2dMobilityModel::DoStart (void) { - m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); + DoStartPrivate (); + MobilityModel::DoStart (); } void -RandomWalk2dMobilityModel::Start (void) +RandomWalk2dMobilityModel::DoStartPrivate (void) { m_helper.Update (); double speed = m_speed.GetValue (); @@ -109,9 +111,10 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft) Vector nextPosition = position; nextPosition.x += speed.x * delayLeft.GetSeconds (); nextPosition.y += speed.y * delayLeft.GetSeconds (); + m_event.Cancel (); if (m_bounds.IsInside (nextPosition)) { - m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::Start, this); + m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::DoStartPrivate, this); } else { @@ -163,7 +166,7 @@ RandomWalk2dMobilityModel::DoSetPosition (const Vector &position) NS_ASSERT (m_bounds.IsInside (position)); m_helper.SetPosition (position); Simulator::Remove (m_event); - m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); + m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::DoStartPrivate, this); } Vector RandomWalk2dMobilityModel::DoGetVelocity (void) const diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index 504b2e82d..f0b4bcf36 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -52,13 +52,12 @@ class RandomWalk2dMobilityModel : public MobilityModel MODE_TIME }; - RandomWalk2dMobilityModel (); - private: - void Start (void); void Rebound (Time timeLeft); void DoWalk (Time timeLeft); + void DoStartPrivate (void); virtual void DoDispose (void); + virtual void DoStart (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); virtual Vector DoGetVelocity (void) const; diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index bff248676..f6f3bc27b 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -54,11 +54,6 @@ RandomWaypointMobilityModel::GetTypeId (void) return tid; } -RandomWaypointMobilityModel::RandomWaypointMobilityModel () -{ - m_event = Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this); -} - void RandomWaypointMobilityModel::BeginWalk (void) { @@ -74,13 +69,21 @@ RandomWaypointMobilityModel::BeginWalk (void) m_helper.SetVelocity (Vector (k*dx, k*dy, k*dz)); m_helper.Unpause (); Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed); + m_event.Cancel (); m_event = Simulator::Schedule (travelDelay, - &RandomWaypointMobilityModel::Start, this); + &RandomWaypointMobilityModel::DoStartPrivate, this); NotifyCourseChange (); } void -RandomWaypointMobilityModel::Start (void) +RandomWaypointMobilityModel::DoStart (void) +{ + DoStartPrivate (); + MobilityModel::DoStart (); +} + +void +RandomWaypointMobilityModel::DoStartPrivate (void) { m_helper.Update (); m_helper.Pause (); @@ -100,7 +103,7 @@ RandomWaypointMobilityModel::DoSetPosition (const Vector &position) { m_helper.SetPosition (position); Simulator::Remove (m_event); - m_event = Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this); + m_event = Simulator::ScheduleNow (&RandomWaypointMobilityModel::DoStartPrivate, this); } Vector RandomWaypointMobilityModel::DoGetVelocity (void) const diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index d3386d5ec..3dae7c290 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -45,10 +45,11 @@ class RandomWaypointMobilityModel : public MobilityModel { public: static TypeId GetTypeId (void); - RandomWaypointMobilityModel (); +protected: + virtual void DoStart (void); private: - void Start (void); void BeginWalk (void); + void DoStartPrivate (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); virtual Vector DoGetVelocity (void) const; diff --git a/src/node/application.cc b/src/node/application.cc index f89dd7a56..4ae464bfe 100644 --- a/src/node/application.cc +++ b/src/node/application.cc @@ -40,6 +40,14 @@ Application::GetTypeId (void) { static TypeId tid = TypeId ("ns3::Application") .SetParent () + .AddAttribute ("StartTime", "Time at which the application will start", + TimeValue (Seconds (0.0)), + MakeTimeAccessor (&Application::m_startTime), + MakeTimeChecker ()) + .AddAttribute ("StopTime", "Time at which the application will stop", + TimeValue (TimeStep (0)), + MakeTimeAccessor (&Application::m_stopTime), + MakeTimeChecker ()) ; return tid; } @@ -52,38 +60,38 @@ Application::Application() Application::~Application() {} +void +Application::SetStartTime (Time start) +{ + m_startTime = start; +} +void +Application::SetStopTime (Time stop) +{ + m_stopTime = stop; +} + + void Application::DoDispose (void) { m_node = 0; - Simulator::Cancel(m_startEvent); - Simulator::Cancel(m_stopEvent); + m_startEvent.Cancel (); + m_stopEvent.Cancel (); Object::DoDispose (); } - -void Application::Start(const Time& startTime) -{ - ScheduleStart (startTime); -} -void Application::Start(const RandomVariable& startVar) +void +Application::DoStart (void) { - RandomVariable v = startVar; - ScheduleStart (Seconds (v.GetValue ())); + m_startEvent = Simulator::Schedule (m_startTime, &Application::StartApplication, this); + if (m_stopTime != TimeStep (0)) + { + m_stopEvent = Simulator::Schedule (m_stopTime, &Application::StopApplication, this); + } + Object::DoStart (); } - - -void Application::Stop(const Time& stopTime) -{ - ScheduleStop (stopTime); -} - -void Application::Stop(const RandomVariable& stopVar) -{ - RandomVariable v = stopVar; - ScheduleStop (Seconds (v.GetValue ())); -} - + Ptr Application::GetNode() const { return m_node; @@ -105,20 +113,6 @@ void Application::StopApplication() { // Provide null functionality in case subclass is not interested } - -// Private helpers -void Application::ScheduleStart (const Time &startTime) -{ - m_startEvent = Simulator::Schedule (startTime, - &Application::StartApplication, this); -} - -void Application::ScheduleStop (const Time &stopTime) -{ - m_stopEvent = Simulator::Schedule (stopTime, - &Application::StopApplication, this); -} - } //namespace ns3 diff --git a/src/node/application.h b/src/node/application.h index bb706cd4f..27cb61176 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -64,7 +64,7 @@ public: static TypeId GetTypeId (void); Application (); virtual ~Application (); - + /** * \brief Specify application start time * \param startTime Start time for this application, @@ -76,15 +76,7 @@ public: * private "StartApplication" method defined below, which is called at the * time specified, to cause the application to begin. */ - void Start (const Time& startTime); - - /** - * \brief Specify application start time. - * \param startVariable the random variable to use to pick - * the real start time as a relative time, in units of - * seconds, relative to the current simulation time. - */ - void Start (const RandomVariable& startVariable); + void SetStartTime (Time start); /** * \brief Specify application stop time @@ -97,16 +89,8 @@ public: * the private StopApplication method, to be notified when that * time has come. */ - void Stop (const Time& stopTime); - - /** - * \brief Specify application stop time - * \param stopVariable the random variable to use to pick - * the real stop time, in units of seconds, - * relative to the current simulation time. - */ - void Stop (const RandomVariable& stopVariable); - + void SetStopTime (Time stop); + /** * \returns the Node to which this Application object is attached. */ @@ -137,13 +121,13 @@ private: virtual void StopApplication (void); protected: virtual void DoDispose (void); -private: - void ScheduleStart (const Time &time); - void ScheduleStop (const Time &time); + virtual void DoStart (void); - EventId m_startEvent; - EventId m_stopEvent; Ptr m_node; + Time m_startTime; + Time m_stopTime; + EventId m_startEvent; + EventId m_stopEvent; }; } //namespace ns3 diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 57e4dc07b..f2fc7192e 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -119,6 +119,7 @@ NodeListPriv::Add (Ptr node) { uint32_t index = m_nodes.size (); m_nodes.push_back (node); + Simulator::ScheduleWithContext (index, TimeStep (0), &Node::Start, node); return index; } diff --git a/src/node/node.cc b/src/node/node.cc index d1265ec7a..cb7b2df85 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -167,6 +167,24 @@ Node::DoDispose() m_applications.clear (); Object::DoDispose (); } +void +Node::DoStart (void) +{ + for (std::vector >::iterator i = m_devices.begin (); + i != m_devices.end (); i++) + { + Ptr device = *i; + device->Start (); + } + for (std::vector >::iterator i = m_applications.begin (); + i != m_applications.end (); i++) + { + Ptr application = *i; + application->Start (); + } + + Object::DoStart (); +} void Node::NotifyDeviceAdded (Ptr device) diff --git a/src/node/node.h b/src/node/node.h index 2ce67b530..bb19cb631 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -186,6 +186,7 @@ protected: * end of their own DoDispose method. */ virtual void DoDispose (void); + virtual void DoStart (void); private: /** diff --git a/src/routing/list-routing/ipv4-list-routing.cc b/src/routing/list-routing/ipv4-list-routing.cc index 09749ca04..a8e265baf 100644 --- a/src/routing/list-routing/ipv4-list-routing.cc +++ b/src/routing/list-routing/ipv4-list-routing.cc @@ -68,6 +68,19 @@ Ipv4ListRouting::DoDispose (void) m_ipv4 = 0; } +void +Ipv4ListRouting::DoStart (void) +{ + for (Ipv4RoutingProtocolList::iterator rprotoIter = m_routingProtocols.begin (); + rprotoIter != m_routingProtocols.end (); rprotoIter++) + { + Ptr protocol = (*rprotoIter).second; + protocol->Start (); + } + Ipv4RoutingProtocol::DoStart (); +} + + Ptr Ipv4ListRouting::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, enum Socket::SocketErrno &sockerr) { diff --git a/src/routing/list-routing/ipv4-list-routing.h b/src/routing/list-routing/ipv4-list-routing.h index 42581ab53..780db8805 100644 --- a/src/routing/list-routing/ipv4-list-routing.h +++ b/src/routing/list-routing/ipv4-list-routing.h @@ -88,6 +88,7 @@ public: protected: void DoDispose (void); + void DoStart (void); private: typedef std::pair > Ipv4RoutingProtocolEntry; typedef std::list Ipv4RoutingProtocolList; diff --git a/src/routing/olsr/olsr-routing-protocol.cc b/src/routing/olsr/olsr-routing-protocol.cc index b6489e813..be16fb25d 100644 --- a/src/routing/olsr/olsr-routing-protocol.cc +++ b/src/routing/olsr/olsr-routing-protocol.cc @@ -213,8 +213,6 @@ RoutingProtocol::SetIpv4 (Ptr ipv4) m_linkTupleTimerFirstTime = true; m_ipv4 = ipv4; - - Simulator::ScheduleNow (&RoutingProtocol::Start, this); } void RoutingProtocol::DoDispose () @@ -231,7 +229,7 @@ void RoutingProtocol::DoDispose () Ipv4RoutingProtocol::DoDispose (); } -void RoutingProtocol::Start () +void RoutingProtocol::DoStart () { if (m_mainAddress == Ipv4Address ()) { diff --git a/src/routing/olsr/olsr-routing-protocol.h b/src/routing/olsr/olsr-routing-protocol.h index bab7865c8..30f5e2c01 100644 --- a/src/routing/olsr/olsr-routing-protocol.h +++ b/src/routing/olsr/olsr-routing-protocol.h @@ -81,6 +81,8 @@ public: void SetMainInterface (uint32_t interface); +protected: + virtual void DoStart (void); private: std::map m_table; ///< Data structure for the routing table. @@ -111,7 +113,7 @@ private: Ptr m_ipv4; private: - void Start (); + void Clear (); uint32_t GetSize () const { return m_table.size (); } std::vector GetEntries () const;