diff --git a/bindings/python/ns3_module_bridge.py b/bindings/python/ns3_module_bridge.py index 013863812..647193174 100644 --- a/bindings/python/ns3_module_bridge.py +++ b/bindings/python/ns3_module_bridge.py @@ -103,16 +103,6 @@ def register_Ns3BridgeNetDevice_methods(root_module, cls): 'ns3::Ptr< ns3::NetDevice >', [param('uint32_t', 'n')], is_const=True) - ## bridge-net-device.h: void ns3::BridgeNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## bridge-net-device.h: std::string ns3::BridgeNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## bridge-net-device.h: void ns3::BridgeNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_core.py b/bindings/python/ns3_module_core.py index 71322205c..e108eba13 100644 --- a/bindings/python/ns3_module_core.py +++ b/bindings/python/ns3_module_core.py @@ -115,8 +115,12 @@ def register_types(module): module.add_class('EnumChecker', parent=root_module['ns3::AttributeChecker']) ## enum.h: ns3::EnumValue [class] module.add_class('EnumValue', parent=root_module['ns3::AttributeValue']) + ## random-variable.h: ns3::ErlangVariable [class] + module.add_class('ErlangVariable', parent=root_module['ns3::RandomVariable']) ## random-variable.h: ns3::ExponentialVariable [class] module.add_class('ExponentialVariable', parent=root_module['ns3::RandomVariable']) + ## random-variable.h: ns3::GammaVariable [class] + module.add_class('GammaVariable', parent=root_module['ns3::RandomVariable']) ## random-variable.h: ns3::IntEmpiricalVariable [class] module.add_class('IntEmpiricalVariable', parent=root_module['ns3::EmpiricalVariable']) ## integer.h: ns3::IntegerValue [class] @@ -261,7 +265,9 @@ def register_methods(root_module): register_Ns3EmptyAttributeValue_methods(root_module, root_module['ns3::EmptyAttributeValue']) register_Ns3EnumChecker_methods(root_module, root_module['ns3::EnumChecker']) register_Ns3EnumValue_methods(root_module, root_module['ns3::EnumValue']) + register_Ns3ErlangVariable_methods(root_module, root_module['ns3::ErlangVariable']) register_Ns3ExponentialVariable_methods(root_module, root_module['ns3::ExponentialVariable']) + register_Ns3GammaVariable_methods(root_module, root_module['ns3::GammaVariable']) register_Ns3IntEmpiricalVariable_methods(root_module, root_module['ns3::IntEmpiricalVariable']) register_Ns3IntegerValue_methods(root_module, root_module['ns3::IntegerValue']) register_Ns3LogNormalVariable_methods(root_module, root_module['ns3::LogNormalVariable']) @@ -1497,6 +1503,25 @@ def register_Ns3EnumValue_methods(root_module, cls): is_virtual=True) return +def register_Ns3ErlangVariable_methods(root_module, cls): + ## random-variable.h: ns3::ErlangVariable::ErlangVariable(ns3::ErlangVariable const & arg0) [copy constructor] + cls.add_constructor([param('ns3::ErlangVariable const &', 'arg0')]) + ## random-variable.h: ns3::ErlangVariable::ErlangVariable() [constructor] + cls.add_constructor([]) + ## random-variable.h: ns3::ErlangVariable::ErlangVariable(unsigned int k, double lambda) [constructor] + cls.add_constructor([param('unsigned int', 'k'), param('double', 'lambda')]) + ## random-variable.h: double ns3::ErlangVariable::GetValue() const [member function] + cls.add_method('GetValue', + 'double', + [], + is_const=True) + ## random-variable.h: double ns3::ErlangVariable::GetValue(unsigned int k, double lambda) const [member function] + cls.add_method('GetValue', + 'double', + [param('unsigned int', 'k'), param('double', 'lambda')], + is_const=True) + return + def register_Ns3ExponentialVariable_methods(root_module, cls): ## random-variable.h: ns3::ExponentialVariable::ExponentialVariable(ns3::ExponentialVariable const & arg0) [copy constructor] cls.add_constructor([param('ns3::ExponentialVariable const &', 'arg0')]) @@ -1508,6 +1533,25 @@ def register_Ns3ExponentialVariable_methods(root_module, cls): cls.add_constructor([param('double', 'm'), param('double', 'b')]) return +def register_Ns3GammaVariable_methods(root_module, cls): + ## random-variable.h: ns3::GammaVariable::GammaVariable(ns3::GammaVariable const & arg0) [copy constructor] + cls.add_constructor([param('ns3::GammaVariable const &', 'arg0')]) + ## random-variable.h: ns3::GammaVariable::GammaVariable() [constructor] + cls.add_constructor([]) + ## random-variable.h: ns3::GammaVariable::GammaVariable(double alpha, double beta) [constructor] + cls.add_constructor([param('double', 'alpha'), param('double', 'beta')]) + ## random-variable.h: double ns3::GammaVariable::GetValue() const [member function] + cls.add_method('GetValue', + 'double', + [], + is_const=True) + ## random-variable.h: double ns3::GammaVariable::GetValue(double alpha, double beta) const [member function] + cls.add_method('GetValue', + 'double', + [param('double', 'alpha'), param('double', 'beta')], + is_const=True) + return + def register_Ns3IntEmpiricalVariable_methods(root_module, cls): ## random-variable.h: ns3::IntEmpiricalVariable::IntEmpiricalVariable(ns3::IntEmpiricalVariable const & arg0) [copy constructor] cls.add_constructor([param('ns3::IntEmpiricalVariable const &', 'arg0')]) @@ -1984,7 +2028,7 @@ def register_Ns3TracedValue__Unsigned_int_methods(root_module, cls): cls.add_method('ConnectWithoutContext', 'void', [param('ns3::CallbackBase const &', 'cb')]) - ## traced-value.h: void ns3::TracedValue::Connect(ns3::CallbackBase const & cb, std::basic_string,std::allocator > path) [member function] + ## traced-value.h: void ns3::TracedValue::Connect(ns3::CallbackBase const & cb, std::string path) [member function] cls.add_method('Connect', 'void', [param('ns3::CallbackBase const &', 'cb'), param('std::string', 'path')]) @@ -1992,7 +2036,7 @@ def register_Ns3TracedValue__Unsigned_int_methods(root_module, cls): cls.add_method('DisconnectWithoutContext', 'void', [param('ns3::CallbackBase const &', 'cb')]) - ## traced-value.h: void ns3::TracedValue::Disconnect(ns3::CallbackBase const & cb, std::basic_string,std::allocator > path) [member function] + ## traced-value.h: void ns3::TracedValue::Disconnect(ns3::CallbackBase const & cb, std::string path) [member function] cls.add_method('Disconnect', 'void', [param('ns3::CallbackBase const &', 'cb'), param('std::string', 'path')]) @@ -2140,7 +2184,7 @@ def register_functions(root_module): module.add_function('TypeNameGet', 'std::string', [], - template_parameters=['long']) + template_parameters=['long long']) ## type-name.h: extern std::string ns3::TypeNameGet() [free function] module.add_function('TypeNameGet', 'std::string', @@ -2160,7 +2204,7 @@ def register_functions(root_module): module.add_function('TypeNameGet', 'std::string', [], - template_parameters=['unsigned long']) + template_parameters=['unsigned long long']) ## type-name.h: extern std::string ns3::TypeNameGet() [free function] module.add_function('TypeNameGet', 'std::string', diff --git a/bindings/python/ns3_module_csma.py b/bindings/python/ns3_module_csma.py index 17494ae9e..d7e8e9b4f 100644 --- a/bindings/python/ns3_module_csma.py +++ b/bindings/python/ns3_module_csma.py @@ -273,16 +273,6 @@ def register_Ns3CsmaNetDevice_methods(root_module, cls): cls.add_method('GetEncapsulationMode', 'ns3::CsmaNetDevice::EncapsulationMode', []) - ## csma-net-device.h: void ns3::CsmaNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## csma-net-device.h: std::string ns3::CsmaNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## csma-net-device.h: void ns3::CsmaNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_emu.py b/bindings/python/ns3_module_emu.py index 54ffede89..4fa5d12a1 100644 --- a/bindings/python/ns3_module_emu.py +++ b/bindings/python/ns3_module_emu.py @@ -80,16 +80,6 @@ def register_Ns3EmuNetDevice_methods(root_module, cls): cls.add_method('SetAddress', 'void', [param('ns3::Mac48Address', 'addr')]) - ## emu-net-device.h: void ns3::EmuNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## emu-net-device.h: std::string ns3::EmuNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## emu-net-device.h: void ns3::EmuNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_node.py b/bindings/python/ns3_module_node.py index b214fcda6..5b08a1038 100644 --- a/bindings/python/ns3_module_node.py +++ b/bindings/python/ns3_module_node.py @@ -133,6 +133,8 @@ def register_types(module): module.add_class('SimpleChannel', parent=root_module['ns3::Channel']) ## simple-net-device.h: ns3::SimpleNetDevice [class] module.add_class('SimpleNetDevice', parent=root_module['ns3::NetDevice']) + module.add_container('ns3::olsr::MprSet', 'ns3::Ipv4Address', container_type='set') + module.add_container('std::vector< ns3::Ipv4Address >', 'ns3::Ipv4Address', container_type='vector') ## Register a nested module for the namespace Config @@ -173,7 +175,6 @@ def register_types_ns3_internal(module): def register_types_ns3_olsr(module): root_module = module.get_root() - module.add_container('std::vector< ns3::Ipv4Address >', 'ns3::Ipv4Address', container_type='vector') def register_methods(root_module): register_Ns3Address_methods(root_module, root_module['ns3::Address']) @@ -2310,16 +2311,6 @@ def register_Ns3Channel_methods(root_module, cls): is_static=True) ## channel.h: ns3::Channel::Channel() [constructor] cls.add_constructor([]) - ## channel.h: ns3::Channel::Channel(std::string name) [constructor] - cls.add_constructor([param('std::string', 'name')]) - ## channel.h: void ns3::Channel::SetName(std::string arg0) [member function] - cls.add_method('SetName', - 'void', - [param('std::string', 'arg0')]) - ## channel.h: std::string ns3::Channel::GetName() [member function] - cls.add_method('GetName', - 'std::string', - []) ## channel.h: uint32_t ns3::Channel::GetNDevices() const [member function] cls.add_method('GetNDevices', 'uint32_t', @@ -2749,16 +2740,6 @@ def register_Ns3NetDevice_methods(root_module, cls): 'ns3::TypeId', [], is_static=True) - ## net-device.h: void ns3::NetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_pure_virtual=True, is_virtual=True) - ## net-device.h: std::string ns3::NetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_pure_virtual=True, is_const=True, is_virtual=True) ## net-device.h: void ns3::NetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', @@ -3015,16 +2996,6 @@ def register_Ns3SimpleNetDevice_methods(root_module, cls): cls.add_method('SetAddress', 'void', [param('ns3::Mac48Address', 'address')]) - ## simple-net-device.h: void ns3::SimpleNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## simple-net-device.h: std::string ns3::SimpleNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## simple-net-device.h: void ns3::SimpleNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_olsr.py b/bindings/python/ns3_module_olsr.py index 7f269fbef..7e7b633cd 100644 --- a/bindings/python/ns3_module_olsr.py +++ b/bindings/python/ns3_module_olsr.py @@ -3,6 +3,14 @@ from pybindgen import Module, FileCodeSink, param, retval, cppclass def register_types(module): root_module = module.get_root() + ## olsr-state.h: ns3::OlsrState [class] + module.add_class('OlsrState') + module.add_container('std::vector< ns3::olsr::MprSelectorTuple >', 'ns3::olsr::MprSelectorTuple', container_type='vector') + module.add_container('std::vector< ns3::olsr::NeighborTuple >', 'ns3::olsr::NeighborTuple', container_type='vector') + module.add_container('std::vector< ns3::olsr::TwoHopNeighborTuple >', 'ns3::olsr::TwoHopNeighborTuple', container_type='vector') + module.add_container('std::vector< ns3::olsr::LinkTuple >', 'ns3::olsr::LinkTuple', container_type='vector') + module.add_container('std::vector< ns3::olsr::TopologyTuple >', 'ns3::olsr::TopologyTuple', container_type='vector') + module.add_container('std::vector< ns3::olsr::IfaceAssocTuple >', 'ns3::olsr::IfaceAssocTuple', container_type='vector') ## Register a nested module for the namespace Config @@ -43,8 +51,12 @@ def register_types_ns3_internal(module): def register_types_ns3_olsr(module): root_module = module.get_root() - ## olsr-agent.h: ns3::olsr::Agent [class] - module.add_class('Agent', parent=root_module['ns3::Object']) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple [struct] + module.add_class('DuplicateTuple') + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple [struct] + module.add_class('IfaceAssocTuple') + ## olsr-repositories.h: ns3::olsr::LinkTuple [struct] + module.add_class('LinkTuple') ## olsr-header.h: ns3::olsr::MessageHeader [class] module.add_class('MessageHeader', parent=root_module['ns3::Header']) ## olsr-header.h: ns3::olsr::MessageHeader::MessageType [enumeration] @@ -61,18 +73,30 @@ def register_types_ns3_olsr(module): module.add_class('Mid', outer_class=root_module['ns3::olsr::MessageHeader']) ## olsr-header.h: ns3::olsr::MessageHeader::Tc [struct] module.add_class('Tc', outer_class=root_module['ns3::olsr::MessageHeader']) + ## olsr-repositories.h: ns3::olsr::MprSelectorTuple [struct] + module.add_class('MprSelectorTuple') + ## olsr-repositories.h: ns3::olsr::NeighborTuple [struct] + module.add_class('NeighborTuple') + ## olsr-repositories.h: ns3::olsr::NeighborTuple::Status [enumeration] + module.add_enum('Status', ['STATUS_NOT_SYM', 'STATUS_SYM'], outer_class=root_module['ns3::olsr::NeighborTuple']) ## olsr-header.h: ns3::olsr::PacketHeader [class] module.add_class('PacketHeader', parent=root_module['ns3::Header']) - ## olsr-routing-table.h: ns3::olsr::RoutingTable [class] - module.add_class('RoutingTable', parent=root_module['ns3::Ipv4RoutingProtocol']) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry [struct] + ## olsr-routing-protocol.h: ns3::olsr::RoutingProtocol [class] + module.add_class('RoutingProtocol', parent=root_module['ns3::Ipv4RoutingProtocol']) + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry [struct] module.add_class('RoutingTableEntry') + ## olsr-repositories.h: ns3::olsr::TopologyTuple [struct] + module.add_class('TopologyTuple') + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple [struct] + module.add_class('TwoHopNeighborTuple') module.add_container('std::vector< ns3::olsr::MessageHeader::Hello::LinkMessage >', 'ns3::olsr::MessageHeader::Hello::LinkMessage', container_type='vector') module.add_container('std::vector< ns3::olsr::MessageHeader::Hna::Association >', 'ns3::olsr::MessageHeader::Hna::Association', container_type='vector') - module.add_container('std::vector< ns3::olsr::RoutingTableEntry >', 'ns3::olsr::RoutingTableEntry', container_type='vector') def register_methods(root_module): - register_Ns3OlsrAgent_methods(root_module, root_module['ns3::olsr::Agent']) + register_Ns3OlsrState_methods(root_module, root_module['ns3::OlsrState']) + register_Ns3OlsrDuplicateTuple_methods(root_module, root_module['ns3::olsr::DuplicateTuple']) + register_Ns3OlsrIfaceAssocTuple_methods(root_module, root_module['ns3::olsr::IfaceAssocTuple']) + register_Ns3OlsrLinkTuple_methods(root_module, root_module['ns3::olsr::LinkTuple']) register_Ns3OlsrMessageHeader_methods(root_module, root_module['ns3::olsr::MessageHeader']) register_Ns3OlsrMessageHeaderHello_methods(root_module, root_module['ns3::olsr::MessageHeader::Hello']) register_Ns3OlsrMessageHeaderHelloLinkMessage_methods(root_module, root_module['ns3::olsr::MessageHeader::Hello::LinkMessage']) @@ -80,41 +104,258 @@ def register_methods(root_module): register_Ns3OlsrMessageHeaderHnaAssociation_methods(root_module, root_module['ns3::olsr::MessageHeader::Hna::Association']) register_Ns3OlsrMessageHeaderMid_methods(root_module, root_module['ns3::olsr::MessageHeader::Mid']) register_Ns3OlsrMessageHeaderTc_methods(root_module, root_module['ns3::olsr::MessageHeader::Tc']) + register_Ns3OlsrMprSelectorTuple_methods(root_module, root_module['ns3::olsr::MprSelectorTuple']) + register_Ns3OlsrNeighborTuple_methods(root_module, root_module['ns3::olsr::NeighborTuple']) register_Ns3OlsrPacketHeader_methods(root_module, root_module['ns3::olsr::PacketHeader']) - register_Ns3OlsrRoutingTable_methods(root_module, root_module['ns3::olsr::RoutingTable']) + register_Ns3OlsrRoutingProtocol_methods(root_module, root_module['ns3::olsr::RoutingProtocol']) register_Ns3OlsrRoutingTableEntry_methods(root_module, root_module['ns3::olsr::RoutingTableEntry']) + register_Ns3OlsrTopologyTuple_methods(root_module, root_module['ns3::olsr::TopologyTuple']) + register_Ns3OlsrTwoHopNeighborTuple_methods(root_module, root_module['ns3::olsr::TwoHopNeighborTuple']) return -def register_Ns3OlsrAgent_methods(root_module, cls): - ## olsr-agent.h: ns3::olsr::Agent::Agent(ns3::olsr::Agent const & arg0) [copy constructor] - cls.add_constructor([param('ns3::olsr::Agent const &', 'arg0')]) - ## olsr-agent.h: ns3::olsr::Agent::Agent() [constructor] +def register_Ns3OlsrState_methods(root_module, cls): + ## olsr-state.h: ns3::OlsrState::OlsrState(ns3::OlsrState const & arg0) [copy constructor] + cls.add_constructor([param('ns3::OlsrState const &', 'arg0')]) + ## olsr-state.h: ns3::OlsrState::OlsrState() [constructor] cls.add_constructor([]) - ## olsr-agent.h: static ns3::TypeId ns3::olsr::Agent::GetTypeId() [member function] - cls.add_method('GetTypeId', - 'ns3::TypeId', + ## olsr-state.h: ns3::olsr::MprSelectorSet const & ns3::OlsrState::GetMprSelectors() const [member function] + cls.add_method('GetMprSelectors', + 'ns3::olsr::MprSelectorSet const &', [], - is_static=True) - ## olsr-agent.h: void ns3::olsr::Agent::SetNode(ns3::Ptr node) [member function] - cls.add_method('SetNode', + is_const=True) + ## olsr-state.h: ns3::olsr::MprSelectorTuple * ns3::OlsrState::FindMprSelectorTuple(ns3::Ipv4Address const & mainAddr) [member function] + cls.add_method('FindMprSelectorTuple', + 'ns3::olsr::MprSelectorTuple *', + [param('ns3::Ipv4Address const &', 'mainAddr')]) + ## olsr-state.h: void ns3::OlsrState::EraseMprSelectorTuple(ns3::olsr::MprSelectorTuple const & tuple) [member function] + cls.add_method('EraseMprSelectorTuple', 'void', - [param('ns3::Ptr< ns3::Node >', 'node')], - is_pure_virtual=True, is_virtual=True) - ## olsr-agent.h: void ns3::olsr::Agent::SetMainInterface(uint32_t interface) [member function] - cls.add_method('SetMainInterface', + [param('ns3::olsr::MprSelectorTuple const &', 'tuple')]) + ## olsr-state.h: void ns3::OlsrState::EraseMprSelectorTuples(ns3::Ipv4Address const & mainAddr) [member function] + cls.add_method('EraseMprSelectorTuples', 'void', - [param('uint32_t', 'interface')], - is_pure_virtual=True, is_virtual=True) - ## olsr-agent.h: void ns3::olsr::Agent::Start() [member function] - cls.add_method('Start', + [param('ns3::Ipv4Address const &', 'mainAddr')]) + ## olsr-state.h: void ns3::OlsrState::InsertMprSelectorTuple(ns3::olsr::MprSelectorTuple const & tuple) [member function] + cls.add_method('InsertMprSelectorTuple', 'void', + [param('ns3::olsr::MprSelectorTuple const &', 'tuple')]) + ## olsr-state.h: std::string ns3::OlsrState::PrintMprSelectorSet() const [member function] + cls.add_method('PrintMprSelectorSet', + 'std::string', [], - is_pure_virtual=True, is_virtual=True) - ## olsr-agent.h: ns3::Ptr ns3::olsr::Agent::GetRoutingTable() const [member function] - cls.add_method('GetRoutingTable', - 'ns3::Ptr< ns3::olsr::RoutingTable const >', + is_const=True) + ## olsr-state.h: ns3::olsr::NeighborSet const & ns3::OlsrState::GetNeighbors() const [member function] + cls.add_method('GetNeighbors', + 'ns3::olsr::NeighborSet const &', [], - is_pure_virtual=True, is_const=True, is_virtual=True) + is_const=True) + ## olsr-state.h: ns3::olsr::NeighborSet & ns3::OlsrState::GetNeighbors() [member function] + cls.add_method('GetNeighbors', + 'ns3::olsr::NeighborSet &', + []) + ## olsr-state.h: ns3::olsr::NeighborTuple * ns3::OlsrState::FindNeighborTuple(ns3::Ipv4Address const & mainAddr) [member function] + cls.add_method('FindNeighborTuple', + 'ns3::olsr::NeighborTuple *', + [param('ns3::Ipv4Address const &', 'mainAddr')]) + ## olsr-state.h: ns3::olsr::NeighborTuple const * ns3::OlsrState::FindSymNeighborTuple(ns3::Ipv4Address const & mainAddr) const [member function] + cls.add_method('FindSymNeighborTuple', + 'ns3::olsr::NeighborTuple const *', + [param('ns3::Ipv4Address const &', 'mainAddr')], + is_const=True) + ## olsr-state.h: ns3::olsr::NeighborTuple * ns3::OlsrState::FindNeighborTuple(ns3::Ipv4Address const & mainAddr, uint8_t willingness) [member function] + cls.add_method('FindNeighborTuple', + 'ns3::olsr::NeighborTuple *', + [param('ns3::Ipv4Address const &', 'mainAddr'), param('uint8_t', 'willingness')]) + ## olsr-state.h: void ns3::OlsrState::EraseNeighborTuple(ns3::olsr::NeighborTuple const & neighborTuple) [member function] + cls.add_method('EraseNeighborTuple', + 'void', + [param('ns3::olsr::NeighborTuple const &', 'neighborTuple')]) + ## olsr-state.h: void ns3::OlsrState::EraseNeighborTuple(ns3::Ipv4Address const & mainAddr) [member function] + cls.add_method('EraseNeighborTuple', + 'void', + [param('ns3::Ipv4Address const &', 'mainAddr')]) + ## olsr-state.h: void ns3::OlsrState::InsertNeighborTuple(ns3::olsr::NeighborTuple const & tuple) [member function] + cls.add_method('InsertNeighborTuple', + 'void', + [param('ns3::olsr::NeighborTuple const &', 'tuple')]) + ## olsr-state.h: ns3::olsr::TwoHopNeighborSet const & ns3::OlsrState::GetTwoHopNeighbors() const [member function] + cls.add_method('GetTwoHopNeighbors', + 'ns3::olsr::TwoHopNeighborSet const &', + [], + is_const=True) + ## olsr-state.h: ns3::olsr::TwoHopNeighborSet & ns3::OlsrState::GetTwoHopNeighbors() [member function] + cls.add_method('GetTwoHopNeighbors', + 'ns3::olsr::TwoHopNeighborSet &', + []) + ## olsr-state.h: ns3::olsr::TwoHopNeighborTuple * ns3::OlsrState::FindTwoHopNeighborTuple(ns3::Ipv4Address const & neighbor, ns3::Ipv4Address const & twoHopNeighbor) [member function] + cls.add_method('FindTwoHopNeighborTuple', + 'ns3::olsr::TwoHopNeighborTuple *', + [param('ns3::Ipv4Address const &', 'neighbor'), param('ns3::Ipv4Address const &', 'twoHopNeighbor')]) + ## olsr-state.h: void ns3::OlsrState::EraseTwoHopNeighborTuple(ns3::olsr::TwoHopNeighborTuple const & tuple) [member function] + cls.add_method('EraseTwoHopNeighborTuple', + 'void', + [param('ns3::olsr::TwoHopNeighborTuple const &', 'tuple')]) + ## olsr-state.h: void ns3::OlsrState::EraseTwoHopNeighborTuples(ns3::Ipv4Address const & neighbor) [member function] + cls.add_method('EraseTwoHopNeighborTuples', + 'void', + [param('ns3::Ipv4Address const &', 'neighbor')]) + ## olsr-state.h: void ns3::OlsrState::EraseTwoHopNeighborTuples(ns3::Ipv4Address const & neighbor, ns3::Ipv4Address const & twoHopNeighbor) [member function] + cls.add_method('EraseTwoHopNeighborTuples', + 'void', + [param('ns3::Ipv4Address const &', 'neighbor'), param('ns3::Ipv4Address const &', 'twoHopNeighbor')]) + ## olsr-state.h: void ns3::OlsrState::InsertTwoHopNeighborTuple(ns3::olsr::TwoHopNeighborTuple const & tuple) [member function] + cls.add_method('InsertTwoHopNeighborTuple', + 'void', + [param('ns3::olsr::TwoHopNeighborTuple const &', 'tuple')]) + ## olsr-state.h: bool ns3::OlsrState::FindMprAddress(ns3::Ipv4Address const & address) [member function] + cls.add_method('FindMprAddress', + 'bool', + [param('ns3::Ipv4Address const &', 'address')]) + ## olsr-state.h: void ns3::OlsrState::SetMprSet(ns3::olsr::MprSet mprSet) [member function] + cls.add_method('SetMprSet', + 'void', + [param('ns3::olsr::MprSet', 'mprSet')]) + ## olsr-state.h: ns3::olsr::DuplicateTuple * ns3::OlsrState::FindDuplicateTuple(ns3::Ipv4Address const & address, uint16_t sequenceNumber) [member function] + cls.add_method('FindDuplicateTuple', + 'ns3::olsr::DuplicateTuple *', + [param('ns3::Ipv4Address const &', 'address'), param('uint16_t', 'sequenceNumber')]) + ## olsr-state.h: void ns3::OlsrState::EraseDuplicateTuple(ns3::olsr::DuplicateTuple const & tuple) [member function] + cls.add_method('EraseDuplicateTuple', + 'void', + [param('ns3::olsr::DuplicateTuple const &', 'tuple')]) + ## olsr-state.h: void ns3::OlsrState::InsertDuplicateTuple(ns3::olsr::DuplicateTuple const & tuple) [member function] + cls.add_method('InsertDuplicateTuple', + 'void', + [param('ns3::olsr::DuplicateTuple const &', 'tuple')]) + ## olsr-state.h: ns3::olsr::LinkSet const & ns3::OlsrState::GetLinks() const [member function] + cls.add_method('GetLinks', + 'ns3::olsr::LinkSet const &', + [], + is_const=True) + ## olsr-state.h: ns3::olsr::LinkTuple * ns3::OlsrState::FindLinkTuple(ns3::Ipv4Address const & ifaceAddr) [member function] + cls.add_method('FindLinkTuple', + 'ns3::olsr::LinkTuple *', + [param('ns3::Ipv4Address const &', 'ifaceAddr')]) + ## olsr-state.h: ns3::olsr::LinkTuple * ns3::OlsrState::FindSymLinkTuple(ns3::Ipv4Address const & ifaceAddr, ns3::Time time) [member function] + cls.add_method('FindSymLinkTuple', + 'ns3::olsr::LinkTuple *', + [param('ns3::Ipv4Address const &', 'ifaceAddr'), param('ns3::Time', 'time')]) + ## olsr-state.h: void ns3::OlsrState::EraseLinkTuple(ns3::olsr::LinkTuple const & tuple) [member function] + cls.add_method('EraseLinkTuple', + 'void', + [param('ns3::olsr::LinkTuple const &', 'tuple')]) + ## olsr-state.h: ns3::olsr::LinkTuple & ns3::OlsrState::InsertLinkTuple(ns3::olsr::LinkTuple const & tuple) [member function] + cls.add_method('InsertLinkTuple', + 'ns3::olsr::LinkTuple &', + [param('ns3::olsr::LinkTuple const &', 'tuple')]) + ## olsr-state.h: ns3::olsr::TopologySet const & ns3::OlsrState::GetTopologySet() const [member function] + cls.add_method('GetTopologySet', + 'ns3::olsr::TopologySet const &', + [], + is_const=True) + ## olsr-state.h: ns3::olsr::TopologyTuple * ns3::OlsrState::FindTopologyTuple(ns3::Ipv4Address const & destAddr, ns3::Ipv4Address const & lastAddr) [member function] + cls.add_method('FindTopologyTuple', + 'ns3::olsr::TopologyTuple *', + [param('ns3::Ipv4Address const &', 'destAddr'), param('ns3::Ipv4Address const &', 'lastAddr')]) + ## olsr-state.h: ns3::olsr::TopologyTuple * ns3::OlsrState::FindNewerTopologyTuple(ns3::Ipv4Address const & lastAddr, uint16_t ansn) [member function] + cls.add_method('FindNewerTopologyTuple', + 'ns3::olsr::TopologyTuple *', + [param('ns3::Ipv4Address const &', 'lastAddr'), param('uint16_t', 'ansn')]) + ## olsr-state.h: void ns3::OlsrState::EraseTopologyTuple(ns3::olsr::TopologyTuple const & tuple) [member function] + cls.add_method('EraseTopologyTuple', + 'void', + [param('ns3::olsr::TopologyTuple const &', 'tuple')]) + ## olsr-state.h: void ns3::OlsrState::EraseOlderTopologyTuples(ns3::Ipv4Address const & lastAddr, uint16_t ansn) [member function] + cls.add_method('EraseOlderTopologyTuples', + 'void', + [param('ns3::Ipv4Address const &', 'lastAddr'), param('uint16_t', 'ansn')]) + ## olsr-state.h: void ns3::OlsrState::InsertTopologyTuple(ns3::olsr::TopologyTuple const & tuple) [member function] + cls.add_method('InsertTopologyTuple', + 'void', + [param('ns3::olsr::TopologyTuple const &', 'tuple')]) + ## olsr-state.h: ns3::olsr::IfaceAssocSet const & ns3::OlsrState::GetIfaceAssocSet() const [member function] + cls.add_method('GetIfaceAssocSet', + 'ns3::olsr::IfaceAssocSet const &', + [], + is_const=True) + ## olsr-state.h: ns3::olsr::IfaceAssocSet & ns3::OlsrState::GetIfaceAssocSetMutable() [member function] + cls.add_method('GetIfaceAssocSetMutable', + 'ns3::olsr::IfaceAssocSet &', + []) + ## olsr-state.h: ns3::olsr::IfaceAssocTuple * ns3::OlsrState::FindIfaceAssocTuple(ns3::Ipv4Address const & ifaceAddr) [member function] + cls.add_method('FindIfaceAssocTuple', + 'ns3::olsr::IfaceAssocTuple *', + [param('ns3::Ipv4Address const &', 'ifaceAddr')]) + ## olsr-state.h: ns3::olsr::IfaceAssocTuple const * ns3::OlsrState::FindIfaceAssocTuple(ns3::Ipv4Address const & ifaceAddr) const [member function] + cls.add_method('FindIfaceAssocTuple', + 'ns3::olsr::IfaceAssocTuple const *', + [param('ns3::Ipv4Address const &', 'ifaceAddr')], + is_const=True) + ## olsr-state.h: void ns3::OlsrState::EraseIfaceAssocTuple(ns3::olsr::IfaceAssocTuple const & tuple) [member function] + cls.add_method('EraseIfaceAssocTuple', + 'void', + [param('ns3::olsr::IfaceAssocTuple const &', 'tuple')]) + ## olsr-state.h: void ns3::OlsrState::InsertIfaceAssocTuple(ns3::olsr::IfaceAssocTuple const & tuple) [member function] + cls.add_method('InsertIfaceAssocTuple', + 'void', + [param('ns3::olsr::IfaceAssocTuple const &', 'tuple')]) + ## olsr-state.h: std::vector > ns3::OlsrState::FindNeighborInterfaces(ns3::Ipv4Address const & neighborMainAddr) const [member function] + cls.add_method('FindNeighborInterfaces', + 'std::vector< ns3::Ipv4Address >', + [param('ns3::Ipv4Address const &', 'neighborMainAddr')], + is_const=True) + return + +def register_Ns3OlsrDuplicateTuple_methods(root_module, cls): + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::DuplicateTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::DuplicateTuple(ns3::olsr::DuplicateTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::DuplicateTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::address [variable] + cls.add_instance_attribute('address', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::expirationTime [variable] + cls.add_instance_attribute('expirationTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::ifaceList [variable] + cls.add_instance_attribute('ifaceList', 'std::vector< ns3::Ipv4Address >', is_const=False) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::retransmitted [variable] + cls.add_instance_attribute('retransmitted', 'bool', is_const=False) + ## olsr-repositories.h: ns3::olsr::DuplicateTuple::sequenceNumber [variable] + cls.add_instance_attribute('sequenceNumber', 'uint16_t', is_const=False) + return + +def register_Ns3OlsrIfaceAssocTuple_methods(root_module, cls): + cls.add_output_stream_operator() + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple::IfaceAssocTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple::IfaceAssocTuple(ns3::olsr::IfaceAssocTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::IfaceAssocTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple::ifaceAddr [variable] + cls.add_instance_attribute('ifaceAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple::mainAddr [variable] + cls.add_instance_attribute('mainAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::IfaceAssocTuple::time [variable] + cls.add_instance_attribute('time', 'ns3::Time', is_const=False) + return + +def register_Ns3OlsrLinkTuple_methods(root_module, cls): + cls.add_output_stream_operator() + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::LinkTuple::LinkTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::LinkTuple::LinkTuple(ns3::olsr::LinkTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::LinkTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::LinkTuple::asymTime [variable] + cls.add_instance_attribute('asymTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::LinkTuple::localIfaceAddr [variable] + cls.add_instance_attribute('localIfaceAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::LinkTuple::neighborIfaceAddr [variable] + cls.add_instance_attribute('neighborIfaceAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::LinkTuple::symTime [variable] + cls.add_instance_attribute('symTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::LinkTuple::time [variable] + cls.add_instance_attribute('time', 'ns3::Time', is_const=False) return def register_Ns3OlsrMessageHeader_methods(root_module, cls): @@ -394,6 +635,33 @@ def register_Ns3OlsrMessageHeaderTc_methods(root_module, cls): cls.add_instance_attribute('neighborAddresses', 'std::vector< ns3::Ipv4Address >', is_const=False) return +def register_Ns3OlsrMprSelectorTuple_methods(root_module, cls): + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::MprSelectorTuple::MprSelectorTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::MprSelectorTuple::MprSelectorTuple(ns3::olsr::MprSelectorTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::MprSelectorTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::MprSelectorTuple::expirationTime [variable] + cls.add_instance_attribute('expirationTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::MprSelectorTuple::mainAddr [variable] + cls.add_instance_attribute('mainAddr', 'ns3::Ipv4Address', is_const=False) + return + +def register_Ns3OlsrNeighborTuple_methods(root_module, cls): + cls.add_output_stream_operator() + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::NeighborTuple::NeighborTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::NeighborTuple::NeighborTuple(ns3::olsr::NeighborTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::NeighborTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::NeighborTuple::neighborMainAddr [variable] + cls.add_instance_attribute('neighborMainAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::NeighborTuple::status [variable] + cls.add_instance_attribute('status', 'ns3::olsr::NeighborTuple::Status', is_const=False) + ## olsr-repositories.h: ns3::olsr::NeighborTuple::willingness [variable] + cls.add_instance_attribute('willingness', 'uint8_t', is_const=False) + return + def register_Ns3OlsrPacketHeader_methods(root_module, cls): cls.add_output_stream_operator() ## olsr-header.h: ns3::olsr::PacketHeader::PacketHeader(ns3::olsr::PacketHeader const & arg0) [copy constructor] @@ -450,66 +718,39 @@ def register_Ns3OlsrPacketHeader_methods(root_module, cls): [param('uint16_t', 'seqnum')]) return -def register_Ns3OlsrRoutingTable_methods(root_module, cls): - ## olsr-routing-table.h: ns3::olsr::RoutingTable::RoutingTable(ns3::olsr::RoutingTable const & arg0) [copy constructor] - cls.add_constructor([param('ns3::olsr::RoutingTable const &', 'arg0')]) - ## olsr-routing-table.h: ns3::olsr::RoutingTable::RoutingTable() [constructor] +def register_Ns3OlsrRoutingProtocol_methods(root_module, cls): + ## olsr-routing-protocol.h: ns3::olsr::RoutingProtocol::RoutingProtocol(ns3::olsr::RoutingProtocol const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::RoutingProtocol const &', 'arg0')]) + ## olsr-routing-protocol.h: static ns3::TypeId ns3::olsr::RoutingProtocol::GetTypeId() [member function] + cls.add_method('GetTypeId', + 'ns3::TypeId', + [], + is_static=True) + ## olsr-routing-protocol.h: ns3::olsr::RoutingProtocol::RoutingProtocol() [constructor] cls.add_constructor([]) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::SetIpv4(ns3::Ptr ipv4) [member function] - cls.add_method('SetIpv4', + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::SetNode(ns3::Ptr node) [member function] + cls.add_method('SetNode', 'void', - [param('ns3::Ptr< ns3::Ipv4 >', 'ipv4')]) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::SetMainAddress(ns3::Ipv4Address mainAddress) [member function] - cls.add_method('SetMainAddress', - 'void', - [param('ns3::Ipv4Address', 'mainAddress')]) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::Clear() [member function] - cls.add_method('Clear', + [param('ns3::Ptr< ns3::Node >', 'node')]) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::Start() [member function] + cls.add_method('Start', 'void', []) - ## olsr-routing-table.h: uint32_t ns3::olsr::RoutingTable::GetSize() const [member function] - cls.add_method('GetSize', - 'uint32_t', - [], - is_const=True) - ## olsr-routing-table.h: std::vector > ns3::olsr::RoutingTable::GetEntries() const [member function] - cls.add_method('GetEntries', - 'std::vector< ns3::olsr::RoutingTableEntry >', - [], - is_const=True) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::RemoveEntry(ns3::Ipv4Address const & dest) [member function] - cls.add_method('RemoveEntry', + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::SetMainInterface(uint32_t interface) [member function] + cls.add_method('SetMainInterface', 'void', - [param('ns3::Ipv4Address const &', 'dest')]) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::AddEntry(ns3::Ipv4Address const & dest, ns3::Ipv4Address const & next, uint32_t interface, uint32_t distance) [member function] - cls.add_method('AddEntry', - 'void', - [param('ns3::Ipv4Address const &', 'dest'), param('ns3::Ipv4Address const &', 'next'), param('uint32_t', 'interface'), param('uint32_t', 'distance')]) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::AddEntry(ns3::Ipv4Address const & dest, ns3::Ipv4Address const & next, ns3::Ipv4Address const & interfaceAddress, uint32_t distance) [member function] - cls.add_method('AddEntry', - 'void', - [param('ns3::Ipv4Address const &', 'dest'), param('ns3::Ipv4Address const &', 'next'), param('ns3::Ipv4Address const &', 'interfaceAddress'), param('uint32_t', 'distance')]) - ## olsr-routing-table.h: bool ns3::olsr::RoutingTable::Lookup(ns3::Ipv4Address const & dest, ns3::olsr::RoutingTableEntry & outEntry) const [member function] - cls.add_method('Lookup', - 'bool', - [param('ns3::Ipv4Address const &', 'dest'), param('ns3::olsr::RoutingTableEntry &', 'outEntry')], - is_const=True) - ## olsr-routing-table.h: bool ns3::olsr::RoutingTable::FindSendEntry(ns3::olsr::RoutingTableEntry const & entry, ns3::olsr::RoutingTableEntry & outEntry) const [member function] - cls.add_method('FindSendEntry', - 'bool', - [param('ns3::olsr::RoutingTableEntry const &', 'entry'), param('ns3::olsr::RoutingTableEntry &', 'outEntry')], - is_const=True) - ## olsr-routing-table.h: bool ns3::olsr::RoutingTable::RequestRoute(uint32_t ifIndex, ns3::Ipv4Header const & ipHeader, ns3::Ptr packet, ns3::Callback,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> routeReply) [member function] + [param('uint32_t', 'interface')]) + ## olsr-routing-protocol.h: bool ns3::olsr::RoutingProtocol::RequestRoute(uint32_t ifIndex, ns3::Ipv4Header const & ipHeader, ns3::Ptr packet, ns3::Callback,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> routeReply) [member function] cls.add_method('RequestRoute', 'bool', [param('uint32_t', 'ifIndex'), param('ns3::Ipv4Header const &', 'ipHeader'), param('ns3::Ptr< ns3::Packet >', 'packet'), param('ns3::Callback< void, bool, ns3::Ipv4Route const &, ns3::Ptr< ns3::Packet >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'routeReply')], - is_virtual=True) - ## olsr-routing-table.h: bool ns3::olsr::RoutingTable::RequestIfIndex(ns3::Ipv4Address destination, uint32_t & ifIndex) [member function] + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: bool ns3::olsr::RoutingProtocol::RequestIfIndex(ns3::Ipv4Address destination, uint32_t & ifIndex) [member function] cls.add_method('RequestIfIndex', 'bool', [param('ns3::Ipv4Address', 'destination'), param('uint32_t &', 'ifIndex')], - is_virtual=True) - ## olsr-routing-table.h: void ns3::olsr::RoutingTable::DoDispose() [member function] + visibility='private', is_virtual=True) + ## olsr-routing-protocol.h: void ns3::olsr::RoutingProtocol::DoDispose() [member function] cls.add_method('DoDispose', 'void', [], @@ -517,20 +758,52 @@ def register_Ns3OlsrRoutingTable_methods(root_module, cls): return def register_Ns3OlsrRoutingTableEntry_methods(root_module, cls): - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::destAddr [variable] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::destAddr [variable] cls.add_instance_attribute('destAddr', 'ns3::Ipv4Address', is_const=False) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::nextAddr [variable] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::nextAddr [variable] cls.add_instance_attribute('nextAddr', 'ns3::Ipv4Address', is_const=False) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::interface [variable] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::interface [variable] cls.add_instance_attribute('interface', 'uint32_t', is_const=False) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::distance [variable] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::distance [variable] cls.add_instance_attribute('distance', 'uint32_t', is_const=False) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::RoutingTableEntry(ns3::olsr::RoutingTableEntry const & arg0) [copy constructor] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::RoutingTableEntry(ns3::olsr::RoutingTableEntry const & arg0) [copy constructor] cls.add_constructor([param('ns3::olsr::RoutingTableEntry const &', 'arg0')]) - ## olsr-routing-table.h: ns3::olsr::RoutingTableEntry::RoutingTableEntry() [constructor] + ## olsr-routing-protocol.h: ns3::olsr::RoutingTableEntry::RoutingTableEntry() [constructor] cls.add_constructor([]) return +def register_Ns3OlsrTopologyTuple_methods(root_module, cls): + cls.add_output_stream_operator() + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::TopologyTuple::TopologyTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::TopologyTuple::TopologyTuple(ns3::olsr::TopologyTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::TopologyTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::TopologyTuple::destAddr [variable] + cls.add_instance_attribute('destAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::TopologyTuple::expirationTime [variable] + cls.add_instance_attribute('expirationTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::TopologyTuple::lastAddr [variable] + cls.add_instance_attribute('lastAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::TopologyTuple::sequenceNumber [variable] + cls.add_instance_attribute('sequenceNumber', 'uint16_t', is_const=False) + return + +def register_Ns3OlsrTwoHopNeighborTuple_methods(root_module, cls): + cls.add_output_stream_operator() + cls.add_binary_comparison_operator('==') + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple::TwoHopNeighborTuple() [constructor] + cls.add_constructor([]) + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple::TwoHopNeighborTuple(ns3::olsr::TwoHopNeighborTuple const & arg0) [copy constructor] + cls.add_constructor([param('ns3::olsr::TwoHopNeighborTuple const &', 'arg0')]) + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple::expirationTime [variable] + cls.add_instance_attribute('expirationTime', 'ns3::Time', is_const=False) + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple::neighborMainAddr [variable] + cls.add_instance_attribute('neighborMainAddr', 'ns3::Ipv4Address', is_const=False) + ## olsr-repositories.h: ns3::olsr::TwoHopNeighborTuple::twoHopNeighborAddr [variable] + cls.add_instance_attribute('twoHopNeighborAddr', 'ns3::Ipv4Address', is_const=False) + return + def register_functions(root_module): module = root_module register_functions_ns3_Config(module.get_submodule('Config'), root_module) diff --git a/bindings/python/ns3_module_point_to_point.py b/bindings/python/ns3_module_point_to_point.py index 1541d7d25..2360f1f62 100644 --- a/bindings/python/ns3_module_point_to_point.py +++ b/bindings/python/ns3_module_point_to_point.py @@ -175,16 +175,6 @@ def register_Ns3PointToPointNetDevice_methods(root_module, cls): 'uint16_t', [], is_const=True) - ## point-to-point-net-device.h: void ns3::PointToPointNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## point-to-point-net-device.h: std::string ns3::PointToPointNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## point-to-point-net-device.h: void ns3::PointToPointNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_tap_bridge.py b/bindings/python/ns3_module_tap_bridge.py index 49b6e651f..060f909a6 100644 --- a/bindings/python/ns3_module_tap_bridge.py +++ b/bindings/python/ns3_module_tap_bridge.py @@ -86,16 +86,6 @@ def register_Ns3TapBridge_methods(root_module, cls): cls.add_method('GetMode', 'ns3::TapBridge::Mode', []) - ## tap-bridge.h: void ns3::TapBridge::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## tap-bridge.h: std::string ns3::TapBridge::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## tap-bridge.h: void ns3::TapBridge::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/ns3_module_wifi.py b/bindings/python/ns3_module_wifi.py index 564128159..383402cb2 100644 --- a/bindings/python/ns3_module_wifi.py +++ b/bindings/python/ns3_module_wifi.py @@ -228,8 +228,8 @@ def register_Ns3InterferenceHelper_methods(root_module, cls): 'ns3::Ptr< ns3::ErrorRateModel >', [], is_const=True) - ## interference-helper.h: double ns3::InterferenceHelper::GetNoiseFloorW() const [member function] - cls.add_method('GetNoiseFloorW', + ## interference-helper.h: double ns3::InterferenceHelper::GetNoiseFigure() const [member function] + cls.add_method('GetNoiseFigure', 'double', [], is_const=True) @@ -237,10 +237,10 @@ def register_Ns3InterferenceHelper_methods(root_module, cls): cls.add_method('SetErrorRateModel', 'void', [param('ns3::Ptr< ns3::ErrorRateModel >', 'rate')]) - ## interference-helper.h: void ns3::InterferenceHelper::SetNoiseFloorW(double noiseFloor) [member function] - cls.add_method('SetNoiseFloorW', + ## interference-helper.h: void ns3::InterferenceHelper::SetNoiseFigure(double value) [member function] + cls.add_method('SetNoiseFigure', 'void', - [param('double', 'noiseFloor')]) + [param('double', 'value')]) return def register_Ns3InterferenceHelperSnrPer_methods(root_module, cls): @@ -727,8 +727,8 @@ def register_Ns3AmrrWifiRemoteStation_methods(root_module, cls): def register_Ns3ArfWifiRemoteStation_methods(root_module, cls): ## arf-wifi-manager.h: ns3::ArfWifiRemoteStation::ArfWifiRemoteStation(ns3::ArfWifiRemoteStation const & arg0) [copy constructor] cls.add_constructor([param('ns3::ArfWifiRemoteStation const &', 'arg0')]) - ## arf-wifi-manager.h: ns3::ArfWifiRemoteStation::ArfWifiRemoteStation(ns3::Ptr stations, int minTimerTimeout, int minSuccessThreshold) [constructor] - cls.add_constructor([param('ns3::Ptr< ns3::ArfWifiManager >', 'stations'), param('int', 'minTimerTimeout'), param('int', 'minSuccessThreshold')]) + ## arf-wifi-manager.h: ns3::ArfWifiRemoteStation::ArfWifiRemoteStation(ns3::Ptr manager) [constructor] + cls.add_constructor([param('ns3::Ptr< ns3::ArfWifiManager >', 'manager')]) ## arf-wifi-manager.h: void ns3::ArfWifiRemoteStation::DoReportRxOk(double rxSnr, ns3::WifiMode txMode) [member function] cls.add_method('DoReportRxOk', 'void', @@ -1667,6 +1667,11 @@ def register_Ns3WifiRemoteStationManager_methods(root_module, cls): 'bool', [], is_const=True) + ## wifi-remote-station-manager.h: ns3::WifiMode ns3::WifiRemoteStationManager::GetNonUnicastMode() const [member function] + cls.add_method('GetNonUnicastMode', + 'ns3::WifiMode', + [], + is_const=True) ## wifi-remote-station-manager.h: ns3::WifiRemoteStation * ns3::WifiRemoteStationManager::Lookup(ns3::Mac48Address address) [member function] cls.add_method('Lookup', 'ns3::WifiRemoteStation *', @@ -1707,10 +1712,10 @@ def register_Ns3YansWifiPhy_methods(root_module, cls): cls.add_method('SetStandard', 'void', [param('ns3::WifiPhyStandard', 'standard')]) - ## yans-wifi-phy.h: void ns3::YansWifiPhy::SetRxNoise(double ratio) [member function] - cls.add_method('SetRxNoise', + ## yans-wifi-phy.h: void ns3::YansWifiPhy::SetRxNoiseFigure(double noiseFigureDb) [member function] + cls.add_method('SetRxNoiseFigure', 'void', - [param('double', 'ratio')]) + [param('double', 'noiseFigureDb')]) ## yans-wifi-phy.h: void ns3::YansWifiPhy::SetTxPowerStart(double start) [member function] cls.add_method('SetTxPowerStart', 'void', @@ -1751,8 +1756,8 @@ def register_Ns3YansWifiPhy_methods(root_module, cls): cls.add_method('SetMobility', 'void', [param('ns3::Ptr< ns3::Object >', 'mobility')]) - ## yans-wifi-phy.h: double ns3::YansWifiPhy::GetRxNoise() const [member function] - cls.add_method('GetRxNoise', + ## yans-wifi-phy.h: double ns3::YansWifiPhy::GetRxNoiseFigure() const [member function] + cls.add_method('GetRxNoiseFigure', 'double', [], is_const=True) @@ -1900,8 +1905,8 @@ def register_Ns3YansWifiPhy_methods(root_module, cls): def register_Ns3AarfWifiRemoteStation_methods(root_module, cls): ## aarf-wifi-manager.h: ns3::AarfWifiRemoteStation::AarfWifiRemoteStation(ns3::AarfWifiRemoteStation const & arg0) [copy constructor] cls.add_constructor([param('ns3::AarfWifiRemoteStation const &', 'arg0')]) - ## aarf-wifi-manager.h: ns3::AarfWifiRemoteStation::AarfWifiRemoteStation(ns3::Ptr stations, uint32_t minTimerThreshold, uint32_t minSuccessThreshold, double successK, uint32_t maxSuccessThreshold, double timerK) [constructor] - cls.add_constructor([param('ns3::Ptr< ns3::AarfWifiManager >', 'stations'), param('uint32_t', 'minTimerThreshold'), param('uint32_t', 'minSuccessThreshold'), param('double', 'successK'), param('uint32_t', 'maxSuccessThreshold'), param('double', 'timerK')]) + ## aarf-wifi-manager.h: ns3::AarfWifiRemoteStation::AarfWifiRemoteStation(ns3::Ptr stations) [constructor] + cls.add_constructor([param('ns3::Ptr< ns3::AarfWifiManager >', 'stations')]) ## aarf-wifi-manager.h: void ns3::AarfWifiRemoteStation::ReportRecoveryFailure() [member function] cls.add_method('ReportRecoveryFailure', 'void', @@ -1912,6 +1917,11 @@ def register_Ns3AarfWifiRemoteStation_methods(root_module, cls): 'void', [], visibility='private', is_virtual=True) + ## aarf-wifi-manager.h: ns3::Ptr ns3::AarfWifiRemoteStation::GetManager() const [member function] + cls.add_method('GetManager', + 'ns3::Ptr< ns3::WifiRemoteStationManager >', + [], + is_const=True, visibility='private', is_virtual=True) return def register_Ns3AdhocWifiMac_methods(root_module, cls): @@ -2697,16 +2707,6 @@ def register_Ns3WifiNetDevice_methods(root_module, cls): 'ns3::Ptr< ns3::WifiRemoteStationManager >', [], is_const=True) - ## wifi-net-device.h: void ns3::WifiNetDevice::SetName(std::string const name) [member function] - cls.add_method('SetName', - 'void', - [param('std::string const', 'name')], - is_virtual=True) - ## wifi-net-device.h: std::string ns3::WifiNetDevice::GetName() const [member function] - cls.add_method('GetName', - 'std::string', - [], - is_const=True, is_virtual=True) ## wifi-net-device.h: void ns3::WifiNetDevice::SetIfIndex(uint32_t const index) [member function] cls.add_method('SetIfIndex', 'void', diff --git a/bindings/python/waf b/bindings/python/waf old mode 100644 new mode 100755 diff --git a/bindings/python/wscript b/bindings/python/wscript index 89cdccfec..d33fdf381 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -273,7 +273,7 @@ class all_ns3_headers_taskgen(TaskGen.task_gen): def apply(self): ## get all of the ns3 headers - ns3_dir_node = Build.bld.path.find_dir("ns3") + ns3_dir_node = self.bld.path.find_dir("ns3") all_headers_inputs = [] for filename in self.to_list(self.source): @@ -284,7 +284,7 @@ class all_ns3_headers_taskgen(TaskGen.task_gen): ## if self.source was empty, include all ns3 headers in enabled modules if not all_headers_inputs: - for ns3headers in Build.bld.all_task_gen: + for ns3headers in self.bld.all_task_gen: if type(ns3headers).__name__ == 'ns3header_taskgen': # XXX: find less hackish way to compare ## skip headers not part of enabled modules if self.env['NS3_ENABLED_MODULES']: @@ -307,7 +307,7 @@ class all_ns3_headers_taskgen(TaskGen.task_gen): pass -def get_modules_and_headers(): +def get_modules_and_headers(bld): """ Gets a dict of module_name => ([module_dep1, module_dep2, ...], [module_header1, module_header2, ...]) @@ -315,13 +315,13 @@ def get_modules_and_headers(): """ retval = {} - for module in Build.bld.all_task_gen: + for module in bld.all_task_gen: if not module.name.startswith('ns3-'): continue module_name = module.name[4:] # strip the ns3- prefix ## find the headers object for this module headers = [] - for ns3headers in Build.bld.all_task_gen: + for ns3headers in bld.all_task_gen: if type(ns3headers).__name__ != 'ns3header_taskgen': # XXX: find less hackish way to compare continue if ns3headers.module != module_name: @@ -338,8 +338,9 @@ class python_scan_task(Task.TaskBase): """ after = 'gen_everything_h_task' before = 'cc cxx' - def __init__(self, curdirnode, env): - super(python_scan_task, self).__init__() + def __init__(self, curdirnode, env, bld): + self.bld = bld + super(python_scan_task, self).__init__(generator=self) self.curdirnode = curdirnode self.env = env @@ -356,7 +357,7 @@ class python_scan_task(Task.TaskBase): os.path.join(self.curdirnode.abspath(), 'ns3modulegen_generated.py'), # output file ] scan = subprocess.Popen(argv, stdin=subprocess.PIPE) - scan.stdin.write(repr(get_modules_and_headers())) + scan.stdin.write(repr(get_modules_and_headers(self.bld))) scan.stdin.close() retval = scan.wait() print "Scan finished with exit code", retval @@ -365,7 +366,7 @@ class python_scan_task(Task.TaskBase): # signal stop (we generated files into the source dir and WAF # can't cope with it, so we have to force the user to restart # WAF) - Build.bld.generator.stop = 1 + self.bld.generator.stop = 1 return 0 @@ -384,7 +385,7 @@ def build(bld): if Options.options.python_scan: if not env['ENABLE_PYTHON_SCANNING']: raise Utils.WafError("Cannot re-scan python bindings: (py)gccxml not available") - python_scan_task(bld.path, env) + python_scan_task(bld.path, env, bld) return ## Get a list of scanned modules; the set of scanned modules @@ -412,7 +413,7 @@ def build(bld): 'ns3modulegen.log', ] argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}', '${SRC[0]}', '${TGT[0]}'] - argv.extend(get_modules_and_headers().iterkeys()) + argv.extend(get_modules_and_headers(bld).iterkeys()) for module in scanned_modules: source.append("ns3_module_%s.py" % module) local = "ns3_module_%s__local.py" % module @@ -429,16 +430,13 @@ def build(bld): if was_enabled: features.append(name) - bindgen = bld.new_task_gen('command', source=source, target=target, - command=argv, variables=dict(FEATURES=(','.join(features)))) + bindgen = bld.new_task_gen('command', source=source, target=target, command=argv) + bindgen.env['FEATURES'] = ','.join(features) + bindgen.dep_vars = ['FEATURES'] bindgen.before = 'cxx' bindgen.after = 'gen_everything_h_task' + bindgen.name = "pybindgen-command" - ## we build python bindings if either we have the tools to - ## generate them or if the pregenerated source file is already - ## present in the source dir. - if env['ENABLE_PYTHON_BINDINGS'] \ - or os.path.exists(os.path.join(bld.path.abspath(), 'ns3module.cc')): pymod = bld.new_task_gen('cxx', 'shlib', 'pyext') pymod.source = ['ns3module.cc', 'ns3module_helpers.cc'] pymod.includes = '.' diff --git a/doc/tutorial/in-process/introduction.texi b/doc/tutorial/in-process/introduction.texi index f57fa0236..17cb4d7c9 100644 --- a/doc/tutorial/in-process/introduction.texi +++ b/doc/tutorial/in-process/introduction.texi @@ -487,7 +487,7 @@ the following into your Linux shell (assuming you have installed Mercurial): cd mkdir repos cd !$ - hg clone http://code.nanam.org/ns-3-dev + hg clone http://code.nsnam.org/ns-3-dev @end verbatim As the hg command executes, you should see something like the following, diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index 50e99073a..6f0e0bc54 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -251,6 +251,24 @@ int main (int argc, char *argv[]) dataset = experiment.Run (wifi, wifiPhy, wifiChannel); gnuplot.AddDataset (dataset); + NS_LOG_DEBUG ("aarf-cd"); + experiment = Experiment ("aarf-cd"); + wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager"); + dataset = experiment.Run (wifi, wifiPhy, wifiChannel); + gnuplot.AddDataset (dataset); + + NS_LOG_DEBUG ("cara"); + experiment = Experiment ("cara"); + wifi.SetRemoteStationManager ("ns3::CaraWifiManager"); + dataset = experiment.Run (wifi, wifiPhy, wifiChannel); + gnuplot.AddDataset (dataset); + + NS_LOG_DEBUG ("rraa"); + experiment = Experiment ("rraa"); + wifi.SetRemoteStationManager ("ns3::RraaWifiManager"); + dataset = experiment.Run (wifi, wifiPhy, wifiChannel); + gnuplot.AddDataset (dataset); + NS_LOG_DEBUG ("ideal"); experiment = Experiment ("ideal"); wifi.SetRemoteStationManager ("ns3::IdealWifiManager"); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index 6bd6c74d1..e5cc5d84e 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -32,14 +32,14 @@ using namespace ns3; void -DevTxTrace (std::string context, Ptr p, Mac48Address address) +DevTxTrace (std::string context, Ptr p) { - std::cout << " TX to=" << address << " p: " << *p << std::endl; + std::cout << " TX p: " << *p << std::endl; } void -DevRxTrace (std::string context, Ptr p, Mac48Address address) +DevRxTrace (std::string context, Ptr p) { - std::cout << " RX from=" << address << " p: " << *p << std::endl; + std::cout << " RX p: " << *p << std::endl; } void PhyRxOkTrace (std::string context, Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) @@ -168,8 +168,8 @@ int main (int argc, char *argv[]) Simulator::Stop (Seconds (44.0)); - Config::Connect ("/NodeList/*/DeviceList/*/Tx", MakeCallback (&DevTxTrace)); - Config::Connect ("/NodeList/*/DeviceList/*/Rx", MakeCallback (&DevRxTrace)); + Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback (&DevTxTrace)); + Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback (&DevRxTrace)); Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", MakeCallback (&PhyRxOkTrace)); Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&PhyRxErrorTrace)); Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace)); diff --git a/regression.py b/regression.py index 161f8b79b..653731cc5 100644 --- a/regression.py +++ b/regression.py @@ -3,10 +3,9 @@ import os import sys import shutil import pproc as subprocess -import urllib +import errno # WAF modules -import Build import Options import Utils import Task @@ -66,9 +65,11 @@ class regression_test_task(Task.TaskBase): after = 'cc cxx cc_link cxx_link' color = 'BLUE' - def __init__(self, env, test_name, test_scripts_dir, build_traces_dir, reference_traces): - super(regression_test_task, self).__init__() + def __init__(self, bld, env, test_name, test_scripts_dir, build_traces_dir, reference_traces): + self.bld = bld + self.generator = self self.env = env + super(regression_test_task, self).__init__(generator=self, env=env) self.test_name = test_name self.test_scripts_dir = test_scripts_dir self.build_traces_dir = build_traces_dir @@ -77,6 +78,9 @@ class regression_test_task(Task.TaskBase): def __str__(self): return 'regression-test (%s)\n' % self.test_name + def runnable_status(self): + return Task.RUN_ME + def run(self): """Run a single test""" sys.path.insert(0, self.test_scripts_dir) @@ -118,7 +122,11 @@ class regression_test_task(Task.TaskBase): if Options.options.regression_generate: # clean the target dir - shutil.rmtree(reference_traces_path, ignore_errors=True) + try: + shutil.rmtree(reference_traces_path) + except OSError, ex: + if ex.errno not in [errno.ENOENT]: + raise os.makedirs(reference_traces_path) result = self.run_reference_generate(reference_traces_path, program, arguments, is_pyscript) if result == 0: @@ -127,7 +135,11 @@ class regression_test_task(Task.TaskBase): print "GENERATE FAIL " + self.test_name else: # clean the target dir - shutil.rmtree(trace_output_path, ignore_errors=True) + try: + shutil.rmtree(trace_output_path) + except OSError, ex: + if ex.errno not in [errno.ENOENT]: + raise os.makedirs(trace_output_path) # run it result = self.run_reference_test(reference_traces_path, trace_output_path, program, arguments, is_pyscript) @@ -147,13 +159,13 @@ class regression_test_task(Task.TaskBase): script = os.path.abspath(os.path.join('..', *os.path.split(program))) argv = [self.env['PYTHON'], script] + arguments try: - wutils.run_argv(argv, cwd=trace_output_path) + wutils.run_argv(argv, self.env, cwd=trace_output_path) except Utils.WafError, ex: print >> sys.stderr, ex return 1 else: try: - wutils.run_program(program, + wutils.run_program(program, self.env, command_template=wutils.get_command_template(self.env, arguments), cwd=trace_output_path) except Utils.WafError, ex: @@ -179,13 +191,13 @@ class regression_test_task(Task.TaskBase): script = os.path.abspath(os.path.join('..', *os.path.split(program))) argv = [self.env['PYTHON'], script] + arguments try: - retval = wutils.run_argv(argv, cwd=trace_output_path) + retval = wutils.run_argv(argv, self.env, cwd=trace_output_path) except Utils.WafError, ex: print >> sys.stderr, ex return 1 else: try: - retval = wutils.run_program(program, + retval = wutils.run_program(program, self.env, command_template=wutils.get_command_template(self.env, arguments), cwd=trace_output_path) except Utils.WafError, ex: @@ -198,13 +210,17 @@ class regression_test_collector_task(Task.TaskBase): after = 'regression_test_task' color = 'BLUE' - def __init__(self, test_tasks): - super(regression_test_collector_task, self).__init__() + def __init__(self, bld, test_tasks): + self.bld = bld + super(regression_test_collector_task, self).__init__(generator=self) self.test_tasks = test_tasks def __str__(self): return 'regression-test-collector\n' + def runnable_status(self): + return Task.RUN_ME + def run(self): failed_tests = [test for test in self.test_tasks if test.result is not None and test.result != 0] skipped_tests = [test for test in self.test_tasks if test.result is None] @@ -248,5 +264,7 @@ def run_regression(bld, reference_traces): build_traces_dir = bld.path.find_or_declare('regression/traces').abspath(bld.env) tasks = [] for test in tests: - tasks.append(regression_test_task(bld.env, test, test_scripts_dir, build_traces_dir, reference_traces)) - regression_test_collector_task(tasks) + task = regression_test_task(bld, bld.env, test, test_scripts_dir, build_traces_dir, reference_traces) + #bld.task_manager.add_task(task) + tasks.append(task) + regression_test_collector_task(bld, tasks) diff --git a/samples/main-random-variable.cc b/samples/main-random-variable.cc new file mode 100644 index 000000000..de16cd6da --- /dev/null +++ b/samples/main-random-variable.cc @@ -0,0 +1,377 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 Timo Bingmann + * + * 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: Timo Bingmann + */ +#include "ns3/random-variable.h" +#include "ns3/gnuplot.h" +#include +#include + +using namespace ns3; + +/// Round a double number to the given precision. e.g. dround(0.234, 0.1) = 0.2 +/// and dround(0.257, 0.1) = 0.3 +double dround(double number, double precision) +{ + number /= precision; + if (number >= 0) + number = std::floor(number + 0.5); + else + number = std::ceil(number - 0.5); + number *= precision; + return number; +} + +static GnuplotDataset +Histogramm (RandomVariable rndvar, unsigned int probes, double precision, const std::string& title, bool notcontinous = false) +{ + typedef std::map histogramm_maptype; + histogramm_maptype histogramm; + + for(unsigned int i = 0; i < probes; ++i) + { + double val = dround( rndvar.GetValue(), precision ); + + ++histogramm[val]; + } + + Gnuplot2dDataset data; + data.SetTitle(title); + + if (notcontinous) + { + data.SetStyle(Gnuplot2dDataset::IMPULSES); + } + + for(histogramm_maptype::const_iterator hi = histogramm.begin(); + hi != histogramm.end(); ++hi) + { + data.Add(hi->first, (double)hi->second / (double)probes / precision); + } + + return data; +} + +int main (int argc, char *argv[]) +{ + unsigned int probes = 1000000; + double precision = 0.01; + + GnuplotCollection gnuplots("main-random-variables.pdf"); + gnuplots.SetTerminal("pdf enhanced"); + + { + Gnuplot plot; + plot.SetTitle("UniformVariable"); + plot.AppendExtra("set yrange [0:]"); + + plot.AddDataset( Histogramm(UniformVariable(0.0, 1.0), probes, precision, + "UniformVariable [0.0 .. 1.0)") ); + + plot.AddDataset( Gnuplot2dFunction("0.1", + "0 <= x && x <= 1 ? 1.0 : 0") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("ExponentialVariable"); + plot.AppendExtra("set xrange [0:8]"); + plot.AppendExtra("ExpDist(x,l) = 1/l * exp(-1/l * x)"); + + plot.AddDataset( Histogramm(ExponentialVariable(0.5), probes, precision, + "ExponentialVariable m=0.5") ); + + plot.AddDataset( Gnuplot2dFunction("ExponentialDistribution mean 0.5", + "ExpDist(x, 0.5)") ); + + plot.AddDataset( Histogramm(ExponentialVariable(1.0), probes, precision, + "ExponentialVariable m=1") ); + + plot.AddDataset( Gnuplot2dFunction("ExponentialDistribution mean 1.0", + "ExpDist(x, 1.0)") ); + + plot.AddDataset( Histogramm(ExponentialVariable(1.5), probes, precision, + "ExponentialVariable m=1.5") ); + + plot.AddDataset( Gnuplot2dFunction("ExponentialDistribution mean 1.5", + "ExpDist(x, 1.5)") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("ParetoVariable"); + plot.AppendExtra("set xrange [0:2]"); + + plot.AddDataset( Histogramm(ParetoVariable(1.0, 1.5), probes, precision, + "ParetoVariable m=1.0 s=1.5") ); + + plot.AddDataset( Histogramm(ParetoVariable(1.0, 2.0), probes, precision, + "ParetoVariable m=1.0 s=2.0") ); + + plot.AddDataset( Histogramm(ParetoVariable(1.0, 2.5), probes, precision, + "ParetoVariable m=1.0 s=2.5") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("WeibullVariable"); + plot.AppendExtra("set xrange [0:3]"); + + plot.AddDataset( Histogramm(WeibullVariable(1.0, 1.0), probes, precision, + "WeibullVariable m=1.0 s=1.0") ); + + plot.AddDataset( Histogramm(WeibullVariable(1.0, 2.0), probes, precision, + "WeibullVariable m=1.0 s=2.0") ); + + plot.AddDataset( Histogramm(WeibullVariable(1.0, 3.0), probes, precision, + "WeibullVariable m=1.0 s=3.0") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("NormalVariable"); + plot.AppendExtra("set xrange [-3:3]"); + plot.AppendExtra("NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)"); + + plot.AddDataset( Histogramm(NormalVariable(0.0, 1.0), probes, precision, + "NormalVariable m=0.0 v=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("NormalDist {/Symbol m}=0.0 {/Symbol s}=1.0", + "NormalDist(x,0.0,1.0)") ); + + plot.AddDataset( Histogramm(NormalVariable(0.0, 2.0), probes, precision, + "NormalVariable m=0.0 v=2.0") ); + + plot.AddDataset( Gnuplot2dFunction("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(2.0)", + "NormalDist(x,0.0,sqrt(2.0))") ); + + plot.AddDataset( Histogramm(NormalVariable(0.0, 3.0), probes, precision, + "NormalVariable m=0.0 v=3.0") ); + + plot.AddDataset( Gnuplot2dFunction("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(3.0)", + "NormalDist(x,0.0,sqrt(3.0))") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("EmpiricalVariable"); + plot.AppendExtra("set xrange [*:*]"); + + EmpiricalVariable emp1; + emp1.CDF(0.0, 0.0 / 15.0); + emp1.CDF(0.2, 1.0 / 15.0); + emp1.CDF(0.4, 3.0 / 15.0); + emp1.CDF(0.6, 6.0 / 15.0); + emp1.CDF(0.8, 10.0 / 15.0); + emp1.CDF(1.0, 15.0 / 15.0); + + plot.AddDataset( Histogramm(emp1, probes, precision, + "EmpiricalVariable (Stairs)") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("DeterministicVariable"); + plot.AppendExtra("set xrange [*:*]"); + + double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 }; + DeterministicVariable det1 (values, sizeof(values) / sizeof(values[0])); + + plot.AddDataset( Histogramm(det1, probes, precision, + "DeterministicVariable", true) ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("LogNormalVariable"); + plot.AppendExtra("set xrange [0:3]"); + + plot.AppendExtra("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)"); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 1.0), probes, precision, + "LogNormalVariable m=0.0 s=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("LogNormalDist(x, 0.0, 1.0)", + "LogNormalDist(x, 0.0, 1.0)") ); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 0.5), probes, precision, + "LogNormalVariable m=0.0 s=0.5") ); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 0.25), probes, precision, + "LogNormalVariable m=0.0 s=0.25") ); + + plot.AddDataset( Gnuplot2dFunction("LogNormalDist(x, 0.0, 0.25)", + "LogNormalDist(x, 0.0, 0.25)") ); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 0.125), probes, precision, + "LogNormalVariable m=0.0 s=0.125") ); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 2.0), probes, precision, + "LogNormalVariable m=0.0 s=2.0") ); + + plot.AddDataset( Gnuplot2dFunction("LogNormalDist(x, 0.0, 2.0)", + "LogNormalDist(x, 0.0, 2.0)") ); + + plot.AddDataset( Histogramm(LogNormalVariable(0.0, 2.5), probes, precision, + "LogNormalVariable m=0.0 s=2.5") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("TriangularVariable"); + plot.AppendExtra("set xrange [*:*]"); + + plot.AddDataset( Histogramm(TriangularVariable(0.0, 1.0, 0.5), probes, precision, + "TriangularVariable [0.0 .. 1.0) m=0.5") ); + + plot.AddDataset( Histogramm(TriangularVariable(0.0, 1.0, 0.4), probes, precision, + "TriangularVariable [0.0 .. 1.0) m=0.4") ); + + plot.AddDataset( Histogramm(TriangularVariable(0.0, 1.0, 0.65), probes, precision, + "TriangularVariable [0.0 .. 1.0) m=0.65") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("GammaVariable"); + plot.AppendExtra("set xrange [0:10]"); + plot.AppendExtra("set yrange [0:1]"); + plot.AppendExtra("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)"); + + plot.AppendExtra("set label 1 '{/Symbol g}(x,{/Symbol a},{/Symbol b}) = x^{/Symbol a-1} e^{-x {/Symbol b}^{-1}} ( {/Symbol b}^{/Symbol a} {/Symbol G}({/Symbol a}) )^{-1}' at 0.7, 0.9"); + + plot.AddDataset( Histogramm(GammaVariable(1.0, 1.0), probes, precision, + "GammaVariable a=1.0 b=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 1.0, 1.0)", + "GammaDist(x, 1.0, 1.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(1.5, 1.0), probes, precision, + "GammaVariable a=1.5 b=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 1.5, 1.0)", + "GammaDist(x, 1.5, 1.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(2.0, 1.0), probes, precision, + "GammaVariable a=2.0 b=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 2.0, 1.0)", + "GammaDist(x, 2.0, 1.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(4.0, 1.0), probes, precision, + "GammaVariable a=4.0 b=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 4.0, 1.0)", + "GammaDist(x, 4.0, 1.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(2.0, 2.0), probes, precision, + "GammaVariable a=2.0 b=2.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 2.0, 2.0)", + "GammaDist(x, 2.0, 2.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(2.5, 3.0), probes, precision, + "GammaVariable a=2.5 b=3.0") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 2.5, 3.0)", + "GammaDist(x, 2.5, 3.0)") ); + + plot.AddDataset( Histogramm(GammaVariable(2.5, 4.5), probes, precision, + "GammaVariable a=2.5 b=4.5") ); + + plot.AddDataset( Gnuplot2dFunction("{/Symbol g}(x, 2.5, 4.5)", + "GammaDist(x, 2.5, 4.5)") ); + + gnuplots.AddPlot(plot); + } + + { + Gnuplot plot; + plot.SetTitle("ErlangVariable"); + plot.AppendExtra("set xrange [0:10]"); + plot.AppendExtra("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!"); + + plot.AppendExtra("set label 1 'Erlang(x,k,{/Symbol l}) = x^{k-1} e^{-x {/Symbol l}^{-1}} ( {/Symbol l}^k (k-1)! )^{-1}' at 0.7, 0.9"); + + plot.AddDataset( Histogramm(ErlangVariable(1, 1.0), probes, precision, + "ErlangVariable k=1 {/Symbol l}=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 1, 1.0)", + "ErlangDist(x, 1, 1.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(2, 1.0), probes, precision, + "ErlangVariable k=2 {/Symbol l}=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 2, 1.0)", + "ErlangDist(x, 2, 1.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(3, 1.0), probes, precision, + "ErlangVariable k=3 {/Symbol l}=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 3, 1.0)", + "ErlangDist(x, 3, 1.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(5, 1.0), probes, precision, + "ErlangVariable k=5 {/Symbol l}=1.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 5, 1.0)", + "ErlangDist(x, 5, 1.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(2, 2.0), probes, precision, + "ErlangVariable k=2 {/Symbol l}=2.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 2, 2.0)", + "ErlangDist(x, 2, 2.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(2, 3.0), probes, precision, + "ErlangVariable k=2 {/Symbol l}=3.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 2, 3.0)", + "ErlangDist(x, 2, 3.0)") ); + + plot.AddDataset( Histogramm(ErlangVariable(2, 5.0), probes, precision, + "ErlangVariable k=2 {/Symbol l}=5.0") ); + + plot.AddDataset( Gnuplot2dFunction("Erlang(x, 2, 5.0)", + "ErlangDist(x, 2, 5.0)") ); + + gnuplots.AddPlot(plot); + } + + gnuplots.GenerateOutput(std::cout); + + return 0; +} diff --git a/samples/main-simulator.cc b/samples/main-simulator.cc index 1f93d7634..793c6a9c6 100644 --- a/samples/main-simulator.cc +++ b/samples/main-simulator.cc @@ -1,6 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/simulator.h" #include "ns3/nstime.h" +#include "ns3/command-line.h" #include using namespace ns3; @@ -37,6 +38,9 @@ random_function (MyModel *model) int main (int argc, char *argv[]) { + CommandLine cmd; + cmd.Parse (argc, argv); + MyModel model; Simulator::Schedule (Seconds (10.0), &random_function, &model); diff --git a/samples/wscript b/samples/wscript index deba5598e..0c081ee80 100644 --- a/samples/wscript +++ b/samples/wscript @@ -10,6 +10,9 @@ def build(bld): obj = bld.create_ns3_program('main-simulator') obj.source = 'main-simulator.cc' + obj = bld.create_ns3_program('main-random-variable') + obj.source = 'main-random-variable.cc' + obj = bld.create_ns3_program('main-packet-header', ['common', 'simulator']) obj.source = 'main-packet-header.cc' diff --git a/src/core/log.h b/src/core/log.h index 4f62eb47e..ef141f351 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -23,6 +23,7 @@ #include #include +#include namespace ns3 { diff --git a/src/core/ptr.h b/src/core/ptr.h index 4861ceb4b..c61db5506 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -106,7 +106,7 @@ public: T *operator -> () const; T *operator -> (); const T &operator * () const; - const T &operator * (); + T &operator * (); // allow if (!sp) bool operator! (); // allow if (sp) @@ -472,7 +472,7 @@ Ptr::operator * () const } template -const T & +T & Ptr::operator * () { return *m_ptr; diff --git a/src/core/random-variable.cc b/src/core/random-variable.cc index 70be8a201..c8989d223 100644 --- a/src/core/random-variable.cc +++ b/src/core/random-variable.cc @@ -1218,6 +1218,230 @@ LogNormalVariable::LogNormalVariable (double mu, double sigma) : RandomVariable (LogNormalVariableImpl (mu, sigma)) {} +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// GammaVariableImpl +class GammaVariableImpl : public RandomVariableBase +{ +public: + /** + * \param alpha alpha parameter of the gamma distribution + * \param beta beta parameter of the gamma distribution + */ + GammaVariableImpl (double alpha, double beta); + + /** + * \return A random value from this distribution + */ + virtual double GetValue (); + + /** + * \return A random value from the gamma distribution with parameters alpha + * and beta + */ + double GetValue(double alpha, double beta); + + virtual RandomVariableBase* Copy(void) const; + +private: + double m_alpha; + double m_beta; + NormalVariable m_normal; +}; + + +RandomVariableBase* GammaVariableImpl::Copy () const +{ + return new GammaVariableImpl (m_alpha, m_beta); +} + +GammaVariableImpl::GammaVariableImpl (double alpha, double beta) + : m_alpha(alpha), m_beta(beta) +{ +} + +double +GammaVariableImpl::GetValue () +{ + return GetValue(m_alpha, m_beta); +} + +/* + The code for the following generator functions was adapted from ns-2 + tools/ranvar.cc + + Originally the algorithm was devised by Marsaglia in 2000: + G. Marsaglia, W. W. Tsang: A simple method for gereating Gamma variables + ACM Transactions on mathematical software, Vol. 26, No. 3, Sept. 2000 + + The Gamma distribution density function has the form + + x^(alpha-1) * exp(-x/beta) + p(x; alpha, beta) = ---------------------------- + beta^alpha * Gamma(alpha) + + for x > 0. +*/ +double +GammaVariableImpl::GetValue (double alpha, double beta) +{ + if(!m_generator) + { + m_generator = new RngStream(); + } + + if (alpha < 1) + { + double u = m_generator->RandU01 (); + return GetValue(1.0 + alpha, beta) * pow (u, 1.0 / alpha); + } + + double x, v, u; + double d = alpha - 1.0 / 3.0; + double c = (1.0 / 3.0) / sqrt (d); + + while (1) + { + do + { + x = m_normal.GetValue (); + v = 1.0 + c * x; + } while (v <= 0); + + v = v * v * v; + u = m_generator->RandU01 (); + if (u < 1 - 0.0331 * x * x * x * x) + { + break; + } + if (log (u) < 0.5 * x * x + d * (1 - v + log (v))) + { + break; + } + } + + return beta * d * v; +} + +GammaVariable::GammaVariable () + : RandomVariable (GammaVariableImpl (1.0, 1.0)) +{ +} + +GammaVariable::GammaVariable (double alpha, double beta) + : RandomVariable (GammaVariableImpl (alpha, beta)) +{ +} + +double GammaVariable::GetValue(void) const +{ + return this->RandomVariable::GetValue (); +} + +double GammaVariable::GetValue(double alpha, double beta) const +{ + return ((GammaVariableImpl*)Peek())->GetValue(alpha, beta); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// ErlangVariableImpl + +class ErlangVariableImpl : public RandomVariableBase +{ +public: + /** + * \param k k parameter of the Erlang distribution + * \param lambda lambda parameter of the Erlang distribution + */ + ErlangVariableImpl (unsigned int k, double lambda); + + /** + * \return A random value from this distribution + */ + virtual double GetValue (); + + /** + * \return A random value from the Erlang distribution with parameters k and + * lambda. + */ + double GetValue(unsigned int k, double lambda); + + virtual RandomVariableBase* Copy(void) const; + +private: + unsigned int m_k; + double m_lambda; +}; + + +RandomVariableBase* ErlangVariableImpl::Copy () const +{ + return new ErlangVariableImpl (m_k, m_lambda); +} + +ErlangVariableImpl::ErlangVariableImpl (unsigned int k, double lambda) + : m_k(k), m_lambda(lambda) +{ +} + +double +ErlangVariableImpl::GetValue () +{ + return GetValue(m_k, m_lambda); +} + +/* + The code for the following generator functions was adapted from ns-2 + tools/ranvar.cc + + The Erlang distribution density function has the form + + x^(k-1) * exp(-x/lambda) + p(x; k, lambda) = --------------------------- + lambda^k * (k-1)! + + for x > 0. +*/ +double +ErlangVariableImpl::GetValue (unsigned int k, double lambda) +{ + if(!m_generator) + { + m_generator = new RngStream(); + } + + ExponentialVariable exponential(lambda); + + double result = 0; + for (unsigned int i = 0; i < k; ++i) + { + result += exponential.GetValue(); + } + + return result; +} + +ErlangVariable::ErlangVariable () + : RandomVariable (ErlangVariableImpl (1, 1.0)) +{ +} + +ErlangVariable::ErlangVariable (unsigned int k, double lambda) + : RandomVariable (ErlangVariableImpl (k, lambda)) +{ +} + +double ErlangVariable::GetValue(void) const +{ + return this->RandomVariable::GetValue (); +} + +double ErlangVariable::GetValue(unsigned int k, double lambda) const +{ + return ((ErlangVariableImpl*)Peek())->GetValue(k, lambda); +} + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // TriangularVariableImpl methods diff --git a/src/core/random-variable.h b/src/core/random-variable.h index fc48ddf7a..a637726d4 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -36,7 +36,7 @@ * */ -namespace ns3{ +namespace ns3 { class RandomVariableBase; @@ -422,7 +422,7 @@ public: * value and a shape (alpha) parameter of 1.5. * \param m mean value of the distribution */ - WeibullVariable(double m) ; + WeibullVariable(double m) ; /** * Constructs a weibull random variable with the specified mean @@ -560,7 +560,6 @@ public: explicit DeterministicVariable(double* d, uint32_t c); }; - /** * \brief Log-normal Distributed random var * \ingroup randomvariable @@ -593,6 +592,108 @@ public: LogNormalVariable (double mu, double sigma); }; +/** + * \brief Gamma Distributed Random Variable + * \ingroup randomvariable + * + * GammaVariable defines a random variable with gamma distribution. + * + * This class supports the creation of objects that return random numbers + * from a fixed gamma distribution. It also supports the generation of + * single random numbers from various gamma distributions. + * + * The probability density function is defined over the interval [0,+inf) as: + * \f$ x^{\alpha-1} \frac{e^{-\frac{x}{\beta}}}{\beta^\alpha \Gamma(\alpha)}\f$ + * where \f$ mean = \alpha\beta \f$ and + * \f$ variance = \alpha \beta^2\f$ + */ +class GammaVariable : public RandomVariable +{ +public: + /** + * Constructs a gamma random variable with alpha = 1.0 and beta = 1.0 + */ + GammaVariable (); + + /** + * \param alpha alpha parameter of the gamma distribution + * \param beta beta parameter of the gamma distribution + */ + GammaVariable (double alpha, double beta); + + /** + * \brief call RandomVariable::GetValue + * \return A floating point random value + * + * Note: we have to re-implement this method here because the method is + * overloaded below for the two-argument variant and the c++ name resolution + * rules don't work well with overloads split between parent and child + * classes. + */ + double GetValue (void) const; + + /** + * \brief Returns a gamma random distributed double with parameters alpha and beta. + * \param alpha alpha parameter of the gamma distribution + * \param beta beta parameter of the gamma distribution + * \return A floating point random value + */ + double GetValue(double alpha, double beta) const; +}; + +/** + * \brief Erlang Distributed Random Variable + * \ingroup randomvariable + * + * ErlangVariable defines a random variable with Erlang distribution. + * + * The Erlang distribution is a special case of the Gamma distribution where k + * (= alpha) is a non-negative integer. Erlang distributed variables can be + * generated using a much faster algorithm than gamma variables. + * + * This class supports the creation of objects that return random numbers from + * a fixed Erlang distribution. It also supports the generation of single + * random numbers from various Erlang distributions. + * + * The probability density function is defined over the interval [0,+inf) as: + * \f$ \frac{x^{k-1} e^{-\frac{x}{\lambda}}}{\lambda^k (k-1)!}\f$ + * where \f$ mean = k \lambda \f$ and + * \f$ variance = k \lambda^2\f$ + */ +class ErlangVariable : public RandomVariable +{ +public: + /** + * Constructs an Erlang random variable with k = 1 and lambda = 1.0 + */ + ErlangVariable (); + + /** + * \param k k parameter of the Erlang distribution. Must be a non-negative integer. + * \param lambda lambda parameter of the Erlang distribution + */ + ErlangVariable (unsigned int k, double lambda); + + /** + * \brief call RandomVariable::GetValue + * \return A floating point random value + * + * Note: we have to re-implement this method here because the method is + * overloaded below for the two-argument variant and the c++ name resolution + * rules don't work well with overloads split between parent and child + * classes. + */ + double GetValue (void) const; + + /** + * \brief Returns an Erlang random distributed double with parameters k and lambda. + * \param k k parameter of the Erlang distribution. Must be a non-negative integer. + * \param lambda lambda parameter of the Erlang distribution + * \return A floating point random value + */ + double GetValue(unsigned int k, double lambda) const; +}; + /** * \brief Triangularly Distributed random var * \ingroup randomvariable diff --git a/src/core/type-id.cc b/src/core/type-id.cc index 90d400c05..dcab76ecb 100644 --- a/src/core/type-id.cc +++ b/src/core/type-id.cc @@ -71,6 +71,9 @@ public: bool MustHideFromDocumentation (uint16_t uid) const; private: + bool HasTraceSource (uint16_t uid, std::string name); + bool HasAttribute (uint16_t uid, std::string name); + struct AttributeInformation { std::string name; std::string help; @@ -231,6 +234,33 @@ IidManager::GetRegistered (uint32_t i) const return i + 1; } +bool +IidManager::HasAttribute (uint16_t uid, + std::string name) +{ + struct IidInformation *information = LookupInformation (uid); + while (true) + { + for (std::vector::const_iterator i = information->attributes.begin (); + i != information->attributes.end (); ++i) + { + if (i->name == name) + { + return true; + } + } + struct IidInformation *parent = LookupInformation (information->parent); + if (parent == information) + { + // top of inheritance tree + return false; + } + // check parent + information = parent; + } + return false; +} + void IidManager::AddAttribute (uint16_t uid, std::string name, @@ -241,14 +271,10 @@ IidManager::AddAttribute (uint16_t uid, ns3::Ptr checker) { struct IidInformation *information = LookupInformation (uid); - for (std::vector::const_iterator j = information->attributes.begin (); - j != information->attributes.end (); j++) + if (HasAttribute (uid, name)) { - if (j->name == name) - { - NS_FATAL_ERROR ("Registered the same attribute twice name=\""<name<<"\""); - return; - } + NS_FATAL_ERROR ("Attribute \"" << name << "\" already registered on tid=\"" << + information->name << "\""); } struct AttributeInformation param; param.name = name; @@ -310,6 +336,33 @@ IidManager::GetAttributeChecker (uint16_t uid, uint32_t i) const return information->attributes[i].checker; } +bool +IidManager::HasTraceSource (uint16_t uid, + std::string name) +{ + struct IidInformation *information = LookupInformation (uid); + while (true) + { + for (std::vector::const_iterator i = information->traceSources.begin (); + i != information->traceSources.end (); ++i) + { + if (i->name == name) + { + return true; + } + } + struct IidInformation *parent = LookupInformation (information->parent); + if (parent == information) + { + // top of inheritance tree + return false; + } + // check parent + information = parent; + } + return false; +} + void IidManager::AddTraceSource (uint16_t uid, std::string name, @@ -317,6 +370,11 @@ IidManager::AddTraceSource (uint16_t uid, ns3::Ptr accessor) { struct IidInformation *information = LookupInformation (uid); + if (HasTraceSource (uid, name)) + { + NS_FATAL_ERROR ("Trace source \"" << name << "\" already registered on tid=\"" << + information->name << "\""); + } struct TraceSourceInformation source; source.name = name; source.help = help; diff --git a/src/devices/bridge/bridge-channel.cc b/src/devices/bridge/bridge-channel.cc index e5eac7a54..b8b8b6bca 100644 --- a/src/devices/bridge/bridge-channel.cc +++ b/src/devices/bridge/bridge-channel.cc @@ -34,7 +34,7 @@ BridgeChannel::GetTypeId (void) } BridgeChannel::BridgeChannel () - : Channel ("BridgeChannel") + : Channel () { NS_LOG_FUNCTION_NOARGS (); } diff --git a/src/devices/bridge/bridge-net-device.cc b/src/devices/bridge/bridge-net-device.cc index fa314928b..03d7778eb 100644 --- a/src/devices/bridge/bridge-net-device.cc +++ b/src/devices/bridge/bridge-net-device.cc @@ -53,7 +53,6 @@ BridgeNetDevice::GetTypeId (void) BridgeNetDevice::BridgeNetDevice () : m_node (0), - m_name (""), m_ifIndex (0), m_mtu (0xffff) { @@ -111,7 +110,14 @@ BridgeNetDevice::ReceiveFromDevice (Ptr incomingPort, Ptr incomingPort, Ptr uint16_t protocol, Mac48Address src, Mac48Address dst) { NS_LOG_FUNCTION_NOARGS (); - NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName () + NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName () << ", packet=" << packet << ", protocol="< incomingPort, Ptr Ptr outPort = GetLearnedState (dst); if (outPort != NULL && outPort != incomingPort) { - NS_LOG_LOGIC ("Learning bridge state says to use port `" << outPort->GetName () << "'"); + NS_LOG_LOGIC ("Learning bridge state says to use port `" << outPort->GetInstanceTypeId ().GetName () << "'"); outPort->SendFrom (packet->Copy (), src, dst, protocol); } else @@ -141,8 +147,9 @@ BridgeNetDevice::ForwardUnicast (Ptr incomingPort, Ptr Ptr port = *iter; if (port != incomingPort) { - NS_LOG_LOGIC ("LearningBridgeForward (" << src << " => " << dst << "): " << incomingPort->GetName () - << " --> " << port->GetName () + NS_LOG_LOGIC ("LearningBridgeForward (" << src << " => " << dst << "): " + << incomingPort->GetInstanceTypeId ().GetName () + << " --> " << port->GetInstanceTypeId ().GetName () << " (UID " << packet->GetUid () << ")."); port->SendFrom (packet->Copy (), src, dst, protocol); } @@ -155,7 +162,7 @@ BridgeNetDevice::ForwardBroadcast (Ptr incomingPort, Ptr incomingPort, Ptr port = *iter; if (port != incomingPort) { - NS_LOG_LOGIC ("LearningBridgeForward (" << src << " => " << dst << "): " << incomingPort->GetName () - << " --> " << port->GetName () + NS_LOG_LOGIC ("LearningBridgeForward (" << src << " => " << dst << "): " + << incomingPort->GetInstanceTypeId ().GetName () + << " --> " << port->GetInstanceTypeId ().GetName () << " (UID " << packet->GetUid () << ")."); port->SendFrom (packet->Copy (), src, dst, protocol); } @@ -242,27 +250,13 @@ BridgeNetDevice::AddBridgePort (Ptr bridgePort) m_address = Mac48Address::ConvertFrom (bridgePort->GetAddress ()); } - NS_LOG_DEBUG ("RegisterProtocolHandler for " << bridgePort->GetName ()); + NS_LOG_DEBUG ("RegisterProtocolHandler for " << bridgePort->GetInstanceTypeId ().GetName ()); m_node->RegisterProtocolHandler (MakeCallback (&BridgeNetDevice::ReceiveFromDevice, this), 0, bridgePort, true); m_ports.push_back (bridgePort); m_channel->AddChannel (bridgePort->GetChannel ()); } -void -BridgeNetDevice::SetName(const std::string name) -{ - NS_LOG_FUNCTION_NOARGS (); - m_name = name; -} - -std::string -BridgeNetDevice::GetName(void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_name; -} - void BridgeNetDevice::SetIfIndex(const uint32_t index) { diff --git a/src/devices/bridge/bridge-net-device.h b/src/devices/bridge/bridge-net-device.h index 4af590c97..02be49f37 100644 --- a/src/devices/bridge/bridge-net-device.h +++ b/src/devices/bridge/bridge-net-device.h @@ -88,8 +88,6 @@ public: Ptr GetBridgePort (uint32_t n) const; // inherited from NetDevice base class. - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; virtual Ptr GetChannel (void) const; @@ -140,7 +138,6 @@ private: std::map m_learnState; Ptr m_node; Ptr m_channel; - std::string m_name; std::vector< Ptr > m_ports; uint32_t m_ifIndex; uint16_t m_mtu; diff --git a/src/devices/csma/csma-channel.cc b/src/devices/csma/csma-channel.cc index ab2a83bf3..20b870db1 100644 --- a/src/devices/csma/csma-channel.cc +++ b/src/devices/csma/csma-channel.cc @@ -51,7 +51,7 @@ CsmaChannel::GetTypeId (void) CsmaChannel::CsmaChannel () : - Channel ("Csma Channel") + Channel () { NS_LOG_FUNCTION_NOARGS (); m_state = IDLE; diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index f9742c649..dc953e7b6 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -154,8 +154,7 @@ CsmaNetDevice::GetTypeId (void) } CsmaNetDevice::CsmaNetDevice () - : m_name (""), - m_linkUp (false) + : m_linkUp (false) { NS_LOG_FUNCTION (this); m_txMachineState = READY; @@ -873,20 +872,6 @@ CsmaNetDevice::NotifyLinkUp (void) } } - void -CsmaNetDevice::SetName (const std::string name) -{ - NS_LOG_FUNCTION (name); - m_name = name; -} - - std::string -CsmaNetDevice::GetName (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_name; -} - void CsmaNetDevice::SetIfIndex (const uint32_t index) { @@ -1054,25 +1039,6 @@ CsmaNetDevice::SetNode (Ptr node) NS_LOG_FUNCTION (node); m_node = node; - int count = -1; - if (m_name.size () == 0) - { - for (uint32_t i = 0; i < node->GetNDevices (); i++) - { - Ptr dev = node->GetDevice (i); - if (dynamic_cast (PeekPointer (dev))) - { - count++; - if (dev == this) - { - break; - } - } - } - std::ostringstream s; - s << "eth" << count; - m_name = s.str (); - } } bool diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index 2213e1390..7dc1f9c55 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -305,8 +305,6 @@ public: // // The following methods are inherited from NetDevice base class. // - virtual void SetName (const std::string name); - virtual std::string GetName (void) const; virtual void SetIfIndex (const uint32_t index); virtual uint32_t GetIfIndex (void) const; virtual Ptr GetChannel (void) const; @@ -807,11 +805,6 @@ private: */ uint32_t m_ifIndex; - /** - * The human readable name of this device. - */ - std::string m_name; - /** * Flag indicating whether or not the link is up. In this case, * whether or not the device is connected to a channel. diff --git a/src/devices/emu/emu-encode-decode.cc b/src/devices/emu/emu-encode-decode.cc index 49b044099..f61c50d03 100644 --- a/src/devices/emu/emu-encode-decode.cc +++ b/src/devices/emu/emu-encode-decode.cc @@ -20,6 +20,7 @@ #include #include #include +#include namespace ns3 { diff --git a/src/devices/emu/emu-net-device.cc b/src/devices/emu/emu-net-device.cc index 0a987850e..7d3e451eb 100644 --- a/src/devices/emu/emu-net-device.cc +++ b/src/devices/emu/emu-net-device.cc @@ -68,11 +68,6 @@ EmuNetDevice::GetTypeId (void) Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), MakeMac48AddressAccessor (&EmuNetDevice::m_address), MakeMac48AddressChecker ()) - .AddAttribute ("DeviceName", - "The name of the underlying real device (e.g. eth1).", - StringValue ("eth1"), - MakeStringAccessor (&EmuNetDevice::m_deviceName), - MakeStringChecker ()) .AddAttribute ("Start", "The simulation time at which to spin up the device thread.", TimeValue (Seconds (0.)), @@ -173,8 +168,7 @@ EmuNetDevice::EmuNetDevice () m_sock (-1), m_readThread (0), m_ifIndex (std::numeric_limits::max ()), // absurdly large value - m_sll_ifindex (-1), - m_name ("Emu NetDevice") + m_sll_ifindex (-1) { NS_LOG_FUNCTION (this); Start (m_tStart); @@ -843,18 +837,6 @@ EmuNetDevice::NotifyLinkUp (void) } } -void -EmuNetDevice::SetName(const std::string name) -{ - m_name = name; -} - -std::string -EmuNetDevice::GetName(void) const -{ - return m_name; -} - void EmuNetDevice::SetIfIndex(const uint32_t index) { diff --git a/src/devices/emu/emu-net-device.h b/src/devices/emu/emu-net-device.h index 02947cb53..189a81833 100644 --- a/src/devices/emu/emu-net-device.h +++ b/src/devices/emu/emu-net-device.h @@ -105,9 +105,6 @@ public: // // Pure virtual methods inherited from NetDevice we must implement. // - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; - virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; @@ -449,11 +446,6 @@ private: */ int32_t m_sll_ifindex; - /** - * The human readable name of this device. - */ - std::string m_name; - /** * Flag indicating whether or not the link is up. In this case, * whether or not the device is connected to a channel. diff --git a/src/devices/point-to-point/point-to-point-channel.cc b/src/devices/point-to-point/point-to-point-channel.cc index b94add35c..6fa1b7bee 100644 --- a/src/devices/point-to-point/point-to-point-channel.cc +++ b/src/devices/point-to-point/point-to-point-channel.cc @@ -43,11 +43,11 @@ PointToPointChannel::GetTypeId (void) } // -// By default, you get a channel with the name "PointToPoint Channel" that +// By default, you get a channel that // has an "infitely" fast transmission speed and zero delay. PointToPointChannel::PointToPointChannel() : - Channel ("PointToPoint Channel"), + Channel (), m_delay (Seconds (0.)), m_nDevices (0) { diff --git a/src/devices/point-to-point/point-to-point-channel.h b/src/devices/point-to-point/point-to-point-channel.h index b31a37ae7..9830e048f 100644 --- a/src/devices/point-to-point/point-to-point-channel.h +++ b/src/devices/point-to-point/point-to-point-channel.h @@ -50,7 +50,7 @@ public: /** * \brief Create a PointToPointChannel * - * By default, you get a channel with the name "PointToPoint Channel" that + * By default, you get a channel that * has zero transmission delay. */ PointToPointChannel (); diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index 856ba6852..609441cad 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -148,7 +148,6 @@ PointToPointNetDevice::PointToPointNetDevice () : m_txMachineState (READY), m_channel (0), - m_name (""), m_linkUp (false), m_currentPkt (0) { @@ -373,18 +372,6 @@ PointToPointNetDevice::NotifyLinkUp (void) } } - void -PointToPointNetDevice::SetName(const std::string name) -{ - m_name = name; -} - - std::string -PointToPointNetDevice::GetName(void) const -{ - return m_name; -} - void PointToPointNetDevice::SetIfIndex(const uint32_t index) { diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index 5af6c9c66..956b6a356 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -226,12 +226,6 @@ public: */ uint16_t GetFrameSize (void) const; -// -// Pure virtual methods inherited from NetDevice we must implement. -// - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; - virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; @@ -531,7 +525,6 @@ private: NetDevice::ReceiveCallback m_rxCallback; NetDevice::PromiscReceiveCallback m_promiscCallback; uint32_t m_ifIndex; - std::string m_name; bool m_linkUp; Callback m_linkChangeCallback; diff --git a/src/devices/tap-bridge/tap-bridge.cc b/src/devices/tap-bridge/tap-bridge.cc index fa14796a9..9c99c21fb 100644 --- a/src/devices/tap-bridge/tap-bridge.cc +++ b/src/devices/tap-bridge/tap-bridge.cc @@ -957,20 +957,6 @@ TapBridge::ReceiveFromBridgedDevice ( NS_ABORT_MSG_IF (bytesWritten != p->GetSize (), "TapBridge::ReceiveFromBridgedDevice(): Write error."); } -void -TapBridge::SetName(const std::string name) -{ - NS_LOG_FUNCTION_NOARGS (); - m_name = name; -} - -std::string -TapBridge::GetName(void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_name; -} - void TapBridge::SetIfIndex(const uint32_t index) { diff --git a/src/devices/tap-bridge/tap-bridge.h b/src/devices/tap-bridge/tap-bridge.h index 62d6a1350..ac2fb2a2d 100644 --- a/src/devices/tap-bridge/tap-bridge.h +++ b/src/devices/tap-bridge/tap-bridge.h @@ -173,8 +173,6 @@ public: // The following methods are inherited from NetDevice base class and are // documented there. // - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; virtual Ptr GetChannel (void) const; @@ -318,12 +316,6 @@ private: */ Ptr m_node; - /** - * \internal - * - * A possible name for the (ghost) Node to which we are connected. - */ - std::string m_name; /** * \internal diff --git a/src/devices/tap-bridge/tap-creator.cc b/src/devices/tap-bridge/tap-creator.cc index a80606e56..fd18752d2 100644 --- a/src/devices/tap-bridge/tap-creator.cc +++ b/src/devices/tap-bridge/tap-creator.cc @@ -138,13 +138,17 @@ AsciiToMac48 (const char *str, uint8_t addr[6]) } } -static void -SetInetAddress (sockaddr *ad, uint32_t networkOrder) +static sockaddr +CreateInetAddress (uint32_t networkOrder) { - struct sockaddr_in *sin = (struct sockaddr_in*)ad; - sin->sin_family = AF_INET; - sin->sin_port = 0; // unused - sin->sin_addr.s_addr = htonl (networkOrder); + union { + struct sockaddr any_socket; + struct sockaddr_in si; + } s; + s.si.sin_family = AF_INET; + s.si.sin_port = 0; // unused + s.si.sin_addr.s_addr = htonl (networkOrder); + return s.any_socket; } static void @@ -330,7 +334,7 @@ CreateTap (const char *dev, const char *gw, const char *ip, const char *mac, con // // Set the IP address of the new interface/device. // - SetInetAddress (&ifr.ifr_addr, AsciiToIpv4 (ip)); + ifr.ifr_addr = CreateInetAddress (AsciiToIpv4 (ip)); status = ioctl (fd, SIOCSIFADDR, &ifr); ABORT_IF (status == -1, "Could not set IP address", true); LOG ("Set device IP address to " << ip); @@ -338,7 +342,7 @@ CreateTap (const char *dev, const char *gw, const char *ip, const char *mac, con // // Set the net mask of the new interface/device // - SetInetAddress (&ifr.ifr_netmask, AsciiToIpv4 (netmask)); + ifr.ifr_netmask = CreateInetAddress (AsciiToIpv4 (netmask)); status = ioctl (fd, SIOCSIFNETMASK, &ifr); ABORT_IF (status == -1, "Could not set net mask", true); LOG ("Set device Net Mask to " << netmask); diff --git a/src/devices/tap-bridge/tap-encode-decode.cc b/src/devices/tap-bridge/tap-encode-decode.cc index 9d85519ab..d6a03588d 100644 --- a/src/devices/tap-bridge/tap-encode-decode.cc +++ b/src/devices/tap-bridge/tap-encode-decode.cc @@ -20,6 +20,7 @@ #include #include #include +#include namespace ns3 { diff --git a/src/devices/wifi/aarf-wifi-manager.cc b/src/devices/wifi/aarf-wifi-manager.cc index 23451d704..765fec03a 100644 --- a/src/devices/wifi/aarf-wifi-manager.cc +++ b/src/devices/wifi/aarf-wifi-manager.cc @@ -71,39 +71,34 @@ AarfWifiManager::~AarfWifiManager () WifiRemoteStation * AarfWifiManager::CreateStation (void) { - return new AarfWifiRemoteStation (this, m_minTimerThreshold, - m_minSuccessThreshold, - m_successK, - m_maxSuccessThreshold, - m_timerK); + return new AarfWifiRemoteStation (this); } -AarfWifiRemoteStation::AarfWifiRemoteStation (Ptr stations, - uint32_t minTimerThreshold, - uint32_t minSuccessThreshold, - double successK, - uint32_t maxSuccessThreshold, - double timerK) - : ArfWifiRemoteStation (stations, minTimerThreshold, minSuccessThreshold), - m_successK (successK), - m_maxSuccessThreshold (maxSuccessThreshold), - m_timerK (timerK) +AarfWifiRemoteStation::AarfWifiRemoteStation (Ptr manager) + : ArfWifiRemoteStation (manager), + m_manager (manager) {} AarfWifiRemoteStation::~AarfWifiRemoteStation () {} +Ptr +AarfWifiRemoteStation::GetManager (void) const +{ + return m_manager; +} + void AarfWifiRemoteStation::ReportRecoveryFailure (void) { - SetSuccessThreshold ((int)(Min (GetSuccessThreshold () * m_successK, - m_maxSuccessThreshold))); + SetSuccessThreshold ((int)(Min (GetSuccessThreshold () * m_manager->m_successK, + m_manager->m_maxSuccessThreshold))); SetTimerTimeout ((int)(Max (GetMinTimerTimeout (), - GetSuccessThreshold () * m_timerK))); + GetSuccessThreshold () * m_manager->m_timerK))); } void diff --git a/src/devices/wifi/aarf-wifi-manager.h b/src/devices/wifi/aarf-wifi-manager.h index 855c327f5..79a70789b 100644 --- a/src/devices/wifi/aarf-wifi-manager.h +++ b/src/devices/wifi/aarf-wifi-manager.h @@ -17,8 +17,8 @@ * * Author: Mathieu Lacage */ -#ifndef AARF_MAC_STATIONS_H -#define AARF_MAC_STATIONS_H +#ifndef AARF_WIFI_MANAGER_H +#define AARF_WIFI_MANAGER_H #include "arf-wifi-manager.h" @@ -39,6 +39,7 @@ public: AarfWifiManager (); virtual ~AarfWifiManager (); private: + friend class AarfWifiRemoteStation; virtual class WifiRemoteStation *CreateStation (void); uint32_t m_minTimerThreshold; uint32_t m_minSuccessThreshold; @@ -50,24 +51,18 @@ private: class AarfWifiRemoteStation : public ArfWifiRemoteStation { public: - AarfWifiRemoteStation (Ptr stations, - uint32_t minTimerThreshold, - uint32_t minSuccessThreshold, - double successK, - uint32_t maxSuccessThreshold, - double timerK); + AarfWifiRemoteStation (Ptr stations); virtual ~AarfWifiRemoteStation (); private: virtual void ReportRecoveryFailure (void); virtual void ReportFailure (void); + virtual Ptr GetManager (void) const; - double m_successK; - uint32_t m_maxSuccessThreshold; - double m_timerK; + Ptr m_manager; }; } // namespace ns3 -#endif /* AARF_MAC_STATIONS_H */ +#endif /* AARF_WIFI_MANAGER_H */ diff --git a/src/devices/wifi/aarfcd-wifi-manager.cc b/src/devices/wifi/aarfcd-wifi-manager.cc new file mode 100644 index 000000000..5f1b6c721 --- /dev/null +++ b/src/devices/wifi/aarfcd-wifi-manager.cc @@ -0,0 +1,410 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2004,2005,2006 INRIA + * + * 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: Federico Maguolo + */ + +#include "aarfcd-wifi-manager.h" +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/simulator.h" +#include "ns3/boolean.h" +#include + +NS_LOG_COMPONENT_DEFINE ("Aarfcd"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED(AarfcdWifiManager); + +AarfcdWifiRemoteStation::AarfcdWifiRemoteStation (Ptr manager) + : m_manager (manager) +{ + m_timerTimeout = m_manager->m_minTimerThreshold; + m_successThreshold = m_manager->m_minSuccessThreshold; + m_rate = GetMinRate (); + + m_success = 0; + m_failed = 0; + m_recovery = false; + m_retry = 0; + m_timer = 0; + m_rtsOn = false; + m_rtsWnd = m_manager->m_minRtsWnd; + m_rtsCounter = 0; + m_justModifyRate = true; + m_haveASuccess = false; +} +AarfcdWifiRemoteStation::~AarfcdWifiRemoteStation () +{} + +uint32_t +AarfcdWifiRemoteStation::GetMaxRate (void) +{ + return GetNSupportedModes () - 1; +} +uint32_t +AarfcdWifiRemoteStation::GetMinRate (void) +{ + return 0; +} + +void +AarfcdWifiRemoteStation::ReportRecoveryFailure (void) +{ + m_successThreshold = (int)(std::min ((uint32_t)(m_successThreshold * m_manager->m_successK), + m_manager->m_maxSuccessThreshold)); + m_timerTimeout = (int)(std::max (m_manager->m_minTimerThreshold, + (uint32_t)(m_successThreshold * m_manager->m_timerK))); +} + +void +AarfcdWifiRemoteStation::ReportFailure (void) +{ + m_timerTimeout = m_manager->m_minTimerThreshold; + m_successThreshold = m_manager->m_minSuccessThreshold; +} + +bool +AarfcdWifiRemoteStation::NeedRecoveryFallback (void) +{ + if (m_retry >= 1) + { + return true; + } + else + { + return false; + } +} +bool +AarfcdWifiRemoteStation::NeedNormalFallback (void) +{ + int retryMod = (m_retry - 1) % 2; + if (retryMod == 1) + { + return true; + } + else + { + return false; + } +} + + + +void +AarfcdWifiRemoteStation::DoReportRtsFailed (void) +{ + //printf ("%.9f %p RtsFail %d %d %d\n",Simulator::Now ().GetSeconds (),this,m_rate,m_timer,m_retry); + NS_LOG_INFO ("" << this << " RtsFail rate=" << m_rate); + if (m_manager->m_rtsFailsAsDataFails) + { + m_rtsCounter--; + ReportDataFailed (); + } +} +/** + * It is important to realize that "recovery" mode starts after failure of + * the first transmission after a rate increase and ends at the first successful + * transmission. Specifically, recovery mode transcends retransmissions boundaries. + * Fundamentally, ARF handles each data transmission independently, whether it + * is the initial transmission of a packet or the retransmission of a packet. + * The fundamental reason for this is that there is a backoff between each data + * transmission, be it an initial transmission or a retransmission. + */ +void +AarfcdWifiRemoteStation::DoReportDataFailed (void) +{ + NS_LOG_INFO ("" << this << " TxFail rate=" << m_rate); + m_timer++; + m_failed++; + m_retry++; + m_success = 0; + //printf ("%.9f %p Fail %d %d %d\n",Simulator::Now ().GetSeconds (),this,m_rate,m_timer,m_retry); + if (!m_rtsOn) + { + TurnOnRts (); + if (!m_justModifyRate && !m_haveASuccess) + { + //printf ("%p Increase RTS Windows\n",this); + IncreaseRtsWnd (); + } + else + { + //printf ("%p Reset RTS Window\n",this); + ResetRtsWnd (); + } + m_rtsCounter = m_rtsWnd; + if (m_retry >= 2) + { + m_timer = 0; + } + //printf ("%.9f %p AtcivateRTS %d %d\n",Simulator::Now ().GetSeconds (),this, m_rate, m_rtsCounter); + } + else if (m_recovery) + { + NS_ASSERT (m_retry >= 1); + m_justModifyRate = false; + m_rtsCounter = m_rtsWnd; + if (NeedRecoveryFallback ()) + { + if (m_manager->m_turnOffRtsAfterRateDecrease) + { + TurnOffRts (); + } + m_justModifyRate = true; + ReportRecoveryFailure (); + if (m_rate != GetMinRate ()) + { + m_rate--; + } + NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << m_successThreshold); + //printf ("%.9f %p DecreaseRateRecovery %d\n", Simulator::Now ().GetSeconds (),this, m_rate); + } + m_timer = 0; + } + else + { + NS_ASSERT (m_retry >= 1); + m_justModifyRate = false; + m_rtsCounter = m_rtsWnd; + if (NeedNormalFallback ()) + { + if (m_manager->m_turnOffRtsAfterRateDecrease) + { + TurnOffRts (); + } + m_justModifyRate = true; + ReportFailure (); + if (m_rate != GetMinRate ()) + { + m_rate--; + } + NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << m_successThreshold); + //printf ("%.9f %p DecreaseRate %d\n", Simulator::Now ().GetSeconds (),this,m_rate); + } + if (m_retry >= 2) + { + m_timer = 0; + } + } + CheckRts (); +} +void +AarfcdWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode) +{} +void +AarfcdWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) +{ + NS_LOG_INFO ("" << this << " RtsOk rate=" << m_rate); + NS_LOG_DEBUG ("self="<= m_timerTimeout) + { + NS_LOG_INFO ("" << this << " JI rate=" << m_rate << " Sthr=" << m_successThreshold); + } + CheckRts (); +} +void +AarfcdWifiRemoteStation::DoReportFinalRtsFailed (void) +{} +void +AarfcdWifiRemoteStation::DoReportFinalDataFailed (void) +{} + +WifiMode +AarfcdWifiRemoteStation::DoGetDataMode (uint32_t size) +{ + return GetSupportedMode (m_rate); +} +WifiMode +AarfcdWifiRemoteStation::DoGetRtsMode (void) +{ + // XXX: we could/should implement the Arf algorithm for + // RTS only by picking a single rate within the BasicRateSet. + return GetSupportedMode (0); +} + +Ptr +AarfcdWifiRemoteStation::GetManager (void) const +{ + return m_manager; +} + +void +AarfcdWifiRemoteStation::CheckRts (void) +{ + if (m_rtsCounter == 0 && m_rtsOn) + { + //printf ("%p Turn off RTS\n",this); + TurnOffRts (); + } +} + +void +AarfcdWifiRemoteStation::TurnOffRts (void) +{ + //printf ("%.9f %p DeatcivateRTS %d %d\n",Simulator::Now ().GetSeconds (),this, m_rate, m_rtsCounter); + m_rtsOn = false; + m_haveASuccess = false; +} + +void +AarfcdWifiRemoteStation::TurnOnRts (void) +{ + m_rtsOn = true; +} + +void +AarfcdWifiRemoteStation::IncreaseRtsWnd (void) +{ + if (m_rtsWnd == m_manager->m_maxRtsWnd) + { + return; + } + + m_rtsWnd *= 2; + if (m_rtsWnd > m_manager->m_maxRtsWnd) + { + m_rtsWnd = m_manager->m_maxRtsWnd; + } +} + +void +AarfcdWifiRemoteStation::ResetRtsWnd (void) +{ + m_rtsWnd = m_manager->m_minRtsWnd; +} + +bool +AarfcdWifiRemoteStation::NeedRts (Ptr packet) +{ + //printf ("%.9f %p NeedRts %d %d\n",Simulator::Now ().GetSeconds (),this,m_rate,(m_rtsOn?1:0)); + NS_LOG_INFO ("" << this << " rate=" << m_rate << " rts=" << (m_rtsOn?"RTS":"BASIC") << " rtsCounter=" << m_rtsCounter); + return m_rtsOn; +} + + + + + +TypeId +AarfcdWifiManager::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::AarfcdWifiManager") + .SetParent () + .AddConstructor () + .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.", + DoubleValue (2.0), + MakeDoubleAccessor (&AarfcdWifiManager::m_successK), + MakeDoubleChecker ()) + .AddAttribute ("TimerK", + "Multiplication factor for the timer threshold in the AARF algorithm.", + DoubleValue (2.0), + MakeDoubleAccessor (&AarfcdWifiManager::m_timerK), + MakeDoubleChecker ()) + .AddAttribute ("MaxSuccessThreshold", + "Maximum value of the success threshold in the AARF algorithm.", + UintegerValue (60), + MakeUintegerAccessor (&AarfcdWifiManager::m_maxSuccessThreshold), + MakeUintegerChecker ()) + .AddAttribute ("MinTimerThreshold", + "The minimum value for the 'timer' threshold in the AARF algorithm.", + UintegerValue (15), + MakeUintegerAccessor (&AarfcdWifiManager::m_minTimerThreshold), + MakeUintegerChecker ()) + .AddAttribute ("MinSuccessThreshold", + "The minimum value for the success threshold in the AARF algorithm.", + UintegerValue (10), + MakeUintegerAccessor (&AarfcdWifiManager::m_minSuccessThreshold), + MakeUintegerChecker ()) + .AddAttribute ("MinRtsWnd", + "Minimum value for Rts window of Aarf-CD", + UintegerValue (1), + MakeUintegerAccessor (&AarfcdWifiManager::m_minRtsWnd), + MakeUintegerChecker ()) + .AddAttribute ("MaxRtsWnd", + "Maximum value for Rts window of Aarf-CD", + UintegerValue (40), + MakeUintegerAccessor (&AarfcdWifiManager::m_maxRtsWnd), + MakeUintegerChecker ()) + .AddAttribute ("RtsFailsAsDataFails", + "If true the RTS failures will be treated by Aarf-CD as Data failures", + BooleanValue (false), + MakeBooleanAccessor (&AarfcdWifiManager::m_rtsFailsAsDataFails), + MakeBooleanChecker ()) + .AddAttribute ("TurnOffRtsAfterRateDecrease", + "If true the RTS mechanism will be turned off when the rate will be decreased", + BooleanValue (true), + MakeBooleanAccessor (&AarfcdWifiManager::m_turnOffRtsAfterRateDecrease), + MakeBooleanChecker ()) + .AddAttribute ("TurnOnRtsAfterRateIncrease", + "If true the RTS mechanism will be turned on when the rate will be increased", + BooleanValue (true), + MakeBooleanAccessor (&AarfcdWifiManager::m_turnOnRtsAfterRateIncrease), + MakeBooleanChecker ()) + ; + return tid; +} +AarfcdWifiManager::AarfcdWifiManager () + : WifiRemoteStationManager () +{} +AarfcdWifiManager::~AarfcdWifiManager () +{} +WifiRemoteStation * +AarfcdWifiManager::CreateStation (void) +{ + return new AarfcdWifiRemoteStation (this); +} + +} // namespace ns3 diff --git a/src/devices/wifi/aarfcd-wifi-manager.h b/src/devices/wifi/aarfcd-wifi-manager.h new file mode 100644 index 000000000..f95d45356 --- /dev/null +++ b/src/devices/wifi/aarfcd-wifi-manager.h @@ -0,0 +1,112 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Federico Maguolo + */ +#ifndef AARFCD_WIFI_MANAGER_H +#define AARFCD_WIFI_MANAGER_H + +#include "wifi-remote-station-manager.h" + +namespace ns3 { + +/** + * \brief an implementation of the AARF-CD algorithm + * + * This algorithm was first described in "Efficient Collision Detection for Auto Rate Fallback Algorithm". + * The implementation available here was done by Federico Maguolo for a very early development + * version of ns-3. Federico died before merging this work in ns-3 itself so his code was ported + * to ns-3 later without his supervision. + */ +class AarfcdWifiManager : public WifiRemoteStationManager +{ +public: + static TypeId GetTypeId (void); + AarfcdWifiManager (); + virtual ~AarfcdWifiManager (); + +private: + friend class AarfcdWifiRemoteStation; + virtual WifiRemoteStation *CreateStation (void); + uint32_t m_minTimerThreshold; + uint32_t m_minSuccessThreshold; + double m_successK; + uint32_t m_maxSuccessThreshold; + double m_timerK; + uint32_t m_minRtsWnd; + uint32_t m_maxRtsWnd; + bool m_rtsFailsAsDataFails; + bool m_turnOffRtsAfterRateDecrease; + bool m_turnOnRtsAfterRateIncrease; +}; + + +class AarfcdWifiRemoteStation : public WifiRemoteStation +{ +public: + AarfcdWifiRemoteStation (Ptr manager); + virtual ~AarfcdWifiRemoteStation (); + + +private: + virtual void DoReportRxOk (double rxSnr, WifiMode txMode); + virtual void DoReportRtsFailed (void); + virtual void DoReportDataFailed (void); + virtual void DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr); + virtual void DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr); + virtual void DoReportFinalRtsFailed (void); + virtual void DoReportFinalDataFailed (void); + virtual Ptr GetManager (void) const; + virtual WifiMode DoGetDataMode (uint32_t size); + virtual WifiMode DoGetRtsMode (void); + virtual bool NeedRts (Ptr packet); + + void ReportRecoveryFailure (void); + void ReportFailure (void); + uint32_t GetMaxRate (void); + uint32_t GetMinRate (void); + void CheckRts (void); + void IncreaseRtsWnd (void); + void ResetRtsWnd (void); + void TurnOffRts (void); + void TurnOnRts (void); + + bool NeedRecoveryFallback (void); + bool NeedNormalFallback (void); + + uint32_t m_timer; + uint32_t m_success; + uint32_t m_failed; + bool m_recovery; + bool m_justModifyRate; + uint32_t m_retry; + + uint32_t m_successThreshold; + uint32_t m_timerTimeout; + + uint32_t m_rate; + bool m_rtsOn; + uint32_t m_rtsWnd; + uint32_t m_rtsCounter; + bool m_haveASuccess; + + Ptr m_manager; +}; + +} // namespace ns3 + +#endif /* MAARF_MAC_STATIONS_H */ diff --git a/src/devices/wifi/arf-wifi-manager.cc b/src/devices/wifi/arf-wifi-manager.cc index e20e0b73e..fbbc0391f 100644 --- a/src/devices/wifi/arf-wifi-manager.cc +++ b/src/devices/wifi/arf-wifi-manager.cc @@ -28,15 +28,11 @@ NS_LOG_COMPONENT_DEFINE ("ns3::ArfWifiManager"); namespace ns3 { -ArfWifiRemoteStation::ArfWifiRemoteStation (Ptr stations, - int minTimerTimeout, - int minSuccessThreshold) - : m_stations (stations) +ArfWifiRemoteStation::ArfWifiRemoteStation (Ptr manager) + : m_manager (manager) { - m_minTimerTimeout = minTimerTimeout; - m_minSuccessThreshold = minSuccessThreshold; - m_successThreshold = m_minSuccessThreshold; - m_timerTimeout = m_minTimerTimeout; + m_successThreshold = m_manager->m_successThreshold; + m_timerTimeout = m_manager->m_timerThreshold; m_rate = GetMinRate (); m_success = 0; @@ -189,11 +185,11 @@ void ArfWifiRemoteStation::ReportFailure (void) {} uint32_t ArfWifiRemoteStation::GetMinTimerTimeout (void) { - return m_minTimerTimeout; + return m_manager->m_timerThreshold; } uint32_t ArfWifiRemoteStation::GetMinSuccessThreshold (void) { - return m_minSuccessThreshold; + return m_manager->m_successThreshold; } uint32_t ArfWifiRemoteStation::GetTimerTimeout (void) { @@ -205,18 +201,18 @@ uint32_t ArfWifiRemoteStation::GetSuccessThreshold (void) } void ArfWifiRemoteStation::SetTimerTimeout (uint32_t timerTimeout) { - NS_ASSERT (timerTimeout >= m_minTimerTimeout); + NS_ASSERT (timerTimeout >= m_manager->m_timerThreshold); m_timerTimeout = timerTimeout; } void ArfWifiRemoteStation::SetSuccessThreshold (uint32_t successThreshold) { - NS_ASSERT (successThreshold >= m_minSuccessThreshold); + NS_ASSERT (successThreshold >= m_manager->m_successThreshold); m_successThreshold = successThreshold; } Ptr ArfWifiRemoteStation::GetManager (void) const { - return m_stations; + return m_manager; } NS_OBJECT_ENSURE_REGISTERED (ArfWifiManager); @@ -247,7 +243,7 @@ ArfWifiManager::~ArfWifiManager () WifiRemoteStation * ArfWifiManager::CreateStation (void) { - return new ArfWifiRemoteStation (this, m_timerThreshold, m_successThreshold); + return new ArfWifiRemoteStation (this); } } // namespace ns3 diff --git a/src/devices/wifi/arf-wifi-manager.h b/src/devices/wifi/arf-wifi-manager.h index f074bc5d1..6fb68a86b 100644 --- a/src/devices/wifi/arf-wifi-manager.h +++ b/src/devices/wifi/arf-wifi-manager.h @@ -46,6 +46,7 @@ public: virtual ~ArfWifiManager (); private: + friend class ArfWifiRemoteStation; virtual class WifiRemoteStation *CreateStation (void); uint32_t m_timerThreshold; uint32_t m_successThreshold; @@ -55,9 +56,7 @@ private: class ArfWifiRemoteStation : public WifiRemoteStation { public: - ArfWifiRemoteStation (Ptr stations, - int minTimerTimeout, - int minSuccessThreshold); + ArfWifiRemoteStation (Ptr manager); virtual ~ArfWifiRemoteStation (); protected: @@ -85,10 +84,7 @@ private: uint32_t m_rate; - uint32_t m_minTimerTimeout; - uint32_t m_minSuccessThreshold; - - Ptr m_stations; + Ptr m_manager; private: // overriden by AarfMacStation. diff --git a/src/devices/wifi/cara-wifi-manager.cc b/src/devices/wifi/cara-wifi-manager.cc new file mode 100644 index 000000000..9224960b0 --- /dev/null +++ b/src/devices/wifi/cara-wifi-manager.cc @@ -0,0 +1,193 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2004,2005,2006 INRIA + * + * 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: Federico Maguolo + */ + +#include "cara-wifi-manager.h" +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/simulator.h" + +NS_LOG_COMPONENT_DEFINE ("Cara"); + + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED(CaraWifiManager); + +CaraWifiRemoteStation::CaraWifiRemoteStation (Ptr manager) + : m_manager (manager) +{ + m_rate = GetMinRate (); + + m_success = 0; + m_failed = 0; + m_timer = 0; +} +CaraWifiRemoteStation::~CaraWifiRemoteStation () +{} + +uint32_t +CaraWifiRemoteStation::GetMaxRate (void) +{ + return GetNSupportedModes () - 1; +} +uint32_t +CaraWifiRemoteStation::GetMinRate (void) +{ + return 0; +} + +bool +CaraWifiRemoteStation::NeedNormalFallback (void) +{ + return (m_failed >= m_manager->m_failureThreshold); +} + +void +CaraWifiRemoteStation::DoReportRtsFailed (void) +{} + +void +CaraWifiRemoteStation::DoReportDataFailed (void) +{ + NS_LOG_FUNCTION (this); + m_timer++; + m_failed++; + m_success = 0; + if (NeedNormalFallback ()) + { + NS_LOG_DEBUG ("self="< () + .AddConstructor () + .AddAttribute ("ProbeThreshold", + "The number of consecutive transmissions failure to activate the RTS probe.", + UintegerValue (1), + MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold), + MakeUintegerChecker ()) + .AddAttribute ("FailureThreshold", + "The number of consecutive transmissions failure to decrease the rate.", + UintegerValue (2), + MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold), + MakeUintegerChecker ()) + .AddAttribute ("SuccessThreshold", + "The minimum number of sucessfull transmissions to try a new rate.", + UintegerValue (10), + MakeUintegerAccessor (&CaraWifiManager::m_successThreshold), + MakeUintegerChecker ()) + .AddAttribute ("Timeout", + "The 'timer' in the CARA algorithm", + UintegerValue (15), + MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout), + MakeUintegerChecker ()) + ; + return tid; +} + +CaraWifiManager::CaraWifiManager () + : WifiRemoteStationManager () +{} +CaraWifiManager::~CaraWifiManager () +{} + +WifiRemoteStation * +CaraWifiManager::CreateStation (void) +{ + return new CaraWifiRemoteStation (this); +} + +} // namespace ns3 diff --git a/src/devices/wifi/cara-wifi-manager.h b/src/devices/wifi/cara-wifi-manager.h new file mode 100644 index 000000000..0e47348e6 --- /dev/null +++ b/src/devices/wifi/cara-wifi-manager.h @@ -0,0 +1,91 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Federico Maguolo + */ +#ifndef CARA_WIFI_MANAGER_H +#define CARA_WIFI_MANAGER_H + +#include "wifi-remote-station-manager.h" + +namespace ns3 { + +/** + * \brief implement the CARA rate control algorithm + * + * Implement the CARA algorithm from: + * J. Kim, S. Kim, S. Choi, and D. Qiao. + * "CARA: Collision-Aware Rate Adaptation for IEEE 802.11 WLANs." + * + * Originally implemented by Federico Maguolo for a very early + * prototype version of ns-3. + */ +class CaraWifiManager : public WifiRemoteStationManager +{ +public: + static TypeId GetTypeId (void); + CaraWifiManager (); + virtual ~CaraWifiManager (); + +private: + friend class CaraWifiRemoteStation; + virtual class WifiRemoteStation *CreateStation (void); + uint32_t m_timerTimeout; + uint32_t m_successThreshold; + uint32_t m_failureThreshold; + uint32_t m_probeThreshold; +}; + + +class CaraWifiRemoteStation : public WifiRemoteStation +{ +public: + CaraWifiRemoteStation (Ptr manager); + virtual ~CaraWifiRemoteStation (); + +private: + virtual Ptr GetManager (void) const; + virtual void DoReportRtsFailed (void); + virtual void DoReportDataFailed (void); + virtual void DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr); + virtual void DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr); + virtual void DoReportFinalRtsFailed (void); + virtual void DoReportFinalDataFailed (void); + virtual void DoReportRxOk (double rxSnr, WifiMode txMode); + virtual WifiMode DoGetDataMode (uint32_t size); + virtual WifiMode DoGetRtsMode (void); + + virtual bool NeedRts (Ptr packet); + + uint32_t m_timer; + uint32_t m_success; + uint32_t m_failed; + + uint32_t m_rate; + + Ptr m_manager; + + uint32_t GetMaxRate (void); + uint32_t GetMinRate (void); + + bool NeedNormalFallback (void); + +}; + +} // namespace ns3 + +#endif /* CARA_WIFI_MANAGER_H */ diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 18787ab57..01cf118b2 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -1,4 +1,22 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #ifdef RUN_SELF_TESTS #include "ns3/test.h" diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index c2dbc9e63..6dd69b31f 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -1,4 +1,22 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #include "ns3/assert.h" #include "ns3/log.h" diff --git a/src/devices/wifi/interference-helper.cc b/src/devices/wifi/interference-helper.cc index fa50b5674..dff6c5eb9 100644 --- a/src/devices/wifi/interference-helper.cc +++ b/src/devices/wifi/interference-helper.cc @@ -1,3 +1,22 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #include "interference-helper.h" #include "wifi-phy.h" #include "error-rate-model.h" @@ -137,15 +156,15 @@ InterferenceHelper::GetMaxPacketDuration (void) const } void -InterferenceHelper::SetNoiseFloorW (double noiseFloor) +InterferenceHelper::SetNoiseFigure (double value) { - m_noiseFloorW = noiseFloor; + m_noiseFigure = value; } double -InterferenceHelper::GetNoiseFloorW (void) const +InterferenceHelper::GetNoiseFigure (void) const { - return m_noiseFloorW; + return m_noiseFigure; } void @@ -260,9 +279,10 @@ InterferenceHelper::CalculateSnr (double signal, double noiseInterference, WifiM { // thermal noise at 290K in J/s = W static const double BOLTZMANN = 1.3803e-23; + // Nt is the power of thermal noise in W double Nt = BOLTZMANN * 290.0 * mode.GetBandwidth (); - // receiver noise Floor (W) - double noiseFloor = m_noiseFloorW * Nt; + // receiver noise Floor (W) which accounts for thermal noise and non-idealities of the receiver + double noiseFloor = m_noiseFigure * Nt; double noise = noiseFloor + noiseInterference; double snr = signal / noise; return snr; diff --git a/src/devices/wifi/interference-helper.h b/src/devices/wifi/interference-helper.h index 29d284501..0b40e239d 100644 --- a/src/devices/wifi/interference-helper.h +++ b/src/devices/wifi/interference-helper.h @@ -1,3 +1,22 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #ifndef INTERFERENCE_HELPER_H #define INTERFERENCE_HELPER_H @@ -50,10 +69,10 @@ public: ~InterferenceHelper (); void Configure80211aParameters (void); - void SetNoiseFloorW (double noiseFloor); + void SetNoiseFigure (double value); void SetErrorRateModel (Ptr rate); - double GetNoiseFloorW (void) const; + double GetNoiseFigure (void) const; Ptr GetErrorRateModel (void) const; @@ -99,7 +118,7 @@ private: WifiMode m_shortPlcpHeaderMode; uint32_t m_plcpHeaderLength; Time m_maxPacketDuration; - double m_noiseFloorW; + double m_noiseFigure; /**< noise figure (linear) */ Events m_events; bool m_80211a; Ptr m_errorRateModel; diff --git a/src/devices/wifi/rraa-wifi-manager.cc b/src/devices/wifi/rraa-wifi-manager.cc index 85e9a6c0d..93285a4fa 100644 --- a/src/devices/wifi/rraa-wifi-manager.cc +++ b/src/devices/wifi/rraa-wifi-manager.cc @@ -29,6 +29,8 @@ NS_LOG_COMPONENT_DEFINE ("RraaWifiManager"); namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED(RraaWifiManager); RraaWifiRemoteStation::RraaWifiRemoteStation (Ptr stations) : m_stations (stations) @@ -188,7 +190,7 @@ RraaWifiRemoteStation::ARts (void) TypeId RraaWifiManager::GetTypeId (void) { - static TypeId tid = TypeId ("RraaWifiManager") + static TypeId tid = TypeId ("ns3::RraaWifiManager") .SetParent () .AddConstructor () .AddAttribute ("Basic", diff --git a/src/devices/wifi/wifi-mode.cc b/src/devices/wifi/wifi-mode.cc index 3fe41c456..132773c28 100644 --- a/src/devices/wifi/wifi-mode.cc +++ b/src/devices/wifi/wifi-mode.cc @@ -87,6 +87,12 @@ WifiMode::GetConstellationSize (void) const std::string WifiMode::GetUniqueName (void) const { + // needed for ostream printing of the invalid mode + if (m_uid == 0) + { + return "Invalid-WifiMode"; + } + struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid); return item->uniqueUid; } diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index 5f67c2224..d7dccc85d 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -136,16 +136,6 @@ WifiNetDevice::GetRemoteStationManager (void) const return m_stationManager; } -void -WifiNetDevice::SetName(const std::string name) -{ - m_name = name; -} -std::string -WifiNetDevice::GetName(void) const -{ - return m_name; -} void WifiNetDevice::SetIfIndex(const uint32_t index) { diff --git a/src/devices/wifi/wifi-net-device.h b/src/devices/wifi/wifi-net-device.h index 2bee1d2f9..d5aae5797 100644 --- a/src/devices/wifi/wifi-net-device.h +++ b/src/devices/wifi/wifi-net-device.h @@ -75,8 +75,6 @@ public: // inherited from NetDevice base class. - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; virtual Ptr GetChannel (void) const; @@ -123,7 +121,6 @@ private: TracedCallback, Mac48Address> m_txLogger; uint32_t m_ifIndex; - std::string m_name; bool m_linkUp; Callback m_linkChange; mutable uint16_t m_mtu; diff --git a/src/devices/wifi/wifi-phy-test.cc b/src/devices/wifi/wifi-phy-test.cc index 5b1397476..500879d85 100644 --- a/src/devices/wifi/wifi-phy-test.cc +++ b/src/devices/wifi/wifi-phy-test.cc @@ -1,3 +1,22 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #include "wifi-net-device.h" #include "yans-wifi-channel.h" #include "yans-wifi-phy.h" diff --git a/src/devices/wifi/wifi-remote-station-manager.cc b/src/devices/wifi/wifi-remote-station-manager.cc index 7d2f2e535..de3a3cf96 100644 --- a/src/devices/wifi/wifi-remote-station-manager.cc +++ b/src/devices/wifi/wifi-remote-station-manager.cc @@ -97,7 +97,7 @@ NonUnicastWifiRemoteStation::DoReportFinalDataFailed (void) WifiMode NonUnicastWifiRemoteStation::DoGetDataMode (uint32_t size) { - WifiMode mode = m_stations->GetBasicMode (0); + WifiMode mode = m_stations->GetNonUnicastMode (); NS_LOG_DEBUG ("non-unicast size="< SupportedModes; virtual Ptr GetManager (void) const = 0; virtual WifiMode DoGetDataMode (uint32_t size) = 0; virtual WifiMode DoGetRtsMode (void) = 0; - uint32_t GetNFragments (Ptr packet); -protected: virtual void DoReportRtsFailed (void) = 0; virtual void DoReportDataFailed (void) = 0; virtual void DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) = 0; @@ -272,9 +272,12 @@ protected: virtual void DoReportFinalRtsFailed (void) = 0; virtual void DoReportFinalDataFailed (void) = 0; virtual void DoReportRxOk (double rxSnr, WifiMode txMode) = 0; +protected: uint32_t GetNSupportedModes (void) const; WifiMode GetSupportedMode (uint32_t i) const; private: + typedef std::vector SupportedModes; + uint32_t GetNFragments (Ptr packet); bool IsIn (WifiMode mode) const; WifiMode GetControlAnswerMode (WifiMode reqMode); enum { diff --git a/src/devices/wifi/wifi-test.cc b/src/devices/wifi/wifi-test.cc index 045e7081b..2e15b4965 100644 --- a/src/devices/wifi/wifi-test.cc +++ b/src/devices/wifi/wifi-test.cc @@ -1,3 +1,22 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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: Mathieu Lacage + */ #ifdef RUN_SELF_TESTS #include "wifi-net-device.h" diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index 30098e7b1..710659ffb 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -42,6 +42,8 @@ def build(bld): 'amrr-wifi-manager.cc', 'onoe-wifi-manager.cc', 'rraa-wifi-manager.cc', + 'aarfcd-wifi-manager.cc', + 'cara-wifi-manager.cc', 'constant-rate-wifi-manager.cc', 'wifi-test.cc', ] diff --git a/src/devices/wifi/yans-wifi-phy.cc b/src/devices/wifi/yans-wifi-phy.cc index 95d1455c5..181b904e8 100644 --- a/src/devices/wifi/yans-wifi-phy.cc +++ b/src/devices/wifi/yans-wifi-phy.cc @@ -93,11 +93,17 @@ YansWifiPhy::GetTypeId (void) MakeDoubleAccessor (&YansWifiPhy::SetTxPowerStart, &YansWifiPhy::GetTxPowerStart), MakeDoubleChecker ()) - .AddAttribute ("RxNoise", - "Ratio of energy lost by receiver (dB).", + .AddAttribute ("RxNoiseFigure", + "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver." + " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is " + "\"the difference in decibels (dB) between" + " the noise output of the actual receiver to the noise output of an " + " ideal receiver with the same overall gain and bandwidth when the receivers " + " are connected to sources at the standard noise temperature T0 (usually 290 K)\"." + " For", DoubleValue (7), - MakeDoubleAccessor (&YansWifiPhy::SetRxNoise, - &YansWifiPhy::GetRxNoise), + MakeDoubleAccessor (&YansWifiPhy::SetRxNoiseFigure, + &YansWifiPhy::GetRxNoiseFigure), MakeDoubleChecker ()) .AddAttribute ("Standard", "The standard chosen configures a set of transmission modes" " and some PHY-specific constants.", @@ -163,10 +169,10 @@ YansWifiPhy::SetStandard (enum WifiPhyStandard standard) void -YansWifiPhy::SetRxNoise (double db) +YansWifiPhy::SetRxNoiseFigure (double noiseFigureDb) { - NS_LOG_FUNCTION (this << db); - m_interference.SetNoiseFloorW (DbToRatio (db)); + NS_LOG_FUNCTION (this << noiseFigureDb); + m_interference.SetNoiseFigure (DbToRatio (noiseFigureDb)); } void YansWifiPhy::SetTxPowerStart (double start) @@ -227,9 +233,9 @@ YansWifiPhy::SetMobility (Ptr mobility) } double -YansWifiPhy::GetRxNoise (void) const +YansWifiPhy::GetRxNoiseFigure (void) const { - return RatioToDb (m_interference.GetNoiseFloorW ()); + return RatioToDb (m_interference.GetNoiseFigure ()); } double YansWifiPhy::GetTxPowerStart (void) const diff --git a/src/devices/wifi/yans-wifi-phy.h b/src/devices/wifi/yans-wifi-phy.h index f06b1a9e8..ef6488863 100644 --- a/src/devices/wifi/yans-wifi-phy.h +++ b/src/devices/wifi/yans-wifi-phy.h @@ -90,7 +90,7 @@ public: WifiPreamble preamble); void SetStandard (enum WifiPhyStandard standard); - void SetRxNoise (double ratio); + void SetRxNoiseFigure (double noiseFigureDb); void SetTxPowerStart (double start); void SetTxPowerEnd (double end); void SetNTxPower (uint32_t n); @@ -101,7 +101,7 @@ public: void SetErrorRateModel (Ptr rate); void SetDevice (Ptr device); void SetMobility (Ptr mobility); - double GetRxNoise (void) const; + double GetRxNoiseFigure (void) const; double GetTxGain (void) const; double GetRxGain (void) const; double GetEdThreshold (void) const; diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index fd033726d..58526d33a 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -18,7 +18,7 @@ * Author: Mathieu Lacage */ #include "olsr-helper.h" -#include "ns3/olsr-agent.h" +#include "ns3/olsr-routing-protocol.h" #include "ns3/node-list.h" #include "ns3/names.h" @@ -26,7 +26,7 @@ namespace ns3 { OlsrHelper::OlsrHelper () { - m_agentFactory.SetTypeId ("ns3::olsr::AgentImpl"); + m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol"); } void @@ -63,15 +63,17 @@ OlsrHelper::Install (NodeContainer container) void OlsrHelper::Install (Ptr node) { - if (node->GetObject () != 0) + if (node->GetObject () != 0) { NS_FATAL_ERROR ("OlsrHelper::Install(): Aggregating " - "an Olsr Agent to a node with an existing Olsr Agent"); + "an Olsr Agent to a node with an existing Olsr RoutingProtocol"); return; } - Ptr agent = m_agentFactory.Create (); - agent->SetNode (node); + Ptr agent = m_agentFactory.Create (); node->AggregateObject (agent); + Ptr ipv4 = node->GetObject (); + ipv4->AddRoutingProtocol (agent, 10); + agent->SetNode (node); agent->Start (); } void diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index 7db006e4d..a11215564 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -150,7 +150,13 @@ void Ipv4L3Protocol::DoDispose (void) { NS_LOG_FUNCTION (this); - for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) + + for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i) + { + *i = 0; + } + + for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { *i = 0; } diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index 7a129f052..7896a1f82 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -52,15 +52,46 @@ HierarchicalMobilityModel::HierarchicalMobilityModel () void HierarchicalMobilityModel::SetChild (Ptr model) { + Ptr oldChild = m_child; + Vector pos; + if (m_child) + { + pos = GetPosition (); + m_child->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this)); + } m_child = model; m_child->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this)); + + // if we had a child before, then we had a valid position before; + // try to preserve the old absolute position. + if (oldChild) + { + SetPosition (pos); + } } void HierarchicalMobilityModel::SetParent (Ptr model) { + Vector pos; + if (m_child) + { + pos = GetPosition (); + } + if (m_parent) + { + m_parent->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); + } m_parent = model; - m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); + if (m_parent) + { + m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); + } + // try to preserve the old position across parent changes + if (m_child) + { + SetPosition (pos); + } } @@ -79,6 +110,10 @@ HierarchicalMobilityModel::GetParent (void) const Vector HierarchicalMobilityModel::DoGetPosition (void) const { + if (!m_parent) + { + return m_child->GetPosition (); + } Vector parentPosition = m_parent->GetPosition (); Vector childPosition = m_child->GetPosition (); return Vector (parentPosition.x + childPosition.x, @@ -88,27 +123,41 @@ HierarchicalMobilityModel::DoGetPosition (void) const void HierarchicalMobilityModel::DoSetPosition (const Vector &position) { - if (m_parent == 0 || m_child == 0) + if (m_child == 0) { return; } // This implementation of DoSetPosition is really an arbitraty choice. // anything else would have been ok. - Vector parentPosition = m_parent->GetPosition (); - Vector childPosition (position.x - parentPosition.x, - position.y - parentPosition.y, - position.z - parentPosition.z); - m_child->SetPosition (childPosition); + if (m_parent) + { + Vector parentPosition = m_parent->GetPosition (); + Vector childPosition (position.x - parentPosition.x, + position.y - parentPosition.y, + position.z - parentPosition.z); + m_child->SetPosition (childPosition); + } + else + { + m_child->SetPosition (position); + } } Vector HierarchicalMobilityModel::DoGetVelocity (void) const { - Vector parentSpeed = m_parent->GetVelocity (); - Vector childSpeed = m_child->GetVelocity (); - Vector speed (parentSpeed.x + childSpeed.x, - parentSpeed.y + childSpeed.y, - parentSpeed.z + childSpeed.z); - return speed; + if (m_parent) + { + Vector parentSpeed = m_parent->GetVelocity (); + Vector childSpeed = m_child->GetVelocity (); + Vector speed (parentSpeed.x + childSpeed.x, + parentSpeed.y + childSpeed.y, + parentSpeed.z + childSpeed.z); + return speed; + } + else + { + return m_child->GetVelocity (); + } } void diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index f2d1cda70..5ef664863 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -27,8 +27,31 @@ namespace ns3 { /** * \brief a hierachical mobility model. * - * This model allows you to specify the position of a - * child object relative to a parent object. + * This model allows you to specify the position of a child object + * relative to a parent object. + * + * Basically this is a mobility model that combines two other mobility + * models: a "parent" model and a "child" model. The position of the + * hierarchical model is always the vector sum of the parent + child + * positions, so that if the parent model "moves", then this model + * will report an equal relative movement. Useful, for instance, if + * you want to simulate a node inside another node that moves, such as + * a vehicle. + * + * Setting the position on this model is always done using world + * absolute coordinates, and it changes only the child mobility model + * position, never the parent. The child mobility model always uses a + * coordinate sytem relative to the parent model position. + * + * @note: as a special case, the parent model may be NULL, which is + * semantically equivalent to having a ConstantPositionMobilityModel + * as parent positioned at origin (0,0,0). In other words, setting + * the parent model to NULL makes the child model and the hierarchical + * model start using world absolute coordinates. + * + * @warning: changing the parent/child mobility models in the middle + * of a simulation will probably not play very well with the + * ConfigStore APIs, so do this only if you know what you are doing. */ class HierarchicalMobilityModel : public MobilityModel { @@ -52,14 +75,26 @@ public: * position by the child mobility model. */ Ptr GetParent (void) const; + /** + * Sets the child mobility model to a new one. If before there + * already existed a child model, then the child mobility model + * current position is also modified to ensure that the composite + * position is preserved. + */ + void SetChild (Ptr model); + /** + * Sets the parent mobility model to a new one. If before there + * already existed a child model, then the child mobility model + * current position is also modified to ensure that the composite + * position is preserved. + */ + void SetParent (Ptr model); private: virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); virtual Vector DoGetVelocity (void) const; - void SetChild (Ptr model); - void SetParent (Ptr model); void ParentChanged (Ptr model); void ChildChanged (Ptr model); diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index 5188fff82..bff248676 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -45,7 +45,7 @@ RandomWaypointMobilityModel::GetTypeId (void) RandomVariableValue (ConstantVariable (2.0)), MakeRandomVariableAccessor (&RandomWaypointMobilityModel::m_pause), MakeRandomVariableChecker ()) - .AddAttribute ("Position", + .AddAttribute ("PositionAllocator", "The position model used to pick a destination point.", PointerValue (), MakePointerAccessor (&RandomWaypointMobilityModel::m_position), diff --git a/src/node/channel.cc b/src/node/channel.cc index 6f23bad49..e85503c66 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -35,34 +35,14 @@ Channel::GetTypeId (void) } Channel::Channel () - : m_name("Channel") { NS_LOG_FUNCTION_NOARGS (); } -Channel::Channel (std::string name) - : m_name(name) -{ - NS_LOG_FUNCTION (this << name); -} Channel::~Channel () { NS_LOG_FUNCTION_NOARGS (); } - void -Channel::SetName(std::string name) -{ - NS_LOG_FUNCTION (this << name); - m_name = name; -} - - std::string -Channel::GetName(void) -{ - NS_LOG_FUNCTION_NOARGS (); - return m_name; -} - } // namespace ns3 diff --git a/src/node/channel.h b/src/node/channel.h index 1e4a0cd6a..68f8d3175 100644 --- a/src/node/channel.h +++ b/src/node/channel.h @@ -43,12 +43,8 @@ public: static TypeId GetTypeId (void); Channel (); - Channel (std::string name); virtual ~Channel (); - void SetName(std::string); - std::string GetName(void); - /** * \returns the number of NetDevices connected to this Channel. * @@ -63,10 +59,8 @@ public: */ virtual Ptr GetDevice (uint32_t i) const = 0; -private: - std::string m_name; }; -}; // namespace ns3 +} // namespace ns3 #endif /* NS3_CHANNEL_H */ diff --git a/src/node/ipv6-address.cc b/src/node/ipv6-address.cc index adab50e86..ef99226df 100644 --- a/src/node/ipv6-address.cc +++ b/src/node/ipv6-address.cc @@ -338,7 +338,8 @@ void Ipv6Address::Print (std::ostream& os) const << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[12] << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[13] << ":" << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[14] - << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[15]; + << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[15] + << std::dec << std::setfill(' '); } bool Ipv6Address::IsLocalhost () const diff --git a/src/node/net-device.h b/src/node/net-device.h index ced6c9dff..dcdaa6d75 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -67,14 +67,6 @@ public: static TypeId GetTypeId (void); virtual ~NetDevice(); - /** - * \param name name of the device (e.g. "eth0") - */ - virtual void SetName(const std::string name) = 0; - /** - * \return name name of the device (e.g. "eth0") - */ - virtual std::string GetName(void) const = 0; /** * \param index ifIndex of the device */ diff --git a/src/node/node.cc b/src/node/node.cc index 9cecbab14..199490484 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -225,7 +225,7 @@ bool Node::PromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) { - NS_LOG_FUNCTION(device->GetName ()); + NS_LOG_FUNCTION(this); return ReceiveFromDevice (device, packet, protocol, from, to, packetType, true); } @@ -233,7 +233,7 @@ bool Node::NonPromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, const Address &from) { - NS_LOG_FUNCTION(device->GetName ()); + NS_LOG_FUNCTION(this); return ReceiveFromDevice (device, packet, protocol, from, from, NetDevice::PacketType (0), false); } @@ -242,8 +242,7 @@ Node::ReceiveFromDevice (Ptr device, Ptr packet, uint16 const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous) { NS_LOG_DEBUG("Node " << GetId () << " ReceiveFromDevice: dev " - << device->GetIfIndex () << " (" - << device->GetName () << " type " << device->GetInstanceTypeId ().GetName () + << device->GetIfIndex () << " (type=" << device->GetInstanceTypeId ().GetName () << ") Packet UID " << packet->GetUid ()); bool found = false; diff --git a/src/node/simple-net-device.cc b/src/node/simple-net-device.cc index d13bd53fe..d996d5341 100644 --- a/src/node/simple-net-device.cc +++ b/src/node/simple-net-device.cc @@ -38,7 +38,6 @@ SimpleNetDevice::SimpleNetDevice () : m_channel (0), m_node (0), m_mtu (0xffff), - m_name (""), m_ifIndex (0) {} @@ -83,16 +82,6 @@ SimpleNetDevice::SetAddress (Mac48Address address) m_address = address; } -void -SimpleNetDevice::SetName(const std::string name) -{ - m_name = name; -} -std::string -SimpleNetDevice::GetName(void) const -{ - return m_name; -} void SimpleNetDevice::SetIfIndex(const uint32_t index) { diff --git a/src/node/simple-net-device.h b/src/node/simple-net-device.h index 1e1f15323..7840887cf 100644 --- a/src/node/simple-net-device.h +++ b/src/node/simple-net-device.h @@ -46,8 +46,6 @@ public: void SetAddress (Mac48Address address); // inherited from NetDevice base class. - virtual void SetName(const std::string name); - virtual std::string GetName(void) const; virtual void SetIfIndex(const uint32_t index); virtual uint32_t GetIfIndex(void) const; virtual Ptr GetChannel (void) const; @@ -82,7 +80,6 @@ private: NetDevice::PromiscReceiveCallback m_promiscCallback; Ptr m_node; uint16_t m_mtu; - std::string m_name; uint32_t m_ifIndex; Mac48Address m_address; }; diff --git a/src/node/socket.cc b/src/node/socket.cc index 4ceac3962..e13dcf43e 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -252,6 +252,19 @@ Socket::NotifyDataRecv (void) } } +void +Socket::DoDispose (void) +{ + + m_connectionSucceeded = MakeNullCallback > (); + m_connectionFailed = MakeNullCallback > (); + m_connectionRequest = MakeNullCallback, const Address &> (); + m_newConnectionCreated = MakeNullCallback, const Address &> (); + m_dataSent = MakeNullCallback, uint32_t> (); + m_sendCb = MakeNullCallback, uint32_t> (); + m_receivedData = MakeNullCallback > (); +} + /*************************************************************** * Socket Tags ***************************************************************/ diff --git a/src/node/socket.h b/src/node/socket.h index caba3627b..fbc4b723c 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -499,6 +499,7 @@ protected: void NotifyDataSent (uint32_t size); void NotifySend (uint32_t spaceAvailable); void NotifyDataRecv (void); + virtual void DoDispose (void); private: Callback > m_connectionSucceeded; Callback > m_connectionFailed; diff --git a/src/routing/olsr/olsr-agent.cc b/src/routing/olsr/olsr-agent.cc deleted file mode 100644 index 7b3c200a3..000000000 --- a/src/routing/olsr/olsr-agent.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INESC Porto - * - * 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: Gustavo J. A. M. Carneiro - */ - -#include "olsr-agent.h" - -namespace ns3 { -namespace olsr { - -NS_OBJECT_ENSURE_REGISTERED (Agent); - -TypeId -Agent::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::olsr::Agent") - .SetParent (); - return tid; -} - -}} diff --git a/src/routing/olsr/olsr-agent.h b/src/routing/olsr/olsr-agent.h deleted file mode 100644 index ab1bec264..000000000 --- a/src/routing/olsr/olsr-agent.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INESC Porto - * - * 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: Gustavo J. A. M. Carneiro - */ - -#ifndef OLSR_AGENT_H -#define OLSR_AGENT_H - -#include "ns3/node.h" -#include "ns3/olsr-routing-table.h" - -namespace ns3 { -namespace olsr { - -/** - * \brief Class implementing the OLSR state machine - * - * This class represents an instance of the OLSR protocol. It - * attaches itself to a Node, and its lifecycle is bound to that node. - * Normally the functions in the ns3::olsr namespace are more simple - * to use to start OLSR on nodes, but access to the underlying OLSR - * agent can be useful in order to customize the OLSR parameters. - * Example: - * - * \code - * Ptr olsr = Agend::CreateDefault (); - * agent->SetMainInterface (2); - * agent->Start (); - * \endcode - */ -class Agent : public Object -{ -public: - static TypeId GetTypeId (void); - - virtual void SetNode (Ptr node) = 0; - - /** - * \brief Sets the main interface to be used by OLSR - * - * Normally OLSR supports multiple interfaces, but the protocol - * requires the definition of a "main interface". This interface's - * IPv4 address provides the identity of the node, and all outgoing - * OLSR routing messages must have the main interface address, - * regardless of the actual interface used to transmit the packet. - * This method allows one to explicitly select an interface as the - * main interface. It must be called before the agent starts, but - * calling it is optional; if not called, the agent tries to guess - * and uses a suitable interface. - */ - virtual void SetMainInterface (uint32_t interface) = 0; - - /** - * \brief Starts the OLSR protocol operation - * - * Calling this method essentially bootstraps the OLSR protocol, and - * causes the agent to start broadcasting OLSR messages to - * neighbors, as well start listening to messages from neighbors. - */ - virtual void Start () = 0; - - virtual Ptr GetRoutingTable () const = 0; -}; - -}} // namespace olsr, ns3 - -#endif /* OLSR_AGENT_H */ - diff --git a/src/routing/olsr/repositories.h b/src/routing/olsr/olsr-repositories.h similarity index 99% rename from src/routing/olsr/repositories.h rename to src/routing/olsr/olsr-repositories.h index 386c7f221..4990a4094 100644 --- a/src/routing/olsr/repositories.h +++ b/src/routing/olsr/olsr-repositories.h @@ -21,7 +21,7 @@ */ /// -/// \file OLSR_repositories.h +/// \file OLSR_olsr-repositories.h /// \brief Here are defined all data structures needed by an OLSR node. /// diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-routing-protocol.cc similarity index 86% rename from src/routing/olsr/olsr-agent-impl.cc rename to src/routing/olsr/olsr-routing-protocol.cc index 6252f984d..72c734008 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-routing-protocol.cc @@ -33,7 +33,7 @@ if (GetObject ()) { std::clog << "[node " << GetObject ()->GetId () << "] "; } -#include "olsr-agent-impl.h" +#include "olsr-routing-protocol.h" #include "ns3/socket-factory.h" #include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" @@ -44,6 +44,7 @@ #include "ns3/uinteger.h" #include "ns3/enum.h" #include "ns3/trace-source-accessor.h" +#include "ns3/ipv4-header.h" /********** Useful macros **********/ @@ -142,63 +143,63 @@ NS_LOG_COMPONENT_DEFINE ("OlsrAgent"); /********** OLSR class **********/ -NS_OBJECT_ENSURE_REGISTERED (AgentImpl); +NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); TypeId -AgentImpl::GetTypeId (void) +RoutingProtocol::GetTypeId (void) { - static TypeId tid = TypeId ("ns3::olsr::AgentImpl") - .SetParent () - .AddConstructor () + static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol") + .SetParent () + .AddConstructor () .AddAttribute ("HelloInterval", "HELLO messages emission interval.", TimeValue (Seconds (2)), - MakeTimeAccessor (&AgentImpl::m_helloInterval), + MakeTimeAccessor (&RoutingProtocol::m_helloInterval), MakeTimeChecker ()) .AddAttribute ("TcInterval", "TC messages emission interval.", TimeValue (Seconds (5)), - MakeTimeAccessor (&AgentImpl::m_tcInterval), + MakeTimeAccessor (&RoutingProtocol::m_tcInterval), MakeTimeChecker ()) .AddAttribute ("MidInterval", "MID messages emission interval. Normally it is equal to TcInterval.", TimeValue (Seconds (5)), - MakeTimeAccessor (&AgentImpl::m_midInterval), + MakeTimeAccessor (&RoutingProtocol::m_midInterval), MakeTimeChecker ()) .AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.", EnumValue (OLSR_WILL_DEFAULT), - MakeEnumAccessor (&AgentImpl::m_willingness), + MakeEnumAccessor (&RoutingProtocol::m_willingness), MakeEnumChecker (OLSR_WILL_NEVER, "never", OLSR_WILL_LOW, "low", OLSR_WILL_DEFAULT, "default", OLSR_WILL_HIGH, "high", OLSR_WILL_ALWAYS, "always")) .AddTraceSource ("Rx", "Receive OLSR packet.", - MakeTraceSourceAccessor (&AgentImpl::m_rxPacketTrace)) + MakeTraceSourceAccessor (&RoutingProtocol::m_rxPacketTrace)) .AddTraceSource ("Tx", "Send OLSR packet.", - MakeTraceSourceAccessor (&AgentImpl::m_txPacketTrace)) + MakeTraceSourceAccessor (&RoutingProtocol::m_txPacketTrace)) .AddTraceSource ("RoutingTableChanged", "The OLSR routing table has changed.", - MakeTraceSourceAccessor (&AgentImpl::m_routingTableChanged)) + MakeTraceSourceAccessor (&RoutingProtocol::m_routingTableChanged)) ; return tid; } -AgentImpl::AgentImpl () +RoutingProtocol::RoutingProtocol () : m_helloTimer (Timer::CANCEL_ON_DESTROY), m_tcTimer (Timer::CANCEL_ON_DESTROY), m_midTimer (Timer::CANCEL_ON_DESTROY) {} -AgentImpl::~AgentImpl () +RoutingProtocol::~RoutingProtocol () {} void -AgentImpl::SetNode (Ptr node) +RoutingProtocol::SetNode (Ptr node) { - NS_LOG_DEBUG ("Created olsr::AgentImpl"); - m_helloTimer.SetFunction (&AgentImpl::HelloTimerExpire, this); - m_tcTimer.SetFunction (&AgentImpl::TcTimerExpire, this); - m_midTimer.SetFunction (&AgentImpl::MidTimerExpire, this); - m_queuedMessagesTimer.SetFunction (&AgentImpl::SendQueuedMessages, this); + NS_LOG_DEBUG ("Created olsr::RoutingProtocol"); + m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); + m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this); + m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this); + m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this); m_packetSequenceNumber = OLSR_MAX_SEQ_NUM; m_messageSequenceNumber = OLSR_MAX_SEQ_NUM; @@ -210,27 +211,21 @@ AgentImpl::SetNode (Ptr node) NS_ASSERT (m_ipv4); } -void AgentImpl::DoDispose () +void RoutingProtocol::DoDispose () { m_ipv4 = 0; for (std::map< Ptr, Ipv4Address >::iterator iter = m_socketAddresses.begin (); iter != m_socketAddresses.end (); iter++) { - iter->first->Dispose (); + iter->first->Close (); } m_socketAddresses.clear (); - if (m_routingTable) - { - m_routingTable->Dispose (); - m_routingTable = 0; - } - - Object::DoDispose (); + Ipv4RoutingProtocol::DoDispose (); } -void AgentImpl::Start () +void RoutingProtocol::Start () { if (m_mainAddress == Ipv4Address ()) { @@ -250,13 +245,6 @@ void AgentImpl::Start () NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress); - m_routingTable = CreateObject (); - m_routingTable->SetIpv4 (m_ipv4); - m_routingTable->SetMainAddress (m_mainAddress); - // Add OLSR as routing protocol, with slightly higher priority than - // static routing. - m_ipv4->AddRoutingProtocol (m_routingTable, 10); - Ipv4Address loopback ("127.0.0.1"); for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) { @@ -279,7 +267,7 @@ void AgentImpl::Start () // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), UdpSocketFactory::GetTypeId()); - socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this)); + socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvOlsr, this)); if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER))) { NS_FATAL_ERROR ("Failed to bind() OLSR receive socket"); @@ -295,7 +283,7 @@ void AgentImpl::Start () NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started"); } -void AgentImpl::SetMainInterface (uint32_t interface) +void RoutingProtocol::SetMainInterface (uint32_t interface) { m_mainAddress = m_ipv4->GetAddress (interface); } @@ -304,7 +292,7 @@ void AgentImpl::SetMainInterface (uint32_t interface) // // \brief Processes an incoming %OLSR packet following RFC 3626 specification. void -AgentImpl::RecvOlsr (Ptr socket) +RoutingProtocol::RecvOlsr (Ptr socket) { Ptr receivedPacket; Address sourceAddress; @@ -453,7 +441,7 @@ AgentImpl::RecvOlsr (Ptr socket) /// \return the degree of the node. /// int -AgentImpl::Degree (NeighborTuple const &tuple) +RoutingProtocol::Degree (NeighborTuple const &tuple) { int degree = 0; for (TwoHopNeighborSet::const_iterator it = m_state.GetTwoHopNeighbors ().begin (); @@ -475,7 +463,7 @@ AgentImpl::Degree (NeighborTuple const &tuple) /// \brief Computates MPR set of a node following RFC 3626 hints. /// void -AgentImpl::MprComputation() +RoutingProtocol::MprComputation() { NS_LOG_FUNCTION (this); @@ -744,7 +732,7 @@ AgentImpl::MprComputation() /// \return the corresponding main address. /// Ipv4Address -AgentImpl::GetMainAddress (Ipv4Address iface_addr) const +RoutingProtocol::GetMainAddress (Ipv4Address iface_addr) const { const IfaceAssocTuple *tuple = m_state.FindIfaceAssocTuple (iface_addr); @@ -759,13 +747,13 @@ AgentImpl::GetMainAddress (Ipv4Address iface_addr) const /// \brief Creates the routing table of the node following RFC 3626 hints. /// void -AgentImpl::RoutingTableComputation () +RoutingProtocol::RoutingTableComputation () { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " s: Node " << m_mainAddress << ": RoutingTableComputation begin..."); // 1. All the entries from the routing table are removed. - m_routingTable->Clear (); + Clear (); // 2. The new routing entries are added starting with the // symmetric neighbors (h=1) as the destination nodes. @@ -792,10 +780,10 @@ AgentImpl::RoutingTableComputation () NS_LOG_LOGIC ("Link tuple matches neighbor " << nb_tuple.neighborMainAddr << " => adding routing table entry to neighbor"); lt = &link_tuple; - m_routingTable->AddEntry (link_tuple.neighborIfaceAddr, - link_tuple.neighborIfaceAddr, - link_tuple.localIfaceAddr, - 1); + AddEntry (link_tuple.neighborIfaceAddr, + link_tuple.neighborIfaceAddr, + link_tuple.localIfaceAddr, + 1); if (link_tuple.neighborIfaceAddr == nb_tuple.neighborMainAddr) { nb_main_addr = true; @@ -823,10 +811,10 @@ AgentImpl::RoutingTableComputation () { NS_LOG_LOGIC ("no R_dest_addr is equal to the main address of the neighbor " "=> adding additional routing entry"); - m_routingTable->AddEntry(nb_tuple.neighborMainAddr, - lt->neighborIfaceAddr, - lt->localIfaceAddr, - 1); + AddEntry(nb_tuple.neighborMainAddr, + lt->neighborIfaceAddr, + lt->localIfaceAddr, + 1); } } } @@ -892,11 +880,11 @@ AgentImpl::RoutingTableComputation () // R_dest_addr == N_neighbor_main_addr // of the 2-hop tuple; RoutingTableEntry entry; - bool foundEntry = m_routingTable->Lookup (nb2hop_tuple.neighborMainAddr, entry); + bool foundEntry = Lookup (nb2hop_tuple.neighborMainAddr, entry); if (foundEntry) { NS_LOG_LOGIC ("Adding routing entry for two-hop neighbor."); - m_routingTable->AddEntry (nb2hop_tuple.twoHopNeighborAddr, + AddEntry (nb2hop_tuple.twoHopNeighborAddr, entry.nextAddr, entry.interface, 2); @@ -927,8 +915,8 @@ AgentImpl::RoutingTableComputation () NS_LOG_LOGIC ("Looking at topology tuple: " << topology_tuple); RoutingTableEntry destAddrEntry, lastAddrEntry; - bool have_destAddrEntry = m_routingTable->Lookup (topology_tuple.destAddr, destAddrEntry); - bool have_lastAddrEntry = m_routingTable->Lookup (topology_tuple.lastAddr, lastAddrEntry); + bool have_destAddrEntry = Lookup (topology_tuple.destAddr, destAddrEntry); + bool have_lastAddrEntry = Lookup (topology_tuple.lastAddr, lastAddrEntry); if (!have_destAddrEntry && have_lastAddrEntry && lastAddrEntry.distance == h) { NS_LOG_LOGIC ("Adding routing table entry based on the topology tuple."); @@ -942,10 +930,10 @@ AgentImpl::RoutingTableComputation () // R_iface_addr = R_iface_addr of the recorded // route entry where: // R_dest_addr == T_last_addr. - m_routingTable->AddEntry (topology_tuple.destAddr, - lastAddrEntry.nextAddr, - lastAddrEntry.interface, - h + 1); + AddEntry (topology_tuple.destAddr, + lastAddrEntry.nextAddr, + lastAddrEntry.interface, + h + 1); added = true; } else @@ -973,8 +961,8 @@ AgentImpl::RoutingTableComputation () { IfaceAssocTuple const &tuple = *it; RoutingTableEntry entry1, entry2; - bool have_entry1 = m_routingTable->Lookup (tuple.mainAddr, entry1); - bool have_entry2 = m_routingTable->Lookup (tuple.ifaceAddr, entry2); + bool have_entry1 = Lookup (tuple.mainAddr, entry1); + bool have_entry2 = Lookup (tuple.ifaceAddr, entry2); if (have_entry1 && !have_entry2) { // then a route entry is created in the routing table with: @@ -983,15 +971,15 @@ AgentImpl::RoutingTableComputation () // R_next_addr = R_next_addr (of the recorded route entry) // R_dist = R_dist (of the recorded route entry) // R_iface_addr = R_iface_addr (of the recorded route entry). - m_routingTable->AddEntry (tuple.ifaceAddr, - entry1.nextAddr, - entry1.interface, - entry1.distance); + AddEntry (tuple.ifaceAddr, + entry1.nextAddr, + entry1.interface, + entry1.distance); } } NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end."); - m_routingTableChanged (m_routingTable->GetSize ()); + m_routingTableChanged (GetSize ()); } @@ -1006,7 +994,7 @@ AgentImpl::RoutingTableComputation () /// \param sender_iface the address of the interface where the message was sent from. /// void -AgentImpl::ProcessHello (const olsr::MessageHeader &msg, +RoutingProtocol::ProcessHello (const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface) { @@ -1067,7 +1055,7 @@ AgentImpl::ProcessHello (const olsr::MessageHeader &msg, /// \param sender_iface the address of the interface where the message was sent from. /// void -AgentImpl::ProcessTc (const olsr::MessageHeader &msg, +RoutingProtocol::ProcessTc (const olsr::MessageHeader &msg, const Ipv4Address &senderIface) { const olsr::MessageHeader::Tc &tc = msg.GetTc (); @@ -1130,7 +1118,7 @@ AgentImpl::ProcessTc (const olsr::MessageHeader &msg, // Schedules topology tuple deletion m_events.Track (Simulator::Schedule (DELAY (topologyTuple.expirationTime), - &AgentImpl::TopologyTupleTimerExpire, + &RoutingProtocol::TopologyTupleTimerExpire, this, topologyTuple.destAddr, topologyTuple.lastAddr)); @@ -1162,7 +1150,7 @@ AgentImpl::ProcessTc (const olsr::MessageHeader &msg, /// \param sender_iface the address of the interface where the message was sent from. /// void -AgentImpl::ProcessMid (const olsr::MessageHeader &msg, +RoutingProtocol::ProcessMid (const olsr::MessageHeader &msg, const Ipv4Address &senderIface) { const olsr::MessageHeader::Mid &mid = msg.GetMid (); @@ -1208,7 +1196,7 @@ AgentImpl::ProcessMid (const olsr::MessageHeader &msg, NS_LOG_LOGIC ("New IfaceAssoc added: " << tuple); // Schedules iface association tuple deletion Simulator::Schedule (DELAY (tuple.time), - &AgentImpl::IfaceAssocTupleTimerExpire, this, tuple.ifaceAddr); + &RoutingProtocol::IfaceAssocTupleTimerExpire, this, tuple.ifaceAddr); } } @@ -1244,7 +1232,7 @@ AgentImpl::ProcessMid (const olsr::MessageHeader &msg, /// \param local_iface the address of the interface where the message was received from. /// void -AgentImpl::ForwardDefault (olsr::MessageHeader olsrMessage, +RoutingProtocol::ForwardDefault (olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress) @@ -1304,7 +1292,7 @@ AgentImpl::ForwardDefault (olsr::MessageHeader olsrMessage, AddDuplicateTuple (newDup); // Schedule dup tuple deletion Simulator::Schedule (OLSR_DUP_HOLD_TIME, - &AgentImpl::DupTupleTimerExpire, this, + &RoutingProtocol::DupTupleTimerExpire, this, newDup.address, newDup.sequenceNumber); } } @@ -1319,7 +1307,7 @@ AgentImpl::ForwardDefault (olsr::MessageHeader olsrMessage, /// \param delay maximum delay the %OLSR message is going to be buffered. /// void -AgentImpl::QueueMessage (const olsr::MessageHeader &message, Time delay) +RoutingProtocol::QueueMessage (const olsr::MessageHeader &message, Time delay) { m_queuedMessages.push_back (message); if (not m_queuedMessagesTimer.IsRunning ()) @@ -1330,7 +1318,7 @@ AgentImpl::QueueMessage (const olsr::MessageHeader &message, Time delay) } void -AgentImpl::SendPacket (Ptr packet, +RoutingProtocol::SendPacket (Ptr packet, const MessageList &containedMessages) { NS_LOG_DEBUG ("OLSR node " << m_mainAddress << " sending a OLSR packet"); @@ -1356,7 +1344,7 @@ AgentImpl::SendPacket (Ptr packet, /// dictated by OLSR_MAX_MSGS constant. /// void -AgentImpl::SendQueuedMessages () +RoutingProtocol::SendQueuedMessages () { Ptr packet = Create (); int numMessages = 0; @@ -1395,7 +1383,7 @@ AgentImpl::SendQueuedMessages () /// \brief Creates a new %OLSR HELLO message which is buffered for being sent later on. /// void -AgentImpl::SendHello () +RoutingProtocol::SendHello () { NS_LOG_FUNCTION (this); @@ -1506,7 +1494,7 @@ AgentImpl::SendHello () /// \brief Creates a new %OLSR TC message which is buffered for being sent later on. /// void -AgentImpl::SendTc () +RoutingProtocol::SendTc () { NS_LOG_FUNCTION (this); @@ -1532,7 +1520,7 @@ AgentImpl::SendTc () /// \brief Creates a new %OLSR MID message which is buffered for being sent later on. /// void -AgentImpl::SendMid () +RoutingProtocol::SendMid () { olsr::MessageHeader msg; olsr::MessageHeader::Mid &mid = msg.GetMid (); @@ -1576,7 +1564,7 @@ AgentImpl::SendMid () /// \brief Updates Link Set according to a new received HELLO message (following RFC 3626 /// specification). Neighbor Set is also updated if needed. void -AgentImpl::LinkSensing (const olsr::MessageHeader &msg, +RoutingProtocol::LinkSensing (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, const Ipv4Address &senderIface) @@ -1700,7 +1688,7 @@ AgentImpl::LinkSensing (const olsr::MessageHeader &msg, { LinkTupleAdded (*link_tuple, hello.willingness); m_events.Track (Simulator::Schedule (DELAY (std::min (link_tuple->time, link_tuple->symTime)), - &AgentImpl::LinkTupleTimerExpire, this, + &RoutingProtocol::LinkTupleTimerExpire, this, link_tuple->neighborIfaceAddr)); } NS_LOG_DEBUG ("@" << now.GetSeconds () << ": Olsr node " << m_mainAddress @@ -1711,7 +1699,7 @@ AgentImpl::LinkSensing (const olsr::MessageHeader &msg, /// \brief Updates the Neighbor Set according to the information contained in a new received /// HELLO message (following RFC 3626). void -AgentImpl::PopulateNeighborSet (const olsr::MessageHeader &msg, +RoutingProtocol::PopulateNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) { NeighborTuple *nb_tuple = m_state.FindNeighborTuple (msg.GetOriginatorAddress ()); @@ -1726,7 +1714,7 @@ AgentImpl::PopulateNeighborSet (const olsr::MessageHeader &msg, /// \brief Updates the 2-hop Neighbor Set according to the information contained in a new /// received HELLO message (following RFC 3626). void -AgentImpl::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, +RoutingProtocol::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) { Time now = Simulator::Now (); @@ -1801,7 +1789,7 @@ AgentImpl::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, AddTwoHopNeighborTuple (new_nb2hop_tuple); // Schedules nb2hop tuple deletion m_events.Track (Simulator::Schedule (DELAY (new_nb2hop_tuple.expirationTime), - &AgentImpl::Nb2hopTupleTimerExpire, this, + &RoutingProtocol::Nb2hopTupleTimerExpire, this, new_nb2hop_tuple.neighborMainAddr, new_nb2hop_tuple.twoHopNeighborAddr)); } @@ -1838,7 +1826,7 @@ AgentImpl::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, /// \brief Updates the MPR Selector Set according to the information contained in a new /// received HELLO message (following RFC 3626). void -AgentImpl::PopulateMprSelectorSet (const olsr::MessageHeader &msg, +RoutingProtocol::PopulateMprSelectorSet (const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello) { NS_LOG_FUNCTION (this); @@ -1878,7 +1866,7 @@ AgentImpl::PopulateMprSelectorSet (const olsr::MessageHeader &msg, // Schedules mpr selector tuple deletion m_events.Track (Simulator::Schedule (DELAY (mprsel_tuple.expirationTime), - &AgentImpl::MprSelTupleTimerExpire, this, + &RoutingProtocol::MprSelTupleTimerExpire, this, mprsel_tuple.mainAddr)); } else @@ -1938,7 +1926,7 @@ OLSR::mac_failed(Ptr p) { /// \param tuple link tuple with the information of the link to the neighbor which has been lost. /// void -AgentImpl::NeighborLoss (const LinkTuple &tuple) +RoutingProtocol::NeighborLoss (const LinkTuple &tuple) { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "s: OLSR Node " << m_mainAddress @@ -1957,7 +1945,7 @@ AgentImpl::NeighborLoss (const LinkTuple &tuple) /// \param tuple the duplicate tuple to be added. /// void -AgentImpl::AddDuplicateTuple (const DuplicateTuple &tuple) +RoutingProtocol::AddDuplicateTuple (const DuplicateTuple &tuple) { /*debug("%f: Node %d adds dup tuple: addr = %d seq_num = %d\n", Simulator::Now (), @@ -1973,7 +1961,7 @@ AgentImpl::AddDuplicateTuple (const DuplicateTuple &tuple) /// \param tuple the duplicate tuple to be removed. /// void -AgentImpl::RemoveDuplicateTuple (const DuplicateTuple &tuple) +RoutingProtocol::RemoveDuplicateTuple (const DuplicateTuple &tuple) { /*debug("%f: Node %d removes dup tuple: addr = %d seq_num = %d\n", Simulator::Now (), @@ -1984,7 +1972,7 @@ AgentImpl::RemoveDuplicateTuple (const DuplicateTuple &tuple) } void -AgentImpl::LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness) +RoutingProtocol::LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness) { // Creates associated neighbor tuple NeighborTuple nb_tuple; @@ -2009,7 +1997,7 @@ AgentImpl::LinkTupleAdded (const LinkTuple &tuple, uint8_t willingness) /// \param tuple the link tuple to be removed. /// void -AgentImpl::RemoveLinkTuple (const LinkTuple &tuple) +RoutingProtocol::RemoveLinkTuple (const LinkTuple &tuple) { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "s: OLSR Node " << m_mainAddress @@ -2027,7 +2015,7 @@ AgentImpl::RemoveLinkTuple (const LinkTuple &tuple) /// \param tuple the link tuple which has been updated. /// void -AgentImpl::LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness) +RoutingProtocol::LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness) { // Each time a link tuple changes, the associated neighbor tuple must be recomputed @@ -2074,7 +2062,7 @@ AgentImpl::LinkTupleUpdated (const LinkTuple &tuple, uint8_t willingness) /// \param tuple the neighbor tuple to be added. /// void -AgentImpl::AddNeighborTuple (const NeighborTuple &tuple) +RoutingProtocol::AddNeighborTuple (const NeighborTuple &tuple) { // debug("%f: Node %d adds neighbor tuple: nb_addr = %d status = %s\n", // Simulator::Now (), @@ -2092,7 +2080,7 @@ AgentImpl::AddNeighborTuple (const NeighborTuple &tuple) /// \param tuple the neighbor tuple to be removed. /// void -AgentImpl::RemoveNeighborTuple (const NeighborTuple &tuple) +RoutingProtocol::RemoveNeighborTuple (const NeighborTuple &tuple) { // debug("%f: Node %d removes neighbor tuple: nb_addr = %d status = %s\n", // Simulator::Now (), @@ -2110,7 +2098,7 @@ AgentImpl::RemoveNeighborTuple (const NeighborTuple &tuple) /// \param tuple the 2-hop neighbor tuple to be added. /// void -AgentImpl::AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) +RoutingProtocol::AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) { // debug("%f: Node %d adds 2-hop neighbor tuple: nb_addr = %d nb2hop_addr = %d\n", // Simulator::Now (), @@ -2127,7 +2115,7 @@ AgentImpl::AddTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) /// \param tuple the 2-hop neighbor tuple to be removed. /// void -AgentImpl::RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) +RoutingProtocol::RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) { // debug("%f: Node %d removes 2-hop neighbor tuple: nb_addr = %d nb2hop_addr = %d\n", // Simulator::Now (), @@ -2139,7 +2127,7 @@ AgentImpl::RemoveTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) } void -AgentImpl::IncrementAnsn () +RoutingProtocol::IncrementAnsn () { m_ansn = (m_ansn + 1) % (OLSR_MAX_SEQ_NUM + 1); } @@ -2152,7 +2140,7 @@ AgentImpl::IncrementAnsn () /// \param tuple the MPR selector tuple to be added. /// void -AgentImpl::AddMprSelectorTuple (const MprSelectorTuple &tuple) +RoutingProtocol::AddMprSelectorTuple (const MprSelectorTuple &tuple) { // debug("%f: Node %d adds MPR selector tuple: nb_addr = %d\n", // Simulator::Now (), @@ -2171,7 +2159,7 @@ AgentImpl::AddMprSelectorTuple (const MprSelectorTuple &tuple) /// \param tuple the MPR selector tuple to be removed. /// void -AgentImpl::RemoveMprSelectorTuple (const MprSelectorTuple &tuple) +RoutingProtocol::RemoveMprSelectorTuple (const MprSelectorTuple &tuple) { // debug("%f: Node %d removes MPR selector tuple: nb_addr = %d\n", // Simulator::Now (), @@ -2188,7 +2176,7 @@ AgentImpl::RemoveMprSelectorTuple (const MprSelectorTuple &tuple) /// \param tuple the topology tuple to be added. /// void -AgentImpl::AddTopologyTuple (const TopologyTuple &tuple) +RoutingProtocol::AddTopologyTuple (const TopologyTuple &tuple) { // debug("%f: Node %d adds topology tuple: dest_addr = %d last_addr = %d seq = %d\n", // Simulator::Now (), @@ -2206,7 +2194,7 @@ AgentImpl::AddTopologyTuple (const TopologyTuple &tuple) /// \param tuple the topology tuple to be removed. /// void -AgentImpl::RemoveTopologyTuple (const TopologyTuple &tuple) +RoutingProtocol::RemoveTopologyTuple (const TopologyTuple &tuple) { // debug("%f: Node %d removes topology tuple: dest_addr = %d last_addr = %d seq = %d\n", // Simulator::Now (), @@ -2224,7 +2212,7 @@ AgentImpl::RemoveTopologyTuple (const TopologyTuple &tuple) /// \param tuple the interface association tuple to be added. /// void -AgentImpl::AddIfaceAssocTuple (const IfaceAssocTuple &tuple) +RoutingProtocol::AddIfaceAssocTuple (const IfaceAssocTuple &tuple) { // debug("%f: Node %d adds iface association tuple: main_addr = %d iface_addr = %d\n", // Simulator::Now (), @@ -2241,7 +2229,7 @@ AgentImpl::AddIfaceAssocTuple (const IfaceAssocTuple &tuple) /// \param tuple the interface association tuple to be removed. /// void -AgentImpl::RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple) +RoutingProtocol::RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple) { // debug("%f: Node %d removes iface association tuple: main_addr = %d iface_addr = %d\n", // Simulator::Now (), @@ -2253,14 +2241,14 @@ AgentImpl::RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple) } -uint16_t AgentImpl::GetPacketSequenceNumber () +uint16_t RoutingProtocol::GetPacketSequenceNumber () { m_packetSequenceNumber = (m_packetSequenceNumber + 1) % (OLSR_MAX_SEQ_NUM + 1); return m_packetSequenceNumber; } /// Increments message sequence number and returns the new value. -uint16_t AgentImpl::GetMessageSequenceNumber () +uint16_t RoutingProtocol::GetMessageSequenceNumber () { m_messageSequenceNumber = (m_messageSequenceNumber + 1) % (OLSR_MAX_SEQ_NUM + 1); return m_messageSequenceNumber; @@ -2272,7 +2260,7 @@ uint16_t AgentImpl::GetMessageSequenceNumber () /// \param e The event which has expired. /// void -AgentImpl::HelloTimerExpire () +RoutingProtocol::HelloTimerExpire () { SendHello (); m_helloTimer.Schedule (m_helloInterval); @@ -2283,7 +2271,7 @@ AgentImpl::HelloTimerExpire () /// \param e The event which has expired. /// void -AgentImpl::TcTimerExpire () +RoutingProtocol::TcTimerExpire () { if (m_state.GetMprSelectors ().size () > 0) { @@ -2302,7 +2290,7 @@ AgentImpl::TcTimerExpire () /// \param e The event which has expired. /// void -AgentImpl::MidTimerExpire () +RoutingProtocol::MidTimerExpire () { SendMid (); m_midTimer.Schedule (m_midInterval); @@ -2316,7 +2304,7 @@ AgentImpl::MidTimerExpire () /// \param tuple The tuple which has expired. /// void -AgentImpl::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) +RoutingProtocol::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) { DuplicateTuple *tuple = m_state.FindDuplicateTuple (address, sequenceNumber); @@ -2331,7 +2319,7 @@ AgentImpl::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) else { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), - &AgentImpl::DupTupleTimerExpire, this, + &RoutingProtocol::DupTupleTimerExpire, this, address, sequenceNumber)); } } @@ -2348,7 +2336,7 @@ AgentImpl::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) /// \param e The event which has expired. /// void -AgentImpl::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) +RoutingProtocol::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) { Time now = Simulator::Now (); @@ -2370,13 +2358,13 @@ AgentImpl::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) NeighborLoss (*tuple); m_events.Track (Simulator::Schedule (DELAY (tuple->time), - &AgentImpl::LinkTupleTimerExpire, this, + &RoutingProtocol::LinkTupleTimerExpire, this, neighborIfaceAddr)); } else { m_events.Track (Simulator::Schedule (DELAY (std::min (tuple->time, tuple->symTime)), - &AgentImpl::LinkTupleTimerExpire, this, + &RoutingProtocol::LinkTupleTimerExpire, this, neighborIfaceAddr)); } } @@ -2389,7 +2377,7 @@ AgentImpl::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) /// \param e The event which has expired. /// void -AgentImpl::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr) +RoutingProtocol::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr) { TwoHopNeighborTuple *tuple; tuple = m_state.FindTwoHopNeighborTuple (neighborMainAddr, twoHopNeighborAddr); @@ -2404,7 +2392,7 @@ AgentImpl::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address two else { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), - &AgentImpl::Nb2hopTupleTimerExpire, + &RoutingProtocol::Nb2hopTupleTimerExpire, this, neighborMainAddr, twoHopNeighborAddr)); } } @@ -2417,7 +2405,7 @@ AgentImpl::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address two /// \param e The event which has expired. /// void -AgentImpl::MprSelTupleTimerExpire (Ipv4Address mainAddr) +RoutingProtocol::MprSelTupleTimerExpire (Ipv4Address mainAddr) { MprSelectorTuple *tuple = m_state.FindMprSelectorTuple (mainAddr); if (tuple == NULL) @@ -2431,7 +2419,7 @@ AgentImpl::MprSelTupleTimerExpire (Ipv4Address mainAddr) else { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), - &AgentImpl::MprSelTupleTimerExpire, + &RoutingProtocol::MprSelTupleTimerExpire, this, mainAddr)); } } @@ -2444,7 +2432,7 @@ AgentImpl::MprSelTupleTimerExpire (Ipv4Address mainAddr) /// \param e The event which has expired. /// void -AgentImpl::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) +RoutingProtocol::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) { TopologyTuple *tuple = m_state.FindTopologyTuple (destAddr, lastAddr); if (tuple == NULL) @@ -2458,7 +2446,7 @@ AgentImpl::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) else { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), - &AgentImpl::TopologyTupleTimerExpire, + &RoutingProtocol::TopologyTupleTimerExpire, this, tuple->destAddr, tuple->lastAddr)); } } @@ -2469,7 +2457,7 @@ AgentImpl::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) /// \param e The event which has expired. /// void -AgentImpl::IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr) +RoutingProtocol::IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr) { IfaceAssocTuple *tuple = m_state.FindIfaceAssocTuple (ifaceAddr); if (tuple == NULL) @@ -2483,17 +2471,211 @@ AgentImpl::IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr) else { m_events.Track (Simulator::Schedule (DELAY (tuple->time), - &AgentImpl::IfaceAssocTupleTimerExpire, + &RoutingProtocol::IfaceAssocTupleTimerExpire, this, ifaceAddr)); } } -Ptr -AgentImpl::GetRoutingTable () const +/// +/// \brief Clears the routing table and frees the memory assigned to each one of its entries. +/// +void +RoutingProtocol::Clear () { - return m_routingTable; + NS_LOG_FUNCTION_NOARGS (); + m_table.clear (); } +/// +/// \brief Deletes the entry whose destination address is given. +/// \param dest address of the destination node. +/// +void +RoutingProtocol::RemoveEntry (Ipv4Address const &dest) +{ + m_table.erase (dest); +} + +/// +/// \brief Looks up an entry for the specified destination address. +/// \param dest destination address. +/// \param outEntry output parameter to hold the routing entry result, if fuond +/// \return true if found, false if not found +/// +bool +RoutingProtocol::Lookup (Ipv4Address const &dest, + RoutingTableEntry &outEntry) const +{ + // Get the iterator at "dest" position + std::map::const_iterator it = + m_table.find (dest); + // If there is no route to "dest", return NULL + if (it == m_table.end ()) + return false; + outEntry = it->second; + return true; +} + +/// +/// \brief Finds the appropiate entry which must be used in order to forward +/// a data packet to a next hop (given a destination). +/// +/// Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the +/// form [dest addr,next-hop addr]. In this case, if this function is invoked with +/// [A,B] then pair [C,C] is returned because C is the next hop that must be used +/// to forward a data packet destined to A. That is, C is a neighbor of this node, +/// but B isn't. This function finds the appropiate neighbor for forwarding a packet. +/// +/// \param entry the routing table entry which indicates the destination node +/// we are interested in. +/// \return the appropiate routing table entry which indicates the next +/// hop which must be used for forwarding a data packet, or NULL +/// if there is no such entry. +/// +bool +RoutingProtocol::FindSendEntry (RoutingTableEntry const &entry, + RoutingTableEntry &outEntry) const +{ + outEntry = entry; + while (outEntry.destAddr != outEntry.nextAddr) + { + if (not Lookup(outEntry.nextAddr, outEntry)) + return false; + } + return true; +} + + +bool +RoutingProtocol::RequestRoute (uint32_t ifIndex, + const Ipv4Header &ipHeader, + Ptr packet, + RouteReplyCallback routeReply) +{ + RoutingTableEntry entry1, entry2; + if (Lookup (ipHeader.GetDestination (), entry1)) + { + bool foundSendEntry = FindSendEntry (entry1, entry2); + if (!foundSendEntry) + NS_FATAL_ERROR ("FindSendEntry failure"); + + Ipv4Route route = Ipv4Route::CreateHostRouteTo + (ipHeader.GetDestination (), entry2.nextAddr, entry2.interface); + + NS_LOG_DEBUG ("Olsr node " << m_mainAddress + << ": RouteRequest for dest=" << ipHeader.GetDestination () + << " --> nestHop=" << entry2.nextAddr + << " interface=" << entry2.interface); + + routeReply (true, route, packet, ipHeader); + return true; + } + else + { +#ifdef NS3_LOG_ENABLE + NS_LOG_DEBUG ("Olsr node " << m_mainAddress + << ": RouteRequest for dest=" << ipHeader.GetDestination () + << " --> NOT FOUND; ** Dumping routing table..."); + for (std::map::const_iterator iter = m_table.begin (); + iter != m_table.end (); iter++) + { + NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr + << " via interface " << iter->second.interface); + } + + NS_LOG_DEBUG ("** Routing table dump end."); +#endif + return false; + } +} + +bool +RoutingProtocol::RequestIfIndex (Ipv4Address destination, + uint32_t& ifIndex) +{ + RoutingTableEntry entry1, entry2; + if (Lookup (destination, entry1)) + { + bool foundSendEntry = FindSendEntry (entry1, entry2); + if (!foundSendEntry) + NS_FATAL_ERROR ("FindSendEntry failure"); + ifIndex = entry2.interface; + return true; + } + else + { + return false; + } +} + + +/// +/// \brief Adds a new entry into the routing table. +/// +/// If an entry for the given destination existed, it is deleted and freed. +/// +/// \param dest address of the destination node. +/// \param next address of the next hop node. +/// \param iface address of the local interface. +/// \param dist distance to the destination node. +/// +void +RoutingProtocol::AddEntry (Ipv4Address const &dest, + Ipv4Address const &next, + uint32_t interface, + uint32_t distance) +{ + NS_LOG_FUNCTION (this << dest << next << interface << distance << m_mainAddress); + + NS_ASSERT (distance > 0); + + // Creates a new rt entry with specified values + RoutingTableEntry &entry = m_table[dest]; + + entry.destAddr = dest; + entry.nextAddr = next; + entry.interface = interface; + entry.distance = distance; +} + +void +RoutingProtocol::AddEntry (Ipv4Address const &dest, + Ipv4Address const &next, + Ipv4Address const &interfaceAddress, + uint32_t distance) +{ + NS_LOG_FUNCTION (this << dest << next << interfaceAddress << distance << m_mainAddress); + + NS_ASSERT (distance > 0); + NS_ASSERT (m_ipv4); + + RoutingTableEntry entry; + for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) + { + if (m_ipv4->GetAddress (i) == interfaceAddress) + { + AddEntry (dest, next, i, distance); + return; + } + } + NS_ASSERT (false); // should not be reached + AddEntry (dest, next, 0, distance); +} + + +std::vector +RoutingProtocol::GetEntries () const +{ + std::vector retval; + for (std::map::const_iterator iter = m_table.begin (); + iter != m_table.end (); iter++) + { + retval.push_back (iter->second); + } + return retval; +} + + }} // namespace olsr, ns3 diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-routing-protocol.h similarity index 77% rename from src/routing/olsr/olsr-agent-impl.h rename to src/routing/olsr/olsr-routing-protocol.h index 94effeba1..cf7a606d1 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-routing-protocol.h @@ -24,14 +24,9 @@ #ifndef __OLSR_AGENT_IMPL_H__ #define __OLSR_AGENT_IMPL_H__ -#include - -#include "olsr-agent.h" #include "olsr-header.h" #include "olsr-state.h" - -#include "olsr-routing-table.h" -#include "repositories.h" +#include "olsr-repositories.h" #include "ns3/object.h" #include "ns3/packet.h" @@ -40,27 +35,46 @@ #include "ns3/event-garbage-collector.h" #include "ns3/timer.h" #include "ns3/traced-callback.h" +#include "ns3/ipv4.h" + +#include +#include namespace ns3 { namespace olsr { -class AgentImpl : public Agent +/// An %OLSR's routing table entry. +struct RoutingTableEntry +{ + Ipv4Address destAddr; ///< Address of the destination node. + Ipv4Address nextAddr; ///< Address of the next hop. + uint32_t interface; ///< Interface index + uint32_t distance; ///< Distance in hops to the destination. + + RoutingTableEntry () : // default values + destAddr (), nextAddr (), + interface (0), distance (0) {}; +}; + + +class RoutingProtocol : public Ipv4RoutingProtocol { public: static TypeId GetTypeId (void); - AgentImpl (); - virtual ~AgentImpl (); + RoutingProtocol (); + virtual ~RoutingProtocol (); - virtual void SetNode (Ptr node); + void SetNode (Ptr node); - virtual void Start (); - virtual void SetMainInterface (uint32_t interface); - virtual Ptr GetRoutingTable () const; + void Start (); + void SetMainInterface (uint32_t interface); private: + std::map m_table; ///< Data structure for the routing table. + EventGarbageCollector m_events; /// Address of the routing agent. @@ -82,14 +96,39 @@ private: /// Willingness for forwarding packets on behalf of other nodes. uint8_t m_willingness; - /// Routing table. - Ptr m_routingTable; /// Internal state with all needed data structs. OlsrState m_state; Ptr m_ipv4; -protected: +private: + + void Clear (); + uint32_t GetSize () const { return m_table.size (); } + std::vector GetEntries () const; + void RemoveEntry (const Ipv4Address &dest); + void AddEntry (const Ipv4Address &dest, + const Ipv4Address &next, + uint32_t interface, + uint32_t distance); + void AddEntry (const Ipv4Address &dest, + const Ipv4Address &next, + const Ipv4Address &interfaceAddress, + uint32_t distance); + bool Lookup (const Ipv4Address &dest, + RoutingTableEntry &outEntry) const; + bool FindSendEntry (const RoutingTableEntry &entry, + RoutingTableEntry &outEntry) const; + + // From Ipv4RoutingProtocol + virtual bool RequestRoute (uint32_t ifIndex, + const Ipv4Header &ipHeader, + Ptr packet, + RouteReplyCallback routeReply); + virtual bool RequestIfIndex (Ipv4Address destination, + uint32_t& ifIndex); + + void DoDispose (); void SendPacket (Ptr packet, const MessageList &containedMessages); diff --git a/src/routing/olsr/olsr-routing-table.cc b/src/routing/olsr/olsr-routing-table.cc deleted file mode 100644 index 296a69745..000000000 --- a/src/routing/olsr/olsr-routing-table.cc +++ /dev/null @@ -1,332 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2004 Francisco J. Ros - * Copyright (c) 2007 INESC Porto - * - * 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: Francisco J. Ros - * Gustavo J. A. M. Carneiro - */ - -/// -/// \file OLSR_rtable.cc -/// \brief Implementation of our routing table. -/// - -#include "olsr-routing-table.h" -#include "ns3/packet.h" -#include "ns3/ipv4-header.h" -#include "ns3/log.h" - -namespace ns3 { namespace olsr { - -NS_LOG_COMPONENT_DEFINE ("OlsrRoutingTable"); - -/// -/// \brief Clears the routing table and frees the memory assigned to each one of its entries. -/// -void -RoutingTable::Clear () -{ - NS_LOG_FUNCTION_NOARGS (); - m_table.clear (); -} - -/// -/// \brief Deletes the entry whose destination address is given. -/// \param dest address of the destination node. -/// -void -RoutingTable::RemoveEntry (Ipv4Address const &dest) -{ - m_table.erase (dest); -} - -/// -/// \brief Looks up an entry for the specified destination address. -/// \param dest destination address. -/// \param outEntry output parameter to hold the routing entry result, if fuond -/// \return true if found, false if not found -/// -bool -RoutingTable::Lookup (Ipv4Address const &dest, - RoutingTableEntry &outEntry) const -{ - // Get the iterator at "dest" position - std::map::const_iterator it = - m_table.find (dest); - // If there is no route to "dest", return NULL - if (it == m_table.end ()) - return false; - outEntry = it->second; - return true; -} - -/// -/// \brief Finds the appropiate entry which must be used in order to forward -/// a data packet to a next hop (given a destination). -/// -/// Imagine a routing table like this: [A,B] [B,C] [C,C]; being each pair of the -/// form [dest addr,next-hop addr]. In this case, if this function is invoked with -/// [A,B] then pair [C,C] is returned because C is the next hop that must be used -/// to forward a data packet destined to A. That is, C is a neighbor of this node, -/// but B isn't. This function finds the appropiate neighbor for forwarding a packet. -/// -/// \param entry the routing table entry which indicates the destination node -/// we are interested in. -/// \return the appropiate routing table entry which indicates the next -/// hop which must be used for forwarding a data packet, or NULL -/// if there is no such entry. -/// -bool -RoutingTable::FindSendEntry (RoutingTableEntry const &entry, - RoutingTableEntry &outEntry) const -{ - outEntry = entry; - while (outEntry.destAddr != outEntry.nextAddr) - { - if (not Lookup(outEntry.nextAddr, outEntry)) - return false; - } - return true; -} - - -bool -RoutingTable::RequestRoute (uint32_t ifIndex, - const Ipv4Header &ipHeader, - Ptr packet, - RouteReplyCallback routeReply) -{ - RoutingTableEntry entry1, entry2; - if (Lookup (ipHeader.GetDestination (), entry1)) - { - bool foundSendEntry = FindSendEntry (entry1, entry2); - if (!foundSendEntry) - NS_FATAL_ERROR ("FindSendEntry failure"); - - Ipv4Route route = Ipv4Route::CreateHostRouteTo - (ipHeader.GetDestination (), entry2.nextAddr, entry2.interface); - - NS_LOG_DEBUG ("Olsr node " << m_mainAddress - << ": RouteRequest for dest=" << ipHeader.GetDestination () - << " --> nestHop=" << entry2.nextAddr - << " interface=" << entry2.interface); - - routeReply (true, route, packet, ipHeader); - return true; - } - else - { -#ifdef NS3_LOG_ENABLE - NS_LOG_DEBUG ("Olsr node " << m_mainAddress - << ": RouteRequest for dest=" << ipHeader.GetDestination () - << " --> NOT FOUND; ** Dumping routing table..."); - for (std::map::const_iterator iter = m_table.begin (); - iter != m_table.end (); iter++) - { - NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr - << " via interface " << iter->second.interface); - } - - NS_LOG_DEBUG ("** Routing table dump end."); -#endif - return false; - } -} - -bool -RoutingTable::RequestIfIndex (Ipv4Address destination, - uint32_t& ifIndex) -{ - RoutingTableEntry entry1, entry2; - if (Lookup (destination, entry1)) - { - bool foundSendEntry = FindSendEntry (entry1, entry2); - if (!foundSendEntry) - NS_FATAL_ERROR ("FindSendEntry failure"); - ifIndex = entry2.interface; - return true; - } - else - { - return false; - } -} - - -/// -/// \brief Adds a new entry into the routing table. -/// -/// If an entry for the given destination existed, it is deleted and freed. -/// -/// \param dest address of the destination node. -/// \param next address of the next hop node. -/// \param iface address of the local interface. -/// \param dist distance to the destination node. -/// -void -RoutingTable::AddEntry (Ipv4Address const &dest, - Ipv4Address const &next, - uint32_t interface, - uint32_t distance) -{ - NS_LOG_FUNCTION (this << dest << next << interface << distance << m_mainAddress); - - NS_ASSERT (distance > 0); - - // Creates a new rt entry with specified values - RoutingTableEntry &entry = m_table[dest]; - - entry.destAddr = dest; - entry.nextAddr = next; - entry.interface = interface; - entry.distance = distance; -} - -void -RoutingTable::AddEntry (Ipv4Address const &dest, - Ipv4Address const &next, - Ipv4Address const &interfaceAddress, - uint32_t distance) -{ - NS_LOG_FUNCTION (this << dest << next << interfaceAddress << distance << m_mainAddress); - - NS_ASSERT (distance > 0); - NS_ASSERT (m_ipv4); - - RoutingTableEntry entry; - for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) - { - if (m_ipv4->GetAddress (i) == interfaceAddress) - { - AddEntry (dest, next, i, distance); - return; - } - } - NS_ASSERT (false); // should not be reached - AddEntry (dest, next, 0, distance); -} - -void -RoutingTable::SetMainAddress (Ipv4Address mainAddress) -{ - m_mainAddress = mainAddress; -} - -void -RoutingTable::SetIpv4 (Ptr ipv4) -{ - m_ipv4 = ipv4; -} - -std::vector -RoutingTable::GetEntries () const -{ - std::vector retval; - for (std::map::const_iterator iter = m_table.begin (); - iter != m_table.end (); iter++) - { - retval.push_back (iter->second); - } - return retval; -} - -/// -/// \brief Returns the number of entries in the routing table. -/// \return the number of entries in the routing table. -/// -// u_int32_t -// RoutingTable::size() { -// return rt_.size(); -// } - -}}; // namespace ns3, olsr - - - -#ifdef RUN_SELF_TESTS - - -#include "ns3/test.h" - - -namespace ns3 { namespace olsr { - -class OlsrRoutingTableTest : public ns3::Test { -private: -public: - OlsrRoutingTableTest (); - virtual bool RunTests (void); - - -}; - -OlsrRoutingTableTest::OlsrRoutingTableTest () - : ns3::Test ("OlsrRoutingTable") -{} - - -bool -OlsrRoutingTableTest::RunTests (void) -{ - bool result = true; - - RoutingTable table; - - table.AddEntry (Ipv4Address ("1.2.3.5"), - Ipv4Address ("1.2.3.4"), - 0, - 1); - - table.AddEntry (Ipv4Address ("1.2.3.4"), - Ipv4Address ("1.2.3.4"), - 0, - 1); - - RoutingTableEntry entry1; - NS_TEST_ASSERT (table.Lookup (Ipv4Address ("1.2.3.5"), entry1)); - NS_TEST_ASSERT_EQUAL (entry1.destAddr, Ipv4Address ("1.2.3.5")); - NS_TEST_ASSERT_EQUAL (entry1.nextAddr, Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (entry1.interface, 0); - NS_TEST_ASSERT_EQUAL (entry1.distance, 1); - - RoutingTableEntry entry2; - NS_TEST_ASSERT (table.Lookup (Ipv4Address ("1.2.3.4"), entry2)); - NS_TEST_ASSERT_EQUAL (entry2.destAddr, Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (entry2.nextAddr, Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (entry2.interface, 0); - NS_TEST_ASSERT_EQUAL (entry2.distance, 1); - - RoutingTableEntry sendEntry; - NS_TEST_ASSERT (table.FindSendEntry (entry1, sendEntry)); - NS_TEST_ASSERT_EQUAL (sendEntry.destAddr, Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (sendEntry.nextAddr, Ipv4Address ("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (sendEntry.interface, 0); - NS_TEST_ASSERT_EQUAL (sendEntry.distance, 1); - - table.RemoveEntry (Ipv4Address ("1.2.3.5")); - RoutingTableEntry removedEntry; - NS_TEST_ASSERT (not table.Lookup (Ipv4Address ("1.2.3.5"), removedEntry)); - - return result; -} - -static OlsrRoutingTableTest gOlsrRoutingTableTest; - -}}; // namespace - - -#endif /* RUN_SELF_TESTS */ diff --git a/src/routing/olsr/olsr-routing-table.h b/src/routing/olsr/olsr-routing-table.h deleted file mode 100644 index bbd20a2bc..000000000 --- a/src/routing/olsr/olsr-routing-table.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2004 Francisco J. Ros - * Copyright (c) 2007 INESC Porto - * - * 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: Francisco J. Ros - * Gustavo J. A. M. Carneiro - */ - -/// -/// \file olsr-routing-table.h -/// \brief Header file for routing table's related stuff. -/// - -#ifndef __OLSR_RTABLE_H__ -#define __OLSR_RTABLE_H__ - -#include "ns3/ipv4.h" -#include - - -namespace ns3 { namespace olsr { - -/// An %OLSR's routing table entry. -struct RoutingTableEntry -{ - Ipv4Address destAddr; ///< Address of the destination node. - Ipv4Address nextAddr; ///< Address of the next hop. - uint32_t interface; ///< Interface index - uint32_t distance; ///< Distance in hops to the destination. - - RoutingTableEntry () : // default values - destAddr (), nextAddr (), - interface (0), distance (0) {}; -}; - -/// -/// \brief Defines rtable_t as a map of OLSR_rt_entry, whose key is the destination address. -/// -/// The routing table is thus defined as pairs: [dest address, entry]. Each element -/// of the pair can be accesed via "first" and "second" members. -/// -//typedef std::map RoutingTable; - -/// -/// \brief This class is a representation of the OLSR's Routing Table. -/// -class RoutingTable : public Ipv4RoutingProtocol -{ - std::map m_table; ///< Data structure for the routing table. - Ptr m_ipv4; - - Ipv4Address m_mainAddress; // used only for printing debug messages - - void DoDispose () - { - m_ipv4 = 0; - Ipv4RoutingProtocol::DoDispose (); - } - -public: - - RoutingTable () {} - - void SetIpv4 (Ptr ipv4); - void SetMainAddress (Ipv4Address mainAddress); - - ~RoutingTable () {} - - void Clear (); - uint32_t GetSize () const { return m_table.size (); } - std::vector GetEntries () const; - void RemoveEntry (const Ipv4Address &dest); - void AddEntry (const Ipv4Address &dest, - const Ipv4Address &next, - uint32_t interface, - uint32_t distance); - void AddEntry (const Ipv4Address &dest, - const Ipv4Address &next, - const Ipv4Address &interfaceAddress, - uint32_t distance); - bool Lookup (const Ipv4Address &dest, - RoutingTableEntry &outEntry) const; - bool FindSendEntry (const RoutingTableEntry &entry, - RoutingTableEntry &outEntry) const; - - // From Ipv4RoutingProtocol - virtual bool RequestRoute (uint32_t ifIndex, - const Ipv4Header &ipHeader, - Ptr packet, - RouteReplyCallback routeReply); - virtual bool RequestIfIndex (Ipv4Address destination, - uint32_t& ifIndex); - -}; - -}}; // namespace ns3, olsr - -#endif diff --git a/src/routing/olsr/olsr-state.h b/src/routing/olsr/olsr-state.h index d647445fe..b2ea6749b 100644 --- a/src/routing/olsr/olsr-state.h +++ b/src/routing/olsr/olsr-state.h @@ -25,7 +25,7 @@ #ifndef __OLSR_STATE_H__ #define __OLSR_STATE_H__ -#include "repositories.h" +#include "olsr-repositories.h" namespace ns3 { diff --git a/src/routing/olsr/wscript b/src/routing/olsr/wscript index 52e835d5b..7170e4478 100644 --- a/src/routing/olsr/wscript +++ b/src/routing/olsr/wscript @@ -6,16 +6,15 @@ def build(bld): module.source = [ 'olsr-header.cc', 'olsr-state.cc', - 'olsr-routing-table.cc', - 'olsr-agent.cc', - 'olsr-agent-impl.cc', + 'olsr-routing-protocol.cc', ] headers = bld.new_task_gen('ns3header') headers.module = 'olsr' headers.source = [ - 'olsr-agent.h', + 'olsr-routing-protocol.h', 'olsr-header.h', - 'olsr-routing-table.h' + 'olsr-state.h', + 'olsr-repositories.h', ] diff --git a/src/wscript b/src/wscript index 91c364e2d..5c8c5f9a0 100644 --- a/src/wscript +++ b/src/wscript @@ -9,8 +9,7 @@ import TaskGen import Task import Options import Build -from Utils import md5 - +import Utils all_modules = ( 'core', @@ -111,7 +110,7 @@ class ns3header_taskgen(TaskGen.task_gen): def apply(self): if self.module is None: raise Utils.WafError("'module' missing on ns3headers object %s" % self) - ns3_dir_node = Build.bld.path.find_dir("ns3") + ns3_dir_node = self.bld.path.find_dir("ns3") if self.sub_dir is not None: ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir) for filename in self.to_list(self.source): @@ -178,7 +177,7 @@ class gen_ns3_module_header_task(Task.Task): return 0 def sig_explicit_deps(self): - m = md5() + m = Utils.md5() m.update('\n'.join([node.abspath(self.env) for node in self.inputs])) return m.digest() @@ -187,7 +186,7 @@ class gen_ns3_module_header_task(Task.Task): return self.uid except AttributeError: "this is not a real hot zone, but we want to avoid surprizes here" - m = md5() + m = Utils.md5() m.update("ns-3-module-header-%s" % self.module) self.uid = m.digest() return self.uid @@ -201,13 +200,12 @@ class ns3moduleheader_taskgen(TaskGen.task_gen): COLOR = 'BLUE' def __init__(self, *args, **kwargs): super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs) - self.module_name = None def apply(self): ## get all of the ns3 headers - ns3_dir_node = Build.bld.path.find_dir("ns3") + ns3_dir_node = self.bld.path.find_dir("ns3") all_headers_inputs = [] - for ns3headers in Build.bld.all_task_gen: + for ns3headers in self.bld.all_task_gen: if isinstance(ns3headers, ns3header_taskgen): if ns3headers.module != self.module: continue @@ -217,8 +215,10 @@ class ns3moduleheader_taskgen(TaskGen.task_gen): if node is None: fatal("missing header file %s" % (source,)) all_headers_inputs.append(node) + if not all_headers_inputs: + raise Utils.WscriptError("error finding headers for module %s" % self.module) assert all_headers_inputs - module_obj = Build.bld.name_to_obj("ns3-" + self.module, self.env) + module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env) assert module_obj is not None all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)] task = self.create_task('gen_ns3_module_header', self.env) diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index 12684629a..a1c5e468e 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -239,7 +239,7 @@ int main (int argc, char *argv[]) info.RecordAggregationInfo ("ns3::Node", "ns3::TcpSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::UdpSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory"); - info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::Agent"); + info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::RoutingProtocol"); info.RecordAggregationInfo ("ns3::Node", "ns3::MobilityModel"); info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L3Protocol"); info.RecordAggregationInfo ("ns3::Node", "ns3::ArpL3Protocol"); diff --git a/utils/python-unit-tests.py b/utils/python-unit-tests.py index 00713e8d9..a08f668fe 100644 --- a/utils/python-unit-tests.py +++ b/utils/python-unit-tests.py @@ -97,14 +97,14 @@ class TestSimulator(unittest.TestCase): ## -- object pointer values mobility = ns3.RandomWaypointMobilityModel() ptr = ns3.PointerValue() - mobility.GetAttribute("Position", ptr) + mobility.GetAttribute("PositionAllocator", ptr) self.assertEqual(ptr.GetObject(), None) pos = ns3.ListPositionAllocator() - mobility.SetAttribute("Position", ns3.PointerValue(pos)) + mobility.SetAttribute("PositionAllocator", ns3.PointerValue(pos)) ptr = ns3.PointerValue() - mobility.GetAttribute("Position", ptr) + mobility.GetAttribute("PositionAllocator", ptr) self.assert_(ptr.GetObject() is not None) def testIdentity(self): diff --git a/waf b/waf index 23b5ac178..25ac3fc18 100755 Binary files a/waf and b/waf differ diff --git a/wscript b/wscript index b1a288ddd..f47c67b67 100644 --- a/wscript +++ b/wscript @@ -10,6 +10,7 @@ import os.path # WAF modules import pproc as subprocess import Options + import Logs import TaskGen import Constants @@ -23,6 +24,7 @@ Task.algotype = Constants.JOBCONTROL # so that Task.maxjobs=1 takes effect import Utils import Build import Configure +import Scripting import cflags # override the build profiles from waf cflags.profiles = { @@ -133,7 +135,7 @@ def set_options(opt): action="store_true", default=False, dest='valgrind') opt.add_option('--shell', - help=('Run a shell with an environment suitably modified to run locally built programs'), + help=('DEPRECATED (run ./waf shell)'), action="store_true", default=False, dest='shell') opt.add_option('--enable-sudo', @@ -161,7 +163,7 @@ def set_options(opt): opt.sub_options('src/internet-stack') -def check_compilation_flag(conf, flag): +def _check_compilation_flag(conf, flag): """ Checks if the C++ compiler accepts a certain compilation flag or flags flag: can be a string or a list of strings @@ -186,7 +188,7 @@ def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled def configure(conf): # attach some extra methods - conf.check_compilation_flag = types.MethodType(check_compilation_flag, conf) + conf.check_compilation_flag = types.MethodType(_check_compilation_flag, conf) conf.report_optional_feature = types.MethodType(report_optional_feature, conf) conf.env['NS3_OPTIONAL_FEATURES'] = [] @@ -235,7 +237,7 @@ def configure(conf): env.append_value('CXXDEFINES', 'RUN_SELF_TESTS') if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ: - if check_compilation_flag(conf, '-Wno-error=deprecated-declarations'): + if conf.check_compilation_flag('-Wno-error=deprecated-declarations'): env.append_value('CXXFLAGS', '-Wno-error=deprecated-declarations') if Options.options.build_profile == 'debug': @@ -244,9 +246,11 @@ def configure(conf): env['PLATFORM'] = sys.platform - if sys.platform == 'win32': - if env['COMPILER_CXX'] == 'g++': + if conf.env['CXX_NAME'] == 'gcc': + if sys.platform == 'win32': env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc") + elif sys.platform == 'cygwin': + env.append_value("LINKFLAGS", "-Wl,--enable-auto-import") conf.sub_config('src') conf.sub_config('utils') @@ -363,6 +367,7 @@ def add_scratch_programs(bld): def build(bld): + wutils.bld = bld if Options.options.no_task_lines: import Runner def null_printout(s): @@ -378,21 +383,6 @@ def build(bld): variant_env = bld.env_of_name(variant_name) bld.all_envs['default'] = variant_env - if Options.options.shell: - run_shell() - raise SystemExit(0) - - if Options.options.doxygen: - doxygen() - raise SystemExit(0) - - check_shell() - - if Options.options.doxygen: - doxygen() - raise SystemExit(0) - - print "Entering directory `%s'" % os.path.join(bld.path.abspath(), 'build') # process subfolders from here bld.add_subdirs('src') bld.add_subdirs('samples utils examples') @@ -427,14 +417,14 @@ def build(bld): changed = True ## remove objects that depend on modules not listed - for obj in list(Build.bld.all_task_gen): + for obj in list(bld.all_task_gen): if hasattr(obj, 'ns3_module_dependencies'): for dep in obj.ns3_module_dependencies: if dep not in modules: - Build.bld.all_task_gen.remove(obj) + bld.all_task_gen.remove(obj) break if obj.name in env['NS3_MODULES'] and obj.name not in modules: - Build.bld.all_task_gen.remove(obj) + bld.all_task_gen.remove(obj) ## Create a single ns3 library containing all enabled modules lib = bld.new_task_gen('cxx', 'shlib') @@ -468,26 +458,47 @@ def build(bld): regression.run_regression(bld, regression_traces) -def shutdown(): - env = Build.bld.env - if Options.commands['check']: - _run_waf_check() +def shutdown(ctx): + bld = wutils.bld + if wutils.bld is None: + return + env = bld.env + + #if Options.commands['check']: + # _run_waf_check() if Options.options.lcov_report: lcov_report() if Options.options.run: - wutils.run_program(Options.options.run, wutils.get_command_template(env)) + wutils.run_program(Options.options.run, env, wutils.get_command_template(env)) raise SystemExit(0) if Options.options.pyrun: - wutils.run_python_program(Options.options.pyrun) + wutils.run_python_program(Options.options.pyrun, env) raise SystemExit(0) -def _run_waf_check(): + if Options.options.shell: + raise Utils.WafError("Run `./waf shell' now, instead of `./waf shell'") + + if Options.options.doxygen: + doxygen() + raise SystemExit(0) + + check_shell(bld) + + if Options.options.doxygen: + doxygen() + raise SystemExit(0) + + +check_context = Build.BuildContext +def check(bld): + "run the NS-3 unit tests" + Scripting.build(bld) ## generate the trace sources list docs - env = Build.bld.env + env = bld.env proc_env = wutils.get_proc_env() try: program_obj = wutils.find_program('print-introspected-doxygen', env) @@ -507,21 +518,21 @@ def _run_waf_check(): if env['ENABLE_PYTHON_BINDINGS']: print "-- Running NS-3 Python bindings unit tests..." - wutils.run_argv([env['PYTHON'], os.path.join("utils", "python-unit-tests.py")], proc_env) + wutils.run_argv([env['PYTHON'], os.path.join("utils", "python-unit-tests.py")], env, proc_env) else: print "-- Skipping NS-3 Python bindings unit tests: Python bindings not enabled." -def check_shell(): +def check_shell(bld): if 'NS3_MODULE_PATH' not in os.environ: return - env = Build.bld.env + env = bld.env correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH']) found_modpath = os.environ['NS3_MODULE_PATH'] if found_modpath != correct_modpath: - msg = ("Detected shell (waf --shell) with incorrect configuration\n" + msg = ("Detected shell (./waf shell) with incorrect configuration\n" "=========================================================\n" "Possible reasons for this problem:\n" " 1. You switched to another ns-3 tree from inside this shell\n" @@ -533,14 +544,20 @@ def check_shell(): raise Utils.WafError(msg) -def run_shell(): +shell_context = Build.BuildContext +def shell(ctx): + """run a shell with an environment suitably modified to run locally built programs""" + + #make sure we build first" + Scripting.build(ctx) + if sys.platform == 'win32': shell = os.environ.get("COMSPEC", "cmd.exe") else: shell = os.environ.get("SHELL", "/bin/sh") - env = Build.bld.env - wutils.run_argv([shell], {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])}) + env = wutils.bld.env + wutils.run_argv([shell], env, {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])}) def doxygen(): if not os.path.exists('doc/introspected-doxygen.h'): @@ -598,7 +615,7 @@ from Scripting import dist_exts, excludes, BLDDIR import Utils import os -def copytree(src, dst, symlinks=False, excludes=(), build_dir=None): +def _copytree(src, dst, symlinks=False, excludes=(), build_dir=None): """Recursively copy a directory tree using copy2(). The destination directory must not already exist. @@ -668,7 +685,7 @@ def copytree(src, dst, symlinks=False, excludes=(), build_dir=None): def DistDir(appname, version): - "make a distribution directory with all the sources in it" + #"make a distribution directory with all the sources in it" import shutil # Our temporary folder where to put our files @@ -683,7 +700,7 @@ def DistDir(appname, version): build_dir = getattr(Utils.g_module, BLDDIR, None) # Copy everything into the new folder - copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir) + _copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir) # TODO undocumented hook dist_hook = getattr(Utils.g_module, 'dist_hook', None) diff --git a/wutils.py b/wutils.py index 33cc5a4f7..d82fe305d 100644 --- a/wutils.py +++ b/wutils.py @@ -11,11 +11,13 @@ import Utils import Logs import TaskGen import Build +import re # these are set from the main wscript file APPNAME=None VERSION=None +bld=None # # The last part of the path name to use to find the regression traces tarball. @@ -27,14 +29,7 @@ TRACEBALL_SUFFIX = ".tar.bz2" def get_command_template(env, arguments=()): - if Options.options.valgrind: - if Options.options.command_template: - raise Utils.WafError("Options --command-template and --valgrind are conflicting") - if not env['VALGRIND']: - raise Utils.WafError("valgrind is not installed") - cmd = env['VALGRIND'] + " --leak-check=full --error-exitcode=1 %s" - else: - cmd = Options.options.command_template or '%s' + cmd = Options.options.command_template or '%s' for arg in arguments: cmd = cmd + " " + arg return cmd @@ -65,7 +60,7 @@ def find_program(program_name, env): launch_dir = os.path.abspath(Options.cwd_launch) top_dir = os.path.abspath(Options.launch_dir) found_programs = [] - for obj in Build.bld.all_task_gen: + for obj in bld.all_task_gen: if not getattr(obj, 'is_ns3_program', False): continue @@ -84,7 +79,7 @@ def find_program(program_name, env): % (program_name, found_programs)) def get_proc_env(os_env=None): - env = Build.bld.env + env = bld.env if sys.platform == 'linux2': pathvar = 'LD_LIBRARY_PATH' elif sys.platform == 'darwin': @@ -111,7 +106,7 @@ def get_proc_env(os_env=None): else: proc_env[pathvar] = os.pathsep.join(list(env['NS3_MODULE_PATH'])) - pymoddir = Build.bld.path.find_dir('bindings/python').abspath(env) + pymoddir = bld.path.find_dir('bindings/python').abspath(env) if 'PYTHONPATH' in proc_env: proc_env['PYTHONPATH'] = os.pathsep.join([pymoddir] + [proc_env['PYTHONPATH']]) else: @@ -119,10 +114,29 @@ def get_proc_env(os_env=None): return proc_env -def run_argv(argv, os_env=None, cwd=None): +def run_argv(argv, env, os_env=None, cwd=None): proc_env = get_proc_env(os_env) - #env = Build.bld.env - retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait() + if Options.options.valgrind: + if Options.options.command_template: + raise Utils.WafError("Options --command-template and --valgrind are conflicting") + if not env['VALGRIND']: + raise Utils.WafError("valgrind is not installed") + argv = [env['VALGRIND'], "--leak-check=full", "--error-exitcode=1"] + argv + proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE) + reg = re.compile ('definitely lost: ([^ ]+) bytes') + error = False + for line in proc.stderr: + sys.stderr.write(line) + result = reg.search(line) + if result is None: + continue + if result.group(1) != "0": + error = True + retval = proc.wait() + if retval == 0 and error: + retval = 1 + else: + retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait() if retval: raise Utils.WafError("Command %s exited with code %i" % (argv, retval)) return retval @@ -133,7 +147,7 @@ def get_run_program(program_string, command_template=None): run_program(program_string, command_template). """ #print "get_run_program_argv(program_string=%r, command_template=%r)" % (program_string, command_template) - env = Build.bld.env + env = bld.env if command_template in (None, '%s'): argv = shlex.split(program_string) @@ -169,7 +183,7 @@ def get_run_program(program_string, command_template=None): execvec = shlex.split(command_template % (program_node.abspath(env),)) return program_name, execvec -def run_program(program_string, command_template=None, cwd=None): +def run_program(program_string, env, command_template=None, cwd=None): """ if command_template is not None, then program_string == program name and argv is given by command_template with %s replaced by the @@ -182,17 +196,17 @@ def run_program(program_string, command_template=None, cwd=None): cwd = Options.options.cwd_launch else: cwd = Options.cwd_launch - return run_argv(execvec, cwd=cwd) + return run_argv(execvec, env, cwd=cwd) -def run_python_program(program_string): - env = Build.bld.env +def run_python_program(program_string, env): + env = bld.env execvec = shlex.split(program_string) if (Options.options.cwd_launch): cwd = Options.options.cwd_launch else: cwd = Options.cwd_launch - return run_argv([env['PYTHON']] + execvec, cwd=cwd) + return run_argv([env['PYTHON']] + execvec, env, cwd=cwd)