Bug 1974 - CalculateTxTime should return a Time, not a double

This commit is contained in:
Tommaso Pecorella
2015-02-28 18:20:46 +01:00
parent 17e5e203b3
commit 0630f6dee9
9 changed files with 92 additions and 35 deletions

View File

@@ -21,9 +21,13 @@ Supported platforms
New user-visible features
-------------------------
- (network) CalculateTxTime has been declared obsolete.
CalculateBytesTxTime and CalculateBitsTxTime are to be used instead.
The reurn value is a Time, instead of a double.
Bugs fixed
----------
- Bug 1974 - CalculateTxTime should return a Time, not a double
- Bug 2073 - NDisc cache entries update timer might be stuck in a loop
Known issues

View File

@@ -520,7 +520,7 @@ CsmaNetDevice::TransmitStart (void)
m_txMachineState = BUSY;
m_phyTxBeginTrace (m_currentPkt);
Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
Time tEvent = m_bps.CalculateBytesTxTime (m_currentPkt->GetSize ());
NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec");
Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, this);
}
@@ -656,7 +656,7 @@ CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
//
// We use the Ethernet interframe gap of 96 bit times.
//
m_tInterframeGap = Seconds (m_bps.CalculateTxTime (96/8));
m_tInterframeGap = m_bps.CalculateBytesTxTime (96/8);
//
// This device is up whenever a channel is attached to it.

View File

