merge with ns-3-dev
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 21 Sep 2007 13:59:03 +0100
changeset 1747 abbefda4216a
parent 1746 f4913893aea9 (current diff)
parent 1518 b6983560649f (diff)
child 1748 d2b5acae027d
merge with ns-3-dev
README.multicast-routing
examples/wscript
src/applications/onoff-application.cc
src/applications/onoff-application.h
src/applications/packet-sink.cc
src/applications/packet-sink.h
src/applications/waf
src/applications/wscript
src/internet-node/ipv4-l3-protocol.cc
src/internet-node/wscript
src/node/ipv4-address.cc
src/wscript
wscript
--- a/.hgtags	Thu Sep 13 15:31:55 2007 +0100
+++ b/.hgtags	Fri Sep 21 13:59:03 2007 +0100
@@ -5,3 +5,4 @@
 5701e60bf01a8ac1308945e69001e0cc07948faf release ns-3.0.4
 08046b6aef37932507696a2f2f427b42d693781e release ns-3.0.5
 267e2ebc28e4e4ae2f579e1cfc29902acade0c34 buffer-working-before-breaking
+606df29888e7573b825fc891a002f0757166b616 release ns-3.0.6
--- a/README.multicast-routing	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-Static multicast routing overview
---------------------------------
-
-This is brief documentation of a proposal to add static multicast
-routing to ns-3.
-
-This extension allows the simulation user to:
-
-- manually add Ipv4 multicast routes to a router
-- specify a default outgoing interface for multicast sources (hosts) in 
-  various ways
-- allow a multicast receiver (hosts) to join a multicast group, to enable
-  reception of that group's datagrams
-
-1.  Code location:
-
-- http://code.nsnam.org/craigdo/ns-3-mc
-
-- the main source code is found in src/internet-node/ipv4-static-routing.{cc,h}
-
-also touched are:
-- src/internet-node/ipv4-l3-protocol.cc (forwarding methods for the
-  static routing API)
-- src/node/net-device.cc (provides virtual NetDevice::MakeMulticastAddress)
-- src/arp-ipv4-interface.cc (calls NetDevice::MakeMulticastAddress)
-- src/devices/csma/csma-net-device.cc (handles multicast addressing and
-  reception).
-- src/devices/point-to-point/point-to-point-net-device.cc (implements required
-  virtual methods.
-- src/internet-node/ (several files have added tracing)
- 
-- a heavily commented example script is in examples/csma-multicast.cc
-
-2.  API:
-
-The API for adding a multicast route is:
-
-/**
- * @brief Add a multicast route to the static routing table.
- *
- * A multicast route must specify an origin IP address, a multicast group and
- * an input network interface index as conditions and provide a vector of
- * output network interface indices over which packets matching the conditions
- * are sent.
- *
- * Typically there are two main types of multicast routes:  routes of the 
- * first kind are used during forwarding.  All of the conditions must be
- * exlicitly provided.  The second kind of routes are used to get packets off
- * of a local node.  The difference is in the input interface.  Routes for
- * forwarding will always have an explicit input interface specified.  Routes
- * off of a node will always set the input interface to a wildcard specified
- * by the index Ipv4RoutingProtocol::IF_INDEX_ANY.
- *
- * For routes off of a local node wildcards may be used in the origin and
- * multicast group addresses.  The wildcard used for Ipv4Adresses is that 
- * address returned by Ipv4Address::GetAny () -- typically "0.0.0.0".  Usage
- * of a wildcard allows one to specify default behavior to varying degrees.
- *
- * For example, making the origin address a wildcard, but leaving the 
- * multicast group specific allows one (in the case of a node with multiple
- * interfaces) to create different routes using different output interfaces
- * for each multicast group.
- *
- * If the origin and multicast addresses are made wildcards, you have created
- * essentially a default multicast address that can forward to multiple 
- * interfaces.  Compare this to the actual default multicast address that is
- * limited to specifying a single output interface for compatibility with
- * existing functionality in other systems.
- * 
- * @param origin The Ipv4Address of the origin of packets for this route.  May
- * be Ipv4Address:GetAny for open groups.
- * @param group The Ipv4Address of the multicast group or this route.
- * @param inputInterface The input network interface index over which to 
- * expect packets destined for this route.  May be
- * Ipv4RoutingProtocol::IF_INDEX_ANY for packets of local origin.
- * @param outputInterface A vector of network interface indices used to specify
- * how to send packets to the destination(s).
- *
- * @see Ipv4Address
- */
-  Ipv4::AddMulticastRoute (Ipv4Address origin,
-	                   Ipv4Address group,
-                           uint32_t inputInterface,
-                           std::vector<uint32_t> outputInterfaces)
-
-To remove a route, one uses:
-
-/**
- * @brief Remove a route from the static multicast routing table.
- *
- * Externally, the multicast static routing table appears simply as a table 
- * with n entries.  The one sublety of note is that if a default multicast
- * route has been set it will appear as the zeroth entry in the table.  This
- * means that the default route may be removed by calling this method with
- * appropriate wildcard parameters.
- *
- * This method causes the multicast routing table to be searched for the first
- * route that matches the parameters and removes it.
- *
- * Wildcards may be provided to this function, but the wildcards are used to
- * exacly match wildcards in the routes (see AddMulticastRoute).  That is,
- * calling RemoveMulticastRoute with the origin set to "0.0.0.0" will not
- * remove routes with any address in the origin, but will only remove routes
- * with "0.0.0.0" set as the the origin.
- *
- * @param origin The IP address specified as the origin of packets for the
- * route.
- * @param origin The IP address specified as the multicast group addres of
- * the route.
- * @param inputInterfade The network interface index specified as the expected
- * input interface for the route.
- * @returns True if a route was found and removed, false otherwise.
- *
- * @see Ipv4MulticastRoute
- * @see Ipv4StaticRouting::AddMulticastRoute
- */
-  Ipv4::RemoveMulticastRoute (Ipv4Address origin,
-                              Ipv4Address group,
-                              uint32_t inputInterface)
-
-For symmetry with the unicast routing interface, a method is provided to 
-remove routes by index:
-
-/**
- * @brief Remove a route from the static multicast routing table.
- *
- * Externally, the multicast static routing table appears simply as a table 
- * with n entries.  The one sublety of note is that if a default multicast
- * route has been set it will appear as the zeroth entry in the table.  This 
- * means that if the default route has been set, calling 
- * RemoveMulticastRoute (0) will remove the default route.
- *
- * @param index The index (into the multicast routing table) of the route to
- * remove.  If the default route has been set, it will occupy index zero.
- *
- * @see Ipv4Route
- * @see Ipv4StaticRouting::GetRoute
- * @see Ipv4StaticRouting::AddRoute
- */
-  void RemoveMulticastRoute (uint32_t index);
-
-For compatibility, and to provide simplicity, one can set a default multicast
-route for a host originating data:
-
-/**
- * @brief Add a default multicast route to the static routing table.
- *
- * This is the multicast equivalent of the unicast version SetDefaultRoute.
- * We tell the routing system what to do in the case where a specific route
- * to a destination multicast group is not found.  The system forwards 
- * packets out the specified interface in the hope that "something out there"
- * knows better how to route the packet.  This method is only used in 
- * initially sending packets off of a host.  The default multicast route is
- * not consulted during forwarding -- exact routes must be specified using
- * AddMulticastRoute for that case.
- *
- * Since we're basically sending packets to some entity we think may know
- * better what to do, we don't pay attention to "subtleties" like origin
- * address, nor do we worry about forwarding out multiple  interfaces.  If the
- * default multicast route is set, it is returned as the selected route from 
- * LookupStatic irrespective of origin or multicast group if another specific
- * route is not found.
- *
- * @param outputInterface The network interface index used to specify where
- * to send packets in the case of unknown routes.
- *
- * @see Ipv4Address
- */
-  Ipv4::SetDefaultMulticastRoute (uint32_t outputInterface)
-
-For a host wanting to receive multicast data, the following function is used
-to join each multicast group.
-
-  /**
-   * \brief Join a multicast group for a given multicast source and 
-   *        group.
-   *
-   * \param origin The Ipv4 address of the multicast source.
-   * \param group The multicast group address.
-   */
-  Ipv4::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group);
-
-To stop receiving multicast data, the following function is used:
-
-  /**
-   * \brief Leave a multicast group for a given multicast source and 
-   *        group.
-   *
-   * \param origin The Ipv4 address of the multicast source.
-   * \param group The multicast group address.
-   */
-   LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group);
-
-There are new lookup functions implemented in Ipv4:
-
-  /**
-   * \brief Find and return the interface ID of the interface that has been
-   *        assigned the specified IP address.
-   * \param addr The IP address assigned to the interface of interest.
-   * \returns The index of the ipv4 interface with the given address.
-   *
-   * Each IP interface has an IP address associated with it.  It is often 
-   * useful to search the list of interfaces for one that corresponds to 
-   * a known IP Address.  This call takes an IP address as a parameter and
-   * returns the interface index of the first interface that has been assigned
-   * that address.  If the address is not found, this function asserts.
-   */
-  Ipv4::FindInterfaceForAddr (Ipv4Address addr) const;
-
-  /**
-   * \brief Find and return the interface ID of the interface that has been
-   *        assigned the specified (masked) IP address.
-   * \param addr The IP address assigned to the interface of interest.
-   * \param mask The address mask to be used in address matching.
-   * \returns The index of the ipv4 interface with the given address.
-   *
-   * Each IP interface has an IP address associated with it.  It is often 
-   * useful to search the list of interfaces for one that corresponds to 
-   * a known IP Address.  This call takes an IP address and an IP address
-   * mask as parameters and returns the interface index of the first interface
-   * that matches the masked IP address.
-   */
-   Ipv4::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const;
-
-Also, there are various methods to lookup and iterate the static multicast
-routes of a node, in the Ipv4StaticRouting class.
-
-3.  Dependencies:
-
-- fix for bug 69 (source Ipv4 address is set correctly for UDP)
-- fix for OnOffApplication that receives data
-
-4.  Open issues or features not included
-
-- choose source interface on a per-group basis when a host is multihomed
--- a/RELEASE_NOTES	Thu Sep 13 15:31:55 2007 +0100
+++ b/RELEASE_NOTES	Fri Sep 21 13:59:03 2007 +0100
@@ -3,6 +3,13 @@
 
 This file contains ns-3 release notes (most recent releases first).
 
+Release 3.0.6 (2007/09/15)
+========================
+  - Static multicast IPv4 routing
+  - Logging overhaul (NS_LOG macros)
+  - Refactoring of tracing subsystem
+  - Tutorial document started
+ 
 Release 3.0.5 (2007/08/15)
 ========================
 
--- a/VERSION	Thu Sep 13 15:31:55 2007 +0100
+++ b/VERSION	Fri Sep 21 13:59:03 2007 +0100
@@ -1,1 +1,1 @@
-3.0.5
+3.0.6
--- a/examples/csma-broadcast.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/csma-broadcast.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -24,8 +24,8 @@
 //       |     |       
 //     ==========
 //
-//   n0 originates UDP broadcast to 255.255.255.255, which is replicated 
-//   and received on both n1 and n2
+//   n0 originates UDP broadcast to 255.255.255.255/discard port, which 
+//   is replicated and received on both n1 and n2
 
 #include <iostream>
 #include <fstream>
@@ -36,7 +36,7 @@
 #include "ns3/default-value.h"
 #include "ns3/ptr.h"
 #include "ns3/random-variable.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
@@ -56,34 +56,40 @@
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
 #include "ns3/onoff-application.h"
-
+#include "ns3/packet-sink.h"
 
 using namespace ns3;
 
+NS_LOG_COMPONENT_DEFINE ("CsmaBroadcastExample");
 
-int main (int argc, char *argv[])
+int 
+main (int argc, char *argv[])
 {
-
   // Users may find it convenient to turn on explicit debugging
   // for selected modules; the below lines suggest how to do this
 #if 0
-  DebugComponentEnable("Object");
-  DebugComponentEnable("Queue");
-  DebugComponentEnable("DropTailQueue");
-  DebugComponentEnable("Channel");
-  DebugComponentEnable("CsmaChannel");
-  DebugComponentEnable("NetDevice");
-  DebugComponentEnable("CsmaNetDevice");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("OnOffApplication");
-  DebugComponentEnable("PacketSocket");
-  DebugComponentEnable("UdpSocket");
-  DebugComponentEnable("UdpL4Protocol");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("Ipv4StaticRouting");
-  DebugComponentEnable("Ipv4Interface");
-  DebugComponentEnable("ArpIpv4Interface");
-  DebugComponentEnable("Ipv4LoopbackInterface");
+  LogComponentEnable ("CsmaBroadcastExample", LOG_LEVEL_INFO);
+
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  // Enable the below logging command to see the packets being received
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
 #endif
 
   // Set up some default values for the simulation.  Use the Bind()
@@ -100,11 +106,13 @@
 
   // Here, we will explicitly create four nodes.  In more sophisticated
   // topologies, we could configure a node factory.
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
 
   // We create the channels first without any IP addressing information
+  NS_LOG_INFO ("Create channels.");
   Ptr<CsmaChannel> channel0 = 
     CsmaTopology::CreateCsmaChannel(
       DataRate(5000000), MilliSeconds(2));
@@ -114,6 +122,7 @@
     CsmaTopology::CreateCsmaChannel(
       DataRate(5000000), MilliSeconds(2));
 
+  NS_LOG_INFO ("Build Topology.");
   uint32_t n0ifIndex0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, channel0, 
                                          Mac48Address("10:54:23:54:0:50"));
   uint32_t n0ifIndex1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, channel1, 
@@ -124,6 +133,7 @@
                                          Mac48Address("10:54:23:54:23:52"));
 
   // Later, we add IP addresses.  
+  NS_LOG_INFO ("Assign IP Addresses.");
   CsmaIpv4Topology::AddIpv4Address (
       n0, n0ifIndex0, Ipv4Address("10.1.0.1"), Ipv4Mask("255.255.0.0"));
 
@@ -136,32 +146,43 @@
   CsmaIpv4Topology::AddIpv4Address (
       n2, n2ifIndex, Ipv4Address("192.168.1.2"), Ipv4Mask("255.255.255.0"));
 
-  // XXX Is this the right thing to do?
-  //
-  // The OnOff application uses a connected socket.  This socket needs to be
-  // able to figure out which interface to use as the source address for
-  // packets.  When there's one interface, this isn't too hard, but node zero
-  // has two interfaces, and limited broadcasts will be sent out both of those
-  // interfaces.  We need to provide some way to disambiguate the choice.
-  // If we supply a default route, the specified interface will be chosen.
-
-  Ptr<Ipv4> ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
-  ipv4->SetDefaultRoute ("192.168.1.3", n0ifIndex0);
+  // RFC 863 discard port ("9") indicates packet should be thrown away
+  // by the system.  We allow this silent discard to be overridden
+  // by the PacketSink application.
+  uint16_t port = 9;
 
   // Create the OnOff application to send UDP datagrams of size
-  // 210 bytes at a rate of 448 Kb/s
-  // from n0 to n1
+  // 512 bytes (default) at a rate of 500 Kb/s (default) from n0
+  NS_LOG_INFO ("Create Applications.");
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("255.255.255.255", 80), 
+    InetSocketAddress ("255.255.255.255", port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
   // Start the application
   ooff->Start(Seconds(1.0));
   ooff->Stop (Seconds(10.0));
+  
+  // Create an optional packet sink to receive these packets
+  Ptr<PacketSink> sink = Create<PacketSink> (
+    n1,
+    InetSocketAddress (Ipv4Address::GetAny (), port),
+    "Udp");
+  // Start the sink
+  sink->Start (Seconds (1.0));
+  sink->Stop (Seconds (10.0));
 
- 
+  // Create an optional packet sink to receive these packets
+  sink = Create<PacketSink> (
+    n2,
+    InetSocketAddress (Ipv4Address::GetAny (), port),
+    "Udp");
+  // Start the sink
+  sink->Start (Seconds (1.0));
+  sink->Stop (Seconds (10.0));
+
+  NS_LOG_INFO ("Configure Tracing.");
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   // Trace output will be sent to the csma-broadcast.tr file
   AsciiTrace asciitrace ("csma-broadcast.tr");
@@ -176,7 +197,8 @@
   PcapTrace pcaptrace ("csma-broadcast.pcap");
   pcaptrace.TraceAllIp ();
 
-  Simulator::Run ();
-    
+  NS_LOG_INFO ("Run Simulation.");
+  Simulator::Run ();    
   Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
 }
--- a/examples/csma-multicast.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/csma-multicast.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -33,7 +33,7 @@
 #include "ns3/default-value.h"
 #include "ns3/ptr.h"
 #include "ns3/random-variable.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
 #include "ns3/data-rate.h"
@@ -51,10 +51,11 @@
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
 #include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
 
 using namespace ns3;
 
-NS_DEBUG_COMPONENT_DEFINE ("CsmaMulticast");
+NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
 
 int 
 main (int argc, char *argv[])
@@ -64,27 +65,31 @@
 // for selected modules; the below lines suggest how to do this
 //
 #if 0
-  DebugComponentEnable("CsmaMulticast");
+  LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
 
-  DebugComponentEnable("Object");
-  DebugComponentEnable("Queue");
-  DebugComponentEnable("DropTailQueue");
-  DebugComponentEnable("Channel");
-  DebugComponentEnable("CsmaChannel");
-  DebugComponentEnable("NetDevice");
-  DebugComponentEnable("CsmaNetDevice");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("OnOffApplication");
-  DebugComponentEnable("PacketSocket");
-  DebugComponentEnable("UdpSocket");
-  DebugComponentEnable("UdpL4Protocol");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("Ipv4StaticRouting");
-  DebugComponentEnable("Ipv4Interface");
-  DebugComponentEnable("ArpIpv4Interface");
-  DebugComponentEnable("Ipv4LoopbackInterface");
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
 #endif
-
 //
 // Set up default values for the simulation.  Use the DefaultValue::Bind()
 // technique to tell the system what subclass of Queue to use.  The Bind
@@ -100,14 +105,14 @@
 //
 // Explicitly create the nodes required by the topology (shown above).
 //
-  NS_DEBUG("Create nodes.");
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
   Ptr<Node> n3 = Create<InternetNode> ();
   Ptr<Node> n4 = Create<InternetNode> ();
 
-  NS_DEBUG("Create channels.");
+  NS_LOG_INFO ("Create channels.");
 //
 // Explicitly create the channels required by the topology (shown above).
 //
@@ -117,7 +122,7 @@
   Ptr<CsmaChannel> lan1 = 
     CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
 
-  NS_DEBUG("Build Topology.");
+  NS_LOG_INFO ("Build Topology.");
 //
 // Now fill out the topology by creating the net devices required to connect
 // the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
@@ -143,17 +148,16 @@
   uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1, 
     Mac48Address("08:00:2e:00:00:05"));
 
-  NS_DEBUG ("nd0 = " << nd0);
-  NS_DEBUG ("nd1 = " << nd1);
-  NS_DEBUG ("nd2Lan0 = " << nd2Lan0);
-  NS_DEBUG ("nd2Lan1 = " << nd2Lan1);
-  NS_DEBUG ("nd3 = " << nd3);
-  NS_DEBUG ("nd4 = " << nd3);
+  NS_LOG_INFO ("nd0 = " << nd0);
+  NS_LOG_INFO ("nd1 = " << nd1);
+  NS_LOG_INFO ("nd2Lan0 = " << nd2Lan0);
+  NS_LOG_INFO ("nd2Lan1 = " << nd2Lan1);
+  NS_LOG_INFO ("nd3 = " << nd3);
+  NS_LOG_INFO ("nd4 = " << nd3);
 //
 // We've got the "hardware" in place.  Now we need to add IP addresses.
 //
-  NS_DEBUG("Assign IP Addresses.");
-
+  NS_LOG_INFO ("Assign IP Addresses.");
   CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address ("10.1.1.1"), 
     Ipv4Mask ("255.255.255.0"));
 
@@ -180,7 +184,7 @@
   CsmaIpv4Topology::AddIpv4Address (n4, nd4, Ipv4Address ("10.1.2.3"), 
     Ipv4Mask ("255.255.255.0"));
 
-  NS_DEBUG("Configure multicasting.");
+  NS_LOG_INFO ("Configure multicasting.");
 //
 // Now we can configure multicasting.  As described above, the multicast 
 // source is at node zero, which we assigned the IP address of 10.1.1.1 
@@ -271,10 +275,15 @@
 // Create an OnOff application to send UDP datagrams from node zero to the
 // multicast group (node four will be listening).
 //
-  NS_DEBUG("Create Applications.");
+  NS_LOG_INFO ("Create Applications.");
+
+  uint16_t port = 9;   // Discard port (RFC 863)
+
+  // Configure a multicast packet generator that generates a packet
+  // every few seconds
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress (multicastGroup, 80), 
+    InetSocketAddress (multicastGroup, port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0),
@@ -285,11 +294,23 @@
 //
   ooff->Start(Seconds(1.));
   ooff->Stop (Seconds(10.));
+
+  // Create an optional packet sink to receive these packets
+  // If you enable logging on this (above) it will print a log statement
+  // for every packet received
+  Ptr<PacketSink> sink = Create<PacketSink> (
+    n4,
+    InetSocketAddress (Ipv4Address::GetAny (), port),
+    "Udp");
+  // Start the sink
+  sink->Start (Seconds (1.0));
+  sink->Stop (Seconds (10.0));
+
 //
 // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
 // Trace output will be sent to the file "csma-multicast.tr"
 //
-  NS_DEBUG("Configure Tracing.");
+  NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("csma-multicast.tr");
   asciitrace.TraceAllNetDeviceRx ();
   asciitrace.TraceAllQueues ();
@@ -305,8 +326,8 @@
 //
 // Now, do the actual simulation.
 //
-  NS_DEBUG("Run Simulation.");
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
   Simulator::Destroy ();
-  NS_DEBUG("Done.");
+  NS_LOG_INFO ("Done.");
 }
--- a/examples/csma-one-subnet.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/csma-one-subnet.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -29,7 +29,7 @@
 #include "ns3/default-value.h"
 #include "ns3/ptr.h"
 #include "ns3/random-variable.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
 #include "ns3/data-rate.h"
@@ -50,7 +50,7 @@
 
 using namespace ns3;
 
-NS_DEBUG_COMPONENT_DEFINE ("CsmaOneSubnet");
+NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample");
 
 int 
 main (int argc, char *argv[])
@@ -60,25 +60,29 @@
 // for selected modules; the below lines suggest how to do this
 //
 #if 0 
-  DebugComponentEnable("CsmaOneSubnet");
+  LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
 
-  DebugComponentEnable("Object");
-  DebugComponentEnable("Queue");
-  DebugComponentEnable("DropTailQueue");
-  DebugComponentEnable("Channel");
-  DebugComponentEnable("CsmaChannel");
-  DebugComponentEnable("CsmaNetDevice");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("NetDevice");
-  DebugComponentEnable("PacketSocket");
-  DebugComponentEnable("OnOffApplication");
-  DebugComponentEnable("UdpSocket");
-  DebugComponentEnable("UdpL4Protocol");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("Ipv4StaticRouting");
-  DebugComponentEnable("Ipv4Interface");
-  DebugComponentEnable("ArpIpv4Interface");
-  DebugComponentEnable("Ipv4LoopbackInterface");
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
 #endif
 //
 // Set up default values for the simulation.  Use the DefaultValue::Bind()
@@ -95,20 +99,20 @@
 //
 // Explicitly create the nodes required by the topology (shown above).
 //
-  NS_DEBUG("Create nodes.");
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
   Ptr<Node> n3 = Create<InternetNode> ();
 
-  NS_DEBUG("Create channels.");
+  NS_LOG_INFO ("Create channels.");
 //
 // Explicitly create the channels required by the topology (shown above).
 //
   Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel(
     DataRate(5000000), MilliSeconds(2));
 
-  NS_DEBUG("Build Topology.");
+  NS_LOG_INFO ("Build Topology.");
 //
 // Now fill out the topology by creating the net devices required to connect
 // the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
@@ -129,15 +133,10 @@
 
   uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, 
     Mac48Address("08:00:2e:00:00:03"));
-
-  NS_DEBUG ("nd0 = " << nd0);
-  NS_DEBUG ("nd1 = " << nd1);
-  NS_DEBUG ("nd2 = " << nd2);
-  NS_DEBUG ("nd3 = " << nd3);
 //
 // We've got the "hardware" in place.  Now we need to add IP addresses.
 //
-  NS_DEBUG("Assign IP Addresses.");
+  NS_LOG_INFO ("Assign IP Addresses.");
 //
 // XXX BUGBUG
 // Need a better way to get the interface index.  The point-to-point topology
@@ -164,10 +163,11 @@
 //
 // Create an OnOff application to send UDP datagrams from node zero to node 1.
 //
-  NS_DEBUG("Create Applications.");
+  NS_LOG_INFO ("Create Applications.");
+  uint16_t port = 9;   // Discard port (RFC 863)
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("10.1.1.2", 80), 
+    InetSocketAddress ("10.1.1.2", port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -181,7 +181,7 @@
 //
   ooff = Create<OnOffApplication> (
     n3, 
-    InetSocketAddress ("10.1.1.1", 80), 
+    InetSocketAddress ("10.1.1.1", port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -192,7 +192,7 @@
 // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
 // Trace output will be sent to the file "csma-one-subnet.tr"
 //
-   NS_DEBUG("Configure Tracing.");
+   NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("csma-one-subnet.tr");
   asciitrace.TraceAllNetDeviceRx ();
   asciitrace.TraceAllQueues ();
@@ -208,8 +208,8 @@
 //
 // Now, do the actual simulation.
 //
-  NS_DEBUG("Run Simulation.");
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
   Simulator::Destroy ();
-  NS_DEBUG("Done.");
+  NS_LOG_INFO ("Done.");
 }
--- a/examples/csma-packet-socket.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/csma-packet-socket.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -37,7 +37,7 @@
 #include "ns3/default-value.h"
 #include "ns3/ptr.h"
 #include "ns3/random-variable.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
@@ -56,6 +56,8 @@
 
 using namespace ns3;
 
+NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
+
 static Ptr<CsmaNetDevice>
 CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
 {
@@ -66,28 +68,56 @@
   return device;
 }
 
+int
+main (int argc, char *argv[])
+{
+#if 0 
+  LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
 
-int main (int argc, char *argv[])
-{
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+
   CommandLine::Parse (argc, argv);
 
   // Here, we will explicitly create four nodes.  In more sophisticated
   // topologies, we could configure a node factory.
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<Node> ();
   Ptr<Node> n1 = Create<Node> (); 
   Ptr<Node> n2 = Create<Node> (); 
   Ptr<Node> n3 = Create<Node> ();
 
   // create the shared medium used by all csma devices.
+  NS_LOG_INFO ("Create channels.");
   Ptr<CsmaChannel> channel = Create<CsmaChannel> (DataRate(5000000), MilliSeconds(2));
 
   // use a helper function to connect our nodes to the shared channel.
+  NS_LOG_INFO ("Build Topology.");
   Ptr<NetDevice> n0If = CreateCsmaDevice (n0, channel);
   Ptr<NetDevice> n1If = CreateCsmaDevice (n1, channel);
   Ptr<NetDevice> n2If = CreateCsmaDevice (n2, channel);
   Ptr<NetDevice> n3If = CreateCsmaDevice (n3, channel);
 
-
   // create the address which identifies n1 from n0
   PacketSocketAddress n0ToN1;
   n0ToN1.SetSingleDevice (n0If->GetIfIndex ());      // set outgoing interface for outgoing packets
@@ -103,6 +133,7 @@
   // Create the OnOff application to send raw datagrams of size
   // 210 bytes at a rate of 448 Kb/s
   // from n0 to n1
+  NS_LOG_INFO ("Create Applications.");
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
     n0ToN1,
@@ -126,11 +157,13 @@
  
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   // Trace output will be sent to the csma-packet-socket.tr file
+  NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("csma-packet-socket.tr");
   asciitrace.TraceAllNetDeviceRx ();
   asciitrace.TraceAllQueues ();
 
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
-    
   Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
 }
--- a/examples/mixed-global-routing.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/mixed-global-routing.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -36,7 +36,7 @@
 #include <string>
 #include <cassert>
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 #include "ns3/command-line.h"
 #include "ns3/default-value.h"
@@ -68,22 +68,39 @@
 
 using namespace ns3;
 
-int main (int argc, char *argv[])
+NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample");
+
+int 
+main (int argc, char *argv[])
 {
 
   // Users may find it convenient to turn on explicit debugging
   // for selected modules; the below lines suggest how to do this
 #if 0 
-  DebugComponentEnable ("Object");
-  DebugComponentEnable ("Queue");
-  DebugComponentEnable ("DropTailQueue");
-  DebugComponentEnable ("Channel");
-  DebugComponentEnable ("PointToPointChannel");
-  DebugComponentEnable ("PointToPointNetDevice");
-  DebugComponentEnable ("GlobalRouter");
-  DebugComponentEnable ("GlobalRouteManager");
+  LogComponentEnable ("MixedGlobalRoutingExample", LOG_LEVEL_INFO);
+
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
 #endif
-
   // Set up some default values for the simulation.  Use the Bind ()
   // technique to tell the system what subclass of Queue to use,
   // and what the queue limit is
@@ -102,6 +119,7 @@
   // Bind ()s at run-time, via command-line arguments
   CommandLine::Parse (argc, argv);
 
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
@@ -111,6 +129,7 @@
   Ptr<Node> n6 = Create<InternetNode> ();
 
   // We create the channels first without any IP addressing information
+  NS_LOG_INFO ("Create channels.");
   Ptr<PointToPointChannel> channel0 = 
     PointToPointTopology::AddPointToPointLink (
       n0, n2, DataRate (5000000), MilliSeconds (2));
@@ -128,6 +147,7 @@
     CsmaTopology::CreateCsmaChannel(
       DataRate(5000000), MilliSeconds(2));
 
+  NS_LOG_INFO ("Build Topology.");
   uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, channelc0,
                                          Mac48Address("10:54:23:54:23:50"));
   uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, channelc0,
@@ -138,6 +158,7 @@
                                          Mac48Address("10:54:23:54:23:53"));
 
   // Later, we add IP addresses.  
+  NS_LOG_INFO ("Assign IP Addresses.");
   PointToPointTopology::AddIpv4Addresses (
       channel0, n0, Ipv4Address ("10.1.1.1"),
       n2, Ipv4Address ("10.1.1.2"));
@@ -168,9 +189,11 @@
 
   // Create the OnOff application to send UDP datagrams of size
   // 210 bytes at a rate of 448 Kb/s
+  NS_LOG_INFO ("Create Applications.");
+  uint16_t port = 9;   // Discard port (RFC 863)
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("10.1.3.2", 80), 
+    InetSocketAddress ("10.1.3.2", port), 
     "Udp",
     ConstantVariable (1), 
     ConstantVariable (0),
@@ -182,6 +205,7 @@
 
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   // Trace output will be sent to the simple-global-routing.tr file
+  NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("mixed-global-routing.tr");
   asciitrace.TraceAllQueues ();
   asciitrace.TraceAllNetDeviceRx ();
@@ -193,7 +217,8 @@
   PcapTrace pcaptrace ("mixed-global-routing.pcap");
   pcaptrace.TraceAllIp ();
 
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
-    
   Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
 }
--- a/examples/simple-global-routing.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/simple-global-routing.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -42,7 +42,7 @@
 #include <string>
 #include <cassert>
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 #include "ns3/command-line.h"
 #include "ns3/default-value.h"
@@ -70,25 +70,41 @@
 
 using namespace ns3;
 
-int main (int argc, char *argv[])
+NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
+
+int 
+main (int argc, char *argv[])
 {
-
   // Users may find it convenient to turn on explicit debugging
   // for selected modules; the below lines suggest how to do this
 #if 0 
-  DebugComponentEnable ("Object");
-  DebugComponentEnable ("Queue");
-  DebugComponentEnable ("DropTailQueue");
-  DebugComponentEnable ("Channel");
-  DebugComponentEnable ("PointToPointChannel");
-  DebugComponentEnable ("PointToPointNetDevice");
-  DebugComponentEnable ("GlobalRouter");
-  DebugComponentEnable ("GlobalRouteMaager");
+  LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
+
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
 #endif
-
-  // Set up some default values for the simulation.  Use the DefaultValue::Bind ()
-  // technique to tell the system what subclass of Queue to use,
-  // and what the queue limit is
+  // Set up some default values for the simulation.  Use the 
+  // DefaultValue::Bind () technique to tell the system what subclass of 
+  // Queue to use, and what the queue limit is
 
   // The below Bind command tells the queue factory which class to
   // instantiate, when the queue factory is invoked in the topology code
@@ -105,12 +121,14 @@
 
   // Here, we will explicitly create four nodes.  In more sophisticated
   // topologies, we could configure a node factory.
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
   Ptr<Node> n3 = Create<InternetNode> ();
 
   // We create the channels first without any IP addressing information
+  NS_LOG_INFO ("Create channels.");
   Ptr<PointToPointChannel> channel0 = 
     PointToPointTopology::AddPointToPointLink (
       n0, n2, DataRate (5000000), MilliSeconds (2));
@@ -124,6 +142,7 @@
       n2, n3, DataRate (1500000), MilliSeconds (10));
   
   // Later, we add IP addresses.  
+  NS_LOG_INFO ("Assign IP Addresses.");
   PointToPointTopology::AddIpv4Addresses (
       channel0, n0, Ipv4Address ("10.1.1.1"),
       n2, Ipv4Address ("10.1.1.2"));
@@ -142,9 +161,11 @@
 
   // Create the OnOff application to send UDP datagrams of size
   // 210 bytes at a rate of 448 Kb/s
+  NS_LOG_INFO ("Create Applications.");
+  uint16_t port = 9;   // Discard port (RFC 863)
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("10.1.3.2", 80), 
+    InetSocketAddress ("10.1.3.2", port), 
     "Udp",
     ConstantVariable (1), 
     ConstantVariable (0));
@@ -156,7 +177,7 @@
   // The last argument "true" disables output from the Receive callback
   Ptr<PacketSink> sink = Create<PacketSink> (
     n3, 
-    InetSocketAddress (Ipv4Address::GetAny (), 80), 
+    InetSocketAddress (Ipv4Address::GetAny (), port), 
     "Udp");
   // Start the sink
   sink->Start (Seconds (1.0));
@@ -165,7 +186,7 @@
   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   ooff = Create<OnOffApplication> (
     n3, 
-    InetSocketAddress ("10.1.2.1", 80),
+    InetSocketAddress ("10.1.2.1", port),
     "Udp",
     ConstantVariable (1), 
     ConstantVariable (0));
@@ -176,7 +197,7 @@
   // Create a packet sink to receive these packets
   sink = Create<PacketSink> (
     n1, 
-    InetSocketAddress (Ipv4Address::GetAny (), 80), 
+    InetSocketAddress (Ipv4Address::GetAny (), port), 
     "Udp");
   // Start the sink
   sink->Start (Seconds (1.1));
@@ -184,6 +205,7 @@
 
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   // Trace output will be sent to the simple-global-routing.tr file
+  NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("simple-global-routing.tr");
   asciitrace.TraceAllQueues ();
   asciitrace.TraceAllNetDeviceRx ();
@@ -195,9 +217,10 @@
   PcapTrace pcaptrace ("simple-global-routing.pcap");
   pcaptrace.TraceAllIp ();
 
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();
-    
   Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
 
   return 0;
 }
