#ifndef ANIMATION_TRACE_H #define ANIMATION_TRACE_H #include "ns3/object.h" #include "ns3/config.h" #include "ns3/log.h" #include "ns3/net-device.h" #include "ns3/node-list.h" #include "ns3/nstime.h" #include "ns3/ptr.h" #include "ns3/simulator.h" #include #include // Add a doxygen group for this module. // If you have more than one file, this should be in only one of them. /** * \defgroup animation-trace Description of the animation-trace */ namespace ns3 { class AnimationTrace : public Object { public: /** * \brief Constructor * \param filename The Filename for the trace file used by the Animator * */ AnimationTrace(const std::string filename); /** * \brief Destructor for the animator interface. * */ ~AnimationTrace(); void StartAnimation(); void StopAnimation(); void SetNodePosition(Ptr n, int x, int y); /// AnimXmlElement class class AnimXmlElement { public: /** * Constructor * * \param tagName tag name * \param emptyElement empty element? */ AnimXmlElement(std::string tagName, bool emptyElement = true); template /** * Add attribute function * \param attribute the attribute name * \param value the attribute value * \param xmlEscape true to escape */ void AddAttribute(std::string attribute, T value, bool xmlEscape = false); /** * Set text function * \param text the text for the element */ void SetText(std::string text); /** * Append child function * \param e the element to add as a child */ void AppendChild(AnimXmlElement e); /** * Get text for the element function * \param autoClose auto close the element * \returns the text */ std::string ToString(bool autoClose = true); private: std::string m_tagName; ///< tag name std::string m_text; ///< element string std::vector m_attributes; ///< list of attributes std::vector m_children; ///< list of children }; private: void SetOutputFile(const std::string& fn); void WriteNodes(); void WriteNodeColors(); void WriteNodeSizes(); void WriteNodeDescription(); void WriteLinkProperties(); void WriteXmlAnim(); void WriteXmlClose(std::string name); void WriteXmlNode(uint32_t id, uint32_t sysId, double locX, double locY); void WriteXmlNodeColors(uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b); void WriteXmlUpdateNodeSize(uint32_t nodeId, double width, double height); void WriteXmlUpdateNodeDescription(Ptr n); void WriteXmlLink(uint32_t fromId, uint32_t toLp, uint32_t toId); void WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, uint32_t tId, double fbRx, double lbRx, std::string metaInfo = ""); void ConnectCallbacks(); void DevTxTrace(std::string context, Ptr p, Ptr tx, Ptr rx, Time txTime, Time rxTime); bool CheckMaxPktsPerTraceFile(); int WriteN(const std::string& st, FILE* f); int WriteN(const char* data, uint32_t count, FILE* f); std::string GetPacketMetadata(Ptr p); std::string m_version = "netanim-3.109"; std::string m_outputFileName; uint64_t m_currentPktCount = 0; uint64_t m_maxPkts = 10000; FILE* m_f; uint64_t gAnimUid; ///< Packet unique identifier used by AnimationInterface std::map> m_nodeLocation; ///< node location std::map m_nodeDescription; }; } #endif /* ANIMATION_TRACE_H */