From 5d52c033184116f42aabff29d9d150bb5336bfef Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sat, 20 Sep 2014 23:53:22 +0200 Subject: [PATCH] Bug 652 - no public API for IPv4 neighbor table - Print functions --- CHANGES.html | 3 + RELEASE_NOTES | 2 + examples/wireless/wifi-simple-adhoc-grid.cc | 4 +- src/internet/bindings/modulegen__gcc_ILP32.py | 61 ++++++++++- src/internet/bindings/modulegen__gcc_LP64.py | 61 ++++++++++- src/internet/helper/ipv4-routing-helper.cc | 93 ++++++++++++++++ src/internet/helper/ipv4-routing-helper.h | 101 +++++++++++++++++- src/internet/helper/ipv6-routing-helper.cc | 93 ++++++++++++++++ src/internet/helper/ipv6-routing-helper.h | 97 +++++++++++++++++ src/internet/model/arp-cache.cc | 38 ++++++- src/internet/model/arp-cache.h | 12 ++- src/internet/model/ipv4-interface.h | 1 + src/internet/model/ipv6-interface.cc | 6 ++ src/internet/model/ipv6-interface.h | 6 ++ src/internet/model/ndisc-cache.cc | 44 ++++++++ src/internet/model/ndisc-cache.h | 9 +- 16 files changed, 616 insertions(+), 15 deletions(-) diff --git a/CHANGES.html b/CHANGES.html index 8a802e096..cdce6be92 100644 --- a/CHANGES.html +++ b/CHANGES.html @@ -54,6 +54,9 @@ us a note on ns-developers mailing list.

Changes from ns-3.21 to ns-3.22

New API:

Changes to existing API:

diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 7cec589d6..b740c21c4 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -21,6 +21,8 @@ Supported platforms New user-visible features ------------------------- +- It is now possible to print the Neighbor Cache (ARP and NDISC) by using + the RoutingProtocolHelper Bugs fixed ---------- diff --git a/examples/wireless/wifi-simple-adhoc-grid.cc b/examples/wireless/wifi-simple-adhoc-grid.cc index 5933dead2..909e380c3 100644 --- a/examples/wireless/wifi-simple-adhoc-grid.cc +++ b/examples/wireless/wifi-simple-adhoc-grid.cc @@ -227,6 +227,8 @@ int main (int argc, char *argv[]) // Trace routing tables Ptr routingStream = Create ("wifi-simple-adhoc-grid.routes", std::ios::out); olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream); + Ptr neighborStream = Create ("wifi-simple-adhoc-grid.neighbors", std::ios::out); + olsr.PrintNeighborCacheAllEvery (Seconds (2), neighborStream); // To do-- enable an IP-level trace that shows forwarding events only } @@ -238,7 +240,7 @@ int main (int argc, char *argv[]) // Output what we are doing NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance); - Simulator::Stop (Seconds (32.0)); + Simulator::Stop (Seconds (33.0)); Simulator::Run (); Simulator::Destroy (); diff --git a/src/internet/bindings/modulegen__gcc_ILP32.py b/src/internet/bindings/modulegen__gcc_ILP32.py index 740191c67..cda05393e 100644 --- a/src/internet/bindings/modulegen__gcc_ILP32.py +++ b/src/internet/bindings/modulegen__gcc_ILP32.py @@ -2804,6 +2804,26 @@ def register_Ns3Ipv4RoutingHelper_methods(root_module, cls): 'ns3::Ptr< ns3::Ipv4RoutingProtocol >', [param('ns3::Ptr< ns3::Node >', 'node')], is_pure_virtual=True, is_const=True, is_virtual=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAllEvery(ns3::Time printInterval, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAt(ns3::Time printTime, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheEvery(ns3::Time printInterval, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintRoutingTableAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] cls.add_method('PrintRoutingTableAllAt', 'void', @@ -3508,6 +3528,26 @@ def register_Ns3Ipv6RoutingHelper_methods(root_module, cls): 'ns3::Ptr< ns3::Ipv6RoutingProtocol >', [param('ns3::Ptr< ns3::Node >', 'node')], is_pure_virtual=True, is_const=True, is_virtual=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAllEvery(ns3::Time printInterval, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAt(ns3::Time printTime, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheEvery(ns3::Time printInterval, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintRoutingTableAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] cls.add_method('PrintRoutingTableAllAt', 'void', @@ -4269,10 +4309,10 @@ def register_Ns3PcapHelper_methods(root_module, cls): cls.add_constructor([param('ns3::PcapHelper const &', 'arg0')]) ## trace-helper.h (module 'network'): ns3::PcapHelper::PcapHelper() [constructor] cls.add_constructor([]) - ## trace-helper.h (module 'network'): ns3::Ptr ns3::PcapHelper::CreateFile(std::string filename, std::_Ios_Openmode filemode, uint32_t dataLinkType, uint32_t snapLen=65535, int32_t tzCorrection=0) [member function] + ## trace-helper.h (module 'network'): ns3::Ptr ns3::PcapHelper::CreateFile(std::string filename, std::_Ios_Openmode filemode, uint32_t dataLinkType, uint32_t snapLen=std::numeric_limits::max(), int32_t tzCorrection=0) [member function] cls.add_method('CreateFile', 'ns3::Ptr< ns3::PcapFileWrapper >', - [param('std::string', 'filename'), param('std::_Ios_Openmode', 'filemode'), param('uint32_t', 'dataLinkType'), param('uint32_t', 'snapLen', default_value='65535'), param('int32_t', 'tzCorrection', default_value='0')]) + [param('std::string', 'filename'), param('std::_Ios_Openmode', 'filemode'), param('uint32_t', 'dataLinkType'), param('uint32_t', 'snapLen', default_value='std::numeric_limits::max()'), param('int32_t', 'tzCorrection', default_value='0')]) ## trace-helper.h (module 'network'): std::string ns3::PcapHelper::GetFilenameFromDevice(std::string prefix, ns3::Ptr device, bool useObjectNames=true) [member function] cls.add_method('GetFilenameFromDevice', 'std::string', @@ -5276,7 +5316,6 @@ def register_Ns3Empty_methods(root_module, cls): return def register_Ns3Int64x64_t_methods(root_module, cls): - cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('!=') cls.add_inplace_numeric_operator('+=', param('ns3::int64x64_t const &', u'right')) cls.add_binary_numeric_operator('*', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right')) @@ -5290,6 +5329,7 @@ def register_Ns3Int64x64_t_methods(root_module, cls): cls.add_inplace_numeric_operator('-=', param('ns3::int64x64_t const &', u'right')) cls.add_inplace_numeric_operator('/=', param('ns3::int64x64_t const &', u'right')) cls.add_output_stream_operator() + cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('==') cls.add_binary_comparison_operator('>=') ## int64x64-double.h (module 'core'): ns3::int64x64_t::int64x64_t() [constructor] @@ -10058,7 +10098,6 @@ def register_Ns3TcpWestwood_methods(root_module, cls): return def register_Ns3Time_methods(root_module, cls): - cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('!=') cls.add_inplace_numeric_operator('+=', param('ns3::Time const &', u'right')) cls.add_binary_numeric_operator('*', root_module['ns3::Time'], root_module['ns3::Time'], param('int64_t const &', u'right')) @@ -10069,6 +10108,7 @@ def register_Ns3Time_methods(root_module, cls): cls.add_binary_comparison_operator('>') cls.add_inplace_numeric_operator('-=', param('ns3::Time const &', u'right')) cls.add_output_stream_operator() + cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('==') cls.add_binary_comparison_operator('>=') ## nstime.h (module 'core'): ns3::Time::Time() [constructor] @@ -10761,6 +10801,10 @@ def register_Ns3ArpCache_methods(root_module, cls): cls.add_method('Lookup', 'ns3::ArpCache::Entry *', [param('ns3::Ipv4Address', 'destination')]) + ## arp-cache.h (module 'internet'): void ns3::ArpCache::PrintArpCache(ns3::Ptr stream) [member function] + cls.add_method('PrintArpCache', + 'void', + [param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')]) ## arp-cache.h (module 'internet'): void ns3::ArpCache::SetAliveTimeout(ns3::Time aliveTimeout) [member function] cls.add_method('SetAliveTimeout', 'void', @@ -13640,6 +13684,11 @@ def register_Ns3Ipv6Interface_methods(root_module, cls): 'uint32_t', [], is_const=True) + ## ipv6-interface.h (module 'internet'): ns3::Ptr ns3::Ipv6Interface::GetNdiscCache() const [member function] + cls.add_method('GetNdiscCache', + 'ns3::Ptr< ns3::NdiscCache >', + [], + is_const=True) ## ipv6-interface.h (module 'internet'): uint16_t ns3::Ipv6Interface::GetReachableTime() const [member function] cls.add_method('GetReachableTime', 'uint16_t', @@ -14483,6 +14532,10 @@ def register_Ns3NdiscCache_methods(root_module, cls): cls.add_method('Lookup', 'ns3::NdiscCache::Entry *', [param('ns3::Ipv6Address', 'dst')]) + ## ndisc-cache.h (module 'internet'): void ns3::NdiscCache::PrintNdiscCache(ns3::Ptr stream) [member function] + cls.add_method('PrintNdiscCache', + 'void', + [param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')]) ## ndisc-cache.h (module 'internet'): void ns3::NdiscCache::Remove(ns3::NdiscCache::Entry * entry) [member function] cls.add_method('Remove', 'void', diff --git a/src/internet/bindings/modulegen__gcc_LP64.py b/src/internet/bindings/modulegen__gcc_LP64.py index 740191c67..cda05393e 100644 --- a/src/internet/bindings/modulegen__gcc_LP64.py +++ b/src/internet/bindings/modulegen__gcc_LP64.py @@ -2804,6 +2804,26 @@ def register_Ns3Ipv4RoutingHelper_methods(root_module, cls): 'ns3::Ptr< ns3::Ipv4RoutingProtocol >', [param('ns3::Ptr< ns3::Node >', 'node')], is_pure_virtual=True, is_const=True, is_virtual=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAllEvery(ns3::Time printInterval, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheAt(ns3::Time printTime, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintNeighborCacheEvery(ns3::Time printInterval, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) ## ipv4-routing-helper.h (module 'internet'): void ns3::Ipv4RoutingHelper::PrintRoutingTableAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] cls.add_method('PrintRoutingTableAllAt', 'void', @@ -3508,6 +3528,26 @@ def register_Ns3Ipv6RoutingHelper_methods(root_module, cls): 'ns3::Ptr< ns3::Ipv6RoutingProtocol >', [param('ns3::Ptr< ns3::Node >', 'node')], is_pure_virtual=True, is_const=True, is_virtual=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAllEvery(ns3::Time printInterval, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAllEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheAt(ns3::Time printTime, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheAt', + 'void', + [param('ns3::Time', 'printTime'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) + ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintNeighborCacheEvery(ns3::Time printInterval, ns3::Ptr node, ns3::Ptr stream) const [member function] + cls.add_method('PrintNeighborCacheEvery', + 'void', + [param('ns3::Time', 'printInterval'), param('ns3::Ptr< ns3::Node >', 'node'), param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')], + is_const=True) ## ipv6-routing-helper.h (module 'internet'): void ns3::Ipv6RoutingHelper::PrintRoutingTableAllAt(ns3::Time printTime, ns3::Ptr stream) const [member function] cls.add_method('PrintRoutingTableAllAt', 'void', @@ -4269,10 +4309,10 @@ def register_Ns3PcapHelper_methods(root_module, cls): cls.add_constructor([param('ns3::PcapHelper const &', 'arg0')]) ## trace-helper.h (module 'network'): ns3::PcapHelper::PcapHelper() [constructor] cls.add_constructor([]) - ## trace-helper.h (module 'network'): ns3::Ptr ns3::PcapHelper::CreateFile(std::string filename, std::_Ios_Openmode filemode, uint32_t dataLinkType, uint32_t snapLen=65535, int32_t tzCorrection=0) [member function] + ## trace-helper.h (module 'network'): ns3::Ptr ns3::PcapHelper::CreateFile(std::string filename, std::_Ios_Openmode filemode, uint32_t dataLinkType, uint32_t snapLen=std::numeric_limits::max(), int32_t tzCorrection=0) [member function] cls.add_method('CreateFile', 'ns3::Ptr< ns3::PcapFileWrapper >', - [param('std::string', 'filename'), param('std::_Ios_Openmode', 'filemode'), param('uint32_t', 'dataLinkType'), param('uint32_t', 'snapLen', default_value='65535'), param('int32_t', 'tzCorrection', default_value='0')]) + [param('std::string', 'filename'), param('std::_Ios_Openmode', 'filemode'), param('uint32_t', 'dataLinkType'), param('uint32_t', 'snapLen', default_value='std::numeric_limits::max()'), param('int32_t', 'tzCorrection', default_value='0')]) ## trace-helper.h (module 'network'): std::string ns3::PcapHelper::GetFilenameFromDevice(std::string prefix, ns3::Ptr device, bool useObjectNames=true) [member function] cls.add_method('GetFilenameFromDevice', 'std::string', @@ -5276,7 +5316,6 @@ def register_Ns3Empty_methods(root_module, cls): return def register_Ns3Int64x64_t_methods(root_module, cls): - cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('!=') cls.add_inplace_numeric_operator('+=', param('ns3::int64x64_t const &', u'right')) cls.add_binary_numeric_operator('*', root_module['ns3::int64x64_t'], root_module['ns3::int64x64_t'], param('ns3::int64x64_t const &', u'right')) @@ -5290,6 +5329,7 @@ def register_Ns3Int64x64_t_methods(root_module, cls): cls.add_inplace_numeric_operator('-=', param('ns3::int64x64_t const &', u'right')) cls.add_inplace_numeric_operator('/=', param('ns3::int64x64_t const &', u'right')) cls.add_output_stream_operator() + cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('==') cls.add_binary_comparison_operator('>=') ## int64x64-double.h (module 'core'): ns3::int64x64_t::int64x64_t() [constructor] @@ -10058,7 +10098,6 @@ def register_Ns3TcpWestwood_methods(root_module, cls): return def register_Ns3Time_methods(root_module, cls): - cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('!=') cls.add_inplace_numeric_operator('+=', param('ns3::Time const &', u'right')) cls.add_binary_numeric_operator('*', root_module['ns3::Time'], root_module['ns3::Time'], param('int64_t const &', u'right')) @@ -10069,6 +10108,7 @@ def register_Ns3Time_methods(root_module, cls): cls.add_binary_comparison_operator('>') cls.add_inplace_numeric_operator('-=', param('ns3::Time const &', u'right')) cls.add_output_stream_operator() + cls.add_binary_comparison_operator('<=') cls.add_binary_comparison_operator('==') cls.add_binary_comparison_operator('>=') ## nstime.h (module 'core'): ns3::Time::Time() [constructor] @@ -10761,6 +10801,10 @@ def register_Ns3ArpCache_methods(root_module, cls): cls.add_method('Lookup', 'ns3::ArpCache::Entry *', [param('ns3::Ipv4Address', 'destination')]) + ## arp-cache.h (module 'internet'): void ns3::ArpCache::PrintArpCache(ns3::Ptr stream) [member function] + cls.add_method('PrintArpCache', + 'void', + [param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')]) ## arp-cache.h (module 'internet'): void ns3::ArpCache::SetAliveTimeout(ns3::Time aliveTimeout) [member function] cls.add_method('SetAliveTimeout', 'void', @@ -13640,6 +13684,11 @@ def register_Ns3Ipv6Interface_methods(root_module, cls): 'uint32_t', [], is_const=True) + ## ipv6-interface.h (module 'internet'): ns3::Ptr ns3::Ipv6Interface::GetNdiscCache() const [member function] + cls.add_method('GetNdiscCache', + 'ns3::Ptr< ns3::NdiscCache >', + [], + is_const=True) ## ipv6-interface.h (module 'internet'): uint16_t ns3::Ipv6Interface::GetReachableTime() const [member function] cls.add_method('GetReachableTime', 'uint16_t', @@ -14483,6 +14532,10 @@ def register_Ns3NdiscCache_methods(root_module, cls): cls.add_method('Lookup', 'ns3::NdiscCache::Entry *', [param('ns3::Ipv6Address', 'dst')]) + ## ndisc-cache.h (module 'internet'): void ns3::NdiscCache::PrintNdiscCache(ns3::Ptr stream) [member function] + cls.add_method('PrintNdiscCache', + 'void', + [param('ns3::Ptr< ns3::OutputStreamWrapper >', 'stream')]) ## ndisc-cache.h (module 'internet'): void ns3::NdiscCache::Remove(ns3::NdiscCache::Entry * entry) [member function] cls.add_method('Remove', 'void', diff --git a/src/internet/helper/ipv4-routing-helper.cc b/src/internet/helper/ipv4-routing-helper.cc index deaa64202..c253f86ac 100644 --- a/src/internet/helper/ipv4-routing-helper.cc +++ b/src/internet/helper/ipv4-routing-helper.cc @@ -23,6 +23,10 @@ #include "ns3/simulator.h" #include "ns3/ipv4-routing-protocol.h" #include "ns3/ipv4-list-routing.h" +#include "ns3/ipv4-l3-protocol.h" +#include "ns3/ipv4-interface.h" +#include "ns3/arp-cache.h" +#include "ns3/names.h" #include "ipv4-routing-helper.h" namespace ns3 { @@ -82,4 +86,93 @@ Ipv4RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr stream) const +{ + for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) + { + Ptr node = NodeList::GetNode (i); + Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, this, node, stream); + } +} + +void +Ipv4RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) const +{ + for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) + { + Ptr node = NodeList::GetNode (i); + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, this, printInterval, node, stream); + } +} + +void +Ipv4RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) const +{ + Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, this, node, stream); +} + +void +Ipv4RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream) const +{ + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, this, printInterval, node, stream); +} + +void +Ipv4RoutingHelper::PrintArpCache (Ptr node, Ptr stream) const +{ + std::ostream* os = stream->GetStream (); + + *os << "ARP Cache of node "; + std::string found = Names::FindName (node); + if (Names::FindName (node) != "") + { + *os << found; + } + else + { + *os << static_cast (node->GetId ()); + } + *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + + Ptr ipv4 = node->GetObject (); + for (uint32_t i=0; iGetNInterfaces(); i++) + { + Ptr arpCache = ipv4->GetInterface (i)->GetArpCache (); + if (arpCache) + { + arpCache->PrintArpCache (stream); + } + } +} + +void +Ipv4RoutingHelper::PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream) const +{ + std::ostream* os = stream->GetStream (); + + *os << "ARP Cache of node "; + std::string found = Names::FindName (node); + if (Names::FindName (node) != "") + { + *os << found; + } + else + { + *os << static_cast (node->GetId ()); + } + *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + + Ptr ipv4 = node->GetObject (); + for (uint32_t i=0; iGetNInterfaces(); i++) + { + Ptr arpCache = ipv4->GetInterface (i)->GetArpCache (); + if (arpCache) + { + arpCache->PrintArpCache (stream); + } + } + Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, this, printInterval, node, stream); +} + } // namespace ns3 diff --git a/src/internet/helper/ipv4-routing-helper.h b/src/internet/helper/ipv4-routing-helper.h index 6a676836a..f7edf680e 100644 --- a/src/internet/helper/ipv4-routing-helper.h +++ b/src/internet/helper/ipv4-routing-helper.h @@ -109,6 +109,68 @@ public: */ void PrintRoutingTableEvery (Time printInterval, Ptr node, Ptr stream) const; + /** + * \brief prints the neighbor cache of all nodes at a particular time. + * \param printTime the time at which the neighbor cache is supposed to be printed. + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAllAt (Time printTime, Ptr stream) const; + + /** + * \brief prints the neighbor cache of all nodes at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) const; + + /** + * \brief prints the neighbor cache of a node at a particular time. + * \param printTime the time at which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) const; + + /** + * \brief prints the neighbor cache of a node at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream) const; + /** * \brief Request a specified routing protocol <T> from Ipv4RoutingProtocol protocol * @@ -130,7 +192,7 @@ private: * \param stream The output stream object to use * * This method calls the PrintRoutingTable() method of the - * Ipv6RoutingProtocol stored in the Ipv6 object; + * Ipv4RoutingProtocol stored in the Ipv4 object; * the output format is routing protocol-specific. */ void Print (Ptr node, Ptr stream) const; @@ -144,10 +206,45 @@ private: * \param stream The output stream object to use * * This method calls the PrintRoutingTable() method of the - * Ipv6RoutingProtocol stored in the Ipv6 object, for the selected node + * Ipv4RoutingProtocol stored in the Ipv4 object, for the selected node * at the specified interval; the output format is routing protocol-specific. */ void PrintEvery (Time printInterval, Ptr node, Ptr stream) const; + + /** + * \internal + * + * \brief prints the neighbor cache of a node. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintArpCache (Ptr node, Ptr stream) const; + + /** + * \internal + * + * \brief prints the neighbor cache of a node at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintArpCache() method of the + * ArpCache associated with each Ipv4Interface stored in the Ipv4 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 10.1.1.2 dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintArpCacheEvery (Time printInterval, Ptr node, Ptr stream) const; }; diff --git a/src/internet/helper/ipv6-routing-helper.cc b/src/internet/helper/ipv6-routing-helper.cc index 6ab299d69..5fd121288 100644 --- a/src/internet/helper/ipv6-routing-helper.cc +++ b/src/internet/helper/ipv6-routing-helper.cc @@ -23,6 +23,10 @@ #include "ns3/simulator.h" #include "ns3/ipv6-routing-protocol.h" #include "ns3/ipv6-list-routing.h" +#include "ns3/ipv6-l3-protocol.h" +#include "ns3/ipv6-interface.h" +#include "ns3/ndisc-cache.h" +#include "ns3/names.h" #include "ipv6-routing-helper.h" namespace ns3 { @@ -82,4 +86,93 @@ Ipv6RoutingHelper::PrintEvery (Time printInterval, Ptr node, Ptr stream) const +{ + for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) + { + Ptr node = NodeList::GetNode (i); + Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, this, node, stream); + } +} + +void +Ipv6RoutingHelper::PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) const +{ + for (uint32_t i = 0; i < NodeList::GetNNodes (); i++) + { + Ptr node = NodeList::GetNode (i); + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, this, printInterval, node, stream); + } +} + +void +Ipv6RoutingHelper::PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) const +{ + Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, this, node, stream); +} + +void +Ipv6RoutingHelper::PrintNeighborCacheEvery (Time printInterval,Ptr node, Ptr stream) const +{ + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, this, printInterval, node, stream); +} + +void +Ipv6RoutingHelper::PrintNdiscCache (Ptr node, Ptr stream) const +{ + std::ostream* os = stream->GetStream (); + + *os << "NDISC Cache of node "; + std::string found = Names::FindName (node); + if (Names::FindName (node) != "") + { + *os << found; + } + else + { + *os << static_cast (node->GetId ()); + } + *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + + Ptr ipv6 = node->GetObject (); + for (uint32_t i=0; iGetNInterfaces(); i++) + { + Ptr ndiscCache = ipv6->GetInterface (i)->GetNdiscCache (); + if (ndiscCache) + { + ndiscCache->PrintNdiscCache (stream); + } + } +} + +void +Ipv6RoutingHelper::PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream) const +{ + std::ostream* os = stream->GetStream (); + + *os << "NDISC Cache of node "; + std::string found = Names::FindName (node); + if (Names::FindName (node) != "") + { + *os << found; + } + else + { + *os << static_cast (node->GetId ()); + } + *os << " at time " << Simulator::Now ().GetSeconds () << "\n"; + + Ptr ipv6 = node->GetObject (); + for (uint32_t i=0; iGetNInterfaces(); i++) + { + Ptr ndiscCache = ipv6->GetInterface (i)->GetNdiscCache (); + if (ndiscCache) + { + ndiscCache->PrintNdiscCache (stream); + } + } + Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, this, printInterval, node, stream); +} + } // namespace ns3 diff --git a/src/internet/helper/ipv6-routing-helper.h b/src/internet/helper/ipv6-routing-helper.h index df577a53e..cd4b1a4ce 100644 --- a/src/internet/helper/ipv6-routing-helper.h +++ b/src/internet/helper/ipv6-routing-helper.h @@ -111,6 +111,68 @@ public: */ void PrintRoutingTableEvery (Time printInterval, Ptr node, Ptr stream) const; + /** + * \brief prints the neighbor cache of all nodes at a particular time. + * \param printTime the time at which the neighbor cache is supposed to be printed. + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAllAt (Time printTime, Ptr stream) const; + + /** + * \brief prints the neighbor cache of all nodes at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAllEvery (Time printInterval, Ptr stream) const; + + /** + * \brief prints the neighbor cache of a node at a particular time. + * \param printTime the time at which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheAt (Time printTime, Ptr node, Ptr stream) const; + + /** + * \brief prints the neighbor cache of a node at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNeighborCacheEvery (Time printInterval, Ptr node, Ptr stream) const; + /** * \brief Request a specified routing protocol <T> from Ipv6RoutingProtocol protocol * @@ -150,6 +212,41 @@ private: * at the specified interval; the output format is routing protocol-specific. */ void PrintEvery (Time printInterval, Ptr node, Ptr stream) const; + + /** + * \internal + * + * \brief prints the neighbor cache of a node. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNdiscCache (Ptr node, Ptr stream) const; + + /** + * \internal + * + * \brief prints the neighbor cache of a node at regular intervals specified by user. + * \param printInterval the time interval for which the neighbor cache is supposed to be printed. + * \param node The node ptr for which we need the neighbor cache to be printed + * \param stream The output stream object to use + * + * This method calls the PrintNdiscCache() method of the + * NdiscCache associated with each Ipv6Interface stored in the Ipv6 object, for all nodes at the + * specified time. The output format is similar to: + * \verbatim + 2001:db8::f00d:beef:cafe dev 1 lladdr 00-06-00:00:00:00:00:02 REACHABLE + \endverbatim + * Note that the MAC address is printed as "type"-"size"-"actual address" + */ + void PrintNdiscCacheEvery (Time printInterval, Ptr node, Ptr stream) const; }; /** diff --git a/src/internet/model/arp-cache.cc b/src/internet/model/arp-cache.cc index 7a9f8ab28..fe9610dcb 100644 --- a/src/internet/model/arp-cache.cc +++ b/src/internet/model/arp-cache.cc @@ -24,6 +24,7 @@ #include "ns3/log.h" #include "ns3/node.h" #include "ns3/trace-source-accessor.h" +#include "ns3/names.h" #include "arp-cache.h" #include "arp-header.h" @@ -242,6 +243,42 @@ ArpCache::Flush (void) } } +void +ArpCache::PrintArpCache (Ptr stream) +{ + NS_LOG_FUNCTION (this << stream); + std::ostream* os = stream->GetStream (); + + for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) + { + *os << i->first << " dev "; + std::string found = Names::FindName (m_device); + if (Names::FindName (m_device) != "") + { + *os << found; + } + else + { + *os << static_cast (m_device->GetIfIndex ()); + } + + *os << " lladdr " << i->second->GetMacAddress (); + + if (i->second->IsAlive ()) + { + *os << " REACHABLE\n"; + } + else if (i->second->IsWaitReply ()) + { + *os << " DELAY\n"; + } + else + { + *os << " STALE\n"; + } + } +} + ArpCache::Entry * ArpCache::Lookup (Ipv4Address to) { @@ -346,7 +383,6 @@ Address ArpCache::Entry::GetMacAddress (void) const { NS_LOG_FUNCTION (this); - NS_ASSERT (m_state == ALIVE); return m_macAddress; } Ipv4Address diff --git a/src/internet/model/arp-cache.h b/src/internet/model/arp-cache.h index 05a4b90e3..f9a69e675 100644 --- a/src/internet/model/arp-cache.h +++ b/src/internet/model/arp-cache.h @@ -33,6 +33,7 @@ #include "ns3/object.h" #include "ns3/traced-callback.h" #include "ns3/sgi-hashmap.h" +#include "ns3/output-stream-wrapper.h" namespace ns3 { @@ -76,8 +77,8 @@ public: /** * \brief Set the NetDevice and Ipv4Interface associated with the ArpCache * - * \param device The hardware NetDevice associated with this ARP chache - * \param interface the Ipv4Interface associated with this ARP chache + * \param device The hardware NetDevice associated with this ARP cache + * \param interface the Ipv4Interface associated with this ARP cache */ void SetDevice (Ptr device, Ptr interface); /** @@ -154,6 +155,13 @@ public: */ void Flush (void); + /** + * \brief Print the ARP cache entries + * + * \param stream the ostream the ARP cache entries is printed to + */ + void PrintArpCache (Ptr stream); + /** * \brief A record that that holds information about an ArpCache entry */ diff --git a/src/internet/model/ipv4-interface.h b/src/internet/model/ipv4-interface.h index 072fb1929..4bf984e7e 100644 --- a/src/internet/model/ipv4-interface.h +++ b/src/internet/model/ipv4-interface.h @@ -78,6 +78,7 @@ public: * \returns the underlying NetDevice. This method cannot return zero. */ Ptr GetDevice (void) const; + /** * \return ARP cache used by this interface */ diff --git a/src/internet/model/ipv6-interface.cc b/src/internet/model/ipv6-interface.cc index 9c5ac1aa1..ed8388f92 100644 --- a/src/internet/model/ipv6-interface.cc +++ b/src/internet/model/ipv6-interface.cc @@ -505,5 +505,11 @@ void Ipv6Interface::SetNsDadUid (Ipv6Address address, uint32_t uid) /* not found, maybe address has expired */ } +Ptr Ipv6Interface::GetNdiscCache () const +{ + NS_LOG_FUNCTION (this); + return m_ndCache; +} + } /* namespace ns3 */ diff --git a/src/internet/model/ipv6-interface.h b/src/internet/model/ipv6-interface.h index c7c615b1b..b238771b2 100644 --- a/src/internet/model/ipv6-interface.h +++ b/src/internet/model/ipv6-interface.h @@ -250,6 +250,12 @@ public: */ void SetNsDadUid (Ipv6Address address, uint32_t uid); + /** + * \return NDISC cache used by this interface + */ + Ptr GetNdiscCache () const; + + protected: /** * \brief Dispose this object. diff --git a/src/internet/model/ndisc-cache.cc b/src/internet/model/ndisc-cache.cc index 79b6d313b..6b1dbc7e1 100644 --- a/src/internet/model/ndisc-cache.cc +++ b/src/internet/model/ndisc-cache.cc @@ -21,6 +21,7 @@ #include "ns3/log.h" #include "ns3/uinteger.h" #include "ns3/node.h" +#include "ns3/names.h" #include "ipv6-l3-protocol.h" #include "icmpv6-l4-protocol.h" @@ -149,6 +150,49 @@ uint32_t NdiscCache::GetUnresQlen () return m_unresQlen; } +void NdiscCache::PrintNdiscCache (Ptr stream) +{ + NS_LOG_FUNCTION (this << stream); + std::ostream* os = stream->GetStream (); + + for (CacheI i = m_ndCache.begin (); i != m_ndCache.end (); i++) + { + *os << i->first << " dev "; + std::string found = Names::FindName (m_device); + if (Names::FindName (m_device) != "") + { + *os << found; + } + else + { + *os << static_cast (m_device->GetIfIndex ()); + } + + *os << " lladdr " << i->second->GetMacAddress (); + + if (i->second->IsReachable ()) + { + *os << " REACHABLE\n"; + } + else if (i->second->IsDelay ()) + { + *os << " DELAY\n"; + } + else if (i->second->IsIncomplete ()) + { + *os << " INCOMPLETE\n"; + } + else if (i->second->IsProbe ()) + { + *os << " PROBE\n"; + } + else + { + *os << " STALE\n"; + } + } +} + NdiscCache::Entry::Entry (NdiscCache* nd) : m_ndCache (nd), m_waiting (), diff --git a/src/internet/model/ndisc-cache.h b/src/internet/model/ndisc-cache.h index 0211ad627..6887b9d1f 100644 --- a/src/internet/model/ndisc-cache.h +++ b/src/internet/model/ndisc-cache.h @@ -22,7 +22,6 @@ #define NDISC_CACHE_H #include - #include #include "ns3/packet.h" @@ -32,6 +31,7 @@ #include "ns3/ptr.h" #include "ns3/timer.h" #include "ns3/sgi-hashmap.h" +#include "ns3/output-stream-wrapper.h" namespace ns3 { @@ -124,6 +124,13 @@ public: */ void SetDevice (Ptr device, Ptr interface); + /** + * \brief Print the NDISC cache entries + * + * \param stream the ostream the NDISC cache entries is printed to + */ + void PrintNdiscCache (Ptr stream); + /** * \class Entry * \brief A record that holds information about an NdiscCache entry.