diff --git a/examples/matrix-topology/matrix-topology.cc b/examples/matrix-topology/matrix-topology.cc index d82a2bf31..5c6366a82 100644 --- a/examples/matrix-topology/matrix-topology.cc +++ b/examples/matrix-topology/matrix-topology.cc @@ -95,7 +95,7 @@ int main (int argc, char *argv[]) std::string tr_name ("n-node-ppp.tr"); std::string pcap_name ("n-node-ppp"); std::string flow_name ("n-node-ppp.xml"); - std::string anim_name ("n-node-ppp.anim"); + std::string anim_name ("n-node-ppp.anim.xml"); std::string adj_mat_file_name ("examples/matrix-topology/adjacency_matrix.txt"); std::string node_coordinates_file_name ("examples/matrix-topology/node_coordinates.txt"); @@ -275,24 +275,12 @@ int main (int argc, char *argv[]) // Configure animator with default settings - bool animEnabled = false; - AnimationInterface anim; - if (anim.SetServerPort (9) && anim.SetOutputFile (anim_name.c_str ())) - { - NS_LOG_INFO ("Animation Interface Enabled."); - animEnabled = true; - anim.StartAnimation (); - } - + AnimationInterface anim (anim_name.c_str ()); NS_LOG_INFO ("Run Simulation."); Simulator::Stop (Seconds (SimTime)); Simulator::Run (); // flowmon->SerializeToXmlFile (flow_name.c_str(), true, true); - if (animEnabled) - { - anim.StopAnimation (); - } Simulator::Destroy (); // ---------- End of Simulation Monitoring --------------------------------- diff --git a/src/netanim/examples/wireless-animation.cc b/src/netanim/examples/wireless-animation.cc index f4f0c4353..d8bbd9312 100644 --- a/src/netanim/examples/wireless-animation.cc +++ b/src/netanim/examples/wireless-animation.cc @@ -152,6 +152,7 @@ main (int argc, char *argv[]) Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Simulator::Stop (Seconds (15.0)); AnimationInterface anim ("wireless-animation.xml"); + anim.EnablePacketMetadata (true); Simulator::Run (); Simulator::Destroy (); return 0; diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 88f97aa59..6f9bdfb65 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -64,7 +64,7 @@ AnimationInterface::AnimationInterface () usingSockets (false), mport (0), outputfilename (""), OutputFileSet (false), ServerPortSet (false), gAnimUid (0),randomPosition (true), m_writeCallback (0), m_started (false), - m_enablePacketMetadata (false) + m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)) { initialized = true; StartAnimation (); @@ -75,7 +75,7 @@ AnimationInterface::AnimationInterface (const std::string fn, bool usingXML) usingSockets (false), mport (0), outputfilename (fn), OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true), m_writeCallback (0), m_started (false), - m_enablePacketMetadata (false) + m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)) { initialized = true; StartAnimation (); @@ -86,7 +86,7 @@ AnimationInterface::AnimationInterface (const uint16_t port, bool usingXML) usingSockets (true), mport (port), outputfilename (""), OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true), m_writeCallback (0), m_started (false), - m_enablePacketMetadata (false) + m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)) { initialized = true; StartAnimation (); @@ -103,6 +103,17 @@ void AnimationInterface::SetXMLOutput () m_xml = true; } + +void AnimationInterface::SetStartTime (Time t) +{ + m_startTime = t; +} + +void AnimationInterface::SetStopTime (Time t) +{ + m_stopTime = t; +} + bool AnimationInterface::SetOutputFile (const std::string& fn) { if (OutputFileSet) @@ -156,6 +167,15 @@ void AnimationInterface::ResetAnimWriteCallback () m_writeCallback = 0; } +bool AnimationInterface::IsInTimeWindow () +{ + if ((Simulator::Now () >= m_startTime) && + (Simulator::Now () <= m_stopTime)) + return true; + else + return false; +} + bool AnimationInterface::SetServerPort (uint16_t port) { #if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H) @@ -741,7 +761,7 @@ uint64_t AnimationInterface::GetAnimUidFromPacket (Ptr p) void AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -771,7 +791,7 @@ void AnimationInterface::WifiPhyTxEndTrace (std::string context, void AnimationInterface::WifiPhyTxDropTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -786,7 +806,7 @@ void AnimationInterface::WifiPhyTxDropTrace (std::string context, void AnimationInterface::WifiPhyRxBeginTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -825,7 +845,7 @@ void AnimationInterface::WifiPhyRxBeginTrace (std::string context, void AnimationInterface::WifiPhyRxEndTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -852,7 +872,7 @@ void AnimationInterface::WifiPhyRxEndTrace (std::string context, void AnimationInterface::WifiMacRxTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -881,7 +901,7 @@ void AnimationInterface::WifiPhyRxDropTrace (std::string context, void AnimationInterface::WimaxTxTrace (std::string context, Ptr p, const Mac48Address & m) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -900,7 +920,7 @@ void AnimationInterface::WimaxTxTrace (std::string context, Ptr p, void AnimationInterface::WimaxRxTrace (std::string context, Ptr p, const Mac48Address & m) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -919,7 +939,7 @@ void AnimationInterface::WimaxRxTrace (std::string context, Ptr p, void AnimationInterface::LteTxTrace (std::string context, Ptr p, const Mac48Address & m) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -938,7 +958,7 @@ void AnimationInterface::LteTxTrace (std::string context, Ptr p, c void AnimationInterface::LteRxTrace (std::string context, Ptr p, const Mac48Address & m) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -962,7 +982,7 @@ void AnimationInterface::LteRxTrace (std::string context, Ptr p, c void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -980,7 +1000,7 @@ void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -1001,7 +1021,7 @@ void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr ndev = GetNetDeviceFromContext (context); NS_ASSERT (ndev); @@ -1024,7 +1044,7 @@ void AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr p) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; NS_LOG_FUNCTION (this); Ptr ndev = GetNetDeviceFromContext (context); @@ -1051,7 +1071,7 @@ void AnimationInterface::CsmaMacRxTrace (std::string context, void AnimationInterface::MobilityCourseChangeTrace (Ptr mobility) { - if (!m_started) + if (!m_started || !IsInTimeWindow ()) return; Ptr n = mobility->GetObject (); NS_ASSERT (n); @@ -1091,6 +1111,8 @@ bool AnimationInterface::NodeHasMoved (Ptr n, Vector newLocation) void AnimationInterface::MobilityAutoCheck () { + if (!m_started || !IsInTimeWindow ()) + return; std::vector > MovedNodes = RecalcTopoBounds (); std::ostringstream oss; oss << GetXMLOpen_topology (topo_minX, topo_minY, topo_maxX, topo_maxY); @@ -1132,39 +1154,31 @@ std::string AnimationInterface::GetPreamble () Description of attributes:\n\ =========================\n\ anim\n\ - * lp = Logical Processor Id\n\ topology\n\ * minX = minimum X coordinate of the canvas\n\ * minY = minimum Y coordinate of the canvas\n\ * maxX = maximum X coordinate of the canvas\n\ * maxY = maximum Y coordinate of the canvas\n\ node\n\ - * lp = Logical Processor Id\n\ * id = Node Id\n\ * locX = X coordinate\n\ * locY = Y coordinate\n\ link\n\ - * fromLp = From logical processor Id\n\ * fromId = From Node Id\n\ - * toLp = To logical processor Id\n\ * toId = To Node Id\n\ packet\n\ - * fromLp = From logical processor Id\n\ * fbTx = First bit transmit time\n\ * lbTx = Last bit transmit time\n\ rx\n\ - * toLp = To logical processor Id\n\ * toId = To Node Id\n\ * fbRx = First bit Rx Time\n\ * lbRx = Last bit Rx\n\ wpacket\n\ - * fromLp = From logical processor Id\n\ * fromId = From Node Id\n\ * fbTx = First bit transmit time\n\ * lbTx = Last bit transmit time\n\ * range = Reception range\n\ rx\n\ - * toLp = To logical processor Id\n\ * toId = To Node Id\n\ * fbRx = First bit Rx time\n\ * lbRx = Last bit Rx time-->\n\ @@ -1254,7 +1268,7 @@ std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp,uint32_t id,do std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId) { std::ostringstream oss; - oss << "" << std::endl; return oss.str (); @@ -1265,7 +1279,7 @@ std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t from { std::ostringstream oss; oss << std::setprecision (10); - oss << "" << std::endl; + oss << "" << std::endl; return oss.str (); } @@ -1289,7 +1303,7 @@ std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId { std::ostringstream oss; oss << std::setprecision (10); - oss << "" << std::endl; diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index c6850705e..b2c475adf 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -127,6 +127,24 @@ public: */ void SetXMLOutput (); + /** + * \brief Specify the time at which capture should start + * + * \param t The time at which AnimationInterface should begin capture of traffic info + * + * \returns none + */ + void SetStartTime (Time t); + + /** + * \brief Specify the time at which capture should stop + * + * \param t The time at which AnimationInterface should stop capture of traffic info + * + * \returns none + */ + void SetStopTime (Time t); + /** * \brief (Deprecated) Specify that animation commands are to be written to * a socket. @@ -249,6 +267,7 @@ private: std::string outputfilename; bool OutputFileSet; bool ServerPortSet; + void DevTxTrace (std::string context, Ptr p, Ptr tx, @@ -344,8 +363,11 @@ private: bool m_started; bool m_enablePacketMetadata; + Time m_startTime; + Time m_stopTime; std::map m_macToNodeIdMap; + bool IsInTimeWindow (); // Path helper std::vector GetElementsFromContext (std::string context);