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

View file

@ -81,10 +81,10 @@ protected:
> m_txrxMock;
/**
* \brief Get the delay associated with this channel
* \returns Time delay
* \brief Get the propagation delay associated with this channel
* \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<PropagationLossModel> GetPropagationLoss () const;

View file

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

View file

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