subframe indication now triggered independently by LteUePhy
authorNicola Baldo <nicola@baldo.biz>
Sun, 29 Jul 2012 20:32:28 +0200
changeset 9053 974762654b12
parent 9052 db76e8754e2f
child 9054 16f693a95855
child 9346 00e674a0d567
subframe indication now triggered independently by LteUePhy
src/lte/helper/lte-helper.cc
src/lte/model/lte-enb-phy.cc
src/lte/model/lte-enb-phy.h
src/lte/model/lte-spectrum-phy.cc
src/lte/model/lte-spectrum-phy.h
src/lte/model/lte-ue-phy.cc
--- a/src/lte/helper/lte-helper.cc	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/helper/lte-helper.cc	Sun Jul 29 20:32:28 2012 +0200
@@ -484,7 +484,7 @@
   // connect at the PHY layer
   Ptr<LteEnbPhy> enbPhy = enbDevice->GetObject<LteEnbNetDevice> ()->GetPhy ();
   Ptr<LteUePhy> uePhy = ueDevice->GetObject<LteUeNetDevice> ()->GetPhy ();
-  enbPhy->AddUePhy (rnti, uePhy);
+  enbPhy->AddUePhy (rnti);
 
 //  
   // WILD HACK - should be done through PHY SAP, probably passing by RRC
--- a/src/lte/model/lte-enb-phy.cc	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/model/lte-enb-phy.cc	Sun Jul 29 20:32:28 2012 +0200
@@ -42,6 +42,14 @@
 namespace ns3 {
 
 
+// duration of the data part of a subframe in DL
+// = 0.001 / 14 * 11 (fixed to 11 symbols) -1ns as margin to avoid overlapping simulator events
+static const Time DL_DATA_DURATION = NanoSeconds (785714 -1);
+
+//  delay from subframe start to transmission of the data in DL 
+// = 0.001 / 14 * 3 (ctrl fixed to 3 symbols)
+static const Time DL_CTRL_DELAY_FROM_SUBFRAME_START = NanoSeconds (214286);
+
 ////////////////////////////////////////
 // member SAP forwarders
 ////////////////////////////////////////
@@ -267,13 +275,13 @@
 }
 
 bool
