diff -r 52904cc0aa8a src/network/utils/generic-phy.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/network/utils/generic-phy.cc Mon Nov 28 23:53:47 2011 +0100 @@ -0,0 +1,52 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 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 "generic-phy.h" +#include + + +NS_LOG_COMPONENT_DEFINE ("GenericPhy"); + +namespace ns3 { + + +NS_OBJECT_ENSURE_REGISTERED (GenericPhy); + + +GenericPhy::GenericPhy () +{ + NS_LOG_FUNCTION (this); +} + +TypeId +GenericPhy::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::GenericPhy") + .SetParent () + ; + return tid; +} + +GenericPhy::~GenericPhy () +{ +} + +} // namespace ns3 diff -r 52904cc0aa8a src/network/utils/generic-phy.h --- a/src/network/utils/generic-phy.h Thu Nov 17 18:11:07 2011 +0000 +++ b/src/network/utils/generic-phy.h Mon Nov 28 23:53:47 2011 +0100 @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2010 CTTC + * Copyright (c) 2010,2011 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 @@ -22,9 +22,11 @@ #define GENERIC_PHY_H #include +#include namespace ns3 { +class Packet; /** * This method allows the MAC to instruct the PHY to start a @@ -67,6 +69,30 @@ */ typedef Callback< void, Ptr > GenericPhyRxEndOkCallback; + +/** + * The GenericPhy Object is provided as a base class for all objects + * that use the GenericPhy interface. The purpose of having such an + * object is to allow making any PHY object that uses the GenericPhy + * interface reachable through the attribute system via an upper + * layer object (such as NetDevice), but without resorting to an + * opaque Ptr which would give some problems. + * See https://www.nsnam.org/bugzilla/show_bug.cgi?id=962 for the + * related discussion. + * + */ +class GenericPhy : public Object +{ +public: + GenericPhy (); + virtual ~GenericPhy (); + + // inherited from Object + static TypeId GetTypeId (void); +}; + + + } // namespace ns3 diff -r 52904cc0aa8a src/network/wscript --- a/src/network/wscript Thu Nov 17 18:11:07 2011 +0000 +++ b/src/network/wscript Mon Nov 28 23:53:47 2011 +0100 @@ -45,6 +45,7 @@ 'utils/packet-socket-factory.cc', 'utils/pcap-file.cc', 'utils/pcap-file-wrapper.cc', + 'utils/generic-phy.cc', 'utils/queue.cc', 'utils/radiotap-header.cc', 'utils/simple-channel.cc', diff -r 52904cc0aa8a src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc --- a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc Mon Nov 28 23:53:47 2011 +0100 @@ -110,7 +110,7 @@ Ptr phy = (m_phy.Create ())->GetObject (); NS_ASSERT (phy); - dev->SetPhy (phy); + dev->SetPhy (phy->GetObject ()); NS_ASSERT (node); phy->SetMobility (node->GetObject ()); diff -r 52904cc0aa8a src/spectrum/helper/spectrum-analyzer-helper.cc --- a/src/spectrum/helper/spectrum-analyzer-helper.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/helper/spectrum-analyzer-helper.cc Mon Nov 28 23:53:47 2011 +0100 @@ -29,6 +29,8 @@ #include "ns3/non-communicating-net-device.h" #include "ns3/output-stream-wrapper.h" #include "ns3/trace-helper.h" +#include "ns3/generic-phy.h" + #include "spectrum-analyzer-helper.h" @@ -139,7 +141,7 @@ Ptr phy = m_phy.Create ()->GetObject (); NS_ASSERT (phy); - dev->SetPhy (phy); + dev->SetPhy (phy->GetObject ()); NS_ASSERT (node); phy->SetMobility (node->GetObject ()); diff -r 52904cc0aa8a src/spectrum/helper/waveform-generator-helper.cc --- a/src/spectrum/helper/waveform-generator-helper.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/helper/waveform-generator-helper.cc Mon Nov 28 23:53:47 2011 +0100 @@ -27,6 +27,7 @@ #include "ns3/spectrum-channel.h" #include "ns3/waveform-generator.h" #include "ns3/non-communicating-net-device.h" +#include "ns3/generic-phy.h" #include "waveform-generator-helper.h" @@ -95,7 +96,7 @@ Ptr phy = m_phy.Create ()->GetObject (); NS_ASSERT (phy); - dev->SetPhy (phy); + dev->SetPhy (phy->GetObject ()); NS_ASSERT (node); phy->SetMobility (node->GetObject ()); diff -r 52904cc0aa8a src/spectrum/model/aloha-noack-net-device.cc --- a/src/spectrum/model/aloha-noack-net-device.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/aloha-noack-net-device.cc Mon Nov 28 23:53:47 2011 +0100 @@ -82,7 +82,7 @@ PointerValue (), MakePointerAccessor (&AlohaNoackNetDevice::GetPhy, &AlohaNoackNetDevice::SetPhy), - MakePointerChecker ()) + MakePointerChecker ()) .AddTraceSource ("MacTx", "Trace source indicating a packet has arrived for transmission by this device", MakeTraceSourceAccessor (&AlohaNoackNetDevice::m_macTxTrace)) @@ -248,14 +248,14 @@ } void -AlohaNoackNetDevice::SetPhy (Ptr phy) +AlohaNoackNetDevice::SetPhy (Ptr phy) { NS_LOG_FUNCTION (this << phy); m_phy = phy; } -Ptr +Ptr AlohaNoackNetDevice::GetPhy () const { NS_LOG_FUNCTION (this); diff -r 52904cc0aa8a src/spectrum/model/aloha-noack-net-device.h --- a/src/spectrum/model/aloha-noack-net-device.h Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/aloha-noack-net-device.h Mon Nov 28 23:53:47 2011 +0100 @@ -137,12 +137,12 @@ * callbacks, so we do not require that the PHY inherits by any * specific class. */ - void SetPhy (Ptr phy); + void SetPhy (Ptr phy); /** * @return a reference to the PHY object embedded in this NetDevice. */ - Ptr GetPhy () const; + Ptr GetPhy () const; @@ -221,7 +221,7 @@ Ptr m_currentPkt; - Ptr m_phy; + Ptr m_phy; }; diff -r 52904cc0aa8a src/spectrum/model/half-duplex-ideal-phy.cc --- a/src/spectrum/model/half-duplex-ideal-phy.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/half-duplex-ideal-phy.cc Mon Nov 28 23:53:47 2011 +0100 @@ -45,6 +45,11 @@ m_state (IDLE) { m_interference.SetErrorModel (CreateObject ()); + // this allows to mark this object as being convertable to + // GenericPhy (i.e., calling GetObject () returns + // non-null) without inheriting from it (which would require + // multiple inheritance) + AggregateObject (CreateObject ()); } diff -r 52904cc0aa8a src/spectrum/model/non-communicating-net-device.cc --- a/src/spectrum/model/non-communicating-net-device.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/non-communicating-net-device.cc Mon Nov 28 23:53:47 2011 +0100 @@ -26,6 +26,7 @@ #include "ns3/uinteger.h" #include "ns3/pointer.h" #include "ns3/channel.h" +#include "ns3/generic-phy.h" #include "non-communicating-net-device.h" @@ -48,7 +49,7 @@ PointerValue (), MakePointerAccessor (&NonCommunicatingNetDevice::GetPhy, &NonCommunicatingNetDevice::SetPhy), - MakePointerChecker ()) + MakePointerChecker ()) ; return tid; } @@ -181,14 +182,14 @@ } void -NonCommunicatingNetDevice::SetPhy (Ptr phy) +NonCommunicatingNetDevice::SetPhy (Ptr phy) { NS_LOG_FUNCTION (this << phy); m_phy = phy; } -Ptr +Ptr NonCommunicatingNetDevice::GetPhy () const { NS_LOG_FUNCTION (this); diff -r 52904cc0aa8a src/spectrum/model/non-communicating-net-device.h --- a/src/spectrum/model/non-communicating-net-device.h Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/non-communicating-net-device.h Mon Nov 28 23:53:47 2011 +0100 @@ -37,7 +37,7 @@ class Channel; class SpectrumErrorModel; class Queue; - +class GenericPhy; /** @@ -79,12 +79,12 @@ * * @param phy the Phy object embedded within this device. */ - void SetPhy (Ptr phy); + void SetPhy (Ptr phy); /** * @return a reference to the PHY object embedded in this NetDevice. */ - Ptr GetPhy () const; + Ptr GetPhy () const; @@ -128,7 +128,7 @@ uint32_t m_ifIndex; - Ptr m_phy; + Ptr m_phy; }; diff -r 52904cc0aa8a src/spectrum/model/spectrum-analyzer.cc --- a/src/spectrum/model/spectrum-analyzer.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/spectrum-analyzer.cc Mon Nov 28 23:53:47 2011 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer"); @@ -41,6 +42,11 @@ m_active (false) { NS_LOG_FUNCTION (this); + // this allows to mark this object as being convertable to + // GenericPhy (i.e., calling GetObject () returns + // non-null) without inheriting from it (which would require + // multiple inheritance) + AggregateObject (CreateObject ()); } diff -r 52904cc0aa8a src/spectrum/model/waveform-generator.cc --- a/src/spectrum/model/waveform-generator.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/model/waveform-generator.cc Mon Nov 28 23:53:47 2011 +0100 @@ -24,7 +24,7 @@ #include #include #include - +#include NS_LOG_COMPONENT_DEFINE ("WaveformGenerator"); @@ -40,7 +40,11 @@ m_startTime (Seconds (0)), m_active (false) { - + // this allows to mark this object as being convertable to + // GenericPhy (i.e., calling GetObject () returns + // non-null) without inheriting from it (which would require + // multiple inheritance) + AggregateObject (CreateObject ()); } diff -r 52904cc0aa8a src/spectrum/test/spectrum-ideal-phy-test.cc --- a/src/spectrum/test/spectrum-ideal-phy-test.cc Thu Nov 17 18:11:07 2011 +0000 +++ b/src/spectrum/test/spectrum-ideal-phy-test.cc Mon Nov 28 23:53:47 2011 +0100 @@ -192,7 +192,7 @@ apps.Start (Seconds (0.0)); apps.Stop (Seconds (testDuration)); - Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxEndOk", MakeCallback (&PhyRxEndOkTrace)); + Config::Connect ("/NodeList/*/DeviceList/*/Phy/$ns3::HalfDuplexIdealPhy/RxEndOk", MakeCallback (&PhyRxEndOkTrace)); g_rxBytes = 0; Simulator::Stop (Seconds (testDuration+0.000000001));