fixup: mobility model and loss

This commit is contained in:
Tim Schubert 2020-08-07 18:03:55 +02:00
parent 582d6c58d0
commit 42f5bac245
4 changed files with 131 additions and 121 deletions

View file

@ -31,8 +31,8 @@ NS_LOG_COMPONENT_DEFINE ("MockChannel");
NS_OBJECT_ENSURE_REGISTERED (MockChannel); NS_OBJECT_ENSURE_REGISTERED (MockChannel);
TypeId TypeId
MockChannel::GetTypeId (void) MockChannel::GetTypeId (void)
{ {
static TypeId tid = TypeId ("ns3::MockChannel") static TypeId tid = TypeId ("ns3::MockChannel")
.SetParent<Channel> () .SetParent<Channel> ()
.SetGroupName ("Leo") .SetGroupName ("Leo")
@ -54,7 +54,7 @@ MockChannel::GetTypeId (void)
"ns3::MockChannel::TxRxAnimationCallback") "ns3::MockChannel::TxRxAnimationCallback")
; ;
return tid; return tid;
} }
// //
// By default, you get a channel that // By default, you get a channel that
@ -65,12 +65,12 @@ MockChannel::MockChannel() : Channel (), m_link (0)
} }
MockChannel::~MockChannel() MockChannel::~MockChannel()
{ {
} }
bool bool
MockChannel::Detach (uint32_t deviceId) MockChannel::Detach (uint32_t deviceId)
{ {
NS_LOG_FUNCTION (this << deviceId); NS_LOG_FUNCTION (this << deviceId);
if (deviceId < m_link.size ()) if (deviceId < m_link.size ())
{ {
@ -87,48 +87,51 @@ MockChannel::Detach (uint32_t deviceId)
return false; return false;
} }
return true; return true;
} }
int32_t int32_t
MockChannel::Attach (Ptr<MockNetDevice> device) MockChannel::Attach (Ptr<MockNetDevice> device)
{ {
NS_LOG_FUNCTION (this << device); NS_LOG_FUNCTION (this << device);
NS_ASSERT (device != 0); NS_ASSERT (device != 0);
m_link.push_back(device); m_link.push_back(device);
return m_link.size() - 1; return m_link.size() - 1;
} }
std::size_t std::size_t
MockChannel::GetNDevices (void) const MockChannel::GetNDevices (void) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION_NOARGS ();
return m_link.size (); return m_link.size ();
} }
Ptr<NetDevice> Ptr<NetDevice>
MockChannel::GetDevice (std::size_t i) const MockChannel::GetDevice (std::size_t i) const
{ {
NS_LOG_FUNCTION_NOARGS (); NS_LOG_FUNCTION_NOARGS ();
return m_link[i]; return m_link[i];
} }
Time Time
MockChannel::GetDelay (Ptr<const MockNetDevice> src, Ptr<const MockNetDevice> dst, Time txTime) const MockChannel::GetPropagationDelay (Ptr<MobilityModel> srcMob, Ptr<MobilityModel> dstMob, Time txTime) const
{ {
NS_LOG_FUNCTION (this << src << dst << txTime); NS_LOG_FUNCTION (this << srcMob << dstMob << txTime);
Ptr<MobilityModel> modSrc = src->GetNode ()->GetObject<MobilityModel> (); if (GetPropagationDelay ())
Ptr<MobilityModel> modDst = dst->GetNode ()->GetObject<MobilityModel> (); {
Time propagationDelay = m_propagationDelay->GetDelay (srcMob, dstMob);
Time propagationDelay = m_propagationDelay->GetDelay (modSrc, modDst); return propagationDelay;
}
return txTime + propagationDelay; else
} {
return Time (0);
}
}
// TODO optimize // TODO optimize
Ptr<MockNetDevice> Ptr<MockNetDevice>
MockChannel::GetDevice (Address &addr) const MockChannel::GetDevice (Address &addr) const
{ {
for (Ptr<MockNetDevice> dev : m_link) for (Ptr<MockNetDevice> dev : m_link)
{ {
if (dev->GetAddress () == addr) if (dev->GetAddress () == addr)
@ -138,37 +141,45 @@ MockChannel::GetDevice (Address &addr) const
} }
return 0; return 0;
} }
Ptr<PropagationDelayModel> Ptr<PropagationDelayModel>
MockChannel::GetPropagationDelay () const MockChannel::GetPropagationDelay () const
{ {
return m_propagationDelay; return m_propagationDelay;
} }
Ptr<PropagationLossModel> Ptr<PropagationLossModel>
MockChannel::GetPropagationLoss () const MockChannel::GetPropagationLoss () const
{ {
return m_propagationLoss; return m_propagationLoss;
} }
bool bool
MockChannel::Deliver ( MockChannel::Deliver (
Ptr<const Packet> p, Ptr<const Packet> p,
Ptr<MockNetDevice> src, Ptr<MockNetDevice> src,
Ptr<MockNetDevice> dst, Ptr<MockNetDevice> dst,
Time txTime) Time txTime)
{ {
NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime); NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime);
Time delay = txTime;
double rxPower = GetPropagationLoss ()->CalcRxPower (1.0, src, dst); Ptr<MobilityModel> srcMob = src->GetObject<MobilityModel> ();
Ptr<MobilityModel> dstMob = dst->GetObject<MobilityModel> ();
if (rxPower == 0.0) if (srcMob != 0 && dstMob != 0)
{
Ptr<PropagationLossModel> pLoss = GetPropagationLoss ();
if (pLoss != 0)
{
if (pLoss->CalcRxPower (1.0, srcMob, dstMob) == 0.0)
{ {
return false; return false;
} }
}
Time delay = GetDelay (src, dst, txTime); delay += GetPropagationDelay (srcMob, dstMob, txTime);
}
Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), Simulator::ScheduleWithContext (dst->GetNode ()->GetId (),
delay, delay,
@ -180,6 +191,6 @@ MockChannel::Deliver (
// Call the tx anim callback on the net device // Call the tx anim callback on the net device
m_txrxMock (p, src, dst, txTime, delay); m_txrxMock (p, src, dst, txTime, delay);
return true; return true;
} }
} // namespace ns3 } // namespace ns3

