From 77e7c6f60f94429c57c6d875716638da16019a71 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 12 Sep 2007 15:23:25 -0700 Subject: [PATCH 01/22] start of udp echo applications --- examples/udp-echo.cc | 200 ++++++++++++++++++ examples/wscript | 4 + samples/wscript | 2 +- .../{ => onoff}/onoff-application.cc | 0 .../{ => onoff}/onoff-application.h | 0 src/applications/{ => onoff}/wscript | 8 +- .../{ => packet-sink}/packet-sink.cc | 0 .../{ => packet-sink}/packet-sink.h | 0 src/applications/packet-sink/wscript | 12 ++ src/applications/udp-echo/udp-echo-client.cc | 192 +++++++++++++++++ src/applications/udp-echo/udp-echo-client.h | 70 ++++++ src/applications/udp-echo/wscript | 12 ++ src/applications/waf | 1 - src/internet-node/wscript | 2 +- src/wscript | 4 +- 15 files changed, 498 insertions(+), 9 deletions(-) create mode 100644 examples/udp-echo.cc rename src/applications/{ => onoff}/onoff-application.cc (100%) rename src/applications/{ => onoff}/onoff-application.h (100%) rename src/applications/{ => onoff}/wscript (66%) rename src/applications/{ => packet-sink}/packet-sink.cc (100%) rename src/applications/{ => packet-sink}/packet-sink.h (100%) create mode 100644 src/applications/packet-sink/wscript create mode 100644 src/applications/udp-echo/udp-echo-client.cc create mode 100644 src/applications/udp-echo/udp-echo-client.h create mode 100644 src/applications/udp-echo/wscript delete mode 100755 src/applications/waf diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc new file mode 100644 index 000000000..5a0280695 --- /dev/null +++ b/examples/udp-echo.cc @@ -0,0 +1,200 @@ +/* -*- 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 +// +// - CBR/UDP flows from n0 to n1 and from n3 to n0 +// - DropTail queues +// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" + +#include "ns3/command-line.h" +#include "ns3/default-value.h" +#include "ns3/ptr.h" +#include "ns3/debug.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/eui48-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" + +using namespace ns3; + +NS_DEBUG_COMPONENT_DEFINE ("UdpEcho"); + +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 1 + DebugComponentEnable("CsmaOneSubnet"); + + 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"); + DebugComponentEnable("UdpEchoClient"); +#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_DEBUG("Create nodes."); + Ptr n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + + NS_DEBUG("Create channels."); +// +// Explicitly create the channels required by the topology (shown above). +// + Ptr lan = CsmaTopology::CreateCsmaChannel( + DataRate(5000000), MilliSeconds(2)); + + NS_DEBUG("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, + Eui48Address("08:00:2e:00:00:00")); + + uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, + Eui48Address("08:00:2e:00:00:01")); + + uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, + Eui48Address("08:00:2e:00:00:02")); + + uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, + Eui48Address("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."); +// +// 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")); +// +// Create a UdpEchoClient application to send UDP datagrams from node zero to +// node 1. +// + NS_DEBUG("Create Applications."); + Ptr client = Create (n0,"10.1.1.2", 80, + 1, Seconds(1.), 1024); +// +// Tell the application when to start and stop. +// + client->Start(Seconds(1.0)); + client->Stop (Seconds(10.0)); +// +// 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."); + AsciiTrace asciitrace ("csma-one-subnet.tr"); + asciitrace.TraceAllNetDeviceRx (); + asciitrace.TraceAllQueues (); +// +// Also configure some tcpdump traces; each interface will be traced. +// The output files will be named: +// csma-one-subnet.pcap-- +// and can be read by the "tcpdump -r" command (use "-tt" option to +// display timestamps correctly) +// + PcapTrace pcaptrace ("csma-one-subnet.pcap"); + pcaptrace.TraceAllIp (); +// +// Now, do the actual simulation. +// + NS_DEBUG("Run Simulation."); + Simulator::Run (); + Simulator::Destroy (); + NS_DEBUG("Done."); +} diff --git a/examples/wscript b/examples/wscript index 0c887cad0..a1f16e29b 100644 --- a/examples/wscript +++ b/examples/wscript @@ -14,6 +14,10 @@ def build(bld): ['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' diff --git a/samples/wscript b/samples/wscript index d8733131a..e89fbe9b8 100644 --- a/samples/wscript +++ b/samples/wscript @@ -26,7 +26,7 @@ def build(bld): 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', diff --git a/src/applications/onoff-application.cc b/src/applications/onoff/onoff-application.cc similarity index 100% rename from src/applications/onoff-application.cc rename to src/applications/onoff/onoff-application.cc diff --git a/src/applications/onoff-application.h b/src/applications/onoff/onoff-application.h similarity index 100% rename from src/applications/onoff-application.h rename to src/applications/onoff/onoff-application.h diff --git a/src/applications/wscript b/src/applications/onoff/wscript similarity index 66% rename from src/applications/wscript rename to src/applications/onoff/wscript index 760f76e18..c1bfe4c52 100644 --- a/src/applications/wscript +++ b/src/applications/onoff/wscript @@ -1,14 +1,12 @@ ## -*- 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 = [ + module = bld.create_ns3_module('onoff', ['core']) + module.source = [ 'onoff-application.cc', - 'packet-sink.cc', ] - headers = bld.create_obj('ns3header') headers.source = [ 'onoff-application.h', - 'packet-sink.h', ] + diff --git a/src/applications/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc similarity index 100% rename from src/applications/packet-sink.cc rename to src/applications/packet-sink/packet-sink.cc diff --git a/src/applications/packet-sink.h b/src/applications/packet-sink/packet-sink.h similarity index 100% rename from src/applications/packet-sink.h rename to src/applications/packet-sink/packet-sink.h diff --git a/src/applications/packet-sink/wscript b/src/applications/packet-sink/wscript new file mode 100644 index 000000000..332b6e4a1 --- /dev/null +++ b/src/applications/packet-sink/wscript @@ -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', + ] + diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc new file mode 100644 index 000000000..317a91065 --- /dev/null +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -0,0 +1,192 @@ +/* -*- 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/debug.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" + +#if 0 +int sock; /* Socket descriptor */ +struct sockaddr_in echoServAddr; /* Echo server address */ +struct sockaddr_in fromAddr; /* Source address of echo */ +unsigned short echoServPort; /* Echo server port */ +unsigned int fromSize; /* In-out of address size for recvfrom() */ +char *servIP; /* IP address of server */ +char *echoString; /* String to send to echo server */ +char echoBuffer[ECHOMAX+1]; /* Buffer for receiving echoed string */ +int echoStringLen; /* Length of string to echo */ +int respStringLen; /* Length of received response */ + +if ((echoStringLen = strlen(echoString)) > ECHOMAX) /* Check input length */ + DieWithError("Echo word too long"); + +if (argc == 4) + echoServPort = atoi(argv[3]); /* Use given port, if any */ + else + echoServPort = 7; /* 7 is the well-known port for the echo service */ + +/* Create a datagram/UDP socket */ +if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + DieWithError("socket() failed"); + +/* Construct the server address structure */ +memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ +echoServAddr.sin_family = AF_INET; /* Internet addr family */ +echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ +echoServAddr.sin_port = htons(echoServPort); /* Server port */ + +/* Send the string to the server */ +if (sendto(sock, echoString, echoStringLen, 0, (struct sockaddr *) + &echoServAddr, sizeof(echoServAddr)) != echoStringLen) + DieWithError("sendto() sent a different number of bytes than expected"); + +/* Recv a response */ +fromSize = sizeof(fromAddr); +if ((respStringLen = recvfrom(sock, echoBuffer, ECHOMAX, 0, + (struct sockaddr *) &fromAddr, &fromSize)) != echoStringLen) + DieWithError("recvfrom() failed"); + +if (echoServAddr.sin_addr.s_addr != fromAddr.sin_addr.s_addr) + { + fprintf(stderr,"Error: received a packet from unknown source.\n"); + exit(1); + } + +/* null-terminate the received data */ +echoBuffer[respStringLen] = '\0'; +printf("Received: %s\n", echoBuffer); /* Print the echoed arg */ + +close(sock); +exit(0); +#endif + +namespace ns3 { + +NS_DEBUG_COMPONENT_DEFINE ("UdpEchoClient"); + +UdpEchoClient::UdpEchoClient ( + Ptr n, + Ipv4Address serverAddress, + uint16_t serverPort, + uint32_t count, + Time interval, + uint32_t size) +: + Application(n) +{ + NS_DEBUG ("UdpEchoClient::UdpEchoClient (" << n << ", " << serverAddress << + ", " << serverPort << ", " << count << ", " << interval << + ", " << size << ")"); + + Construct (n, serverAddress, serverPort, count, interval, size); +} + +UdpEchoClient::~UdpEchoClient() +{ + NS_DEBUG ("UdpEchoClient::~UdpEchoClient ()"); +} + +void +UdpEchoClient::Construct ( + Ptr n, + Ipv4Address serverAddress, + uint16_t serverPort, + uint32_t count, + Time interval, + uint32_t size) +{ + NS_DEBUG ("UdpEchoClient::Construct (" << 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_DEBUG ("UdpEchoClient::DoDispose ()"); + Application::DoDispose (); +} + +void +UdpEchoClient::StartApplication (void) +{ + NS_DEBUG ("UdpEchoClient::StartApplication ()"); + + if (!m_socket) + { + InterfaceId iid = InterfaceId::LookupByName ("Udp"); + Ptr socketFactory = + GetNode ()->QueryInterface (iid); + m_socket = socketFactory->CreateSocket (); + m_socket->Bind (); + m_socket->Connect (m_peer); + } + + StopApplication (); + ScheduleTransmit (Seconds(0.)); +} + +void +UdpEchoClient::StopApplication () +{ + NS_DEBUG ("UdpEchoClient::StopApplication ()"); +} + +void +UdpEchoClient::ScheduleTransmit (Time dt) +{ + NS_DEBUG ("UdpEchoClient::ScheduleTransmit (" << dt << ")"); + m_sendEvent = Simulator::Schedule(dt, &UdpEchoClient::Send, this); +} + +void +UdpEchoClient::Send (void) +{ + NS_DEBUG ("UdpEchoClient::Send ()"); + + NS_ASSERT (m_sendEvent.IsExpired ()); + + Packet p (m_size); + m_socket->Send (p); + ++m_sent; + + if (m_sent < m_count) + { + ScheduleTransmit (m_interval); + } +} + +} // Namespace ns3 diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h new file mode 100644 index 000000000..7c5f2478a --- /dev/null +++ b/src/applications/udp-echo/udp-echo-client.h @@ -0,0 +1,70 @@ +/* -*- 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 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 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); + + Ptr 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 m_socket; + Address m_peer; + EventId m_sendEvent; + +}; + +} // namespace ns3 + +#endif // __UDP_ECHO_CLIENT_H__ + diff --git a/src/applications/udp-echo/wscript b/src/applications/udp-echo/wscript new file mode 100644 index 000000000..00cbaa3c5 --- /dev/null +++ b/src/applications/udp-echo/wscript @@ -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('udp-echo', ['internet-node']) + module.source = [ + 'udp-echo-client.cc', + ] + headers = bld.create_obj('ns3header') + headers.source = [ + 'udp-echo-client.h', + ] + diff --git a/src/applications/waf b/src/applications/waf deleted file mode 100755 index 3dcf598bc..000000000 --- a/src/applications/waf +++ /dev/null @@ -1 +0,0 @@ -exec "`dirname "$0"`"/../../waf "$@" \ No newline at end of file diff --git a/src/internet-node/wscript b/src/internet-node/wscript index a5f5ec6ef..3bb60d1bb 100644 --- a/src/internet-node/wscript +++ b/src/internet-node/wscript @@ -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', diff --git a/src/wscript b/src/wscript index 859021e66..27c0154c9 100644 --- a/src/wscript +++ b/src/wscript @@ -18,7 +18,9 @@ all_modules = ( 'internet-node', 'devices/point-to-point', 'devices/csma', - 'applications', + 'applications/onoff', + 'applications/packet-sink', + 'applications/udp-echo', 'routing/global-routing', 'mobility', ) From 0e3ff45eb9238a70d09b6bf13af4097250d49292 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 12 Sep 2007 16:20:07 -0700 Subject: [PATCH 02/22] server half --- examples/udp-echo.cc | 25 ++-- src/applications/onoff/waf | 1 + src/applications/packet-sink/waf | 1 + src/applications/udp-echo/udp-echo-server.cc | 120 +++++++++++++++++++ src/applications/udp-echo/udp-echo-server.h | 61 ++++++++++ src/applications/udp-echo/waf | 1 + src/applications/udp-echo/wscript | 2 + 7 files changed, 204 insertions(+), 7 deletions(-) create mode 100755 src/applications/onoff/waf create mode 100755 src/applications/packet-sink/waf create mode 100644 src/applications/udp-echo/udp-echo-server.cc create mode 100644 src/applications/udp-echo/udp-echo-server.h create mode 100755 src/applications/udp-echo/waf diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 5a0280695..b59c2b5a8 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -23,7 +23,7 @@ // // - CBR/UDP flows from n0 to n1 and from n3 to n0 // - DropTail queues -// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" +// - Tracing of queues and packet receptions to file "udp-echo.tr" #include "ns3/command-line.h" #include "ns3/default-value.h" @@ -46,6 +46,7 @@ #include "ns3/socket.h" #include "ns3/ipv4-route.h" #include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" using namespace ns3; @@ -161,12 +162,13 @@ main (int argc, char *argv[]) CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0")); + + NS_DEBUG("Create Applications."); // // Create a UdpEchoClient application to send UDP datagrams from node zero to // node 1. // - NS_DEBUG("Create Applications."); - Ptr client = Create (n0,"10.1.1.2", 80, + Ptr client = Create (n0, "10.1.1.2", 80, 1, Seconds(1.), 1024); // // Tell the application when to start and stop. @@ -174,21 +176,30 @@ main (int argc, char *argv[]) client->Start(Seconds(1.0)); client->Stop (Seconds(10.0)); // +// Create a UdpEchoServer application on node 1. +// + Ptr server = Create (n0, "0.0.0.0", 80); +// +// Tell the application when to start and stop. +// + server->Start(Seconds(0.)); + server->Stop (Seconds(10.0)); +// // Configure tracing of all enqueue, dequeue, and NetDevice receive events. -// Trace output will be sent to the file "csma-one-subnet.tr" +// Trace output will be sent to the file "udp-echo.tr" // NS_DEBUG("Configure Tracing."); - AsciiTrace asciitrace ("csma-one-subnet.tr"); + 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: -// csma-one-subnet.pcap-- +// udp-echo.pcap-- // and can be read by the "tcpdump -r" command (use "-tt" option to // display timestamps correctly) // - PcapTrace pcaptrace ("csma-one-subnet.pcap"); + PcapTrace pcaptrace ("udp-echo.pcap"); pcaptrace.TraceAllIp (); // // Now, do the actual simulation. diff --git a/src/applications/onoff/waf b/src/applications/onoff/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/applications/onoff/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" diff --git a/src/applications/packet-sink/waf b/src/applications/packet-sink/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/applications/packet-sink/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc new file mode 100644 index 000000000..26958b80f --- /dev/null +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -0,0 +1,120 @@ +/* -*- 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/debug.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_DEBUG_COMPONENT_DEFINE ("UdpEchoServer"); + +UdpEchoServer::UdpEchoServer ( + Ptr n, + Ipv4Address clientAddress, + uint16_t clientPort) +: + Application(n) +{ + NS_DEBUG ("UdpEchoServer::UdpEchoServer (" << n << ", " << clientAddress << + ", " << clientPort << ")"); + + Construct (n, clientAddress, clientPort); +} + +UdpEchoServer::~UdpEchoServer() +{ + NS_DEBUG ("UdpEchoServer::~UdpEchoServer ()"); +} + +void +UdpEchoServer::Construct ( + Ptr n, + Ipv4Address clientAddress, + uint16_t clientPort) +{ + NS_DEBUG ("UdpEchoServer::Construct (" << n << ", " << clientAddress << + ", " << clientPort << ")"); + + m_node = n; + m_clientAddress = clientAddress; + m_clientPort = clientPort; + + m_socket = 0; + m_client = InetSocketAddress (clientAddress, clientPort); +} + +void +UdpEchoServer::DoDispose (void) +{ + NS_DEBUG ("UdpEchoServer::DoDispose ()"); + Application::DoDispose (); +} + +void +UdpEchoServer::StartApplication (void) +{ + NS_DEBUG ("UdpEchoServer::StartApplication ()"); + + if (!m_socket) + { + InterfaceId iid = InterfaceId::LookupByName ("Udp"); + Ptr socketFactory = + GetNode ()->QueryInterface (iid); + m_socket = socketFactory->CreateSocket (); + m_socket->Bind (m_client); + } + + m_socket->SetRecvCallback((Callback, const Packet &, + const Address &>) MakeCallback(&UdpEchoServer::Receive, this)); +} + +void +UdpEchoServer::StopApplication () +{ + NS_DEBUG ("UdpEchoServer::StopApplication ()"); + if (!m_socket) + { + m_socket->SetRecvCallback((Callback, const Packet &, + const Address &>) NULL); + } +} + +void UdpEchoServer::Receive( + Ptr socket, + const Packet &packet, + const Address &from) +{ + NS_DEBUG ("UdpEchoServer::Receive (" << socket << ", " << packet << + ", " << from << ")"); + + if (InetSocketAddress::IsMatchingType (from)) + { + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); + NS_DEBUG ("UdpEchoServer::Receive(): Received " << + packet.GetSize() << " bytes from " << address.GetIpv4()); + } +} + +} // Namespace ns3 diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h new file mode 100644 index 000000000..d9de1221f --- /dev/null +++ b/src/applications/udp-echo/udp-echo-server.h @@ -0,0 +1,61 @@ +/* -*- 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 n, Ipv4Address clientAddr, uint16_t clientPort); + virtual ~UdpEchoServer (); + +protected: + virtual void DoDispose (void); + +private: + void Construct (Ptr n, Ipv4Address clientAddr, uint16_t clientPort); + + virtual void StartApplication (void); + virtual void StopApplication (void); + + void Receive(Ptr socket, const Packet &packet, + const Address &from); + + Ptr m_node; + Ipv4Address m_clientAddress; + uint16_t m_clientPort; + + Ptr m_socket; + Address m_client; +}; + +} // namespace ns3 + +#endif // __UDP_ECHO_SERVER_H__ + diff --git a/src/applications/udp-echo/waf b/src/applications/udp-echo/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/applications/udp-echo/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" diff --git a/src/applications/udp-echo/wscript b/src/applications/udp-echo/wscript index 00cbaa3c5..f6416980a 100644 --- a/src/applications/udp-echo/wscript +++ b/src/applications/udp-echo/wscript @@ -4,9 +4,11 @@ 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', ] From 51a6c25e1645be919a4201e6dcb77978e981854d Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 12 Sep 2007 16:24:31 -0700 Subject: [PATCH 03/22] log rides along for free --- src/core/log.cc | 269 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/log.h | 167 +++++++++++++++++++++++++++++ src/core/wscript | 2 + 3 files changed, 438 insertions(+) create mode 100644 src/core/log.cc create mode 100644 src/core/log.h diff --git a/src/core/log.cc b/src/core/log.cc new file mode 100644 index 000000000..fa1c6f6f9 --- /dev/null +++ b/src/core/log.cc @@ -0,0 +1,269 @@ +/* -*- 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 + */ +#include +#include +#include +#include "log.h" +#include "assert.h" +#include "ns3/core-config.h" +#include "fatal-error.h" + +#ifdef HAVE_STDLIB_H +#include +#endif + +namespace ns3 { + +typedef std::list > ComponentList; +typedef std::list >::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_LEVEL_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 == "debug") + { + level |= LOG_LEVEL_DEBUG; + } + else if (lev == "func") + { + level |= LOG_LEVEL_FUNCTION; + } + else if (lev == "param") + { + level |= LOG_LEVEL_PARAM; + } + else if (lev == "warn") + { + level |= LOG_LEVEL_WARN; + } + else if (lev == "error") + { + level |= LOG_LEVEL_ERROR; + } + } 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; +} +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_LEVEL_DEBUG)) + { + std::cout << "debug"; + } + if (i->second->IsEnabled (LOG_LEVEL_FUNCTION)) + { + std::cout << "|func"; + } + if (i->second->IsEnabled (LOG_LEVEL_PARAM)) + { + std::cout << "|param"; + } + if (i->second->IsEnabled (LOG_LEVEL_WARN)) + { + std::cout << "|warn"; + } + if (i->second->IsEnabled (LOG_LEVEL_ERROR)) + { + std::cout << "|error"; + } + std::cout << std::endl; + } +} + +} // namespace ns3 + + diff --git a/src/core/log.h b/src/core/log.h new file mode 100644 index 000000000..3745164c8 --- /dev/null +++ b/src/core/log.h @@ -0,0 +1,167 @@ +/* -*- 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 + */ +#ifndef LOG_H +#define LOG_H + +#include +#include + +/** + * \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. + */ +#define NS_LOG_COMPONENT_DEFINE(name) \ + static ns3::LogComponent g_log = ns3::LogComponent (name) + +/** + * \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. + */ +#define NS_LOG(level,msg) \ + do \ + { \ + if (g_log.IsEnabled (level)) \ + { \ + std::clog << msg << std::endl; \ + } \ + } \ + while (false) + +#define NS_LOG_DEBUG(msg) \ + NS_LOG (ns3::LOG_LEVEL_DEBUG,msg) + +#define NS_LOG_FUNCTION \ + NS_LOG (ns3::LOG_LEVEL_FUNCTION, __PRETTY_PRINT__) + +#define NS_LOG_PARAM(msg) \ + NS_LOG (ns3::LOG_LEVEL_PARAM,msg) + +#define NS_LOG_WARN(msg) \ + NS_LOG (ns3::LOG_LEVEL_WARN,msg) + +#define NS_LOG_ERROR(msg) \ + NS_LOG (ns3::LOG_LEVEL_ERROR,msg) + +#define NS_LOG_UNCOND(msg) \ + do \ + { \ + std::clog << msg << std::endl; \ + } \ + while (false) + + + +namespace ns3 { + +enum LogLevel { + LOG_LEVEL_DEBUG = 1<<0, + LOG_LEVEL_FUNCTION = 1<<1, + LOG_LEVEL_PARAM = 1<<2, + LOG_LEVEL_WARN = 1<<3, + LOG_LEVEL_ERROR = 1<<4, + LOG_LEVEL_LAST = 1<<31 +}; + +/** + * \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. + */ +void LogComponentEnable (char const *name, enum LogLevel level); + +/** + * \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. + */ +void LogComponentDisable (char const *name, enum LogLevel level); + +/** + * \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 + */ +void LogComponentPrintList (void); + +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: + uint32_t m_levels; +}; + +} // namespace ns3 + +#endif /* LOG_H */ diff --git a/src/core/wscript b/src/core/wscript index 455779fd6..5806f254b 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -30,6 +30,7 @@ def build(bld): core.source = [ 'callback-test.cc', 'debug.cc', + 'log.cc', 'breakpoint.cc', 'ptr.cc', 'object.cc', @@ -69,6 +70,7 @@ def build(bld): 'ptr.h', 'object.h', 'debug.h', + 'log.h', 'assert.h', 'breakpoint.h', 'fatal-error.h', From 61a105af21099235ba4faf891348db9e1a645aa8 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 12 Sep 2007 16:54:21 -0700 Subject: [PATCH 04/22] working one way echo app --- examples/csma-broadcast.cc | 1 + examples/csma-multicast.cc | 1 + examples/csma-one-subnet.cc | 1 + examples/simple-point-to-point.cc | 1 + examples/udp-echo.cc | 30 ++++++---- src/applications/udp-echo/udp-echo-client.cc | 59 +------------------ src/node/socket.cc | 61 ++++++++++++++++---- 7 files changed, 76 insertions(+), 78 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index b032f0aea..c0ad09770 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -77,6 +77,7 @@ int main (int argc, char *argv[]) DebugComponentEnable("Ipv4L3Protocol"); DebugComponentEnable("OnOffApplication"); DebugComponentEnable("PacketSocket"); + DebugComponentEnable("Socket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 6bae090ff..df1c51f01 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -76,6 +76,7 @@ main (int argc, char *argv[]) DebugComponentEnable("Ipv4L3Protocol"); DebugComponentEnable("OnOffApplication"); DebugComponentEnable("PacketSocket"); + DebugComponentEnable("Socket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index 19d9200ff..ef3496a12 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -72,6 +72,7 @@ main (int argc, char *argv[]) DebugComponentEnable("NetDevice"); DebugComponentEnable("PacketSocket"); DebugComponentEnable("OnOffApplication"); + DebugComponentEnable("Socket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index 4b9de40f4..91214f53a 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -85,6 +85,7 @@ main (int argc, char *argv[]) DebugComponentEnable("NetDevice"); DebugComponentEnable("PacketSocket"); DebugComponentEnable("OnOffApplication"); + DebugComponentEnable("Socket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index b59c2b5a8..7e169dc8a 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -59,8 +59,8 @@ 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 1 - DebugComponentEnable("CsmaOneSubnet"); +#if 0 + DebugComponentEnable("UdpEcho"); DebugComponentEnable("Object"); DebugComponentEnable("Queue"); @@ -72,6 +72,7 @@ main (int argc, char *argv[]) DebugComponentEnable("NetDevice"); DebugComponentEnable("PacketSocket"); DebugComponentEnable("OnOffApplication"); + DebugComponentEnable("Socket"); DebugComponentEnable("UdpSocket"); DebugComponentEnable("UdpL4Protocol"); DebugComponentEnable("Ipv4L3Protocol"); @@ -80,7 +81,12 @@ main (int argc, char *argv[]) DebugComponentEnable("ArpIpv4Interface"); DebugComponentEnable("Ipv4LoopbackInterface"); DebugComponentEnable("UdpEchoClient"); + DebugComponentEnable("UdpEchoServer"); #endif + + DebugComponentEnable("UdpEcho"); + DebugComponentEnable("UdpEchoClient"); + DebugComponentEnable("UdpEchoServer"); // // Set up default values for the simulation. Use the DefaultValue::Bind() // technique to tell the system what subclass of Queue to use. The Bind @@ -165,6 +171,15 @@ main (int argc, char *argv[]) NS_DEBUG("Create Applications."); // +// Create a UdpEchoServer application on node 1. +// + Ptr server = Create (n1, "0.0.0.0", 80); +// +// Tell the application when to start and stop. +// + server->Start(Seconds(1.)); + server->Stop (Seconds(10.0)); +// // Create a UdpEchoClient application to send UDP datagrams from node zero to // node 1. // @@ -173,18 +188,9 @@ main (int argc, char *argv[]) // // Tell the application when to start and stop. // - client->Start(Seconds(1.0)); + client->Start(Seconds(2.0)); client->Stop (Seconds(10.0)); // -// Create a UdpEchoServer application on node 1. -// - Ptr server = Create (n0, "0.0.0.0", 80); -// -// Tell the application when to start and stop. -// - server->Start(Seconds(0.)); - server->Stop (Seconds(10.0)); -// // Configure tracing of all enqueue, dequeue, and NetDevice receive events. // Trace output will be sent to the file "udp-echo.tr" // diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 317a91065..8bcd1c8ed 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -23,64 +23,8 @@ #include "ns3/simulator.h" #include "ns3/socket-factory.h" #include "ns3/packet.h" - #include "udp-echo-client.h" -#if 0 -int sock; /* Socket descriptor */ -struct sockaddr_in echoServAddr; /* Echo server address */ -struct sockaddr_in fromAddr; /* Source address of echo */ -unsigned short echoServPort; /* Echo server port */ -unsigned int fromSize; /* In-out of address size for recvfrom() */ -char *servIP; /* IP address of server */ -char *echoString; /* String to send to echo server */ -char echoBuffer[ECHOMAX+1]; /* Buffer for receiving echoed string */ -int echoStringLen; /* Length of string to echo */ -int respStringLen; /* Length of received response */ - -if ((echoStringLen = strlen(echoString)) > ECHOMAX) /* Check input length */ - DieWithError("Echo word too long"); - -if (argc == 4) - echoServPort = atoi(argv[3]); /* Use given port, if any */ - else - echoServPort = 7; /* 7 is the well-known port for the echo service */ - -/* Create a datagram/UDP socket */ -if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) - DieWithError("socket() failed"); - -/* Construct the server address structure */ -memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ -echoServAddr.sin_family = AF_INET; /* Internet addr family */ -echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ -echoServAddr.sin_port = htons(echoServPort); /* Server port */ - -/* Send the string to the server */ -if (sendto(sock, echoString, echoStringLen, 0, (struct sockaddr *) - &echoServAddr, sizeof(echoServAddr)) != echoStringLen) - DieWithError("sendto() sent a different number of bytes than expected"); - -/* Recv a response */ -fromSize = sizeof(fromAddr); -if ((respStringLen = recvfrom(sock, echoBuffer, ECHOMAX, 0, - (struct sockaddr *) &fromAddr, &fromSize)) != echoStringLen) - DieWithError("recvfrom() failed"); - -if (echoServAddr.sin_addr.s_addr != fromAddr.sin_addr.s_addr) - { - fprintf(stderr,"Error: received a packet from unknown source.\n"); - exit(1); - } - -/* null-terminate the received data */ -echoBuffer[respStringLen] = '\0'; -printf("Received: %s\n", echoBuffer); /* Print the echoed arg */ - -close(sock); -exit(0); -#endif - namespace ns3 { NS_DEBUG_COMPONENT_DEFINE ("UdpEchoClient"); @@ -183,6 +127,9 @@ UdpEchoClient::Send (void) m_socket->Send (p); ++m_sent; + NS_DEBUG ("UdpEchoClient::Send (): Sent " << m_size << " bytes to " << + m_serverAddress); + if (m_sent < m_count) { ScheduleTransmit (m_interval); diff --git a/src/node/socket.cc b/src/node/socket.cc index 58f83947f..efb28002a 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -19,83 +19,114 @@ * Authors: George F. Riley * Mathieu Lacage */ -#include "socket.h" + +#include "ns3/debug.h" #include "ns3/packet.h" +#include "socket.h" + +NS_DEBUG_COMPONENT_DEFINE ("Socket"); namespace ns3 { Socket::~Socket () -{} +{ + NS_DEBUG("Socket::~Socket ()"); +} void Socket::SetCloseCallback (Callback > closeCompleted) { + NS_DEBUG("Socket::SetCloseCallback ()"); m_closeCompleted = closeCompleted; } + void -Socket::SetConnectCallback (Callback > connectionSucceeded, - Callback > connectionFailed, - Callback > halfClose) +Socket::SetConnectCallback ( + Callback > connectionSucceeded, + Callback > connectionFailed, + Callback > halfClose) { + NS_DEBUG("Socket::SetConnectCallback ()"); m_connectionSucceeded = connectionSucceeded; m_connectionFailed = connectionFailed; m_halfClose = halfClose; } + void -Socket::SetAcceptCallback (Callback, const Address &> connectionRequest, - Callback, const Address&> newConnectionCreated, - Callback > closeRequested) +Socket::SetAcceptCallback ( + Callback, const Address &> connectionRequest, + Callback, const Address&> newConnectionCreated, + Callback > closeRequested) { + NS_DEBUG("Socket::SetAcceptCallback ()"); m_connectionRequest = connectionRequest; m_newConnectionCreated = newConnectionCreated; m_closeRequested = closeRequested; } + void Socket::SetSendCallback (Callback, uint32_t> dataSent) { + NS_DEBUG("Socket::SetSendCallback ()"); m_dataSent = dataSent; } + void Socket::SetRecvCallback (Callback, const Packet &,const Address&> receivedData) { + NS_DEBUG("Socket::SetRecvCallback ()"); m_receivedData = receivedData; } void Socket::NotifyCloseCompleted (void) { + NS_DEBUG("Socket::NotifyCloseCompleted ()"); + if (!m_closeCompleted.IsNull ()) { m_closeCompleted (this); } } + void Socket::NotifyConnectionSucceeded (void) { + NS_DEBUG("Socket::NotifyConnectionSucceeded ()"); + if (!m_connectionSucceeded.IsNull ()) { m_connectionSucceeded (this); } } + void Socket::NotifyConnectionFailed (void) { + NS_DEBUG("Socket::NotifyConnectionFailed ()"); + if (!m_connectionFailed.IsNull ()) { m_connectionFailed (this); } } + void Socket::NotifyHalfClose (void) { + NS_DEBUG("Socket::NotifyHalfClose ()"); + if (!m_halfClose.IsNull ()) { m_halfClose (this); } } + bool Socket::NotifyConnectionRequest (const Address &from) { + NS_DEBUG("Socket::NotifyConnectionRequest ()"); + if (!m_connectionRequest.IsNull ()) { return m_connectionRequest (this, from); @@ -106,39 +137,49 @@ Socket::NotifyConnectionRequest (const Address &from) return false; } } + void Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) { + NS_DEBUG("Socket::NotifyNewConnectionCreated ()"); + if (!m_newConnectionCreated.IsNull ()) { m_newConnectionCreated (socket, from); } } + void Socket::NotifyCloseRequested (void) { + NS_DEBUG("Socket::NotifyCloseRequested ()"); + if (!m_closeRequested.IsNull ()) { m_closeRequested (this); } } + void Socket::NotifyDataSent (uint32_t size) { + NS_DEBUG("Socket::NotifyDataSent ()"); + if (!m_dataSent.IsNull ()) { m_dataSent (this, size); } } + void Socket::NotifyDataReceived (const Packet &p, const Address &from) { + NS_DEBUG("Socket::NotifyDataReceived ()"); + if (!m_receivedData.IsNull ()) { m_receivedData (this, p, from); } } - - }//namespace ns3 From 9bc6fe4e7a6f817c1bc00ddc1d73e326296b0e7c Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 10:52:41 -0700 Subject: [PATCH 05/22] finish up basic echo apps --- examples/udp-echo.cc | 37 ++++++++++---------- src/applications/udp-echo/udp-echo-client.cc | 30 +++++++++++++++- src/applications/udp-echo/udp-echo-client.h | 2 ++ src/applications/udp-echo/udp-echo-server.cc | 29 +++++++-------- src/applications/udp-echo/udp-echo-server.h | 12 +++---- 5 files changed, 69 insertions(+), 41 deletions(-) diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 7e169dc8a..fb91c3247 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -21,7 +21,7 @@ // ================= // LAN // -// - CBR/UDP flows from n0 to n1 and from n3 to n0 +// - UDP flows from n0 to n1 and back // - DropTail queues // - Tracing of queues and packet receptions to file "udp-echo.tr" @@ -136,11 +136,6 @@ main (int argc, char *argv[]) uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, Eui48Address("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. // @@ -171,25 +166,29 @@ main (int argc, char *argv[]) NS_DEBUG("Create Applications."); // -// Create a UdpEchoServer application on node 1. +// Create a UdpEchoServer application on node one. // - Ptr server = Create (n1, "0.0.0.0", 80); -// -// Tell the application when to start and stop. -// - server->Start(Seconds(1.)); - server->Stop (Seconds(10.0)); + uint16_t port = 80; + + Ptr server = Create (n1, port); // // Create a UdpEchoClient application to send UDP datagrams from node zero to -// node 1. +// node one. // - Ptr client = Create (n0, "10.1.1.2", 80, - 1, Seconds(1.), 1024); + uint32_t packetSize = 1024; + uint32_t maxPacketCount = 1; + Time interPacketInterval = Seconds (1.); + + Ptr client = Create (n0, "10.1.1.2", port, + maxPacketCount, interPacketInterval, packetSize); // -// Tell the application when to start and stop. +// Tell the applications when to start and stop. // - client->Start(Seconds(2.0)); - client->Stop (Seconds(10.0)); + 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" diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 8bcd1c8ed..065b8bed1 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -99,7 +99,9 @@ UdpEchoClient::StartApplication (void) m_socket->Connect (m_peer); } - StopApplication (); + m_socket->SetRecvCallback((Callback, const Packet &, + const Address &>) MakeCallback(&UdpEchoClient::Receive, this)); + ScheduleTransmit (Seconds(0.)); } @@ -107,6 +109,14 @@ void UdpEchoClient::StopApplication () { NS_DEBUG ("UdpEchoClient::StopApplication ()"); + + if (!m_socket) + { + m_socket->SetRecvCallback((Callback, const Packet &, + const Address &>) NULL); + } + + Simulator::Cancel(m_sendEvent); } void @@ -136,4 +146,22 @@ UdpEchoClient::Send (void) } } +void +UdpEchoClient::Receive( + Ptr socket, + const Packet &packet, + const Address &from) +{ + NS_DEBUG ("UdpEchoClient::Receive (" << socket << ", " << packet << + ", " << from << ")"); + + if (InetSocketAddress::IsMatchingType (from)) + { + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); + NS_DEBUG ("UdpEchoClient::Receive(): Received " << + packet.GetSize() << " bytes from " << address.GetIpv4()); + } +} + + } // Namespace ns3 diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index 7c5f2478a..91914287d 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -50,6 +50,8 @@ private: void ScheduleTransmit (Time dt); void Send (void); + void Receive(Ptr socket, const Packet &packet, const Address &from); + Ptr m_node; Ipv4Address m_serverAddress; uint16_t m_serverPort; diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 26958b80f..8f51f9f1c 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -15,6 +15,7 @@ * 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/debug.h" #include "ns3/ipv4-address.h" #include "ns3/nstime.h" @@ -32,15 +33,14 @@ NS_DEBUG_COMPONENT_DEFINE ("UdpEchoServer"); UdpEchoServer::UdpEchoServer ( Ptr n, - Ipv4Address clientAddress, - uint16_t clientPort) + uint16_t port) : Application(n) { - NS_DEBUG ("UdpEchoServer::UdpEchoServer (" << n << ", " << clientAddress << - ", " << clientPort << ")"); + NS_DEBUG ("UdpEchoServer::UdpEchoServer (" << n << ", " << + port << ")"); - Construct (n, clientAddress, clientPort); + Construct (n, port); } UdpEchoServer::~UdpEchoServer() @@ -51,18 +51,15 @@ UdpEchoServer::~UdpEchoServer() void UdpEchoServer::Construct ( Ptr n, - Ipv4Address clientAddress, - uint16_t clientPort) + uint16_t port) { - NS_DEBUG ("UdpEchoServer::Construct (" << n << ", " << clientAddress << - ", " << clientPort << ")"); + NS_DEBUG ("UdpEchoServer::Construct (" << n << ", " << port << ")"); m_node = n; - m_clientAddress = clientAddress; - m_clientPort = clientPort; + m_port = port; m_socket = 0; - m_client = InetSocketAddress (clientAddress, clientPort); + m_local = InetSocketAddress (Ipv4Address::GetAny (), port); } void @@ -83,7 +80,7 @@ UdpEchoServer::StartApplication (void) Ptr socketFactory = GetNode ()->QueryInterface (iid); m_socket = socketFactory->CreateSocket (); - m_socket->Bind (m_client); + m_socket->Bind (m_local); } m_socket->SetRecvCallback((Callback, const Packet &, @@ -101,7 +98,8 @@ UdpEchoServer::StopApplication () } } -void UdpEchoServer::Receive( +void +UdpEchoServer::Receive( Ptr socket, const Packet &packet, const Address &from) @@ -114,6 +112,9 @@ void UdpEchoServer::Receive( InetSocketAddress address = InetSocketAddress::ConvertFrom (from); NS_DEBUG ("UdpEchoServer::Receive(): Received " << packet.GetSize() << " bytes from " << address.GetIpv4()); + + NS_DEBUG ("UdpEchoServer::Receive (): Echoing packet"); + socket->SendTo (from, packet); } } diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h index d9de1221f..597fef8fe 100644 --- a/src/applications/udp-echo/udp-echo-server.h +++ b/src/applications/udp-echo/udp-echo-server.h @@ -32,27 +32,25 @@ class Packet; class UdpEchoServer : public Application { public: - UdpEchoServer (Ptr n, Ipv4Address clientAddr, uint16_t clientPort); + UdpEchoServer (Ptr n, uint16_t clientPort); virtual ~UdpEchoServer (); protected: virtual void DoDispose (void); private: - void Construct (Ptr n, Ipv4Address clientAddr, uint16_t clientPort); + void Construct (Ptr n, uint16_t clientPort); virtual void StartApplication (void); virtual void StopApplication (void); - void Receive(Ptr socket, const Packet &packet, - const Address &from); + void Receive(Ptr socket, const Packet &packet, const Address &from); Ptr m_node; - Ipv4Address m_clientAddress; - uint16_t m_clientPort; + uint16_t m_port; Ptr m_socket; - Address m_client; + Address m_local; }; } // namespace ns3 From 873176a3e6c98e49a89fffe379fb7a5f6591b169 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 11:04:47 -0700 Subject: [PATCH 06/22] add tutorial directory and hello-simulator --- examples/udp-echo.cc | 10 +++++----- tutorial/hello-simulator.cc | 29 +++++++++++++++++++++++++++++ tutorial/waf | 1 + tutorial/wscript | 6 ++++++ wscript | 2 +- 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tutorial/hello-simulator.cc create mode 100755 tutorial/waf create mode 100644 tutorial/wscript diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index fb91c3247..8f5569ba0 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -39,7 +39,7 @@ #include "ns3/csma-net-device.h" #include "ns3/csma-topology.h" #include "ns3/csma-ipv4-topology.h" -#include "ns3/eui48-address.h" +#include "ns3/mac48-address.h" #include "ns3/ipv4-address.h" #include "ns3/inet-socket-address.h" #include "ns3/ipv4.h" @@ -126,16 +126,16 @@ main (int argc, char *argv[]) // zero. // uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, - Eui48Address("08:00:2e:00:00:00")); + Mac48Address("08:00:2e:00:00:00")); uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, - Eui48Address("08:00:2e:00:00:01")); + Mac48Address("08:00:2e:00:00:01")); uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, - Eui48Address("08:00:2e:00:00:02")); + Mac48Address("08:00:2e:00:00:02")); uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, - Eui48Address("08:00:2e:00:00:03")); + Mac48Address("08:00:2e:00:00:03")); // // We've got the "hardware" in place. Now we need to add IP addresses. // diff --git a/tutorial/hello-simulator.cc b/tutorial/hello-simulator.cc new file mode 100644 index 000000000..c9c18cac6 --- /dev/null +++ b/tutorial/hello-simulator.cc @@ -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/debug.h" + +using namespace ns3; + +NS_DEBUG_COMPONENT_DEFINE ("HelloSimulator"); + +int +main (int argc, char *argv[]) +{ + DebugComponentEnable("HelloSimulator"); + + NS_DEBUG("Hello Simulator"); +} diff --git a/tutorial/waf b/tutorial/waf new file mode 100755 index 000000000..191b7dbb2 --- /dev/null +++ b/tutorial/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../waf "$@" diff --git a/tutorial/wscript b/tutorial/wscript new file mode 100644 index 000000000..abd2df7b9 --- /dev/null +++ b/tutorial/wscript @@ -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' diff --git a/wscript b/wscript index 5904c5ad2..9e54f7050 100644 --- a/wscript +++ b/wscript @@ -173,7 +173,7 @@ def build(bld): # 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') From 16b634a7fcbb9ff72fd9d8e6d69ccbcbdee3b8b9 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 12:37:30 -0700 Subject: [PATCH 07/22] sorting out logging --- src/core/log.cc | 71 ++++++++++++++++++++++++++----------- src/core/log.h | 61 +++++++++++++++++-------------- tutorial/hello-simulator.cc | 8 ++--- 3 files changed, 89 insertions(+), 51 deletions(-) diff --git a/src/core/log.cc b/src/core/log.cc index fa1c6f6f9..64a288289 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -101,11 +101,23 @@ LogComponentEnableEnvVar (void) cur_lev = next_lev + 1; next_lev = tmp.find ("|", cur_lev); std::string lev = tmp.substr (cur_lev, next_lev - cur_lev); - if (lev == "debug") + if (lev == "error") + { + level |= LOG_LEVEL_ERROR; + } + else if (lev == "warn") + { + level |= LOG_LEVEL_WARN; + } + else if (lev == "debug") { level |= LOG_LEVEL_DEBUG; } - else if (lev == "func") + else if (lev == "info") + { + level |= LOG_LEVEL_INFO; + } + else if (lev == "function") { level |= LOG_LEVEL_FUNCTION; } @@ -113,13 +125,13 @@ LogComponentEnableEnvVar (void) { level |= LOG_LEVEL_PARAM; } - else if (lev == "warn") + else if (lev == "logic") { - level |= LOG_LEVEL_WARN; + level |= LOG_LEVEL_LOGIC; } - else if (lev == "error") + else if (lev == "all") { - level |= LOG_LEVEL_ERROR; + level |= LOG_LEVEL_ALL; } } while (next_lev != std::string::npos); } @@ -159,7 +171,6 @@ LogComponentEnableEnvVar (void) #endif } - LogComponent::LogComponent (char const * name) : m_levels (0) { @@ -172,22 +183,28 @@ LogComponent::LogComponent (char const * name) } components->push_back (std::make_pair (name, this)); } + bool LogComponent::IsEnabled (enum LogLevel level) const { LogComponentEnableEnvVar (); - return (level & m_levels) == 1; +// return (level & m_levels) ? 1 : 0; + + return m_levels >= level; } + bool LogComponent::IsNoneEnabled (void) const { return m_levels == 0; } + void LogComponent::Enable (enum LogLevel level) { m_levels |= level; } + void LogComponent::Disable (enum LogLevel level) { @@ -209,6 +226,7 @@ LogComponentEnable (char const *name, enum LogLevel level) } } } + void LogComponentDisable (char const *name, enum LogLevel level) { @@ -225,7 +243,6 @@ LogComponentDisable (char const *name, enum LogLevel level) } } - void LogComponentPrintList (void) { @@ -240,25 +257,37 @@ LogComponentPrintList (void) std::cout << "0" << std::endl; continue; } - if (i->second->IsEnabled (LOG_LEVEL_DEBUG)) + if (i->second->IsEnabled (LOG_LEVEL_ERROR)) { - std::cout << "debug"; - } - if (i->second->IsEnabled (LOG_LEVEL_FUNCTION)) - { - std::cout << "|func"; - } - if (i->second->IsEnabled (LOG_LEVEL_PARAM)) - { - std::cout << "|param"; + std::cout << "error"; } if (i->second->IsEnabled (LOG_LEVEL_WARN)) { std::cout << "|warn"; } - if (i->second->IsEnabled (LOG_LEVEL_ERROR)) + if (i->second->IsEnabled (LOG_LEVEL_DEBUG)) { - std::cout << "|error"; + std::cout << "|debug"; + } + if (i->second->IsEnabled (LOG_LEVEL_INFO)) + { + std::cout << "|info"; + } + if (i->second->IsEnabled (LOG_LEVEL_FUNCTION)) + { + std::cout << "|function"; + } + if (i->second->IsEnabled (LOG_LEVEL_PARAM)) + { + std::cout << "|param"; + } + if (i->second->IsEnabled (LOG_LEVEL_LOGIC)) + { + std::cout << "|logic"; + } + if (i->second->IsEnabled (LOG_LEVEL_ALL)) + { + std::cout << "|all"; } std::cout << std::endl; } diff --git a/src/core/log.h b/src/core/log.h index 3745164c8..28d075565 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -74,7 +74,7 @@ * defined with the NS_LOG_COMPONENT_DEFINE macro in the * same file. */ -#define NS_LOG(level,msg) \ +#define NS_LOG(level, msg) \ do \ { \ if (g_log.IsEnabled (level)) \ @@ -84,39 +84,48 @@ } \ while (false) -#define NS_LOG_DEBUG(msg) \ - NS_LOG (ns3::LOG_LEVEL_DEBUG,msg) - -#define NS_LOG_FUNCTION \ - NS_LOG (ns3::LOG_LEVEL_FUNCTION, __PRETTY_PRINT__) - -#define NS_LOG_PARAM(msg) \ - NS_LOG (ns3::LOG_LEVEL_PARAM,msg) +#define NS_LOG_ERROR(msg) \ + NS_LOG(ns3::LOG_LEVEL_ERROR, msg) #define NS_LOG_WARN(msg) \ - NS_LOG (ns3::LOG_LEVEL_WARN,msg) + NS_LOG(ns3::LOG_LEVEL_WARN, msg) -#define NS_LOG_ERROR(msg) \ - NS_LOG (ns3::LOG_LEVEL_ERROR,msg) +#define NS_LOG_DEBUG(msg) \ + NS_LOG(ns3::LOG_LEVEL_DEBUG, msg) -#define NS_LOG_UNCOND(msg) \ - do \ - { \ - std::clog << msg << std::endl; \ - } \ +#define NS_LOG_INFO(msg) \ + NS_LOG(ns3::LOG_LEVEL_INFO, msg) + +#define NS_LOG_FUNCTION(msg) \ + NS_LOG(ns3::LOG_LEVEL_FUNCTION, msg) + +#define NS_LOG_PARAM(msg) \ + NS_LOG(ns3::LOG_LEVEL_PARAM, msg) + +#define NS_LOG_LOGIC(msg) \ + NS_LOG(ns3::LOG_LEVEL_LOGIC, msg) + +#define NS_LOG_ALL(msg) \ + NS_LOG(ns3::LOG_LEVEL_ALL, msg) + +#define NS_LOG_UNCOND(msg) \ + do \ + { \ + std::clog << msg << std::endl; \ + } \ while (false) - - namespace ns3 { enum LogLevel { - LOG_LEVEL_DEBUG = 1<<0, - LOG_LEVEL_FUNCTION = 1<<1, - LOG_LEVEL_PARAM = 1<<2, - LOG_LEVEL_WARN = 1<<3, - LOG_LEVEL_ERROR = 1<<4, - LOG_LEVEL_LAST = 1<<31 + LOG_LEVEL_ERROR = 1<<0, // serious error messages only + LOG_LEVEL_WARN = 1<<1, // add warning messages + LOG_LEVEL_DEBUG = 1<<2, // add rare ad-hoc debug messages + LOG_LEVEL_INFO = 1<<3, // add informational messages (e.g., banners) + LOG_LEVEL_FUNCTION = 1<<4, // add function tracing + LOG_LEVEL_PARAM = 1<<5, // add parameters to functions + LOG_LEVEL_LOGIC = 1<<6, // add control flow tracing within functions + LOG_LEVEL_ALL = 1<<30 // print everything }; /** @@ -159,7 +168,7 @@ public: void Enable (enum LogLevel level); void Disable (enum LogLevel level); private: - uint32_t m_levels; + int32_t m_levels; }; } // namespace ns3 diff --git a/tutorial/hello-simulator.cc b/tutorial/hello-simulator.cc index c9c18cac6..84ac0914e 100644 --- a/tutorial/hello-simulator.cc +++ b/tutorial/hello-simulator.cc @@ -14,16 +14,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "ns3/debug.h" +#include "ns3/log.h" using namespace ns3; -NS_DEBUG_COMPONENT_DEFINE ("HelloSimulator"); +NS_LOG_COMPONENT_DEFINE ("HelloSimulator"); int main (int argc, char *argv[]) { - DebugComponentEnable("HelloSimulator"); + LogComponentEnable ("HelloSimulator", LOG_LEVEL_INFO); - NS_DEBUG("Hello Simulator"); + NS_LOG_INFO ("Hello Simulator"); } From 90b02a4f6c54e9e1b1a64d27d5b66e45157ad198 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 17:47:42 -0700 Subject: [PATCH 08/22] checkpoint debug to log --- examples/csma-broadcast.cc | 62 +++-- examples/csma-multicast.cc | 77 ++--- examples/csma-one-subnet.cc | 66 +++-- examples/csma-packet-socket.cc | 43 ++- examples/mixed-global-routing.cc | 48 +++- examples/simple-global-routing.cc | 54 ++-- examples/simple-point-to-point.cc | 66 ++--- examples/udp-echo.cc | 67 +++-- samples/main-channel.cc | 50 ++-- samples/main-default-value.cc | 8 +- samples/main-query-interface.cc | 16 +- samples/main-tw.cc | 4 +- src/applications/onoff/onoff-application.cc | 49 ++-- src/applications/packet-sink/packet-sink.cc | 10 +- src/applications/udp-echo/udp-echo-client.cc | 33 +-- src/applications/udp-echo/udp-echo-server.cc | 30 +- src/common/buffer.cc | 16 +- src/common/packet-metadata.cc | 30 +- src/core/composite-trace-resolver.cc | 16 +- src/core/fatal-error.h | 5 +- src/core/log.h | 32 ++- src/core/object.cc | 8 +- src/core/random-variable-default-value.cc | 12 +- src/core/trace-resolver.cc | 6 +- src/devices/csma/csma-channel.cc | 77 ++--- src/devices/csma/csma-ipv4-topology.cc | 1 - src/devices/csma/csma-net-device.cc | 128 +++++---- src/devices/csma/csma-topology.cc | 1 - .../point-to-point/point-to-point-channel.cc | 35 ++- .../point-to-point-net-device.cc | 63 +++-- .../point-to-point/point-to-point-topology.cc | 2 +- src/internet-node/ipv4-end-point-demux.cc | 84 +++--- src/internet-node/ipv4-header.cc | 6 +- src/internet-node/ipv4-interface.cc | 40 +-- src/internet-node/ipv4-l3-protocol.cc | 263 ++++++++++-------- src/internet-node/ipv4-loopback-interface.cc | 12 +- src/internet-node/ipv4-static-routing.cc | 67 +++-- src/internet-node/udp-l4-protocol.cc | 43 +-- src/internet-node/udp-socket.cc | 68 ++--- 39 files changed, 969 insertions(+), 729 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 06625559b..84efdd4f1 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -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" @@ -57,36 +57,40 @@ #include "ns3/ipv4-route.h" #include "ns3/onoff-application.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("Socket"); - DebugComponentEnable("UdpSocket"); - DebugComponentEnable("UdpL4Protocol"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("Ipv4StaticRouting"); - DebugComponentEnable("Ipv4Interface"); - DebugComponentEnable("ArpIpv4Interface"); - DebugComponentEnable("Ipv4LoopbackInterface"); -#endif + 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); + 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 @@ -101,11 +105,13 @@ int main (int argc, char *argv[]) // Here, we will explicitly create four nodes. In more sophisticated // topologies, we could configure a node factory. + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); // We create the channels first without any IP addressing information + NS_LOG_INFO ("Create channels."); Ptr channel0 = CsmaTopology::CreateCsmaChannel( DataRate(5000000), MilliSeconds(2)); @@ -115,6 +121,7 @@ int main (int argc, char *argv[]) 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, @@ -125,6 +132,7 @@ int main (int argc, char *argv[]) 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")); @@ -152,6 +160,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s // from n0 to n1 + NS_LOG_INFO ("Create Applications."); Ptr ooff = Create ( n0, InetSocketAddress ("255.255.255.255", 80), @@ -162,7 +171,7 @@ int main (int argc, char *argv[]) ooff->Start(Seconds(1.0)); ooff->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"); @@ -177,7 +186,8 @@ int main (int argc, char *argv[]) PcapTrace pcaptrace ("csma-broadcast.pcap"); pcaptrace.TraceAllIp (); - Simulator::Run (); - + NS_LOG_INFO ("Run Simulation."); + Simulator::Run (); Simulator::Destroy (); + NS_LOG_INFO ("Done."); } diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 6f5cf7abc..5ca1d79d5 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -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" @@ -54,7 +54,7 @@ using namespace ns3; -NS_DEBUG_COMPONENT_DEFINE ("CsmaMulticast"); +NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample"); int main (int argc, char *argv[]) @@ -64,28 +64,30 @@ main (int argc, char *argv[]) // 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("Socket"); - 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() // technique to tell the system what subclass of Queue to use. The Bind @@ -101,14 +103,14 @@ main (int argc, char *argv[]) // // Explicitly create the nodes required by the topology (shown above). // - NS_DEBUG("Create nodes."); + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); Ptr n4 = Create (); - NS_DEBUG("Create channels."); + NS_LOG_INFO ("Create channels."); // // Explicitly create the channels required by the topology (shown above). // @@ -118,7 +120,7 @@ main (int argc, char *argv[]) Ptr 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 @@ -144,17 +146,16 @@ main (int argc, char *argv[]) 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")); @@ -181,7 +182,7 @@ main (int argc, char *argv[]) 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 @@ -272,7 +273,7 @@ main (int argc, char *argv[]) // 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."); Ptr ooff = Create ( n0, InetSocketAddress (multicastGroup, 80), @@ -290,7 +291,7 @@ main (int argc, char *argv[]) // 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 (); @@ -306,8 +307,8 @@ main (int argc, char *argv[]) // // 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."); } diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index 8179555a9..dfc41a88e 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -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,26 +60,29 @@ main (int argc, char *argv[]) // 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("Socket"); - 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() @@ -96,20 +99,20 @@ main (int argc, char *argv[]) // // Explicitly create the nodes required by the topology (shown above). // - NS_DEBUG("Create nodes."); + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); - NS_DEBUG("Create channels."); + NS_LOG_INFO ("Create channels."); // // Explicitly create the channels required by the topology (shown above). // Ptr 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 @@ -130,15 +133,10 @@ main (int argc, char *argv[]) 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 @@ -165,7 +163,7 @@ main (int argc, char *argv[]) // // Create an OnOff application to send UDP datagrams from node zero to node 1. // - NS_DEBUG("Create Applications."); + NS_LOG_INFO ("Create Applications."); Ptr ooff = Create ( n0, InetSocketAddress ("10.1.1.2", 80), @@ -193,7 +191,7 @@ main (int argc, char *argv[]) // 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 (); @@ -209,8 +207,8 @@ main (int argc, char *argv[]) // // 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."); } diff --git a/examples/csma-packet-socket.cc b/examples/csma-packet-socket.cc index ef1c33357..fde9a8f0b 100644 --- a/examples/csma-packet-socket.cc +++ b/examples/csma-packet-socket.cc @@ -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 CreateCsmaDevice (Ptr node, Ptr channel) { @@ -66,28 +68,56 @@ CreateCsmaDevice (Ptr node, Ptr channel) return device; } - -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { +#if 0 + LogComponentEnable ("CsmaPacketSocketExample", 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 + 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 n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); // create the shared medium used by all csma devices. + NS_LOG_INFO ("Create channels."); Ptr channel = Create (DataRate(5000000), MilliSeconds(2)); // use a helper function to connect our nodes to the shared channel. + NS_LOG_INFO ("Build Topology."); Ptr n0If = CreateCsmaDevice (n0, channel); Ptr n1If = CreateCsmaDevice (n1, channel); Ptr n2If = CreateCsmaDevice (n2, channel); Ptr 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 @@ int main (int argc, char *argv[]) // 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 ooff = Create ( n0, n0ToN1, @@ -126,11 +157,13 @@ int main (int argc, char *argv[]) // 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."); } diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index d8038eaeb..ba2901a65 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -36,7 +36,7 @@ #include #include -#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"); -#endif + 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 @@ int main (int argc, char *argv[]) // Bind ()s at run-time, via command-line arguments CommandLine::Parse (argc, argv); + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); @@ -111,6 +129,7 @@ int main (int argc, char *argv[]) Ptr n6 = Create (); // We create the channels first without any IP addressing information + NS_LOG_INFO ("Create channels."); Ptr channel0 = PointToPointTopology::AddPointToPointLink ( n0, n2, DataRate (5000000), MilliSeconds (2)); @@ -128,6 +147,7 @@ int main (int argc, char *argv[]) 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 @@ int main (int argc, char *argv[]) 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,6 +189,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s + NS_LOG_INFO ("Create Applications."); Ptr ooff = Create ( n0, InetSocketAddress ("10.1.3.2", 80), @@ -182,6 +204,7 @@ int main (int argc, char *argv[]) // 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 +216,8 @@ int main (int argc, char *argv[]) PcapTrace pcaptrace ("mixed-global-routing.pcap"); pcaptrace.TraceAllIp (); + NS_LOG_INFO ("Run Simulation."); Simulator::Run (); - Simulator::Destroy (); + NS_LOG_INFO ("Done."); } diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index bcfc01d17..8c6bd9db6 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -42,7 +42,7 @@ #include #include -#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"); -#endif + LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO); - // 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 + 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 // 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 @@ int main (int argc, char *argv[]) // Here, we will explicitly create four nodes. In more sophisticated // topologies, we could configure a node factory. + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); // We create the channels first without any IP addressing information + NS_LOG_INFO ("Create channels."); Ptr channel0 = PointToPointTopology::AddPointToPointLink ( n0, n2, DataRate (5000000), MilliSeconds (2)); @@ -124,6 +142,7 @@ int main (int argc, char *argv[]) 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,6 +161,7 @@ int main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s + NS_LOG_INFO ("Create Applications."); Ptr ooff = Create ( n0, InetSocketAddress ("10.1.3.2", 80), @@ -184,6 +204,7 @@ int main (int argc, char *argv[]) // 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 +216,10 @@ int main (int argc, char *argv[]) PcapTrace pcaptrace ("simple-global-routing.pcap"); pcaptrace.TraceAllIp (); + NS_LOG_INFO ("Run Simulation."); Simulator::Run (); - Simulator::Destroy (); + NS_LOG_INFO ("Done."); return 0; } diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index 91b9f2a89..c4cfef038 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -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,35 +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("Socket"); - 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() @@ -114,14 +116,14 @@ main (int argc, char *argv[]) // 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 n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); // We create the channels first without any IP addressing information - NS_DEBUG("Create channels."); + NS_LOG_INFO ("Create channels."); Ptr channel0 = PointToPointTopology::AddPointToPointLink ( n0, n2, DataRate(5000000), MilliSeconds(2)); @@ -135,7 +137,7 @@ main (int argc, char *argv[]) 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")); @@ -152,14 +154,14 @@ main (int argc, char *argv[]) // 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."); Ptr ooff = Create ( n0, InetSocketAddress ("10.1.3.2", 80), @@ -201,7 +203,7 @@ main (int argc, char *argv[]) // 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 = n0->QueryInterface (Ipv4::iid); ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); @@ -210,7 +212,7 @@ main (int argc, char *argv[]) // 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 (); @@ -223,8 +225,8 @@ main (int argc, char *argv[]) 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."); } diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 8f5569ba0..70fcf4895 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -28,7 +28,7 @@ #include "ns3/command-line.h" #include "ns3/default-value.h" #include "ns3/ptr.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 ("UdpEcho"); +NS_LOG_COMPONENT_DEFINE ("UdpEchoExample"); int main (int argc, char *argv[]) @@ -60,33 +60,30 @@ main (int argc, char *argv[]) // for selected modules; the below lines suggest how to do this // #if 0 - DebugComponentEnable("UdpEcho"); + LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO); - DebugComponentEnable("Object"); - DebugComponentEnable("Queue"); - DebugComponentEnable("DropTailQueue"); - DebugComponentEnable("Channel"); - DebugComponentEnable("CsmaChannel"); - DebugComponentEnable("CsmaNetDevice"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("NetDevice"); - DebugComponentEnable("PacketSocket"); - DebugComponentEnable("OnOffApplication"); - DebugComponentEnable("Socket"); - DebugComponentEnable("UdpSocket"); - DebugComponentEnable("UdpL4Protocol"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("Ipv4StaticRouting"); - DebugComponentEnable("Ipv4Interface"); - DebugComponentEnable("ArpIpv4Interface"); - DebugComponentEnable("Ipv4LoopbackInterface"); - DebugComponentEnable("UdpEchoClient"); - DebugComponentEnable("UdpEchoServer"); + 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 - - DebugComponentEnable("UdpEcho"); - DebugComponentEnable("UdpEchoClient"); - DebugComponentEnable("UdpEchoServer"); // // Set up default values for the simulation. Use the DefaultValue::Bind() // technique to tell the system what subclass of Queue to use. The Bind @@ -102,20 +99,20 @@ main (int argc, char *argv[]) // // Explicitly create the nodes required by the topology (shown above). // - NS_DEBUG("Create nodes."); + NS_LOG_INFO ("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); - NS_DEBUG("Create channels."); + NS_LOG_INFO ("Create channels."); // // Explicitly create the channels required by the topology (shown above). // Ptr 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 @@ -139,7 +136,7 @@ main (int argc, char *argv[]) // // 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,7 +161,7 @@ main (int argc, char *argv[]) CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0")); - NS_DEBUG("Create Applications."); + NS_LOG_INFO ("Create Applications."); // // Create a UdpEchoServer application on node one. // @@ -193,7 +190,7 @@ main (int argc, char *argv[]) // Configure tracing of all enqueue, dequeue, and NetDevice receive events. // Trace output will be sent to the file "udp-echo.tr" // - NS_DEBUG("Configure Tracing."); + NS_LOG_INFO ("Configure Tracing."); AsciiTrace asciitrace ("udp-echo.tr"); asciitrace.TraceAllNetDeviceRx (); asciitrace.TraceAllQueues (); @@ -209,8 +206,8 @@ main (int argc, char *argv[]) // // 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."); } diff --git a/samples/main-channel.cc b/samples/main-channel.cc index 250a354c8..99ceb04ec 100644 --- a/samples/main-channel.cc +++ b/samples/main-channel.cc @@ -18,7 +18,7 @@ */ #include -#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 @@ protected: 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 @@ FakeInternetNode::Doit (void) 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 @@ FakeInternetNode::UpperDoSendUp (Packet &p) 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 @@ protected: 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 @@ FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper) 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 @@ FakePhysicalLayer::UpperDoSendUp (Packet &p) 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 @@ public: 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; diff --git a/samples/main-default-value.cc b/samples/main-default-value.cc index f125a7181..dcaa8a83a 100644 --- a/samples/main-default-value.cc +++ b/samples/main-default-value.cc @@ -3,7 +3,7 @@ #include #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 @@ int main (int argc, char* argv[]) 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; diff --git a/samples/main-query-interface.cc b/samples/main-query-interface.cc index 20da36ff3..db23a5000 100644 --- a/samples/main-query-interface.cc +++ b/samples/main-query-interface.cc @@ -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 @@ private: 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 @@ private: 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 @@ AnImplementation::AnImplementation (void) void AnImplementation::domethodA () { - NS_DEBUG_UNCOND("AnImplementation::domethodA"); + NS_LOG_FUNCTION; } // @@ -201,7 +203,7 @@ ANewImplementation::ANewImplementation (void) void ANewImplementation::methodImpl (void) { - NS_DEBUG_UNCOND("ANewImplementation::methodImpl\n"); + NS_LOG_FUNCTION; } const InterfaceId ANewImplementation::iid = @@ -238,7 +240,7 @@ AnExtendedImplementation::AnExtendedImplementation (void) void AnExtendedImplementation::methodExtendedImpl (void) { - NS_DEBUG_UNCOND("AnExtendedImplementation::methodExtendedImpl\n"); + NS_LOG_FUNCTION; } const InterfaceId AnExtendedImplementation::iid = diff --git a/samples/main-tw.cc b/samples/main-tw.cc index c4e1ff1f4..4fcb8b94b 100644 --- a/samples/main-tw.cc +++ b/samples/main-tw.cc @@ -18,14 +18,14 @@ */ #include -#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"); diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 9df4274bc..29f3d9d04 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -22,7 +22,7 @@ // George F. Riley, Georgia Tech, Spring 2007 // Adapted from ApplicationOnOff in GTNetS. -#include "ns3/debug.h" +#include "ns3/log.h" #include "ns3/address.h" #include "ns3/node.h" #include "ns3/nstime.h" @@ -35,7 +35,7 @@ #include "ns3/packet.h" #include "onoff-application.h" -NS_DEBUG_COMPONENT_DEFINE ("OnOffApplication"); +NS_LOG_COMPONENT_DEFINE ("OnOffApplication"); using namespace std; @@ -73,8 +73,8 @@ OnOffApplication::OnOffApplication(Ptr n, : Application(n), m_cbrRate (rate) { - Construct (n, remote, iid, - ontime, offtime, size); + NS_LOG_FUNCTION; + Construct (n, remote, iid, ontime, offtime, size); } void @@ -85,6 +85,8 @@ OnOffApplication::Construct (Ptr n, const RandomVariable& offTime, uint32_t size) { + NS_LOG_FUNCTION; + m_socket = 0; m_peer = remote; m_connected = false; @@ -100,34 +102,37 @@ OnOffApplication::Construct (Ptr n, OnOffApplication::~OnOffApplication() { - NS_DEBUG("OnOffApplication::~OnOffApplication()"); + NS_LOG_FUNCTION; } void OnOffApplication::SetMaxBytes(uint32_t maxBytes) { - NS_DEBUG("OnOffApplication::SetMaxBytes(" << maxBytes << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << maxBytes << ")"); m_maxBytes = maxBytes; } void OnOffApplication::SetDefaultRate (const DataRate &rate) { - NS_DEBUG("OnOffApplication::SetDefaultRate(" << &rate << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &rate << ")"); g_defaultRate.SetValue (rate); } void OnOffApplication::SetDefaultSize (uint32_t size) { - NS_DEBUG("OnOffApplication::SetDefaultSize(" << size << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << size << ")"); g_defaultSize.SetValue (size); } void OnOffApplication::DoDispose (void) { - NS_DEBUG("OnOffApplication::DoDispose()"); + NS_LOG_FUNCTION; m_socket = 0; delete m_onTime; @@ -143,7 +148,7 @@ OnOffApplication::DoDispose (void) // Application Methods void OnOffApplication::StartApplication() // Called at time specified by Start { - NS_DEBUG("OnOffApplication::StartApplication()"); + NS_LOG_FUNCTION; // Create the socket if not already if (!m_socket) @@ -164,7 +169,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Start void OnOffApplication::StopApplication() // Called at time specified by Stop { - NS_DEBUG("OnOffApplication::StopApplication()"); + NS_LOG_FUNCTION; if (m_sendEvent.IsRunning ()) { // Cancel the pending send packet event @@ -179,14 +184,14 @@ void OnOffApplication::StopApplication() // Called at time specified by Stop // Event handlers void OnOffApplication::StartSending() { - NS_DEBUG("OnOffApplication::StartSending ()"); + NS_LOG_FUNCTION; ScheduleNextTx(); // Schedule the send packet event } void OnOffApplication::StopSending() { - NS_DEBUG("OnOffApplication::StopSending ()"); + NS_LOG_FUNCTION; Simulator::Cancel(m_sendEvent); } @@ -194,15 +199,15 @@ void OnOffApplication::StopSending() // Private helpers void OnOffApplication::ScheduleNextTx() { - NS_DEBUG("OnOffApplication::ScheduleNextTx ()"); + NS_LOG_FUNCTION; if (m_totBytes < m_maxBytes) { uint32_t bits = m_pktSize * 8 - m_residualBits; - NS_DEBUG("OnOffApplication::ScheduleNextTx (): bits = " << bits); + NS_LOG_LOGIC ("bits = " << bits); Time nextTime(Seconds (bits / static_cast(m_cbrRate.GetBitRate()))); // Time till next packet - NS_DEBUG("OnOffApplication::ScheduleNextTx (): nextTime = " << nextTime); + NS_LOG_LOGIC ("nextTime = " << nextTime); m_sendEvent = Simulator::Schedule(nextTime, &OnOffApplication::SendPacket, this); } @@ -214,17 +219,16 @@ void OnOffApplication::ScheduleNextTx() void OnOffApplication::ScheduleStartEvent() { // Schedules the event to start sending data (switch to the "On" state) - NS_DEBUG("OnOffApplication::ScheduleStartEvent ()"); + NS_LOG_FUNCTION; Time offInterval = Seconds(m_offTime->GetValue()); - NS_DEBUG("OnOffApplication::ScheduleStartEvent (): " - "start at " << offInterval); + 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_DEBUG("OnOffApplication::ScheduleStopEvent ()"); + NS_LOG_FUNCTION; Time onInterval = Seconds(m_onTime->GetValue()); Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this); @@ -233,7 +237,7 @@ void OnOffApplication::ScheduleStopEvent() void OnOffApplication::SendPacket() { - NS_DEBUG("OnOffApplication::SendPacket ()"); + NS_LOG_FUNCTION; NS_ASSERT (m_sendEvent.IsExpired ()); m_socket->Send(Packet (m_pktSize)); @@ -245,7 +249,7 @@ void OnOffApplication::SendPacket() void OnOffApplication::ConnectionSucceeded(Ptr) { - NS_DEBUG("OnOffApplication::ConnectionSucceeded ()"); + NS_LOG_FUNCTION; m_connected = true; ScheduleStartEvent(); @@ -253,6 +257,7 @@ void OnOffApplication::ConnectionSucceeded(Ptr) void OnOffApplication::ConnectionFailed(Ptr) { + NS_LOG_FUNCTION; cout << "OnOffApplication, Connection Failed" << endl; } diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 2ca60bfb3..503e0cbff 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -18,7 +18,7 @@ * Author: Tom Henderson (tomhend@u.washington.edu) */ #include "ns3/address.h" -#include "ns3/debug.h" +#include "ns3/log.h" #include "ns3/inet-socket-address.h" #include "ns3/node.h" #include "ns3/socket.h" @@ -31,7 +31,7 @@ using namespace std; namespace ns3 { -NS_DEBUG_COMPONENT_DEFINE ("PacketSink"); +NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication"); // Constructors @@ -99,9 +99,9 @@ void PacketSink::Receive(Ptr socket, const Packet &packet, if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_DEBUG ( __PRETTY_FUNCTION__ << ": Received " << - packet.GetSize() << " bytes from " << address.GetIpv4() << " [" - << address << "]---'" << packet.PeekData() << "'"); + NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << + address.GetIpv4() << " [" << address << "]---'" << + packet.PeekData() << "'"); // TODO: Add a tracing source here } } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 065b8bed1..a5489ef2c 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -15,7 +15,7 @@ * 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/debug.h" +#include "ns3/log.h" #include "ns3/ipv4-address.h" #include "ns3/nstime.h" #include "ns3/inet-socket-address.h" @@ -27,7 +27,7 @@ namespace ns3 { -NS_DEBUG_COMPONENT_DEFINE ("UdpEchoClient"); +NS_LOG_COMPONENT_DEFINE ("UdpEchoClientApplication"); UdpEchoClient::UdpEchoClient ( Ptr n, @@ -39,7 +39,8 @@ UdpEchoClient::UdpEchoClient ( : Application(n) { - NS_DEBUG ("UdpEchoClient::UdpEchoClient (" << n << ", " << serverAddress << + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << n << ", " << serverAddress << ", " << serverPort << ", " << count << ", " << interval << ", " << size << ")"); @@ -48,7 +49,7 @@ UdpEchoClient::UdpEchoClient ( UdpEchoClient::~UdpEchoClient() { - NS_DEBUG ("UdpEchoClient::~UdpEchoClient ()"); + NS_LOG_FUNCTION; } void @@ -60,7 +61,8 @@ UdpEchoClient::Construct ( Time interval, uint32_t size) { - NS_DEBUG ("UdpEchoClient::Construct (" << n << ", " << serverAddress << + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << n << ", " << serverAddress << ", " << serverPort << ", " << count << ", " << interval << ", " << size << ")"); @@ -80,14 +82,14 @@ UdpEchoClient::Construct ( void UdpEchoClient::DoDispose (void) { - NS_DEBUG ("UdpEchoClient::DoDispose ()"); + NS_LOG_FUNCTION; Application::DoDispose (); } void UdpEchoClient::StartApplication (void) { - NS_DEBUG ("UdpEchoClient::StartApplication ()"); + NS_LOG_FUNCTION; if (!m_socket) { @@ -108,7 +110,7 @@ UdpEchoClient::StartApplication (void) void UdpEchoClient::StopApplication () { - NS_DEBUG ("UdpEchoClient::StopApplication ()"); + NS_LOG_FUNCTION; if (!m_socket) { @@ -122,14 +124,14 @@ UdpEchoClient::StopApplication () void UdpEchoClient::ScheduleTransmit (Time dt) { - NS_DEBUG ("UdpEchoClient::ScheduleTransmit (" << dt << ")"); + NS_LOG_FUNCTION; m_sendEvent = Simulator::Schedule(dt, &UdpEchoClient::Send, this); } void UdpEchoClient::Send (void) { - NS_DEBUG ("UdpEchoClient::Send ()"); + NS_LOG_FUNCTION; NS_ASSERT (m_sendEvent.IsExpired ()); @@ -137,8 +139,7 @@ UdpEchoClient::Send (void) m_socket->Send (p); ++m_sent; - NS_DEBUG ("UdpEchoClient::Send (): Sent " << m_size << " bytes to " << - m_serverAddress); + NS_LOG_INFO ("Sent " << m_size << " bytes to " << m_serverAddress); if (m_sent < m_count) { @@ -152,14 +153,14 @@ UdpEchoClient::Receive( const Packet &packet, const Address &from) { - NS_DEBUG ("UdpEchoClient::Receive (" << socket << ", " << packet << - ", " << from << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_DEBUG ("UdpEchoClient::Receive(): Received " << - packet.GetSize() << " bytes from " << address.GetIpv4()); + NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << + address.GetIpv4()); } } diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 8f51f9f1c..11654ed8d 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "ns3/debug.h" +#include "ns3/log.h" #include "ns3/ipv4-address.h" #include "ns3/nstime.h" #include "ns3/inet-socket-address.h" @@ -29,7 +29,7 @@ namespace ns3 { -NS_DEBUG_COMPONENT_DEFINE ("UdpEchoServer"); +NS_LOG_COMPONENT_DEFINE ("UdpEchoServerApplication"); UdpEchoServer::UdpEchoServer ( Ptr n, @@ -37,15 +37,15 @@ UdpEchoServer::UdpEchoServer ( : Application(n) { - NS_DEBUG ("UdpEchoServer::UdpEchoServer (" << n << ", " << - port << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << n << ", " << port << ")"); Construct (n, port); } UdpEchoServer::~UdpEchoServer() { - NS_DEBUG ("UdpEchoServer::~UdpEchoServer ()"); + NS_LOG_FUNCTION; } void @@ -53,7 +53,8 @@ UdpEchoServer::Construct ( Ptr n, uint16_t port) { - NS_DEBUG ("UdpEchoServer::Construct (" << n << ", " << port << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << n << ", " << port << ")"); m_node = n; m_port = port; @@ -65,14 +66,14 @@ UdpEchoServer::Construct ( void UdpEchoServer::DoDispose (void) { - NS_DEBUG ("UdpEchoServer::DoDispose ()"); + NS_LOG_FUNCTION; Application::DoDispose (); } void UdpEchoServer::StartApplication (void) { - NS_DEBUG ("UdpEchoServer::StartApplication ()"); + NS_LOG_FUNCTION; if (!m_socket) { @@ -90,7 +91,8 @@ UdpEchoServer::StartApplication (void) void UdpEchoServer::StopApplication () { - NS_DEBUG ("UdpEchoServer::StopApplication ()"); + NS_LOG_FUNCTION; + if (!m_socket) { m_socket->SetRecvCallback((Callback, const Packet &, @@ -104,16 +106,16 @@ UdpEchoServer::Receive( const Packet &packet, const Address &from) { - NS_DEBUG ("UdpEchoServer::Receive (" << socket << ", " << packet << - ", " << from << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_DEBUG ("UdpEchoServer::Receive(): Received " << - packet.GetSize() << " bytes from " << address.GetIpv4()); + NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " << + address.GetIpv4()); - NS_DEBUG ("UdpEchoServer::Receive (): Echoing packet"); + NS_LOG_LOGIC ("Echoing packet"); socket->SendTo (from, packet); } } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 06af758ce..6154df7d3 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -19,13 +19,13 @@ */ #include "buffer.h" #include "ns3/assert.h" -#include "ns3/debug.h" +#include "ns3/log.h" #include -NS_DEBUG_COMPONENT_DEFINE ("Buffer"); +NS_LOG_COMPONENT_DEFINE ("Buffer"); -#define DEBUG_INTERNAL_STATE(y) \ -NS_DEBUG (y << "start="<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 @@ Buffer::RemoveAtStart (uint32_t start) 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 @@ Buffer::RemoveAtEnd (uint32_t end) 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 ()); } diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index 4229e15f8..812e9a9dc 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -21,12 +21,12 @@ #include #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 @@ PacketMetadata::ReadItems (uint16_t current, struct PacketMetadata::Data * PacketMetadata::Create (uint32_t size) { - NS_DEBUG ("create size="< resolver) void CompositeTraceResolver::Connect (std::string path, CallbackBase const &cb, const TraceContext &context) { - NS_DEBUG ("connect path="<name); + NS_LOG_LOGIC ("print " << (*i)->name); (*i)->CollectSources (path, context, collection); } if (m_parent != 0) @@ -316,7 +316,7 @@ CompositeTraceResolver::TraceAll (std::ostream &os, const TraceContext &context) { for (TraceItems::const_iterator i = m_items.begin (); i != m_items.end (); i++) { - NS_DEBUG ("print " << (*i)->name); + NS_LOG_LOGIC ("print " << (*i)->name); (*i)->TraceAll (os, context); } if (m_parent != 0) diff --git a/src/core/fatal-error.h b/src/core/fatal-error.h index 2c83de580..6dcf049b8 100644 --- a/src/core/fatal-error.h +++ b/src/core/fatal-error.h @@ -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 \ diff --git a/src/core/log.h b/src/core/log.h index 28d075565..f6e8f45a2 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -74,16 +74,28 @@ * defined with the NS_LOG_COMPONENT_DEFINE macro in the * same file. */ -#define NS_LOG(level, msg) \ - do \ - { \ - if (g_log.IsEnabled (level)) \ - { \ - std::clog << msg << std::endl; \ - } \ - } \ +#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_LEVEL_ERROR, msg) @@ -96,8 +108,8 @@ #define NS_LOG_INFO(msg) \ NS_LOG(ns3::LOG_LEVEL_INFO, msg) -#define NS_LOG_FUNCTION(msg) \ - NS_LOG(ns3::LOG_LEVEL_FUNCTION, msg) +#define NS_LOG_FUNCTION \ + NS_LOG_F(ns3::LOG_LEVEL_FUNCTION) #define NS_LOG_PARAM(msg) \ NS_LOG(ns3::LOG_LEVEL_PARAM, msg) diff --git a/src/core/object.cc b/src/core/object.cc index 27ac31917..1c6d58772 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -23,10 +23,10 @@ #include "singleton.h" #include "uid-manager.h" #include "trace-resolver.h" -#include "debug.h" +#include "log.h" #include -NS_DEBUG_COMPONENT_DEFINE ("Object"); +NS_LOG_COMPONENT_DEFINE ("Object"); namespace { @@ -322,7 +322,7 @@ Object::DoCollectSources (std::string path, const TraceContext &context, 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 @@ Object::DoCollectSources (std::string path, const TraceContext &context, 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); } diff --git a/src/core/random-variable-default-value.cc b/src/core/random-variable-default-value.cc index 14fdfa5a3..58597c545 100644 --- a/src/core/random-variable-default-value.cc +++ b/src/core/random-variable-default-value.cc @@ -19,9 +19,9 @@ * Author: Mathieu Lacage */ #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 @@ RandomVariableDefaultValue::Parse (const std::string &value, 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 @@ RandomVariableDefaultValue::Parse (const std::string &value, 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; } diff --git a/src/core/trace-resolver.cc b/src/core/trace-resolver.cc index d891c94c4..6569e206d 100644 --- a/src/core/trace-resolver.cc +++ b/src/core/trace-resolver.cc @@ -19,9 +19,9 @@ * Author: Mathieu Lacage */ #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 @@ TraceResolver::Unref (void) m_count--; if (m_count == 0) { - NS_DEBUG ("delete "< device) { - NS_DEBUG("CsmaChannel::Attach (" << device << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << device << ")"); NS_ASSERT(device != 0); CsmaDeviceRec rec(device); @@ -106,7 +109,8 @@ CsmaChannel::Attach(Ptr device) bool CsmaChannel::Reattach(Ptr device) { - NS_DEBUG("CsmaChannel::Reattach (" << device << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << device << ")"); NS_ASSERT(device != 0); std::vector::iterator it; @@ -131,7 +135,9 @@ CsmaChannel::Reattach(Ptr device) 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 @@ CsmaChannel::Reattach(uint32_t deviceId) 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 @@ CsmaChannel::Detach(uint32_t deviceId) bool CsmaChannel::Detach(Ptr device) { - NS_DEBUG("CsmaChannel::Detach (" << device << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << device << ")"); NS_ASSERT(device != 0); std::vector::iterator it; @@ -199,25 +207,23 @@ CsmaChannel::Detach(Ptr device) 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 @@ CsmaChannel::IsActive(uint32_t deviceId) 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 @@ CsmaChannel::TransmitEnd() 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 @@ CsmaChannel::TransmitEnd() 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::iterator it; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) diff --git a/src/devices/csma/csma-ipv4-topology.cc b/src/devices/csma/csma-ipv4-topology.cc index dd4d03700..750860f4d 100644 --- a/src/devices/csma/csma-ipv4-topology.cc +++ b/src/devices/csma/csma-ipv4-topology.cc @@ -20,7 +20,6 @@ #include #include "ns3/assert.h" -#include "ns3/debug.h" #include "ns3/fatal-error.h" #include "ns3/nstime.h" #include "ns3/internet-node.h" diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 1d15f2b9b..e4fd05a1b 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -19,7 +19,7 @@ * Author: Emmanuelle Laprise */ -#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 @@ CsmaTraceType::Print (std::ostream &os) const break; } } + uint16_t CsmaTraceType::GetUid (void) { + NS_LOG_FUNCTION; static uint16_t uid = AllocateUid ("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 @@ CsmaNetDevice::CsmaNetDevice (Ptr node) : 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 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, : 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 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, : 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 (Ptr node, Mac48Address addr, 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::DoDispose () CsmaNetDevice& CsmaNetDevice::operator= (const CsmaNetDevice nd) { - NS_DEBUG ("CsmaNetDevice::operator= (" << &nd << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &nd << ")"); return *this; } */ @@ -133,6 +150,7 @@ CsmaNetDevice::operator= (const CsmaNetDevice nd) void CsmaNetDevice::Init(bool sendEnable, bool receiveEnable) { + NS_LOG_FUNCTION; m_txMachineState = READY; m_tInterframeGap = Seconds(0); m_channel = 0; @@ -148,53 +166,63 @@ CsmaNetDevice::Init(bool sendEnable, bool receiveEnable) 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 @@ CsmaNetDevice::AddHeader (Packet& p, Mac48Address dest, 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 @@ CsmaNetDevice::ProcessHeader (Packet& p, uint16_t & param) bool CsmaNetDevice::DoNeedsArp (void) const { + NS_LOG_FUNCTION; if ((m_encapMode == IP_ARP) || (m_encapMode == LLC)) { return true; @@ -285,9 +316,10 @@ CsmaNetDevice::SendTo ( 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 @@ CsmaNetDevice::SendTo ( 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 @@ CsmaNetDevice::TransmitStart () 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 @@ CsmaNetDevice::TransmitStart () 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 @@ CsmaNetDevice::TransmitStart () 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 @@ CsmaNetDevice::TransmitAbort (void) 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 @@ CsmaNetDevice::TransmitCompleteEvent (void) 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 @@ CsmaNetDevice::TransmitCompleteEvent (void) 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 @@ CsmaNetDevice::TransmitReadyEvent (void) Ptr CsmaNetDevice::GetTraceResolver (void) const { + NS_LOG_FUNCTION; Ptr resolver = Create (); resolver->AddComposite ("queue", m_queue); resolver->AddSource ("rx", @@ -481,7 +506,8 @@ CsmaNetDevice::GetTraceResolver (void) const bool CsmaNetDevice::Attach (Ptr ch) { - NS_DEBUG ("CsmaNetDevice::Attach (" << &ch << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &ch << ")"); m_channel = ch; @@ -499,7 +525,8 @@ CsmaNetDevice::Attach (Ptr ch) void CsmaNetDevice::AddQueue (Ptr q) { - NS_DEBUG ("CsmaNetDevice::AddQueue (" << q << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << q << ")"); m_queue = q; } @@ -507,6 +534,8 @@ CsmaNetDevice::AddQueue (Ptr q) void CsmaNetDevice::Receive (const Packet& packet) { + NS_LOG_FUNCTION; + EthernetHeader header (false); EthernetTrailer trailer; Mac48Address broadcast; @@ -514,7 +543,7 @@ CsmaNetDevice::Receive (const Packet& packet) 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 @@ CsmaNetDevice::Receive (const Packet& packet) 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 @@ CsmaNetDevice::Receive (const Packet& packet) (mcDest != multicast) && (header.GetDestination () != destination)) { - NS_DEBUG ("CsmaNetDevice::Receive (): Dropping pkt "); + NS_LOG_LOGIC ("Dropping pkt "); m_dropTrace (p); return; } @@ -595,15 +623,14 @@ CsmaNetDevice::Receive (const Packet& packet) 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 @@ CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const // 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 @@ CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const Ptr CsmaNetDevice::GetQueue(void) const { - return m_queue; + NS_LOG_FUNCTION; + return m_queue; } Ptr CsmaNetDevice::DoGetChannel(void) const { - return m_channel; + NS_LOG_FUNCTION; + return m_channel; } } // namespace ns3 diff --git a/src/devices/csma/csma-topology.cc b/src/devices/csma/csma-topology.cc index 27e4e9e29..48a96ec2a 100644 --- a/src/devices/csma/csma-topology.cc +++ b/src/devices/csma/csma-topology.cc @@ -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" diff --git a/src/devices/point-to-point/point-to-point-channel.cc b/src/devices/point-to-point/point-to-point-channel.cc index ae78010cf..858338fa2 100644 --- a/src/devices/point-to-point/point-to-point-channel.cc +++ b/src/devices/point-to-point/point-to-point-channel.cc @@ -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 @@ PointToPointChannel::PointToPointChannel() m_delay (Seconds(0)), m_nDevices(0) { - NS_DEBUG("PointToPointChannel::PointToPointChannel ()"); + NS_LOG_FUNCTION; } PointToPointChannel::PointToPointChannel( @@ -51,8 +51,9 @@ PointToPointChannel::PointToPointChannel( 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 @@ PointToPointChannel::PointToPointChannel( 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 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 @@ PointToPointChannel::Attach(Ptr device) } } -bool PointToPointChannel::TransmitStart(Packet& p, +bool +PointToPointChannel::TransmitStart(Packet& p, Ptr 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 @@ bool PointToPointChannel::TransmitStart(Packet& p, uint32_t PointToPointChannel::GetNDevices (void) const { + NS_LOG_FUNCTION; return m_nDevices; } Ptr PointToPointChannel::GetDevice (uint32_t i) const { + NS_LOG_FUNCTION; NS_ASSERT(i < 2); return m_link[i].m_src; } @@ -129,12 +134,14 @@ PointToPointChannel::GetDevice (uint32_t i) const const DataRate& PointToPointChannel::GetDataRate (void) { + NS_LOG_FUNCTION; return m_bps; } const Time& PointToPointChannel::GetDelay (void) { + NS_LOG_FUNCTION; return m_delay; } diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index 322511467..20140386c 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -20,7 +20,7 @@ * Revised: George Riley */ -#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 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate( 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"); return uid; } + std::string PointToPointTraceType::GetTypeName (void) const { + NS_LOG_FUNCTION; return "ns3::PointToPointTraceType"; } @@ -69,11 +75,13 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node, 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 (Ptr node, 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 @@ PointToPointNetDevice::AddHeader(Packet& p, uint16_t protocolNumber) bool PointToPointNetDevice::ProcessHeader(Packet& p, uint16_t& param) { + NS_LOG_FUNCTION; LlcSnapHeader llc; p.RemoveHeader (llc); @@ -109,26 +119,30 @@ PointToPointNetDevice::ProcessHeader(Packet& p, uint16_t& param) 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 @@ -156,9 +170,9 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, 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 +183,7 @@ PointToPointNetDevice::TransmitStart (Packet &p) 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 +194,7 @@ PointToPointNetDevice::TransmitStart (Packet &p) 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 +211,7 @@ void PointToPointNetDevice::TransmitComplete (void) Ptr PointToPointNetDevice::GetTraceResolver (void) const { + NS_LOG_FUNCTION; Ptr resolver = Create (); resolver->AddComposite ("queue", m_queue); resolver->AddSource ("rx", @@ -209,9 +223,11 @@ PointToPointNetDevice::GetTraceResolver (void) const return resolver; } -bool PointToPointNetDevice::Attach (Ptr ch) +bool +PointToPointNetDevice::Attach (Ptr ch) { - NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &ch << ")"); m_channel = ch; @@ -237,14 +253,16 @@ bool PointToPointNetDevice::Attach (Ptr ch) void PointToPointNetDevice::AddQueue (Ptr 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 +273,19 @@ void PointToPointNetDevice::Receive (Packet& p) Ptr PointToPointNetDevice::GetQueue(void) const { - return m_queue; + NS_LOG_FUNCTION; + return m_queue; } Ptr PointToPointNetDevice::DoGetChannel(void) const { - return m_channel; + NS_LOG_FUNCTION; + return m_channel; } bool PointToPointNetDevice::DoNeedsArp (void) const { + NS_LOG_FUNCTION; return false; } diff --git a/src/devices/point-to-point/point-to-point-topology.cc b/src/devices/point-to-point/point-to-point-topology.cc index 5a9558419..4c99eaf88 100644 --- a/src/devices/point-to-point/point-to-point-topology.cc +++ b/src/devices/point-to-point/point-to-point-topology.cc @@ -24,7 +24,7 @@ #include #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" diff --git a/src/internet-node/ipv4-end-point-demux.cc b/src/internet-node/ipv4-end-point-demux.cc index 6d310e133..d17c450d8 100644 --- a/src/internet-node/ipv4-end-point-demux.cc +++ b/src/internet-node/ipv4-end-point-demux.cc @@ -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) -{} +{ + 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 @@ Ipv4EndPointDemux::~Ipv4EndPointDemux () 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 @@ Ipv4EndPointDemux::LookupPortLocal (uint16_t port) 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 @@ Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port) 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 @@ Ipv4EndPoint * 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 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, (*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 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, 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 @@ Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint) } } - /* * If we have an exact match, we return it. * Otherwise, if we find a generic match, we return it. @@ -166,40 +177,42 @@ Ipv4EndPointDemux::EndPoints 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,6 +241,7 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, uint16_t Ipv4EndPointDemux::AllocateEphemeralPort (void) { + NS_LOG_FUNCTION; uint16_t port = m_ephemeral; do { diff --git a/src/internet-node/ipv4-header.cc b/src/internet-node/ipv4-header.cc index 83750632d..2fd8fc059 100644 --- a/src/internet-node/ipv4-header.cc +++ b/src/internet-node/ipv4-header.cc @@ -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 @@ Ipv4Header::Serialize (Buffer::Iterator start) const uint8_t *data = start.PeekData (); uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ()); checksum = UtilsChecksumComplete (checksum); - NS_DEBUG ("checksum=" < nd) : 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 @@ Ipv4Interface::DoDispose (void) Ptr 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 @@ Ipv4Interface::GetBroadcast (void) const 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 @@ Ipv4Interface::GetMtu (void) const 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 @@ Ipv4Interface::SetDown (void) 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); } } diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 1c211edf1..50fd2e39a 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -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 @@ const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800; 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 @@ Ipv4L3ProtocolTraceContextElement::Print (std::ostream &os) const break; } } + uint16_t Ipv4L3ProtocolTraceContextElement::GetUid (void) { + NS_LOG_FUNCTION; static uint16_t uid = AllocateUid ("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"); return uid; } + std::string Ipv4L3ProtocolInterfaceIndex::GetTypeName (void) const { + NS_LOG_FUNCTION; return "ns3::Ipv4L3ProtocolInterfaceIndex"; } @@ -129,8 +157,7 @@ Ipv4L3Protocol::Ipv4L3Protocol(Ptr node) m_identification (0), m_node (node) { - NS_DEBUG("Ipv4L3Protocol::Ipv4L3Protocol ()"); - + NS_LOG_FUNCTION; SetInterfaceId (Ipv4L3Protocol::iid); m_staticRouting = Create (); AddRoutingProtocol (m_staticRouting, 0); @@ -139,14 +166,13 @@ Ipv4L3Protocol::Ipv4L3Protocol(Ptr node) 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 @@ Ipv4L3Protocol::DoDispose (void) void Ipv4L3Protocol::SetupLoopback (void) { - NS_DEBUG("Ipv4L3Protocol::SetupLoopback ()"); + NS_LOG_FUNCTION; Ptr interface = Create (m_node); interface->SetAddress (Ipv4Address::GetLoopback ()); @@ -170,7 +196,7 @@ Ipv4L3Protocol::SetupLoopback (void) Ptr Ipv4L3Protocol::GetTraceResolver (void) const { - NS_DEBUG("Ipv4L3Protocol::GetTraceResolver ()"); + NS_LOG_FUNCTION; Ptr resolver = Create (); resolver->AddSource ("tx", @@ -196,7 +222,7 @@ Ipv4L3Protocol::GetTraceResolver (void) const void Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl) { - NS_DEBUG("Ipv4L3Protocol::SetDefaultTtl ()"); + NS_LOG_FUNCTION; m_defaultTtl = ttl; } @@ -206,8 +232,8 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, 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 @@ void 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 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 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 @@ Ipv4L3Protocol::Lookup ( 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 @@ Ipv4L3Protocol::Lookup ( 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 @@ Ipv4L3Protocol::Lookup ( 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 @@ Ipv4L3Protocol::Lookup ( 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 @@ void Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, int priority) { - NS_DEBUG("Ipv4L3Protocol::AddRoutingProtocol (" << &routingProtocol << - ", " << priority << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &routingProtocol << ", " << priority << ")"); m_routingProtocols.push_back (std::pair > (-priority, routingProtocol)); m_routingProtocols.sort (); @@ -327,21 +357,22 @@ Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, 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 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, uint32_t inputInterface, std::vector 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 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, 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 @@ Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface) 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 @@ Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin, 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 device) { - NS_DEBUG("Ipv4L3Protocol::AddInterface (" << &device << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &device << ")"); Ptr interface = Create (m_node, device); return AddIpv4Interface (interface); } @@ -409,7 +445,8 @@ Ipv4L3Protocol::AddInterface (Ptr device) uint32_t Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { - 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 @@ Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) Ptr 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 @@ Ipv4L3Protocol::GetInterface (uint32_t index) const 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 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const 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 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr 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 @@ Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) void Ipv4L3Protocol::Receive( Ptr 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 @@ Ipv4L3Protocol::Receive( Ptr device, const Packet& p, uint16_t protoc return; } + NS_LOG_LOGIC ("Forward up"); ForwardUp (packet, ipHeader); } @@ -540,8 +582,9 @@ Ipv4L3Protocol::Send (Packet const &packet, 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 @@ Ipv4L3Protocol::SendRealOut (bool found, 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 outInterface = GetInterface (route.GetInterface ()); @@ -610,14 +653,12 @@ Ipv4L3Protocol::SendRealOut (bool found, 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 @@ Ipv4L3Protocol::Forwarding ( Ipv4Header &ipHeader, Ptr 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 @@ Ipv4L3Protocol::Forwarding ( { 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 @@ Ipv4L3Protocol::Forwarding ( 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 @@ Ipv4L3Protocol::Forwarding ( { // 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 @@ Ipv4L3Protocol::Forwarding ( 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 demux = m_node->QueryInterface (Ipv4L4Demux::iid); Ptr protocol = demux->GetProtocol (ip.GetProtocol ()); protocol->Receive (p, ip.GetSource (), ip.GetDestination ()); @@ -720,8 +758,8 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip) 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 (origin, group)); } @@ -729,8 +767,8 @@ Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) 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 @@ Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { - NS_DEBUG("Ipv4L3Protocol::SetAddress (" << i << ", " << address << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ", " << address << ")"); Ptr interface = GetInterface (i); interface->SetAddress (address); } @@ -755,7 +794,8 @@ Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - NS_DEBUG("Ipv4L3Protocol::SetNetworkMask (" << i << ", " << mask << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ", " << mask << ")"); Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } @@ -763,7 +803,8 @@ Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { - NS_DEBUG("Ipv4L3Protocol::GetNetworkMask (" << i << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ")"); Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } @@ -771,7 +812,8 @@ Ipv4L3Protocol::GetNetworkMask (uint32_t i) const Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { - NS_DEBUG("Ipv4L3Protocol::GetAddress (" << i << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ")"); Ptr interface = GetInterface (i); return interface->GetAddress (); } @@ -780,8 +822,8 @@ bool 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 @@ Ipv4L3Protocol::GetIfIndexForDestination ( 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 @@ Ipv4L3Protocol::GetIfIndexForDestination ( // 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 @@ Ipv4L3Protocol::GetIfIndexForDestination ( // 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 @@ Ipv4L3Protocol::GetIfIndexForDestination ( 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 interface = GetInterface (i); return interface->GetMtu (); } @@ -859,7 +898,8 @@ Ipv4L3Protocol::GetMtu (uint32_t i) const bool Ipv4L3Protocol::IsUp (uint32_t i) const { - NS_DEBUG("Ipv4L3Protocol::IsUp (" << i << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ")"); Ptr interface = GetInterface (i); return interface->IsUp (); } @@ -867,7 +907,8 @@ Ipv4L3Protocol::IsUp (uint32_t i) const void Ipv4L3Protocol::SetUp (uint32_t i) { - NS_DEBUG("Ipv4L3Protocol::SetUp (" << i << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << i << ")"); Ptr interface = GetInterface (i); interface->SetUp (); @@ -885,7 +926,8 @@ Ipv4L3Protocol::SetUp (uint32_t i) void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { - NS_DEBUG("Ipv4L3Protocol::SetDown (" << ifaceIndex << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << ifaceIndex << ")"); Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); @@ -907,5 +949,4 @@ Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) } } - }//namespace ns3 diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index ae158a9fe..eb59a662d 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -20,14 +20,14 @@ * Mathieu Lacage , */ -#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 @@ Ipv4LoopbackInterface::Ipv4LoopbackInterface (Ptr node) : 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 ipv4 = m_node->QueryInterface (Ipv4L3Protocol::iid); diff --git a/src/internet-node/ipv4-static-routing.cc b/src/internet-node/ipv4-static-routing.cc index c181dde29..6b7d8671d 100644 --- a/src/internet-node/ipv4-static-routing.cc +++ b/src/internet-node/ipv4-static-routing.cc @@ -19,17 +19,18 @@ // Author: George F. Riley // Gustavo Carneiro -#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 @@ Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 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 @@ void 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 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, Ipv4Address nextHop, uint32_t interface) { + NS_LOG_FUNCTION; Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateNetworkRouteTo (network, networkMask, @@ -71,6 +74,7 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkMask, uint32_t interface) { + NS_LOG_FUNCTION; Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateNetworkRouteTo (network, networkMask, @@ -82,6 +86,7 @@ void 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 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, uint32_t inputInterface, std::vector outputInterfaces) { + NS_LOG_FUNCTION; Ipv4MulticastRoute *route = new Ipv4MulticastRoute (); *route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group, inputInterface, outputInterfaces); @@ -103,6 +109,7 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, 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 @@ Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface) 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 @@ Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const Ipv4MulticastRoute * Ipv4StaticRouting::GetDefaultMulticastRoute () const { + NS_LOG_FUNCTION; if (m_defaultMulticastRoute != 0) { return m_defaultMulticastRoute; @@ -186,9 +196,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, 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 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, 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 @@ Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index) Ipv4Route * Ipv4StaticRouting::LookupStatic (Ipv4Address dest) { + NS_LOG_FUNCTION; for (HostRoutesCI i = m_hostRoutes.begin (); i != m_hostRoutes.end (); i++) @@ -289,6 +299,7 @@ Ipv4StaticRouting::LookupStatic ( 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 @@ Ipv4StaticRouting::LookupStatic ( uint32_t Ipv4StaticRouting::GetNRoutes (void) { + NS_LOG_FUNCTION; uint32_t n = 0; if (m_defaultRoute != 0) { @@ -403,6 +415,7 @@ Ipv4StaticRouting::GetNRoutes (void) Ipv4Route * Ipv4StaticRouting::GetDefaultRoute () { + NS_LOG_FUNCTION; if (m_defaultRoute != 0) { return m_defaultRoute; @@ -416,6 +429,7 @@ Ipv4StaticRouting::GetDefaultRoute () Ipv4Route * Ipv4StaticRouting::GetRoute (uint32_t index) { + NS_LOG_FUNCTION; if (index == 0 && m_defaultRoute != 0) { return m_defaultRoute; @@ -457,6 +471,7 @@ Ipv4StaticRouting::GetRoute (uint32_t index) void Ipv4StaticRouting::RemoveRoute (uint32_t index) { + NS_LOG_FUNCTION; if (index == 0 && m_defaultRoute != 0) { delete m_defaultRoute; @@ -506,26 +521,24 @@ Ipv4StaticRouting::RequestRoute ( 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 @@ Ipv4StaticRouting::RequestRoute ( 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 @@ Ipv4StaticRouting::RequestRoute ( // // 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 @@ Ipv4StaticRouting::RequestRoute ( 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 @@ Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) // // 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 @@ Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) void Ipv4StaticRouting::DoDispose (void) { + NS_LOG_FUNCTION; for (HostRoutesI i = m_hostRoutes.begin (); i != m_hostRoutes.end (); i = m_hostRoutes.erase (i)) diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index adf462f05..8d7bd395f 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#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 @@ UdpL4Protocol::UdpL4Protocol (Ptr node) 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 @@ UdpL4Protocol::DoDispose (void) Ptr UdpL4Protocol::CreateSocket (void) { - NS_DEBUG("UdpL4Protocol::CreateSocket ()"); + NS_LOG_FUNCTION; Ptr socket = Create (m_node, this); return socket; } @@ -75,36 +75,40 @@ UdpL4Protocol::CreateSocket (void) 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 @@ UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, 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 @@ UdpL4Protocol::Receive(Packet& packet, 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 @@ UdpL4Protocol::Send (Packet packet, 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 @@ UdpL4Protocol::Send (Packet packet, Ptr ipv4 = m_node->QueryInterface (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); } } diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 6f123bed5..9212614fa 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#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 @@ UdpSocket::UdpSocket (Ptr node, Ptr udp) 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 @@ UdpSocket::~UdpSocket () enum Socket::SocketErrno UdpSocket::GetErrno (void) const { - NS_DEBUG("UdpSocket::GetErrno ()"); - + NS_LOG_FUNCTION; return m_errno; } Ptr 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 @@ UdpSocket::Destroy (void) int UdpSocket::FinishBind (void) { - NS_DEBUG("UdpSocket::FinishBind ()"); - + NS_LOG_FUNCTION; if (m_endPoint == 0) { return -1; @@ -110,8 +108,7 @@ UdpSocket::FinishBind (void) int UdpSocket::Bind (void) { - NS_DEBUG("UdpSocket::Bind ()"); - + NS_LOG_FUNCTION; m_endPoint = m_udp->Allocate (); return FinishBind (); } @@ -119,11 +116,12 @@ UdpSocket::Bind (void) 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 @@ UdpSocket::Bind (const Address &address) int UdpSocket::ShutdownSend (void) { - NS_DEBUG("UdpSocket::ShutDownSend ()"); + NS_LOG_FUNCTION; m_shutdownSend = true; return 0; } @@ -160,7 +158,7 @@ UdpSocket::ShutdownSend (void) int UdpSocket::ShutdownRecv (void) { - NS_DEBUG("UdpSocket::ShutDownRecv ()"); + NS_LOG_FUNCTION; m_shutdownRecv = false; return 0; } @@ -168,7 +166,7 @@ UdpSocket::ShutdownRecv (void) int UdpSocket::Close(void) { - NS_DEBUG("UdpSocket::Close ()"); + NS_LOG_FUNCTION; NotifyCloseCompleted (); return 0; } @@ -176,7 +174,8 @@ UdpSocket::Close(void) 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,7 +183,7 @@ UdpSocket::Connect(const Address & address) NotifyConnectionSucceeded (); m_connected = true; - NS_DEBUG ("UdpSocket::Connect (): Updating local address"); + NS_LOG_LOGIC ("Updating local address"); uint32_t localIfIndex; @@ -195,8 +194,7 @@ UdpSocket::Connect(const Address & address) m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex)); } - NS_DEBUG ("UdpSocket::Connect (): Local address is " << - m_endPoint->GetLocalAddress()); + NS_LOG_LOGIC ("Local address is " << m_endPoint->GetLocalAddress()); return 0; } @@ -204,7 +202,8 @@ UdpSocket::Connect(const Address & address) int UdpSocket::Send (const Packet &p) { - NS_DEBUG("UdpSocket::Send (" << &p << ")"); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << &p << ")"); if (!m_connected) { @@ -217,6 +216,7 @@ UdpSocket::Send (const Packet &p) int UdpSocket::DoSend (const Packet &p) { + NS_LOG_FUNCTION; if (m_endPoint == 0) { if (Bind () == -1) @@ -238,11 +238,12 @@ UdpSocket::DoSend (const Packet &p) 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 +252,7 @@ UdpSocket::DoSendTo (const Packet &p, const Address &address) 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 +260,8 @@ UdpSocket::DoSendTo (const Packet &p, const Address &address) 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 +289,7 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) // 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 +301,7 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) } 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 +309,7 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) } else { - NS_DEBUG("UdpSocket::DoSendTo (): ERROR_NOROUTETOHOST"); + NS_LOG_ERROR ("ERROR_NOROUTETOHOST"); m_errno = ERROR_NOROUTETOHOST; return -1; } @@ -319,7 +320,8 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) 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 +331,8 @@ UdpSocket::SendTo(const Address &address, const Packet &p) 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) { From 2e1dcf1479762a5c166413140a2d1d78787aaa77 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 21:36:32 -0700 Subject: [PATCH 09/22] debug to log --- src/internet-node/arp-ipv4-interface.cc | 25 +-- src/internet-node/arp-l3-protocol.cc | 45 +++-- src/node/channel.cc | 18 +- src/node/drop-tail-queue.cc | 33 ++-- src/node/ethernet-header.cc | 4 +- src/node/ethernet-trailer.cc | 8 +- src/node/ipv4-address.cc | 6 +- src/node/net-device.cc | 46 ++++- src/node/packet-socket.cc | 31 +++- src/node/queue.cc | 87 ++++++---- src/node/socket.cc | 43 ++--- src/routing/global-routing/candidate-queue.cc | 34 ++-- .../global-route-manager-impl.cc | 163 +++++++++--------- .../global-routing/global-route-manager.cc | 5 +- .../global-routing/global-router-interface.cc | 117 ++++++++----- 15 files changed, 378 insertions(+), 287 deletions(-) diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index ed8ef584c..8d80c5711 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -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 @@ ArpIpv4Interface::ArpIpv4Interface (Ptr node, Ptr device) : Ipv4Interface (device), m_node (node) { - NS_DEBUG ("ArpIpv4Interface::ArpIpv4Interface ()"); + NS_LOG_FUNCTION; } ArpIpv4Interface::~ArpIpv4Interface () { - NS_DEBUG ("ArpIpv4Interface::~ArpIpv4Interface ()"); + NS_LOG_FUNCTION; } Ptr ArpIpv4Interface::GetTraceResolver (void) const { - NS_DEBUG ("ArpIpv4Interface::DoCreateTraceResolver ()"); + NS_LOG_FUNCTION; Ptr resolver = Create (); if (GetDevice () != 0) { @@ -63,12 +63,13 @@ ArpIpv4Interface::GetTraceResolver (void) const 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 arp = m_node->QueryInterface (ArpL3Protocol::iid); Address hardwareDestination; @@ -77,13 +78,13 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) 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 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) } 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); } diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index bcc62bfe2..e32e07fde 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #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 @@ const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; ArpL3Protocol::ArpL3Protocol (Ptr 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 @@ ArpL3Protocol::DoDispose (void) ArpCache * ArpL3Protocol::FindCache (Ptr 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 @@ ArpL3Protocol::FindCache (Ptr device) void ArpL3Protocol::Receive(Ptr 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="<GetId ()<<", got request from " << arp.GetSourceIpv4Address () << " for address " << arp.GetDestinationIpv4Address () << "; we have address " << @@ -93,7 +99,7 @@ ArpL3Protocol::Receive(Ptr device, const Packet& p, uint16_t protocol if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { - NS_DEBUG ("node="<GetId () <<", got request from " << + NS_LOG_LOGIC ("node="<GetId () <<", got request from " << arp.GetSourceIpv4Address () << " -- send reply"); SendArpReply (cache, arp.GetSourceIpv4Address (), arp.GetSourceHardwareAddress ()); @@ -108,7 +114,7 @@ ArpL3Protocol::Receive(Ptr device, const Packet& p, uint16_t protocol { if (entry->IsWaitReply ()) { - NS_DEBUG ("node="<GetId ()<<", got reply from " << + NS_LOG_LOGIC ("node="<GetId ()<<", got reply from " << arp.GetSourceIpv4Address () << " for waiting entry -- flush"); Address from_mac = arp.GetSourceHardwareAddress (); @@ -119,7 +125,7 @@ ArpL3Protocol::Receive(Ptr device, const Packet& p, uint16_t protocol { // ignore this reply which might well be an attempt // at poisening my arp cache. - NS_DEBUG ("node="<GetId ()<<", got reply from " << + NS_LOG_LOGIC("node="<GetId ()<<", got reply from " << arp.GetSourceIpv4Address () << " for non-waiting entry -- drop"); // XXX report packet as dropped. @@ -127,13 +133,13 @@ ArpL3Protocol::Receive(Ptr device, const Packet& p, uint16_t protocol } else { - NS_DEBUG ("node="<GetId ()<<", got reply for unknown entry -- drop"); + NS_LOG_LOGIC ("node="<GetId ()<<", got reply for unknown entry -- drop"); // XXX report packet as dropped. } } else { - NS_DEBUG ("node="<GetId ()<<", got request from " << + NS_LOG_LOGIC ("node="<GetId ()<<", got request from " << arp.GetSourceIpv4Address () << " for unknown address " << arp.GetDestinationIpv4Address () << " -- drop"); } @@ -143,6 +149,7 @@ ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, Ptr device, Address *hardwareDestination) { + NS_LOG_FUNCTION; ArpCache *cache = FindCache (device); ArpCache::Entry *entry = cache->Lookup (destination); if (entry != 0) @@ -151,21 +158,21 @@ ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, { if (entry->IsDead ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", dead entry for " << destination << " expired -- send arp request"); entry->MarkWaitReply (packet); SendArpRequest (cache, destination); } else if (entry->IsAlive ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", alive entry for " << destination << " expired -- send arp request"); entry->MarkWaitReply (packet); SendArpRequest (cache, destination); } else if (entry->IsWaitReply ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", wait reply for " << destination << " expired -- drop"); entry->MarkDead (); // XXX report packet as 'dropped' @@ -175,20 +182,20 @@ ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, { if (entry->IsDead ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", dead entry for " << destination << " valid -- drop"); // XXX report packet as 'dropped' } else if (entry->IsAlive ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", alive entry for " << destination << " valid -- send"); *hardwareDestination = entry->GetMacAddress (); return true; } else if (entry->IsWaitReply ()) { - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", wait reply for " << destination << " valid -- drop previous"); Packet old = entry->UpdateWaitReply (packet); // XXX report 'old' packet as 'dropped' @@ -199,7 +206,7 @@ ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, else { // This is our first attempt to transmit data to this destination. - NS_DEBUG ("node="<GetId ()<< + NS_LOG_LOGIC ("node="<GetId ()<< ", no entry for " << destination << " -- send arp request"); entry = cache->Add (destination); entry->MarkWaitReply (packet); @@ -211,8 +218,9 @@ ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, void ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) { + NS_LOG_FUNCTION; ArpHeader arp; - NS_DEBUG ("ARP: sending request from node "<GetId ()<< + NS_LOG_LOGIC ("ARP: sending request from node "<GetId ()<< " || src: " << cache->GetDevice ()->GetAddress () << " / " << cache->GetInterface ()->GetAddress () << " || dst: " << cache->GetDevice ()->GetBroadcast () << @@ -229,8 +237,9 @@ ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) void ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) { + NS_LOG_FUNCTION; ArpHeader arp; - NS_DEBUG ("ARP: sending reply from node "<GetId ()<< + NS_LOG_LOGIC ("ARP: sending reply from node "<GetId ()<< "|| src: " << cache->GetDevice ()->GetAddress () << " / " << cache->GetInterface ()->GetAddress () << " || dst: " << toMac << " / " << toIp); diff --git a/src/node/channel.cc b/src/node/channel.cc index 25db07984..e809b6dbc 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -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 - * - * 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 @@ const InterfaceId Channel::iid = MakeInterfaceId ("Channel", Object::iid); 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; } diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 74c8fde17..8b5ceea79 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -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 @@ DropTailQueue::DropTailQueue () : 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 @@ DropTailQueue::DoEnqueue (const Packet& p) 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 @@ DropTailQueue::DoDequeue (Packet& p) 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; } diff --git a/src/node/ethernet-header.cc b/src/node/ethernet-header.cc index 7a4671012..ce2241f50 100644 --- a/src/node/ethernet-header.cc +++ b/src/node/ethernet-header.cc @@ -22,12 +22,12 @@ #include #include #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 { diff --git a/src/node/ethernet-trailer.cc b/src/node/ethernet-trailer.cc index 6fdb5a845..049fe24d0 100644 --- a/src/node/ethernet-trailer.cc +++ b/src/node/ethernet-trailer.cc @@ -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 @@ EthernetTrailer::CheckFcs (const Packet& p) const { 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 @@ EthernetTrailer::CheckFcs (const Packet& p) const 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 diff --git a/src/node/ipv4-address.cc b/src/node/ipv4-address.cc index 0b0a48f29..b36892c50 100644 --- a/src/node/ipv4-address.cc +++ b/src/node/ipv4-address.cc @@ -18,12 +18,12 @@ * * Author: Mathieu Lacage */ -#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 { diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 0e8223f60..888243c0f 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -22,15 +22,13 @@ #include #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 @@ NetDevice::NetDevice(Ptr node, const Address& addr) : 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 @@ NetDevice::SetMtu (const uint16_t mtu) 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 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 @@ NetDevice::GetBroadcast (void) const void NetDevice::EnableBroadcast (Address broadcast) { + NS_LOG_FUNCTION; m_isBroadcast = true; m_broadcast = broadcast; } @@ -132,18 +145,21 @@ NetDevice::EnableBroadcast (Address broadcast) 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 @@ NetDevice::GetMulticast (void) const 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 @@ NetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const void NetDevice::EnableMulticast (Address multicast) { + NS_LOG_FUNCTION; m_isMulticast = true; m_multicast = multicast; } @@ -167,24 +185,28 @@ NetDevice::EnableMulticast (Address multicast) 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 @@ NetDevice::DisablePointToPoint (void) 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 @@ NetDevice::Send(const Packet& p, const Address& dest, uint16_t protocolNumber) Ptr NetDevice::GetChannel (void) const { + NS_LOG_FUNCTION; return DoGetChannel (); } @@ -212,10 +236,10 @@ NetDevice::GetChannel (void) const 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 @@ NetDevice::ForwardUp(const Packet& p, uint16_t param, const Address &from) } else { - NS_DEBUG ("NetDevice::Receive call back is NULL"); + NS_LOG_WARN ("NetDevice::Receive call back is NULL"); } return retval; @@ -232,6 +256,7 @@ NetDevice::ForwardUp(const Packet& p, uint16_t param, const Address &from) void NetDevice::NotifyLinkUp (void) { + NS_LOG_FUNCTION; m_isUp = true; if (!m_linkChangeCallback.IsNull ()) { @@ -242,6 +267,7 @@ NetDevice::NotifyLinkUp (void) void NetDevice::NotifyLinkDown (void) { + NS_LOG_FUNCTION; m_isUp = false; if (!m_linkChangeCallback.IsNull ()) { @@ -252,24 +278,28 @@ NetDevice::NotifyLinkDown (void) Ptr 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; } diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index f642eee9e..448b84334 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -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) : 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::Init() } 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 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 @@ PacketSocket::Bind (const Address &address) int PacketSocket::DoBind (const PacketSocketAddress &address) { + NS_LOG_FUNCTION; if (m_state == STATE_BOUND || m_state == STATE_CONNECTED) { @@ -119,6 +130,7 @@ PacketSocket::DoBind (const PacketSocketAddress &address) int PacketSocket::ShutdownSend (void) { + NS_LOG_FUNCTION; if (m_state == STATE_CLOSED) { m_errno = ERROR_BADF; @@ -127,9 +139,11 @@ PacketSocket::ShutdownSend (void) 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 @@ PacketSocket::ShutdownRecv (void) 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 @@ PacketSocket::Close(void) int PacketSocket::Connect(const Address &ad) { + NS_LOG_FUNCTION; PacketSocketAddress address; if (m_state == STATE_CLOSED) { @@ -188,6 +205,7 @@ PacketSocket::Connect(const Address &ad) int PacketSocket::Send (const Packet &p) { + NS_LOG_FUNCTION; if (m_state == STATE_OPEN || m_state == STATE_BOUND) { @@ -200,6 +218,7 @@ PacketSocket::Send (const Packet &p) int PacketSocket::SendTo(const Address &address, const Packet &p) { + NS_LOG_FUNCTION; PacketSocketAddress ad; if (m_state == STATE_CLOSED) { @@ -265,6 +284,7 @@ void PacketSocket::ForwardUp (Ptr device, const Packet &packet, uint16_t protocol, const Address &from) { + NS_LOG_FUNCTION; if (m_shutdownRecv) { return; @@ -277,8 +297,7 @@ PacketSocket::ForwardUp (Ptr device, const Packet &packet, 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); } diff --git a/src/node/queue.cc b/src/node/queue.cc index 8ed033b66..a2eec08ae 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -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 @@ static ClassIdDefaultValue g_classIdDefaultValue ("Queue", "Packet Queue", 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"); 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 @@ Queue::Queue() : 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 Queue::GetTraceResolver (void) const { + NS_LOG_FUNCTION; Ptr resolver = Create (); resolver->AddSource ("enqueue", TraceDoc ("store packet in queue", @@ -122,9 +138,9 @@ Queue::GetTraceResolver (void) const 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 @@ Queue::Enqueue (const Packet& p) 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 @@ Queue::Dequeue (Packet &p) 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 @@ Queue::Dequeue (Packet &p) 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 @@ Queue::Peek (Packet &p) 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 @@ Queue::ResetStatistics (void) 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::CreateDefault (void) { + NS_LOG_FUNCTION; ClassId classId = g_classIdDefaultValue.GetValue (); Ptr queue = ComponentManager::Create (classId, Queue::iid); return queue; diff --git a/src/node/socket.cc b/src/node/socket.cc index efb28002a..48623abbe 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -20,23 +20,23 @@ * Mathieu Lacage */ -#include "ns3/debug.h" +#include "ns3/log.h" #include "ns3/packet.h" #include "socket.h" -NS_DEBUG_COMPONENT_DEFINE ("Socket"); +NS_LOG_COMPONENT_DEFINE ("Socket"); namespace ns3 { Socket::~Socket () { - NS_DEBUG("Socket::~Socket ()"); + NS_LOG_FUNCTION; } void Socket::SetCloseCallback (Callback > closeCompleted) { - NS_DEBUG("Socket::SetCloseCallback ()"); + NS_LOG_FUNCTION; m_closeCompleted = closeCompleted; } @@ -46,7 +46,7 @@ Socket::SetConnectCallback ( Callback > connectionFailed, Callback > halfClose) { - NS_DEBUG("Socket::SetConnectCallback ()"); + NS_LOG_FUNCTION; m_connectionSucceeded = connectionSucceeded; m_connectionFailed = connectionFailed; m_halfClose = halfClose; @@ -58,7 +58,7 @@ Socket::SetAcceptCallback ( Callback, const Address&> newConnectionCreated, Callback > closeRequested) { - NS_DEBUG("Socket::SetAcceptCallback ()"); + NS_LOG_FUNCTION; m_connectionRequest = connectionRequest; m_newConnectionCreated = newConnectionCreated; m_closeRequested = closeRequested; @@ -67,22 +67,21 @@ Socket::SetAcceptCallback ( void Socket::SetSendCallback (Callback, uint32_t> dataSent) { - NS_DEBUG("Socket::SetSendCallback ()"); + NS_LOG_FUNCTION; m_dataSent = dataSent; } void Socket::SetRecvCallback (Callback, const Packet &,const Address&> receivedData) { - NS_DEBUG("Socket::SetRecvCallback ()"); + NS_LOG_FUNCTION; m_receivedData = receivedData; } void Socket::NotifyCloseCompleted (void) { - NS_DEBUG("Socket::NotifyCloseCompleted ()"); - + NS_LOG_FUNCTION; if (!m_closeCompleted.IsNull ()) { m_closeCompleted (this); @@ -92,8 +91,7 @@ Socket::NotifyCloseCompleted (void) void Socket::NotifyConnectionSucceeded (void) { - NS_DEBUG("Socket::NotifyConnectionSucceeded ()"); - + NS_LOG_FUNCTION; if (!m_connectionSucceeded.IsNull ()) { m_connectionSucceeded (this); @@ -103,8 +101,7 @@ Socket::NotifyConnectionSucceeded (void) void Socket::NotifyConnectionFailed (void) { - NS_DEBUG("Socket::NotifyConnectionFailed ()"); - + NS_LOG_FUNCTION; if (!m_connectionFailed.IsNull ()) { m_connectionFailed (this); @@ -114,8 +111,7 @@ Socket::NotifyConnectionFailed (void) void Socket::NotifyHalfClose (void) { - NS_DEBUG("Socket::NotifyHalfClose ()"); - + NS_LOG_FUNCTION; if (!m_halfClose.IsNull ()) { m_halfClose (this); @@ -125,8 +121,7 @@ Socket::NotifyHalfClose (void) bool Socket::NotifyConnectionRequest (const Address &from) { - NS_DEBUG("Socket::NotifyConnectionRequest ()"); - + NS_LOG_FUNCTION; if (!m_connectionRequest.IsNull ()) { return m_connectionRequest (this, from); @@ -141,8 +136,7 @@ Socket::NotifyConnectionRequest (const Address &from) void Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) { - NS_DEBUG("Socket::NotifyNewConnectionCreated ()"); - + NS_LOG_FUNCTION; if (!m_newConnectionCreated.IsNull ()) { m_newConnectionCreated (socket, from); @@ -152,8 +146,7 @@ Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) void Socket::NotifyCloseRequested (void) { - NS_DEBUG("Socket::NotifyCloseRequested ()"); - + NS_LOG_FUNCTION; if (!m_closeRequested.IsNull ()) { m_closeRequested (this); @@ -163,8 +156,7 @@ Socket::NotifyCloseRequested (void) void Socket::NotifyDataSent (uint32_t size) { - NS_DEBUG("Socket::NotifyDataSent ()"); - + NS_LOG_FUNCTION; if (!m_dataSent.IsNull ()) { m_dataSent (this, size); @@ -174,8 +166,7 @@ Socket::NotifyDataSent (uint32_t size) void Socket::NotifyDataReceived (const Packet &p, const Address &from) { - NS_DEBUG("Socket::NotifyDataReceived ()"); - + NS_LOG_FUNCTION; if (!m_receivedData.IsNull ()) { m_receivedData (this, p, from); diff --git a/src/routing/global-routing/candidate-queue.cc b/src/routing/global-routing/candidate-queue.cc index ffade0a31..e6d3b552e 100644 --- a/src/routing/global-routing/candidate-queue.cc +++ b/src/routing/global-routing/candidate-queue.cc @@ -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 @@ CandidateQueue::Clear (void) 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 @@ CandidateQueue::Push (SPFVertex *vNew) SPFVertex * CandidateQueue::Pop (void) { - NS_DEBUG("CandidateQueue::Pop ()"); - + NS_LOG_FUNCTION; if (m_candidates.empty ()) { return 0; @@ -87,8 +84,7 @@ CandidateQueue::Pop (void) SPFVertex * CandidateQueue::Top (void) const { - NS_DEBUG("CandidateQueue::Top ()"); - + NS_LOG_FUNCTION; if (m_candidates.empty ()) { return 0; @@ -100,24 +96,21 @@ CandidateQueue::Top (void) const 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 @@ CandidateQueue::Find (const Ipv4Address addr) const void CandidateQueue::Reorder (void) { - NS_DEBUG("CandidateQueue::Reorder ()"); - + NS_LOG_FUNCTION; std::list temp; while (!m_candidates.empty ()) { diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index 951ead2aa..88d9def84 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -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 #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 @@ SPFVertex::SPFVertex () : m_parent (0), m_children () { + NS_LOG_FUNCTION; } SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : @@ -66,20 +66,22 @@ SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : 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 @@ SPFVertex::~SPFVertex () 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 @@ SPFVertex::GetChild (uint32_t n) const uint32_t SPFVertex::AddChild (SPFVertex* child) { + NS_LOG_FUNCTION; m_children.push_back (child); return m_children.size (); } @@ -217,29 +236,27 @@ GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : 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 @@ GlobalRouteManagerLSDB::Initialize () 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 @@ GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const GlobalRoutingLSA* GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const { - NS_DEBUG ("GlobalRouteManagerLSDB::GetLSAByLinkData ()"); + NS_LOG_FUNCTION; // // Look up an LSA by its address. // @@ -308,14 +325,13 @@ GlobalRouteManagerImpl::GlobalRouteManagerImpl () : 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 @@ GlobalRouteManagerImpl::~GlobalRouteManagerImpl () void GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb) { - NS_DEBUG ("GlobalRouteManagerImpl::DebugUseLsdb ()"); - + NS_LOG_FUNCTION; if (m_lsdb) { delete m_lsdb; @@ -344,14 +359,12 @@ GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb) void GlobalRouteManagerImpl::SelectRouterNodes () { - NS_DEBUG ("GlobalRouteManagerImpl::SelectRouterNodes ()"); - + NS_LOG_FUNCTION; for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) { Ptr 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 = Create (node); node->AddInterface (globalRouter); @@ -370,7 +383,7 @@ GlobalRouteManagerImpl::SelectRouterNodes () void GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () { - NS_DEBUG ("GlobalRouteManagerImpl::BuildGlobalRoutingDatabase()"); + NS_LOG_FUNCTION; // // Walk the list of nodes looking for the GlobalRouter Interface. // @@ -396,7 +409,7 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () // 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 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () // 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 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () void GlobalRouteManagerImpl::InitializeRoutes () { - NS_DEBUG ("GlobalRouteManagerImpl::InitializeRoutes ()"); + NS_LOG_FUNCTION; // // Walk the list of nodes in the system. // @@ -491,16 +504,17 @@ GlobalRouteManagerImpl::InitializeRoutes () 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) // 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) // 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) { 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) { 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) // 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) 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 @@ GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) // root node). // candidate.Push (w); - NS_DEBUG ("SPFNext: Pushing " << + NS_LOG_LOGIC ("Pushing " << w->GetVertexId () << ", parent vertexId: " << v->GetVertexId ()); } @@ -691,8 +704,8 @@ GlobalRouteManagerImpl::SPFNexthopCalculation ( 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 @@ GlobalRouteManagerImpl::SPFNexthopCalculation ( 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 @@ GlobalRouteManagerImpl::SPFNexthopCalculation ( 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 @@ GlobalRouteManagerImpl::SPFNexthopCalculation ( */ 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 @@ GlobalRouteManagerImpl::SPFGetNextLink ( SPFVertex* w, GlobalRoutingLinkRecord* prev_link) { - NS_DEBUG ("GlobalRouteManagerImpl::SPFGetNextLink ()"); + NS_LOG_FUNCTION; bool skip = true; bool found_prev_link = false; @@ -907,12 +920,12 @@ GlobalRouteManagerImpl::SPFGetNextLink ( { 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 @@ GlobalRouteManagerImpl::SPFGetNextLink ( // if (skip == false) { - NS_DEBUG ("SPFGetNextLink: Returning the found link"); + NS_LOG_LOGIC ("Returning the found link"); return l; } else @@ -933,7 +946,7 @@ GlobalRouteManagerImpl::SPFGetNextLink ( // Setting skip to false gets us the next point-to-point global router link // record in the LSA from . // - NS_DEBUG ("SPFGetNextLink: Skipping the found link"); + NS_LOG_LOGIC ("Skipping the found link"); skip = false; continue; } @@ -948,7 +961,7 @@ GlobalRouteManagerImpl::SPFGetNextLink ( void GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) { - NS_DEBUG ("GlobalRouteManagerImpl::DebugSPFCalculate ()"); + NS_LOG_FUNCTION; SPFCalculate (root); } @@ -956,8 +969,8 @@ GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) void GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) { - NS_DEBUG ("GlobalRouteManagerImpl::SPFCalculate (): " - "root = " << root); + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << root << ")"); SPFVertex *v; // @@ -1023,7 +1036,7 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) // 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 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) uint32_t GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) { + NS_LOG_FUNCTION; // // We have an IP address 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 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) 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 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) // 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 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) 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 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) // 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 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) 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 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) 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 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) // 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 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) 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 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) // 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 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) 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 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) void GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v) { + NS_LOG_FUNCTION; v->GetParent ()->AddChild (v); } diff --git a/src/routing/global-routing/global-route-manager.cc b/src/routing/global-routing/global-route-manager.cc index ed2d0bfef..4349f0df8 100644 --- a/src/routing/global-routing/global-route-manager.cc +++ b/src/routing/global-routing/global-route-manager.cc @@ -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" diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index bf1b68a29..2819b7a24 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -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 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord () m_linkType (Unknown), m_metric (0) { - NS_DEBUG("GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ()"); + NS_LOG_FUNCTION; } GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( @@ -58,47 +57,48 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( 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::GetLinkType (void) const 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 @@ GlobalRoutingLSA::GlobalRoutingLSA() m_attachedRouters(), m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED) { - NS_DEBUG("GlobalRoutingLSA::GlobalRoutingLSA ()"); + NS_LOG_FUNCTION; } GlobalRoutingLSA::GlobalRoutingLSA ( @@ -156,8 +156,9 @@ GlobalRoutingLSA::GlobalRoutingLSA ( 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 @@ GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) 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 (GlobalRoutingLSA& lsa) 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 @@ GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa) 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::CopyLinkRecords (const GlobalRoutingLSA& lsa) 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 @@ GlobalRoutingLSA::ClearLinkRecords(void) *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 @@ GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr) 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 @@ GlobalRoutingLSA::GetLinkRecord (uint32_t n) const 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 @@ GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr) 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 @@ GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const 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 @@ const InterfaceId GlobalRouter::iid = GlobalRouter::GlobalRouter (Ptr 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 @@ GlobalRouter::DoDispose () 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 @@ GlobalRouter::ClearLSAs () *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 @@ GlobalRouter::GetRouterId (void) const 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 (): interface not set"); @@ -499,14 +524,14 @@ GlobalRouter::DiscoverLSAs (void) // 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 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 @@ GlobalRouter::DiscoverLSAs (void) 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 @@ GlobalRouter::DiscoverLSAs (void) 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 @@ GlobalRouter::DiscoverLSAs (void) } 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 @@ GlobalRouter::DiscoverLSAs (void) 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 @@ GlobalRouter::DiscoverLSAs (void) } 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 @@ GlobalRouter::DiscoverLSAs (void) // 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 @@ GlobalRouter::DiscoverLSAs (void) NS_ASSERT_MSG(srRemote, "GlobalRouter::DiscoverLSAs():QI for remote 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 @@ GlobalRouter::DiscoverLSAs (void) // 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 @@ GlobalRouter::DiscoverLSAs (void) // 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 @@ GlobalRouter::DiscoverLSAs (void) pLSA->AddAttachedRouter (tempAddr); } m_LSAs.push_back (pLSA); - NS_DEBUG(*pLSA); + NS_LOG_LOGIC (*pLSA); } } @@ -734,7 +757,7 @@ GlobalRouter::FindDesignatedRouterForLink (Ptr node, uint32_t GlobalRouter::GetNumLSAs (void) const { - NS_DEBUG("GlobalRouter::GetNumLSAs ()"); + NS_LOG_FUNCTION; return m_LSAs.size (); } @@ -744,6 +767,7 @@ GlobalRouter::GetNumLSAs (void) const 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 @@ GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const Ptr GlobalRouter::GetAdjacent(Ptr nd, Ptr ch) const { - + NS_LOG_FUNCTION; NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices"); // @@ -809,6 +833,7 @@ GlobalRouter::GetAdjacent(Ptr nd, Ptr ch) const uint32_t GlobalRouter::FindIfIndexForDevice(Ptr node, Ptr nd) const { + NS_LOG_FUNCTION; Ptr ipv4 = node->QueryInterface (Ipv4::iid); NS_ASSERT_MSG(ipv4, "QI for interface failed"); for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) From ed9f98bda15fb8d902dc0ff670c505856ddc7544 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 13 Sep 2007 22:17:29 -0700 Subject: [PATCH 10/22] disable log unless debug build --- src/core/log.cc | 5 ++- src/core/log.h | 74 ++++++++++++++++++++++++++++++------- src/node/queue.cc | 2 +- tutorial/hello-simulator.cc | 4 +- wscript | 1 + 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/core/log.cc b/src/core/log.cc index 64a288289..fc7576cfa 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -17,6 +17,9 @@ * * Author: Mathieu Lacage */ + +#ifdef NS3_LOG_ENABLE + #include #include #include @@ -295,4 +298,4 @@ LogComponentPrintList (void) } // namespace ns3 - +#endif // NS3_LOG_ENABLE diff --git a/src/core/log.h b/src/core/log.h index f6e8f45a2..1ab45080d 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -17,8 +17,9 @@ * * Author: Mathieu Lacage */ -#ifndef LOG_H -#define LOG_H + +#ifndef __LOG_H__ +#define __LOG_H__ #include #include @@ -61,9 +62,18 @@ * 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 @@ -74,15 +84,18 @@ * defined with the NS_LOG_COMPONENT_DEFINE macro in the * same file. */ -#define NS_LOG(level, msg) \ - do \ - { \ - if (g_log.IsEnabled (level)) \ - { \ - std::clog << __PRETTY_FUNCTION__ << " ==> " << \ - msg << std::endl; \ - } \ - } \ + +#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) \ @@ -95,7 +108,6 @@ } \ while (false) - #define NS_LOG_ERROR(msg) \ NS_LOG(ns3::LOG_LEVEL_ERROR, msg) @@ -127,8 +139,26 @@ } \ 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_LEVEL_ERROR = 1<<0, // serious error messages only LOG_LEVEL_WARN = 1<<1, // add warning messages @@ -140,6 +170,8 @@ enum LogLevel { LOG_LEVEL_ALL = 1<<30 // print everything }; +#endif + /** * \param name a log component name * \ingroup logging @@ -148,7 +180,11 @@ enum LogLevel { * 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 @@ -158,7 +194,11 @@ void LogComponentEnable (char const *name, enum LogLevel level); * 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 @@ -170,7 +210,13 @@ void LogComponentDisable (char const *name, enum LogLevel level); * * For example: NS_LOG=print-list */ +#ifdef NS3_LOG_ENABLE void LogComponentPrintList (void); +#else +#define LogComponentPrintList() +#endif + +#ifdef NS3_LOG_ENABLE class LogComponent { public: @@ -183,6 +229,8 @@ private: int32_t m_levels; }; +#endif + } // namespace ns3 -#endif /* LOG_H */ +#endif // __LOG_H__ diff --git a/src/node/queue.cc b/src/node/queue.cc index a2eec08ae..4a622c2b0 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -214,7 +214,7 @@ bool Queue::IsEmpty (void) { NS_LOG_FUNCTION; - NS_LOG_LOGIC ("returns" << (m_nPackets == 0)); + NS_LOG_LOGIC ("returns " << (m_nPackets == 0)); return m_nPackets == 0; } diff --git a/tutorial/hello-simulator.cc b/tutorial/hello-simulator.cc index 84ac0914e..735d98130 100644 --- a/tutorial/hello-simulator.cc +++ b/tutorial/hello-simulator.cc @@ -16,10 +16,10 @@ #include "ns3/log.h" -using namespace ns3; - NS_LOG_COMPONENT_DEFINE ("HelloSimulator"); +using namespace ns3; + int main (int argc, char *argv[]) { diff --git a/wscript b/wscript index 9e54f7050..1e8fd84e2 100644 --- a/wscript +++ b/wscript @@ -119,6 +119,7 @@ def configure(conf): 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. From 8649c899dbc59bc4cc864f6b1a25e2cca747f06f Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Fri, 14 Sep 2007 09:57:53 -0700 Subject: [PATCH 11/22] allow discrete levels --- src/core/log.cc | 68 ++++++++++++++++++++++++--------- src/core/log.h | 47 +++++++++++++++-------- src/mobility/random-position.cc | 6 +-- 3 files changed, 83 insertions(+), 38 deletions(-) diff --git a/src/core/log.cc b/src/core/log.cc index fc7576cfa..6f5bd6acf 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -92,7 +92,7 @@ LogComponentEnableEnvVar (void) if (equal == std::string::npos) { component = tmp; - level = LOG_LEVEL_DEBUG; + level = LOG_DEBUG; } else { @@ -106,33 +106,65 @@ LogComponentEnableEnvVar (void) std::string lev = tmp.substr (cur_lev, next_lev - cur_lev); if (lev == "error") { - level |= LOG_LEVEL_ERROR; + level |= LOG_ERROR; } else if (lev == "warn") { - level |= LOG_LEVEL_WARN; + level |= LOG_WARN; } else if (lev == "debug") { - level |= LOG_LEVEL_DEBUG; + level |= LOG_DEBUG; } else if (lev == "info") { - level |= LOG_LEVEL_INFO; + level |= LOG_INFO; } else if (lev == "function") { - level |= LOG_LEVEL_FUNCTION; + level |= LOG_FUNCTION; } else if (lev == "param") { - level |= LOG_LEVEL_PARAM; + level |= LOG_PARAM; } else if (lev == "logic") { - level |= LOG_LEVEL_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; } @@ -191,9 +223,7 @@ bool LogComponent::IsEnabled (enum LogLevel level) const { LogComponentEnableEnvVar (); -// return (level & m_levels) ? 1 : 0; - - return m_levels >= level; + return (level & m_levels) ? 1 : 0; } bool @@ -260,35 +290,35 @@ LogComponentPrintList (void) std::cout << "0" << std::endl; continue; } - if (i->second->IsEnabled (LOG_LEVEL_ERROR)) + if (i->second->IsEnabled (LOG_ERROR)) { std::cout << "error"; } - if (i->second->IsEnabled (LOG_LEVEL_WARN)) + if (i->second->IsEnabled (LOG_WARN)) { std::cout << "|warn"; } - if (i->second->IsEnabled (LOG_LEVEL_DEBUG)) + if (i->second->IsEnabled (LOG_DEBUG)) { std::cout << "|debug"; } - if (i->second->IsEnabled (LOG_LEVEL_INFO)) + if (i->second->IsEnabled (LOG_INFO)) { std::cout << "|info"; } - if (i->second->IsEnabled (LOG_LEVEL_FUNCTION)) + if (i->second->IsEnabled (LOG_FUNCTION)) { std::cout << "|function"; } - if (i->second->IsEnabled (LOG_LEVEL_PARAM)) + if (i->second->IsEnabled (LOG_PARAM)) { std::cout << "|param"; } - if (i->second->IsEnabled (LOG_LEVEL_LOGIC)) + if (i->second->IsEnabled (LOG_LOGIC)) { std::cout << "|logic"; } - if (i->second->IsEnabled (LOG_LEVEL_ALL)) + if (i->second->IsEnabled (LOG_ALL)) { std::cout << "|all"; } diff --git a/src/core/log.h b/src/core/log.h index 1ab45080d..267419bf5 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -109,28 +109,28 @@ while (false) #define NS_LOG_ERROR(msg) \ - NS_LOG(ns3::LOG_LEVEL_ERROR, msg) + NS_LOG(ns3::LOG_ERROR, msg) #define NS_LOG_WARN(msg) \ - NS_LOG(ns3::LOG_LEVEL_WARN, msg) + NS_LOG(ns3::LOG_WARN, msg) #define NS_LOG_DEBUG(msg) \ - NS_LOG(ns3::LOG_LEVEL_DEBUG, msg) + NS_LOG(ns3::LOG_DEBUG, msg) #define NS_LOG_INFO(msg) \ - NS_LOG(ns3::LOG_LEVEL_INFO, msg) + NS_LOG(ns3::LOG_INFO, msg) #define NS_LOG_FUNCTION \ - NS_LOG_F(ns3::LOG_LEVEL_FUNCTION) + NS_LOG_F(ns3::LOG_FUNCTION) #define NS_LOG_PARAM(msg) \ - NS_LOG(ns3::LOG_LEVEL_PARAM, msg) + NS_LOG(ns3::LOG_PARAM, msg) #define NS_LOG_LOGIC(msg) \ - NS_LOG(ns3::LOG_LEVEL_LOGIC, msg) + NS_LOG(ns3::LOG_LOGIC, msg) #define NS_LOG_ALL(msg) \ - NS_LOG(ns3::LOG_LEVEL_ALL, msg) + NS_LOG(ns3::LOG_ALL, msg) #define NS_LOG_UNCOND(msg) \ do \ @@ -160,14 +160,29 @@ namespace ns3 { #ifdef NS3_LOG_ENABLE enum LogLevel { - LOG_LEVEL_ERROR = 1<<0, // serious error messages only - LOG_LEVEL_WARN = 1<<1, // add warning messages - LOG_LEVEL_DEBUG = 1<<2, // add rare ad-hoc debug messages - LOG_LEVEL_INFO = 1<<3, // add informational messages (e.g., banners) - LOG_LEVEL_FUNCTION = 1<<4, // add function tracing - LOG_LEVEL_PARAM = 1<<5, // add parameters to functions - LOG_LEVEL_LOGIC = 1<<6, // add control flow tracing within functions - LOG_LEVEL_ALL = 1<<30 // print everything + 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 diff --git a/src/mobility/random-position.cc b/src/mobility/random-position.cc index 5e821cfc0..4e2a79f69 100644 --- a/src/mobility/random-position.cc +++ b/src/mobility/random-position.cc @@ -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 -NS_DEBUG_COMPONENT_DEFINE ("RandomPosition"); +NS_LOG_COMPONENT_DEFINE ("RandomPosition"); namespace ns3 { @@ -127,7 +127,7 @@ RandomDiscPosition::Get (void) const 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); } From 9ef345f02de8b33645f744410fb2214a0b67fc4f Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 14:42:31 -0700 Subject: [PATCH 12/22] Enable enqueue/dequeue tracing for point-to-point links --- examples/csma-multicast.cc | 3 +++ examples/simple-point-to-point.cc | 2 +- src/devices/point-to-point/point-to-point-net-device.cc | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 5ca1d79d5..2d70a7ba4 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -63,6 +63,9 @@ 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 // + +NS_LOG_ALL(""); + #if 0 LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO); diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index c4cfef038..720f241a3 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -214,8 +214,8 @@ main (int argc, char *argv[]) // Trace output will be sent to the simple-point-to-point.tr file NS_LOG_INFO ("Configure Tracing."); AsciiTrace asciitrace ("simple-point-to-point.tr"); - asciitrace.TraceAllQueues (); asciitrace.TraceAllNetDeviceRx (); + asciitrace.TraceAllQueues (); // Also configure some tcpdump traces; each interface will be traced // The output files will be named diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index 20140386c..ce3a253eb 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -156,9 +156,12 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, // // // 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 From b310b6745d923e138f23a0300d4b38d950fc5217 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 14:52:09 -0700 Subject: [PATCH 13/22] Revert accidental tweaks of example files (not intended for checkin) --- examples/csma-multicast.cc | 3 --- examples/simple-point-to-point.cc | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 2d70a7ba4..5ca1d79d5 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -63,9 +63,6 @@ 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 // - -NS_LOG_ALL(""); - #if 0 LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO); diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index 720f241a3..c4cfef038 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -214,8 +214,8 @@ main (int argc, char *argv[]) // Trace output will be sent to the simple-point-to-point.tr file NS_LOG_INFO ("Configure Tracing."); AsciiTrace asciitrace ("simple-point-to-point.tr"); - asciitrace.TraceAllNetDeviceRx (); asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); // Also configure some tcpdump traces; each interface will be traced // The output files will be named From 36b77224c523895b672c691c1db369af87437e67 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 14:55:18 -0700 Subject: [PATCH 14/22] Remove temporary module documentation --- README.multicast-routing | 235 --------------------------------------- 1 file changed, 235 deletions(-) delete mode 100644 README.multicast-routing diff --git a/README.multicast-routing b/README.multicast-routing deleted file mode 100644 index 2fe30532e..000000000 --- a/README.multicast-routing +++ /dev/null @@ -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 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 From bba1cb3859313d4244dc3b43a5565d05ec2d05de Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 15:46:04 -0700 Subject: [PATCH 15/22] remove local address setting from UdpSocket::Connect() --- src/internet-node/udp-socket.cc | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 9212614fa..9f4f6744d 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -183,19 +183,6 @@ UdpSocket::Connect(const Address & address) NotifyConnectionSucceeded (); m_connected = true; - NS_LOG_LOGIC ("Updating local address"); - - uint32_t localIfIndex; - - Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); - - if (ipv4->GetIfIndexForDestination (m_defaultAddress, localIfIndex)) - { - m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex)); - } - - NS_LOG_LOGIC ("Local address is " << m_endPoint->GetLocalAddress()); - return 0; } From 7bf7f4bbe5c554396a53b650d1c19e31e290e59c Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 15:57:49 -0700 Subject: [PATCH 16/22] add PacketSinks, change port number to UDP discard port, fix comment on onoff-application, delete logic for setting a default route --- examples/csma-broadcast.cc | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 84efdd4f1..acd09e07b 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -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 #include @@ -56,6 +56,7 @@ #include "ns3/socket.h" #include "ns3/ipv4-route.h" #include "ns3/onoff-application.h" +#include "ns3/packet-sink.h" using namespace ns3; @@ -87,10 +88,10 @@ main (int argc, char *argv[]) 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); - 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 @@ -145,31 +146,41 @@ main (int argc, char *argv[]) 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 = n0->QueryInterface (Ipv4::iid); - ipv4->SetDefaultRoute ("192.168.1.3", n0ifIndex0); + // RFC 863 discard port indicates packet should be thrown away + // by the system. We allow this silent discard to be overridden + // by the PacketSink application. + uint16_t discard_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 ooff = Create ( n0, - InetSocketAddress ("255.255.255.255", 80), + InetSocketAddress ("255.255.255.255", discard_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 sink = Create ( + n1, + InetSocketAddress (Ipv4Address::GetAny (), discard_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 ( + n2, + InetSocketAddress (Ipv4Address::GetAny (), discard_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 From 1d79c8dc53332b1c798fba3155cb9f0b51705385 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 16:11:36 -0700 Subject: [PATCH 17/22] change ephemeral port range to 49152-65535 (IANA recommendation) --- src/internet-node/ipv4-end-point-demux.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/internet-node/ipv4-end-point-demux.cc b/src/internet-node/ipv4-end-point-demux.cc index d17c450d8..20dc0d271 100644 --- a/src/internet-node/ipv4-end-point-demux.cc +++ b/src/internet-node/ipv4-end-point-demux.cc @@ -28,7 +28,7 @@ namespace ns3{ NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux"); Ipv4EndPointDemux::Ipv4EndPointDemux () - : m_ephemeral (1025) + : m_ephemeral (49152) { NS_LOG_FUNCTION; } @@ -246,9 +246,9 @@ Ipv4EndPointDemux::AllocateEphemeralPort (void) do { port++; - if (port > 5000) + if (port == 65535) { - port = 1024; + port = 49152; } if (!LookupPortLocal (port)) { From 5e49ae47a9fcbad4f94003abf5b5386c31788a77 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 16:17:10 -0700 Subject: [PATCH 18/22] change port number used by example scripts to 'discard' or 'echo' instead of '80' --- examples/csma-broadcast.cc | 10 +++++----- examples/csma-multicast.cc | 5 ++++- examples/csma-one-subnet.cc | 5 +++-- examples/mixed-global-routing.cc | 3 ++- examples/simple-global-routing.cc | 9 +++++---- examples/simple-point-to-point.cc | 9 +++++---- examples/udp-echo.cc | 2 +- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index acd09e07b..06775e26d 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -146,17 +146,17 @@ main (int argc, char *argv[]) CsmaIpv4Topology::AddIpv4Address ( n2, n2ifIndex, Ipv4Address("192.168.1.2"), Ipv4Mask("255.255.255.0")); - // RFC 863 discard port indicates packet should be thrown away + // 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 discard_port = 9; + uint16_t port = 9; // Create the OnOff application to send UDP datagrams of size // 512 bytes (default) at a rate of 500 Kb/s (default) from n0 NS_LOG_INFO ("Create Applications."); Ptr ooff = Create ( n0, - InetSocketAddress ("255.255.255.255", discard_port), + InetSocketAddress ("255.255.255.255", port), "Udp", ConstantVariable(1), ConstantVariable(0)); @@ -167,7 +167,7 @@ main (int argc, char *argv[]) // Create an optional packet sink to receive these packets Ptr sink = Create ( n1, - InetSocketAddress (Ipv4Address::GetAny (), discard_port), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.0)); @@ -176,7 +176,7 @@ main (int argc, char *argv[]) // Create an optional packet sink to receive these packets sink = Create ( n2, - InetSocketAddress (Ipv4Address::GetAny (), discard_port), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.0)); diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 5ca1d79d5..3e8551a13 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -274,9 +274,12 @@ main (int argc, char *argv[]) // multicast group (node four will be listening). // NS_LOG_INFO ("Create Applications."); + + uint16_t port = 9; // Discard port (RFC 863) + Ptr ooff = Create ( n0, - InetSocketAddress (multicastGroup, 80), + InetSocketAddress (multicastGroup, port), "Udp", ConstantVariable(1), ConstantVariable(0), diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index dfc41a88e..76918cbb7 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -164,9 +164,10 @@ main (int argc, char *argv[]) // Create an OnOff application to send UDP datagrams from node zero to node 1. // NS_LOG_INFO ("Create Applications."); + uint16_t port = 9; // Discard port (RFC 863) Ptr ooff = Create ( n0, - InetSocketAddress ("10.1.1.2", 80), + InetSocketAddress ("10.1.1.2", port), "Udp", ConstantVariable(1), ConstantVariable(0)); @@ -180,7 +181,7 @@ main (int argc, char *argv[]) // ooff = Create ( n3, - InetSocketAddress ("10.1.1.1", 80), + InetSocketAddress ("10.1.1.1", port), "Udp", ConstantVariable(1), ConstantVariable(0)); diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index ba2901a65..e5eb8dd97 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -190,9 +190,10 @@ main (int argc, char *argv[]) // 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 ooff = Create ( n0, - InetSocketAddress ("10.1.3.2", 80), + InetSocketAddress ("10.1.3.2", port), "Udp", ConstantVariable (1), ConstantVariable (0), diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index 8c6bd9db6..362ca7af3 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -162,9 +162,10 @@ main (int argc, char *argv[]) // 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 ooff = Create ( n0, - InetSocketAddress ("10.1.3.2", 80), + InetSocketAddress ("10.1.3.2", port), "Udp", ConstantVariable (1), ConstantVariable (0)); @@ -176,7 +177,7 @@ main (int argc, char *argv[]) // The last argument "true" disables output from the Receive callback Ptr sink = Create ( n3, - InetSocketAddress (Ipv4Address::GetAny (), 80), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.0)); @@ -185,7 +186,7 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n1, starting at time 1.1 seconds ooff = Create ( n3, - InetSocketAddress ("10.1.2.1", 80), + InetSocketAddress ("10.1.2.1", port), "Udp", ConstantVariable (1), ConstantVariable (0)); @@ -196,7 +197,7 @@ main (int argc, char *argv[]) // Create a packet sink to receive these packets sink = Create ( n1, - InetSocketAddress (Ipv4Address::GetAny (), 80), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.1)); diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index c4cfef038..5bbde9bca 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -162,9 +162,10 @@ main (int argc, char *argv[]) // 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 ooff = Create ( n0, - InetSocketAddress ("10.1.3.2", 80), + InetSocketAddress ("10.1.3.2", port), "Udp", ConstantVariable(1), ConstantVariable(0)); @@ -175,7 +176,7 @@ main (int argc, char *argv[]) // Create an optional packet sink to receive these packets Ptr sink = Create ( n3, - InetSocketAddress (Ipv4Address::GetAny (), 80), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.0)); @@ -184,7 +185,7 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n1, starting at time 1.1 seconds ooff = Create ( n3, - InetSocketAddress ("10.1.2.1", 80), + InetSocketAddress ("10.1.2.1", port), "Udp", ConstantVariable(1), ConstantVariable(0)); @@ -195,7 +196,7 @@ main (int argc, char *argv[]) // Create a packet sink to receive these packets sink = Create ( n1, - InetSocketAddress (Ipv4Address::GetAny (), 80), + InetSocketAddress (Ipv4Address::GetAny (), port), "Udp"); // Start the sink sink->Start (Seconds (1.1)); diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 70fcf4895..8eebef638 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -165,7 +165,7 @@ main (int argc, char *argv[]) // // Create a UdpEchoServer application on node one. // - uint16_t port = 80; + uint16_t port = 9; // well-known echo port number Ptr server = Create (n1, port); // From e26b497ccc32ae31fcb5c014d4e2c95d5e425f18 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 16:23:49 -0700 Subject: [PATCH 19/22] Add PacketSink to receive multicast --- examples/csma-multicast.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 3e8551a13..942485f50 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -51,6 +51,7 @@ #include "ns3/socket.h" #include "ns3/ipv4-route.h" #include "ns3/onoff-application.h" +#include "ns3/packet-sink.h" using namespace ns3; @@ -87,6 +88,7 @@ main (int argc, char *argv[]) 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() @@ -277,6 +279,8 @@ main (int argc, char *argv[]) uint16_t port = 9; // Discard port (RFC 863) + // Configure a multicast packet generator that generates a packet + // every few seconds Ptr ooff = Create ( n0, InetSocketAddress (multicastGroup, port), @@ -290,6 +294,18 @@ main (int argc, char *argv[]) // 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 sink = Create ( + 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" From ccee2254e0843c64d8a7a59bdab275209fd1f1c2 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 15 Sep 2007 13:52:59 -0700 Subject: [PATCH 20/22] release notes for 3.0.6 --- RELEASE_NOTES | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 85a5f2d6e..e429e5fec 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -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) ======================== From acadb46e6c86422d4bba5ad90eab94b9dce6b98c Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 15 Sep 2007 13:56:21 -0700 Subject: [PATCH 21/22] bump version number --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index eca690e73..818bd47ab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.5 +3.0.6 From df5905ace677a44c10200c1ba03ff5d19ba308c1 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 15 Sep 2007 14:07:35 -0700 Subject: [PATCH 22/22] Added tag release ns-3.0.6 for changeset 606df29888e7 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 68f54ead8..35f08ab9c 100644 --- a/.hgtags +++ b/.hgtags @@ -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