src/netanim/model/animation-interface.h
changeset 8773 25b20434eba8
parent 7823 2a669a0c452e
child 8803 e51a5a77909c
equal deleted inserted replaced
8772:ce0699130fc4 8773:25b20434eba8
    50 #define HANDLETYPE int
    50 #define HANDLETYPE int
    51 #endif
    51 #endif
    52 
    52 
    53 namespace ns3 {
    53 namespace ns3 {
    54 
    54 
       
    55 #define MAX_PKTS_PER_TRACE_FILE 100000
       
    56 
    55 /**
    57 /**
    56  * \defgroup netanim Netanim
    58  * \defgroup netanim Netanim
    57  *
    59  *
    58  * This section documents the API of the ns-3 netanim module. For a generic functional description, please refer to the ns-3 manual.
    60  * This section documents the API of the ns-3 netanim module. For a generic functional description, please refer to the ns-3 manual.
    59  */
    61  */
    83   ~AnimationInterface ();
    85   ~AnimationInterface ();
    84 
    86 
    85   /**
    87   /**
    86    * \brief Constructor
    88    * \brief Constructor
    87    * \param filename The Filename for the trace file used by the Animator
    89    * \param filename The Filename for the trace file used by the Animator
       
    90    * \param maxPktsPerFile The maximum number of packets per trace file.
       
    91 	    AnimationInterface will create trace files with the following 
       
    92             filenames : filename, filename-1, filename-2..., filename-N
       
    93 	    where each file contains packet info for 'maxPktPerFile' number of packets
    88    * \param usingXML Set to true if XML output traces are required
    94    * \param usingXML Set to true if XML output traces are required
    89    *
    95    *
    90    */
    96    */
    91   AnimationInterface (const std::string filename, bool usingXML = true);
    97   AnimationInterface (const std::string filename, 
       
    98 	uint64_t maxPktsPerFile = MAX_PKTS_PER_TRACE_FILE, 
       
    99 	bool usingXML = true);
    92 
   100 
    93   /**
   101   /**
    94    * \brief Constructor
   102    * \brief Constructor
    95    * \param port Port on which ns-3 should listen to for connection from the
   103    * \param port Port on which ns-3 should listen to for connection from the
    96    *        external netanim application
   104    *        external netanim application
   167    *
   175    *
   168    * Writes the topology information to the appropriate output, depending
   176    * Writes the topology information to the appropriate output, depending
   169    * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
   177    * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
   170    * Then creates the callbacks needed for the animator to start processing
   178    * Then creates the callbacks needed for the animator to start processing
   171    * packets.
   179    * packets.
   172    *
   180    * 
   173    */
   181    * \param restart True when restarting animation
   174   void StartAnimation ();
   182    */
       
   183   void StartAnimation (bool restart = false);
   175 
   184 
   176   /**
   185   /**
   177    * \brief Closes the interface to the animator.
   186    * \brief Closes the interface to the animator.
   178    *
   187    *
   179    */
   188    */
   266    * \param enable if true enables writing the packet metadata to the XML trace file
   275    * \param enable if true enables writing the packet metadata to the XML trace file
   267    *        if false disables writing the packet metadata
   276    *        if false disables writing the packet metadata
   268    */
   277    */
   269   void EnablePacketMetadata (bool enable);
   278   void EnablePacketMetadata (bool enable);
   270 
   279 
       
   280 
       
   281   /**
       
   282    *
       
   283    * \brief Get trace file packet count (This used only for testing)
       
   284    *
       
   285    * returns Number of packets recorded in the current trace file
       
   286    *
       
   287    */
       
   288   uint64_t GetTracePktCount ();
   271 
   289 
   272 
   290 
   273 private:
   291 private:
   274 #ifndef WIN32
   292 #ifndef WIN32
   275   int m_fHandle;  // File handle for output (-1 if none)
   293   int m_fHandle;  // File handle for output (-1 if none)
   278 #else
   296 #else
   279   SOCKET m_fHandle;  // File handle for output (-1 if none)
   297   SOCKET m_fHandle;  // File handle for output (-1 if none)
   280   int  WriteN (SOCKET, const char*, uint32_t);
   298   int  WriteN (SOCKET, const char*, uint32_t);
   281 #endif
   299 #endif
   282   bool m_xml;      // True if xml format desired
   300   bool m_xml;      // True if xml format desired
   283   Time mobilitypollinterval;
   301   Time m_mobilityPollInterval;
   284   bool usingSockets;
   302   bool m_usingSockets;
   285   uint16_t mport;
   303   uint16_t m_port;
   286   std::string outputfilename;
   304   std::string m_outputFileName;
   287   bool OutputFileSet;
   305   bool m_outputFileSet;
   288   bool ServerPortSet;
   306   bool m_serverPortSet;
       
   307   uint64_t gAnimUid ;    // Packet unique identifier used by Animtion
       
   308   bool m_randomPosition;
       
   309   AnimWriteCallback m_writeCallback;
       
   310   bool m_started;
       
   311   bool m_enablePacketMetadata; 
       
   312   Time m_startTime;
       
   313   Time m_stopTime;
       
   314   uint64_t m_maxPktsPerFile;
       
   315   std::string m_originalFileName;
   289 
   316 
   290   void DevTxTrace (std::string context,
   317   void DevTxTrace (std::string context,
   291                    Ptr<const Packet> p,
   318                    Ptr<const Packet> p,
   292                    Ptr<NetDevice> tx,
   319                    Ptr<NetDevice> tx,
   293                    Ptr<NetDevice> rx,
   320                    Ptr<NetDevice> rx,
   337 
   364 
   338   void OutputWirelessPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
   365   void OutputWirelessPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
   339   void OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
   366   void OutputCsmaPacket (Ptr<const Packet> p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo);
   340   void MobilityAutoCheck ();
   367   void MobilityAutoCheck ();
   341   
   368   
   342   uint64_t gAnimUid ;    // Packet unique identifier used by Animtion
   369 
   343 
   370   std::map<uint64_t, AnimPacketInfo> m_pendingWifiPackets;
   344   std::map<uint64_t, AnimPacketInfo> pendingWifiPackets;
       
   345   void AddPendingWifiPacket (uint64_t AnimUid, AnimPacketInfo&);
   371   void AddPendingWifiPacket (uint64_t AnimUid, AnimPacketInfo&);
   346   bool WifiPacketIsPending (uint64_t AnimUid); 
   372   bool WifiPacketIsPending (uint64_t AnimUid); 
   347 
   373 
   348   std::map<uint64_t, AnimPacketInfo> pendingWimaxPackets;
   374   std::map<uint64_t, AnimPacketInfo> m_pendingWimaxPackets;
   349   void AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo&);
   375   void AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo&);
   350   bool WimaxPacketIsPending (uint64_t AnimUid); 
   376   bool WimaxPacketIsPending (uint64_t AnimUid); 
   351 
   377 
   352   std::map<uint64_t, AnimPacketInfo> pendingLtePackets;
   378   std::map<uint64_t, AnimPacketInfo> m_pendingLtePackets;
   353   void AddPendingLtePacket (uint64_t AnimUid, AnimPacketInfo&);
   379   void AddPendingLtePacket (uint64_t AnimUid, AnimPacketInfo&);
   354   bool LtePacketIsPending (uint64_t AnimUid);
   380   bool LtePacketIsPending (uint64_t AnimUid);
   355 
   381 
   356   std::map<uint64_t, AnimPacketInfo> pendingCsmaPackets;
   382   std::map<uint64_t, AnimPacketInfo> m_pendingCsmaPackets;
   357   void AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo&);
   383   void AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo&);
   358   bool CsmaPacketIsPending (uint64_t AnimUid);
   384   bool CsmaPacketIsPending (uint64_t AnimUid);
   359 
   385 
   360   uint64_t GetAnimUidFromPacket (Ptr <const Packet>);
   386   uint64_t GetAnimUidFromPacket (Ptr <const Packet>);
   361 
   387 
   362   std::map<uint32_t, Vector> nodeLocation;
   388   std::map<uint32_t, Vector> m_nodeLocation;
   363   Vector GetPosition (Ptr <Node> n);
   389   Vector GetPosition (Ptr <Node> n);
   364   Vector UpdatePosition (Ptr <Node> n);
   390   Vector UpdatePosition (Ptr <Node> n);
   365   Vector UpdatePosition (Ptr <Node> n, Vector v);
   391   Vector UpdatePosition (Ptr <Node> n, Vector v);
   366   void WriteDummyPacket ();
   392   void WriteDummyPacket ();
   367   bool NodeHasMoved (Ptr <Node> n, Vector newLocation);
   393   bool NodeHasMoved (Ptr <Node> n, Vector newLocation);
   374 
   400 
   375   // Recalculate topology bounds
   401   // Recalculate topology bounds
   376   void RecalcTopoBounds (Vector v);
   402   void RecalcTopoBounds (Vector v);
   377   std::vector < Ptr <Node> > RecalcTopoBounds ();
   403   std::vector < Ptr <Node> > RecalcTopoBounds ();
   378 
   404 
   379   bool randomPosition;
       
   380   AnimWriteCallback m_writeCallback;
       
   381   void ConnectCallbacks ();
   405   void ConnectCallbacks ();
   382 
   406 
   383   bool m_started;
       
   384   bool m_enablePacketMetadata; 
       
   385   Time m_startTime;
       
   386   Time m_stopTime;
       
   387   
   407   
   388   std::map <std::string, uint32_t> m_macToNodeIdMap;
   408   std::map <std::string, uint32_t> m_macToNodeIdMap;
   389   bool IsInTimeWindow ();
   409   bool IsInTimeWindow ();
   390 
   410 
   391   // Path helper
   411   // Path helper
   392   std::vector<std::string> GetElementsFromContext (std::string context);
   412   std::vector<std::string> GetElementsFromContext (std::string context);
   393   Ptr <NetDevice> GetNetDeviceFromContext (std::string context);
   413   Ptr <NetDevice> GetNetDeviceFromContext (std::string context);
   394 
   414 
   395   static std::map <uint32_t, std::string> nodeDescriptions;
   415   static std::map <uint32_t, std::string> nodeDescriptions;
       
   416   uint64_t m_currentPktCount;
       
   417 
       
   418   void StartNewTraceFile();
   396 
   419 
   397   // XML helpers
   420   // XML helpers
   398   std::string GetPreamble (void);
   421   std::string GetPreamble (void);
   399   // Topology element dimensions
   422   // Topology element dimensions
   400   double topo_minX;
   423   double m_topoMinX;
   401   double topo_minY;
   424   double m_topoMinY;
   402   double topo_maxX;
   425   double m_topoMaxX;
   403   double topo_maxY;
   426   double m_topoMaxY;
   404 
   427 
   405   std::string GetPacketMetadata (Ptr<const Packet> p);
   428   std::string GetPacketMetadata (Ptr<const Packet> p);
   406 
   429 
   407   std::string GetXMLOpen_anim (uint32_t lp);
   430   std::string GetXMLOpen_anim (uint32_t lp);
   408   std::string GetXMLOpen_topology (double minX,double minY,double maxX,double maxY);
   431   std::string GetXMLOpen_topology (double minX,double minY,double maxX,double maxY);