-LteEnbPhy::AddUePhy (uint16_t rnti, Ptr<LteUePhy> phy)
+LteEnbPhy::AddUePhy (uint16_t rnti)
 {
-  std::map <uint16_t, Ptr<LteUePhy> >::iterator it;
+  std::set <uint16_t>::iterator it;
   it = m_ueAttached.find (rnti);
   if (it == m_ueAttached.end ())
     {
-      m_ueAttached.insert (std::pair<uint16_t, Ptr<LteUePhy> > (rnti, phy));
+      m_ueAttached.insert (rnti);
       return (true);
     }
   else
@@ -286,7 +294,7 @@
 bool
 LteEnbPhy::DeleteUePhy (uint16_t rnti)
 {
-  std::map <uint16_t, Ptr<LteUePhy> >::iterator it;
+  std::set <uint16_t>::iterator it;
   it = m_ueAttached.find (rnti);
   if (it == m_ueAttached.end ())
     {
@@ -422,7 +430,7 @@
   NS_LOG_DEBUG (this << " eNB Expected TBs " << uldcilist.size ());
   for (dciIt = uldcilist.begin (); dciIt!=uldcilist.end (); dciIt++)
     {
-      std::map <uint16_t, Ptr<LteUePhy> >::iterator it2;
+      std::set <uint16_t>::iterator it2;
       it2 = m_ueAttached.find ((*dciIt).GetDci ().m_rnti);
       
       if (it2 == m_ueAttached.end ())
@@ -493,7 +501,7 @@
   Ptr<PacketBurst> pb = GetPacketBurst ();
   if (pb)
     {
-      Simulator::Schedule (Seconds (0.000214286), // ctrl frame fixed to 3 symbols
+      Simulator::Schedule (DL_CTRL_DELAY_FROM_SUBFRAME_START, // ctrl frame fixed to 3 symbols
                        &LteEnbPhy::SendDataChannels,
                        this,pb);
     }
@@ -501,15 +509,6 @@
   // trigger the MAC
   m_enbPhySapUser->SubframeIndication (m_nrFrames, m_nrSubFrames);
 
-
-  // trigger the UE(s)
-  std::map <uint16_t, Ptr<LteUePhy> >::iterator it;
-  for (it = m_ueAttached.begin (); it != m_ueAttached.end (); it++)
-    {
-      (*it).second->SubframeIndication (m_nrFrames, m_nrSubFrames);
-    }
-
-
   Simulator::Schedule (Seconds (GetTti ()),
                        &LteEnbPhy::EndSubFrame,
                        this);
@@ -539,10 +538,9 @@
   SetDownlinkSubChannels (m_dlDataRbMap);
   // send the current burts of packets
   NS_LOG_LOGIC (this << " eNB start TX DATA");
-  double dlDataFrame = 0.000785714; // 0.001 / 14 * 11 (fixed to 11 symbols)
   std::list<Ptr<LteControlMessage> > ctrlMsgList;
   ctrlMsgList.clear ();
-  m_downlinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsgList, dlDataFrame);
+  m_downlinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsgList, DL_DATA_DURATION);
 }
 
 
--- a/src/lte/model/lte-enb-phy.h	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/model/lte-enb-phy.h	Sun Jul 29 20:32:28 2012 +0200
@@ -23,10 +23,14 @@
 #define ENB_LTE_PHY_H
 
 
-#include "lte-phy.h"
 #include <ns3/lte-enb-phy-sap.h>
+#include <ns3/lte-phy.h>
+#include <ns3/lte-ue-phy.h>
+
 #include <map>
-#include <ns3/lte-ue-phy.h>
+#include <set>
+
+
 
 namespace ns3 {
 
@@ -173,7 +177,7 @@
 
   void DoSendLteControlMessage (Ptr<LteControlMessage> msg);
 
-  bool AddUePhy (uint16_t rnti, Ptr<LteUePhy> phy);
+  bool AddUePhy (uint16_t rnti);
 
   bool DeleteUePhy (uint16_t rnti);
   
@@ -233,7 +237,7 @@
 
 
 private:
-  std::map <uint16_t, Ptr<LteUePhy> > m_ueAttached;
+  std::set <uint16_t> m_ueAttached;
   
   std::vector <int> m_listOfDownlinkSubchannel;
   
--- a/src/lte/model/lte-spectrum-phy.cc	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/model/lte-spectrum-phy.cc	Sun Jul 29 20:32:28 2012 +0200
@@ -41,7 +41,19 @@
 NS_LOG_COMPONENT_DEFINE ("LteSpectrumPhy");
 
 namespace ns3 {
-  
+
+
+
+// duration of SRS portion of UL subframe  
+// = 1 symbol for SRS -1ns as margin to avoid overlapping simulator events
+static const Time UL_SRS_DURATION = NanoSeconds (71429 -1);  
+
+// duration of the control portion of a subframe
+// = 0.001 / 14 * 3 (ctrl fixed to 3 symbols) -1ns as margin to avoid overlapping simulator events
+static const Time DL_CTRL_DURATION = NanoSeconds (214286 -1);
+
+
+
   
 TbId_t::TbId_t ()
 {
@@ -130,7 +142,6 @@
   return os;
 }
 
-
 TypeId
 LteSpectrumPhy::GetTypeId (void)
 {
@@ -300,70 +311,9 @@
 }
 
 
-bool
-LteSpectrumPhy::StartTx (Ptr<PacketBurst> pb)
-{
-  NS_LOG_WARN (this << " Obsolete Function");
-  NS_LOG_FUNCTION (this << pb);
-  NS_LOG_LOGIC (this << " state: " << m_state);
-
-  m_phyTxStartTrace (pb);
-
-  switch (m_state)
-    {
-    case RX_DATA:
-    case RX_CTRL:
-      NS_FATAL_ERROR ("cannot TX while RX: according to FDD channel acces, the physical layer for transmission cannot be used for reception");
-      break;
-
-    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<Packet> firstPacketInBurst = *(pb->Begin ());
-        firstPacketInBurst->AddPacketTag (tag);
-
-        ChangeState (TX);
-        NS_ASSERT (m_channel);
-        double tti = 0.001;
-        Ptr<LteSpectrumSignalParameters> txParams = Create<LteSpectrumSignalParameters> ();
-        txParams->duration = Seconds (tti);
-        txParams->txPhy = GetObject<SpectrumPhy> ();
-        txParams->txAntenna = m_antenna;
-        txParams->psd = m_txPsd;
-        txParams->packetBurst = pb;
-        m_channel->StartTx (txParams);
-        Simulator::Schedule (Seconds (tti), &LteSpectrumPhy::EndTx, this);
-      }
-      return false;
-      break;
-
-    default:
-      NS_FATAL_ERROR ("unknown state");
-      return true;
-      break;
-    }
-}
-
 
 bool
-LteSpectrumPhy::StartTxDataFrame (Ptr<PacketBurst> pb, std::list<Ptr<LteControlMessage> > ctrlMsgList, double duration)
+LteSpectrumPhy::StartTxDataFrame (Ptr<PacketBurst> pb, std::list<Ptr<LteControlMessage> > ctrlMsgList, Time duration)
 {
   NS_LOG_FUNCTION (this << pb);
   NS_LOG_LOGIC (this << " state: " << m_state);
@@ -398,7 +348,7 @@
       ChangeState (TX);
       NS_ASSERT (m_channel);
       Ptr<LteSpectrumSignalParametersDataFrame> txParams = Create<LteSpectrumSignalParametersDataFrame> ();
-      txParams->duration = Seconds (duration);
+      txParams->duration = duration;
       txParams->txPhy = GetObject<SpectrumPhy> ();
       txParams->txAntenna = m_antenna;
       txParams->psd = m_txPsd;
@@ -406,7 +356,7 @@
       txParams->ctrlMsgList = ctrlMsgList;
       txParams->cellId = m_cellId;
       m_channel->StartTx (txParams);
-      Simulator::Schedule (Seconds (duration), &LteSpectrumPhy::EndTx, this);
+      Simulator::Schedule (duration, &LteSpectrumPhy::EndTx, this);
     }
     return false;
     break;
@@ -452,16 +402,16 @@
       // LteSpectrumSignalParametersDlCtrlFrame
       ChangeState (TX);
       NS_ASSERT (m_channel);
-      double dlCtrlFrame = 0.000214286; // 0.001 / 14 * 3 (fixed to 3 symbols)
+
       Ptr<LteSpectrumSignalParametersDlCtrlFrame> txParams = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
-      txParams->duration = Seconds (dlCtrlFrame);
+      txParams->duration = DL_CTRL_DURATION;
       txParams->txPhy = GetObject<SpectrumPhy> ();
       txParams->txAntenna = m_antenna;
       txParams->psd = m_txPsd;
       txParams->cellId = m_cellId;
       txParams->ctrlMsgList = ctrlMsgList;
       m_channel->StartTx (txParams);
-      Simulator::Schedule (Seconds (dlCtrlFrame), &LteSpectrumPhy::EndTx, this);
+      Simulator::Schedule (DL_CTRL_DURATION, &LteSpectrumPhy::EndTx, this);
     }
     return false;
     break;
@@ -508,15 +458,14 @@
       // LteSpectrumSignalParametersDlCtrlFrame
       ChangeState (TX);
       NS_ASSERT (m_channel);
-      double ulCtrlFrame = 0.000071429; // 0.001 / 14 * 1 (fixed to 1 symbols)
       Ptr<LteSpectrumSignalParametersUlSrsFrame> txParams = Create<LteSpectrumSignalParametersUlSrsFrame> ();
-      txParams->duration = Seconds (ulCtrlFrame);
+      txParams->duration = UL_SRS_DURATION;
       txParams->txPhy = GetObject<SpectrumPhy> ();
       txParams->txAntenna = m_antenna;
       txParams->psd = m_txPsd;
       txParams->cellId = m_cellId;
       m_channel->StartTx (txParams);
-      Simulator::Schedule (Seconds (ulCtrlFrame), &LteSpectrumPhy::EndTx, this);
+      Simulator::Schedule (UL_SRS_DURATION, &LteSpectrumPhy::EndTx, this);
     }
     return false;
     break;
@@ -622,7 +571,7 @@
                   // start RX
                   m_firstRxStart = Simulator::Now ();
                   m_firstRxDuration = params->duration;
-                  NS_LOG_LOGIC (this << " scheduling EndRx with delay " << params->duration);
+                  NS_LOG_LOGIC (this << " scheduling EndRx with delay " << params->duration.GetSeconds () << "s");
                   Simulator::Schedule (params->duration, &LteSpectrumPhy::EndRxData, this);
                 }
               else
