From c7672326fd67f62120708cfd825f2116d2d36737 Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Tue, 15 Mar 2011 11:22:36 +0100 Subject: [PATCH] added PHY synchronization model --- src/lte/model/lte-phy-tag.cc | 50 +++++------- src/lte/model/lte-phy-tag.h | 9 ++- src/lte/model/lte-spectrum-phy.cc | 130 +++++++++++++++++------------- src/lte/wscript | 2 + 4 files changed, 102 insertions(+), 89 deletions(-) diff --git a/src/lte/model/lte-phy-tag.cc b/src/lte/model/lte-phy-tag.cc index 45fd1454b..8711228a9 100644 --- a/src/lte/model/lte-phy-tag.cc +++ b/src/lte/model/lte-phy-tag.cc @@ -20,7 +20,7 @@ */ -#include "lte-mac-tag.h" +#include "lte-phy-tag.h" #include "ns3/tag.h" #include "ns3/uinteger.h" @@ -44,55 +44,47 @@ LtePhyTag::GetInstanceTypeId (void) const return GetTypeId (); } -LtePhyTag::LtePhyTag (Ptr enbPhy) - : m_enbPhy (enbPhy.PeekPointer ()) +LtePhyTag::LtePhyTag () +{ +} + +LtePhyTag::LtePhyTag (uint16_t cellId) + : m_cellId (cellId) +{ +} + +LtePhyTag::~LtePhyTag () { } uint32_t LtePhyTag::GetSerializedSize (void) const { - return sizeof (void*); + return 2; } void LtePhyTag::Serialize (TagBuffer i) const { - switch (sizeof (void*)) - { - case 4: - i.WriteU32 ((uint32_t) m_enbPhy); - break; - case 8: - i.WriteU64 ((uint64_t) m_enbPhy); - break; - default: - NS_FATAL ("unknown pointer size"); - break; - } + i.WriteU16 (m_cellId); } void LtePhyTag::Deserialize (TagBuffer i) { - switch (sizeof (void*)) - { - case 4: - m_enbPhy = (LtePhy*) i.ReadU32 (); - break; - case 8: - m_enbPhy = (LtePhy*) i.ReadU64 (); - break; - default: - NS_FATAL ("unknown pointer size"); - break; - } + m_cellId = i.ReadU16 (); } void LtePhyTag::Print (std::ostream &os) const { - os << "0x" << std::hex << m_enbPhy << std::dec; + os << m_cellId; +} + +uint16_t +LtePhyTag::GetCellId () const +{ + return m_cellId; } } // namespace ns3 diff --git a/src/lte/model/lte-phy-tag.h b/src/lte/model/lte-phy-tag.h index d8d7fc3ec..fc3a0ac53 100644 --- a/src/lte/model/lte-phy-tag.h +++ b/src/lte/model/lte-phy-tag.h @@ -42,18 +42,21 @@ public: /** * Create a LtePhyTag with the given RNTI and LC id */ - LtePhyTag (Ptr enbPhy); + LtePhyTag (uint16_t cellId); + + + virtual ~LtePhyTag (); virtual void Serialize (TagBuffer i) const; virtual void Deserialize (TagBuffer i); virtual uint32_t GetSerializedSize () const; virtual void Print (std::ostream &os) const; - bool IsEnbPhyEqual () const; + uint16_t GetCellId () const; private: - LtePhy* m_enbPhy; + uint16_t m_cellId; }; diff --git a/src/lte/model/lte-spectrum-phy.cc b/src/lte/model/lte-spectrum-phy.cc index b0f8fdce7..17861d9f1 100644 --- a/src/lte/model/lte-spectrum-phy.cc +++ b/src/lte/model/lte-spectrum-phy.cc @@ -29,6 +29,7 @@ #include "lte-net-device.h" #include "lte-mac-tag.h" #include "lte-sinr-chunk-processor.h" +#include "lte-phy-tag.h" NS_LOG_COMPONENT_DEFINE ("LteSpectrumPhy"); @@ -166,7 +167,7 @@ SpectrumType LteSpectrumPhy::GetSpectrumType () { NS_LOG_FUNCTION (this); - static SpectrumType st = SpectrumTypeFactory::Create ("IdealOfdm"); + static SpectrumType st = SpectrumTypeFactory::Create ("Lte"); return st; } @@ -239,44 +240,54 @@ LteSpectrumPhy::StartTx (Ptr pb) for (std::list >::const_iterator iter = pb->Begin (); iter - != pb->End (); ++iter) + != pb->End (); ++iter) { Ptr packet = (*iter)->Copy (); m_phyTxStartTrace (packet); } - - if (m_state == LteSpectrumPhy::RX) + switch (m_state) { - /* - * NS FATAL ERROR: according to FDD channel acces, - * the physical layer for transmission cannot be used for reception. - */ - NS_FATAL_ERROR ("FDD ERROR: R State while sending packet"); - } + case RX: + NS_FATAL_ERROR ("cannot TX while RX: according to FDD channel acces, the physical layer for transmission cannot be used for reception"); + break; - if (m_state == LteSpectrumPhy::IDLE) - { - - /* - m_txPsd must be setted by the device, according to - (i) the available subchannel for transmission - (ii) the power transmission - */ - NS_ASSERT (m_txPsd); - - m_txPacketBurst = pb; - ChangeState (TX); - NS_ASSERT (m_channel); - double tti = 0.001; - m_channel->StartTx (pb, m_txPsd, GetSpectrumType (), Seconds (tti), GetObject ()); - Simulator::Schedule (Seconds (tti), &LteSpectrumPhy::EndTx, this); - return false; - } - else - { - // The device have already started the transmission. + case TX: + NS_FATAL_ERROR ("cannot TX while already TX: the MAC should avoid this"); + break; + + case IDLE: + { + /* + m_txPsd must be setted by the device, according to + (i) the available subchannel for transmission + (ii) the power transmission + */ + NS_ASSERT (m_txPsd); + m_txPacketBurst = pb; + + // we need to convey some PHY meta information to the receiver + // to be used for simulation purposes (e.g., the CellId). This + // is done by adding an LtePhyTag to the first packet in the + // burst. + NS_ASSERT (pb->Begin () != pb->End ()); + LtePhyTag tag (m_cellId); + Ptr firstPacketInBurst = *(pb->Begin ()); + firstPacketInBurst->AddPacketTag (tag); + + ChangeState (TX); + NS_ASSERT (m_channel); + double tti = 0.001; + m_channel->StartTx (pb, m_txPsd, GetSpectrumType (), Seconds (tti), GetObject ()); + Simulator::Schedule (Seconds (tti), &LteSpectrumPhy::EndTx, this); + } return true; + break; + + default: + NS_FATAL_ERROR ("uknown state"); + return true; + break; } } @@ -319,7 +330,8 @@ LteSpectrumPhy::StartRx (Ptr pb, Ptr rxPsd, S m_interference.AddSignal (rxPsd, duration); - // the device might start RX only if the signal is of a type understood by this device + // the device might start RX only if the signal is of a type + // understood by this device - in this case, an LTE signal. if (st == GetSpectrumType ()) { switch (m_state) @@ -337,38 +349,42 @@ LteSpectrumPhy::StartRx (Ptr pb, Ptr rxPsd, S break; case IDLE: - // preamble detection and synchronization is supposed to be always successful. - NS_LOG_LOGIC (this << " receiving new packet"); - m_interference.StartRx (rxPsd); - - - for (std::list >::const_iterator iter = pb->Begin (); iter - != pb->End (); ++iter) + // To check if we're synchronized to this signal, we check + // for the CellId which is reported in the LtePhyTag + NS_ASSERT (pb->Begin () != pb->End ()); + LtePhyTag tag; + Ptr firstPacketInBurst = *(pb->Begin ()); + firstPacketInBurst->RemovePacketTag (tag); + if (tag.GetCellId () == m_cellId) { - Ptr packet = (*iter)->Copy (); - m_phyRxStartTrace (packet); + // we're synchronized with this signal + ChangeState (RX); + + m_interference.StartRx (rxPsd); + + for (std::list >::const_iterator iter = pb->Begin (); iter + != pb->End (); ++iter) + { + Ptr packet = (*iter)->Copy (); + m_phyRxStartTrace (packet); + } + + m_rxPacketBurst = pb; + m_rxPsd = rxPsd; + + NS_LOG_LOGIC (this << " scheduling EndRx with delay " << duration); + m_endRxEventId = Simulator::Schedule (duration, &LteSpectrumPhy::EndRx, this); + + break; + } - - - m_rxPacketBurst = pb; - m_rxPsd = rxPsd; - - ChangeState (RX); - - - NS_LOG_LOGIC (this << " scheduling EndRx with delay " << duration); - m_endRxEventId = Simulator::Schedule (duration, &LteSpectrumPhy::EndRx, this); - - break; - } + + NS_LOG_LOGIC (this << "state: " << m_state); } - - NS_LOG_LOGIC (this << "state: " << m_state); } - void LteSpectrumPhy::AbortRx () { diff --git a/src/lte/wscript b/src/lte/wscript index d4afb8bec..22883eb1f 100644 --- a/src/lte/wscript +++ b/src/lte/wscript @@ -34,6 +34,7 @@ def build(bld): 'model/lte-enb-mac.cc', 'model/lte-ue-mac.cc', 'model/lte-mac-tag.cc', + 'model/lte-phy-tag.cc', 'model/lte-enb-phy-sap.cc', 'model/lte-ue-phy-sap.cc', 'model/lte-interference.cc', @@ -76,6 +77,7 @@ def build(bld): 'model/lte-enb-mac.h', 'model/lte-ue-mac.h', 'model/lte-mac-tag.h', + 'model/lte-phy-tag.h', 'model/lte-enb-phy-sap.h', 'model/lte-ue-phy-sap.h', 'model/lte-interference.h',