mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 10:03:58 +02:00
refactor mock-channel
This commit is contained in:
parent
76c314130e
commit
95774794b5
6 changed files with 221 additions and 84 deletions
114
model/isl-mock-channel.cc
Normal file
114
model/isl-mock-channel.cc
Normal 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
68
model/isl-mock-channel.h
Normal 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 */
|
|
@ -35,7 +35,6 @@ MockChannel::GetTypeId (void)
|
|||
static TypeId tid = TypeId ("ns3::MockChannel")
|
||||
.SetParent<Channel> ()
|
||||
.SetGroupName ("Leo")
|
||||
.AddConstructor<MockChannel> ()
|
||||
.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<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
|
||||
MockChannel::GetDelay (Ptr<const MockNetDevice> src, Ptr<const MockNetDevice> dst, Time txTime) const
|
||||
{
|
||||
|
@ -199,4 +139,16 @@ MockChannel::GetDevice (Address &addr) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
Ptr<PropagationDelayModel>
|
||||
MockChannel::GetPropagationDelay () const
|
||||
{
|
||||
return m_propagationDelay;
|
||||
}
|
||||
|
||||
Ptr<PropagationLossModel>
|
||||
MockChannel::GetPropagationLoss () const
|
||||
{
|
||||
return m_propagationLoss;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
|
|
@ -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 <string>
|
||||
#include <stdint.h>
|
||||
|
@ -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<NetDevice> 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<NetDevice> GetDevice (std::size_t i) const;
|
||||
virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime);
|
||||
|
||||
std::size_t GetNDevices (void) const;
|
||||
virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime) = 0;
|
||||
|
||||
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
|
||||
Ptr<NetDevice>, // Transmitting NetDevice
|
||||
Ptr<NetDevice>, // 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<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
|
||||
*/
|
||||
|
@ -97,11 +101,8 @@ private:
|
|||
* \brief Propagation loss model to be used with this channel
|
||||
*/
|
||||
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
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* ISL_CHANNEL_H */
|
||||
#endif /* MOCK_CHANNEL_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue