From e1f2b32ab63650fd4e99022dfe0024b373bab7af Mon Sep 17 00:00:00 2001 From: John Abraham Date: Fri, 25 May 2012 11:45:23 -0700 Subject: [PATCH] NetAnim: Update LTE callbacks after recent lena commit --- src/netanim/model/animation-interface.cc | 138 +++++++++++++++++++++-- src/netanim/model/animation-interface.h | 10 ++ 2 files changed, 140 insertions(+), 8 deletions(-) diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 8df8c5abb..5a1d785fa 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -35,6 +35,8 @@ #include "ns3/wifi-net-device.h" #include "ns3/wifi-mac.h" #include "ns3/constant-position-mobility-model.h" +#include "ns3/lte-ue-phy.h" +#include "ns3/lte-enb-phy.h" #include #include @@ -44,14 +46,6 @@ #include #include -// Socket related includes -#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H) -#include -#include -#else -#include -#endif - NS_LOG_COMPONENT_DEFINE ("AnimationInterface"); @@ -455,6 +449,77 @@ void AnimationInterface::StartAnimation (bool restart) ConnectCallbacks (); } +void AnimationInterface::ConnectLteEnb (Ptr n, Ptr nd, uint32_t devIndex) +{ + + Ptr lteEnbPhy = nd->GetPhy (); + Ptr dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy (); + Ptr ulPhy = lteEnbPhy->GetUplinkSpectrumPhy (); + std::ostringstream oss; + //NodeList/*/DeviceList/*/ + oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; + if (dlPhy) + { + dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } + if (ulPhy) + { + ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } +} + + + +void AnimationInterface::ConnectLteUe (Ptr n, Ptr nd, uint32_t devIndex) +{ + + Ptr lteUePhy = nd->GetPhy (); + Ptr dlPhy = lteUePhy->GetDownlinkSpectrumPhy (); + Ptr ulPhy = lteUePhy->GetUplinkSpectrumPhy (); + std::ostringstream oss; + //NodeList/*/DeviceList/*/ + oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; + if (dlPhy) + { + dlPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + dlPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } + if (ulPhy) + { + ulPhy->TraceConnect ("TxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + ulPhy->TraceConnect ("RxStart",oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } +} + +void AnimationInterface::ConnectLte () +{ + + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + NS_ASSERT (n); + uint32_t nDevices = n->GetNDevices (); + for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex) + { + Ptr nd = n->GetDevice(devIndex); + if (!nd) + continue; + Ptr lteUeNetDevice = DynamicCast (nd); + if (lteUeNetDevice) + { + ConnectLteUe (n, lteUeNetDevice, devIndex); + continue; + } + Ptr lteEnbNetDevice = DynamicCast (nd); + if (lteEnbNetDevice) + ConnectLteEnb (n, lteEnbNetDevice, devIndex); + } + + } +} + void AnimationInterface::ConnectCallbacks () { // Connect the callbacks @@ -483,6 +548,7 @@ void AnimationInterface::ConnectCallbacks () Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx", MakeCallback (&AnimationInterface::CsmaMacRxTrace, this)); + ConnectLte (); } @@ -933,6 +999,62 @@ void AnimationInterface::LteRxTrace (std::string context, Ptr p, c OutputWirelessPacket (p, pktInfo, pktrxInfo); } +void AnimationInterface::LteSpectrumPhyTxStart (std::string context, Ptr pb) +{ + if (!m_started || !IsInTimeWindow ()) + return; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + + std::list > pbList = pb->GetPackets (); + for (std::list >::iterator i = pbList.begin (); + i != pbList.end (); + ++i) + { + Ptr p = *i; + gAnimUid++; + NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid); + AnimPacketInfo pktinfo (ndev, Simulator::Now (), Simulator::Now () + Seconds (0.001), UpdatePosition (n)); + //TODO 0.0001 is used until Lte implements TxBegin and TxEnd traces + AnimByteTag tag; + tag.Set (gAnimUid); + p->AddByteTag (tag); + AddPendingLtePacket (gAnimUid, pktinfo); + } +} + +void AnimationInterface::LteSpectrumPhyRxStart (std::string context, Ptr pb) +{ + if (!m_started || !IsInTimeWindow ()) + return; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + + std::list > pbList = pb->GetPackets (); + for (std::list >::iterator i = pbList.begin (); + i != pbList.end (); + ++i) + { + Ptr p = *i; + uint64_t AnimUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid); + if (!LtePacketIsPending (AnimUid)) + { + NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid"); + return; + } + AnimPacketInfo& pktInfo = m_pendingLtePackets[AnimUid]; + pktInfo.ProcessRxBegin (ndev, Simulator::Now ()); + 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 (p, pktInfo, pktrxInfo); + } +} void AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) { diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index 9be26008f..9d2124533 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -34,6 +34,8 @@ #include "ns3/config.h" #include "ns3/animation-interface-helper.h" #include "ns3/mac48-address.h" +#include "ns3/lte-ue-net-device.h" +#include "ns3/lte-enb-net-device.h" namespace ns3 { @@ -304,6 +306,11 @@ private: Ptr p, const Mac48Address &); + void LteSpectrumPhyTxStart (std::string context, + Ptr pb); + void LteSpectrumPhyRxStart (std::string context, + Ptr pb); + void MobilityCourseChangeTrace (Ptr mob); // Write a string to the specified handle; @@ -350,6 +357,9 @@ private: std::vector < Ptr > RecalcTopoBounds (); void ConnectCallbacks (); + void ConnectLte (); + void ConnectLteUe (Ptr n, Ptr nd, uint32_t devIndex); + void ConnectLteEnb (Ptr n, Ptr nd, uint32_t devIndex); std::map m_macToNodeIdMap;