diff --git a/src/netanim/examples/wireless-animation.cc b/src/netanim/examples/wireless-animation.cc index d8bbd9312..98279235b 100644 --- a/src/netanim/examples/wireless-animation.cc +++ b/src/netanim/examples/wireless-animation.cc @@ -151,6 +151,9 @@ main (int argc, char *argv[]) Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Simulator::Stop (Seconds (15.0)); + AnimationInterface::SetNodeDescription (wifiApNode, "AP"); + AnimationInterface::SetNodeDescription (wifiStaNodes, "STA"); + AnimationInterface::SetNodeDescription (csmaNodes, "CSMA"); AnimationInterface anim ("wireless-animation.xml"); anim.EnablePacketMetadata (true); Simulator::Run (); diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 76632fbd2..d6a3551c8 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -54,11 +54,14 @@ NS_LOG_COMPONENT_DEFINE ("AnimationInterface"); -#define PURGE_INTERVAL 5 -static bool initialized = false; + namespace ns3 { +#define PURGE_INTERVAL 5 +static bool initialized = false; +std::map AnimationInterface::nodeDescriptions; + AnimationInterface::AnimationInterface () : m_fHandle (STDOUT_FILENO), m_xml (false), mobilitypollinterval (Seconds(0.25)), usingSockets (false), mport (0), outputfilename (""), @@ -249,7 +252,7 @@ Vector AnimationInterface::UpdatePosition (Ptr n) } else { - NS_LOG_UNCOND ( "WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"); + NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"); Vector deterministicVector (100,100,0); Vector randomVector (UniformVariable (0, topo_maxX-topo_minX).GetValue (), UniformVariable (0, topo_maxY-topo_minY).GetValue (), 0); if (randomPosition) @@ -1025,6 +1028,7 @@ void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr n, double x, double y, } +void AnimationInterface::SetNodeDescription (Ptr n, std::string descr) +{ + NS_ASSERT (n); + nodeDescriptions[n->GetId ()] = descr; +} + +void AnimationInterface::SetNodeDescription (NodeContainer nc, std::string descr) +{ + for (uint32_t i = 0; i < nc.GetN (); ++i) + { + Ptr n = nc.Get (i); + NS_ASSERT (n); + nodeDescriptions[n->GetId ()] = descr; + } +} + // XML Private Helpers @@ -1273,8 +1293,16 @@ std::string AnimationInterface::GetXMLOpen_topology (double minX,double minY,dou std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp,uint32_t id,double locX,double locY) { std::ostringstream oss; - oss <<"\n"; + oss <<"\n"; return oss.str (); } std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId) @@ -1306,7 +1334,7 @@ std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fro oss << "" << std::endl; + << "\" range=\"" << range << "\">" << std::endl; return oss.str (); } diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index b2c475adf..4a3ffb923 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -26,6 +26,7 @@ #include #include "ns3/ptr.h" #include "ns3/net-device.h" +#include "ns3/node-container.h" #include "ns3/nstime.h" #include "ns3/log.h" #include "ns3/node-list.h" @@ -228,6 +229,22 @@ public: */ static void SetConstantPosition (Ptr n, double x, double y, double z=0); + /** + * \brief Helper function to set a brief description for a given node + * \param n Ptr to the node + * \param descr A string to briefly describe the node + * + */ + static void SetNodeDescription (Ptr n, std::string descr); + + /** + * \brief Helper function to set a brief description for nodes in a Node Container + * \param nc NodeContainer containing the nodes + * \param descr A string to briefly describe the nodes + * + */ + static void SetNodeDescription (NodeContainer nc, std::string descr); + /** * \brief Is AnimationInterface started * \returns true if AnimationInterface was started @@ -251,6 +268,8 @@ public: */ void EnablePacketMetadata (bool enable); + + private: #ifndef WIN32 int m_fHandle; // File handle for output (-1 if none) @@ -373,6 +392,8 @@ private: std::vector GetElementsFromContext (std::string context); Ptr GetNetDeviceFromContext (std::string context); + static std::map nodeDescriptions; + // XML helpers std::string GetPreamble (void); // Topology element dimensions