diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index a0135fa1c..e550e2fc2 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -61,7 +61,8 @@ AnimationInterface::AnimationInterface () : m_fHandle (STDOUT_FILENO), m_xml (false), mobilitypollinterval (Seconds(0.25)), usingSockets (false), mport (0), outputfilename (""), OutputFileSet (false), ServerPortSet (false), gAnimUid (0),randomPosition (true), - m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true) + m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true), + m_enablePacketMetadata (false) { initialized = true; StartAnimation (); @@ -71,7 +72,8 @@ AnimationInterface::AnimationInterface (const std::string fn, bool usingXML) : m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)), usingSockets (false), mport (0), outputfilename (fn), OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true), - m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true) + m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true), + m_enablePacketMetadata (false) { initialized = true; StartAnimation (); @@ -81,7 +83,8 @@ AnimationInterface::AnimationInterface (const uint16_t port, bool usingXML) : m_fHandle (STDOUT_FILENO), m_xml (usingXML), mobilitypollinterval (Seconds(0.25)), usingSockets (true), mport (port), outputfilename (""), OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true), - m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true) + m_writeCallback (0), m_started (false), m_enforceWifiMacRx (true), + m_enablePacketMetadata (false) { initialized = true; StartAnimation (); @@ -123,6 +126,13 @@ bool AnimationInterface::SetOutputFile (const std::string& fn) return true; } +void AnimationInterface::EnablePacketMetadata (bool enable) +{ + m_enablePacketMetadata = enable; + if (enable) + Packet::EnablePrinting (); +} + bool AnimationInterface::IsInitialized () { return initialized; @@ -642,8 +652,8 @@ void AnimationInterface::WriteDummyPacket () double lbRx = now.GetSeconds (); if (m_xml) { - oss << GetXMLOpen_packet (0,0,fbTx,lbTx,"DummyPktIgnoreThis"); - oss << GetXMLOpenClose_rx (0,0,fbRx,lbRx); + oss << GetXMLOpen_packet (0, 0, fbTx, lbTx, "DummyPktIgnoreThis"); + oss << GetXMLOpenClose_rx (0, 0, fbRx, lbRx); oss << GetXMLClose ("packet"); } WriteN (m_fHandle, oss.str ()); @@ -666,8 +676,10 @@ void AnimationInterface::DevTxTrace (std::string context, Ptr p, double lbRx = (now + rxTime).GetSeconds (); if (m_xml) { - oss << GetXMLOpen_packet (0,tx->GetNode ()->GetId (),fbTx,lbTx); - oss << GetXMLOpenClose_rx (0,rx->GetNode ()->GetId (),fbRx,lbRx); + oss << GetXMLOpen_packet (0, tx->GetNode ()->GetId (), fbTx, lbTx); + oss << GetXMLOpenClose_rx (0, rx->GetNode ()->GetId (), fbRx, lbRx); + if (m_enablePacketMetadata) + oss << GetXMLOpenClose_meta (GetPacketMetadata (p)); oss << GetXMLClose ("packet"); } else @@ -794,7 +806,7 @@ void AnimationInterface::WifiPhyRxBeginTrace (std::string context, if (m_enforceWifiMacRx) return; pendingWifiPackets[AnimUid].ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n)); - OutputWirelessPacket (pendingWifiPackets[AnimUid], pendingWifiPackets[AnimUid].GetRxInfo (ndev)); + OutputWirelessPacket (p, pendingWifiPackets[AnimUid], pendingWifiPackets[AnimUid].GetRxInfo (ndev)); } @@ -841,7 +853,7 @@ void AnimationInterface::WifiMacRxTrace (std::string context, if (pktrxInfo.IsPhyRxComplete ()) { NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete"); - OutputWirelessPacket (pktInfo, pktrxInfo); + OutputWirelessPacket (p, pktInfo, pktrxInfo); } } @@ -885,7 +897,7 @@ void AnimationInterface::WimaxRxTrace (std::string context, Ptr p, pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n)); //TODO 0.001 is used until Wimax implements RxBegin and RxEnd traces AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev); - OutputWirelessPacket (pktInfo, pktrxInfo); + OutputWirelessPacket (p, pktInfo, pktrxInfo); } void AnimationInterface::LteTxTrace (std::string context, Ptr p, const Mac48Address & m) @@ -927,7 +939,7 @@ void AnimationInterface::LteRxTrace (std::string context, Ptr p, c pktInfo.ProcessRxEnd (ndev, Simulator::Now () + Seconds (0.001), UpdatePosition (n)); //TODO 0.001 is used until Lte implements RxBegin and RxEnd traces AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev); - OutputWirelessPacket (pktInfo, pktrxInfo); + OutputWirelessPacket (p, pktInfo, pktrxInfo); } @@ -1011,7 +1023,7 @@ void AnimationInterface::CsmaMacRxTrace (std::string context, if (pktrxInfo.IsPhyRxComplete ()) { NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete"); - OutputCsmaPacket (pktInfo, pktrxInfo); + OutputCsmaPacket (p, pktInfo, pktrxInfo); } } @@ -1082,6 +1094,12 @@ void AnimationInterface::MobilityAutoCheck () } } +std::string AnimationInterface::GetPacketMetadata (Ptr p) +{ + std::ostringstream oss; + p->Print (oss); + return oss.str (); +} // Helper to output a wireless packet. // For now, only the XML interface is supported @@ -1134,7 +1152,7 @@ std::string AnimationInterface::GetPreamble () return s; } -void AnimationInterface::OutputWirelessPacket (AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo) +void AnimationInterface::OutputWirelessPacket (Ptr p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo) { NS_ASSERT (m_xml); std::ostringstream oss; @@ -1146,12 +1164,14 @@ void AnimationInterface::OutputWirelessPacket (AnimPacketInfo &pktInfo, AnimRxIn uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId (); oss << GetXMLOpenClose_rx (0, rxId, pktrxInfo.m_fbRx, pktrxInfo.m_lbRx); + if (m_enablePacketMetadata) + oss << GetXMLOpenClose_meta (GetPacketMetadata (p)); oss << GetXMLClose ("wpacket"); WriteN (m_fHandle, oss.str ()); } -void AnimationInterface::OutputCsmaPacket (AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo) +void AnimationInterface::OutputCsmaPacket (Ptr p, AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo) { NS_ASSERT (m_xml); std::ostringstream oss; @@ -1161,6 +1181,8 @@ void AnimationInterface::OutputCsmaPacket (AnimPacketInfo &pktInfo, AnimRxInfo p oss << GetXMLOpen_packet (0, nodeId, pktInfo.m_fbTx, pktInfo.m_lbTx); uint32_t rxId = pktrxInfo.m_rxnd->GetNode ()->GetId (); oss << GetXMLOpenClose_rx (0, rxId, pktrxInfo.m_fbRx, pktrxInfo.m_lbRx); + if (m_enablePacketMetadata) + oss << GetXMLOpenClose_meta (GetPacketMetadata (p)); oss << GetXMLClose ("packet"); WriteN (m_fHandle, oss.str ()); } @@ -1251,6 +1273,14 @@ std::string AnimationInterface::GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId return oss.str (); } +std::string AnimationInterface::GetXMLOpenClose_meta (std::string metaInfo) +{ + std::ostringstream oss; + oss << "" << std::endl; + return oss.str (); +} + std::vector AnimationInterface::GetElementsFromContext (std::string context) { std::vector elements; diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index 50a0d6c0e..9c45c69a8 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -225,6 +225,14 @@ public: */ void ShowAll802_11 (bool showAll); + /** + * + * \brief Enable Packet metadata + * \param enable if true enables writing the packet metadata to the XML trace file + * if false disables writing the packet metadata + */ + void EnablePacketMetadata (bool enable); + private: #ifndef WIN32 int m_fHandle; // File handle for output (-1 if none) @@ -289,8 +297,8 @@ private: // Write a string to the specified handle; int WriteN (int, const std::string&); - void OutputWirelessPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); - void OutputCsmaPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); + void OutputWirelessPacket (Ptr p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); + void OutputCsmaPacket (Ptr p, AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); void MobilityAutoCheck (); uint64_t gAnimUid ; // Packet unique identifier used by Animtion @@ -336,6 +344,7 @@ private: bool m_started; bool m_enforceWifiMacRx; + bool m_enablePacketMetadata; // Path helper std::vector GetElementsFromContext (std::string context); @@ -349,6 +358,8 @@ private: double topo_maxX; double topo_maxY; + std::string GetPacketMetadata (Ptr p); + std::string GetXMLOpen_anim (uint32_t lp); 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); @@ -357,6 +368,7 @@ private: std::string GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx); std::string GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, double range); std::string GetXMLClose (std::string name) {return "\n"; } + std::string GetXMLOpenClose_meta (std::string metaInfo); };