From 6445633ff8da7262b55563b4bcd36f4fcc2d39f3 Mon Sep 17 00:00:00 2001 From: John Abraham Date: Fri, 16 Sep 2011 11:22:52 -0400 Subject: [PATCH] NetAnim: Connect Csma traces --- .../helper/animation-interface-helper.cc | 10 ++ .../helper/animation-interface-helper.h | 19 ++- src/netanim/model/animation-interface.cc | 146 +++++++++++++++--- src/netanim/model/animation-interface.h | 20 ++- src/netanim/wscript | 2 +- 5 files changed, 171 insertions(+), 26 deletions(-) diff --git a/src/netanim/helper/animation-interface-helper.cc b/src/netanim/helper/animation-interface-helper.cc index e8b052146..fec23ac00 100644 --- a/src/netanim/helper/animation-interface-helper.cc +++ b/src/netanim/helper/animation-interface-helper.cc @@ -60,6 +60,7 @@ bool AnimPacketInfo::ProcessRxEnd (Ptr nd, const Time& lbRx, Ve } rxInfo.rxRange = CalculateDistance (m_txLoc, rxLoc); rxInfo.m_lbRx = lbRx.GetSeconds (); + rxInfo.SetPhyRxComplete (); firstlastbitDelta = rxInfo.m_lbRx - rxInfo.m_fbRx; return true; } @@ -81,5 +82,14 @@ void AnimPacketInfo::ProcessRxDrop (Ptr nd) { } +bool AnimRxInfo::IsPhyRxComplete () +{ + return m_PhyRxComplete; +} + +void AnimRxInfo::SetPhyRxComplete () +{ + m_PhyRxComplete = true; +} } // namespace ns3 diff --git a/src/netanim/helper/animation-interface-helper.h b/src/netanim/helper/animation-interface-helper.h index 89f7b1bab..c0fce3e22 100644 --- a/src/netanim/helper/animation-interface-helper.h +++ b/src/netanim/helper/animation-interface-helper.h @@ -62,8 +62,7 @@ public: * */ AnimRxInfo (const Time& fbRx, Ptr nd ,double rxRange) - : m_fbRx (fbRx.GetSeconds ()), m_lbRx (0), m_rxnd (nd), - rxRange (rxRange) {} + : m_fbRx (fbRx.GetSeconds ()), m_lbRx (0), m_rxnd (nd), rxRange (rxRange), m_PhyRxComplete (false){} /** * \brief First bit receive time @@ -92,6 +91,22 @@ public: * */ double rxRange; + + /** + * \brief Check if Wifi Phy Rx is Complete + * \returns true if Wifi Phy Rx is complete + * + */ + bool IsPhyRxComplete (); + + /** + * \brief Set Wifi Phy Rx Complete + * + */ + void SetPhyRxComplete (); + +private: + bool m_PhyRxComplete; }; diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index daedbbb56..ca7409449 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -161,6 +161,11 @@ bool AnimationInterface::WifiPacketIsPending (uint64_t AnimUid) return (pendingWifiPackets.find (AnimUid) != pendingWifiPackets.end ()); } +bool AnimationInterface::CsmaPacketIsPending (uint64_t AnimUid) +{ + return (pendingCsmaPackets.find (AnimUid) != pendingCsmaPackets.end ()); +} + bool AnimationInterface::WimaxPacketIsPending (uint64_t AnimUid) { @@ -187,20 +192,16 @@ Vector AnimationInterface::UpdatePosition (Ptr n) else { NS_LOG_WARN ( "Node:" << n->GetId () << " Does not have a mobility model"); + Vector deterministicVector (100,100,0); + Vector randomVector (UniformVariable ().GetInteger (0,1000), UniformVariable ().GetInteger (0,1000), 0); if (randomPosition) { - Vector deterministicVector (100,100,0); - Vector randomVector (UniformVariable ().GetInteger (0,1000), UniformVariable ().GetInteger (0,1000), 0); - if (randomPosition) - { - nodeLocation[n->GetId ()] = randomVector; - } - else - { - nodeLocation[n->GetId ()] = deterministicVector; - } + nodeLocation[n->GetId ()] = randomVector; + } + else + { + nodeLocation[n->GetId ()] = deterministicVector; } - } return nodeLocation[n->GetId ()]; } @@ -343,14 +344,22 @@ void AnimationInterface::StartAnimation () MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this)); Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxEnd", MakeCallback (&AnimationInterface::WifiPhyRxEndTrace, this)); - Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop", - MakeCallback (&AnimationInterface::WifiPhyRxDropTrace, this)); + Config::Connect ("NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx", + MakeCallback (&AnimationInterface::WifiMacRxTrace, this)); Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this)); Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx", MakeCallback (&AnimationInterface::WimaxTxTrace, this)); Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx", MakeCallback (&AnimationInterface::WimaxRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin", + MakeCallback (&AnimationInterface::CsmaPhyTxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd", + MakeCallback (&AnimationInterface::CsmaPhyTxEndTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd", + MakeCallback (&AnimationInterface::CsmaPhyRxEndTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx", + MakeCallback (&AnimationInterface::CsmaMacRxTrace, this)); @@ -485,7 +494,7 @@ void AnimationInterface::WriteDummyPacket () double lbRx = now.GetSeconds (); if (m_xml) { - oss << GetXMLOpen_packet (0,0,fbTx,lbTx); + oss << GetXMLOpen_packet (0,0,fbTx,lbTx,"DummyPktIgnoreThis"); oss << GetXMLOpenClose_rx (0,0,fbRx,lbRx); oss << GetXMLClose ("packet"); } @@ -551,6 +560,12 @@ void AnimationInterface::AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo } +void AnimationInterface::AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo &pktinfo) +{ + NS_ASSERT (pktinfo.m_txnd); + pendingCsmaPackets[AnimUid] = pktinfo; +} + uint64_t AnimationInterface::GetAnimUidFromPacket (Ptr p) { AnimByteTag tag; @@ -621,16 +636,28 @@ void AnimationInterface::WifiPhyRxEndTrace (std::string context, uint64_t AnimUid = GetAnimUidFromPacket (p); NS_ASSERT (WifiPacketIsPending (AnimUid) == true); AnimPacketInfo& pktInfo = pendingWifiPackets[AnimUid]; - if (pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n))) + pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n)); +} + +void AnimationInterface::WifiMacRxTrace (std::string context, + Ptr p) +{ + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + uint64_t AnimUid = GetAnimUidFromPacket (p); + NS_ASSERT (WifiPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = pendingWifiPackets[AnimUid]; + AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev); + if (pktrxInfo.IsPhyRxComplete ()) { - AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev); - NS_LOG_INFO ("RxEndTrace for packet:" << AnimUid << " complete"); + NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete"); OutputWirelessPacket (pktInfo, pktrxInfo); pktInfo.RemoveRxInfo (ndev); } + } - - void AnimationInterface::WifiPhyRxDropTrace (std::string context, Ptr p) { @@ -669,6 +696,69 @@ void AnimationInterface::WimaxRxTrace (std::string context, Ptr p, OutputWirelessPacket (pktInfo, pktrxInfo); } +void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) +{ + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + gAnimUid++; + NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid); + AnimByteTag tag; + tag.Set (gAnimUid); + p->AddByteTag (tag); + AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now (), UpdatePosition (n)); + AddPendingCsmaPacket (gAnimUid, pktinfo); + +} + +void AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr p) +{ + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + uint64_t AnimUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << AnimUid); + NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = pendingCsmaPackets[AnimUid]; + pktInfo.m_lbTx = Simulator::Now ().GetSeconds (); +} + +void AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr p) +{ + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + uint64_t AnimUid = GetAnimUidFromPacket (p); + NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = pendingCsmaPackets[AnimUid]; + pendingCsmaPackets[AnimUid].ProcessRxBegin (ndev, Simulator::Now ()); + pktInfo.ProcessRxEnd (ndev, Simulator::Now (), UpdatePosition (n)); + NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << AnimUid); +} + + +void AnimationInterface::CsmaMacRxTrace (std::string context, + Ptr p) +{ + NS_LOG_FUNCTION (this); + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + uint64_t AnimUid = GetAnimUidFromPacket (p); + NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = pendingCsmaPackets[AnimUid]; + AnimRxInfo pktrxInfo = pktInfo.GetRxInfo (ndev); + if (pktrxInfo.IsPhyRxComplete ()) + { + NS_LOG_INFO ("MacRxTrace for packet:" << AnimUid << " complete"); + OutputCsmaPacket (pktInfo, pktrxInfo); + pktInfo.RemoveRxInfo (ndev); + } +} + + void AnimationInterface::MobilityCourseChangeTrace (Ptr mobility) { @@ -798,6 +888,21 @@ void AnimationInterface::OutputWirelessPacket (AnimPacketInfo &pktInfo, AnimRxIn WriteN (m_fHandle, oss.str ()); } +void AnimationInterface::OutputCsmaPacket (AnimPacketInfo &pktInfo, AnimRxInfo pktrxInfo) +{ + NS_ASSERT (m_xml); + std::ostringstream oss; + NS_ASSERT (pktInfo.m_txnd); + uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId (); + + 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); + oss << GetXMLClose ("packet"); + WriteN (m_fHandle, oss.str ()); +} + + // XML Private Helpers std::string AnimationInterface::GetXMLOpen_anim (uint32_t lp) @@ -833,13 +938,14 @@ std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp,uint32_t f } -std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx) +std::string AnimationInterface::GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, std::string auxInfo) { std::ostringstream oss; oss << std::setprecision (10); oss << ""; return oss.str (); } diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index e5b1d9bb4..814f2dcd4 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -106,7 +106,7 @@ public: void SetXMLOutput (); /** - * \brief Specify that animation commands are to be written to + * \brief (Deprecated) Specify that animation commands are to be written to * a socket. * * This call is used to set the ns3 process in server mode, waiting @@ -204,6 +204,8 @@ private: Ptr p); void WifiPhyRxEndTrace (std::string context, Ptr p); + void WifiMacRxTrace (std::string context, + Ptr p); void WifiPhyRxDropTrace (std::string context, Ptr p); void WimaxTxTrace (std::string context, @@ -212,6 +214,14 @@ private: void WimaxRxTrace (std::string context, Ptr p, const Mac48Address &); + void CsmaPhyTxBeginTrace (std::string context, + Ptr p); + void CsmaPhyTxEndTrace (std::string context, + Ptr p); + void CsmaPhyRxEndTrace (std::string context, + Ptr p); + void CsmaMacRxTrace (std::string context, + Ptr p); void MobilityCourseChangeTrace (Ptr mob); // Write specified amount of data to the specified handle @@ -220,8 +230,8 @@ private: // Write a string to the specified handle; int WriteN (int, const std::string&); - //Helpers to output xml wireless packet void OutputWirelessPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); + void OutputCsmaPacket (AnimPacketInfo& pktInfo, AnimRxInfo pktrxInfo); void MobilityAutoCheck (); uint64_t gAnimUid ; // Packet unique identifier used by Animtion @@ -234,6 +244,10 @@ private: void AddPendingWimaxPacket (uint64_t AnimUid, AnimPacketInfo&); bool WimaxPacketIsPending (uint64_t AnimUid); + std::map pendingCsmaPackets; + void AddPendingCsmaPacket (uint64_t AnimUid, AnimPacketInfo&); + bool CsmaPacketIsPending (uint64_t AnimUid); + uint64_t GetAnimUidFromPacket (Ptr ); std::map nodeLocation; @@ -267,7 +281,7 @@ private: 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); std::string GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId); - std::string GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx); + std::string GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, std::string auxInfo = ""); 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"; } diff --git a/src/netanim/wscript b/src/netanim/wscript index 22f86dcd4..bc76fd484 100644 --- a/src/netanim/wscript +++ b/src/netanim/wscript @@ -1,7 +1,7 @@ ## -*-Mode : python; py-indent-offset : 4; indent-tabs-mode : nil; coding : utf-8; -*- def build (bld) : - module = bld.create_ns3_module ('netanim', ['internet', 'mobility', 'wimax', 'wifi']) + module = bld.create_ns3_module ('netanim', ['internet', 'mobility', 'wimax', 'wifi', 'csma']) module.includes = '.' module.source = [ 'model/animation-interface.cc',