diff --git a/src/netanim/examples/dynamic_linknode.cc b/src/netanim/examples/dynamic_linknode.cc index 0ec87a7ef..1cbcb4a2c 100644 --- a/src/netanim/examples/dynamic_linknode.cc +++ b/src/netanim/examples/dynamic_linknode.cc @@ -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); diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index bc7a368a6..56ae5fbfe 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -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 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 n, bool show) +{ + ShowNode (n, show); +} + +void AnimationInterface::UpdateNodeColor (Ptr 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 fromNode, Ptr 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 fromNode, Ptr 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 n, std::string descr) { if (initialized) @@ -1461,6 +1514,22 @@ void AnimationInterface::SetNodeDescription (Ptr n, std::string descr) nodeDescriptions[n->GetId ()] = descr; } +void AnimationInterface::UpdateNodeDescription (Ptr 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 << "\n"; + return oss.str (); + +} + std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id, double locX, double locY) { std::ostringstream oss; - oss <<" - * Modified by: John Abraham + * Author: John Abraham */ // Interface between ns3 and the network animator @@ -236,6 +236,38 @@ public: */ static void SetNodeDescription (Ptr 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 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 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 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 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 fromNode, Ptr 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 fromNode, Ptr toNode, + std::string linkDescription); + /** * \brief Is AnimationInterface started @@ -458,7 +535,7 @@ private: std::vector GetElementsFromContext (std::string context); Ptr GetNetDeviceFromContext (std::string context); - static std::map nodeColors; + static std::map nodeColors; static std::map nodeDescriptions; static std::map 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 = "");