From e683e1ab1c81e6989cc9a39137c5a40b5adf2b00 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 9 Aug 2007 21:25:23 +0200 Subject: [PATCH 01/92] remove TraceContext argument from TraceResolver constructor and move it to Connect --- src/common/array-trace-resolver.h | 14 +++---- src/common/composite-trace-resolver.cc | 36 +++++++++--------- src/common/composite-trace-resolver.h | 37 +++++++++---------- src/common/empty-trace-resolver.cc | 3 +- src/common/empty-trace-resolver.h | 2 +- src/common/terminal-trace-resolver.h | 14 +++---- src/common/trace-resolver.cc | 23 ++++-------- src/common/trace-resolver.h | 21 ++--------- src/common/trace-root.cc | 6 +-- src/common/trace-root.h | 2 +- src/devices/csma-cd/csma-cd-net-device.cc | 4 +- src/devices/csma-cd/csma-cd-net-device.h | 2 +- .../point-to-point-net-device.cc | 5 +-- .../point-to-point-net-device.h | 2 +- src/internet-node/arp-ipv4-interface.cc | 4 +- src/internet-node/arp-ipv4-interface.h | 2 +- src/internet-node/arp-l3-protocol.cc | 4 +- src/internet-node/arp-l3-protocol.h | 2 +- src/internet-node/ipv4-interface.cc | 4 +- src/internet-node/ipv4-interface.h | 4 +- src/internet-node/ipv4-l3-protocol.cc | 9 ++--- src/internet-node/ipv4-l3-protocol.h | 4 +- src/internet-node/ipv4-l4-demux.cc | 4 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/internet-node/ipv4-l4-protocol.h | 2 +- src/internet-node/ipv4-loopback-interface.cc | 4 +- src/internet-node/ipv4-loopback-interface.h | 2 +- src/internet-node/udp-l4-protocol.cc | 4 +- src/internet-node/udp-l4-protocol.h | 2 +- src/node/net-device.cc | 4 +- src/node/net-device.h | 4 +- src/node/node-list.cc | 11 +++--- src/node/node-list.h | 2 +- src/node/node.cc | 9 ++--- src/node/node.h | 5 +-- src/node/queue.cc | 4 +- src/node/queue.h | 2 +- 37 files changed, 114 insertions(+), 151 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index e4507d4af..ffcc6cc89 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -37,7 +37,6 @@ class ArrayTraceResolver : public TraceResolver { public: /** - * \param context trace context associated to this trace resolver * \param getSize callback which returns dynamically the size of underlying array * \param get callback which returns any element in the underlying array * @@ -51,8 +50,7 @@ public: * a pointer to a TraceResolver. i.e. the signature is: * TraceResolver * (*) (TraceContext const &) */ - ArrayTraceResolver (TraceContext const &context, - Callback getSize, + ArrayTraceResolver (Callback getSize, Callback get); private: virtual TraceResolverList DoLookup (std::string id) const; @@ -64,11 +62,9 @@ private: namespace ns3 { template -ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context, - Callback getSize, +ArrayTraceResolver::ArrayTraceResolver (Callback getSize, Callback get) - : TraceResolver (context), - m_getSize (getSize), + : m_getSize (getSize), m_get (get) {} template @@ -80,10 +76,10 @@ ArrayTraceResolver::DoLookup (std::string id) const { for (uint32_t i = 0; i < m_getSize (); i++) { - TraceContext context = GetContext (); + TraceContext context; INDEX index = i; context.Add (index); - list.push_back (m_get (i)->CreateTraceResolver (context)); + list.push_back (std::make_pair (m_get (i)->CreateTraceResolver (), context)); } } return list; diff --git a/src/common/composite-trace-resolver.cc b/src/common/composite-trace-resolver.cc index bf60aa81e..e9f461959 100644 --- a/src/common/composite-trace-resolver.cc +++ b/src/common/composite-trace-resolver.cc @@ -22,8 +22,7 @@ namespace ns3 { -CompositeTraceResolver::CompositeTraceResolver (TraceContext const &context) - : TraceResolver (context) +CompositeTraceResolver::CompositeTraceResolver () {} CompositeTraceResolver::~CompositeTraceResolver () @@ -31,15 +30,14 @@ CompositeTraceResolver::~CompositeTraceResolver () void CompositeTraceResolver::Add (std::string name, - Callback createResolver) + Callback createResolver) { - TraceContext traceContext = GetContext (); - DoAdd (name, createResolver, traceContext); + DoAdd (name, createResolver, TraceContext ()); } void CompositeTraceResolver::DoAdd (std::string name, - Callback createResolver, + Callback createResolver, TraceContext const &context) { struct CallbackTraceSourceItem item; @@ -57,7 +55,7 @@ CompositeTraceResolver::DoLookup (std::string id) const TraceResolver::TraceResolverList list; for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { - list.push_back (i->createResolver (i->context)); + list.push_back (std::make_pair (i->createResolver (), i->context)); } return list; } @@ -71,7 +69,7 @@ CompositeTraceResolver::DoLookup (std::string id) const if (i->name == id) { TraceResolver::TraceResolverList list; - list.push_back (i->createResolver (i->context)); + list.push_back (std::make_pair (i->createResolver (), i->context)); return list; } } @@ -102,7 +100,7 @@ CompositeTraceResolver::DoLookup (std::string id) const { if (j->name == *i) { - list.push_back (j->createResolver (j->context)); + list.push_back (std::make_pair (j->createResolver (), j->context)); break; } } @@ -168,7 +166,7 @@ public: private: void TraceDouble (TraceContext const &context, double v); void TraceInt (TraceContext const &context, int v); - TraceResolver *CreateSubResolver (TraceContext const &context); + TraceResolver *CreateSubResolver (); bool m_gotDoubleA; @@ -209,9 +207,9 @@ CompositeTraceResolverTest::TraceInt (TraceContext const &context, int v) } TraceResolver * -CompositeTraceResolverTest::CreateSubResolver (TraceContext const &context) +CompositeTraceResolverTest::CreateSubResolver (void) { - CompositeTraceResolver *subresolver = new CompositeTraceResolver (context); + CompositeTraceResolver *subresolver = new CompositeTraceResolver (); subresolver->Add ("trace-int", m_traceInt, SubTraceSourceTest (SubTraceSourceTest::INT)); return subresolver; @@ -225,14 +223,14 @@ CompositeTraceResolverTest::RunTests (void) CallbackTraceSource traceDoubleB; TraceContext context; - CompositeTraceResolver resolver (context) ; + CompositeTraceResolver resolver; resolver.Add ("trace-double-a", traceDoubleA, TraceSourceTest (TraceSourceTest::DOUBLEA)); resolver.Add ("trace-double-b", traceDoubleB, TraceSourceTest (TraceSourceTest::DOUBLEB)); - resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); + resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); m_gotDoubleA = false; m_gotDoubleB = false; @@ -263,7 +261,7 @@ CompositeTraceResolverTest::RunTests (void) } resolver.Connect ("/trace-double-a", - MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); + MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); m_gotDoubleA = false; m_gotDoubleB = false; traceDoubleA (0); @@ -276,7 +274,7 @@ CompositeTraceResolverTest::RunTests (void) MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); resolver.Connect ("/(trace-double-a)", - MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); + MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); m_gotDoubleA = false; m_gotDoubleB = false; traceDoubleA (0); @@ -289,7 +287,7 @@ CompositeTraceResolverTest::RunTests (void) MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); resolver.Connect ("/(trace-double-a|trace-double-b)", - MakeCallback (&CompositeTraceResolverTest::TraceDouble, this)); + MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); m_gotDoubleA = false; m_gotDoubleB = false; traceDoubleA (0); @@ -326,7 +324,7 @@ CompositeTraceResolverTest::RunTests (void) TraceSourceTest (TraceSourceTest::SUBRESOLVER)); resolver.Connect ("/subresolver/trace-int", - MakeCallback (&CompositeTraceResolverTest::TraceInt, this)); + MakeCallback (&CompositeTraceResolverTest::TraceInt, this), TraceContext ()); m_gotInt = false; m_traceInt (1); if (!m_gotInt) @@ -344,7 +342,7 @@ CompositeTraceResolverTest::RunTests (void) } resolver.Connect ("/*/trace-int", - MakeCallback (&CompositeTraceResolverTest::TraceInt, this)); + MakeCallback (&CompositeTraceResolverTest::TraceInt, this), TraceContext ()); m_gotInt = false; m_traceInt (1); if (!m_gotInt) diff --git a/src/common/composite-trace-resolver.h b/src/common/composite-trace-resolver.h index cadf9da2d..0f08be274 100644 --- a/src/common/composite-trace-resolver.h +++ b/src/common/composite-trace-resolver.h @@ -38,7 +38,7 @@ namespace ns3 { class CompositeTraceResolver : public TraceResolver { public: - CompositeTraceResolver (TraceContext const &context); + CompositeTraceResolver (); virtual ~CompositeTraceResolver (); /** * \param name name of trace source @@ -109,7 +109,7 @@ public: */ template void Add (std::string name, - Callback createResolver, + Callback createResolver, T const &context); /** @@ -122,23 +122,22 @@ public: * will be invoked to create the child trace resolver. */ void Add (std::string name, - Callback createResolver); + Callback createResolver); private: template void DoAddTraceSource (std::string name, SOURCE &traceSource, CONTEXT const &context); template - static TraceResolver *CreateTerminalTraceResolver (SOURCE *trace, - TraceContext const &context); + static TraceResolver *CreateTerminalTraceResolver (SOURCE *trace); void DoAdd (std::string name, - Callback createResolver, + Callback createResolver, TraceContext const &context); virtual TraceResolverList DoLookup (std::string id) const; struct CallbackTraceSourceItem { std::string name; - Callback createResolver; + Callback createResolver; TraceContext context; }; @@ -155,21 +154,21 @@ void CompositeTraceResolver::DoAddTraceSource (std::string name, SOURCE &traceSource, CONTEXT const &context) { - TraceContext traceContext = GetContext (); - traceContext.Add (context); - TraceResolver *(*create) (SOURCE *trace, TraceContext const &context); + TraceResolver *(*create) (SOURCE *trace); create = &CompositeTraceResolver::CreateTerminalTraceResolver; - Callback createResolver = + Callback createResolver = MakeBoundCallback (create, &traceSource); - DoAdd (name, createResolver, traceContext); + + TraceContext ctx; + ctx.Add (context); + DoAdd (name, createResolver, ctx); } template TraceResolver * -CompositeTraceResolver::CreateTerminalTraceResolver (SOURCE *traceSource, - TraceContext const &context) +CompositeTraceResolver::CreateTerminalTraceResolver (SOURCE *traceSource) { - return new TerminalTraceResolver (*traceSource, context); + return new TerminalTraceResolver (*traceSource); } @@ -209,12 +208,12 @@ CompositeTraceResolver::Add (std::string name, template void CompositeTraceResolver::Add (std::string name, - Callback createResolver, + Callback createResolver, T const &context) { - TraceContext traceContext = GetContext (); - traceContext.Add (context); - DoAdd (name, createResolver, traceContext); + TraceContext ctx; + ctx.Add (context); + DoAdd (name, createResolver, ctx); } }//namespace ns3 diff --git a/src/common/empty-trace-resolver.cc b/src/common/empty-trace-resolver.cc index 18b9e5301..dc3478864 100644 --- a/src/common/empty-trace-resolver.cc +++ b/src/common/empty-trace-resolver.cc @@ -20,6 +20,5 @@ */ #include "empty-trace-resolver.h" -ns3::EmptyTraceResolver::EmptyTraceResolver (TraceContext const &context) - : TraceResolver (context) +ns3::EmptyTraceResolver::EmptyTraceResolver () {} diff --git a/src/common/empty-trace-resolver.h b/src/common/empty-trace-resolver.h index 04f1c1bc4..1e5ddab46 100644 --- a/src/common/empty-trace-resolver.h +++ b/src/common/empty-trace-resolver.h @@ -44,7 +44,7 @@ public: * * The only constructor exported by this class. */ - EmptyTraceResolver (TraceContext const &o); + EmptyTraceResolver (); }; }//namespace ns3 diff --git a/src/common/terminal-trace-resolver.h b/src/common/terminal-trace-resolver.h index e026d07cb..a2d985ad8 100644 --- a/src/common/terminal-trace-resolver.h +++ b/src/common/terminal-trace-resolver.h @@ -31,9 +31,9 @@ template class TerminalTraceResolver : public TraceResolver { public: - TerminalTraceResolver (T &traceSource, TraceContext const &context); + TerminalTraceResolver (T &traceSource); private: - virtual void DoConnect (CallbackBase const &cb); + virtual void DoConnect (CallbackBase const &cb, const TraceContext &context); virtual void DoDisconnect (CallbackBase const &cb); T &m_traceSource; }; @@ -43,16 +43,14 @@ class TerminalTraceResolver : public TraceResolver namespace ns3 { template -TerminalTraceResolver::TerminalTraceResolver (T &traceSource, - TraceContext const &context) - : TraceResolver (context), - m_traceSource (traceSource) +TerminalTraceResolver::TerminalTraceResolver (T &traceSource) + : m_traceSource (traceSource) {} template void -TerminalTraceResolver::DoConnect (CallbackBase const &cb) +TerminalTraceResolver::DoConnect (CallbackBase const &cb, const TraceContext &context) { - m_traceSource.AddCallback (cb, GetContext ()); + m_traceSource.AddCallback (cb, context); } template void diff --git a/src/common/trace-resolver.cc b/src/common/trace-resolver.cc index 251e7cc87..75c7a576d 100644 --- a/src/common/trace-resolver.cc +++ b/src/common/trace-resolver.cc @@ -22,21 +22,12 @@ namespace ns3 { -TraceResolver::TraceResolver (TraceContext const &context) - : m_context (context) -{} TraceResolver::~TraceResolver () {} -TraceContext const & -TraceResolver::GetContext (void) const -{ - return m_context; -} - void -TraceResolver::Connect (std::string path, CallbackBase const &cb) +TraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { std::string::size_type cur = 1; // check that first char is "/" @@ -45,16 +36,18 @@ TraceResolver::Connect (std::string path, CallbackBase const &cb) TraceResolverList resolverList = DoLookup (element); for (TraceResolverList::iterator i = resolverList.begin (); i != resolverList.end (); i++) { - TraceResolver *resolver = *i; + TraceResolver *resolver = i->first; + TraceContext tmp = context; + tmp.Add (i->second); if (next == std::string::npos) { // we really break the recursion here. - resolver->DoConnect (cb); + resolver->DoConnect (cb, tmp); } else { std::string subpath = std::string (path, next, std::string::npos); - resolver->Connect (subpath, cb); + resolver->Connect (subpath, cb, tmp); } delete resolver; } @@ -71,7 +64,7 @@ TraceResolver::Disconnect (std::string path, CallbackBase const &cb) TraceResolverList resolverList = DoLookup (element); for (TraceResolverList::iterator i = resolverList.begin (); i != resolverList.end (); i++) { - TraceResolver *resolver = *i; + TraceResolver *resolver = i->first; if (next == std::string::npos) { // we really break the recursion here. @@ -93,7 +86,7 @@ TraceResolver::DoLookup (std::string id) const return TraceResolverList (); } void -TraceResolver::DoConnect (CallbackBase const &cb) +TraceResolver::DoConnect (CallbackBase const &cb, const TraceContext &context) {} void diff --git a/src/common/trace-resolver.h b/src/common/trace-resolver.h index 93bf43095..63dbd267e 100644 --- a/src/common/trace-resolver.h +++ b/src/common/trace-resolver.h @@ -59,7 +59,7 @@ public: * users could also conceivably call it directly if they want to * skip the ns3::TraceRoot. */ - void Connect (std::string path, CallbackBase const &cb); + void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); /** * \param path the namespace path to resolver * \param cb the callback to disconnect in the matching namespace @@ -70,23 +70,8 @@ public: */ void Disconnect (std::string path, CallbackBase const &cb); protected: - /** - * \param context the context used to initialize this TraceResolver. - * - * Every subclass must call this constructor - */ - TraceResolver (TraceContext const &context); - /** - * \returns the ns3::TraceContext stored in this ns3::TraceResolver. - * - * Subclasses usually invoke this method to get access to the - * TraceContext stored here to pass it down to the TraceResolver - * constructors invoked from within the DoLookup method. - */ - TraceContext const &GetContext (void) const; - typedef std::list TraceResolverList; + typedef std::list > TraceResolverList; private: - TraceResolver (); /** * \param id the id to resolve. This is supposed to be * one element of the global tracing namespace. @@ -104,7 +89,7 @@ private: * * This method is invoked on leaf trace resolvers. */ - virtual void DoConnect (CallbackBase const &cb); + virtual void DoConnect (CallbackBase const &cb, const TraceContext &context); /** * \param cb callback to disconnect * diff --git a/src/common/trace-root.cc b/src/common/trace-root.cc index 5bb270b8c..cd49b1150 100644 --- a/src/common/trace-root.cc +++ b/src/common/trace-root.cc @@ -28,7 +28,7 @@ void TraceRoot::Connect (std::string path, CallbackBase const &cb) { TraceResolver *resolver = GetComposite (); - resolver->Connect (path, cb); + resolver->Connect (path, cb, TraceContext ()); } void TraceRoot::Disconnect (std::string path, CallbackBase const &cb) @@ -38,7 +38,7 @@ TraceRoot::Disconnect (std::string path, CallbackBase const &cb) } void TraceRoot::Register (std::string name, - Callback createResolver) + Callback createResolver) { CompositeTraceResolver *resolver = GetComposite (); resolver->Add (name, createResolver); @@ -47,7 +47,7 @@ TraceRoot::Register (std::string name, CompositeTraceResolver * TraceRoot::GetComposite (void) { - static CompositeTraceResolver resolver = CompositeTraceResolver (TraceContext ()); + static CompositeTraceResolver resolver; return &resolver; } diff --git a/src/common/trace-root.h b/src/common/trace-root.h index a07f923cd..270747fce 100644 --- a/src/common/trace-root.h +++ b/src/common/trace-root.h @@ -325,7 +325,7 @@ public: static void Connect (std::string path, CallbackBase const &cb); static void Disconnect (std::string path, CallbackBase const &cb); static void Register (std::string name, - Callback createResolver); + Callback createResolver); private: static CompositeTraceResolver *GetComposite (void); }; diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index d5dfc8501..bb51fd36a 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -450,9 +450,9 @@ CsmaCdNetDevice::TransmitReadyEvent (void) } TraceResolver * -CsmaCdNetDevice::DoCreateTraceResolver (TraceContext const &context) +CsmaCdNetDevice::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); resolver->Add ("queue", MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma-cd/csma-cd-net-device.h index 36a555339..51b3db8ea 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma-cd/csma-cd-net-device.h @@ -311,7 +311,7 @@ private: * (NOT TESTED) * @see class TraceResolver */ - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); + virtual TraceResolver *DoCreateTraceResolver (void); /** * Aborts the transmission of the current packet 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 86c9d9a4c..f09810f82 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 @@ -188,10 +188,9 @@ void PointToPointNetDevice::TransmitComplete (void) TransmitStart(p); } -TraceResolver* PointToPointNetDevice::DoCreateTraceResolver ( - TraceContext const &context) +TraceResolver* PointToPointNetDevice::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); resolver->Add ("queue", MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); resolver->Add ("rx", 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 b6be56afa..8d2a02fe2 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 @@ -243,7 +243,7 @@ private: * * @see class TraceResolver */ - virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context); + virtual TraceResolver* DoCreateTraceResolver (void); virtual bool DoNeedsArp (void) const; /** * Enumeration of the states of the transmit machine of the net device. diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index efe767531..7077d0903 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -41,9 +41,9 @@ ArpIpv4Interface::~ArpIpv4Interface () {} TraceResolver * -ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context) +ArpIpv4Interface::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); if (GetDevice () != 0) { resolver->Add ("netdevice", diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index 7df522e01..537a16a2f 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -44,7 +44,7 @@ class ArpIpv4Interface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); + virtual TraceResolver *DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index 100f1df88..46654c89e 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -59,9 +59,9 @@ ArpL3Protocol::DoDispose (void) } TraceResolver * -ArpL3Protocol::CreateTraceResolver (TraceContext const &context) +ArpL3Protocol::CreateTraceResolver (void) { - return new EmptyTraceResolver (context); + return new EmptyTraceResolver (); } ArpCache * diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index a2ea8227e..3d752b46e 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -49,7 +49,7 @@ public: ArpL3Protocol (Ptr node); virtual ~ArpL3Protocol (); - virtual TraceResolver *CreateTraceResolver (TraceContext const &context); + virtual TraceResolver *CreateTraceResolver (void); /** * \brief Recieve a packet */ diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index cfc398582..d44edf130 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -46,9 +46,9 @@ Ipv4Interface::GetDevice (void) const } TraceResolver * -Ipv4Interface::CreateTraceResolver (TraceContext const &context) +Ipv4Interface::CreateTraceResolver (void) { - return DoCreateTraceResolver (context); + return DoCreateTraceResolver (); } void diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index 1098c567c..e5c6788eb 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -83,7 +83,7 @@ public: * This method will delegate the work to the private DoCreateTraceResolver * method which is supposed to be implemented by subclasses. */ - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); /** * \returns the underlying NetDevice. This method can return * zero if this interface has no associated NetDevice. @@ -153,7 +153,7 @@ public: private: virtual void SendTo (Packet p, Ipv4Address dest) = 0; - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; + virtual TraceResolver *DoCreateTraceResolver (void) = 0; Ptr m_netdevice; bool m_ifup; Ipv4Address m_address; diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index be483dfa0..9fd06abba 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -154,9 +154,9 @@ Ipv4L3Protocol::SetupLoopback (void) } TraceResolver * -Ipv4L3Protocol::CreateTraceResolver (TraceContext const &context) +Ipv4L3Protocol::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); @@ -166,12 +166,11 @@ Ipv4L3Protocol::CreateTraceResolver (TraceContext const &context) } TraceResolver * -Ipv4L3Protocol::InterfacesCreateTraceResolver (TraceContext const &context) const +Ipv4L3Protocol::InterfacesCreateTraceResolver (void) const { ArrayTraceResolver *resolver = new ArrayTraceResolver - (context, - MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this), + (MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this), MakeCallback (&Ipv4L3Protocol::GetInterface, this)); return resolver; } diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index 2cce3efa3..4209019ad 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -92,7 +92,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - virtual TraceResolver *CreateTraceResolver (TraceContext const &context); + virtual TraceResolver *CreateTraceResolver (void); /** * \param ttl default ttl to use @@ -189,7 +189,7 @@ private: void ForwardUp (Packet p, Ipv4Header const&ip); uint32_t AddIpv4Interface (Ipv4Interface *interface); void SetupLoopback (void); - TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const; + TraceResolver *InterfacesCreateTraceResolver (void) const; typedef std::list Ipv4InterfaceList; typedef std::list< std::pair< int, Ptr > > Ipv4RoutingProtocolList; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 977b802ba..9981a718d 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -79,9 +79,9 @@ Ipv4L4Demux::DoDispose (void) } TraceResolver * -Ipv4L4Demux::CreateTraceResolver (TraceContext const &context) +Ipv4L4Demux::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { Ptr protocol = *i; diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 7e7fba62e..8431e1e48 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -66,7 +66,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); /** * \param protocol a template for the protocol to add to this L4 Demux. * \returns the L4Protocol effectively added. diff --git a/src/internet-node/ipv4-l4-protocol.h b/src/internet-node/ipv4-l4-protocol.h index f23aa510b..4ecd5a142 100644 --- a/src/internet-node/ipv4-l4-protocol.h +++ b/src/internet-node/ipv4-l4-protocol.h @@ -59,7 +59,7 @@ public: */ int GetVersion() const; - virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0; + virtual TraceResolver *CreateTraceResolver () = 0; /** * \param p packet to forward up diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 47ddc9ee2..4e23abde3 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -35,9 +35,9 @@ Ipv4LoopbackInterface::~Ipv4LoopbackInterface () {} TraceResolver * -Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context) +Ipv4LoopbackInterface::DoCreateTraceResolver (void) { - return new EmptyTraceResolver (context); + return new EmptyTraceResolver (); } void diff --git a/src/internet-node/ipv4-loopback-interface.h b/src/internet-node/ipv4-loopback-interface.h index 3eead3a01..b17f46449 100644 --- a/src/internet-node/ipv4-loopback-interface.h +++ b/src/internet-node/ipv4-loopback-interface.h @@ -43,7 +43,7 @@ class Ipv4LoopbackInterface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); + virtual TraceResolver *DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index f0ef8569b..a83cb4657 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -46,9 +46,9 @@ UdpL4Protocol::~UdpL4Protocol () {} TraceResolver * -UdpL4Protocol::CreateTraceResolver (TraceContext const &context) +UdpL4Protocol::CreateTraceResolver (void) { - return new EmptyTraceResolver (context); + return new EmptyTraceResolver (); } void diff --git a/src/internet-node/udp-l4-protocol.h b/src/internet-node/udp-l4-protocol.h index 4d7a082d4..d41bbb839 100644 --- a/src/internet-node/udp-l4-protocol.h +++ b/src/internet-node/udp-l4-protocol.h @@ -49,7 +49,7 @@ public: UdpL4Protocol (Ptr node); virtual ~UdpL4Protocol (); - virtual TraceResolver *CreateTraceResolver (TraceContext const &context); + virtual TraceResolver *CreateTraceResolver (void); /** * \return A smart Socket pointer to a UdpSocket, allocated by this instance * of the UDP protocol diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 4fa2e8d51..626b82c63 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -184,9 +184,9 @@ NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber) } TraceResolver * -NetDevice::CreateTraceResolver (TraceContext const &context) +NetDevice::CreateTraceResolver (void) { - return DoCreateTraceResolver (context); + return DoCreateTraceResolver (); } Ptr diff --git a/src/node/net-device.h b/src/node/net-device.h index dd590f39c..cadd70dfc 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -69,7 +69,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); /** * \return the channel this NetDevice is connected to. The value @@ -290,7 +290,7 @@ public: * * Subclasses must implement this method. */ - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; + virtual TraceResolver *DoCreateTraceResolver (void) = 0; /** * \returns the channel associated to this NetDevice. * diff --git a/src/node/node-list.cc b/src/node/node-list.cc index eb43727d9..761717c9f 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -76,7 +76,7 @@ public: uint32_t Add (Ptr node); NodeList::Iterator Begin (void); NodeList::Iterator End (void); - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); @@ -131,12 +131,11 @@ NodeListPriv::GetNode (uint32_t n) TraceResolver * -NodeListPriv::CreateTraceResolver (TraceContext const &context) +NodeListPriv::CreateTraceResolver (void) { ArrayTraceResolver, NodeListIndex> *resolver = new ArrayTraceResolver, NodeListIndex> - (context, - MakeCallback (&NodeListPriv::GetNNodes, this), + (MakeCallback (&NodeListPriv::GetNNodes, this), MakeCallback (&NodeListPriv::GetNode, this)); return resolver; } @@ -166,9 +165,9 @@ NodeList::End (void) return SimulationSingleton::Get ()->End (); } TraceResolver * -NodeList::CreateTraceResolver (TraceContext const &context) +NodeList::CreateTraceResolver (void) { - return SimulationSingleton::Get ()->CreateTraceResolver (context); + return SimulationSingleton::Get ()->CreateTraceResolver (); } Ptr NodeList::GetNode (uint32_t n) diff --git a/src/node/node-list.h b/src/node/node-list.h index 1fdcd9e0e..beda5611c 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -79,7 +79,7 @@ public: * \returns the requested trace resolver. The caller * takes ownership of the returned pointer. */ - static TraceResolver *CreateTraceResolver (TraceContext const &context); + static TraceResolver *CreateTraceResolver (void); /** * \param n index of requested node. diff --git a/src/node/node.cc b/src/node/node.cc index ee83e8588..4de3a93ad 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -83,9 +83,9 @@ Node::~Node () {} TraceResolver * -Node::CreateTraceResolver (TraceContext const &context) +Node::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); DoFillTraceResolver (*resolver); return resolver; } @@ -142,12 +142,11 @@ Node::GetNApplications (void) const } TraceResolver * -Node::CreateDevicesTraceResolver (const TraceContext &context) +Node::CreateDevicesTraceResolver (void) { ArrayTraceResolver,NodeNetDeviceIndex> *resolver = new ArrayTraceResolver,NodeNetDeviceIndex> - (context, - MakeCallback (&Node::GetNDevices, this), + (MakeCallback (&Node::GetNDevices, this), MakeCallback (&Node::GetDevice, this)); return resolver; diff --git a/src/node/node.h b/src/node/node.h index f4d898f53..104f3a2a4 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -85,7 +85,6 @@ public: virtual ~Node(); /** - * \param context the trace context for the TraceResolver to create * \returns a newly-created TraceResolver. The caller takes * ownership of the returned pointer. * @@ -93,7 +92,7 @@ public: * could be used directly by a user who needs access to very low-level * trace configuration. */ - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); /** * \returns the unique id of this node. @@ -213,7 +212,7 @@ private: bool ReceiveFromDevice (Ptr device, const Packet &packet, uint16_t protocol, const Address &from); void Construct (void); - TraceResolver *CreateDevicesTraceResolver (const TraceContext &context); + TraceResolver *CreateDevicesTraceResolver (void); struct ProtocolHandlerEntry { ProtocolHandler handler; diff --git a/src/node/queue.cc b/src/node/queue.cc index 72eafed69..163f73ffc 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -95,9 +95,9 @@ Queue::~Queue() } TraceResolver * -Queue::CreateTraceResolver (TraceContext const &context) +Queue::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (); resolver->Add ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); resolver->Add ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); resolver->Add ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); diff --git a/src/node/queue.h b/src/node/queue.h index d135fff68..2c010c363 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -70,7 +70,7 @@ public: Queue (); virtual ~Queue (); - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (void); /** * \return true if the queue is empty; false otherwise From 07aedd4bb2bc59bf3a1143b52b9ad0cb4f98f971 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 14:13:47 +0200 Subject: [PATCH 02/92] allow resolvers to override Connect and Disconnect directly --- src/common/trace-resolver.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/trace-resolver.h b/src/common/trace-resolver.h index 63dbd267e..abb5cf1da 100644 --- a/src/common/trace-resolver.h +++ b/src/common/trace-resolver.h @@ -59,7 +59,7 @@ public: * users could also conceivably call it directly if they want to * skip the ns3::TraceRoot. */ - void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); + virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); /** * \param path the namespace path to resolver * \param cb the callback to disconnect in the matching namespace @@ -68,7 +68,7 @@ public: * users could also conceivably call it directly if they want to * skip the ns3::TraceRoot. */ - void Disconnect (std::string path, CallbackBase const &cb); + virtual void Disconnect (std::string path, CallbackBase const &cb); protected: typedef std::list > TraceResolverList; private: From cb9fdc66e3493db9de4b7e85cca6f323b2dd493b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 14:14:29 +0200 Subject: [PATCH 03/92] override Connect and Disconnect in Composite and Terminal Trace resolvers --- src/common/composite-trace-resolver.cc | 86 ++++++++++++++++++++------ src/common/composite-trace-resolver.h | 32 +++++++--- src/common/terminal-trace-resolver.h | 20 ++++-- 3 files changed, 106 insertions(+), 32 deletions(-) diff --git a/src/common/composite-trace-resolver.cc b/src/common/composite-trace-resolver.cc index e9f461959..a789a9b51 100644 --- a/src/common/composite-trace-resolver.cc +++ b/src/common/composite-trace-resolver.cc @@ -19,6 +19,9 @@ * Author: Mathieu Lacage */ #include "composite-trace-resolver.h" +#include "ns3/debug.h" + +NS_DEBUG_COMPONENT_DEFINE ("CompositeTraceResolver"); namespace ns3 { @@ -47,17 +50,39 @@ CompositeTraceResolver::DoAdd (std::string name, m_items.push_back (item); } -TraceResolver::TraceResolverList -CompositeTraceResolver::DoLookup (std::string id) const +void +CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { + NS_DEBUG ("connect path="<createResolver (), i->context)); - } - return list; + OperationOne (subpath, i, cb, context, op); + } + return; } std::string::size_type start, end; start = id.find_first_of ("(", 0); @@ -68,30 +93,29 @@ CompositeTraceResolver::DoLookup (std::string id) const { if (i->name == id) { - TraceResolver::TraceResolverList list; - list.push_back (std::make_pair (i->createResolver (), i->context)); - return list; + OperationOne (subpath, i, cb, context, op); + return; } } } std::list names; std::string alternatives = std::string (id, start+1, end-1); - std::string::size_type next, cur; - next = 0; - cur = 0; + std::string::size_type next_pos, cur_pos; + next_pos = 0; + cur_pos = 0; while (true) { std::string element; - next = alternatives.find ("|", cur); - if (next == std::string::npos) + next_pos = alternatives.find ("|", cur_pos); + if (next_pos == std::string::npos) { - element = std::string (alternatives, cur, alternatives.size ()); + element = std::string (alternatives, cur_pos, alternatives.size ()); names.push_back (element); break; } - element = std::string (alternatives, cur, next); + element = std::string (alternatives, cur_pos, next_pos); names.push_back (element); - cur = next + 1; + cur_pos = next_pos + 1; } TraceResolver::TraceResolverList list; for (std::list::const_iterator i = names.begin (); i != names.end (); i++) @@ -100,12 +124,38 @@ CompositeTraceResolver::DoLookup (std::string id) const { if (j->name == *i) { - list.push_back (std::make_pair (j->createResolver (), j->context)); + OperationOne (subpath, j, cb, context, op); break; } } } - return list; +} + +void +CompositeTraceResolver::OperationOne (std::string subpath, + TraceItems::const_iterator i, + const CallbackBase &cb, + const TraceContext &context, + enum Operation op) +{ + TraceResolver *resolver = i->createResolver (); + switch (op) { + case CONNECT: { + NS_DEBUG ("connect to path="<::TerminalTraceResolver (T &traceSource) {} template void -TerminalTraceResolver::DoConnect (CallbackBase const &cb, const TraceContext &context) +TerminalTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { - m_traceSource.AddCallback (cb, context); + if (path == "") + { + m_traceSource.AddCallback (cb, context); + } } template void -TerminalTraceResolver::DoDisconnect (CallbackBase const &cb) +TerminalTraceResolver::Disconnect (std::string path, CallbackBase const &cb) { - m_traceSource.RemoveCallback (cb); + if (path == "") + { + m_traceSource.RemoveCallback (cb); + } } }//namespace ns3 From 346cdbfb18ba07d928bb1ae066fc24dcf3823a81 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 14:25:58 +0200 Subject: [PATCH 04/92] override Connect from ArrayTraceResolver --- src/common/array-trace-resolver.h | 37 ++++++++++++++++++++------ src/common/composite-trace-resolver.cc | 18 +++---------- src/common/trace-resolver.cc | 28 +++++++++++++++++++ src/common/trace-resolver.h | 2 ++ 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index ffcc6cc89..65fe2b546 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -52,8 +52,10 @@ public: */ ArrayTraceResolver (Callback getSize, Callback get); + + virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); + virtual void Disconnect (std::string path, CallbackBase const &cb); private: - virtual TraceResolverList DoLookup (std::string id) const; Callback m_getSize; Callback m_get; }; @@ -67,22 +69,41 @@ ArrayTraceResolver::ArrayTraceResolver (Callback getSize, : m_getSize (getSize), m_get (get) {} + template -TraceResolver::TraceResolverList -ArrayTraceResolver::DoLookup (std::string id) const +void +ArrayTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { - TraceResolverList list; + std::string id = GetElement (path); + std::string subpath = GetSubpath (path); if (id == "*") { for (uint32_t i = 0; i < m_getSize (); i++) { - TraceContext context; + TraceContext tmp = context; INDEX index = i; - context.Add (index); - list.push_back (std::make_pair (m_get (i)->CreateTraceResolver (), context)); + tmp.Add (index); + TraceResolver *resolver = m_get (i)->CreateTraceResolver (); + resolver->Connect (subpath, cb, tmp); + delete resolver; + } + } +} +template +void +ArrayTraceResolver::Disconnect (std::string path, CallbackBase const &cb) +{ + std::string id = GetElement (path); + std::string subpath = GetSubpath (path); + if (id == "*") + { + for (uint32_t i = 0; i < m_getSize (); i++) + { + TraceResolver *resolver = m_get (i)->CreateTraceResolver (); + resolver->Disconnect (subpath, cb); + delete resolver; } } - return list; } diff --git a/src/common/composite-trace-resolver.cc b/src/common/composite-trace-resolver.cc index a789a9b51..ed0da7c8e 100644 --- a/src/common/composite-trace-resolver.cc +++ b/src/common/composite-trace-resolver.cc @@ -61,19 +61,8 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con const TraceContext &context, enum Operation op) { - std::string::size_type cur = 1; - // check that first char is "/" - std::string::size_type next = path.find ("/", cur); - std::string id = std::string (path, cur, next-1); - std::string subpath; - if (next != std::string::npos) - { - subpath = std::string (path, next, std::string::npos); - } - else - { - subpath = ""; - } + std::string id = GetElement (path); + std::string subpath = GetSubpath (path); if (id == "*") { @@ -150,7 +139,8 @@ CompositeTraceResolver::OperationOne (std::string subpath, resolver->Disconnect (subpath, cb); break; } - } + delete resolver; +} void CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb) diff --git a/src/common/trace-resolver.cc b/src/common/trace-resolver.cc index 75c7a576d..0b2d5124e 100644 --- a/src/common/trace-resolver.cc +++ b/src/common/trace-resolver.cc @@ -80,6 +80,34 @@ TraceResolver::Disconnect (std::string path, CallbackBase const &cb) resolverList.erase (resolverList.begin (), resolverList.end ()); } +std::string +TraceResolver::GetElement (std::string path) +{ + std::string::size_type cur = 1; + // check that first char is "/" + std::string::size_type next = path.find ("/", cur); + std::string id = std::string (path, cur, next-1); + return id; +} +std::string +TraceResolver::GetSubpath (std::string path) +{ + std::string::size_type cur = 1; + // check that first char is "/" + std::string::size_type next = path.find ("/", cur); + std::string subpath; + if (next != std::string::npos) + { + subpath = std::string (path, next, std::string::npos); + } + else + { + subpath = ""; + } + return subpath; +} + + TraceResolver::TraceResolverList TraceResolver::DoLookup (std::string id) const { diff --git a/src/common/trace-resolver.h b/src/common/trace-resolver.h index abb5cf1da..04f6b2751 100644 --- a/src/common/trace-resolver.h +++ b/src/common/trace-resolver.h @@ -71,6 +71,8 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb); protected: typedef std::list > TraceResolverList; + std::string GetElement (std::string path); + std::string GetSubpath (std::string path); private: /** * \param id the id to resolve. This is supposed to be From 493c34dfb9261daa72884bf1e3b8eea8aac7c9f6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 14:28:52 +0200 Subject: [PATCH 05/92] remove dead code --- src/common/composite-trace-resolver.cc | 2 - src/common/trace-resolver.cc | 65 +------------------------- src/common/trace-resolver.h | 27 ----------- 3 files changed, 2 insertions(+), 92 deletions(-) diff --git a/src/common/composite-trace-resolver.cc b/src/common/composite-trace-resolver.cc index ed0da7c8e..fa7157afb 100644 --- a/src/common/composite-trace-resolver.cc +++ b/src/common/composite-trace-resolver.cc @@ -66,7 +66,6 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con if (id == "*") { - TraceResolver::TraceResolverList list; for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { OperationOne (subpath, i, cb, context, op); @@ -106,7 +105,6 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con names.push_back (element); cur_pos = next_pos + 1; } - TraceResolver::TraceResolverList list; for (std::list::const_iterator i = names.begin (); i != names.end (); i++) { for (TraceItems::const_iterator j = m_items.begin (); j != m_items.end (); j++) diff --git a/src/common/trace-resolver.cc b/src/common/trace-resolver.cc index 0b2d5124e..7d2a00700 100644 --- a/src/common/trace-resolver.cc +++ b/src/common/trace-resolver.cc @@ -28,57 +28,11 @@ TraceResolver::~TraceResolver () void TraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) -{ - std::string::size_type cur = 1; - // check that first char is "/" - std::string::size_type next = path.find ("/", cur); - std::string element = std::string (path, cur, next-1); - TraceResolverList resolverList = DoLookup (element); - for (TraceResolverList::iterator i = resolverList.begin (); i != resolverList.end (); i++) - { - TraceResolver *resolver = i->first; - TraceContext tmp = context; - tmp.Add (i->second); - if (next == std::string::npos) - { - // we really break the recursion here. - resolver->DoConnect (cb, tmp); - } - else - { - std::string subpath = std::string (path, next, std::string::npos); - resolver->Connect (subpath, cb, tmp); - } - delete resolver; - } - resolverList.erase (resolverList.begin (), resolverList.end ()); -} +{} void TraceResolver::Disconnect (std::string path, CallbackBase const &cb) -{ - std::string::size_type cur = 1; - // check that first char is "/" - std::string::size_type next = path.find ("/", cur); - std::string element = std::string (path, cur, next-1); - TraceResolverList resolverList = DoLookup (element); - for (TraceResolverList::iterator i = resolverList.begin (); i != resolverList.end (); i++) - { - TraceResolver *resolver = i->first; - if (next == std::string::npos) - { - // we really break the recursion here. - resolver->DoDisconnect (cb); - } - else - { - std::string subpath = std::string (path, next, std::string::npos); - resolver->Disconnect (subpath, cb); - } - delete resolver; - } - resolverList.erase (resolverList.begin (), resolverList.end ()); -} +{} std::string TraceResolver::GetElement (std::string path) @@ -107,19 +61,4 @@ TraceResolver::GetSubpath (std::string path) return subpath; } - -TraceResolver::TraceResolverList -TraceResolver::DoLookup (std::string id) const -{ - return TraceResolverList (); -} -void -TraceResolver::DoConnect (CallbackBase const &cb, const TraceContext &context) -{} - -void -TraceResolver::DoDisconnect (CallbackBase const &cb) -{} - - }//namespace ns3 diff --git a/src/common/trace-resolver.h b/src/common/trace-resolver.h index 04f6b2751..f34827716 100644 --- a/src/common/trace-resolver.h +++ b/src/common/trace-resolver.h @@ -70,35 +70,8 @@ public: */ virtual void Disconnect (std::string path, CallbackBase const &cb); protected: - typedef std::list > TraceResolverList; std::string GetElement (std::string path); std::string GetSubpath (std::string path); -private: - /** - * \param id the id to resolve. This is supposed to be - * one element of the global tracing namespace. - * \returns a list of reslvers which match the input namespace element - * - * A subclass which overrides this method should return a potentially - * empty list of pointers to ns3::TraceResolver instances which match - * the input namespace element. Each of these TraceResolver should be - * instanciated with a TraceContext which holds enough context - * information to identify the type of the TraceResolver. - */ - virtual TraceResolverList DoLookup (std::string id) const; - /** - * \param cb callback to connect - * - * This method is invoked on leaf trace resolvers. - */ - virtual void DoConnect (CallbackBase const &cb, const TraceContext &context); - /** - * \param cb callback to disconnect - * - * This method is invoked on leaf trace resolvers. - */ - virtual void DoDisconnect (CallbackBase const &cb); - TraceContext m_context; }; }//namespace ns3 From 3153bfd916000167a73c6741d4730eee48095978 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 14:43:15 +0200 Subject: [PATCH 06/92] add refcounting to TraceResolver --- src/common/trace-resolver.cc | 19 +++++++++++++++++++ src/common/trace-resolver.h | 6 ++++++ src/core/object.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/common/trace-resolver.cc b/src/common/trace-resolver.cc index 7d2a00700..1dd6126a3 100644 --- a/src/common/trace-resolver.cc +++ b/src/common/trace-resolver.cc @@ -22,10 +22,29 @@ namespace ns3 { +TraceResolver::TraceResolver () + : m_count (1) +{} TraceResolver::~TraceResolver () {} +void +TraceResolver::Ref (void) +{ + m_count++; +} +void +TraceResolver::Unref (void) +{ + m_count--; + if (m_count == 0) + { + delete this; + } +} + + void TraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) {} diff --git a/src/common/trace-resolver.h b/src/common/trace-resolver.h index f34827716..78a3a0a4b 100644 --- a/src/common/trace-resolver.h +++ b/src/common/trace-resolver.h @@ -50,7 +50,12 @@ class CallbackBase; class TraceResolver { public: + + TraceResolver (); virtual ~TraceResolver (); + void Ref (void); + void Unref (void); + /** * \param path the namespace path to resolver * \param cb the callback to connect to the matching namespace @@ -72,6 +77,7 @@ public: protected: std::string GetElement (std::string path); std::string GetSubpath (std::string path); + uint32_t m_count; }; }//namespace ns3 diff --git a/src/core/object.h b/src/core/object.h index d45d7f67c..1b60e85e9 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -131,6 +131,7 @@ public: * on one to get the other, and vice-versa. */ void AddInterface (Ptr other); + protected: /** * \param iid an InterfaceId From 704cab010df3c7776f03f7b16f896e3f0a78c277 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 15:08:50 +0200 Subject: [PATCH 07/92] remove dead code --- .../global-route-manager-impl.cc | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index 142f613be..85ee4ee2d 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -1195,27 +1195,6 @@ GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v) namespace ns3 { -class GlobalRouterTestNode : public Node -{ -public: - GlobalRouterTestNode (); - -private: - virtual void DoAddDevice (Ptr device) const {}; - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); -}; - -GlobalRouterTestNode::GlobalRouterTestNode () -{ -// Ptr ipv4 = Create (this); -} - - TraceResolver* -GlobalRouterTestNode::DoCreateTraceResolver (TraceContext const &context) -{ - return 0; -} - class GlobalRouteManagerImplTest : public Test { public: GlobalRouteManagerImplTest (); From 6b64959309b05a6d9c92dd1ef372012b46038bee Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 15:47:00 +0200 Subject: [PATCH 08/92] avoid problems by converting back and forth between pointers and references --- src/common/terminal-trace-resolver.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/terminal-trace-resolver.h b/src/common/terminal-trace-resolver.h index 32422edb4..f35d32d86 100644 --- a/src/common/terminal-trace-resolver.h +++ b/src/common/terminal-trace-resolver.h @@ -32,12 +32,12 @@ template class TerminalTraceResolver : public TraceResolver { public: - TerminalTraceResolver (T &traceSource); + TerminalTraceResolver (T *traceSource); virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); private: - T &m_traceSource; + T *m_traceSource; }; }//namespace ns3 @@ -45,7 +45,7 @@ class TerminalTraceResolver : public TraceResolver namespace ns3 { template -TerminalTraceResolver::TerminalTraceResolver (T &traceSource) +TerminalTraceResolver::TerminalTraceResolver (T *traceSource) : m_traceSource (traceSource) {} template @@ -54,7 +54,7 @@ TerminalTraceResolver::Connect (std::string path, CallbackBase const &cb, con { if (path == "") { - m_traceSource.AddCallback (cb, context); + m_traceSource->AddCallback (cb, context); } } template @@ -63,7 +63,7 @@ TerminalTraceResolver::Disconnect (std::string path, CallbackBase const &cb) { if (path == "") { - m_traceSource.RemoveCallback (cb); + m_traceSource->RemoveCallback (cb); } } From 0b34c336f7f5e3c33b60792cb51bb7b02e3da392 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 15:47:13 +0200 Subject: [PATCH 09/92] convert TraceResolver * to Ptr --- src/common/array-trace-resolver.h | 8 +++---- src/common/composite-trace-resolver.cc | 13 ++++++------ src/common/composite-trace-resolver.h | 21 ++++++++++--------- src/common/trace-resolver.cc | 4 ++++ src/common/trace-root.cc | 10 ++++----- src/common/trace-root.h | 4 ++-- src/devices/csma-cd/csma-cd-net-device.cc | 4 ++-- src/devices/csma-cd/csma-cd-net-device.h | 2 +- .../point-to-point-net-device.cc | 5 +++-- .../point-to-point-net-device.h | 2 +- src/internet-node/arp-ipv4-interface.cc | 4 ++-- src/internet-node/arp-ipv4-interface.h | 2 +- src/internet-node/arp-l3-protocol.cc | 4 ++-- src/internet-node/arp-l3-protocol.h | 2 +- src/internet-node/ipv4-interface.cc | 3 ++- src/internet-node/ipv4-interface.h | 4 ++-- src/internet-node/ipv4-l3-protocol.cc | 10 ++++----- src/internet-node/ipv4-l3-protocol.h | 4 ++-- src/internet-node/ipv4-l4-demux.cc | 4 ++-- src/internet-node/ipv4-l4-demux.h | 2 +- src/internet-node/ipv4-l4-protocol.h | 2 +- src/internet-node/ipv4-loopback-interface.cc | 4 ++-- src/internet-node/ipv4-loopback-interface.h | 2 +- src/internet-node/udp-l4-protocol.cc | 4 ++-- src/internet-node/udp-l4-protocol.h | 2 +- src/node/net-device.cc | 3 ++- src/node/net-device.h | 4 ++-- src/node/node-list.cc | 10 ++++----- src/node/node-list.h | 2 +- src/node/node.cc | 12 +++++------ src/node/node.h | 4 ++-- src/node/queue.cc | 4 ++-- src/node/queue.h | 2 +- 33 files changed, 86 insertions(+), 81 deletions(-) diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h index 65fe2b546..b6ffe0212 100644 --- a/src/common/array-trace-resolver.h +++ b/src/common/array-trace-resolver.h @@ -48,7 +48,7 @@ public: * to provide a method named CreateTraceResolver which takes as * only argument a reference to a const TraceContext and returns * a pointer to a TraceResolver. i.e. the signature is: - * TraceResolver * (*) (TraceContext const &) + * Ptr (*) (void) */ ArrayTraceResolver (Callback getSize, Callback get); @@ -83,9 +83,8 @@ ArrayTraceResolver::Connect (std::string path, CallbackBase const &cb, TraceContext tmp = context; INDEX index = i; tmp.Add (index); - TraceResolver *resolver = m_get (i)->CreateTraceResolver (); + Ptr resolver = m_get (i)->CreateTraceResolver (); resolver->Connect (subpath, cb, tmp); - delete resolver; } } } @@ -99,9 +98,8 @@ ArrayTraceResolver::Disconnect (std::string path, CallbackBase const &c { for (uint32_t i = 0; i < m_getSize (); i++) { - TraceResolver *resolver = m_get (i)->CreateTraceResolver (); + Ptr resolver = m_get (i)->CreateTraceResolver (); resolver->Disconnect (subpath, cb); - delete resolver; } } } diff --git a/src/common/composite-trace-resolver.cc b/src/common/composite-trace-resolver.cc index fa7157afb..ee19ae960 100644 --- a/src/common/composite-trace-resolver.cc +++ b/src/common/composite-trace-resolver.cc @@ -33,14 +33,14 @@ CompositeTraceResolver::~CompositeTraceResolver () void CompositeTraceResolver::Add (std::string name, - Callback createResolver) + Callback > createResolver) { DoAdd (name, createResolver, TraceContext ()); } void CompositeTraceResolver::DoAdd (std::string name, - Callback createResolver, + Callback > createResolver, TraceContext const &context) { struct CallbackTraceSourceItem item; @@ -125,7 +125,7 @@ CompositeTraceResolver::OperationOne (std::string subpath, const TraceContext &context, enum Operation op) { - TraceResolver *resolver = i->createResolver (); + Ptr resolver = i->createResolver (); switch (op) { case CONNECT: { NS_DEBUG ("connect to path="< void Add (std::string name, - Callback createResolver, + Callback > createResolver, T const &context); /** @@ -122,7 +123,7 @@ public: * will be invoked to create the child trace resolver. */ void Add (std::string name, - Callback createResolver); + Callback > createResolver); virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); @@ -130,7 +131,7 @@ private: struct CallbackTraceSourceItem { std::string name; - Callback createResolver; + Callback > createResolver; TraceContext context; }; typedef std::list TraceItems; @@ -143,9 +144,9 @@ private: void DoAddTraceSource (std::string name, SOURCE &traceSource, CONTEXT const &context); template - static TraceResolver *CreateTerminalTraceResolver (SOURCE *trace); + static Ptr CreateTerminalTraceResolver (SOURCE *trace); void DoAdd (std::string name, - Callback createResolver, + Callback > createResolver, TraceContext const &context); void OperationOne (std::string subpath, TraceItems::const_iterator i, @@ -170,9 +171,9 @@ void CompositeTraceResolver::DoAddTraceSource (std::string name, SOURCE &traceSource, CONTEXT const &context) { - TraceResolver *(*create) (SOURCE *trace); + Ptr (*create) (SOURCE *trace); create = &CompositeTraceResolver::CreateTerminalTraceResolver; - Callback createResolver = + Callback > createResolver = MakeBoundCallback (create, &traceSource); TraceContext ctx; @@ -181,10 +182,10 @@ CompositeTraceResolver::DoAddTraceSource (std::string name, } template -TraceResolver * +Ptr CompositeTraceResolver::CreateTerminalTraceResolver (SOURCE *traceSource) { - return new TerminalTraceResolver (*traceSource); + return Create > (traceSource); } @@ -224,7 +225,7 @@ CompositeTraceResolver::Add (std::string name, template void CompositeTraceResolver::Add (std::string name, - Callback createResolver, + Callback > createResolver, T const &context) { TraceContext ctx; diff --git a/src/common/trace-resolver.cc b/src/common/trace-resolver.cc index 1dd6126a3..0bd3e0443 100644 --- a/src/common/trace-resolver.cc +++ b/src/common/trace-resolver.cc @@ -19,6 +19,9 @@ * Author: Mathieu Lacage */ #include "trace-resolver.h" +#include "ns3/debug.h" + +NS_DEBUG_COMPONENT_DEFINE ("TraceResolver"); namespace ns3 { @@ -40,6 +43,7 @@ TraceResolver::Unref (void) m_count--; if (m_count == 0) { + NS_DEBUG ("delete "< resolver = GetComposite (); resolver->Connect (path, cb, TraceContext ()); } void TraceRoot::Disconnect (std::string path, CallbackBase const &cb) { - TraceResolver *resolver = GetComposite (); + Ptr resolver = GetComposite (); resolver->Disconnect (path, cb); } void TraceRoot::Register (std::string name, - Callback createResolver) + Callback > createResolver) { - CompositeTraceResolver *resolver = GetComposite (); + Ptr resolver = GetComposite (); resolver->Add (name, createResolver); } -CompositeTraceResolver * +Ptr TraceRoot::GetComposite (void) { static CompositeTraceResolver resolver; diff --git a/src/common/trace-root.h b/src/common/trace-root.h index 270747fce..76b6a7efb 100644 --- a/src/common/trace-root.h +++ b/src/common/trace-root.h @@ -325,9 +325,9 @@ public: static void Connect (std::string path, CallbackBase const &cb); static void Disconnect (std::string path, CallbackBase const &cb); static void Register (std::string name, - Callback createResolver); + Callback > createResolver); private: - static CompositeTraceResolver *GetComposite (void); + static Ptr GetComposite (void); }; }// namespace ns3 diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index bb51fd36a..e587bb089 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -449,10 +449,10 @@ CsmaCdNetDevice::TransmitReadyEvent (void) } } -TraceResolver * +Ptr CsmaCdNetDevice::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); resolver->Add ("queue", MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma-cd/csma-cd-net-device.h index 51b3db8ea..42b85f3b5 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma-cd/csma-cd-net-device.h @@ -311,7 +311,7 @@ private: * (NOT TESTED) * @see class TraceResolver */ - virtual TraceResolver *DoCreateTraceResolver (void); + virtual Ptr DoCreateTraceResolver (void); /** * Aborts the transmission of the current packet 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 f09810f82..5275b6209 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 @@ -188,9 +188,10 @@ void PointToPointNetDevice::TransmitComplete (void) TransmitStart(p); } -TraceResolver* PointToPointNetDevice::DoCreateTraceResolver (void) +Ptr +PointToPointNetDevice::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); resolver->Add ("queue", MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); resolver->Add ("rx", 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 8d2a02fe2..3a1bc1e0e 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 @@ -243,7 +243,7 @@ private: * * @see class TraceResolver */ - virtual TraceResolver* DoCreateTraceResolver (void); + virtual Ptr DoCreateTraceResolver (void); virtual bool DoNeedsArp (void) const; /** * Enumeration of the states of the transmit machine of the net device. diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 7077d0903..3c353efe6 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -40,10 +40,10 @@ ArpIpv4Interface::ArpIpv4Interface (Ptr node, Ptr device) ArpIpv4Interface::~ArpIpv4Interface () {} -TraceResolver * +Ptr ArpIpv4Interface::DoCreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); if (GetDevice () != 0) { resolver->Add ("netdevice", diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index 537a16a2f..a31039478 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -44,7 +44,7 @@ class ArpIpv4Interface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual TraceResolver *DoCreateTraceResolver (void); + virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index 46654c89e..b116ce648 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -58,10 +58,10 @@ ArpL3Protocol::DoDispose (void) Object::DoDispose (); } -TraceResolver * +Ptr ArpL3Protocol::CreateTraceResolver (void) { - return new EmptyTraceResolver (); + return Create (); } ArpCache * diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index 3d752b46e..468c301b6 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -49,7 +49,7 @@ public: ArpL3Protocol (Ptr node); virtual ~ArpL3Protocol (); - virtual TraceResolver *CreateTraceResolver (void); + virtual Ptr CreateTraceResolver (void); /** * \brief Recieve a packet */ diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index d44edf130..699d6109d 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -22,6 +22,7 @@ #include "ipv4-interface.h" #include "ns3/ipv4-address.h" #include "ns3/net-device.h" +#include "ns3/trace-resolver.h" namespace ns3 { @@ -45,7 +46,7 @@ Ipv4Interface::GetDevice (void) const return m_netdevice; } -TraceResolver * +Ptr Ipv4Interface::CreateTraceResolver (void) { return DoCreateTraceResolver (); diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index e5c6788eb..a462d5be5 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -83,7 +83,7 @@ public: * This method will delegate the work to the private DoCreateTraceResolver * method which is supposed to be implemented by subclasses. */ - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); /** * \returns the underlying NetDevice. This method can return * zero if this interface has no associated NetDevice. @@ -153,7 +153,7 @@ public: private: virtual void SendTo (Packet p, Ipv4Address dest) = 0; - virtual TraceResolver *DoCreateTraceResolver (void) = 0; + virtual Ptr DoCreateTraceResolver (void) = 0; Ptr m_netdevice; bool m_ifup; Ipv4Address m_address; diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 9fd06abba..df97fafc0 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -153,10 +153,10 @@ Ipv4L3Protocol::SetupLoopback (void) interface->SetUp (); } -TraceResolver * +Ptr Ipv4L3Protocol::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); @@ -165,11 +165,11 @@ Ipv4L3Protocol::CreateTraceResolver (void) return resolver; } -TraceResolver * +Ptr Ipv4L3Protocol::InterfacesCreateTraceResolver (void) const { - ArrayTraceResolver *resolver = - new ArrayTraceResolver + Ptr >resolver = + Create > (MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this), MakeCallback (&Ipv4L3Protocol::GetInterface, this)); return resolver; diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index 4209019ad..f6fcec7a7 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -92,7 +92,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - virtual TraceResolver *CreateTraceResolver (void); + virtual Ptr CreateTraceResolver (void); /** * \param ttl default ttl to use @@ -189,7 +189,7 @@ private: void ForwardUp (Packet p, Ipv4Header const&ip); uint32_t AddIpv4Interface (Ipv4Interface *interface); void SetupLoopback (void); - TraceResolver *InterfacesCreateTraceResolver (void) const; + Ptr InterfacesCreateTraceResolver (void) const; typedef std::list Ipv4InterfaceList; typedef std::list< std::pair< int, Ptr > > Ipv4RoutingProtocolList; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 9981a718d..56ee9eb9a 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -78,10 +78,10 @@ Ipv4L4Demux::DoDispose (void) Object::DoDispose (); } -TraceResolver * +Ptr Ipv4L4Demux::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { Ptr protocol = *i; diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 8431e1e48..0b4755435 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -66,7 +66,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); /** * \param protocol a template for the protocol to add to this L4 Demux. * \returns the L4Protocol effectively added. diff --git a/src/internet-node/ipv4-l4-protocol.h b/src/internet-node/ipv4-l4-protocol.h index 4ecd5a142..c658318a1 100644 --- a/src/internet-node/ipv4-l4-protocol.h +++ b/src/internet-node/ipv4-l4-protocol.h @@ -59,7 +59,7 @@ public: */ int GetVersion() const; - virtual TraceResolver *CreateTraceResolver () = 0; + virtual Ptr CreateTraceResolver () = 0; /** * \param p packet to forward up diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 4e23abde3..1364e2daf 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -34,10 +34,10 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr node) Ipv4LoopbackInterface::~Ipv4LoopbackInterface () {} -TraceResolver * +Ptr Ipv4LoopbackInterface::DoCreateTraceResolver (void) { - return new EmptyTraceResolver (); + return Create (); } void diff --git a/src/internet-node/ipv4-loopback-interface.h b/src/internet-node/ipv4-loopback-interface.h index b17f46449..e9df32007 100644 --- a/src/internet-node/ipv4-loopback-interface.h +++ b/src/internet-node/ipv4-loopback-interface.h @@ -43,7 +43,7 @@ class Ipv4LoopbackInterface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual TraceResolver *DoCreateTraceResolver (void); + virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index a83cb4657..13e937d3c 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -45,10 +45,10 @@ UdpL4Protocol::UdpL4Protocol (Ptr node) UdpL4Protocol::~UdpL4Protocol () {} -TraceResolver * +Ptr UdpL4Protocol::CreateTraceResolver (void) { - return new EmptyTraceResolver (); + return Create (); } void diff --git a/src/internet-node/udp-l4-protocol.h b/src/internet-node/udp-l4-protocol.h index d41bbb839..da2cd0e2d 100644 --- a/src/internet-node/udp-l4-protocol.h +++ b/src/internet-node/udp-l4-protocol.h @@ -49,7 +49,7 @@ public: UdpL4Protocol (Ptr node); virtual ~UdpL4Protocol (); - virtual TraceResolver *CreateTraceResolver (void); + virtual Ptr CreateTraceResolver (void); /** * \return A smart Socket pointer to a UdpSocket, allocated by this instance * of the UDP protocol diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 626b82c63..cdc1f63f3 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -23,6 +23,7 @@ #include "ns3/assert.h" #include "ns3/object.h" #include "ns3/debug.h" +#include "ns3/trace-resolver.h" #include "channel.h" @@ -183,7 +184,7 @@ NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber) } } -TraceResolver * +Ptr NetDevice::CreateTraceResolver (void) { return DoCreateTraceResolver (); diff --git a/src/node/net-device.h b/src/node/net-device.h index cadd70dfc..af63be5b4 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -69,7 +69,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); /** * \return the channel this NetDevice is connected to. The value @@ -290,7 +290,7 @@ public: * * Subclasses must implement this method. */ - virtual TraceResolver *DoCreateTraceResolver (void) = 0; + virtual Ptr DoCreateTraceResolver (void) = 0; /** * \returns the channel associated to this NetDevice. * diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 761717c9f..823b92a0c 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -76,7 +76,7 @@ public: uint32_t Add (Ptr node); NodeList::Iterator Begin (void); NodeList::Iterator End (void); - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); @@ -130,11 +130,11 @@ NodeListPriv::GetNode (uint32_t n) } -TraceResolver * +Ptr NodeListPriv::CreateTraceResolver (void) { - ArrayTraceResolver, NodeListIndex> *resolver = - new ArrayTraceResolver, NodeListIndex> + Ptr, NodeListIndex> >resolver = + Create, NodeListIndex> > (MakeCallback (&NodeListPriv::GetNNodes, this), MakeCallback (&NodeListPriv::GetNode, this)); return resolver; @@ -164,7 +164,7 @@ NodeList::End (void) { return SimulationSingleton::Get ()->End (); } -TraceResolver * +Ptr NodeList::CreateTraceResolver (void) { return SimulationSingleton::Get ()->CreateTraceResolver (); diff --git a/src/node/node-list.h b/src/node/node-list.h index beda5611c..66cd6965d 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -79,7 +79,7 @@ public: * \returns the requested trace resolver. The caller * takes ownership of the returned pointer. */ - static TraceResolver *CreateTraceResolver (void); + static Ptr CreateTraceResolver (void); /** * \param n index of requested node. diff --git a/src/node/node.cc b/src/node/node.cc index 4de3a93ad..554431db1 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -82,11 +82,11 @@ Node::Construct (void) Node::~Node () {} -TraceResolver * +Ptr Node::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); - DoFillTraceResolver (*resolver); + Ptr resolver = Create (); + DoFillTraceResolver (*PeekPointer (resolver)); return resolver; } @@ -141,11 +141,11 @@ Node::GetNApplications (void) const return m_applications.size (); } -TraceResolver * +Ptr Node::CreateDevicesTraceResolver (void) { - ArrayTraceResolver,NodeNetDeviceIndex> *resolver = - new ArrayTraceResolver,NodeNetDeviceIndex> + Ptr,NodeNetDeviceIndex> >resolver = + Create,NodeNetDeviceIndex> > (MakeCallback (&Node::GetNDevices, this), MakeCallback (&Node::GetDevice, this)); diff --git a/src/node/node.h b/src/node/node.h index 104f3a2a4..7931dd001 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -92,7 +92,7 @@ public: * could be used directly by a user who needs access to very low-level * trace configuration. */ - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); /** * \returns the unique id of this node. @@ -212,7 +212,7 @@ private: bool ReceiveFromDevice (Ptr device, const Packet &packet, uint16_t protocol, const Address &from); void Construct (void); - TraceResolver *CreateDevicesTraceResolver (void); + Ptr CreateDevicesTraceResolver (void); struct ProtocolHandlerEntry { ProtocolHandler handler; diff --git a/src/node/queue.cc b/src/node/queue.cc index 163f73ffc..8a6725e4e 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -94,10 +94,10 @@ Queue::~Queue() NS_DEBUG("Queue::~Queue ()"); } -TraceResolver * +Ptr Queue::CreateTraceResolver (void) { - CompositeTraceResolver *resolver = new CompositeTraceResolver (); + Ptr resolver = Create (); resolver->Add ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); resolver->Add ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); resolver->Add ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); diff --git a/src/node/queue.h b/src/node/queue.h index 2c010c363..bf2c6a2d6 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -70,7 +70,7 @@ public: Queue (); virtual ~Queue (); - TraceResolver *CreateTraceResolver (void); + Ptr CreateTraceResolver (void); /** * \return true if the queue is empty; false otherwise From 072734f7e8107705546df35b8cd3c6a779424363 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 15:53:43 +0200 Subject: [PATCH 10/92] move trace code to core module --- src/common/wscript | 20 ------------------- src/{common => core}/array-trace-resolver.h | 0 src/{common => core}/callback-trace-source.cc | 0 src/{common => core}/callback-trace-source.h | 0 .../composite-trace-resolver.cc | 0 .../composite-trace-resolver.h | 0 src/{common => core}/empty-trace-resolver.cc | 0 src/{common => core}/empty-trace-resolver.h | 0 src/{common => core}/fv-trace-source.h | 0 src/{common => core}/stream-tracer-test.cc | 0 src/{common => core}/stream-tracer.h | 0 src/{common => core}/sv-trace-source.h | 0 .../terminal-trace-resolver.h | 0 src/{common => core}/trace-context-element.cc | 0 src/{common => core}/trace-context-element.h | 0 src/{common => core}/trace-context.cc | 0 src/{common => core}/trace-context.h | 0 src/{common => core}/trace-resolver.cc | 0 src/{common => core}/trace-resolver.h | 0 src/{common => core}/trace-root.cc | 0 src/{common => core}/trace-root.h | 0 src/{common => core}/uv-trace-source.h | 0 src/{common => core}/variable-tracer-test.cc | 0 src/core/wscript | 20 +++++++++++++++++++ 24 files changed, 20 insertions(+), 20 deletions(-) rename src/{common => core}/array-trace-resolver.h (100%) rename src/{common => core}/callback-trace-source.cc (100%) rename src/{common => core}/callback-trace-source.h (100%) rename src/{common => core}/composite-trace-resolver.cc (100%) rename src/{common => core}/composite-trace-resolver.h (100%) rename src/{common => core}/empty-trace-resolver.cc (100%) rename src/{common => core}/empty-trace-resolver.h (100%) rename src/{common => core}/fv-trace-source.h (100%) rename src/{common => core}/stream-tracer-test.cc (100%) rename src/{common => core}/stream-tracer.h (100%) rename src/{common => core}/sv-trace-source.h (100%) rename src/{common => core}/terminal-trace-resolver.h (100%) rename src/{common => core}/trace-context-element.cc (100%) rename src/{common => core}/trace-context-element.h (100%) rename src/{common => core}/trace-context.cc (100%) rename src/{common => core}/trace-context.h (100%) rename src/{common => core}/trace-resolver.cc (100%) rename src/{common => core}/trace-resolver.h (100%) rename src/{common => core}/trace-root.cc (100%) rename src/{common => core}/trace-root.h (100%) rename src/{common => core}/uv-trace-source.h (100%) rename src/{common => core}/variable-tracer-test.cc (100%) diff --git a/src/common/wscript b/src/common/wscript index c6e9cb45d..2472ecd1e 100644 --- a/src/common/wscript +++ b/src/common/wscript @@ -12,14 +12,6 @@ def build(bld): 'tags.cc', 'tag-registry.cc', 'pcap-writer.cc', - 'variable-tracer-test.cc', - 'trace-context.cc', - 'trace-context-element.cc', - 'trace-resolver.cc', - 'callback-trace-source.cc', - 'empty-trace-resolver.cc', - 'composite-trace-resolver.cc', - 'trace-root.cc', 'data-rate.cc', ] @@ -35,18 +27,6 @@ def build(bld): 'packet.h', 'packet-printer.h', 'packet-metadata.h', - 'uv-trace-source.h', - 'sv-trace-source.h', - 'fv-trace-source.h', 'pcap-writer.h', - 'callback-trace-source.h', - 'trace-context.h', - 'trace-context-element.h', - 'trace-resolver.h', - 'empty-trace-resolver.h', - 'composite-trace-resolver.h', - 'array-trace-resolver.h', - 'trace-root.h', - 'terminal-trace-resolver.h', 'data-rate.h', ] diff --git a/src/common/array-trace-resolver.h b/src/core/array-trace-resolver.h similarity index 100% rename from src/common/array-trace-resolver.h rename to src/core/array-trace-resolver.h diff --git a/src/common/callback-trace-source.cc b/src/core/callback-trace-source.cc similarity index 100% rename from src/common/callback-trace-source.cc rename to src/core/callback-trace-source.cc diff --git a/src/common/callback-trace-source.h b/src/core/callback-trace-source.h similarity index 100% rename from src/common/callback-trace-source.h rename to src/core/callback-trace-source.h diff --git a/src/common/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc similarity index 100% rename from src/common/composite-trace-resolver.cc rename to src/core/composite-trace-resolver.cc diff --git a/src/common/composite-trace-resolver.h b/src/core/composite-trace-resolver.h similarity index 100% rename from src/common/composite-trace-resolver.h rename to src/core/composite-trace-resolver.h diff --git a/src/common/empty-trace-resolver.cc b/src/core/empty-trace-resolver.cc similarity index 100% rename from src/common/empty-trace-resolver.cc rename to src/core/empty-trace-resolver.cc diff --git a/src/common/empty-trace-resolver.h b/src/core/empty-trace-resolver.h similarity index 100% rename from src/common/empty-trace-resolver.h rename to src/core/empty-trace-resolver.h diff --git a/src/common/fv-trace-source.h b/src/core/fv-trace-source.h similarity index 100% rename from src/common/fv-trace-source.h rename to src/core/fv-trace-source.h diff --git a/src/common/stream-tracer-test.cc b/src/core/stream-tracer-test.cc similarity index 100% rename from src/common/stream-tracer-test.cc rename to src/core/stream-tracer-test.cc diff --git a/src/common/stream-tracer.h b/src/core/stream-tracer.h similarity index 100% rename from src/common/stream-tracer.h rename to src/core/stream-tracer.h diff --git a/src/common/sv-trace-source.h b/src/core/sv-trace-source.h similarity index 100% rename from src/common/sv-trace-source.h rename to src/core/sv-trace-source.h diff --git a/src/common/terminal-trace-resolver.h b/src/core/terminal-trace-resolver.h similarity index 100% rename from src/common/terminal-trace-resolver.h rename to src/core/terminal-trace-resolver.h diff --git a/src/common/trace-context-element.cc b/src/core/trace-context-element.cc similarity index 100% rename from src/common/trace-context-element.cc rename to src/core/trace-context-element.cc diff --git a/src/common/trace-context-element.h b/src/core/trace-context-element.h similarity index 100% rename from src/common/trace-context-element.h rename to src/core/trace-context-element.h diff --git a/src/common/trace-context.cc b/src/core/trace-context.cc similarity index 100% rename from src/common/trace-context.cc rename to src/core/trace-context.cc diff --git a/src/common/trace-context.h b/src/core/trace-context.h similarity index 100% rename from src/common/trace-context.h rename to src/core/trace-context.h diff --git a/src/common/trace-resolver.cc b/src/core/trace-resolver.cc similarity index 100% rename from src/common/trace-resolver.cc rename to src/core/trace-resolver.cc diff --git a/src/common/trace-resolver.h b/src/core/trace-resolver.h similarity index 100% rename from src/common/trace-resolver.h rename to src/core/trace-resolver.h diff --git a/src/common/trace-root.cc b/src/core/trace-root.cc similarity index 100% rename from src/common/trace-root.cc rename to src/core/trace-root.cc diff --git a/src/common/trace-root.h b/src/core/trace-root.h similarity index 100% rename from src/common/trace-root.h rename to src/core/trace-root.h diff --git a/src/common/uv-trace-source.h b/src/core/uv-trace-source.h similarity index 100% rename from src/common/uv-trace-source.h rename to src/core/uv-trace-source.h diff --git a/src/common/variable-tracer-test.cc b/src/core/variable-tracer-test.cc similarity index 100% rename from src/common/variable-tracer-test.cc rename to src/core/variable-tracer-test.cc diff --git a/src/core/wscript b/src/core/wscript index bba53ae71..c9b13f4ac 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -42,6 +42,14 @@ def build(bld): 'type-name.cc', 'component-manager.cc', 'random-variable-default-value.cc', + 'variable-tracer-test.cc', + 'trace-context.cc', + 'trace-context-element.cc', + 'trace-resolver.cc', + 'callback-trace-source.cc', + 'empty-trace-resolver.cc', + 'composite-trace-resolver.cc', + 'trace-root.cc', ] if sys.platform == 'win32': @@ -73,5 +81,17 @@ def build(bld): 'component-manager.h', 'type-traits.h', 'random-variable-default-value.h', + 'uv-trace-source.h', + 'sv-trace-source.h', + 'fv-trace-source.h', + 'callback-trace-source.h', + 'trace-context.h', + 'trace-context-element.h', + 'trace-resolver.h', + 'empty-trace-resolver.h', + 'composite-trace-resolver.h', + 'array-trace-resolver.h', + 'trace-root.h', + 'terminal-trace-resolver.h', ] From 3691c3cc982c53e67e9dc349da967235817e1eaf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 15:57:33 +0200 Subject: [PATCH 11/92] fix includes --- src/core/array-trace-resolver.h | 2 +- src/core/callback-trace-source.cc | 2 +- src/core/callback-trace-source.h | 4 ++-- src/core/composite-trace-resolver.cc | 4 ++-- src/core/composite-trace-resolver.h | 4 ++-- src/core/random-variable-default-value.cc | 2 +- src/core/stream-tracer-test.cc | 2 +- src/core/sv-trace-source.h | 2 +- src/core/terminal-trace-resolver.h | 2 +- src/core/trace-context.cc | 4 ++-- src/core/trace-context.h | 2 +- src/core/trace-resolver.cc | 2 +- src/core/trace-root.cc | 4 ++-- src/core/trace-root.h | 2 +- src/core/uid-manager.cc | 4 ++-- src/core/uv-trace-source.h | 2 +- src/core/variable-tracer-test.cc | 4 ++-- 17 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index b6ffe0212..547ff0009 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -23,7 +23,7 @@ #include #include -#include "ns3/callback.h" +#include "callback.h" #include "trace-resolver.h" namespace ns3 { diff --git a/src/core/callback-trace-source.cc b/src/core/callback-trace-source.cc index d35b4f860..7bcb41fe0 100644 --- a/src/core/callback-trace-source.cc +++ b/src/core/callback-trace-source.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "callback-trace-source.h" -#include "ns3/test.h" +#include "test.h" namespace ns3 { diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index a1e13df9d..6282467f9 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -23,8 +23,8 @@ #define CALLBACK_TRACE_H #include -#include "ns3/callback.h" -#include "ns3/fatal-error.h" +#include "callback.h" +#include "fatal-error.h" #include "trace-context.h" namespace ns3 { diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index ee19ae960..83d63c29b 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "composite-trace-resolver.h" -#include "ns3/debug.h" +#include "debug.h" NS_DEBUG_COMPONENT_DEFINE ("CompositeTraceResolver"); @@ -149,7 +149,7 @@ CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb) #ifdef RUN_SELF_TESTS -#include "ns3/test.h" +#include "test.h" #include "trace-context-element.h" namespace ns3 { diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 7f87c708c..d33c4cc5c 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -21,8 +21,8 @@ #ifndef COMPOSITE_TRACE_RESOLVER_H #define COMPOSITE_TRACE_RESOLVER_H -#include "ns3/callback.h" -#include "ns3/ptr.h" +#include "callback.h" +#include "ptr.h" #include "trace-resolver.h" #include "callback-trace-source.h" #include "uv-trace-source.h" diff --git a/src/core/random-variable-default-value.cc b/src/core/random-variable-default-value.cc index 3217c3513..14fdfa5a3 100644 --- a/src/core/random-variable-default-value.cc +++ b/src/core/random-variable-default-value.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "random-variable-default-value.h" -#include "ns3/debug.h" +#include "debug.h" NS_DEBUG_COMPONENT_DEFINE ("RandomVariableDefaultValue"); diff --git a/src/core/stream-tracer-test.cc b/src/core/stream-tracer-test.cc index f38e80dc4..f708015b6 100644 --- a/src/core/stream-tracer-test.cc +++ b/src/core/stream-tracer-test.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "stream-tracer.h" -#include "ns3/test.h" +#include "test.h" #include #ifdef RUN_SELF_TESTS diff --git a/src/core/sv-trace-source.h b/src/core/sv-trace-source.h index ce5511705..291bc764e 100644 --- a/src/core/sv-trace-source.h +++ b/src/core/sv-trace-source.h @@ -74,7 +74,7 @@ class UVTraceSource; * ns3::UVTraceSource : \code #include - #include "ns3/sv-trace-source.h" + #include "sv-trace-source.h" ns3::SVTraceSource var; \endcode diff --git a/src/core/terminal-trace-resolver.h b/src/core/terminal-trace-resolver.h index f35d32d86..42ee7fc2d 100644 --- a/src/core/terminal-trace-resolver.h +++ b/src/core/terminal-trace-resolver.h @@ -22,7 +22,7 @@ #define TERMINAL_TRACE_RESOLVER_H #include "trace-resolver.h" -#include "ns3/assert.h" +#include "assert.h" namespace ns3 { diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index 50e9d0a73..3082f50b5 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -20,7 +20,7 @@ */ #include "trace-context.h" #include "trace-context-element.h" -#include "ns3/assert.h" +#include "assert.h" namespace ns3 { @@ -233,7 +233,7 @@ TraceContext::Print (std::ostream &os) const }//namespace ns3 -#include "ns3/test.h" +#include "test.h" #include namespace ns3 { diff --git a/src/core/trace-context.h b/src/core/trace-context.h index eee3c960c..d33ee2fda 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -23,7 +23,7 @@ #include #include -#include "ns3/fatal-error.h" +#include "fatal-error.h" #include "trace-context-element.h" namespace ns3 { diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 0bd3e0443..b92bc785f 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "trace-resolver.h" -#include "ns3/debug.h" +#include "debug.h" NS_DEBUG_COMPONENT_DEFINE ("TraceResolver"); diff --git a/src/core/trace-root.cc b/src/core/trace-root.cc index 826cc419b..9de21a127 100644 --- a/src/core/trace-root.cc +++ b/src/core/trace-root.cc @@ -19,8 +19,8 @@ * Author: Mathieu Lacage */ #include "trace-root.h" -#include "ns3/composite-trace-resolver.h" -#include "ns3/trace-context.h" +#include "composite-trace-resolver.h" +#include "trace-context.h" namespace ns3 { diff --git a/src/core/trace-root.h b/src/core/trace-root.h index 76b6a7efb..eb3ddc2ea 100644 --- a/src/core/trace-root.h +++ b/src/core/trace-root.h @@ -22,7 +22,7 @@ #define TRACE_ROOT_H #include -#include "ns3/callback.h" +#include "callback.h" /** * \defgroup lowleveltracing Low-level tracing diff --git a/src/core/uid-manager.cc b/src/core/uid-manager.cc index f6aa3f6de..364ab769c 100644 --- a/src/core/uid-manager.cc +++ b/src/core/uid-manager.cc @@ -19,8 +19,8 @@ * Author: Mathieu Lacage */ #include "uid-manager.h" -#include "ns3/fatal-error.h" -#include "ns3/assert.h" +#include "fatal-error.h" +#include "assert.h" namespace ns3 { diff --git a/src/core/uv-trace-source.h b/src/core/uv-trace-source.h index b83873580..0bdfb3f94 100644 --- a/src/core/uv-trace-source.h +++ b/src/core/uv-trace-source.h @@ -78,7 +78,7 @@ class SVTraceSource; * ns3::UVTraceSource : \code #include - #include "ns3/uv-trace-source.h" + #include "uv-trace-source.h" ns3::UVTraceSource var; \endcode diff --git a/src/core/variable-tracer-test.cc b/src/core/variable-tracer-test.cc index 29f3fc148..bd996e739 100644 --- a/src/core/variable-tracer-test.cc +++ b/src/core/variable-tracer-test.cc @@ -22,8 +22,8 @@ #include "uv-trace-source.h" #include "sv-trace-source.h" #include "trace-context.h" -#include "ns3/test.h" -#include "ns3/callback.h" +#include "test.h" +#include "callback.h" namespace ns3 { From 1124cf3a03bcf7d7a89cc6815be6703c3793accf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 10 Aug 2007 16:05:20 +0200 Subject: [PATCH 12/92] add Object::TraceConnect, TraceDisconnect, and GetTraceResolver methods --- src/core/object.cc | 19 +++++++++++++++++++ src/core/object.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/object.cc b/src/core/object.cc index 9b4812c42..8e2ada60a 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -22,6 +22,7 @@ #include "assert.h" #include "singleton.h" #include "uid-manager.h" +#include "empty-trace-resolver.h" #include namespace { @@ -163,6 +164,18 @@ Object::AddInterface (Ptr o) NS_ASSERT (o->Check ()); } +void +Object::TraceConnect (std::string path, const CallbackBase &cb) +{ + GetTraceResolver ()->Connect (path, cb, TraceContext ()); +} +void +Object::TraceDisconnect (std::string path, const CallbackBase &cb) +{ + GetTraceResolver ()->Disconnect (path, cb); +} + + void Object::SetInterfaceId (InterfaceId iid) { @@ -176,6 +189,12 @@ Object::DoDispose (void) NS_ASSERT (!m_disposed); } +Ptr +Object::GetTraceResolver (void) const +{ + return Create (); +} + bool Object::Check (void) const { diff --git a/src/core/object.h b/src/core/object.h index 1b60e85e9..355d196ee 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -27,6 +27,9 @@ namespace ns3 { +class TraceResolver; +class CallbackBase; + /** * \brief a unique identifier for an interface. * @@ -132,6 +135,9 @@ public: */ void AddInterface (Ptr other); + + void TraceConnect (std::string path, const CallbackBase &cb); + void TraceDisconnect (std::string path, const CallbackBase &cb); protected: /** * \param iid an InterfaceId @@ -147,6 +153,8 @@ protected: * up to their parent's implementation once they are done. */ virtual void DoDispose (void); + + virtual Ptr GetTraceResolver (void) const; private: Ptr DoQueryInterface (InterfaceId iid) const; bool Check (void) const; From c62cf3c82d0d0a1f94a2eae0dffbecc84af6e5ae Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 16:25:19 +0200 Subject: [PATCH 13/92] rewrite the ArrayTraceResolver to use iterators --- src/core/array-trace-resolver.h | 169 +++++++++++++++++++++----------- 1 file changed, 114 insertions(+), 55 deletions(-) diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index 547ff0009..3ba7147c5 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -25,85 +25,144 @@ #include #include "callback.h" #include "trace-resolver.h" +#include "object.h" namespace ns3 { /** * \brief a helper class to offer trace resolution for an array of objects. * \ingroup lowleveltracing + * + * \class ArrayTraceResolver + * + * An ArrayTraceResolver is a resolver which can match any input integer + * against an element in an array. The array is accessed using a + * pair iterators. Each element of the array is expected + * to be a subclass of the Object base class. + * + * When the Connect method is called, this trace resolver will + * automatically store in the TraceContext of each resolved object + * its index through an object of type INDEX specified during the + * instanciation of the ArrayTraceResolver template. */ -template +template class ArrayTraceResolver : public TraceResolver { public: - /** - * \param getSize callback which returns dynamically the size of underlying array - * \param get callback which returns any element in the underlying array - * - * Construct a trace resolver which can match any input integer - * against an element in an array. The array is accessed using a - * pair of callbacks. It is the responsability of the user to - * provide two such callbacks whose job is to adapt the array - * API to the resolver needs. Each element of the array is expected - * to provide a method named CreateTraceResolver which takes as - * only argument a reference to a const TraceContext and returns - * a pointer to a TraceResolver. i.e. the signature is: - * Ptr (*) (void) - */ - ArrayTraceResolver (Callback getSize, - Callback get); + ArrayTraceResolver (); + ~ArrayTraceResolver (); + /** + * \param begin an iterator which points to the start of the array. + * \param end an iterator which points to the end of the array. + */ + template + void SetIterators (T begin, T end); + + // inherited from TraceResolver virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); + private: - Callback m_getSize; - Callback m_get; + class IteratorBase + { + public: + virtual ~IteratorBase () {} + virtual void Next (void) = 0; + virtual bool HasNext (void) = 0; + virtual Ptr Get (void) = 0; + virtual void Rewind (void) = 0; + }; + IteratorBase *m_iter; }; }//namespace ns3 + +// implementation namespace ns3 { -template -ArrayTraceResolver::ArrayTraceResolver (Callback getSize, - Callback get) - : m_getSize (getSize), - m_get (get) +template +ArrayTraceResolver::ArrayTraceResolver () + : m_iter (0) {} -template -void -ArrayTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) +template +ArrayTraceResolver::~ArrayTraceResolver () { - std::string id = GetElement (path); - std::string subpath = GetSubpath (path); - if (id == "*") - { - for (uint32_t i = 0; i < m_getSize (); i++) - { - TraceContext tmp = context; - INDEX index = i; - tmp.Add (index); - Ptr resolver = m_get (i)->CreateTraceResolver (); - resolver->Connect (subpath, cb, tmp); - } - } -} -template -void -ArrayTraceResolver::Disconnect (std::string path, CallbackBase const &cb) -{ - std::string id = GetElement (path); - std::string subpath = GetSubpath (path); - if (id == "*") - { - for (uint32_t i = 0; i < m_getSize (); i++) - { - Ptr resolver = m_get (i)->CreateTraceResolver (); - resolver->Disconnect (subpath, cb); - } - } + delete m_iter; } +template +template +void +ArrayTraceResolver::SetIterators (T begin, T end) +{ + class Iterator : public IteratorBase + { + public: + Iterator (T begin, T end) + : m_begin (begin), m_end (end), m_cur (begin) + {} + virtual void Next (void) + {m_cur++;} + virtual bool HasNext (void) + {return m_cur != m_end;} + virtual Ptr Get (void) + {return *m_cur;} + virtual void Rewind (void) + {m_cur = m_begin;} + private: + T m_begin; + T m_end; + T m_cur; + }; + delete m_iter; + m_iter = new Iterator (begin, end); +} + +template +void +ArrayTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) +{ + if (path == "") + { + return; + } + std::string id = GetElement (path); + std::string subpath = GetSubpath (path); + if (id == "*") + { + uint32_t j = 0; + for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ()) + { + TraceContext tmp = context; + INDEX index = j; + tmp.Add (index); + Ptr obj = m_iter->Get (); + obj->TraceConnect (subpath, cb, tmp); + j++; + } + } +} +template +void +ArrayTraceResolver::Disconnect (std::string path, CallbackBase const &cb) +{ + if (path == "") + { + return; + } + std::string id = GetElement (path); + std::string subpath = GetSubpath (path); + if (id == "*") + { + for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ()) + { + Ptr obj = m_iter->Get (); + obj->TraceDisconnect (subpath, cb); + } + } +} }//namespace ns3 From 2db3a828d67dea4c7f1c40408d3e09ee1df4a336 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 16:26:25 +0200 Subject: [PATCH 14/92] rewrite the CompositeTraceResolver to use a simpler implementation, not based on callbacks --- src/core/composite-trace-resolver.cc | 116 +++++++++++++---- src/core/composite-trace-resolver.h | 184 +++++++++++++++++---------- 2 files changed, 208 insertions(+), 92 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 83d63c29b..72a768e91 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -29,25 +29,68 @@ CompositeTraceResolver::CompositeTraceResolver () {} CompositeTraceResolver::~CompositeTraceResolver () -{} +{ + for (TraceItems::iterator i = m_items.begin (); i != m_items.end (); i++) + { + delete *i; + } + m_items.clear (); +} + +void +CompositeTraceResolver::AddItem (CompositeItem *item) +{ + m_items.push_back (item); +} void CompositeTraceResolver::Add (std::string name, Callback > createResolver) { - DoAdd (name, createResolver, TraceContext ()); + class MakerCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {maker ()->Connect (subpath, cb, context);} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {maker ()->Disconnect (subpath, cb);} + + Callback > maker; + } *item = new MakerCompositeItem (); + item->name = name; + item->context = TraceContext (); + item->maker = createResolver; + AddItem (item); } void -CompositeTraceResolver::DoAdd (std::string name, - Callback > createResolver, - TraceContext const &context) +CompositeTraceResolver::AddChild (std::string name, Ptr child) { - struct CallbackTraceSourceItem item; - item.name = name; - item.createResolver = createResolver; - item.context = context; - m_items.push_back (item); + DoAddChild (name, child, TraceContext ()); +} +void +CompositeTraceResolver::DoAddChild (std::string name, Ptr child, const TraceContext &context) +{ + class ChildCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {child->TraceConnect (subpath, cb, context);} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {child->TraceDisconnect (subpath, cb);} + + Ptr child; + } *item = new ChildCompositeItem (); + item->name = name; + item->context = context; + item->child = child; + AddItem (item); +} + +void +CompositeTraceResolver::SetParent (Ptr resolver) +{ + m_parent = resolver; } void @@ -57,10 +100,15 @@ CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const DoRecursiveOperation (path, cb, context, CONNECT); } void -CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase const &cb, +CompositeTraceResolver::DoRecursiveOperation (std::string path, + const CallbackBase &cb, const TraceContext &context, enum Operation op) { + if (path == "") + { + return; + } std::string id = GetElement (path); std::string subpath = GetSubpath (path); @@ -70,6 +118,7 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con { OperationOne (subpath, i, cb, context, op); } + DoRecursiveOperationForParent (path, cb, context, op); return; } std::string::size_type start, end; @@ -79,9 +128,10 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con { for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { - if (i->name == id) + if ((*i)->name == id) { OperationOne (subpath, i, cb, context, op); + DoRecursiveOperationForParent (path, cb, context, op); return; } } @@ -109,13 +159,34 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, CallbackBase con { for (TraceItems::const_iterator j = m_items.begin (); j != m_items.end (); j++) { - if (j->name == *i) + if ((*j)->name == *i) { OperationOne (subpath, j, cb, context, op); break; } } } + DoRecursiveOperationForParent (path, cb, context, op); +} + +void +CompositeTraceResolver::DoRecursiveOperationForParent (std::string path, + const CallbackBase &cb, + const TraceContext &context, + enum Operation op) +{ + if (m_parent == 0) + { + return; + } + switch (op) { + case CONNECT: + m_parent->Connect (path, cb, context); + break; + case DISCONNECT: + m_parent->Disconnect (path, cb); + break; + } } void @@ -125,16 +196,15 @@ CompositeTraceResolver::OperationOne (std::string subpath, const TraceContext &context, enum Operation op) { - Ptr resolver = i->createResolver (); switch (op) { case CONNECT: { - NS_DEBUG ("connect to path="< #include "callback.h" #include "ptr.h" #include "trace-resolver.h" @@ -28,7 +29,7 @@ #include "uv-trace-source.h" #include "sv-trace-source.h" #include "fv-trace-source.h" -#include "terminal-trace-resolver.h" +#include "array-trace-resolver.h" namespace ns3 { @@ -95,24 +96,6 @@ public: template void Add (std::string name, FVTraceSource &trace, T const &context); - - /** - * \param name name of child trace resolver - * \param createResolver a trace resolver constructor - * \param context the context associated to this entry - * - * Add a child trace resolver to this resolver. This child - * trace resolver will match the name specified during - * namespace resolution. When this happens, the constructor - * will be invoked to create the child trace resolver and - * the associated TraceContext will be automatically extended - * to contain the input context. - */ - template - void Add (std::string name, - Callback > createResolver, - T const &context); - /** * \param name name of child trace resolver * \param createResolver a trace resolver constructor @@ -124,71 +107,63 @@ public: */ void Add (std::string name, Callback > createResolver); + + void AddChild (std::string name, Ptr child); + + template + void AddChild (std::string name, Ptr child, const T &contextElement); + + template + void AddArray (std::string name, + ITERATOR begin, ITERATOR end, INDEX index); + + + void SetParent (Ptr parent); + virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); private: - struct CallbackTraceSourceItem + class CompositeItem { + public: + virtual ~CompositeItem () {} + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) = 0; + virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0; + std::string name; - Callback > createResolver; TraceContext context; }; - typedef std::list TraceItems; + typedef std::vector TraceItems; enum Operation { CONNECT, DISCONNECT }; - template - void DoAddTraceSource (std::string name, - SOURCE &traceSource, CONTEXT const &context); - template - static Ptr CreateTerminalTraceResolver (SOURCE *trace); - void DoAdd (std::string name, - Callback > createResolver, - TraceContext const &context); + void AddItem (CompositeItem *item); void OperationOne (std::string subpath, TraceItems::const_iterator i, const CallbackBase &cb, const TraceContext &context, enum Operation op); - void DoRecursiveOperation (std::string path, CallbackBase const &cb, + void DoRecursiveOperation (std::string path, + const CallbackBase &cb, const TraceContext &context, enum Operation op); + void DoRecursiveOperationForParent (std::string path, + const CallbackBase &cb, + const TraceContext &context, + enum Operation op); + void DoAddChild (std::string name, Ptr child, const TraceContext &context); - - - TraceItems m_items; + CompositeTraceResolver::TraceItems m_items; + Ptr m_parent; }; }//namespace ns3 namespace ns3 { -template -void -CompositeTraceResolver::DoAddTraceSource (std::string name, - SOURCE &traceSource, CONTEXT const &context) -{ - Ptr (*create) (SOURCE *trace); - create = &CompositeTraceResolver::CreateTerminalTraceResolver; - Callback > createResolver = - MakeBoundCallback (create, &traceSource); - - TraceContext ctx; - ctx.Add (context); - DoAdd (name, createResolver, ctx); -} - -template -Ptr -CompositeTraceResolver::CreateTerminalTraceResolver (SOURCE *traceSource) -{ - return Create > (traceSource); -} - - template &trace, T const &context) { - DoAddTraceSource (name, trace, context); + class CallbackCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + CallbackTraceSource *trace; + } *item = new CallbackCompositeItem (); + item->name = name; + item->context.Add (context); + item->trace = &trace; + AddItem (item); } template void CompositeTraceResolver::Add (std::string name, SVTraceSource &trace, T const &context) { - DoAddTraceSource (name, trace, context); + class SVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + SVTraceSource *trace; + } *item = new SVCompositeItem (); + item->name = name; + item->context.Add (context); + item->trace = &trace; + AddItem (item); } template void CompositeTraceResolver::Add (std::string name, UVTraceSource &trace, T const &context) { - DoAddTraceSource (name, trace, context); + class UVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + UVTraceSource *trace; + } *item = new UVCompositeItem (); + item->name = name; + item->context.Add (context); + item->trace = &trace; + AddItem (item); } template void CompositeTraceResolver::Add (std::string name, FVTraceSource &trace, T const &context) { - DoAddTraceSource (name, trace, context); + class FVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + FVTraceSource *trace; + } *item = new FVCompositeItem (); + item->name = name; + item->context.Add (context); + item->trace = &trace; + AddItem (item); } + +template +void +CompositeTraceResolver::AddArray (std::string name, + ITERATOR begin, ITERATOR end, INDEX index) +{ + class ArrayCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {array->Connect (subpath, cb, context);} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {array->Disconnect (subpath, cb);} + + Ptr > array; + } *item = new ArrayCompositeItem (); + item->name = name; + item->context = TraceContext (); + item->array = Create > (); + item->array->SetIterators (begin, end); + AddItem (item); +} + template void -CompositeTraceResolver::Add (std::string name, - Callback > createResolver, - T const &context) +CompositeTraceResolver::AddChild (std::string name, Ptr child, const T &contextElement) { - TraceContext ctx; - ctx.Add (context); - DoAdd (name, createResolver, ctx); + TraceContext context; + context.Add (contextElement); + DoAddChild (name, child, context); } + + }//namespace ns3 #endif /* COMPOSITE_TRACE_RESOLVER_H */ From 6e762c1ae3202c8d51f8c2f83ee9eaea428f0c39 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 16:26:53 +0200 Subject: [PATCH 15/92] the TerminalTraceResolver is not used anymore by the CompositeTraceResolver implementation --- src/core/terminal-trace-resolver.h | 72 ------------------------------ src/core/wscript | 1 - 2 files changed, 73 deletions(-) delete mode 100644 src/core/terminal-trace-resolver.h diff --git a/src/core/terminal-trace-resolver.h b/src/core/terminal-trace-resolver.h deleted file mode 100644 index 42ee7fc2d..000000000 --- a/src/core/terminal-trace-resolver.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 TERMINAL_TRACE_RESOLVER_H -#define TERMINAL_TRACE_RESOLVER_H - -#include "trace-resolver.h" -#include "assert.h" - -namespace ns3 { - -class TraceContext; - -template -class TerminalTraceResolver : public TraceResolver -{ - public: - TerminalTraceResolver (T *traceSource); - - virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); - virtual void Disconnect (std::string path, CallbackBase const &cb); - private: - T *m_traceSource; -}; - -}//namespace ns3 - -namespace ns3 { - -template -TerminalTraceResolver::TerminalTraceResolver (T *traceSource) - : m_traceSource (traceSource) -{} -template -void -TerminalTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) -{ - if (path == "") - { - m_traceSource->AddCallback (cb, context); - } -} -template -void -TerminalTraceResolver::Disconnect (std::string path, CallbackBase const &cb) -{ - if (path == "") - { - m_traceSource->RemoveCallback (cb); - } -} - -}//namespace ns3 - -#endif /* TERMINAL_TRACE_RESOLVER_H */ diff --git a/src/core/wscript b/src/core/wscript index c9b13f4ac..7a9e8171a 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -92,6 +92,5 @@ def build(bld): 'composite-trace-resolver.h', 'array-trace-resolver.h', 'trace-root.h', - 'terminal-trace-resolver.h', ] From 2df1260c871fe1268d5bbc5c684b527f9ca9d82b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 16:27:42 +0200 Subject: [PATCH 16/92] remove const keyword and add a TraceConnect method which takes a TraceContext argument --- src/core/object.cc | 9 +++++++-- src/core/object.h | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index 8e2ada60a..440bd0f31 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -167,7 +167,12 @@ Object::AddInterface (Ptr o) void Object::TraceConnect (std::string path, const CallbackBase &cb) { - GetTraceResolver ()->Connect (path, cb, TraceContext ()); + TraceConnect (path, cb, TraceContext ()); +} +void +Object::TraceConnect (std::string path, const CallbackBase &cb, const TraceContext &context) +{ + GetTraceResolver ()->Connect (path, cb, context); } void Object::TraceDisconnect (std::string path, const CallbackBase &cb) @@ -190,7 +195,7 @@ Object::DoDispose (void) } Ptr -Object::GetTraceResolver (void) const +Object::GetTraceResolver (void) { return Create (); } diff --git a/src/core/object.h b/src/core/object.h index 355d196ee..1b0825381 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -28,6 +28,7 @@ namespace ns3 { class TraceResolver; +class TraceContext; class CallbackBase; /** @@ -137,6 +138,7 @@ public: void TraceConnect (std::string path, const CallbackBase &cb); + void TraceConnect (std::string path, const CallbackBase &cb, const TraceContext &context); void TraceDisconnect (std::string path, const CallbackBase &cb); protected: /** @@ -154,7 +156,7 @@ protected: */ virtual void DoDispose (void); - virtual Ptr GetTraceResolver (void) const; + virtual Ptr GetTraceResolver (void); private: Ptr DoQueryInterface (InterfaceId iid) const; bool Check (void) const; From ec4d9bbcb9460d2a464a8df0c0c974822efda31c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 16:28:29 +0200 Subject: [PATCH 17/92] use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code --- src/devices/csma-cd/csma-cd-net-device.cc | 9 ++- src/devices/csma-cd/csma-cd-net-device.h | 13 ++-- .../point-to-point-net-device.cc | 6 +- .../point-to-point-net-device.h | 12 ++-- src/internet-node/arp-cache.cc | 6 +- src/internet-node/arp-cache.h | 6 +- src/internet-node/arp-ipv4-interface.cc | 7 +- src/internet-node/arp-ipv4-interface.h | 5 +- src/internet-node/arp-l3-protocol.cc | 8 +-- src/internet-node/arp-l3-protocol.h | 2 - src/internet-node/internet-node.cc | 11 ++-- src/internet-node/internet-node.h | 2 +- src/internet-node/ipv4-interface.cc | 13 ++-- src/internet-node/ipv4-interface.h | 21 ++---- src/internet-node/ipv4-l3-protocol.cc | 66 ++++++++----------- src/internet-node/ipv4-l3-protocol.h | 25 +++---- src/internet-node/ipv4-l4-demux.cc | 7 +- src/internet-node/ipv4-l4-demux.h | 12 +--- src/internet-node/ipv4-l4-protocol.h | 6 -- src/internet-node/ipv4-loopback-interface.cc | 7 -- src/internet-node/ipv4-loopback-interface.h | 1 - src/internet-node/udp-l4-protocol.cc | 6 -- src/internet-node/udp-l4-protocol.h | 1 - src/node/net-device.cc | 6 -- src/node/net-device.h | 17 ----- src/node/node-list.cc | 17 +++-- src/node/node-list.h | 2 +- src/node/node.cc | 24 +------ src/node/node.h | 23 +------ src/node/queue.cc | 3 +- src/node/queue.h | 3 +- 31 files changed, 109 insertions(+), 238 deletions(-) diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index e587bb089..fe5c0ba26 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -450,19 +450,18 @@ CsmaCdNetDevice::TransmitReadyEvent (void) } Ptr -CsmaCdNetDevice::DoCreateTraceResolver (void) +CsmaCdNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, - PeekPointer (m_queue))); + resolver->AddChild ("queue", m_queue); resolver->Add ("rx", m_rxTrace, CsmaCdTraceType (CsmaCdTraceType::RX)); resolver->Add ("drop", m_dropTrace, CsmaCdTraceType (CsmaCdTraceType::DROP)); - return resolver; + resolver->SetParent (NetDevice::GetTraceResolver ()); + return resolver; } bool diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma-cd/csma-cd-net-device.h index 42b85f3b5..5de056109 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma-cd/csma-cd-net-device.h @@ -191,6 +191,13 @@ enum CsmaCdEncapsulationMode { protected: virtual bool DoNeedsArp (void) const; virtual void DoDispose (void); + /** + * Create a Trace Resolver for events in the net device. + * (NOT TESTED) + * @see class TraceResolver + */ + virtual Ptr GetTraceResolver (void); + /** * Get a copy of the attached Queue. * @@ -306,12 +313,6 @@ private: * @see TransmitStart () */ void TransmitReadyEvent (void); - /** - * Create a Trace Resolver for events in the net device. - * (NOT TESTED) - * @see class TraceResolver - */ - virtual Ptr DoCreateTraceResolver (void); /** * Aborts the transmission of the current packet 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 5275b6209..633fbe5c6 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 @@ -189,14 +189,14 @@ void PointToPointNetDevice::TransmitComplete (void) } Ptr -PointToPointNetDevice::DoCreateTraceResolver (void) +PointToPointNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue))); + resolver->AddChild ("queue", m_queue); resolver->Add ("rx", m_rxTrace, PointToPointTraceType ()); + resolver->SetParent (NetDevice::GetTraceResolver ()); return resolver; } 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 3a1bc1e0e..5cee2cf70 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 @@ -152,6 +152,12 @@ public: */ void Receive (Packet& p); protected: + /** + * Create a Trace Resolver for events in the net device. + * + * @see class TraceResolver + */ + virtual Ptr GetTraceResolver (void); virtual void DoDispose (void); /** * Get a copy of the attached Queue. @@ -238,12 +244,6 @@ private: * */ void TransmitComplete(void); - /** - * Create a Trace Resolver for events in the net device. - * - * @see class TraceResolver - */ - virtual Ptr DoCreateTraceResolver (void); virtual bool DoNeedsArp (void) const; /** * Enumeration of the states of the transmit machine of the net device. diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index b4987daef..15a1d9316 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -19,16 +19,16 @@ * Author: Mathieu Lacage */ #include "ns3/assert.h" - #include "ns3/packet.h" #include "ns3/simulator.h" #include "arp-cache.h" #include "arp-header.h" +#include "ipv4-interface.h" namespace ns3 { -ArpCache::ArpCache (Ptr device, Ipv4Interface *interface) +ArpCache::ArpCache (Ptr device, Ptr interface) : m_device (device), m_interface (interface), m_aliveTimeout (Seconds (120)), @@ -47,7 +47,7 @@ ArpCache::GetDevice (void) const return m_device; } -Ipv4Interface * +Ptr ArpCache::GetInterface (void) const { return m_interface; diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 2cd88c85f..adf106009 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -48,7 +48,7 @@ public: * \param device The hardware NetDevice associated with this ARP chache * \param interface the Ipv4Interface associated with this ARP chache */ - ArpCache (Ptr device, Ipv4Interface *interface); + ArpCache (Ptr device, Ptr interface); ~ArpCache (); /** * \return The NetDevice that this ARP cache is associated with @@ -57,7 +57,7 @@ public: /** * \return the Ipv4Interface that this ARP cache is associated with */ - Ipv4Interface *GetInterface (void) const; + Ptr GetInterface (void) const; void SetAliveTimeout (Time aliveTimeout); void SetDeadTimeout (Time deadTimeout); @@ -152,7 +152,7 @@ private: typedef sgi::hash_map::iterator CacheI; Ptr m_device; - Ipv4Interface *m_interface; + Ptr m_interface; Time m_aliveTimeout; Time m_deadTimeout; Time m_waitReplyTimeout; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 3c353efe6..2648c5ec4 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -41,15 +41,14 @@ ArpIpv4Interface::~ArpIpv4Interface () {} Ptr -ArpIpv4Interface::DoCreateTraceResolver (void) +ArpIpv4Interface::GetTraceResolver (void) { Ptr resolver = Create (); if (GetDevice () != 0) { - resolver->Add ("netdevice", - MakeCallback (&NetDevice::CreateTraceResolver, PeekPointer (GetDevice ()))); + resolver->AddChild ("netdevice", GetDevice ()); } - + resolver->SetParent (Ipv4Interface::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index a31039478..73bf4f462 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -42,9 +42,10 @@ class ArpIpv4Interface : public Ipv4Interface ArpIpv4Interface (Ptr node, Ptr device); virtual ~ArpIpv4Interface (); - private: +protected: + virtual Ptr GetTraceResolver (void); +private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index b116ce648..b4d346e60 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -58,12 +58,6 @@ ArpL3Protocol::DoDispose (void) Object::DoDispose (); } -Ptr -ArpL3Protocol::CreateTraceResolver (void) -{ - return Create (); -} - ArpCache * ArpL3Protocol::FindCache (Ptr device) { @@ -75,7 +69,7 @@ ArpL3Protocol::FindCache (Ptr device) } } Ptr ipv4 = m_node->QueryInterface (Ipv4L3Protocol::iid); - Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device); + Ptr interface = ipv4->FindInterfaceForDevice (device); ArpCache * cache = new ArpCache (device, interface); NS_ASSERT (device->IsBroadcast ()); device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index 468c301b6..5f6819df6 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -48,8 +48,6 @@ public: */ ArpL3Protocol (Ptr node); virtual ~ArpL3Protocol (); - - virtual Ptr CreateTraceResolver (void); /** * \brief Recieve a packet */ diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 5c2a3de72..7bc9cd3c8 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -74,13 +74,14 @@ InternetNode::Construct (void) Object::AddInterface (ipv4L4Demux); } -void -InternetNode::DoFillTraceResolver (CompositeTraceResolver &resolver) +Ptr +InternetNode::GetTraceResolver () { - Node::DoFillTraceResolver (resolver); + Ptr resolver = Create (); Ptr ipv4 = QueryInterface (Ipv4L3Protocol::iid); - resolver.Add ("ipv4", - MakeCallback (&Ipv4L3Protocol::CreateTraceResolver, PeekPointer (ipv4))); + resolver->AddChild ("ipv4", ipv4); + resolver->SetParent (Node::GetTraceResolver ()); + return resolver; } void diff --git a/src/internet-node/internet-node.h b/src/internet-node/internet-node.h index deabd20eb..d54714a8b 100644 --- a/src/internet-node/internet-node.h +++ b/src/internet-node/internet-node.h @@ -42,8 +42,8 @@ public: protected: virtual void DoDispose(void); + virtual Ptr GetTraceResolver (void); private: - virtual void DoFillTraceResolver (CompositeTraceResolver &resolver); bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; void Construct (void); }; diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index 699d6109d..3ea9120d2 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -40,18 +40,19 @@ Ipv4Interface::Ipv4Interface (Ptr nd) Ipv4Interface::~Ipv4Interface () {} +void +Ipv4Interface::DoDispose (void) +{ + m_netdevice = 0; + Object::DoDispose (); +} + Ptr Ipv4Interface::GetDevice (void) const { return m_netdevice; } -Ptr -Ipv4Interface::CreateTraceResolver (void) -{ - return DoCreateTraceResolver (); -} - void Ipv4Interface::SetAddress (Ipv4Address a) { diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index a462d5be5..1836aa3b7 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -26,6 +26,7 @@ #include #include "ns3/ipv4-address.h" #include "ns3/ptr.h" +#include "ns3/object.h" namespace ns3 { @@ -60,9 +61,8 @@ class TraceContext; * * Subclasses must implement the two methods: * - Ipv4Interface::SendTo - * - Ipv4Interface::DoCreateTraceResolver */ -class Ipv4Interface +class Ipv4Interface : public Object { public: /** @@ -73,17 +73,6 @@ public: Ipv4Interface (Ptr nd); virtual ~Ipv4Interface(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - * - * This method will delegate the work to the private DoCreateTraceResolver - * method which is supposed to be implemented by subclasses. - */ - Ptr CreateTraceResolver (void); /** * \returns the underlying NetDevice. This method can return * zero if this interface has no associated NetDevice. @@ -150,10 +139,10 @@ public: */ void Send(Packet p, Ipv4Address dest); - - private: +protected: + virtual void DoDispose (void); +private: virtual void SendTo (Packet p, Ipv4Address dest) = 0; - virtual Ptr DoCreateTraceResolver (void) = 0; Ptr m_netdevice; bool m_ifup; Ipv4Address m_address; diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index df97fafc0..75320e886 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -22,7 +22,6 @@ #include "ns3/packet.h" #include "ns3/debug.h" #include "ns3/composite-trace-resolver.h" -#include "ns3/array-trace-resolver.h" #include "ns3/callback.h" #include "ns3/ipv4-address.h" #include "ns3/ipv4-route.h" @@ -90,26 +89,26 @@ Ipv4L3ProtocolTraceContextElement::GetUid (void) } -Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex () +Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex () : m_index (0) {} -Ipv4l3ProtocolInterfaceIndex::Ipv4l3ProtocolInterfaceIndex (uint32_t index) +Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex (uint32_t index) : m_index (index) {} uint32_t -Ipv4l3ProtocolInterfaceIndex::Get (void) const +Ipv4L3ProtocolInterfaceIndex::Get (void) const { return m_index; } void -Ipv4l3ProtocolInterfaceIndex::Print (std::ostream &os) const +Ipv4L3ProtocolInterfaceIndex::Print (std::ostream &os) const { os << "ipv4-interface=" << m_index; } uint16_t -Ipv4l3ProtocolInterfaceIndex::GetUid (void) +Ipv4L3ProtocolInterfaceIndex::GetUid (void) { - static uint16_t uid = AllocateUid ("Ipv4l3ProtocolInterfaceIndex"); + static uint16_t uid = AllocateUid ("Ipv4L3ProtocolInterfaceIndex"); return uid; } @@ -131,10 +130,6 @@ Ipv4L3Protocol::~Ipv4L3Protocol () void Ipv4L3Protocol::DoDispose (void) { - for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) - { - delete (*i); - } m_interfaces.clear (); m_node = 0; m_staticRouting->Dispose (); @@ -145,7 +140,7 @@ Ipv4L3Protocol::DoDispose (void) void Ipv4L3Protocol::SetupLoopback (void) { - Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node); + Ptr interface = Create (m_node); interface->SetAddress (Ipv4Address::GetLoopback ()); interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); uint32_t index = AddIpv4Interface (interface); @@ -154,24 +149,15 @@ Ipv4L3Protocol::SetupLoopback (void) } Ptr -Ipv4L3Protocol::CreateTraceResolver (void) +Ipv4L3Protocol::GetTraceResolver (void) { Ptr resolver = Create (); resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); - resolver->Add ("interfaces", - MakeCallback (&Ipv4L3Protocol::InterfacesCreateTraceResolver, this)); - return resolver; -} - -Ptr -Ipv4L3Protocol::InterfacesCreateTraceResolver (void) const -{ - Ptr >resolver = - Create > - (MakeCallback (&Ipv4L3Protocol::GetNInterfaces, this), - MakeCallback (&Ipv4L3Protocol::GetInterface, this)); + resolver->AddArray ("interfaces", + m_interfaces.begin (), m_interfaces.end (), + Ipv4L3ProtocolInterfaceIndex ()); return resolver; } @@ -264,18 +250,18 @@ Ipv4L3Protocol::RemoveRoute (uint32_t index) uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { - Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); + Ptr interface = Create (m_node, device); return AddIpv4Interface (interface); } uint32_t -Ipv4L3Protocol::AddIpv4Interface (Ipv4Interface *interface) +Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; return index; } -Ipv4Interface * +Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { uint32_t tmp = 0; @@ -295,7 +281,7 @@ Ipv4L3Protocol::GetNInterfaces (void) const return m_nInterfaces; } -Ipv4Interface * +Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) { for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -363,7 +349,7 @@ Ipv4L3Protocol::Send (Packet const &packet, for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++) { - Ipv4Interface *outInterface = *ifaceIter; + Ptr outInterface = *ifaceIter; Packet packetCopy = packet; NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ()); @@ -400,7 +386,7 @@ Ipv4L3Protocol::SendRealOut (bool found, return; } packet.AddHeader (ipHeader); - Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); + Ptr outInterface = GetInterface (route.GetInterface ()); NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); m_txTrace (packet, route.GetInterface ()); if (route.IsGateway ()) @@ -430,7 +416,7 @@ Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr interface = *i; if (interface->GetDevice () == device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) @@ -480,43 +466,43 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip) void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetAddress (address); } void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetAddress (); } uint16_t Ipv4L3Protocol::GetMtu (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->GetMtu (); } bool Ipv4L3Protocol::IsUp (uint32_t i) const { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); return interface->IsUp (); } void Ipv4L3Protocol::SetUp (uint32_t i) { - Ipv4Interface *interface = GetInterface (i); + Ptr interface = GetInterface (i); interface->SetUp (); // If interface address and network mask have been set, add a route @@ -532,7 +518,7 @@ Ipv4L3Protocol::SetUp (uint32_t i) void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { - Ipv4Interface *interface = GetInterface (ifaceIndex); + Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); // Remove all routes that are going through this interface diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index f6fcec7a7..0866861c0 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -63,11 +63,11 @@ private: enum Type m_type; }; -class Ipv4l3ProtocolInterfaceIndex : public TraceContextElement +class Ipv4L3ProtocolInterfaceIndex : public TraceContextElement { public: - Ipv4l3ProtocolInterfaceIndex (); - Ipv4l3ProtocolInterfaceIndex (uint32_t index); + Ipv4L3ProtocolInterfaceIndex (); + Ipv4L3ProtocolInterfaceIndex (uint32_t index); uint32_t Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); @@ -85,15 +85,6 @@ public: Ipv4L3Protocol(Ptr node); virtual ~Ipv4L3Protocol (); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - virtual Ptr CreateTraceResolver (void); - /** * \param ttl default ttl to use * @@ -109,7 +100,7 @@ public: * Try to find an Ipv4Interface whose NetDevice is equal to * the input NetDevice. */ - Ipv4Interface *FindInterfaceForDevice (Ptr device); + Ptr FindInterfaceForDevice (Ptr device); /** * Lower layer calls this method after calling L3Demux::Lookup @@ -159,7 +150,7 @@ public: void RemoveRoute (uint32_t i); uint32_t AddInterface (Ptr device); - Ipv4Interface * GetInterface (uint32_t i) const; + Ptr GetInterface (uint32_t i) const; uint32_t GetNInterfaces (void) const; @@ -178,6 +169,7 @@ public: protected: virtual void DoDispose (void); + virtual Ptr GetTraceResolver (void); private: @@ -187,11 +179,10 @@ private: Ipv4Header const &ipHeader); bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr device); void ForwardUp (Packet p, Ipv4Header const&ip); - uint32_t AddIpv4Interface (Ipv4Interface *interface); + uint32_t AddIpv4Interface (Ptr interface); void SetupLoopback (void); - Ptr InterfacesCreateTraceResolver (void) const; - typedef std::list Ipv4InterfaceList; + typedef std::list > Ipv4InterfaceList; typedef std::list< std::pair< int, Ptr > > Ipv4RoutingProtocolList; Ipv4InterfaceList m_interfaces; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 56ee9eb9a..74ee536b5 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -79,7 +79,7 @@ Ipv4L4Demux::DoDispose (void) } Ptr -Ipv4L4Demux::CreateTraceResolver (void) +Ipv4L4Demux::GetTraceResolver (void) { Ptr resolver = Create (); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) @@ -89,10 +89,9 @@ Ipv4L4Demux::CreateTraceResolver (void) std::ostringstream oss (protValue); oss << (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceContextElement protocolNumber = (*i)->GetProtocolNumber (); - resolver->Add (protValue, - MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, PeekPointer (protocol)), - protocolNumber); + resolver->AddChild (protValue, protocol, protocolNumber); } + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } void diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 0b4755435..4700ec697 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -59,14 +59,6 @@ public: Ipv4L4Demux (Ptr node); virtual ~Ipv4L4Demux(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - Ptr CreateTraceResolver (void); /** * \param protocol a template for the protocol to add to this L4 Demux. * \returns the L4Protocol effectively added. @@ -95,8 +87,10 @@ public: * returned from the Ipv4L4Protocol::Insert method. */ void Remove (Ptr protocol); -private: +protected: + Ptr GetTraceResolver (void); virtual void DoDispose (void); +private: typedef std::list > L4List_t; L4List_t m_protocols; Ptr m_node; diff --git a/src/internet-node/ipv4-l4-protocol.h b/src/internet-node/ipv4-l4-protocol.h index c658318a1..e54dfcc97 100644 --- a/src/internet-node/ipv4-l4-protocol.h +++ b/src/internet-node/ipv4-l4-protocol.h @@ -37,10 +37,6 @@ class TraceContext; /** * \brief L4 Protocol base class * - * All subclasses must implement: - * - Ipv4L4Protocol::Copy - * - Ipv4L4Protocol::CreateTraceResolver - * * If you want to implement a new L4 protocol, all you have to do is * implement a subclass of this base class and add it to an L4Demux. */ @@ -59,8 +55,6 @@ public: */ int GetVersion() const; - virtual Ptr CreateTraceResolver () = 0; - /** * \param p packet to forward up * \param source source address of packet received diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 1364e2daf..307533d6e 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -33,13 +33,6 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr node) {} Ipv4LoopbackInterface::~Ipv4LoopbackInterface () {} - -Ptr -Ipv4LoopbackInterface::DoCreateTraceResolver (void) -{ - return Create (); -} - void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { diff --git a/src/internet-node/ipv4-loopback-interface.h b/src/internet-node/ipv4-loopback-interface.h index e9df32007..8e33f81d7 100644 --- a/src/internet-node/ipv4-loopback-interface.h +++ b/src/internet-node/ipv4-loopback-interface.h @@ -43,7 +43,6 @@ class Ipv4LoopbackInterface : public Ipv4Interface private: virtual void SendTo (Packet p, Ipv4Address dest); - virtual Ptr DoCreateTraceResolver (void); Ptr m_node; }; diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index 13e937d3c..d9b5afe23 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -45,12 +45,6 @@ UdpL4Protocol::UdpL4Protocol (Ptr node) UdpL4Protocol::~UdpL4Protocol () {} -Ptr -UdpL4Protocol::CreateTraceResolver (void) -{ - return Create (); -} - void UdpL4Protocol::DoDispose (void) { diff --git a/src/internet-node/udp-l4-protocol.h b/src/internet-node/udp-l4-protocol.h index da2cd0e2d..46fe62761 100644 --- a/src/internet-node/udp-l4-protocol.h +++ b/src/internet-node/udp-l4-protocol.h @@ -49,7 +49,6 @@ public: UdpL4Protocol (Ptr node); virtual ~UdpL4Protocol (); - virtual Ptr CreateTraceResolver (void); /** * \return A smart Socket pointer to a UdpSocket, allocated by this instance * of the UDP protocol diff --git a/src/node/net-device.cc b/src/node/net-device.cc index cdc1f63f3..8ec8b0992 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -184,12 +184,6 @@ NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber) } } -Ptr -NetDevice::CreateTraceResolver (void) -{ - return DoCreateTraceResolver (); -} - Ptr NetDevice::GetChannel (void) const { diff --git a/src/node/net-device.h b/src/node/net-device.h index af63be5b4..7516345d8 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -62,14 +62,6 @@ public: static const InterfaceId iid; virtual ~NetDevice(); - /** - * \param context the trace context to use to construct the - * TraceResolver to return - * \returns a TraceResolver which can resolve all traces - * performed in this object. The caller must - * delete the returned object. - */ - Ptr CreateTraceResolver (void); /** * \return the channel this NetDevice is connected to. The value @@ -282,15 +274,6 @@ public: * Subclasses must implement this method. */ virtual bool DoNeedsArp (void) const = 0; - /** - * \param context the trace context to associated to the - * trace resolver. - * \returns a trace resolver associated to the input context. - * the caller takes ownership of the pointer returned. - * - * Subclasses must implement this method. - */ - virtual Ptr DoCreateTraceResolver (void) = 0; /** * \returns the channel associated to this NetDevice. * diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 823b92a0c..1b74dbe86 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -33,7 +33,7 @@ static class Initialization public: Initialization () { - ns3::TraceRoot::Register ("nodes", ns3::MakeCallback (&ns3::NodeList::CreateTraceResolver)); + ns3::TraceRoot::Register ("nodes", ns3::MakeCallback (&ns3::NodeList::GetTraceResolver)); } } g_initialization; } @@ -76,7 +76,7 @@ public: uint32_t Add (Ptr node); NodeList::Iterator Begin (void); NodeList::Iterator End (void); - Ptr CreateTraceResolver (void); + Ptr GetTraceResolver (void); Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); @@ -131,12 +131,11 @@ NodeListPriv::GetNode (uint32_t n) Ptr -NodeListPriv::CreateTraceResolver (void) +NodeListPriv::GetTraceResolver (void) { - Ptr, NodeListIndex> >resolver = - Create, NodeListIndex> > - (MakeCallback (&NodeListPriv::GetNNodes, this), - MakeCallback (&NodeListPriv::GetNode, this)); + Ptr >resolver = + Create > (); + resolver->SetIterators (Begin (), End ()); return resolver; } @@ -165,9 +164,9 @@ NodeList::End (void) return SimulationSingleton::Get ()->End (); } Ptr -NodeList::CreateTraceResolver (void) +NodeList::GetTraceResolver (void) { - return SimulationSingleton::Get ()->CreateTraceResolver (); + return SimulationSingleton::Get ()->GetTraceResolver (); } Ptr NodeList::GetNode (uint32_t n) diff --git a/src/node/node-list.h b/src/node/node-list.h index 66cd6965d..8af457b88 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -79,7 +79,7 @@ public: * \returns the requested trace resolver. The caller * takes ownership of the returned pointer. */ - static Ptr CreateTraceResolver (void); + static Ptr GetTraceResolver (void); /** * \param n index of requested node. diff --git a/src/node/node.cc b/src/node/node.cc index 554431db1..031ed34ab 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -25,7 +25,6 @@ #include "packet-socket-factory.h" #include "ns3/simulator.h" #include "ns3/composite-trace-resolver.h" -#include "ns3/array-trace-resolver.h" namespace ns3{ @@ -83,10 +82,11 @@ Node::~Node () {} Ptr -Node::CreateTraceResolver (void) +Node::GetTraceResolver (void) { Ptr resolver = Create (); - DoFillTraceResolver (*PeekPointer (resolver)); + resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ()); + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -141,24 +141,6 @@ Node::GetNApplications (void) const return m_applications.size (); } -Ptr -Node::CreateDevicesTraceResolver (void) -{ - Ptr,NodeNetDeviceIndex> >resolver = - Create,NodeNetDeviceIndex> > - (MakeCallback (&Node::GetNDevices, this), - MakeCallback (&Node::GetDevice, this)); - - return resolver; -} - -void -Node::DoFillTraceResolver (CompositeTraceResolver &resolver) -{ - resolver.Add ("devices", - MakeCallback (&Node::CreateDevicesTraceResolver, this)); -} - void Node::DoDispose() { diff --git a/src/node/node.h b/src/node/node.h index 7931dd001..0066bf319 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -84,16 +84,6 @@ public: virtual ~Node(); - /** - * \returns a newly-created TraceResolver. The caller takes - * ownership of the returned pointer. - * - * Request the Node to create a trace resolver. This method - * could be used directly by a user who needs access to very low-level - * trace configuration. - */ - Ptr CreateTraceResolver (void); - /** * \returns the unique id of this node. * @@ -182,23 +172,15 @@ public: void UnregisterProtocolHandler (ProtocolHandler handler); protected: + virtual Ptr GetTraceResolver (void); /** * The dispose method. Subclasses must override this method * and must chain up to it by calling Node::DoDispose at the * end of their own DoDispose method. */ virtual void DoDispose (void); - /** - * \param resolver the resolver to store trace sources in. - * - * If a subclass wants to add new traces to a Node, it needs - * to override this method and record the new trace sources - * in the input resolver. Subclasses also _must_ chain up to - * their parent's DoFillTraceResolver method prior - * to recording they own trace sources. - */ - virtual void DoFillTraceResolver (CompositeTraceResolver &resolver); private: + /** * \param device the device added to this Node. * @@ -212,7 +194,6 @@ private: bool ReceiveFromDevice (Ptr device, const Packet &packet, uint16_t protocol, const Address &from); void Construct (void); - Ptr CreateDevicesTraceResolver (void); struct ProtocolHandlerEntry { ProtocolHandler handler; diff --git a/src/node/queue.cc b/src/node/queue.cc index 8a6725e4e..78ad9369c 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -95,12 +95,13 @@ Queue::~Queue() } Ptr -Queue::CreateTraceResolver (void) +Queue::GetTraceResolver (void) { Ptr resolver = Create (); resolver->Add ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); resolver->Add ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); resolver->Add ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } diff --git a/src/node/queue.h b/src/node/queue.h index bf2c6a2d6..c10795c67 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -69,8 +69,6 @@ public: Queue (); virtual ~Queue (); - - Ptr CreateTraceResolver (void); /** * \return true if the queue is empty; false otherwise @@ -167,6 +165,7 @@ private: virtual bool DoPeek (Packet &p) = 0; protected: + Ptr GetTraceResolver (void); // called by subclasses to notify parent of packet drops. void Drop (const Packet& p); From 03cf88211eea89b6a49f95a4f14c5cb2a9d3a41a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 17:59:56 +0200 Subject: [PATCH 18/92] constify --- src/core/callback.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/callback.h b/src/core/callback.h index 94e58ca92..c5d3cf442 100644 --- a/src/core/callback.h +++ b/src/core/callback.h @@ -306,11 +306,11 @@ public: return (*(PeekImpl ())) (a1,a2,a3,a4,a5); } - bool IsEqual (CallbackBase const &other) { + bool IsEqual (CallbackBase const &other) const { return PeekImpl ()->IsEqual (other.PeekImpl ()); } - bool CheckType (CallbackBase const& other) { + bool CheckType (CallbackBase const& other) const { CallbackImplBase *otherBase = other.PeekImpl (); if (dynamic_cast *> (otherBase) != 0) { From de7999c932d257043590731f452cf95a31d2defb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:00:15 +0200 Subject: [PATCH 19/92] constify --- src/core/callback-trace-source.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index 6282467f9..7de77c56a 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -44,11 +44,11 @@ public: CallbackTraceSource (); void AddCallback (CallbackBase const & callback, TraceContext const & context); void RemoveCallback (CallbackBase const & callback); - void operator() (void); - void operator() (T1 a1); - void operator() (T1 a1, T2 a2); - void operator() (T1 a1, T2 a2, T3 a3); - void operator() (T1 a1, T2 a2, T3 a3, T4 a4); + void operator() (void) const; + void operator() (T1 a1) const; + void operator() (T1 a1, T2 a2) const; + void operator() (T1 a1, T2 a2, T3 a3) const; + void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const; private: typedef std::list > CallbackList; @@ -99,9 +99,9 @@ CallbackTraceSource::RemoveCallback (CallbackBase const & callback) template void -CallbackTraceSource::operator() (void) +CallbackTraceSource::operator() (void) const { - for (typename CallbackList::iterator i = m_callbackList.begin (); + for (typename CallbackList::const_iterator i = m_callbackList.begin (); i != m_callbackList.end (); i++) { (*i) (m_context); @@ -110,9 +110,9 @@ CallbackTraceSource::operator() (void) template void -CallbackTraceSource::operator() (T1 a1) +CallbackTraceSource::operator() (T1 a1) const { - for (typename CallbackList::iterator i = m_callbackList.begin (); + for (typename CallbackList::const_iterator i = m_callbackList.begin (); i != m_callbackList.end (); i++) { (*i) (m_context, a1); @@ -121,9 +121,9 @@ CallbackTraceSource::operator() (T1 a1) template void -CallbackTraceSource::operator() (T1 a1, T2 a2) +CallbackTraceSource::operator() (T1 a1, T2 a2) const { - for (typename CallbackList::iterator i = m_callbackList.begin (); + for (typename CallbackList::const_iterator i = m_callbackList.begin (); i != m_callbackList.end (); i++) { (*i) (m_context, a1, a2); @@ -132,9 +132,9 @@ CallbackTraceSource::operator() (T1 a1, T2 a2) template void -CallbackTraceSource::operator() (T1 a1, T2 a2, T3 a3) +CallbackTraceSource::operator() (T1 a1, T2 a2, T3 a3) const { - for (typename CallbackList::iterator i = m_callbackList.begin (); + for (typename CallbackList::const_iterator i = m_callbackList.begin (); i != m_callbackList.end (); i++) { (*i) (m_context, a1, a2, a3); @@ -143,9 +143,9 @@ CallbackTraceSource::operator() (T1 a1, T2 a2, T3 a3) template void -CallbackTraceSource::operator() (T1 a1, T2 a2, T3 a3, T4 a4) +CallbackTraceSource::operator() (T1 a1, T2 a2, T3 a3, T4 a4) const { - for (typename CallbackList::iterator i = m_callbackList.begin (); + for (typename CallbackList::const_iterator i = m_callbackList.begin (); i != m_callbackList.end (); i++) { (*i) (m_context, a1, a2, a3, a4); From 442d4c9e35ef8f52d66049845935defae45fa049 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:27:30 +0200 Subject: [PATCH 20/92] add an abstract base to CallbackTraceSource --- src/core/callback-trace-source.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index 7de77c56a..e5cc1a599 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -29,6 +29,14 @@ namespace ns3 { +class CallbackTraceSourceBase +{ +public: + virtual ~CallbackTraceSourceBase () {} + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) = 0; + virtual void RemoveCallback (CallbackBase const & callback) = 0; +}; + /** * \brief log arbitrary number of parameters to a matching ns3::Callback @@ -39,11 +47,11 @@ namespace ns3 { */ template -class CallbackTraceSource { +class CallbackTraceSource : public CallbackTraceSourceBase { public: CallbackTraceSource (); - void AddCallback (CallbackBase const & callback, TraceContext const & context); - void RemoveCallback (CallbackBase const & callback); + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context); + virtual void RemoveCallback (CallbackBase const & callback); void operator() (void) const; void operator() (T1 a1) const; void operator() (T1 a1, T2 a2) const; From 9fbb2607a151b3c213658c9da7153961a931cf5f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:27:52 +0200 Subject: [PATCH 21/92] use the abstract base of CallbackTraceSource to avoid pushing too much code in the header --- src/core/composite-trace-resolver.cc | 123 +++++++++++++++++++- src/core/composite-trace-resolver.h | 164 +++++++++++++++------------ 2 files changed, 209 insertions(+), 78 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 72a768e91..ddc7bd001 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -63,6 +63,115 @@ CompositeTraceResolver::Add (std::string name, AddItem (item); } +void +CompositeTraceResolver::Add (std::string name, + FVTraceSourceBase &trace) +{ + DoAddFV (name, trace, TraceContext ()); +} + + +void +CompositeTraceResolver::DoAddFV (std::string name, + FVTraceSourceBase &trace, + const TraceContext &context) +{ + class FVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + FVTraceSourceBase *trace; + } *item = new FVCompositeItem (); + item->name = name; + item->context = context; + item->trace = &trace; + AddItem (item); +} + +void +CompositeTraceResolver::Add (std::string name, + UVTraceSourceBase &trace) +{ + DoAddUV (name, trace, TraceContext ()); +} + + +void +CompositeTraceResolver::DoAddUV (std::string name, + UVTraceSourceBase &trace, + const TraceContext &context) +{ + class UVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + UVTraceSourceBase *trace; + } *item = new UVCompositeItem (); + item->name = name; + item->context = context; + item->trace = &trace; + AddItem (item); +} + +void +CompositeTraceResolver::Add (std::string name, + SVTraceSourceBase &trace) +{ + DoAddSV (name, trace, TraceContext ()); +} +void +CompositeTraceResolver::DoAddSV (std::string name, + SVTraceSourceBase &trace, + const TraceContext &context) +{ + class SVCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + SVTraceSourceBase *trace; + } *item = new SVCompositeItem (); + item->name = name; + item->context = context; + item->trace = &trace; + AddItem (item); +} + +void +CompositeTraceResolver::DoAddCallback (std::string name, + CallbackTraceSourceBase &trace, + const TraceContext &context) +{ + class CallbackCompositeItem : public CompositeItem + { + public: + virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) + {if (subpath == "") {trace->AddCallback (cb, context);}} + virtual void Disconnect (std::string subpath, const CallbackBase &cb) + {if (subpath == "") {trace->RemoveCallback (cb);}} + + CallbackTraceSourceBase *trace; + } *item = new CallbackCompositeItem (); + item->name = name; + item->context = context; + item->trace = &trace; + AddItem (item); +} + + + + void CompositeTraceResolver::AddChild (std::string name, Ptr child) { @@ -229,18 +338,22 @@ class TraceSourceTest : public TraceContextElement public: enum Sources { DOUBLEA, - DOUBLEB + DOUBLEB, + UINT16_T }; static uint16_t GetUid (void) {static uint16_t uid = AllocateUid ("TraceSourceTest"); return uid;} void Print (std::ostream &os) {os << "tracesource="; if (m_sources == DOUBLEA) {os << "doubleA";} - else if (m_sources == DOUBLEB) {os << "doubleB";}} + else if (m_sources == DOUBLEB) {os << "doubleB";} + else if (m_sources == UINT16_T) {os << "uint16_t";} + } TraceSourceTest () : m_sources (TraceSourceTest::DOUBLEA) {} TraceSourceTest (enum Sources sources) :m_sources (sources) {} - bool IsDoubleA (void) {return m_sources == TraceSourceTest::DOUBLEA;} - bool IsDoubleB (void) {return m_sources == TraceSourceTest::DOUBLEB;} + bool IsDoubleA (void) const {return m_sources == TraceSourceTest::DOUBLEA;} + bool IsDoubleB (void) const {return m_sources == TraceSourceTest::DOUBLEB;} + bool IsUint16 (void) const {return m_sources == TraceSourceTest::UINT16_T;} private: enum TraceSourceTest::Sources m_sources; }; @@ -462,7 +575,9 @@ CompositeTraceResolverTest::RunTests (void) ok = false; } + SVTraceSource source; + resolver.Add ("uint16_t", source, TraceSourceTest (TraceSourceTest::UINT16_T)); return ok; diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index e8b09610c..5d6415055 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -52,11 +52,9 @@ public: * resolution. The TraceContext of this trace source will also * be automatically extended to contain the input context. */ - template + template void Add (std::string name, - CallbackTraceSource &trace, T const &context); + CallbackTraceSourceBase &trace, T const &context); /** * \param name name of trace source * \param trace a signed variable trace source @@ -69,7 +67,7 @@ public: */ template void Add (std::string name, - SVTraceSource &trace, T const &context); + SVTraceSourceBase &trace, T const &context); /** * \param name name of trace source * \param trace an unsigned variable trace source @@ -82,7 +80,7 @@ public: */ template void Add (std::string name, - UVTraceSource &trace, T const &context); + UVTraceSourceBase &trace, T const &context); /** * \param name name of trace source * \param trace a floating-point variable trace source @@ -95,7 +93,49 @@ public: */ template void Add (std::string name, - FVTraceSource &trace, T const &context); + FVTraceSourceBase &trace, T const &context); + /** + * \param name name of trace source + * \param trace a callback trace source + * + * Add a callback trace source in this resolver. This trace + * source will match the name specified during namespace + * resolution. + */ + template + void Add (std::string name, + CallbackTraceSource &trace); + /** + * \param name name of trace source + * \param trace a signed variable trace source + * + * Add a signed variable trace source in this resolver. + * This trace source will match the name specified during namespace + * resolution. + */ + void Add (std::string name, + SVTraceSourceBase &trace); + /** + * \param name name of trace source + * \param trace an unsigned variable trace source + * + * Add an unsigned variable trace source in this resolver. + * This trace source will match the name specified during namespace + * resolution. + */ + void Add (std::string name, + UVTraceSourceBase &trace); + /** + * \param name name of trace source + * \param trace a floating-point variable trace source + * + * Add a floating-point variable trace source in this resolver. + * This trace source will match the name specified during namespace + * resolution. + */ + void Add (std::string name, + FVTraceSourceBase &trace); /** * \param name name of child trace resolver * \param createResolver a trace resolver constructor @@ -155,6 +195,19 @@ private: const TraceContext &context, enum Operation op); void DoAddChild (std::string name, Ptr child, const TraceContext &context); + void DoAddCallback (std::string name, + CallbackTraceSourceBase &trace, + const TraceContext &context); + void DoAddSV (std::string name, + SVTraceSourceBase &trace, + const TraceContext &context); + void DoAddUV (std::string name, + UVTraceSourceBase &trace, + const TraceContext &context); + void DoAddFV (std::string name, + FVTraceSourceBase &trace, + const TraceContext &context); + CompositeTraceResolver::TraceItems m_items; Ptr m_parent; @@ -166,88 +219,51 @@ namespace ns3 { -template +template void CompositeTraceResolver::Add (std::string name, - CallbackTraceSource &trace, + CallbackTraceSourceBase &trace, T const &context) { - class CallbackCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} + TraceContext ctx; + ctx.Add (context); + DoAddCallback (name, trace, ctx); +} +template +void +CompositeTraceResolver::Add (std::string name, + CallbackTraceSource &trace) +{ + DoAddCallback (name, trace, TraceContext ()); +} - CallbackTraceSource *trace; - } *item = new CallbackCompositeItem (); - item->name = name; - item->context.Add (context); - item->trace = &trace; - AddItem (item); +template +void +CompositeTraceResolver::Add (std::string name, + SVTraceSourceBase &trace, T const &context) +{ + TraceContext ctx; + ctx.Add (context); + DoAddSV (name, trace, ctx); } template void CompositeTraceResolver::Add (std::string name, - SVTraceSource &trace, T const &context) + UVTraceSourceBase &trace, T const &context) { - class SVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - SVTraceSource *trace; - } *item = new SVCompositeItem (); - item->name = name; - item->context.Add (context); - item->trace = &trace; - AddItem (item); + TraceContext ctx; + ctx.Add (context); + DoAddUV (name, trace, ctx); } template void CompositeTraceResolver::Add (std::string name, - UVTraceSource &trace, T const &context) + FVTraceSourceBase &trace, T const &context) { - class UVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - UVTraceSource *trace; - } *item = new UVCompositeItem (); - item->name = name; - item->context.Add (context); - item->trace = &trace; - AddItem (item); -} -template -void -CompositeTraceResolver::Add (std::string name, - FVTraceSource &trace, T const &context) -{ - class FVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - FVTraceSource *trace; - } *item = new FVCompositeItem (); - item->name = name; - item->context.Add (context); - item->trace = &trace; - AddItem (item); + TraceContext ctx; + ctx.Add (context); + DoAddFV (name, trace, ctx); } template From 1d546dbd839b041939ca264ff65352621a2b3b3d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:28:13 +0200 Subject: [PATCH 22/92] an untested interface id trace resolver --- src/core/object.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/core/object.cc b/src/core/object.cc index 440bd0f31..f19d4ae65 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -35,6 +35,7 @@ class IidTree public: void SetParent (uint16_t child, const uint16_t *parent); uint16_t LookupParent (uint16_t child); + private: std::vector m_parents; }; @@ -56,6 +57,54 @@ IidTree::LookupParent (uint16_t child) namespace ns3 { +class InterfaceIdTraceResolver : public TraceResolver +{ +public: + InterfaceIdTraceResolver (Ptr aggregate); + virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); + virtual void Disconnect (std::string path, CallbackBase const &cb); +private: + Ptr ParseForInterface (std::string path); + Ptr m_aggregate; +}; + +InterfaceIdTraceResolver::InterfaceIdTraceResolver (Ptr aggregate) + : m_aggregate (aggregate) +{} +Ptr +InterfaceIdTraceResolver::ParseForInterface (std::string path) +{ + std::string element = GetElement (path); + std::string::size_type dollar_pos = element.find ("$"); + if (dollar_pos != 0) + { + return 0; + } + std::string interfaceName = element.substr (1, std::string::npos); + InterfaceId interfaceId = InterfaceId::LookupByName (interfaceName); + Ptr interface = m_aggregate->QueryInterface (interfaceId); + return interface; +} +void +InterfaceIdTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) +{ + Ptr interface = ParseForInterface (path); + if (interface != 0) + { + interface->TraceConnect (GetSubpath (path), cb, context); + } +} +void +InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb) +{ + Ptr interface = ParseForInterface (path); + if (interface != 0) + { + interface->TraceDisconnect (GetSubpath (path), cb); + } +} + + InterfaceId::InterfaceId (uint16_t iid) : m_iid (iid) {} @@ -197,7 +246,9 @@ Object::DoDispose (void) Ptr Object::GetTraceResolver (void) { - return Create (); + Ptr resolver = + Create (this); + return resolver; } bool From b4aae4755604c8a997a128346bc30d19d1aa2c76 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:28:37 +0200 Subject: [PATCH 23/92] replace the adhoc mobility course change callbacks with a trace source --- samples/main-random-topology.cc | 4 +-- src/mobility/hierarchical-mobility-model.cc | 8 ++--- src/mobility/hierarchical-mobility-model.h | 4 +-- src/mobility/mobility-model-notifier.cc | 39 ++++++--------------- src/mobility/mobility-model-notifier.h | 22 +++--------- 5 files changed, 23 insertions(+), 54 deletions(-) diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index 3fb52a0d9..3021ed3fb 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -15,7 +15,7 @@ using namespace ns3; static void -CourseChange (Ptr position) +CourseChange (const TraceContext &context, Ptr position) { Position pos = position->Get (); std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y @@ -39,7 +39,7 @@ int main (int argc, char *argv[]) for (uint32_t i = 0; i < 10000; i++) { Ptr notifier = Create (); - notifier->RegisterListener (MakeCallback (&CourseChange)); + notifier->TraceConnect ("/course-change", MakeCallback (&CourseChange)); objects.push_back (notifier); } diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index 7e4aa3fe3..046f98056 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -41,8 +41,8 @@ HierarchicalMobilityModel::HierarchicalMobilityModel (Ptr child, parentNotifier = Create (); parent->AddInterface (parentNotifier); } - childNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ChildChanged, this)); - parentNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); + childNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this)); + parentNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); } Ptr @@ -89,13 +89,13 @@ HierarchicalMobilityModel::DoGetSpeed (void) const } void -HierarchicalMobilityModel::ParentChanged (Ptr model) +HierarchicalMobilityModel::ParentChanged (const TraceContext &context, Ptr model) { MobilityModel::NotifyCourseChange (); } void -HierarchicalMobilityModel::ChildChanged (Ptr model) +HierarchicalMobilityModel::ChildChanged (const TraceContext &context, Ptr model) { MobilityModel::NotifyCourseChange (); } diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index 1502c516a..16be7820b 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -63,8 +63,8 @@ private: virtual void DoSet (const Position &position); virtual Speed DoGetSpeed (void) const; - void ParentChanged (Ptr model); - void ChildChanged (Ptr model); + void ParentChanged (const TraceContext &context, Ptr model); + void ChildChanged (const TraceContext &context, Ptr model); Ptr m_child; Ptr m_parent; diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index abb476c20..adea6d771 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -19,6 +19,7 @@ * Author: Mathieu Lacage */ #include "mobility-model-notifier.h" +#include "ns3/composite-trace-resolver.h" namespace ns3 { @@ -32,37 +33,19 @@ MobilityModelNotifier::MobilityModelNotifier () SetInterfaceId (MobilityModelNotifier::iid); } -void -MobilityModelNotifier::RegisterListener (Listener listener) -{ - m_listeners.push_back (listener); -} -void -MobilityModelNotifier::UnregisterListener (Listener callback) -{ - for (std::list::iterator i = m_listeners.begin (); - i != m_listeners.end ();) - { - Listener listener = *i; - if (listener.IsEqual (callback)) - { - i = m_listeners.erase (i); - } - else - { - i++; - } - } -} void MobilityModelNotifier::Notify (Ptr position) const { - for (std::list::const_iterator i = m_listeners.begin (); - i != m_listeners.end (); i++) - { - Listener listener = *i; - listener (position); - } + m_trace (position); +} + +Ptr +MobilityModelNotifier::GetTraceResolver (void) +{ + Ptr resolver = + Create (); + resolver->Add ("course-change", m_trace); + return resolver; } } // namespace ns3 diff --git a/src/mobility/mobility-model-notifier.h b/src/mobility/mobility-model-notifier.h index 8aec327de..0f8422d4e 100644 --- a/src/mobility/mobility-model-notifier.h +++ b/src/mobility/mobility-model-notifier.h @@ -24,6 +24,7 @@ #include "ns3/object.h" #include "ns3/component-manager.h" #include "ns3/callback.h" +#include "ns3/callback-trace-source.h" #include "mobility-model.h" namespace ns3 { @@ -37,8 +38,6 @@ public: static const InterfaceId iid; static const ClassId cid; - typedef Callback > Listener; - /** * Create a new position notifier */ @@ -48,23 +47,10 @@ public: * \param position the position which just changed. */ void Notify (Ptr position) const; - - /** - * \param listener listener to add - * - * The listener will be notified upon every position change. - */ - void RegisterListener (Listener listener); - /** - * \param listener listener to remove - * - * The listener will not be notified anymore upon every - * position change. It is not an error to try to unregister - * a non-registered liste - */ - void UnregisterListener (Listener listener); +protected: + virtual Ptr GetTraceResolver (void); private: - std::list m_listeners; + CallbackTraceSource > m_trace; }; } // namespace ns3 From 2bd8f97709e4bcae033e6fce202b14bdf9da631f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:37:38 +0200 Subject: [PATCH 24/92] add NS_TEST_ASSERT_UNEQUAL --- src/core/test.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/test.h b/src/core/test.h index 356c08ee2..809c44f0d 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -118,6 +118,23 @@ private: << ", got " << (got) << std::endl; \ result = false; \ } +/** + * Convenience macro to check that a value returned by a test is what + * is expected. Note: this macro assumes a 'bool result = true' + * declaration exists in the test function body, and that the function + * returns that value. + * + * \param got value obtained from the test + * \param expected value that the test is expected to return + */ +#define NS_TEST_ASSERT_UNEQUAL(got, expected) \ + if ((got) == (expected)) \ + { \ + Failure () << __FILE__ << ":" <<__LINE__ \ + << ": did not want " << (expected) \ + << ", got " << (got) << std::endl; \ + result = false; \ + } /** * Convenience macro to check an assertion is held during an unit * test. Note: this macro assumes a 'bool result = true' declaration From 722285bd8fcd017ec8d57fc6aa6b43895076494e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 18:43:15 +0200 Subject: [PATCH 25/92] rewrite Object tests with test.h macros --- src/core/object.cc | 119 ++++++++++----------------------------------- 1 file changed, 25 insertions(+), 94 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index f19d4ae65..6e67ecae6 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -368,112 +368,43 @@ ObjectTest::ObjectTest () bool ObjectTest::RunTests (void) { - bool ok = true; + bool result = true; Ptr baseA = Create (); - if (baseA->QueryInterface (BaseA::iid) != baseA) - { - ok = false; - } - if (baseA->QueryInterface (DerivedA::iid) != 0) - { - ok = false; - } - if (baseA->QueryInterface (DerivedA::iid) != 0) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (BaseA::iid), baseA); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), 0); baseA = Create (10); - if (baseA->QueryInterface (BaseA::iid) != baseA) - { - ok = false; - } - if (baseA->QueryInterface (DerivedA::iid) != baseA) - { - ok = false; - } - if (baseA->QueryInterface (DerivedA::iid) == 0) - { - ok = false; - } + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (BaseA::iid), baseA); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), baseA); + NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (DerivedA::iid), 0); baseA = Create (); Ptr baseB = Create (); Ptr baseBCopy = baseB; baseA->AddInterface (baseB); - if (baseA->QueryInterface (BaseA::iid) == 0) - { - ok = false; - } - if (baseA->QueryInterface (DerivedA::iid) != 0) - { - ok = false; - } - if (baseA->QueryInterface (BaseB::iid) == 0) - { - ok = false; - } - if (baseA->QueryInterface (DerivedB::iid) != 0) - { - ok = false; - } - if (baseB->QueryInterface (BaseB::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (DerivedB::iid) != 0) - { - ok = false; - } - if (baseB->QueryInterface (BaseA::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (DerivedA::iid) != 0) - { - ok = false; - } - if (baseBCopy->QueryInterface (BaseA::iid) == 0) - { - ok = false; - } + NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (BaseA::iid), 0); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (BaseB::iid), 0); + NS_TEST_ASSERT_EQUAL (baseA->QueryInterface (DerivedB::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (BaseB::iid), 0); + NS_TEST_ASSERT_EQUAL (baseB->QueryInterface (DerivedB::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (BaseA::iid), 0); + NS_TEST_ASSERT_EQUAL (baseB->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface (BaseA::iid), 0); baseA = Create (1); baseB = Create (1); baseBCopy = baseB; baseA->AddInterface (baseB); - if (baseA->QueryInterface (DerivedB::iid) == 0) - { - ok = false; - } - if (baseA->QueryInterface (BaseB::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (DerivedA::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (BaseA::iid) == 0) - { - ok = false; - } - if (baseBCopy->QueryInterface (DerivedA::iid) == 0) - { - ok = false; - } - if (baseBCopy->QueryInterface (BaseA::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (DerivedB::iid) == 0) - { - ok = false; - } - if (baseB->QueryInterface (BaseB::iid) == 0) - { - ok = false; - } + NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (DerivedB::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseA->QueryInterface (BaseB::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (BaseA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface (DerivedA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseBCopy->QueryInterface (BaseA::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (DerivedB::iid), 0); + NS_TEST_ASSERT_UNEQUAL (baseB->QueryInterface (BaseB::iid), 0) baseA = Create (); baseB = Create (); @@ -481,7 +412,7 @@ ObjectTest::RunTests (void) baseA = 0; baseA = baseB->QueryInterface (BaseA::iid); - return ok; + return result; } static ObjectTest g_interfaceObjectTests; From 4d50d21f782e2c3f4e244badae4c730ccc80cd76 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 21:08:28 +0200 Subject: [PATCH 26/92] rewrite tests with test.h macros --- src/core/callback-trace-source.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/core/callback-trace-source.cc b/src/core/callback-trace-source.cc index 7bcb41fe0..aa686c14d 100644 --- a/src/core/callback-trace-source.cc +++ b/src/core/callback-trace-source.cc @@ -55,7 +55,7 @@ CallbackTraceSourceTest::CbTwo (TraceContext const &context, uint8_t a, double b bool CallbackTraceSourceTest::RunTests (void) { - bool ok = true; + bool result = true; TraceContext ctx; CallbackTraceSource trace; @@ -64,28 +64,31 @@ CallbackTraceSourceTest::RunTests (void) m_one = false; m_two = false; trace (1, 2); - if (!m_one || !m_two) - { - ok = false; - } + NS_TEST_ASSERT (m_one); + NS_TEST_ASSERT (m_two); + trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this)); m_one = false; m_two = false; trace (1, 2); - if (m_one || !m_two) - { - ok = false; - } + NS_TEST_ASSERT (!m_one); + NS_TEST_ASSERT (m_two); trace.RemoveCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this)); m_one = false; m_two = false; trace (1, 2); - if (m_one || m_two) - { - ok = false; - } + NS_TEST_ASSERT (!m_one); + NS_TEST_ASSERT (!m_two); - return ok; + trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbOne, this), ctx); + trace.AddCallback (MakeCallback (&CallbackTraceSourceTest::CbTwo, this), ctx); + m_one = false; + m_two = false; + trace (1, 2); + NS_TEST_ASSERT (m_one); + NS_TEST_ASSERT (m_two); + + return result; } CallbackTraceSourceTest g_callbackTraceTest; From 23d17d56e9b060c2e489d37564babe45fd41b131 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 21:23:40 +0200 Subject: [PATCH 27/92] test object-based tracing --- src/core/object.cc | 124 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) diff --git a/src/core/object.cc b/src/core/object.cc index 6e67ecae6..c16a7db63 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -22,7 +22,9 @@ #include "assert.h" #include "singleton.h" #include "uid-manager.h" -#include "empty-trace-resolver.h" +#include "sv-trace-source.h" +#include "trace-resolver.h" +#include "composite-trace-resolver.h" #include namespace { @@ -301,7 +303,18 @@ public: { SetInterfaceId (BaseA::iid); } + void BaseGenerateTrace (int16_t v) + { m_source = v; } virtual void Dispose (void) {} + virtual ns3::Ptr GetTraceResolver (void) + { + ns3::Ptr resolver = + ns3::Create (); + resolver->Add ("basea-x", m_source); + resolver->SetParent (Object::GetTraceResolver ()); + return resolver; + } + ns3::SVTraceSource m_source; }; class DerivedA : public BaseA @@ -312,9 +325,20 @@ public: { SetInterfaceId (DerivedA::iid); } + void DerivedGenerateTrace (int16_t v) + { m_sourceDerived = v; } virtual void Dispose (void) { BaseA::Dispose (); } + virtual ns3::Ptr GetTraceResolver (void) + { + ns3::Ptr resolver = + ns3::Create (); + resolver->Add ("deriveda-x", m_sourceDerived); + resolver->SetParent (BaseA::GetTraceResolver ()); + return resolver; + } + ns3::SVTraceSource m_sourceDerived; }; const ns3::InterfaceId BaseA::iid = @@ -330,7 +354,18 @@ public: { SetInterfaceId (BaseB::iid); } + void BaseGenerateTrace (int16_t v) + { m_source = v; } virtual void Dispose (void) {} + virtual ns3::Ptr GetTraceResolver (void) + { + ns3::Ptr resolver = + ns3::Create (); + resolver->Add ("baseb-x", m_source); + resolver->SetParent (Object::GetTraceResolver ()); + return resolver; + } + ns3::SVTraceSource m_source; }; class DerivedB : public BaseB @@ -341,9 +376,20 @@ public: { SetInterfaceId (DerivedB::iid); } + void DerivedGenerateTrace (int16_t v) + { m_sourceDerived = v; } virtual void Dispose (void) { BaseB::Dispose (); } + virtual ns3::Ptr GetTraceResolver (void) + { + ns3::Ptr resolver = + ns3::Create (); + resolver->Add ("derivedb-x", m_sourceDerived); + resolver->SetParent (BaseB::GetTraceResolver ()); + return resolver; + } + ns3::SVTraceSource m_sourceDerived; }; const ns3::InterfaceId BaseB::iid = @@ -360,11 +406,42 @@ class ObjectTest : public Test public: ObjectTest (); virtual bool RunTests (void); +private: + void BaseATrace (const TraceContext &context, int64_t oldValue, int64_t newValue); + void DerivedATrace (const TraceContext &context, int64_t oldValue, int64_t newValue); + void BaseBTrace (const TraceContext &context, int64_t oldValue, int64_t newValue); + void DerivedBTrace (const TraceContext &context, int64_t oldValue, int64_t newValue); + + bool m_baseATrace; + bool m_derivedATrace; + bool m_baseBTrace; + bool m_derivedBTrace; }; ObjectTest::ObjectTest () : Test ("Object") {} +void +ObjectTest::BaseATrace (const TraceContext &context, int64_t oldValue, int64_t newValue) +{ + m_baseATrace = true; +} +void +ObjectTest::DerivedATrace (const TraceContext &context, int64_t oldValue, int64_t newValue) +{ + m_derivedATrace = true; +} +void +ObjectTest::BaseBTrace (const TraceContext &context, int64_t oldValue, int64_t newValue) +{ + m_baseBTrace = true; +} +void +ObjectTest::DerivedBTrace (const TraceContext &context, int64_t oldValue, int64_t newValue) +{ + m_derivedBTrace = true; +} + bool ObjectTest::RunTests (void) { @@ -412,6 +489,51 @@ ObjectTest::RunTests (void) baseA = 0; baseA = baseB->QueryInterface (BaseA::iid); + baseA = Create (); + baseA->TraceConnect ("/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + m_baseATrace = false; + baseA->BaseGenerateTrace (1); + NS_TEST_ASSERT (m_baseATrace); + baseA->TraceDisconnect ("/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + + baseB = Create (); + baseB->TraceConnect ("/baseb-x", MakeCallback (&ObjectTest::BaseBTrace, this)); + m_baseBTrace = false; + baseB->BaseGenerateTrace (2); + NS_TEST_ASSERT (m_baseBTrace); + baseB->TraceDisconnect ("/baseb-x", MakeCallback (&ObjectTest::BaseBTrace, this)); + + baseA->AddInterface (baseB); + + baseA->TraceConnect ("/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + m_baseATrace = false; + baseA->BaseGenerateTrace (3); + NS_TEST_ASSERT (m_baseATrace); + baseA->TraceDisconnect ("/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + + baseA->TraceConnect ("/$BaseB/baseb-x", MakeCallback (&ObjectTest::BaseBTrace, this)); + m_baseBTrace = false; + baseB->BaseGenerateTrace (4); + NS_TEST_ASSERT (m_baseBTrace); + baseA->TraceDisconnect ("/$BaseB/baseb-x", MakeCallback (&ObjectTest::BaseBTrace, this)); + m_baseBTrace = false; + baseB->BaseGenerateTrace (5); + NS_TEST_ASSERT (!m_baseBTrace); + + baseB->TraceConnect ("/$BaseA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + m_baseATrace = false; + baseA->BaseGenerateTrace (6); + NS_TEST_ASSERT (m_baseATrace); + baseB->TraceDisconnect ("/$BaseA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + + baseA->TraceConnect ("/$BaseA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + m_baseATrace = false; + baseA->BaseGenerateTrace (7); + NS_TEST_ASSERT (m_baseATrace); + baseA->TraceDisconnect ("/$BaseA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + + + return result; } From fcfdb189141c0a3a590c95ee63bdcaedfb3e4930 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 21:23:55 +0200 Subject: [PATCH 28/92] add some debugging for disconnect --- src/core/composite-trace-resolver.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index ddc7bd001..92bec309c 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -313,6 +313,7 @@ CompositeTraceResolver::OperationOne (std::string subpath, (*i)->Connect (subpath, cb, ctx); } break; case DISCONNECT: + NS_DEBUG ("disconnect from path="< -class CallbackTraceSource : public CallbackTraceSourceBase { +class CallbackTraceSource : public TraceSource { public: CallbackTraceSource (); virtual void AddCallback (CallbackBase const & callback, TraceContext const & context); diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 92bec309c..736ddbd3e 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -63,6 +63,14 @@ CompositeTraceResolver::Add (std::string name, AddItem (item); } +void +CompositeTraceResolver::Add (std::string name, + TraceSource &trace) +{ + DoAddSource (name, trace, TraceContext ()); +} + + void CompositeTraceResolver::Add (std::string name, FVTraceSourceBase &trace) @@ -149,11 +157,11 @@ CompositeTraceResolver::DoAddSV (std::string name, } void -CompositeTraceResolver::DoAddCallback (std::string name, - CallbackTraceSourceBase &trace, - const TraceContext &context) +CompositeTraceResolver::DoAddSource (std::string name, + TraceSource &trace, + const TraceContext &context) { - class CallbackCompositeItem : public CompositeItem + class SourceCompositeItem : public CompositeItem { public: virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) @@ -161,8 +169,8 @@ CompositeTraceResolver::DoAddCallback (std::string name, virtual void Disconnect (std::string subpath, const CallbackBase &cb) {if (subpath == "") {trace->RemoveCallback (cb);}} - CallbackTraceSourceBase *trace; - } *item = new CallbackCompositeItem (); + TraceSource *trace; + } *item = new SourceCompositeItem (); item->name = name; item->context = context; item->trace = &trace; diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 5d6415055..6da904ec8 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -54,7 +54,7 @@ public: */ template void Add (std::string name, - CallbackTraceSourceBase &trace, T const &context); + TraceSource &trace, T const &context); /** * \param name name of trace source * \param trace a signed variable trace source @@ -102,10 +102,8 @@ public: * source will match the name specified during namespace * resolution. */ - template void Add (std::string name, - CallbackTraceSource &trace); + TraceSource &trace); /** * \param name name of trace source * \param trace a signed variable trace source @@ -195,9 +193,9 @@ private: const TraceContext &context, enum Operation op); void DoAddChild (std::string name, Ptr child, const TraceContext &context); - void DoAddCallback (std::string name, - CallbackTraceSourceBase &trace, - const TraceContext &context); + void DoAddSource (std::string name, + TraceSource &trace, + const TraceContext &context); void DoAddSV (std::string name, SVTraceSourceBase &trace, const TraceContext &context); @@ -222,20 +220,12 @@ namespace ns3 { template void CompositeTraceResolver::Add (std::string name, - CallbackTraceSourceBase &trace, + TraceSource &trace, T const &context) { TraceContext ctx; ctx.Add (context); - DoAddCallback (name, trace, ctx); -} -template -void -CompositeTraceResolver::Add (std::string name, - CallbackTraceSource &trace) -{ - DoAddCallback (name, trace, TraceContext ()); + DoAddSource (name, trace, ctx); } template diff --git a/src/core/fv-trace-source.h b/src/core/fv-trace-source.h index 2e059303b..f305980a5 100644 --- a/src/core/fv-trace-source.h +++ b/src/core/fv-trace-source.h @@ -23,11 +23,12 @@ #define F_VARIABLE_TRACER_H #include "callback-trace-source.h" +#include "trace-source.h" #include namespace ns3 { -class FVTraceSourceBase { +class FVTraceSourceBase : public TraceSource { public: typedef CallbackTraceSource ChangeNotifyCallback; diff --git a/src/core/sv-trace-source.h b/src/core/sv-trace-source.h index 291bc764e..d7038c0ad 100644 --- a/src/core/sv-trace-source.h +++ b/src/core/sv-trace-source.h @@ -23,11 +23,12 @@ #define SV_TRACE_SOURCE_H #include "callback-trace-source.h" +#include "trace-source.h" #include namespace ns3 { -class SVTraceSourceBase { +class SVTraceSourceBase : public TraceSource { public: typedef CallbackTraceSource ChangeNotifyCallback; @@ -37,7 +38,7 @@ public: return *this; } - ~SVTraceSourceBase () {} + virtual ~SVTraceSourceBase () {} void AddCallback (CallbackBase const & callback, TraceContext const & context) { m_callback.AddCallback (callback, context); diff --git a/src/core/trace-source.h b/src/core/trace-source.h new file mode 100644 index 000000000..1b4c96577 --- /dev/null +++ b/src/core/trace-source.h @@ -0,0 +1,36 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * 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 TRACE_SOURCE_H +#define TRACE_SOURCE_H + +namespace ns3 { + +class TraceSource +{ +public: + virtual ~TraceSource () {} + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) = 0; + virtual void RemoveCallback (CallbackBase const & callback) = 0; +}; + +} // namespace ns3 + +#endif /* TRACE_SOURCE_H */ diff --git a/src/core/uv-trace-source.h b/src/core/uv-trace-source.h index 0bdfb3f94..2216f2c98 100644 --- a/src/core/uv-trace-source.h +++ b/src/core/uv-trace-source.h @@ -23,11 +23,12 @@ #define UV_TRACE_SOURCE_H #include "callback-trace-source.h" +#include "trace-source.h" #include namespace ns3 { -class UVTraceSourceBase { +class UVTraceSourceBase : public TraceSource { public: typedef CallbackTraceSource ChangeNotifyCallback; diff --git a/src/core/wscript b/src/core/wscript index 7a9e8171a..ea91c7619 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -81,6 +81,7 @@ def build(bld): 'component-manager.h', 'type-traits.h', 'random-variable-default-value.h', + 'trace-source.h', 'uv-trace-source.h', 'sv-trace-source.h', 'fv-trace-source.h', From 14f3f825554e3a5d8e49bb8ec0c1881726e4400c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 22:24:45 +0200 Subject: [PATCH 30/92] remove useless code --- src/core/composite-trace-resolver.cc | 86 --------------------- src/core/composite-trace-resolver.h | 107 --------------------------- 2 files changed, 193 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 736ddbd3e..8f8f31ed2 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -70,92 +70,6 @@ CompositeTraceResolver::Add (std::string name, DoAddSource (name, trace, TraceContext ()); } - -void -CompositeTraceResolver::Add (std::string name, - FVTraceSourceBase &trace) -{ - DoAddFV (name, trace, TraceContext ()); -} - - -void -CompositeTraceResolver::DoAddFV (std::string name, - FVTraceSourceBase &trace, - const TraceContext &context) -{ - class FVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - FVTraceSourceBase *trace; - } *item = new FVCompositeItem (); - item->name = name; - item->context = context; - item->trace = &trace; - AddItem (item); -} - -void -CompositeTraceResolver::Add (std::string name, - UVTraceSourceBase &trace) -{ - DoAddUV (name, trace, TraceContext ()); -} - - -void -CompositeTraceResolver::DoAddUV (std::string name, - UVTraceSourceBase &trace, - const TraceContext &context) -{ - class UVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - UVTraceSourceBase *trace; - } *item = new UVCompositeItem (); - item->name = name; - item->context = context; - item->trace = &trace; - AddItem (item); -} - -void -CompositeTraceResolver::Add (std::string name, - SVTraceSourceBase &trace) -{ - DoAddSV (name, trace, TraceContext ()); -} -void -CompositeTraceResolver::DoAddSV (std::string name, - SVTraceSourceBase &trace, - const TraceContext &context) -{ - class SVCompositeItem : public CompositeItem - { - public: - virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {if (subpath == "") {trace->AddCallback (cb, context);}} - virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {if (subpath == "") {trace->RemoveCallback (cb);}} - - SVTraceSourceBase *trace; - } *item = new SVCompositeItem (); - item->name = name; - item->context = context; - item->trace = &trace; - AddItem (item); -} - void CompositeTraceResolver::DoAddSource (std::string name, TraceSource &trace, diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 6da904ec8..8c43e8f98 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -55,45 +55,6 @@ public: template void Add (std::string name, TraceSource &trace, T const &context); - /** - * \param name name of trace source - * \param trace a signed variable trace source - * \param context the context associated to this trace source - * - * Add a signed variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. The TraceContext of this trace source will also - * be automatically extended to contain the input context. - */ - template - void Add (std::string name, - SVTraceSourceBase &trace, T const &context); - /** - * \param name name of trace source - * \param trace an unsigned variable trace source - * \param context the context associated to this trace source - * - * Add an unsigned variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. The TraceContext of this trace source will also - * be automatically extended to contain the input context. - */ - template - void Add (std::string name, - UVTraceSourceBase &trace, T const &context); - /** - * \param name name of trace source - * \param trace a floating-point variable trace source - * \param context the context associated to this trace source - * - * Add a floating-point variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. The TraceContext of this trace source will also - * be automatically extended to contain the input context. - */ - template - void Add (std::string name, - FVTraceSourceBase &trace, T const &context); /** * \param name name of trace source * \param trace a callback trace source @@ -104,36 +65,6 @@ public: */ void Add (std::string name, TraceSource &trace); - /** - * \param name name of trace source - * \param trace a signed variable trace source - * - * Add a signed variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. - */ - void Add (std::string name, - SVTraceSourceBase &trace); - /** - * \param name name of trace source - * \param trace an unsigned variable trace source - * - * Add an unsigned variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. - */ - void Add (std::string name, - UVTraceSourceBase &trace); - /** - * \param name name of trace source - * \param trace a floating-point variable trace source - * - * Add a floating-point variable trace source in this resolver. - * This trace source will match the name specified during namespace - * resolution. - */ - void Add (std::string name, - FVTraceSourceBase &trace); /** * \param name name of child trace resolver * \param createResolver a trace resolver constructor @@ -196,16 +127,6 @@ private: void DoAddSource (std::string name, TraceSource &trace, const TraceContext &context); - void DoAddSV (std::string name, - SVTraceSourceBase &trace, - const TraceContext &context); - void DoAddUV (std::string name, - UVTraceSourceBase &trace, - const TraceContext &context); - void DoAddFV (std::string name, - FVTraceSourceBase &trace, - const TraceContext &context); - CompositeTraceResolver::TraceItems m_items; Ptr m_parent; @@ -228,34 +149,6 @@ CompositeTraceResolver::Add (std::string name, DoAddSource (name, trace, ctx); } -template -void -CompositeTraceResolver::Add (std::string name, - SVTraceSourceBase &trace, T const &context) -{ - TraceContext ctx; - ctx.Add (context); - DoAddSV (name, trace, ctx); -} -template -void -CompositeTraceResolver::Add (std::string name, - UVTraceSourceBase &trace, T const &context) -{ - TraceContext ctx; - ctx.Add (context); - DoAddUV (name, trace, ctx); -} -template -void -CompositeTraceResolver::Add (std::string name, - FVTraceSourceBase &trace, T const &context) -{ - TraceContext ctx; - ctx.Add (context); - DoAddFV (name, trace, ctx); -} - template void CompositeTraceResolver::AddArray (std::string name, From 233d71fec7abc4d5a5409a5b1799845d8eed3e2f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 22:31:16 +0200 Subject: [PATCH 31/92] CompositeTraceResolver::Add -> CompositeTraceResolver::AddSource --- src/core/composite-trace-resolver.cc | 18 +++++++++--------- src/core/composite-trace-resolver.h | 14 +++++++------- src/core/object.cc | 8 ++++---- src/devices/csma-cd/csma-cd-net-device.cc | 12 ++++++------ .../point-to-point-net-device.cc | 6 +++--- src/internet-node/ipv4-l3-protocol.cc | 6 +++--- src/mobility/mobility-model-notifier.cc | 2 +- src/node/queue.cc | 6 +++--- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 8f8f31ed2..3b69b6da2 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -64,7 +64,7 @@ CompositeTraceResolver::Add (std::string name, } void -CompositeTraceResolver::Add (std::string name, +CompositeTraceResolver::AddSource (std::string name, TraceSource &trace) { DoAddSource (name, trace, TraceContext ()); @@ -351,8 +351,8 @@ Ptr CompositeTraceResolverTest::CreateSubResolver (void) { Ptr subresolver = Create (); - subresolver->Add ("trace-int", m_traceInt, - SubTraceSourceTest (SubTraceSourceTest::INT)); + subresolver->AddSource ("trace-int", m_traceInt, + SubTraceSourceTest (SubTraceSourceTest::INT)); return subresolver; } bool @@ -366,10 +366,10 @@ CompositeTraceResolverTest::RunTests (void) CompositeTraceResolver resolver; - resolver.Add ("trace-double-a", traceDoubleA, - TraceSourceTest (TraceSourceTest::DOUBLEA)); - resolver.Add ("trace-double-b", traceDoubleB, - TraceSourceTest (TraceSourceTest::DOUBLEB)); + resolver.AddSource ("trace-double-a", traceDoubleA, + TraceSourceTest (TraceSourceTest::DOUBLEA)); + resolver.AddSource ("trace-double-b", traceDoubleB, + TraceSourceTest (TraceSourceTest::DOUBLEB)); resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); @@ -461,7 +461,7 @@ CompositeTraceResolverTest::RunTests (void) } resolver.Add ("subresolver", - MakeCallback (&CompositeTraceResolverTest::CreateSubResolver, this)); + MakeCallback (&CompositeTraceResolverTest::CreateSubResolver, this)); resolver.Connect ("/subresolver/trace-int", MakeCallback (&CompositeTraceResolverTest::TraceInt, this), TraceContext ()); @@ -501,7 +501,7 @@ CompositeTraceResolverTest::RunTests (void) SVTraceSource source; - resolver.Add ("uint16_t", source, TraceSourceTest (TraceSourceTest::UINT16_T)); + resolver.AddSource ("uint16_t", source, TraceSourceTest (TraceSourceTest::UINT16_T)); return ok; diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 8c43e8f98..b5579c14e 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -53,8 +53,8 @@ public: * be automatically extended to contain the input context. */ template - void Add (std::string name, - TraceSource &trace, T const &context); + void AddSource (std::string name, + TraceSource &trace, T const &context); /** * \param name name of trace source * \param trace a callback trace source @@ -63,8 +63,8 @@ public: * source will match the name specified during namespace * resolution. */ - void Add (std::string name, - TraceSource &trace); + void AddSource (std::string name, + TraceSource &trace); /** * \param name name of child trace resolver * \param createResolver a trace resolver constructor @@ -140,9 +140,9 @@ namespace ns3 { template void -CompositeTraceResolver::Add (std::string name, - TraceSource &trace, - T const &context) +CompositeTraceResolver::AddSource (std::string name, + TraceSource &trace, + T const &context) { TraceContext ctx; ctx.Add (context); diff --git a/src/core/object.cc b/src/core/object.cc index c16a7db63..b820a5b7c 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -310,7 +310,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->Add ("basea-x", m_source); + resolver->AddSource ("basea-x", m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -334,7 +334,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->Add ("deriveda-x", m_sourceDerived); + resolver->AddSource ("deriveda-x", m_sourceDerived); resolver->SetParent (BaseA::GetTraceResolver ()); return resolver; } @@ -361,7 +361,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->Add ("baseb-x", m_source); + resolver->AddSource ("baseb-x", m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -385,7 +385,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->Add ("derivedb-x", m_sourceDerived); + resolver->AddSource ("derivedb-x", m_sourceDerived); resolver->SetParent (BaseB::GetTraceResolver ()); return resolver; } diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index fe5c0ba26..82b6b7db6 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -454,12 +454,12 @@ CsmaCdNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); - resolver->Add ("rx", - m_rxTrace, - CsmaCdTraceType (CsmaCdTraceType::RX)); - resolver->Add ("drop", - m_dropTrace, - CsmaCdTraceType (CsmaCdTraceType::DROP)); + resolver->AddSource ("rx", + m_rxTrace, + CsmaCdTraceType (CsmaCdTraceType::RX)); + resolver->AddSource ("drop", + m_dropTrace, + CsmaCdTraceType (CsmaCdTraceType::DROP)); resolver->SetParent (NetDevice::GetTraceResolver ()); return resolver; } 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 633fbe5c6..3b94b5bcf 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 @@ -193,9 +193,9 @@ PointToPointNetDevice::GetTraceResolver (void) { Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); - resolver->Add ("rx", - m_rxTrace, - PointToPointTraceType ()); + resolver->AddSource ("rx", + m_rxTrace, + PointToPointTraceType ()); resolver->SetParent (NetDevice::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 75320e886..2e3f4a421 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -152,9 +152,9 @@ Ptr Ipv4L3Protocol::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); - resolver->Add ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); - resolver->Add ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); + resolver->AddSource ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); + resolver->AddSource ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); + resolver->AddSource ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); resolver->AddArray ("interfaces", m_interfaces.begin (), m_interfaces.end (), Ipv4L3ProtocolInterfaceIndex ()); diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index adea6d771..ffab72953 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -44,7 +44,7 @@ MobilityModelNotifier::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("course-change", m_trace); + resolver->AddSource ("course-change", m_trace); return resolver; } diff --git a/src/node/queue.cc b/src/node/queue.cc index 78ad9369c..00b6f5387 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -98,9 +98,9 @@ Ptr Queue::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->Add ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); - resolver->Add ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); - resolver->Add ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); + resolver->AddSource ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); + resolver->AddSource ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); + resolver->AddSource ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } From 66d375b3b35f6ab2ccafc5367ececd0c4a0c10e4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 22:44:12 +0200 Subject: [PATCH 32/92] add forgotten virtual keyword --- src/core/fv-trace-source.h | 4 ++-- src/core/sv-trace-source.h | 4 ++-- src/core/uv-trace-source.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/fv-trace-source.h b/src/core/fv-trace-source.h index f305980a5..5b9f44df4 100644 --- a/src/core/fv-trace-source.h +++ b/src/core/fv-trace-source.h @@ -40,10 +40,10 @@ public: ~FVTraceSourceBase () {} - void AddCallback (CallbackBase const & callback, TraceContext const & context) { + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) { m_callback.AddCallback (callback, context); } - void RemoveCallback (CallbackBase const & callback) { + virtual void RemoveCallback (CallbackBase const & callback) { m_callback.RemoveCallback (callback); } protected: diff --git a/src/core/sv-trace-source.h b/src/core/sv-trace-source.h index d7038c0ad..7c2bd8818 100644 --- a/src/core/sv-trace-source.h +++ b/src/core/sv-trace-source.h @@ -40,10 +40,10 @@ public: virtual ~SVTraceSourceBase () {} - void AddCallback (CallbackBase const & callback, TraceContext const & context) { + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) { m_callback.AddCallback (callback, context); } - void RemoveCallback (CallbackBase const & callback) { + virtual void RemoveCallback (CallbackBase const & callback) { m_callback.RemoveCallback (callback); } protected: diff --git a/src/core/uv-trace-source.h b/src/core/uv-trace-source.h index 2216f2c98..55602e614 100644 --- a/src/core/uv-trace-source.h +++ b/src/core/uv-trace-source.h @@ -43,10 +43,10 @@ public: } ~UVTraceSourceBase () {} - void AddCallback (CallbackBase const & callback, TraceContext const & context) { + virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) { m_callback.AddCallback (callback, context); } - void RemoveCallback (CallbackBase const & callback) { + virtual void RemoveCallback (CallbackBase const & callback) { m_callback.RemoveCallback (callback); } From f90c3d03508ce4b144cd6d06131f8f8ea1337871 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 22:44:21 +0200 Subject: [PATCH 33/92] more tests --- src/core/object.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/object.cc b/src/core/object.cc index b820a5b7c..57f288cda 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -532,7 +532,31 @@ ObjectTest::RunTests (void) NS_TEST_ASSERT (m_baseATrace); baseA->TraceDisconnect ("/$BaseA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); - + Ptr derivedA; + derivedA = Create (1); + baseB = Create (); + derivedA->AddInterface (baseB); + baseB->TraceConnect ("/$DerivedA/deriveda-x", MakeCallback (&ObjectTest::DerivedATrace, this)); + baseB->TraceConnect ("/$DerivedA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + m_derivedATrace = false; + m_baseATrace = false; + derivedA->DerivedGenerateTrace (8); + derivedA->BaseGenerateTrace (9); + NS_TEST_ASSERT (m_derivedATrace); + NS_TEST_ASSERT (m_baseATrace); + baseB->TraceDisconnect ("/$DerivedA/deriveda-x", MakeCallback (&ObjectTest::BaseATrace, this)); + baseB->TraceDisconnect ("/$DerivedA/basea-x", MakeCallback (&ObjectTest::BaseATrace, this)); + + baseB->TraceConnect ("/$DerivedA/*", MakeCallback (&ObjectTest::DerivedATrace, this)); + m_derivedATrace = false; + derivedA->DerivedGenerateTrace (10); + NS_TEST_ASSERT (m_derivedATrace); + // here, we have connected the derived trace sink to all + // trace sources, including the base trace source. + m_derivedATrace = false; + derivedA->BaseGenerateTrace (11); + NS_TEST_ASSERT (m_derivedATrace); + baseB->TraceDisconnect ("/$DerivedA/*", MakeCallback (&ObjectTest::BaseATrace, this)); return result; } From 6f9ab0dea5c99014c1ee25016ecd1fdb591b38ca Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sun, 12 Aug 2007 22:45:24 +0200 Subject: [PATCH 34/92] move includes down to where they are really needed --- src/core/object.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index 57f288cda..73ade0d61 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -22,9 +22,7 @@ #include "assert.h" #include "singleton.h" #include "uid-manager.h" -#include "sv-trace-source.h" #include "trace-resolver.h" -#include "composite-trace-resolver.h" #include namespace { @@ -292,6 +290,8 @@ Object::MaybeDelete (void) const #ifdef RUN_SELF_TESTS #include "test.h" +#include "sv-trace-source.h" +#include "composite-trace-resolver.h" namespace { From 9a836af0d06d2820a41eab68ee6427d2db36ef14 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 13:15:13 +0200 Subject: [PATCH 35/92] add image path --- doc/doxygen.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index fc6fd25fa..7d6248d95 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -514,7 +514,7 @@ EXAMPLE_RECURSIVE = NO # directories that contain image that are included in the documentation (see # the \image command). -IMAGE_PATH = +IMAGE_PATH = doc # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program From 3f159872c07c0df4819ea53e2a5d8b15830286e0 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 13:15:27 +0200 Subject: [PATCH 36/92] add operator << for Packet and TraceContext --- src/common/packet.cc | 6 ++++++ src/common/packet.h | 2 ++ src/core/trace-context.cc | 6 ++++++ src/core/trace-context.h | 2 ++ 4 files changed, 16 insertions(+) diff --git a/src/common/packet.cc b/src/common/packet.cc index 4c1a3b87d..966b2b879 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -199,6 +199,12 @@ Packet::Deserialize (Buffer buffer) buffer.RemoveAtStart (metadataDeserialized); } +std::ostream& operator<< (std::ostream& os, const Packet &packet) +{ + packet.Print (os); + return os; +} + } // namespace ns3 diff --git a/src/common/packet.h b/src/common/packet.h index 00c540600..f1e14cf02 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -328,6 +328,8 @@ private: static uint32_t m_globalUid; }; +std::ostream& operator<< (std::ostream& os, const Packet &packet); + /** * \defgroup packetperf Packet Performance * The current implementation of the byte buffers and tag list is based diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index 3082f50b5..1dbcf856e 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -231,6 +231,12 @@ TraceContext::Print (std::ostream &os) const } while (true); } +std::ostream& operator<< (std::ostream& os, const TraceContext &context) +{ + context.Print (os); + return os; +} + }//namespace ns3 #include "test.h" diff --git a/src/core/trace-context.h b/src/core/trace-context.h index d33ee2fda..78114732e 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -99,6 +99,8 @@ private: } * m_data; }; +std::ostream& operator<< (std::ostream& os, const TraceContext &context); + }//namespace ns3 namespace ns3 { From c1b38a92039f4048e56c1dd1900f68bdb76a603c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 13:21:59 +0200 Subject: [PATCH 37/92] rename TraceContext::Add to AddElement and Union --- src/core/array-trace-resolver.h | 2 +- src/core/callback-trace-source.h | 2 +- src/core/composite-trace-resolver.cc | 2 +- src/core/composite-trace-resolver.h | 4 ++-- src/core/trace-context.cc | 16 ++++++++-------- src/core/trace-context.h | 10 +++++----- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index 3ba7147c5..116c875ab 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -137,7 +137,7 @@ ArrayTraceResolver::Connect (std::string path, CallbackBase const &cb, co { TraceContext tmp = context; INDEX index = j; - tmp.Add (index); + tmp.AddElement (index); Ptr obj = m_iter->Get (); obj->TraceConnect (subpath, cb, tmp); j++; diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index beeec7045..4b5f61b93 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -75,7 +75,7 @@ CallbackTraceSource::AddCallback (CallbackBase const & callback, { Callback cb; cb.Assign (callback); - m_context.Add (context); + m_context.Union (context); m_callbackList.push_back (cb); } template - */ -#include "trace-root.h" -#include "composite-trace-resolver.h" -#include "trace-context.h" - -namespace ns3 { - -void -TraceRoot::Connect (std::string path, CallbackBase const &cb) -{ - Ptr resolver = GetComposite (); - resolver->Connect (path, cb, TraceContext ()); -} -void -TraceRoot::Disconnect (std::string path, CallbackBase const &cb) -{ - Ptr resolver = GetComposite (); - resolver->Disconnect (path, cb); -} -void -TraceRoot::Register (std::string name, - Callback > createResolver) -{ - Ptr resolver = GetComposite (); - resolver->Add (name, createResolver); -} - -Ptr -TraceRoot::GetComposite (void) -{ - static CompositeTraceResolver resolver; - return &resolver; -} - -} // namespace ns3 diff --git a/src/core/trace-root.h b/src/core/trace-root.h deleted file mode 100644 index eb3ddc2ea..000000000 --- a/src/core/trace-root.h +++ /dev/null @@ -1,335 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 TRACE_ROOT_H -#define TRACE_ROOT_H - -#include -#include "callback.h" - -/** - * \defgroup lowleveltracing Low-level tracing - * - * This low-level API is built around a few concepts: - * - There can be any number of trace source objects. Each trace source - * object can generate any number of trace events. The current - * trace source objects are: ns3::CallbackTraceSourceSource, ns3::UVTraceSource, - * ns3::SVTraceSource, and, ns3::FVTraceSource. - * - Each trace source can be connected to any number of trace sinks. - * A trace sink is a ns3::Callback with a very special signature. Its - * first argument is always a ns3::TraceContext. - * - Every trace source is uniquely identified by a ns3::TraceContext. Every - * trace sink can query a ns3::TraceContext for information. This allows - * a trace sink which is connected to multiple trace sources to identify - * from which source each event is coming from. - * - * To define new trace sources, a model author needs to instante one trace source - * object for each kind of tracing event he wants to export. The trace source objects - * currently defined are: - * - ns3::CallbackTraceSourceSource: this trace source can be used to convey any kind of - * trace event to the user. It is a functor, that is, it is a variable - * which behaves like a function which will forward every event to every - * connected trace sink (i.e., ns3::Callback). This trace source takes - * up to four arguments and forwards these 4 arguments together with the - * ns3::TraceContext which identifies this trace source to the connected - * trace sinks. - * - ns3::UVTraceSource: this trace source is used to convey key state variable - * changes to the user. It behaves like a normal integer unsigned variable: - * you can apply every normal arithmetic operator to it. It will forward - * every change in the value of the variable back to every connected trace - * sink by providing a TraceContext, the old value and the new value. - * - ns3::SVTraceSource: this is the signed integer equivalent of - * ns3::UVTraceSource. - * - ns3::FVTraceSource: this is the floating point equivalent of - * ns3::UVTraceSource and ns3::SVTraceSource. - * - * For example, to define a trace source which notifies you of a new packet - * being transmitted, you would have to: - * \code - * class MyModel - * { - * public: - * void Tx (Packet const &p); - * private: - * CallbackTraceSource m_txTrace; - * }; - * - * void - * MyModel::Tx (Packet const &p) - * { - * // trace packet tx event. - * m_txTrace (p); - * // ... send the packet for real. - * } - * \endcode - * - * Once the model author has instantiated these objects and has wired them - * in his simulation code (that is, he calls them wherever he wants to trigger - * a trace event), he needs to make these trace sources available to users - * to allow them to connect any number of trace sources to any number - * of user trace sinks. While it would be possible to make each model - * export directly each of his trace source instances and request users to - * invoke a source->Connect (callback) method to perform the connection - * explicitely, it was felt that this was a bit cumbersome to do. - * - * As such, the ``connection'' between a set of sources and a sink is - * performed through a third-party class, the TraceResolver, which - * can be used to automate the connection of multiple matching trace sources - * to a single sink. This TraceResolver works by defining a hierarchical - * tracing namespace: the root of this namespace is accessed through the - * ns3::TraceRoot class. The namespace is represented as a string made of - * multiple elements, each of which is separated from the other elements - * by the '/' character. A namespace string always starts with a '/'. - * - * By default, the current simulation models provide a '/nodes' tracing root. - * This '/nodes' namespace is structured as follows: - * \code - * /nodes/n/arp - * /nodes/n/udp - * /nodes/n/ipv4 - * /tx - * /rx - * /drop - * /interfaces/n/netdevice - * /queue/ - * /enque - * /deque - * /drop - * \endcode - * - * The 'n' element which follows the /nodes and /interfaces namespace elements - * identify a specific node and interface through their index within the - * ns3::NodeList and ns3::Ipv4 objects respectively. - * - * To connect a trace sink to a trace source identified by a namespace string, - * a user can call the ns3::TraceRoot::Connect method (the ns3::TraceRoot::Disconnect - * method does the symmetric operation). This connection method can accept - * fully-detailed namespace strings but it can also perform pattern matching - * on the user-provided namespace strings to connect multiple trace sources - * to a single trace sink in a single connection operation. - * - * The syntax of the pattern matching rules are loosely based on regular - * expressions: - * - the '*' character matches every element - * - the (a|b) construct matches element 'a' or 'b' - * - the [ss-ee] construct matches all numerical values which belong - * to the interval which includes ss and ee - * - * For example, the user could use the following to connect a single sink - * to the ipv4 tx, rx, and drop trace events: - * - * \code - * void MyTraceSink (TraceContext const &context, Packet &packet); - * TraceRoot::Connect ("/nodes/ * /ipv4/ *", MakeCallback (&MyTraceSink)); - * \endcode - * - * Of course, this code would work only if the signature of the trace sink - * is exactly equal to the signature of all the trace sources which match - * the namespace string (if one of the matching trace source does not match - * exactly, a fatal error will be triggered at runtime during the connection - * process). The ns3::TraceContext extra argument contains - * information on where the trace source is located in the namespace tree. - * In that example, if there are multiple nodes in this scenario, each - * call to the MyTraceSink function would receive a different TraceContext, - * each of which would contain a different NodeList::NodeIndex object. - * - * It is important to understand exactly what an ns3::TraceContext - * is. It is a container for a number of type instances. Each instance of - * a ns3::TraceContext contains one and only one instance of a given type. - * ns3::TraceContext::Add can be called to add a type instance into a - * TraceContext instance and ns3::TraceContext::Get can be called to get - * a copy of a type instance stored into the ns3::TraceContext. If ::Get - * cannot retrieve the requested type, a fatal error is triggered at - * runtime. The values stored into an ns3::TraceContext attached to a - * trace source are automatically determined during the namespace - * resolution process. To retrieve a value from a ns3::TraceContext, the - * code can be as simple as this: - * \code - * void MyTraceSink (TraceContext const &context, Packet &packet) - * { - * NodeList::NodeIndex index; - * context.Get (index); - * std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl; - * } - * \endcode - * - * The hierarchical global namespace described here is not implemented - * in a single central location: it was felt that doing this would make - * it too hard to introduce user-specific models which could hook - * automatically into the overal tracing system. If the tracing - * namespace was implemented in a single central location, every model - * author would have had to modify this central component to make - * his own model available to trace users. - * - * Instead, the handling of the namespace is distributed across every relevant - * model: every model implements only the part of the namespace it is - * really responsible for. To do this, every model is expected - * to provide an instance of a TraceResolver whose - * responsability is to recursively provide access to the trace sources - * defined in its model. Each TraceResolver instance should be a subclass - * of the TraceResolver base class which implements either the DoLookup - * or the DoConnect and DoDisconnect methods. Because implementing these - * methods can be a bit tedious, our tracing framework provides a number - * of helper template classes which should save the model author from - * having to implement his own in most cases: - * - ns3::CompositeTraceResolver: this subclass of ns3::TraceResolver can - * be used to aggregate together multiple trace sources and multiple other - * ns3::TraceResolver instances. - * - ns3::ArrayTraceResolver: this subclass of ns3::TraceResolver can be - * used to match any number of elements within an array where every element - * is identified by its index. - * - * Once you can instantiate your own ns3::TraceResolver object instance, you - * have to hook it up into the global namespace. There are two ways to do this: - * - you can hook your ns3::TraceResolver creation method as a new trace - * root by using the ns3::TraceRoot::Register method - * - you can hook your new ns3::TraceResolver creation method into the - * container of your model. This step will obvsiouly depend on which model - * contains your own model but, if you wrote a new l3 protocol, all you - * would have to do to hook into your container L3Demux class is to implement - * the pure virtual method inherited from the L3Protocol class whose name is - * ns3::L3protocol::CreateTraceResolver. - * - * So, in most cases, exporting a model's trace sources is a matter of - * implementing a method CreateTraceResolver as shown below: - * \code - * class MyModel - * { - * public: - * enum TraceType { - * TX, - * RX, - * ... - * }; - * TraceResolver *CreateTraceResolver (TraceContext const &context); - * void Tx (Packet const &p); - * private: - * CallbackTraceSource m_txTrace; - * }; - * - * TraceResolver * - * MyModel::CreateTraceResolver (TraceContext const &context) - * { - * CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - * resolver->Add ("tx", m_txTrace, MyModel::TX); - * return resolver; - * } - * void - * MyModel::Tx (Packet const &p) - * { - * m_txTrace (p); - * } - * \endcode - * - * If you really want to have fun and implement your own ns3::TraceResolver - * subclass, you need to understand the basic Connection and Disconnection - * algorithm. The code of that algorithm is wholy contained in the - * ns3::TraceResolver::Connect and ns3::TraceResolver::Disconnect methods. - * The idea is that we recursively parse the input namespace string by removing - * the first namespace element. This element is 'resolved' is calling - * the ns3::TraceResolver::DoLookup method which returns a list of - * TraceResolver instances. Each of the returned TraceResolver instance is - * then given what is left of the namespace by calling ns3::TraceResolver::Connect - * until the last namespace element is processed. At this point, we invoke - * the ns3::TraceResolver::DoConnect or ns3::TraceResolver::DoDisconnect - * methods to break the recursion. A good way to understand this algorithm - * is to trace its behavior. Let's say that you want to connect to - * '/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *'. It would generate - * the following call traces: - * - * \code - * TraceRoot::Connect ("/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback); - * traceContext = TraceContext (); - * rootResolver = CompositeTraceResolver (traceContext); - * rootResolver->Connect ("/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback); - * resolver = CompositeTraceResolver::DoLookup ("nodes"); - * return NodeList::CreateTraceResolver (GetContext ()); - * return ArrayTraceResolver (context); - * resolver->Connect ("/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback); - * ArrayTraceResolver::DoLookup ("*"); - * for (i = 0; i < n_nodes; i++) - * resolver = nodes[i]->CreateTraceResolver (GetContext ()); - * return CompositeTraceResolver (context); - * resolvers.add (resolver); - * return resolvers; - * for resolver in (resolvers) - * resolver->Connect ("/ipv4/interfaces/ * /netdevice/queue/ *", callback); - * CompositeTraceResolver::DoLookup ("ipv4"); - * resolver = ipv4->CreateTraceResolver (GetContext ()); - * return CompositeTraceResolver (context); - * return resolver; - * resolver->Connect ("/interfaces/ * /netdevice/queue/ *", callback); - * CompositeTraceResolver::DoLookup ("interfaces"); - * resolver = ArrayTraceResolver (GetContext ()); - * resolver->Connect ("/ * /netdevice/queue/ *", callback); - * ArrayTraceResolver::DoLookup ("*"); - * for (i = 0; i < n_interfaces; i++) - * resolver = interfaces[i]->CreateTraceResolver (GetContext ()); - * return CompositeTraceResolver () - * resolvers.add (resolver); - * return resolvers; - * resolver->Connect ("/netdevice/queue/ *", callback); - * CompositeTraceResolver::DoLookup ("netdevice"); - * resolver = NetDevice::CreateTraceResolver (GetContext ()); - * return CompositeTraceResolver (); - * return resolver; - * resolver->Connect ("/queue/ *", callback); - * CompositeTraceResolver::DoLookup ("queue"); - * resolver = Queue::CreateTraceResolver (GetContext ()); - * return CompositeTraceResolver (); - * return resolver - * resolver->Connect ("*", callback); - * CompositeTraceResolver::DoLookup ("*"); - * for match in (matches) - * resolver = TerminalTraceResolver ("match"); - * resolvers.add (resolver) - * return resolvers; - * for resolver in (resolvers) - * TerminalTraceResolver->DoConnect (callback); - * \endcode - */ - -namespace ns3 { - -class CompositeTraceResolver; -class TraceResolver; -class TraceContext; -class CallbackBase; - -/** - * \brief The main class used to access tracing functionality for - * a user. - * - * \ingroup lowleveltracing - */ -class TraceRoot -{ -public: - static void Connect (std::string path, CallbackBase const &cb); - static void Disconnect (std::string path, CallbackBase const &cb); - static void Register (std::string name, - Callback > createResolver); -private: - static Ptr GetComposite (void); -}; - -}// namespace ns3 - -#endif /* TRACE_ROOT_H */ diff --git a/src/core/wscript b/src/core/wscript index ea91c7619..dacab2c32 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -49,7 +49,6 @@ def build(bld): 'callback-trace-source.cc', 'empty-trace-resolver.cc', 'composite-trace-resolver.cc', - 'trace-root.cc', ] if sys.platform == 'win32': @@ -92,6 +91,5 @@ def build(bld): 'empty-trace-resolver.h', 'composite-trace-resolver.h', 'array-trace-resolver.h', - 'trace-root.h', ] diff --git a/src/internet-node/ascii-trace.cc b/src/internet-node/ascii-trace.cc index cb48f06fc..582a37854 100644 --- a/src/internet-node/ascii-trace.cc +++ b/src/internet-node/ascii-trace.cc @@ -21,9 +21,9 @@ #include "ascii-trace.h" #include "ns3/trace-context.h" -#include "ns3/trace-root.h" #include "ns3/simulator.h" #include "ns3/node.h" +#include "ns3/node-list.h" #include "ns3/packet.h" namespace ns3 { @@ -40,15 +40,15 @@ void AsciiTrace::TraceAllQueues (void) { Packet::EnableMetadata (); - TraceRoot::Connect ("/nodes/*/devices/*/queue/*", - MakeCallback (&AsciiTrace::LogDevQueue, this)); + NodeList::Connect ("/nodes/*/devices/*/queue/*", + MakeCallback (&AsciiTrace::LogDevQueue, this)); } void AsciiTrace::TraceAllNetDeviceRx (void) { Packet::EnableMetadata (); - TraceRoot::Connect ("/nodes/*/devices/*/rx", - MakeCallback (&AsciiTrace::LogDevRx, this)); + NodeList::Connect ("/nodes/*/devices/*/rx", + MakeCallback (&AsciiTrace::LogDevRx, this)); } void diff --git a/src/internet-node/pcap-trace.cc b/src/internet-node/pcap-trace.cc index 240100fb5..dd0b39a29 100644 --- a/src/internet-node/pcap-trace.cc +++ b/src/internet-node/pcap-trace.cc @@ -22,7 +22,7 @@ #include -#include "ns3/trace-root.h" +#include "ns3/node-list.h" #include "ns3/trace-context.h" #include "ns3/callback.h" #include "ns3/pcap-writer.h" @@ -50,8 +50,8 @@ PcapTrace::~PcapTrace () void PcapTrace::TraceAllIp (void) { - TraceRoot::Connect ("/nodes/*/ipv4/(tx|rx)", - MakeCallback (&PcapTrace::LogIp, this)); + NodeList::Connect ("/nodes/*/ipv4/(tx|rx)", + MakeCallback (&PcapTrace::LogIp, this)); } PcapWriter * diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 1b74dbe86..4fd63ed81 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -20,24 +20,12 @@ * Mathieu Lacage , */ -#include "ns3/array-trace-resolver.h" -#include "ns3/trace-root.h" +#include "ns3/composite-trace-resolver.h" #include "ns3/simulator.h" #include "ns3/simulation-singleton.h" #include "node-list.h" #include "node.h" -namespace { -static class Initialization -{ -public: - Initialization () - { - ns3::TraceRoot::Register ("nodes", ns3::MakeCallback (&ns3::NodeList::GetTraceResolver)); - } -} g_initialization; -} - namespace ns3 { NodeListIndex::NodeListIndex () @@ -133,9 +121,8 @@ NodeListPriv::GetNode (uint32_t n) Ptr NodeListPriv::GetTraceResolver (void) { - Ptr >resolver = - Create > (); - resolver->SetIterators (Begin (), End ()); + Ptr resolver = Create (); + resolver->AddArray ("nodes", Begin (), End (), NodeListIndex ()); return resolver; } @@ -163,17 +150,21 @@ NodeList::End (void) { return SimulationSingleton::Get ()->End (); } -Ptr -NodeList::GetTraceResolver (void) -{ - return SimulationSingleton::Get ()->GetTraceResolver (); -} Ptr NodeList::GetNode (uint32_t n) { return SimulationSingleton::Get ()->GetNode (n); } - +void +NodeList::Connect (std::string name, const CallbackBase &cb) +{ + SimulationSingleton::Get ()->GetTraceResolver ()->Connect (name, cb, TraceContext ()); +} +void +NodeList::Disconnect (std::string name, const CallbackBase &cb) +{ + SimulationSingleton::Get ()->GetTraceResolver ()->Disconnect (name, cb); +} }//namespace ns3 diff --git a/src/node/node-list.h b/src/node/node-list.h index 8af457b88..d40587094 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -29,8 +29,7 @@ namespace ns3 { class Node; -class TraceResolver; -class TraceContext; +class CallbackBase; class NodeListIndex : public TraceContextElement { @@ -73,19 +72,28 @@ public: * list. */ static Iterator End (void); - /** - * \param context trace context to use for trace resolver - * to create. - * \returns the requested trace resolver. The caller - * takes ownership of the returned pointer. - */ - static Ptr GetTraceResolver (void); - /** * \param n index of requested node. * \returns the Node associated to index n. */ static Ptr GetNode (uint32_t n); + /** + * \param name namespace regexp to match + * \param cb callback to connect + * + * Connect input callback to all trace sources which match + * the input namespace regexp. + */ + static void Connect (std::string name, const CallbackBase &cb); + /** + * \param name namespace regexp to match + * \param cb callback to connect + * + * Disconnect input callback from all trace sources which match + * the input namespace regexp. + */ + static void Disconnect (std::string name, const CallbackBase &cb); +private: }; }//namespace ns3 From 669ce539dd8f45a30b9e412db8ae73340c574683 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 14:06:11 +0200 Subject: [PATCH 39/92] cleanup a bit --- src/core/trace-resolver.cc | 9 ------- src/core/trace-resolver.h | 54 ++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index b92bc785f..4d4e4078a 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -48,15 +48,6 @@ TraceResolver::Unref (void) } } - -void -TraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) -{} - -void -TraceResolver::Disconnect (std::string path, CallbackBase const &cb) -{} - std::string TraceResolver::GetElement (std::string path) { diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 78a3a0a4b..f22b73352 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -30,22 +30,14 @@ namespace ns3 { class CallbackBase; /** - * \brief the base class which is used to incremental perform trace + * \brief the base class which is used to recursively perform trace * namespace resolution. - * \ingroup lowleveltracing + * \ingroup tracing * - * This class provides a public API to the ns3::TraceRoot object: - * - ns3::TraceResolver::Connect - * - ns3::TraceResolver::Disconnect - * - * It also provides an API for its subclasses. Each subclass should - * implement one of: - * - ns3::TraceResolver::DoLookup - * - ns3::TraceResolver::DoConnect and ns3::TraceResolver::DoDisconnect - * Each subclass must also provide an ns3::TraceContext to the TraceResolver - * constructor. Finally, each subclass can access the ns3::TraceContext - * associated to this ns3::TraceResolver through the - * ns3::TraceResolver::GetContext method. + * Subclasses must implement the two pure virtal methods defined in + * this base class: + * - ns3::TraceResolver::Connect + * - ns3::TraceResolver::Disconnect. */ class TraceResolver { @@ -59,24 +51,42 @@ public: /** * \param path the namespace path to resolver * \param cb the callback to connect to the matching namespace + * \param context the context in which to store the trace context * - * This method is typically invoked by ns3::TraceRoot but advanced - * users could also conceivably call it directly if they want to - * skip the ns3::TraceRoot. + * First, extract the leading path element from the input path, and + * match this leading patch element against any terminal trace source + * contained in this trace resolver. + * Second, recursively resolve the rest of the path using other + * objects if there are any. + * If there is any TraceContextElement associated to one of the matching + * elements, it should be added to the input TraceContext. */ - virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); + virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context) = 0; /** * \param path the namespace path to resolver * \param cb the callback to disconnect in the matching namespace * - * This method is typically invoked by ns3::TraceRoot but advanced - * users could also conceivably call it directly if they want to - * skip the ns3::TraceRoot. + * This method should behave as Connect. */ - virtual void Disconnect (std::string path, CallbackBase const &cb); + virtual void Disconnect (std::string path, CallbackBase const &cb) = 0; protected: + /** + * \param path a namespace path + * \returns the initial element of the path. + * + * If the input path is "/foo/...", the return + * value is "foo". + */ std::string GetElement (std::string path); + /** + * \param path a namespace path + * \returns the subpath. + * + * If the input path is "/foo/bar/...", the return + * value is "/bar/...". + */ std::string GetSubpath (std::string path); +private: uint32_t m_count; }; From 90c8be1fa3ec68c669e5761bce5f47d698623d05 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 14:59:50 +0200 Subject: [PATCH 40/92] add TraceContextElement::GetName method --- src/core/composite-trace-resolver.cc | 2 ++ src/core/trace-context-element.cc | 7 +++++++ src/core/trace-context-element.h | 13 +++++++++++++ src/devices/csma-cd/csma-cd-net-device.cc | 5 +++++ src/devices/csma-cd/csma-cd-net-device.h | 1 + .../point-to-point/point-to-point-net-device.cc | 5 +++++ .../point-to-point/point-to-point-net-device.h | 1 + src/internet-node/ipv4-l3-protocol.cc | 10 ++++++++++ src/internet-node/ipv4-l3-protocol.h | 2 ++ src/internet-node/ipv4-l4-demux.cc | 5 +++++ src/internet-node/ipv4-l4-demux.h | 1 + src/node/node-list.cc | 5 +++++ src/node/node-list.h | 1 + src/node/node.cc | 5 +++++ src/node/node.h | 1 + src/node/queue.cc | 5 +++++ src/node/queue.h | 1 + 17 files changed, 70 insertions(+) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 308544868..edf1e9c26 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -273,6 +273,7 @@ public: else if (m_sources == DOUBLEB) {os << "doubleB";} else if (m_sources == UINT16_T) {os << "uint16_t";} } + std::string GetName (void) {return "TraceSourceTest";} TraceSourceTest () : m_sources (TraceSourceTest::DOUBLEA) {} TraceSourceTest (enum Sources sources) :m_sources (sources) {} bool IsDoubleA (void) const {return m_sources == TraceSourceTest::DOUBLEA;} @@ -292,6 +293,7 @@ public: {static uint16_t uid = AllocateUid ("SubTraceSourceTest"); return uid;} void Print (std::ostream &os) {os << "subtracesource=int";} + std::string GetName (void) const {return "SubTraceSourceTest";} SubTraceSourceTest () : m_sources (SubTraceSourceTest::INT) {} SubTraceSourceTest (enum Sources sources) : m_sources (sources) {} private: diff --git a/src/core/trace-context-element.cc b/src/core/trace-context-element.cc index 838250af8..24b02fd23 100644 --- a/src/core/trace-context-element.cc +++ b/src/core/trace-context-element.cc @@ -2,6 +2,13 @@ namespace ns3 { +std::string +ElementRegistry::GetName (uint16_t uid) +{ + InfoVector *vec = GetInfoVector (); + struct Info info = (*vec)[uid - 1]; + return info.getName (); +} uint32_t ElementRegistry::GetSize (uint16_t uid) { diff --git a/src/core/trace-context-element.h b/src/core/trace-context-element.h index e1c36c4d9..fa945294d 100644 --- a/src/core/trace-context-element.h +++ b/src/core/trace-context-element.h @@ -115,19 +115,24 @@ public: static uint32_t GetSize (uint16_t uid); static void Print (uint16_t uid, uint8_t *instance, std::ostream &os); + static std::string GetName (uint16_t uid); static void Destroy (uint16_t uid, uint8_t *instance); private: + typedef std::string (*GetNameCb) (void); typedef void (*PrintCb) (uint8_t *instance, std::ostream &os); typedef void (*DestroyCb) (uint8_t *instance); struct Info { uint32_t size; std::string uidString; + GetNameCb getName; PrintCb print; DestroyCb destroy; }; typedef std::vector InfoVector; static InfoVector *GetInfoVector (void); template + static std::string DoGetName (void); + template static void DoPrint (uint8_t *instance, std::ostream &os); template static void DoDestroy (uint8_t *instance); @@ -143,6 +148,13 @@ ElementRegistry::DoPrint (uint8_t *instance, std::ostream &os) obj.Print (os); } template +std::string +ElementRegistry::DoGetName (void) +{ + static T obj; + return obj.GetName (); +} +template void ElementRegistry::DoDestroy (uint8_t *instance) { @@ -169,6 +181,7 @@ ElementRegistry::AllocateUid (std::string name) struct Info info; info.size = sizeof (T); info.uidString = name; + info.getName = &ElementRegistry::DoGetName; info.print = &ElementRegistry::DoPrint; info.destroy = &ElementRegistry::DoDestroy; vec->push_back (info); diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index 82b6b7db6..6454ae724 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -59,6 +59,11 @@ CsmaCdTraceType::GetUid (void) static uint16_t uid = AllocateUid ("CsmaCdTraceType"); return uid; } +std::string +CsmaCdTraceType::GetName (void) const +{ + return "CsmaCdTraceType"; +} CsmaCdNetDevice::CsmaCdNetDevice (Ptr node) diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma-cd/csma-cd-net-device.h index 5de056109..9348674a2 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma-cd/csma-cd-net-device.h @@ -52,6 +52,7 @@ public: CsmaCdTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); + std::string GetName (void) const; private: enum Type m_type; }; 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 3b94b5bcf..4d7e89e7c 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 @@ -53,6 +53,11 @@ PointToPointTraceType::GetUid (void) static uint16_t uid = AllocateUid ("PointToPointTraceType"); return uid; } +std::string +PointToPointTraceType::GetName (void) const +{ + return "PointToPointTraceType"; +} PointToPointNetDevice::PointToPointNetDevice (Ptr node, 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 5cee2cf70..9844699af 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 @@ -44,6 +44,7 @@ public: PointToPointTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); + std::string GetName (void) const; }; /** diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 2e3f4a421..d01034ef2 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -87,6 +87,11 @@ Ipv4L3ProtocolTraceContextElement::GetUid (void) static uint16_t uid = AllocateUid ("Ipv4L3ProtocolTraceContextElement"); return uid; } +std::string +Ipv4L3ProtocolTraceContextElement::GetName (void) const +{ + return "Ipv4L3ProtocolTraceContextElement"; +} Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex () @@ -111,6 +116,11 @@ Ipv4L3ProtocolInterfaceIndex::GetUid (void) static uint16_t uid = AllocateUid ("Ipv4L3ProtocolInterfaceIndex"); return uid; } +std::string +Ipv4L3ProtocolInterfaceIndex::GetName (void) const +{ + return "Ipv4L3ProtocolInterfaceIndex"; +} Ipv4L3Protocol::Ipv4L3Protocol(Ptr node) diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index 0866861c0..ad9d482d2 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -59,6 +59,7 @@ public: bool IsDrop (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); + std::string GetName (void) const; private: enum Type m_type; }; @@ -71,6 +72,7 @@ public: uint32_t Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); + std::string GetName (void) const; private: uint32_t m_index; }; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 74ee536b5..120b3f47e 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -54,6 +54,11 @@ Ipv4L4ProtocolTraceContextElement::GetUid (void) static uint16_t uid = AllocateUid ("Ipv4L4ProtocolTraceContextElement"); return uid; } +std::string +Ipv4L4ProtocolTraceContextElement::GetName (void) const +{ + return "Ipv4L4ProtocolTraceContextElement"; +} Ipv4L4Demux::Ipv4L4Demux (Ptr node) diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 4700ec697..efd91bd44 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -45,6 +45,7 @@ public: int Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); + std::string GetName (void) const; private: int m_protocolNumber; }; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 4fd63ed81..2276c0da3 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -50,6 +50,11 @@ NodeListIndex::Get (void) const { return m_index; } +std::string +NodeListIndex::GetName (void) const +{ + return "NodeListIndex"; +} /** diff --git a/src/node/node-list.h b/src/node/node-list.h index d40587094..6774d8ce7 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -39,6 +39,7 @@ public: void Print (std::ostream &os); static uint16_t GetUid (void); uint32_t Get (void) const; + std::string GetName (void) const; private: uint32_t m_index; }; diff --git a/src/node/node.cc b/src/node/node.cc index 031ed34ab..52231fa1b 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -52,6 +52,11 @@ NodeNetDeviceIndex::GetUid (void) static uint16_t uid = AllocateUid ("NodeNetDeviceIndex"); return uid; } +std::string +NodeNetDeviceIndex::GetName (void) const +{ + return "NodeNetDeviceIndex"; +} diff --git a/src/node/node.h b/src/node/node.h index 0066bf319..062f259c6 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -44,6 +44,7 @@ public: NodeNetDeviceIndex (uint32_t index); uint32_t Get (void) const; void Print (std::ostream &os) const; + std::string GetName (void) const; static uint16_t GetUid (void); private: uint32_t m_index; diff --git a/src/node/queue.cc b/src/node/queue.cc index 00b6f5387..10bcc1c04 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -32,6 +32,11 @@ static ClassIdDefaultValue g_classIdDefaultValue ("Queue", "Packet Queue", Queue::iid, "DropTailQueue"); +std::string +QueueTraceType::GetName (void) const +{ + return "QueueTraceType"; +} uint16_t QueueTraceType::GetUid (void) { diff --git a/src/node/queue.h b/src/node/queue.h index c10795c67..f10191fad 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -52,6 +52,7 @@ public: bool IsDequeue (void) const; bool IsDrop (void) const; void Print (std::ostream &os) const; + std::string GetName (void) const; private: enum Type m_type; }; From e366a6eed4c845836751af8e65f422acd841d47e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 15:07:39 +0200 Subject: [PATCH 41/92] remove dead code --- src/core/empty-trace-resolver.cc | 24 --------- src/core/empty-trace-resolver.h | 52 -------------------- src/core/wscript | 2 - src/internet-node/arp-l3-protocol.cc | 1 - src/internet-node/ipv4-loopback-interface.cc | 1 - src/internet-node/udp-l4-protocol.cc | 1 - 6 files changed, 81 deletions(-) delete mode 100644 src/core/empty-trace-resolver.cc delete mode 100644 src/core/empty-trace-resolver.h diff --git a/src/core/empty-trace-resolver.cc b/src/core/empty-trace-resolver.cc deleted file mode 100644 index dc3478864..000000000 --- a/src/core/empty-trace-resolver.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 "empty-trace-resolver.h" - -ns3::EmptyTraceResolver::EmptyTraceResolver () -{} diff --git a/src/core/empty-trace-resolver.h b/src/core/empty-trace-resolver.h deleted file mode 100644 index 1e5ddab46..000000000 --- a/src/core/empty-trace-resolver.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 EMPTY_TRACE_RESOLVER_H -#define EMPTY_TRACE_RESOLVER_H - -#include "trace-resolver.h" - -namespace ns3 { - -class TraceContext; - -/** - * \brief a TraceResolver instance which does not resolve anything. - * \ingroup tracing - * - * Trying to resolve against this class will yield no matches and no - * connections. Returning an instance of this class from a - * CreateTraceResolver method is a hand way of not implementing - * any Tracing code. - */ -class EmptyTraceResolver : public TraceResolver -{ -public: - /** - * \param o necessary context for this class. - * - * The only constructor exported by this class. - */ - EmptyTraceResolver (); -}; - -}//namespace ns3 - -#endif /* EMPTY_TRACE_RESOLVER_H */ diff --git a/src/core/wscript b/src/core/wscript index dacab2c32..7d913eddc 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -47,7 +47,6 @@ def build(bld): 'trace-context-element.cc', 'trace-resolver.cc', 'callback-trace-source.cc', - 'empty-trace-resolver.cc', 'composite-trace-resolver.cc', ] @@ -88,7 +87,6 @@ def build(bld): 'trace-context.h', 'trace-context-element.h', 'trace-resolver.h', - 'empty-trace-resolver.h', 'composite-trace-resolver.h', 'array-trace-resolver.h', ] diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index b4d346e60..bcc62bfe2 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -20,7 +20,6 @@ */ #include "ns3/packet.h" #include "ns3/debug.h" -#include "ns3/empty-trace-resolver.h" #include "ns3/node.h" #include "ns3/net-device.h" diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index 307533d6e..d3bc45207 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -19,7 +19,6 @@ * Authors: * Mathieu Lacage , */ -#include "ns3/empty-trace-resolver.h" #include "ns3/net-device.h" #include "ns3/node.h" #include "ipv4-loopback-interface.h" diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index d9b5afe23..fc2a54dc9 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -21,7 +21,6 @@ #include "ns3/assert.h" #include "ns3/packet.h" -#include "ns3/empty-trace-resolver.h" #include "ns3/node.h" #include "udp-l4-protocol.h" From 3eeae9047288ae84b0b32945d7e7b87ba158eb39 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 15:34:57 +0200 Subject: [PATCH 42/92] replace enum with virtual class and subclasses --- src/core/composite-trace-resolver.cc | 106 ++++++++++++++------------- src/core/composite-trace-resolver.h | 22 ++---- 2 files changed, 62 insertions(+), 66 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index edf1e9c26..972867731 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -128,13 +128,35 @@ void CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { NS_DEBUG ("connect path="<name == id) { - OperationOne (subpath, i, cb, context, op); - DoRecursiveOperationForParent (path, cb, context, op); + operation.Do (subpath, *i); + operation.DoParent (path, m_parent); return; } } @@ -192,60 +214,40 @@ CompositeTraceResolver::DoRecursiveOperation (std::string path, { if ((*j)->name == *i) { - OperationOne (subpath, j, cb, context, op); + operation.Do (subpath, *j); break; } } } - DoRecursiveOperationForParent (path, cb, context, op); -} - -void -CompositeTraceResolver::DoRecursiveOperationForParent (std::string path, - const CallbackBase &cb, - const TraceContext &context, - enum Operation op) -{ - if (m_parent == 0) - { - return; - } - switch (op) { - case CONNECT: - m_parent->Connect (path, cb, context); - break; - case DISCONNECT: - m_parent->Disconnect (path, cb); - break; - } -} - -void -CompositeTraceResolver::OperationOne (std::string subpath, - TraceItems::const_iterator i, - const CallbackBase &cb, - const TraceContext &context, - enum Operation op) -{ - switch (op) { - case CONNECT: { - NS_DEBUG ("connect to path="<Rewind (); m_iter->HasNext (); m_iter->Next ()) + { + TraceContext tmp = context; + INDEX index = j; + tmp.AddElement (index); + Ptr obj = m_iter->Get (); + obj->GetTraceResolver ()->PrintAvailable (path, tmp, os); + j++; + } +} }//namespace ns3 diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 972867731..0c6ce941e 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -82,7 +82,14 @@ CompositeTraceResolver::DoAddSource (std::string name, {if (subpath == "") {trace->AddCallback (cb, context);}} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {if (subpath == "") {trace->RemoveCallback (cb);}} - + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + { + os << path << "/" << this->name << " ["; + TraceContext ctx = context; + ctx.Union (this->context); + ctx.PrintAvailable (os, ","); + os << "]" << std::endl; + } TraceSource *trace; } *item = new SourceCompositeItem (); item->name = name; @@ -106,9 +113,17 @@ CompositeTraceResolver::DoAddChild (std::string name, Ptr child, const T { public: virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {child->TraceConnect (subpath, cb, context);} + {child->GetTraceResolver ()->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {child->TraceDisconnect (subpath, cb);} + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + { + path.append ("/"); + path.append (this->name); + TraceContext ctx = context; + ctx.Union (this->context); + this->child->GetTraceResolver ()->PrintAvailable (path, ctx, os); + } Ptr child; } *item = new ChildCompositeItem (); @@ -249,6 +264,19 @@ CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb) } operation = DisconnectOperation (cb); DoRecursiveOperation (path, operation); } +void +CompositeTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) +{ + for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) + { + NS_DEBUG ("print " << (*i)->name); + (*i)->PrintAvailable (path, context, os); + } + if (m_parent != 0) + { + m_parent->PrintAvailable (path, context, os); + } +} }//namespace ns3 diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index ca16b75b7..3be3c332c 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -91,6 +91,7 @@ public: virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os); private: class CompositeItem @@ -99,6 +100,7 @@ private: virtual ~CompositeItem () {} virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) = 0; virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0; + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) {} std::string name; TraceContext context; @@ -155,7 +157,13 @@ CompositeTraceResolver::AddArray (std::string name, {array->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {array->Disconnect (subpath, cb);} - + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + { + path.append ("/"); + path.append (this->name); + TraceContext ctx = context; + ctx.Union (this->context); + array->PrintAvailable (path, ctx, os);} Ptr > array; } *item = new ArrayCompositeItem (); item->name = name; diff --git a/src/core/object.cc b/src/core/object.cc index 73ade0d61..bd2128c7c 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -63,6 +63,7 @@ public: InterfaceIdTraceResolver (Ptr aggregate); virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os); private: Ptr ParseForInterface (std::string path); Ptr m_aggregate; @@ -91,7 +92,7 @@ InterfaceIdTraceResolver::Connect (std::string path, CallbackBase const &cb, con Ptr interface = ParseForInterface (path); if (interface != 0) { - interface->TraceConnect (GetSubpath (path), cb, context); + interface->GetTraceResolver ()->Connect (GetSubpath (path), cb, context); } } void @@ -103,6 +104,11 @@ InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb) interface->TraceDisconnect (GetSubpath (path), cb); } } +void +InterfaceIdTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) +{ + +} InterfaceId::InterfaceId (uint16_t iid) @@ -216,12 +222,7 @@ Object::AddInterface (Ptr o) void Object::TraceConnect (std::string path, const CallbackBase &cb) { - TraceConnect (path, cb, TraceContext ()); -} -void -Object::TraceConnect (std::string path, const CallbackBase &cb, const TraceContext &context) -{ - GetTraceResolver ()->Connect (path, cb, context); + GetTraceResolver ()->Connect (path, cb, TraceContext ()); } void Object::TraceDisconnect (std::string path, const CallbackBase &cb) @@ -229,7 +230,6 @@ Object::TraceDisconnect (std::string path, const CallbackBase &cb) GetTraceResolver ()->Disconnect (path, cb); } - void Object::SetInterfaceId (InterfaceId iid) { diff --git a/src/core/object.h b/src/core/object.h index 1b0825381..affaf223e 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -138,8 +138,8 @@ public: void TraceConnect (std::string path, const CallbackBase &cb); - void TraceConnect (std::string path, const CallbackBase &cb, const TraceContext &context); void TraceDisconnect (std::string path, const CallbackBase &cb); + virtual Ptr GetTraceResolver (void); protected: /** * \param iid an InterfaceId @@ -155,8 +155,6 @@ protected: * up to their parent's implementation once they are done. */ virtual void DoDispose (void); - - virtual Ptr GetTraceResolver (void); private: Ptr DoQueryInterface (InterfaceId iid) const; bool Check (void) const; diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index f22b73352..f0f61f761 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -69,6 +69,8 @@ public: * This method should behave as Connect. */ virtual void Disconnect (std::string path, CallbackBase const &cb) = 0; + + virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) = 0; protected: /** * \param path a namespace path diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 2276c0da3..7278f2e3a 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -171,5 +171,9 @@ NodeList::Disconnect (std::string name, const CallbackBase &cb) { SimulationSingleton::Get ()->GetTraceResolver ()->Disconnect (name, cb); } - +Ptr +NodeList::GetTraceResolver (void) +{ + return SimulationSingleton::Get ()->GetTraceResolver (); +} }//namespace ns3 diff --git a/src/node/node-list.h b/src/node/node-list.h index 6774d8ce7..dfb4e4ce9 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -30,6 +30,7 @@ namespace ns3 { class Node; class CallbackBase; +class TraceResolver; class NodeListIndex : public TraceContextElement { @@ -94,6 +95,7 @@ public: * the input namespace regexp. */ static void Disconnect (std::string name, const CallbackBase &cb); + static Ptr GetTraceResolver (void); private: }; diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc new file mode 100644 index 000000000..81f283f2c --- /dev/null +++ b/utils/print-trace-sources.cc @@ -0,0 +1,23 @@ +#include "ns3/internet-node.h" +#include "ns3/ptr.h" +#include "ns3/trace-resolver.h" +#include "ns3/node-list.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/csma-cd-net-device.h" +#include "ns3/queue.h" + +using namespace ns3; + +int main (int argc, char *argv[]) +{ + Ptr node = Create (); + + Ptr p2p = Create (node); + p2p->AddQueue (Queue::CreateDefault ()); + Ptr csma = Create (node); + csma->AddQueue (Queue::CreateDefault ()); + + NodeList::GetTraceResolver ()->PrintAvailable ("", TraceContext (), std::cout); + + return 0; +} diff --git a/utils/wscript b/utils/wscript index d64d46dc5..ebf8b356c 100644 --- a/utils/wscript +++ b/utils/wscript @@ -16,3 +16,7 @@ def build(bld): obj = bld.create_ns3_program('replay-simulation', ['simulator']) obj.source = 'replay-simulation.cc' + + obj = bld.create_ns3_program('print-trace-sources', + ['internet-node', 'csma-cd', 'point-to-point']) + obj.source = 'print-trace-sources.cc' From 403ece5588bbad6cf7e0a1fd1b5f3763002452e6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 20:45:49 +0200 Subject: [PATCH 45/92] add TraceContext::IsSimilar --- src/core/trace-context.cc | 36 ++++++++++++++++++++++++++++++++++++ src/core/trace-context.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index d4fa486d7..a106e27f4 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -256,6 +256,42 @@ TraceContext::PrintAvailable (std::ostream &os, std::string separator) const } while (true); } +bool +TraceContext::IsSimilar (const TraceContext &o) const +{ + if (m_data == 0 && o.m_data == 0) + { + return true; + } + if ((m_data != 0 && o.m_data == 0) || + (m_data == 0 && o.m_data != 0)) + { + return false; + } + uint8_t myCurrentUid; + uint16_t myI = 0; + uint8_t otherCurrentUid; + uint16_t otherI = 0; + do { + myCurrentUid = m_data->data[myI]; + otherCurrentUid = o.m_data->data[otherI]; + uint8_t mySize = ElementRegistry::GetSize (myCurrentUid); + uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid); + myI += 1 + mySize; + otherI += 1 + otherSize; + } while (myCurrentUid == otherCurrentUid && + myCurrentUid != 0 && + otherCurrentUid != 0); + if (myCurrentUid == 0 && otherCurrentUid == 0) + { + return true; + } + else + { + return false; + } +} + std::ostream& operator<< (std::ostream& os, const TraceContext &context) { context.Print (os); diff --git a/src/core/trace-context.h b/src/core/trace-context.h index c6f63ce99..fef2adcc6 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -81,6 +81,7 @@ public: void Print (std::ostream &os) const; void PrintAvailable (std::ostream &os, std::string separator) const; + bool IsSimilar (const TraceContext &o) const; private: friend class TraceContextTest; // used exclusively for testing code. From 95c06276cf95462bd99431008824206807e1ebbf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 27 Aug 2007 20:46:10 +0200 Subject: [PATCH 46/92] add TraceResolver::CollectSources --- src/core/trace-resolver.cc | 30 ++++++++++++++++++++++++++++++ src/core/trace-resolver.h | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 4d4e4078a..3da9a088f 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -75,4 +75,34 @@ TraceResolver::GetSubpath (std::string path) return subpath; } +void +TraceResolver::SourceCollection::AddUnique (std::string path, const TraceContext &context, + std::string help) +{ + for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) + { + if (i->path == path && + i->help == help && + context.IsSimilar (i->context)) + { + return; + } + } + struct Source source; + source.path = path; + source.context = context; + source.help = help; + m_sources.push_back (source); +} +void +TraceResolver::SourceCollection::Print (std::ostream &os) const +{ + for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) + { + os << i->path << " ["; + i->context.PrintAvailable (os, " "); + os << "] " << i->help << std::endl; + } +} + }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index f0f61f761..0fd5720f3 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -71,6 +71,26 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb) = 0; virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) = 0; + + + class SourceCollection + { + public: + void Print (std::ostream &os) const; + void AddUnique (std::string path, const TraceContext &context, + std::string help); + private: + struct Source + { + std::string path; + TraceContext context; + std::string help; + }; + typedef std::vector SourceVector; + SourceVector m_sources; + }; + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) {} protected: /** * \param path a namespace path From 65f12f1df54056dd9fe7cc81d81f7fdc688e27cc Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 09:37:10 +0200 Subject: [PATCH 47/92] replace TraceResolver::PrintAvailable with TraceResolver::CollectSources --- src/core/array-trace-resolver.h | 9 ++++-- src/core/composite-trace-resolver.cc | 34 +++++++++++++++------- src/core/composite-trace-resolver.h | 13 ++++++--- src/core/object.cc | 42 ++++++++++++++++++++++++++-- src/core/object.h | 10 ++++++- src/core/trace-context.cc | 27 +++++++++++------- src/core/trace-resolver.cc | 18 ++++++++++++ src/core/trace-resolver.h | 9 +++--- utils/print-trace-sources.cc | 4 ++- 9 files changed, 130 insertions(+), 36 deletions(-) diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index 0f76f57c9..c3f8181a6 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -62,7 +62,8 @@ public: // inherited from TraceResolver virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os); + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection); private: class IteratorBase @@ -166,7 +167,8 @@ ArrayTraceResolver::Disconnect (std::string path, CallbackBase const &cb) } template void -ArrayTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) +ArrayTraceResolver::CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { path.append ("/[0-n]"); uint32_t j = 0; @@ -176,11 +178,12 @@ ArrayTraceResolver::PrintAvailable (std::string path, const TraceContext INDEX index = j; tmp.AddElement (index); Ptr obj = m_iter->Get (); - obj->GetTraceResolver ()->PrintAvailable (path, tmp, os); + obj->GetTraceResolver ()->CollectSources (path, tmp, collection); j++; } } + }//namespace ns3 #endif /* ARRAY_TRACE_RESOLVER_H */ diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 0c6ce941e..0e8f5a947 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -54,7 +54,15 @@ CompositeTraceResolver::Add (std::string name, {maker ()->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {maker ()->Disconnect (subpath, cb);} - + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) + { + path.append ("/"); + path.append (this->name); + TraceContext ctx = context; + ctx.Union (this->context); + this->maker ()->CollectSources (path, ctx, collection); + } Callback > maker; } *item = new MakerCompositeItem (); item->name = name; @@ -82,13 +90,15 @@ CompositeTraceResolver::DoAddSource (std::string name, {if (subpath == "") {trace->AddCallback (cb, context);}} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {if (subpath == "") {trace->RemoveCallback (cb);}} - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { - os << path << "/" << this->name << " ["; + path.append ("/"); + path.append (this->name); TraceContext ctx = context; ctx.Union (this->context); - ctx.PrintAvailable (os, ","); - os << "]" << std::endl; + // XXX help string + collection->AddUnique (path, ctx, ""); } TraceSource *trace; } *item = new SourceCompositeItem (); @@ -116,13 +126,14 @@ CompositeTraceResolver::DoAddChild (std::string name, Ptr child, const T {child->GetTraceResolver ()->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {child->TraceDisconnect (subpath, cb);} - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { path.append ("/"); path.append (this->name); TraceContext ctx = context; ctx.Union (this->context); - this->child->GetTraceResolver ()->PrintAvailable (path, ctx, os); + this->child->GetTraceResolver ()->CollectSources (path, ctx, collection); } Ptr child; @@ -264,20 +275,23 @@ CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb) } operation = DisconnectOperation (cb); DoRecursiveOperation (path, operation); } + void -CompositeTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) +CompositeTraceResolver::CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { NS_DEBUG ("print " << (*i)->name); - (*i)->PrintAvailable (path, context, os); + (*i)->CollectSources (path, context, collection); } if (m_parent != 0) { - m_parent->PrintAvailable (path, context, os); + m_parent->CollectSources (path, context, collection); } } + }//namespace ns3 #ifdef RUN_SELF_TESTS diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 3be3c332c..b65682fbb 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -91,7 +91,8 @@ public: virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os); + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection); private: class CompositeItem @@ -100,7 +101,8 @@ private: virtual ~CompositeItem () {} virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) = 0; virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0; - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) {} + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) = 0; std::string name; TraceContext context; @@ -157,13 +159,16 @@ CompositeTraceResolver::AddArray (std::string name, {array->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) {array->Disconnect (subpath, cb);} - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { path.append ("/"); path.append (this->name); TraceContext ctx = context; ctx.Union (this->context); - array->PrintAvailable (path, ctx, os);} + array->CollectSources (path, ctx, collection); + } + Ptr > array; } *item = new ArrayCompositeItem (); item->name = name; diff --git a/src/core/object.cc b/src/core/object.cc index bd2128c7c..a59da10e2 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -63,7 +63,8 @@ public: InterfaceIdTraceResolver (Ptr aggregate); virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os); + virtual void CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection); private: Ptr ParseForInterface (std::string path); Ptr m_aggregate; @@ -105,9 +106,10 @@ InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb) } } void -InterfaceIdTraceResolver::PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) +InterfaceIdTraceResolver::CollectSources (std::string path, const TraceContext &context, + SourceCollection *collection) { - + m_aggregate->DoCollectSources (path, context, collection); } @@ -128,6 +130,12 @@ InterfaceId::LookupParent (InterfaceId iid) { return Singleton::Get ()->LookupParent (iid.m_iid); } +std::string +InterfaceId::GetName (void) const +{ + std::string name = Singleton::Get ()->LookupByUid (m_iid); + return name; +} bool operator == (const InterfaceId &a, const InterfaceId &b) { @@ -284,6 +292,34 @@ Object::MaybeDelete (void) const } while (current != end); } +void +Object::DoCollectSources (std::string path, const TraceContext &context, + TraceResolver::SourceCollection *collection) +{ + Object *current = this->m_next; + if (collection->IsFlagSet ()) + { + return; + } + collection->SetFlag (); + while (current != this) + { + NS_ASSERT (current != 0); + InterfaceId cur = current->m_iid; + while (cur != Object::iid) + { + std::string name = cur.GetName (); + std::string fullpath = path; + fullpath.append ("/$"); + fullpath.append (name); + current->GetTraceResolver ()->CollectSources (fullpath, context, collection); + cur = InterfaceId::LookupParent (cur); + } + current = current->m_next; + } + collection->ClearFlag (); +} + } // namespace ns3 diff --git a/src/core/object.h b/src/core/object.h index affaf223e..32f1806a4 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -24,10 +24,10 @@ #include #include #include "ptr.h" +#include "trace-resolver.h" namespace ns3 { -class TraceResolver; class TraceContext; class CallbackBase; @@ -60,6 +60,11 @@ public: * id is not a valid interface id. */ static InterfaceId LookupParent (InterfaceId iid); + + /** + * \returns the name of this interface. + */ + std::string GetName (void) const; ~InterfaceId (); private: InterfaceId (uint16_t iid); @@ -156,7 +161,10 @@ protected: */ virtual void DoDispose (void); private: + friend class InterfaceIdTraceResolver; Ptr DoQueryInterface (InterfaceId iid) const; + void DoCollectSources (std::string path, const TraceContext &context, + TraceResolver::SourceCollection *collection); bool Check (void) const; void MaybeDelete (void) const; mutable uint32_t m_count; diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index a106e27f4..d065bfa73 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -272,16 +272,23 @@ TraceContext::IsSimilar (const TraceContext &o) const uint16_t myI = 0; uint8_t otherCurrentUid; uint16_t otherI = 0; - do { - myCurrentUid = m_data->data[myI]; - otherCurrentUid = o.m_data->data[otherI]; - uint8_t mySize = ElementRegistry::GetSize (myCurrentUid); - uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid); - myI += 1 + mySize; - otherI += 1 + otherSize; - } while (myCurrentUid == otherCurrentUid && - myCurrentUid != 0 && - otherCurrentUid != 0); + + myCurrentUid = m_data->data[myI]; + otherCurrentUid = o.m_data->data[otherI]; + + while (myCurrentUid == otherCurrentUid && + myCurrentUid != 0 && + otherCurrentUid != 0 && + myI < m_data->size && + otherI < o.m_data->size) + { + uint8_t mySize = ElementRegistry::GetSize (myCurrentUid); + uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid); + myI += 1 + mySize; + otherI += 1 + otherSize; + myCurrentUid = m_data->data[myI]; + otherCurrentUid = o.m_data->data[otherI]; + } if (myCurrentUid == 0 && otherCurrentUid == 0) { return true; diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 3da9a088f..b4acde66c 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -105,4 +105,22 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const } } +void +TraceResolver::SourceCollection::SetFlag (void) +{ + m_flag = true; +} + +void +TraceResolver::SourceCollection::ClearFlag (void) +{ + m_flag = false; +} +bool +TraceResolver::SourceCollection::IsFlagSet (void) +{ + return m_flag; +} + + }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 0fd5720f3..639ddcb85 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -70,15 +70,15 @@ public: */ virtual void Disconnect (std::string path, CallbackBase const &cb) = 0; - virtual void PrintAvailable (std::string path, const TraceContext &context, std::ostream &os) = 0; - - class SourceCollection { public: void Print (std::ostream &os) const; void AddUnique (std::string path, const TraceContext &context, std::string help); + void SetFlag (void); + void ClearFlag (void); + bool IsFlagSet (void); private: struct Source { @@ -88,9 +88,10 @@ public: }; typedef std::vector SourceVector; SourceVector m_sources; + bool m_flag; }; virtual void CollectSources (std::string path, const TraceContext &context, - SourceCollection *collection) {} + SourceCollection *collection) = 0; protected: /** * \param path a namespace path diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc index 81f283f2c..0c3e489a0 100644 --- a/utils/print-trace-sources.cc +++ b/utils/print-trace-sources.cc @@ -17,7 +17,9 @@ int main (int argc, char *argv[]) Ptr csma = Create (node); csma->AddQueue (Queue::CreateDefault ()); - NodeList::GetTraceResolver ()->PrintAvailable ("", TraceContext (), std::cout); + TraceResolver::SourceCollection collection; + NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection); + collection.Print (std::cout); return 0; } From 8acd0300cdff95dd10d287ebf84b895854d9bc64 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 11:01:00 +0200 Subject: [PATCH 48/92] keep track of trace source help strings --- src/core/composite-trace-resolver.cc | 18 +++++++++------ src/core/composite-trace-resolver.h | 22 ++++++++----------- src/core/object.cc | 8 +++---- src/core/trace-resolver.cc | 7 ++++-- src/devices/csma-cd/csma-cd-net-device.cc | 2 ++ .../point-to-point-net-device.cc | 1 + src/internet-node/ipv4-l3-protocol.cc | 9 +++++--- src/mobility/mobility-model-notifier.cc | 3 ++- src/node/queue.cc | 9 +++++--- 9 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 0e8f5a947..959561f6e 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -73,13 +73,15 @@ CompositeTraceResolver::Add (std::string name, void CompositeTraceResolver::AddSource (std::string name, - TraceSource &trace) + std::string helpText, + TraceSource &trace) { - DoAddSource (name, trace, TraceContext ()); + DoAddSource (name, helpText, trace, TraceContext ()); } void CompositeTraceResolver::DoAddSource (std::string name, + std::string helpText, TraceSource &trace, const TraceContext &context) { @@ -98,13 +100,15 @@ CompositeTraceResolver::DoAddSource (std::string name, TraceContext ctx = context; ctx.Union (this->context); // XXX help string - collection->AddUnique (path, ctx, ""); + collection->AddUnique (path, ctx, helpText); } TraceSource *trace; + std::string helpText; } *item = new SourceCompositeItem (); item->name = name; item->context = context; item->trace = &trace; + item->helpText = helpText; AddItem (item); } @@ -397,7 +401,7 @@ Ptr CompositeTraceResolverTest::CreateSubResolver (void) { Ptr subresolver = Create (); - subresolver->AddSource ("trace-int", m_traceInt, + subresolver->AddSource ("trace-int", "test source", m_traceInt, SubTraceSourceTest (SubTraceSourceTest::INT)); return subresolver; } @@ -412,9 +416,9 @@ CompositeTraceResolverTest::RunTests (void) CompositeTraceResolver resolver; - resolver.AddSource ("trace-double-a", traceDoubleA, + resolver.AddSource ("trace-double-a", "test source", traceDoubleA, TraceSourceTest (TraceSourceTest::DOUBLEA)); - resolver.AddSource ("trace-double-b", traceDoubleB, + resolver.AddSource ("trace-double-b", "test source", traceDoubleB, TraceSourceTest (TraceSourceTest::DOUBLEB)); resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); @@ -547,7 +551,7 @@ CompositeTraceResolverTest::RunTests (void) SVTraceSource source; - resolver.AddSource ("uint16_t", source, TraceSourceTest (TraceSourceTest::UINT16_T)); + resolver.AddSource ("uint16_t", "test source", source, TraceSourceTest (TraceSourceTest::UINT16_T)); return ok; diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index b65682fbb..47fd4ca3f 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -53,7 +53,7 @@ public: * be automatically extended to contain the input context. */ template - void AddSource (std::string name, + void AddSource (std::string name, std::string helpText, TraceSource &trace, T const &context); /** * \param name name of trace source @@ -64,18 +64,8 @@ public: * resolution. */ void AddSource (std::string name, + std::string helpText, TraceSource &trace); - /** - * \param name name of child trace resolver - * \param createResolver a trace resolver constructor - * - * Add a child trace resolver to this resolver. This child - * trace resolver will match the name specified during - * namespace resolution. When this happens, the constructor - * will be invoked to create the child trace resolver. - */ - void Add (std::string name, - Callback > createResolver); void AddChild (std::string name, Ptr child); @@ -95,6 +85,7 @@ public: SourceCollection *collection); private: + friend class CompositeTraceResolverTest; class CompositeItem { public: @@ -123,8 +114,12 @@ private: const Operation &operation); void DoAddChild (std::string name, Ptr child, const TraceContext &context); void DoAddSource (std::string name, + std::string helpText, TraceSource &trace, const TraceContext &context); + void Add (std::string name, + Callback > createResolver); + CompositeTraceResolver::TraceItems m_items; Ptr m_parent; @@ -139,12 +134,13 @@ namespace ns3 { template void CompositeTraceResolver::AddSource (std::string name, + std::string helpText, TraceSource &trace, T const &context) { TraceContext ctx; ctx.AddElement (context); - DoAddSource (name, trace, ctx); + DoAddSource (name, helpText, trace, ctx); } template diff --git a/src/core/object.cc b/src/core/object.cc index a59da10e2..c2d7c389a 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -346,7 +346,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("basea-x", m_source); + resolver->AddSource ("basea-x", "test source", m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -370,7 +370,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("deriveda-x", m_sourceDerived); + resolver->AddSource ("deriveda-x", "test source", m_sourceDerived); resolver->SetParent (BaseA::GetTraceResolver ()); return resolver; } @@ -397,7 +397,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("baseb-x", m_source); + resolver->AddSource ("baseb-x", "test source", m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -421,7 +421,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("derivedb-x", m_sourceDerived); + resolver->AddSource ("derivedb-x", "test source", m_sourceDerived); resolver->SetParent (BaseB::GetTraceResolver ()); return resolver; } diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index b4acde66c..a5f5267a4 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -99,9 +99,12 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const { for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) { - os << i->path << " ["; + os << "source=" << i->path << std::endl; + os << "TraceContextElement="; i->context.PrintAvailable (os, " "); - os << "] " << i->help << std::endl; + os << std::endl; + os << i->help << std::endl; + os << std::endl; } } diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index 6454ae724..29fa3dd4a 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -460,9 +460,11 @@ CsmaCdNetDevice::GetTraceResolver (void) Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); resolver->AddSource ("rx", + "receive MAC packet", m_rxTrace, CsmaCdTraceType (CsmaCdTraceType::RX)); resolver->AddSource ("drop", + "drop MAC packet", m_dropTrace, CsmaCdTraceType (CsmaCdTraceType::DROP)); resolver->SetParent (NetDevice::GetTraceResolver ()); 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 4d7e89e7c..19cb27b7a 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 @@ -199,6 +199,7 @@ PointToPointNetDevice::GetTraceResolver (void) Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); resolver->AddSource ("rx", + "receive MAC packet", m_rxTrace, PointToPointTraceType ()); resolver->SetParent (NetDevice::GetTraceResolver ()); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index d01034ef2..b59901dc2 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -162,9 +162,12 @@ Ptr Ipv4L3Protocol::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("tx", m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); - resolver->AddSource ("rx", m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); - resolver->AddSource ("drop", m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); + resolver->AddSource ("tx", "send ipv4 packet to outgoing interface", + m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); + resolver->AddSource ("rx", "receive ipv4 packet from incoming interface", + m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); + resolver->AddSource ("drop", "drop ipv4 packet", + m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); resolver->AddArray ("interfaces", m_interfaces.begin (), m_interfaces.end (), Ipv4L3ProtocolInterfaceIndex ()); diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index ffab72953..01bad6070 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -44,7 +44,8 @@ MobilityModelNotifier::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("course-change", m_trace); + resolver->AddSource ("course-change", "speed vector changed value", + m_trace); return resolver; } diff --git a/src/node/queue.cc b/src/node/queue.cc index 10bcc1c04..7ebbf838e 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -103,9 +103,12 @@ Ptr Queue::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("enqueue", m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); - resolver->AddSource ("dequeue", m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); - resolver->AddSource ("drop", m_traceDrop, QueueTraceType (QueueTraceType::DROP)); + resolver->AddSource ("enqueue", "store packet in queue", + m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); + resolver->AddSource ("dequeue", "remove packet from queue", + m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); + resolver->AddSource ("drop", "drop packet from queue", + m_traceDrop, QueueTraceType (QueueTraceType::DROP)); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } From fa4bcd0cd471d039dd35efb2a51ae4c8a1c01640 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 11:20:55 +0200 Subject: [PATCH 49/92] make sure to get to the parent during trace resolution --- src/mobility/mobility-model-notifier.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index 01bad6070..add1cb993 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -46,6 +46,7 @@ MobilityModelNotifier::GetTraceResolver (void) Create (); resolver->AddSource ("course-change", "speed vector changed value", m_trace); + resolver->SetParent (Object::GetTraceResolver ()); return resolver; } From 579a173fbf72fc21fdac9ca25b5d1a0d2cdf405c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 11:21:42 +0200 Subject: [PATCH 50/92] avoid problems with recursive use of Object::DoCollectSources --- src/core/object.cc | 28 +++++++++++++++++++++------- src/core/object.h | 1 + src/core/trace-resolver.cc | 18 ------------------ src/core/trace-resolver.h | 4 ---- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index c2d7c389a..565897947 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -23,8 +23,11 @@ #include "singleton.h" #include "uid-manager.h" #include "trace-resolver.h" +#include "debug.h" #include +NS_DEBUG_COMPONENT_DEFINE ("Object"); + namespace { class IidManager : public ns3::UidManager @@ -173,6 +176,7 @@ Object::Object () : m_count (1), m_iid (Object::iid), m_disposed (false), + m_collecting (false), m_next (this) {} Object::~Object () @@ -296,15 +300,23 @@ void Object::DoCollectSources (std::string path, const TraceContext &context, TraceResolver::SourceCollection *collection) { - Object *current = this->m_next; - if (collection->IsFlagSet ()) - { - return; - } - collection->SetFlag (); + Object *current; + current = this; + do { + if (current->m_collecting) + { + return; + } + current = current->m_next; + } while (current != this); + + m_collecting = true; + + current = this->m_next; while (current != this) { NS_ASSERT (current != 0); + NS_DEBUG ("collect current=" << current); InterfaceId cur = current->m_iid; while (cur != Object::iid) { @@ -312,12 +324,14 @@ Object::DoCollectSources (std::string path, const TraceContext &context, std::string fullpath = path; fullpath.append ("/$"); fullpath.append (name); + NS_DEBUG ("collect: " << fullpath); current->GetTraceResolver ()->CollectSources (fullpath, context, collection); cur = InterfaceId::LookupParent (cur); } current = current->m_next; } - collection->ClearFlag (); + + m_collecting = false; } } // namespace ns3 diff --git a/src/core/object.h b/src/core/object.h index 32f1806a4..8661d7f8a 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -170,6 +170,7 @@ private: mutable uint32_t m_count; InterfaceId m_iid; bool m_disposed; + bool m_collecting; Object *m_next; }; diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index a5f5267a4..d0191f859 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -108,22 +108,4 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const } } -void -TraceResolver::SourceCollection::SetFlag (void) -{ - m_flag = true; -} - -void -TraceResolver::SourceCollection::ClearFlag (void) -{ - m_flag = false; -} -bool -TraceResolver::SourceCollection::IsFlagSet (void) -{ - return m_flag; -} - - }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 639ddcb85..c3802619a 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -76,9 +76,6 @@ public: void Print (std::ostream &os) const; void AddUnique (std::string path, const TraceContext &context, std::string help); - void SetFlag (void); - void ClearFlag (void); - bool IsFlagSet (void); private: struct Source { @@ -88,7 +85,6 @@ public: }; typedef std::vector SourceVector; SourceVector m_sources; - bool m_flag; }; virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; From f55a3c0b3d5ec1da9feeeb48f8bb26be92830d44 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 11:22:01 +0200 Subject: [PATCH 51/92] document also mobility model notifier --- utils/print-trace-sources.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc index 0c3e489a0..948cf03c3 100644 --- a/utils/print-trace-sources.cc +++ b/utils/print-trace-sources.cc @@ -5,12 +5,14 @@ #include "ns3/point-to-point-net-device.h" #include "ns3/csma-cd-net-device.h" #include "ns3/queue.h" +#include "ns3/mobility-model-notifier.h" using namespace ns3; int main (int argc, char *argv[]) { Ptr node = Create (); + node->AddInterface (Create ()); Ptr p2p = Create (node); p2p->AddQueue (Queue::CreateDefault ()); From 966643a542a80fa225627e4b5a8baa62f49870e3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 12:06:15 +0200 Subject: [PATCH 52/92] improve trace list output --- src/core/trace-resolver.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index d0191f859..683df2ab7 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -100,10 +100,10 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) { os << "source=" << i->path << std::endl; - os << "TraceContextElement="; - i->context.PrintAvailable (os, " "); - os << std::endl; - os << i->help << std::endl; + os << "TraceContext=["; + i->context.PrintAvailable (os, ","); + os << "]" << std::endl; + os << "help=\"" << i->help << "\"" << std::endl; os << std::endl; } } From 0b0a18796771d0e3691966dc2bbccf8baeea11ed Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 12:42:27 +0200 Subject: [PATCH 53/92] document trace source signature --- src/core/trace-doc.cc | 67 +++++++++++++++++++++++++++++++++++++++++++ src/core/trace-doc.h | 50 ++++++++++++++++++++++++++++++++ src/core/wscript | 2 ++ 3 files changed, 119 insertions(+) create mode 100644 src/core/trace-doc.cc create mode 100644 src/core/trace-doc.h diff --git a/src/core/trace-doc.cc b/src/core/trace-doc.cc new file mode 100644 index 000000000..adf3c8c27 --- /dev/null +++ b/src/core/trace-doc.cc @@ -0,0 +1,67 @@ +#include "trace-doc.h" + +namespace ns3 { + +TraceDoc::TraceDoc (std::string help) + : m_help (help) +{} +TraceDoc::TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help) + : m_help (help) +{ + m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); +} +TraceDoc::TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help) +{ + m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); + m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); +} +TraceDoc::TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help, + std::string arg2Type, + std::string arg2Help) +{ + m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); + m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); + m_argVector.push_back (std::make_pair (arg2Type, arg2Help)); +} +TraceDoc::TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help, + std::string arg2Type, + std::string arg2Help, + std::string arg3Type, + std::string arg3Help) +{ + m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); + m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); + m_argVector.push_back (std::make_pair (arg2Type, arg2Help)); + m_argVector.push_back (std::make_pair (arg3Type, arg3Help)); +} +std::string +TraceDoc::GetHelp (void) +{ + return m_help; +} +TraceDoc::Iterator +TraceDoc::ArgsBegin (void) const +{ + return m_argVector.begin (); +} +TraceDoc::Iterator +TraceDoc::ArgsEnd (void) const +{ + return m_argVector.end (); +} + +} // namespace ns3 diff --git a/src/core/trace-doc.h b/src/core/trace-doc.h new file mode 100644 index 000000000..1ccfc0d99 --- /dev/null +++ b/src/core/trace-doc.h @@ -0,0 +1,50 @@ +#ifndef TRACE_DOC_H +#define TRACE_DOC_H + +#include +#include + +namespace ns3 { + +class TraceDoc +{ + typedef std::vector > ArgVector; +public: + typedef ArgVector::const_iterator Iterator; + + TraceDoc (std::string help); + TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help); + TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help); + TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help, + std::string arg2Type, + std::string arg2Help); + TraceDoc (std::string help, + std::string arg0Type, + std::string arg0Help, + std::string arg1Type, + std::string arg1Help, + std::string arg2Type, + std::string arg2Help, + std::string arg3Type, + std::string arg3Help); + std::string GetHelp (void); + Iterator ArgsBegin (void) const; + Iterator ArgsEnd (void) const; +private: + ArgVector m_argVector; + std::string m_help; +}; + +} // namespace ns3 + +#endif /* TRACE_DOC_H */ diff --git a/src/core/wscript b/src/core/wscript index 7d913eddc..b32bd3a9c 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -48,6 +48,7 @@ def build(bld): 'trace-resolver.cc', 'callback-trace-source.cc', 'composite-trace-resolver.cc', + 'trace-doc.cc', ] if sys.platform == 'win32': @@ -89,5 +90,6 @@ def build(bld): 'trace-resolver.h', 'composite-trace-resolver.h', 'array-trace-resolver.h', + 'trace-doc.h', ] From a5cf22af8038eec74d5707ecaf0222a9aa48e610 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 13:10:18 +0200 Subject: [PATCH 54/92] document trace source signatures --- src/core/composite-trace-resolver.cc | 21 +++++++++---------- src/core/composite-trace-resolver.h | 11 +++++----- src/core/object.cc | 8 +++---- src/core/trace-doc.cc | 9 +++++++- src/core/trace-doc.h | 4 ++-- src/core/trace-resolver.cc | 17 ++++++++++----- src/core/trace-resolver.h | 8 ++++--- src/devices/csma/csma-net-device.cc | 6 ++++-- .../point-to-point-net-device.cc | 3 ++- src/internet-node/ipv4-l3-protocol.cc | 14 ++++++++++--- src/mobility/mobility-model-notifier.cc | 6 +++++- src/node/queue.cc | 12 ++++++++--- 12 files changed, 78 insertions(+), 41 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 959561f6e..0b45b7cd7 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -73,15 +73,15 @@ CompositeTraceResolver::Add (std::string name, void CompositeTraceResolver::AddSource (std::string name, - std::string helpText, + const TraceDoc &doc, TraceSource &trace) { - DoAddSource (name, helpText, trace, TraceContext ()); + DoAddSource (name, doc, trace, TraceContext ()); } void CompositeTraceResolver::DoAddSource (std::string name, - std::string helpText, + const TraceDoc &doc, TraceSource &trace, const TraceContext &context) { @@ -99,16 +99,15 @@ CompositeTraceResolver::DoAddSource (std::string name, path.append (this->name); TraceContext ctx = context; ctx.Union (this->context); - // XXX help string - collection->AddUnique (path, ctx, helpText); + collection->AddUnique (path, ctx, this->doc); } TraceSource *trace; - std::string helpText; + TraceDoc doc; } *item = new SourceCompositeItem (); item->name = name; item->context = context; item->trace = &trace; - item->helpText = helpText; + item->doc = doc; AddItem (item); } @@ -401,7 +400,7 @@ Ptr CompositeTraceResolverTest::CreateSubResolver (void) { Ptr subresolver = Create (); - subresolver->AddSource ("trace-int", "test source", m_traceInt, + subresolver->AddSource ("trace-int", TraceDoc ("test source"), m_traceInt, SubTraceSourceTest (SubTraceSourceTest::INT)); return subresolver; } @@ -416,9 +415,9 @@ CompositeTraceResolverTest::RunTests (void) CompositeTraceResolver resolver; - resolver.AddSource ("trace-double-a", "test source", traceDoubleA, + resolver.AddSource ("trace-double-a", TraceDoc ("test source"), traceDoubleA, TraceSourceTest (TraceSourceTest::DOUBLEA)); - resolver.AddSource ("trace-double-b", "test source", traceDoubleB, + resolver.AddSource ("trace-double-b", TraceDoc ("test source"), traceDoubleB, TraceSourceTest (TraceSourceTest::DOUBLEB)); resolver.Connect ("/*", MakeCallback (&CompositeTraceResolverTest::TraceDouble, this), TraceContext ()); @@ -551,7 +550,7 @@ CompositeTraceResolverTest::RunTests (void) SVTraceSource source; - resolver.AddSource ("uint16_t", "test source", source, TraceSourceTest (TraceSourceTest::UINT16_T)); + resolver.AddSource ("uint16_t", TraceDoc ("test source"), source, TraceSourceTest (TraceSourceTest::UINT16_T)); return ok; diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 47fd4ca3f..c9b0fd1d7 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -30,6 +30,7 @@ #include "sv-trace-source.h" #include "fv-trace-source.h" #include "array-trace-resolver.h" +#include "trace-doc.h" namespace ns3 { @@ -53,7 +54,7 @@ public: * be automatically extended to contain the input context. */ template - void AddSource (std::string name, std::string helpText, + void AddSource (std::string name, const TraceDoc &doc, TraceSource &trace, T const &context); /** * \param name name of trace source @@ -64,7 +65,7 @@ public: * resolution. */ void AddSource (std::string name, - std::string helpText, + const TraceDoc &doc, TraceSource &trace); void AddChild (std::string name, Ptr child); @@ -114,7 +115,7 @@ private: const Operation &operation); void DoAddChild (std::string name, Ptr child, const TraceContext &context); void DoAddSource (std::string name, - std::string helpText, + const TraceDoc &doc, TraceSource &trace, const TraceContext &context); void Add (std::string name, @@ -134,13 +135,13 @@ namespace ns3 { template void CompositeTraceResolver::AddSource (std::string name, - std::string helpText, + const TraceDoc &doc, TraceSource &trace, T const &context) { TraceContext ctx; ctx.AddElement (context); - DoAddSource (name, helpText, trace, ctx); + DoAddSource (name, doc, trace, ctx); } template diff --git a/src/core/object.cc b/src/core/object.cc index 565897947..8b5852665 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -360,7 +360,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("basea-x", "test source", m_source); + resolver->AddSource ("basea-x", ns3::TraceDoc ("test source"), m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -384,7 +384,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("deriveda-x", "test source", m_sourceDerived); + resolver->AddSource ("deriveda-x", ns3::TraceDoc ("test source"), m_sourceDerived); resolver->SetParent (BaseA::GetTraceResolver ()); return resolver; } @@ -411,7 +411,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("baseb-x", "test source", m_source); + resolver->AddSource ("baseb-x", ns3::TraceDoc ("test source"), m_source); resolver->SetParent (Object::GetTraceResolver ()); return resolver; } @@ -435,7 +435,7 @@ public: { ns3::Ptr resolver = ns3::Create (); - resolver->AddSource ("derivedb-x", "test source", m_sourceDerived); + resolver->AddSource ("derivedb-x", ns3::TraceDoc ("test source"), m_sourceDerived); resolver->SetParent (BaseB::GetTraceResolver ()); return resolver; } diff --git a/src/core/trace-doc.cc b/src/core/trace-doc.cc index adf3c8c27..b41089d10 100644 --- a/src/core/trace-doc.cc +++ b/src/core/trace-doc.cc @@ -2,6 +2,10 @@ namespace ns3 { +TraceDoc::TraceDoc () + : m_help ("empty help") +{} + TraceDoc::TraceDoc (std::string help) : m_help (help) {} @@ -17,6 +21,7 @@ TraceDoc::TraceDoc (std::string help, std::string arg0Help, std::string arg1Type, std::string arg1Help) + : m_help (help) { m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); @@ -28,6 +33,7 @@ TraceDoc::TraceDoc (std::string help, std::string arg1Help, std::string arg2Type, std::string arg2Help) + : m_help (help) { m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); @@ -42,6 +48,7 @@ TraceDoc::TraceDoc (std::string help, std::string arg2Help, std::string arg3Type, std::string arg3Help) + : m_help (help) { m_argVector.push_back (std::make_pair (arg0Type, arg0Help)); m_argVector.push_back (std::make_pair (arg1Type, arg1Help)); @@ -49,7 +56,7 @@ TraceDoc::TraceDoc (std::string help, m_argVector.push_back (std::make_pair (arg3Type, arg3Help)); } std::string -TraceDoc::GetHelp (void) +TraceDoc::GetHelp (void) const { return m_help; } diff --git a/src/core/trace-doc.h b/src/core/trace-doc.h index 1ccfc0d99..6e2ec0600 100644 --- a/src/core/trace-doc.h +++ b/src/core/trace-doc.h @@ -11,7 +11,7 @@ class TraceDoc typedef std::vector > ArgVector; public: typedef ArgVector::const_iterator Iterator; - + TraceDoc (); TraceDoc (std::string help); TraceDoc (std::string help, std::string arg0Type, @@ -37,7 +37,7 @@ public: std::string arg2Help, std::string arg3Type, std::string arg3Help); - std::string GetHelp (void); + std::string GetHelp (void) const; Iterator ArgsBegin (void) const; Iterator ArgsEnd (void) const; private: diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 683df2ab7..698a23b7d 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -76,13 +76,13 @@ TraceResolver::GetSubpath (std::string path) } void -TraceResolver::SourceCollection::AddUnique (std::string path, const TraceContext &context, - std::string help) +TraceResolver::SourceCollection::AddUnique (std::string path, + const TraceContext &context, + const TraceDoc &doc) { for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) { if (i->path == path && - i->help == help && context.IsSimilar (i->context)) { return; @@ -91,7 +91,7 @@ TraceResolver::SourceCollection::AddUnique (std::string path, const TraceContext struct Source source; source.path = path; source.context = context; - source.help = help; + source.doc = doc; m_sources.push_back (source); } void @@ -103,7 +103,14 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const os << "TraceContext=["; i->context.PrintAvailable (os, ","); os << "]" << std::endl; - os << "help=\"" << i->help << "\"" << std::endl; + os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl; + os << "const TraceContext &: the trace context associated to the connected trace source." << std::endl; + uint32_t k = 0; + for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) + { + os << "argument " << k << " -- " << j->first << ": " << j->second << "." << std::endl; + k++; + } os << std::endl; } } diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index c3802619a..762717728 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -24,6 +24,7 @@ #include #include #include "trace-context.h" +#include "trace-doc.h" namespace ns3 { @@ -74,14 +75,15 @@ public: { public: void Print (std::ostream &os) const; - void AddUnique (std::string path, const TraceContext &context, - std::string help); + void AddUnique (std::string path, + const TraceContext &context, + const TraceDoc &doc); private: struct Source { std::string path; TraceContext context; - std::string help; + TraceDoc doc; }; typedef std::vector SourceVector; SourceVector m_sources; diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 2b829f668..06fea4895 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -463,11 +463,13 @@ CsmaNetDevice::GetTraceResolver (void) Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); resolver->AddSource ("rx", - "receive MAC packet", + TraceDoc ("receive MAC packet", + "const Packet &", "packet received"), m_rxTrace, CsmaTraceType (CsmaTraceType::RX)); resolver->AddSource ("drop", - "drop MAC packet", + TraceDoc ("drop MAC packet", + "const Packet &", "packet dropped"), m_dropTrace, CsmaTraceType (CsmaTraceType::DROP)); resolver->SetParent (NetDevice::GetTraceResolver ()); 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 4506cd740..e6c2d8de6 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 @@ -200,7 +200,8 @@ PointToPointNetDevice::GetTraceResolver (void) Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); resolver->AddSource ("rx", - "receive MAC packet", + TraceDoc ("receive MAC packet", + "const Packet &", "packet received"), m_rxTrace, PointToPointTraceType ()); resolver->SetParent (NetDevice::GetTraceResolver ()); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index b59901dc2..2eab180d9 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -162,11 +162,19 @@ Ptr Ipv4L3Protocol::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("tx", "send ipv4 packet to outgoing interface", + resolver->AddSource ("tx", + TraceDoc ("send ipv4 packet to outgoing interface", + "const Packet &", "packet sent", + "uint32_t", "index of output ipv4 interface"), m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX)); - resolver->AddSource ("rx", "receive ipv4 packet from incoming interface", + resolver->AddSource ("rx", + TraceDoc ("receive ipv4 packet from incoming interface", + "const Packet &", "packet received", + "uint32_t", "index of input ipv4 interface"), m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX)); - resolver->AddSource ("drop", "drop ipv4 packet", + resolver->AddSource ("drop", + TraceDoc ("drop ipv4 packet", + "const Packet &", "packet dropped"), m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP)); resolver->AddArray ("interfaces", m_interfaces.begin (), m_interfaces.end (), diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index add1cb993..e7cb8bc3e 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -20,6 +20,7 @@ */ #include "mobility-model-notifier.h" #include "ns3/composite-trace-resolver.h" +#include "ns3/trace-doc.h" namespace ns3 { @@ -44,7 +45,10 @@ MobilityModelNotifier::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("course-change", "speed vector changed value", + resolver->AddSource ("course-change", + TraceDoc ("The value of the speed vector changed", + "Ptr", + "the mobility model whose course changed"), m_trace); resolver->SetParent (Object::GetTraceResolver ()); return resolver; diff --git a/src/node/queue.cc b/src/node/queue.cc index 7ebbf838e..809600854 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -103,11 +103,17 @@ Ptr Queue::GetTraceResolver (void) { Ptr resolver = Create (); - resolver->AddSource ("enqueue", "store packet in queue", + resolver->AddSource ("enqueue", + TraceDoc ("store packet in queue", + "const Packet &", "packet queued"), m_traceEnqueue, QueueTraceType (QueueTraceType::ENQUEUE)); - resolver->AddSource ("dequeue", "remove packet from queue", + resolver->AddSource ("dequeue", + TraceDoc ("remove packet from queue", + "const Packet &", "packet dequeued"), m_traceDequeue, QueueTraceType (QueueTraceType::DEQUEUE)); - resolver->AddSource ("drop", "drop packet from queue", + resolver->AddSource ("drop", + TraceDoc ("drop packet from queue", + "const Packet &", "packet dropped"), m_traceDrop, QueueTraceType (QueueTraceType::DROP)); resolver->SetParent (Object::GetTraceResolver ()); return resolver; From 91a6beb749b992109d0aba583db18caf47845c38 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 13:14:43 +0200 Subject: [PATCH 55/92] api doxygen for Object base class --- src/core/object.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/object.h b/src/core/object.h index 8661d7f8a..8124ec991 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -141,9 +141,28 @@ public: */ void AddInterface (Ptr other); - + /** + * \param path the path to match for the callback + * \param cb callback to connect + * + * Connect the input callback to all trace sources which + * match the input path. + * + */ void TraceConnect (std::string path, const CallbackBase &cb); + /** + * \param path the path to match for the callback + * \param cb callback to disconnect + * + * Disconnect the input callback from all trace sources which + * match the input path. + */ void TraceDisconnect (std::string path, const CallbackBase &cb); + /** + * \returns the trace resolver associated to this object. + * + * This method should be rarely called by users. + */ virtual Ptr GetTraceResolver (void); protected: /** From 4d9cf433ff516c5a4787fc71ccc6a7c6954ee404 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 14:33:53 +0200 Subject: [PATCH 56/92] constify --- src/core/composite-trace-resolver.cc | 6 ++--- src/core/composite-trace-resolver.h | 8 +++---- src/core/object.cc | 24 +++++++++---------- src/core/object.h | 10 ++++---- src/devices/csma/csma-net-device.cc | 2 +- src/devices/csma/csma-net-device.h | 2 +- .../point-to-point-net-device.cc | 2 +- .../point-to-point-net-device.h | 2 +- src/internet-node/arp-ipv4-interface.cc | 2 +- src/internet-node/arp-ipv4-interface.h | 2 +- src/internet-node/internet-node.cc | 2 +- src/internet-node/internet-node.h | 2 +- src/internet-node/ipv4-l3-protocol.cc | 2 +- src/internet-node/ipv4-l3-protocol.h | 2 +- src/internet-node/ipv4-l4-demux.cc | 2 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/mobility/mobility-model-notifier.cc | 2 +- src/mobility/mobility-model-notifier.h | 2 +- src/node/node-list.cc | 12 +++++----- src/node/node-list.h | 2 +- src/node/node.cc | 2 +- src/node/node.h | 2 +- src/node/queue.cc | 2 +- src/node/queue.h | 2 +- 24 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 0b45b7cd7..5f04b2c28 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -74,7 +74,7 @@ CompositeTraceResolver::Add (std::string name, void CompositeTraceResolver::AddSource (std::string name, const TraceDoc &doc, - TraceSource &trace) + const TraceSource &trace) { DoAddSource (name, doc, trace, TraceContext ()); } @@ -82,7 +82,7 @@ CompositeTraceResolver::AddSource (std::string name, void CompositeTraceResolver::DoAddSource (std::string name, const TraceDoc &doc, - TraceSource &trace, + const TraceSource &trace, const TraceContext &context) { class SourceCompositeItem : public CompositeItem @@ -106,7 +106,7 @@ CompositeTraceResolver::DoAddSource (std::string name, } *item = new SourceCompositeItem (); item->name = name; item->context = context; - item->trace = &trace; + item->trace = const_cast (&trace); item->doc = doc; AddItem (item); } diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index c9b0fd1d7..e9ead6af0 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -55,7 +55,7 @@ public: */ template void AddSource (std::string name, const TraceDoc &doc, - TraceSource &trace, T const &context); + const TraceSource &trace, T const &context); /** * \param name name of trace source * \param trace a callback trace source @@ -66,7 +66,7 @@ public: */ void AddSource (std::string name, const TraceDoc &doc, - TraceSource &trace); + const TraceSource &trace); void AddChild (std::string name, Ptr child); @@ -116,7 +116,7 @@ private: void DoAddChild (std::string name, Ptr child, const TraceContext &context); void DoAddSource (std::string name, const TraceDoc &doc, - TraceSource &trace, + const TraceSource &trace, const TraceContext &context); void Add (std::string name, Callback > createResolver); @@ -136,7 +136,7 @@ template void CompositeTraceResolver::AddSource (std::string name, const TraceDoc &doc, - TraceSource &trace, + const TraceSource &trace, T const &context) { TraceContext ctx; diff --git a/src/core/object.cc b/src/core/object.cc index 8b5852665..56768be5d 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -63,20 +63,20 @@ namespace ns3 { class InterfaceIdTraceResolver : public TraceResolver { public: - InterfaceIdTraceResolver (Ptr aggregate); + InterfaceIdTraceResolver (Ptr aggregate); virtual void Connect (std::string path, CallbackBase const &cb, const TraceContext &context); virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); private: - Ptr ParseForInterface (std::string path); - Ptr m_aggregate; + Ptr ParseForInterface (std::string path); + Ptr m_aggregate; }; -InterfaceIdTraceResolver::InterfaceIdTraceResolver (Ptr aggregate) +InterfaceIdTraceResolver::InterfaceIdTraceResolver (Ptr aggregate) : m_aggregate (aggregate) {} -Ptr +Ptr InterfaceIdTraceResolver::ParseForInterface (std::string path) { std::string element = GetElement (path); @@ -93,7 +93,7 @@ InterfaceIdTraceResolver::ParseForInterface (std::string path) void InterfaceIdTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { - Ptr interface = ParseForInterface (path); + Ptr interface = ParseForInterface (path); if (interface != 0) { interface->GetTraceResolver ()->Connect (GetSubpath (path), cb, context); @@ -102,7 +102,7 @@ InterfaceIdTraceResolver::Connect (std::string path, CallbackBase const &cb, con void InterfaceIdTraceResolver::Disconnect (std::string path, CallbackBase const &cb) { - Ptr interface = ParseForInterface (path); + Ptr interface = ParseForInterface (path); if (interface != 0) { interface->TraceDisconnect (GetSubpath (path), cb); @@ -232,12 +232,12 @@ Object::AddInterface (Ptr o) } void -Object::TraceConnect (std::string path, const CallbackBase &cb) +Object::TraceConnect (std::string path, const CallbackBase &cb) const { GetTraceResolver ()->Connect (path, cb, TraceContext ()); } void -Object::TraceDisconnect (std::string path, const CallbackBase &cb) +Object::TraceDisconnect (std::string path, const CallbackBase &cb) const { GetTraceResolver ()->Disconnect (path, cb); } @@ -256,7 +256,7 @@ Object::DoDispose (void) } Ptr -Object::GetTraceResolver (void) +Object::GetTraceResolver (void) const { Ptr resolver = Create (this); @@ -298,9 +298,9 @@ Object::MaybeDelete (void) const void Object::DoCollectSources (std::string path, const TraceContext &context, - TraceResolver::SourceCollection *collection) + TraceResolver::SourceCollection *collection) const { - Object *current; + const Object *current; current = this; do { if (current->m_collecting) diff --git a/src/core/object.h b/src/core/object.h index 8124ec991..ea4f091db 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -149,7 +149,7 @@ public: * match the input path. * */ - void TraceConnect (std::string path, const CallbackBase &cb); + void TraceConnect (std::string path, const CallbackBase &cb) const; /** * \param path the path to match for the callback * \param cb callback to disconnect @@ -157,13 +157,13 @@ public: * Disconnect the input callback from all trace sources which * match the input path. */ - void TraceDisconnect (std::string path, const CallbackBase &cb); + void TraceDisconnect (std::string path, const CallbackBase &cb) const; /** * \returns the trace resolver associated to this object. * * This method should be rarely called by users. */ - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; protected: /** * \param iid an InterfaceId @@ -183,13 +183,13 @@ private: friend class InterfaceIdTraceResolver; Ptr DoQueryInterface (InterfaceId iid) const; void DoCollectSources (std::string path, const TraceContext &context, - TraceResolver::SourceCollection *collection); + TraceResolver::SourceCollection *collection) const; bool Check (void) const; void MaybeDelete (void) const; mutable uint32_t m_count; InterfaceId m_iid; bool m_disposed; - bool m_collecting; + mutable bool m_collecting; Object *m_next; }; diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 06fea4895..8b11ec583 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -458,7 +458,7 @@ CsmaNetDevice::TransmitReadyEvent (void) } Ptr -CsmaNetDevice::GetTraceResolver (void) +CsmaNetDevice::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index 392e8c91d..db850914e 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -212,7 +212,7 @@ protected: * (NOT TESTED) * @see class TraceResolver */ - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; /** * Get a copy of the attached Queue. 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 e6c2d8de6..d2b5e45e0 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 @@ -195,7 +195,7 @@ void PointToPointNetDevice::TransmitComplete (void) } Ptr -PointToPointNetDevice::GetTraceResolver (void) +PointToPointNetDevice::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddChild ("queue", m_queue); 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 0adc8fde0..88544b7ed 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 @@ -158,7 +158,7 @@ protected: * * @see class TraceResolver */ - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; virtual void DoDispose (void); /** * Get a copy of the attached Queue. diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 2648c5ec4..c6dff084e 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -41,7 +41,7 @@ ArpIpv4Interface::~ArpIpv4Interface () {} Ptr -ArpIpv4Interface::GetTraceResolver (void) +ArpIpv4Interface::GetTraceResolver (void) const { Ptr resolver = Create (); if (GetDevice () != 0) diff --git a/src/internet-node/arp-ipv4-interface.h b/src/internet-node/arp-ipv4-interface.h index 73bf4f462..c5d36a29f 100644 --- a/src/internet-node/arp-ipv4-interface.h +++ b/src/internet-node/arp-ipv4-interface.h @@ -43,7 +43,7 @@ class ArpIpv4Interface : public Ipv4Interface virtual ~ArpIpv4Interface (); protected: - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; private: virtual void SendTo (Packet p, Ipv4Address dest); Ptr m_node; diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index 7bc9cd3c8..a27288ebc 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -75,7 +75,7 @@ InternetNode::Construct (void) } Ptr -InternetNode::GetTraceResolver () +InternetNode::GetTraceResolver () const { Ptr resolver = Create (); Ptr ipv4 = QueryInterface (Ipv4L3Protocol::iid); diff --git a/src/internet-node/internet-node.h b/src/internet-node/internet-node.h index d54714a8b..0c855029e 100644 --- a/src/internet-node/internet-node.h +++ b/src/internet-node/internet-node.h @@ -42,7 +42,7 @@ public: protected: virtual void DoDispose(void); - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; private: bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; void Construct (void); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 2eab180d9..1409cad50 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -159,7 +159,7 @@ Ipv4L3Protocol::SetupLoopback (void) } Ptr -Ipv4L3Protocol::GetTraceResolver (void) +Ipv4L3Protocol::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddSource ("tx", diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index ad9d482d2..f5e8aef04 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -171,7 +171,7 @@ public: protected: virtual void DoDispose (void); - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; private: diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 120b3f47e..b4e7e0860 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -84,7 +84,7 @@ Ipv4L4Demux::DoDispose (void) } Ptr -Ipv4L4Demux::GetTraceResolver (void) +Ipv4L4Demux::GetTraceResolver (void) const { Ptr resolver = Create (); for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index efd91bd44..40641485b 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -89,7 +89,7 @@ public: */ void Remove (Ptr protocol); protected: - Ptr GetTraceResolver (void); + Ptr GetTraceResolver (void) const; virtual void DoDispose (void); private: typedef std::list > L4List_t; diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index e7cb8bc3e..5dbb1bbc2 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -41,7 +41,7 @@ MobilityModelNotifier::Notify (Ptr position) const } Ptr -MobilityModelNotifier::GetTraceResolver (void) +MobilityModelNotifier::GetTraceResolver (void) const { Ptr resolver = Create (); diff --git a/src/mobility/mobility-model-notifier.h b/src/mobility/mobility-model-notifier.h index 0f8422d4e..1d2409f8e 100644 --- a/src/mobility/mobility-model-notifier.h +++ b/src/mobility/mobility-model-notifier.h @@ -48,7 +48,7 @@ public: */ void Notify (Ptr position) const; protected: - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; private: CallbackTraceSource > m_trace; }; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 7278f2e3a..9c3b27ce7 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -67,9 +67,9 @@ public: ~NodeListPriv (); uint32_t Add (Ptr node); - NodeList::Iterator Begin (void); - NodeList::Iterator End (void); - Ptr GetTraceResolver (void); + NodeList::Iterator Begin (void) const; + NodeList::Iterator End (void) const; + Ptr GetTraceResolver (void) const; Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); @@ -101,12 +101,12 @@ NodeListPriv::Add (Ptr node) } NodeList::Iterator -NodeListPriv::Begin (void) +NodeListPriv::Begin (void) const { return m_nodes.begin (); } NodeList::Iterator -NodeListPriv::End (void) +NodeListPriv::End (void) const { return m_nodes.end (); } @@ -124,7 +124,7 @@ NodeListPriv::GetNode (uint32_t n) Ptr -NodeListPriv::GetTraceResolver (void) +NodeListPriv::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddArray ("nodes", Begin (), End (), NodeListIndex ()); diff --git a/src/node/node-list.h b/src/node/node-list.h index dfb4e4ce9..d256953c1 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -54,7 +54,7 @@ private: class NodeList { public: - typedef std::vector< Ptr >::iterator Iterator; + typedef std::vector< Ptr >::const_iterator Iterator; /** * \param node node to add diff --git a/src/node/node.cc b/src/node/node.cc index 52231fa1b..c9b304a93 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -87,7 +87,7 @@ Node::~Node () {} Ptr -Node::GetTraceResolver (void) +Node::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ()); diff --git a/src/node/node.h b/src/node/node.h index 062f259c6..4f1c5be86 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -173,7 +173,7 @@ public: void UnregisterProtocolHandler (ProtocolHandler handler); protected: - virtual Ptr GetTraceResolver (void); + virtual Ptr GetTraceResolver (void) const; /** * The dispose method. Subclasses must override this method * and must chain up to it by calling Node::DoDispose at the diff --git a/src/node/queue.cc b/src/node/queue.cc index 809600854..74e36f3ee 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -100,7 +100,7 @@ Queue::~Queue() } Ptr -Queue::GetTraceResolver (void) +Queue::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddSource ("enqueue", diff --git a/src/node/queue.h b/src/node/queue.h index f10191fad..7b54f6e72 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -166,7 +166,7 @@ private: virtual bool DoPeek (Packet &p) = 0; protected: - Ptr GetTraceResolver (void); + Ptr GetTraceResolver (void) const; // called by subclasses to notify parent of packet drops. void Drop (const Packet& p); From c384b746f77d69b68fcbf0554bd7e7ef1fe0379a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 14:51:13 +0200 Subject: [PATCH 57/92] add doxygen documentation and rename TraceContext::Get to TraceContext::GetElement --- src/core/composite-trace-resolver.cc | 2 +- src/core/trace-context.cc | 32 +++++++++---------- src/core/trace-context.h | 46 ++++++++++++++++++++-------- src/core/trace-resolver.h | 15 ++++++--- src/internet-node/pcap-trace.cc | 2 +- 5 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 5f04b2c28..fb0c85d01 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -374,7 +374,7 @@ void CompositeTraceResolverTest::TraceDouble (TraceContext const &context, double v) { TraceSourceTest source; - context.Get (source); + context.GetElement (source); if (source.IsDoubleA ()) { m_gotDoubleA = true; diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index d065bfa73..e09f461ca 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -358,25 +358,25 @@ TraceContextTest::RunTests (void) { ok = false; } - ctx.Get (v0); + ctx.GetElement (v0); ctx.AddElement (v1); - ctx.Get (v1); - ctx.Get (v0); - ctx.Get (v1); + ctx.GetElement (v1); + ctx.GetElement (v0); + ctx.GetElement (v1); TraceContext copy = ctx; - ctx.Get (v0); - ctx.Get (v1); - copy.Get (v0); - copy.Get (v1); + ctx.GetElement (v0); + ctx.GetElement (v1); + copy.GetElement (v0); + copy.GetElement (v1); copy.AddElement (v2); - copy.Get (v0); - copy.Get (v1); - copy.Get (v2); + copy.GetElement (v0); + copy.GetElement (v1); + copy.GetElement (v2); ctx.AddElement (v3); - ctx.Get (v0); - ctx.Get (v1); - ctx.Get (v3); + ctx.GetElement (v0); + ctx.GetElement (v1); + ctx.GetElement (v3); if (ctx.SafeGet (v2)) { @@ -387,13 +387,13 @@ TraceContextTest::RunTests (void) ok = false; } ctx.Union (copy); - ctx.Get (v2); + ctx.GetElement (v2); if (copy.SafeGet (v3)) { ok = false; } copy.Union (ctx); - copy.Get (v3); + copy.GetElement (v3); return ok; } diff --git a/src/core/trace-context.h b/src/core/trace-context.h index fef2adcc6..13c9f15a7 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -34,8 +34,10 @@ namespace ns3 { * * Instances of this class are used to hold context * for each trace source. Each instance holds a list of - * 'contexts'. Trace sinks can lookup these contexts + * TraceContextElement. Trace sinks can lookup these contexts * from this list with the ns3::TraceContext::Get method. + * They can also ask the TraceContext for the list of + * TraceContextElements it contains with the PrintAvailable method. * * This class is implemented * using Copy On Write which means that copying unmodified @@ -54,6 +56,9 @@ public: /** * \param context add context to list of trace contexts. + * + * A copy of the input context is appended at the end of the list + * stored in this TraceContext. */ template void AddElement (T const &context); @@ -63,7 +68,7 @@ public: * * Perform the Union operation (in the sense of set theory) on the * two input lists of elements. This method is used in the - * ns3::CallbackTraceSourceSource class when multiple sinks are connected + * ns3::CallbackTraceSource class when multiple sinks are connected * to a single source to ensure that the source does not need * to store a single TraceContext instance per connected sink. * Instead, all sinks share the same TraceContext. @@ -72,15 +77,35 @@ public: /** * \param context context to get from this list of trace contexts. - * - * This method cannot fail. If the requested trace context is not - * stored in this TraceContext, then, the program will halt. + * \returns true if the requested trace context element was found + * in this TraceContext, false otherwise. */ template - void Get (T &context) const; + bool GetElement (T &context) const; + /** + * \param os a c++ STL output stream + * + * Iterate over the list of TraceContextElement stored in this + * TraceContext and invoke each of their Print method. + */ void Print (std::ostream &os) const; + /** + * \param os a c++ STL output stream + * \param separator the separator inserted between each TraceContextElement typename. + * + * Print the typename of each TraceContextElement stored in this TraceContext. + */ void PrintAvailable (std::ostream &os, std::string separator) const; + /** + * \param o another trace context + * \returns true if the input trace context contains exactly the same set of + * TraceContextElement instances, false otherwise. + * + * This method does not test for equality: the content of each matching + * TraceContextElement could be different. It merely checks that both + * trace contexts contain the same types of TraceContextElements. + */ bool IsSimilar (const TraceContext &o) const; private: friend class TraceContextTest; @@ -123,8 +148,8 @@ TraceContext::AddElement (T const &context) } } template -void -TraceContext::Get (T &context) const +bool +TraceContext::GetElement (T &context) const { TraceContextElement *parent; // if the following assignment fails, it is because the input @@ -132,10 +157,7 @@ TraceContext::Get (T &context) const parent = &context; uint8_t *data = (uint8_t *) &context; bool found = DoGet (T::GetUid (), data); - if (!found) - { - NS_FATAL_ERROR ("Type not stored in TraceContext"); - } + return found; } template bool diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 762717728..dcc0f9699 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -35,10 +35,9 @@ class CallbackBase; * namespace resolution. * \ingroup tracing * - * Subclasses must implement the two pure virtal methods defined in - * this base class: - * - ns3::TraceResolver::Connect - * - ns3::TraceResolver::Disconnect. + * Although users could conceivably implement their own trace resolver + * subclasses, doing so is complicated so, it is recommended to use + * the default implementation ns3::CompositeTraceResolver instead. */ class TraceResolver { @@ -88,6 +87,14 @@ public: typedef std::vector SourceVector; SourceVector m_sources; }; + /** + * \param path the path to the current recursive level. + * \param context the trace context associated to the current recursive level + * \param collection the collection in which to gather every trace source found. + * + * This method is invoked recursively until all trace sources have been + * stored in the output SourceCollection argument. + */ virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; protected: diff --git a/src/internet-node/pcap-trace.cc b/src/internet-node/pcap-trace.cc index dd0b39a29..3378b52c5 100644 --- a/src/internet-node/pcap-trace.cc +++ b/src/internet-node/pcap-trace.cc @@ -83,7 +83,7 @@ void PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex) { NodeListIndex nodeIndex; - context.Get (nodeIndex); + context.GetElement (nodeIndex); PcapWriter *writer = GetStream (nodeIndex.Get (), interfaceIndex); writer->WritePacket (p); } From 33e923540a142b6e9fa91ae9d68de64e4383ec57 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 15:04:37 +0200 Subject: [PATCH 58/92] add some doxygen --- src/core/trace-context-element.h | 6 ++++++ src/core/trace-source.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/core/trace-context-element.h b/src/core/trace-context-element.h index fa945294d..4ed08c3ac 100644 --- a/src/core/trace-context-element.h +++ b/src/core/trace-context-element.h @@ -48,6 +48,7 @@ namespace ns3 { * MyContext (); * ~MyContext (); * void Print (std::ostream &os) const; + * std::string GetName (void) const; * * // the user-specific API to manipulate the context. * void SetData (uint8_t data); @@ -71,6 +72,11 @@ namespace ns3 { * { * os << "mycontext=" << (uint32_t) m_myContextData; * } + * std::string + * MyContext::GetName (void) const + * { + * return "MyContext"; + * } * void * MyContext::SetData (uint8_t data) * { diff --git a/src/core/trace-source.h b/src/core/trace-source.h index 1b4c96577..9424b9086 100644 --- a/src/core/trace-source.h +++ b/src/core/trace-source.h @@ -23,11 +23,26 @@ namespace ns3 { +/** + * \brief the base class for all trace sources + * + * Every trace source which wishes to be connectable and disconnectable with + * the TraceResolver system should derive from this base class and implement + * all three methods below. + */ class TraceSource { public: virtual ~TraceSource () {} + /** + * \param callback the callback to connect to this trace source + * \param the context associated to the input callback which should be passed + * back to the user. + */ virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) = 0; + /** + * \param callback the callback to disconnect from this trace source + */ virtual void RemoveCallback (CallbackBase const & callback) = 0; }; From f9a61206857102c4c1dbbaa7854a2742e9f33478 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 15:59:49 +0200 Subject: [PATCH 59/92] avoid method naming ambiguity in CompositeTraceResolver --- src/core/composite-trace-resolver.cc | 36 +++++++++---------- src/core/composite-trace-resolver.h | 32 ++++++++--------- src/core/object.cc | 8 ++--- src/devices/csma/csma-net-device.cc | 4 +-- .../point-to-point-net-device.cc | 4 +-- src/internet-node/arp-ipv4-interface.cc | 4 +-- src/internet-node/internet-node.cc | 4 +-- src/internet-node/ipv4-l4-demux.cc | 4 +-- src/mobility/mobility-model-notifier.cc | 2 +- src/node/node.cc | 2 +- src/node/queue.cc | 2 +- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index fb0c85d01..0f4e782b8 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -38,7 +38,7 @@ CompositeTraceResolver::~CompositeTraceResolver () } void -CompositeTraceResolver::AddItem (CompositeItem *item) +CompositeTraceResolver::AddItem (ResolveItem *item) { m_items.push_back (item); } @@ -47,7 +47,7 @@ void CompositeTraceResolver::Add (std::string name, Callback > createResolver) { - class MakerCompositeItem : public CompositeItem + class MakerResolveItem : public ResolveItem { public: virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) @@ -64,7 +64,7 @@ CompositeTraceResolver::Add (std::string name, this->maker ()->CollectSources (path, ctx, collection); } Callback > maker; - } *item = new MakerCompositeItem (); + } *item = new MakerResolveItem (); item->name = name; item->context = TraceContext (); item->maker = createResolver; @@ -85,7 +85,7 @@ CompositeTraceResolver::DoAddSource (std::string name, const TraceSource &trace, const TraceContext &context) { - class SourceCompositeItem : public CompositeItem + class SourceResolveItem : public ResolveItem { public: virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) @@ -103,7 +103,7 @@ CompositeTraceResolver::DoAddSource (std::string name, } TraceSource *trace; TraceDoc doc; - } *item = new SourceCompositeItem (); + } *item = new SourceResolveItem (); item->name = name; item->context = context; item->trace = const_cast (&trace); @@ -115,20 +115,20 @@ CompositeTraceResolver::DoAddSource (std::string name, void -CompositeTraceResolver::AddChild (std::string name, Ptr child) +CompositeTraceResolver::AddComposite (std::string name, Ptr composite) { - DoAddChild (name, child, TraceContext ()); + DoAddComposite (name, composite, TraceContext ()); } void -CompositeTraceResolver::DoAddChild (std::string name, Ptr child, const TraceContext &context) +CompositeTraceResolver::DoAddComposite (std::string name, Ptr composite, const TraceContext &context) { - class ChildCompositeItem : public CompositeItem + class CompositeResolveItem : public ResolveItem { public: virtual void Connect (std::string subpath, const CallbackBase &cb, const TraceContext &context) - {child->GetTraceResolver ()->Connect (subpath, cb, context);} + {composite->GetTraceResolver ()->Connect (subpath, cb, context);} virtual void Disconnect (std::string subpath, const CallbackBase &cb) - {child->TraceDisconnect (subpath, cb);} + {composite->TraceDisconnect (subpath, cb);} virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) { @@ -136,19 +136,19 @@ CompositeTraceResolver::DoAddChild (std::string name, Ptr child, const T path.append (this->name); TraceContext ctx = context; ctx.Union (this->context); - this->child->GetTraceResolver ()->CollectSources (path, ctx, collection); + this->composite->GetTraceResolver ()->CollectSources (path, ctx, collection); } - Ptr child; - } *item = new ChildCompositeItem (); + Ptr composite; + } *item = new CompositeResolveItem (); item->name = name; item->context = context; - item->child = child; + item->composite = composite; AddItem (item); } void -CompositeTraceResolver::SetParent (Ptr resolver) +CompositeTraceResolver::SetParentResolver (Ptr resolver) { m_parent = resolver; } @@ -163,7 +163,7 @@ CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const ConnectOperation (const CallbackBase &cb, const TraceContext &context) : m_cb (cb), m_context (context) {} - virtual void Do (std::string subpath, CompositeItem *item) const + virtual void Do (std::string subpath, ResolveItem *item) const { NS_DEBUG ("connect to path="<SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } ns3::SVTraceSource m_source; @@ -385,7 +385,7 @@ public: ns3::Ptr resolver = ns3::Create (); resolver->AddSource ("deriveda-x", ns3::TraceDoc ("test source"), m_sourceDerived); - resolver->SetParent (BaseA::GetTraceResolver ()); + resolver->SetParentResolver (BaseA::GetTraceResolver ()); return resolver; } ns3::SVTraceSource m_sourceDerived; @@ -412,7 +412,7 @@ public: ns3::Ptr resolver = ns3::Create (); resolver->AddSource ("baseb-x", ns3::TraceDoc ("test source"), m_source); - resolver->SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } ns3::SVTraceSource m_source; @@ -436,7 +436,7 @@ public: ns3::Ptr resolver = ns3::Create (); resolver->AddSource ("derivedb-x", ns3::TraceDoc ("test source"), m_sourceDerived); - resolver->SetParent (BaseB::GetTraceResolver ()); + resolver->SetParentResolver (BaseB::GetTraceResolver ()); return resolver; } ns3::SVTraceSource m_sourceDerived; diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 8b11ec583..413478ad3 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -461,7 +461,7 @@ Ptr CsmaNetDevice::GetTraceResolver (void) const { Ptr resolver = Create (); - resolver->AddChild ("queue", m_queue); + resolver->AddComposite ("queue", m_queue); resolver->AddSource ("rx", TraceDoc ("receive MAC packet", "const Packet &", "packet received"), @@ -472,7 +472,7 @@ CsmaNetDevice::GetTraceResolver (void) const "const Packet &", "packet dropped"), m_dropTrace, CsmaTraceType (CsmaTraceType::DROP)); - resolver->SetParent (NetDevice::GetTraceResolver ()); + resolver->SetParentResolver (NetDevice::GetTraceResolver ()); return resolver; } 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 d2b5e45e0..cee375b53 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 @@ -198,13 +198,13 @@ Ptr PointToPointNetDevice::GetTraceResolver (void) const { Ptr resolver = Create (); - resolver->AddChild ("queue", m_queue); + resolver->AddComposite ("queue", m_queue); resolver->AddSource ("rx", TraceDoc ("receive MAC packet", "const Packet &", "packet received"), m_rxTrace, PointToPointTraceType ()); - resolver->SetParent (NetDevice::GetTraceResolver ()); + resolver->SetParentResolver (NetDevice::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index c6dff084e..3a03c5316 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -46,9 +46,9 @@ ArpIpv4Interface::GetTraceResolver (void) const Ptr resolver = Create (); if (GetDevice () != 0) { - resolver->AddChild ("netdevice", GetDevice ()); + resolver->AddComposite ("netdevice", GetDevice ()); } - resolver->SetParent (Ipv4Interface::GetTraceResolver ()); + resolver->SetParentResolver (Ipv4Interface::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/internet-node.cc b/src/internet-node/internet-node.cc index a27288ebc..5a927b55f 100644 --- a/src/internet-node/internet-node.cc +++ b/src/internet-node/internet-node.cc @@ -79,8 +79,8 @@ InternetNode::GetTraceResolver () const { Ptr resolver = Create (); Ptr ipv4 = QueryInterface (Ipv4L3Protocol::iid); - resolver->AddChild ("ipv4", ipv4); - resolver->SetParent (Node::GetTraceResolver ()); + resolver->AddComposite ("ipv4", ipv4); + resolver->SetParentResolver (Node::GetTraceResolver ()); return resolver; } diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index b4e7e0860..a4d83d49b 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -94,9 +94,9 @@ Ipv4L4Demux::GetTraceResolver (void) const std::ostringstream oss (protValue); oss << (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceContextElement protocolNumber = (*i)->GetProtocolNumber (); - resolver->AddChild (protValue, protocol, protocolNumber); + resolver->AddComposite (protValue, protocol, protocolNumber); } - resolver->SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } void diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index 5dbb1bbc2..ebe64f3df 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -50,7 +50,7 @@ MobilityModelNotifier::GetTraceResolver (void) const "Ptr", "the mobility model whose course changed"), m_trace); - resolver->SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } diff --git a/src/node/node.cc b/src/node/node.cc index c9b304a93..ed56ca8d8 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -91,7 +91,7 @@ Node::GetTraceResolver (void) const { Ptr resolver = Create (); resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ()); - resolver->SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } diff --git a/src/node/queue.cc b/src/node/queue.cc index 74e36f3ee..2ebc6c0d1 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -115,7 +115,7 @@ Queue::GetTraceResolver (void) const TraceDoc ("drop packet from queue", "const Packet &", "packet dropped"), m_traceDrop, QueueTraceType (QueueTraceType::DROP)); - resolver->SetParent (Object::GetTraceResolver ()); + resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; } From cda26929bdd689606d81452fa645406add6fefe2 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Aug 2007 16:06:12 +0200 Subject: [PATCH 60/92] some doxygen additions --- src/core/composite-trace-resolver.h | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index c0eb96bac..2a96149ca 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -45,6 +45,7 @@ public: virtual ~CompositeTraceResolver (); /** * \param name name of trace source + * \param doc the documentation associated to this trace source * \param trace a callback trace source * \param context the context associated to this trace source * @@ -58,6 +59,7 @@ public: const TraceSource &trace, T const &context); /** * \param name name of trace source + * \param doc the documentation associated to this trace source * \param trace a callback trace source * * Add a callback trace source in this resolver. This trace @@ -68,16 +70,48 @@ public: const TraceDoc &doc, const TraceSource &trace); + /** + * \param name the name of the composite element + * \param composite the composite object + * + * The input composite object will be used to resolve a connection + * of a disconnection attempt if its name matches the trace path. + * + */ void AddComposite (std::string name, Ptr composite); + /** + * \param name the name of the composite element + * \param composite the composite object + * \param contextElement the context element associated to the composite + * + * The input composite object will be used to resolve a connection + * of a disconnection attempt if its name matches the trace path. + * The contextElement will be appended to the TraceContext during connection. + */ template void AddComposite (std::string name, Ptr composite, const T &contextElement); + /** + * \param name the name of the array + * \param begin an iterator which points to the first element of the array + * \param begin an iterator which points to the last element of the array + * \param index an object which can store the index of an element in the + * array. In practice, this object should support a constructor + * whose single argument is an array index. + */ template void AddArray (std::string name, ITERATOR begin, ITERATOR end, INDEX index); - + /** + * \param parent the parent trace resolver + * + * The parent trace resolver is the trace resolver returned by the + * GetTraceResolver method of the base class of the caller. It is + * used during connection and disconnection to chain up the connect + * and disconnect calls to the parent. + */ void SetParentResolver (Ptr parent); From 69c4f021c970f73f226b44db5634347a0f42dc48 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 14:30:44 +0200 Subject: [PATCH 61/92] make the output of the list of existing traces more readable --- src/core/trace-resolver.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 698a23b7d..2feedd2b6 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -104,13 +104,19 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const i->context.PrintAvailable (os, ","); os << "]" << std::endl; os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl; - os << "const TraceContext &: the trace context associated to the connected trace source." << std::endl; - uint32_t k = 0; + os << "argument 0 -- the trace context associated to the connected trace source." << std::endl; + uint32_t k = 2; for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) { - os << "argument " << k << " -- " << j->first << ": " << j->second << "." << std::endl; + os << "argument " << k << " -- " << j->second << "." << std::endl; k++; } + os << "void TraceSinkCallback (const TraceContext &"; + for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) + { + os << ", " << k->first; + } + os << ")" << std::endl; os << std::endl; } } From ec3c5c7774fce36e99bb1af41ee6947108e9cf89 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 14:30:58 +0200 Subject: [PATCH 62/92] s/lowleveltracing/tracing/ --- doc/main.txt | 4 ++-- src/core/array-trace-resolver.h | 2 +- src/core/callback-trace-source.h | 2 +- src/core/sv-trace-source.h | 2 +- src/core/trace-context.h | 2 +- src/core/uv-trace-source.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/main.txt b/doc/main.txt index 3fc144687..37e1ed92d 100644 --- a/doc/main.txt +++ b/doc/main.txt @@ -23,6 +23,7 @@ * - \ref config * - a base class for objects which need to support reference counting * and QueryInterface: ns3::Object and ns3::InterfaceId + * - a set of low-level trace facilities integrated in the ns3::Object system: \ref tracing * - a ns3::ComponentManager which can be used to manage the creation * of any object which derives from ns3::Object through an ns3::ClassId * - a smart-pointer class ns3::Ptr designed to work together with ns3::Object @@ -33,11 +34,10 @@ * ns3::Scheduler and ns3::SchedulerFactory * - a simulator class used to create, schedule and cancel events: ns3::Simulator * - * The "common" module contains: + * The "core" module contains: * - a packet class to create and manipulate simulation packets: ns3::Packet, ns3::Header, * and ns3::Trailer. This packet class also supports per-packet ns3::Tag which are * globs of data which can be attached to any packet. - * - a set of low-level trace facilities: \ref lowleveltracing * * The "node" module contains: * - a ns3::Node base class which should be subclassed by any new type of diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index c3f8181a6..0d1086447 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -31,7 +31,7 @@ namespace ns3 { /** * \brief a helper class to offer trace resolution for an array of objects. - * \ingroup lowleveltracing + * \ingroup tracing * * \class ArrayTraceResolver * diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index 4b5f61b93..d571b5739 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -32,7 +32,7 @@ namespace ns3 { /** * \brief log arbitrary number of parameters to a matching ns3::Callback - * \ingroup lowleveltracing + * \ingroup tracing * * Whenever operator () is invoked on this class, the call and its arguments * are forwarded to the internal matching ns3::Callback. diff --git a/src/core/sv-trace-source.h b/src/core/sv-trace-source.h index 7c2bd8818..23d28f988 100644 --- a/src/core/sv-trace-source.h +++ b/src/core/sv-trace-source.h @@ -63,7 +63,7 @@ class UVTraceSource; /** * \brief trace variables of type "signed integer" - * \ingroup lowleveltracing + * \ingroup tracing * * This template class implements a POD type: it * behaves like any other variable of type "signed integer" diff --git a/src/core/trace-context.h b/src/core/trace-context.h index 13c9f15a7..4ca77d44f 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -30,7 +30,7 @@ namespace ns3 { /** * \brief Provide context to trace sources - * \ingroup lowleveltracing + * \ingroup tracing * * Instances of this class are used to hold context * for each trace source. Each instance holds a list of diff --git a/src/core/uv-trace-source.h b/src/core/uv-trace-source.h index 55602e614..ff248bbf4 100644 --- a/src/core/uv-trace-source.h +++ b/src/core/uv-trace-source.h @@ -67,7 +67,7 @@ class SVTraceSource; /** * \brief trace variables of type "unsigned integer" - * \ingroup lowleveltracing + * \ingroup tracing * * This template class implements a POD type: it * behaves like any other variable of type "unsigned integer" From cd40e709019f2ee44585032b155d0e52e3aaab4b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 14:41:21 +0200 Subject: [PATCH 63/92] improve output of list of existing traces --- src/core/trace-resolver.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index 2feedd2b6..f2bd31ea3 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -104,19 +104,19 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const i->context.PrintAvailable (os, ","); os << "]" << std::endl; os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl; - os << "argument 0 -- the trace context associated to the connected trace source." << std::endl; - uint32_t k = 2; - for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) - { - os << "argument " << k << " -- " << j->second << "." << std::endl; - k++; - } os << "void TraceSinkCallback (const TraceContext &"; for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) { os << ", " << k->first; } os << ")" << std::endl; + os << "argument 1 -- the trace context associated to the connected trace source." << std::endl; + uint32_t k = 2; + for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) + { + os << "argument " << k << " -- " << j->second << "." << std::endl; + k++; + } os << std::endl; } } From c8967b4b5eab407283e4c29dc5a552d84c8ed511 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 14:43:31 +0200 Subject: [PATCH 64/92] add some tracing documentation --- src/core/tracing.h | 297 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 src/core/tracing.h diff --git a/src/core/tracing.h b/src/core/tracing.h new file mode 100644 index 000000000..44e4577c6 --- /dev/null +++ b/src/core/tracing.h @@ -0,0 +1,297 @@ +/** + * \defgroup tracing Tracing + * + * The flexibility of the ns-3 tracing system comes at the cost of quite + * a bit of complexity so, before trying to use the low-level aspects + * of the tracing API, it is important to focus on some basic definitions: + * + * - A trace source is an object instance which can report trace events + * to a set of listening trace sinks. + * + * - A trace sink is a user-provided callback (a function) which can + * be connected to a set of trace sources to receive the events generated + * by each trace source. + * + * - Trace context: each trace source instance is associated with a single + * trace context which can be used by each connected trace sink to + * identify the instance of the source of the event. + * + * - A trace resolver is an object which allows users to establish + * connections between a set of trace sources and a set of trace sinks. + * The trace contexts are configured during connection by the trace + * resolvers. + * + * So, what does it look like in practice ? First, let's look at trace + * sources. We have two types of trace sources: numeric, and, normal + * trace sources. Numeric trace sources behave as normal c++ integers + * or c++ floating point numbers except that they report as trace events + * each change of their value. For example: + * \code + * class MyModel + * { + * public: + * void DoSomething (void) + * { + * // use the "int" trace source just + * // like any other "int" variable. + * m_cwnd *= 2; + * m_cwnd += 4; + * if (m_cwnd > 100) + * { + * // do something. + * } + * } + * private: + * // declare an instance of a "int" trace source + * SVTraceSource m_cwnd; + * }; + * \endcode + * Normal trace sources, on the other hand, allow you to trace the + * call of arbitrary functions and methods, as shown below. They are + * typically used to track "rx", "tx", or "drop" events but could + * also be used to track route change events, or position change + * events: + * \code + * class MyModel + * { + * public: + * void DoSomething (Packet packet, double value) + * { + * m_doSomething (packet, value); + * // do something + * } + * private: + * // report every "something" function call. + * CallbackTraceSource m_doSomething; + * }; + * \endcode + * Every type of trace source derives from the ns3::TraceSource base class. + * As of today, the set of concrete subclasses is relatively short: + * ns3::CallbackTraceSource, ns3::SvTraceSource, ns3::UvTraceSource, and, + * ns3::FvTraceSource. + * + * To receive these trace events, a user should specify a set of trace sinks. + * For example, to receive the "int" and the "something events outlined + * above, a user would declare the following functions which receive + * as an extra first argument the context of the trace source which + * generated the specific event. + * \code + * // oldValue and newValue contain the previous and new values of + * // the connected SVTraceSource trace source. + * void + * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue) + * { + * // for example, print the new value: + * std::cout << "cwnd=" << newValue << std::endl; + * } + * void + * DoSomethingTraceSink (const TraceContext &context, Packet packet, double value) + * { + * // for example, print the arguments + * std::cout << "value=" << value << ", packet " << packet << std::endl; + * } + * \endcode + * + * The hard part of this tracing framework is the "connection" step: there is a point + * in the simulation scenario where the user is expected to specify which trace sources + * should be connected to which trace sinks. There are many ways to do this: the + * users who want to could implement the "quick and dirty" way, that is, they could + * write adhoc code to connect their trace sinks to the trace sources using the + * TraceSource::AddCallback method. For example, they could patch their models to + * the following: + * \code + * class MyModel + * { + * public: + * void DoSomething (void) + * { + * // ... + * } + * SVTraceSource *GetCwndTraceSource (void) const + * { + * return &m_cwnd; + * } + * private: + * // declare an instance of a "int" trace source + * SVTraceSource m_cwnd; + * }; + * \endcode + * And, then, call directly the GetCwndTraceSource method: + * \code + * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue) + * { + * // for example, print the new value: + * std::cout << "cwnd=" << newValue << std::endl; + * } + * // create a model instance + * MyModel *model = ...; + * SVTraceSource *cwnd = model->GetCwndTraceSource (); + * // connect the trace sink to the cwnd trace source of + * // this model instance. + * cwnd->AddCallback (MakeCallback (&CwndTraceSink), + * TraceContext ()); + * \endcode + * + * The solution described above is simple to implement for a model + * author but it is hard to extend and becomes quickly cumbersome + * to use with complex models made of composite objects. TraceResolvers + * deal with these problems and offer a simple API to connect large + * sets of trace sources to a single sink (as is typical for simulations + * where users want to receive the "ipv4 rx" events from all nodes). + * + * The user-visible API to connect and disconnect trace sources to + * and from trace sinks is quite small: ns3::Object::Connect + * and ns3::Object::Disconnect both take a "namespace" regexp string + * and a callback. The input callback is connected to each trace source + * which matches the namespace regexp string. The format of the namespace + * string depends on the set of models implemented by the simulator. + * The following diagram shows a small part of the namespace exported + * by the current version of the simulator: + * + * \image html namespace-2.png ns-3 namespace + * + * In this namespace, the "rx" trace source of the PointToPointNetdevice + * index 0 within node index 3 is uniquely identified by the namespace + * string "/nodes/3/devices/0/rx". It is also possible to match all + * such "rx" trace sources with a single namespace string using + * a limited form of regular expressions: "/nodes/3/devices/* /rx" + * identifies the "rx" trace source within all NetDevices within node + * index 3. Similarly, "/nodes/* /devices/* /rx" identifies the "rx" + * trace source within all NetDevices within all nodes. It is thus + * possible to connect a single trace sink to a set of matching trace + * sources in a single operation: + * \code + * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * { + * // context contains enough information to uniquely identify + * // the trace source instance. + * std::cout << "context: \"" << context << "\""; + * // packet is the per-event information conveyed from the + * // trace source to the trace sink. + * std:: cout << " packet: " << packet << std::endl; + * } + * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback (&DeviceRxSink)); + * \endcode + * Which, at runtime, is going to generate output looking like this: + * \code + * context: "nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... + * context: "nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... + * ... + * \endcode + * In the example above, we see that the ns3::TraceContext contains three + * ns3::TraceContextElement which were printed using a space separator: + * - nodeid=i + * - device=j + * - dev-rx + * + * Of course, the user could also extract each of these elements from + * the context to generate a different output: + * \code + * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * { + * NodeListIndex nodeIndex; + * NodeNetDeviceIndex deviceIndex; + * context.Get (nodeIndex); + * context.Get (deviceIndex); + * std::cout << "node-index=" << nodeIndex.Get (); + * std::cout << ", device-index=" << deviceIndex.Get (); + * std::cout << ", packet: " << packet; + * std::cout << std::endl; + * } + * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback (&DeviceRxSink)); + * \endcode + * Extracting TraceContextElement objects from a TraceContext in this manner + * raises a few obvious questions: + * - how do I know which trace context elements are present in a given + * TraceContext ? + * - how are these elements added to the TraceContext ? + * + * + * + * + * Connecting trace sinks to a set of existing trace sources is nice but + * model developers also often need to be able to create new trace sources + * and hook them into the namespace resolution system. Creating new trace + * sources is pretty easy: it is a matter of instantiating a proper + * subclass of the ns3::TraceSource base class. However, hooking each + * new trace source in the overall namespace resolution system requires + * some new effort. The core requirement is that the user needs to + * subclass from the ns3::Object base class which provides the most + * basic ns3::Object::Connect, and, ns3::Object::Disconnect methods. + * These two methods are simple forwarding methods to the virtual + * ns3::Object::GetTraceResolver method which does the bulk of the work + * required to setup properly trace sources. + * + * Every subclass of the ns3::Object base class which wishes to export + * a set of trace sources and make them available through the Connect/Disconnect + * functions needs to override the ns3::Object::GetTraceResolver method. + * This method needs to return a subclass of the ns3::TraceResolver + * base class which implements the ns3::TraceResolver::Connect and + * ns3::TraceResolver::Disconnect methods. Providing an implementation + * of these two methods is a bit complicated so, a default implementation + * named CompositeTraceResolver is provided: + * \code + * class MyModel : public Object + * { + * public: + * void DoSomething (void) + * { + * // change value of m_cwnd + * } + * protected: + * virtual Ptr GetTraceResolver (void) + * { + * // create the composite resolver + * Ptr resolver = Create (); + * resolver->AddSource ("cwnd", m_cwnd); + * resolver->AddSource ("rx", m_rx); + * return resolver; + * } + * private: + * SVTraceSource m_cwnd; + * CallbackTraceSource m_rx; + * }; + * void MyTraceSink (const TraceContext &context, Packet packet) + * { + * std::cout << context << " packet: " << packet << std::endl; + * } + * object->Connect ("/.../rx", MakeCallback (&MyTraceSink)); + * \endcode + * + * The above example is enough to export a trace source as a member of the + * tracing namespace so, it would be enough to allow a user to perform a + * pair of Connect/Disconnect operations but it would not be enough to allow + * a TraceContext to contain information about these trace sources. Specifically, + * printing the content of the TraceContext as shown above would give no + * information whatsoever about the type of trace source which was connected. + * + * but it is not enough to allow the TraceContext + * stored in each TraceSource to store information about these trace sources. + * + * - A trace source: a trace source is an object instance which is a + * subclass of the ns3::TraceSource base class. Each instance + * of a trace source should be used to report a single type of + * event. For example, if you want to report ipv4 rx and tx events, + * you should use two different trace source instances. + * + * - Trace sinks: a trace sink is a callback, that is, a function, + * which is provided by the user of a model to receive the events + * reported by a set of trace sources within that model. A trace + * sink is said to be "connected" once it has been associated + * to a set of trace sources. + * + * - Trace context: each trace source instance is associated with a single + * instance of an immutable trace context. Each ns3::TraceContext stores + * a set of trace context element instances, each of which is a subclass + * of the ns3::TraceContextElement base class. Whenever a trace sink + * provided by a user is called because a trace event was reported on + * a connected trace source, the trace context associated to the + * relevant trace source is passed as an extra argument to the user's + * trace sink. + * + * - instrumentation of models is done through a set of trace source + * instances, each of which is a subclass of the ns3::TraceSource + * base class. + * + * + */ From 45f247393e5280b8e621590f32a02cca5653754d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 15:11:29 +0200 Subject: [PATCH 65/92] add some text on trace sink signatures --- src/core/tracing.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/tracing.h b/src/core/tracing.h index 44e4577c6..ca017a55e 100644 --- a/src/core/tracing.h +++ b/src/core/tracing.h @@ -12,14 +12,8 @@ * be connected to a set of trace sources to receive the events generated * by each trace source. * - * - Trace context: each trace source instance is associated with a single - * trace context which can be used by each connected trace sink to - * identify the instance of the source of the event. - * * - A trace resolver is an object which allows users to establish * connections between a set of trace sources and a set of trace sinks. - * The trace contexts are configured during connection by the trace - * resolvers. * * So, what does it look like in practice ? First, let's look at trace * sources. We have two types of trace sources: numeric, and, normal @@ -71,10 +65,8 @@ * ns3::FvTraceSource. * * To receive these trace events, a user should specify a set of trace sinks. - * For example, to receive the "int" and the "something events outlined - * above, a user would declare the following functions which receive - * as an extra first argument the context of the trace source which - * generated the specific event. + * For example, to receive the "int" and the "something" events shown in the + * examples above, a user would declare the following functions: * \code * // oldValue and newValue contain the previous and new values of * // the connected SVTraceSource trace source. @@ -91,6 +83,18 @@ * std::cout << "value=" << value << ", packet " << packet << std::endl; * } * \endcode + * Each of these sink function takes, as a first argument, a reference to a + * const TraceContext object. This context object contains information which + * describes the instance of the connected trace source: that information is + * setup during the connection process and does not change afterwards + * The type and the number of the other arguments to each trace sink depends + * on the type of the connected trace source: it conveys per-event information + * from the trace source to the trace sink. For example, UVTraceSource and + * SVTraceSource trace sources require two extra arguments. The former requires + * two unsigned 64 bit integers while the latter requires two signed 64 bit + * integers. More generally, users can consult the \ref trace-source-list + * to figure out the arguments which a trace sink is required to receive + * for each trace source. * * The hard part of this tracing framework is the "connection" step: there is a point * in the simulation scenario where the user is expected to specify which trace sources From 01d0b1767c5559934205cbdd3abd7758b13d1f49 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:41:23 +0200 Subject: [PATCH 66/92] empty file for doxygen generation --- doc/trace-source-list.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/trace-source-list.h diff --git a/doc/trace-source-list.h b/doc/trace-source-list.h new file mode 100644 index 000000000..e69de29bb From 45c531c463bfe932f849b2dcd76297cd3895ebfa Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:42:00 +0200 Subject: [PATCH 67/92] ignore empty file --- .hgignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgignore b/.hgignore index 96ea69ce7..93984cae5 100644 --- a/.hgignore +++ b/.hgignore @@ -6,6 +6,7 @@ build .*\.sconsign doc/html.* doc/latex.* +doc/trace-source-list.h .lock-wscript .waf* waf From 15234069fed92532ee21112c2641bc162dd653e6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:42:18 +0200 Subject: [PATCH 68/92] add trace-source-file.h to doxygen list --- doc/doxygen.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 7d6248d95..6f4b503d7 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -450,7 +450,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = src doc/main.txt +INPUT = src doc/main.txt doc/trace-source-list.h # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp From 0e177e766a8ada01260976e9ac94afa0c6711ada Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:42:55 +0200 Subject: [PATCH 69/92] add iterator to go through available list --- src/core/trace-context.cc | 91 +++++++++++++++++++++++++++++++++++++++ src/core/trace-context.h | 20 +++++++++ 2 files changed, 111 insertions(+) diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index e09f461ca..23842d00a 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -24,6 +24,72 @@ namespace ns3 { +TraceContext::Iterator & +TraceContext::Iterator::operator ++ (void) +{ + ReadOne (); + return *this; +} +TraceContext::Iterator +TraceContext::Iterator::operator ++ (int) +{ + Iterator old (*this); + ReadOne (); + return old; +} +const std::string & +TraceContext::Iterator::operator * (void) const +{ + return m_name; +} +const std::string * +TraceContext::Iterator::operator -> (void) const +{ + return &m_name; +} +TraceContext::Iterator::Iterator (uint8_t *buffer) + : m_buffer (buffer), + m_current (0) +{ + ReadOne (); +} +TraceContext::Iterator::Iterator (uint8_t *buffer, uint16_t index) + : m_buffer (buffer), + m_current (index) +{} +void +TraceContext::Iterator::ReadOne (void) +{ + if (m_buffer == 0) + { + return; + } + uint8_t uid = m_buffer[m_current]; + uint8_t size = ElementRegistry::GetSize (uid); + m_name = ElementRegistry::GetName (uid); + m_current += 1 + size; +} +bool +TraceContext::Iterator::operator != (const Iterator &o) +{ + return ! (*this == o); +} +bool +TraceContext::Iterator::operator == (const Iterator &o) +{ + if (m_buffer == 0 && o.m_buffer == 0) + { + return true; + } + if (m_buffer != 0 && o.m_buffer == 0 || + m_buffer == 0 && o.m_buffer != 0) + { + return false; + } + return m_current == o.m_current; +} + + TraceContext::TraceContext () : m_data (0) {} @@ -230,6 +296,31 @@ TraceContext::Print (std::ostream &os) const } } while (true); } +TraceContext::Iterator +TraceContext::AvailableBegin (void) const +{ + if (m_data == 0) + { + return Iterator (0); + } + return Iterator (m_data->data); +} +TraceContext::Iterator +TraceContext::AvailableEnd (void) const +{ + if (m_data == 0) + { + return Iterator (0); + } + uint8_t currentUid; + uint16_t i = 0; + do { + currentUid = m_data->data[i]; + uint8_t size = ElementRegistry::GetSize (currentUid); + i += 1 + size; + } while (i < m_data->size && currentUid != 0); + return Iterator (m_data->data, i); +} void TraceContext::PrintAvailable (std::ostream &os, std::string separator) const diff --git a/src/core/trace-context.h b/src/core/trace-context.h index 4ca77d44f..5ab3cd3c6 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -97,6 +97,26 @@ public: * Print the typename of each TraceContextElement stored in this TraceContext. */ void PrintAvailable (std::ostream &os, std::string separator) const; + class Iterator + { + public: + Iterator &operator ++ (void); + Iterator operator ++ (int); + const std::string &operator * (void) const; + const std::string *operator -> (void) const; + bool operator == (const Iterator &o); + bool operator != (const Iterator &o); + private: + friend class TraceContext; + Iterator (uint8_t *buffer); + Iterator (uint8_t *buffer, uint16_t index); + void ReadOne (void); + uint8_t *m_buffer; + uint16_t m_current; + std::string m_name; + }; + Iterator AvailableBegin (void) const; + Iterator AvailableEnd (void) const; /** * \param o another trace context * \returns true if the input trace context contains exactly the same set of From c5b3ed12a0965c52070aff532506a9bbed912194 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:43:04 +0200 Subject: [PATCH 70/92] add PrintDoxygen method --- src/core/trace-resolver.cc | 47 +++++++++++++++++++++++++++++++++++++- src/core/trace-resolver.h | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index f2bd31ea3..ff0448ca3 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -94,7 +94,7 @@ TraceResolver::SourceCollection::AddUnique (std::string path, source.doc = doc; m_sources.push_back (source); } -void +void TraceResolver::SourceCollection::Print (std::ostream &os) const { for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) @@ -120,5 +120,50 @@ TraceResolver::SourceCollection::Print (std::ostream &os) const os << std::endl; } } +void +TraceResolver::SourceCollection::PrintDoxygen (std::ostream &os) const +{ + uint32_t z = 0; + for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) + { + os << "///" << std::endl; + os << "/// \\ingroup TraceSourceList" << std::endl; + os << "/// \\brief " << i->doc.GetHelp () << std::endl; + os << "/// \\param arg1 the trace context associated to the connected trace source." << std::endl; + uint32_t j = 2; + for (TraceDoc::Iterator l = i->doc.ArgsBegin (); l != i->doc.ArgsEnd (); l++) + { + os << "/// \\param arg" << j << " " << l->second << "." << std::endl; + j++; + } + os << "///" << std::endl; + os << "///" << std::endl; + os << "/// The path to this trace source is: " << i->path << "." << std::endl; + os << "///" << std::endl; + if (i->context.AvailableBegin () == i->context.AvailableEnd ()) + { + os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl; + } + else + { + os << "/// The following classes can be extracted from \\p arg1 with " << std::endl; + os << "/// ns3::TraceContext::GetElement:" << std::endl; + for (TraceContext::Iterator m = i->context.AvailableBegin (); m != i->context.AvailableEnd (); m++) + { + os << "/// - " << (*m) << std::endl; + } + } + os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ; + j = 2; + for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) + { + os << ", " << k->first << " arg" << j; + j++; + } + os << ");" << std::endl; + os << std::endl; + z++; + } +} }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index dcc0f9699..9bf429b12 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -74,6 +74,7 @@ public: { public: void Print (std::ostream &os) const; + void PrintDoxygen (std::ostream &os) const; void AddUnique (std::string path, const TraceContext &context, const TraceDoc &doc); From ca379f08141cfef572081e0e5e45452f518f596a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 29 Aug 2007 16:43:19 +0200 Subject: [PATCH 71/92] reference the proper trace source list group --- src/core/tracing.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/tracing.h b/src/core/tracing.h index ca017a55e..0612b144e 100644 --- a/src/core/tracing.h +++ b/src/core/tracing.h @@ -1,3 +1,7 @@ +/** + * \defgroup TraceSourceList List of trace sources + */ + /** * \defgroup tracing Tracing * @@ -92,7 +96,7 @@ * from the trace source to the trace sink. For example, UVTraceSource and * SVTraceSource trace sources require two extra arguments. The former requires * two unsigned 64 bit integers while the latter requires two signed 64 bit - * integers. More generally, users can consult the \ref trace-source-list + * integers. More generally, users can consult the \ref TraceSourceList * to figure out the arguments which a trace sink is required to receive * for each trace source. * From d23b3123ba0ae31e195f428e9be7c0fa53dbbd5a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 13:58:15 +0200 Subject: [PATCH 72/92] move printing to client code --- src/core/trace-resolver.cc | 74 +++-------------------------------- src/core/trace-resolver.h | 14 ++++--- utils/print-trace-sources.cc | 75 +++++++++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 75 deletions(-) diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index ff0448ca3..d891c94c4 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -94,76 +94,14 @@ TraceResolver::SourceCollection::AddUnique (std::string path, source.doc = doc; m_sources.push_back (source); } -void -TraceResolver::SourceCollection::Print (std::ostream &os) const +TraceResolver::SourceCollection::Iterator +TraceResolver::SourceCollection::Begin (void) const { - for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) - { - os << "source=" << i->path << std::endl; - os << "TraceContext=["; - i->context.PrintAvailable (os, ","); - os << "]" << std::endl; - os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl; - os << "void TraceSinkCallback (const TraceContext &"; - for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) - { - os << ", " << k->first; - } - os << ")" << std::endl; - os << "argument 1 -- the trace context associated to the connected trace source." << std::endl; - uint32_t k = 2; - for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) - { - os << "argument " << k << " -- " << j->second << "." << std::endl; - k++; - } - os << std::endl; - } + return m_sources.begin (); } -void -TraceResolver::SourceCollection::PrintDoxygen (std::ostream &os) const +TraceResolver::SourceCollection::Iterator +TraceResolver::SourceCollection::End (void) const { - uint32_t z = 0; - for (SourceVector::const_iterator i = m_sources.begin (); i != m_sources.end (); i++) - { - os << "///" << std::endl; - os << "/// \\ingroup TraceSourceList" << std::endl; - os << "/// \\brief " << i->doc.GetHelp () << std::endl; - os << "/// \\param arg1 the trace context associated to the connected trace source." << std::endl; - uint32_t j = 2; - for (TraceDoc::Iterator l = i->doc.ArgsBegin (); l != i->doc.ArgsEnd (); l++) - { - os << "/// \\param arg" << j << " " << l->second << "." << std::endl; - j++; - } - os << "///" << std::endl; - os << "///" << std::endl; - os << "/// The path to this trace source is: " << i->path << "." << std::endl; - os << "///" << std::endl; - if (i->context.AvailableBegin () == i->context.AvailableEnd ()) - { - os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl; - } - else - { - os << "/// The following classes can be extracted from \\p arg1 with " << std::endl; - os << "/// ns3::TraceContext::GetElement:" << std::endl; - for (TraceContext::Iterator m = i->context.AvailableBegin (); m != i->context.AvailableEnd (); m++) - { - os << "/// - " << (*m) << std::endl; - } - } - os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ; - j = 2; - for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) - { - os << ", " << k->first << " arg" << j; - j++; - } - os << ");" << std::endl; - os << std::endl; - z++; - } + return m_sources.end (); } - }//namespace ns3 diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index 9bf429b12..c78a6f21d 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -73,18 +73,20 @@ public: class SourceCollection { public: - void Print (std::ostream &os) const; - void PrintDoxygen (std::ostream &os) const; - void AddUnique (std::string path, - const TraceContext &context, - const TraceDoc &doc); - private: struct Source { std::string path; TraceContext context; TraceDoc doc; }; + typedef std::vector::const_iterator Iterator; + void AddUnique (std::string path, + const TraceContext &context, + const TraceDoc &doc); + + Iterator Begin (void) const; + Iterator End (void) const; + private: typedef std::vector SourceVector; SourceVector m_sources; }; diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc index 21f8eb1da..a4e3d01c9 100644 --- a/utils/print-trace-sources.cc +++ b/utils/print-trace-sources.cc @@ -9,6 +9,79 @@ using namespace ns3; +void +PrintSimpleText (const TraceResolver::SourceCollection *sources, std::ostream &os) +{ + for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++) + { + os << "source=" << i->path << std::endl; + os << "TraceContext=["; + i->context.PrintAvailable (os, ","); + os << "]" << std::endl; + os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl; + os << "void TraceSinkCallback (const TraceContext &"; + for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) + { + os << ", " << k->first; + } + os << ")" << std::endl; + os << "argument 1 -- the trace context associated to the connected trace source." << std::endl; + uint32_t k = 2; + for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++) + { + os << "argument " << k << " -- " << j->second << "." << std::endl; + k++; + } + os << std::endl; + } +} +void +PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream &os) +{ + uint32_t z = 0; + for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++) + { + os << "///" << std::endl; + os << "/// \\ingroup TraceSourceList" << std::endl; + os << "/// \\brief " << i->doc.GetHelp () << std::endl; + os << "/// \\param arg1 the trace context associated to the connected trace source." << std::endl; + uint32_t j = 2; + for (TraceDoc::Iterator l = i->doc.ArgsBegin (); l != i->doc.ArgsEnd (); l++) + { + os << "/// \\param arg" << j << " " << l->second << "." << std::endl; + j++; + } + os << "///" << std::endl; + os << "///" << std::endl; + os << "/// The path to this trace source is: " << i->path << "." << std::endl; + os << "///" << std::endl; + if (i->context.AvailableBegin () == i->context.AvailableEnd ()) + { + os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl; + } + else + { + os << "/// The following classes can be extracted from \\p arg1 with " << std::endl; + os << "/// ns3::TraceContext::GetElement:" << std::endl; + for (TraceContext::Iterator m = i->context.AvailableBegin (); m != i->context.AvailableEnd (); m++) + { + os << "/// - " << (*m) << std::endl; + } + } + os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ; + j = 2; + for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++) + { + os << ", " << k->first << " arg" << j; + j++; + } + os << ");" << std::endl; + os << std::endl; + z++; + } +} + + int main (int argc, char *argv[]) { Ptr node = Create (); @@ -21,7 +94,7 @@ int main (int argc, char *argv[]) TraceResolver::SourceCollection collection; NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection); - collection.Print (std::cout); + PrintDoxygenText (&collection, std::cout); return 0; } From 62df1e933bf9220bf1dd142266bd17e2c51395b5 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 14:25:09 +0200 Subject: [PATCH 73/92] rewrite the TraceContext::SourceCollection::Iterator class --- src/core/trace-context.cc | 102 ++++++++++++----------------------- src/core/trace-context.h | 18 +++---- utils/print-trace-sources.cc | 6 +-- 3 files changed, 43 insertions(+), 83 deletions(-) diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index 23842d00a..4c77d741f 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -24,71 +24,51 @@ namespace ns3 { -TraceContext::Iterator & -TraceContext::Iterator::operator ++ (void) -{ - ReadOne (); - return *this; -} -TraceContext::Iterator -TraceContext::Iterator::operator ++ (int) -{ - Iterator old (*this); - ReadOne (); - return old; -} -const std::string & -TraceContext::Iterator::operator * (void) const -{ - return m_name; -} -const std::string * -TraceContext::Iterator::operator -> (void) const -{ - return &m_name; -} -TraceContext::Iterator::Iterator (uint8_t *buffer) +TraceContext::Iterator::Iterator () + : m_buffer (0), + m_size (0), + m_current (0) +{} +TraceContext::Iterator::Iterator (uint8_t *buffer, uint16_t size) : m_buffer (buffer), + m_size (size), m_current (0) { - ReadOne (); + m_uid = m_buffer[m_current]; +} +bool +TraceContext::Iterator::IsLast (void) const +{ + if (m_buffer == 0 || m_uid == 0 || m_current >= m_size) + { + return true; + } + return false; } -TraceContext::Iterator::Iterator (uint8_t *buffer, uint16_t index) - : m_buffer (buffer), - m_current (index) -{} void -TraceContext::Iterator::ReadOne (void) +TraceContext::Iterator::Next (void) { if (m_buffer == 0) { return; } - uint8_t uid = m_buffer[m_current]; - uint8_t size = ElementRegistry::GetSize (uid); - m_name = ElementRegistry::GetName (uid); - m_current += 1 + size; -} -bool -TraceContext::Iterator::operator != (const Iterator &o) -{ - return ! (*this == o); -} -bool -TraceContext::Iterator::operator == (const Iterator &o) -{ - if (m_buffer == 0 && o.m_buffer == 0) + if (m_uid == 0) { - return true; + return; } - if (m_buffer != 0 && o.m_buffer == 0 || - m_buffer == 0 && o.m_buffer != 0) + else { - return false; + uint8_t size = ElementRegistry::GetSize (m_uid); + m_current += 1 + size; } - return m_current == o.m_current; + m_uid = m_buffer[m_current]; +} +std::string +TraceContext::Iterator::Get (void) const +{ + std::string name = ElementRegistry::GetName (m_uid); + return name; } - TraceContext::TraceContext () : m_data (0) @@ -297,29 +277,13 @@ TraceContext::Print (std::ostream &os) const } while (true); } TraceContext::Iterator -TraceContext::AvailableBegin (void) const +TraceContext::Begin (void) const { if (m_data == 0) { - return Iterator (0); + return Iterator (); } - return Iterator (m_data->data); -} -TraceContext::Iterator -TraceContext::AvailableEnd (void) const -{ - if (m_data == 0) - { - return Iterator (0); - } - uint8_t currentUid; - uint16_t i = 0; - do { - currentUid = m_data->data[i]; - uint8_t size = ElementRegistry::GetSize (currentUid); - i += 1 + size; - } while (i < m_data->size && currentUid != 0); - return Iterator (m_data->data, i); + return Iterator (m_data->data, m_data->size); } void diff --git a/src/core/trace-context.h b/src/core/trace-context.h index 5ab3cd3c6..908f3ecb9 100644 --- a/src/core/trace-context.h +++ b/src/core/trace-context.h @@ -100,23 +100,19 @@ public: class Iterator { public: - Iterator &operator ++ (void); - Iterator operator ++ (int); - const std::string &operator * (void) const; - const std::string *operator -> (void) const; - bool operator == (const Iterator &o); - bool operator != (const Iterator &o); + void Next (void); + bool IsLast (void) const; + std::string Get (void) const; private: friend class TraceContext; - Iterator (uint8_t *buffer); + Iterator (); Iterator (uint8_t *buffer, uint16_t index); - void ReadOne (void); uint8_t *m_buffer; + uint16_t m_size; uint16_t m_current; - std::string m_name; + uint8_t m_uid; }; - Iterator AvailableBegin (void) const; - Iterator AvailableEnd (void) const; + Iterator Begin (void) const; /** * \param o another trace context * \returns true if the input trace context contains exactly the same set of diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc index a4e3d01c9..af7cfb755 100644 --- a/utils/print-trace-sources.cc +++ b/utils/print-trace-sources.cc @@ -55,7 +55,7 @@ PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream & os << "///" << std::endl; os << "/// The path to this trace source is: " << i->path << "." << std::endl; os << "///" << std::endl; - if (i->context.AvailableBegin () == i->context.AvailableEnd ()) + if (i->context.Begin ().IsLast ()) { os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl; } @@ -63,9 +63,9 @@ PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream & { os << "/// The following classes can be extracted from \\p arg1 with " << std::endl; os << "/// ns3::TraceContext::GetElement:" << std::endl; - for (TraceContext::Iterator m = i->context.AvailableBegin (); m != i->context.AvailableEnd (); m++) + for (TraceContext::Iterator m = i->context.Begin (); !m.IsLast (); m.Next ()) { - os << "/// - " << (*m) << std::endl; + os << "/// - " << m.Get () << std::endl; } } os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ; From 3330ba77b171b53bcd0dbeac72921c882cb1d52c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 14:35:44 +0200 Subject: [PATCH 74/92] GetName -> GetTypeName --- doc/trace-source-list.h | 204 ++++++++++++++++++ src/core/composite-trace-resolver.cc | 4 +- src/core/trace-context-element.cc | 4 +- src/core/trace-context-element.h | 19 +- src/core/trace-context.cc | 8 +- src/devices/csma/csma-net-device.cc | 4 +- src/devices/csma/csma-net-device.h | 2 +- .../point-to-point-net-device.cc | 4 +- .../point-to-point-net-device.h | 2 +- src/internet-node/ipv4-l3-protocol.cc | 8 +- src/internet-node/ipv4-l3-protocol.h | 4 +- src/internet-node/ipv4-l4-demux.cc | 4 +- src/internet-node/ipv4-l4-demux.h | 2 +- src/node/node-list.cc | 4 +- src/node/node-list.h | 2 +- src/node/node.cc | 4 +- src/node/node.h | 2 +- src/node/queue.cc | 4 +- src/node/queue.h | 2 +- 19 files changed, 246 insertions(+), 41 deletions(-) diff --git a/doc/trace-source-list.h b/doc/trace-source-list.h index e69de29bb..c23d06ece 100644 --- a/doc/trace-source-list.h +++ b/doc/trace-source-list.h @@ -0,0 +1,204 @@ +/// +/// \ingroup TraceSourceList +/// \brief send ipv4 packet to outgoing interface +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet sent. +/// \param arg3 index of output ipv4 interface. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/ipv4/tx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback0 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3); + +/// +/// \ingroup TraceSourceList +/// \brief receive ipv4 packet from incoming interface +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet received. +/// \param arg3 index of input ipv4 interface. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/ipv4/rx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback1 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3); + +/// +/// \ingroup TraceSourceList +/// \brief drop ipv4 packet +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet dropped. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/ipv4/drop. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback2 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief store packet in queue +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet queued. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/enqueue. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::QueueTraceType +void TraceSinkCallback3 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief remove packet from queue +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet dequeued. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/dequeue. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::QueueTraceType +void TraceSinkCallback4 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief drop packet from queue +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet dropped. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/drop. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::QueueTraceType +void TraceSinkCallback5 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief receive MAC packet +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet received. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/rx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::PointToPointTraceType +void TraceSinkCallback6 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief receive MAC packet +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet received. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/rx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::CsmaTraceType +void TraceSinkCallback7 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief drop MAC packet +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet dropped. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/drop. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::NodeNetDeviceIndex +/// - ns3::CsmaTraceType +void TraceSinkCallback8 (const TraceContext & arg1, const Packet & arg2); + +/// +/// \ingroup TraceSourceList +/// \brief The value of the speed vector changed +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 the mobility model whose course changed. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/$MobilityModelNotifier/course-change. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +void TraceSinkCallback9 (const TraceContext & arg1, Ptr arg2); + +/// +/// \ingroup TraceSourceList +/// \brief send ipv4 packet to outgoing interface +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet sent. +/// \param arg3 index of output ipv4 interface. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/tx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback10 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3); + +/// +/// \ingroup TraceSourceList +/// \brief receive ipv4 packet from incoming interface +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet received. +/// \param arg3 index of input ipv4 interface. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/rx. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback11 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3); + +/// +/// \ingroup TraceSourceList +/// \brief drop ipv4 packet +/// \param arg1 the trace context associated to the connected trace source. +/// \param arg2 packet dropped. +/// +/// +/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/drop. +/// +/// The following classes can be extracted from \p arg1 with +/// ns3::TraceContext::GetElement: +/// - ns3::NodeListIndex +/// - ns3::Ipv4L3ProtocolTraceContextElement +void TraceSinkCallback12 (const TraceContext & arg1, const Packet & arg2); + diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 0f4e782b8..bb0aacabb 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -320,7 +320,7 @@ public: else if (m_sources == DOUBLEB) {os << "doubleB";} else if (m_sources == UINT16_T) {os << "uint16_t";} } - std::string GetName (void) {return "TraceSourceTest";} + std::string GetTypeName (void) {return "ns3::TraceSourceTest";} TraceSourceTest () : m_sources (TraceSourceTest::DOUBLEA) {} TraceSourceTest (enum Sources sources) :m_sources (sources) {} bool IsDoubleA (void) const {return m_sources == TraceSourceTest::DOUBLEA;} @@ -340,7 +340,7 @@ public: {static uint16_t uid = AllocateUid ("SubTraceSourceTest"); return uid;} void Print (std::ostream &os) {os << "subtracesource=int";} - std::string GetName (void) const {return "SubTraceSourceTest";} + std::string GetTypeName (void) const {return "ns3::SubTraceSourceTest";} SubTraceSourceTest () : m_sources (SubTraceSourceTest::INT) {} SubTraceSourceTest (enum Sources sources) : m_sources (sources) {} private: diff --git a/src/core/trace-context-element.cc b/src/core/trace-context-element.cc index 24b02fd23..dee4e97f4 100644 --- a/src/core/trace-context-element.cc +++ b/src/core/trace-context-element.cc @@ -3,11 +3,11 @@ namespace ns3 { std::string -ElementRegistry::GetName (uint16_t uid) +ElementRegistry::GetTypeName (uint16_t uid) { InfoVector *vec = GetInfoVector (); struct Info info = (*vec)[uid - 1]; - return info.getName (); + return info.getTypeName (); } uint32_t ElementRegistry::GetSize (uint16_t uid) diff --git a/src/core/trace-context-element.h b/src/core/trace-context-element.h index 4ed08c3ac..2baa7e39f 100644 --- a/src/core/trace-context-element.h +++ b/src/core/trace-context-element.h @@ -48,7 +48,7 @@ namespace ns3 { * MyContext (); * ~MyContext (); * void Print (std::ostream &os) const; - * std::string GetName (void) const; + * std::string GetTypeName (void) const; * * // the user-specific API to manipulate the context. * void SetData (uint8_t data); @@ -73,8 +73,9 @@ namespace ns3 { * os << "mycontext=" << (uint32_t) m_myContextData; * } * std::string - * MyContext::GetName (void) const + * MyContext::GetTypeName (void) const * { + * // return a fully-qualified c++ type name * return "MyContext"; * } * void @@ -121,23 +122,23 @@ public: static uint32_t GetSize (uint16_t uid); static void Print (uint16_t uid, uint8_t *instance, std::ostream &os); - static std::string GetName (uint16_t uid); + static std::string GetTypeName (uint16_t uid); static void Destroy (uint16_t uid, uint8_t *instance); private: - typedef std::string (*GetNameCb) (void); + typedef std::string (*GetTypeNameCb) (void); typedef void (*PrintCb) (uint8_t *instance, std::ostream &os); typedef void (*DestroyCb) (uint8_t *instance); struct Info { uint32_t size; std::string uidString; - GetNameCb getName; + GetTypeNameCb getTypeName; PrintCb print; DestroyCb destroy; }; typedef std::vector InfoVector; static InfoVector *GetInfoVector (void); template - static std::string DoGetName (void); + static std::string DoGetTypeName (void); template static void DoPrint (uint8_t *instance, std::ostream &os); template @@ -155,10 +156,10 @@ ElementRegistry::DoPrint (uint8_t *instance, std::ostream &os) } template std::string -ElementRegistry::DoGetName (void) +ElementRegistry::DoGetTypeName (void) { static T obj; - return obj.GetName (); + return obj.GetTypeName (); } template void @@ -187,7 +188,7 @@ ElementRegistry::AllocateUid (std::string name) struct Info info; info.size = sizeof (T); info.uidString = name; - info.getName = &ElementRegistry::DoGetName; + info.getTypeName = &ElementRegistry::DoGetTypeName; info.print = &ElementRegistry::DoPrint; info.destroy = &ElementRegistry::DoDestroy; vec->push_back (info); diff --git a/src/core/trace-context.cc b/src/core/trace-context.cc index 4c77d741f..af3ac2cfa 100644 --- a/src/core/trace-context.cc +++ b/src/core/trace-context.cc @@ -66,7 +66,7 @@ TraceContext::Iterator::Next (void) std::string TraceContext::Iterator::Get (void) const { - std::string name = ElementRegistry::GetName (m_uid); + std::string name = ElementRegistry::GetTypeName (m_uid); return name; } @@ -298,7 +298,7 @@ TraceContext::PrintAvailable (std::ostream &os, std::string separator) const do { currentUid = m_data->data[i]; uint8_t size = ElementRegistry::GetSize (currentUid); - os << ElementRegistry::GetName (currentUid); + os << ElementRegistry::GetTypeName (currentUid); i += 1 + size; if (i < m_data->size && currentUid != 0) { @@ -371,8 +371,8 @@ template class Ctx : public TraceContextElement { public: - static uint16_t GetUid (void) {static uint16_t uid = AllocateUid > (GetName ()); return uid;} - static std::string GetName (void) {std::ostringstream oss; oss << "Ctx" << N; return oss.str ();} + static uint16_t GetUid (void) {static uint16_t uid = AllocateUid > (GetTypeName ()); return uid;} + static std::string GetTypeName (void) {std::ostringstream oss; oss << "Ctx" << N; return oss.str ();} Ctx () : m_v (0) {} Ctx (int v) : m_v (v) {} void Print (std::ostream &os) {os << N;} diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 413478ad3..a66c43018 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -60,9 +60,9 @@ CsmaTraceType::GetUid (void) return uid; } std::string -CsmaTraceType::GetName (void) const +CsmaTraceType::GetTypeName (void) const { - return "CsmaTraceType"; + return "ns3::CsmaTraceType"; } diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index db850914e..45d384a0a 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -52,7 +52,7 @@ public: CsmaTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); - std::string GetName (void) const; + std::string GetTypeName (void) const; private: enum Type m_type; }; 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 cee375b53..71853b84c 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 @@ -54,9 +54,9 @@ PointToPointTraceType::GetUid (void) return uid; } std::string -PointToPointTraceType::GetName (void) const +PointToPointTraceType::GetTypeName (void) const { - return "PointToPointTraceType"; + return "ns3::PointToPointTraceType"; } 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 88544b7ed..88357136b 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 @@ -44,7 +44,7 @@ public: PointToPointTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); - std::string GetName (void) const; + std::string GetTypeName (void) const; }; /** diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 1409cad50..05200f6c2 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -88,9 +88,9 @@ Ipv4L3ProtocolTraceContextElement::GetUid (void) return uid; } std::string -Ipv4L3ProtocolTraceContextElement::GetName (void) const +Ipv4L3ProtocolTraceContextElement::GetTypeName (void) const { - return "Ipv4L3ProtocolTraceContextElement"; + return "ns3::Ipv4L3ProtocolTraceContextElement"; } @@ -117,9 +117,9 @@ Ipv4L3ProtocolInterfaceIndex::GetUid (void) return uid; } std::string -Ipv4L3ProtocolInterfaceIndex::GetName (void) const +Ipv4L3ProtocolInterfaceIndex::GetTypeName (void) const { - return "Ipv4L3ProtocolInterfaceIndex"; + return "ns3::Ipv4L3ProtocolInterfaceIndex"; } diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index f5e8aef04..0383e8d9a 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -59,7 +59,7 @@ public: bool IsDrop (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); - std::string GetName (void) const; + std::string GetTypeName (void) const; private: enum Type m_type; }; @@ -72,7 +72,7 @@ public: uint32_t Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); - std::string GetName (void) const; + std::string GetTypeName (void) const; private: uint32_t m_index; }; diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index a4d83d49b..122d32ab8 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -55,9 +55,9 @@ Ipv4L4ProtocolTraceContextElement::GetUid (void) return uid; } std::string -Ipv4L4ProtocolTraceContextElement::GetName (void) const +Ipv4L4ProtocolTraceContextElement::GetTypeName (void) const { - return "Ipv4L4ProtocolTraceContextElement"; + return "ns3::Ipv4L4ProtocolTraceContextElement"; } diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 40641485b..11ada2ca6 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -45,7 +45,7 @@ public: int Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); - std::string GetName (void) const; + std::string GetTypeName (void) const; private: int m_protocolNumber; }; diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 9c3b27ce7..3a68bf584 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -51,9 +51,9 @@ NodeListIndex::Get (void) const return m_index; } std::string -NodeListIndex::GetName (void) const +NodeListIndex::GetTypeName (void) const { - return "NodeListIndex"; + return "ns3::NodeListIndex"; } diff --git a/src/node/node-list.h b/src/node/node-list.h index d256953c1..d423d82fc 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -40,7 +40,7 @@ public: void Print (std::ostream &os); static uint16_t GetUid (void); uint32_t Get (void) const; - std::string GetName (void) const; + std::string GetTypeName (void) const; private: uint32_t m_index; }; diff --git a/src/node/node.cc b/src/node/node.cc index ed56ca8d8..171af4e2d 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -53,9 +53,9 @@ NodeNetDeviceIndex::GetUid (void) return uid; } std::string -NodeNetDeviceIndex::GetName (void) const +NodeNetDeviceIndex::GetTypeName (void) const { - return "NodeNetDeviceIndex"; + return "ns3::NodeNetDeviceIndex"; } diff --git a/src/node/node.h b/src/node/node.h index 4f1c5be86..07739ec81 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -44,7 +44,7 @@ public: NodeNetDeviceIndex (uint32_t index); uint32_t Get (void) const; void Print (std::ostream &os) const; - std::string GetName (void) const; + std::string GetTypeName (void) const; static uint16_t GetUid (void); private: uint32_t m_index; diff --git a/src/node/queue.cc b/src/node/queue.cc index 2ebc6c0d1..8ed033b66 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -33,9 +33,9 @@ static ClassIdDefaultValue g_classIdDefaultValue ("Queue", "Packet Queue", std::string -QueueTraceType::GetName (void) const +QueueTraceType::GetTypeName (void) const { - return "QueueTraceType"; + return "ns3::QueueTraceType"; } uint16_t QueueTraceType::GetUid (void) diff --git a/src/node/queue.h b/src/node/queue.h index 7b54f6e72..bfe0d009e 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -52,7 +52,7 @@ public: bool IsDequeue (void) const; bool IsDrop (void) const; void Print (std::ostream &os) const; - std::string GetName (void) const; + std::string GetTypeName (void) const; private: enum Type m_type; }; From 471e30d85e0db85dafeb7331c32b753992cd4f7f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 14:42:38 +0200 Subject: [PATCH 75/92] fix dox warnings --- src/core/composite-trace-resolver.h | 2 +- src/core/trace-source.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 2a96149ca..56886d739 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -95,7 +95,7 @@ public: /** * \param name the name of the array * \param begin an iterator which points to the first element of the array - * \param begin an iterator which points to the last element of the array + * \param end an iterator which points to the last element of the array * \param index an object which can store the index of an element in the * array. In practice, this object should support a constructor * whose single argument is an array index. diff --git a/src/core/trace-source.h b/src/core/trace-source.h index 9424b9086..2a90de2ee 100644 --- a/src/core/trace-source.h +++ b/src/core/trace-source.h @@ -36,7 +36,7 @@ public: virtual ~TraceSource () {} /** * \param callback the callback to connect to this trace source - * \param the context associated to the input callback which should be passed + * \param context the context associated to the input callback which should be passed * back to the user. */ virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) = 0; From 87a9c29cf76c82c56fc626332369c5c9ec36e329 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 14:54:05 +0200 Subject: [PATCH 76/92] add doxygen for each TraceSourceElement subclass --- src/devices/csma/csma-net-device.cc | 5 +++++ src/devices/csma/csma-net-device.h | 7 +++++++ .../point-to-point/point-to-point-net-device.h | 3 +++ src/internet-node/ipv4-l3-protocol.h | 18 ++++++++++++++++++ src/internet-node/ipv4-l4-demux.h | 6 ++++++ src/node/node-list.h | 6 ++++++ src/node/node.h | 6 ++++++ src/node/queue.h | 12 ++++++++++++ 8 files changed, 63 insertions(+) diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index a66c43018..6b5747581 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -64,6 +64,11 @@ CsmaTraceType::GetTypeName (void) const { return "ns3::CsmaTraceType"; } +enum CsmaTraceType::Type +CsmaTraceType::Get (void) const +{ + return m_type; +} CsmaNetDevice::CsmaNetDevice (Ptr node) diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index 45d384a0a..713611a2a 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -41,6 +41,9 @@ namespace ns3 { class Queue; class CsmaChannel; +/** + * \brief hold in a TraceContext the type of trace source from a CsmaNetDevice + */ class CsmaTraceType : public TraceContextElement { public: @@ -53,6 +56,10 @@ public: void Print (std::ostream &os) const; static uint16_t GetUid (void); std::string GetTypeName (void) const; + /** + * \returns the type of the trace source which generated an event. + */ + enum Type Get (void) const; private: enum Type m_type; }; 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 88357136b..a5868bea4 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 @@ -38,6 +38,9 @@ namespace ns3 { class Queue; class PointToPointChannel; +/** + * \brief hold in a TraceContext the type of trace source from a PointToPointNetDevice + */ class PointToPointTraceType : public TraceContextElement { public: diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index 0383e8d9a..8eb6dbe10 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -44,6 +44,9 @@ class Node; class TraceResolver; class TraceContext; +/** + * \brief hold in a TraceContext the type of trace source used by this Ipv4L3Protocol + */ class Ipv4L3ProtocolTraceContextElement : public TraceContextElement { public: @@ -54,8 +57,17 @@ public: }; Ipv4L3ProtocolTraceContextElement (); Ipv4L3ProtocolTraceContextElement (enum Type type); + /** + * \returns true if this is a tx event, false otherwise. + */ bool IsTx (void) const; + /** + * \returns true if this is a rx event, false otherwise. + */ bool IsRx (void) const; + /** + * \returns true if this is a drop event, false otherwise. + */ bool IsDrop (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); @@ -64,11 +76,17 @@ private: enum Type m_type; }; +/** + * \brief hold in a TraceContext the index of an Ipv4Interface within the ipv4 stack of a Node + */ class Ipv4L3ProtocolInterfaceIndex : public TraceContextElement { public: Ipv4L3ProtocolInterfaceIndex (); Ipv4L3ProtocolInterfaceIndex (uint32_t index); + /** + * \returns the index of the Ipv4Interface within a Node. + */ uint32_t Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); diff --git a/src/internet-node/ipv4-l4-demux.h b/src/internet-node/ipv4-l4-demux.h index 11ada2ca6..6e1208c13 100644 --- a/src/internet-node/ipv4-l4-demux.h +++ b/src/internet-node/ipv4-l4-demux.h @@ -37,11 +37,17 @@ class Node; class TraceResolver; class TraceContext; +/** + * \brief hold in a TraceContext the protocol number of a L4 Protocol + */ class Ipv4L4ProtocolTraceContextElement : public TraceContextElement { public: Ipv4L4ProtocolTraceContextElement (); Ipv4L4ProtocolTraceContextElement (int protocolNumber); + /** + * \returns the protocol number as registered in the Ipv4L4Demux. + */ int Get (void) const; void Print (std::ostream &os) const; static uint16_t GetUid (void); diff --git a/src/node/node-list.h b/src/node/node-list.h index d423d82fc..4a6c113bf 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -32,6 +32,9 @@ class Node; class CallbackBase; class TraceResolver; +/** + * \brief hold in a TraceContext the index of a node within a NodeList. + */ class NodeListIndex : public TraceContextElement { public: @@ -39,6 +42,9 @@ public: NodeListIndex (uint32_t index); void Print (std::ostream &os); static uint16_t GetUid (void); + /** + * \returns the index of the node within the NodeList + */ uint32_t Get (void) const; std::string GetTypeName (void) const; private: diff --git a/src/node/node.h b/src/node/node.h index 07739ec81..cd032e2e0 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -37,11 +37,17 @@ class Packet; class Address; class CompositeTraceResolver; +/** + * \brief hold in a TraceContext the index of a NetDevice within a Node + */ class NodeNetDeviceIndex : public TraceContextElement { public: NodeNetDeviceIndex (); NodeNetDeviceIndex (uint32_t index); + /** + * \returns the index of the NetDevice within its container Node. + */ uint32_t Get (void) const; void Print (std::ostream &os) const; std::string GetTypeName (void) const; diff --git a/src/node/queue.h b/src/node/queue.h index bfe0d009e..b8531c9c7 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -37,6 +37,9 @@ namespace ns3 { class StringEnumDefaultValue; +/** + * \brief hold in a TraceContext the type of a trace source + */ class QueueTraceType : public TraceContextElement { public: @@ -48,8 +51,17 @@ public: static uint16_t GetUid (void); QueueTraceType (); QueueTraceType (enum Type type); + /** + * \returns true if this is an enqueue event, false otherwise. + */ bool IsEnqueue (void) const; + /** + * \returns true if this is a dequeue event, false otherwise. + */ bool IsDequeue (void) const; + /** + * \returns true if this is a drop event, false otherwise. + */ bool IsDrop (void) const; void Print (std::ostream &os) const; std::string GetTypeName (void) const; From 2894f50005e7c58f097be9a34a04f552f64cd782 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 14:57:59 +0200 Subject: [PATCH 77/92] add explanatory diagram --- doc/namespace-2.dia | 1658 +++++++++++++++++++++++++++++++++++++++++++ doc/namespace-2.png | Bin 0 -> 32010 bytes 2 files changed, 1658 insertions(+) create mode 100644 doc/namespace-2.dia create mode 100644 doc/namespace-2.png diff --git a/doc/namespace-2.dia b/doc/namespace-2.dia new file mode 100644 index 000000000..5cd5ed59e --- /dev/null +++ b/doc/namespace-2.dia @@ -0,0 +1,1658 @@ + + + + + + + + + + + + + #A4# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/devices/[0-n]# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #NodeList# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #Node# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/queue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/nodes/[0-n]# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/udp# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/rx# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/netdevice# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/ipv4# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/interfaces/[0-n]# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/rx# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/queue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/rx# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/enqueue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/dequeue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/drop# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #InternetNode# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #PointToPointNetDevice# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #Queue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #Ipv4L3Protocol# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #Ipv4Interface# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #CsmaNetDevice# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/enqueue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/dequeue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #/drop# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #Queue# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/namespace-2.png b/doc/namespace-2.png new file mode 100644 index 0000000000000000000000000000000000000000..7ea379c82a853bc3bc9d41fa5d992a6e96457777 GIT binary patch literal 32010 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 literal 0 HcmV?d00001 From 5883e3db527fd925d725e08c088beed8fe315c6c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 15:14:26 +0200 Subject: [PATCH 78/92] make sure that l4 protocols are correctly registered within the tracing namespace --- src/internet-node/ipv4-l4-demux.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 122d32ab8..ae4a09e42 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -90,11 +90,10 @@ Ipv4L4Demux::GetTraceResolver (void) const for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { Ptr protocol = *i; - std::string protValue; - std::ostringstream oss (protValue); - oss << (*i)->GetProtocolNumber (); + std::ostringstream oss; + oss << (unsigned int) (*i)->GetProtocolNumber (); Ipv4L4ProtocolTraceContextElement protocolNumber = (*i)->GetProtocolNumber (); - resolver->AddComposite (protValue, protocol, protocolNumber); + resolver->AddComposite (oss.str (), protocol, protocolNumber); } resolver->SetParentResolver (Object::GetTraceResolver ()); return resolver; From 8c85cc598dc2d14d0f14120895d2c706529f6f18 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 15:20:08 +0200 Subject: [PATCH 79/92] add missing const --- src/core/object.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/object.cc b/src/core/object.cc index 6d4779c08..85f180cf0 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -356,7 +356,7 @@ public: void BaseGenerateTrace (int16_t v) { m_source = v; } virtual void Dispose (void) {} - virtual ns3::Ptr GetTraceResolver (void) + virtual ns3::Ptr GetTraceResolver (void) const { ns3::Ptr resolver = ns3::Create (); @@ -380,7 +380,7 @@ public: virtual void Dispose (void) { BaseA::Dispose (); } - virtual ns3::Ptr GetTraceResolver (void) + virtual ns3::Ptr GetTraceResolver (void) const { ns3::Ptr resolver = ns3::Create (); @@ -407,7 +407,7 @@ public: void BaseGenerateTrace (int16_t v) { m_source = v; } virtual void Dispose (void) {} - virtual ns3::Ptr GetTraceResolver (void) + virtual ns3::Ptr GetTraceResolver (void) const { ns3::Ptr resolver = ns3::Create (); @@ -431,7 +431,7 @@ public: virtual void Dispose (void) { BaseB::Dispose (); } - virtual ns3::Ptr GetTraceResolver (void) + virtual ns3::Ptr GetTraceResolver (void) const { ns3::Ptr resolver = ns3::Create (); From bb1711de6047c609a113431f5ba2eb7d22d915ab Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 15:45:46 +0200 Subject: [PATCH 80/92] add section on TraceContexts in tutorial --- src/core/tracing.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/core/tracing.h b/src/core/tracing.h index 0612b144e..645a1dd26 100644 --- a/src/core/tracing.h +++ b/src/core/tracing.h @@ -100,6 +100,80 @@ * to figure out the arguments which a trace sink is required to receive * for each trace source. * + * Since there is no working magic here, defining a trace sink does not connect + * it directly to a set of trace sources. To connect a trace sink, a user must call + * ns3::NodeList::Connect. The second argument is a callback to the user's trace sink. + * That callback is easy to construct: call ns3::MakeCallback and you are done. The + * first argument is a string whose format is similar to a unix path and which is + * used to uniquely identify the set of trace sources you want to connect to. + * The set of acceptable path strings is also documented in the \ref TraceSourceList. + * + * So, what does this look like from the perspective of a user ? If we wanted to + * connect to a trace source defined somewhere deep into the a set of NetDevice objects + * located in some nodes of the system, we could write the following: + * \code + * void + * DoSomethingTraceSink (const TraceContext &context, Packet packet) + * { + * // for example, print the arguments + * std::cout << "packet: " << packet << std::endl; + * } + * // connect the above sink to a matching trace source + * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback &DoSomethingTraceSink); + * \endcode + * + * The connection path string "/nodes/* /devices/* /rx" matches the "rx" trace source + * located in every netdevice located in every node. The syntax of that path string + * is loosely based on regular expressions so, a user could conceivably connect + * to the trace sources present in only one node identified by node index: + * "/nodex/3/devices/* /rx". + * + * The matching algorithm used here is very useful since it allows you to connect + * at once a large set of trace sources to a single sink but it introduces another + * problem: it becomes impossible when you receive an event in your trace sink to + * know from _which_ trace source the event is coming from. In our example, the + * trace source might be coming from the NetDevice number 2 of Node 10 or Netdevice + * number 0 of Node 5. In both cases, you might need to know which of these NetDevice + * is generating this event, if only to generate some ascii trace dump. + * + * It turns out that there are many ways to get this information. The simplest + * way to get this information is to use the builtin printing facility of + * the TraceContext object: + * \code + * void + * DoSomethingTraceSink (const TraceContext &context, Packet packet) + * { + * // for example, print the arguments + * std::cout << "context=\"" << context << "\" packet: " << packet << std::endl; + * } + * \endcode + * The above code is going to generate output which looks like the following: + * \code + * context="nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... + * context="nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... + * ... + * \endcode + * + * Another more advanced way to get information out of a TraceContext is to call its + * ns3::TraceContext::GetElement method. This method takes as its first and only + * argument an instance of the object we want to read and the list of available + * object instances we can read from a TraceContext is documented, once again, + * in the \ref TraceSourceList. For example, we could write the following to + * generate adhoc trace output: + * \code + * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * { + * NodeListIndex nodeIndex; + * NodeNetDeviceIndex deviceIndex; + * context.GetElement (nodeIndex); + * context.GetElement (deviceIndex); + * std::cout << "node-index=" << nodeIndex.Get (); + * std::cout << ", device-index=" << deviceIndex.Get (); + * std::cout << ", packet: " << packet; + * std::cout << std::endl; + * } + * \endcode + * * The hard part of this tracing framework is the "connection" step: there is a point * in the simulation scenario where the user is expected to specify which trace sources * should be connected to which trace sinks. There are many ways to do this: the From 0a9cb8d248da98d4c723158bf18e4a75abfe2928 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 16:00:26 +0200 Subject: [PATCH 81/92] start section on registering new TraceSource objects --- src/core/tracing.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/core/tracing.h b/src/core/tracing.h index 645a1dd26..259ba0903 100644 --- a/src/core/tracing.h +++ b/src/core/tracing.h @@ -55,6 +55,7 @@ * public: * void DoSomething (Packet packet, double value) * { + * // report this event on packet with value * m_doSomething (packet, value); * // do something * } @@ -174,6 +175,75 @@ * } * \endcode * + * Using existing trace sources to connect them to a set of adhoc trace sinks + * is not really complicated but, setting up new trace sources which can hook + * in this automatic connection system is a bit more complicated. + * + * So far, we know that a model author can generate trace events really easily: + * \code + * class MyModel + * { + * public: + * void DoSomething (Packet packet, double value) + * { + * // report this event on packet with value + * m_doSomething (packet, value); + * // do something + * } + * private: + * // report every "something" function call. + * CallbackTraceSource m_doSomething; + * }; + * \endcode + * + * To make these new trace sources available to the rest of the connection system, + * the first step is to make sure that your model object derives from the ns3::Object + * base class either directly (as shown below) or indirectly through another base class: + * \code + * class MyModel : public Object {...}; + * // or: + * class SomeOtherObject : public Object {...}; + * class MyModel : public SomeOtherObject {...}; + * \endcode + * + * This is pretty trivial and lays the ground for the second step: overriding the + * ns3::Object::GetTraceResolver method: + * \code + * class MyModel : public MyParent + * { + * public: + * // declare overriden method + * virtual Ptr GetTraceResolver (void) const; + * private: + * // the new trace source to export. + * CallbackTraceSource m_rxSource; + * }; + * \endcode + * + * To implement this method, you could attempt to implement a new subclass of + * the ns3::TraceResolver base class and return an instance from this method but + * this would be very hard. Instead, you should use the helper class + * ns3::CompositeTraceResolver to register your trace sources and chain up to + * your parent: + * \code + * Ptr + * MyModel::GetTraceResolver (void) const + * { + * // create an empty trace resolver + * Ptr resolver = Create (); + * // register m_rxSource + * resolver->AddSource ("rx", // the name of the trace source in the path string + * TraceDoc ("some help text to explain the purpose of this trace source", + * "Packet", // the type of the first argument to the trace source + * "the purpose of the first argument", + * "type-of-second-argument", "purpose-of-second-argument"), + * m_rxSource // the trace source itself is registered); + * // make sure we include the trace sources implemented in the parent. + * resolver->SetParentResolver (MyParent::GetTraceResolver ()); + * return resolver; + * } + * \endcode + * * The hard part of this tracing framework is the "connection" step: there is a point * in the simulation scenario where the user is expected to specify which trace sources * should be connected to which trace sinks. There are many ways to do this: the From e068eb8bd18f9db71885d0f6e82e2e0721b58d7c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 16:38:26 +0200 Subject: [PATCH 82/92] add missing requirement to doxygen --- src/core/trace-context-element.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/trace-context-element.h b/src/core/trace-context-element.h index 2baa7e39f..aba7c2598 100644 --- a/src/core/trace-context-element.h +++ b/src/core/trace-context-element.h @@ -37,6 +37,8 @@ namespace ns3 { * This method takes a c++ output stream and argument and is * expected to write an ascii string describing its content * in this output stream. + * - a public GetTypeName method which returns the fully-qualified + * c++ type name of this subclass as a string. * * A typical subclass should look like this: * \code From 4ddb3275970c60f26fbea5805304f5399c948e74 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 30 Aug 2007 16:38:41 +0200 Subject: [PATCH 83/92] finish trace tutorial --- src/core/tracing.h | 342 ++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 190 deletions(-) diff --git a/src/core/tracing.h b/src/core/tracing.h index 259ba0903..3305195cb 100644 --- a/src/core/tracing.h +++ b/src/core/tracing.h @@ -237,213 +237,175 @@ * "Packet", // the type of the first argument to the trace source * "the purpose of the first argument", * "type-of-second-argument", "purpose-of-second-argument"), - * m_rxSource // the trace source itself is registered); + * m_rxSource // the trace source itself is registered + * ); * // make sure we include the trace sources implemented in the parent. * resolver->SetParentResolver (MyParent::GetTraceResolver ()); * return resolver; * } * \endcode * - * The hard part of this tracing framework is the "connection" step: there is a point - * in the simulation scenario where the user is expected to specify which trace sources - * should be connected to which trace sinks. There are many ways to do this: the - * users who want to could implement the "quick and dirty" way, that is, they could - * write adhoc code to connect their trace sinks to the trace sources using the - * TraceSource::AddCallback method. For example, they could patch their models to - * the following: + * Once you have written that code, you must make sure that this new method GetTraceResolver + * is going to be called at some point by the tracing system. If your model is located somewhere + * deep in MAC or PHY layer, that is, it is part of a NetDevice implementation, all you + * have to do is to make sure that your model is registered as a "composite" of your NetDevice + * subclass: * \code - * class MyModel + * class MyNetDevice : public NetDevice * { * public: - * void DoSomething (void) - * { + * Ptr GetTraceResolver (void) const; + * private: + * Ptr m_model; + * }; + * + * Ptr + * MyNetDevice::GetTraceResolver (void) const + * { + * Ptr resolver = ...; + * // register other trace source + * ... + * // register now your model as a "composite" + * resolver->AddComposite ("my-model", m_model); + * // chain up to parent. + * resolver->SetParentResolver (NetDevice::GetTraceResolver ()); + * return resolver; + * } + * \endcode + * + * The code above will make your "rx" trace source appear under the + * /nodes/xx/devices/xx/my-model/rx namespace path. + * + * The last important feature which model developers need to understand + * is how to provide extra TraceContext data to trace sinks. For example, + * if your model exports many trace sources, and if a single trace sink + * is connected to all these trace sources at the same time, it might need + * to know, for each event what its event source is. So, if you have a + * TX, a RX, and a DROP trace source: + * \code + * class MyModel + * { + * private: + * CallbackTraceSource m_rxSource; + * CallbackTraceSource m_txSource; + * CallbackTraceSource m_dropSource; + * }; + * \endcode + * You would like to allow your connected trace sinks to read their + * TraceContext for the type of source: + * \code + * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * { + * MyModelTraceType type; + * context.GetElement (type); + * switch (type) { + * case MyModelTraceType::RX: + * std::cout << "drop" << std::endl; + * break; + * case MyModelTraceType::TX: + * std::cout << "drop" << std::endl; + * break; + * case MyModelTraceType::DROP: + * std::cout << "drop" << std::endl; + * break; + * } + * \endcode + * or, more simply: + * \code + * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * { + * // context contains MyModelTraceType so, + * // it is going to print it + * std::cout << context << std::endl; + * } + * \endcode + * + * This kind of extra information is not generated magically: model + * authors must provide to the ns3::CompositeTraceResolver that + * per-source extra information during registration to allow the + * connection system to store it safely in the user's TraceContext objects. + * + * The first step to achieve this is to define and implement a new + * subclass of the ns3::TraceContextElement base class: + * \code + * class MyModelTraceType : public TraceContextElement + * { + * public: + * enum Type { + * RX, + * TX, + * DROP + * }; + * // called from MyModel::GetTraceResolver + * MyModelTraceType (enum Type type); + * // called from trace sink + * enum Type Get (void) const; + * // needed by the tracing subsystem + * static uint16_t GetUid (void); + * // needed by the tracing subsystem to + * // print the content of a TraceContext + * void Print (std::ostream &os) const; + * // needed by the tracing subsystem to + * // generate the doxygen documentation. + * std::string GetTypeName (void) const; + * private: + * enum Type m_type; + * }; + * \endcode + * The implementation is quite straightforward: + * \code + * MyModelTraceType::MyModelTraceType (enum Type type) + * : m_type (type) + * {} + * enum Type + * MyModelTraceType::Get (void) const + * { + * return m_type; + * } + * uint16_t + * MyModelTraceType::GetUid (void) + * { + * // use protected TraceContextElement::AllocateUid method + * static uint16_t uid = AllocateUid ("ns3::MyModelTraceType"); + * return uid; + * } + * void + * MyModelTraceType::Print (std::ostream &os) const + * ( + * switch (m_type) { + * case RX: os << "rx"; break; * // ... * } - * SVTraceSource *GetCwndTraceSource (void) const - * { - * return &m_cwnd; - * } - * private: - * // declare an instance of a "int" trace source - * SVTraceSource m_cwnd; - * }; - * \endcode - * And, then, call directly the GetCwndTraceSource method: - * \code - * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue) + * ) + * std::string + * MyModelTraceType::GetTypeName (void) const * { - * // for example, print the new value: - * std::cout << "cwnd=" << newValue << std::endl; + * return "ns3::MyModelTraceType"; * } - * // create a model instance - * MyModel *model = ...; - * SVTraceSource *cwnd = model->GetCwndTraceSource (); - * // connect the trace sink to the cwnd trace source of - * // this model instance. - * cwnd->AddCallback (MakeCallback (&CwndTraceSink), - * TraceContext ()); * \endcode - * - * The solution described above is simple to implement for a model - * author but it is hard to extend and becomes quickly cumbersome - * to use with complex models made of composite objects. TraceResolvers - * deal with these problems and offer a simple API to connect large - * sets of trace sources to a single sink (as is typical for simulations - * where users want to receive the "ipv4 rx" events from all nodes). * - * The user-visible API to connect and disconnect trace sources to - * and from trace sinks is quite small: ns3::Object::Connect - * and ns3::Object::Disconnect both take a "namespace" regexp string - * and a callback. The input callback is connected to each trace source - * which matches the namespace regexp string. The format of the namespace - * string depends on the set of models implemented by the simulator. - * The following diagram shows a small part of the namespace exported - * by the current version of the simulator: - * - * \image html namespace-2.png ns-3 namespace - * - * In this namespace, the "rx" trace source of the PointToPointNetdevice - * index 0 within node index 3 is uniquely identified by the namespace - * string "/nodes/3/devices/0/rx". It is also possible to match all - * such "rx" trace sources with a single namespace string using - * a limited form of regular expressions: "/nodes/3/devices/* /rx" - * identifies the "rx" trace source within all NetDevices within node - * index 3. Similarly, "/nodes/* /devices/* /rx" identifies the "rx" - * trace source within all NetDevices within all nodes. It is thus - * possible to connect a single trace sink to a set of matching trace - * sources in a single operation: + * Once this subclass is implemented, the work is almost completed: you + * just need to pass an instance of that class as the last argument of + * the ns3::CompositeTraceResolver::AddSource method as shown below: * \code - * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * Ptr + * MyModel::GetTraceResolver (void) const * { - * // context contains enough information to uniquely identify - * // the trace source instance. - * std::cout << "context: \"" << context << "\""; - * // packet is the per-event information conveyed from the - * // trace source to the trace sink. - * std:: cout << " packet: " << packet << std::endl; + * // create an empty trace resolver + * Ptr resolver = Create (); + * // register m_rxSource + * resolver->AddSource ("rx", // the name of the trace source in the path string + * TraceDoc ("some help text to explain the purpose of this trace source", + * "Packet", // the type of the first argument to the trace source + * "the purpose of the first argument", + * "type-of-second-argument", "purpose-of-second-argument"), + * m_rxSource, // the trace source itself is registered + * // the TraceContextElement associated to this trace source. + * MyModelTraceType (MyModelTraceType::RX) + * ); + * // make sure we include the trace sources implemented in the parent. + * resolver->SetParentResolver (MyParent::GetTraceResolver ()); + * return resolver; * } - * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback (&DeviceRxSink)); * \endcode - * Which, at runtime, is going to generate output looking like this: - * \code - * context: "nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... - * context: "nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... - * ... - * \endcode - * In the example above, we see that the ns3::TraceContext contains three - * ns3::TraceContextElement which were printed using a space separator: - * - nodeid=i - * - device=j - * - dev-rx - * - * Of course, the user could also extract each of these elements from - * the context to generate a different output: - * \code - * void DeviceRxSink (const TraceContext &context, const Packet &packet) - * { - * NodeListIndex nodeIndex; - * NodeNetDeviceIndex deviceIndex; - * context.Get (nodeIndex); - * context.Get (deviceIndex); - * std::cout << "node-index=" << nodeIndex.Get (); - * std::cout << ", device-index=" << deviceIndex.Get (); - * std::cout << ", packet: " << packet; - * std::cout << std::endl; - * } - * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback (&DeviceRxSink)); - * \endcode - * Extracting TraceContextElement objects from a TraceContext in this manner - * raises a few obvious questions: - * - how do I know which trace context elements are present in a given - * TraceContext ? - * - how are these elements added to the TraceContext ? - * - * - * - * - * Connecting trace sinks to a set of existing trace sources is nice but - * model developers also often need to be able to create new trace sources - * and hook them into the namespace resolution system. Creating new trace - * sources is pretty easy: it is a matter of instantiating a proper - * subclass of the ns3::TraceSource base class. However, hooking each - * new trace source in the overall namespace resolution system requires - * some new effort. The core requirement is that the user needs to - * subclass from the ns3::Object base class which provides the most - * basic ns3::Object::Connect, and, ns3::Object::Disconnect methods. - * These two methods are simple forwarding methods to the virtual - * ns3::Object::GetTraceResolver method which does the bulk of the work - * required to setup properly trace sources. - * - * Every subclass of the ns3::Object base class which wishes to export - * a set of trace sources and make them available through the Connect/Disconnect - * functions needs to override the ns3::Object::GetTraceResolver method. - * This method needs to return a subclass of the ns3::TraceResolver - * base class which implements the ns3::TraceResolver::Connect and - * ns3::TraceResolver::Disconnect methods. Providing an implementation - * of these two methods is a bit complicated so, a default implementation - * named CompositeTraceResolver is provided: - * \code - * class MyModel : public Object - * { - * public: - * void DoSomething (void) - * { - * // change value of m_cwnd - * } - * protected: - * virtual Ptr GetTraceResolver (void) - * { - * // create the composite resolver - * Ptr resolver = Create (); - * resolver->AddSource ("cwnd", m_cwnd); - * resolver->AddSource ("rx", m_rx); - * return resolver; - * } - * private: - * SVTraceSource m_cwnd; - * CallbackTraceSource m_rx; - * }; - * void MyTraceSink (const TraceContext &context, Packet packet) - * { - * std::cout << context << " packet: " << packet << std::endl; - * } - * object->Connect ("/.../rx", MakeCallback (&MyTraceSink)); - * \endcode - * - * The above example is enough to export a trace source as a member of the - * tracing namespace so, it would be enough to allow a user to perform a - * pair of Connect/Disconnect operations but it would not be enough to allow - * a TraceContext to contain information about these trace sources. Specifically, - * printing the content of the TraceContext as shown above would give no - * information whatsoever about the type of trace source which was connected. - * - * but it is not enough to allow the TraceContext - * stored in each TraceSource to store information about these trace sources. - * - * - A trace source: a trace source is an object instance which is a - * subclass of the ns3::TraceSource base class. Each instance - * of a trace source should be used to report a single type of - * event. For example, if you want to report ipv4 rx and tx events, - * you should use two different trace source instances. - * - * - Trace sinks: a trace sink is a callback, that is, a function, - * which is provided by the user of a model to receive the events - * reported by a set of trace sources within that model. A trace - * sink is said to be "connected" once it has been associated - * to a set of trace sources. - * - * - Trace context: each trace source instance is associated with a single - * instance of an immutable trace context. Each ns3::TraceContext stores - * a set of trace context element instances, each of which is a subclass - * of the ns3::TraceContextElement base class. Whenever a trace sink - * provided by a user is called because a trace event was reported on - * a connected trace source, the trace context associated to the - * relevant trace source is passed as an extra argument to the user's - * trace sink. - * - * - instrumentation of models is done through a set of trace source - * instances, each of which is a subclass of the ns3::TraceSource - * base class. - * - * */ From 99d7c597b6d443975ecd81acede05a28b418dc96 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 4 Sep 2007 15:34:04 +0200 Subject: [PATCH 84/92] move tracing tutorial to doc directory --- doc/doxygen.conf | 2 +- {src/core => doc}/tracing.h | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {src/core => doc}/tracing.h (100%) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 6f4b503d7..ac0f72a0e 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -450,7 +450,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = src doc/main.txt doc/trace-source-list.h +INPUT = src doc/main.txt doc/trace-source-list.h doc/tracing.h # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/src/core/tracing.h b/doc/tracing.h similarity index 100% rename from src/core/tracing.h rename to doc/tracing.h From e143b5d14291f371c931af9adaf63977bce3b365 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 5 Sep 2007 12:08:57 +0200 Subject: [PATCH 85/92] re-organize the tutorial and use sections --- doc/tracing.h | 194 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 157 insertions(+), 37 deletions(-) diff --git a/doc/tracing.h b/doc/tracing.h index 3305195cb..720e9a334 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -19,6 +19,8 @@ * - A trace resolver is an object which allows users to establish * connections between a set of trace sources and a set of trace sinks. * + * \section TraceSource Generating Trace Events + * * So, what does it look like in practice ? First, let's look at trace * sources. We have two types of trace sources: numeric, and, normal * trace sources. Numeric trace sources behave as normal c++ integers @@ -53,15 +55,15 @@ * class MyModel * { * public: - * void DoSomething (Packet packet, double value) + * void DoSomething (Packet packet) * { - * // report this event on packet with value - * m_doSomething (packet, value); + * // report this event on packet + * m_doSomething (packet); * // do something * } * private: * // report every "something" function call. - * CallbackTraceSource m_doSomething; + * CallbackTraceSource m_doSomething; * }; * \endcode * Every type of trace source derives from the ns3::TraceSource base class. @@ -69,6 +71,8 @@ * ns3::CallbackTraceSource, ns3::SvTraceSource, ns3::UvTraceSource, and, * ns3::FvTraceSource. * + * \section TraceSink Receiving Trace Events + * * To receive these trace events, a user should specify a set of trace sinks. * For example, to receive the "int" and the "something" events shown in the * examples above, a user would declare the following functions: @@ -82,10 +86,10 @@ * std::cout << "cwnd=" << newValue << std::endl; * } * void - * DoSomethingTraceSink (const TraceContext &context, Packet packet, double value) + * DoSomethingTraceSink (const TraceContext &context, Packet packet) * { * // for example, print the arguments - * std::cout << "value=" << value << ", packet " << packet << std::endl; + * std::cout << "packet " << packet << std::endl; * } * \endcode * Each of these sink function takes, as a first argument, a reference to a @@ -99,7 +103,10 @@ * two unsigned 64 bit integers while the latter requires two signed 64 bit * integers. More generally, users can consult the \ref TraceSourceList * to figure out the arguments which a trace sink is required to receive - * for each trace source. + * for each trace source: a signature of the user trace sink must match + * _exactly_ the signature documented in the \ref TraceSourceList. + * + * \section TraceConnection Connecting Trace Sources to Trace Sinks * * Since there is no working magic here, defining a trace sink does not connect * it directly to a set of trace sources. To connect a trace sink, a user must call @@ -135,9 +142,14 @@ * know from _which_ trace source the event is coming from. In our example, the * trace source might be coming from the NetDevice number 2 of Node 10 or Netdevice * number 0 of Node 5. In both cases, you might need to know which of these NetDevice - * is generating this event, if only to generate some ascii trace dump. + * is generating this event, if only to generate some ascii trace dump. Another + * similar use-case is that you might have connected the same trace sink to + * multiple types of events which have the same signature: it is quite common + * to receive all tx, rx, and drop events in the same trace sink and that would be + * quite trivial to achieve with a string such as: "/nodes/* /devices/* /*" * - * It turns out that there are many ways to get this information. The simplest + * The source of a trace event can be retrieved from a trace sink using + * different means: the simplest * way to get this information is to use the builtin printing facility of * the TraceContext object: * \code @@ -175,6 +187,12 @@ * } * \endcode * + * \section TraceSourceSimpleExport A simple way to export Trace Sources + * + * XXX + * + * \section ExportingTraceSources Exporting new Trace Sources + * * Using existing trace sources to connect them to a set of adhoc trace sinks * is not really complicated but, setting up new trace sources which can hook * in this automatic connection system is a bit more complicated. @@ -184,15 +202,15 @@ * class MyModel * { * public: - * void DoSomething (Packet packet, double value) + * void DoSomething (Packet packet) * { * // report this event on packet with value - * m_doSomething (packet, value); + * m_doSomething (packet); * // do something * } * private: * // report every "something" function call. - * CallbackTraceSource m_doSomething; + * CallbackTraceSource m_doSomething; * }; * \endcode * @@ -276,12 +294,25 @@ * The code above will make your "rx" trace source appear under the * /nodes/xx/devices/xx/my-model/rx namespace path. * + * If you have implemented a new layer 3 or 4 protocol object, the process to + * export your trace sources is quite similar. You need to subclass from + * ns3::Object, override the ns3::Object::GetTraceResolver method, make + * sure you chain up to your parent's GetTraceResolver method, and, finally, + * make sure that someone calls your new GetTraceResolver method. How to accomplish + * the latter should be documented in the node's API documentation which describes + * how to implement a new layer 3 or 4 protocol object. + * + * \section AdvancedTraceContext Creating new Trace Context Elements + * * The last important feature which model developers need to understand - * is how to provide extra TraceContext data to trace sinks. For example, - * if your model exports many trace sources, and if a single trace sink - * is connected to all these trace sources at the same time, it might need - * to know, for each event what its event source is. So, if you have a - * TX, a RX, and a DROP trace source: + * is how to provide extra context information to trace sinks. For example, + * if your model exports both rx and tx trace sources which share the same + * signature, it is quite natural for a user to connect to a single trace sink + * to both of them with a trace path string such as "/nodes/* /devices/* /(rx|tx)". + * In this case, it becomes necessary to be able, from the trace sink function, + * to tell which event triggered the call to the trace sink: a rx or a tx event. + * + * That example is detailed below with a TX, a RX, and a DROP source: * \code * class MyModel * { @@ -291,42 +322,125 @@ * CallbackTraceSource m_dropSource; * }; * \endcode - * You would like to allow your connected trace sinks to read their - * TraceContext for the type of source: + * When a single sink is connected to all 3 sources here, one might want + * to write code like the following: * \code * void DeviceRxSink (const TraceContext &context, const Packet &packet) * { - * MyModelTraceType type; - * context.GetElement (type); * switch (type) { - * case MyModelTraceType::RX: - * std::cout << "drop" << std::endl; + * case RX: + * std::cout << "rx" << std::endl; * break; - * case MyModelTraceType::TX: - * std::cout << "drop" << std::endl; + * case TX: + * std::cout << "tx" << std::endl; * break; - * case MyModelTraceType::DROP: + * case DROP: * std::cout << "drop" << std::endl; * break; * } * \endcode - * or, more simply: + * + * \subsection AdvancedTraceContextSimpleSolution The simple solution + * + * The simplest way to do achieve the result shown above is to include + * in the trace source an extra explicit argument which describes the source event: + * - define a small enum with 3 values + * - change the signature of m_rxSource, m_txSource, and m_dropSource to include + * the enum + * - pass the enum value in each event + * + * The resulting code is shown below: * \code - * void DeviceRxSink (const TraceContext &context, const Packet &packet) + * class MyModel * { - * // context contains MyModelTraceType so, - * // it is going to print it - * std::cout << context << std::endl; + * public: + * // define the trace type enum. + * enum TraceType { + * RX, + * TX, + * DROP + * }; + * private: + * // generate events + * void NotifyRxPacket (Packet p) { + * m_rxSource (p, MyModel::RX); + * } + * void NotifyTxPacket (Packet p) { + * m_rxSource (p, MyModel::TX); + * } + * void NotifyDropPacket (Packet p) { + * m_rxSource (p, MyModel::DROP); + * } + * CallbackTraceSource m_rxSource; + * CallbackTraceSource m_txSource; + * CallbackTraceSource m_dropSource; + * }; + * \endcode + * These 3 new sources can be connected easily to a new trace sink: + * \code + * void ASimpleTraceSink (const TraceContext &context, const Packet &packet, enum MyModel::TraceType type) + * { + * // here, read the "type" argument * } * \endcode * - * This kind of extra information is not generated magically: model - * authors must provide to the ns3::CompositeTraceResolver that - * per-source extra information during registration to allow the - * connection system to store it safely in the user's TraceContext objects. + * This solution works but it makes it impossible to connect a single trace sink to a set + * of trace sources which represent "rx" events in different NetDevice objects since + * each of them will define a different enum type with different values: since the + * trace sink signature must match exactly the trace source signature, it is impossible + * to connect at the same time to all "rx" events of different NetDevice. + * + * \subsection AdvancedTraceContextFancySolution The more complex and generic solution + * + * There is, hopefully, a way to get the best of both worlds, that is, to allow a + * user to connect to a lot of trace source events of the same kind but coming from different + * implementations and to allow the user to differentiate between these different + * implementations. + * + * Rather than define an adhoc enum type with a list of trace sources, you can also + * define a new ns3::TraceContextElement for your source sources. For example, if you + * define a new MyModelTraceType class which contains the type of trace, your users can + * then write trace sink code which looks like this: + * \code + * void AFancyTraceSink (const TraceContext &context, const Packet &packet) + * { + * MyModelTraceType type; + * if (context.GetElement (type)) + * { + * switch (type.Get ()) + * { + * case MyModelTraceType::RX: + * std::cout << "rx" << std::endl; + * break; + * case MyModelTraceType::TX: + * std::cout << "tx" << std::endl; + * break; + * case MyModelTraceType::DROP: + * std::cout << "drop" << std::endl; + * break; + * } + * } + * } + * \endcode + * + * Of course, since the type of trace is stored in the TraceContext, your users can + * also take the shortcut which uses the printing functionality of the TraceContext: + * \code + * void ALessFancyTraceSink (const TraceContext &context, const Packet &packet) + * { + * std::cout << "context=\"" << context << "\" packet: " << packet << std::endl; + * } + * \endcode + * which will generate something like the following when the trace source comes + * from MyModel: + * \code + * context="my-model-rx" packet: ... + * \endcode * * The first step to achieve this is to define and implement a new - * subclass of the ns3::TraceContextElement base class: + * subclass of the ns3::TraceContextElement base class. The exact list of + * public methods which must be implemented is described in the API + * documentation of the ns3::TraceContextElement class. * \code * class MyModelTraceType : public TraceContextElement * { @@ -352,7 +466,7 @@ * enum Type m_type; * }; * \endcode - * The implementation is quite straightforward: + * The implementation does not require much thinking: * \code * MyModelTraceType::MyModelTraceType (enum Type type) * : m_type (type) @@ -366,12 +480,15 @@ * MyModelTraceType::GetUid (void) * { * // use protected TraceContextElement::AllocateUid method + * // the input string is used to uniquely identify this new subclass * static uint16_t uid = AllocateUid ("ns3::MyModelTraceType"); * return uid; * } * void * MyModelTraceType::Print (std::ostream &os) const * ( + * // this method is invoked by the print function of a TraceContext + * // if it contains an instance of this TraceContextElement. * switch (m_type) { * case RX: os << "rx"; break; * // ... @@ -380,6 +497,9 @@ * std::string * MyModelTraceType::GetTypeName (void) const * { + * // This method should return a fully-qualified c++ typename + * // This method is used only for documentation purposes to + * // generate the content of the Trace Source List. * return "ns3::MyModelTraceType"; * } * \endcode From 7d8b071049c117ee95ce2d383f5b9738a3748c7b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 5 Sep 2007 12:34:53 +0200 Subject: [PATCH 86/92] add an overload of the TraceSource::AddCallback method --- src/core/trace-source.cc | 31 +++++++++++++++++++++++++++++++ src/core/trace-source.h | 7 +++++++ src/core/wscript | 1 + 3 files changed, 39 insertions(+) create mode 100644 src/core/trace-source.cc diff --git a/src/core/trace-source.cc b/src/core/trace-source.cc new file mode 100644 index 000000000..64c7d8960 --- /dev/null +++ b/src/core/trace-source.cc @@ -0,0 +1,31 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 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 "trace-source.h" +#include "trace-context.h" + +namespace ns3 { + +void +TraceSource::AddCallback (CallbackBase const & callback) +{ + AddCallback (callback, TraceContext ()); +} + +} // namespace ns3 diff --git a/src/core/trace-source.h b/src/core/trace-source.h index 2a90de2ee..f9ee2ddac 100644 --- a/src/core/trace-source.h +++ b/src/core/trace-source.h @@ -23,6 +23,9 @@ namespace ns3 { +class CallbackBase; +class TraceContext; + /** * \brief the base class for all trace sources * @@ -40,6 +43,10 @@ public: * back to the user. */ virtual void AddCallback (CallbackBase const & callback, TraceContext const & context) = 0; + /** + * \param callback the callback to connect to this trace source + */ + void AddCallback (CallbackBase const & callback); /** * \param callback the callback to disconnect from this trace source */ diff --git a/src/core/wscript b/src/core/wscript index b32bd3a9c..455779fd6 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -49,6 +49,7 @@ def build(bld): 'callback-trace-source.cc', 'composite-trace-resolver.cc', 'trace-doc.cc', + 'trace-source.cc', ] if sys.platform == 'win32': From 6b8f9a0d079427e0d36babbc3dcd12359e4d5678 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 5 Sep 2007 12:36:21 +0200 Subject: [PATCH 87/92] add missing section on simple trace connection --- doc/tracing.h | 60 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/doc/tracing.h b/doc/tracing.h index 720e9a334..f3db38481 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -106,11 +106,59 @@ * for each trace source: a signature of the user trace sink must match * _exactly_ the signature documented in the \ref TraceSourceList. * - * \section TraceConnection Connecting Trace Sources to Trace Sinks * - * Since there is no working magic here, defining a trace sink does not connect - * it directly to a set of trace sources. To connect a trace sink, a user must call - * ns3::NodeList::Connect. The second argument is a callback to the user's trace sink. + * \section TraceSourceSimpleExport A simple way to connect Trace Sources with Trace Sinks + * + * The crux of the complexity of the ns-3 tracing system comes from its + * flexible system used to connect trace sources to trace sinks but what is really + * nice about it is that it is not necessary to use it to setup simple traces. + * + * The simplest way to export a set of trace sources to a user, for example, + * during the early prototyping phases of a system, is to add a set of public methods + * to give to your users access to the trace source object instances you use to generate + * trace events: + * \code + * class MyModel + * { + * public: + * void DoSomething (Packet packet) + * { + * // report this event on packet + * m_doSomething (packet); + * // do something + * } + * CallbackTraceSource *PeekSomethingTraceSource (void) const + * { + * return &m_doSomething + * } + * private: + * // report every "something" function call. + * CallbackTraceSource m_doSomething; + * }; + * \endcode + * If your users hold a pointer to an instance of MyModel, and if they want to connect + * a MySomethingSink, they can simply do the following which invokes the + * TraceSource::AddCallback method and creates a Callback object from the user's + * sink with the MakeCallback function. + * \code + * void + * MySomethingSink (const TraceContext &context, Packet packet) + * { + * // do whatever you want. + * } + * MyModel *model = ...; + * model->AddCallback (MakeCallback (&MySomethingSink)); + * \endcode + * + * The full power of the tracing system comes however from its ns3::NodeList::Connect + * method which is described in the following sections. + * + * \section TraceConnection Connecting Trace Sources to Trace Sinks + * + * If a trace source is integrated in the ns-3 trace connection facility, a user + * should call the ns3::NodeList::Connect method to establish a connection between + * a trace sink and a set of matching trace sources. The second argument to that + * method is a callback to the user's trace sink. * That callback is easy to construct: call ns3::MakeCallback and you are done. The * first argument is a string whose format is similar to a unix path and which is * used to uniquely identify the set of trace sources you want to connect to. @@ -187,10 +235,6 @@ * } * \endcode * - * \section TraceSourceSimpleExport A simple way to export Trace Sources - * - * XXX - * * \section ExportingTraceSources Exporting new Trace Sources * * Using existing trace sources to connect them to a set of adhoc trace sinks From eb81a302b076d7b50eb4979522228088f274ddeb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 5 Sep 2007 12:39:11 +0200 Subject: [PATCH 88/92] fix a small typo --- doc/tracing.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/tracing.h b/doc/tracing.h index f3db38481..45e7d9db5 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -147,7 +147,8 @@ * // do whatever you want. * } * MyModel *model = ...; - * model->AddCallback (MakeCallback (&MySomethingSink)); + * CallbackTraceSource *source = model->PeekSomethingTraceSource (); + * source->AddCallback (MakeCallback (&MySomethingSink)); * \endcode * * The full power of the tracing system comes however from its ns3::NodeList::Connect From 187ae2fe0e3c3bdb28b6a2bfdadcd963ce71db16 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 6 Sep 2007 10:04:19 +0200 Subject: [PATCH 89/92] add tests, fix the failing tests and add support for 6-arg callbacks --- src/core/callback-test.cc | 50 +++++++++++++ src/core/callback.h | 148 +++++++++++++++++++++++++++----------- 2 files changed, 155 insertions(+), 43 deletions(-) diff --git a/src/core/callback-test.cc b/src/core/callback-test.cc index 9e8cf259f..0e9811e7b 100644 --- a/src/core/callback-test.cc +++ b/src/core/callback-test.cc @@ -57,6 +57,14 @@ void *Test10 (bool *a, int const & b) return a; } +void TestFZero (void) {} +void TestFOne (int) {} +void TestFTwo (int, int) {} +void TestFThree (int, int, int) {} +void TestFFour (int, int, int, int) {} +void TestFFive (int, int, int, int, int) {} +void TestFSix (int, int, int, int, int, int) {} + class CallbackTest : public ns3::Test { private: bool m_test1; @@ -73,6 +81,22 @@ public: void Test3 (double a); int Test4 (double a, int b); void Test8 (Callback callback); + + void TestZero (void) {} + void TestOne (int) {} + void TestTwo (int, int) {} + void TestThree (int, int, int) {} + void TestFour (int, int, int, int) {} + void TestFive (int, int, int, int, int) {} + void TestSix (int, int, int, int, int, int) {} + + void TestCZero (void) const {} + void TestCOne (int) const {} + void TestCTwo (int, int) const {} + void TestCThree (int, int, int) const {} + void TestCFour (int, int, int, int) const {} + void TestCFive (int, int, int, int, int) const {} + void TestCSix (int, int, int, int, int, int) const {} }; CallbackTest::CallbackTest () @@ -110,6 +134,7 @@ CallbackTest::Test8 (Callback callback) { callback (3); } + bool CallbackTest::IsWrong (void) { @@ -216,6 +241,31 @@ CallbackTest::RunTests (void) MakeBoundCallback (&Test9, &v); MakeBoundCallback (&Test10, &v); + + MakeCallback (&CallbackTest::TestZero, this); + MakeCallback (&CallbackTest::TestOne, this); + MakeCallback (&CallbackTest::TestTwo, this); + MakeCallback (&CallbackTest::TestThree, this); + MakeCallback (&CallbackTest::TestFour, this); + MakeCallback (&CallbackTest::TestFive, this); + MakeCallback (&CallbackTest::TestSix, this); + + MakeCallback (&CallbackTest::TestCZero, this); + MakeCallback (&CallbackTest::TestCOne, this); + MakeCallback (&CallbackTest::TestCTwo, this); + MakeCallback (&CallbackTest::TestCThree, this); + MakeCallback (&CallbackTest::TestCFour, this); + MakeCallback (&CallbackTest::TestCFive, this); + MakeCallback (&CallbackTest::TestCSix, this); + + MakeCallback (&TestFZero); + MakeCallback (&TestFOne); + MakeCallback (&TestFTwo); + MakeCallback (&TestFThree); + MakeCallback (&TestFFour); + MakeCallback (&TestFFive); + MakeCallback (&TestFSix); + return ok; } diff --git a/src/core/callback.h b/src/core/callback.h index c5d3cf442..4e43a1436 100644 --- a/src/core/callback.h +++ b/src/core/callback.h @@ -25,6 +25,7 @@ #include "ptr.h" #include "fatal-error.h" #include "empty.h" +#include namespace ns3 { @@ -89,55 +90,62 @@ private: }; // declare the CallbackImpl class -template +template class CallbackImpl; // define CallbackImpl for 0 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (void) = 0; }; // define CallbackImpl for 1 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (T1) = 0; }; // define CallbackImpl for 2 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (T1, T2) = 0; }; // define CallbackImpl for 3 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (T1, T2, T3) = 0; }; // define CallbackImpl for 4 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (T1, T2, T3, T4) = 0; }; // define CallbackImpl for 5 params template -class CallbackImpl : public CallbackImplBase { +class CallbackImpl : public CallbackImplBase { public: virtual ~CallbackImpl () {} virtual R operator() (T1, T2, T3, T4, T5) = 0; }; +// define CallbackImpl for 6 params + template +class CallbackImpl : public CallbackImplBase { +public: + virtual ~CallbackImpl () {} + virtual R operator() (T1, T2, T3, T4, T5, T6) = 0; +}; // an impl for Functors: -template -class FunctorCallbackImpl : public CallbackImpl { +template +class FunctorCallbackImpl : public CallbackImpl { public: FunctorCallbackImpl (T const &functor) : m_functor (functor) {} @@ -160,9 +168,12 @@ public: R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) { return m_functor (a1,a2,a3,a4,a5); } + R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5,T6 a6) { + return m_functor (a1,a2,a3,a4,a5,a6); + } virtual bool IsEqual (CallbackImplBase const *other) const { - FunctorCallbackImpl const *otherDerived = - dynamic_cast const *> (other); + FunctorCallbackImpl const *otherDerived = + dynamic_cast const *> (other); if (otherDerived == 0) { return false; @@ -178,8 +189,8 @@ private: }; // an impl for pointer to member functions -template -class MemPtrCallbackImpl : public CallbackImpl { +template +class MemPtrCallbackImpl : public CallbackImpl { public: MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr) : m_objPtr (objPtr), m_memPtr (mem_ptr) {} @@ -202,9 +213,12 @@ public: R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5) { return ((CallbackTraits::GetReference (m_objPtr)).*m_memPtr) (a1, a2, a3, a4, a5); } + R operator() (T1 a1,T2 a2,T3 a3,T4 a4,T5 a5,T6 a6) { + return ((CallbackTraits::GetReference (m_objPtr)).*m_memPtr) (a1, a2, a3, a4, a5, a6); + } virtual bool IsEqual (CallbackImplBase const *other) const { - MemPtrCallbackImpl const *otherDerived = - dynamic_cast const *> (other); + MemPtrCallbackImpl const *otherDerived = + dynamic_cast const *> (other); if (otherDerived == 0) { return false; @@ -260,22 +274,22 @@ public: template + typename T5 = empty, typename T6 = empty> class Callback : public CallbackBase { public: // There are two dummy args below to ensure that this constructor is // always properly disambiguited by the c++ compiler template Callback (FUNCTOR const &functor, bool, bool) - : m_impl (Create > (functor)) + : m_impl (Create > (functor)) {} template Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr) - : m_impl (Create > (objPtr, mem_ptr)) + : m_impl (Create > (objPtr, mem_ptr)) {} - Callback (Ptr > const &impl) + Callback (Ptr > const &impl) : m_impl (impl) {} @@ -305,6 +319,9 @@ public: R operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) const { return (*(PeekImpl ())) (a1,a2,a3,a4,a5); } + R operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5,T6 a6) const { + return (*(PeekImpl ())) (a1,a2,a3,a4,a5,a6); + } bool IsEqual (CallbackBase const &other) const { return PeekImpl ()->IsEqual (other.PeekImpl ()); @@ -312,7 +329,7 @@ public: bool CheckType (CallbackBase const& other) const { CallbackImplBase *otherBase = other.PeekImpl (); - if (dynamic_cast *> (otherBase) != 0) + if (dynamic_cast *> (otherBase) != 0) { return true; } @@ -328,27 +345,27 @@ public: " got=" << typeid (other).name () << ", expected=" << typeid (*this).name ()); } - const Callback *goodType = static_cast *> (&other); + const Callback *goodType = static_cast *> (&other); *this = *goodType; } void Assign (Ptr other) { - CallbackImpl *impl = dynamic_cast *> (PeekPointer (other)); + CallbackImpl *impl = dynamic_cast *> (PeekPointer (other)); if (other == 0) { NS_FATAL_ERROR ("Incompatible types. (feed to \"c++filt -t\")" " got=" << typeid (other).name () << ", expected=" << typeid (*impl).name ()); } - *this = Callback (impl); + *this = Callback (impl); } virtual PtrGetImpl (void) const { return m_impl; } private: - virtual CallbackImpl *PeekImpl (void) const { + virtual CallbackImpl *PeekImpl (void) const { return PeekPointer (m_impl); } - Ptr > m_impl; + Ptr > m_impl; }; /** @@ -369,7 +386,7 @@ Callback MakeCallback (R (T::*memPtr) (void), OBJ objPtr) { return Callback (objPtr, memPtr); } template -Callback MakeCallback (R (T::*mem_ptr) () const, OBJ const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) () const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } /** @@ -381,11 +398,11 @@ Callback MakeCallback (R (T::*mem_ptr) () const, OBJ const objPtr) { * and potentially return a value. */ template -Callback MakeCallback (R (T::*mem_ptr) (T1), OBJ *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1), OBJ objPtr) { return Callback (objPtr, mem_ptr); } template -Callback MakeCallback (R (T::*mem_ptr) (T1) const, OBJ const *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1) const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } /** @@ -397,11 +414,11 @@ Callback MakeCallback (R (T::*mem_ptr) (T1) const, OBJ const *const objPtr * and potentially return a value. */ template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2), OBJ *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2), OBJ objPtr) { return Callback (objPtr, mem_ptr); } template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2) const, OBJ const*const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2) const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } /** @@ -413,11 +430,11 @@ Callback MakeCallback (R (T::*mem_ptr) (T1,T2) const, OBJ const*const o * and potentially return a value. */ template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3), OBJ *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3), OBJ objPtr) { return Callback (objPtr, mem_ptr); } template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3) const, OBJ const*const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3) const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } /** @@ -429,11 +446,11 @@ Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3) const, OBJ const*c * and potentially return a value. */ template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4), OBJ *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4), OBJ objPtr) { return Callback (objPtr, mem_ptr); } template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4) const, OBJ const*const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4) const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } /** @@ -445,13 +462,29 @@ Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4) const, OBJ c * and potentially return a value. */ template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5), OBJ objPtr) { return Callback (objPtr, mem_ptr); } template -Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5) const, OBJ const*const objPtr) { +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5) const, OBJ objPtr) { return Callback (objPtr, mem_ptr); } +/** + * \ingroup MakeCallback + * \param mem_ptr class method member pointer + * \param objPtr class instance + * \return a wrapper Callback + * Build Callbacks for class method members which takes five arguments + * and potentially return a value. + */ +template +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5,T6), OBJ objPtr) { + return Callback (objPtr, mem_ptr); +} +template +Callback MakeCallback (R (T::*mem_ptr) (T1,T2,T3,T4,T5,T6) const, OBJ objPtr) { + return Callback (objPtr, mem_ptr); +} /** * \ingroup MakeCallback @@ -519,6 +552,17 @@ template MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) { return Callback (fnPtr, true, true); } +/** + * \ingroup MakeCallback + * \param fnPtr function pointer + * \return a wrapper Callback + * Build Callbacks for functions which takes five arguments + * and potentially return a value. + */ +template +Callback MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5,T6)) { + return Callback (fnPtr, true, true); +} @@ -587,6 +631,17 @@ template MakeNullCallback (void) { return Callback (); } +/** + * \ingroup MakeCallback + * \overload Callback MakeNullCallback (void) + * \return a wrapper Callback + * Build a null callback which takes five arguments + * and potentially return a value. + */ +template +Callback MakeNullCallback (void) { + return Callback (); +} /* @@ -596,9 +651,10 @@ Callback MakeNullCallback (void) { */ // an impl for Bound Functors: template -class BoundFunctorCallbackImpl : public CallbackImpl { +class BoundFunctorCallbackImpl : public CallbackImpl { public: - BoundFunctorCallbackImpl (T const &functor, TX a) + template + BoundFunctorCallbackImpl (FUNCTOR functor, ARG a) : m_functor (functor), m_a (a) {} virtual ~BoundFunctorCallbackImpl () {} R operator() (void) { @@ -640,36 +696,42 @@ private: template Callback MakeBoundCallback (R (*fnPtr) (TX), TX a) { - Ptr > impl = + Ptr > impl = Create >(fnPtr, a); return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1), TX a) { - Ptr > impl = + Ptr > impl = Create > (fnPtr, a); return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) { - Ptr > impl = + Ptr > impl = Create > (fnPtr, a); return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) { - Ptr > impl = + Ptr > impl = Create > (fnPtr, a); return Callback (impl); } template Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) { - Ptr > impl = + Ptr > impl = Create > (fnPtr, a); return Callback (impl); } +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5,T6), TX a) { + Ptr > impl = + Create > (fnPtr, a); + return Callback (impl); +} }; // namespace ns3 From 8b5b6d36360f3bc467a567ca582b353bec75101c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 6 Sep 2007 12:33:22 +0200 Subject: [PATCH 90/92] add bound callback tests and make them work --- src/core/callback-test.cc | 29 +++++++++++++++++++++++++++ src/core/callback.h | 42 +++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/core/callback-test.cc b/src/core/callback-test.cc index 0e9811e7b..4fb062321 100644 --- a/src/core/callback-test.cc +++ b/src/core/callback-test.cc @@ -65,6 +65,13 @@ void TestFFour (int, int, int, int) {} void TestFFive (int, int, int, int, int) {} void TestFSix (int, int, int, int, int, int) {} +void TestFROne (int &) {} +void TestFRTwo (int &, int &) {} +void TestFRThree (int &, int &, int &) {} +void TestFRFour (int &, int &, int &, int &) {} +void TestFRFive (int &, int &, int &, int &, int &) {} +void TestFRSix (int &, int &, int &, int &, int &, int &) {} + class CallbackTest : public ns3::Test { private: bool m_test1; @@ -266,6 +273,28 @@ CallbackTest::RunTests (void) MakeCallback (&TestFFive); MakeCallback (&TestFSix); + MakeCallback (&TestFROne); + MakeCallback (&TestFRTwo); + MakeCallback (&TestFRThree); + MakeCallback (&TestFRFour); + MakeCallback (&TestFRFive); + MakeCallback (&TestFRSix); + + + MakeBoundCallback (&TestFOne, 1); + MakeBoundCallback (&TestFTwo, 1); + MakeBoundCallback (&TestFThree, 1); + MakeBoundCallback (&TestFFour, 1); + MakeBoundCallback (&TestFFive, 1); + + MakeBoundCallback (&TestFROne, 1); + MakeBoundCallback (&TestFRTwo, 1); + MakeBoundCallback (&TestFRThree, 1); + MakeBoundCallback (&TestFRFour, 1); + MakeBoundCallback (&TestFRFive, 1); + + + return ok; } diff --git a/src/core/callback.h b/src/core/callback.h index 4e43a1436..ff04de447 100644 --- a/src/core/callback.h +++ b/src/core/callback.h @@ -25,7 +25,7 @@ #include "ptr.h" #include "fatal-error.h" #include "empty.h" -#include +#include "type-traits.h" namespace ns3 { @@ -691,47 +691,51 @@ public: } private: T m_functor; - TX m_a; + typename TypeTraits::ReferencedType m_a; }; -template -Callback MakeBoundCallback (R (*fnPtr) (TX), TX a) { +template +Callback MakeBoundCallback (R (*fnPtr) (TX), ARG a) { Ptr > impl = Create >(fnPtr, a); return Callback (impl); } -template -Callback MakeBoundCallback (R (*fnPtr) (TX,T1), TX a) { +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1), ARG a) { Ptr > impl = Create > (fnPtr, a); return Callback (impl); } -template -Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) { +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2), ARG a) { Ptr > impl = Create > (fnPtr, a); return Callback (impl); } -template -Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) { +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3), ARG a) { + Ptr > impl = + Create > (fnPtr, a); + return Callback (impl); +} +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), ARG a) { Ptr > impl = Create > (fnPtr, a); return Callback (impl); } - -template -Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) { +template +Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), ARG a) { Ptr > impl = Create > (fnPtr, a); return Callback (impl); } -template -Callback MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5,T6), TX a) { - Ptr > impl = - Create > (fnPtr, a); - return Callback (impl); -} }; // namespace ns3 From 1a75a82523e026cfeaefeecf20b0cc4a6809f734 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 6 Sep 2007 12:56:31 +0200 Subject: [PATCH 91/92] add support for NodeList::ConnectPrinterToAll --- examples/simple-point-to-point.cc | 3 + src/core/array-trace-resolver.h | 16 +++++ src/core/callback-trace-source.cc | 7 ++- src/core/callback-trace-source.h | 94 ++++++++++++++++++++++++++++ src/core/composite-trace-resolver.cc | 31 +++++++++ src/core/composite-trace-resolver.h | 8 +++ src/core/fv-trace-source.h | 3 + src/core/object.cc | 31 +++++++++ src/core/object.h | 1 + src/core/sv-trace-source.h | 3 + src/core/trace-resolver.h | 2 + src/core/trace-source.h | 3 + src/core/uv-trace-source.h | 5 +- src/node/node-list.cc | 5 ++ src/node/node-list.h | 1 + 15 files changed, 210 insertions(+), 3 deletions(-) diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index 4e7657cdb..91a1f45e1 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -64,6 +64,7 @@ #include "ns3/ipv4-route.h" #include "ns3/point-to-point-topology.h" #include "ns3/onoff-application.h" +#include "ns3/node-list.h" using namespace ns3; @@ -178,6 +179,8 @@ int main (int argc, char *argv[]) asciitrace.TraceAllQueues (); asciitrace.TraceAllNetDeviceRx (); + NodeList::ConnectPrinterToAll (std::cout); + // Also configure some tcpdump traces; each interface will be traced // The output files will be named // simple-point-to-point.pcap-- diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index 0d1086447..d5bc2ca32 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -64,6 +64,7 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); private: class IteratorBase @@ -183,6 +184,21 @@ ArrayTraceResolver::CollectSources (std::string path, const TraceContext } } +template +void +ArrayTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +{ + uint32_t j = 0; + for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ()) + { + TraceContext tmp = context; + INDEX index = j; + tmp.AddElement (index); + Ptr obj = m_iter->Get (); + obj->GetTraceResolver ()->ConnectPrinterToAll (os, tmp); + j++; + } +} }//namespace ns3 diff --git a/src/core/callback-trace-source.cc b/src/core/callback-trace-source.cc index aa686c14d..02298520e 100644 --- a/src/core/callback-trace-source.cc +++ b/src/core/callback-trace-source.cc @@ -19,6 +19,9 @@ * Author: Mathieu Lacage */ #include "callback-trace-source.h" + +#ifdef RUN_SELF_TESTS + #include "test.h" namespace ns3 { @@ -93,6 +96,6 @@ CallbackTraceSourceTest::RunTests (void) CallbackTraceSourceTest g_callbackTraceTest; - - }//namespace ns3 + +#endif /* RUN_SELF_TESTS */ diff --git a/src/core/callback-trace-source.h b/src/core/callback-trace-source.h index d571b5739..2e302cdc2 100644 --- a/src/core/callback-trace-source.h +++ b/src/core/callback-trace-source.h @@ -44,6 +44,7 @@ public: CallbackTraceSource (); virtual void AddCallback (CallbackBase const & callback, TraceContext const & context); virtual void RemoveCallback (CallbackBase const & callback); + virtual void ConnectPrinter (std::ostream &os, const TraceContext &context); void operator() (void) const; void operator() (T1 a1) const; void operator() (T1 a1, T2 a2) const; @@ -62,6 +63,92 @@ private: namespace ns3 { +namespace internal { + +template +class TraceSinkPrint; + +template +class TraceSinkPrint +{ +public: + static Callback Make (std::ostream &os) + { + return ns3::MakeBoundCallback (&DoPrint, &os); + } +private: + static void DoPrint (std::ostream *os, const TraceContext &context, T1 a1, T2 a2, T3 a3, T4 a4) + { + *os << "context=\"" << context << "\" arg1=\"" << a1 << "\" arg2=\"" << a2 << "\" arg3=\"" << a3 << "\" arg4=\"" << a4 << "\"" << std::endl; + } +}; + +template +class TraceSinkPrint +{ +public: + static Callback Make (std::ostream &os) + { + return ns3::MakeBoundCallback (&DoPrint, &os); + } +private: + static void DoPrint (std::ostream *os, const TraceContext &context, T1 a1, T2 a2, T3 a3) + { + *os << "context=\"" << context << "\" arg1=\"" << a1 << "\" arg2=\"" << a2 << "\" arg3=\"" << a3 << "\"" << std::endl; + } +}; + +template +class TraceSinkPrint +{ +public: + static Callback Make (std::ostream &os) + { + return ns3::MakeBoundCallback (&DoPrint, &os); + } +private: + static void DoPrint (std::ostream *os, const TraceContext &context, T1 a1, T2 a2) + { + *os << "context=\"" << context << "\" arg1=\"" << a1 << "\" arg2=\"" << a2 << "\"" << std::endl; + } +}; + +template +class TraceSinkPrint +{ +public: + static Callback Make (std::ostream &os) + { + return ns3::MakeBoundCallback (&DoPrint, &os); + } +private: + static void DoPrint (std::ostream *os, const TraceContext &context, T1 a1) + { + *os << "context=\"" << context << "\" arg1=\"" << a1 << "\"" << std::endl; + } +}; + +template <> +class TraceSinkPrint +{ +public: + static Callback Make (std::ostream &os) + { + return ns3::MakeBoundCallback (&DoPrint, &os); + } +private: + static void DoPrint (std::ostream *os, const TraceContext &context) + { + *os << "context=\"" << context << std::endl; + } +}; + +} // namespace internal + + template CallbackTraceSource::CallbackTraceSource () @@ -99,6 +186,13 @@ CallbackTraceSource::RemoveCallback (CallbackBase const & callback) template void +CallbackTraceSource::ConnectPrinter (std::ostream &os, const TraceContext &context) +{ + AddCallback (ns3::internal::TraceSinkPrint::Make (os), context); +} +template +void CallbackTraceSource::operator() (void) const { for (typename CallbackList::const_iterator i = m_callbackList.begin (); diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index bb0aacabb..377da45b5 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -63,6 +63,12 @@ CompositeTraceResolver::Add (std::string name, ctx.Union (this->context); this->maker ()->CollectSources (path, ctx, collection); } + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + { + TraceContext ctx = context; + ctx.Union (this->context); + this->maker ()->ConnectPrinterToAll (os, ctx); + } Callback > maker; } *item = new MakerResolveItem (); item->name = name; @@ -101,6 +107,12 @@ CompositeTraceResolver::DoAddSource (std::string name, ctx.Union (this->context); collection->AddUnique (path, ctx, this->doc); } + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + { + TraceContext ctx = context; + ctx.Union (this->context); + this->trace->ConnectPrinter (os, ctx); + } TraceSource *trace; TraceDoc doc; } *item = new SourceResolveItem (); @@ -138,6 +150,12 @@ CompositeTraceResolver::DoAddComposite (std::string name, Ptr composite, ctx.Union (this->context); this->composite->GetTraceResolver ()->CollectSources (path, ctx, collection); } + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + { + TraceContext ctx = context; + ctx.Union (this->context); + this->composite->GetTraceResolver ()->ConnectPrinterToAll (os, ctx); + } Ptr composite; } *item = new CompositeResolveItem (); @@ -293,6 +311,19 @@ CompositeTraceResolver::CollectSources (std::string path, const TraceContext &co m_parent->CollectSources (path, context, collection); } } +void +CompositeTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +{ + for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) + { + NS_DEBUG ("print " << (*i)->name); + (*i)->ConnectPrinterToAll (os, context); + } + if (m_parent != 0) + { + m_parent->ConnectPrinterToAll (os, context); + } +} }//namespace ns3 diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index 56886d739..c0612151f 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -120,6 +120,7 @@ private: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); friend class CompositeTraceResolverTest; class ResolveItem { @@ -129,6 +130,7 @@ private: virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0; virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) = 0; std::string name; TraceContext context; @@ -199,6 +201,12 @@ CompositeTraceResolver::AddArray (std::string name, ctx.Union (this->context); array->CollectSources (path, ctx, collection); } + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + { + TraceContext ctx = context; + ctx.Union (this->context); + array->ConnectPrinterToAll (os, ctx); + } Ptr > array; } *item = new ArrayResolveItem (); diff --git a/src/core/fv-trace-source.h b/src/core/fv-trace-source.h index 5b9f44df4..c0f816dbb 100644 --- a/src/core/fv-trace-source.h +++ b/src/core/fv-trace-source.h @@ -46,6 +46,9 @@ public: virtual void RemoveCallback (CallbackBase const & callback) { m_callback.RemoveCallback (callback); } + virtual void ConnectPrinter (std::ostream &os, const TraceContext &context) { + m_callback.ConnectPrinter (os, context); + } protected: void notify (double oldVal, double newVal) { if (oldVal != newVal) diff --git a/src/core/object.cc b/src/core/object.cc index 85f180cf0..ce87c0f63 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -68,6 +68,7 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); private: Ptr ParseForInterface (std::string path); Ptr m_aggregate; @@ -114,6 +115,11 @@ InterfaceIdTraceResolver::CollectSources (std::string path, const TraceContext & { m_aggregate->DoCollectSources (path, context, collection); } +void +InterfaceIdTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +{ + m_aggregate->DoConnectPrinterToAll (os, context); +} InterfaceId::InterfaceId (uint16_t iid) @@ -333,6 +339,31 @@ Object::DoCollectSources (std::string path, const TraceContext &context, m_collecting = false; } +void +Object::DoConnectPrinterToAll (std::ostream &os, const TraceContext &context) const +{ + const Object *current; + current = this; + do { + if (current->m_collecting) + { + return; + } + current = current->m_next; + } while (current != this); + + m_collecting = true; + + current = this->m_next; + while (current != this) + { + NS_ASSERT (current != 0); + current->GetTraceResolver ()->ConnectPrinterToAll (os, context); + current = current->m_next; + } + + m_collecting = false; +} } // namespace ns3 diff --git a/src/core/object.h b/src/core/object.h index ea4f091db..9cc5a0f68 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -184,6 +184,7 @@ private: Ptr DoQueryInterface (InterfaceId iid) const; void DoCollectSources (std::string path, const TraceContext &context, TraceResolver::SourceCollection *collection) const; + void DoConnectPrinterToAll (std::ostream &os, const TraceContext &context) const; bool Check (void) const; void MaybeDelete (void) const; mutable uint32_t m_count; diff --git a/src/core/sv-trace-source.h b/src/core/sv-trace-source.h index 23d28f988..8cbb2447b 100644 --- a/src/core/sv-trace-source.h +++ b/src/core/sv-trace-source.h @@ -46,6 +46,9 @@ public: virtual void RemoveCallback (CallbackBase const & callback) { m_callback.RemoveCallback (callback); } + virtual void ConnectPrinter (std::ostream &os, const TraceContext &context) { + m_callback.ConnectPrinter (os, context); + } protected: void Notify (int64_t oldVal, int64_t newVal) { if (oldVal != newVal) diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index c78a6f21d..f3e0d101a 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -100,6 +100,8 @@ public: */ virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; + + virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) = 0; protected: /** * \param path a namespace path diff --git a/src/core/trace-source.h b/src/core/trace-source.h index f9ee2ddac..9a35a80ad 100644 --- a/src/core/trace-source.h +++ b/src/core/trace-source.h @@ -21,6 +21,8 @@ #ifndef TRACE_SOURCE_H #define TRACE_SOURCE_H +#include + namespace ns3 { class CallbackBase; @@ -51,6 +53,7 @@ public: * \param callback the callback to disconnect from this trace source */ virtual void RemoveCallback (CallbackBase const & callback) = 0; + virtual void ConnectPrinter (std::ostream &os, TraceContext const &context) = 0; }; } // namespace ns3 diff --git a/src/core/uv-trace-source.h b/src/core/uv-trace-source.h index ff248bbf4..0fe84c826 100644 --- a/src/core/uv-trace-source.h +++ b/src/core/uv-trace-source.h @@ -47,7 +47,10 @@ public: m_callback.AddCallback (callback, context); } virtual void RemoveCallback (CallbackBase const & callback) { - m_callback.RemoveCallback (callback); + m_callback.RemoveCallback (callback); + } + virtual void ConnectPrinter (std::ostream &os, const TraceContext &context) { + m_callback.ConnectPrinter (os, context); } protected: diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 3a68bf584..95a009bbb 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -171,6 +171,11 @@ NodeList::Disconnect (std::string name, const CallbackBase &cb) { SimulationSingleton::Get ()->GetTraceResolver ()->Disconnect (name, cb); } +void +NodeList::ConnectPrinterToAll (std::ostream &os) +{ + SimulationSingleton::Get ()->GetTraceResolver ()->ConnectPrinterToAll (os, TraceContext ()); +} Ptr NodeList::GetTraceResolver (void) { diff --git a/src/node/node-list.h b/src/node/node-list.h index 4a6c113bf..02c638bbf 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -101,6 +101,7 @@ public: * the input namespace regexp. */ static void Disconnect (std::string name, const CallbackBase &cb); + static void ConnectPrinterToAll (std::ostream &os); static Ptr GetTraceResolver (void); private: }; From 6c05ba06ffeb6ecd991ba354e0f5b04417d701ff Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 6 Sep 2007 13:32:29 +0200 Subject: [PATCH 92/92] rename ConnectPrinterToAll to TraceAll --- examples/simple-point-to-point.cc | 2 +- src/core/array-trace-resolver.h | 6 +++--- src/core/composite-trace-resolver.cc | 16 ++++++++-------- src/core/composite-trace-resolver.h | 8 ++++---- src/core/object.cc | 10 +++++----- src/core/object.h | 2 +- src/core/trace-resolver.h | 2 +- src/node/node-list.cc | 4 ++-- src/node/node-list.h | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index 91a1f45e1..852d9c420 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -179,7 +179,7 @@ int main (int argc, char *argv[]) asciitrace.TraceAllQueues (); asciitrace.TraceAllNetDeviceRx (); - NodeList::ConnectPrinterToAll (std::cout); + NodeList::TraceAll (std::cout); // Also configure some tcpdump traces; each interface will be traced // The output files will be named diff --git a/src/core/array-trace-resolver.h b/src/core/array-trace-resolver.h index d5bc2ca32..ecbc63d5d 100644 --- a/src/core/array-trace-resolver.h +++ b/src/core/array-trace-resolver.h @@ -64,7 +64,7 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); + virtual void TraceAll (std::ostream &os, const TraceContext &context); private: class IteratorBase @@ -186,7 +186,7 @@ ArrayTraceResolver::CollectSources (std::string path, const TraceContext template void -ArrayTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +ArrayTraceResolver::TraceAll (std::ostream &os, const TraceContext &context) { uint32_t j = 0; for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ()) @@ -195,7 +195,7 @@ ArrayTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceCon INDEX index = j; tmp.AddElement (index); Ptr obj = m_iter->Get (); - obj->GetTraceResolver ()->ConnectPrinterToAll (os, tmp); + obj->GetTraceResolver ()->TraceAll (os, tmp); j++; } } diff --git a/src/core/composite-trace-resolver.cc b/src/core/composite-trace-resolver.cc index 377da45b5..bf59054f2 100644 --- a/src/core/composite-trace-resolver.cc +++ b/src/core/composite-trace-resolver.cc @@ -63,11 +63,11 @@ CompositeTraceResolver::Add (std::string name, ctx.Union (this->context); this->maker ()->CollectSources (path, ctx, collection); } - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + virtual void TraceAll (std::ostream &os, const TraceContext &context) { TraceContext ctx = context; ctx.Union (this->context); - this->maker ()->ConnectPrinterToAll (os, ctx); + this->maker ()->TraceAll (os, ctx); } Callback > maker; } *item = new MakerResolveItem (); @@ -107,7 +107,7 @@ CompositeTraceResolver::DoAddSource (std::string name, ctx.Union (this->context); collection->AddUnique (path, ctx, this->doc); } - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + virtual void TraceAll (std::ostream &os, const TraceContext &context) { TraceContext ctx = context; ctx.Union (this->context); @@ -150,11 +150,11 @@ CompositeTraceResolver::DoAddComposite (std::string name, Ptr composite, ctx.Union (this->context); this->composite->GetTraceResolver ()->CollectSources (path, ctx, collection); } - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + virtual void TraceAll (std::ostream &os, const TraceContext &context) { TraceContext ctx = context; ctx.Union (this->context); - this->composite->GetTraceResolver ()->ConnectPrinterToAll (os, ctx); + this->composite->GetTraceResolver ()->TraceAll (os, ctx); } Ptr composite; @@ -312,16 +312,16 @@ CompositeTraceResolver::CollectSources (std::string path, const TraceContext &co } } void -CompositeTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +CompositeTraceResolver::TraceAll (std::ostream &os, const TraceContext &context) { for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { NS_DEBUG ("print " << (*i)->name); - (*i)->ConnectPrinterToAll (os, context); + (*i)->TraceAll (os, context); } if (m_parent != 0) { - m_parent->ConnectPrinterToAll (os, context); + m_parent->TraceAll (os, context); } } diff --git a/src/core/composite-trace-resolver.h b/src/core/composite-trace-resolver.h index c0612151f..ceca4044a 100644 --- a/src/core/composite-trace-resolver.h +++ b/src/core/composite-trace-resolver.h @@ -120,7 +120,7 @@ private: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); + virtual void TraceAll (std::ostream &os, const TraceContext &context); friend class CompositeTraceResolverTest; class ResolveItem { @@ -130,7 +130,7 @@ private: virtual void Disconnect (std::string subpath, const CallbackBase &cb) = 0; virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) = 0; + virtual void TraceAll (std::ostream &os, const TraceContext &context) = 0; std::string name; TraceContext context; @@ -201,11 +201,11 @@ CompositeTraceResolver::AddArray (std::string name, ctx.Union (this->context); array->CollectSources (path, ctx, collection); } - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) + virtual void TraceAll (std::ostream &os, const TraceContext &context) { TraceContext ctx = context; ctx.Union (this->context); - array->ConnectPrinterToAll (os, ctx); + array->TraceAll (os, ctx); } Ptr > array; diff --git a/src/core/object.cc b/src/core/object.cc index ce87c0f63..27ac31917 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -68,7 +68,7 @@ public: virtual void Disconnect (std::string path, CallbackBase const &cb); virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection); - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context); + virtual void TraceAll (std::ostream &os, const TraceContext &context); private: Ptr ParseForInterface (std::string path); Ptr m_aggregate; @@ -116,9 +116,9 @@ InterfaceIdTraceResolver::CollectSources (std::string path, const TraceContext & m_aggregate->DoCollectSources (path, context, collection); } void -InterfaceIdTraceResolver::ConnectPrinterToAll (std::ostream &os, const TraceContext &context) +InterfaceIdTraceResolver::TraceAll (std::ostream &os, const TraceContext &context) { - m_aggregate->DoConnectPrinterToAll (os, context); + m_aggregate->DoTraceAll (os, context); } @@ -340,7 +340,7 @@ Object::DoCollectSources (std::string path, const TraceContext &context, m_collecting = false; } void -Object::DoConnectPrinterToAll (std::ostream &os, const TraceContext &context) const +Object::DoTraceAll (std::ostream &os, const TraceContext &context) const { const Object *current; current = this; @@ -358,7 +358,7 @@ Object::DoConnectPrinterToAll (std::ostream &os, const TraceContext &context) co while (current != this) { NS_ASSERT (current != 0); - current->GetTraceResolver ()->ConnectPrinterToAll (os, context); + current->GetTraceResolver ()->TraceAll (os, context); current = current->m_next; } diff --git a/src/core/object.h b/src/core/object.h index 9cc5a0f68..36aa3a384 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -184,7 +184,7 @@ private: Ptr DoQueryInterface (InterfaceId iid) const; void DoCollectSources (std::string path, const TraceContext &context, TraceResolver::SourceCollection *collection) const; - void DoConnectPrinterToAll (std::ostream &os, const TraceContext &context) const; + void DoTraceAll (std::ostream &os, const TraceContext &context) const; bool Check (void) const; void MaybeDelete (void) const; mutable uint32_t m_count; diff --git a/src/core/trace-resolver.h b/src/core/trace-resolver.h index f3e0d101a..3db2b42c3 100644 --- a/src/core/trace-resolver.h +++ b/src/core/trace-resolver.h @@ -101,7 +101,7 @@ public: virtual void CollectSources (std::string path, const TraceContext &context, SourceCollection *collection) = 0; - virtual void ConnectPrinterToAll (std::ostream &os, const TraceContext &context) = 0; + virtual void TraceAll (std::ostream &os, const TraceContext &context) = 0; protected: /** * \param path a namespace path diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 95a009bbb..1accfa2be 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -172,9 +172,9 @@ NodeList::Disconnect (std::string name, const CallbackBase &cb) SimulationSingleton::Get ()->GetTraceResolver ()->Disconnect (name, cb); } void -NodeList::ConnectPrinterToAll (std::ostream &os) +NodeList::TraceAll (std::ostream &os) { - SimulationSingleton::Get ()->GetTraceResolver ()->ConnectPrinterToAll (os, TraceContext ()); + SimulationSingleton::Get ()->GetTraceResolver ()->TraceAll (os, TraceContext ()); } Ptr NodeList::GetTraceResolver (void) diff --git a/src/node/node-list.h b/src/node/node-list.h index 02c638bbf..dc0e69d8c 100644 --- a/src/node/node-list.h +++ b/src/node/node-list.h @@ -101,7 +101,7 @@ public: * the input namespace regexp. */ static void Disconnect (std::string name, const CallbackBase &cb); - static void ConnectPrinterToAll (std::ostream &os); + static void TraceAll (std::ostream &os); static Ptr GetTraceResolver (void); private: };