21 #ifndef ANIMATION_INTERFACE__H 
   22 #define ANIMATION_INTERFACE__H 
   28 #include "ns3/net-device.h" 
   29 #include "ns3/node-container.h" 
   30 #include "ns3/nstime.h" 
   32 #include "ns3/node-list.h" 
   33 #include "ns3/random-variable-stream.h" 
   34 #include "ns3/simulator.h" 
   35 #include "ns3/config.h" 
   36 #include "ns3/animation-interface-helper.h" 
   37 #include "ns3/mac48-address.h" 
   38 #include "ns3/lte-ue-net-device.h" 
   39 #include "ns3/lte-enb-net-device.h" 
   40 #include "ns3/uan-phy-gen.h" 
   44 #define MAX_PKTS_PER_TRACE_FILE 100000 
   54   std::string fromNodeDescription;
 
   55   std::string toNodeDescription;
 
   56   std::string linkDescription;
 
   64       if (  ((first.fromNode == second.fromNode) && (first.toNode == second.toNode)) ||
 
   65             ((first.fromNode == second.toNode) && (first.toNode == second.fromNode)) )
 
   69       std::ostringstream oss1;
 
   70       oss1 << first.fromNode << first.toNode;
 
   71       std::ostringstream oss2;
 
   72       oss2 << second.fromNode << second.toNode;
 
   73       return oss1.str () < oss2.str ();
 
   79   std::string destination;
 
  119     uint64_t maxPktsPerFile = MAX_PKTS_PER_TRACE_FILE, 
 
  120     bool usingXML = 
true);
 
  260   void ShowNode (uint32_t nodeId, 
bool show = 
true);
 
  307   void UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b);
 
  330                                   std::string linkDescription,
 
  331                                   std::string fromNodeDescription = 
"",
 
  332                                   std::string toNodeDescription = 
"");
 
  344                                   std::string linkDescription,
 
  345                                   std::string fromNodeDescription = 
"",
 
  346                                   std::string toNodeDescription = 
