From 40bbf068bf3ed17f69b115f2b40c2f07726b5360 Mon Sep 17 00:00:00 2001 From: John Abraham Date: Fri, 27 Jul 2012 10:29:53 -0700 Subject: [PATCH] NetAnim: Support for link description --- src/netanim/model/animation-interface.cc | 61 +++++++++++++++++++++--- src/netanim/model/animation-interface.h | 46 ++++++++++++++++++ 2 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 868550230..7ca516592 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -55,7 +55,9 @@ namespace ns3 { #define PURGE_INTERVAL 5 static bool initialized = false; std::map AnimationInterface::nodeDescriptions; -std::map AnimationInterface::nodeColors; +std::map AnimationInterface::nodeColors; +std::map AnimationInterface::linkProperties; + AnimationInterface::AnimationInterface (const std::string fn, uint64_t maxPktsPerFile, bool usingXML) : m_xml (usingXML), m_mobilityPollInterval (Seconds(0.25)), @@ -437,7 +439,7 @@ void AnimationInterface::StartAnimation (bool restart) std::ostringstream oss; if (m_xml) { - oss << GetXMLOpenClose_link (0,n1Id,0,n2Id); + oss << GetXMLOpenClose_link (0, n1Id, 0, n2Id); } else { @@ -453,6 +455,7 @@ void AnimationInterface::StartAnimation (bool restart) } } } + linkProperties.clear (); if (m_xml && !restart) { WriteN (GetXMLClose ("topology")); @@ -1316,6 +1319,9 @@ std::string AnimationInterface::GetPreamble () link\n\ * fromId = From Node Id\n\ * toId = To Node Id\n\ + * fd = From Node description (for IP Address)\n\ + * td = To Node description (for IP Address)\n\ + * ld = Link description (for Bandwidth,delay etc)\n\ packet\n\ * fbTx = First bit transmit time\n\ * lbTx = Last bit transmit time\n\ @@ -1411,6 +1417,30 @@ void AnimationInterface::SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, u } } + +void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode, + std::string fromNodeDescription, + std::string toNodeDescription, + std::string linkDescription) +{ + + P2pLinkNodeIdPair p2pPair; + p2pPair.fromNode = fromNode; + p2pPair.toNode = toNode; + LinkProperties lp = { fromNodeDescription, toNodeDescription, linkDescription }; + linkProperties[p2pPair] = lp; + /* DEBUG */ + /* + for (std::map ::const_iterator i = linkProperties.begin (); + i != linkProperties.end(); ++i) + { + P2pLinkNodeIdPair ppair = i->first; + LinkProperties l = i->second; + NS_LOG_UNCOND ("A:" << ppair.nodeA << " B:" << ppair.nodeB << " ad:" << l.nodeADescription << " bd:" << l.nodeBDescription << " ld:" << l.linkDescription); + + }*/ +} + void AnimationInterface::SetNodeDescription (Ptr n, std::string descr) { if (initialized) @@ -1488,17 +1518,34 @@ std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, -std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId) +std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId) { std::ostringstream oss; oss << "" << std::endl; + << "\" toId=\"" << toId + << "\" "; + + std::string fromNodeDescription = ""; + std::string toNodeDescription = ""; + std::string linkDescription = ""; + + P2pLinkNodeIdPair p = { fromId, toId }; + if (linkProperties.find (p) != linkProperties.end()) + { + LinkProperties lprop = linkProperties[p]; + fromNodeDescription = lprop.fromNodeDescription; + toNodeDescription = lprop.toNodeDescription; + linkDescription = lprop.linkDescription; + } + oss << " fd=\"" << fromNodeDescription << "\"" + << " td=\"" << toNodeDescription << "\"" + << " ld=\"" << linkDescription << "\"" + << " />\n"; return oss.str (); } -std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, std::string auxInfo) +std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, std::string auxInfo) { std::ostringstream oss; oss << std::setprecision (10); @@ -1510,7 +1557,7 @@ std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t from return oss.str (); } -std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, double range) +std::string AnimationInterface::GetXMLOpen_wpacket (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, double range) { std::ostringstream oss; oss << std::setprecision (10); diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index cd79db059..af56e2a1d 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -42,6 +42,37 @@ namespace ns3 { #define MAX_PKTS_PER_TRACE_FILE 100000 struct Rgb; +typedef struct +{ + uint32_t fromNode; + uint32_t toNode; +} P2pLinkNodeIdPair; + +typedef struct +{ + std::string fromNodeDescription; + std::string toNodeDescription; + std::string linkDescription; +} LinkProperties; + +struct LinkPairCompare +{ + bool operator () (P2pLinkNodeIdPair first, P2pLinkNodeIdPair second) + { + //Check if they are the same node pairs but flipped + if ( ((first.fromNode == second.fromNode) && (first.toNode == second.toNode)) || + ((first.fromNode == second.toNode) && (first.toNode == second.fromNode)) ) + { + return false; + } + std::ostringstream oss1; + oss1 << first.fromNode << first.toNode; + std::ostringstream oss2; + oss2 << second.fromNode << second.toNode; + return oss1.str () < oss2.str (); + } + +}; /** * \defgroup netanim Netanim @@ -234,6 +265,20 @@ public: */ static void SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, uint8_t b); + /** + * \brief Helper function to set the description for a link + * \param fromNode Node Id of the "from Node" of the p2p link + * \param toNode Node Id of the "to Node" of the p2p link + * \param fromNodeDescription Description at the "from Node" end such as IP address + * \param toNodeDescription Description at the "to Node" end such as Ip address + * \param linkDescription Description of the link such as link bandwidth + * + */ + static void SetLinkDescription (uint32_t fromNode, uint32_t toNode, + std::string fromNodeDescription, + std::string toNodeDescription, + std::string linkDescription); + /** * \brief Is AnimationInterface started @@ -404,6 +449,7 @@ private: static std::map nodeColors; static std::map nodeDescriptions; + static std::map linkProperties; uint64_t m_currentPktCount; void StartNewTraceFile();