View file

@ -81,10 +81,10 @@ protected:
> m_txrxMock; > m_txrxMock;
/** /**
* \brief Get the delay associated with this channel * \brief Get the propagation delay associated with this channel
* \returns Time delay * \returns Propagation time delay
*/ */
Time GetDelay (Ptr<const MockNetDevice> first, Ptr<const MockNetDevice> second, Time txTime) const; Time GetPropagationDelay (Ptr<MobilityModel> first, Ptr<MobilityModel> second, Time txTime) const;
Ptr<PropagationDelayModel> GetPropagationDelay () const; Ptr<PropagationDelayModel> GetPropagationDelay () const;
Ptr<PropagationLossModel> GetPropagationLoss () const; Ptr<PropagationLossModel> GetPropagationLoss () const;

View file

@ -582,7 +582,7 @@ bool
MockNetDevice::IsBroadcast (void) const MockNetDevice::IsBroadcast (void) const
{ {
NS_LOG_FUNCTION (this); NS_LOG_FUNCTION (this);
return false; return true;
} }
// //
@ -601,7 +601,7 @@ bool
MockNetDevice::IsMulticast (void) const MockNetDevice::IsMulticast (void) const
{ {
NS_LOG_FUNCTION (this); NS_LOG_FUNCTION (this);
return false; return true;
} }
Address Address

View file

@ -43,7 +43,6 @@ LeoMockChannelTransmitUnknownTestCase::DoRun (void)
Time txTime; Time txTime;
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel")); channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
dev->SetAttribute ("MobilityModel", StringValue ("ns3::ConstantPositionMobilityModel"));
bool result = channel->TransmitStart (p, srcId, destAddr, txTime); bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
NS_TEST_ASSERT_MSG_EQ (result, false, "Unknown destination fails to deliver"); NS_TEST_ASSERT_MSG_EQ (result, false, "Unknown destination fails to deliver");