--- a/examples/simple-point-to-point.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/simple-point-to-point.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -38,7 +38,7 @@
 // - Tracing of queues and packet receptions to file 
 //   "simple-point-to-point.tr"
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/command-line.h"
 #include "ns3/default-value.h"
 #include "ns3/ptr.h"
@@ -64,34 +64,37 @@
 
 using namespace ns3;
 
-NS_DEBUG_COMPONENT_DEFINE ("SimplePointToPoint");
+NS_LOG_COMPONENT_DEFINE ("SimplePointToPointExample");
 
 int 
 main (int argc, char *argv[])
 {
-
   // Users may find it convenient to turn on explicit debugging
   // for selected modules; the below lines suggest how to do this
-  // remember to add #include "ns3/debug.h" before enabling these
 #if 0 
-  DebugComponentEnable("SimplePointToPoint");
-  DebugComponentEnable("Object");
-  DebugComponentEnable("Queue");
-  DebugComponentEnable("DropTailQueue");
-  DebugComponentEnable("Channel");
-  DebugComponentEnable("PointToPointChannel");
-  DebugComponentEnable("PointToPointNetDevice");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("NetDevice");
-  DebugComponentEnable("PacketSocket");
-  DebugComponentEnable("OnOffApplication");
-  DebugComponentEnable("UdpSocket");
-  DebugComponentEnable("UdpL4Protocol");
-  DebugComponentEnable("Ipv4L3Protocol");
-  DebugComponentEnable("Ipv4StaticRouting");
-  DebugComponentEnable("Ipv4Interface");
-  DebugComponentEnable("ArpIpv4Interface");
-  DebugComponentEnable("Ipv4LoopbackInterface");
+  LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
+
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
 #endif
 
   // Set up some default values for the simulation.  Use the Bind()
@@ -113,14 +116,14 @@
 
   // Here, we will explicitly create four nodes.  In more sophisticated
   // topologies, we could configure a node factory.
-  NS_DEBUG("Create nodes.");
+  NS_LOG_INFO ("Create nodes.");
   Ptr<Node> n0 = Create<InternetNode> ();
   Ptr<Node> n1 = Create<InternetNode> (); 
   Ptr<Node> n2 = Create<InternetNode> (); 
   Ptr<Node> n3 = Create<InternetNode> ();
 
   // We create the channels first without any IP addressing information
-  NS_DEBUG("Create channels.");
+  NS_LOG_INFO ("Create channels.");
   Ptr<PointToPointChannel> channel0 = 
     PointToPointTopology::AddPointToPointLink (
       n0, n2, DataRate(5000000), MilliSeconds(2));
@@ -134,7 +137,7 @@
       n2, n3, DataRate(1500000), MilliSeconds(10));
   
   // Later, we add IP addresses.  
-  NS_DEBUG("Assign IP Addresses.");
+  NS_LOG_INFO ("Assign IP Addresses.");
   PointToPointTopology::AddIpv4Addresses (
       channel0, n0, Ipv4Address("10.1.1.1"),
       n2, Ipv4Address("10.1.1.2"));
@@ -151,17 +154,18 @@
   // NetDevice creation, IP Address assignment, and routing) are 
   // separated because there may be a need to postpone IP Address
   // assignment (emulation) or modify to use dynamic routing
-  NS_DEBUG("Add Static Routes.");
+  NS_LOG_INFO ("Add Static Routes.");
   PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
   PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
   PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
 
   // Create the OnOff application to send UDP datagrams of size
   // 210 bytes at a rate of 448 Kb/s
-  NS_DEBUG("Create Applications.");
+  NS_LOG_INFO ("Create Applications.");
+  uint16_t port = 9;   // Discard port (RFC 863)
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("10.1.3.2", 80), 
+    InetSocketAddress ("10.1.3.2", port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -172,7 +176,7 @@
   // Create an optional packet sink to receive these packets
   Ptr<PacketSink> sink = Create<PacketSink> (
     n3,
-    InetSocketAddress (Ipv4Address::GetAny (), 80),
+    InetSocketAddress (Ipv4Address::GetAny (), port),
     "Udp");
   // Start the sink
   sink->Start (Seconds (1.0));
@@ -181,7 +185,7 @@
   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   ooff = Create<OnOffApplication> (
     n3, 
-    InetSocketAddress ("10.1.2.1", 80), 
+    InetSocketAddress ("10.1.2.1", port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
@@ -192,7 +196,7 @@
   // Create a packet sink to receive these packets
   sink = Create<PacketSink> (
     n1,
-    InetSocketAddress (Ipv4Address::GetAny (), 80),
+    InetSocketAddress (Ipv4Address::GetAny (), port),
     "Udp");
   // Start the sink
   sink->Start (Seconds (1.1));
@@ -200,7 +204,7 @@
 
   // Here, finish off packet routing configuration
   // This will likely set by some global StaticRouting object in the future
-  NS_DEBUG("Set Default Routes.");
+  NS_LOG_INFO ("Set Default Routes.");
   Ptr<Ipv4> ipv4;
   ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
   ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
@@ -209,7 +213,7 @@
   
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   // Trace output will be sent to the simple-point-to-point.tr file
-  NS_DEBUG("Configure Tracing.");
+  NS_LOG_INFO ("Configure Tracing.");
   AsciiTrace asciitrace ("simple-point-to-point.tr");
   asciitrace.TraceAllQueues ();
   asciitrace.TraceAllNetDeviceRx ();
@@ -222,8 +226,8 @@
   PcapTrace pcaptrace ("simple-point-to-point.pcap");
   pcaptrace.TraceAllIp ();
 
-  NS_DEBUG("Run Simulation.");
+  NS_LOG_INFO ("Run Simulation.");
   Simulator::Run ();    
   Simulator::Destroy ();
-  NS_DEBUG("Done.");
+  NS_LOG_INFO ("Done.");
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/udp-echo.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,213 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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
+ */
+
+// Network topology
+//
+//       n0    n1   n2   n3
+//       |     |    |    |
+//       =================
+//              LAN
+//
+// - UDP flows from n0 to n1 and back
+// - DropTail queues 
+// - Tracing of queues and packet receptions to file "udp-echo.tr"
+
+#include "ns3/command-line.h"
+#include "ns3/default-value.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/internet-node.h"
+#include "ns3/csma-channel.h"
+#include "ns3/csma-net-device.h"
+#include "ns3/csma-topology.h"
+#include "ns3/csma-ipv4-topology.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/socket.h"
+#include "ns3/ipv4-route.h"
+#include "ns3/udp-echo-client.h"
+#include "ns3/udp-echo-server.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoExample");
+
+int 
+main (int argc, char *argv[])
+{
+//
+// Users may find it convenient to turn on explicit debugging
+// for selected modules; the below lines suggest how to do this
+//
+#if 0
+  LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO);
+
+  LogComponentEnable("Object", LOG_LEVEL_ALL);
+  LogComponentEnable("Queue", LOG_LEVEL_ALL);
+  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+  LogComponentEnable("Channel", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("Socket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+//
+// Set up default values for the simulation.  Use the DefaultValue::Bind()
+// technique to tell the system what subclass of Queue to use.  The Bind
+// command command tells the queue factory which class to instantiate when the
+// queue factory is invoked in the topology code
+//
+  DefaultValue::Bind ("Queue", "DropTailQueue");
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
+  CommandLine::Parse (argc, argv);
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+  NS_LOG_INFO ("Create nodes.");
+  Ptr<Node> n0 = Create<InternetNode> ();
+  Ptr<Node> n1 = Create<InternetNode> (); 
+  Ptr<Node> n2 = Create<InternetNode> (); 
+  Ptr<Node> n3 = Create<InternetNode> ();
+
+  NS_LOG_INFO ("Create channels.");
+//
+// Explicitly create the channels required by the topology (shown above).
+//
+  Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel(
+    DataRate(5000000), MilliSeconds(2));
+
+  NS_LOG_INFO ("Build Topology.");
+//
+// Now fill out the topology by creating the net devices required to connect
+// the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
+// create a net device, add a MAC address (in memory of the pink flamingo) and
+// connect the net device to a nodes and also to a channel. the 
+// AddIpv4CsmaNetDevice method returns a net device index for the net device
+// created on the node.  Interpret nd0 as the net device we created for node
+// zero.
+//
+  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, 
+    Mac48Address("08:00:2e:00:00:00"));
+
+  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, 
+    Mac48Address("08:00:2e:00:00:01"));
+
+  uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, 
+    Mac48Address("08:00:2e:00:00:02"));
+
+  uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, 
+    Mac48Address("08:00:2e:00:00:03"));
+//
+// We've got the "hardware" in place.  Now we need to add IP addresses.
+//
+  NS_LOG_INFO ("Assign IP Addresses.");
+//
+// XXX BUGBUG
+// Need a better way to get the interface index.  The point-to-point topology
+// as implemented can't return the index since it creates interfaces on both
+// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address).  We need a
+// method on Ipv4 to find the interface index corresponding to a given ipv4 
+// address.
+//
+// Assign IP addresses to the net devices and associated interfaces
+// on the lan.  The AddIpv4Address method returns an Ipv4 interface index
+// which we do not need here.
+//
+  CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"), 
+    Ipv4Mask("255.255.255.0"));
+
+  CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"), 
+    Ipv4Mask("255.255.255.0"));
+
+  CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"), 
+    Ipv4Mask("255.255.255.0"));
+  
+  CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), 
+    Ipv4Mask("255.255.255.0"));
+
+  NS_LOG_INFO ("Create Applications.");
+//
+// Create a UdpEchoServer application on node one.
+//
+  uint16_t port = 9;  // well-known echo port number
+
+  Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
+//
+// Create a UdpEchoClient application to send UDP datagrams from node zero to
+// node one.
+//
+  uint32_t packetSize = 1024;
+  uint32_t maxPacketCount = 1;
+  Time interPacketInterval = Seconds (1.);
+
+  Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, 
+    maxPacketCount, interPacketInterval, packetSize);
+//
+// Tell the applications when to start and stop.
+//
+  server->Start(Seconds(1.));
+  client->Start(Seconds(2.));
+
+  server->Stop (Seconds(10.));
+  client->Stop (Seconds(10.));
+//
+// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+// Trace output will be sent to the file "udp-echo.tr"
+//
+  NS_LOG_INFO ("Configure Tracing.");
+  AsciiTrace asciitrace ("udp-echo.tr");
+  asciitrace.TraceAllNetDeviceRx ();
+  asciitrace.TraceAllQueues ();
+//
+// Also configure some tcpdump traces; each interface will be traced.
+// The output files will be named:
+//     udp-echo.pcap-<nodeId>-<interfaceId>
+// and can be read by the "tcpdump -r" command (use "-tt" option to
+// display timestamps correctly)
+//
+  PcapTrace pcaptrace ("udp-echo.pcap");
+  pcaptrace.TraceAllIp ();
+//
+// Now, do the actual simulation.
+//
+  NS_LOG_INFO ("Run Simulation.");
+  Simulator::Run ();
+  Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
+}
--- a/examples/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/examples/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -14,6 +14,10 @@
         ['csma', 'internet-node'])
     obj.source = 'csma-one-subnet.cc'
 
+    obj = bld.create_ns3_program('udp-echo',
+        ['csma', 'internet-node'])
+    obj.source = 'udp-echo.cc'
+
     obj = bld.create_ns3_program('csma-broadcast',
         ['csma', 'internet-node'])
     obj.source = 'csma-broadcast.cc'
--- a/samples/main-channel.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/samples/main-channel.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -18,7 +18,7 @@
  */
 
 #include <string>
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/assert.h"
 #include "ns3/packet.h"
 #include "ns3/drop-tail.h"
@@ -27,6 +27,8 @@
 
 using namespace ns3;
 
+NS_LOG_COMPONENT_DEFINE ("ChannelSample");
+
 // ===========================================================================
 // Cook up a simplistic Internet Node
 // ===========================================================================
