mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 10:03:58 +02:00
fixup: mobility model and loss
This commit is contained in:
parent
582d6c58d0
commit
42f5bac245
4 changed files with 131 additions and 121 deletions
|
@ -31,30 +31,30 @@ 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")
|
||||||
.AddAttribute ("PropagationDelay",
|
.AddAttribute ("PropagationDelay",
|
||||||
"A propagation delay model for the channel.",
|
"A propagation delay model for the channel.",
|
||||||
PointerValue (),
|
PointerValue (),
|
||||||
MakePointerAccessor (&MockChannel::m_propagationDelay),
|
MakePointerAccessor (&MockChannel::m_propagationDelay),
|
||||||
MakePointerChecker<PropagationDelayModel> ())
|
MakePointerChecker<PropagationDelayModel> ())
|
||||||
.AddAttribute ("PropagationLoss",
|
.AddAttribute ("PropagationLoss",
|
||||||
"A propagation loss model for the channel.",
|
"A propagation loss model for the channel.",
|
||||||
PointerValue (),
|
PointerValue (),
|
||||||
MakePointerAccessor (&MockChannel::m_propagationLoss),
|
MakePointerAccessor (&MockChannel::m_propagationLoss),
|
||||||
MakePointerChecker<PropagationLossModel> ())
|
MakePointerChecker<PropagationLossModel> ())
|
||||||
.AddTraceSource ("TxRxMockChannel",
|
.AddTraceSource ("TxRxMockChannel",
|
||||||
"Trace source indicating transmission of packet "
|
"Trace source indicating transmission of packet "
|
||||||
"from the MockChannel, used by the Animation "
|
"from the MockChannel, used by the Animation "
|
||||||
"interface.",
|
"interface.",
|
||||||
MakeTraceSourceAccessor (&MockChannel::m_txrxMock),
|
MakeTraceSourceAccessor (&MockChannel::m_txrxMock),
|
||||||
"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,121 +65,132 @@ 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);
|
|
||||||
if (deviceId < m_link.size ())
|
|
||||||
{
|
|
||||||
if (!m_link[deviceId]->IsLinkUp ())
|
|
||||||
{
|
{
|
||||||
NS_LOG_WARN ("MockChannel::Detach(): Device is already detached (" << deviceId << ")");
|
NS_LOG_FUNCTION (this << deviceId);
|
||||||
return false;
|
if (deviceId < m_link.size ())
|
||||||
|
{
|
||||||
|
if (!m_link[deviceId]->IsLinkUp ())
|
||||||
|
{
|
||||||
|
NS_LOG_WARN ("MockChannel::Detach(): Device is already detached (" << deviceId << ")");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_link[deviceId]->NotifyLinkDown ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_link[deviceId]->NotifyLinkDown ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
if (dev->GetAddress () == addr)
|
|
||||||
{
|
{
|
||||||
return dev;
|
for (Ptr<MockNetDevice> dev : m_link)
|
||||||
}
|
{
|
||||||
}
|
if (dev->GetAddress () == addr)
|
||||||
|
{
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<PropagationDelayModel>
|
Ptr<PropagationDelayModel>
|
||||||
MockChannel::GetPropagationDelay () const
|
MockChannel::GetPropagationDelay () const
|
||||||
{
|
|
||||||
return m_propagationDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptr<PropagationLossModel>
|
|
||||||
MockChannel::GetPropagationLoss () const
|
|
||||||
{
|
|
||||||
return m_propagationLoss;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
double rxPower = GetPropagationLoss ()->CalcRxPower (1.0, src, dst);
|
|
||||||
|
|
||||||
if (rxPower == 0.0)
|
|
||||||
{
|
{
|
||||||
return false;
|
return m_propagationDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
Time delay = GetDelay (src, dst, txTime);
|
Ptr<PropagationLossModel>
|
||||||
|
MockChannel::GetPropagationLoss () const
|
||||||
|
{
|
||||||
|
return m_propagationLoss;
|
||||||
|
}
|
||||||
|
|
||||||
Simulator::ScheduleWithContext (dst->GetNode ()->GetId (),
|
bool
|
||||||
delay,
|
MockChannel::Deliver (
|
||||||
&MockNetDevice::Receive,
|
Ptr<const Packet> p,
|
||||||
dst,
|
Ptr<MockNetDevice> src,
|
||||||
p->Copy (),
|
Ptr<MockNetDevice> dst,
|
||||||
src);
|
Time txTime)
|
||||||
|
{
|
||||||
|
NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime);
|
||||||
|
Time delay = txTime;
|
||||||
|
|
||||||
// Call the tx anim callback on the net device
|
Ptr<MobilityModel> srcMob = src->GetObject<MobilityModel> ();
|
||||||
m_txrxMock (p, src, dst, txTime, delay);
|
Ptr<MobilityModel> dstMob = dst->GetObject<MobilityModel> ();
|
||||||
return true;
|
|
||||||
}
|
if (srcMob != 0 && dstMob != 0)
|
||||||
|
{
|
||||||
|
Ptr<PropagationLossModel> pLoss = GetPropagationLoss ();
|
||||||
|
if (pLoss != 0)
|
||||||
|
{
|
||||||
|
if (pLoss->CalcRxPower (1.0, srcMob, dstMob) == 0.0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delay += GetPropagationDelay (srcMob, dstMob, txTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ns3
|
} // namespace ns3
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue