diff --git a/model/mock-channel.cc b/model/mock-channel.cc index bba30a2..736aded 100644 --- a/model/mock-channel.cc +++ b/model/mock-channel.cc @@ -31,30 +31,30 @@ NS_LOG_COMPONENT_DEFINE ("MockChannel"); NS_OBJECT_ENSURE_REGISTERED (MockChannel); TypeId -MockChannel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::MockChannel") - .SetParent () - .SetGroupName ("Leo") - .AddAttribute ("PropagationDelay", - "A propagation delay model for the channel.", - PointerValue (), - MakePointerAccessor (&MockChannel::m_propagationDelay), - MakePointerChecker ()) - .AddAttribute ("PropagationLoss", - "A propagation loss model for the channel.", - PointerValue (), - MakePointerAccessor (&MockChannel::m_propagationLoss), - MakePointerChecker ()) - .AddTraceSource ("TxRxMockChannel", - "Trace source indicating transmission of packet " - "from the MockChannel, used by the Animation " - "interface.", - MakeTraceSourceAccessor (&MockChannel::m_txrxMock), - "ns3::MockChannel::TxRxAnimationCallback") - ; - return tid; -} + MockChannel::GetTypeId (void) + { + static TypeId tid = TypeId ("ns3::MockChannel") + .SetParent () + .SetGroupName ("Leo") + .AddAttribute ("PropagationDelay", + "A propagation delay model for the channel.", + PointerValue (), + MakePointerAccessor (&MockChannel::m_propagationDelay), + MakePointerChecker ()) + .AddAttribute ("PropagationLoss", + "A propagation loss model for the channel.", + PointerValue (), + MakePointerAccessor (&MockChannel::m_propagationLoss), + MakePointerChecker ()) + .AddTraceSource ("TxRxMockChannel", + "Trace source indicating transmission of packet " + "from the MockChannel, used by the Animation " + "interface.", + MakeTraceSourceAccessor (&MockChannel::m_txrxMock), + "ns3::MockChannel::TxRxAnimationCallback") + ; + return tid; + } // // By default, you get a channel that @@ -65,121 +65,132 @@ MockChannel::MockChannel() : Channel (), m_link (0) } MockChannel::~MockChannel() -{ -} + { + } bool -MockChannel::Detach (uint32_t deviceId) -{ - NS_LOG_FUNCTION (this << deviceId); - if (deviceId < m_link.size ()) - { - if (!m_link[deviceId]->IsLinkUp ()) + MockChannel::Detach (uint32_t deviceId) { - NS_LOG_WARN ("MockChannel::Detach(): Device is already detached (" << deviceId << ")"); - return false; + 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 << ")"); + return false; + } + + m_link[deviceId]->NotifyLinkDown (); + } + else + { + return false; + } + return true; } - m_link[deviceId]->NotifyLinkDown (); - } - else - { - return false; - } - return true; -} - int32_t -MockChannel::Attach (Ptr device) -{ - NS_LOG_FUNCTION (this << device); - NS_ASSERT (device != 0); - m_link.push_back(device); - return m_link.size() - 1; -} + MockChannel::Attach (Ptr 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 -{ - NS_LOG_FUNCTION_NOARGS (); - return m_link.size (); -} + MockChannel::GetNDevices (void) const + { + NS_LOG_FUNCTION_NOARGS (); + return m_link.size (); + } Ptr -MockChannel::GetDevice (std::size_t i) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_link[i]; -} + MockChannel::GetDevice (std::size_t i) const + { + NS_LOG_FUNCTION_NOARGS (); + return m_link[i]; + } Time -MockChannel::GetDelay (Ptr src, Ptr dst, Time txTime) const -{ - NS_LOG_FUNCTION (this << src << dst << txTime); + MockChannel::GetPropagationDelay (Ptr srcMob, Ptr dstMob, Time txTime) const + { + NS_LOG_FUNCTION (this << srcMob << dstMob << txTime); - Ptr modSrc = src->GetNode ()->GetObject (); - Ptr modDst = dst->GetNode ()->GetObject (); - - 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 -MockChannel::GetDevice (Address &addr) const -{ - for (Ptr dev : m_link) - { - if (dev->GetAddress () == addr) + MockChannel::GetDevice (Address &addr) const { - return dev; - } - } + for (Ptr dev : m_link) + { + if (dev->GetAddress () == addr) + { + return dev; + } + } - return 0; -} + return 0; + } Ptr -MockChannel::GetPropagationDelay () const -{ - return m_propagationDelay; -} - -Ptr -MockChannel::GetPropagationLoss () const -{ - return m_propagationLoss; -} - -bool -MockChannel::Deliver ( - Ptr p, - Ptr src, - Ptr 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) + MockChannel::GetPropagationDelay () const { - return false; + return m_propagationDelay; } - Time delay = GetDelay (src, dst, txTime); +Ptr + MockChannel::GetPropagationLoss () const + { + return m_propagationLoss; + } - Simulator::ScheduleWithContext (dst->GetNode ()->GetId (), - delay, - &MockNetDevice::Receive, - dst, - p->Copy (), - src); +bool + MockChannel::Deliver ( + Ptr p, + Ptr src, + Ptr dst, + Time txTime) + { + NS_LOG_FUNCTION (this << p << src->GetAddress () << dst->GetAddress () << txTime); + Time delay = txTime; - // Call the tx anim callback on the net device - m_txrxMock (p, src, dst, txTime, delay); - return true; -} + Ptr srcMob = src->GetObject (); + Ptr dstMob = dst->GetObject (); + + if (srcMob != 0 && dstMob != 0) + { + Ptr 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 diff --git a/model/mock-channel.h b/model/mock-channel.h index 65314fc..904012b 100644 --- a/model/mock-channel.h +++ b/model/mock-channel.h @@ -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 first, Ptr second, Time txTime) const; + Time GetPropagationDelay (Ptr first, Ptr second, Time txTime) const; Ptr GetPropagationDelay () const; Ptr GetPropagationLoss () const; diff --git a/model/mock-net-device.cc b/model/mock-net-device.cc index ea70150..6abdb77 100644 --- a/model/mock-net-device.cc +++ b/model/mock-net-device.cc @@ -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 diff --git a/test/leo-mock-channel-test-suite.cc b/test/leo-mock-channel-test-suite.cc index a6643c8..5a88601 100644 --- a/test/leo-mock-channel-test-suite.cc +++ b/test/leo-mock-channel-test-suite.cc @@ -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");