diff --git a/helper/isl-helper.cc b/helper/isl-helper.cc index b64da3b..fdd89e5 100644 --- a/helper/isl-helper.cc +++ b/helper/isl-helper.cc @@ -31,7 +31,7 @@ #include "ns3/trace-helper.h" #include "../model/mock-net-device.h" -#include "../model/mock-channel.h" +#include "../model/isl-mock-channel.h" #include "isl-helper.h" namespace ns3 { @@ -42,7 +42,7 @@ IslHelper::IslHelper () { m_queueFactory.SetTypeId ("ns3::DropTailQueue"); m_deviceFactory.SetTypeId ("ns3::MockNetDevice"); - m_channelFactory.SetTypeId ("ns3::MockChannel"); + m_channelFactory.SetTypeId ("ns3::IslMockChannel"); } void diff --git a/model/isl-mock-channel.cc b/model/isl-mock-channel.cc new file mode 100644 index 0000000..a4e7cc1 --- /dev/null +++ b/model/isl-mock-channel.cc @@ -0,0 +1,114 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007, 2008 University of Washington + * + * 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 + */ + +#include +#include +#include +#include +#include +#include "isl-mock-channel.h" + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("IslMockChannel"); + +NS_OBJECT_ENSURE_REGISTERED (IslMockChannel); + +TypeId +IslMockChannel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::IslMockChannel") + .SetParent () + .SetGroupName ("Leo") + .AddConstructor () + ; + return tid; +} + +// +// By default, you get a channel that +// has an "infitely" fast transmission speed and zero processing delay. +IslMockChannel::IslMockChannel() : MockChannel () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +IslMockChannel::~IslMockChannel() +{ +} + +bool IslMockChannel::Deliver ( + Ptr p, + Ptr src, + Ptr dst, + Time txTime) +{ + NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime); + Time delay = GetDelay (src, dst, txTime); + + /* Check if there is LOS between the source and destination */ + if (GetPropagationLoss ()->CalcRxPower(1, src->GetMobilityModel(), dst->GetMobilityModel()) > 0) + { + Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), + delay, + &MockNetDevice::Receive, + dst, + p->Copy (), + src); + + // Call the tx anim callback on the net device + m_txrxMock (p, src, dst, txTime, delay); + return true; + } + else + { + NS_LOG_LOGIC (dst << " unreachable from " << src); + + return false; + } +} + +bool +IslMockChannel::TransmitStart ( + Ptr p, + uint32_t srcId, + Address destAddr, + Time txTime) +{ + NS_LOG_FUNCTION (this << p << srcId << destAddr << txTime); + NS_LOG_LOGIC ("UID is " << p->GetUid () << ")"); + + Ptr src = DynamicCast (GetDevice (srcId)); + Ptr dst = DynamicCast (GetDevice (destAddr)); + + if (dst == nullptr) + { + NS_LOG_LOGIC ("destination address " << destAddr << " unknown on channel"); + for (uint32_t i = 0; i < GetNDevices (); i++) + { + Deliver (p, src, DynamicCast (GetDevice (i)), txTime); + } + return true; + } + else + { + return Deliver (p, src, dst, txTime); + } +} + +} // namespace ns3 diff --git a/model/isl-mock-channel.h b/model/isl-mock-channel.h new file mode 100644 index 0000000..05bda45 --- /dev/null +++ b/model/isl-mock-channel.h @@ -0,0 +1,68 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#ifndef ISL_CHANNEL_H +#define ISL_CHANNEL_H + +#include +#include + +#include "ns3/object.h" +#include "ns3/ptr.h" +#include "ns3/channel.h" +#include "ns3/mobility-model.h" +#include "ns3/net-device.h" +#include "ns3/time-data-calculators.h" +#include "ns3/traced-callback.h" +#include "ns3/mobility-module.h" +#include "ns3/propagation-delay-model.h" +#include "ns3/propagation-loss-model.h" +#include "mock-net-device.h" +#include "mock-channel.h" + +namespace ns3 { + +class MockNetDevice; + +/** + * \ingroup network + * \defgroup channel Channel + */ +/** + * \ingroup channel + * \brief Simplified inter-satellite channel + * + * A perfect channel with varariable delay (time-of-flight). + * + */ +class IslMockChannel : public MockChannel +{ +public: + static TypeId GetTypeId (void); + + IslMockChannel (); + virtual ~IslMockChannel (); + + bool TransmitStart (Ptr p, uint32_t devId, Address dst, Time txTime); + +private: + + bool Deliver (Ptr p, Ptr src, Ptr dst, Time txTime); +}; // class MockChannel + +} // namespace ns3 + +#endif /* ISL_CHANNEL_H */ diff --git a/model/mock-channel.cc b/model/mock-channel.cc index 01f925a..5cdd439 100644 --- a/model/mock-channel.cc +++ b/model/mock-channel.cc @@ -35,7 +35,6 @@ MockChannel::GetTypeId (void) static TypeId tid = TypeId ("ns3::MockChannel") .SetParent () .SetGroupName ("Leo") - .AddConstructor () .AddAttribute ("PropagationDelay", "A propagation delay model for the channel.", PointerValue (), @@ -112,65 +111,6 @@ MockChannel::GetDevice (std::size_t i) const return m_link[i]; } -bool MockChannel::Deliver ( - Ptr p, - Ptr src, - Ptr dst, - Time txTime) -{ - NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime); - Time delay = GetDelay (src, dst, txTime); - - /* Check if there is LOS between the source and destination */ - if (m_propagationLoss->CalcRxPower(1, src->GetMobilityModel(), dst->GetMobilityModel()) > 0) - { - Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), - delay, - &MockNetDevice::Receive, - dst, - p->Copy (), - src); - - // Call the tx anim callback on the net device - m_txrxMock (p, src, dst, txTime, delay); - return true; - } - else - { - NS_LOG_LOGIC (dst << " unreachable from " << src); - - return false; - } -} - -bool -MockChannel::TransmitStart ( - Ptr p, - uint32_t srcId, - Address destAddr, - Time txTime) -{ - NS_LOG_FUNCTION (this << p << srcId << destAddr << txTime); - NS_LOG_LOGIC ("UID is " << p->GetUid () << ")"); - - Ptr src = m_link[srcId]; - Ptr dst = GetDevice (destAddr); - - if (dst == nullptr) - { - NS_LOG_LOGIC ("destination address " << destAddr << " unknown on channel"); - for (uint32_t i = 0; i < m_link.size (); i++) - { - Deliver (p, src, m_link[i], txTime); - } - return true; - } - else - { - return Deliver (p, src, dst, txTime); - } -} - Time MockChannel::GetDelay (Ptr src, Ptr dst, Time txTime) const { @@ -199,4 +139,16 @@ MockChannel::GetDevice (Address &addr) const return 0; } +Ptr +MockChannel::GetPropagationDelay () const +{ + return m_propagationDelay; +} + +Ptr +MockChannel::GetPropagationLoss () const +{ + return m_propagationLoss; +} + } // namespace ns3 diff --git a/model/mock-channel.h b/model/mock-channel.h index 81bc9de..b3b3820 100644 --- a/model/mock-channel.h +++ b/model/mock-channel.h @@ -14,8 +14,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef ISL_CHANNEL_H -#define ISL_CHANNEL_H +#ifndef MOCK_CHANNEL_H +#define MOCK_CHANNEL_H #include #include @@ -42,9 +42,7 @@ class MockNetDevice; */ /** * \ingroup channel - * \brief Simplified inter-satellite channel - * - * A perfect channel with varariable delay (time-of-flight). + * \brief Mocked channel * */ class MockChannel : public Channel @@ -55,6 +53,8 @@ public: MockChannel (); virtual ~MockChannel (); + Ptr GetDevice (std::size_t i) const; + /** * \brief Attach a device to the channel. * \param device Device to attach to the channel @@ -68,27 +68,31 @@ public: * \return true on success, false on failure */ bool Detach (uint32_t deviceId); - virtual std::size_t GetNDevices (void) const; - virtual Ptr GetDevice (std::size_t i) const; - virtual bool TransmitStart (Ptr p, uint32_t devId, Address dst, Time txTime); + + std::size_t GetNDevices (void) const; + virtual bool TransmitStart (Ptr p, uint32_t devId, Address dst, Time txTime) = 0; protected: - /** - * \brief Get the delay associated with this channel - * \returns Time delay - */ - Time GetDelay (Ptr first, Ptr second, Time txTime) const; - -private: - - Ptr GetDevice (Address &addr) const; - TracedCallback, // Packet being transmitted Ptr, // Transmitting NetDevice Ptr, // Receiving NetDevice Time, // Amount of time to transmit the pkt Time // Last bit receive time (relative to now) > m_txrxMock; + + /** + * \brief Get the delay associated with this channel + * \returns Time delay + */ + Time GetDelay (Ptr first, Ptr second, Time txTime) const; + + Ptr GetPropagationDelay () const; + Ptr GetPropagationLoss () const; + Ptr GetDevice (Address &addr) const; +private: + + std::vector > m_link; + /** * \brief Propagation delay model to be used with this channel */ @@ -97,11 +101,8 @@ private: * \brief Propagation loss model to be used with this channel */ Ptr m_propagationLoss; - std::vector > m_link; - - bool Deliver (Ptr p, Ptr src, Ptr dst, Time txTime); }; // class MockChannel } // namespace ns3 -#endif /* ISL_CHANNEL_H */ +#endif /* MOCK_CHANNEL_H */ diff --git a/wscript b/wscript index 236a7d7..cf0311c 100644 --- a/wscript +++ b/wscript @@ -12,6 +12,7 @@ def build(bld): 'model/leo.cc', 'model/mock-net-device.cc', 'model/mock-channel.cc', + 'model/isl-mock-channel.cc', 'model/isl-propagation-loss-model.cc', 'model/leo-mobility-model.cc', 'helper/leo-helper.cc', @@ -29,6 +30,7 @@ def build(bld): 'model/leo.h', 'model/mock-net-device.h', 'model/mock-channel.h', + 'model/isl-mock-channel.h', 'model/isl-propagation-loss-model.h', 'model/leo-mobility-model.h', 'helper/leo-helper.h',