@@ -48,19 +50,19 @@
 
 FakeInternetNode::FakeInternetNode ()
 {
-  NS_DEBUG_UNCOND("FakeInternetNode::FakeInternetNode ()");
+  NS_LOG_FUNCTION;
 }
 
 FakeInternetNode::~FakeInternetNode ()
 {
-  NS_DEBUG_UNCOND("FakeInternetNode::~FakeInternetNode ()");
+  NS_LOG_FUNCTION;
 }
 
   void
 FakeInternetNode::Doit (void)
 {
-  NS_DEBUG_UNCOND("FakeInternetNode::Doit ()");
-  NS_DEBUG_UNCOND("FakeInternetNode::Doit (): **** Send outbound packet");
+  NS_LOG_FUNCTION;
+  NS_LOG_INFO ("**** Send outbound packet");
   Packet p;
 
   m_dtqOutbound.Enqueue(p);
@@ -70,9 +72,9 @@
   bool
 FakeInternetNode::UpperDoSendUp (Packet &p)
 {
-  NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (" << &p << ")");
-
-  NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (): **** Receive inbound packet");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
+  NS_LOG_INFO ("**** Receive inbound packet");
   m_dtqInbound.Enqueue(p);
   return m_dtqInbound.Dequeue(p);
 }
@@ -80,7 +82,8 @@
   bool
 FakeInternetNode::UpperDoPull (Packet &p)
 {
-  NS_DEBUG_UNCOND("FakeInternetNode::DoPull (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   return m_dtqOutbound.Dequeue(p);
 }
@@ -107,29 +110,29 @@
 
 FakePhysicalLayer::FakePhysicalLayer ()
 {
-  NS_DEBUG_UNCOND("FakePhysicalLayer::FakePhysicalLayer ()");
+  NS_LOG_FUNCTION;
 }
 
 FakePhysicalLayer::~FakePhysicalLayer ()
 {
-  NS_DEBUG_UNCOND("FakePhysicalLayer::~FakePhysicalLayer ()");
+  NS_LOG_FUNCTION;
 }
 
   bool
 FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper)
 {
-  NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify ()");
+  NS_LOG_FUNCTION;
 
   Packet p;
 
-  NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Starting pull");
+  NS_LOG_LOGIC ("Starting pull");
 
   NS_ASSERT(m_upperPartner);
   m_upperPartner->UpperPull(p);
 
   m_dtqOutbound.Enqueue(p);
 
-  NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Got bits,  Notify lower");
+  NS_LOG_LOGIC ("Got bits,  Notify lower");
 
   NS_ASSERT(m_lowerPartner);
   return m_lowerPartner->LowerNotify(this);
@@ -138,7 +141,8 @@
   bool
 FakePhysicalLayer::UpperDoSendUp (Packet &p)
 {
-  NS_DEBUG_UNCOND("FakePhysicalLayer::UpperDoSendUp (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   NS_ASSERT(m_upperPartner);
   return m_upperPartner->UpperSendUp(p);
@@ -147,7 +151,8 @@
   bool
 FakePhysicalLayer::UpperDoPull (Packet &p)
 {
-  NS_DEBUG_UNCOND("FakePhysicalLayer::DoPull (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   return m_dtqOutbound.Dequeue(p);
 }
@@ -164,24 +169,17 @@
 
 FakeChannel::FakeChannel ()
 {
-  NS_DEBUG_UNCOND("FakeChannel::FakeChannel ()");
+  NS_LOG_FUNCTION;
 }
 
 FakeChannel::~FakeChannel ()
 {
-  NS_DEBUG_UNCOND("FakeChannel::~FakeChannel ()");
+  NS_LOG_FUNCTION;
 }
 
 int main (int argc, char *argv[])
 {
-  NS_DEBUG_UNCOND("Channel Hackorama");
-
-#if 0
-  DebugComponentEnable("Queue");
-  DebugComponentEnable("DropTailQueue");
-  DebugComponentEnable("LayerConnector");
-  DebugComponentEnable("Channel");
-#endif
+  NS_LOG_INFO ("Channel Hackorama");
 
   FakeInternetNode      node1, node2, node3, node4;
   FakePhysicalLayer     phys1, phys2, phys3, phys4;
--- a/samples/main-default-value.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/samples/main-default-value.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -3,7 +3,7 @@
 #include <string>
 #include "ns3/default-value.h"
 #include "ns3/command-line.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 using namespace ns3;
 
@@ -76,9 +76,9 @@
   DefaultValue::Bind("testInt1", "57");
 
   TestClass* testclass = new TestClass ();
-  NS_DEBUG_UNCOND("TestBool1 default value (" << testclass->m_testBool1 << ")");
-  NS_DEBUG_UNCOND("TestInt1 default value (" << testclass->m_testInt1 << ")");
-  NS_DEBUG_UNCOND("TestInt2 default value (" << testclass->m_testInt2 << ")");
+  NS_LOG_UNCOND("TestBool1 default value (" << testclass->m_testBool1 << ")");
+  NS_LOG_UNCOND("TestInt1 default value (" << testclass->m_testInt1 << ")");
+  NS_LOG_UNCOND("TestInt2 default value (" << testclass->m_testInt2 << ")");
   delete testclass;
 
   return 0;
--- a/samples/main-query-interface.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/samples/main-query-interface.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -17,7 +17,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/object.h"
 #include "ns3/component-manager.h"
 
@@ -79,10 +79,11 @@
 void
 AnInterface::methodA (void)
 {
+  NS_LOG_FUNCTION;
   // pre-dispatch asserts
-   NS_DEBUG_UNCOND("AnInterface pre-condition::methodA");
+  NS_LOG_LOGIC ("pre-condition");
   domethodA ();
-   NS_DEBUG_UNCOND("AnInterface post-condition::methodA\n");
+  NS_LOG_LOGIC ("post-condition");
   // post-dispatch asserts
 }
 
@@ -114,12 +115,13 @@
 void
 AnImplementation::methodImpl (void)
 {
-   NS_DEBUG_UNCOND("AnImplementation::methodImpl\n");
+  NS_LOG_FUNCTION;
 }
 
 
 AnImplementation::AnImplementation (void)
 {
+  NS_LOG_FUNCTION;
   // enable our interface
   SetInterfaceId (AnImplementation::iid);
 }
@@ -127,7 +129,7 @@
 void
 AnImplementation::domethodA () 
 {
-   NS_DEBUG_UNCOND("AnImplementation::domethodA");
+  NS_LOG_FUNCTION;
 }
 
 //
@@ -201,7 +203,7 @@
 void
 ANewImplementation::methodImpl (void)
 {
-   NS_DEBUG_UNCOND("ANewImplementation::methodImpl\n");
+  NS_LOG_FUNCTION;
 }
 
 const InterfaceId ANewImplementation::iid = 
@@ -238,7 +240,7 @@
 void
 AnExtendedImplementation::methodExtendedImpl (void)
 {
-   NS_DEBUG_UNCOND("AnExtendedImplementation::methodExtendedImpl\n");
+  NS_LOG_FUNCTION;
 }
 
 const InterfaceId AnExtendedImplementation::iid = 
--- a/samples/main-tw.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/samples/main-tw.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -18,14 +18,14 @@
  */
 
 #include <string>
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/trace-writer.h"
 
 using namespace ns3;
 
 int main (int argc, char *argv[])
 {
-  NS_DEBUG_UNCOND("TraceWriter Test")
+  NS_LOG_UNCOND("TraceWriter Test")
 
   TraceWriter writer1;
   writer1.Open("trace-writer-test.txt");
--- a/samples/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/samples/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -26,7 +26,7 @@
     obj.source = 'main-test.cc'
 
     obj = bld.create_ns3_program('main-simple',
-                                 ['node', 'internet-node', 'applications'])
+                                 ['node', 'internet-node', 'onoff'])
     obj.source = 'main-simple.cc'
 
     obj = bld.create_ns3_program('main-default-value',
--- a/src/applications/onoff-application.cc	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,259 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-//
-// 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: George F. Riley<riley@ece.gatech.edu>
-//
-
-// ns3 - On/Off Data Source Application class
-// George F. Riley, Georgia Tech, Spring 2007
-// Adapted from ApplicationOnOff in GTNetS.
-
-#include "ns3/debug.h"
-#include "ns3/address.h"
-#include "ns3/node.h"
-#include "ns3/nstime.h"
-#include "ns3/data-rate.h"
-#include "ns3/random-variable.h"
-#include "ns3/socket.h"
-#include "ns3/simulator.h"
-#include "ns3/socket-factory.h"
-#include "ns3/default-value.h"
-#include "ns3/packet.h"
-#include "onoff-application.h"
-
-NS_DEBUG_COMPONENT_DEFINE ("OnOffApplication");
-
-using namespace std;
-
-namespace ns3 {
-
-// Defaults for rate/size
-static DataRateDefaultValue g_defaultRate ("OnOffApplicationDataRate", 
-                                           "The data rate in on state for OnOffApplication",
-                                           DataRate ("500kb/s"));
-static NumericDefaultValue<uint32_t> g_defaultSize ("OnOffApplicationPacketSize", 
-                                                    "The size of packets sent in on state for OnOffApplication",
-                                                    512, 1);
-// Constructors
-
-OnOffApplication::OnOffApplication(Ptr<Node> n, 
-                                   const Address &remote,
-                                   std::string iid,
-                                   const  RandomVariable& ontime,
-                                   const  RandomVariable& offtime)
-  :  Application(n),
-     m_cbrRate (g_defaultRate.GetValue ())
-{
-  Construct (n, remote, iid,
-             ontime, offtime, 
-             g_defaultSize.GetValue ());
-}
-
-OnOffApplication::OnOffApplication(Ptr<Node> n, 
-                                   const Address &remote,
-                                   std::string iid,
-                                   const  RandomVariable& ontime,
-                                   const  RandomVariable& offtime,
-                                   DataRate  rate,
-                                   uint32_t size)
-  :  Application(n),
-     m_cbrRate (rate)
-{
-  Construct (n, remote, iid, 
-             ontime, offtime, size);
-}
-
-void
-OnOffApplication::Construct (Ptr<Node> n, 
-                             const Address &remote,
-                             std::string iid,
-                             const  RandomVariable& onTime,
-                             const  RandomVariable& offTime,
-                             uint32_t size)
-{
-  m_socket = 0;
-  m_peer = remote;
-  m_connected = false;
-  m_onTime = onTime.Copy ();
-  m_offTime = offTime.Copy ();
-  m_pktSize = size;
-  m_residualBits = 0;
-  m_lastStartTime = Seconds (0);
-  m_maxBytes = 0xffffffff;
-  m_totBytes = 0;
-  m_iid = iid;
-}
-
-OnOffApplication::~OnOffApplication()
-{
-  NS_DEBUG("OnOffApplication::~OnOffApplication()");
-}
-
-void 
-OnOffApplication::SetMaxBytes(uint32_t maxBytes)
-{
-  NS_DEBUG("OnOffApplication::SetMaxBytes(" << maxBytes << ")");
-  m_maxBytes = maxBytes;
-}
-
-void
-OnOffApplication::SetDefaultRate (const DataRate &rate)
-{
-  NS_DEBUG("OnOffApplication::SetDefaultRate(" << &rate << ")");
-  g_defaultRate.SetValue (rate);
-}
-
-void 
-OnOffApplication::SetDefaultSize (uint32_t size)
-{
-  NS_DEBUG("OnOffApplication::SetDefaultSize(" << size << ")");
-  g_defaultSize.SetValue (size);
-}
-
-void
-OnOffApplication::DoDispose (void)
-{
-  NS_DEBUG("OnOffApplication::DoDispose()");
-
-  m_socket = 0;
-  delete m_onTime;
-  delete m_offTime;
-
-  m_onTime = 0;
-  m_offTime = 0;
-
-  // chain up
-  Application::DoDispose ();
-}
-
-// Application Methods
-void OnOffApplication::StartApplication() // Called at time specified by Start
-{
-  NS_DEBUG("OnOffApplication::StartApplication()");
-
-  // Create the socket if not already
-  if (!m_socket)
-    {
-      InterfaceId iid = InterfaceId::LookupByName (m_iid);
-      Ptr<SocketFactory> socketFactory = GetNode ()->QueryInterface<SocketFactory> (iid);
-      m_socket = socketFactory->CreateSocket ();
-      m_socket->Bind ();
-      m_socket->Connect (m_peer);
-    }
-  // Insure no pending event
-  StopApplication();
-  // If we are not yet connected, there is nothing to do here
-  // The ConnectionComplete upcall will start timers at that time
-  //if (!m_connected) return;
-  ScheduleStartEvent();
-}
-
-void OnOffApplication::StopApplication() // Called at time specified by Stop
-{
-  NS_DEBUG("OnOffApplication::StopApplication()");
-
-  if (m_sendEvent.IsRunning ())
-    { // Cancel the pending send packet event
-      // Calculate residual bits since last packet sent
-      Time delta(Simulator::Now() - m_lastStartTime);
-      m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds());
-    }
-  Simulator::Cancel(m_sendEvent);
-  Simulator::Cancel(m_startStopEvent);
-}
-
-// Event handlers
-void OnOffApplication::StartSending()
-{
-  NS_DEBUG("OnOffApplication::StartSending ()");
-
-  ScheduleNextTx();  // Schedule the send packet event
-}
-
-void OnOffApplication::StopSending()
-{
-  NS_DEBUG("OnOffApplication::StopSending ()");
-
-  Simulator::Cancel(m_sendEvent);
-}
-
-// Private helpers
-void OnOffApplication::ScheduleNextTx()
-{
-  NS_DEBUG("OnOffApplication::ScheduleNextTx ()");
-
-  if (m_totBytes < m_maxBytes)
-    {
-      uint32_t bits = m_pktSize * 8 - m_residualBits;
-      NS_DEBUG("OnOffApplication::ScheduleNextTx (): bits = " << bits);
-      Time nextTime(Seconds (bits / 
-        static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
-      NS_DEBUG("OnOffApplication::ScheduleNextTx (): nextTime = " << nextTime);
-      m_sendEvent = Simulator::Schedule(nextTime, 
-                                        &OnOffApplication::SendPacket, this);
-    }
-  else
-    { // All done, cancel any pending events
-      StopApplication();
-    }
-}
-
-void OnOffApplication::ScheduleStartEvent()
-{  // Schedules the event to start sending data (switch to the "On" state)
-  NS_DEBUG("OnOffApplication::ScheduleStartEvent ()");
-
-  Time offInterval = Seconds(m_offTime->GetValue());
-  NS_DEBUG("OnOffApplication::ScheduleStartEvent (): "
-    "start at " << offInterval);
-  m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
-}
-
-void OnOffApplication::ScheduleStopEvent()
-{  // Schedules the event to stop sending data (switch to "Off" state)
-  NS_DEBUG("OnOffApplication::ScheduleStopEvent ()");
-
-  Time onInterval = Seconds(m_onTime->GetValue());
-  Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
-}
-
-  
-void OnOffApplication::SendPacket()
-{
-  NS_DEBUG("OnOffApplication::SendPacket ()");
-
-  NS_ASSERT (m_sendEvent.IsExpired ());
-  m_socket->Send(Packet (m_pktSize));
-  m_totBytes += m_pktSize;
-  m_lastStartTime = Simulator::Now();
-  m_residualBits = 0;
-  ScheduleNextTx();
-}
-
-void OnOffApplication::ConnectionSucceeded(Ptr<Socket>)
-{
-  NS_DEBUG("OnOffApplication::ConnectionSucceeded ()");
-
-  m_connected = true;
-  ScheduleStartEvent();
-}
-  
-void OnOffApplication::ConnectionFailed(Ptr<Socket>)
-{
-  cout << "OnOffApplication, Connection Failed" << endl;
-}
-
-} // Namespace ns3
--- a/src/applications/onoff-application.h	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-//
-// 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: George F. Riley<riley@ece.gatech.edu>
-//
-
-// ns3 - On/Off Data Source Application class
-// George F. Riley, Georgia Tech, Spring 2007
-// Adapted from ApplicationOnOff in GTNetS.
-
-#ifndef __onoff_application_h__
-#define __onoff_application_h__
-
-#include "ns3/application.h"
-#include "ns3/event-id.h"
-#include "ns3/ptr.h"
-#include "ns3/data-rate.h"
-
-namespace ns3 {
-
-class Address;
-class RandomVariable;
-class Socket;
-
-/**
- * \brief Generate traffic to a single destination according to an
- *        OnOff pattern.
- *
- * This traffic follows an On/Off pattern: after Application::StartApplication
- * is called, "On" and "Off" states alternate. The duration of each of
- * these states is determined with the onTime and the offTime random
- * variables. During the "Off" state, no traffic is generated.
- * During the "On" state, cbr traffic is generated. This cbr traffic is
- * characterized by the specified "data rate" and "packet size".
- */
-class OnOffApplication : public Application 
-{
-public:
-  /**
-   * \param n node associated to this application
-   * \param remote remote ip address
-   * \param iid
-   * \param ontime on time random variable
-   * \param offtime off time random variable
-   */
-  OnOffApplication(Ptr<Node> n,
-                   const Address &remote,
-                   std::string iid,
-                   const RandomVariable& ontime,
-                   const RandomVariable& offtime);
-
-  /**
-   * \param n node associated to this application
-   * \param remote remote ip address
-   * \param iid
-   * \param ontime on time random variable
-   * \param offtime off time random variable
-   * \param rate data rate when on
-   * \param size size of packets when sending data.
-   */
-  OnOffApplication(Ptr<Node> n,
-                   const Address &remote,
-                   std::string iid,
-                   const RandomVariable& ontime,
-                   const RandomVariable& offtime,
-                   DataRate  rate,
-                   uint32_t size);
-
-  virtual ~OnOffApplication();
-
-  void SetMaxBytes(uint32_t maxBytes);
-
-  /**
-   * \param r the data rate
-   *
-   * Set the data rate to use for every OnOffApplication for which
-   * the user does not specify an explicit data rate.
-   */
-  static void SetDefaultRate(const DataRate & r);
-
-  /**
-   * \param size the packet size
-   *
-   * Set the packet size to use for every OnOffApplication for
-   * which the user does not specify an explicit packet size.
-   */
-  static void SetDefaultSize (uint32_t size);
-
-protected:
-  virtual void DoDispose (void);
-private:
-  // inherited from Application base class.
-  virtual void StartApplication (void);    // Called at time specified by Start
-  virtual void StopApplication (void);     // Called at time specified by Stop
-
-  void Construct (Ptr<Node> n,
-                  const Address &remote,
-                  std::string iid,
-                  const RandomVariable& ontime,
-                  const RandomVariable& offtime,
-                  uint32_t size);
-
-
-  // Event handlers
-  void StartSending();
-  void StopSending();
-  void SendPacket();
-
-  Ptr<Socket>     m_socket;       // Associated socket
-  Address         m_peer;         // Peer address
-  bool            m_connected;    // True if connected
-  RandomVariable* m_onTime;       // rng for On Time
-  RandomVariable* m_offTime;      // rng for Off Time
-  DataRate        m_cbrRate;      // Rate that data is generated
-  uint32_t        m_pktSize;      // Size of packets
-  uint32_t        m_residualBits; // Number of generated, but not sent, bits
-  Time            m_lastStartTime;// Time last packet sent
-  uint32_t        m_maxBytes;     // Limit total number of bytes sent
-  uint32_t        m_totBytes;     // Total bytes sent so far
-  EventId         m_startStopEvent;     // Event id for next start or stop event
-  EventId         m_sendEvent;    // Eventid of pending "send packet" event
-  bool            m_sending;      // True if currently in sending state
-  std::string     m_iid;
-  
-private:
-  void ScheduleNextTx();
-  void ScheduleStartEvent();
-  void ScheduleStopEvent();
-  void ConnectionSucceeded(Ptr<Socket>);
-  void ConnectionFailed(Ptr<Socket>);
-  void Ignore(Ptr<Socket>);
-};
-
-} // namespace ns3
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff/onoff-application.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,264 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+//
+// 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: George F. Riley<riley@ece.gatech.edu>
+//
+
+// ns3 - On/Off Data Source Application class
+// George F. Riley, Georgia Tech, Spring 2007
+// Adapted from ApplicationOnOff in GTNetS.
+
+#include "ns3/log.h"
+#include "ns3/address.h"
+#include "ns3/node.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+#include "ns3/random-variable.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/default-value.h"
+#include "ns3/packet.h"
+#include "onoff-application.h"
+
+NS_LOG_COMPONENT_DEFINE ("OnOffApplication");
+
+using namespace std;
+
+namespace ns3 {
+
+// Defaults for rate/size
+static DataRateDefaultValue g_defaultRate ("OnOffApplicationDataRate", 
+                                           "The data rate in on state for OnOffApplication",
+                                           DataRate ("500kb/s"));
+static NumericDefaultValue<uint32_t> g_defaultSize ("OnOffApplicationPacketSize", 
+                                                    "The size of packets sent in on state for OnOffApplication",
+                                                    512, 1);
+// Constructors
+
+OnOffApplication::OnOffApplication(Ptr<Node> n, 
+                                   const Address &remote,
+                                   std::string iid,
+                                   const  RandomVariable& ontime,
+                                   const  RandomVariable& offtime)
+  :  Application(n),
+     m_cbrRate (g_defaultRate.GetValue ())
+{
+  Construct (n, remote, iid,
+             ontime, offtime, 
+             g_defaultSize.GetValue ());
+}
+
+OnOffApplication::OnOffApplication(Ptr<Node> n, 
+                                   const Address &remote,
+                                   std::string iid,
+                                   const  RandomVariable& ontime,
+                                   const  RandomVariable& offtime,
+                                   DataRate  rate,
+                                   uint32_t size)
+  :  Application(n),
+     m_cbrRate (rate)
+{
+  NS_LOG_FUNCTION;
+  Construct (n, remote, iid, ontime, offtime, size);
+}
+
+void
+OnOffApplication::Construct (Ptr<Node> n, 
+                             const Address &remote,
+                             std::string iid,
+                             const  RandomVariable& onTime,
+                             const  RandomVariable& offTime,
+                             uint32_t size)
+{
+  NS_LOG_FUNCTION;
+
+  m_socket = 0;
+  m_peer = remote;
+  m_connected = false;
+  m_onTime = onTime.Copy ();
+  m_offTime = offTime.Copy ();
+  m_pktSize = size;
+  m_residualBits = 0;
+  m_lastStartTime = Seconds (0);
+  m_maxBytes = 0xffffffff;
+  m_totBytes = 0;
+  m_iid = iid;
+}
+
+OnOffApplication::~OnOffApplication()
+{
+  NS_LOG_FUNCTION;
+}
+
+void 
+OnOffApplication::SetMaxBytes(uint32_t maxBytes)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << maxBytes << ")");
+  m_maxBytes = maxBytes;
+}
+
+void
+OnOffApplication::SetDefaultRate (const DataRate &rate)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &rate << ")");
+  g_defaultRate.SetValue (rate);
+}
+
+void 
+OnOffApplication::SetDefaultSize (uint32_t size)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << size << ")");
+  g_defaultSize.SetValue (size);
+}
+
+void
+OnOffApplication::DoDispose (void)
+{
+  NS_LOG_FUNCTION;
+
+  m_socket = 0;
+  delete m_onTime;
+  delete m_offTime;
+
+  m_onTime = 0;
+  m_offTime = 0;
+
+  // chain up
+  Application::DoDispose ();
+}
+
+// Application Methods
+void OnOffApplication::StartApplication() // Called at time specified by Start
+{
+  NS_LOG_FUNCTION;
+
+  // Create the socket if not already
+  if (!m_socket)
+    {
+      InterfaceId iid = InterfaceId::LookupByName (m_iid);
+      Ptr<SocketFactory> socketFactory = GetNode ()->QueryInterface<SocketFactory> (iid);
+      m_socket = socketFactory->CreateSocket ();
+      m_socket->Bind ();
+      m_socket->Connect (m_peer);
+    }
+  // Insure no pending event
+  StopApplication();
+  // If we are not yet connected, there is nothing to do here
+  // The ConnectionComplete upcall will start timers at that time
+  //if (!m_connected) return;
+  ScheduleStartEvent();
+}
+
+void OnOffApplication::StopApplication() // Called at time specified by Stop
+{
+  NS_LOG_FUNCTION;
+
+  if (m_sendEvent.IsRunning ())
+    { // Cancel the pending send packet event
+      // Calculate residual bits since last packet sent
+      Time delta(Simulator::Now() - m_lastStartTime);
+      m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds());
+    }
+  Simulator::Cancel(m_sendEvent);
+  Simulator::Cancel(m_startStopEvent);
+}
+
+// Event handlers
+void OnOffApplication::StartSending()
+{
+  NS_LOG_FUNCTION;
+
+  ScheduleNextTx();  // Schedule the send packet event
+}
+
+void OnOffApplication::StopSending()
+{
+  NS_LOG_FUNCTION;
+
+  Simulator::Cancel(m_sendEvent);
+}
+
+// Private helpers
+void OnOffApplication::ScheduleNextTx()
+{
+  NS_LOG_FUNCTION;
+
+  if (m_totBytes < m_maxBytes)
+    {
+      uint32_t bits = m_pktSize * 8 - m_residualBits;
+      NS_LOG_LOGIC ("bits = " << bits);
+      Time nextTime(Seconds (bits / 
+        static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
+      NS_LOG_LOGIC ("nextTime = " << nextTime);
+      m_sendEvent = Simulator::Schedule(nextTime, 
+                                        &OnOffApplication::SendPacket, this);
+    }
+  else
+    { // All done, cancel any pending events
+      StopApplication();
+    }
+}
+
+void OnOffApplication::ScheduleStartEvent()
+{  // Schedules the event to start sending data (switch to the "On" state)
+  NS_LOG_FUNCTION;
+
+  Time offInterval = Seconds(m_offTime->GetValue());
+  NS_LOG_LOGIC ("start at " << offInterval);
+  m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
+}
+
+void OnOffApplication::ScheduleStopEvent()
+{  // Schedules the event to stop sending data (switch to "Off" state)
+  NS_LOG_FUNCTION;
+
+  Time onInterval = Seconds(m_onTime->GetValue());
+  Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
+}
+
+  
+void OnOffApplication::SendPacket()
+{
+  NS_LOG_FUNCTION;
+
+  NS_ASSERT (m_sendEvent.IsExpired ());
+  m_socket->Send(Packet (m_pktSize));
+  m_totBytes += m_pktSize;
+  m_lastStartTime = Simulator::Now();
+  m_residualBits = 0;
+  ScheduleNextTx();
+}
+
+void OnOffApplication::ConnectionSucceeded(Ptr<Socket>)
+{
+  NS_LOG_FUNCTION;
+
+  m_connected = true;
+  ScheduleStartEvent();
+}
+  
+void OnOffApplication::ConnectionFailed(Ptr<Socket>)
+{
+  NS_LOG_FUNCTION;
+  cout << "OnOffApplication, Connection Failed" << endl;
+}
+
+} // Namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff/onoff-application.h	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,151 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+//
+// 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: George F. Riley<riley@ece.gatech.edu>
+//
+
+// ns3 - On/Off Data Source Application class
+// George F. Riley, Georgia Tech, Spring 2007
+// Adapted from ApplicationOnOff in GTNetS.
+
+#ifndef __onoff_application_h__
+#define __onoff_application_h__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+#include "ns3/data-rate.h"
+
+namespace ns3 {
+
+class Address;
+class RandomVariable;
+class Socket;
+
+/**
+ * \brief Generate traffic to a single destination according to an
+ *        OnOff pattern.
+ *
+ * This traffic follows an On/Off pattern: after Application::StartApplication
+ * is called, "On" and "Off" states alternate. The duration of each of
+ * these states is determined with the onTime and the offTime random
+ * variables. During the "Off" state, no traffic is generated.
+ * During the "On" state, cbr traffic is generated. This cbr traffic is
+ * characterized by the specified "data rate" and "packet size".
+ */
+class OnOffApplication : public Application 
+{
+public:
+  /**
+   * \param n node associated to this application
+   * \param remote remote ip address
+   * \param iid
+   * \param ontime on time random variable
+   * \param offtime off time random variable
+   */
+  OnOffApplication(Ptr<Node> n,
+                   const Address &remote,
+                   std::string iid,
+                   const RandomVariable& ontime,
+                   const RandomVariable& offtime);
+
+  /**
+   * \param n node associated to this application
+   * \param remote remote ip address
+   * \param iid
+   * \param ontime on time random variable
+   * \param offtime off time random variable
+   * \param rate data rate when on
+   * \param size size of packets when sending data.
+   */
+  OnOffApplication(Ptr<Node> n,
+                   const Address &remote,
+                   std::string iid,
+                   const RandomVariable& ontime,
+                   const RandomVariable& offtime,
+                   DataRate  rate,
+                   uint32_t size);
+
+  virtual ~OnOffApplication();
+
+  void SetMaxBytes(uint32_t maxBytes);
+
+  /**
+   * \param r the data rate
+   *
+   * Set the data rate to use for every OnOffApplication for which
+   * the user does not specify an explicit data rate.
+   */
+  static void SetDefaultRate(const DataRate & r);
+
+  /**
+   * \param size the packet size
+   *
+   * Set the packet size to use for every OnOffApplication for
+   * which the user does not specify an explicit packet size.
+   */
+  static void SetDefaultSize (uint32_t size);
+
+protected:
+  virtual void DoDispose (void);
+private:
+  // inherited from Application base class.
+  virtual void StartApplication (void);    // Called at time specified by Start
+  virtual void StopApplication (void);     // Called at time specified by Stop
+
+  void Construct (Ptr<Node> n,
+                  const Address &remote,
+                  std::string iid,
+                  const RandomVariable& ontime,
+                  const RandomVariable& offtime,
+                  uint32_t size);
+
+
+  // Event handlers
+  void StartSending();
+  void StopSending();
+  void SendPacket();
+
+  Ptr<Socket>     m_socket;       // Associated socket
+  Address         m_peer;         // Peer address
+  bool            m_connected;    // True if connected
+  RandomVariable* m_onTime;       // rng for On Time
+  RandomVariable* m_offTime;      // rng for Off Time
+  DataRate        m_cbrRate;      // Rate that data is generated
+  uint32_t        m_pktSize;      // Size of packets
+  uint32_t        m_residualBits; // Number of generated, but not sent, bits
+  Time            m_lastStartTime;// Time last packet sent
+  uint32_t        m_maxBytes;     // Limit total number of bytes sent
+  uint32_t        m_totBytes;     // Total bytes sent so far
+  EventId         m_startStopEvent;     // Event id for next start or stop event
+  EventId         m_sendEvent;    // Eventid of pending "send packet" event
+  bool            m_sending;      // True if currently in sending state
+  std::string     m_iid;
+  
+private:
+  void ScheduleNextTx();
+  void ScheduleStartEvent();
+  void ScheduleStopEvent();
+  void ConnectionSucceeded(Ptr<Socket>);
+  void ConnectionFailed(Ptr<Socket>);
+  void Ignore(Ptr<Socket>);
+};
+
+} // namespace ns3
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff/waf	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,12 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    module = bld.create_ns3_module('onoff', ['core'])
+    module.source = [
+        'onoff-application.cc',
+        ]
+    headers = bld.create_obj('ns3header')
+    headers.source = [
+        'onoff-application.h',
+        ]
+
--- a/src/applications/packet-sink.cc	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright 2007 University of Washington
- * 
- * 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:  Tom Henderson (tomhend@u.washington.edu)
- */
-#include "ns3/address.h"
-#include "ns3/debug.h"
-#include "ns3/inet-socket-address.h"
-#include "ns3/node.h"
-#include "ns3/socket.h"
-#include "ns3/simulator.h"
-#include "ns3/socket-factory.h"
-#include "ns3/packet.h"
-#include "packet-sink.h"
-
-using namespace std;
-
-namespace ns3 {
-
-NS_DEBUG_COMPONENT_DEFINE ("PacketSink");
-
-// Constructors
-
-PacketSink::PacketSink (Ptr<Node> n, 
-                        const Address &local,
-                        std::string iid)
-  :  Application(n)
-{
-  Construct (n, local, iid);
-}
-
-void
-PacketSink::Construct (Ptr<Node> n, 
-                       const Address &local,
-                       std::string iid)
-{
-  m_socket = 0;
-  m_local = local;
-  m_iid = iid;
-}
-
-PacketSink::~PacketSink()
-{}
-
-void
-PacketSink::DoDispose (void)
-{
-  m_socket = 0;
-
-  // chain up
-  Application::DoDispose ();
-}
-
-
-// Application Methods
-void PacketSink::StartApplication()    // Called at time specified by Start
-{
-  // Create the socket if not already
-  if (!m_socket)
-    {
-      InterfaceId iid = InterfaceId::LookupByName (m_iid);
-      Ptr<SocketFactory> socketFactory = 
-        GetNode ()->QueryInterface<SocketFactory> (iid);
-      m_socket = socketFactory->CreateSocket ();
-      m_socket->Bind (m_local);
-    }
-  m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
-    const Address &>) MakeCallback(&PacketSink::Receive, this));
-}
-
-void PacketSink::StopApplication()     // Called at time specified by Stop
-{
-  if (!m_socket) 
-    {
-      m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
-                               const Address &>) NULL);
- 
-    }
-}
-
-// This LOG output inspired by the application on Joseph Kopena's wiki
-void PacketSink::Receive(Ptr<Socket> socket, const Packet &packet,
-                       const Address &from) 
-{
-  if (InetSocketAddress::IsMatchingType (from))
-    {
-      InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
-      NS_DEBUG ( __PRETTY_FUNCTION__ << ": Received " << 
-        packet.GetSize() << " bytes from " << address.GetIpv4() << " [" 
-        << address << "]---'" << packet.PeekData() << "'");
-      // TODO:  Add a tracing source here
-    }
-}
-
-} // Namespace ns3
--- a/src/applications/packet-sink.h	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright 2007 University of Washington
- * 
- * 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:  Tom Henderson (tomhend@u.washington.edu)
- */
-
-#ifndef __packet_sink_h__
-#define __packet_sink_h__
-
-#include "ns3/application.h"
-#include "ns3/event-id.h"
-#include "ns3/ptr.h"
-
-namespace ns3 {
-
-class Address;
-class Socket;
-class Packet;
-
-/**
- * \brief Receive and consume traffic generated to an IP address and port
- *
- * This application was written to complement OnOffApplication, but it
- * is more general so a PacketSink name was selected.  Functionally it is
- * important to use in multicast situations, so that reception of the layer-2
- * multicast frames of interest are enabled, but it is also useful for
- * unicast as an example of how you can write something simple to receive
- * packets at the application layer.  Also, if an IP stack generates 
- * ICMP Port Unreachable errors, receiving applications will be needed.
- *
- * The constructor specifies the Address (IP address and port) and the 
- * transport protocol to use.   A virtual Receive () method is installed 
- * as a callback on the receiving socket.  By default, when logging is
- * enabled, it prints out the size of packets and their address, but
- * we intend to also add a tracing source to Receive() at a later date.
- */
-class PacketSink : public Application 
-{
-public:
-  /**
-   * \param n node associated to this application
-   * \param local local address to bind to
-   * \param iid string to identify transport protocol of interest
-   */
-  PacketSink (Ptr<Node> n,
-              const Address &local,
-              std::string iid);
-
-  virtual ~PacketSink ();
-
-protected:
-  virtual void DoDispose (void);
-private:
-  // inherited from Application base class.
-  virtual void StartApplication (void);    // Called at time specified by Start
-  virtual void StopApplication (void);     // Called at time specified by Stop
-
-  void Construct (Ptr<Node> n,
-                  const Address &local,
-                  std::string iid);
-
-  virtual void Receive (Ptr<Socket> socket, const Packet& packet, const Address& from);
-
-  Ptr<Socket>     m_socket;       // Associated socket
-  Address         m_local;        // Local address to bind to
-  std::string     m_iid;          // Protocol name (e.g., "Udp")
-  
-};
-
-} // namespace ns3
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/packet-sink/packet-sink.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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:  Tom Henderson (tomhend@u.washington.edu)
+ */
+#include "ns3/address.h"
+#include "ns3/log.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/node.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "packet-sink.h"
+
+using namespace std;
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication");
+
+// Constructors
+
+PacketSink::PacketSink (Ptr<Node> n, 
+                        const Address &local,
+                        std::string iid)
+  :  Application(n)
+{
+  Construct (n, local, iid);
+}
+
+void
+PacketSink::Construct (Ptr<Node> n, 
+                       const Address &local,
+                       std::string iid)
+{
+  m_socket = 0;
+  m_local = local;
+  m_iid = iid;
+}
+
+PacketSink::~PacketSink()
+{}
+
+void
+PacketSink::DoDispose (void)
+{
+  m_socket = 0;
+
+  // chain up
+  Application::DoDispose ();
+}
+
+
+// Application Methods
+void PacketSink::StartApplication()    // Called at time specified by Start
+{
+  // Create the socket if not already
+  if (!m_socket)
+    {
+      InterfaceId iid = InterfaceId::LookupByName (m_iid);
+      Ptr<SocketFactory> socketFactory = 
+        GetNode ()->QueryInterface<SocketFactory> (iid);
+      m_socket = socketFactory->CreateSocket ();
+      m_socket->Bind (m_local);
+    }
+  m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+    const Address &>) MakeCallback(&PacketSink::Receive, this));
+}
+
+void PacketSink::StopApplication()     // Called at time specified by Stop
+{
+  if (!m_socket) 
+    {
+      m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+                               const Address &>) NULL);
+ 
+    }
+}
+
+// This LOG output inspired by the application on Joseph Kopena's wiki
+void PacketSink::Receive(Ptr<Socket> socket, const Packet &packet,
+                       const Address &from) 
+{
+  if (InetSocketAddress::IsMatchingType (from))
+    {
+      InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+      NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << 
+        address.GetIpv4() << " [" << address << "]---'" << 
+        packet.PeekData() << "'");
+      // TODO:  Add a tracing source here
+    }
+}
+
+} // Namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/packet-sink/packet-sink.h	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,87 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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:  Tom Henderson (tomhend@u.washington.edu)
+ */
+
+#ifndef __packet_sink_h__
+#define __packet_sink_h__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+/**
+ * \brief Receive and consume traffic generated to an IP address and port
+ *
+ * This application was written to complement OnOffApplication, but it
+ * is more general so a PacketSink name was selected.  Functionally it is
+ * important to use in multicast situations, so that reception of the layer-2
+ * multicast frames of interest are enabled, but it is also useful for
+ * unicast as an example of how you can write something simple to receive
+ * packets at the application layer.  Also, if an IP stack generates 
+ * ICMP Port Unreachable errors, receiving applications will be needed.
+ *
+ * The constructor specifies the Address (IP address and port) and the 
+ * transport protocol to use.   A virtual Receive () method is installed 
+ * as a callback on the receiving socket.  By default, when logging is
+ * enabled, it prints out the size of packets and their address, but
+ * we intend to also add a tracing source to Receive() at a later date.
+ */
+class PacketSink : public Application 
+{
+public:
+  /**
+   * \param n node associated to this application
+   * \param local local address to bind to
+   * \param iid string to identify transport protocol of interest
+   */
+  PacketSink (Ptr<Node> n,
+              const Address &local,
+              std::string iid);
+
+  virtual ~PacketSink ();
+
+protected:
+  virtual void DoDispose (void);
+private:
+  // inherited from Application base class.
+  virtual void StartApplication (void);    // Called at time specified by Start
+  virtual void StopApplication (void);     // Called at time specified by Stop
+
+  void Construct (Ptr<Node> n,
+                  const Address &local,
+                  std::string iid);
+
+  virtual void Receive (Ptr<Socket> socket, const Packet& packet, const Address& from);
+
+  Ptr<Socket>     m_socket;       // Associated socket
+  Address         m_local;        // Local address to bind to
+  std::string     m_iid;          // Protocol name (e.g., "Udp")
+  
+};
+
+} // namespace ns3
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/packet-sink/waf	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/packet-sink/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,12 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    module = bld.create_ns3_module('packet-sink', ['node'])
+    module.source = [
+        'packet-sink.cc',
+        ]
+    headers = bld.create_obj('ns3header')
+    headers.source = [
+        'packet-sink.h',
+        ]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/udp-echo-client.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,168 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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
+ */
+#include "ns3/log.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/nstime.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "udp-echo-client.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoClientApplication");
+
+UdpEchoClient::UdpEchoClient (
+  Ptr<Node> n,
+  Ipv4Address serverAddress,
+  uint16_t serverPort,
+  uint32_t count,
+  Time interval,
+  uint32_t size)
+: 
+  Application(n)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
+    ", " << serverPort << ", " << count << ", " << interval <<
+    ", " << size << ")");
+
+  Construct (n, serverAddress, serverPort, count, interval, size);
+}
+
+UdpEchoClient::~UdpEchoClient()
+{
+  NS_LOG_FUNCTION;
+}
+
+void
+UdpEchoClient::Construct (
+  Ptr<Node> n,
+  Ipv4Address serverAddress,
+  uint16_t serverPort,
+  uint32_t count,
+  Time interval,
+  uint32_t size)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
+    ", " << serverPort << ", " << count << ", " << interval <<
+    ", " << size << ")");
+
+  m_node = n;
+  m_serverAddress = serverAddress;
+  m_serverPort = serverPort;
+  m_count = count;
+  m_interval = interval;
+  m_size = size;
+
+  m_sent = 0;
+  m_socket = 0;
+  m_peer = InetSocketAddress (serverAddress, serverPort);
+  m_sendEvent = EventId ();
+}
+
+void
+UdpEchoClient::DoDispose (void)
+{
+  NS_LOG_FUNCTION;
+  Application::DoDispose ();
+}
+
+void 
+UdpEchoClient::StartApplication (void)
+{
+  NS_LOG_FUNCTION;
+
+  if (!m_socket)
+    {
+      InterfaceId iid = InterfaceId::LookupByName ("Udp");
+      Ptr<SocketFactory> socketFactory = 
+        GetNode ()->QueryInterface<SocketFactory> (iid);
+      m_socket = socketFactory->CreateSocket ();
+      m_socket->Bind ();
+      m_socket->Connect (m_peer);
+    }
+
+  m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+    const Address &>) MakeCallback(&UdpEchoClient::Receive, this));
+
+  ScheduleTransmit (Seconds(0.));
+}
+
+void 
+UdpEchoClient::StopApplication ()
+{
+  NS_LOG_FUNCTION;
+
+  if (!m_socket) 
+    {
+      m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+        const Address &>) NULL);
+    }
+
+  Simulator::Cancel(m_sendEvent);
+}
+
+void 
+UdpEchoClient::ScheduleTransmit (Time dt)
+{
+  NS_LOG_FUNCTION;
+  m_sendEvent = Simulator::Schedule(dt, &UdpEchoClient::Send, this);
+}
+
+void 
+UdpEchoClient::Send (void)
+{
+  NS_LOG_FUNCTION;
+
+  NS_ASSERT (m_sendEvent.IsExpired ());
+
+  Packet p (m_size);
+  m_socket->Send (p);
+  ++m_sent;
+
+  NS_LOG_INFO ("Sent " << m_size << " bytes to " << m_serverAddress);
+
+  if (m_sent < m_count) 
+    {
+      ScheduleTransmit (m_interval);
+    }
+}
+
+void
+UdpEchoClient::Receive(
+  Ptr<Socket> socket, 
+  const Packet &packet,
+  const Address &from) 
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
+
+  if (InetSocketAddress::IsMatchingType (from))
+    {
+      InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+      NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << 
+        address.GetIpv4());
+    }
+}
+
+
+} // Namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/udp-echo-client.h	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,72 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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
+ */
+
+#ifndef __UDP_ECHO_CLIENT_H__
+#define __UDP_ECHO_CLIENT_H__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+class UdpEchoClient : public Application 
+{
+public:
+  UdpEchoClient (Ptr<Node> n, Ipv4Address serverAddr, uint16_t serverPort,
+    uint32_t count, Time interval, uint32_t size);
+
+  virtual ~UdpEchoClient ();
+
+protected:
+  virtual void DoDispose (void);
+
+private:
+  void Construct (Ptr<Node> n, Ipv4Address serverAddr, uint16_t serverPort,
+    uint32_t count, Time interval, uint32_t size);
+
+  virtual void StartApplication (void);
+  virtual void StopApplication (void);
+
+  void ScheduleTransmit (Time dt);
+  void Send (void);
+
+  void Receive(Ptr<Socket> socket, const Packet &packet, const Address &from);
+
+  Ptr<Node> m_node;
+  Ipv4Address m_serverAddress;
+  uint16_t m_serverPort;
+  uint32_t m_count;
+  Time m_interval;
+  uint32_t m_size;
+
+  uint32_t m_sent;
+  Ptr<Socket> m_socket;
+  Address m_peer;
+  EventId m_sendEvent;
+
+};
+
+} // namespace ns3
+
+#endif // __UDP_ECHO_CLIENT_H__
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/udp-echo-server.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,123 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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
+ */
+
+#include "ns3/log.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/nstime.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+
+#include "udp-echo-server.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoServerApplication");
+
+UdpEchoServer::UdpEchoServer (
+  Ptr<Node> n,
+  uint16_t port)
+: 
+  Application(n)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << n << ", " << port << ")");
+
+  Construct (n, port);
+}
+
+UdpEchoServer::~UdpEchoServer()
+{
+  NS_LOG_FUNCTION;
+}
+
+void
+UdpEchoServer::Construct (
+  Ptr<Node> n,
+  uint16_t port)
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << n << ", " << port << ")");
+
+  m_node = n;
+  m_port = port;
+
+  m_socket = 0;
+  m_local = InetSocketAddress (Ipv4Address::GetAny (), port);
+}
+
+void
+UdpEchoServer::DoDispose (void)
+{
+  NS_LOG_FUNCTION;
+  Application::DoDispose ();
+}
+
+void 
+UdpEchoServer::StartApplication (void)
+{
+  NS_LOG_FUNCTION;
+
+  if (!m_socket)
+    {
+      InterfaceId iid = InterfaceId::LookupByName ("Udp");
+      Ptr<SocketFactory> socketFactory = 
+        GetNode ()->QueryInterface<SocketFactory> (iid);
+      m_socket = socketFactory->CreateSocket ();
+      m_socket->Bind (m_local);
+    }
+
+  m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+    const Address &>) MakeCallback(&UdpEchoServer::Receive, this));
+}
+
+void 
+UdpEchoServer::StopApplication ()
+{
+  NS_LOG_FUNCTION;
+
+  if (!m_socket) 
+    {
+      m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
+        const Address &>) NULL);
+    }
+}
+
+void
+UdpEchoServer::Receive(
+  Ptr<Socket> socket, 
+  const Packet &packet,
+  const Address &from) 
+{
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
+
+  if (InetSocketAddress::IsMatchingType (from))
+    {
+      InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+      NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << 
+        address.GetIpv4());
+
+      NS_LOG_LOGIC ("Echoing packet");
+      socket->SendTo (from, packet);
+    }
+}
+
+} // Namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/udp-echo-server.h	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,59 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ * 
+ * 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
+ */
+
+#ifndef __UDP_ECHO_SERVER_H__
+#define __UDP_ECHO_SERVER_H__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+class UdpEchoServer : public Application 
+{
+public:
+  UdpEchoServer (Ptr<Node> n, uint16_t clientPort);
+  virtual ~UdpEchoServer ();
+
+protected:
+  virtual void DoDispose (void);
+
+private:
+  void Construct (Ptr<Node> n, uint16_t clientPort);
+
+  virtual void StartApplication (void);
+  virtual void StopApplication (void);
+
+  void Receive(Ptr<Socket> socket, const Packet &packet, const Address &from);
+
+  Ptr<Node> m_node;
+  uint16_t m_port;
+
+  Ptr<Socket> m_socket;
+  Address m_local;
+};
+
+} // namespace ns3
+
+#endif // __UDP_ECHO_SERVER_H__
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/waf	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/udp-echo/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    module = bld.create_ns3_module('udp-echo', ['internet-node'])
+    module.source = [
+        'udp-echo-client.cc',
+        'udp-echo-server.cc',
+        ]
+    headers = bld.create_obj('ns3header')
+    headers.source = [
+        'udp-echo-client.h',
+        'udp-echo-server.h',
+        ]
+
--- a/src/applications/waf	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-exec "`dirname "$0"`"/../../waf "$@"
\ No newline at end of file
--- a/src/applications/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-def build(bld):
-    obj = bld.create_ns3_module('applications', ['node'])
-    obj.source = [
-        'onoff-application.cc',
-        'packet-sink.cc',
-        ]
-
-    headers = bld.create_obj('ns3header')
-    headers.source = [
-        'onoff-application.h',
-        'packet-sink.h',
-        ]
--- a/src/common/buffer.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/common/buffer.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,13 +19,13 @@
  */
 #include "buffer.h"
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include <iostream>
 
-NS_DEBUG_COMPONENT_DEFINE ("Buffer");
+NS_LOG_COMPONENT_DEFINE ("Buffer");
 
-#define DEBUG_INTERNAL_STATE(y)                                                                    \
-NS_DEBUG (y << "start="<<m_start<<", end="<<m_end<<", zero start="<<m_zeroAreaStart<<              \
+#define LOG_INTERNAL_STATE(y)                                                                    \
+NS_LOG_LOGIC (y << "start="<<m_start<<", end="<<m_end<<", zero start="<<m_zeroAreaStart<<              \
           ", zero end="<<m_zeroAreaEnd<<", count="<<m_data->m_count<<", size="<<m_data->m_size<<   \
           ", dirty start="<<m_data->m_dirtyStart<<", dirty end="<<m_data->m_dirtyEnd)
 
@@ -394,7 +394,7 @@
   // update dirty area
   m_data->m_dirtyStart = m_start;
   m_data->m_dirtyEnd = m_end;
-  DEBUG_INTERNAL_STATE ("add start=" << start << ", ");
+  LOG_INTERNAL_STATE ("add start=" << start << ", ");
   NS_ASSERT (CheckInternalState ());
 }
 void 
@@ -457,7 +457,7 @@
   // update dirty area
   m_data->m_dirtyStart = m_start;
   m_data->m_dirtyEnd = m_end;
-  DEBUG_INTERNAL_STATE ("add end=" << end << ", ");
+  LOG_INTERNAL_STATE ("add end=" << end << ", ");
   NS_ASSERT (CheckInternalState ());
 }
 
@@ -502,7 +502,7 @@
       m_zeroAreaStart = m_end;
     }
   HEURISTICS (m_maxZeroAreaStart = std::max (m_maxZeroAreaStart, m_zeroAreaStart));
-  DEBUG_INTERNAL_STATE ("rem start=" << start << ", ");
+  LOG_INTERNAL_STATE ("rem start=" << start << ", ");
   NS_ASSERT (CheckInternalState ());
 }
 void 
@@ -536,7 +536,7 @@
       m_zeroAreaStart = m_start;
     }
   HEURISTICS (m_maxZeroAreaStart = std::max (m_maxZeroAreaStart, m_zeroAreaStart));
-  DEBUG_INTERNAL_STATE ("rem end=" << end << ", ");
+  LOG_INTERNAL_STATE ("rem end=" << end << ", ");
   NS_ASSERT (CheckInternalState ());
 }
 
--- a/src/common/packet-metadata.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/common/packet-metadata.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -21,12 +21,12 @@
 #include <list>
 #include "ns3/assert.h"
 #include "ns3/fatal-error.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "packet-metadata.h"
 #include "buffer.h"
 #include "chunk-registry.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("PacketMetadata");