"");
 
  357                               std::string linkDescription);
 
  367                               std::string linkDescription);
 
  416   int WriteN (
const char*, uint32_t, FILE * f);
 
  418   Time m_mobilityPollInterval;
 
  419   std::string m_outputFileName;
 
  420   bool m_outputFileSet;
 
  422   bool m_randomPosition;
 
  425   bool m_enablePacketMetadata; 
 
  428   uint64_t m_maxPktsPerFile;
 
  429   std::string m_originalFileName;
 
  430   Time m_routingStopTime;
 
  431   std::string m_routingFileName;
 
  432   Time m_routingPollInterval;
 
  435   void TrackIpv4Route ();
 
  436   void TrackIpv4RoutePaths ();
 
  437   std::string GetIpv4RoutingTable (
Ptr <Node> n);
 
  451   bool SetRoutingOutputFile (
const std::string& fn);
 
  481   void DevTxTrace (std::string context,
 
  487   void WifiPhyTxBeginTrace (std::string context,
 
  489   void WifiPhyTxEndTrace (std::string context,
 
  491   void WifiPhyTxDropTrace (std::string context,
 
  493   void WifiPhyRxBeginTrace (std::string context,
 
  495   void WifiPhyRxEndTrace (std::string context,
 
  497   void WifiMacRxTrace (std::string context,
 
  499   void WifiPhyRxDropTrace (std::string context,
 
  501   void WimaxTxTrace (std::string context,
 
  504   void WimaxRxTrace (std::string context,
 
  507   void CsmaPhyTxBeginTrace (std::string context,
 
  509   void CsmaPhyTxEndTrace (std::string context,
 
  511   void CsmaPhyRxEndTrace (std::string context,
 
  513   void CsmaMacRxTrace (std::string context,
 
  516   void LteTxTrace (std::string context,
 
  520   void LteRxTrace (std::string context,
 
  524   void LteSpectrumPhyTxStart (std::string context,
 
  526   void LteSpectrumPhyRxStart (std::string context,
 
  529   void UanPhyGenTxTrace (std::string context,
 
  531   void UanPhyGenRxTrace (std::string context,
 
  537   int  WriteN (
const std::string&, FILE * f);
 
  541   void MobilityAutoCheck ();
 
  544   std::map<uint64_t, AnimPacketInfo> m_pendingWifiPackets;
 
  546   bool WifiPacketIsPending (uint64_t AnimUid); 
 
  548   std::map<uint64_t, AnimPacketInfo> m_pendingWimaxPackets;
 
  550   bool WimaxPacketIsPending (uint64_t AnimUid); 
 
  552   std::map<uint64_t, AnimPacketInfo> m_pendingLtePackets;
 
  554   bool LtePacketIsPending (uint64_t AnimUid);
 
  556   std::map<uint64_t, AnimPacketInfo> m_pendingCsmaPackets;
 
  558   bool CsmaPacketIsPending (uint64_t AnimUid);
 
  560   std::map<uint64_t, AnimPacketInfo> m_pendingUanPackets;
 
  562   bool UanPacketIsPending (uint64_t AnimUid);
 
  566   std::map<uint32_t, Vector> m_nodeLocation;
 
  570   void WriteDummyPacket ();
 
  573   void PurgePendingWifi ();
 
  574   void PurgePendingWimax ();
 
  575   void PurgePendingLte ();
 
  576   void PurgePendingCsma ();
 
  579   void RecalcTopoBounds (
Vector v);
 
  580   std::vector < Ptr <Node> > RecalcTopoBounds ();
 
  582   void ConnectCallbacks ();
 
  588   std::map <std::string, uint32_t> m_macToNodeIdMap;
 
  589   std::map <std::string, uint32_t> m_ipv4ToNodeIdMap;
 
  590   void AddToIpv4AddressNodeIdTable (std::string, uint32_t);
 
  591   std::vector <Ipv4RouteTrackElement> m_ipv4RouteTrackElements;
 
  592   typedef std::vector <Ipv4RoutePathElement> Ipv4RoutePathElements;
 
  593   void RecursiveIpv4RoutePathSearch (std::string fromIpv4, std::string toIpv4, Ipv4RoutePathElements &);
 
  594   void WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements);
 
  595   bool IsInTimeWindow ();
 
  598   std::vector<std::string> GetElementsFromContext (std::string context);
 
  601   static std::map <uint32_t, Rgb> nodeColors;
 
  602   static std::map <uint32_t, std::string> nodeDescriptions;
 
  603   static std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> linkProperties;
 
  604   uint64_t m_currentPktCount;
 
  606   void StartNewTraceFile();
 
  610   void WriteNonP2pLinkProperties (uint32_t 
id, std::string ipv4Address, std::string channelType);
 
  612   std::string GetNetAnimVersion ();
 
  615   std::string GetPreamble (
void);
 
  624   std::string GetXMLOpen_anim (uint32_t lp);
 
  625   std::string GetXMLOpen_topology (
double minX, 
double minY, 
double maxX, 
double maxY);
 
  626   std::string GetXMLOpenClose_node (uint32_t lp, uint32_t 
id, 
double locX, 
double locY);
 
  627   std::string GetXMLOpenClose_node (uint32_t lp, uint32_t 
id, 
double locX, 
double locY, 
struct Rgb rgb);
 
  628   std::string GetXMLOpenClose_nodeupdate (uint32_t 
id, 
bool visible = 
true);
 
  629   std::string GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId);
 
  630   std::string GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string);
 
  631   std::string GetXMLOpen_packet (uint32_t fromLp, uint32_t fromId, 
double fbTx, 
double lbTx, std::string auxInfo = 
"");
 
  632   std::string GetXMLOpenClose_p (std::string pktType, uint32_t fId, 
double fbTx, 
double lbTx, uint32_t tId, 
double fbRx, 
double lbRx,
 
  633                                  std::string metaInfo = 
"", std::string auxInfo = 
"");
 
  634   std::string GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, 
double fbRx, 
double lbRx);
 
  635   std::string GetXMLOpen_wpacket (uint32_t fromLp, uint32_t fromId, 
double fbTx, 
double lbTx, 
double range);
 
  636   std::string GetXMLClose (std::string name) {
return "</" + name + 
">\n"; }
 
  637   std::string GetXMLOpenClose_meta (std::string metaInfo);
 
  638   std::string GetXMLOpenClose_NonP2pLinkProperties (uint32_t 
id, std::string ipv4Address, std::string channelType);
 
  639   std::string GetXMLOpenClose_routing (uint32_t 
id, std::string routingInfo);
 
  640   std::string GetXMLOpenClose_rp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements);
 
  715   virtual void Print (std::ostream &os) 
const;
 
  722   void Set (uint64_t AnimUid);
 
  729   uint64_t 
Get (
void) 
const;
 
void Set(uint64_t AnimUid)
Set global Uid in tag. 
uint64_t GetTracePktCount()
Get trace file packet count (This used only for testing) 
AnimationInterface & AddSourceDestination(uint32_t fromNodeId, std::string destinationIpv4Address)
Helper function to print the routing path from a source node to destination IP. 
void EnablePacketMetadata(bool enable)
Enable Packet metadata. 
static TypeId GetTypeId(void)
Get Type Id. 
static void SetNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to set the node color. 
static bool IsInitialized(void)
Check if AnimationInterface is initialized. 
virtual void Deserialize(TagBuffer i)
Deserialize function. 
void SetStartTime(Time t)
Specify the time at which capture should start. 
void SetStopTime(Time t)
Specify the time at which capture should stop. 
void UpdateNodeColor(Ptr< Node > n, uint8_t r, uint8_t g, uint8_t b)
Helper function to update the node color. 
void ResetAnimWriteCallback()
Reset the write callback function. 
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node. 
virtual void Print(std::ostream &os) const 
Print tag info. 
static void SetLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription, std::string fromNodeDescription="", std::string toNodeDescription="")
Helper function to set the description for a link. 
void SetXMLOutput()
Specify that animation commands are to be written in XML format. 
void SetRandomPosition(bool setRandPos)
Set random position if a Mobility Model does not exists for the node. 
~AnimationInterface()
Destructor for the animator interface. 
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables. 
static void SetNodeDescription(Ptr< Node > n, std::string descr)
Helper function to set a brief description for a given node. 
void StartAnimation(bool restart=false)
Writes the topology information and sets up the appropriate animation packet tx callback. 
int64_t AssignStreams(int64_t stream)
AnimationInterface & EnableIpv4RouteTracking(std::string fileName, Time startTime, Time stopTime, Time pollInterval=Seconds(5))
Enable tracking of the Ipv4 routing table for all Nodes. 
tag a set of bytes in a packet 
keep track of a set of node pointers. 
void UpdateLinkDescription(uint32_t fromNode, uint32_t toNode, std::string linkDescription)
Helper function to update the description for a link. 
virtual void Serialize(TagBuffer i) const 
Serialize function. 
bool SetOutputFile(const std::string &fn)
Specify that animation commands are to be written to the specified output file. 
Byte tag using by Anim to uniquely identify packets. 
virtual TypeId GetInstanceTypeId(void) const 
Get Instance Type Id. 
void StopAnimation(bool onlyAnimation=false)
Closes the interface to the animator. 
uint64_t Get(void) const 
Get Uid in tag. 
Time Seconds(double seconds)
create ns3::Time instances in units of seconds. 
AnimationInterface(const std::string filename, uint64_t maxPktsPerFile=MAX_PKTS_PER_TRACE_FILE, bool usingXML=true)
Constructor. 
virtual uint32_t GetSerializedSize(void) const 
Get Serialized Size. 
Interface to network animator. 
void SetAnimWriteCallback(AnimWriteCallback cb)
Set a callback function to listen to AnimationInterface write events. 
void SetMobilityPollInterval(Time t)
Set mobility poll interval:WARNING: setting a low interval can cause slowness. 
A structure to store red, blue and green components for entities such as nodes. 
void ShowNode(uint32_t nodeId, bool show=true)
Helper function to show/hide a node. 
bool IsStarted(void)
Is AnimationInterface started. 
a unique identifier for an interface. 
void(* AnimWriteCallback)(const char *str)
typedef for WriteCallBack used for listening to AnimationInterface write messages ...
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node. 
AnimPacketInfo helper class.