--- a/src/netanim/model/animation-interface.cc Mon Nov 28 07:40:36 2011 -0800
+++ b/src/netanim/model/animation-interface.cc Wed Nov 30 19:11:19 2011 -0500
@@ -51,14 +51,18 @@
NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
+#define PURGE_INTERVAL 5
+static bool initialized = false;
+
namespace ns3 {
AnimationInterface::AnimationInterface ()
: m_fHandle (STDOUT_FILENO), m_xml (false), mobilitypollinterval (Seconds(0.25)),
usingSockets (false), mport (0), outputfilename (""),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0),randomPosition (true),
- m_writeCallback (0)
+ m_writeCallback (0), m_started (false)
{
+ initialized = true;
StartAnimation ();
}
@@ -66,8 +70,9 @@
: m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)),
usingSockets (false), mport (0), outputfilename (fn),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
- m_writeCallback (0)
+ m_writeCallback (0), m_started (false)
{
+ initialized = true;
StartAnimation ();
}
@@ -75,8 +80,9 @@
: m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)),
usingSockets (true), mport (port), outputfilename (""),
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
- m_writeCallback (0)
+ m_writeCallback (0), m_started (false)
{
+ initialized = true;
StartAnimation ();
}
@@ -116,6 +122,17 @@
return true;
}
+bool AnimationInterface::IsInitialized ()
+{
+ return initialized;
+}
+
+bool AnimationInterface::IsStarted ()
+{
+ return m_started;
+
+}
+
void AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb)
{
m_writeCallback = cb;
@@ -226,8 +243,90 @@
return nodeLocation[n->GetId ()];
}
+void AnimationInterface::PurgePendingWifi ()
+{
+ if (pendingWifiPackets.empty ())
+ return;
+ std::vector <uint64_t> purgeList;
+ for (std::map<uint64_t, AnimPacketInfo>::iterator i = pendingWifiPackets.begin ();
+ i != pendingWifiPackets.end ();
+ ++i)
+ {
+
+ AnimPacketInfo pktInfo = i->second;
+ double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
+ if (delta > PURGE_INTERVAL)
+ {
+ purgeList.push_back (i->first);
+ }
+ }
+
+ for (std::vector <uint64_t>::iterator i = purgeList.begin ();
+ i != purgeList.end ();
+ ++i)
+ {
+ pendingWifiPackets.erase (*i);
+ }
+
+}
+
+void AnimationInterface::PurgePendingWimax ()
+{
+ if (pendingWimaxPackets.empty ())
+ return;
+ std::vector <uint64_t> purgeList;
+ for (std::map<uint64_t, AnimPacketInfo>::iterator i = pendingWimaxPackets.begin ();
+ i != pendingWimaxPackets.end ();
+ ++i)
+ {
+
+ AnimPacketInfo pktInfo = i->second;
+ double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
+ if (delta > PURGE_INTERVAL)
+ {
+ purgeList.push_back (i->first);
+ }
+ }
+
+ for (std::vector <uint64_t>::iterator i = purgeList.begin ();
+ i != purgeList.end ();
+ ++i)
+ {
+ pendingWimaxPackets.erase (*i);
+ }
+
+}
+
+void AnimationInterface::PurgePendingCsma ()
+{
+ if (pendingCsmaPackets.empty ())
+ return;
+ std::vector <uint64_t> purgeList;
+ for (std::map<uint64_t, AnimPacketInfo>::iterator i = pendingCsmaPackets.begin ();
+ i != pendingCsmaPackets.end ();
+ ++i)
+ {
+
+ AnimPacketInfo pktInfo = i->second;
+ double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx);
+ if (delta > PURGE_INTERVAL)
+ {
+ purgeList.push_back (i->first);
+ }
+ }
+
+ for (std::vector <uint64_t>::iterator i = purgeList.begin ();
+ i != purgeList.end ();
+ ++i)
+ {
+ pendingCsmaPackets.erase (*i);
+ }
+
+}
+
void AnimationInterface::StartAnimation ()
{
+ m_started = true;
if (usingSockets)
{
SetServerPort (mport);
@@ -336,6 +435,11 @@
Simulator::Schedule (mobilitypollinterval, &AnimationInterface::MobilityAutoCheck, this);
}
+ ConnectCallbacks ();
+}
+
+void AnimationInterface::ConnectCallbacks ()
+{
// Connect the callbacks
Config::Connect ("/ChannelList/*/TxRxPointToPoint",
MakeCallback (&AnimationInterface::DevTxTrace, this));
@@ -365,11 +469,12 @@
MakeCallback (&AnimationInterface::CsmaMacRxTrace, this));
+}
-}
void AnimationInterface::StopAnimation ()
{
+ m_started = false;
NS_LOG_INFO ("Stopping Animation");
ResetAnimWriteCallback ();
if (m_fHandle > 0)
@@ -510,6 +615,8 @@
Ptr<NetDevice> tx, Ptr<NetDevice> rx,
Time txTime, Time rxTime)
{
+ if (!m_started)
+ return;
NS_ASSERT (tx);
NS_ASSERT (rx);
Time now = Simulator::Now ();
@@ -586,6 +693,8 @@
void AnimationInterface::WifiPhyTxBeginTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -608,6 +717,8 @@
void AnimationInterface::WifiPhyTxDropTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
// Erase pending wifi
@@ -621,6 +732,8 @@
void AnimationInterface::WifiPhyRxBeginTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
uint64_t AnimUid = GetAnimUidFromPacket (p);
@@ -638,6 +751,8 @@
void AnimationInterface::WifiPhyRxEndTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -656,6 +771,8 @@
void AnimationInterface::WifiMacRxTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -684,6 +801,8 @@
void AnimationInterface::WimaxTxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -701,6 +820,8 @@
void AnimationInterface::WimaxRxTrace (std::string context, Ptr<const Packet> p, const Mac48Address & m)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -717,6 +838,8 @@
void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -733,6 +856,8 @@
void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
uint64_t AnimUid = GetAnimUidFromPacket (p);
@@ -749,6 +874,8 @@
void AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
Ptr <Node> n = ndev->GetNode ();
@@ -770,6 +897,8 @@
void AnimationInterface::CsmaMacRxTrace (std::string context,
Ptr<const Packet> p)
{
+ if (!m_started)
+ return;
NS_LOG_FUNCTION (this);
Ptr <NetDevice> ndev = GetNetDeviceFromContext (context);
NS_ASSERT (ndev);
@@ -796,6 +925,8 @@
void AnimationInterface::MobilityCourseChangeTrace (Ptr <const MobilityModel> mobility)
{
+ if (!m_started)
+ return;
Ptr <Node> n = mobility->GetObject <Node> ();
NS_ASSERT (n);
Vector v ;
@@ -849,6 +980,9 @@
WriteDummyPacket ();
if (!Simulator::IsFinished ())
{
+ PurgePendingWifi ();
+ PurgePendingWimax ();
+ PurgePendingCsma ();
Simulator::Schedule (mobilitypollinterval, &AnimationInterface::MobilityAutoCheck, this);
}
}