+NS_LOG_COMPONENT_DEFINE ("PacketMetadata");
 
 namespace ns3 {
 
@@ -610,7 +610,7 @@
 struct PacketMetadata::Data *
 PacketMetadata::Create (uint32_t size)
 {
-  NS_DEBUG ("create size="<<size<<", max="<<m_maxSize);
+  NS_LOG_LOGIC ("create size="<<size<<", max="<<m_maxSize);
   if (size > m_maxSize)
     {
       m_maxSize = size;
@@ -621,21 +621,21 @@
       m_freeList.pop_back ();
       if (data->m_size >= size) 
         {
-          NS_DEBUG ("create found size="<<data->m_size);
+          NS_LOG_LOGIC ("create found size="<<data->m_size);
           data->m_count = 1;
           return data;
         }
       PacketMetadata::Deallocate (data);
-      NS_DEBUG ("create dealloc size="<<data->m_size);
+      NS_LOG_LOGIC ("create dealloc size="<<data->m_size);
     }
-  NS_DEBUG ("create alloc size="<<m_maxSize);
+  NS_LOG_LOGIC ("create alloc size="<<m_maxSize);
   return PacketMetadata::Allocate (m_maxSize);
 }
 
 void
 PacketMetadata::Recycle (struct PacketMetadata::Data *data)
 {
-  NS_DEBUG ("recycle size="<<data->m_size<<", list="<<m_freeList.size ());
+  NS_LOG_LOGIC ("recycle size="<<data->m_size<<", list="<<m_freeList.size ());
   NS_ASSERT (data->m_count == 0);
   if (m_freeList.size () > 1000 ||
       data->m_size < m_maxSize) 
@@ -1133,10 +1133,10 @@
   while (current != 0xffff)
     {
       ReadItems (current, &item, &extraItem);
-      NS_DEBUG ("bytesWritten=" << bytesWritten << ", typeUid="<<item.typeUid <<
-                ", size="<<item.size<<", chunkUid="<<item.chunkUid<<
-                ", fragmentStart="<<extraItem.fragmentStart<<", fragmentEnd="<<extraItem.fragmentEnd<<
-                ", packetUid="<<extraItem.packetUid);
+      NS_LOG_LOGIC ("bytesWritten=" << bytesWritten << ", typeUid="<<
+        item.typeUid << ", size="<<item.size<<", chunkUid="<<item.chunkUid<<
+        ", fragmentStart="<<extraItem.fragmentStart<<", fragmentEnd="<<
+        extraItem.fragmentEnd<< ", packetUid="<<extraItem.packetUid);
       uint32_t uid = (item.typeUid & 0xfffffffe) >> 1;
       if (uid != 0)
         {
@@ -1215,10 +1215,10 @@
       size -= 4;
       extraItem.packetUid = i.ReadU32 ();
       size -= 4;
-      NS_DEBUG ("size=" << size << ", typeUid="<<item.typeUid <<
-                ", size="<<item.size<<", chunkUid="<<item.chunkUid<<
-                ", fragmentStart="<<extraItem.fragmentStart<<", fragmentEnd="<<extraItem.fragmentEnd<<
-                ", packetUid="<<extraItem.packetUid);
+      NS_LOG_LOGIC ("size=" << size << ", typeUid="<<item.typeUid <<
+        ", size="<<item.size<<", chunkUid="<<item.chunkUid<<
+        ", fragmentStart="<<extraItem.fragmentStart<<", fragmentEnd="<<
+        extraItem.fragmentEnd<< ", packetUid="<<extraItem.packetUid);
       uint32_t tmp = AddBig (0xffff, m_tail, &item, &extraItem);
       UpdateTail (tmp);
     }
--- a/src/core/composite-trace-resolver.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/composite-trace-resolver.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,9 +19,9 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "composite-trace-resolver.h"
-#include "debug.h"
+#include "log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("CompositeTraceResolver");
+NS_LOG_COMPONENT_DEFINE ("CompositeTraceResolver");
 
 namespace ns3 {
 
@@ -174,7 +174,7 @@
 void 
 CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context)
 {
-  NS_DEBUG ("connect path="<<path);
+  NS_LOG_LOGIC ("connect path="<<path);
   class ConnectOperation : public Operation
   {
   public:
@@ -183,7 +183,7 @@
     {}
     virtual void Do (std::string subpath, ResolveItem *item) const
     {
-      NS_DEBUG ("connect to path="<<subpath<<" name="<<item->name);
+      NS_LOG_LOGIC ("connect to path="<<subpath<<" name="<<item->name);
       TraceContext context = m_context;
       context.Union (item->context);
       item->Connect (subpath, m_cb, context);
@@ -272,7 +272,7 @@
 void 
 CompositeTraceResolver::Disconnect (std::string path, CallbackBase const &cb)
 {
-  NS_DEBUG ("disconnect path="<<path);
+  NS_LOG_LOGIC ("disconnect path="<<path);
   class DisconnectOperation : public Operation
   {
   public:
@@ -281,7 +281,7 @@
     {}
     virtual void Do (std::string subpath, ResolveItem *item) const
     {
-      NS_DEBUG ("disconnect from path="<<subpath<<" name="<<item->name);
+      NS_LOG_LOGIC ("disconnect from path="<<subpath<<" name="<<item->name);
       item->Disconnect (subpath, m_cb);
     }
     virtual void DoParent (std::string path, Ptr<TraceResolver> parent) const
@@ -303,7 +303,7 @@
 {
   for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++)
     {
-      NS_DEBUG ("print " << (*i)->name);
+      NS_LOG_LOGIC ("print " << (*i)->name);
       (*i)->CollectSources (path, context, collection);
     }
   if (m_parent != 0)
@@ -316,7 +316,7 @@
 {
   for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++)
     {
-      NS_DEBUG ("print " << (*i)->name);
+      NS_LOG_LOGIC ("print " << (*i)->name);
       (*i)->TraceAll (os, context);
     }
   if (m_parent != 0)
--- a/src/core/fatal-error.h	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/fatal-error.h	Fri Sep 21 13:59:03 2007 +0100
@@ -32,9 +32,8 @@
  *
  * When this macro is hit at runtime, the user-specified 
  * error message is output and the program is halted by calling
- * the NS_DEBUG_BREAKPOINT macro. This macro is enabled
- * unconditionally in all builds, including debug and optimized 
- * builds.
+ * the NS_BREAKPOINT macro. This macro is enabled unconditionally
+ * in all builds, including debug and optimized builds.
  */
 #define NS_FATAL_ERROR(msg)				\
   do                                                    \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/log.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,331 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006,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 <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifdef NS3_LOG_ENABLE
+
+#include <list>
+#include <utility>
+#include <iostream>
+#include "log.h"
+#include "assert.h"
+#include "ns3/core-config.h"
+#include "fatal-error.h"
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+namespace ns3 {
+
+typedef std::list<std::pair <std::string, LogComponent *> > ComponentList;
+typedef std::list<std::pair <std::string, LogComponent *> >::iterator ComponentListI;
+
+static 
+ComponentList *GetComponentList (void)
+{
+  static ComponentList components;
+  return &components;
+}
+
+void
+LogComponentEnableEnvVar (void)
+{
+  static bool isFirstLog = true;
+  if (!isFirstLog)
+    {
+      return;
+    }
+#ifdef HAVE_GETENV
+  char *envVar = getenv("NS_LOG");
+  if (envVar == 0)
+    {
+      isFirstLog = false;
+      return;
+    }
+  std::string env = envVar;
+  if (env == "print-list")
+    {
+      LogComponentPrintList ();
+      isFirstLog = false;
+      return;
+    }
+  bool allFound = true;
+  std::string::size_type cur = 0;
+  std::string::size_type next = 0;
+  while (true)
+    {
+      next = env.find_first_of (";", cur);
+      std::string tmp = std::string (env, cur, next);
+      {
+        /* The following code is a workaround for a bug in the g++
+         * c++ string library. Its goal is to remove any trailing ';'
+         * from the string even though there should not be any in
+         * it. This code should be safe even if the bug is not there.
+         */
+        std::string::size_type trailing = tmp.find_first_of (";");
+        tmp = tmp.substr (0, trailing);
+      }
+      if (tmp.size () == 0)
+        {
+          break;
+        }
+      std::string::size_type equal = tmp.find ("=");
+      std::string component;
+      int level;
+      if (equal == std::string::npos)
+        {
+          component = tmp;
+          level = LOG_DEBUG;
+        }
+      else
+        {
+          component = tmp.substr (0, equal);
+          std::string::size_type cur_lev;
+          std::string::size_type next_lev = equal;
+          do
+            {
+              cur_lev = next_lev + 1;
+              next_lev = tmp.find ("|", cur_lev);
+              std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
+              if (lev == "error")
+                {
+                  level |= LOG_ERROR;
+                }
+              else if (lev == "warn")
+                {
+                  level |= LOG_WARN;
+                }
+              else if (lev == "debug")
+                {
+                  level |= LOG_DEBUG;
+                }
+              else if (lev == "info")
+                {
+                  level |= LOG_INFO;
+                }
+              else if (lev == "function")
+                {
+                  level |= LOG_FUNCTION;
+                }
+              else if (lev == "param")
+                {
+                  level |= LOG_PARAM;
+                }
+              else if (lev == "logic")
+                {
+                  level |= LOG_LOGIC;
+                }
+              else if (lev == "all")
+                {
+                  level |= LOG_ALL;
+                }
+              else if (lev == "errorlevel")
+                {
+                  level |= LOG_LEVEL_ERROR;
+                }
+              else if (lev == "warnlevel")
+                {
+                  level |= LOG_LEVEL_WARN;
+                }
+              else if (lev == "debuglevel")
+                {
+                  level |= LOG_LEVEL_DEBUG;
+                }
+              else if (lev == "infolevel")
+                {
+                  level |= LOG_LEVEL_INFO;
+                }
+              else if (lev == "functionlevel")
+                {
+                  level |= LOG_LEVEL_FUNCTION;
+                }
+              else if (lev == "paramlevel")
+                {
+                  level |= LOG_LEVEL_PARAM;
+                }
+              else if (lev == "logiclevel")
+                {
+                  level |= LOG_LEVEL_LOGIC;
+                }
+              else if (lev == "alllevel")
+                {
+                  level |= LOG_LEVEL_ALL;
+                }
+            } while (next_lev != std::string::npos);
+        }
+      bool found = false;
+      ComponentList *components = GetComponentList ();
+      for (ComponentListI i = components->begin ();
+           i != components->end ();
+           i++)
+        {
+          if (i->first.compare (component) == 0)
+            {
+              found = true;
+              
+              i->second->Enable ((enum LogLevel)level);
+              break;
+            }
+        }
+      if (!found)
+        {
+          allFound = false;
+        }
+      if (next == std::string::npos)
+        {
+          break;
+        }
+      cur = next + 1;
+      if (cur >= env.size ()) 
+        {
+          break;
+        }
+    }
+  if (allFound)
+    {
+      isFirstLog = false;
+    }
+  
+#endif
+}
+
+LogComponent::LogComponent (char const * name)
+  : m_levels (0)
+{
+  ComponentList *components = GetComponentList ();
+  for (ComponentListI i = components->begin ();
+       i != components->end ();
+       i++)
+    {
+      NS_ASSERT (i->first != name);
+    }
+  components->push_back (std::make_pair (name, this));
+}
+
+bool 
+LogComponent::IsEnabled (enum LogLevel level) const
+{
+  LogComponentEnableEnvVar ();
+  return (level & m_levels) ? 1 : 0;
+}
+
+bool
+LogComponent::IsNoneEnabled (void) const
+{
+  return m_levels == 0;
+}
+
+void 
+LogComponent::Enable (enum LogLevel level)
+{
+  m_levels |= level;
+}
+
+void 
+LogComponent::Disable (enum LogLevel level)
+{
+  m_levels &= ~level;
+}
+
+void 
+LogComponentEnable (char const *name, enum LogLevel level)
+{
+  ComponentList *components = GetComponentList ();
+  for (ComponentListI i = components->begin ();
+       i != components->end ();
+       i++)
+    {
+      if (i->first.compare (name) == 0) 
+	{
+	  i->second->Enable (level);
+	  break;
+	}
+    }  
+}
+
+void 
+LogComponentDisable (char const *name, enum LogLevel level)
+{
+  ComponentList *components = GetComponentList ();
+  for (ComponentListI i = components->begin ();
+       i != components->end ();
+       i++)
+    {
+      if (i->first.compare (name) == 0) 
+	{
+	  i->second->Disable (level);
+	  break;
+	}
+    }  
+}
+
+void 
+LogComponentPrintList (void)
+{
+  ComponentList *components = GetComponentList ();
+  for (ComponentListI i = components->begin ();
+       i != components->end ();
+       i++)
+    {
+      std::cout << i->first << "=";
+      if (i->second->IsNoneEnabled ())
+        {
+          std::cout << "0" << std::endl;
+          continue;
+        }
+      if (i->second->IsEnabled (LOG_ERROR))
+        {
+          std::cout << "error";
+        }
+      if (i->second->IsEnabled (LOG_WARN))
+        {
+          std::cout << "|warn";
+        }
+      if (i->second->IsEnabled (LOG_DEBUG))
+        {
+          std::cout << "|debug";
+        }
+      if (i->second->IsEnabled (LOG_INFO))
+        {
+          std::cout << "|info";
+        }
+      if (i->second->IsEnabled (LOG_FUNCTION))
+        {
+          std::cout << "|function";
+        }
+      if (i->second->IsEnabled (LOG_PARAM))
+        {
+          std::cout << "|param";
+        }
+      if (i->second->IsEnabled (LOG_LOGIC))
+        {
+          std::cout << "|logic";
+        }
+      if (i->second->IsEnabled (LOG_ALL))
+        {
+          std::cout << "|all";
+        }
+      std::cout << std::endl;
+    }
+}
+
+} // namespace ns3
+
+#endif // NS3_LOG_ENABLE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/log.h	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,251 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006,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 <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef __LOG_H__
+#define __LOG_H__
+
+#include <string>
+#include <iostream>
+
+/**
+ * \defgroup logging Logging
+ * \brief Logging functions and macros
+ *
+ *   LOG functionality: macros which allow developers to
+ *     send information out on screen. All logging messages 
+ *     are disabled by default. To enable selected logging 
+ *     messages, use the ns3::LogComponentEnable
+ *     function. 
+ * 
+ * Alternatively, you can use the NS_LOG
+ * environment variable to define a ';'-separated list of
+ * logging components to enable. For example, NS_LOG=a;b;c;DAFD;GH
+ * would enable the components 'a', 'b', 'c', 'DAFD', and, 'GH'.
+ *
+ * For each component, the "debug" log level is enabled by default
+ * but more components can be enabled selectively with the following
+ * syntax: NS_LOG='Component1=func|param|warn;Component2=error|debug'
+ * This example would enable the 'func', 'param', and 'warn' log
+ * levels for 'Component1' and the 'error' and 'debug' log levels
+ * for 'Component2'.
+ *
+ * The list of available log components can be printed on stdout
+ * with the NS_LOG=print-list syntax.
+ */
+
+/**
+ * \ingroup logging
+ * \param name a string
+ *
+ * Define a Log component with a specific name. This macro
+ * should be used at the top of every file in which you want 
+ * to use the NS_LOG macro. This macro defines a new
+ * "log component" which can be later selectively enabled
+ * or disabled with the ns3::LogComponentEnable and 
+ * ns3::LogComponentDisable functions or with the NS_LOG
+ * environment variable.
+ */
+
+#ifdef NS3_LOG_ENABLE
+
+#define NS_LOG_COMPONENT_DEFINE(name)                                \
+  static ns3::LogComponent g_log = ns3::LogComponent (name)
+
+#else
+
+#define NS_LOG_COMPONENT_DEFINE(name)
+
+#endif
+
+/**
+ * \ingroup logging
+ * \param msg message to output
+ *
+ * Generate logging output in the "log component" of the 
+ * current file. i.e., every call to NS_LOG from within
+ * a file implicitely generates out within the component
+ * defined with the NS_LOG_COMPONENT_DEFINE macro in the
+ * same file.
+ */
+
+#ifdef NS3_LOG_ENABLE
+
+#define NS_LOG(level, msg)                                      \
+  do                                                            \
+    {                                                           \
+      if (g_log.IsEnabled (level))                              \
+        {                                                       \
+          std::clog << __PRETTY_FUNCTION__ << " ==> " <<        \
+            msg << std::endl;                                   \
+        }                                                       \
+    }                                                           \
+  while (false)
+
+#define NS_LOG_F(level)                                 \
+  do                                                    \
+    {                                                   \
+      if (g_log.IsEnabled (level))                      \
+        {                                               \
+          std::clog << __PRETTY_FUNCTION__ << std::endl;\
+        }                                               \
+    }                                                   \
+  while (false)
+
+#define NS_LOG_ERROR(msg) \
+  NS_LOG(ns3::LOG_ERROR, msg)
+
+#define NS_LOG_WARN(msg) \
+  NS_LOG(ns3::LOG_WARN, msg)
+
+#define NS_LOG_DEBUG(msg) \
+  NS_LOG(ns3::LOG_DEBUG, msg)
+
+#define NS_LOG_INFO(msg) \
+  NS_LOG(ns3::LOG_INFO, msg)
+
+#define NS_LOG_FUNCTION \
+  NS_LOG_F(ns3::LOG_FUNCTION)
+
+#define NS_LOG_PARAM(msg) \
+  NS_LOG(ns3::LOG_PARAM, msg)
+
+#define NS_LOG_LOGIC(msg) \
+  NS_LOG(ns3::LOG_LOGIC, msg)
+
+#define NS_LOG_ALL(msg) \
+  NS_LOG(ns3::LOG_ALL, msg)
+
+#define NS_LOG_UNCOND(msg)              \
+  do                                    \
+    {                                   \
+      std::clog << msg << std::endl;    \
+    }                                   \
+  while (false)
+
+#else
+
+#define NS_LOG(level, msg)
+#define NS_LOG_F(level)
+#define NS_LOG_ERROR(msg)
+#define NS_LOG_WARN(msg)
+#define NS_LOG_DEBUG(msg)
+#define NS_LOG_INFO(msg)
+#define NS_LOG_FUNCTION
+#define NS_LOG_PARAM(msg)
+#define NS_LOG_LOGIC(msg)
+#define NS_LOG_ALL(msg)
+#define NS_LOG_UNCOND(msg)
+
+#endif
+
+namespace ns3 {
+
+#ifdef NS3_LOG_ENABLE
+
+enum LogLevel {
+  LOG_ERROR          = 0x0001, // serious error messages only
+  LOG_LEVEL_ERROR    = 0x0001,
+
+  LOG_WARN           = 0x0002, // warning messages
+  LOG_LEVEL_WARN     = 0x0003,
+
+  LOG_DEBUG          = 0x0004, // rare ad-hoc debug messages
+  LOG_LEVEL_DEBUG    = 0x0007,
+
+  LOG_INFO           = 0x0008, // informational messages (e.g., banners)
+  LOG_LEVEL_INFO     = 0x000f,
+
+  LOG_FUNCTION       = 0x0010, // function tracing
+  LOG_LEVEL_FUNCTION = 0x001f, 
+
+  LOG_PARAM          = 0x0020, // parameters to functions
+  LOG_LEVEL_PARAM    = 0x003f,
+
+  LOG_LOGIC          = 0x0040, // control flow tracing within functions
+  LOG_LEVEL_LOGIC    = 0x007f,
+
+  LOG_ALL            = 0x4000, // print everything
+  LOG_LEVEL_ALL      = 0x7fff
+};
+
+#endif
+
+/**
+ * \param name a log component name
+ * \ingroup logging
+ *
+ * Enable the logging output associated with that log component.
+ * The logging output can be later disabled with a call
+ * to ns3::LogComponentDisable.
+ */
+#ifdef NS3_LOG_ENABLE
+void LogComponentEnable (char const *name, enum LogLevel level);
+#else
+#define LogComponentEnable(a,b)
+#endif
+
+/**
+ * \param name a log component name
+ * \ingroup logging
+ *
+ * Disable the logging output associated with that log component.
+ * The logging output can be later re-enabled with a call
+ * to ns3::LogComponentEnable.
+ */
+#ifdef NS3_LOG_ENABLE
+void LogComponentDisable (char const *name, enum LogLevel level);
+#else
+#define LogComponentDisable(a,b)
+#endif
+
+/**
+ * \ingroup logging
+ *
+ * Print the list of logging messages available.
+ * The output of this function can be obtained by setting
+ * the NS_LOG environment variable to the special value 
+ * 'print-list'.
+ * 
+ * For example: NS_LOG=print-list
+ */
+#ifdef NS3_LOG_ENABLE
+void LogComponentPrintList (void);
+#else
+#define LogComponentPrintList()
+#endif
+
+#ifdef NS3_LOG_ENABLE
+
+class LogComponent {
+public:
+  LogComponent (char const *name);
+  bool IsEnabled (enum LogLevel level) const;
+  bool IsNoneEnabled (void) const;
+  void Enable (enum LogLevel level);
+  void Disable (enum LogLevel level);
+private:
+  int32_t m_levels;
+};
+
+#endif
+
+} // namespace ns3
+
+#endif // __LOG_H__
--- a/src/core/object.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/object.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -23,10 +23,10 @@
 #include "singleton.h"
 #include "uid-manager.h"
 #include "trace-resolver.h"
-#include "debug.h"
+#include "log.h"
 #include <vector>
 
-NS_DEBUG_COMPONENT_DEFINE ("Object");
+NS_LOG_COMPONENT_DEFINE ("Object");
 
 namespace {
 
@@ -322,7 +322,7 @@
   while (current != this)
     {
       NS_ASSERT (current != 0);
-      NS_DEBUG ("collect current=" << current);
+      NS_LOG_LOGIC ("collect current=" << current);
       InterfaceId cur = current->m_iid;
       while (cur != Object::iid)
         {
@@ -330,7 +330,7 @@
           std::string fullpath = path;
           fullpath.append ("/$");
           fullpath.append (name);
-          NS_DEBUG ("collect: " << fullpath);
+          NS_LOG_LOGIC("collect: " << fullpath);
           current->GetTraceResolver ()->CollectSources (fullpath, context, collection);
           cur = InterfaceId::LookupParent (cur);
         }
--- a/src/core/random-variable-default-value.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/random-variable-default-value.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,9 +19,9 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "random-variable-default-value.h"
-#include "debug.h"
+#include "log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("RandomVariableDefaultValue");
+NS_LOG_COMPONENT_DEFINE ("RandomVariableDefaultValue");
 
 namespace ns3 {
 
@@ -75,12 +75,12 @@
       double constant = ReadAsDouble (v, ok);
       if (mustCreate)
 	{
-          NS_DEBUG ("create Constant constant=" << constant);
+          NS_LOG_LOGIC ("create Constant constant=" << constant);
 	  *pVariable = new ConstantVariable (constant);
 	}
       else
         {
-          NS_DEBUG ("parse  Constant constant=" << constant);
+          NS_LOG_LOGIC ("parse  Constant constant=" << constant);
         }
       return ok;
     }
@@ -99,12 +99,12 @@
       maxVal = ReadAsDouble (max, ok);
       if (mustCreate)
 	{
-          NS_DEBUG ("create Uniform min=" << min << ", max=" << max);
+          NS_LOG_LOGIC ("create Uniform min=" << min << ", max=" << max);
 	  *pVariable = new UniformVariable (minVal, maxVal);
 	}
       else
         {
-          NS_DEBUG ("parse  Uniform min=" << min << ", max=" << max);
+          NS_LOG_LOGIC ("parse  Uniform min=" << min << ", max=" << max);
         }
       return ok;
     }
--- a/src/core/trace-resolver.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/trace-resolver.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,9 +19,9 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "trace-resolver.h"
-#include "debug.h"
+#include "log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("TraceResolver");
+NS_LOG_COMPONENT_DEFINE ("TraceResolver");
 
 namespace ns3 {
 
@@ -43,7 +43,7 @@
   m_count--;
   if (m_count == 0)
     {
-      NS_DEBUG ("delete "<<this);
+      NS_LOG_LOGIC ("delete "<<this);
       delete this;
     }
 }
--- a/src/core/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/core/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -30,6 +30,7 @@
     core.source = [
         'callback-test.cc',
         'debug.cc',
+        'log.cc',
         'breakpoint.cc',
         'ptr.cc',
         'object.cc',
@@ -69,6 +70,7 @@
         'ptr.h',
         'object.h',
         'debug.h',
+        'log.h',
         'assert.h',
         'breakpoint.h',
         'fatal-error.h',
--- a/src/devices/csma/csma-channel.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/csma/csma-channel.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -23,9 +23,9 @@
 #include "csma-net-device.h"
 #include "ns3/packet.h"
 #include "ns3/simulator.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("CsmaChannel");
+NS_LOG_COMPONENT_DEFINE ("CsmaChannel");
 
 namespace ns3 {
 
@@ -55,7 +55,7 @@
   m_bps (DataRate(0xffffffff)),
   m_delay (Seconds(0))
 {
-  NS_DEBUG("CsmaChannel::CsmaChannel ()");
+  NS_LOG_FUNCTION;
   Init();
 }
 
@@ -67,8 +67,9 @@
   m_bps (bps),
   m_delay (delay)
 {
-  NS_DEBUG("CsmaChannel::CsmaChannel (" << Channel::GetName() 
-    << ", " << bps.GetBitRate() << ", " << delay << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << 
+    ", " << delay << ")");
   Init();
 }
 
@@ -81,8 +82,9 @@
   m_bps (bps), 
   m_delay (delay)
 {
-  NS_DEBUG("CsmaChannel::CsmaChannel (" << name << ", " << 
-           bps.GetBitRate() << ", " << delay << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << delay << 
+    ")");
   Init();
 }
 
@@ -94,7 +96,8 @@
 int32_t
 CsmaChannel::Attach(Ptr<CsmaNetDevice> device)
 {
-  NS_DEBUG("CsmaChannel::Attach (" << device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << device << ")");
   NS_ASSERT(device != 0);
 
   CsmaDeviceRec rec(device);
@@ -106,7 +109,8 @@
 bool
 CsmaChannel::Reattach(Ptr<CsmaNetDevice> device)
 {
-  NS_DEBUG("CsmaChannel::Reattach (" << device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << device << ")");
   NS_ASSERT(device != 0);
 
   std::vector<CsmaDeviceRec>::iterator it;
@@ -131,7 +135,9 @@
 bool
 CsmaChannel::Reattach(uint32_t deviceId)
 {
-  NS_DEBUG("CsmaChannel::Reattach (" << deviceId << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << deviceId << ")");
+
   if (deviceId < m_deviceList.size())
     {
       return false;
@@ -151,22 +157,23 @@
 bool
 CsmaChannel::Detach(uint32_t deviceId)
 {
-  NS_DEBUG("CsmaChannel::Detach (" << deviceId << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << deviceId << ")");
 
   if (deviceId < m_deviceList.size())
     {
       if (!m_deviceList[deviceId].active)
         {
-          NS_DEBUG("CsmaChannel::Detach Device is already detached (" 
-                   << deviceId << ")");
+          NS_LOG_WARN ("CsmaChannel::Detach Device is already detached (" << 
+            deviceId << ")");
           return false;
         }
 
       m_deviceList[deviceId].active = false;
       if ((m_state == TRANSMITTING) && (m_currentSrc == deviceId))
         {
-          NS_DEBUG("CsmaChannel::Detach Device is currently"
-                   << "transmitting (" << deviceId << ")");
+          NS_LOG_WARN ("CsmaChannel::Detach Device is currently" << 
+            "transmitting (" << deviceId << ")");
           // Here we will need to place a warning in the packet
         }
 
@@ -181,7 +188,8 @@
 bool
 CsmaChannel::Detach(Ptr<CsmaNetDevice> device)
 {
-  NS_DEBUG("CsmaChannel::Detach (" << device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << device << ")");
   NS_ASSERT(device != 0);
 
   std::vector<CsmaDeviceRec>::iterator it;
@@ -199,25 +207,23 @@
 bool
 CsmaChannel::TransmitStart(Packet& p, uint32_t srcId)
 {
-  NS_DEBUG ("CsmaChannel::TransmitStart (" << &p << ", " << srcId 
-            << ")");
-  NS_DEBUG ("CsmaChannel::TransmitStart (): UID is " << 
-            p.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << srcId << ")");
+  NS_LOG_INFO ("UID is " << p.GetUid () << ")");
 
   if (m_state != IDLE)
     {
-      NS_DEBUG("CsmaChannel::TransmitStart (): state is not IDLE");
+      NS_LOG_WARN ("state is not IDLE");
       return false;
     }
 
   if (!IsActive(srcId))
     {
-      NS_DEBUG("CsmaChannel::TransmitStart (): ERROR: Seclected "
-               << "source is not currently attached to network");
+      NS_LOG_ERROR ("Seclected source is not currently attached to network");
       return false;
     }
 
-  NS_DEBUG("CsmaChannel::TransmitStart (): switch to TRANSMITTING");
+  NS_LOG_LOGIC ("switch to TRANSMITTING");
   m_currentPkt = p;
   m_currentSrc = srcId;
   m_state = TRANSMITTING;
@@ -233,10 +239,9 @@
 bool
 CsmaChannel::TransmitEnd()
 {
-  NS_DEBUG("CsmaChannel::TransmitEnd (" << &m_currentPkt << ", " 
-           << m_currentSrc << ")");
-  NS_DEBUG("CsmaChannel::TransmitEnd (): UID is " << 
-            m_currentPkt.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &m_currentPkt << ", " << m_currentSrc << ")");
+  NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")");
 
   NS_ASSERT(m_state == TRANSMITTING);
   m_state = PROPAGATING;
@@ -244,13 +249,12 @@
   bool retVal = true;
 
   if (!IsActive(m_currentSrc)) {
-    NS_DEBUG("CsmaChannel::TransmitEnd (): ERROR: Seclected source "
-             << "was detached before the end of the transmission");
+    NS_LOG_ERROR ("Seclected source was detached before the end of the"
+      "transmission");
     retVal = false;
   }
 
-  NS_DEBUG ("CsmaChannel::TransmitEnd (): Schedule event in " << 
-            m_delay.GetSeconds () << " sec");
+  NS_LOG_LOGIC ("Schedule event in " << m_delay.GetSeconds () << " sec");
 
   Simulator::Schedule (m_delay,
                        &CsmaChannel::PropagationCompleteEvent,
@@ -261,14 +265,13 @@
 void
 CsmaChannel::PropagationCompleteEvent()
 {
-  NS_DEBUG("CsmaChannel::PropagationCompleteEvent (" 
-           << &m_currentPkt << ")");
-  NS_DEBUG ("CsmaChannel::PropagationCompleteEvent (): UID is " << 
-            m_currentPkt.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &m_currentPkt << ")");
+  NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")");
 
   NS_ASSERT(m_state == PROPAGATING);
 
-  NS_DEBUG ("CsmaChannel::PropagationCompleteEvent (): Receive");
+  NS_LOG_LOGIC ("Receive");
   
   std::vector<CsmaDeviceRec>::iterator it;
   for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) 
--- a/src/devices/csma/csma-ipv4-topology.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/csma/csma-ipv4-topology.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,7 +20,6 @@
 
 #include <algorithm>
 #include "ns3/assert.h"
-#include "ns3/debug.h"
 #include "ns3/fatal-error.h"
 #include "ns3/nstime.h"
 #include "ns3/internet-node.h"
--- a/src/devices/csma/csma-net-device.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/csma/csma-net-device.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,7 +19,7 @@
  * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/queue.h"
 #include "ns3/simulator.h"
 #include "ns3/composite-trace-resolver.h"
@@ -29,16 +29,22 @@
 #include "ns3/ethernet-trailer.h"
 #include "ns3/llc-snap-header.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("CsmaNetDevice");
+NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice");
 
 namespace ns3 {
 
 CsmaTraceType::CsmaTraceType (enum Type type)
   : m_type (type)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 CsmaTraceType::CsmaTraceType ()
   : m_type (RX)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 void 
 CsmaTraceType::Print (std::ostream &os) const
 {
@@ -51,20 +57,26 @@
     break;
   }
 }
+
 uint16_t 
 CsmaTraceType::GetUid (void)
 {
+  NS_LOG_FUNCTION;
   static uint16_t uid = AllocateUid<CsmaTraceType> ("CsmaTraceType");
   return uid;
 }
+
 std::string 
 CsmaTraceType::GetTypeName (void) const
 {
+  NS_LOG_FUNCTION;
   return "ns3::CsmaTraceType";
 }
+
 enum CsmaTraceType::Type 
 CsmaTraceType::Get (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type;
 }
 
@@ -72,7 +84,8 @@
   : NetDevice (node, Mac48Address::Allocate ()),
     m_bps (DataRate (0xffffffff))
 {
-  NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << node << ")");
   m_encapMode = IP_ARP;
   Init(true, true);
 }
@@ -82,7 +95,8 @@
   : NetDevice(node, addr), 
     m_bps (DataRate (0xffffffff))
 {
-  NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << node << ")");
   m_encapMode = encapMode;
 
   Init(true, true);
@@ -94,7 +108,8 @@
   : NetDevice(node, addr), 
     m_bps (DataRate (0xffffffff))
 {
-  NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << node << ")");
   m_encapMode = encapMode;
 
   Init(sendEnable, receiveEnable);
@@ -102,13 +117,14 @@
 
 CsmaNetDevice::~CsmaNetDevice()
 {
-  NS_DEBUG ("CsmaNetDevice::~CsmaNetDevice ()");
+  NS_LOG_FUNCTION;
   m_queue = 0;
 }
 
 void 
 CsmaNetDevice::DoDispose ()
 {
+  NS_LOG_FUNCTION;
   m_channel = 0;
   NetDevice::DoDispose ();
 }
@@ -125,7 +141,8 @@
 CsmaNetDevice&
 CsmaNetDevice::operator= (const CsmaNetDevice nd)
 {
-  NS_DEBUG ("CsmaNetDevice::operator= (" << &nd << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &nd << ")");
   return *this;
 }
 */
@@ -133,6 +150,7 @@
 void 
 CsmaNetDevice::Init(bool sendEnable, bool receiveEnable)
 {
+  NS_LOG_FUNCTION;
   m_txMachineState = READY;
   m_tInterframeGap = Seconds(0);
   m_channel = 0; 
@@ -148,53 +166,63 @@
 void
 CsmaNetDevice::SetSendEnable (bool sendEnable)
 {
+  NS_LOG_FUNCTION;
   m_sendEnable = sendEnable;
 }
 
 void
 CsmaNetDevice::SetReceiveEnable (bool receiveEnable)
 {
+  NS_LOG_FUNCTION;
   m_receiveEnable = receiveEnable;
 }
+
 bool
 CsmaNetDevice::IsSendEnabled (void)
 {
+  NS_LOG_FUNCTION;
   return (m_sendEnable);
 }
 
 bool
 CsmaNetDevice::IsReceiveEnabled (void)
 {
+  NS_LOG_FUNCTION;
   return (m_receiveEnable);
 }
 
 void 
 CsmaNetDevice::SetDataRate (DataRate bps)
 {
+  NS_LOG_FUNCTION;
   m_bps = bps;
 }
 
 void 
 CsmaNetDevice::SetInterframeGap (Time t)
 {
+  NS_LOG_FUNCTION;
   m_tInterframeGap = t;
 }
 
 void 
 CsmaNetDevice::SetBackoffParams (Time slotTime, uint32_t minSlots, 
-                                      uint32_t maxSlots, uint32_t ceiling, 
-                                      uint32_t maxRetries)
+                                 uint32_t maxSlots, uint32_t ceiling, 
+                                 uint32_t maxRetries)
 {
+  NS_LOG_FUNCTION;
   m_backoff.m_slotTime = slotTime;
   m_backoff.m_minSlots = minSlots;
   m_backoff.m_maxSlots = maxSlots;
   m_backoff.m_ceiling = ceiling;
   m_backoff.m_maxRetries = maxRetries;
 }
+
 void 
 CsmaNetDevice::AddHeader (Packet& p, Mac48Address dest,
                             uint16_t protocolNumber)
 {
+  NS_LOG_FUNCTION;
   if (m_encapMode == RAW)
     {
       return;
@@ -228,9 +256,11 @@
   trailer.CalcFcs(p);
   p.AddTrailer(trailer);
 }
+
 bool 
 CsmaNetDevice::ProcessHeader (Packet& p, uint16_t & param)
 {
+  NS_LOG_FUNCTION;
   if (m_encapMode == RAW)
     {
       return true;
@@ -269,6 +299,7 @@
 bool
 CsmaNetDevice::DoNeedsArp (void) const
 {
+  NS_LOG_FUNCTION;
   if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
     {
       return true;
@@ -285,9 +316,10 @@
   const Address& dest, 
   uint16_t protocolNumber)
 {
+  NS_LOG_FUNCTION;
   Packet p = packet;
-  NS_DEBUG ("CsmaNetDevice::SendTo (" << &p << ")");
-  NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << p.GetUid () << ")");
+  NS_LOG_LOGIC ("p=" << &p);
+  NS_LOG_LOGIC ("UID is " << p.GetUid () << ")");
 
   NS_ASSERT (IsLinkUp ());
 
@@ -320,9 +352,9 @@
 void
 CsmaNetDevice::TransmitStart ()
 {
-  NS_DEBUG ("CsmaNetDevice::TransmitStart (" << &m_currentPkt << ")");
-  NS_DEBUG ("CsmaNetDevice::TransmitStart (): UID is " 
-            << m_currentPkt.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("m_currentPkt=" << &m_currentPkt);
+  NS_LOG_LOGIC ("UID is " << m_currentPkt.GetUid ());
 //
 // This function is called to start the process of transmitting a packet.
 // We need to tell the channel that we've started wiggling the wire and
@@ -349,9 +381,8 @@
           m_backoff.IncrNumRetries();
           Time backoffTime = m_backoff.GetBackoffTime();
 
-          NS_DEBUG ("CsmaNetDevice::TransmitStart (): " 
-                    << "Channel busy, backing off for " 
-                    << backoffTime.GetSeconds () << "sec");
+          NS_LOG_LOGIC ("Channel busy, backing off for " << 
+            backoffTime.GetSeconds () << " sec");
 
           Simulator::Schedule (backoffTime, 
                                &CsmaNetDevice::TransmitStart, 
@@ -364,18 +395,16 @@
       m_txMachineState = BUSY;
       Time tEvent = Seconds (m_bps.CalculateTxTime(m_currentPkt.GetSize()));
       
-      NS_DEBUG ("CsmaNetDevice::TransmitStart (): " <<
-                "Schedule TransmitCompleteEvent in " << 
-                tEvent.GetSeconds () << "sec");
+      NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << 
+        tEvent.GetSeconds () << "sec");
       
       Simulator::Schedule (tEvent, 
                            &CsmaNetDevice::TransmitCompleteEvent, 
                            this);
       if (!m_channel->TransmitStart (m_currentPkt, m_deviceId))
         {
-          NS_DEBUG ("CsmaNetDevice::TransmitStart (): " <<
-                    "Channel transmit start did not work at " << 
-                    tEvent.GetSeconds () << "sec");
+          NS_LOG_WARN ("Channel transmit start did not work at " << 
+            tEvent.GetSeconds () << "sec");
           m_txMachineState = READY;
         } 
       else 
@@ -390,10 +419,8 @@
 void
 CsmaNetDevice::TransmitAbort (void)
 {
-  NS_DEBUG ("CsmaNetDevice::TransmitAbort ()");
-
-  NS_DEBUG ("CsmaNetDevice::TransmitAbort (): Pkt UID is " <<
-            m_currentPkt.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt.GetUid () << ")");
 
   // Try to transmit a new packet
   bool found;
@@ -407,7 +434,7 @@
 void
 CsmaNetDevice::TransmitCompleteEvent (void)
 {
-  NS_DEBUG ("CsmaNetDevice::TransmitCompleteEvent ()");
+  NS_LOG_FUNCTION;
 //
 // This function is called to finish the  process of transmitting a packet.
 // We need to tell the channel that we've stopped wiggling the wire and
@@ -419,13 +446,10 @@
   NS_ASSERT(m_channel->GetState() == TRANSMITTING);
   m_txMachineState = GAP;
 
-  NS_DEBUG ("CsmaNetDevice::TransmitCompleteEvent (): Pkt UID is " << 
-            m_currentPkt.GetUid () << ")");
+  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt.GetUid () << ")");
   m_channel->TransmitEnd (); 
 
-  NS_DEBUG (
-    "CsmaNetDevice::TransmitCompleteEvent (): " <<
-    "Schedule TransmitReadyEvent in "
+  NS_LOG_LOGIC ("Schedule TransmitReadyEvent in "
     << m_tInterframeGap.GetSeconds () << "sec");
 
   Simulator::Schedule (m_tInterframeGap, 
@@ -436,7 +460,7 @@
 void
 CsmaNetDevice::TransmitReadyEvent (void)
 {
-  NS_DEBUG ("CsmaNetDevice::TransmitReadyEvent ()");
+  NS_LOG_FUNCTION;
 //
 // This function is called to enable the transmitter after the interframe
 // gap has passed.  If there are pending transmissions, we use this opportunity
@@ -462,6 +486,7 @@
 Ptr<TraceResolver>
 CsmaNetDevice::GetTraceResolver (void) const
 {
+  NS_LOG_FUNCTION;
   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
   resolver->AddComposite ("queue", m_queue);
   resolver->AddSource ("rx",
@@ -481,7 +506,8 @@
 bool
 CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
 {
-  NS_DEBUG ("CsmaNetDevice::Attach (" << &ch << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &ch << ")");
 
   m_channel = ch;
 
@@ -499,7 +525,8 @@
 void
 CsmaNetDevice::AddQueue (Ptr<Queue> q)
 {
-  NS_DEBUG ("CsmaNetDevice::AddQueue (" << q << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << q << ")");
 
   m_queue = q;
 }
@@ -507,6 +534,8 @@
 void
 CsmaNetDevice::Receive (const Packet& packet)
 {
+  NS_LOG_FUNCTION;
+
   EthernetHeader header (false);
   EthernetTrailer trailer;
   Mac48Address broadcast;
@@ -514,7 +543,7 @@
   Mac48Address destination;
   Packet p = packet;
 
-  NS_DEBUG ("CsmaNetDevice::Receive ():  UID is " << p.GetUid());
+  NS_LOG_LOGIC ("UID is " << p.GetUid());
 
   // Only receive if send side of net device is enabled
   if (!IsReceiveEnabled())
@@ -533,8 +562,7 @@
   trailer.CheckFcs(p);
   p.RemoveHeader(header);
 
-  NS_DEBUG ("CsmaNetDevice::Receive ():  Pkt destination is " << 
-    header.GetDestination ());
+  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
 //
 // An IP host group address is mapped to an Ethernet multicast address
 // by placing the low-order 23-bits of the IP address into the low-order
@@ -560,7 +588,7 @@
       (mcDest != multicast) &&
       (header.GetDestination () != destination))
     {
-      NS_DEBUG ("CsmaNetDevice::Receive ():  Dropping pkt ");
+      NS_LOG_LOGIC ("Dropping pkt ");
       m_dropTrace (p);
       return;
     }
@@ -595,15 +623,14 @@
 Address
 CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
 {
-  NS_DEBUG ("CsmaNetDevice::MakeMulticastAddress (" << multicastGroup <<
-    ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << multicastGroup << ")");
 //
 // First, get the generic multicast address.
 //
   Address hardwareDestination = GetMulticast ();
 
-  NS_DEBUG ("CsmaNetDevice::MakeMulticastAddress (): "
-    "Device multicast address: " << hardwareDestination);
+  NS_LOG_LOGIC ("Device multicast address: " << hardwareDestination);
 //
 // It's our address, and we know we're playing with an EUI-48 address here
 // primarily since we know that by construction, but also since the parameter
@@ -641,8 +668,7 @@
 // use it by just returning the EUI-48 address which is automagically converted
 // to an Address.
 //
-  NS_DEBUG ("CsmaNetDevice::MakeMulticastAddress (): "
-    "multicast address is " << etherAddr);
+  NS_LOG_LOGIC ("multicast address is " << etherAddr);
 
   return etherAddr;
 }
@@ -650,13 +676,15 @@
 Ptr<Queue>
 CsmaNetDevice::GetQueue(void) const 
 { 
-    return m_queue;
+  NS_LOG_FUNCTION;
+  return m_queue;
 }
 
 Ptr<Channel>
 CsmaNetDevice::DoGetChannel(void) const 
 { 
-    return m_channel;
+  NS_LOG_FUNCTION;
+  return m_channel;
 }
 
 } // namespace ns3
--- a/src/devices/csma/csma-topology.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/csma/csma-topology.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -22,7 +22,6 @@
 // Topology helper for Csma channels in ns3.
 
 #include "ns3/assert.h"
-#include "ns3/debug.h"
 #include "ns3/queue.h"
 
 #include "csma-channel.h"
--- a/src/devices/point-to-point/point-to-point-channel.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/point-to-point/point-to-point-channel.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -23,9 +23,9 @@
 #include "point-to-point-net-device.h"
 #include "ns3/packet.h"
 #include "ns3/simulator.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("PointToPointChannel");
+NS_LOG_COMPONENT_DEFINE ("PointToPointChannel");
 
 namespace ns3 {
 
@@ -39,7 +39,7 @@
   m_delay (Seconds(0)),
   m_nDevices(0)
 {
-  NS_DEBUG("PointToPointChannel::PointToPointChannel ()");
+  NS_LOG_FUNCTION;
 }
 
 PointToPointChannel::PointToPointChannel(
@@ -51,8 +51,9 @@
   m_delay (delay),
   m_nDevices(0)
 {
-  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() 
-    << ", " << bps.GetBitRate() << ", " << delay << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << 
+    ", " << delay << ")");
 }
 
 PointToPointChannel::PointToPointChannel(
@@ -65,14 +66,16 @@
   m_delay (delay),
   m_nDevices(0)
 {
-  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << 
-    bps.GetBitRate() << ", " << delay << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << 
+    delay << ")");
 }
 
-  void
+void
 PointToPointChannel::Attach(Ptr<PointToPointNetDevice> device)
 {
-  NS_DEBUG("PointToPointChannel::Attach (" << device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << device << ")");
   NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted");
   NS_ASSERT(device != 0);
 
@@ -90,14 +93,14 @@
     }
 }
 
-bool PointToPointChannel::TransmitStart(Packet& p,
+bool
+PointToPointChannel::TransmitStart(Packet& p,
                                         Ptr<PointToPointNetDevice> src,
                                         const Time& txTime)
 {
-  NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << 
-            ")");
-  NS_DEBUG ("PointToPointChannel::TransmitStart (): UID is " << 
-            p.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << src << ")");
+  NS_LOG_LOGIC ("UID is " << p.GetUid () << ")");
 
   NS_ASSERT(m_link[0].m_state != INITIALIZING);
   NS_ASSERT(m_link[1].m_state != INITIALIZING);
@@ -116,12 +119,14 @@
 uint32_t 
 PointToPointChannel::GetNDevices (void) const
 {
+  NS_LOG_FUNCTION;
   return m_nDevices;
 }
 
 Ptr<NetDevice>
 PointToPointChannel::GetDevice (uint32_t i) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT(i < 2);
   return m_link[i].m_src;
 }
@@ -129,12 +134,14 @@
 const DataRate&
 PointToPointChannel::GetDataRate (void)
 {
+  NS_LOG_FUNCTION;
   return m_bps;
 }
 
 const Time&
 PointToPointChannel::GetDelay (void)
 {
+  NS_LOG_FUNCTION;
   return m_delay;
 }
 
--- a/src/devices/point-to-point/point-to-point-net-device.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/point-to-point/point-to-point-net-device.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,7 +20,7 @@
  * Revised: George Riley <riley@ece.gatech.edu>
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/queue.h"
 #include "ns3/simulator.h"
 #include "ns3/composite-trace-resolver.h"
@@ -29,7 +29,7 @@
 #include "point-to-point-net-device.h"
 #include "point-to-point-channel.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice");
+NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice");
 
 namespace ns3 {
 
@@ -39,21 +39,27 @@
            DataRate ("10Mb/s"));
 
 PointToPointTraceType::PointToPointTraceType ()
-{}
+{
+  NS_LOG_FUNCTION;
+}
 void 
 PointToPointTraceType::Print (std::ostream &os) const
 {
   os << "dev-rx";
 }
+
 uint16_t 
 PointToPointTraceType::GetUid (void)
 {
+  NS_LOG_FUNCTION;
   static uint16_t uid = AllocateUid<PointToPointTraceType> ("PointToPointTraceType");
   return uid;
 }
+
 std::string 
 PointToPointTraceType::GetTypeName (void) const
 {
+  NS_LOG_FUNCTION;
   return "ns3::PointToPointTraceType";
 }
 
@@ -69,11 +75,13 @@
   m_queue (0),
   m_rxTrace ()
 {
-  NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << node << ")");
-
-// BUGBUG FIXME
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << node << ")");
+//
+// XXX BUGBUG
 //
 // You _must_ support broadcast to get any sort of packet from the ARP layer.
+//
   EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff"));
 //
 // We want to allow multicast packets to flow across this link
@@ -84,13 +92,14 @@
 
 PointToPointNetDevice::~PointToPointNetDevice()
 {
-  NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()");
+  NS_LOG_FUNCTION;
   m_queue = 0;
 }
 
 void 
 PointToPointNetDevice::AddHeader(Packet& p, uint16_t protocolNumber)
 {
+  NS_LOG_FUNCTION;
   LlcSnapHeader llc;
   llc.SetType (protocolNumber);
   p.AddHeader (llc);
@@ -99,6 +108,7 @@
 bool 
 PointToPointNetDevice::ProcessHeader(Packet& p, uint16_t& param)
 {
+  NS_LOG_FUNCTION;
   LlcSnapHeader llc;
   p.RemoveHeader (llc);
 
@@ -109,26 +119,30 @@
 
 void PointToPointNetDevice::DoDispose()
 {
+  NS_LOG_FUNCTION;
   m_channel = 0;
   NetDevice::DoDispose ();
 }
 
 void PointToPointNetDevice::SetDataRate(const DataRate& bps)
 {
+  NS_LOG_FUNCTION;
   m_bps = bps;
 }
 
 void PointToPointNetDevice::SetInterframeGap(const Time& t)
 {
+  NS_LOG_FUNCTION;
   m_tInterframeGap = t;
 }
 
 bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, 
                                     uint16_t protocolNumber)
 {
+  NS_LOG_FUNCTION;
   Packet p = packet;
-  NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
-  NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
+  NS_LOG_LOGIC ("p=" << &p << ", dest=" << &dest);
+  NS_LOG_LOGIC ("UID is " << p.GetUid ());
 
   // GFR Comment. Why is this an assertion? Can't a link legitimately
   // "go down" during the simulation?  Shouldn't we just wait for it
@@ -142,9 +156,12 @@
 //
 //
 // If there's a transmission in progress, we enque the packet for later
-// trnsmission; otherwise we send it now.
+// transmission; otherwise we send it now.
   if (m_txMachineState == READY) 
     {
+// We still enqueue and dequeue it to hit the tracing hooks
+      m_queue->Enqueue (p);
+      m_queue->Dequeue (p);
       return TransmitStart (p);
     }
   else
@@ -156,9 +173,9 @@
   bool
 PointToPointNetDevice::TransmitStart (Packet &p)
 {
-  NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
-  NS_DEBUG (
-    "PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
+  NS_LOG_LOGIC ("UID is " << p.GetUid () << ")");
 //
 // This function is called to start the process of transmitting a packet.
 // We need to tell the channel that we've started wiggling the wire and
@@ -169,8 +186,7 @@
   Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize()));
   Time txCompleteTime = txTime + m_tInterframeGap;
 
-  NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " <<
-    "Schedule TransmitCompleteEvent in " << 
+  NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << 
     txCompleteTime.GetSeconds () << "sec");
   // Schedule the tx complete event
   Simulator::Schedule (txCompleteTime, 
@@ -181,7 +197,7 @@
 
 void PointToPointNetDevice::TransmitComplete (void)
 {
-  NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()");
+  NS_LOG_FUNCTION;
 //
 // This function is called to finish the  process of transmitting a packet.
 // We need to tell the channel that we've stopped wiggling the wire and
@@ -198,6 +214,7 @@
 Ptr<TraceResolver> 
 PointToPointNetDevice::GetTraceResolver (void) const
 {
+  NS_LOG_FUNCTION;
   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
   resolver->AddComposite ("queue", m_queue);
   resolver->AddSource ("rx",
@@ -209,9 +226,11 @@
   return resolver;
 }
 
-bool PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
+bool 
+PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
 {
-  NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &ch << ")");
 
   m_channel = ch;
 
@@ -237,14 +256,16 @@
 
 void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
 {
-  NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << q << ")");
 
   m_queue = q;
 }
 
 void PointToPointNetDevice::Receive (Packet& p)
 {
-  NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
   uint16_t protocol = 0;
   Packet packet = p;
 
@@ -255,16 +276,19 @@
 
 Ptr<Queue> PointToPointNetDevice::GetQueue(void) const 
 { 
-    return m_queue;
+  NS_LOG_FUNCTION;
+  return m_queue;
 }
 
 Ptr<Channel> PointToPointNetDevice::DoGetChannel(void) const 
 { 
-    return m_channel;
+  NS_LOG_FUNCTION;
+  return m_channel;
 }
 
 bool PointToPointNetDevice::DoNeedsArp (void) const
 {
+  NS_LOG_FUNCTION;
   return false;
 }
 
--- a/src/devices/point-to-point/point-to-point-topology.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/devices/point-to-point/point-to-point-topology.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -24,7 +24,7 @@
 
 #include <algorithm>
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/fatal-error.h"
 #include "ns3/nstime.h"
 #include "ns3/internet-node.h"
--- a/src/internet-node/arp-ipv4-interface.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/arp-ipv4-interface.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -21,7 +21,7 @@
  */
 
 #include "ns3/packet.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/composite-trace-resolver.h"
 #include "ns3/node.h"
 #include "ns3/net-device.h"
@@ -31,7 +31,7 @@
 #include "ipv4-l3-protocol.h"
 #include "arp-l3-protocol.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("ArpIpv4Interface");
+NS_LOG_COMPONENT_DEFINE ("ArpIpv4Interface");
 
 namespace ns3 {
 
@@ -39,18 +39,18 @@
   : Ipv4Interface (device),
     m_node (node)
 {
-  NS_DEBUG ("ArpIpv4Interface::ArpIpv4Interface ()");
+  NS_LOG_FUNCTION;
 }
 
 ArpIpv4Interface::~ArpIpv4Interface ()
 {
-  NS_DEBUG ("ArpIpv4Interface::~ArpIpv4Interface ()");
+  NS_LOG_FUNCTION;
 }
 
 Ptr<TraceResolver>
 ArpIpv4Interface::GetTraceResolver (void) const
 {
-  NS_DEBUG ("ArpIpv4Interface::DoCreateTraceResolver ()");
+  NS_LOG_FUNCTION;
   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
   if (GetDevice () != 0)
     {
@@ -63,12 +63,13 @@
 void 
 ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
 {
-  NS_DEBUG ("ArpIpv4Interface::SendTo (" << &p << ", " << dest << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << dest << ")");
 
   NS_ASSERT (GetDevice () != 0);
   if (GetDevice ()->NeedsArp ())
     {
-      NS_DEBUG ("ArpIpv4Interface::SendTo (): Needs ARP");
+      NS_LOG_LOGIC ("Needs ARP");
       Ptr<ArpL3Protocol> arp = 
         m_node->QueryInterface<ArpL3Protocol> (ArpL3Protocol::iid);
       Address hardwareDestination;
@@ -77,13 +78,13 @@
       if (dest.IsBroadcast () || 
           dest.IsSubnetDirectedBroadcast (GetNetworkMask ()) )
         {
-          NS_DEBUG ("ArpIpv4Interface::SendTo (): IsBroadcast");
+          NS_LOG_LOGIC ("IsBroadcast");
           hardwareDestination = GetDevice ()->GetBroadcast ();
           found = true;
         }
       else if (dest.IsMulticast ())
         {
-          NS_DEBUG ("ArpIpv4Interface::SendTo (): IsMulticast");
+          NS_LOG_LOGIC ("IsMulticast");
           NS_ASSERT_MSG(GetDevice ()->IsMulticast (),
             "ArpIpv4Interface::SendTo (): Sending multicast packet over "
             "non-multicast device");
@@ -93,20 +94,20 @@
         }
       else
         {
-          NS_DEBUG ("ArpIpv4Interface::SendTo (): ARP Lookup");
+          NS_LOG_LOGIC ("ARP Lookup");
           found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
         }
 
       if (found)
         {
-          NS_DEBUG ("ArpIpv4Interface::SendTo (): Address Resolved.  Send.");
+          NS_LOG_LOGIC ("Address Resolved.  Send.");
           GetDevice ()->Send (p, hardwareDestination, 
             Ipv4L3Protocol::PROT_NUMBER);
         }
     }
   else
     {
-      NS_DEBUG ("ArpIpv4Interface::SendTo (): Doesn't need ARP");
+      NS_LOG_LOGIC ("Doesn't need ARP");
       GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), 
         Ipv4L3Protocol::PROT_NUMBER);
     }
--- a/src/internet-node/arp-l3-protocol.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/arp-l3-protocol.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,7 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "ns3/packet.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/node.h"
 #include "ns3/net-device.h"
 
@@ -29,7 +29,7 @@
 #include "arp-cache.h"
 #include "ipv4-interface.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("ArpL3Protocol");
+NS_LOG_COMPONENT_DEFINE ("ArpL3Protocol");
 
 namespace ns3 {
 
@@ -39,15 +39,19 @@
 ArpL3Protocol::ArpL3Protocol (Ptr<Node> node)
   : m_node (node)
 {
+  NS_LOG_FUNCTION;
   SetInterfaceId (ArpL3Protocol::iid);
 }
 
 ArpL3Protocol::~ArpL3Protocol ()
-{}
+{
+  NS_LOG_FUNCTION;
+}
 
 void 
 ArpL3Protocol::DoDispose (void)
 {
+  NS_LOG_FUNCTION;
   for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
     {
       delete *i;
@@ -60,6 +64,7 @@
 ArpCache *
 ArpL3Protocol::FindCache (Ptr<NetDevice> device)
 {
+  NS_LOG_FUNCTION;
   for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
     {
       if ((*i)->GetDevice () == device)
@@ -79,12 +84,13 @@
 void 
 ArpL3Protocol::Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
 {
+  NS_LOG_FUNCTION;
   ArpCache *cache = FindCache (device);
   ArpHeader arp;
   Packet packet = p;
   packet.RemoveHeader (arp);
   
-  NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
+  NS_LOG_LOGIC ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
             " node="<<m_node->GetId ()<<", got request from " <<
             arp.GetSourceIpv4Address () << " for address " <<
             arp.GetDestinationIpv4Address () << "; we have address " <<
@@ -93,7 +99,7 @@
   if (arp.IsRequest () && 
       arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
     {
-      NS_DEBUG ("node="<<m_node->GetId () <<", got request from " << 
+      NS_LOG_LOGIC ("node="<<m_node->GetId () <<", got request from " << 
                 arp.GetSourceIpv4Address () << " -- send reply");
       SendArpReply (cache, arp.GetSourceIpv4Address (),
                     arp.GetSourceHardwareAddress ());
@@ -108,7 +114,7 @@
         {
           if (entry->IsWaitReply ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply from " << 
                         arp.GetSourceIpv4Address ()
                      << " for waiting entry -- flush");
               Address from_mac = arp.GetSourceHardwareAddress ();
@@ -119,7 +125,7 @@
             {
               // ignore this reply which might well be an attempt 
               // at poisening my arp cache.
-              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
+              NS_LOG_LOGIC("node="<<m_node->GetId ()<<", got reply from " << 
                         arp.GetSourceIpv4Address () << 
                         " for non-waiting entry -- drop");
 	      // XXX report packet as dropped.
@@ -127,13 +133,13 @@
         } 
       else 
         {
-          NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
+          NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
 	  // XXX report packet as dropped.
         }
     }
   else
     {
-      NS_DEBUG ("node="<<m_node->GetId ()<<", got request from " <<
+      NS_LOG_LOGIC ("node="<<m_node->GetId ()<<", got request from " <<
                 arp.GetSourceIpv4Address () << " for unknown address " <<
                 arp.GetDestinationIpv4Address () << " -- drop");
     }
@@ -143,6 +149,7 @@
                        Ptr<NetDevice> device,
                        Address *hardwareDestination)
 {
+  NS_LOG_FUNCTION;
   ArpCache *cache = FindCache (device);
   ArpCache::Entry *entry = cache->Lookup (destination);
   if (entry != 0)
@@ -151,21 +158,21 @@
         {
           if (entry->IsDead ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", dead entry for " << destination << " expired -- send arp request");
               entry->MarkWaitReply (packet);
               SendArpRequest (cache, destination);
             } 
           else if (entry->IsAlive ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", alive entry for " << destination << " expired -- send arp request");
               entry->MarkWaitReply (packet);
               SendArpRequest (cache, destination);
             } 
           else if (entry->IsWaitReply ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", wait reply for " << destination << " expired -- drop");
               entry->MarkDead ();
 	      // XXX report packet as 'dropped'
@@ -175,20 +182,20 @@
         {
           if (entry->IsDead ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", dead entry for " << destination << " valid -- drop");
 	      // XXX report packet as 'dropped'
             } 
           else if (entry->IsAlive ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", alive entry for " << destination << " valid -- send");
 	      *hardwareDestination = entry->GetMacAddress ();
               return true;
             } 
           else if (entry->IsWaitReply ()) 
             {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
+              NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                         ", wait reply for " << destination << " valid -- drop previous");
               Packet old = entry->UpdateWaitReply (packet);
 	      // XXX report 'old' packet as 'dropped'
@@ -199,7 +206,7 @@
   else
     {
       // This is our first attempt to transmit data to this destination.
-      NS_DEBUG ("node="<<m_node->GetId ()<<
+      NS_LOG_LOGIC ("node="<<m_node->GetId ()<<
                 ", no entry for " << destination << " -- send arp request");
       entry = cache->Add (destination);
       entry->MarkWaitReply (packet);
@@ -211,8 +218,9 @@
 void
 ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to)
 {
+  NS_LOG_FUNCTION;
   ArpHeader arp;
-  NS_DEBUG ("ARP: sending request from node "<<m_node->GetId ()<<
+  NS_LOG_LOGIC ("ARP: sending request from node "<<m_node->GetId ()<<
             " || src: " << cache->GetDevice ()->GetAddress () <<
             " / " << cache->GetInterface ()->GetAddress () <<
             " || dst: " << cache->GetDevice ()->GetBroadcast () <<
@@ -229,8 +237,9 @@
 void
 ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac)
 {
+  NS_LOG_FUNCTION;
   ArpHeader arp;
-  NS_DEBUG ("ARP: sending reply from node "<<m_node->GetId ()<<
+  NS_LOG_LOGIC ("ARP: sending reply from node "<<m_node->GetId ()<<
             "|| src: " << cache->GetDevice ()->GetAddress () << 
             " / " << cache->GetInterface ()->GetAddress () <<
             " || dst: " << toMac << " / " << toIp);
--- a/src/internet-node/ipv4-end-point-demux.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-end-point-demux.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -21,18 +21,21 @@
 
 #include "ipv4-end-point-demux.h"
 #include "ipv4-end-point.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 namespace ns3{
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4EndPointDemux");
+NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux");
 
 Ipv4EndPointDemux::Ipv4EndPointDemux ()
-  : m_ephemeral (1025)
-{}
+  : m_ephemeral (49152)
+{
+  NS_LOG_FUNCTION;
+}
 
 Ipv4EndPointDemux::~Ipv4EndPointDemux ()
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       Ipv4EndPoint *endPoint = *i;
@@ -44,6 +47,7 @@
 bool
 Ipv4EndPointDemux::LookupPortLocal (uint16_t port)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort  () == port) 
@@ -57,6 +61,7 @@
 bool
 Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort () == port &&
@@ -71,44 +76,49 @@
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (void)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate ()");
+  NS_LOG_FUNCTION;
   uint16_t port = AllocateEphemeralPort ();
   if (port == 0) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate ephemeral port allocation failed.");
+      NS_LOG_WARN ("Ephemeral port allocation failed.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
   m_endPoints.push_back (endPoint);
   return endPoint;
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (Ipv4Address address)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (address=" << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ")");
   uint16_t port = AllocateEphemeralPort ();
   if (port == 0) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate ephemeral port allocation failed.");
+      NS_LOG_WARN ("Ephemeral port allocation failed.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
   m_endPoints.push_back (endPoint);
   return endPoint;
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (uint16_t port)
 {
+  NS_LOG_FUNCTION;
   return Allocate (Ipv4Address::GetAny (), port);
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (address=" << address
-            << ", port=" << port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ", " << port << ")");
   if (LookupLocal (address, port)) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate duplicate address/port; failing.");
+      NS_LOG_WARN ("Duplicate address/port; failing.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
@@ -120,10 +130,11 @@
 Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
 			     Ipv4Address peerAddress, uint16_t peerPort)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (localAddress=" << localAddress
-            << ", localPort=" << localPort
-            << ", peerAddress=" << peerAddress
-            << ", peerPort=" << peerPort << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(localAddress=" << localAddress
+    << ", localPort=" << localPort
+    << ", peerAddress=" << peerAddress
+    << ", peerPort=" << peerPort << ")");
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort () == localPort &&
@@ -131,7 +142,7 @@
           (*i)->GetPeerPort () == peerPort &&
           (*i)->GetPeerAddress () == peerAddress) 
         {
-          NS_DEBUG ("Ipv4EndPointDemux::Allocate: no way we can allocate this end-point.");
+          NS_LOG_WARN ("No way we can allocate this end-point.");
           /* no way we can allocate this end-point. */
           return 0;
         }
@@ -145,6 +156,7 @@
 void 
 Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if (*i == endPoint)
@@ -156,7 +168,6 @@
     }
 }
 
-
 /*
  * If we have an exact match, we return it.
  * Otherwise, if we find a generic match, we return it.
@@ -166,40 +177,42 @@
 Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
                            Ipv4Address saddr, uint16_t sport)
 {
+  NS_LOG_FUNCTION;
   uint32_t genericity = 3;
   Ipv4EndPoint *generic = 0;
   EndPoints retval;
 
-  NS_DEBUG ("Ipv4EndPointDemux::Lookup (daddr=" << daddr << ", dport=" << dport
-            << ", saddr=" << saddr << ", sport=" << sport
-            << ")");
+  NS_LOG_PARAM ("(daddr=" << daddr << ", dport=" << dport
+    << ", saddr=" << saddr << ", sport=" << sport << ")");
+
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup against " << 
-                (*i)->GetLocalAddress ()
-                << ":" << 
-                (*i)->GetLocalPort () 
-                << " " << 
-                (*i)->GetPeerAddress () 
-                << ":" 
-                << (*i)->GetPeerPort ());
+      NS_LOG_LOGIC ("Ipv4EndPointDemux::Lookup against " << 
+                    (*i)->GetLocalAddress ()
+                    << ":" << 
+                    (*i)->GetLocalPort () 
+                    << " " << 
+                    (*i)->GetPeerAddress () 
+                    << ":" 
+                    << (*i)->GetPeerPort ());
+
       if ((*i)->GetLocalPort () != dport) 
         {
           continue;
         }
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup local address matches: "
-                << bool ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ()));
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup peer port matches: "
-                << bool ((*i)->GetPeerPort () == sport || sport == 0));
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup peer address matches: "
-                << bool ((*i)->GetPeerAddress () == saddr ||
-                         (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
+      NS_LOG_LOGIC ("Local address matches: " << 
+        bool ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ()));
+      NS_LOG_LOGIC ("Peer port matches: " << 
+        bool ((*i)->GetPeerPort () == sport || sport == 0));
+      NS_LOG_LOGIC ("Peer address matches: " << 
+        bool ((*i)->GetPeerAddress () == saddr ||
+        (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
       
       if ( ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ())
            && ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0)
            && ((*i)->GetPeerAddress () == saddr || (*i)->GetPeerAddress () == Ipv4Address::GetAny ()))
         {
-          NS_DEBUG ("Ipv4EndPointDemux::Lookup MATCH");
+          NS_LOG_LOGIC ("MATCH");
           /* this is an exact match. */
           retval.push_back (*i);
         }
@@ -228,13 +241,14 @@
 uint16_t
 Ipv4EndPointDemux::AllocateEphemeralPort (void)
 {
+  NS_LOG_FUNCTION;
   uint16_t port = m_ephemeral;
   do 
     {
       port++;
-      if (port > 5000) 
+      if (port == 65535) 
         {
-          port = 1024;
+          port = 49152;
         }
       if (!LookupPortLocal (port)) 
         {
--- a/src/internet-node/ipv4-header.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-header.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,11 +20,11 @@
  */
 
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/header.h"
 #include "ipv4-header.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header");
+NS_LOG_COMPONENT_DEFINE ("Ipv4Header");
 
 namespace ns3 {
 
@@ -271,7 +271,7 @@
       uint8_t *data = start.PeekData ();
       uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
       checksum = UtilsChecksumComplete (checksum);
-      NS_DEBUG ("checksum=" <<checksum);
+      NS_LOG_LOGIC ("checksum=" <<checksum);
       i = start;
       i.Next (10);
       i.WriteU16 (checksum);
--- a/src/internet-node/ipv4-interface.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-interface.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -23,9 +23,9 @@
 #include "ns3/ipv4-address.h"
 #include "ns3/net-device.h"
 #include "ns3/trace-resolver.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4Interface");
+NS_LOG_COMPONENT_DEFINE ("Ipv4Interface");
 
 namespace ns3 {
 
@@ -39,17 +39,19 @@
   : m_netdevice (nd), 
     m_ifup(false)
 {
-  NS_DEBUG ("Ipv4Interface::Ipv4Interface (" << &nd << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &nd << ")");
 }
 
 Ipv4Interface::~Ipv4Interface ()
 {
-  NS_DEBUG ("Ipv4Interface::~Ipv4Interface ()");
+  NS_LOG_FUNCTION;
 }
 
 void
 Ipv4Interface::DoDispose (void)
 {
+  NS_LOG_FUNCTION;
   m_netdevice = 0;
   Object::DoDispose ();
 }
@@ -57,29 +59,30 @@
 Ptr<NetDevice>
 Ipv4Interface::GetDevice (void) const
 {
-  NS_DEBUG ("Ipv4Interface::GetDevice ()");
+  NS_LOG_FUNCTION;
   return m_netdevice;
 }
 
 void 
 Ipv4Interface::SetAddress (Ipv4Address a)
 {
-  NS_DEBUG ("Ipv4Interface::SetAddress (" << a << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << a << ")");
   m_address = a;
 }
 
 void 
 Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
 {
-  NS_DEBUG ("Ipv4Interface::SetMask (" << mask << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << mask << ")");
   m_netmask = mask;
 }
 
 Ipv4Address
 Ipv4Interface::GetBroadcast (void) const
 {
-  NS_DEBUG ("Ipv4Interface::GetBroadcast ()");
-
+  NS_LOG_FUNCTION;
   uint32_t mask = m_netmask.GetHostOrder ();
   uint32_t address = m_address.GetHostOrder ();
   Ipv4Address broadcast = Ipv4Address (address | (~mask));
@@ -89,21 +92,21 @@
 Ipv4Mask 
 Ipv4Interface::GetNetworkMask (void) const
 {
-  NS_DEBUG ("Ipv4Interface::GetNetworkMask ()");
+  NS_LOG_FUNCTION;
   return m_netmask;
 }
 
 Ipv4Address 
 Ipv4Interface::GetAddress (void) const
 {
-  NS_DEBUG ("Ipv4Interface::Address ()");
+  NS_LOG_FUNCTION;
   return m_address;
 }
 
 uint16_t 
 Ipv4Interface::GetMtu (void) const
 {
-  NS_DEBUG ("Ipv4Interface::GetMtu ()");
+  NS_LOG_FUNCTION;
   if (m_netdevice == 0)
     {
       uint32_t mtu = (1<<16) - 1;
@@ -120,28 +123,28 @@
 bool 
 Ipv4Interface::IsUp (void) const
 {
-  NS_DEBUG ("Ipv4Interface::IsUp ()");
+  NS_LOG_FUNCTION;
   return m_ifup;
 }
 
 bool 
 Ipv4Interface::IsDown (void) const
 {
-  NS_DEBUG ("Ipv4Interface::IsDown ()");
+  NS_LOG_FUNCTION;
   return !m_ifup;
 }
 
 void 
 Ipv4Interface::SetUp (void)
 {
-  NS_DEBUG ("Ipv4Interface::SetUp ()");
+  NS_LOG_FUNCTION;
   m_ifup = true;
 }
 
 void 
 Ipv4Interface::SetDown (void)
 {
-  NS_DEBUG ("Ipv4Interface::SetDown ()");
+  NS_LOG_FUNCTION;
   m_ifup = false;
 }
 
@@ -149,10 +152,9 @@
 void 
 Ipv4Interface::Send(Packet p, Ipv4Address dest)
 {
-  NS_DEBUG ("Ipv4Interface::Send ()");
-
+  NS_LOG_FUNCTION;
   if (IsUp()) {
-    NS_DEBUG ("Ipv4Interface::Send (): SendTo ()");
+    NS_LOG_LOGIC ("SendTo");
     SendTo(p, dest);
   }
 }
--- a/src/internet-node/ipv4-l3-protocol.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-l3-protocol.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,7 +20,7 @@
 //
 
 #include "ns3/packet.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/composite-trace-resolver.h"
 #include "ns3/callback.h"
 #include "ns3/ipv4-address.h"
@@ -36,7 +36,7 @@
 #include "arp-ipv4-interface.h"
 #include "ipv4-l4-demux.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4L3Protocol");
+NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
 
 namespace ns3 {
 
@@ -45,28 +45,41 @@
 
 Ipv4L3ProtocolTraceContextElement::Ipv4L3ProtocolTraceContextElement ()
   : m_type (TX)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 Ipv4L3ProtocolTraceContextElement::Ipv4L3ProtocolTraceContextElement (enum Type type)
   : m_type (type)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 bool 
 Ipv4L3ProtocolTraceContextElement::IsTx (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == TX;
 }
+
 bool 
 Ipv4L3ProtocolTraceContextElement::IsRx (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == RX;
 }
+
 bool 
 Ipv4L3ProtocolTraceContextElement::IsDrop (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == DROP;
 }
+
 void 
 Ipv4L3ProtocolTraceContextElement::Print (std::ostream &os) const
 {
+  NS_LOG_FUNCTION;
   os << "ipv4=";
   switch (m_type)
     {
@@ -81,44 +94,59 @@
       break;
     }
 }
+
 uint16_t 
 Ipv4L3ProtocolTraceContextElement::GetUid (void)
 {
+  NS_LOG_FUNCTION;
   static uint16_t uid = AllocateUid<Ipv4L3ProtocolTraceContextElement> ("Ipv4L3ProtocolTraceContextElement");
   return uid;
 }
+
 std::string 
 Ipv4L3ProtocolTraceContextElement::GetTypeName (void) const
 {
+  NS_LOG_FUNCTION;
   return "ns3::Ipv4L3ProtocolTraceContextElement";
 }
 
-
 Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex ()
   : m_index (0)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex (uint32_t index)
   : m_index (index)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 uint32_t 
 Ipv4L3ProtocolInterfaceIndex::Get (void) const
 {
+  NS_LOG_FUNCTION;
   return m_index;
 }
+
 void 
 Ipv4L3ProtocolInterfaceIndex::Print (std::ostream &os) const
 {
   os << "ipv4-interface=" << m_index;
 }
+
 uint16_t 
 Ipv4L3ProtocolInterfaceIndex::GetUid (void)
 {
+  NS_LOG_FUNCTION;
   static uint16_t uid = AllocateUid<Ipv4L3ProtocolInterfaceIndex> ("Ipv4L3ProtocolInterfaceIndex");
   return uid;
 }
+
 std::string
 Ipv4L3ProtocolInterfaceIndex::GetTypeName (void) const
 {
+  NS_LOG_FUNCTION;
   return "ns3::Ipv4L3ProtocolInterfaceIndex";
 }
 
@@ -129,8 +157,7 @@
     m_identification (0),
     m_node (node)
 {
-  NS_DEBUG("Ipv4L3Protocol::Ipv4L3Protocol ()");
-
+  NS_LOG_FUNCTION;
   SetInterfaceId (Ipv4L3Protocol::iid);
   m_staticRouting = Create<Ipv4StaticRouting> ();
   AddRoutingProtocol (m_staticRouting, 0);
@@ -139,14 +166,13 @@
 
 Ipv4L3Protocol::~Ipv4L3Protocol ()
 {
-  NS_DEBUG("Ipv4L3Protocol::~Ipv4L3Protocol ()");
+  NS_LOG_FUNCTION;
 }
 
 void 
 Ipv4L3Protocol::DoDispose (void)
 {
-  NS_DEBUG("Ipv4L3Protocol::DoDispose ()");
-
+  NS_LOG_FUNCTION;
   m_interfaces.clear ();
   m_node = 0;
   m_staticRouting->Dispose ();
@@ -157,7 +183,7 @@
 void
 Ipv4L3Protocol::SetupLoopback (void)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetupLoopback ()");
+  NS_LOG_FUNCTION;
 
   Ptr<Ipv4LoopbackInterface> interface = Create<Ipv4LoopbackInterface> (m_node);
   interface->SetAddress (Ipv4Address::GetLoopback ());
@@ -170,7 +196,7 @@
 Ptr<TraceResolver>
 Ipv4L3Protocol::GetTraceResolver (void) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetTraceResolver ()");
+  NS_LOG_FUNCTION;
 
   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
   resolver->AddSource ("tx", 
@@ -196,7 +222,7 @@
 void 
 Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetDefaultTtl ()");
+  NS_LOG_FUNCTION;
   m_defaultTtl = ttl;
 }
     
@@ -206,8 +232,8 @@
                       Ipv4Address nextHop, 
                       uint32_t interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddHostRouteTo (" << dest << ", " << nextHop <<
-    ", " << interface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << dest << ", " << nextHop << ", " << interface << ")");
   m_staticRouting->AddHostRouteTo (dest, nextHop, interface);
 }
 
@@ -215,8 +241,8 @@
 Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, 
 				uint32_t interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddHostRouteTo (" << dest << ", " << 
-    interface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << dest << ", " << interface << ")");
   m_staticRouting->AddHostRouteTo (dest, interface);
 }
 
@@ -226,25 +252,29 @@
 				   Ipv4Address nextHop, 
 				   uint32_t interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddNetworkRouteTo (" << network << ", " << 
-    networkMask << ", " << nextHop << ", " << interface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << nextHop << 
+    ", " << interface << ")");
   m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface);
 }
+
 void 
 Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 
 				   Ipv4Mask networkMask, 
 				   uint32_t interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddNetworkRouteTo (" << network << ", " << 
-    networkMask << ", " << interface << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << interface << 
+    ")");
   m_staticRouting->AddNetworkRouteTo (network, networkMask, interface);
 }
+
 void 
 Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, 
 				 uint32_t interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetDefaultRoute (" << nextHop << ", " << 
-    interface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << nextHop << ", " << interface << ")");
   m_staticRouting->SetDefaultRoute (nextHop, interface);
 }
 
@@ -254,8 +284,8 @@
   Packet packet,
   Ipv4RoutingProtocol::RouteReplyCallback routeReply)
 {
-  NS_DEBUG("Ipv4L3Protocol::Lookup (" << &ipHeader << 
-    ", " << &packet << &routeReply << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &ipHeader << ", " << &packet << &routeReply << ")");
 
   Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
 }
@@ -267,15 +297,16 @@
   Packet packet,
   Ipv4RoutingProtocol::RouteReplyCallback routeReply)
 {
-  NS_DEBUG("Ipv4L3Protocol::Lookup (" << ifIndex << ", " << &ipHeader << 
-    ", " << &packet << &routeReply << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << ifIndex << ", " << &ipHeader << ", " << &packet << 
+    &routeReply << ")");
 
   for (Ipv4RoutingProtocolList::const_iterator rprotoIter = 
          m_routingProtocols.begin ();
        rprotoIter != m_routingProtocols.end (); 
        rprotoIter++)
     {
-      NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting route");
+      NS_LOG_LOGIC ("Requesting route");
       if ((*rprotoIter).second->RequestRoute (ifIndex, ipHeader, packet, 
                                               routeReply))
         return;
@@ -284,8 +315,7 @@
   if (ipHeader.GetDestination ().IsMulticast () && 
       ifIndex == Ipv4RoutingProtocol::IF_INDEX_ANY)
     {
-      NS_DEBUG ("Ipv4L3Protocol::Lookup (): "
-        "Multicast destination with local source");
+      NS_LOG_LOGIC ("Multicast destination with local source");
 //
 // We have a multicast packet originating from the current node and were not
 // able to send it using the usual RequestRoute process.  Since the usual
@@ -300,8 +330,8 @@
 
       if (route)
         {
-          NS_DEBUG ("Ipv4StaticRouting::Lookup (): "
-            "Local source. Using unicast default route for multicast packet");
+          NS_LOG_LOGIC ("Local source. Using unicast default route for "
+            "multicast packet");
 
           routeReply (true, *route, packet, ipHeader);
           return;
@@ -317,8 +347,8 @@
 Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
                                     int priority)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddRoutingProtocol (" << &routingProtocol << 
-    ", " << priority << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &routingProtocol << ", " << priority << ")");
   m_routingProtocols.push_back
     (std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
   m_routingProtocols.sort ();
@@ -327,21 +357,22 @@
 uint32_t 
 Ipv4L3Protocol::GetNRoutes (void)
 {
-  NS_DEBUG("Ipv4L3Protocol::GetNRoutes ()");
+  NS_LOG_FUNCTION;
   return m_staticRouting->GetNRoutes ();
 }
 
 Ipv4Route *
 Ipv4L3Protocol::GetRoute (uint32_t index)
 {
-  NS_DEBUG("Ipv4L3Protocol::GetRoute ()");
+  NS_LOG_FUNCTION;
   return m_staticRouting->GetRoute (index);
 }
 
 void 
 Ipv4L3Protocol::RemoveRoute (uint32_t index)
 {
-  NS_DEBUG("Ipv4L3Protocol::RemoveRoute (" << index << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM("(" << index << ")");
   m_staticRouting->RemoveRoute (index);
 }
 
@@ -351,8 +382,9 @@
                                    uint32_t inputInterface,
                                    std::vector<uint32_t> outputInterfaces)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddMulticastRoute (" << origin << ", " <<
-    group << ", " << inputInterface << ", " << &outputInterfaces << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << 
+    ", " << &outputInterfaces << ")");
 
   m_staticRouting->AddMulticastRoute (origin, group, inputInterface,
     outputInterfaces);
@@ -361,8 +393,8 @@
 void 
 Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetDefaultMulticastRoute (" << outputInterface <<
-    ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << outputInterface << ")");
 
   m_staticRouting->SetDefaultMulticastRoute (outputInterface);
 }
@@ -370,14 +402,15 @@
 uint32_t 
 Ipv4L3Protocol::GetNMulticastRoutes (void) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetNMulticastRoutes ()");
+  NS_LOG_FUNCTION;
   return m_staticRouting->GetNMulticastRoutes ();
 }
 
 Ipv4MulticastRoute *
 Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetMulticastRoute (" << index << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << index << ")");
   return m_staticRouting->GetMulticastRoute (index);
 }
 
@@ -386,22 +419,25 @@
                                        Ipv4Address group,
                                        uint32_t inputInterface)
 {
-  NS_DEBUG("Ipv4L3Protocol::RemoveMulticastRoute (" << origin << ", " <<
-    group << ", " << inputInterface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << 
+    ")");
   m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface);
 }
 
 void 
 Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index)
 {
-  NS_DEBUG("Ipv4L3Protocol::RemoveMulticastRoute (" << index << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << index << ")");
   m_staticRouting->RemoveMulticastRoute (index);
 }
 
 uint32_t 
 Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddInterface (" << &device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &device << ")");
   Ptr<Ipv4Interface> interface = Create<ArpIpv4Interface> (m_node, device);
   return AddIpv4Interface (interface);
 }
@@ -409,7 +445,8 @@
 uint32_t 
 Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
 {
-  NS_DEBUG("Ipv4L3Protocol::AddIpv4Interface (" << interface << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << interface << ")");
   uint32_t index = m_nInterfaces;
   m_interfaces.push_back (interface);
   m_nInterfaces++;
@@ -419,7 +456,8 @@
 Ptr<Ipv4Interface>
 Ipv4L3Protocol::GetInterface (uint32_t index) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetInterface (" << index << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << index << ")");
   uint32_t tmp = 0;
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
     {
@@ -435,14 +473,15 @@
 uint32_t 
 Ipv4L3Protocol::GetNInterfaces (void) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetNInterface ()");
+  NS_LOG_FUNCTION;
   return m_nInterfaces;
 }
 
 uint32_t 
 Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const
 {
-  NS_DEBUG("Ipv4L3Protocol::FindInterfaceForAddr (" << addr << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << addr << ")");
 
   uint32_t ifIndex = 0;
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
@@ -463,8 +502,8 @@
 uint32_t 
 Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const
 {
-  NS_DEBUG("Ipv4L3Protocol::FindInterfaceForAddr (" << addr << ", " << 
-    mask << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << addr << ", " << mask << ")");
 
   uint32_t ifIndex = 0;
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
@@ -485,7 +524,8 @@
 Ptr<Ipv4Interface>
 Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
 {
-  NS_DEBUG("Ipv4L3Protocol::FindInterfaceForDevice (" << &device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &device << ")");
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
     {
       if ((*i)->GetDevice () == device)
@@ -499,10 +539,11 @@
 void 
 Ipv4L3Protocol::Receive( Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
 {
-  NS_DEBUG("Ipv4L3Protocol::Receive (" << &device << ", " << &p << ", " <<
-    protocol << ", " << from << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &device << ", " << &p << ", " << protocol << ", " << 
+    from << ")");
 
-  NS_DEBUG("Ipv4L3Protocol::Receive (): Packet from " << from);
+  NS_LOG_LOGIC ("Packet from " << from);
 
   uint32_t index = 0;
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
@@ -530,6 +571,7 @@
       return;
     }
 
+  NS_LOG_LOGIC ("Forward up");
   ForwardUp (packet, ipHeader);
 }
 
@@ -540,8 +582,9 @@
             Ipv4Address destination,
             uint8_t protocol)
 {
-  NS_DEBUG("Ipv4L3Protocol::Send (" << &packet << ", " << source << ", " <<
-    ", " << destination << ", " << protocol << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << ", " << 
+    destination << ", " << protocol << ")");
 
   Ipv4Header ipHeader;
 
@@ -591,18 +634,18 @@
                              Packet packet,
                              Ipv4Header const &ipHeader)
 {
-  NS_DEBUG("Ipv4L3Protocol::SendRealOut (" << found << ", " << &route << 
-    ", " << &packet << &ipHeader << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << found << ", " << &route << ", " << &packet << 
+    &ipHeader << ")");
 
   if (!found)
     {
-      NS_DEBUG ("Ipv4L3Protocol::SendRealOut (): No route to host.  Drop.");
+      NS_LOG_WARN ("No route to host.  Drop.");
       m_dropTrace (packet);
       return;
     }
 
-  NS_DEBUG ("Ipv4L3Protocol::SendRealOut (): Send via interface " <<
-        route.GetInterface ());
+  NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
 
   packet.AddHeader (ipHeader);
   Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
@@ -610,14 +653,12 @@
   m_txTrace (packet, route.GetInterface ());
   if (route.IsGateway ()) 
     {
-      NS_DEBUG ("Ipv4L3Protocol::SendRealOut (): Send to gateway " <<
-        route.GetGateway ());
+      NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
       outInterface->Send (packet, route.GetGateway ());
     } 
   else 
     {
-      NS_DEBUG ("Ipv4L3Protocol::SendRealOut (): Send to destination " <<
-        ipHeader.GetDestination ());
+      NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
       outInterface->Send (packet, ipHeader.GetDestination ());
     }
 }
@@ -629,16 +670,16 @@
   Ipv4Header &ipHeader, 
   Ptr<NetDevice> device)
 {
-  NS_DEBUG("Ipv4L3Protocol::Forwarding (" << ifIndex << ", " << &packet << 
-    ", " << &ipHeader << ", " << device << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << ifIndex << ", " << &packet << ", " << &ipHeader << 
+    ", " << device << ")");
 
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
        i != m_interfaces.end (); i++) 
     {
       if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
         {
-          NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-            "For me (destination match)");
+          NS_LOG_LOGIC ("For me (destination match)");
           return false;
         }
     }
@@ -651,8 +692,7 @@
 	{
 	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
 	    {
-              NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-                "For me (interface broadcast address)");
+              NS_LOG_LOGIC ("For me (interface broadcast address)");
 	      return false;
 	    }
 	  break;
@@ -661,15 +701,13 @@
       
   if (ipHeader.GetDestination ().IsBroadcast ()) 
     {
-      NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-        "For me (Ipv4Addr broadcast address)");
+      NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
       return false;
     }
 
   if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) 
     {
-      NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-        "For me (Ipv4Addr any address)");
+      NS_LOG_LOGIC ("For me (Ipv4Addr any address)");
       return false;
     }
 
@@ -677,14 +715,13 @@
     {
       // Should send ttl expired here
       // XXX
-      NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-        "Not for me (TTL expired).  Drop");
+      NS_LOG_LOGIC ("Not for me (TTL expired).  Drop");
       m_dropTrace (packet);
       return true;
     }
   ipHeader.SetTtl (ipHeader.GetTtl () - 1);
 
-  NS_DEBUG("Ipv4L3Protocol::Forwarding (): Forwarding packet.");
+  NS_LOG_LOGIC ("Forwarding packet.");
   Lookup (ifIndex, ipHeader, packet,
           MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
 //
@@ -698,20 +735,21 @@
       if ((*i).first.IsEqual (ipHeader.GetSource ()) &&
           (*i).second.IsEqual (ipHeader.GetDestination ()))
         {
-          NS_DEBUG("Ipv4L3Protocol::Forwarding (): "
-            "For me (Joined multicast group)");
+          NS_LOG_LOGIC ("For me (Joined multicast group)");
           return false;
         }
     }
   
-  NS_DEBUG("Ipv4L3Protocol::Forwarding (): Not for me.");
+  NS_LOG_LOGIC("Not for me.");
   return true;
 }
 
 void
 Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip)
 {
-  NS_DEBUG("Ipv4L3Protocol::ForwardUp (" << &p << ", " << &ip << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << &ip << ")");
+
   Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
   Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
   protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
@@ -720,8 +758,8 @@
 void 
 Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group)
 {
-  NS_DEBUG("Ipv4L3Protocol::JoinMulticastGroup (" << origin << ", " << 
-    group << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << origin << ", " << group << ")");
   m_multicastGroups.push_back(
     std::pair<Ipv4Address, Ipv4Address> (origin, group));
 }
@@ -729,8 +767,8 @@
 void
 Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group)
 {
-  NS_DEBUG("Ipv4L3Protocol::LeaveMulticastGroup (" << origin << ", " << 
-    group << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << origin << ", " << group << ")");
 
   for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin ();
        i != m_multicastGroups.end (); 
@@ -747,7 +785,8 @@
 void 
 Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetAddress (" << i << ", " << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ", " << address << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   interface->SetAddress (address);
 }
@@ -755,7 +794,8 @@
 void 
 Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetNetworkMask (" << i << ", " << mask << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ", " << mask << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   interface->SetNetworkMask (mask);
 }
@@ -763,7 +803,8 @@
 Ipv4Mask 
 Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetNetworkMask (" << i << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   return interface->GetNetworkMask ();
 }
@@ -771,7 +812,8 @@
 Ipv4Address 
 Ipv4L3Protocol::GetAddress (uint32_t i) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetAddress (" << i << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   return interface->GetAddress ();
 }
@@ -780,8 +822,8 @@
 Ipv4L3Protocol::GetIfIndexForDestination (
   Ipv4Address destination, uint32_t& ifIndex) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (" << destination << 
-    ", " << &ifIndex << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")");
 //
 // The first thing we do in trying to determine a source address is to 
 // consult the routing protocols.  These will also check for a default route
@@ -791,13 +833,12 @@
        i != m_routingProtocols.end (); 
        i++)
     {
-      NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting Source Address");
+      NS_LOG_LOGIC ("Requesting Source Address");
       uint32_t ifIndexTmp;
 
       if ((*i).second->RequestIfIndex (destination, ifIndexTmp))
         {
-          NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
-            "Found ifIndex " << ifIndexTmp);
+          NS_LOG_LOGIC ("Found ifIndex " << ifIndexTmp);
           ifIndex = ifIndexTmp;
           return true;
         }
@@ -813,8 +854,7 @@
 //
   if (GetNInterfaces () == 2)
     {
-      NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
-        "One Interface.  Using interface 1.");
+      NS_LOG_LOGIC ("One Interface.  Using interface 1.");
       ifIndex = 1;
       return true;
     }
@@ -833,8 +873,7 @@
 // set to the IP address of the interface set in the default unicast route.
 // Also, in the case of a broadcast, the same will be true.
 //
-  NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
-    "Using default unicast route");
+  NS_LOG_LOGIC ("Using default unicast route");
   Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
 
   NS_ASSERT_MSG(route, 
@@ -843,15 +882,15 @@
 
   ifIndex = route->GetInterface ();
 
-  NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
-    "Default route specifies interface " << ifIndex);
+  NS_LOG_LOGIC ("Default route specifies interface " << ifIndex);
   return true;
 }
 
 uint16_t 
 Ipv4L3Protocol::GetMtu (uint32_t i) const
 {
-  NS_DEBUG("Ipv4L3Protocol::GetMtu (" << i << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   return interface->GetMtu ();
 }
@@ -859,7 +898,8 @@
 bool 
 Ipv4L3Protocol::IsUp (uint32_t i) const
 {
-  NS_DEBUG("Ipv4L3Protocol::IsUp (" << i << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   return interface->IsUp ();
 }
@@ -867,7 +907,8 @@
 void 
 Ipv4L3Protocol::SetUp (uint32_t i)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetUp (" << i << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << i << ")");
   Ptr<Ipv4Interface> interface = GetInterface (i);
   interface->SetUp ();
 
@@ -885,7 +926,8 @@
 void 
 Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
 {
-  NS_DEBUG("Ipv4L3Protocol::SetDown (" << ifaceIndex << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << ifaceIndex << ")");
   Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
   interface->SetDown ();
 
@@ -907,5 +949,4 @@
     }
 }
 
-
 }//namespace ns3
--- a/src/internet-node/ipv4-loopback-interface.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-loopback-interface.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,14 +20,14 @@
  *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/net-device.h"
 #include "ns3/node.h"
 #include "ns3/mac48-address.h"
 #include "ipv4-loopback-interface.h"
 #include "ipv4-l3-protocol.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4LoopbackInterface");
+NS_LOG_COMPONENT_DEFINE ("Ipv4LoopbackInterface");
 
 namespace ns3 {
 
@@ -35,19 +35,19 @@
   : Ipv4Interface (0),
     m_node (node)
 {
-  NS_DEBUG("Ipv4LoopbackInterface::Ipv4LoopbackInterface ()");
+  NS_LOG_FUNCTION;
 }
 
 Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
 {
-  NS_DEBUG("Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()");
+  NS_LOG_FUNCTION;
 }
 
 void 
 Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
 {
-  NS_DEBUG("Ipv4LoopbackInterface::SendTo (" << &packet << ", " << 
-    dest << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &packet << ", " << dest << ")");
 
   Ptr<Ipv4L3Protocol> ipv4 = 
     m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);
--- a/src/internet-node/ipv4-static-routing.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/ipv4-static-routing.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,17 +19,18 @@
 // Author: George F. Riley<riley@ece.gatech.edu>
 //         Gustavo Carneiro <gjc@inescporto.pt>
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ipv4-static-routing.h"
 #include "ns3/packet.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4StaticRouting");
+NS_LOG_COMPONENT_DEFINE ("Ipv4StaticRouting");
 
 namespace ns3 {
 
 Ipv4StaticRouting::Ipv4StaticRouting () 
 : m_defaultRoute (0), m_defaultMulticastRoute (0)
 {
+  NS_LOG_FUNCTION;
 }
 
 void 
@@ -37,7 +38,7 @@
                                    Ipv4Address nextHop, 
                                    uint32_t interface)
 {
-
+  NS_LOG_FUNCTION;
   Ipv4Route *route = new Ipv4Route ();
   *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface);
   m_hostRoutes.push_back (route);
@@ -47,6 +48,7 @@
 Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 
                                    uint32_t interface)
 {
+  NS_LOG_FUNCTION;
   Ipv4Route *route = new Ipv4Route ();
   *route = Ipv4Route::CreateHostRouteTo (dest, interface);
   m_hostRoutes.push_back (route);
@@ -58,6 +60,7 @@
                                       Ipv4Address nextHop, 
                                       uint32_t interface)
 {
+  NS_LOG_FUNCTION;
   Ipv4Route *route = new Ipv4Route ();
   *route = Ipv4Route::CreateNetworkRouteTo (network,
                                             networkMask,
@@ -71,6 +74,7 @@
                                       Ipv4Mask networkMask, 
                                       uint32_t interface)
 {
+  NS_LOG_FUNCTION;
   Ipv4Route *route = new Ipv4Route ();
   *route = Ipv4Route::CreateNetworkRouteTo (network,
                                             networkMask,
@@ -82,6 +86,7 @@
 Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, 
                                     uint32_t interface)
 {
+  NS_LOG_FUNCTION;
   Ipv4Route *route = new Ipv4Route ();
   *route = Ipv4Route::CreateDefaultRoute (nextHop, interface);
   delete m_defaultRoute;
@@ -94,6 +99,7 @@
                                      uint32_t inputInterface,
                                      std::vector<uint32_t> outputInterfaces)
 {
+  NS_LOG_FUNCTION;
   Ipv4MulticastRoute *route = new Ipv4MulticastRoute ();
   *route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group, 
     inputInterface, outputInterfaces);
@@ -103,6 +109,7 @@
 void 
 Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface)
 {
+  NS_LOG_FUNCTION;
   Ipv4Address origin = Ipv4Address::GetAny ();
   Ipv4Address group = Ipv4Address::GetAny ();
   uint32_t inputInterface = Ipv4RoutingProtocol::IF_INDEX_ANY;
@@ -121,12 +128,14 @@
 uint32_t 
 Ipv4StaticRouting::GetNMulticastRoutes (void) const
 {
+  NS_LOG_FUNCTION;
   return m_multicastRoutes.size () + m_defaultMulticastRoute ? 1 : 0;
 }
 
 Ipv4MulticastRoute *
 Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG(index < m_multicastRoutes.size (),
     "Ipv4StaticRouting::GetMulticastRoute ():  Index out of range");
 //
@@ -174,6 +183,7 @@
 Ipv4MulticastRoute *
 Ipv4StaticRouting::GetDefaultMulticastRoute () const
 {
+  NS_LOG_FUNCTION;
   if (m_defaultMulticastRoute != 0)
     {
       return m_defaultMulticastRoute;
@@ -186,9 +196,7 @@
                                         Ipv4Address group,
                                         uint32_t inputInterface)
 {
-//
-// This method does not attempt to delete the multicast route.
-// 
+  NS_LOG_FUNCTION;
   for (MulticastRoutesI i = m_multicastRoutes.begin (); 
        i != m_multicastRoutes.end (); 
        i++) 
@@ -209,6 +217,7 @@
 void 
 Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index)
 {
+  NS_LOG_FUNCTION;
 //
 // From an external point of view the default route appears to be in slot 0
 // of the routing table.  The implementation, however, puts it in a separate 
@@ -253,6 +262,7 @@
 Ipv4Route *
 Ipv4StaticRouting::LookupStatic (Ipv4Address dest)
 {
+  NS_LOG_FUNCTION;
   for (HostRoutesCI i = m_hostRoutes.begin (); 
        i != m_hostRoutes.end (); 
        i++) 
@@ -289,6 +299,7 @@
   Ipv4Address group,
   uint32_t    ifIndex)
 {
+  NS_LOG_FUNCTION;
 //
 // We treat the "any" address (typically 0.0.0.0) as a wildcard in our matching
 // scheme.
@@ -390,6 +401,7 @@
 uint32_t 
 Ipv4StaticRouting::GetNRoutes (void)
 {
+  NS_LOG_FUNCTION;
   uint32_t n = 0;
   if (m_defaultRoute != 0)
     {
@@ -403,6 +415,7 @@
 Ipv4Route *
 Ipv4StaticRouting::GetDefaultRoute ()
 {
+  NS_LOG_FUNCTION;
   if (m_defaultRoute != 0)
     {
       return m_defaultRoute;
@@ -416,6 +429,7 @@
 Ipv4Route *
 Ipv4StaticRouting::GetRoute (uint32_t index)
 {
+  NS_LOG_FUNCTION;
   if (index == 0 && m_defaultRoute != 0)
     {
       return m_defaultRoute;
@@ -457,6 +471,7 @@
 void 
 Ipv4StaticRouting::RemoveRoute (uint32_t index)
 {
+  NS_LOG_FUNCTION;
   if (index == 0 && m_defaultRoute != 0)
     {
       delete m_defaultRoute;
@@ -506,26 +521,24 @@
   Packet packet,
   RouteReplyCallback routeReply)
 {
-  NS_DEBUG ("Ipv4StaticRouting::RequestRoute (" << &ipHeader << ", " <<
-    &packet << ", " << &routeReply << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << ifIndex << &ipHeader << ", " << &packet << ", " << 
+    &routeReply << ")");
 
-  NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): source = " << 
-    ipHeader.GetSource ());
+  NS_LOG_LOGIC ("source = " << ipHeader.GetSource ());
 
-  NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): destination = " << 
-    ipHeader.GetDestination ());
+  NS_LOG_LOGIC ("destination = " << ipHeader.GetDestination ());
 
   if (ipHeader.GetDestination ().IsMulticast ())
     {
-      NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): Multicast destination");
+      NS_LOG_LOGIC ("Multicast destination");
 
       Ipv4MulticastRoute *mRoute = LookupStatic(ipHeader.GetSource (),
         ipHeader.GetDestination (), ifIndex);
 
       if (mRoute)
         {
-          NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
-            "Multicast route found");
+          NS_LOG_LOGIC ("Multicast route found");
 
           for (uint32_t i = 0; i < mRoute->GetNOutputInterfaces (); ++i)
             {
@@ -534,8 +547,8 @@
               Ipv4Route route = 
                 Ipv4Route::CreateHostRouteTo(h.GetDestination (), 
                   mRoute->GetOutputInterface(i));
-              NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): "
-                "Send via interface " << mRoute->GetOutputInterface(i));
+              NS_LOG_LOGIC ( "Send via interface " << 
+                mRoute->GetOutputInterface(i));
               routeReply (true, route, p, h);
             }
           return true;
@@ -545,7 +558,7 @@
 //
 // This is a unicast packet.  Check to see if we have a route for it.
 //
-  NS_DEBUG ("Ipv4StaticRouting::RequestRoute (): Unicast destination");
+  NS_LOG_LOGIC ("Unicast destination");
   Ipv4Route *route = LookupStatic (ipHeader.GetDestination ());
   if (route != 0)
     {
@@ -562,34 +575,31 @@
 bool
 Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex)
 {
-  NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (" << destination << ", " <<
-    &ifIndex << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")");
 //
 // First, see if this is a multicast packet we have a route for.  If we
 // have a route, then send the packet down each of the specified interfaces.
 //
   if (destination.IsMulticast ())
     {
-      NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): Multicast destination");
+      NS_LOG_LOGIC ("Multicast destination");
 
       Ipv4MulticastRoute *mRoute = LookupStatic(Ipv4Address::GetAny (),
         destination, Ipv4RoutingProtocol::IF_INDEX_ANY);
 
       if (mRoute)
         {
-          NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): "
-            "Multicast route found");
+          NS_LOG_LOGIC ("Multicast route found");
 
           if (mRoute->GetNOutputInterfaces () != 1)
             {
-              NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): "
-                "Route is to multiple interfaces.  Ignoring.");
+              NS_LOG_LOGIC ("Route is to multiple interfaces.  Ignoring.");
               return false;
             }
 
           ifIndex = mRoute->GetOutputInterface(0);
-          NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): "
-            "Found ifIndex " << ifIndex);
+          NS_LOG_LOGIC ("Found ifIndex " << ifIndex);
           return true;
         }
       return false; // Let other routing protocols try to handle this
@@ -597,7 +607,7 @@
 //
 // See if this is a unicast packet we have a route for.
 //
-  NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): Unicast destination");
+  NS_LOG_LOGIC ("Unicast destination");
   Ipv4Route *route = LookupStatic (destination);
   if (route)
     {
@@ -613,6 +623,7 @@
 void
 Ipv4StaticRouting::DoDispose (void)
 {
+  NS_LOG_FUNCTION;
   for (HostRoutesI i = m_hostRoutes.begin (); 
        i != m_hostRoutes.end (); 
        i = m_hostRoutes.erase (i)) 
--- a/src/internet-node/udp-l4-protocol.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/udp-l4-protocol.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,7 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/assert.h"
 #include "ns3/packet.h"
 #include "ns3/node.h"
@@ -31,7 +31,7 @@
 #include "ipv4-l3-protocol.h"
 #include "udp-socket.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("UdpL4Protocol");
+NS_LOG_COMPONENT_DEFINE ("UdpL4Protocol");
 
 namespace ns3 {
 
@@ -43,18 +43,18 @@
     m_node (node),
     m_endPoints (new Ipv4EndPointDemux ())
 {
-  NS_DEBUG("UdpL4Protocol::UdpL4Protocol ()");
+  NS_LOG_FUNCTION;
 }
 
 UdpL4Protocol::~UdpL4Protocol ()
 {
-  NS_DEBUG("UdpL4Protocol::~UdpL4Protocol ()");
+  NS_LOG_FUNCTION;
 }
 
 void
 UdpL4Protocol::DoDispose (void)
 {
-  NS_DEBUG("UdpL4Protocol::DoDispose ()");
+  NS_LOG_FUNCTION;
   if (m_endPoints != 0)
     {
       delete m_endPoints;
@@ -67,7 +67,7 @@
 Ptr<Socket>
 UdpL4Protocol::CreateSocket (void)
 {
-  NS_DEBUG("UdpL4Protocol::CreateSocket ()");
+  NS_LOG_FUNCTION;
   Ptr<Socket> socket = Create<UdpSocket> (m_node, this);
   return socket;
 }
@@ -75,36 +75,40 @@
 Ipv4EndPoint *
 UdpL4Protocol::Allocate (void)
 {
-  NS_DEBUG("UdpL4Protocol::Allocate ()");
+  NS_LOG_FUNCTION;
   return m_endPoints->Allocate ();
 }
 
 Ipv4EndPoint *
 UdpL4Protocol::Allocate (Ipv4Address address)
 {
-  NS_DEBUG("UdpL4Protocol::Allocate (" << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ")");
   return m_endPoints->Allocate (address);
 }
 
 Ipv4EndPoint *
 UdpL4Protocol::Allocate (uint16_t port)
 {
-  NS_DEBUG("UdpL4Protocol::Allocate (" << port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << port << ")");
   return m_endPoints->Allocate (port);
 }
 
 Ipv4EndPoint *
 UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
 {
-  NS_DEBUG("UdpL4Protocol::Allocate (" << address << ", " << port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ", " << port << ")");
   return m_endPoints->Allocate (address, port);
 }
 Ipv4EndPoint *
 UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
                Ipv4Address peerAddress, uint16_t peerPort)
 {
-  NS_DEBUG("UdpL4Protocol::Allocate (" << localAddress << ", " << localPort <<
-    ", " << peerAddress << ", " << peerPort << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << localAddress << ", " << localPort << ", " << 
+    peerAddress << ", " << peerPort << ")");
   return m_endPoints->Allocate (localAddress, localPort,
                                 peerAddress, peerPort);
 }
@@ -112,7 +116,8 @@
 void 
 UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint)
 {
-  NS_DEBUG("UdpL4Protocol::Deallocate (" << endPoint << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << endPoint << ")");
   m_endPoints->DeAllocate (endPoint);
 }
 
@@ -121,8 +126,9 @@
              Ipv4Address const &source,
              Ipv4Address const &destination)
 {
-  NS_DEBUG("UdpL4Protocol::Receive (" << &packet << ", " << source <<
-    ", " << destination << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination << 
+    ")");
 
   UdpHeader udpHeader;
   packet.RemoveHeader (udpHeader);
@@ -141,8 +147,9 @@
            Ipv4Address saddr, Ipv4Address daddr, 
            uint16_t sport, uint16_t dport)
 {
-  NS_DEBUG("UdpL4Protocol::Send (" << &packet << ", " << saddr <<
-    ", " << daddr << ", " << sport << ", " << dport << ")");
+  NS_LOG_FUNCTION; 
+  NS_LOG_PARAM ("(" << &packet << ", " << saddr << ", " << daddr << ", " << 
+    sport << ", " << dport << ")");
 
   UdpHeader udpHeader;
   udpHeader.SetDestination (dport);
@@ -157,7 +164,7 @@
   Ptr<Ipv4L3Protocol> ipv4 = m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);
   if (ipv4 != 0)
     {
-      NS_DEBUG("UdpL4Protocol::Send (): Sending to IP");
+      NS_LOG_LOGIC ("Sending to IP");
       ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
     }
 }
--- a/src/internet-node/udp-socket.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/udp-socket.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,7 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/node.h"
 #include "ns3/inet-socket-address.h"
 #include "ns3/ipv4-route.h"
@@ -30,7 +30,7 @@
 #include "ipv4-l4-demux.h"
 #include "ns3/ipv4.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("UdpSocket");
+NS_LOG_COMPONENT_DEFINE ("UdpSocket");
 
 namespace ns3 {
 
@@ -43,12 +43,12 @@
     m_shutdownRecv (false),
     m_connected (false)
 {
-  NS_DEBUG("UdpSocket::UdpSocket ()");
+  NS_LOG_FUNCTION;
 }
 
 UdpSocket::~UdpSocket ()
 {
-  NS_DEBUG("UdpSocket::~UdpSocket ()");
+  NS_LOG_FUNCTION;
 
   m_node = 0;
   if (m_endPoint != 0)
@@ -72,22 +72,21 @@
 enum Socket::SocketErrno
 UdpSocket::GetErrno (void) const
 {
-  NS_DEBUG("UdpSocket::GetErrno ()");
-
+  NS_LOG_FUNCTION;
   return m_errno;
 }
 
 Ptr<Node>
 UdpSocket::GetNode (void) const
 {
-  NS_DEBUG("UdpSocket::GetNode ()");
+  NS_LOG_FUNCTION;
   return m_node;
 }
 
 void 
 UdpSocket::Destroy (void)
 {
-  NS_DEBUG("UdpSocket::Destroy ()");
+  NS_LOG_FUNCTION;
   m_node = 0;
   m_endPoint = 0;
   m_udp = 0;
@@ -96,8 +95,7 @@
 int
 UdpSocket::FinishBind (void)
 {
-  NS_DEBUG("UdpSocket::FinishBind ()");
-
+  NS_LOG_FUNCTION;
   if (m_endPoint == 0)
     {
       return -1;
@@ -110,8 +108,7 @@
 int
 UdpSocket::Bind (void)
 {
-  NS_DEBUG("UdpSocket::Bind ()");
-
+  NS_LOG_FUNCTION;
   m_endPoint = m_udp->Allocate ();
   return FinishBind ();
 }
@@ -119,11 +116,12 @@
 int 
 UdpSocket::Bind (const Address &address)
 {
-  NS_DEBUG("UdpSocket::Bind (" << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM("(" << address << ")");
 
   if (!InetSocketAddress::IsMatchingType (address))
     {
-      NS_DEBUG("UdpSocket::Bind (): Not IsMatchingType");
+      NS_LOG_ERROR ("Not IsMatchingType");
       return ERROR_INVAL;
     }
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
@@ -152,7 +150,7 @@
 int 
 UdpSocket::ShutdownSend (void)
 {
-  NS_DEBUG("UdpSocket::ShutDownSend ()");
+  NS_LOG_FUNCTION;
   m_shutdownSend = true;
   return 0;
 }
@@ -160,7 +158,7 @@
 int 
 UdpSocket::ShutdownRecv (void)
 {
-  NS_DEBUG("UdpSocket::ShutDownRecv ()");
+  NS_LOG_FUNCTION;
   m_shutdownRecv = false;
   return 0;
 }
@@ -168,7 +166,7 @@
 int
 UdpSocket::Close(void)
 {
-  NS_DEBUG("UdpSocket::Close ()");
+  NS_LOG_FUNCTION;
   NotifyCloseCompleted ();
   return 0;
 }
@@ -176,7 +174,8 @@
 int
 UdpSocket::Connect(const Address & address)
 {
-  NS_DEBUG ("UdpSocket::Connect (" << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ")");
   Ipv4Route routeToDest;
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   m_defaultAddress = transport.GetIpv4 ();
@@ -184,27 +183,14 @@
   NotifyConnectionSucceeded ();
   m_connected = true;
 
-  NS_DEBUG ("UdpSocket::Connect (): Updating local address");
-
-  uint32_t localIfIndex;
-
-  Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
-  
-  if (ipv4->GetIfIndexForDestination (m_defaultAddress, localIfIndex))
-    {
-      m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex));
-    }
-
-  NS_DEBUG ("UdpSocket::Connect (): Local address is " << 
-    m_endPoint->GetLocalAddress());
-
   return 0;
 }
 
 int 
 UdpSocket::Send (const Packet &p)
 {
-  NS_DEBUG("UdpSocket::Send (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   if (!m_connected)
     {
@@ -217,6 +203,7 @@
 int 
 UdpSocket::DoSend (const Packet &p)
 {
+  NS_LOG_FUNCTION;
   if (m_endPoint == 0)
     {
       if (Bind () == -1)
@@ -238,11 +225,12 @@
 int
 UdpSocket::DoSendTo (const Packet &p, const Address &address)
 {
-  NS_DEBUG("UdpSocket::DoSendTo (" << &p << ", " << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << address << ")");
 
   if (!m_connected)
     {
-      NS_DEBUG("UdpSocket::DoSendTo (): Not connected");
+      NS_LOG_LOGIC ("Not connected");
       InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
       Ipv4Address ipv4 = transport.GetIpv4 ();
       uint16_t port = transport.GetPort ();
@@ -251,7 +239,7 @@
   else
     {
       // connected UDP socket must use default addresses
-      NS_DEBUG("UdpSocket::DoSendTo (): Connected");
+      NS_LOG_LOGIC ("Connected");
       return DoSendTo (p, m_defaultAddress, m_defaultPort);
     }
 }
@@ -259,8 +247,8 @@
 int
 UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port)
 {
-  NS_DEBUG("UdpSocket::DoSendTo (" << &p << ", " << dest << ", " <<
-    port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ", " << dest << ", " << port << ")");
 
   Ipv4Route routeToDest;
 
@@ -288,7 +276,7 @@
   //
   if (dest.IsBroadcast ())
     {
-      NS_DEBUG("UdpSocket::DoSendTo (): Limited broadcast");
+      NS_LOG_LOGIC ("Limited broadcast");
       for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
         {
           Ipv4Address addri = ipv4->GetAddress (i);
@@ -300,7 +288,7 @@
     }
   else if (ipv4->GetIfIndexForDestination(dest, localIfIndex))
     {
-      NS_DEBUG("UdpSocket::DoSendTo (): Route exists");
+      NS_LOG_LOGIC ("Route exists");
       m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest,
 		   m_endPoint->GetLocalPort (), port);
       NotifyDataSent (p.GetSize ());
@@ -308,7 +296,7 @@
     }
   else
    {
-      NS_DEBUG("UdpSocket::DoSendTo (): ERROR_NOROUTETOHOST");
+      NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
       m_errno = ERROR_NOROUTETOHOST;
       return -1;
    }
@@ -319,7 +307,8 @@
 int 
 UdpSocket::SendTo(const Address &address, const Packet &p)
 {
-  NS_DEBUG("UdpSocket::SendTo (" << address << ", " << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ", " << &p << ")");
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
   uint16_t port = transport.GetPort ();
@@ -329,8 +318,8 @@
 void 
 UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
 {
-  NS_DEBUG("UdpSocket::ForwardUp (" << &packet << ", " << ipv4 << ", " <<
-    port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &packet << ", " << ipv4 << ", " << port << ")");
 
   if (m_shutdownRecv)
     {
--- a/src/internet-node/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/internet-node/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -2,7 +2,7 @@
 
 
 def build(bld):
-    obj = bld.create_ns3_module('internet-node', ['node', 'applications'])
+    obj = bld.create_ns3_module('internet-node', ['node'])
     obj.source = [
         'internet-node.cc',
         'ipv4-l4-demux.cc',
--- a/src/mobility/random-position.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/mobility/random-position.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -21,10 +21,10 @@
 #include "ns3/random-variable.h"
 #include "ns3/default-value.h"
 #include "ns3/random-variable-default-value.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include <cmath>
 
-NS_DEBUG_COMPONENT_DEFINE ("RandomPosition");
+NS_LOG_COMPONENT_DEFINE ("RandomPosition");
 
 namespace ns3 {
 
@@ -127,7 +127,7 @@
   double rho = m_rho->GetValue ();
   double x = m_x + std::cos (theta) * rho;
   double y = m_y + std::sin (theta) * rho;
-  NS_DEBUG ("Disc position x=" << x << ", y=" << y);
+  NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
   return Position (x, y, 0.0);
 }
 
--- a/src/node/channel.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/channel.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -14,16 +14,12 @@
  * 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: Craig Dowell <craigdo@ee.washingon.edu>
- *
- *	Thu Feb 15 14:50:46 PST 2007 craigdo: Created.
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "channel.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Channel");
+NS_LOG_COMPONENT_DEFINE ("Channel");
 
 namespace ns3 {
 
@@ -32,31 +28,35 @@
 Channel::Channel ()
   : m_name("Channel")
 {
+  NS_LOG_FUNCTION;
   SetInterfaceId (Channel::iid);
-  NS_DEBUG("Channel::Channel ()");
 }
 
 Channel::Channel (std::string name)
   : m_name(name)
 {
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << name << ")");
   SetInterfaceId (Channel::iid);
-  NS_DEBUG("Channel::Channel (" << name << ")");
 }
 
 Channel::~Channel ()
 {
-  NS_DEBUG("Channel::~Channel ()");
+  NS_LOG_FUNCTION;
 }
 
   void
 Channel::SetName(std::string name)
 {
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << name << ")");
   m_name = name;
 }
 
   std::string
 Channel::GetName(void)
 {
+  NS_LOG_FUNCTION;
   return m_name;
 }
 
--- a/src/node/drop-tail-queue.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/drop-tail-queue.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -17,10 +17,10 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "drop-tail-queue.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue");
+NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
 
 namespace ns3 {
 
@@ -33,38 +33,39 @@
   m_packets (),
   m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
 {
-  NS_DEBUG("DropTailQueue::DropTailQueue ()");
+  NS_LOG_FUNCTION;
 }
 
 DropTailQueue::~DropTailQueue ()
 {
-  NS_DEBUG("DropTailQueue::~DropTailQueue ()");
+  NS_LOG_FUNCTION;
 }
 
 void 
 DropTailQueue::SetMaxPackets (uint32_t npackets)
 {
-  NS_DEBUG("DropTailQueue::SetMaxPackets (" << npackets << ")");
-
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << npackets << ")");
   m_maxPackets = npackets;
 }
 
 uint32_t 
 DropTailQueue::GetMaxPackets (void)
 {
-  NS_DEBUG("DropTailQueue::GetMaxPackets () <= " << m_maxPackets);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("returns " << m_maxPackets);
   return m_maxPackets;
 }
 
 bool 
 DropTailQueue::DoEnqueue (const Packet& p)
 {
-  NS_DEBUG("DropTailQueue::DoEnqueue (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   if (m_packets.size () >= m_maxPackets)
     {
-      NS_DEBUG("DropTailQueue::DoEnqueue (): Queue full -- droppping pkt");
+      NS_LOG_LOGIC ("Queue full -- droppping pkt");
       Drop (p);
       return false;
     }
@@ -76,18 +77,19 @@
 bool
 DropTailQueue::DoDequeue (Packet& p)
 {
-  NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   if (m_packets.empty()) 
     {
-      NS_DEBUG("DropTailQueue::DoDequeue (): Queue empty");
+      NS_LOG_LOGIC ("Queue empty");
       return false;
     }
 
   p = m_packets.front ();
   m_packets.pop ();
 
-  NS_DEBUG("DropTailQueue::DoDequeue (): Popped " << &p << " <= true");
+  NS_LOG_LOGIC ("Popped " << &p);
 
   return true;
 }
@@ -95,11 +97,12 @@
 bool
 DropTailQueue::DoPeek (Packet& p)
 {
-  NS_DEBUG("DropTailQueue::DoPeek (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   if (m_packets.empty()) 
     {
-      NS_DEBUG("DropTailQueue::DoPeek (): Queue empty");
+      NS_LOG_LOGIC ("Queue empty");
       return false;
     }
 
--- a/src/node/ethernet-header.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/ethernet-header.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -22,12 +22,12 @@
 #include <iomanip>
 #include <iostream>
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/header.h"
 #include "ethernet-header.h"
 #include "address-utils.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("EthernetHeader");
+NS_LOG_COMPONENT_DEFINE ("EthernetHeader");
 
 namespace ns3 {
 
--- a/src/node/ethernet-trailer.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/ethernet-trailer.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -20,11 +20,11 @@
  */
 
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/trailer.h"
 #include "ethernet-trailer.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("EthernetTrailer");
+NS_LOG_COMPONENT_DEFINE ("EthernetTrailer");
 
 namespace ns3 {
 
@@ -62,7 +62,7 @@
     {
       return true;
     } else {
-      NS_DEBUG("FCS calculation is not yet enabled" << std::endl);
+      NS_LOG_WARN ("FCS calculation is not yet enabled");
       return false;
     }
 }
@@ -70,7 +70,7 @@
 void
 EthernetTrailer::CalcFcs (const Packet& p)
 {
-  NS_DEBUG("FCS calculation is not yet enabled" << std::endl);
+  NS_LOG_WARN ("FCS calculation is not yet enabled");
 }
 
 void
--- a/src/node/ipv4-address.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/ipv4-address.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -18,12 +18,12 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#include "ns3/debug.h"
+
+#include "ns3/log.h"
 #include "ipv4-address.h"
 #include "ns3/assert.h"
 
-NS_DEBUG_COMPONENT_DEFINE("Ipv4Address");
-
+NS_LOG_COMPONENT_DEFINE("Ipv4Address");
 
 namespace ns3 {
 
--- a/src/node/net-device.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/net-device.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -22,15 +22,13 @@
 #include <iostream>
 #include "ns3/assert.h"
 #include "ns3/object.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/trace-resolver.h"
-
-
 #include "channel.h"
 #include "net-device.h"
 #include "node.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("NetDevice");
+NS_LOG_COMPONENT_DEFINE ("NetDevice");
 
 namespace ns3 {
 
@@ -47,22 +45,27 @@
   m_isMulticast (false), 
   m_isPointToPoint (false)
 {
+  NS_LOG_FUNCTION;
   SetInterfaceId (NetDevice::iid);
   m_node->AddDevice (this);
 }
 
 NetDevice::~NetDevice ()
-{}
+{
+  NS_LOG_FUNCTION;
+}
 
 Address 
 NetDevice::GetAddress (void) const
 {
+  NS_LOG_FUNCTION;
   return m_address;
 }
 
 bool
 NetDevice::SetMtu (const uint16_t mtu) 
 {
+  NS_LOG_FUNCTION;
   m_mtu = mtu;
   return true;
 }
@@ -70,54 +73,63 @@
 uint16_t 
 NetDevice::GetMtu (void) const
 {
+  NS_LOG_FUNCTION;
   return m_mtu;
 }
 
 void
 NetDevice::SetName(const std::string name) 
 { 
+  NS_LOG_FUNCTION;
   m_name = name; 
 }
 
 std::string 
 NetDevice::GetName(void) const 
 { 
+  NS_LOG_FUNCTION;
   return m_name; 
 }
 
 void
 NetDevice::SetIfIndex(uint32_t index) 
 { 
+  NS_LOG_FUNCTION;
   m_ifIndex = index; 
 }
 
 uint32_t
 NetDevice::GetIfIndex(void) const 
 { 
+  NS_LOG_FUNCTION;
   return m_ifIndex; 
 }
 
 bool 
 NetDevice::IsLinkUp (void) const
 {
+  NS_LOG_FUNCTION;
   return m_isUp;
 }
 
 void 
 NetDevice::SetLinkChangeCallback (Callback<void> callback)
 {
+  NS_LOG_FUNCTION;
   m_linkChangeCallback = callback;
 }
 
 bool
 NetDevice::IsBroadcast (void) const
 {
+  NS_LOG_FUNCTION;
   return m_isBroadcast;
 }
 
 Address const &
 NetDevice::GetBroadcast (void) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT (m_isBroadcast);
   return m_broadcast;
 }
@@ -125,6 +137,7 @@
 void
 NetDevice::EnableBroadcast (Address broadcast)
 {
+  NS_LOG_FUNCTION;
   m_isBroadcast = true;
   m_broadcast = broadcast;
 }
@@ -132,18 +145,21 @@
 void
 NetDevice::DisableBroadcast (void)
 {
+  NS_LOG_FUNCTION;
   m_isBroadcast = false;
 }
 
 bool
 NetDevice::IsMulticast (void) const
 {
+  NS_LOG_FUNCTION;
   return m_isMulticast;
 }
 
 Address 
 NetDevice::GetMulticast (void) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
     "Invalid operation when not IsMulticast ()");
   return m_multicast;
@@ -152,6 +168,7 @@
 Address
 NetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
     "Invalid operation when not IsMulticast ()");
   return m_multicast;
@@ -160,6 +177,7 @@
 void
 NetDevice::EnableMulticast (Address multicast)
 {
+  NS_LOG_FUNCTION;
   m_isMulticast = true;
   m_multicast = multicast;
 }
@@ -167,24 +185,28 @@
 void
 NetDevice::DisableMulticast (void)
 {
+  NS_LOG_FUNCTION;
   m_isMulticast = false;
 }
 
 bool
 NetDevice::IsPointToPoint (void) const
 {
+  NS_LOG_FUNCTION;
   return m_isPointToPoint;
 }
 
 void
 NetDevice::EnablePointToPoint (void)
 {
+  NS_LOG_FUNCTION;
   m_isPointToPoint = true;
 }
 
 void
 NetDevice::DisablePointToPoint (void)
 {
+  NS_LOG_FUNCTION;
   m_isPointToPoint = false;
 }
 
@@ -192,6 +214,7 @@
 bool 
 NetDevice::Send(const Packet& p, const Address& dest, uint16_t protocolNumber)
 {
+  NS_LOG_FUNCTION;
   if (m_isUp)
     {
       return SendTo(p, dest, protocolNumber);
@@ -205,6 +228,7 @@
 Ptr<Channel>
 NetDevice::GetChannel (void) const
 {
+  NS_LOG_FUNCTION;
   return DoGetChannel ();
 }
 
@@ -212,10 +236,10 @@
 bool
 NetDevice::ForwardUp(const Packet& p, uint16_t param, const Address &from)
 {
+  NS_LOG_FUNCTION;
   bool retval = false;
 
-  NS_DEBUG ("NetDevice::ForwardUp: UID is " << p.GetUid()
-            << " device is: " << GetName());
+  NS_LOG_LOGIC ("UID is " << p.GetUid() << " device is: " << GetName());
   
   if (!m_receiveCallback.IsNull ())
     {
@@ -223,7 +247,7 @@
     } 
   else 
     {
-      NS_DEBUG ("NetDevice::Receive call back is NULL");
+      NS_LOG_WARN ("NetDevice::Receive call back is NULL");
     }
 
     return retval;
@@ -232,6 +256,7 @@
 void 
 NetDevice::NotifyLinkUp (void)
 {
+  NS_LOG_FUNCTION;
   m_isUp = true;
   if (!m_linkChangeCallback.IsNull ())
     {
@@ -242,6 +267,7 @@
 void 
 NetDevice::NotifyLinkDown (void)
 {
+  NS_LOG_FUNCTION;
   m_isUp = false;
   if (!m_linkChangeCallback.IsNull ())
     {
@@ -252,24 +278,28 @@
 Ptr<Node>
 NetDevice::GetNode (void) const
 {
+  NS_LOG_FUNCTION;
   return m_node;
 }
 
 bool
 NetDevice::NeedsArp (void) const
 {
+  NS_LOG_FUNCTION;
   return DoNeedsArp ();
 }
 
 void 
 NetDevice::SetReceiveCallback (ReceiveCallback cb)
 {
+  NS_LOG_FUNCTION;
   m_receiveCallback = cb;
 }
 
 void
 NetDevice::DoDispose()
 {
+  NS_LOG_FUNCTION;
   m_node = 0;
 }
 
--- a/src/node/packet-socket.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/packet-socket.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -21,22 +21,24 @@
 
 #include "packet-socket.h"
 #include "packet-socket-address.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/node.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("PacketSocket");
+NS_LOG_COMPONENT_DEFINE ("PacketSocket");
 
 namespace ns3 {
 
 PacketSocket::PacketSocket (Ptr<Node> node)
   : m_node (node)
 {
+  NS_LOG_FUNCTION;
   Init();
 }
 
 void 
 PacketSocket::Init()
 {
+  NS_LOG_FUNCTION;
   m_state = STATE_OPEN;
   m_shutdownSend = false;
   m_shutdownRecv = false;
@@ -44,37 +46,45 @@
 }
 
 PacketSocket::~PacketSocket ()
-{}
+{
+  NS_LOG_FUNCTION;
+}
 
 void 
 PacketSocket::DoDispose (void)
 {
+  NS_LOG_FUNCTION;
   m_device = 0;
 }
 
 enum Socket::SocketErrno
 PacketSocket::GetErrno (void) const
 {
+  NS_LOG_FUNCTION;
   return m_errno;
 }
 
 Ptr<Node>
 PacketSocket::GetNode (void) const
 {
+  NS_LOG_FUNCTION;
   return m_node;
 }
 
 int
 PacketSocket::Bind (void)
 {
+  NS_LOG_FUNCTION;
   PacketSocketAddress address;
   address.SetProtocol (0);
   address.SetAllDevices ();
   return DoBind (address);
 }
+
 int
 PacketSocket::Bind (const Address &address)
-{
+{ 
+  NS_LOG_FUNCTION;
   if (!PacketSocketAddress::IsMatchingType (address))
     {
       m_errno = ERROR_INVAL;
@@ -87,6 +97,7 @@
 int
 PacketSocket::DoBind (const PacketSocketAddress &address)
 {
+  NS_LOG_FUNCTION;
   if (m_state == STATE_BOUND ||
       m_state == STATE_CONNECTED)
     {
@@ -119,6 +130,7 @@
 int
 PacketSocket::ShutdownSend (void)
 {
+  NS_LOG_FUNCTION;
   if (m_state == STATE_CLOSED)
     {
       m_errno = ERROR_BADF;
@@ -127,9 +139,11 @@
   m_shutdownSend = true;
   return 0;
 }
+
 int
 PacketSocket::ShutdownRecv (void)
 {
+  NS_LOG_FUNCTION;
   if (m_state == STATE_CLOSED)
     {
       m_errno = ERROR_BADF;
@@ -138,9 +152,11 @@
   m_shutdownRecv = false;
   return 0;
 }
+
 int
 PacketSocket::Close(void)
 {
+  NS_LOG_FUNCTION;
   if (m_state == STATE_CLOSED)
     {
       m_errno = ERROR_BADF;
@@ -154,6 +170,7 @@
 int
 PacketSocket::Connect(const Address &ad)
 {
+  NS_LOG_FUNCTION;
   PacketSocketAddress address;
   if (m_state == STATE_CLOSED)
     {
@@ -188,6 +205,7 @@
 int
 PacketSocket::Send (const Packet &p)
 {
+  NS_LOG_FUNCTION;
   if (m_state == STATE_OPEN ||
       m_state == STATE_BOUND)
     {
@@ -200,6 +218,7 @@
 int
 PacketSocket::SendTo(const Address &address, const Packet &p)
 {
+  NS_LOG_FUNCTION;
   PacketSocketAddress ad;
   if (m_state == STATE_CLOSED)
     {
@@ -265,6 +284,7 @@
 PacketSocket::ForwardUp (Ptr<NetDevice> device, const Packet &packet, 
                          uint16_t protocol, const Address &from)
 {
+  NS_LOG_FUNCTION;
   if (m_shutdownRecv)
     {
       return;
@@ -277,8 +297,7 @@
   address.SetSingleDevice (device->GetIfIndex ());
   address.SetProtocol (protocol);
 
-  NS_DEBUG ("PacketSocket::ForwardUp: UID is " << packet.GetUid()
-            << " PacketSocket " << this);
+  NS_LOG_LOGIC ("UID is " << packet.GetUid() << " PacketSocket " << this);
   NotifyDataReceived (p, address);
 }
 
--- a/src/node/queue.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/queue.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -17,13 +17,13 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/composite-trace-resolver.h"
 #include "ns3/default-value.h"
 #include "ns3/component-manager.h"
 #include "queue.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("Queue");
+NS_LOG_COMPONENT_DEFINE ("Queue");
 
 namespace ns3 {
 
@@ -35,33 +35,48 @@
 std::string 
 QueueTraceType::GetTypeName (void) const
 {
+  NS_LOG_FUNCTION;
   return "ns3::QueueTraceType";
 }
+
 uint16_t 
 QueueTraceType::GetUid (void)
 {
+  NS_LOG_FUNCTION;
   static uint16_t uid = AllocateUid<QueueTraceType> ("QueueTraceType");
   return uid;
 }
+
 QueueTraceType::QueueTraceType ()
   : m_type (QueueTraceType::ENQUEUE)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 QueueTraceType::QueueTraceType (enum Type type)
   : m_type (type)
-{}
+{
+  NS_LOG_FUNCTION;
+}
+
 bool 
 QueueTraceType::IsEnqueue (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == ENQUEUE;
 }
+
 bool 
 QueueTraceType::IsDequeue (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == DEQUEUE;
 }
+
 bool 
 QueueTraceType::IsDrop (void) const
 {
+  NS_LOG_FUNCTION;
   return m_type == DROP;
 }
 
@@ -90,18 +105,19 @@
   m_nTotalDroppedBytes(0),
   m_nTotalDroppedPackets(0)
 {
+  NS_LOG_FUNCTION;
   SetInterfaceId (Queue::iid);
-  NS_DEBUG("Queue::Queue ()");
 }
 
 Queue::~Queue()
 {
-  NS_DEBUG("Queue::~Queue ()");
+  NS_LOG_FUNCTION;
 }
 
 Ptr<TraceResolver>
 Queue::GetTraceResolver (void) const
 {
+  NS_LOG_FUNCTION;
   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
   resolver->AddSource ("enqueue", 
                        TraceDoc ("store packet in queue",
@@ -122,9 +138,9 @@
 bool 
 Queue::Enqueue (const Packet& p)
 {
-  NS_DEBUG("Queue::Enqueue (" << &p << ")");
-
-  NS_DEBUG("Queue::Enqueue (): m_traceEnqueue (p)");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
+  NS_LOG_LOGIC ("m_traceEnqueue (p)");
 
   m_traceEnqueue (p);
 
@@ -140,7 +156,8 @@
 bool
 Queue::Dequeue (Packet &p)
 {
-  NS_DEBUG("Queue::Dequeue (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   bool retval = DoDequeue (p);
 
@@ -152,7 +169,7 @@
       NS_ASSERT (m_nBytes >= 0);
       NS_ASSERT (m_nPackets >= 0);
 
-      NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
+      NS_LOG_LOGIC("m_traceDequeue (p)");
 
       const Packet packet = p;
       m_traceDequeue (packet);
@@ -164,16 +181,15 @@
 void
 Queue::DequeueAll (void)
 {
-  NS_DEBUG("Queue::DequeueAll ()");
-
-  NS_ASSERT (!"Don't know what to do with dequeued packets!");
+  NS_LOG_FUNCTION;
+  NS_ASSERT_MSG (0, "Don't know what to do with dequeued packets!");
 }
 
 bool
 Queue::Peek (Packet &p)
 {
-  NS_DEBUG("Queue::Peek (" << &p << ")");
-
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
   return DoPeek (p);
 }
 
@@ -181,66 +197,63 @@
 uint32_t 
 Queue::GetNPackets (void)
 {
-  NS_DEBUG("Queue::GetNPackets () <= " << m_nPackets);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("returns " << m_nPackets);
   return m_nPackets;
 }
 
 uint32_t
 Queue::GetNBytes (void)
 {
-  NS_DEBUG("Queue::GetNBytes () <= " << m_nBytes);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC (" returns " << m_nBytes);
   return m_nBytes;
 }
 
-
 bool
 Queue::IsEmpty (void)
 {
-  NS_DEBUG("Queue::IsEmpty () <= " << (m_nPackets == 0));
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("returns " << (m_nPackets == 0));
   return m_nPackets == 0;
 }
 
 uint32_t
 Queue::GetTotalReceivedBytes (void)
 {
-  NS_DEBUG("Queue::GetTotalReceivedBytes () <= " << m_nTotalReceivedBytes);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC("returns " << m_nTotalReceivedBytes);
   return m_nTotalReceivedBytes;
 }
 
 uint32_t
 Queue::GetTotalReceivedPackets (void)
 {
-  NS_DEBUG("Queue::GetTotalReceivedPackets () <= " << m_nTotalReceivedPackets);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets);
   return m_nTotalReceivedPackets;
 }
 
 uint32_t
 Queue:: GetTotalDroppedBytes (void)
 {
-  NS_DEBUG(
-    "Queue::GetTotalDroppedBytes () <= " << m_nTotalDroppedBytes
-    );
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes);
   return m_nTotalDroppedBytes;
 }
 
 uint32_t
 Queue::GetTotalDroppedPackets (void)
 {
-  NS_DEBUG(
-           "Queue::GetTotalDroppedPackets () <= " << m_nTotalDroppedPackets);
-
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC("returns " << m_nTotalDroppedPackets);
   return m_nTotalDroppedPackets;
 }
 
 void 
 Queue::ResetStatistics (void)
 {
-  NS_DEBUG("Queue::ResetStatistics ()");
-
+  NS_LOG_FUNCTION;
   m_nTotalReceivedBytes = 0;
   m_nTotalReceivedPackets = 0;
   m_nTotalDroppedBytes = 0;
@@ -250,18 +263,20 @@
 void
 Queue::Drop (const Packet& p)
 {
-  NS_DEBUG("Queue::Drop (" << &p << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << &p << ")");
 
   m_nTotalDroppedPackets++;
   m_nTotalDroppedBytes += p.GetSize ();
 
-  NS_DEBUG("Queue::Drop (): m_traceDrop (p)");
+  NS_LOG_LOGIC ("m_traceDrop (p)");
   m_traceDrop (p);
 }
 
 Ptr<Queue>
 Queue::CreateDefault (void)
 {
+  NS_LOG_FUNCTION;
   ClassId classId = g_classIdDefaultValue.GetValue ();
   Ptr<Queue> queue = ComponentManager::Create<Queue> (classId, Queue::iid);
   return queue;
--- a/src/node/socket.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/node/socket.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -19,83 +19,109 @@
  * Authors: George F. Riley<riley@ece.gatech.edu>
  *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
+
+#include "ns3/log.h"
+#include "ns3/packet.h"
 #include "socket.h"
-#include "ns3/packet.h"
+
+NS_LOG_COMPONENT_DEFINE ("Socket");
 
 namespace ns3 {
 
 Socket::~Socket ()
-{}
+{
+  NS_LOG_FUNCTION;
+}
 
 void 
 Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
 {
+  NS_LOG_FUNCTION;
   m_closeCompleted = closeCompleted;
 }
+
 void 
-Socket::SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
-			    Callback<void, Ptr<Socket> > connectionFailed,
-			    Callback<void, Ptr<Socket> > halfClose)
+Socket::SetConnectCallback (
+  Callback<void, Ptr<Socket> > connectionSucceeded,
+  Callback<void, Ptr<Socket> > connectionFailed,
+  Callback<void, Ptr<Socket> > halfClose)
 {
+  NS_LOG_FUNCTION;
   m_connectionSucceeded = connectionSucceeded;
   m_connectionFailed = connectionFailed;
   m_halfClose = halfClose;
 }
+
 void 
-Socket::SetAcceptCallback (Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
-			   Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
-			   Callback<void, Ptr<Socket> > closeRequested)
+Socket::SetAcceptCallback (
+  Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
+  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
+  Callback<void, Ptr<Socket> > closeRequested)
 {
+  NS_LOG_FUNCTION;
   m_connectionRequest = connectionRequest;
   m_newConnectionCreated = newConnectionCreated;
   m_closeRequested = closeRequested;
 }
+
 void 
 Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent)
 {
+  NS_LOG_FUNCTION;
   m_dataSent = dataSent;
 }
+
 void 
 Socket::SetRecvCallback (Callback<void, Ptr<Socket>, const Packet &,const Address&> receivedData)
 {
+  NS_LOG_FUNCTION;
   m_receivedData = receivedData;
 }
 
 void 
 Socket::NotifyCloseCompleted (void)
 {
+  NS_LOG_FUNCTION;
   if (!m_closeCompleted.IsNull ())
     {
       m_closeCompleted (this);
     }
 }
+
 void 
 Socket::NotifyConnectionSucceeded (void)
 {
+  NS_LOG_FUNCTION;
   if (!m_connectionSucceeded.IsNull ())
     {
       m_connectionSucceeded (this);
     }
 }
+
 void 
 Socket::NotifyConnectionFailed (void)
 {
+  NS_LOG_FUNCTION;
   if (!m_connectionFailed.IsNull ())
     {
       m_connectionFailed (this);
     }
 }
+
 void 
 Socket::NotifyHalfClose (void)
 {
+  NS_LOG_FUNCTION;
   if (!m_halfClose.IsNull ())
     {
       m_halfClose (this);
     }
 }
+
 bool 
 Socket::NotifyConnectionRequest (const Address &from)
 {
+  NS_LOG_FUNCTION;
   if (!m_connectionRequest.IsNull ())
     {
       return m_connectionRequest (this, from);
@@ -106,39 +132,45 @@
       return false;
     }
 }
+
 void 
 Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
 {
+  NS_LOG_FUNCTION;
   if (!m_newConnectionCreated.IsNull ())
     {
       m_newConnectionCreated (socket, from);
     }
 }
+
 void 
 Socket::NotifyCloseRequested (void)
 {
+  NS_LOG_FUNCTION;
   if (!m_closeRequested.IsNull ())
     {
       m_closeRequested (this);
     }
 }
+
 void 
 Socket::NotifyDataSent (uint32_t size)
 {
+  NS_LOG_FUNCTION;
   if (!m_dataSent.IsNull ())
     {
       m_dataSent (this, size);
     }
 }
+
 void 
 Socket::NotifyDataReceived (const Packet &p, const Address &from)
 {
+  NS_LOG_FUNCTION;
   if (!m_receivedData.IsNull ())
     {
       m_receivedData (this, p, from);
     }
 }
 
-
-
 }//namespace ns3
--- a/src/routing/global-routing/candidate-queue.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/routing/global-routing/candidate-queue.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -14,35 +14,32 @@
  * 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:  Craig Dowell (craigdo@ee.washington.edu)
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/assert.h"
 #include "candidate-queue.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("CandidateQueue");
+NS_LOG_COMPONENT_DEFINE ("CandidateQueue");
 
 namespace ns3 {
 
 CandidateQueue::CandidateQueue()
   : m_candidates ()
 {
-  NS_DEBUG("CandidateQueue::CandidateQueue ()");
+  NS_LOG_FUNCTION;
 }
 
 CandidateQueue::~CandidateQueue()
 {
-  NS_DEBUG("CandidateQueue::~CandidateQueue ()");
+  NS_LOG_FUNCTION;
   Clear ();
 }
 
   void
 CandidateQueue::Clear (void)
 {
-  NS_DEBUG("CandidateQueue::Clear ()");
-
+  NS_LOG_FUNCTION;
   while (!m_candidates.empty ())
     {
       SPFVertex *p = Pop ();
@@ -54,7 +51,8 @@
   void
 CandidateQueue::Push (SPFVertex *vNew)
 {
-  NS_DEBUG("CandidateQueue::Push (" << vNew << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << vNew << ")");
 
   CandidateList_t::iterator i = m_candidates.begin ();  
 
@@ -72,8 +70,7 @@
   SPFVertex *
 CandidateQueue::Pop (void)
 {
-  NS_DEBUG("CandidateQueue::Pop ()");
-
+  NS_LOG_FUNCTION;
   if (m_candidates.empty ())
     {
       return 0;
@@ -87,8 +84,7 @@
   SPFVertex *
 CandidateQueue::Top (void) const
 {
-  NS_DEBUG("CandidateQueue::Top ()");
-
+  NS_LOG_FUNCTION;
   if (m_candidates.empty ())
     {
       return 0;
@@ -100,24 +96,21 @@
   bool
 CandidateQueue::Empty (void) const
 {
-  NS_DEBUG("CandidateQueue::Empty ()");
-
+  NS_LOG_FUNCTION;
   return m_candidates.empty ();
 }
 
   uint32_t
 CandidateQueue::Size (void) const
 {
-  NS_DEBUG("CandidateQueue::Size ()");
-
+  NS_LOG_FUNCTION;
   return m_candidates.size ();
 }
 
   SPFVertex *
 CandidateQueue::Find (const Ipv4Address addr) const
 {
-  NS_DEBUG("CandidateQueue::Find ()");
-
+  NS_LOG_FUNCTION;
   CandidateList_t::const_iterator i = m_candidates.begin ();
 
   for (; i != m_candidates.end (); i++)
@@ -135,8 +128,7 @@
   void
 CandidateQueue::Reorder (void)
 {
-  NS_DEBUG("CandidateQueue::Reorder ()");
-
+  NS_LOG_FUNCTION;
   std::list<SPFVertex*> temp;
 
   while (!m_candidates.empty ()) {
--- a/src/routing/global-routing/global-route-manager-impl.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/routing/global-routing/global-route-manager-impl.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -16,8 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Authors:  Craig Dowell (craigdo@ee.washington.edu)
- *           Tom Henderson (tomhend@u.washington.edu)
+ * Authors:  Tom Henderson (tomhend@u.washington.edu)
  * 
  * Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
  * of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
@@ -28,14 +27,14 @@
 #include <queue>
 #include "ns3/assert.h"
 #include "ns3/fatal-error.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/node-list.h"
 #include "ns3/ipv4.h"
 #include "global-router-interface.h"
 #include "global-route-manager-impl.h"
 #include "candidate-queue.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("GlobalRouteManager");
+NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");
 
 namespace ns3 {
 
@@ -55,6 +54,7 @@
   m_parent (0),
   m_children ()
 {
+  NS_LOG_FUNCTION;
 }
 
 SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : 
@@ -66,20 +66,22 @@
   m_parent (0),
   m_children ()
 {
+  NS_LOG_FUNCTION;
   if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) 
     {
-      NS_DEBUG ("SPFVertex:: setting m_vertexType to VertexRouter");
+      NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter");
       m_vertexType = SPFVertex::VertexRouter;
     }
   else if (lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA) 
     { 
-      NS_DEBUG ("SPFVertex:: setting m_vertexType to VertexNetwork");
+      NS_LOG_LOGIC ("Setting m_vertexType to VertexNetwork");
       m_vertexType = SPFVertex::VertexNetwork;
     }
 }
 
 SPFVertex::~SPFVertex ()
 {
+  NS_LOG_FUNCTION;
   for ( ListOfSPFVertex_t::iterator i = m_children.begin ();
         i != m_children.end ();
         i++)
@@ -95,96 +97,112 @@
   void 
 SPFVertex::SetVertexType (SPFVertex::VertexType type)
 {
+  NS_LOG_FUNCTION;
   m_vertexType = type;
 }
 
   SPFVertex::VertexType 
 SPFVertex::GetVertexType (void) const
 {
+  NS_LOG_FUNCTION;
   return m_vertexType;
 }
 
   void 
 SPFVertex::SetVertexId (Ipv4Address id)
 {
+  NS_LOG_FUNCTION;
   m_vertexId = id;
 }
 
   Ipv4Address
 SPFVertex::GetVertexId (void) const
 {
+  NS_LOG_FUNCTION;
   return m_vertexId;
 }
 
   void 
 SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
 {
+  NS_LOG_FUNCTION;
   m_lsa = lsa;
 }
 
   GlobalRoutingLSA* 
 SPFVertex::GetLSA (void) const
 {
+  NS_LOG_FUNCTION;
   return m_lsa;
 }
 
   void 
 SPFVertex::SetDistanceFromRoot (uint32_t distance)
 {
+  NS_LOG_FUNCTION;
   m_distanceFromRoot = distance;
 }
 
   uint32_t
 SPFVertex::GetDistanceFromRoot (void) const
 {
+  NS_LOG_FUNCTION;
   return m_distanceFromRoot;
 }
 
   void 
 SPFVertex::SetOutgoingInterfaceId (uint32_t id)
 {
+  NS_LOG_FUNCTION;
   m_rootOif = id;
 }
 
   uint32_t 
 SPFVertex::GetOutgoingInterfaceId (void) const
 {
+  NS_LOG_FUNCTION;
   return m_rootOif;
 }
 
   void 
 SPFVertex::SetNextHop (Ipv4Address nextHop)
 {
+  NS_LOG_FUNCTION;
   m_nextHop = nextHop;
 }
 
   Ipv4Address
 SPFVertex::GetNextHop (void) const
 {
+  NS_LOG_FUNCTION;
   return m_nextHop;
 }
 
   void
 SPFVertex::SetParent (SPFVertex* parent)
 {
+  NS_LOG_FUNCTION;
   m_parent = parent;
 }
 
   SPFVertex* 
 SPFVertex::GetParent (void) const
 {
+  NS_LOG_FUNCTION;
   return m_parent;
 }
 
   uint32_t 
 SPFVertex::GetNChildren (void) const
 {
+  NS_LOG_FUNCTION;
   return m_children.size ();
 }
 
   SPFVertex* 
 SPFVertex::GetChild (uint32_t n) const
 {
+  NS_LOG_FUNCTION;
   uint32_t j = 0;
 
   for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
@@ -203,6 +221,7 @@
   uint32_t 
 SPFVertex::AddChild (SPFVertex* child)
 {
+  NS_LOG_FUNCTION;
   m_children.push_back (child);
   return m_children.size ();
 }
@@ -217,29 +236,27 @@
 :
   m_database ()
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()");
+  NS_LOG_FUNCTION;
 }
 
 GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ()
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ()");
-
+  NS_LOG_FUNCTION;
   LSDBMap_t::iterator i;
   for (i= m_database.begin (); i!= m_database.end (); i++)
     {
-      NS_DEBUG ("GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ():free LSA");
+      NS_LOG_LOGIC ("free LSA");
       GlobalRoutingLSA* temp = i->second;
       delete temp;
     }
-  NS_DEBUG ("GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ():  clear map");
+  NS_LOG_LOGIC ("clear map");
   m_database.clear ();
 }
 
   void
 GlobalRouteManagerLSDB::Initialize ()
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::Initialize ()");
-
+  NS_LOG_FUNCTION;
   LSDBMap_t::iterator i;
   for (i= m_database.begin (); i!= m_database.end (); i++)
     {
@@ -251,14 +268,14 @@
   void
 GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::Insert ()");
+  NS_LOG_FUNCTION;
   m_database.insert (LSDBPair_t (addr, lsa));
 }
 
   GlobalRoutingLSA*
 GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::GetLSA ()");
+  NS_LOG_FUNCTION;
 //
 // Look up an LSA by its address.
 //
@@ -276,7 +293,7 @@
   GlobalRoutingLSA*
 GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
 {
-  NS_DEBUG ("GlobalRouteManagerLSDB::GetLSAByLinkData ()");
+  NS_LOG_FUNCTION;
 //
 // Look up an LSA by its address.
 //
@@ -308,14 +325,13 @@
 : 
   m_spfroot (0) 
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::GlobalRoutemanagerImpl ()");
+  NS_LOG_FUNCTION;
   m_lsdb = new GlobalRouteManagerLSDB ();
 }
 
 GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()");
-
+  NS_LOG_FUNCTION;
   if (m_lsdb)
     {
       delete m_lsdb;
@@ -325,8 +341,7 @@
   void
 GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::DebugUseLsdb ()");
-
+  NS_LOG_FUNCTION;
   if (m_lsdb)
     {
       delete m_lsdb;
@@ -344,14 +359,12 @@
   void
 GlobalRouteManagerImpl::SelectRouterNodes () 
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SelectRouterNodes ()");
-
+  NS_LOG_FUNCTION;
   for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
     {
       Ptr<Node> node = *i;
-      NS_DEBUG ("GlobalRouteManagerImpl::SelectRouterNodes (): "
-        "Adding GlobalRouter interface to node " <<
-                node->GetId ());
+      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
+        node->GetId ());
 
       Ptr<GlobalRouter> globalRouter = Create<GlobalRouter> (node);
       node->AddInterface (globalRouter);
@@ -370,7 +383,7 @@
   void
 GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () 
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::BuildGlobalRoutingDatabase()");
+  NS_LOG_FUNCTION;
 //
 // Walk the list of nodes looking for the GlobalRouter Interface.
 //
@@ -396,7 +409,7 @@
 // found.
 //
       uint32_t numLSAs = rtr->DiscoverLSAs ();
-      NS_DEBUG ("Discover LSAs:  Found " << numLSAs << " LSAs");
+      NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
 
       for (uint32_t j = 0; j < numLSAs; ++j)
         {
@@ -406,7 +419,7 @@
 // router.
 //
           rtr->GetLSA (j, *lsa);
-          NS_DEBUG (*lsa);
+          NS_LOG_LOGIC (*lsa);
 //
 // Write the newly discovered link state advertisement to the database.
 //
@@ -451,7 +464,7 @@
   void
 GlobalRouteManagerImpl::InitializeRoutes ()
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::InitializeRoutes ()");
+  NS_LOG_FUNCTION;
 //
 // Walk the list of nodes in the system.
 //
@@ -491,16 +504,17 @@
   void
 GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
 {
+  NS_LOG_FUNCTION;
+
   SPFVertex* w = 0;
   GlobalRoutingLSA* w_lsa = 0;
   GlobalRoutingLinkRecord *l = 0;
   uint32_t distance = 0;
   uint32_t numRecordsInVertex = 0;
-
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFNext ()");
-
+//
 // V points to a Router-LSA or Network-LSA
 // Loop over the links in router LSA or attached routers in Network LSA
+//
   if (v->GetVertexType () == SPFVertex::VertexRouter)
     {
       numRecordsInVertex = v->GetLSA ()->GetNLinkRecords (); 
@@ -515,7 +529,7 @@
 // Get w_lsa:  In case of V is Router-LSA
       if (v->GetVertexType () == SPFVertex::VertexRouter) 
         {
-          NS_DEBUG ("SPFNext: Examining " << v->GetVertexId () << "'s " <<
+          NS_LOG_LOGIC ("Examining " << v->GetVertexId () << "'s " <<
             v->GetLSA ()->GetNLinkRecords () << " link records");
 //
 // (a) If this is a link to a stub network, examine the next link in V's LSA.
@@ -525,8 +539,7 @@
           l = v->GetLSA ()->GetLinkRecord (i);
           if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
             {
-              NS_DEBUG ("SPFNext: Found a Stub record to " << 
-                l->GetLinkId ());
+              NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
               continue;
             }
 //
@@ -542,7 +555,7 @@
 //
               w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
               NS_ASSERT (w_lsa);
-              NS_DEBUG ("SPFNext:  Found a P2P record from " << 
+              NS_LOG_LOGIC ("Found a P2P record from " << 
                 v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
             }
           else if (l->GetLinkType () == 
@@ -550,7 +563,7 @@
             {
               w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
               NS_ASSERT (w_lsa);
-              NS_DEBUG ("SPFNext:  Found a Transit record from " << 
+              NS_LOG_LOGIC ("Found a Transit record from " << 
                 v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
             }
           else 
@@ -567,7 +580,7 @@
             {
               continue;
             }
-          NS_DEBUG ("SPFNext:  Found a Network LSA from " << 
+          NS_LOG_LOGIC ("Found a Network LSA from " << 
             v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
         }
 
@@ -581,7 +594,7 @@
 //
       if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_IN_SPFTREE) 
         {
-          NS_DEBUG ("SPFNext: Skipping->  LSA "<< 
+          NS_LOG_LOGIC ("Skipping ->  LSA "<< 
             w_lsa->GetLinkStateId () << " already in SPF tree");
           continue;
         }
@@ -600,7 +613,7 @@
           distance = v->GetDistanceFromRoot ();
         }
 
-      NS_DEBUG ("SPFNext: Considering w_lsa " << w_lsa->GetLinkStateId ());
+      NS_LOG_LOGIC ("Considering w_lsa " << w_lsa->GetLinkStateId ());
 
 // Is there already vertex w in candidate list?
       if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
@@ -622,7 +635,7 @@
 // root node).
 //
               candidate.Push (w);
-              NS_DEBUG ("SPFNext:  Pushing " << 
+              NS_LOG_LOGIC ("Pushing " << 
                 w->GetVertexId () << ", parent vertexId: " << 
                 v->GetVertexId ());
             }
@@ -691,8 +704,8 @@
   GlobalRoutingLinkRecord* l,
   uint32_t distance)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFNexthopCalculation ()");
-
+  NS_LOG_FUNCTION;
+//
 // If w is a NetworkVertex, l should be null
 /*
   if (w->GetVertexType () == SPFVertex::VertexNetwork && l)
@@ -772,7 +785,7 @@
           w->SetOutgoingInterfaceId (
             FindOutgoingInterfaceId (l->GetLinkData ()));
 
-          NS_DEBUG ("SPFNexthopCalculation: Next hop from " << 
+          NS_LOG_LOGIC ("Next hop from " << 
             v->GetVertexId () << " to " << w->GetVertexId () << 
             " goes through next hop " << w->GetNextHop () <<
             " via outgoing interface " << w->GetOutgoingInterfaceId ());
@@ -789,7 +802,7 @@
             w_lsa->GetNetworkLSANetworkMask () ));
           w->SetDistanceFromRoot (distance);
           w->SetParent (v);
-          NS_DEBUG ("SPFNexthopCalculation: Next hop from " << 
+          NS_LOG_LOGIC ("Next hop from " << 
             v->GetVertexId () << " to network " << w->GetVertexId () << 
             " via outgoing interface " << w->GetOutgoingInterfaceId ());
           return 1;
@@ -816,7 +829,7 @@
  */
                 w->SetNextHop(linkRemote->GetLinkData ());
                 w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ());
-                NS_DEBUG ("SPFNexthopCalculation: Next hop from " << 
+                NS_LOG_LOGIC ("Next hop from " << 
                   v->GetVertexId () << " to " << w->GetVertexId () << 
                   " goes through next hop " << w->GetNextHop () <<
                   " via outgoing interface " << w->GetOutgoingInterfaceId ());
@@ -873,7 +886,7 @@
   SPFVertex* w,
   GlobalRoutingLinkRecord* prev_link) 
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFGetNextLink ()");
+  NS_LOG_FUNCTION;
 
   bool skip = true;
   bool found_prev_link = false;
@@ -907,12 +920,12 @@
         {
           if (!found_prev_link)
             {
-              NS_DEBUG ("SPFGetNextLink: Skipping links before prev_link found");
+              NS_LOG_LOGIC ("Skipping links before prev_link found");
               found_prev_link = true;
               continue;
             }
         
-          NS_DEBUG ("SPFGetNextLink: Found matching link l:  linkId = " <<
+          NS_LOG_LOGIC ("Found matching link l:  linkId = " <<
           l->GetLinkId () << " linkData = " << l->GetLinkData ());
 //
 // If skip is false, don't (not too surprisingly) skip the link found -- it's 
@@ -923,7 +936,7 @@
 //
         if (skip == false) 
           {
-            NS_DEBUG ("SPFGetNextLink: Returning the found link");
+            NS_LOG_LOGIC ("Returning the found link");
             return l;
           }
         else
@@ -933,7 +946,7 @@
 // Setting skip to false gets us the next point-to-point global router link
 // record in the LSA from <v>.
 //
-            NS_DEBUG ("SPFGetNextLink: Skipping the found link");
+            NS_LOG_LOGIC ("Skipping the found link");
             skip = false;
             continue;
           }
@@ -948,7 +961,7 @@
   void
 GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::DebugSPFCalculate ()");
+  NS_LOG_FUNCTION;
   SPFCalculate (root);
 }
 
@@ -956,8 +969,8 @@
   void
 GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFCalculate (): "
-    "root = " << root);
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << root << ")");
 
   SPFVertex *v;
 //
@@ -1023,7 +1036,7 @@
 // the candidate list.
 //
       v = candidate.Pop ();
-      NS_DEBUG ("SPFCalculate: Popped vertex " << v->GetVertexId ());
+      NS_LOG_LOGIC ("Popped vertex " << v->GetVertexId ());
 //
 // Update the status field of the vertex to indicate that it is in the SPF
 // tree.
@@ -1105,6 +1118,7 @@
   uint32_t
 GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
 {
+  NS_LOG_FUNCTION;
 //
 // We have an IP address <a> and a vertex ID of the root of the SPF tree.  
 // The question is what interface index does this address correspond to.
@@ -1180,7 +1194,7 @@
   void
 GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter ()");
+  NS_LOG_FUNCTION;
 
   NS_ASSERT_MSG (m_spfroot, 
     "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
@@ -1193,8 +1207,7 @@
 //
   Ipv4Address routerId = m_spfroot->GetVertexId ();
 
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter (): "
-    "Vertex ID = " << routerId);
+  NS_LOG_LOGIC ("Vertex ID = " << routerId);
 //
 // We need to walk the list of nodes looking for the one that has the router
 // ID corresponding to the root vertex.  This is the one we're going to write
@@ -1214,8 +1227,8 @@
 
       if (rtr == 0)
         {
-          NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter (): "
-            "No GlobalRouter interface on node " << node->GetId ());
+          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
+            node->GetId ());
           continue;
         }
 //
@@ -1223,13 +1236,11 @@
 // root of the SPF tree, then this node is the one for which we need to 
 // write the routing tables.
 //
-      NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter (): "
-        "Considering router " << rtr->GetRouterId ());
+      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
 
       if (rtr->GetRouterId () == routerId)
         {
-          NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter (): "
-            "setting routes for node " << node->GetId ());
+          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
 //
 // Routing information is updated using the Ipv4 interface.  We need to QI
 // for that interface.  If the node is acting as an IP version 4 router, it
@@ -1270,8 +1281,7 @@
                   continue;
                 }
 
-              NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddRouter (): "
-                " Node " << node->GetId () <<
+              NS_LOG_LOGIC (" Node " << node->GetId () <<
                 " add route to " << lr->GetLinkData () <<
                 " using next hop " << v->GetNextHop () <<
                 " via interface " << v->GetOutgoingInterfaceId ());
@@ -1301,7 +1311,7 @@
   void
 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
 {
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddTransit ()");
+  NS_LOG_FUNCTION;
 
   NS_ASSERT_MSG (m_spfroot, 
     "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
@@ -1314,8 +1324,7 @@
 //
   Ipv4Address routerId = m_spfroot->GetVertexId ();
 
-  NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddTransit (): "
-    "Vertex ID = " << routerId);
+  NS_LOG_LOGIC ("Vertex ID = " << routerId);
 //
 // We need to walk the list of nodes looking for the one that has the router
 // ID corresponding to the root vertex.  This is the one we're going to write
@@ -1335,8 +1344,8 @@
 
       if (rtr == 0)
         {
-          NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddTransit (): "
-            "No GlobalRouter interface on node " << node->GetId ());
+          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
+            node->GetId ());
           continue;
         }
 //
@@ -1344,13 +1353,11 @@
 // root of the SPF tree, then this node is the one for which we need to 
 // write the routing tables.
 //
-      NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddTransit (): "
-        "Considering router " << rtr->GetRouterId ());
+      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
 
       if (rtr->GetRouterId () == routerId)
         {
-          NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddTransit (): "
-            "setting routes for node " << node->GetId ());
+          NS_LOG_LOGIC ("setting routes for node " << node->GetId ());
 //
 // Routing information is updated using the Ipv4 interface.  We need to QI
 // for that interface.  If the node is acting as an IP version 4 router, it
@@ -1375,8 +1382,7 @@
           tempip = tempip.CombineMask (tempmask);
           ipv4->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
             v->GetOutgoingInterfaceId ());
-          NS_DEBUG ("GlobalRouteManagerImpl::SPFIntraAddNetwork (): "
-            " Node " << node->GetId () <<
+          NS_LOG_LOGIC ("Node " << node->GetId () <<
             " add network route to " << tempip <<
             " using next hop " << v->GetNextHop () <<
             " via interface " << v->GetOutgoingInterfaceId ());
@@ -1398,6 +1404,7 @@
   void
 GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
 {
+  NS_LOG_FUNCTION;
   v->GetParent ()->AddChild (v);
 }
 
--- a/src/routing/global-routing/global-route-manager.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/routing/global-routing/global-route-manager.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -15,12 +15,11 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Authors:  Craig Dowell (craigdo@ee.washington.edu)
- *           Tom Henderson (tomhend@u.washington.edu)
+ * Author: Tom Henderson (tomhend@u.washington.edu)
  */
 
 #include "ns3/assert.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/simulation-singleton.h"
 #include "global-route-manager.h"
 #include "global-route-manager-impl.h"
--- a/src/routing/global-routing/global-router-interface.cc	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/routing/global-routing/global-router-interface.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -15,11 +15,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Authors:  Craig Dowell (craigdo@ee.washington.edu)
- *           Tom Henderson (tomhend@u.washington.edu)
+ * Authors:  Tom Henderson (tomhend@u.washington.edu)
  */
 
-#include "ns3/debug.h"
+#include "ns3/log.h"
 #include "ns3/assert.h"
 #include "ns3/channel.h"
 #include "ns3/net-device.h"
@@ -27,7 +26,7 @@
 #include "ns3/ipv4.h"
 #include "global-router-interface.h"
 
-NS_DEBUG_COMPONENT_DEFINE ("GlobalRouter");
+NS_LOG_COMPONENT_DEFINE ("GlobalRouter");
 
 namespace ns3 {
 
@@ -44,7 +43,7 @@
   m_linkType (Unknown),
   m_metric (0)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ()");
+  NS_LOG_FUNCTION;
 }
 
 GlobalRoutingLinkRecord::GlobalRoutingLinkRecord (
@@ -58,47 +57,48 @@
   m_linkType (linkType),
   m_metric (metric)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GlobalRoutingLinkRecord (" <<
-    linkType << ", " << linkId << ", " << linkData << ", " << metric << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << linkType << ", " << linkId << ", " << linkData << 
+    ", " << metric << ")");
 }
 
 GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord ()
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord ()");
+  NS_LOG_FUNCTION;
 }
 
   Ipv4Address
 GlobalRoutingLinkRecord::GetLinkId (void) const
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GetLinkId ()");
+  NS_LOG_FUNCTION;
   return m_linkId;
 }
 
   void
 GlobalRoutingLinkRecord::SetLinkId (Ipv4Address addr)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::SetLinkId ()");
+  NS_LOG_FUNCTION;
   m_linkId = addr;
 }
 
   Ipv4Address
 GlobalRoutingLinkRecord::GetLinkData (void) const
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GetLinkData ()");
+  NS_LOG_FUNCTION;
   return m_linkData;
 }
 
   void
 GlobalRoutingLinkRecord::SetLinkData (Ipv4Address addr)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::SetLinkData ()");
+  NS_LOG_FUNCTION;
   m_linkData = addr;
 }
 
   GlobalRoutingLinkRecord::LinkType
 GlobalRoutingLinkRecord::GetLinkType (void) const
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GetLinkType ()");
+  NS_LOG_FUNCTION;
   return m_linkType;
 }
 
@@ -106,21 +106,21 @@
 GlobalRoutingLinkRecord::SetLinkType (
   GlobalRoutingLinkRecord::LinkType linkType)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::SetLinkType ()");
+  NS_LOG_FUNCTION;
   m_linkType = linkType;
 }
 
   uint32_t
 GlobalRoutingLinkRecord::GetMetric (void) const
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::GetMetric ()");
+  NS_LOG_FUNCTION;
   return m_metric;
 }
 
   void
 GlobalRoutingLinkRecord::SetMetric (uint32_t metric)
 {
-  NS_DEBUG("GlobalRoutingLinkRecord::SetMetric ()");
+  NS_LOG_FUNCTION;
   m_metric = metric;
 }
 
@@ -140,7 +140,7 @@
   m_attachedRouters(),
   m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
 {
-  NS_DEBUG("GlobalRoutingLSA::GlobalRoutingLSA ()");
+  NS_LOG_FUNCTION;
 }
 
 GlobalRoutingLSA::GlobalRoutingLSA (
@@ -156,8 +156,9 @@
   m_attachedRouters(),
   m_status(status)
 {
-  NS_DEBUG("GlobalRoutingLSA::GlobalRoutingLSA (" << status << ", " <<
-    linkStateId << ", " << advertisingRtr << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << status << ", " << linkStateId << ", " << 
+    advertisingRtr << ")");
 }
 
 GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa)
@@ -166,6 +167,7 @@
     m_networkLSANetworkMask(lsa.m_networkLSANetworkMask), 
     m_status(lsa.m_status)
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG(IsEmpty(), 
     "GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor");
   CopyLinkRecords (lsa);
@@ -174,6 +176,7 @@
   GlobalRoutingLSA&
 GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa)
 {
+  NS_LOG_FUNCTION;
   m_lsType = lsa.m_lsType;
   m_linkStateId = lsa.m_linkStateId;
   m_advertisingRtr = lsa.m_advertisingRtr;
@@ -188,6 +191,7 @@
   void
 GlobalRoutingLSA::CopyLinkRecords (const GlobalRoutingLSA& lsa)
 {
+  NS_LOG_FUNCTION;
   for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin ();
        i != lsa.m_linkRecords.end (); 
        i++)
@@ -208,18 +212,19 @@
 
 GlobalRoutingLSA::~GlobalRoutingLSA()
 {
-  NS_DEBUG("GlobalRoutingLSA::~GlobalRoutingLSA ()");
+  NS_LOG_FUNCTION;
   ClearLinkRecords ();
 }
 
   void
 GlobalRoutingLSA::ClearLinkRecords(void)
 {
+  NS_LOG_FUNCTION;
   for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
         i != m_linkRecords.end (); 
         i++)
     {
-      NS_DEBUG("GlobalRoutingLSA::ClearLinkRecords ():  free link record");
+      NS_LOG_LOGIC ("Free link record");
 
       GlobalRoutingLinkRecord *p = *i;
       delete p;
@@ -227,13 +232,14 @@
 
       *i = 0;
     }
-  NS_DEBUG("GlobalRoutingLSA::ClearLinkRecords():  clear list");
+  NS_LOG_LOGIC ("Clear list");
   m_linkRecords.clear();
 }
 
   uint32_t
 GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr)
 {
+  NS_LOG_FUNCTION;
   m_linkRecords.push_back (lr);
   return m_linkRecords.size ();
 }
@@ -241,12 +247,14 @@
   uint32_t
 GlobalRoutingLSA::GetNLinkRecords (void) const
 {
+  NS_LOG_FUNCTION;
   return m_linkRecords.size ();
 }
 
   GlobalRoutingLinkRecord *
 GlobalRoutingLSA::GetLinkRecord (uint32_t n) const
 {
+  NS_LOG_FUNCTION;
   uint32_t j = 0;
   for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin ();
         i != m_linkRecords.end (); 
@@ -264,66 +272,77 @@
   bool
 GlobalRoutingLSA::IsEmpty (void) const
 {
+  NS_LOG_FUNCTION;
   return m_linkRecords.size () == 0;
 }
 
   GlobalRoutingLSA::LSType
 GlobalRoutingLSA::GetLSType (void) const
 {
+  NS_LOG_FUNCTION;
   return m_lsType;
 }
 
   void 
 GlobalRoutingLSA::SetLSType (GlobalRoutingLSA::LSType typ) 
 {
+  NS_LOG_FUNCTION;
   m_lsType = typ;
 }
 
   Ipv4Address
 GlobalRoutingLSA::GetLinkStateId (void) const
 {
+  NS_LOG_FUNCTION;
   return m_linkStateId;
 }
 
   void
 GlobalRoutingLSA::SetLinkStateId (Ipv4Address addr)
 {
+  NS_LOG_FUNCTION;
   m_linkStateId = addr;
 }
 
   Ipv4Address
 GlobalRoutingLSA::GetAdvertisingRouter (void) const
 {
+  NS_LOG_FUNCTION;
   return m_advertisingRtr;
 }
 
   void
 GlobalRoutingLSA::SetAdvertisingRouter (Ipv4Address addr)
 {
+  NS_LOG_FUNCTION;
   m_advertisingRtr = addr;
 }
 
   void 
 GlobalRoutingLSA::SetNetworkLSANetworkMask (Ipv4Mask mask)
 {
+  NS_LOG_FUNCTION;
   m_networkLSANetworkMask = mask;
 }
 
   Ipv4Mask 
 GlobalRoutingLSA::GetNetworkLSANetworkMask (void) const
 {
+  NS_LOG_FUNCTION;
   return m_networkLSANetworkMask;
 }
 
   GlobalRoutingLSA::SPFStatus
 GlobalRoutingLSA::GetStatus (void) const
 {
+  NS_LOG_FUNCTION;
   return m_status;
 }
 
   uint32_t 
 GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr)
 {
+  NS_LOG_FUNCTION;
   m_attachedRouters.push_back (addr);
   return m_attachedRouters.size ();
 }
@@ -331,12 +350,14 @@
   uint32_t 
 GlobalRoutingLSA::GetNAttachedRouters (void) const
 {
+  NS_LOG_FUNCTION;
   return m_attachedRouters.size (); 
 }
 
   Ipv4Address 
 GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const
 {
+  NS_LOG_FUNCTION;
   uint32_t j = 0;
   for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin ();
         i != m_attachedRouters.end (); 
@@ -347,13 +368,15 @@
           return *i;
         }
     }
-  NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
+  NS_ASSERT_MSG(false, 
+    "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
   return Ipv4Address("0.0.0.0");
 }
 
   void
 GlobalRoutingLSA::SetStatus (GlobalRoutingLSA::SPFStatus status)
 {
+  NS_LOG_FUNCTION;
   m_status = status;
 }
 
@@ -414,20 +437,21 @@
 GlobalRouter::GlobalRouter (Ptr<Node> node)
   : m_node(node), m_LSAs()
 {
-  NS_DEBUG("GlobalRouter::GlobalRouter ()");
+  NS_LOG_FUNCTION;
   SetInterfaceId (GlobalRouter::iid);
   m_routerId.Set(GlobalRouteManager::AllocateRouterId ());
 }
 
 GlobalRouter::~GlobalRouter ()
 {
-  NS_DEBUG("GlobalRouter::~GlobalRouter ()");
+  NS_LOG_FUNCTION;
   ClearLSAs();
 }
 
 void
 GlobalRouter::DoDispose ()
 {
+  NS_LOG_FUNCTION;
   m_node = 0;
   Object::DoDispose ();
 }
@@ -435,13 +459,12 @@
   void
 GlobalRouter::ClearLSAs ()
 {
-  NS_DEBUG("GlobalRouter::ClearLSAs ()");
-
+  NS_LOG_FUNCTION;
   for ( ListOfLSAs_t::iterator i = m_LSAs.begin ();
         i != m_LSAs.end (); 
         i++)
     {
-      NS_DEBUG("GlobalRouter::ClearLSAs ():  free LSA");
+      NS_LOG_LOGIC ("Free LSA");
 
       GlobalRoutingLSA *p = *i;
       delete p;
@@ -449,13 +472,14 @@
 
       *i = 0;
     }
-  NS_DEBUG("GlobalRouter::ClearLSAs ():  clear list");
+  NS_LOG_LOGIC ("Clear list");
   m_LSAs.clear();
 }
 
   Ipv4Address
 GlobalRouter::GetRouterId (void) const
 {
+  NS_LOG_FUNCTION;
   return m_routerId;
 }
 
@@ -466,7 +490,8 @@
   uint32_t 
 GlobalRouter::DiscoverLSAs (void)
 {
-  NS_DEBUG("GlobalRouter::DiscoverLSAs () for node " << m_node->GetId () );
+  NS_LOG_FUNCTION;
+  NS_LOG_LOGIC("For node " << m_node->GetId () );
   NS_ASSERT_MSG(m_node, 
     "GlobalRouter::DiscoverLSAs (): <Node> interface not set");
 
@@ -499,14 +524,14 @@
 // ethernets, etc.).  
 //
   uint32_t numDevices = m_node->GetNDevices();
-  NS_DEBUG("GlobalRouter::DiscoverLSAs (): numDevices = " << numDevices);
+  NS_LOG_LOGIC ("numDevices = " << numDevices);
   for (uint32_t i = 0; i < numDevices; ++i)
     {
       Ptr<NetDevice> ndLocal = m_node->GetDevice(i);
 
       if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
         {
-          NS_DEBUG("GlobalRouter::DiscoverLSAs (): broadcast link");
+          NS_LOG_LOGIC ("Broadcast link");
           GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
 //
 // We need to determine whether we are on a transit or stub network
@@ -521,7 +546,7 @@
           uint32_t ifIndexLocal = FindIfIndexForDevice(m_node, ndLocal);
           Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
           Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
-          NS_DEBUG("Working with local address " << addrLocal);
+          NS_LOG_LOGIC ("Working with local address " << addrLocal);
 //
 // Now, we're going to walk over to the remote net device on the other end of 
 // the point-to-point channel we now know we have.  This is where our adjacent 
@@ -532,7 +557,7 @@
           if (nDevices == 1)
             {
               // This is a stub broadcast interface
-              NS_DEBUG("GlobalRouter::DiscoverLSAs (): Router-LSA stub broadcast link");
+              NS_LOG_LOGIC("Router-LSA stub broadcast link");
               // XXX in future, need to consider if >1 includes other routers
               plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
               // Link ID is IP network number of attached network
@@ -549,7 +574,7 @@
             }
           else
             {
-              NS_DEBUG("GlobalRouter::DiscoverLSAs (): Router-LSA Broadcast link");
+              NS_LOG_LOGIC ("Router-LSA Broadcast link");
               // multiple routers on a broadcast interface
               // lowest IP address is designated router
               plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
@@ -559,8 +584,7 @@
               if (desigRtr == addrLocal) 
                 {
                   listOfDRInterfaces.push_back (ndLocal);
-                  NS_DEBUG("GlobalRouter::DiscoverLSAs (): " << 
-                    m_node->GetId () << " is a DR");
+                  NS_LOG_LOGIC (m_node->GetId () << " is a DR");
                 }
               plr->SetLinkId (desigRtr);
               // Link Data is router's own IP address
@@ -574,7 +598,7 @@
         }
       else if (ndLocal->IsPointToPoint () )
         {
-          NS_DEBUG("GlobalRouter::DiscoverLSAs (): Router-LSA Point-to-point device");
+          NS_LOG_LOGIC ("Router-LSA Point-to-point device");
 //
 // Now, we have to find the Ipv4 interface whose netdevice is the one we 
 // just found.  This is still the IP on the local side of the channel.  There 
@@ -588,7 +612,7 @@
 //
           Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
           Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
-          NS_DEBUG("Working with local address " << addrLocal);
+          NS_LOG_LOGIC ("Working with local address " << addrLocal);
 //
 // Now, we're going to walk over to the remote net device on the other end of 
 // the point-to-point channel we now know we have.  This is where our adjacent 
@@ -613,7 +637,7 @@
           NS_ASSERT_MSG(srRemote, 
             "GlobalRouter::DiscoverLSAs():QI for remote <GlobalRouter> failed");
           Ipv4Address rtrIdRemote = srRemote->GetRouterId();
-          NS_DEBUG("Working with remote router " << rtrIdRemote);
+          NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
 //
 // Now, just like we did above, we need to get the IP interface index for the 
 // net device on the other end of the point-to-point channel.
@@ -625,7 +649,7 @@
 //
           Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
           Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
-          NS_DEBUG("Working with remote address " << addrRemote);
+          NS_LOG_LOGIC ("Working with remote address " << addrRemote);
 //
 // Now we can fill out the link records for this link.  There are always two
 // link records; the first is a point-to-point record describing the link and
@@ -655,8 +679,7 @@
 // The LSA goes on a list of LSAs in case we want to begin exporting other
 // kinds of advertisements (than Router LSAs).
   m_LSAs.push_back (pLSA);
-  NS_DEBUG(*pLSA);
-
+  NS_LOG_LOGIC (*pLSA);
 
 // Now, determine whether we need to build a NetworkLSA
   if (listOfDRInterfaces.size () > 0)
@@ -692,7 +715,7 @@
               pLSA->AddAttachedRouter (tempAddr);
             }
           m_LSAs.push_back (pLSA);
-          NS_DEBUG(*pLSA);
+          NS_LOG_LOGIC (*pLSA);
         }
     }
 
@@ -734,7 +757,7 @@
   uint32_t 
 GlobalRouter::GetNumLSAs (void) const
 {
-  NS_DEBUG("GlobalRouter::GetNumLSAs ()");
+  NS_LOG_FUNCTION;
   return m_LSAs.size ();
 }
 
@@ -744,6 +767,7 @@
   bool
 GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const
 {
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG(lsa.IsEmpty(), "GlobalRouter::GetLSA (): Must pass empty LSA");
 //
 // All of the work was done in GetNumLSAs.  All we have to do here is to
@@ -773,7 +797,7 @@
   Ptr<NetDevice>
 GlobalRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const
 {
-
+  NS_LOG_FUNCTION;
   NS_ASSERT_MSG(ch->GetNDevices() == 2, 
     "GlobalRouter::GetAdjacent (): Channel with other than two devices");
 //
@@ -809,6 +833,7 @@
   uint32_t
 GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const
 {
+  NS_LOG_FUNCTION;
   Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
   NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed");
   for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
--- a/src/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/src/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -18,7 +18,9 @@
     'internet-node',
     'devices/point-to-point',
     'devices/csma',
-    'applications',
+    'applications/onoff',
+    'applications/packet-sink',
+    'applications/udp-echo',
     'routing/olsr',
     'routing/global-routing',
     'mobility',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tutorial/hello-simulator.cc	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,29 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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
+ */
+
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("HelloSimulator");
+
+using namespace ns3;
+
+int 
+main (int argc, char *argv[])
+{
+  LogComponentEnable ("HelloSimulator", LOG_LEVEL_INFO);
+
+  NS_LOG_INFO ("Hello Simulator");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tutorial/waf	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../waf "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tutorial/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -0,0 +1,6 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    obj = bld.create_ns3_program('hello-simulator',
+        ['core'])
+    obj.source = 'hello-simulator.cc'
--- a/wscript	Thu Sep 13 15:31:55 2007 +0100
+++ b/wscript	Fri Sep 21 13:59:03 2007 +0100
@@ -119,6 +119,7 @@
     if 'debug' in Params.g_options.debug_level.lower():
         variant_env.append_value('CXXDEFINES', 'NS3_DEBUG_ENABLE')
         variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
+        variant_env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
 
     ## In optimized builds we still want debugging symbols, e.g. for
     ## profiling, and at least partially usable stack traces.
@@ -177,7 +178,7 @@
 
     # process subfolders from here
     bld.add_subdirs('src')
-    bld.add_subdirs('samples utils examples')
+    bld.add_subdirs('samples utils examples tutorial')
 
     ## Create a single ns3 library containing all modules
     lib = bld.create_obj('cpp', 'shlib')