@@ -769,8 +769,8 @@ def register_methods(root_module):
def register_Ns3Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## address.h (module 'network'): ns3::Address::Address() [constructor]
cls.add_constructor([])
@@ -1540,11 +1540,21 @@ def register_Ns3DataRate_methods(root_module, cls):
cls.add_constructor([param('uint64_t', 'bps')])
## data-rate.h (module 'network'): ns3::DataRate::DataRate(std::string rate) [constructor]
cls.add_constructor([param('std::string', 'rate')])
## data-rate.h (module 'network'): ns3::Time ns3::DataRate::CalculateBitsTxTime(uint32_t bits) const [member function]
cls.add_method('CalculateBitsTxTime',
'ns3::Time',
[param('uint32_t', 'bits')],
is_const=True)
## data-rate.h (module 'network'): ns3::Time ns3::DataRate::CalculateBytesTxTime(uint32_t bytes) const [member function]
cls.add_method('CalculateBytesTxTime',
'ns3::Time',
[param('uint32_t', 'bytes')],
is_const=True)
## data-rate.h (module 'network'): double ns3::DataRate::CalculateTxTime(uint32_t bytes) const [member function]
cls.add_method('CalculateTxTime',
'double',
[param('uint32_t', 'bytes')],
is_const=True)
deprecated=True, is_const=True)
## data-rate.h (module 'network'): uint64_t ns3::DataRate::GetBitRate() const [member function]
cls.add_method('GetBitRate',
'uint64_t',
@@ -1740,8 +1750,8 @@ def register_Ns3InetSocketAddress_methods(root_module, cls):
def register_Ns3Ipv4Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## ipv4-address.h (module 'network'): ns3::Ipv4Address::Ipv4Address(ns3::Ipv4Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Ipv4Address const &', 'arg0')])
@@ -1911,8 +1921,8 @@ def register_Ns3Ipv4Mask_methods(root_module, cls):
def register_Ns3Ipv6Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## ipv6-address.h (module 'network'): ns3::Ipv6Address::Ipv6Address() [constructor]
cls.add_constructor([])
@@ -2168,8 +2178,8 @@ def register_Ns3Ipv6Prefix_methods(root_module, cls):
def register_Ns3Mac16Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac16-address.h (module 'network'): ns3::Mac16Address::Mac16Address(ns3::Mac16Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac16Address const &', 'arg0')])
@@ -2205,8 +2215,8 @@ def register_Ns3Mac16Address_methods(root_module, cls):
def register_Ns3Mac48Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac48-address.h (module 'network'): ns3::Mac48Address::Mac48Address(ns3::Mac48Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac48Address const &', 'arg0')])
@@ -2277,8 +2287,8 @@ def register_Ns3Mac48Address_methods(root_module, cls):
def register_Ns3Mac64Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac64-address.h (module 'network'): ns3::Mac64Address::Mac64Address(ns3::Mac64Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac64Address const &', 'arg0')])
@@ -3548,8 +3558,8 @@ def register_Ns3TimeWithUnit_methods(root_module, cls):
def register_Ns3TypeId_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## type-id.h (module 'core'): ns3::TypeId::TypeId(char const * name) [constructor]
cls.add_constructor([param('char const *', 'name')])
@@ -3759,10 +3769,8 @@ def register_Ns3Empty_methods(root_module, cls):
return
def register_Ns3Int64x64_t_methods(root_module, cls):
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('!=')
cls.add_inplace_numeric_operator('+=', param('ns3::int64x64_t const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_numeric_operator('*', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
cls.add_binary_numeric_operator('+', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
cls.add_binary_numeric_operator('-', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
@@ -3773,6 +3781,8 @@ def register_Ns3Int64x64_t_methods(root_module, cls):
cls.add_inplace_numeric_operator('*=', param('ns3::int64x64_t const &', u'right'))
cls.add_inplace_numeric_operator('-=', param('ns3::int64x64_t const &', u'right'))
cls.add_inplace_numeric_operator('/=', param('ns3::int64x64_t const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('==')
cls.add_binary_comparison_operator('>=')
## int64x64-double.h (module 'core'): ns3::int64x64_t::int64x64_t() [constructor]
@@ -5404,10 +5414,8 @@ def register_Ns3SocketSetDontFragmentTag_methods(root_module, cls):
return
def register_Ns3Time_methods(root_module, cls):
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('!=')
cls.add_inplace_numeric_operator('+=', param('ns3::Time const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_numeric_operator('*', root_module['ns3::Time'], root_module['ns3::Time'], param('int64_t const &', u'right'))
cls.add_binary_numeric_operator('+', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Time const &', u'right'))
cls.add_binary_numeric_operator('-', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Time const &', u'right'))
@@ -5415,6 +5423,8 @@ def register_Ns3Time_methods(root_module, cls):
cls.add_binary_comparison_operator('<')
cls.add_binary_comparison_operator('>')
cls.add_inplace_numeric_operator('-=', param('ns3::Time const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('==')
cls.add_binary_comparison_operator('>=')
## nstime.h (module 'core'): ns3::Time::Time() [constructor]

View File

@@ -769,8 +769,8 @@ def register_methods(root_module):
def register_Ns3Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## address.h (module 'network'): ns3::Address::Address() [constructor]
cls.add_constructor([])
@@ -1540,11 +1540,21 @@ def register_Ns3DataRate_methods(root_module, cls):
cls.add_constructor([param('uint64_t', 'bps')])
## data-rate.h (module 'network'): ns3::DataRate::DataRate(std::string rate) [constructor]
cls.add_constructor([param('std::string', 'rate')])
## data-rate.h (module 'network'): ns3::Time ns3::DataRate::CalculateBitsTxTime(uint32_t bits) const [member function]
cls.add_method('CalculateBitsTxTime',
'ns3::Time',
[param('uint32_t', 'bits')],
is_const=True)
## data-rate.h (module 'network'): ns3::Time ns3::DataRate::CalculateBytesTxTime(uint32_t bytes) const [member function]
cls.add_method('CalculateBytesTxTime',
'ns3::Time',
[param('uint32_t', 'bytes')],
is_const=True)
## data-rate.h (module 'network'): double ns3::DataRate::CalculateTxTime(uint32_t bytes) const [member function]
cls.add_method('CalculateTxTime',
'double',
[param('uint32_t', 'bytes')],
is_const=True)
deprecated=True, is_const=True)
## data-rate.h (module 'network'): uint64_t ns3::DataRate::GetBitRate() const [member function]
cls.add_method('GetBitRate',
'uint64_t',
@@ -1740,8 +1750,8 @@ def register_Ns3InetSocketAddress_methods(root_module, cls):
def register_Ns3Ipv4Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## ipv4-address.h (module 'network'): ns3::Ipv4Address::Ipv4Address(ns3::Ipv4Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Ipv4Address const &', 'arg0')])
@@ -1911,8 +1921,8 @@ def register_Ns3Ipv4Mask_methods(root_module, cls):
def register_Ns3Ipv6Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## ipv6-address.h (module 'network'): ns3::Ipv6Address::Ipv6Address() [constructor]
cls.add_constructor([])
@@ -2168,8 +2178,8 @@ def register_Ns3Ipv6Prefix_methods(root_module, cls):
def register_Ns3Mac16Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac16-address.h (module 'network'): ns3::Mac16Address::Mac16Address(ns3::Mac16Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac16Address const &', 'arg0')])
@@ -2205,8 +2215,8 @@ def register_Ns3Mac16Address_methods(root_module, cls):
def register_Ns3Mac48Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac48-address.h (module 'network'): ns3::Mac48Address::Mac48Address(ns3::Mac48Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac48Address const &', 'arg0')])
@@ -2277,8 +2287,8 @@ def register_Ns3Mac48Address_methods(root_module, cls):
def register_Ns3Mac64Address_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## mac64-address.h (module 'network'): ns3::Mac64Address::Mac64Address(ns3::Mac64Address const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Mac64Address const &', 'arg0')])
@@ -3548,8 +3558,8 @@ def register_Ns3TimeWithUnit_methods(root_module, cls):
def register_Ns3TypeId_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<')
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('==')
## type-id.h (module 'core'): ns3::TypeId::TypeId(char const * name) [constructor]
cls.add_constructor([param('char const *', 'name')])
@@ -3759,10 +3769,8 @@ def register_Ns3Empty_methods(root_module, cls):
return
def register_Ns3Int64x64_t_methods(root_module, cls):
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('!=')
cls.add_inplace_numeric_operator('+=', param('ns3::int64x64_t const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_numeric_operator('*', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
cls.add_binary_numeric_operator('+', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
cls.add_binary_numeric_operator('-', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right'))
@@ -3773,6 +3781,8 @@ def register_Ns3Int64x64_t_methods(root_module, cls):
cls.add_inplace_numeric_operator('*=', param('ns3::int64x64_t const &', u'right'))
cls.add_inplace_numeric_operator('-=', param('ns3::int64x64_t const &', u'right'))
cls.add_inplace_numeric_operator('/=', param('ns3::int64x64_t const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('==')
cls.add_binary_comparison_operator('>=')
## int64x64-double.h (module 'core'): ns3::int64x64_t::int64x64_t() [constructor]
@@ -5404,10 +5414,8 @@ def register_Ns3SocketSetDontFragmentTag_methods(root_module, cls):
return
def register_Ns3Time_methods(root_module, cls):
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('!=')
cls.add_inplace_numeric_operator('+=', param('ns3::Time const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_numeric_operator('*', root_module['ns3::Time'], root_module['ns3::Time'], param('int64_t const &', u'right'))
cls.add_binary_numeric_operator('+', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Time const &', u'right'))
cls.add_binary_numeric_operator('-', root_module['ns3::Time'], root_module['ns3::Time'], param('ns3::Time const &', u'right'))
@@ -5415,6 +5423,8 @@ def register_Ns3Time_methods(root_module, cls):
cls.add_binary_comparison_operator('<')
cls.add_binary_comparison_operator('>')
cls.add_inplace_numeric_operator('-=', param('ns3::Time const &', u'right'))
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('<=')
cls.add_binary_comparison_operator('==')
cls.add_binary_comparison_operator('>=')
## nstime.h (module 'core'): ns3::Time::Time() [constructor]

View File

@@ -232,6 +232,20 @@ double DataRate::CalculateTxTime (uint32_t bytes) const
return static_cast<double>(bytes)*8/m_bps;
}
Time DataRate::CalculateBytesTxTime (uint32_t bytes) const
{
NS_LOG_FUNCTION (this << bytes);
// \todo avoid to use double (if possible).
return Seconds (static_cast<double>(bytes)*8/m_bps);
}
Time DataRate::CalculateBitsTxTime (uint32_t bits) const
{
NS_LOG_FUNCTION (this << bits);
// \todo avoid to use double (if possible).
return Seconds (static_cast<double>(bits)/m_bps);
}
uint64_t DataRate::GetBitRate () const
{
NS_LOG_FUNCTION (this);

View File

@@ -27,6 +27,7 @@
#include "ns3/nstime.h"
#include "ns3/attribute.h"
#include "ns3/attribute-helper.h"
#include "ns3/deprecated.h"
namespace ns3 {
@@ -42,9 +43,9 @@ namespace ns3 {
* from strings, natural multiplication e.g.:
* \code
* DataRate x("56kbps");
* double nBits = x*ns3::Seconds(19.2);
* double nBits = x*ns3::Seconds (19.2);
* uint32_t nBytes = 20;
* double txtime = x.CalclulateTxTime(nBytes);
* Time txtime = x.CalculateBytesTxTime (nBytes);
* \endcode
* This class also supports the regular comparison operators \c <, \c >,
* \c <=, \c >=, \c ==, and \c !=
@@ -159,6 +160,24 @@ public:
*/
bool operator != (const DataRate& rhs) const;
/**
* \brief Calculate transmission time
*
* Calculates the transmission time at this data rate
* \param bytes The number of bytes (not bits) for which to calculate
* \return The transmission time for the number of bytes specified
*/
Time CalculateBytesTxTime (uint32_t bytes) const;
/**
* \brief Calculate transmission time
*
* Calculates the transmission time at this data rate
* \param bits The number of bits (not bytes) for which to calculate
* \return The transmission time for the number of bits specified
*/
Time CalculateBitsTxTime (uint32_t bits) const;
/**
* \brief Calculate transmission time
*
@@ -166,7 +185,7 @@ public:
* \param bytes The number of bytes (not bits) for which to calculate
* \return The transmission time in seconds for the number of bytes specified
*/
double CalculateTxTime (uint32_t bytes) const;
double CalculateTxTime (uint32_t bytes) const NS_DEPRECATED;
/**
* Get the underlying bitrate

View File

@@ -451,7 +451,7 @@ SimpleNetDevice::SendFrom (Ptr<Packet> p, const Address& source, const Address&
Time txTime = Time (0);
if (m_bps > DataRate (0))
{
txTime = Seconds (m_bps.CalculateTxTime (packet->GetSize ()));
txTime = m_bps.CalculateBytesTxTime (packet->GetSize ());
}
m_channel->Send (p, protocolNumber, to, from, this);
TransmitCompleteEvent = Simulator::Schedule (txTime, &SimpleNetDevice::TransmitComplete, this);
@@ -491,7 +491,7 @@ SimpleNetDevice::TransmitComplete ()
Time txTime = Time (0);
if (m_bps > DataRate (0))
{
txTime = Seconds (m_bps.CalculateTxTime (packet->GetSize ()));
txTime = m_bps.CalculateBytesTxTime (packet->GetSize ());
}
TransmitCompleteEvent = Simulator::Schedule (txTime, &SimpleNetDevice::TransmitComplete, this);
}

View File

@@ -246,7 +246,7 @@ PointToPointNetDevice::TransmitStart (Ptr<Packet> p)
m_currentPkt = p;
m_phyTxBeginTrace (m_currentPkt);
Time txTime = Seconds (m_bps.CalculateTxTime (p->GetSize ()));
Time txTime = m_bps.CalculateBytesTxTime (p->GetSize ());
Time txCompleteTime = txTime + m_tInterframeGap;
NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << txCompleteTime.GetSeconds () << "sec");

View File

@@ -288,8 +288,8 @@ HalfDuplexIdealPhy::StartTx (Ptr<Packet> p)
m_txPacket = p;
ChangeState (TX);
Ptr<HalfDuplexIdealPhySignalParameters> txParams = Create<HalfDuplexIdealPhySignalParameters> ();
double txTimeSeconds = m_rate.CalculateTxTime (p->GetSize ());
txParams->duration = Seconds (txTimeSeconds);
Time txTimeSeconds = m_rate.CalculateBytesTxTime (p->GetSize ());
txParams->duration = txTimeSeconds;
txParams->txPhy = GetObject<SpectrumPhy> ();
txParams->txAntenna = m_antenna;
txParams->psd = m_txPsd;
@@ -297,7 +297,7 @@ HalfDuplexIdealPhy::StartTx (Ptr<Packet> p)
NS_LOG_LOGIC (this << " tx power: " << 10 * std::log10 (Integral (*(txParams->psd))) + 30 << " dBm");
m_channel->StartTx (txParams);
Simulator::Schedule (Seconds (txTimeSeconds), &HalfDuplexIdealPhy::EndTx, this);
Simulator::Schedule (txTimeSeconds, &HalfDuplexIdealPhy::EndTx, this);
}
break;