diff --git a/src/lte/examples/lena-pathloss-traces.cc b/src/lte/examples/lena-pathloss-traces.cc index d06a5efa1..7866be2a3 100644 --- a/src/lte/examples/lena-pathloss-traces.cc +++ b/src/lte/examples/lena-pathloss-traces.cc @@ -26,6 +26,7 @@ #include "ns3/lte-module.h" #include "ns3/config-store.h" #include "ns3/radio-bearer-stats-calculator.h" +#include "ns3/lte-global-pathloss-database.h" #include #include @@ -35,97 +36,9 @@ using namespace ns3; -NS_LOG_COMPONENT_DEFINE ("InterCellInterference"); +NS_LOG_COMPONENT_DEFINE ("LenaPathlossTraces"); -/** - * Store the last pathloss value for each TX-RX pair. This is an - * example of how the PathlossTrace (provided by some SpectrumChannel - * implementations) work. - * - */ -class GlobalPathlossDatabase -{ -public: - - /** - * update the pathloss value - * - * \param context - * \param txPhy the transmitting PHY - * \param rxPhy the receiving PHY - * \param lossDb the loss in dB - */ - virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb) = 0; - - /** - * print the stored pathloss values to standard output - * - */ - void Print (); - -protected: - - // CELL ID IMSI PATHLOSS - std::map > m_pathlossMap; -}; - -void -GlobalPathlossDatabase::Print () -{ - NS_LOG_FUNCTION (this); - for (std::map >::const_iterator cellIdIt = m_pathlossMap.begin (); - cellIdIt != m_pathlossMap.end (); - ++cellIdIt) - { - for (std::map::const_iterator imsiIt = cellIdIt->second.begin (); - imsiIt != cellIdIt->second.end (); - ++imsiIt) - { - std::cout << "CellId: " << cellIdIt->first << " IMSI: " << imsiIt->first << " pathloss: " << imsiIt->second << " dB" << std::endl; - } - } -} - -class DownlinkGlobalPathlossDatabase : public GlobalPathlossDatabase -{ -public: - // inherited from GlobalPathlossDatabase - virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb); -}; - -void -DownlinkGlobalPathlossDatabase::UpdatePathloss (std::string context, - Ptr txPhy, - Ptr rxPhy, - double lossDb) -{ - NS_LOG_FUNCTION (this << lossDb); - uint16_t cellId = txPhy->GetDevice ()->GetObject ()->GetCellId (); - uint16_t imsi = rxPhy->GetDevice ()->GetObject ()->GetImsi (); - m_pathlossMap[cellId][imsi] = lossDb; -} - - -class UplinkGlobalPathlossDatabase : public GlobalPathlossDatabase -{ -public: - // inherited from GlobalPathlossDatabase - virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb); -}; - -void -UplinkGlobalPathlossDatabase::UpdatePathloss (std::string context, - Ptr txPhy, - Ptr rxPhy, - double lossDb) -{ - NS_LOG_FUNCTION (this << lossDb); - uint16_t imsi = txPhy->GetDevice ()->GetObject ()->GetImsi (); - uint16_t cellId = rxPhy->GetDevice ()->GetObject ()->GetCellId (); - m_pathlossMap[cellId][imsi] = lossDb; -} - int main (int argc, char *argv[]) { @@ -242,15 +155,15 @@ int main (int argc, char *argv[]) - // keep track of all path loss values in a global object - DownlinkGlobalPathlossDatabase dlPathlossDb; - UplinkGlobalPathlossDatabase ulPathlossDb; + // keep track of all path loss values in two centralized objects + DownlinkLteGlobalPathlossDatabase dlPathlossDb; + UplinkLteGlobalPathlossDatabase ulPathlossDb; // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel object, // hence the former will have index 0 and the latter 1 Config::Connect ("/ChannelList/0/PathLoss", - MakeCallback (&DownlinkGlobalPathlossDatabase::UpdatePathloss, &dlPathlossDb)); + MakeCallback (&DownlinkLteGlobalPathlossDatabase::UpdatePathloss, &dlPathlossDb)); Config::Connect ("/ChannelList/1/PathLoss", - MakeCallback (&UplinkGlobalPathlossDatabase::UpdatePathloss, &ulPathlossDb)); + MakeCallback (&UplinkLteGlobalPathlossDatabase::UpdatePathloss, &ulPathlossDb)); Simulator::Run (); diff --git a/src/lte/helper/lte-global-pathloss-database.cc b/src/lte/helper/lte-global-pathloss-database.cc new file mode 100644 index 000000000..8fd463cfc --- /dev/null +++ b/src/lte/helper/lte-global-pathloss-database.cc @@ -0,0 +1,98 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011,2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo + */ + + +#include "lte-global-pathloss-database.h" +#include "ns3/lte-enb-net-device.h" +#include "ns3/lte-ue-net-device.h" +#include "ns3/lte-spectrum-phy.h" + +#include + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("LteGlobalPathlossDatabase"); + + + +void +LteGlobalPathlossDatabase::Print () +{ + NS_LOG_FUNCTION (this); + for (std::map >::const_iterator cellIdIt = m_pathlossMap.begin (); + cellIdIt != m_pathlossMap.end (); + ++cellIdIt) + { + for (std::map::const_iterator imsiIt = cellIdIt->second.begin (); + imsiIt != cellIdIt->second.end (); + ++imsiIt) + { + std::cout << "CellId: " << cellIdIt->first << " IMSI: " << imsiIt->first << " pathloss: " << imsiIt->second << " dB" << std::endl; + } + } +} + + +double +LteGlobalPathlossDatabase::GetPathloss (uint16_t cellId, uint64_t imsi) +{ + NS_LOG_FUNCTION (this); + std::map >::iterator cellIt = m_pathlossMap.find (cellId); + if (cellIt == m_pathlossMap.end()) + { + return std::numeric_limits::infinity (); + } + std::map::iterator ueIt = cellIt->second.find (imsi); + if (ueIt == cellIt->second.end()) + { + return std::numeric_limits::infinity (); + } + return ueIt->second; +} + + +void +DownlinkLteGlobalPathlossDatabase::UpdatePathloss (std::string context, + Ptr txPhy, + Ptr rxPhy, + double lossDb) +{ + NS_LOG_FUNCTION (this << lossDb); + uint16_t cellId = txPhy->GetDevice ()->GetObject ()->GetCellId (); + uint16_t imsi = rxPhy->GetDevice ()->GetObject ()->GetImsi (); + m_pathlossMap[cellId][imsi] = lossDb; +} + + +void +UplinkLteGlobalPathlossDatabase::UpdatePathloss (std::string context, + Ptr txPhy, + Ptr rxPhy, + double lossDb) +{ + NS_LOG_FUNCTION (this << lossDb); + uint16_t imsi = txPhy->GetDevice ()->GetObject ()->GetImsi (); + uint16_t cellId = rxPhy->GetDevice ()->GetObject ()->GetCellId (); + m_pathlossMap[cellId][imsi] = lossDb; +} + + + +} // namespace ns3 diff --git a/src/lte/helper/lte-global-pathloss-database.h b/src/lte/helper/lte-global-pathloss-database.h new file mode 100644 index 000000000..1d3ac9cfc --- /dev/null +++ b/src/lte/helper/lte-global-pathloss-database.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011,2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo + */ + + +#ifndef LTE_GLOBAL_PATHLOSS_DATABASE_H +#define LTE_GLOBAL_PATHLOSS_DATABASE_H + +#include +#include +#include +#include + +namespace ns3 { + +class SpectrumPhy; + +/** + * Store the last pathloss value for each TX-RX pair. This is an + * example of how the PathlossTrace (provided by some SpectrumChannel + * implementations) work. + * + */ +class LteGlobalPathlossDatabase +{ +public: + + /** + * update the pathloss value + * + * \param context + * \param txPhy the transmitting PHY + * \param rxPhy the receiving PHY + * \param lossDb the loss in dB + */ + virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb) = 0; + + /** + * + * + * \param cellId the id of the eNB + * \param imsi the id of the UE + * + * \return the pathloss value bewteen the UE and the eNB + */ + double GetPathloss (uint16_t cellId, uint64_t imsi); + + /** + * print the stored pathloss values to standard output + * + */ + void Print (); + +protected: + + // CELL ID IMSI PATHLOSS + std::map > m_pathlossMap; +}; + + +class DownlinkLteGlobalPathlossDatabase : public LteGlobalPathlossDatabase +{ +public: + // inherited from LteGlobalPathlossDatabase + virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb); +}; + + +class UplinkLteGlobalPathlossDatabase : public LteGlobalPathlossDatabase +{ +public: + // inherited from LteGlobalPathlossDatabase + virtual void UpdatePathloss (std::string context, Ptr txPhy, Ptr rxPhy, double lossDb); +}; + + +} // namespace ns3 + + + + +#endif // LTE_GLOBAL_PATHLOSS_DATABASE_H diff --git a/src/lte/wscript b/src/lte/wscript index 1da8986d5..8fadcdf87 100644 --- a/src/lte/wscript +++ b/src/lte/wscript @@ -47,6 +47,7 @@ def build(bld): 'helper/phy-rx-stats-calculator.cc', 'helper/radio-environment-map-helper.cc', 'helper/lte-hex-grid-enb-topology-helper.cc', + 'helper/lte-global-pathloss-database.cc', 'model/rem-spectrum-phy.cc', 'model/ff-mac-common.cc', 'model/ff-mac-csched-sap.cc', @@ -170,6 +171,7 @@ def build(bld): 'helper/radio-bearer-stats-connector.h', 'helper/radio-environment-map-helper.h', 'helper/lte-hex-grid-enb-topology-helper.h', + 'helper/lte-global-pathloss-database.h', 'model/rem-spectrum-phy.h', 'model/ff-mac-common.h', 'model/ff-mac-csched-sap.h',