refactor mock-channel

This commit is contained in:
Tim Schubert 2020-06-22 14:59:00 +02:00
parent 76c314130e
commit 95774794b5
6 changed files with 221 additions and 84 deletions

View file

@ -31,7 +31,7 @@
#include "ns3/trace-helper.h" #include "ns3/trace-helper.h"
#include "../model/mock-net-device.h" #include "../model/mock-net-device.h"
#include "../model/mock-channel.h" #include "../model/isl-mock-channel.h"
#include "isl-helper.h" #include "isl-helper.h"
namespace ns3 { namespace ns3 {
@ -42,7 +42,7 @@ IslHelper::IslHelper ()
{ {
m_queueFactory.SetTypeId ("ns3::DropTailQueue<Packet>"); m_queueFactory.SetTypeId ("ns3::DropTailQueue<Packet>");
m_deviceFactory.SetTypeId ("ns3::MockNetDevice"); m_deviceFactory.SetTypeId ("ns3::MockNetDevice");
m_channelFactory.SetTypeId ("ns3::MockChannel"); m_channelFactory.SetTypeId ("ns3::IslMockChannel");
} }
void void

114
model/isl-mock-channel.cc Normal file
View file

@ -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 <ns3/trace-source-accessor.h>
#include <ns3/packet.h>
#include <ns3/simulator.h>
#include <ns3/log.h>
#include <ns3/pointer.h>
#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<MockChannel> ()
.SetGroupName ("Leo")
.AddConstructor<IslMockChannel> ()
;
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<const Packet> p,
Ptr<MockNetDevice> src,
Ptr<MockNetDevice> 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<const Packet> p,
uint32_t srcId,
Address destAddr,
Time txTime)
{
NS_LOG_FUNCTION (this << p << srcId << destAddr << txTime);
NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
Ptr<MockNetDevice> src = DynamicCast<MockNetDevice> (GetDevice (srcId));
Ptr<MockNetDevice> dst = DynamicCast<MockNetDevice> (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<MockNetDevice> (GetDevice (i)), txTime);
}
return true;
}
else
{
return Deliver (p, src, dst, txTime);
}
}
} // namespace ns3

68
model/isl-mock-channel.h Normal file
View file

@ -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 <string>
#include <stdint.h>
#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<const Packet> p, uint32_t devId, Address dst, Time txTime);
private:
bool Deliver (Ptr<const Packet> p, Ptr<MockNetDevice> src, Ptr<MockNetDevice> dst, Time txTime);
}; // class MockChannel
} // namespace ns3
#endif /* ISL_CHANNEL_H */

View file

@ -35,7 +35,6 @@ MockChannel::GetTypeId (void)
static TypeId tid = TypeId ("ns3::MockChannel") static TypeId tid = TypeId ("ns3::MockChannel")
.SetParent<Channel> () .SetParent<Channel> ()
.SetGroupName ("Leo") .SetGroupName ("Leo")
.AddConstructor<MockChannel> ()
.AddAttribute ("PropagationDelay", .AddAttribute ("PropagationDelay",
"A propagation delay model for the channel.", "A propagation delay model for the channel.",
PointerValue (), PointerValue (),
@ -112,65 +111,6 @@ MockChannel::GetDevice (std::size_t i) const
return m_link[i]; return m_link[i];
} }
bool MockChannel::Deliver (
Ptr<const Packet> p,
Ptr<MockNetDevice> src,
Ptr<MockNetDevice> 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<const Packet> p,
uint32_t srcId,
Address destAddr,
Time txTime)
{
NS_LOG_FUNCTION (this << p << srcId << destAddr << txTime);
NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
Ptr<MockNetDevice> src = m_link[srcId];
Ptr<MockNetDevice> 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 Time
MockChannel::GetDelay (Ptr<const MockNetDevice> src, Ptr<const MockNetDevice> dst, Time txTime) const MockChannel::GetDelay (Ptr<const MockNetDevice> src, Ptr<const MockNetDevice> dst, Time txTime) const
{ {
@ -199,4 +139,16 @@ MockChannel::GetDevice (Address &addr) const
return 0; return 0;
} }
Ptr<PropagationDelayModel>
MockChannel::GetPropagationDelay () const
{
return m_propagationDelay;
}
Ptr<PropagationLossModel>
MockChannel::GetPropagationLoss () const
{
return m_propagationLoss;
}
} // namespace ns3 } // namespace ns3