--- a/src/lte/model/lte-spectrum-phy.h	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/model/lte-spectrum-phy.h	Sun Jul 29 20:32:28 2012 +0200
@@ -174,17 +174,6 @@
    * \param a the Antenna Model
    */
   void SetAntenna (Ptr<AntennaModel> a);
-
-  /**
-   * Start a transmission
-   *
-   *
-   * @param pb the burst of packets to be transmitted
-   *
-   * @return true if an error occurred and the transmission was not
-   * started, false otherwise.
-   */
-  bool StartTx (Ptr<PacketBurst> pb);
   
   /**
   * Start a transmission of data frame in DL and UL
@@ -192,12 +181,12 @@
   *
   * @param pb the burst of packets to be transmitted in PDSCH/PUSCH
   * @param ctrlMsgList the list of LteControlMessage to send
-  * @param duration the duration of the data frame (in sec.)
+  * @param duration the duration of the data frame 
   *
   * @return true if an error occurred and the transmission was not
   * started, false otherwise.
   */
-  bool StartTxDataFrame (Ptr<PacketBurst> pb, std::list<Ptr<LteControlMessage> > ctrlMsgList, double duration);
+  bool StartTxDataFrame (Ptr<PacketBurst> pb, std::list<Ptr<LteControlMessage> > ctrlMsgList, Time duration);
   
   /**
   * Start a transmission of control frame in DL
--- a/src/lte/model/lte-ue-phy.cc	Fri Jul 27 12:54:37 2012 +0200
+++ b/src/lte/model/lte-ue-phy.cc	Sun Jul 29 20:32:28 2012 +0200
@@ -42,6 +42,22 @@
 
 namespace ns3 {
 
+
+
+
+// duration of data portion of UL subframe
+// = TTI - 1 symbol for SRS - 1ns as margin to avoid overlapping simulator events
+// (symbol duration in nanoseconds = TTI / 14 (rounded))
+// in other words, duration of data portion of UL subframe = TTI*(13/14) -1ns
+static const Time UL_DATA_DURATION = NanoSeconds (1e6 - 71429 - 1); 
+
+// delay from subframe start to transmission of SRS 
+// = TTI - 1 symbol for SRS 
+static const Time UL_SRS_DELAY_FROM_SUBFRAME_START = NanoSeconds (1e6 - 71429); 
+
+
+
+
 ////////////////////////////////////////
 // member SAP forwarders
 ////////////////////////////////////////
@@ -99,6 +115,7 @@
   m_phy->DoSetSrsConfigurationIndex (srcCi);
 }
 
+
 ////////////////////////////////////////
 // generic LteUePhy methods
 ////////////////////////////////////////
@@ -136,6 +153,8 @@
     }
   std::vector <int> ulRb;
   m_subChannelsForTransmissionQueue.resize (m_macChTtiDelay, ulRb);
+
+  Simulator::ScheduleNow (&LteUePhy::SubframeIndication, this, 1, 1);
 }
 
 
@@ -577,7 +596,7 @@
 void
 LteUePhy::SubframeIndication (uint32_t frameNo, uint32_t subframeNo)
 {
-  // trigger from eNB
+  NS_LOG_LOGIC (this << frameNo << subframeNo);
   
   // update uplink transmission mask according to previous UL-CQIs
   SetSubChannelsForTransmission (m_subChannelsForTransmissionQueue.at (0));
@@ -599,11 +618,12 @@
     {
       m_srsCounter--;
     }
-  double dataFrame = 0.001 - 0.000071429; // 0.001 - 1 symbol for SRS
+
   if (srs)
     {
-      Simulator::Schedule (Seconds (0.000928572),  // (0.001/14) * 13
-                           &LteUePhy::SendSrs,                         this);
+      Simulator::Schedule (UL_SRS_DELAY_FROM_SUBFRAME_START, 
+                           &LteUePhy::SendSrs,
+                           this);
     }
 
 
@@ -614,7 +634,7 @@
   if (pb)
     {
       NS_LOG_LOGIC (this << " UE - start TX PUSCH + PUCCH");
-      m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, dataFrame);
+      m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, UL_DATA_DURATION);
     }
   else
     {
@@ -627,7 +647,7 @@
               dlRb.push_back (i);
             }
           SetSubChannelsForTransmission (dlRb);
-          m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, dataFrame);
+          m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, UL_DATA_DURATION);
         }
     }
   
@@ -635,6 +655,16 @@
   // trigger the MAC
   m_uePhySapUser->SubframeIndication (frameNo, subframeNo);
 
+
+  ++subframeNo;
+  if (subframeNo > 10)
+    {
+      ++frameNo;
+      subframeNo = 1;
+    }
+
+  // schedule next subframe indication
+  Simulator::Schedule (Seconds (GetTti ()), &LteUePhy::SubframeIndication, this, frameNo, subframeNo);  
 }
 
 void