NetAnim: Add nodeupdate XML tag

This commit is contained in:
John Abraham
2012-07-29 21:07:16 -07:00
parent d620c6817c
commit 604a18e8d6
3 changed files with 182 additions and 7 deletions

View File

@@ -45,6 +45,8 @@ void modify ()
pAnim->UpdateLinkDescription (1, 9, oss.str ());
pAnim->UpdateLinkDescription (1, 10, oss.str ());
pAnim->UpdateLinkDescription (1, 11, oss.str ());
pAnim->UpdateNodeDescription (0, oss.str ());
pAnim->ShowNode (3, false);
if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
// will run endlessly
Simulator::Schedule (Seconds (1), modify);

View File

@@ -407,7 +407,6 @@ void AnimationInterface::StartAnimation (bool restart)
WriteN (oss.str ().c_str (), oss.str ().length ());
}
}
nodeColors.clear ();
NS_LOG_INFO ("Setting p2p links");
// Now dump the p2p links
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
@@ -1410,6 +1409,39 @@ void AnimationInterface::SetNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8
nodeColors[n->GetId ()] = rgb;
}
void AnimationInterface::ShowNode (uint32_t nodeId, bool show)
{
NS_ASSERT (NodeList::GetNode (nodeId));
NS_LOG_INFO ("Setting node visibility for Node Id:" << nodeId);
std::ostringstream oss;
oss << GetXMLOpenClose_nodeupdate (nodeId, show);
WriteN (oss.str ());
}
void AnimationInterface::ShowNode (Ptr <Node> n, bool show)
{
ShowNode (n, show);
}
void AnimationInterface::UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
{
UpdateNodeColor (n->GetId (), r, g, b);
}
void AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b)
{
NS_ASSERT (NodeList::GetNode (nodeId));
NS_LOG_INFO ("Setting node color for Node Id:" << nodeId);
struct Rgb rgb = {r, g, b};
nodeColors[nodeId] = rgb;
std::ostringstream oss;
oss << GetXMLOpenClose_nodeupdate (nodeId);
WriteN (oss.str ());
}
void AnimationInterface::SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, uint8_t b)
{
for (uint32_t i = 0; i < nc.GetN (); ++i)
@@ -1429,10 +1461,20 @@ void AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNo
WriteN (oss.str ());
}
void AnimationInterface::UpdateLinkDescription (Ptr <Node> fromNode, Ptr <Node> toNode,
std::string linkDescription)
{
NS_ASSERT (fromNode);
NS_ASSERT (toNode);
std::ostringstream oss;
oss << GetXMLOpenClose_linkupdate (fromNode->GetId (), toNode->GetId (), linkDescription);
WriteN (oss.str ());
}
void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode,
std::string linkDescription,
std::string fromNodeDescription,
std::string toNodeDescription,
std::string linkDescription)
std::string toNodeDescription)
{
P2pLinkNodeIdPair p2pPair;
@@ -1453,6 +1495,17 @@ void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode,
*/
}
void AnimationInterface::SetLinkDescription (Ptr <Node> fromNode, Ptr <Node> toNode,
std::string linkDescription,
std::string fromNodeDescription,
std::string toNodeDescription)
{
NS_ASSERT (fromNode);
NS_ASSERT (toNode);
SetLinkDescription (fromNode->GetId (), toNode->GetId (), linkDescription, fromNodeDescription, toNodeDescription);
}
void AnimationInterface::SetNodeDescription (Ptr <Node> n, std::string descr)
{
if (initialized)
@@ -1461,6 +1514,22 @@ void AnimationInterface::SetNodeDescription (Ptr <Node> n, std::string descr)
nodeDescriptions[n->GetId ()] = descr;
}
void AnimationInterface::UpdateNodeDescription (Ptr <Node> n, std::string descr)
{
UpdateNodeDescription (n->GetId (), descr);
}
void AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr)
{
NS_ASSERT (NodeList::GetNode (nodeId));
nodeDescriptions[nodeId] = descr;
std::ostringstream oss;
oss << GetXMLOpenClose_nodeupdate (nodeId);
WriteN (oss.str ());
}
void AnimationInterface::SetNodeDescription (NodeContainer nc, std::string descr)
{
if (initialized)
@@ -1492,10 +1561,37 @@ std::string AnimationInterface::GetXMLOpen_topology (double minX, double minY, d
}
std::string AnimationInterface::GetXMLOpenClose_nodeupdate (uint32_t id, bool visible)
{
struct Rgb rgb = nodeColors[id];
uint8_t r = rgb.r;
uint8_t g = rgb.g;
uint8_t b = rgb.b;
std::ostringstream oss;
oss << "<nodeupdate id=\"" << id << "\"";
oss << " t=\"" << Simulator::Now ().GetSeconds () << "\"";
if (visible)
oss << " visible=\"" << 1 << "\"";
else
oss << " visible=\"" << 0 << "\"";
if (nodeDescriptions.find (id) != nodeDescriptions.end ())
{
oss << " descr=\""<< nodeDescriptions[id] << "\"";
}
else
{
oss << " descr=\"\"";
}
oss << " r=\"" << (uint32_t)r << "\" "
<< " g=\"" << (uint32_t)g << "\" b=\"" << (uint32_t)b <<"\"/>\n";
return oss.str ();
}
std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY)
{
std::ostringstream oss;
oss <<"<node id = \"" << id << "\"";
oss <<"<node id=\"" << id << "\"";
if (nodeDescriptions.find (id) != nodeDescriptions.end ())
{
oss << " descr=\""<< nodeDescriptions[id] << "\"";

View File

@@ -13,7 +13,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: George F. Riley<riley@ece.gatech.edu>
* Modified by: John Abraham <john.abraham@gatech.edu>
* Author: John Abraham <john.abraham@gatech.edu>
*/
// Interface between ns3 and the network animator
@@ -236,6 +236,38 @@ public:
*/
static void SetNodeDescription (Ptr <Node> n, std::string descr);
/**
* \brief Helper function to update the description for a given node
* \param n Ptr to the node
* \param descr A string to briefly describe the node
*
*/
void UpdateNodeDescription (Ptr <Node> n, std::string descr);
/**
* \brief Helper function to update the description for a given node
* \param nodeId Id of the node
* \param descr A string to briefly describe the node
*
*/
void UpdateNodeDescription (uint32_t nodeId, std::string descr);
/**
* \brief Helper function to show/hide a node
* \param nodeId Id of the node
* \param show Set to true to show node, set to false to hide
*
*/
void ShowNode (uint32_t nodeId, bool show = true);
/**
* \brief Helper function to show/hide a node
* \param n Ptr to the node
* \param show Set to true to show node, set to false to hide
*
*/
void ShowNode (Ptr <Node> n, bool show = true);
/**
* \brief Helper function to set a brief description for nodes in a Node Container
* \param nc NodeContainer containing the nodes
@@ -255,6 +287,27 @@ public:
static void SetNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b);
/**
* \brief Helper function to update the node color
* \param n Ptr to the node
* \param r Red component value (0-255)
* \param g Green component value (0-255)
* \param b Blue component value (0-255)
*
*/
void UpdateNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b);
/**
* \brief Helper function to update the node color
* \param nodeId Id of the node
* \param r Red component value (0-255)
* \param g Green component value (0-255)
* \param b Blue component value (0-255)
*
*/
void UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b);
/**
* \brief Helper function to set the color of nodes in a container
* \param n Ptr to the node
@@ -279,6 +332,20 @@ public:
std::string fromNodeDescription = "",
std::string toNodeDescription = "");
/**
* \brief Helper function to set the description for a link
* \param fromNode Ptr to the "from Node" of the p2p link
* \param toNode Ptr the "to Node" of the p2p link
* \param linkDescription Description of the link such as link bandwidth
* \param fromNodeDescription Description at the "from Node" end such as IP address
* \param toNodeDescription Description at the "to Node" end such as Ip address
*
*/
static void SetLinkDescription (Ptr <Node> fromNode, Ptr <Node> toNode,
std::string linkDescription,
std::string fromNodeDescription = "",
std::string toNodeDescription = "");
/**
* \brief Helper function to update the description for a link
@@ -290,6 +357,16 @@ public:
void UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
std::string linkDescription);
/**
* \brief Helper function to update the description for a link
* \param fromNode Ptr to the "from Node" of the p2p link
* \param toNode Ptr to the "to Node" of the p2p link
* \param linkDescription Description of the link such as link bandwidth
*
*/
void UpdateLinkDescription (Ptr <Node> fromNode, Ptr <Node> toNode,
std::string linkDescription);
/**
* \brief Is AnimationInterface started
@@ -458,7 +535,7 @@ private:
std::vector<std::string> GetElementsFromContext (std::string context);
Ptr <NetDevice> GetNetDeviceFromContext (std::string context);
static std::map<uint32_t, Rgb> nodeColors;
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;
@@ -479,7 +556,7 @@ private:
std::string GetXMLOpen_topology (double minX, double minY, double maxX, double maxY);
std::string GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY);
std::string GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY, struct Rgb rgb);
std::string GetXMLOpenClose_nodeupdate (uint32_t id, std::string description, struct Rgb rgb);
std::string GetXMLOpenClose_nodeupdate (uint32_t id, bool visible = true);
std::string GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId);
std::string GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string);
std::string GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId, double fbTx, double lbTx, std::string auxInfo = "");