View file

@ -14,8 +14,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef ISL_CHANNEL_H #ifndef MOCK_CHANNEL_H
#define ISL_CHANNEL_H #define MOCK_CHANNEL_H
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
@ -42,9 +42,7 @@ class MockNetDevice;
*/ */
/** /**
* \ingroup channel * \ingroup channel
* \brief Simplified inter-satellite channel * \brief Mocked channel
*
* A perfect channel with varariable delay (time-of-flight).
* *
*/ */
class MockChannel : public Channel class MockChannel : public Channel
@ -55,6 +53,8 @@ public:
MockChannel (); MockChannel ();
virtual ~MockChannel (); virtual ~MockChannel ();
Ptr<NetDevice> GetDevice (std::size_t i) const;
/** /**
* \brief Attach a device to the channel. * \brief Attach a device to the channel.
* \param device Device to attach to the channel * \param device Device to attach to the channel
@ -68,27 +68,31 @@ public:
* \return true on success, false on failure * \return true on success, false on failure
*/ */
bool Detach (uint32_t deviceId); bool Detach (uint32_t deviceId);
virtual std::size_t GetNDevices (void) const;
virtual Ptr<NetDevice> GetDevice (std::size_t i) const; std::size_t GetNDevices (void) const;
virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime); virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime) = 0;
protected: protected:
/**
* \brief Get the delay associated with this channel
* \returns Time delay
*/
Time GetDelay (Ptr<const MockNetDevice> first, Ptr<const MockNetDevice> second, Time txTime) const;
private:
Ptr<MockNetDevice> GetDevice (Address &addr) const;
TracedCallback<Ptr<const Packet>, // Packet being transmitted TracedCallback<Ptr<const Packet>, // Packet being transmitted
Ptr<NetDevice>, // Transmitting NetDevice Ptr<NetDevice>, // Transmitting NetDevice
Ptr<NetDevice>, // Receiving NetDevice Ptr<NetDevice>, // Receiving NetDevice
Time, // Amount of time to transmit the pkt Time, // Amount of time to transmit the pkt
Time // Last bit receive time (relative to now) Time // Last bit receive time (relative to now)
> m_txrxMock; > m_txrxMock;
/**
* \brief Get the delay associated with this channel
* \returns Time delay
*/
Time GetDelay (Ptr<const MockNetDevice> first, Ptr<const MockNetDevice> second, Time txTime) const;
Ptr<PropagationDelayModel> GetPropagationDelay () const;
Ptr<PropagationLossModel> GetPropagationLoss () const;
Ptr<MockNetDevice> GetDevice (Address &addr) const;
private:
std::vector<Ptr<MockNetDevice> > m_link;
/** /**
* \brief Propagation delay model to be used with this channel * \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 * \brief Propagation loss model to be used with this channel
*/ */
Ptr<PropagationLossModel> m_propagationLoss; Ptr<PropagationLossModel> m_propagationLoss;
std::vector<Ptr<MockNetDevice> > m_link;
bool Deliver (Ptr<const Packet> p, Ptr<MockNetDevice> src, Ptr<MockNetDevice> dst, Time txTime);
}; // class MockChannel }; // class MockChannel
} // namespace ns3 } // namespace ns3
#endif /* ISL_CHANNEL_H */ #endif /* MOCK_CHANNEL_H */

View file

@ -12,6 +12,7 @@ def build(bld):
'model/leo.cc', 'model/leo.cc',
'model/mock-net-device.cc', 'model/mock-net-device.cc',
'model/mock-channel.cc', 'model/mock-channel.cc',
'model/isl-mock-channel.cc',
'model/isl-propagation-loss-model.cc', 'model/isl-propagation-loss-model.cc',
'model/leo-mobility-model.cc', 'model/leo-mobility-model.cc',
'helper/leo-helper.cc', 'helper/leo-helper.cc',
@ -29,6 +30,7 @@ def build(bld):
'model/leo.h', 'model/leo.h',
'model/mock-net-device.h', 'model/mock-net-device.h',
'model/mock-channel.h', 'model/mock-channel.h',
'model/isl-mock-channel.h',
'model/isl-propagation-loss-model.h', 'model/isl-propagation-loss-model.h',
'model/leo-mobility-model.h', 'model/leo-mobility-model.h',
'helper/leo-helper.h', 'helper/leo-helper.h',