From fe8a11d26b5060073cb385346391461bcdeaea7a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 5 Jul 2010 17:37:05 +0200 Subject: [PATCH 1/7] avoid crash upon process exit --- src/core/fatal-impl.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/fatal-impl.cc b/src/core/fatal-impl.cc index de6d4e197..0d16bb692 100644 --- a/src/core/fatal-impl.cc +++ b/src/core/fatal-impl.cc @@ -32,11 +32,29 @@ namespace FatalImpl { /* File-scope */ namespace { + std::list **PeekStreamList (void) + { + static std::list *streams = 0; + return &streams; + } std::list *GetStreamList (void) + { + std::list **pstreams = PeekStreamList (); + if (*pstreams == 0) + { + *pstreams = new std::list (); + } + return *pstreams; + } + struct destructor + { + ~destructor () { - static std::list streams; - return &streams; + std::list **pstreams = PeekStreamList (); + delete *pstreams; + *pstreams = 0; } + }; } void From 0adaab0ad9ad5df36da89413f3bed03a9f7cfa4b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 6 Jul 2010 09:07:15 +0200 Subject: [PATCH 2/7] plug leak --- src/core/fatal-impl.cc | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/core/fatal-impl.cc b/src/core/fatal-impl.cc index 0d16bb692..9ee654a57 100644 --- a/src/core/fatal-impl.cc +++ b/src/core/fatal-impl.cc @@ -30,6 +30,19 @@ namespace ns3 { namespace FatalImpl { +/** + * Note on implementation: the singleton pattern we use here is tricky because + * it has to deal with: + * - make sure that whoever calls Register (potentially before main enters and + * before any constructor run in this file) succeeds + * - make sure that whoever calls Unregister (potentially before FlushStream runs + * but also after it runs) succeeds + * - make sure that the memory allocated with new is deallocated with delete before + * the program exits so that valgrind reports no leaks + * + * This is why we go through all the painful hoops below. + */ + /* File-scope */ namespace { std::list **PeekStreamList (void) @@ -66,7 +79,17 @@ RegisterStream (std::ostream* stream) void UnregisterStream (std::ostream* stream) { - GetStreamList ()->remove (stream); + std::list **pl = PeekStreamList (); + if (*pl == 0) + { + return; + } + (*pl)->remove (stream); + if ((*pl)->empty ()) + { + delete *pl; + *pl = 0; + } } @@ -83,16 +106,22 @@ namespace { void FlushStreams (void) { - struct sigaction hdl; + std::list **pl = PeekStreamList (); + if (pl == 0) + { + return; + } + /* Override default SIGSEGV handler - will flush subsequent * streams even if one of the stream pointers is bad. * The SIGSEGV override should only be active for the * duration of this function. */ + struct sigaction hdl; hdl.sa_handler=sigHandler; sigaction (SIGSEGV, &hdl, 0); - std::list *l = GetStreamList (); + std::list *l = *pl; /* Need to do it this way in case any of the ostream* causes SIGSEGV */ while (!l->empty ()) @@ -113,6 +142,9 @@ FlushStreams (void) std::cout.flush (); std::cerr.flush (); std::clog.flush (); + + delete l; + *pl = 0; } } //FatalImpl From 06c8a3b54e965fcb0f2402a91abacb58e99f6635 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Tue, 6 Jul 2010 11:17:18 +0100 Subject: [PATCH 3/7] Python bindins API rescan --- .../apidefs/gcc-ILP32/ns3_module_simulator.py | 43 +++++++-------- .../apidefs/gcc-ILP32/ns3_module_wimax.py | 53 +++++++++++-------- .../apidefs/gcc-LP64/ns3_module_simulator.py | 43 +++++++-------- .../apidefs/gcc-LP64/ns3_module_wimax.py | 53 +++++++++++-------- 4 files changed, 102 insertions(+), 90 deletions(-) diff --git a/bindings/python/apidefs/gcc-ILP32/ns3_module_simulator.py b/bindings/python/apidefs/gcc-ILP32/ns3_module_simulator.py index ba485efba..f8fe7a0a4 100644 --- a/bindings/python/apidefs/gcc-ILP32/ns3_module_simulator.py +++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_simulator.py @@ -5,7 +5,7 @@ def register_types(module): ## event-id.h: ns3::EventId [class] module.add_class('EventId') - ## high-precision-128.h: ns3::HighPrecision [class] + ## high-precision-double.h: ns3::HighPrecision [class] module.add_class('HighPrecision') ## simulator.h: ns3::Simulator [class] module.add_class('Simulator', is_singleton=True) @@ -243,51 +243,46 @@ def register_Ns3EventId_methods(root_module, cls): return def register_Ns3HighPrecision_methods(root_module, cls): - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(ns3::HighPrecision const & arg0) [copy constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(ns3::HighPrecision const & arg0) [copy constructor] cls.add_constructor([param('ns3::HighPrecision const &', 'arg0')]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(double value) [constructor] - cls.add_constructor([param('double', 'value')]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision() [constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision() [constructor] cls.add_constructor([]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(int64_t value, bool dummy) [constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(int64_t value, bool dummy) [constructor] cls.add_constructor([param('int64_t', 'value'), param('bool', 'dummy')]) - ## high-precision-128.h: bool ns3::HighPrecision::Add(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(double value) [constructor] + cls.add_constructor([param('double', 'value')]) + ## high-precision-double.h: void ns3::HighPrecision::Add(ns3::HighPrecision const & o) [member function] cls.add_method('Add', - 'bool', + 'void', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: int ns3::HighPrecision::Compare(ns3::HighPrecision const & o) const [member function] + ## high-precision-double.h: int ns3::HighPrecision::Compare(ns3::HighPrecision const & o) const [member function] cls.add_method('Compare', 'int', [param('ns3::HighPrecision const &', 'o')], is_const=True) - ## high-precision-128.h: bool ns3::HighPrecision::Div(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: void ns3::HighPrecision::Div(ns3::HighPrecision const & o) [member function] cls.add_method('Div', - 'bool', + 'void', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: double ns3::HighPrecision::GetDouble() const [member function] + ## high-precision-double.h: double ns3::HighPrecision::GetDouble() const [member function] cls.add_method('GetDouble', 'double', [], is_const=True) - ## high-precision-128.h: int64_t ns3::HighPrecision::GetInteger() const [member function] + ## high-precision-double.h: int64_t ns3::HighPrecision::GetInteger() const [member function] cls.add_method('GetInteger', 'int64_t', [], is_const=True) - ## high-precision-128.h: bool ns3::HighPrecision::Mul(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: void ns3::HighPrecision::Mul(ns3::HighPrecision const & o) [member function] cls.add_method('Mul', - 'bool', - [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: static void ns3::HighPrecision::PrintStats() [member function] - cls.add_method('PrintStats', 'void', - [], - is_static=True) - ## high-precision-128.h: bool ns3::HighPrecision::Sub(ns3::HighPrecision const & o) [member function] - cls.add_method('Sub', - 'bool', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: static ns3::HighPrecision ns3::HighPrecision::Zero() [member function] + ## high-precision-double.h: void ns3::HighPrecision::Sub(ns3::HighPrecision const & o) [member function] + cls.add_method('Sub', + 'void', + [param('ns3::HighPrecision const &', 'o')]) + ## high-precision-double.h: static ns3::HighPrecision ns3::HighPrecision::Zero() [member function] cls.add_method('Zero', 'ns3::HighPrecision', [], diff --git a/bindings/python/apidefs/gcc-ILP32/ns3_module_wimax.py b/bindings/python/apidefs/gcc-ILP32/ns3_module_wimax.py index 85d1fe94d..43afd7315 100644 --- a/bindings/python/apidefs/gcc-ILP32/ns3_module_wimax.py +++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_wimax.py @@ -2182,6 +2182,12 @@ def register_Ns3SimpleOfdmSendParam_methods(root_module, cls): cls.add_constructor([]) ## simple-ofdm-send-param.h: ns3::simpleOfdmSendParam::simpleOfdmSendParam(ns3::bvec const & fecBlock, uint32_t burstSize, bool isFirstBlock, uint64_t Frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPowerDbm) [constructor] cls.add_constructor([param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'Frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPowerDbm')]) + ## simple-ofdm-send-param.h: ns3::simpleOfdmSendParam::simpleOfdmSendParam(uint32_t burstSize, bool isFirstBlock, uint64_t Frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPowerDbm, ns3::Ptr burst) [constructor] + cls.add_constructor([param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'Frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPowerDbm'), param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-send-param.h: ns3::Ptr ns3::simpleOfdmSendParam::GetBurst() [member function] + cls.add_method('GetBurst', + 'ns3::Ptr< ns3::PacketBurst >', + []) ## simple-ofdm-send-param.h: uint32_t ns3::simpleOfdmSendParam::GetBurstSize() [member function] cls.add_method('GetBurstSize', 'uint32_t', @@ -4079,6 +4085,11 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'uint32_t', [param('ns3::Buffer::Iterator', 'start')], is_virtual=True) + ## wimax-mac-to-mac-header.h: ns3::TypeId ns3::WimaxMacToMacHeader::GetInstanceTypeId() const [member function] + cls.add_method('GetInstanceTypeId', + 'ns3::TypeId', + [], + is_const=True, is_virtual=True) ## wimax-mac-to-mac-header.h: uint32_t ns3::WimaxMacToMacHeader::GetSerializedSize() const [member function] cls.add_method('GetSerializedSize', 'uint32_t', @@ -4089,6 +4100,11 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'uint8_t', [], is_const=True) + ## wimax-mac-to-mac-header.h: static ns3::TypeId ns3::WimaxMacToMacHeader::GetTypeId() [member function] + cls.add_method('GetTypeId', + 'ns3::TypeId', + [], + is_static=True) ## wimax-mac-to-mac-header.h: void ns3::WimaxMacToMacHeader::Print(std::ostream & os) const [member function] cls.add_method('Print', 'void', @@ -4099,11 +4115,6 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'void', [param('ns3::Buffer::Iterator', 'start')], is_const=True, is_virtual=True) - ## wimax-mac-to-mac-header.h: ns3::TypeId ns3::WimaxMacToMacHeader::GetInstanceTypeId() const [member function] - cls.add_method('GetInstanceTypeId', - 'ns3::TypeId', - [], - is_const=True, visibility='private', is_virtual=True) return def register_Ns3WimaxPhy_methods(root_module, cls): @@ -5515,30 +5526,30 @@ def register_Ns3SimpleOfdmWimaxPhy_methods(root_module, cls): 'ns3::TypeId', [], is_static=True) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxBegin(ns3::bvec packet) [member function] + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxBegin(ns3::Ptr burst) [member function] cls.add_method('NotifyRxBegin', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxDrop(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxDrop(ns3::Ptr burst) [member function] cls.add_method('NotifyRxDrop', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxEnd(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxEnd(ns3::Ptr burst) [member function] cls.add_method('NotifyRxEnd', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxBegin(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxBegin(ns3::Ptr burst) [member function] cls.add_method('NotifyTxBegin', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxDrop(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxDrop(ns3::Ptr burst) [member function] cls.add_method('NotifyTxDrop', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxEnd(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxEnd(ns3::Ptr burst) [member function] cls.add_method('NotifyTxEnd', 'void', - [param('ns3::bvec', 'packet')]) + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::Send(ns3::Ptr burst, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction) [member function] cls.add_method('Send', 'void', @@ -5568,10 +5579,10 @@ def register_Ns3SimpleOfdmWimaxPhy_methods(root_module, cls): cls.add_method('SetTxPower', 'void', [param('double', 'txPower')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::StartReceive(ns3::bvec const & fecBlock, uint32_t burstSize, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower) [member function] + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::StartReceive(uint32_t burstSize, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower, ns3::Ptr burst) [member function] cls.add_method('StartReceive', 'void', - [param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPower')]) + [param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPower'), param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::DoDispose() [member function] cls.add_method('DoDispose', 'void', @@ -6285,10 +6296,10 @@ def register_Ns3SimpleOfdmWimaxChannel_methods(root_module, cls): cls.add_constructor([]) ## simple-ofdm-wimax-channel.h: ns3::SimpleOfdmWimaxChannel::SimpleOfdmWimaxChannel(ns3::SimpleOfdmWimaxChannel::PropModel propModel) [constructor] cls.add_constructor([param('ns3::SimpleOfdmWimaxChannel::PropModel', 'propModel')]) - ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::Send(ns3::Time BlockTime, ns3::bvec const & fecBlock, uint32_t burstSize, ns3::Ptr phy, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm) [member function] + ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::Send(ns3::Time BlockTime, uint32_t burstSize, ns3::Ptr phy, bool isFirstBlock, bool isLastBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm, ns3::Ptr burts) [member function] cls.add_method('Send', 'void', - [param('ns3::Time', 'BlockTime'), param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('ns3::Ptr< ns3::WimaxPhy >', 'phy'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'txPowerDbm')]) + [param('ns3::Time', 'BlockTime'), param('uint32_t', 'burstSize'), param('ns3::Ptr< ns3::WimaxPhy >', 'phy'), param('bool', 'isFirstBlock'), param('bool', 'isLastBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'txPowerDbm'), param('ns3::Ptr< ns3::PacketBurst >', 'burts')]) ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::SetPropagationModel(ns3::SimpleOfdmWimaxChannel::PropModel propModel) [member function] cls.add_method('SetPropagationModel', 'void', diff --git a/bindings/python/apidefs/gcc-LP64/ns3_module_simulator.py b/bindings/python/apidefs/gcc-LP64/ns3_module_simulator.py index ba485efba..f8fe7a0a4 100644 --- a/bindings/python/apidefs/gcc-LP64/ns3_module_simulator.py +++ b/bindings/python/apidefs/gcc-LP64/ns3_module_simulator.py @@ -5,7 +5,7 @@ def register_types(module): ## event-id.h: ns3::EventId [class] module.add_class('EventId') - ## high-precision-128.h: ns3::HighPrecision [class] + ## high-precision-double.h: ns3::HighPrecision [class] module.add_class('HighPrecision') ## simulator.h: ns3::Simulator [class] module.add_class('Simulator', is_singleton=True) @@ -243,51 +243,46 @@ def register_Ns3EventId_methods(root_module, cls): return def register_Ns3HighPrecision_methods(root_module, cls): - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(ns3::HighPrecision const & arg0) [copy constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(ns3::HighPrecision const & arg0) [copy constructor] cls.add_constructor([param('ns3::HighPrecision const &', 'arg0')]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(double value) [constructor] - cls.add_constructor([param('double', 'value')]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision() [constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision() [constructor] cls.add_constructor([]) - ## high-precision-128.h: ns3::HighPrecision::HighPrecision(int64_t value, bool dummy) [constructor] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(int64_t value, bool dummy) [constructor] cls.add_constructor([param('int64_t', 'value'), param('bool', 'dummy')]) - ## high-precision-128.h: bool ns3::HighPrecision::Add(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: ns3::HighPrecision::HighPrecision(double value) [constructor] + cls.add_constructor([param('double', 'value')]) + ## high-precision-double.h: void ns3::HighPrecision::Add(ns3::HighPrecision const & o) [member function] cls.add_method('Add', - 'bool', + 'void', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: int ns3::HighPrecision::Compare(ns3::HighPrecision const & o) const [member function] + ## high-precision-double.h: int ns3::HighPrecision::Compare(ns3::HighPrecision const & o) const [member function] cls.add_method('Compare', 'int', [param('ns3::HighPrecision const &', 'o')], is_const=True) - ## high-precision-128.h: bool ns3::HighPrecision::Div(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: void ns3::HighPrecision::Div(ns3::HighPrecision const & o) [member function] cls.add_method('Div', - 'bool', + 'void', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: double ns3::HighPrecision::GetDouble() const [member function] + ## high-precision-double.h: double ns3::HighPrecision::GetDouble() const [member function] cls.add_method('GetDouble', 'double', [], is_const=True) - ## high-precision-128.h: int64_t ns3::HighPrecision::GetInteger() const [member function] + ## high-precision-double.h: int64_t ns3::HighPrecision::GetInteger() const [member function] cls.add_method('GetInteger', 'int64_t', [], is_const=True) - ## high-precision-128.h: bool ns3::HighPrecision::Mul(ns3::HighPrecision const & o) [member function] + ## high-precision-double.h: void ns3::HighPrecision::Mul(ns3::HighPrecision const & o) [member function] cls.add_method('Mul', - 'bool', - [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: static void ns3::HighPrecision::PrintStats() [member function] - cls.add_method('PrintStats', 'void', - [], - is_static=True) - ## high-precision-128.h: bool ns3::HighPrecision::Sub(ns3::HighPrecision const & o) [member function] - cls.add_method('Sub', - 'bool', [param('ns3::HighPrecision const &', 'o')]) - ## high-precision-128.h: static ns3::HighPrecision ns3::HighPrecision::Zero() [member function] + ## high-precision-double.h: void ns3::HighPrecision::Sub(ns3::HighPrecision const & o) [member function] + cls.add_method('Sub', + 'void', + [param('ns3::HighPrecision const &', 'o')]) + ## high-precision-double.h: static ns3::HighPrecision ns3::HighPrecision::Zero() [member function] cls.add_method('Zero', 'ns3::HighPrecision', [], diff --git a/bindings/python/apidefs/gcc-LP64/ns3_module_wimax.py b/bindings/python/apidefs/gcc-LP64/ns3_module_wimax.py index 21ee42217..d909221b1 100644 --- a/bindings/python/apidefs/gcc-LP64/ns3_module_wimax.py +++ b/bindings/python/apidefs/gcc-LP64/ns3_module_wimax.py @@ -2182,6 +2182,12 @@ def register_Ns3SimpleOfdmSendParam_methods(root_module, cls): cls.add_constructor([]) ## simple-ofdm-send-param.h: ns3::simpleOfdmSendParam::simpleOfdmSendParam(ns3::bvec const & fecBlock, uint32_t burstSize, bool isFirstBlock, uint64_t Frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPowerDbm) [constructor] cls.add_constructor([param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'Frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPowerDbm')]) + ## simple-ofdm-send-param.h: ns3::simpleOfdmSendParam::simpleOfdmSendParam(uint32_t burstSize, bool isFirstBlock, uint64_t Frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPowerDbm, ns3::Ptr burst) [constructor] + cls.add_constructor([param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'Frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPowerDbm'), param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-send-param.h: ns3::Ptr ns3::simpleOfdmSendParam::GetBurst() [member function] + cls.add_method('GetBurst', + 'ns3::Ptr< ns3::PacketBurst >', + []) ## simple-ofdm-send-param.h: uint32_t ns3::simpleOfdmSendParam::GetBurstSize() [member function] cls.add_method('GetBurstSize', 'uint32_t', @@ -4079,6 +4085,11 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'uint32_t', [param('ns3::Buffer::Iterator', 'start')], is_virtual=True) + ## wimax-mac-to-mac-header.h: ns3::TypeId ns3::WimaxMacToMacHeader::GetInstanceTypeId() const [member function] + cls.add_method('GetInstanceTypeId', + 'ns3::TypeId', + [], + is_const=True, is_virtual=True) ## wimax-mac-to-mac-header.h: uint32_t ns3::WimaxMacToMacHeader::GetSerializedSize() const [member function] cls.add_method('GetSerializedSize', 'uint32_t', @@ -4089,6 +4100,11 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'uint8_t', [], is_const=True) + ## wimax-mac-to-mac-header.h: static ns3::TypeId ns3::WimaxMacToMacHeader::GetTypeId() [member function] + cls.add_method('GetTypeId', + 'ns3::TypeId', + [], + is_static=True) ## wimax-mac-to-mac-header.h: void ns3::WimaxMacToMacHeader::Print(std::ostream & os) const [member function] cls.add_method('Print', 'void', @@ -4099,11 +4115,6 @@ def register_Ns3WimaxMacToMacHeader_methods(root_module, cls): 'void', [param('ns3::Buffer::Iterator', 'start')], is_const=True, is_virtual=True) - ## wimax-mac-to-mac-header.h: ns3::TypeId ns3::WimaxMacToMacHeader::GetInstanceTypeId() const [member function] - cls.add_method('GetInstanceTypeId', - 'ns3::TypeId', - [], - is_const=True, visibility='private', is_virtual=True) return def register_Ns3WimaxPhy_methods(root_module, cls): @@ -5515,30 +5526,30 @@ def register_Ns3SimpleOfdmWimaxPhy_methods(root_module, cls): 'ns3::TypeId', [], is_static=True) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxBegin(ns3::bvec packet) [member function] + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxBegin(ns3::Ptr burst) [member function] cls.add_method('NotifyRxBegin', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxDrop(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxDrop(ns3::Ptr burst) [member function] cls.add_method('NotifyRxDrop', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxEnd(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyRxEnd(ns3::Ptr burst) [member function] cls.add_method('NotifyRxEnd', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxBegin(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxBegin(ns3::Ptr burst) [member function] cls.add_method('NotifyTxBegin', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxDrop(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxDrop(ns3::Ptr burst) [member function] cls.add_method('NotifyTxDrop', 'void', - [param('ns3::bvec', 'packet')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxEnd(ns3::bvec packet) [member function] + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::NotifyTxEnd(ns3::Ptr burst) [member function] cls.add_method('NotifyTxEnd', 'void', - [param('ns3::bvec', 'packet')]) + [param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::Send(ns3::Ptr burst, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction) [member function] cls.add_method('Send', 'void', @@ -5568,10 +5579,10 @@ def register_Ns3SimpleOfdmWimaxPhy_methods(root_module, cls): cls.add_method('SetTxPower', 'void', [param('double', 'txPower')]) - ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::StartReceive(ns3::bvec const & fecBlock, uint32_t burstSize, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower) [member function] + ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::StartReceive(uint32_t burstSize, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower, ns3::Ptr burst) [member function] cls.add_method('StartReceive', 'void', - [param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPower')]) + [param('uint32_t', 'burstSize'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'rxPower'), param('ns3::Ptr< ns3::PacketBurst >', 'burst')]) ## simple-ofdm-wimax-phy.h: void ns3::SimpleOfdmWimaxPhy::DoDispose() [member function] cls.add_method('DoDispose', 'void', @@ -6285,10 +6296,10 @@ def register_Ns3SimpleOfdmWimaxChannel_methods(root_module, cls): cls.add_constructor([]) ## simple-ofdm-wimax-channel.h: ns3::SimpleOfdmWimaxChannel::SimpleOfdmWimaxChannel(ns3::SimpleOfdmWimaxChannel::PropModel propModel) [constructor] cls.add_constructor([param('ns3::SimpleOfdmWimaxChannel::PropModel', 'propModel')]) - ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::Send(ns3::Time BlockTime, ns3::bvec const & fecBlock, uint32_t burstSize, ns3::Ptr phy, bool isFirstBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm) [member function] + ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::Send(ns3::Time BlockTime, uint32_t burstSize, ns3::Ptr phy, bool isFirstBlock, bool isLastBlock, uint64_t frequency, ns3::WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm, ns3::Ptr burts) [member function] cls.add_method('Send', 'void', - [param('ns3::Time', 'BlockTime'), param('ns3::bvec const &', 'fecBlock'), param('uint32_t', 'burstSize'), param('ns3::Ptr< ns3::WimaxPhy >', 'phy'), param('bool', 'isFirstBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'txPowerDbm')]) + [param('ns3::Time', 'BlockTime'), param('uint32_t', 'burstSize'), param('ns3::Ptr< ns3::WimaxPhy >', 'phy'), param('bool', 'isFirstBlock'), param('bool', 'isLastBlock'), param('uint64_t', 'frequency'), param('ns3::WimaxPhy::ModulationType', 'modulationType'), param('uint8_t', 'direction'), param('double', 'txPowerDbm'), param('ns3::Ptr< ns3::PacketBurst >', 'burts')]) ## simple-ofdm-wimax-channel.h: void ns3::SimpleOfdmWimaxChannel::SetPropagationModel(ns3::SimpleOfdmWimaxChannel::PropModel propModel) [member function] cls.add_method('SetPropagationModel', 'void', From c7d137102c1417d930eed49106e45ad5b9d110af Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 6 Jul 2010 17:15:00 +0200 Subject: [PATCH 4/7] Backed out changeset e27b81575ebe --- .../hwmp-reactive-regression-test-1-1.pcap | Bin 20603 -> 20603 bytes .../hwmp-reactive-regression-test-3-1.pcap | Bin 22322 -> 22322 bytes .../hwmp-reactive-regression-test-5-1.pcap | Bin 14761 -> 14761 bytes ...hwmp-target-flags-regression-test-0-1.pcap | Bin 10436 -> 10436 bytes .../flame/test/flame-regression-test-0-1.pcap | Bin 4996 -> 4996 bytes .../flame/test/flame-regression-test-2-1.pcap | Bin 5274 -> 5274 bytes .../test/aodv-chain-regression-test-0-0.pcap | Bin 6938 -> 6938 bytes .../test/aodv-chain-regression-test-1-0.pcap | Bin 9076 -> 9076 bytes .../test/aodv-chain-regression-test-2-0.pcap | Bin 7450 -> 7450 bytes .../test/aodv-chain-regression-test-3-0.pcap | Bin 7292 -> 7292 bytes .../test/aodv-chain-regression-test-4-0.pcap | Bin 5050 -> 5050 bytes src/routing/aodv/test/bug-606-test-0-0.pcap | Bin 5456 -> 5456 bytes src/routing/aodv/test/bug-606-test-1-0.pcap | Bin 6368 -> 6368 bytes src/routing/aodv/test/bug-606-test-2-0.pcap | Bin 4790 -> 4790 bytes src/routing/aodv/test/tcp-chain-test-0-0.pcap | Bin 2142 -> 2142 bytes src/routing/aodv/test/tcp-chain-test-9-0.pcap | Bin 1972 -> 1972 bytes src/routing/aodv/test/udp-chain-test-0-0.pcap | Bin 35532 -> 35532 bytes src/routing/aodv/test/udp-chain-test-9-0.pcap | Bin 19114 -> 19114 bytes src/routing/olsr/test/bug780-0-0.pcap | Bin 93516 -> 93516 bytes src/routing/olsr/test/bug780-1-0.pcap | Bin 91884 -> 91884 bytes src/simulator/time.cc | 16 ++++++---------- 21 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/devices/mesh/dot11s/test/hwmp-reactive-regression-test-1-1.pcap b/src/devices/mesh/dot11s/test/hwmp-reactive-regression-test-1-1.pcap index 1fd80de31e87358de22ac1b852abb9efa9ab30dc..fbdd90d961bf9b52d4d02f7a1a79dded84962f0c 100644 GIT binary patch delta 1227 zcmZuwZD?C%6u$5KCb@}ALm^vkZfp z8*^wUI9m7hfc>GPiLPd~GOC&Ehac@k6r4ym{UI_~3yLr+Y$_s*RnNVdwS)b5x#v9Z zIq!MSInTXWVmC`{=KMN7!Z93Cad};lpRJkgks|vMLy-Y?3JE2KjmZey#*2jp z54!?Y9pFnfa5fPL^wdexqY@olN~k!e=D8HQBV!tMu>szvxL|M4i}|=mC{YQ+IRj^6 z7H^CGS5mx0@IM6SG>bp3u6~9utJJTFFSI;gA9Gu8kH|3NdET$N?%sHjziq6p5_rs9 z;by4#E1qXhA+77|9JcENd^oYXfXFsFl%hD6k#SA8_?AZZntBv+lZ1;21N#~*ex>P- ztchj`Pc|Cx8K=dc@5q?KX$ASW3ya`g|^KshD1_lb0{Qtv3auBf?lb9lAM?`;zrMen9l5!|~n(7NI91cnaT6W>YB^8kc)GB49kT0GnUx$x|_k}qZFjlCFi6K~Sj8F_Qo z3f(vsly*~9=lDnQ@;zZRWw(b;oxCgj%^P=vMR~l&PGIqVn>~#kIh}RD&e?1mu97{0 zTV!9xo(F7EnW*u4wsf19jChA7_Lp34^g|u#u*HRP?ZLxPI&JLFqvcADP0}2@`6;5Q+y5| zZ5lfp&1$9aJL7vMaiYh>$3;^dBw>LL^0K0dyWVH1^H=#h5!Hn delta 1226 zcmZuwU2GIp6rOwU?oJnWkyzN-+1X)cwtq{MW|v);cC{?qHNXRzg06q52~?kq%C?Cn z6*0uBF{G8BehDN>a5vH){*sa<`k=NYF+4z`6d#P?p>3i*P>qO*F(DPt%wjDG4>xnp zch9-!JLi0Jr_An@*~AxX`2a^>NX7NFd49fTwubWTNA!le*$G%m1REM<{1!^F1@el# z--}DzO&nL!;-XK&R3eO$K>8~9j|hb&^koc; zM{M34{;#BXhv2&eXEd8Xr7nMlFRIk9iEp$lk4N0rTSGF;XqFc>*L^dZ=M`gl75@%% ziJPI~uV|LNh@`HwD!TM;-fJx{AW|`hQW%F*GH&WNFT~vIDQg99kZ{#9(7(>+HyZ9s zI@u`Ug_r@KaZ3F8nT%_7ire4kr)0Okn}#helRckNoS6!JM0OkOH*Im7>_1ek`ja^; z#3cWJCqFl)L{K=sfoxNX1+lj&&vZ;Q>FiZ}OZFpJ-Mo`+MNe}Nf7a(RI?(24=P}=$ z=Ue3^ioGch>qEX}H`|Cxi_VL6*tNbMTjU_-TDCA1R$OOO$i;WF@5o*QdZqeR{H)9; z2QZmXU5Ok_I26846#cXB2c#VBI(KwNMJl<0{f?fb&N^@)X^USzAW^hx><#=%-jjoY z;YT$t51}_>V&6uaD?^yeMETw!{6k1x$`*x>+zjqJL_sPI{uvQE6hI}eiI3^)jJz>z zuex5&Z!&3yDRF^knUP_V)%jZ)ngBWMfrG*9mo7*CH4|_WpuU)rA&!!!z|e+ zu}Jm|Uf)y_qo3Azy;8o%OGdQK7H^eZZuCDLY%7WBO6|e-ptP6x_uQSiBkyv%M;xQ= zIr6^TZu3z=S7F&h>=y}k^iM;4fbsISEsWoUlI>xvjP15L`e*fy0UQ-e;|9h z-oRK#TI?IENocXd7G2|xgcLXC;nR-fYWf}AY>OEAmAHcP;~qY68doe6YR(qVopDoq z4xh+bJRdWwW4YUmzczxS1ruN9O|hSZNrLrxDdfrsk_2m=rg)i1IK>=z|2;x)cc$3| mOmy~$OGJy3yw2@INEGs7yhhGN+Hi!B?L>)Ustbi9fqwyqv4RZ% diff --git a/src/devices/mesh/dot11s/test/hwmp-reactive-regression-test-3-1.pcap b/src/devices/mesh/dot11s/test/hwmp-reactive-regression-test-3-1.pcap index 84ece725f4bf48d5763bb925bd427e9e8469da63..28c26096e8623a185df380d3851a1df16f947a03 100644 GIT binary patch delta 1102 zcmYk4U1(cn7{|~1ygA8EO}fs>dX7zUPSbp}w&}+TGp1S6tWDQ$%}EL!69e9OA&y}- zP!tt6SGx+*YW;Uq=9o6!V66Kn3!B1VZ5fC+GPLT=M1>&=yV!+#;f?b>Z`*Yjhx5G8 z$Nzbr_x)YF!meFmi#e0p7>-6Qylf`vpko?nk9u%h9LGo=bt_BP-B`2?JV<%)w$;sC zxN413YKwFR8(VNB-?tTrX-#G+!29?h~#I1(+?3YKF5md7u#68+pH68-%1u!8Bdj$nry zZ#Ea`YS>xL?X2dGpg3s3(_+)zh%+9Yjlv$Xs;63tjQ*L!bep_O`l^CPVdi^%h_u@D zO+`k;ie%2q$g%xCR7K?Pc^O%bYwXLa)waqh!Q|uAb|z`UF)bYG?4~7p^o~oN-CC_n zQFe-fcH&#rz*Aio?e&P^b#(4=;a*Fq`dZhG8kWHE)YEt|sKHKku?cY+rKJ;iFXaG{ zq(8<{?DwnHhK}>>~(d$~^a>tWuq-Em#nqx=Amldm3nU5+A26ywGdYy~$59eo9Uu zn6dC@ug!Y!Y_?1UB(ks4+^jPn=cm1B59=uGIl#9ITTDq)r=1M`(r24ZW--!NW{0uT z7hooS74`}W{Q-KvBH9TW#A{CW7x+v?D)9T_KQd^-pR@V$yp-`cvyPqfqA+CQV$P-? zm35|6kGOB;Q|5qSA~9go1-1^AiZ2FS{GkXr;C?MaKae0pmld;I!do5Pdx&r1p}HNl z#}N5%-(!eK!A(p`n~12YQ#Xcx_m}DUi-H?n3NDCcI9n4cxjzCwR$!`qx}!Ty-scb delta 1102 zcmYk4T}%{L6vyYD%j`OK*RL9wk=@y0*$)wx4@m?U++~GDs4%;vXcIT_!IwtcbZcVL zHm0@GN}HHf@$W~X(FmAmKq+xsoAd!NP1>j02*!t+w2c~Ld@-rM_@cdY0r6on=bn%M zIp^NrjR|&Rf=#9aRL!tIV&TI;oOU{r6 zrh^8|YB%1A#;IT~>T8e8#cBR*GjJptXTz9@`dJVDj^^lorAYMgiy;L=2_0sg3!ksg z&_u{t&E>47hLP>E;I6Xiudp*7U5LQ$wu+~#vW#8~W2i>nCH*{t3SsuPc@eI*>Gu&C z5i628DkF!sdr=gT=c6(*6VuquqE$1;sfo$QSy3OSLC3VPufCC{=*>G$*Eee35=Gf4 z2HJ=}R0C@pEb4TN;dRt+Ey2U8VDUi1&E>2KU$?HqZc~HZ+Q0_Ish_3>aJbb0B2JHw zAlu<%2hg>}=HCu_Fub{3n;rBlJbHi|xVI(74}RxCLwA{%i+8vv!r*j_EhIC}M?%->LEvBTxIVXefIlt884Eoyh>?7Q2_cIg! z2zv&Z4nKV}BH9TW#A_BhG8`jPfj<@hzODd#X`4@vN*T8^>%e6XGTi};rER*aEHI_I z#eFMhnFB@u&7C$~VGB^HxYSv~Ux|0!5-?x`QV^@s$3BI1pem7H2e-`m?UFOt(ULLTXvKxG@MZ~RK&azqX|4#vf?F0 zfYMMWF`oH_^N^wANXTMOLT>Yx{ePaORTEq?zGS0+W$<;kkqXFzFrUpc##3L zhcsMJd*}+Dt1+6wXEjS1bXRA^PYD4<({FY=Dd0w2$J=U4%yZ^LIK4GdqF*SbG;f~O zdy?DSS*RUl)P?m<6HVGj>T)PD9pHwUhCw!Y5iiYpxni!;UmjIq4K;d3jLcQ?no%0V zkZ#jql=K+M*yMZ*Im4#?DDq!HpBZCsF5|myV9K;;1RG|IbbK>yvF(mmg00mfVfYTzdpB61JFnBze0YPey60 zfKrvc%cI4*!kpaJ7cqJt-F{VmeRTJ)CJU kon3ni#Qr?PbcY5*lboL&1s>(BcOKmiZtdC*#zc49KYG&6SO5S3 delta 694 zcmYL_O-K}B7{}*%-(ANEYj<09oz>l$(N@uQwz@B9Dpd_T|3$jrz>laIv- zl|dc-z7!qCE#IJWrc#o6CGn=NsQBeeunGms!3O1lvTa9kmx>Gi1g&DqAE9e_=}+^! zehL0)NM<7QtKf{T;dsDguL4do|F&1cPff$efXR1P3wON4q1yjUdC0-E@}WVJ21Jno zbOcn~4yFiL3P$J#z68_Mj-Ki?{~VLBW`yv!*2|hDOgC!Ss5beWU@?Pzq^6!|3&l3o z9cS^W?DV#CwOK~pSm`p*qJE-oo5EurVHl4Nve7$OH5wFUvZ}N@_SC7U(GpyptP(Zr z=`u2!Mg1sh5vs(d;71tJElOcc{66#=5w?C0KQtXT4U>lP&WKPH-wlf=AG;;k(le(A zO(553@%zsmV+eZFRkk5vL9Vmsn=X~d_J{*)kB!qYlb@QEorS%QUB%m&#ariOch{56 z^|W0;_6l!~N{7z3nEX619oOLr&kp|y@37JCvOU~-vD7?5i`Z(yu$@mnq0-6i?1451DQwuUJ6s%( l8g|9O0ScqDLxj385k)MS4#h0S(?+&mz5y|BXOY*`r&7<;9vG&2Ax8w`~I delta 43 qcmX>ScqDLxj386J)MS4#h0S(?+&mz5y|BXOY*`r&7<;9vG&2Aw)(nyW diff --git a/src/devices/mesh/flame/test/flame-regression-test-0-1.pcap b/src/devices/mesh/flame/test/flame-regression-test-0-1.pcap index 20872c09524a8555cddb4c5dbd27cd4481dbcc3d..cf37592f3178d50590ef7c358c44e850b063e8cf 100644 GIT binary patch delta 659 zcmYk3PiPZC6vp?>oBfylm&8IE+I5?QwA4gUsMb>yY6!R@f`|-4y+}L+LVM|9PeO{- zgBV_`JqT&Af`=mb2lOT$j2^ux6!BJ%qJn}ab!JM%(>}hL@AtlMwmaFKygd$SFK)q7 zZ@GnY%%JbZk_Cogd}O`-W%|TyszL*wbA!G{B~zU^)PoF1ErZTkC0i*SIiCy@O4&3H zY&DNkJ+f(?O|$p*F6Rt$tUY3i4R&7Y6Z8xlm^!;`CP}kY<}GN_H6BBs`aHv~r!(2= z^s+D6g@lADaQQl@M1j&Tu7J^&-!@fvnSPi8uF_d6#+NHV1D?<=OW@`WP~9}=_f628 zDO=!y5Op(@{$Dh(Gjt-<&6F}PXGOT=2%O8KBG5aB;kUDOR zf7ZD6K5_-_+~NPcJ9oL>-pmQSGG^)RrsT}ht6YZ7aZ7DCmC~2W2z9&`c4JHXzj++) z(N8afH?-hqxOLy&({X##*4%0!@WGU;xU>;)^bWcd-Ek#;{2B@H8H&x;o!h zD6mv>HD@B?>}icogk|{y55o*CL>Zi-FHsCb^70vec$`!5Xd}o88I&-^5~!cAEx-mYNC$HF%0rNrhBI1cgELBIIDPk~m;$gt>Gbjm3Ttz1^~(Wp$*Yz%us z&%3A|3%bk3*gLVsIl+XpO`OICJFWC#dWsEf=C;^Ok!n=pEtsOKJcVVt&oi9!O(vmF zF9eF6FO#$-cCLd?6l(qKJXka8J3|#-qD@;ui%vQzzL*DE;bpqzNL;-Ex|`wrz6pji zDkScW&@@Bk|3xbzLlL8Crj_$*)`W98iIWLx0=>;~e6_&McCPL$E%N`i54aK@(5#!{ zpG9uGk6noyclbZ=#u7K%k9!g??s3d^TXAai(#vpa(9zp%tt=~LfM)#`&ZUm=fA=}u zqn~~TeQF08K3o;sI(}FahFc9Ku8q2yOTCbzx6h?8DN{d`u$wAT3T>)KO`NE@Cf}n- z;?8l`aE4>f*2n2cR8l{10uE3+&fpk*jZ=6{ev;w)C!UT+y@X?R-7|oGA|X$edfqw!;H2Jnx?B$5`F`K|xa+O;*6PqnfR5q5 zwap$*JAyh<%>^OEc?w`2Qxxp4at-=-aS9y$KrhQuc5d?6h#KdX~oB z6fcI{g0|cN+@Ow%p-;0a#f_Vg_tm-c?=n#AHp$lpiz|?~rfYft2k4)U@lO%C>XCxM z=?IxZOI<1>Q(vsUWapepyaB$wEvYPPT3XNjJCfPZH@JOQ<}3|-iQD%ivzxww-vmL1 z=f)LNuBEzr6jR>8nvSsMsy-N4&Uv&o4@#VG>KDfkCRl{zzofm zGn{$ub5g-3)wg_3I$SYW8Toua*Dt*AnfhEYut4oy8UC0GneyybcEj9xt12-$6teMP L)xa5Asy6-u9Bhz+ delta 600 zcmXAlF=!M)6o&Who1M9x-Mib3hnF+1XA#6pa~vp93l$Qsxo8jzkFk(|5YR#kQOH7E zxirSc_|&km5ffrzVK9=yPOuOxBw!H)t5{gsSXhafeQAcr|NifPKeN(WX+2(WdqC&$ z=+b%@CtQa*QQZT_ac)omvp9ziZHN2HHZ4KwZV8ISuqrG{I&?`kY05SDQaLmoHR-cE zhF^FdrZRTmGM&R&n5WnF?NL=E?%k3-*RV@P7e&_}*N)S-VSV}-G-yk7aS-gcaIJcc zM!Xbnh1`NRybKnoBNMnn(=x@?hfwrYh4bGcP~tU7D}&`nP_(9bmBA?eR|)>DAXhzG zGB^<-Q)sE%F*3Dd^~}x%HRWgc>8YSt)RnNFT( zygnkC@+>ueSTglJFgQpgUo7;wBa*2*p@BvE8s_ecSM)n<(4ahnZ&no>r8VxXDK?H) z4E&<|l^oZO`y8+A_Fl{9_Y;hDULOM;aF2-ZzL$Q;FZV6zO19W&D-k;x9C U5^NxGE3wIb0t%aFvEPyg0OnH@s{jB1 delta 66 zcmez3_Qh?(Z6?P3lkYHY=9#>QOM;aF2-Z$M$Q;GEf3pmW9W&EIk;x9C U5^NxGOR>p*0t%aFvEPyg0OeK_qyPW_ diff --git a/src/routing/aodv/test/aodv-chain-regression-test-2-0.pcap b/src/routing/aodv/test/aodv-chain-regression-test-2-0.pcap index 27198c7ba77b2cc2c79b8a61f3a035cd306a510c..a0ea904ec8afc28fab3cdb0f9f0fbf9de8a94f7e 100644 GIT binary patch delta 132 zcmbPbHOp#45))H7`(!;18ODUkjZ9Ho2NDn@i3$S%>>eTS diff --git a/src/routing/aodv/test/aodv-chain-regression-test-3-0.pcap b/src/routing/aodv/test/aodv-chain-regression-test-3-0.pcap index 1565f4808f59920b155a1de4bbc6d2b5dd8e046d..4232ccc17e2611a0fe83bd0759f8ca88475aa216 100644 GIT binary patch delta 175 zcmexk@yBAq8^&7`-}*CJPqt+|!F7NE3eHWwC?L66gGrW=@xWv^=J$*THk+}CF)}?8 znH<0@!(=5k`2n}&S&&VVi^-e?s7_+?1VI)iK~|tz zg~?e0X^e_MQ)L;~ZGJDXlo_gojTxv3s^p3YM2RFTNN~>N_X3KWt3*?n87(*8mzc{8 E06C2^h5!Hn diff --git a/src/routing/aodv/test/aodv-chain-regression-test-4-0.pcap b/src/routing/aodv/test/aodv-chain-regression-test-4-0.pcap index 798c83e35a7e331f56a5fd3e39fb595cd600b6e8..6fd2c4cdbc2f4ae16d7d3654ab58e00a3bd264f7 100644 GIT binary patch delta 61 zcmdm`zDs?>Tt>zNljkv(F_p7VPGFOm#LU8(z`?)}!T`jRFS1Kc4q>unJg~WsDT#?O RZt_PKS;k45`B_)<0RTSY5#j&< delta 61 zcmdm`zDs?>Tt>$Iljkv(F_p1TPGFOm#LU7O&%wYD!T`jRFS1Kc4q>un+`qYxDT#?O RcJfCSS;mQ*`B_)<0RTQU5!?U( diff --git a/src/routing/aodv/test/bug-606-test-0-0.pcap b/src/routing/aodv/test/bug-606-test-0-0.pcap index b5ba6ac1fb0fdfd33d336cc36774367da4df33c7..d0665813408601abe706dae035e122514315f52f 100644 GIT binary patch delta 67 zcmV-J0KEUuD$pvha{>XtlXL=h0l$;$0#5?Z2$OyS90DB)lQ0e-vw8z+2m-7Klkf^0 Z0#FH(1R#?n3@!q436rb=AhUD~+z0`|6#)PM delta 67 zcmV-J0KEUuD$pvha{>XslXL=h0lt�#5?Y2$OyS90D8(lQ0e-vw8z+2m-4Jlkf^0 Z0#6B&1R#?n3@!q336rb=AhUD~+z0@^6#4)F diff --git a/src/routing/aodv/test/bug-606-test-1-0.pcap b/src/routing/aodv/test/bug-606-test-1-0.pcap index efb54fee7d6126f3e62530eac9c1411bd832a5d1..9554a19d82d0fea979b4e2e55d1fa18206d2e625 100644 GIT binary patch delta 138 zcmaE0_`q;O4>PpEthE%?_>cc8KywK$qTp?HveJMU}t*9Jh_fZa>PpEthE{?_>cc8KwZf$qTp?HveJMU}t*DJh_fZazNljkwM7dpTI1^YP|7#x6XhshV&B{%P2s^DZ?Gue$IljkwM7uwGN1^YM{7#x6XhshV&B{%P2s^DZ?J=u^)meGH+KTkRv E0J$j+(*OVf diff --git a/src/routing/aodv/test/tcp-chain-test-0-0.pcap b/src/routing/aodv/test/tcp-chain-test-0-0.pcap index d700a47ce2bbc6f89f22478145ed8af86eccc1f8..4c732ee2e66cfcffe8cd3891b0a5da90ba1672db 100644 GIT binary patch delta 42 zcmV+_0M-BA5Z(~5!U6(R9+Q3q907%s;R0gJf1snq7ACsH}8Ik`7vxEcM1WvvW Ao&W#< delta 42 zcmV+_0M-BA5Z(~5!U6(Q9+Q3q907!r;R0gzmFdh>rVVQt89!`Z%V^EP{Hl;?@)RQH*0YDurfcG%rg0+uKea{ z{C_x^FWhAVbGAtS;bc6pd84u{7vqM_=XGVdm>2Bk1xxW+JQ87a*!zmFdh>rVVQt8Q*VS%V^EP{IZZ~@)RQH*0YDurlAD%rg0+uKea{ z{C_x^&);PObGAtS;bh#ud84u{7vuWP=XGVdnCI{21xxW+JQ88F-~7?XlbcyToE0n< r69LpKzmOfwsY(KJ_+N8^IWuyAoc|^~V9vHOAm@D@ADDBc;Rh!GCn!Mb diff --git a/src/routing/aodv/test/udp-chain-test-9-0.pcap b/src/routing/aodv/test/udp-chain-test-9-0.pcap index 901d3a4e901a4a23cd867a32b4d50203f929c946..3afa2b87f270991edc963e6f8dde37292bd1c5cd 100644 GIT binary patch delta 64 zcmZ2Am2uTn#tk;ij0+~)GDmSGFaQA~5O3JLkomb9^TQzK$p=lPnU4fBPhQU`Kly}~ R9`iFGJC{j*vxN2}c>sDY6Vm_y delta 64 zcmZ2Am2uTn#tk;ijPobkGDmU6GXMc25U=07komb9^MfGf$p=lPnGXjuPhQU`Kly}~ R9`jQmJC{j*vxN2}c>sA`6U_hs diff --git a/src/routing/olsr/test/bug780-0-0.pcap b/src/routing/olsr/test/bug780-0-0.pcap index ee570e8311c0acec3259955da2969fee2308b966..920b2ff823eefda0282d265a9ee8b2ac3ca48c9e 100644 GIT binary patch delta 32 qcmV+*0N?-2+6Bzo1+d7AlVp+_0dA9jk|mP}jAoN!kQ%dyjKtsu#1G5> delta 36 ucmV+<0Nek}+6Bzo1+d7Ale8Zi0dA8q%NUby91W8QjAoM}iypI#jKJVFzz}f& diff --git a/src/routing/olsr/test/bug780-1-0.pcap b/src/routing/olsr/test/bug780-1-0.pcap index 4b98541515df4904111480f2345db3e2efc6deb1..eee30b7828ded55fd396ae2cf25def0785e70811 100644 GIT binary patch delta 40 ycmV+@0N4NQ%?0eu1+c7}lT@A}lg^uFlf::TimeUnit (const std::string& s) iss.str (s); double v; iss >> v; - m_data = HighPrecision (v); - m_data.Mul (HighPrecision (TimeStepPrecision::g_tsPrecFactor, false)); + m_data = HighPrecision (v * TimeStepPrecision::g_tsPrecFactor); } double TimeUnit<1>::GetSeconds (void) const { - HighPrecision tmp = GetHighPrecision (); - HighPrecision factor = HighPrecision (TimeStepPrecision::g_tsPrecFactor, false); - tmp.Div (factor); - return tmp.GetDouble (); + double timeValue = GetHighPrecision ().GetDouble (); + return timeValue / TimeStepPrecision::g_tsPrecFactor; } int64_t @@ -288,10 +285,9 @@ std::istream& operator>> (std::istream& is, Time & time) Time Seconds (double seconds) { - HighPrecision tmp = HighPrecision (seconds); - HighPrecision factor = HighPrecision (TimeStepPrecision::g_tsPrecFactor, false); - tmp.Mul (factor); - return Time (tmp); + double d_sec = seconds * TimeStepPrecision::g_tsPrecFactor; + return Time (HighPrecision (d_sec)); + // return Time (HighPrecision ((int64_t)d_sec, false)); } uint64_t From 33cd14075c02f082ec873ba8878fc776dc4809b0 Mon Sep 17 00:00:00 2001 From: Josh Pelkey Date: Tue, 6 Jul 2010 20:27:51 -0400 Subject: [PATCH 5/7] fix gcc warning --- src/helper/ns2-mobility-helper.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/helper/ns2-mobility-helper.cc b/src/helper/ns2-mobility-helper.cc index 68f0bc31c..556062deb 100644 --- a/src/helper/ns2-mobility-helper.cc +++ b/src/helper/ns2-mobility-helper.cc @@ -483,20 +483,22 @@ GetNodeIdFromToken (string str) int GetNodeIdInt (ParseResult pr) { + int result = -1; switch (pr.tokens.size ()) { case 4: // line like $node_(0) set X_ 11 - return pr.ivals[0]; + result = pr.ivals[0]; break; case 7: // line like $ns_ at 4 "$node_(0) set X_ 28" - return pr.ivals[3]; + result = pr.ivals[3]; break; case 8: // line like $ns_ at 1 "$node_(0) setdest 2 3 4" - return pr.ivals[3]; + result = pr.ivals[3]; break; default: - return -1; + result = -1; } + return result; } // Get node id number in string format From 41c90baf3040ee34ec47e6c6d4d2cd3ee142e84a Mon Sep 17 00:00:00 2001 From: Hajime Tazaki Date: Wed, 7 Jul 2010 23:58:40 +0900 Subject: [PATCH 6/7] update Bug 932: source address selection in IPv4 HDRINCL --- src/internet-stack/ipv4-raw-socket-impl.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/internet-stack/ipv4-raw-socket-impl.cc b/src/internet-stack/ipv4-raw-socket-impl.cc index 946e05653..e81e3f9e4 100644 --- a/src/internet-stack/ipv4-raw-socket-impl.cc +++ b/src/internet-stack/ipv4-raw-socket-impl.cc @@ -185,6 +185,7 @@ Ipv4RawSocketImpl::SendTo (Ptr p, uint32_t flags, InetSocketAddress ad = InetSocketAddress::ConvertFrom (toAddress); Ptr ipv4 = m_node->GetObject (); Ipv4Address dst = ad.GetIpv4 (); + Ipv4Address src = m_src; if (ipv4->GetRoutingProtocol ()) { Ipv4Header header; @@ -197,16 +198,17 @@ Ipv4RawSocketImpl::SendTo (Ptr p, uint32_t flags, { p->RemoveHeader (header); dst = header.GetDestination (); + src = header.GetSource (); } SocketErrno errno_ = ERROR_NOTERROR;//do not use errno as it is the standard C last error number Ptr route; Ptr oif = m_boundnetdevice; //specify non-zero if bound to a source address - if (!oif && m_src != Ipv4Address::GetAny ()) + if (!oif && src != Ipv4Address::GetAny ()) { - int32_t index = ipv4->GetInterfaceForAddress (m_src); + int32_t index = ipv4->GetInterfaceForAddress (src); NS_ASSERT (index >= 0); oif = ipv4->GetNetDevice (index); - NS_LOG_LOGIC ("Set index " << oif << "from source " << m_src); + NS_LOG_LOGIC ("Set index " << oif << "from source " << src); } // TBD-- we could cache the route and just check its validity From 2d87e8d3265f2d231280593bcdf7ce1d123fffc3 Mon Sep 17 00:00:00 2001 From: He Wu Date: Wed, 7 Jul 2010 21:54:32 -0700 Subject: [PATCH 7/7] Initial import of energy model --- AUTHORS | 2 + RELEASE_NOTES | 4 + .../helper/basic-energy-source-helper.cc | 67 ++++ .../helper/basic-energy-source-helper.h | 52 +++ .../helper/basic-radio-energy-model-helper.cc | 96 +++++ .../helper/basic-radio-energy-model-helper.h | 90 +++++ .../energy/helper/energy-model-helper.cc | 114 ++++++ .../energy/helper/energy-model-helper.h | 189 +++++++++ .../energy/model/basic-energy-source.cc | 133 +++++++ .../energy/model/basic-energy-source.h | 95 +++++ .../energy/model/basic-radio-energy-model.cc | 312 +++++++++++++++ .../energy/model/basic-radio-energy-model.h | 159 ++++++++ .../energy/model/device-energy-model.cc | 99 +++++ .../energy/model/device-energy-model.h | 96 +++++ src/contrib/energy/model/energy-source.cc | 157 ++++++++ src/contrib/energy/model/energy-source.h | 158 ++++++++ .../energy/model/radio-energy-model.cc | 100 +++++ src/contrib/energy/model/radio-energy-model.h | 186 +++++++++ .../energy/test/basic-energy-model-test.cc | 358 ++++++++++++++++++ src/contrib/energy/wscript | 28 ++ src/wscript | 1 + 21 files changed, 2496 insertions(+) create mode 100644 src/contrib/energy/helper/basic-energy-source-helper.cc create mode 100644 src/contrib/energy/helper/basic-energy-source-helper.h create mode 100644 src/contrib/energy/helper/basic-radio-energy-model-helper.cc create mode 100644 src/contrib/energy/helper/basic-radio-energy-model-helper.h create mode 100644 src/contrib/energy/helper/energy-model-helper.cc create mode 100644 src/contrib/energy/helper/energy-model-helper.h create mode 100644 src/contrib/energy/model/basic-energy-source.cc create mode 100644 src/contrib/energy/model/basic-energy-source.h create mode 100644 src/contrib/energy/model/basic-radio-energy-model.cc create mode 100644 src/contrib/energy/model/basic-radio-energy-model.h create mode 100644 src/contrib/energy/model/device-energy-model.cc create mode 100644 src/contrib/energy/model/device-energy-model.h create mode 100644 src/contrib/energy/model/energy-source.cc create mode 100644 src/contrib/energy/model/energy-source.h create mode 100644 src/contrib/energy/model/radio-energy-model.cc create mode 100644 src/contrib/energy/model/radio-energy-model.h create mode 100644 src/contrib/energy/test/basic-energy-model-test.cc create mode 100644 src/contrib/energy/wscript diff --git a/AUTHORS b/AUTHORS index a434214f9..720825a22 100644 --- a/AUTHORS +++ b/AUTHORS @@ -37,6 +37,7 @@ Francesco Malandrino (francesco.malandrino@gmail.com) Fabian Mauchle (f1mauchl@hsr.ch) Andrey Mazo (mazo@iitp.ru) Faker Moatamri (faker.moatamri@sophia.inria.fr) +Sidharth Nabar (snabar@uw.edu) Michael Nowatkowski (nowatkom@gmail.com) Duy Nguyen (duy@soe.ucsc.edu) Tommaso Pecorella (tommaso.pecorella@unifi.it) @@ -63,3 +64,4 @@ Guillaume Vu-Brugier (gvubrugier@gmail.com) Tom Wambold (tom5760@gmail.com) Danqi Wang (beyondwdq@gmail.com) Florian Westphal (fw@strlen.de) +He Wu (mdzz@u.washington.edu) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index ebad27363..260ff8993 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -45,6 +45,10 @@ New user-visible features - A brand new NS-2 mobility trace reader supports BonnMotion, SUMO, TraNS, etc. traces. + - An energy model for nodes and devices, including an energy source + model and device energy models allowing energy-aware devices + to notify the energy source about energy consumption. + Bugs fixed ---------- The following lists many of the bugs that were fixed since ns-3.7, in diff --git a/src/contrib/energy/helper/basic-energy-source-helper.cc b/src/contrib/energy/helper/basic-energy-source-helper.cc new file mode 100644 index 000000000..11db73791 --- /dev/null +++ b/src/contrib/energy/helper/basic-energy-source-helper.cc @@ -0,0 +1,67 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#include "basic-energy-source-helper.h" +#include "ns3/energy-source.h" + +namespace ns3 { + +BasicEnergySourceHelper::BasicEnergySourceHelper () +{ + m_basicEnergySource.SetTypeId ("ns3::BasicEnergySource"); +} + +BasicEnergySourceHelper::~BasicEnergySourceHelper () +{ +} + +void +BasicEnergySourceHelper::Set (std::string name, const AttributeValue &v) +{ + m_basicEnergySource.Set (name, v); +} + +Ptr +BasicEnergySourceHelper::Create (void) const +{ + Ptr source = m_basicEnergySource.Create (); + NS_ASSERT (source != 0); + return source; +} + +void +BasicEnergySourceHelper::Install (Ptr node) const +{ + NS_ASSERT (node != NULL); + // check if energy source already exists + Ptr source = node->GetObject (); + if (source != NULL) + { + NS_FATAL_ERROR ("Energy source already installed!"); + return; + } + // create energy source + source = Create (); + NS_ASSERT (source != NULL); + // aggregate source to node + node->AggregateObject (source); +} + +} // namespace ns3 diff --git a/src/contrib/energy/helper/basic-energy-source-helper.h b/src/contrib/energy/helper/basic-energy-source-helper.h new file mode 100644 index 000000000..6dcd144ff --- /dev/null +++ b/src/contrib/energy/helper/basic-energy-source-helper.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef BASIC_ENERGY_SOURCE_HELPER +#define BASIC_ENERGY_SOURCE_HELPER + +#include "energy-model-helper.h" + +namespace ns3 { + +class Node; + +/** + * \brief Creates a BasicEnergySource object. + */ +class BasicEnergySourceHelper : public EnergySourceHelper +{ +public: + BasicEnergySourceHelper (); + ~BasicEnergySourceHelper (); + + void Set (std::string name, const AttributeValue &v); + + Ptr Create (void) const; + + void Install (Ptr node) const; + +private: + ObjectFactory m_basicEnergySource; + +}; + +} // namespace ns3 + +#endif /* BASIC_ENERGY_SOURCE_HELPER */ diff --git a/src/contrib/energy/helper/basic-radio-energy-model-helper.cc b/src/contrib/energy/helper/basic-radio-energy-model-helper.cc new file mode 100644 index 000000000..f732d3d35 --- /dev/null +++ b/src/contrib/energy/helper/basic-radio-energy-model-helper.cc @@ -0,0 +1,96 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#include "basic-radio-energy-model-helper.h" +#include "basic-energy-source-helper.h" +#include "ns3/radio-energy-model.h" +#include "ns3/config.h" +#include "ns3/names.h" +#include "ns3/log.h" + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("BasicRadioEnergyModelHelper"); + +BasicRadioEnergyModelHelper::BasicRadioEnergyModelHelper () +{ + m_radioEnergy.SetTypeId ("ns3::BasicRadioEnergyModel"); + m_depletionCallback.Nullify (); +} + +BasicRadioEnergyModelHelper::~BasicRadioEnergyModelHelper () +{ +} + +void +BasicRadioEnergyModelHelper::Set (std::string name, const AttributeValue &v) +{ + m_radioEnergy.Set (name, v); +} + +Ptr +BasicRadioEnergyModelHelper::Create (void) const +{ + return m_radioEnergy.Create (); +} + +void +BasicRadioEnergyModelHelper::SetDepletionCallback ( + BasicRadioEnergyModel::BasicEnergyDepletionCallback callback) +{ + m_depletionCallback = callback; +} + +/* + * Private function starts here. + */ + +void +BasicRadioEnergyModelHelper::DoInstall (Ptr node) const +{ + NS_LOG_FUNCTION (this << node); + // check if energy source is installed + Ptr source = node->GetObject (); + if (source != NULL) + { + Ptr model = m_radioEnergy.Create ()-> + GetObject (); + if (model == NULL) + { + NS_FATAL_ERROR ( "The requested radio energy model does not exist: " + << m_radioEnergy.GetTypeId ().GetName ()); + } + else + { + // set energy source pointer + model->SetEnergySource (source); + // set energy depletion callback + model->SetEnergyDepletionCallback (m_depletionCallback); + // add model to device model list in energy source + source->AppendDeviceEnergyModel (model); + } + } + else + { + NS_FATAL_ERROR ("Energy source NOT installed!"); + } +} + +} // namespace ns3 diff --git a/src/contrib/energy/helper/basic-radio-energy-model-helper.h b/src/contrib/energy/helper/basic-radio-energy-model-helper.h new file mode 100644 index 000000000..935ee7000 --- /dev/null +++ b/src/contrib/energy/helper/basic-radio-energy-model-helper.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* +* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation; +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Author: Sidharth Nabar , He Wu +*/ + +#ifndef BASIC_RADIO_ENERGY_MODEL_HELPER_H +#define BASIC_RADIO_ENERGY_MODEL_HELPER_H + +#include "energy-model-helper.h" +#include "ns3/device-energy-model.h" +#include "ns3/basic-radio-energy-model.h" + +namespace ns3 { + +/** + * \brief Assign energy model to nodes. + * + * This installer is used for BasicRadioEnergyModel. + */ +class BasicRadioEnergyModelHelper : public DeviceEnergyModelHelper +{ +public: + /** + * Construct a helper which is used to add a radio energy model to a node + */ + BasicRadioEnergyModelHelper (); + + /** + * Destroy a RadioEnergy Helper + */ + ~BasicRadioEnergyModelHelper (); + + /** + * \param name the name of the attribute to set + * \param v the value of the attribute + * + * Sets an attribute of the underlying PHY object. + */ + void Set (std::string name, const AttributeValue &v); + + /** + * \returns A newly created RadioEnergySource object. + */ + Ptr Create (void) const; + + /** + * \param callback Callback function for energy depletion handling. + * + * Sets the callback to be invoked when energy is depleted. + */ + void SetDepletionCallback ( + BasicRadioEnergyModel::BasicEnergyDepletionCallback callback); + + +private: + /** + * \brief Add an energy model to the specified node. + * + * \param node The node on which the energy model is to be installed. + * + * This method creates an instance of a ns3::BasicRadioEnergyModel and + * aggregates it to the given node. + */ + void DoInstall (Ptr node) const; + +private: + ObjectFactory m_radioEnergy; + /// Callback function for energy depletion. + BasicRadioEnergyModel::BasicEnergyDepletionCallback m_depletionCallback; + +}; + +} // namespace ns3 + +#endif /* BASIC_RADIO_ENERGY_MODEL_HELPER_H */ diff --git a/src/contrib/energy/helper/energy-model-helper.cc b/src/contrib/energy/helper/energy-model-helper.cc new file mode 100644 index 000000000..0b55a90db --- /dev/null +++ b/src/contrib/energy/helper/energy-model-helper.cc @@ -0,0 +1,114 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#include "energy-model-helper.h" +#include "ns3/log.h" +#include "ns3/config.h" +#include "ns3/names.h" + +namespace ns3 { + +/* + * EnergySourceHelper + */ +EnergySourceHelper::~EnergySourceHelper () +{ +} + +/* + * DeviceEnergyModelHelper + */ +DeviceEnergyModelHelper::~DeviceEnergyModelHelper () +{ +} + +void +DeviceEnergyModelHelper::Install (Ptr node) const +{ + NS_ASSERT (node != NULL); + DoInstall (node); +} + +void +DeviceEnergyModelHelper::Install (NodeContainer c) const +{ + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) + { + Install (*i); + } +} + +void +DeviceEnergyModelHelper::Install (std::string nodeName) const +{ + Ptr node = Names::Find (nodeName); + Install (node); +} + +void +DeviceEnergyModelHelper::InstallAll (void) const +{ + Install (NodeContainer::GetGlobal ()); +} + +/* + * EnergyModelHelper + */ +EnergyModelHelper::EnergyModelHelper () +{ +} + +void +EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, Ptr node) const +{ + NS_ASSERT (node != NULL); + // install source. source must be installed before installing device model. + sourceHelper.Install (node); + // install device model + modelHelper.Install (node); +} + +void +EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, NodeContainer c) const +{ + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) + { + Install (sourceHelper, modelHelper, *i); + } +} + +void +EnergyModelHelper::Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, std::string nodeName) const +{ + Ptr node = Names::Find (nodeName); + Install (sourceHelper, modelHelper, node); +} + +void +EnergyModelHelper::InstallAll (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper) const +{ + Install (sourceHelper, modelHelper, NodeContainer::GetGlobal ()); +} + +} // namespace ns3 diff --git a/src/contrib/energy/helper/energy-model-helper.h b/src/contrib/energy/helper/energy-model-helper.h new file mode 100644 index 000000000..47c66c982 --- /dev/null +++ b/src/contrib/energy/helper/energy-model-helper.h @@ -0,0 +1,189 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef ENERGY_MODEL_HELPER +#define ENERGY_MODEL_HELPER + +#include "ns3/attribute.h" +#include "ns3/object-factory.h" +#include "ns3/node-container.h" +#include "ns3/ptr.h" +#include "ns3/energy-source.h" +#include "ns3/device-energy-model.h" + +namespace ns3 { + +/** + * \brief Creates EnergySource objects. + * + * This class creates and installs an energy source onto network nodes. This + * base class must be implemented by new EnergySource implementation which wish + * to integrate with the \ref ns3::EnergyModelHelper class. + */ +class EnergySourceHelper +{ +public: + virtual ~EnergySourceHelper (); + + /** + * \returns A newly created EnergySource object. + * Subclasses must implement this methods to allow the ns3::EnergySource class + * to create DeviceEnergyModel object for installation. + */ + virtual Ptr Create (void) const = 0; + + /** + * \param node Pointer to the node where EnergySource will be installed on. + * + * This method installs an EnergySource onto a node. Must be implemented by + * subclasses. + */ + virtual void Install (Ptr node) const = 0; + +}; + + +/** + * \brief Creates DeviceEnergyModel objects + * + * This class can help to create and install an DeviceEnergyModel onto network + * nodes. It can be called separately to install extra DeviceEnergyModels onto + * the same nodes. This base class must be implemented by new DeviceEnergyModel + * which wishes to integrate with the \ref ns3::EnergyModelHelper class. + * + * Note that DeviceEnergyModel objects are *not* aggregated onto the node. They + * can be accessed through the EnergySource object, which *is* aggregated onto + * the node. + */ +class DeviceEnergyModelHelper +{ +public: + virtual ~DeviceEnergyModelHelper (); + + /** + * \returns A newly created DeviceEnergySource object. + * + * Subclasses must implement this method to allow the ns3::DeviceEnergyModel + * class to create DeviceEnergyModel object for installation. + */ + virtual Ptr Create (void) const = 0; + + /** + * \param name Name of attribute to set. + * \param v Value of the attribute. + * + * Sets one of the attributes of underlying DeviceEnergyModel. + */ + virtual void Set (std::string name, const AttributeValue &v) = 0; + + /** + * \param node The node on which a DeviceEnergyModel object must be created. + * + * Installs an DeviceEnergyModel onto a node. Subclasses must implement this + * method. + */ + void Install (Ptr node) const; + + /** + * \param c The set of nodes on which a jammer object must be created. + * + * Installs DeviceEnergyModel onto a list of nodes. Calls Install (Ptr + * node). + */ + void Install (NodeContainer c) const; + + /** + * \param nodeName The name of node. + * + * Calls Install (Ptr node). + */ + void Install (std::string nodeName) const; + + /** + * Install on *ALL* nodes exists in simulation. + */ + void InstallAll (void) const; + + +private: + /** + * \param node The node on which a DeviceEnergyModel object must be created. + * + * Implements Install (Ptr). Subclasses must implement this method. + */ + virtual void DoInstall (Ptr node) const = 0; + +}; + + +/** + * \brief Creates EnergySource and DeviceEnergyModel objects. + * + * This class helps to create EnergySource and DeviceEnergyModel objects. Note + * that only a single EnergySource can exist on the same node where multiple + * DeviceEnergyModel can coexist on the same node. Extra DeviceEnergyModels can + * be installed by DeviceEnergyModelHelper. + */ +class EnergyModelHelper +{ +public: + /** + * Create an EnergyModelHelper in an empty state: all its parameters must be + * set before calling ns3::EnergyModelHelper::Install. + */ + EnergyModelHelper (); + + /** + * \param source The EnergySourceHelper to create EnergySource. + * \param model The DeviceEnergyModelHelper to create DeviceEnergyModel. + * \param node The node on which the energy model will be installed on. + */ + void Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, Ptr node) const; + + /** + * \param source The EnergySourceHelper to create EnergySource. + * \param model The DeviceEnergyModelHelper to create DeviceEnergyModel. + * \param node List of node on which the energy model will be installed on. + */ + void Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, NodeContainer c) const; + + /** + * \param source The EnergySourceHelper to create EnergySource. + * \param model The DeviceEnergyModelHelper to create DeviceEnergyModel. + * \param node name of node on which the energy model will be installed on. + */ + void Install (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper, std::string nodeName) const; + + /** + * \param source The EnergySourceHelper to create EnergySource. + * \param model The DeviceEnergyModelHelper to create DeviceEnergyModel. + * \param node name of node on which the energy model will be installed on. + */ + void InstallAll (const EnergySourceHelper &sourceHelper, + const DeviceEnergyModelHelper &modelHelper) const; + +}; + +} // namespace ns3 + +#endif /* ENERGY_MODEL_HELPER */ diff --git a/src/contrib/energy/model/basic-energy-source.cc b/src/contrib/energy/model/basic-energy-source.cc new file mode 100644 index 000000000..79377ccf5 --- /dev/null +++ b/src/contrib/energy/model/basic-energy-source.cc @@ -0,0 +1,133 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#include "basic-energy-source.h" +#include "ns3/log.h" +#include "ns3/assert.h" +#include "ns3/double.h" +#include "ns3/trace-source-accessor.h" + +NS_LOG_COMPONENT_DEFINE ("BasicEnergySource"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (BasicEnergySource); + +TypeId +BasicEnergySource::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::BasicEnergySource") + .SetParent () + .AddConstructor () + .AddAttribute ("BasicEnergySourceInitialEnergyJ", + "Initial energy stored in basic energy source.", + DoubleValue (10), // in Joules + MakeDoubleAccessor (&BasicEnergySource::SetInitialEnergy, + &BasicEnergySource::DoGetInitialEnergy), + MakeDoubleChecker ()) + .AddTraceSource ("RemainingEnergy", + "Remaining energy at BasicEnergySource.", + MakeTraceSourceAccessor (&BasicEnergySource::m_remainingEnergyJ)) + ; + return tid; +} + +BasicEnergySource::BasicEnergySource () +{ +} + +BasicEnergySource::~BasicEnergySource () +{ +} + +void +BasicEnergySource::SetInitialEnergy (double initialEnergyJ) +{ + NS_LOG_FUNCTION (this << initialEnergyJ); + NS_ASSERT (initialEnergyJ >= 0); + m_initialEnergyJ = initialEnergyJ; + // set remaining energy to be initial energy + m_remainingEnergyJ = m_initialEnergyJ; +} + +/* + * Private functions start here. + */ + +void +BasicEnergySource::DoDispose (void) +{ + NS_LOG_FUNCTION (this); + BreakDeviceEnergyModelRefCycle (); // break reference cycle +} + +double +BasicEnergySource::DoGetInitialEnergy (void) const +{ + NS_LOG_FUNCTION (this); + return m_initialEnergyJ; +} + +double +BasicEnergySource::DoGetRemainingEnergy (void) const +{ + NS_LOG_FUNCTION (this); + return m_remainingEnergyJ; +} + +void +BasicEnergySource::DoDecreaseRemainingEnergy (double energyJ) +{ + NS_LOG_FUNCTION (this << energyJ); + NS_ASSERT (energyJ >= 0); + m_remainingEnergyJ -= energyJ; + // check if remaining energy is 0 + if (m_remainingEnergyJ <= 0) + { + HandleEnergyDrainedEvent (); + } +} + +void +BasicEnergySource::HandleEnergyDrainedEvent (void) +{ + NS_LOG_FUNCTION (this); + NS_LOG_DEBUG ("BasicEnergySource:Energy depleted!"); + NotifyEnergyDrained (); // notify DeviceEnergyModel objects + // energy never goes below 0 + m_remainingEnergyJ = 0; +} + +void +BasicEnergySource::DoIncreaseRemainingEnergy (double energyJ) +{ + NS_LOG_FUNCTION (this << energyJ); + NS_ASSERT (energyJ >= 0); + m_remainingEnergyJ += energyJ; +} + +double +BasicEnergySource::DoGetEnergyFraction (void) const +{ + NS_LOG_FUNCTION (this); + return m_remainingEnergyJ / m_initialEnergyJ; +} + +} // namespace ns3 diff --git a/src/contrib/energy/model/basic-energy-source.h b/src/contrib/energy/model/basic-energy-source.h new file mode 100644 index 000000000..8e007aca5 --- /dev/null +++ b/src/contrib/energy/model/basic-energy-source.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef BASIC_ENERGY_SOURCE +#define BASIC_ENERGY_SOURCE + +#include "ns3/traced-value.h" +#include "energy-source.h" + +namespace ns3 { + +class BasicEnergySource : public EnergySource +{ +public: + static TypeId GetTypeId (void); + BasicEnergySource (); + virtual ~BasicEnergySource (); + + + /** + * \param initialEnergy Initial energy, in Joules + * + * Implements SetInitialEnergy. Note that initial energy is assumed to be set + * before simulation starts and is set only once per simulation. + */ + void SetInitialEnergy (double initialEnergyJ); + + +private: + void DoDispose (void); + + /** + * \return Initial energy stored in energy source, in Joules. + * + * Implements GetInitialEnergy. + */ + double DoGetInitialEnergy (void) const; + + /** + * \return Remaining energy in energy source, in Joules + * + * Implements GetRemainingEnergy. + */ + double DoGetRemainingEnergy (void) const; + + /** + * \param energy Amount of energy (in Joules) to decrease from energy source. + * + * Implements DecreaseRemainingEnergy. + */ + void DoDecreaseRemainingEnergy (double energyJ); + + /** + * Handles the remaining energy going to zero event. This function notifies + * all the energy models aggregated to the node about the energy being + * depleted. Each energy model is then responsible for its own handler. + */ + void HandleEnergyDrainedEvent (void); + + /** + * \param energy Amount of energy (in Joules) to increase from energy source. + * + * Implements IncreaseRemainingEnergy. + */ + void DoIncreaseRemainingEnergy (double energyJ); + + /// Implements GetEnergyFraction. + double DoGetEnergyFraction (void) const; + +private: + double m_initialEnergyJ; // initial energy, in Joules + TracedValue m_remainingEnergyJ; // remaining energy, in Joules + +}; + +} // namespace ns3 + +#endif /* BASIC_ENERGY_SOURCE */ diff --git a/src/contrib/energy/model/basic-radio-energy-model.cc b/src/contrib/energy/model/basic-radio-energy-model.cc new file mode 100644 index 000000000..ee016926b --- /dev/null +++ b/src/contrib/energy/model/basic-radio-energy-model.cc @@ -0,0 +1,312 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Sidharth Nabar , He Wu + */ + +#include "ns3/log.h" +#include "ns3/double.h" +#include "ns3/simulator.h" +#include "ns3/trace-source-accessor.h" +#include "basic-radio-energy-model.h" + +NS_LOG_COMPONENT_DEFINE ("BasicRadioEnergyModel"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (BasicRadioEnergyModel); + +TypeId +BasicRadioEnergyModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::BasicRadioEnergyModel") + .SetParent () + .AddConstructor () + .AddAttribute ("TxPowerW", + "The radio Tx power in Watts.", + DoubleValue (0.0435), // typical CC2420 value + MakeDoubleAccessor (&BasicRadioEnergyModel::SetTxPowerW, + &BasicRadioEnergyModel::GetTxPowerW), + MakeDoubleChecker ()) + .AddAttribute ("RxPowerW", + "The radio Rx power in Watts.", + DoubleValue (0.047), // typical CC2420 value + MakeDoubleAccessor (&BasicRadioEnergyModel::SetRxPowerW, + &BasicRadioEnergyModel::GetRxPowerW), + MakeDoubleChecker ()) + .AddAttribute ("IdlePowerW", + "The default radio Idle power in Watts.", + DoubleValue (0.001065), // typical CC2420 value + MakeDoubleAccessor (&BasicRadioEnergyModel::SetIdlePowerW, + &BasicRadioEnergyModel::GetIdlePowerW), + MakeDoubleChecker ()) + .AddAttribute ("SleepPowerW", + "The default radio Sleep power in Watts.", + DoubleValue (0.00005), // typical CC2420 value + MakeDoubleAccessor (&BasicRadioEnergyModel::SetSleepPowerW, + &BasicRadioEnergyModel::GetSleepPowerW), + MakeDoubleChecker ()) + .AddAttribute ("PeriodicEnergyUpdateInterval", + "Time between two consecutive periodic energy updates.", + TimeValue (Seconds (1.0)), + MakeTimeAccessor (&BasicRadioEnergyModel::SetEnergyUpdateInterval, + &BasicRadioEnergyModel::GetEnergyUpdateInterval), + MakeTimeChecker ()) + .AddTraceSource ("TotalEnergyConsumption", + "Total energy consumption of the radio device.", + MakeTraceSourceAccessor (&BasicRadioEnergyModel::m_totalEnergyConsumption)) + ; + return tid; +} + +BasicRadioEnergyModel::BasicRadioEnergyModel () +{ + NS_LOG_FUNCTION (this); + m_currentState = IDLE; + m_lastUpdateTime = Seconds (0.0); + m_energyDepletionCallback.Nullify (); + /* + * Start scheduling the periodic energy update event. BasicRadioEnergyModel + * is *not* aggregated to the node. Hence we have to schedule this in the + * constructor instead of calling it in DoStart. + */ + m_periodicEnergyUpdateEvent = Simulator::Schedule (Seconds (0.0), + &BasicRadioEnergyModel::DoUpdateRemainingEnergy, this, m_currentState); +} + +BasicRadioEnergyModel::~BasicRadioEnergyModel () +{ +} + +BasicRadioEnergyModel::RadioState +BasicRadioEnergyModel::GetCurrentState (void) const +{ + NS_LOG_FUNCTION (this); + return m_currentState; +} + +void +BasicRadioEnergyModel::SetCurrentState (const RadioState currentState) +{ + NS_LOG_FUNCTION (this); + if (currentState != m_currentState) + { + m_currentState = currentState; + std::string stateName; + switch (currentState) + { + case TX: + stateName = "TX"; + break; + case RX: + stateName = "RX"; + break; + case IDLE: + stateName = "IDLE"; + break; + case SLEEP: + stateName = "SLEEP"; + break; + } + NS_LOG_DEBUG ("BasicRadioEnergyModel: Switching to state: " + << stateName << " at time = " << Simulator::Now ()); + } +} + +Time +BasicRadioEnergyModel::GetEnergyUpdateInterval (void) const +{ + NS_LOG_FUNCTION (this); + return m_energyUpdateInterval; +} + +void +BasicRadioEnergyModel::SetEnergyUpdateInterval (const Time interval) +{ + NS_LOG_FUNCTION (this); + NS_ASSERT (interval.GetSeconds () > 0); + m_energyUpdateInterval = interval; +} + +void +BasicRadioEnergyModel::SetEnergyDepletionCallback ( + BasicEnergyDepletionCallback callback) +{ + NS_LOG_FUNCTION (this); + if (callback.IsNull ()) + { + NS_LOG_DEBUG ("BasicRadioEnergyModel:Setting NULL energy depletion callback!"); + } + m_energyDepletionCallback = callback; +} + +bool +BasicRadioEnergyModel::IsStateTransitionValid (const RadioState destState) +{ + NS_LOG_FUNCTION (this << destState); + bool returnValue = true; + + /* + * This is a placeholder function to specify if some of the radio state + * transitions are prohibited. For example, if transition TX -> RX is not + * allowed, and must go through IDLE as TX -> IDLE -> RX, then this method + * can be used to raise an ns3 error. Initial state is m_currentState. + */ + + return returnValue; +} + +/* + * Private functions start here. + */ + +void +BasicRadioEnergyModel::DoDispose (void) +{ + NS_LOG_FUNCTION (this); + BreakSourceRefCycle (); // break reference cycle to energy source + m_energyDepletionCallback.Nullify (); +} + +void +BasicRadioEnergyModel::DoHandleEnergyDepletion (void) +{ + NS_LOG_FUNCTION (this); + NS_LOG_DEBUG ("BasicRadioEnergyModel:Energy is depleted!"); + // invoke energy depletion callback, if set. + if (!m_energyDepletionCallback.IsNull ()) + { + m_energyDepletionCallback (); + } +} + +double +BasicRadioEnergyModel::DoGetTotalEnergyConsumption (void) const +{ + NS_LOG_FUNCTION (this); + return m_totalEnergyConsumption; +} + +double +BasicRadioEnergyModel::DoGetTxPowerW (void) const +{ + NS_LOG_FUNCTION (this); + return m_txPower; +} + +void +BasicRadioEnergyModel::DoSetTxPowerW (double txPowerW) +{ + NS_LOG_FUNCTION (this << txPowerW); + m_txPower = txPowerW; +} + +double +BasicRadioEnergyModel::DoGetRxPowerW (void) const +{ + NS_LOG_FUNCTION (this); + return m_rxPower; +} + +void +BasicRadioEnergyModel::DoSetRxPowerW (double rxPowerW) +{ + NS_LOG_FUNCTION (this << rxPowerW); + m_rxPower = rxPowerW; +} + +double +BasicRadioEnergyModel::DoGetIdlePowerW (void) const +{ + NS_LOG_FUNCTION (this); + return m_idlePower; +} + +void +BasicRadioEnergyModel::DoSetIdlePowerW (double idlePowerW) +{ + NS_LOG_FUNCTION (this << idlePowerW); + m_idlePower = idlePowerW; +} + +double +BasicRadioEnergyModel::DoGetSleepPowerW (void) const +{ + NS_LOG_FUNCTION (this); + return m_sleepPower; +} + +void +BasicRadioEnergyModel::DoSetSleepPowerW (double sleepPowerW) +{ + NS_LOG_FUNCTION (this << sleepPowerW); + m_sleepPower = sleepPowerW; +} + +void +BasicRadioEnergyModel::DoUpdateRemainingEnergy (const RadioState destState) +{ + NS_LOG_FUNCTION (this << destState); + NS_ASSERT (IsStateTransitionValid (destState)); + + // Cancel the currently scheduled periodic event, if any + m_periodicEnergyUpdateEvent.Cancel (); + + Time duration = Simulator::Now () - m_lastUpdateTime; + NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid + + // update remaining energy accordingly + double energyToDecrease = 0.0; + switch (m_currentState) + { + case TX: + energyToDecrease = duration.GetSeconds () * m_txPower; + DecreaseRemainingEnergy (energyToDecrease); + break; + case RX: + energyToDecrease = duration.GetSeconds () * m_rxPower; + DecreaseRemainingEnergy (energyToDecrease); + break; + case IDLE: + energyToDecrease = duration.GetSeconds () * m_idlePower; + DecreaseRemainingEnergy (energyToDecrease); + break; + case SLEEP: + energyToDecrease = duration.GetSeconds () * m_sleepPower; + DecreaseRemainingEnergy (energyToDecrease); + break; + } + + // update total energy consumption + m_totalEnergyConsumption += energyToDecrease; + + // update last update time stamp + m_lastUpdateTime = Simulator::Now (); + + // update current state & last update time stamp + SetCurrentState (destState); + + // Schedule the next periodic energy update event + m_periodicEnergyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval, + &BasicRadioEnergyModel::DoUpdateRemainingEnergy, this, m_currentState); + + // some debug message + NS_LOG_DEBUG ("BasicRadioEnergyModel:Total energy consumption is " + << m_totalEnergyConsumption << "J"); +} + +} // namespace ns3 diff --git a/src/contrib/energy/model/basic-radio-energy-model.h b/src/contrib/energy/model/basic-radio-energy-model.h new file mode 100644 index 000000000..9ef57527b --- /dev/null +++ b/src/contrib/energy/model/basic-radio-energy-model.h @@ -0,0 +1,159 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef BASIC_RADIO_ENERGY_MODEL_H +#define BASIC_RADIO_ENERGY_MODEL_H + +#include "radio-energy-model.h" +#include "ns3/nstime.h" +#include "ns3/event-id.h" +#include "ns3/traced-value.h" + +namespace ns3 { + +/** + * \brief a basic radio energy model + * + * This is a child class of the RadioEnergyModel class. + * + * 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is + * IDLE. + * The different types of transactions that are defined are: + * 1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration, + * then state goes from TX to IDLE. + * 2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration, + * then state goes from RX to IDLE. + * 3. Go_to_Sleep: State goes from IDLE to SLEEP. + * 4. End_of_Sleep: State goes from SLEEP to IDLE. + * The class keeps track of what state the radio is currently in. + * + * Energy calculation: For each transaction, we see how much time the radio + * spent in each state and calculate energy consumption accordingly. + * + * Energy update: Remaining energy = + * Previous remaining energy - Energy_transaction. + * + * Default values for power consumption are based on CC2420 radio chip, with + * supply voltage as 2.5V and currents as 17.4 mA (TX), 18.8 mA (RX), 20 uA + * (sleep) and 426 uA (idle). + * + * TODO change default values to wifi radio chip numbers. + */ +class BasicRadioEnergyModel : public RadioEnergyModel +{ +public: + /// Callback type for energy depletion handling. + typedef Callback BasicEnergyDepletionCallback; + +public: + static TypeId GetTypeId (void); + BasicRadioEnergyModel (); + virtual ~BasicRadioEnergyModel (); + + /** + * For current state, the getter is public, but the setter method should be + * private. + */ + RadioState GetCurrentState (void) const; + + /** + * \param interval Energy update interval. + * + * Setter for the energy update interval - time between two consecutive energy + * updates. + */ + void SetEnergyUpdateInterval (const Time interval); + + /** + * Getter for the energy update interval - time between two consecutive energy + * updates. + */ + Time GetEnergyUpdateInterval (void) const; + + /** + * \param callback Callback function. + * + * Sets callback for energy depletion handling. + */ + void SetEnergyDepletionCallback (BasicEnergyDepletionCallback callback); + + /** + * \param destState Radio state to switch to. + * \return True if the transition is allowed. + * + * This function checks if a given radio state transition is allowed. + */ + bool IsStateTransitionValid (const RadioState destState); + + +private: + void DoDispose (void); + + /// Handles energy depletion. + void DoHandleEnergyDepletion (void); + + /// Implements GetTotalEnergyConsumption. + double DoGetTotalEnergyConsumption (void) const; + + double DoGetTxPowerW (void) const; + void DoSetTxPowerW (double txPowerW); + double DoGetRxPowerW (void) const; + void DoSetRxPowerW (double rxPowerW); + double DoGetIdlePowerW (void) const; + void DoSetIdlePowerW (double idlePowerW); + double DoGetSleepPowerW (void) const; + void DoSetSleepPowerW (double sleepPowerW); + + void DoUpdateRemainingEnergy (const RadioState destState); + + /** + * \param currentState New state the radio device is currently in. + * + * Sets current state. This function is private so that only the energy model + * can change its own state. + */ + void SetCurrentState (const RadioState currentState); + +private: + /* + * Member variables for the power consumption in different radio modes. + * Power = (supply voltage * current draw) + */ + double m_txPower; + double m_rxPower; + double m_idlePower; + double m_sleepPower; + + // This variable keeps track of the total energy consumed by this particular model. + TracedValue m_totalEnergyConsumption; + + // State variables. + RadioState m_currentState; // current state the radio is in + Time m_lastUpdateTime; // time stamp of previous energy update + EventId m_periodicEnergyUpdateEvent; // scheduled event to update remaining energy periodically + Time m_energyUpdateInterval; // Time between consecutive periodic energy updates. + + // energy depletion callback + BasicEnergyDepletionCallback m_energyDepletionCallback; +}; + +} // namespace ns3 + +#endif /* BASIC_RADIO_ENERGY_MODEL_H */ diff --git a/src/contrib/energy/model/device-energy-model.cc b/src/contrib/energy/model/device-energy-model.cc new file mode 100644 index 000000000..75f6b27e9 --- /dev/null +++ b/src/contrib/energy/model/device-energy-model.cc @@ -0,0 +1,99 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#include "device-energy-model.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("DeviceEnergyModel"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (DeviceEnergyModel); + +TypeId +DeviceEnergyModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::DeviceEnergyModel") + .SetParent () + ; + return tid; +} + +DeviceEnergyModel::DeviceEnergyModel () +{ +} + +DeviceEnergyModel::~DeviceEnergyModel () +{ +} + +void +DeviceEnergyModel::HandleEnergyDepletion (void) +{ + DoHandleEnergyDepletion (); +} + +void +DeviceEnergyModel::SetEnergySource (Ptr source) +{ + NS_LOG_FUNCTION (this << source); + NS_ASSERT (source != NULL); // energy source must exist + m_energySourcePtr = source; +} + +/* + * Private function starts here. + */ + +void +DeviceEnergyModel::DoDispose (void) +{ + NS_LOG_FUNCTION (this); + m_energySourcePtr = NULL; +} + +/* + * Protected functions start here. + */ + +void +DeviceEnergyModel::DecreaseRemainingEnergy (double energyJ) +{ + NS_LOG_FUNCTION (this << energyJ); + NS_ASSERT (m_energySourcePtr != NULL); // energy source must exist + m_energySourcePtr->DecreaseRemainingEnergy (energyJ); +} + +void +DeviceEnergyModel::IncreaseRemainingEnergy (double energyJ) +{ + NS_LOG_FUNCTION (this << energyJ); + NS_ASSERT (m_energySourcePtr != NULL); // energy source must exist + m_energySourcePtr->IncreaseRemainingEnergy (energyJ); +} + +void +DeviceEnergyModel::BreakSourceRefCycle (void) +{ + NS_LOG_FUNCTION (this); + m_energySourcePtr = NULL; +} + +} // namespace ns3 diff --git a/src/contrib/energy/model/device-energy-model.h b/src/contrib/energy/model/device-energy-model.h new file mode 100644 index 000000000..f2790d607 --- /dev/null +++ b/src/contrib/energy/model/device-energy-model.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef DEVICE_ENERGY_MODEL +#define DEVICE_ENERGY_MODEL + +#include "ns3/object.h" +#include "energy-source.h" + +namespace ns3 { + +class EnergySource; + +/** + * \brief Base class for device energy models. + * + * A device energy model should represent the energy consumption behavior of a + * specific device. It will update remaining energy stored in the EnergySource + * object installed on node. When energy is depleted, each DeviceEnergyModel + * object installed on the same node will be informed by the EnergySource. + */ +class DeviceEnergyModel : public Object +{ +public: + static TypeId GetTypeId (void); + DeviceEnergyModel (); + virtual ~DeviceEnergyModel (); + + /** + * This function is called by the EnergySource object when energy stored in + * the energy source is depleted. Should be implemented by child classes. + */ + void HandleEnergyDepletion (void); + + /// Sets the pointer to node energy source. + void SetEnergySource (Ptr source); + +private: + /* + * Do not include DoStart in any child of this base class. DeviceEnergyModel + * is *not* aggregated to the node hence DoStart will *not* be called. + */ + + /** + * All child's implementation must call BreakSourceRefCycle to ensure + * reference cycle to EnergySource object is broken. + */ + void DoDispose (void); + + /// Implements HandleEnergyDepletion. + virtual void DoHandleEnergyDepletion (void) = 0; + +private: + /// Pointer to EnergySource object + Ptr m_energySourcePtr; + +protected: + /// This function is used to access the private energy source pointer. + void DecreaseRemainingEnergy (double energyJ); + + /// This function is used to access the private energy source pointer. + void IncreaseRemainingEnergy (double energyJ); + + /** + * This function is called to break reference cycle between DeviceEnergyModel + * and EnergySource. Child of the DeviceEnergyModel base class must call this + * function in their implementation of DoDispose to make sure the reference + * cycle is broken. + * + * Normally this work will be completed by the DoDispose function. However it + * will be overridden in the child class. Hence we introduced this function. + */ + void BreakSourceRefCycle (void); + +}; + +} + +#endif /* DEVICE_ENERGY_MODEL */ diff --git a/src/contrib/energy/model/energy-source.cc b/src/contrib/energy/model/energy-source.cc new file mode 100644 index 000000000..84e313b72 --- /dev/null +++ b/src/contrib/energy/model/energy-source.cc @@ -0,0 +1,157 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Sidharth Nabar , He Wu + */ + +#include "energy-source.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("EnergySource"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (EnergySource); + +TypeId +EnergySource::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::EnergySource") + .SetParent () + ; + return tid; +} + +EnergySource::EnergySource () +{ +} + +EnergySource::~EnergySource () +{ +} + +double +EnergySource::GetInitialEnergy (void) const +{ + return DoGetInitialEnergy (); +} + +double +EnergySource::GetRemainingEnergy (void) const +{ + return DoGetRemainingEnergy (); +} + +void +EnergySource::DecreaseRemainingEnergy (double energyJ) +{ + DoDecreaseRemainingEnergy (energyJ); +} + +void +EnergySource::IncreaseRemainingEnergy (double energyJ) +{ + DoIncreaseRemainingEnergy (energyJ); +} + +double +EnergySource::GetEnergyFraction (void) const +{ + return DoGetEnergyFraction (); +} + +void +EnergySource::AppendDeviceEnergyModel ( + Ptr deviceEnergyModelPtr) +{ + NS_LOG_FUNCTION (this << deviceEnergyModelPtr); + NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist + m_deviceEnergyModelList.push_back (deviceEnergyModelPtr); +} + +EnergySource::DeviceEnergyModelList +EnergySource::FindDeviceEnergyModels (TypeId tid) +{ + NS_LOG_FUNCTION (this << tid); + DeviceEnergyModelList list; + DeviceEnergyModelList::iterator listItr; + for (listItr = m_deviceEnergyModelList.begin (); + listItr != m_deviceEnergyModelList.end (); listItr++) + { + if ((*listItr)->GetInstanceTypeId () == tid) + { + list.push_back (*listItr); + } + } + return list; +} + +EnergySource::DeviceEnergyModelList +EnergySource::FindDeviceEnergyModels (std::string name) +{ + NS_LOG_FUNCTION (this << name); + DeviceEnergyModelList list; + DeviceEnergyModelList::iterator listItr; + for (listItr = m_deviceEnergyModelList.begin (); + listItr != m_deviceEnergyModelList.end (); listItr++) + { + if ((*listItr)->GetInstanceTypeId ().GetName ().compare (name) == 0) + { + list.push_back (*listItr); + } + } + return list; +} + +/* + * Private function starts here. + */ + +void +EnergySource::DoDispose (void) +{ + NS_LOG_FUNCTION (this); + m_deviceEnergyModelList.clear (); // break reference cycle +} + +/* + * Protected functions start here. + */ + +void +EnergySource::NotifyEnergyDrained (void) +{ + NS_LOG_FUNCTION (this); + // notify all device energy models installed on node + DeviceEnergyModelList::iterator listItr; + for (listItr = m_deviceEnergyModelList.begin (); + listItr != m_deviceEnergyModelList.end (); listItr++) + { + NS_LOG_DEBUG ("BasicEnergySource:Notifying device energy model: " + << (*listItr)->GetInstanceTypeId ()); + (*listItr)->HandleEnergyDepletion (); + } +} + +void +EnergySource::BreakDeviceEnergyModelRefCycle (void) +{ + NS_LOG_FUNCTION (this); + m_deviceEnergyModelList.clear (); // break reference cycle +} + +} // namespace ns3 diff --git a/src/contrib/energy/model/energy-source.h b/src/contrib/energy/model/energy-source.h new file mode 100644 index 000000000..58e93bfec --- /dev/null +++ b/src/contrib/energy/model/energy-source.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Sidharth Nabar , He Wu + */ + +#ifndef ENERGY_SOURCE_H +#define ENERGY_SOURCE_H + +#include "ns3/object.h" +#include "ns3/ptr.h" +#include "ns3/type-id.h" +#include "device-energy-model.h" + +namespace ns3 { + +class DeviceEnergyModel; + +/** + * \brief Energy source base class. + * + * This is the base class for energy sources. Energy sources keep track of + * remaining energy. Device energy models will be updating the remaining energy + * in the energy source. The energy source itself does not update the remaining + * energy. Energy source also keeps a list of device energy models installed on + * the same node. When the remaining energy level reaches 0, the energy source + * will notify all device energy models stored in the list. + * + * Unit of energy is chosen as Joules since energy models typically calculate + * energy as (time in seconds * power in Watts). If the energy source stores + * energy in different units (eg. kWh), a simple converter function should + * suffice. + */ +class EnergySource : public Object +{ +public: + /// List of pointers to DeviceEnergyModel objects. + typedef std::vector< Ptr > DeviceEnergyModelList; + +public: + static TypeId GetTypeId (void); + EnergySource (); + virtual ~EnergySource (); + + /// This function returns initial energy stored in energy source. + double GetInitialEnergy (void) const; + + /// This function returns the remaining energy stored in the energy source. + double GetRemainingEnergy (void) const; + + /** + * \param energy Amount of energy to decrease (in Joules) + * + * This function decreases the remaining energy in the energy source by the + * specified amount. + */ + void DecreaseRemainingEnergy (double energyJ); + + /** + * \param energy Amount of energy to increase (in Joules) + * + * This function increases the remaining energy in the energy source by the + * specified amount. Provided for supporting re-charging or scavenging. + */ + void IncreaseRemainingEnergy (double energyJ); + + /** + * \return Energy fraction = remaining energy / initial energy [0, 1] + * + * This function returns the percentage of energy left in the energy source. + */ + double GetEnergyFraction (void) const; + + /** + * \param deviceEnergyModelPtr Pointer to device energy model. + * \param tid TypeId of the specific device energy model. + * + * This function appends a device energy model to the end of a list of + * DeviceEnergyModelInfo structs. + */ + void AppendDeviceEnergyModel (Ptr deviceEnergyModelPtr); + + /** + * \param tid TypeId of the DeviceEnergyModel we are searching for. + * \returns List of pointers to DeviceEnergyModel objects installed on node. + */ + DeviceEnergyModelList FindDeviceEnergyModels (TypeId tid); + /** + * \param name name of the DeviceEnergyModel we are searching for. + * \returns List of pointers to DeviceEnergyModel objects installed on node. + */ + DeviceEnergyModelList FindDeviceEnergyModels (std::string name); + + +private: + /** + * All child's implementation must call BreakDeviceEnergyModelRefCycle to + * ensure reference cycles to DeviceEnergyModel objects are broken. + */ + void DoDispose (void); + + /// Implements GetInitialEnergy. + virtual double DoGetInitialEnergy (void) const = 0; + + /// Implements GetRemainingEnergy. + virtual double DoGetRemainingEnergy (void) const = 0; + + /// Implements DecreaseRemainingEnergy. + virtual void DoDecreaseRemainingEnergy (double energyJ) = 0; + + /// Implements IncreaseRemainingEnergy. + virtual void DoIncreaseRemainingEnergy (double energyJ) = 0; + + /// Implements GetEnergyFraction. + virtual double DoGetEnergyFraction (void) const = 0; + +private: + /// List of device energy models installed on the same node. + DeviceEnergyModelList m_deviceEnergyModelList; + + +protected: + /** + * This function notifies all DeviceEnergyModel of energy depletion event. It + * is called by the child EnergySource class when energy depletion happens. + */ + void NotifyEnergyDrained (void); + + /** + * This function is called to break reference cycle between EnergySource and + * DeviceEnergyModel. Child of the EnergySource base class must call this + * function in their implementation of DoDispose to make sure the reference + * cycle is broken. + * + * Normally this work will be completed by the DoDispose function. However it + * will be overridden in the child class. Hence we introduced this function. + */ + void BreakDeviceEnergyModelRefCycle (void); + +}; + +} // namespace ns3 + +#endif /* ENERGY_SOURCE_H */ diff --git a/src/contrib/energy/model/radio-energy-model.cc b/src/contrib/energy/model/radio-energy-model.cc new file mode 100644 index 000000000..1d863a61c --- /dev/null +++ b/src/contrib/energy/model/radio-energy-model.cc @@ -0,0 +1,100 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Sidharth Nabar , He Wu + */ + +#include "radio-energy-model.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("RadioEnergyModel"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (RadioEnergyModel); + +TypeId +RadioEnergyModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::RadioEnergyModel") + .SetParent () + ; + return tid; +} + +RadioEnergyModel::RadioEnergyModel () +{ +} + +RadioEnergyModel::~RadioEnergyModel () +{ +} + +double +RadioEnergyModel::GetTxPowerW (void) const +{ + return DoGetTxPowerW (); +} +double +RadioEnergyModel::GetRxPowerW (void) const +{ + return DoGetRxPowerW (); +} + +double +RadioEnergyModel::GetIdlePowerW (void) const +{ + return DoGetIdlePowerW (); +} + +double +RadioEnergyModel::GetSleepPowerW (void) const +{ + return DoGetSleepPowerW (); +} + +void +RadioEnergyModel::SetTxPowerW (double txPowerW) +{ + DoSetTxPowerW (txPowerW); +} + +void +RadioEnergyModel::SetRxPowerW (double rxPowerW) +{ + DoSetRxPowerW (rxPowerW); +} + +void +RadioEnergyModel::SetIdlePowerW (double idlePowerW) +{ + DoSetIdlePowerW (idlePowerW); +} + +void +RadioEnergyModel::SetSleepPowerW (double sleepPowerW) +{ + DoSetSleepPowerW (sleepPowerW); +} + +void +RadioEnergyModel::UpdateRemainingEnergy (const RadioState destState) +{ + DoUpdateRemainingEnergy (destState); +} + +} // namespace ns3 diff --git a/src/contrib/energy/model/radio-energy-model.h b/src/contrib/energy/model/radio-energy-model.h new file mode 100644 index 000000000..67ed84c91 --- /dev/null +++ b/src/contrib/energy/model/radio-energy-model.h @@ -0,0 +1,186 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Sidharth Nabar , He Wu + */ + +#ifndef RADIO_ENERGY_MODEL_H +#define RADIO_ENERGY_MODEL_H + +#include "device-energy-model.h" + +namespace ns3 { + +/** + * \brief Keep track of energy consumption at a radio of a node. + * + * Assumption is that the radio is responsible for a significantly higher + * percentage of energy consumption than the computation at the node. + * + * The units used are: Joules (J) for energy, Watts (W) for power. + * + * This is a base class, which should be inherited and implemented by children + * classes. + */ +class RadioEnergyModel : public DeviceEnergyModel +{ +public: + /** + * The states of the PHY layer. + */ + enum RadioState + { + /** + * The radio is transmitting. + */ + TX = 0, + /** + * The radio is receiving. + */ + RX, + /** + * The radio is idle. + */ + IDLE, + /** + * The radio is in sleep mode. + */ + SLEEP + }; + +public: + static TypeId GetTypeId (void); + RadioEnergyModel (); + virtual ~RadioEnergyModel (); + + /** + * \returns the radio TX power in W. + */ + double GetTxPowerW (void) const; + + /** + * \param txPowerW the radio TX power in W + */ + void SetTxPowerW (double txPowerW); + + /** + * \returns the radio Rx power in W + */ + double GetRxPowerW (void) const; + + /** + * \param rxPowerW the radio RX power in W + */ + void SetRxPowerW (double rxPowerW); + + /** + * \returns the radio IDLE power in W + */ + double GetIdlePowerW (void) const; + + /** + * \param idlePowerW the radio IDLE power in W + */ + void SetIdlePowerW (double idlePowerW); + + /** + * \returns the radio SLEEP power in W + */ + double GetSleepPowerW (void) const; + + /** + * \param sleepPowerW the radio SLEEP power in W. + */ + void SetSleepPowerW (double sleepPowerW); + + /** + * \param destState Radio state to switch to. + * + * This function will update the remaining energy. Its implementation will be + * completed in child classes. + */ + void UpdateRemainingEnergy (const RadioState destState); + + +private: + /** + * \returns the radio TX power in W. + * + * Concrete subclasses of this base class must implement this method. + */ + virtual double DoGetTxPowerW (void) const = 0; + + /** + * \param the radio TX power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual void DoSetTxPowerW (double txPowerW) = 0; + + /** + * \returns the radio RX power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual double DoGetRxPowerW (void) const = 0; + + /** + * \param the radio RX power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual void DoSetRxPowerW (double rxPowerW) = 0; + + /** + * \returns the radio IDLE power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual double DoGetIdlePowerW (void) const = 0; + + /** + * \param idlePowerW the radio IDLE power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual void DoSetIdlePowerW (double idlePowerW) = 0; + + /** + * \returns the radio SLEEP power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual double DoGetSleepPowerW (void) const = 0; + + /** + * \param sleepPowerW the radio SLEEP power in W + * + * Concrete subclasses of this base class must implement this method. + */ + virtual void DoSetSleepPowerW (double sleepPowerW) = 0; + + /** + * \param destState Radio state to switch to. + * + * Concrete subclasses of this base class must implement this method. + */ + virtual void DoUpdateRemainingEnergy (const RadioState destState) = 0; +}; + +}; // namespace ns3 + +#endif /* RADIO_ENERGY_MODEL_H */ diff --git a/src/contrib/energy/test/basic-energy-model-test.cc b/src/contrib/energy/test/basic-energy-model-test.cc new file mode 100644 index 000000000..a248e82df --- /dev/null +++ b/src/contrib/energy/test/basic-energy-model-test.cc @@ -0,0 +1,358 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: He Wu + */ + +#include "ns3/basic-energy-source.h" +#include "ns3/basic-radio-energy-model.h" +#include "ns3/basic-energy-source-helper.h" +#include "ns3/basic-radio-energy-model-helper.h" +#include "ns3/log.h" +#include "ns3/test.h" +#include "ns3/node.h" +#include "ns3/simulator.h" +#include "ns3/double.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("BasicEnergyModelTestSuite"); + +/** + * Test case of update remaining energy for BasicEnergySource and + * BasicRadioEnergyModel. + */ +class BasicEnergyUpdateTest : public TestCase +{ +public: + BasicEnergyUpdateTest (); + virtual ~BasicEnergyUpdateTest (); + +private: + bool DoRun (void); + + /** + * \param state Radio state to switch to. + * \return False if no error occurs. + * + * Runs simulation for a while, check if final state & remaining energy is + * correctly updated. + */ + bool StateSwitchTest (RadioEnergyModel::RadioState state); + +private: + double m_timeS; // in seconds + double m_tolerance; // tolerance for power estimation + + ObjectFactory m_energySource; + ObjectFactory m_deviceEnergyModel; +}; + +BasicEnergyUpdateTest::BasicEnergyUpdateTest () + : TestCase ("Basic energy model update remaining energy test case") +{ + m_timeS = 15.5; // idle for 15 seconds before changing state + m_tolerance = 1.0e-13; // +} + +BasicEnergyUpdateTest::~BasicEnergyUpdateTest () +{ +} + +bool +BasicEnergyUpdateTest::DoRun (void) +{ + // set types + m_energySource.SetTypeId ("ns3::BasicEnergySource"); + m_deviceEnergyModel.SetTypeId ("ns3::BasicRadioEnergyModel"); + + // run state switch tests + if (StateSwitchTest (RadioEnergyModel::TX)) + { + return true; + } + if (StateSwitchTest (RadioEnergyModel::RX)) + { + return true; + } + if (StateSwitchTest (RadioEnergyModel::IDLE)) + { + return true; + } + if (StateSwitchTest (RadioEnergyModel::SLEEP)) + { + return true; + } + + // error free + return false; +} + +bool +BasicEnergyUpdateTest::StateSwitchTest ( + RadioEnergyModel::RadioState state) +{ + // create node + Ptr node = CreateObject (); + + // create energy source + Ptr source = m_energySource.Create (); + // aggregate energy source to node + node->AggregateObject (source); + + // create device energy model + Ptr model = + m_deviceEnergyModel.Create (); + // set energy source pointer + model->SetEnergySource (source); + // add device energy model to model list in energy source + source->AppendDeviceEnergyModel (model); + + // retrieve device energy model from energy source + EnergySource::DeviceEnergyModelList modelList = + source->FindDeviceEnergyModels ("ns3::BasicRadioEnergyModel"); + // check list + NS_TEST_ASSERT_MSG_EQ (false, modelList.empty (), "Model list is empty!"); + // get pointer + Ptr devModel = + DynamicCast (modelList[0]); + // check pointer + NS_TEST_ASSERT_MSG_NE (NULL, devModel, "NULL pointer to device model!"); + + // schedule change of state + Simulator::Schedule (Seconds (m_timeS), + &BasicRadioEnergyModel::UpdateRemainingEnergy, devModel, state); + + // run simulation + Simulator::Stop (Seconds (m_timeS * 2)); // run twice as long + Simulator::Run (); + Simulator::Destroy (); + + // calculate estimated remaining energy + double estRemainingEnergy = source->GetInitialEnergy (); + estRemainingEnergy -= devModel->GetIdlePowerW () * m_timeS; + /* + * Energy is updated periodically, hence we have to take into account of the + * update interval. + */ + double actualTime = m_timeS; + actualTime /= devModel->GetEnergyUpdateInterval ().GetSeconds (); + actualTime = floor (actualTime); // rounding for update interval + actualTime *= devModel->GetEnergyUpdateInterval ().GetSeconds (); + switch (state) + { + case RadioEnergyModel::TX: + estRemainingEnergy -= devModel->GetTxPowerW () * actualTime; + break; + case RadioEnergyModel::RX: + estRemainingEnergy -= devModel->GetRxPowerW () * actualTime; + break; + case RadioEnergyModel::IDLE: + estRemainingEnergy -= devModel->GetIdlePowerW () * actualTime; + break; + case RadioEnergyModel::SLEEP: + estRemainingEnergy -= devModel->GetSleepPowerW () * actualTime; + break; + default: + break; + } + // obtain remaining energy + double remainingEnergy = source->GetRemainingEnergy (); + NS_LOG_UNCOND ("Remaining energy is " << remainingEnergy << "\n" + << "Estimated remaining energy is " << estRemainingEnergy << "\n" + << "Difference is " << estRemainingEnergy - remainingEnergy); + // check remaining energy + NS_TEST_ASSERT_MSG_EQ_TOL (remainingEnergy, estRemainingEnergy, m_tolerance, + "Incorrect remaining energy!"); + + + // obtain radio state + RadioEnergyModel::RadioState endState = devModel->GetCurrentState (); + NS_LOG_UNCOND ("Radio state is " << endState); + // check end state + NS_TEST_ASSERT_MSG_EQ (endState, state, "Incorrect end state!"); + + return false; // no error +} + +// ----------------------------------------------------------------------------// + +/** + * Test case of energy depletion handling for BasicEnergySource and + * BasicRadioEnergyModel. + */ +class BasicEnergyDepletionTest : public TestCase +{ +public: + BasicEnergyDepletionTest (); + virtual ~BasicEnergyDepletionTest (); + +private: + bool DoRun (void); + + // / Callback invoked when energy is drained from source. + void DepletionHandler (void); + + /** + * \param simTimeS Simulation time, in seconds. + * \param updateIntervalS Device model update interval, in seconds. + * \return False if all is good. + * + * Runs simulation with specified simulation time and update interval. + */ + bool DepletionTestCase (double simTimeS, double updateIntervalS); + +private: + int m_numOfModels; // number of BasicRadioEnergyModel to install + int m_callbackCount; // counter for # of callbacks invoked + double m_simTimeS; // maximum simulation time, in seconds + double m_timeStepS; // simulation time step size, in seconds + double m_updateIntervalS; // update interval of each device model + +}; + +BasicEnergyDepletionTest::BasicEnergyDepletionTest () + : TestCase ("Basic energy model energy depletion test case") +{ + m_numOfModels = 10; + m_callbackCount = 0; + m_simTimeS = 4.5; + m_timeStepS = 0.5; + m_updateIntervalS = 1.5; +} + +BasicEnergyDepletionTest::~BasicEnergyDepletionTest () +{ +} + +bool +BasicEnergyDepletionTest::DoRun (void) +{ + /* + * Run simulation with different simulation time and update interval. + */ + for (double simTimeS = 0.0; simTimeS <= m_simTimeS; simTimeS += m_timeStepS) + { + for (double updateIntervalS = 0.5; updateIntervalS <= m_updateIntervalS; + updateIntervalS += m_timeStepS) + { + if (DepletionTestCase (simTimeS, updateIntervalS)) + { + return true; + } + // reset callback count + m_callbackCount = 0; + } + } + // error free + return false; +} + +void +BasicEnergyDepletionTest::DepletionHandler (void) +{ + m_callbackCount++; +} + +bool +BasicEnergyDepletionTest::DepletionTestCase (double simTimeS, + double updateIntervalS) +{ + // create node + Ptr node = CreateObject (); + + /* + * Create and install energy source and a single basic radio energy model on + * the node using helpers. + */ + // source helper + BasicEnergySourceHelper basicSourceHelper; + // set energy to 0 so that we deplete energy at the beginning of simulation + basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (0.0)); + // device energy model helper + BasicRadioEnergyModelHelper radioEnergyHelper; + // set update interval + Time updateInterval = Seconds (1.0); + radioEnergyHelper.Set ("PeriodicEnergyUpdateInterval", + TimeValue (Seconds (updateIntervalS))); + // set energy depletion callback + BasicRadioEnergyModel::BasicEnergyDepletionCallback callback = + MakeCallback (&BasicEnergyDepletionTest::DepletionHandler, this); + radioEnergyHelper.SetDepletionCallback (callback); + // energy model helper + EnergyModelHelper energyHelper; + // install on node + energyHelper.Install (basicSourceHelper, radioEnergyHelper, node); + + // Install more basic radio energy models onto the same node, using helper + for (int i = 1; i < m_numOfModels; i++) + { + radioEnergyHelper.Install (node); + } + + // run simulation + Simulator::Stop (Seconds (simTimeS)); + Simulator::Run (); + Simulator::Destroy (); + + /* + * Calculate total number of callbacks invoked. Taking the ceiling instead of + * the floor here because initial update is at time = 0. + */ + double tmp = ceil (simTimeS / updateIntervalS); + int numOfUpdates = (tmp == 0) ? 1 : tmp; + /* + * Every update will trigger *all* DeviceEnergyModels to react, therefore the + * total count should be numOfUpdates * m_numOfModels ^ 2 + */ + int totalCallbackCount = numOfUpdates * m_numOfModels * m_numOfModels; + + NS_LOG_UNCOND ("Simulation time = " << simTimeS << "s\n" + << "Update interval = " << updateIntervalS << "s\n" + << "Calculated callback count is " << totalCallbackCount << "\n" + << "Actual callback count is " << m_callbackCount); + + // check result + NS_TEST_ASSERT_MSG_EQ (totalCallbackCount, m_callbackCount, + "Not all callbacks are invoked!"); + + return false; +} + +// ----------------------------------------------------------------------------// + +/** + * Unit test suite for energy model. Although the test suite involves 2 modules + * it is still considered a unit test. Because a DeviceEnergyModel cannot live + * without an EnergySource. + */ +class BasicEnergyModelTestSuite : public TestSuite +{ +public: + BasicEnergyModelTestSuite (); +}; + +BasicEnergyModelTestSuite::BasicEnergyModelTestSuite () + : TestSuite ("devices-basic-energy-model", UNIT) +{ + AddTestCase (new BasicEnergyUpdateTest); + AddTestCase (new BasicEnergyDepletionTest); +} + +// create an instance of the test suite +BasicEnergyModelTestSuite g_energyModelTestSuite; diff --git a/src/contrib/energy/wscript b/src/contrib/energy/wscript new file mode 100644 index 000000000..800b036da --- /dev/null +++ b/src/contrib/energy/wscript @@ -0,0 +1,28 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def build(bld): + obj = bld.create_ns3_module('energy', ['node']) + obj.source = [ + 'model/radio-energy-model.cc', + 'model/basic-radio-energy-model.cc', + 'model/energy-source.cc', + 'model/basic-energy-source.cc', + 'model/device-energy-model.cc', + 'helper/energy-model-helper.cc', + 'helper/basic-energy-source-helper.cc', + 'helper/basic-radio-energy-model-helper.cc', + 'test/basic-energy-model-test.cc', + ] + headers = bld.new_task_gen('ns3header') + headers.module = 'energy' + headers.source = [ + 'model/radio-energy-model.h', + 'model/basic-radio-energy-model.h', + 'model/energy-source.h', + 'model/basic-energy-source.h', + 'model/device-energy-model.h', + 'helper/energy-model-helper.h', + 'helper/basic-energy-source-helper.h', + 'helper/basic-radio-energy-model-helper.h', + ] + diff --git a/src/wscript b/src/wscript index e5a6780e4..b833636c7 100644 --- a/src/wscript +++ b/src/wscript @@ -60,6 +60,7 @@ all_modules = ( 'devices/wimax', 'mpi', 'contrib/topology-read', + 'contrib/energy', ) def set_options(opt):