NetAnim: Add description to NodeContainers
This commit is contained in:
@@ -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 ();
|
||||
|
||||
@@ -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 <uint32_t, std::string> 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 <Node> 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<const Packe
|
||||
NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid");
|
||||
AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n));
|
||||
AddPendingCsmaPacket (AnimUid, pktinfo);
|
||||
NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway");
|
||||
}
|
||||
// TODO: NS_ASSERT (CsmaPacketIsPending (AnimUid) == true);
|
||||
AnimPacketInfo& pktInfo = pendingCsmaPackets[AnimUid];
|
||||
@@ -1251,6 +1255,22 @@ void AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y,
|
||||
|
||||
}
|
||||
|
||||
void AnimationInterface::SetNodeDescription (Ptr <Node> 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 <Node> 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 <<"<node lp = \"" << lp << "\" id = \"" << id << "\"" << " locX = \""
|
||||
<< locX << "\" " << "locY = \"" << locY << "\" />\n";
|
||||
oss <<"<node id = \"" << id << "\"";
|
||||
if (nodeDescriptions.find (id) != nodeDescriptions.end ())
|
||||
{
|
||||
oss << " descr=\""<< nodeDescriptions[id] << "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << " descr=\"\"";
|
||||
}
|
||||
oss << " locX = \"" << locX << "\" " << "locY = \"" << locY << "\" />\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 << "<wpacket fromId=\"" << fromId
|
||||
<< "\" fbTx=\"" << fbTx
|
||||
<< "\" lbTx=\"" << lbTx
|
||||
<< "\" range= \"" << range << "\">" << std::endl;
|
||||
<< "\" range=\"" << range << "\">" << std::endl;
|
||||
return oss.str ();
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <map>
|
||||
#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 <Node> 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 <Node> 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<std::string> GetElementsFromContext (std::string context);
|
||||
Ptr <NetDevice> GetNetDeviceFromContext (std::string context);
|
||||
|
||||
static std::map <uint32_t, std::string> nodeDescriptions;
|
||||
|
||||
// XML helpers
|
||||
std::string GetPreamble (void);
|
||||
// Topology element dimensions
|
||||
|
||||
Reference in New Issue
Block a user