NetAnim: Support for link description

This commit is contained in:
John Abraham
2012-07-27 10:29:53 -07:00
parent 2c514e7fbf
commit 40bbf068bf
2 changed files with 100 additions and 7 deletions

View File

@@ -55,7 +55,9 @@ namespace ns3 {
#define PURGE_INTERVAL 5
static bool initialized = false;
std::map <uint32_t, std::string> AnimationInterface::nodeDescriptions;
std::map<uint32_t, Rgb> AnimationInterface::nodeColors;
std::map <uint32_t, Rgb> AnimationInterface::nodeColors;
std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> 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 <P2pLinkNodeIdPair, LinkProperties>::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 <Node> 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 << "<link fromId=\"" << fromId
<< "\" toLp=\"0\" toId=\"" << toId
<< "\"/>" << 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);

View File

@@ -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<uint32_t, Rgb> nodeColors;
static std::map <uint32_t, std::string> nodeDescriptions;
static std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> linkProperties;
uint64_t m_currentPktCount;
void StartNewTraceFile();