From c3cbbcacd7067256371aa0f4a29b4bbe749e1c3d Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 20:40:05 -0800 Subject: [PATCH 01/13] Add src/common/error-model implementation and example script, and add to NetDevices --- examples/simple-error-model.cc | 240 ++++++++++++++ examples/wscript | 4 + src/common/error-model.cc | 300 ++++++++++++++++++ src/common/error-model.h | 236 ++++++++++++++ src/common/wscript | 2 + src/devices/csma/csma-net-device.cc | 65 ++-- src/devices/csma/csma-net-device.h | 17 + .../point-to-point-net-device.cc | 60 +++- .../point-to-point-net-device.h | 34 ++ 9 files changed, 930 insertions(+), 28 deletions(-) create mode 100644 examples/simple-error-model.cc create mode 100644 src/common/error-model.cc create mode 100644 src/common/error-model.h diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc new file mode 100644 index 000000000..04b627e62 --- /dev/null +++ b/examples/simple-error-model.cc @@ -0,0 +1,240 @@ +/* -*- 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 + * + * ns-2 simple.tcl script (ported from ns-2) + * Originally authored by Steve McCanne, 12/19/1996 + */ + +// Port of ns-2/tcl/ex/simple.tcl to ns-3 +// +// Network topology +// +// n0 +// \ 5 Mb/s, 2ms +// \ 1.5Mb/s, 10ms +// n2 -------------------------n3 +// / +// / 5 Mb/s, 2ms +// n1 +// +// - all links are point-to-point links with indicated one-way BW/delay +// - CBR/UDP flows from n0 to n3, and from n3 to n1 +// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. +// (i.e., DataRate of 448,000 bps) +// - DropTail queues +// - Tracing of queues and packet receptions to file +// "simple-error-model.tr" + +#include "ns3/log.h" +#include "ns3/assert.h" +#include "ns3/command-line.h" +#include "ns3/default-value.h" +#include "ns3/ptr.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/default-value.h" +#include "ns3/component-manager.h" +#include "ns3/random-variable.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/point-to-point-net-device.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/point-to-point-topology.h" +#include "ns3/onoff-application.h" +#include "ns3/packet-sink.h" +#include "ns3/error-model.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample"); + +int +main (int argc, char *argv[]) +{ + // Users may find it convenient to turn on explicit debugging + // for selected modules; the below lines suggest how to do this +#if 0 + LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO); +#endif + + // Set up some default values for the simulation. Use the Bind() + // technique to tell the system what subclass of ErrorModel to use + DefaultValue::Bind ("ErrorModel", "RateErrorModel"); + // Set a few parameters + DefaultValue::Bind ("RateErrorModelErrorRate", "0.01"); + DefaultValue::Bind ("RateErrorModelErrorUnit", "EU_PKT"); + + DefaultValue::Bind ("OnOffApplicationPacketSize", "210"); + DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s"); + + + // Allow the user to override any of the defaults and the above + // Bind()s at run-time, via command-line arguments + 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 (); + + // 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)); + + Ptr channel1 = + PointToPointTopology::AddPointToPointLink ( + n1, n2, DataRate(5000000), MilliSeconds(2)); + + Ptr channel2 = + PointToPointTopology::AddPointToPointLink ( + 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")); + + PointToPointTopology::AddIpv4Addresses ( + channel1, n1, Ipv4Address("10.1.2.1"), + n2, Ipv4Address("10.1.2.2")); + + PointToPointTopology::AddIpv4Addresses ( + channel2, n2, Ipv4Address("10.1.3.1"), + n3, Ipv4Address("10.1.3.2")); + + // Finally, we add static routes. These three steps (Channel and + // 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_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_LOG_INFO ("Create Applications."); + uint16_t port = 9; // Discard port (RFC 863) + Ptr ooff = Create ( + n0, + InetSocketAddress ("10.1.3.2", 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 ( + n3, + InetSocketAddress (Ipv4Address::GetAny (), port), + "Udp"); + // Start the sink + sink->Start (Seconds (1.0)); + sink->Stop (Seconds (10.0)); + + // Create a similar flow from n3 to n1, starting at time 1.1 seconds + ooff = Create ( + n3, + InetSocketAddress ("10.1.2.1", port), + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); + + // Create a packet sink to receive these packets + sink = Create ( + n1, + InetSocketAddress (Ipv4Address::GetAny (), port), + "Udp"); + // Start the sink + sink->Start (Seconds (1.1)); + sink->Stop (Seconds (10.0)); + + // Here, finish off packet routing configuration + // This will likely set by some global StaticRouting object in the future + NS_LOG_INFO ("Set Default Routes."); + Ptr ipv4; + ipv4 = n0->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + ipv4 = n3->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + + // + // Error model + // + // We want to add an error model to node 3's NetDevice + // We can obtain a handle to the NetDevice via the channel and node + // pointers + Ptr nd3 = PointToPointTopology::GetNetDevice + (n3, channel2); + // Create an ErrorModel based on the implementation (constructor) + // specified by the default classId + Ptr em = ErrorModel::CreateDefault (); + NS_ASSERT (em != 0); + // Now, query interface on the resulting em pointer to see if a + // RateErrorModel interface exists. If so, set the packet error rate + Ptr bem = em->QueryInterface + (RateErrorModel::iid); + if (bem) + { + bem->SetRandomVariable (UniformVariable ()); + bem->SetRate (0.001); + } + nd3->AddReceiveErrorModel (em); + + // Now, let's use the ListErrorModel and explicitly force a loss + // of the packets with pkt-uids = 11 and 17 on node 2, device 0 + Ptr nd2 = PointToPointTopology::GetNetDevice + (n2, channel0); + std::list sampleList; + sampleList.push_back (11); + sampleList.push_back (17); + // This time, we'll explicitly create the error model we want + Ptr pem = Create (); + pem->SetList (sampleList); + nd2->AddReceiveErrorModel (pem); + + // Configure tracing of all enqueue, dequeue, and NetDevice receive events + // Trace output will be sent to the simple-error-model.tr file + NS_LOG_INFO ("Configure Tracing."); + AsciiTrace asciitrace ("simple-error-model.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + NS_LOG_INFO ("Run Simulation."); + Simulator::Run (); + Simulator::Destroy (); + NS_LOG_INFO ("Done."); +} diff --git a/examples/wscript b/examples/wscript index f597225fb..e458fa057 100644 --- a/examples/wscript +++ b/examples/wscript @@ -14,6 +14,10 @@ def build(bld): ['point-to-point', 'internet-node']) obj.source = 'simple-point-to-point.cc' + obj = bld.create_ns3_program('simple-error-model', + ['point-to-point', 'internet-node']) + obj.source = 'simple-error-model.cc' + obj = bld.create_ns3_program('csma-one-subnet', ['csma', 'internet-node']) obj.source = 'csma-one-subnet.cc' diff --git a/src/common/error-model.cc b/src/common/error-model.cc new file mode 100644 index 000000000..938cced29 --- /dev/null +++ b/src/common/error-model.cc @@ -0,0 +1,300 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Tom Henderson + * This code has been ported from ns-2 (queue/errmodel.{cc,h} + */ + +#include + +#include "error-model.h" + +#include "ns3/packet.h" +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/random-variable.h" +#include "ns3/default-value.h" + +NS_LOG_COMPONENT_DEFINE ("ErrorModel"); + +namespace ns3 { + +static ClassIdDefaultValue g_classIdErrorModelDefaultValue ("ErrorModel", + "Error Model", ErrorModel::iid, "RateErrorModel"); + +const InterfaceId ErrorModel::iid = + MakeInterfaceId ("ErrorModel", Object::iid); + +ErrorModel::ErrorModel () : + m_enable (true) +{ + NS_LOG_FUNCTION; + SetInterfaceId (ErrorModel::iid); +} + +ErrorModel::~ErrorModel () +{ + NS_LOG_FUNCTION; +} + +Ptr +ErrorModel::CreateDefault (void) +{ + NS_LOG_FUNCTION; + ClassId classId = g_classIdErrorModelDefaultValue.GetValue (); + Ptr em = ComponentManager::Create (classId, + ErrorModel::iid); + return em; +} + +bool +ErrorModel::IsCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + bool result; + // Insert any pre-conditions here + result = DoCorrupt (p); + // Insert any post-conditions here + return result; +} + +void +ErrorModel::Reset (void) +{ + NS_LOG_FUNCTION; + DoReset (); +} + +void +ErrorModel::Enable (void) +{ + NS_LOG_FUNCTION; + m_enable = true; +} + +void +ErrorModel::Disable (void) +{ + NS_LOG_FUNCTION; + m_enable = false; +} + +bool +ErrorModel::IsEnabled (void) const +{ + NS_LOG_FUNCTION; + return m_enable; +} + +// +// RateErrorModel +// + +const InterfaceId RateErrorModel::iid = + MakeInterfaceId ("RateErrorModel", ErrorModel::iid); + +const ClassId RateErrorModel::cid = + MakeClassId ("RateErrorModel", ErrorModel::iid, + RateErrorModel::iid); + +// Defaults for rate/size +static NumericDefaultValue g_defaultRateErrorModelErrorRate + ("RateErrorModelErrorRate", "The error rate for the error model", 0.0); + +static EnumDefaultValue + g_defaultRateErrorModelErrorUnit ("RateErrorModelErrorUnit", + "The error unit for this error model", + EU_BYTE, "EU_BYTE", + EU_PKT, "EU_PKT", + EU_BIT, "EU_BIT", + 0, (void*)0); + +RateErrorModel::RateErrorModel () : + m_unit (g_defaultRateErrorModelErrorUnit.GetValue() ), + m_rate (g_defaultRateErrorModelErrorRate.GetValue() ) +{ + NS_LOG_FUNCTION; + // Assume a uniform random variable if user does not specify + m_ranvar = new UniformVariable (); + SetInterfaceId (RateErrorModel::iid); +} + +RateErrorModel::~RateErrorModel () +{ + NS_LOG_FUNCTION; + delete m_ranvar; +} + +enum ErrorUnit +RateErrorModel::GetUnit (void) const +{ + NS_LOG_FUNCTION; + return m_unit; +} + +void +RateErrorModel::SetUnit (enum ErrorUnit error_unit) +{ + NS_LOG_FUNCTION; + m_unit = error_unit; +} + +double +RateErrorModel::GetRate (void) const +{ + NS_LOG_FUNCTION; + return m_rate; +} + +void +RateErrorModel::SetRate (double rate) +{ + NS_LOG_FUNCTION; + m_rate = rate; +} + +void +RateErrorModel::SetRandomVariable (const RandomVariable &ranvar) +{ + NS_LOG_FUNCTION; + delete m_ranvar; + m_ranvar = ranvar.Copy (); +} + +bool +RateErrorModel::DoCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + if (!m_enable) + { + return false; + } + switch (m_unit) + { + case EU_PKT: + return DoCorruptPkt (p); + case EU_BYTE: + return DoCorruptByte (p); + case EU_BIT: + return DoCorruptBit (p); + default: + NS_ASSERT_MSG (false, "m_unit not supported yet"); + break; + } + return false; +} + +bool +RateErrorModel::DoCorruptPkt (Packet& p) +{ + NS_LOG_FUNCTION; + return (m_ranvar->GetValue () < m_rate); +} + +bool +RateErrorModel::DoCorruptByte (Packet& p) +{ + NS_LOG_FUNCTION; + // compute pkt error rate, assume uniformly distributed byte error + double per = 1 - pow (1.0 - m_rate, p.GetSize ()); + return (m_ranvar->GetValue () < per); +} + +bool +RateErrorModel::DoCorruptBit(Packet& p) +{ + NS_LOG_FUNCTION; + // compute pkt error rate, assume uniformly distributed bit error + double per = 1 - pow (1.0 - m_rate, (8 * p.GetSize ()) ); + return (m_ranvar->GetValue () < per); +} + +void +RateErrorModel::DoReset (void) +{ + NS_LOG_FUNCTION; + /* re-initialize any state; no-op for now */ +} + +// +// ListErrorModel +// + +const InterfaceId ListErrorModel::iid = + MakeInterfaceId ("ListErrorModel", ErrorModel::iid); + +const ClassId ListErrorModel::cid = + MakeClassId ("ListErrorModel", ErrorModel::iid, + ListErrorModel::iid); + +ListErrorModel::ListErrorModel () +{ + NS_LOG_FUNCTION; + SetInterfaceId (ListErrorModel::iid); +} + +ListErrorModel::~ListErrorModel () +{ + NS_LOG_FUNCTION; +} + +std::list +ListErrorModel::GetList (void) const +{ + NS_LOG_FUNCTION; + return m_packetList; +} + +void +ListErrorModel::SetList (const std::list &packetlist) +{ + NS_LOG_FUNCTION; + m_packetList = packetlist; +} + +// When performance becomes a concern, the list provided could be +// converted to a dynamically-sized array of uint32_t to avoid +// list iteration below. +bool +ListErrorModel::DoCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + if (!m_enable) + { + return false; + } + uint32_t uid = p.GetUid (); + for (PacketListCI i = m_packetList.begin (); + i != m_packetList.end (); i++) + { + if (uid == *i) + { + return true; + } + } + return false; +} + +void +ListErrorModel::DoReset (void) +{ + NS_LOG_FUNCTION; + m_packetList.clear(); +} + + +} //namespace ns3 diff --git a/src/common/error-model.h b/src/common/error-model.h new file mode 100644 index 000000000..e386d2f94 --- /dev/null +++ b/src/common/error-model.h @@ -0,0 +1,236 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Tom Henderson + * This code has been ported from ns-2 (queue/errmodel.{cc,h} + */ +#ifndef ERROR_MODEL_H +#define ERROR_MODEL_H + +#include +#include "ns3/object.h" +#include "ns3/component-manager.h" + +namespace ns3 { + +class Packet; +class RandomVariable; + +/** + * \brief General error model that can be used to corrupt packets + * + * This object is used to flag packets as being lost/errored or not. + * It is part of the Object framework and can be aggregated to + * other ns3 objects and handled by the Ptr class. + * + * The main method is IsCorrupt(Packet& p) which returns true if + * the packet is to be corrupted according to the underlying model. + * Depending on the error model, the packet itself may have its packet + * data buffer errored or not, or side information may be returned to + * the client in the form of a packet tag. + * The object can have state (resettable by Reset()). + * The object can also be enabled and disabled via two public member functions. + * + * Typical code (simplified) to use an ErrorModel may look something like + * this: + * \code + * Ptr rem = Create (); + * rem->SetRandomVariable (UniformVariable ()); + * rem->SetRate (0.001); + * ... + * Packet p; + * if (rem->IsCorrupt (p)) + * { + * dropTrace(p); + * } else { + * Forward (p); + * } + * \endcode + * + * Two practical error models, a ListErrorModel and a RateErrorModel, + * are currently implemented. + */ +class ErrorModel : public Object +{ +public: + static const InterfaceId iid; + /** + * A factory method to generate a preconfigured default ErrorModel for use + * \return an ErrorModel smart pointer that is the default ErrorModel + * type defined + */ + static Ptr CreateDefault (void); + + ErrorModel (); + virtual ~ErrorModel (); + + /** + * \returns true if the Packet is to be considered as errored/corrupted + * \param pkt Packet to apply error model to + */ + bool IsCorrupt (Packet& pkt); + /** + * Reset any state associated with the error model + */ + void Reset (void); + /** + * Enable the error model + */ + void Enable (void); + /** + * Disable the error model + */ + void Disable (void); + /** + * \return true if error model is enabled; false otherwise + */ + bool IsEnabled (void) const; + +protected: + bool m_enable; + +private: + /* + * These methods must be implemented by subclasses + */ + virtual bool DoCorrupt (Packet&) = 0; + virtual void DoReset (void) = 0; + +}; + +enum ErrorUnit + { + EU_BIT, + EU_BYTE, + EU_PKT + }; + +/** + * \brief Determine which packets are errored corresponding to an underlying + * distribution, rate, and unit. + * + * This object is used to flag packets as being lost/errored or not. + * The two parameters that govern the behavior are the rate (or + * equivalently, the mean duration/spacing between errors), and the + * unit (which may be per-bit, per-byte, and per-packet). + * Users can optionally provide a RandomVariable object; the default + * is to use a Uniform(0,1) distribution. + + * Reset() on this model will do nothing + * + * IsCorrupt() will not modify the packet data buffer + */ +class RateErrorModel : public ErrorModel +{ +public: + static const InterfaceId iid; + static const ClassId cid; + + RateErrorModel (); + virtual ~RateErrorModel (); + + /** + * \returns the ErrorUnit being used by the underlying model + */ + enum ErrorUnit GetUnit (void) const; + /** + * \param error_unit the ErrorUnit to be used by the underlying model + */ + void SetUnit (enum ErrorUnit error_unit); + + /** + * \returns the error rate being applied by the model + */ + double GetRate (void) const; + /** + * \param rate the error rate to be used by the model + */ + void SetRate (double rate); + + /** + * \param ranvar A random variable distribution to generate random variates + */ + void SetRandomVariable (const RandomVariable &ranvar); + +private: + virtual bool DoCorrupt (Packet& p); + virtual bool DoCorruptPkt (Packet& p); + virtual bool DoCorruptByte (Packet& p); + virtual bool DoCorruptBit (Packet& p); + virtual void DoReset (void); + + enum ErrorUnit m_unit; + double m_rate; + + RandomVariable* m_ranvar; +}; + +/** + * \brief Provide a list of Packet uids to corrupt + * + * This object is used to flag packets as being lost/errored or not. + * A note on performance: the list is assumed to be unordered, and + * in general, Packet uids received may be unordered. Therefore, + * each call to IsCorrupt() will result in a walk of the list with + * the present underlying implementation. + * + * Note also that if one wants to target multiple packets from looking + * at an (unerrored) trace file, the act of erroring a given packet may + * cause subsequent packet uids to change. For instance, suppose one wants + * to error packets 11 and 17 on a given device. It may be that erroring + * packet 11 will cause the subsequent uid stream to change and 17 may no + * longer correspond to the second packet that one wants to lose. Therefore, + * be advised that it might take some trial and error to select the + * right uids when multiple are provided. + * + * Reset() on this model will clear the list + * + * IsCorrupt() will not modify the packet data buffer + */ +class ListErrorModel : public ErrorModel +{ +public: + static const InterfaceId iid; + static const ClassId cid; + ListErrorModel (); + virtual ~ListErrorModel (); + + /** + * \return a copy of the underlying list + */ + std::list GetList (void) const; + /** + * \param packetlist The list of packet uids to error. + * + * This method overwrites any previously provided list. + */ + void SetList (const std::list &packetlist); + +private: + virtual bool DoCorrupt (Packet& p); + virtual void DoReset (void); + + typedef std::list PacketList; + typedef std::list::const_iterator PacketListCI; + + PacketList m_packetList; + +}; + + +} //namespace ns3 +#endif diff --git a/src/common/wscript b/src/common/wscript index 2472ecd1e..30589542a 100644 --- a/src/common/wscript +++ b/src/common/wscript @@ -13,6 +13,7 @@ def build(bld): 'tag-registry.cc', 'pcap-writer.cc', 'data-rate.cc', + 'error-model.cc', ] headers = bld.create_obj('ns3header') @@ -29,4 +30,5 @@ def build(bld): 'packet-metadata.h', 'pcap-writer.h', 'data-rate.h', + 'error-model.h', ] diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index e4fd05a1b..903bb6cb6 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -28,6 +28,7 @@ #include "ns3/ethernet-header.h" #include "ns3/ethernet-trailer.h" #include "ns3/llc-snap-header.h" +#include "ns3/error-model.h" NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice"); @@ -82,7 +83,8 @@ CsmaTraceType::Get (void) const CsmaNetDevice::CsmaNetDevice (Ptr node) : NetDevice (node, Mac48Address::Allocate ()), - m_bps (DataRate (0xffffffff)) + m_bps (DataRate (0xffffffff)), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -93,7 +95,8 @@ CsmaNetDevice::CsmaNetDevice (Ptr node) CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, CsmaEncapsulationMode encapMode) : NetDevice(node, addr), - m_bps (DataRate (0xffffffff)) + m_bps (DataRate (0xffffffff)), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -531,6 +534,15 @@ CsmaNetDevice::AddQueue (Ptr q) m_queue = q; } +void CsmaNetDevice::AddReceiveErrorModel (Ptr em) +{ + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << em << ")"); + + m_receiveErrorModel = em; + AddInterface (em); +} + void CsmaNetDevice::Receive (const Packet& packet) { @@ -593,31 +605,41 @@ CsmaNetDevice::Receive (const Packet& packet) return; } - m_rxTrace (p); + if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) ) + { + NS_LOG_LOGIC ("Dropping pkt due to error model "); + m_dropTrace (packet); + // Do not forward up; let this packet go + } + else + { + m_rxTrace (p); // // protocol must be initialized to avoid a compiler warning in the RAW // case that breaks the optimized build. // - uint16_t protocol = 0; + uint16_t protocol = 0; - switch (m_encapMode) - { - case ETHERNET_V1: - case IP_ARP: - protocol = header.GetLengthType(); - break; - case LLC: { - LlcSnapHeader llc; - p.RemoveHeader (llc); - protocol = llc.GetType (); - } break; - case RAW: - NS_ASSERT (false); - break; + switch (m_encapMode) + { + case ETHERNET_V1: + case IP_ARP: + protocol = header.GetLengthType(); + break; + case LLC: + { + LlcSnapHeader llc; + p.RemoveHeader (llc); + protocol = llc.GetType (); + } + break; + case RAW: + NS_ASSERT (false); + break; + } + ForwardUp (p, protocol, header.GetSource ()); + return; } - - ForwardUp (p, protocol, header.GetSource ()); - return; } Address @@ -687,4 +709,5 @@ CsmaNetDevice::DoGetChannel(void) const return m_channel; } + } // namespace ns3 diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index bbe5259ed..1ce38d098 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -40,6 +40,7 @@ namespace ns3 { class Queue; class CsmaChannel; +class ErrorModel; /** * \brief hold in a TraceContext the type of trace source from a CsmaNetDevice @@ -192,6 +193,16 @@ enum CsmaEncapsulationMode { * ownership. */ void AddQueue (Ptr queue); + /** + * Attach a receive ErrorModel to the CsmaNetDevice. + * + * The CsmaNetDevice may optionally include an ErrorModel in + * the packet receive chain. + * + * @see ErrorModel + * @param em a pointer to the ErrorModel + */ + void AddReceiveErrorModel(Ptr em); /** * Receive a packet from a connected CsmaChannel. * @@ -453,6 +464,12 @@ private: * @see class DropTailQueue */ Ptr m_queue; + + /** + * Error model for receive packet events + */ + Ptr m_receiveErrorModel; + /** * NOT TESTED * The trace source for the packet reception events that the device can 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 ce3a253eb..66525b7a1 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 @@ -26,6 +26,7 @@ #include "ns3/composite-trace-resolver.h" #include "ns3/mac48-address.h" #include "ns3/llc-snap-header.h" +#include "ns3/error-model.h" #include "point-to-point-net-device.h" #include "point-to-point-channel.h" @@ -38,14 +39,28 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate( "The default data rate for point to point links", DataRate ("10Mb/s")); -PointToPointTraceType::PointToPointTraceType () +PointToPointTraceType::PointToPointTraceType (enum Type type) + : m_type (type) { NS_LOG_FUNCTION; } +PointToPointTraceType::PointToPointTraceType () + : m_type (RX) +{ + NS_LOG_FUNCTION; +} + void PointToPointTraceType::Print (std::ostream &os) const { - os << "dev-rx"; + switch (m_type) { + case RX: + os << "dev-rx"; + break; + case DROP: + os << "dev-drop"; + break; + } } uint16_t @@ -63,6 +78,12 @@ PointToPointTraceType::GetTypeName (void) const return "ns3::PointToPointTraceType"; } +enum PointToPointTraceType::Type +PointToPointTraceType::Get (void) const +{ + NS_LOG_FUNCTION; + return m_type; +} PointToPointNetDevice::PointToPointNetDevice (Ptr node, const DataRate& rate) @@ -73,7 +94,9 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node, m_tInterframeGap (Seconds(0)), m_channel (0), m_queue (0), - m_rxTrace () + m_rxTrace (), + m_dropTrace (), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -94,6 +117,7 @@ PointToPointNetDevice::~PointToPointNetDevice() { NS_LOG_FUNCTION; m_queue = 0; + m_receiveErrorModel = 0; } void @@ -221,7 +245,12 @@ PointToPointNetDevice::GetTraceResolver (void) const TraceDoc ("receive MAC packet", "const Packet &", "packet received"), m_rxTrace, - PointToPointTraceType ()); + PointToPointTraceType (PointToPointTraceType::RX)); + resolver->AddSource ("drop", + TraceDoc ("drop MAC packet", + "const Packet &", "packet dropped"), + m_dropTrace, + PointToPointTraceType (PointToPointTraceType::DROP)); resolver->SetParentResolver (NetDevice::GetTraceResolver ()); return resolver; } @@ -262,6 +291,15 @@ void PointToPointNetDevice::AddQueue (Ptr q) m_queue = q; } +void PointToPointNetDevice::AddReceiveErrorModel (Ptr em) +{ + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << em << ")"); + + m_receiveErrorModel = em; + AddInterface (em); +} + void PointToPointNetDevice::Receive (Packet& p) { NS_LOG_FUNCTION; @@ -269,9 +307,17 @@ void PointToPointNetDevice::Receive (Packet& p) uint16_t protocol = 0; Packet packet = p; - m_rxTrace (packet); - ProcessHeader(packet, protocol); - ForwardUp (packet, protocol, GetBroadcast ()); + if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) ) + { + m_dropTrace (packet); + // Do not forward up; let this packet go + } + else + { + m_rxTrace (packet); + ProcessHeader(packet, protocol); + ForwardUp (packet, protocol, GetBroadcast ()); + } } Ptr PointToPointNetDevice::GetQueue(void) const diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index b85a2a66b..e597773ad 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -37,6 +37,7 @@ namespace ns3 { class Queue; class PointToPointChannel; +class ErrorModel; /** * \brief hold in a TraceContext the type of trace source from a PointToPointNetDevice @@ -44,10 +45,21 @@ class PointToPointChannel; class PointToPointTraceType : public TraceContextElement { public: + enum Type { + RX, + DROP + }; + PointToPointTraceType (enum Type type); PointToPointTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); std::string GetTypeName (void) const; + /** + * \returns the type of the trace source which generated an event. + */ + enum Type Get (void) const; +private: + enum Type m_type; }; /** @@ -133,6 +145,16 @@ public: * ownership. */ void AddQueue (Ptr queue); + /** + * Attach a receive ErrorModel to the PointToPointNetDevice. + * + * The PointToPointNetDevice may optionally include an ErrorModel in + * the packet receive chain. + * + * @see ErrorModel + * @param em a pointer to the ErrorModel + */ + void AddReceiveErrorModel(Ptr em); /** * Receive a packet from a connected PointToPointChannel. * @@ -288,11 +310,23 @@ private: * @see class TraceResolver */ CallbackTraceSource m_rxTrace; + /** + * The trace source for the packet drop events that the device can + * fire. + * + * @see class CallBackTraceSource + * @see class TraceResolver + */ + CallbackTraceSource m_dropTrace; /** * Default data rate. Used for all newly created p2p net devices */ static DataRateDefaultValue g_defaultRate; + /** + * Error model for receive packet events + */ + Ptr m_receiveErrorModel; }; }; // namespace ns3 From f7e49cfb04c6f0c9a98051d5991c7e2758aca826 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 20:50:53 -0800 Subject: [PATCH 02/13] GetNetDevice method in PointToPointTopology class --- .../point-to-point/point-to-point-topology.cc | 24 +++++++++++++++++++ .../point-to-point/point-to-point-topology.h | 11 +++++++++ 2 files changed, 35 insertions(+) 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 7e0fd4efd..e6b10a82f 100644 --- a/src/devices/point-to-point/point-to-point-topology.cc +++ b/src/devices/point-to-point/point-to-point-topology.cc @@ -62,6 +62,30 @@ PointToPointTopology::AddPointToPointLink( return channel; } +Ptr +PointToPointTopology::GetNetDevice (Ptr n, Ptr chan) +{ + Ptr found = 0; + + // The PointToPoint channel is used to find the relevant NetDevice + NS_ASSERT (chan->GetNDevices () == 2); + Ptr nd1 = chan->GetDevice (0); + Ptr nd2 = chan->GetDevice (1); + if ( nd1->GetNode ()->GetId () == n->GetId () ) + { + found = nd1; + } + else if ( nd2->GetNode ()->GetId () == n->GetId () ) + { + found = nd2; + } + else + { + NS_ASSERT (found); + } + return found; +} + void PointToPointTopology::AddIpv4Addresses( Ptr chan, diff --git a/src/devices/point-to-point/point-to-point-topology.h b/src/devices/point-to-point/point-to-point-topology.h index 35a452269..29b0419a0 100644 --- a/src/devices/point-to-point/point-to-point-topology.h +++ b/src/devices/point-to-point/point-to-point-topology.h @@ -55,6 +55,17 @@ public: static Ptr AddPointToPointLink( Ptr n1, Ptr n2, const DataRate& dataRate, const Time& delay); + /** + * \param n Node + * \param chan PointToPointChannel connected to node n + * \return Pointer to the corresponding PointToPointNetDevice + * + * Utility function to retrieve a PointToPointNetDevice pointer + * corresponding to the input parameters + */ + static Ptr GetNetDevice( + Ptr n, Ptr chan); + /** * \param chan PointToPointChannel to use * \param n1 Node From 1b919575f2128dc76976fd6ccc99322344eec985 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 8 Nov 2007 22:31:54 -0800 Subject: [PATCH 03/13] fix bug 100 DefaultValue::Bind for floats --- src/core/default-value.cc | 2 +- src/core/default-value.h | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index 2acb6e97d..cd3ed23a0 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -381,7 +381,7 @@ DefaultValueTest::RunTests (void) DefaultValue::Bind ("test-c", "257"); NumericDefaultValue x ("test-x", "help-x", 10.0); NumericDefaultValue y ("test-y", "help-y", 10.0); - + DefaultValue::Bind ("test-y", "-3"); EnumDefaultValue e ("test-e", "help-e", MY_ENUM_C, "C", diff --git a/src/core/default-value.h b/src/core/default-value.h index 8d252ab45..f9caac9e4 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -219,6 +219,7 @@ private: virtual bool DoParseValue (const std::string &value); virtual std::string DoGetType (void) const; virtual std::string DoGetDefaultValue (void) const; + T RealMin (void) const; T m_defaultValue; T m_minValue; T m_maxValue; @@ -377,7 +378,7 @@ NumericDefaultValue::NumericDefaultValue (std::string name, T defaultValue) : DefaultValueBase (name, help), m_defaultValue (defaultValue), - m_minValue (std::numeric_limits::min ()), + m_minValue (RealMin ()), m_maxValue (std::numeric_limits::max ()), m_value (defaultValue) { @@ -469,6 +470,21 @@ NumericDefaultValue::DoGetDefaultValue (void) const return oss.str (); } +template +T +NumericDefaultValue::RealMin (void) const +{ + if (std::numeric_limits::is_integer) + { + return std::numeric_limits::min (); + } + else + { + return -std::numeric_limits::max (); + } +} + + /************************************************************** **************************************************************/ From 25d1f542d717748b1e723f8aa766962fcb2f5906 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:05:31 -0800 Subject: [PATCH 04/13] implement StringDefaultValue; bug93 patch from Mathieu --- src/core/default-value.cc | 80 +++++++++++++++++++++++++++++++++++++++ src/core/default-value.h | 36 ++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index cd3ed23a0..24814bf46 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -317,6 +317,86 @@ CommandDefaultValue::DoGetDefaultValue (void) const } +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (0), + m_maxSize (-1) +{ + DefaultValueList::Add (this); +} +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int maxSize) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (0), + m_maxSize (maxSize) +{ + DefaultValueList::Add (this); +} +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int minSize, + int maxSize) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (minSize), + m_maxSize (maxSize) +{ + DefaultValueList::Add (this); +} + + +std::string +StringDefaultValue::GetValue (void) const +{ + return m_value; +} + +bool +StringDefaultValue::DoParseValue (const std::string &value) +{ + if ((int)value.size () < m_minSize) + { + return false; + } + if (m_maxSize != -1 && (int)value.size () > m_maxSize) + { + return false; + } + m_value = value; + return true; +} +std::string +StringDefaultValue::DoGetType (void) const +{ + if (m_maxSize == -1) + { + return "string:0"; + } + else + { + std::ostringstream oss; + oss << "string:0:" << m_maxSize; + return oss.str (); + } +} +std::string +StringDefaultValue::DoGetDefaultValue (void) const +{ + return m_defaultValue; +} + + + }//namespace ns3 #ifdef RUN_SELF_TESTS diff --git a/src/core/default-value.h b/src/core/default-value.h index f9caac9e4..686b3ad94 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -340,6 +340,42 @@ public: T m_value; }; +/** + * \brief A string variable for ns3::Bind + * \ingroup config + * + * Every instance of this type is automatically + * registered in the variable pool which is used + * by ns3::Bind. + */ +class StringDefaultValue : public DefaultValueBase +{ +public: + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue); + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int maxSize); + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int minSize, + int maxSize); + + std::string GetValue (void) const; +private: + virtual bool DoParseValue (const std::string &value); + virtual std::string DoGetType (void) const; + virtual std::string DoGetDefaultValue (void) const; + + std::string m_defaultValue; + std::string m_value; + int m_minSize; + int m_maxSize; +}; + /** * \brief Class used to call a certain function during the configuration of the * simulation From baeee68d27e64a8c85c96547db55996c68f82ec9 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 5 Nov 2007 21:08:02 -0800 Subject: [PATCH 05/13] move ipv4 static to member functions --- src/node/ipv4.cc | 48 ++----------------- src/node/ipv4.h | 20 ++++---- .../global-route-manager-impl.cc | 2 +- 3 files changed, 14 insertions(+), 56 deletions(-) diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index f8a852149..b0e5f9349 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -36,13 +36,11 @@ Ipv4::~Ipv4 () {} uint32_t -Ipv4::GetIfIndexByAddress (Ptr node, Ipv4Address a, Ipv4Mask amask) +Ipv4::GetIfIndexByAddress (Ipv4Address addr, Ipv4Mask mask) { - Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "Ipv4::GetIfIndexByAddress: No Ipv4 interface"); - for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++) + for (uint32_t i = 0; i < GetNInterfaces (); i++) { - if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) ) + if (GetAddress (i).CombineMask(mask) == addr.CombineMask(mask) ) { return i; } @@ -52,44 +50,4 @@ Ipv4::GetIfIndexByAddress (Ptr node, Ipv4Address a, Ipv4Mask amask) return 0; } -// -// XXX BUGBUG I don't think this is really the right approach here. The call -// to GetRoute () filters down into Ipv4L3Protocol where it translates into -// a call into the Ipv4 static routing package. This bypasses any other -// routing packages. At a minimum, the name is misleading. -// -bool -Ipv4::GetRouteToDestination ( - Ptr node, - Ipv4Route& route, - Ipv4Address a, - Ipv4Mask amask) -{ - Ipv4Route tempRoute; - Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "Ipv4::GetRouteToDestination: No Ipv4 interface"); - for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++) - { - tempRoute = ipv4->GetRoute (i); - // Host route found - if ( tempRoute.IsNetwork () == false && tempRoute.GetDest () == a ) - { - route = tempRoute; - return true; - } - else if ( tempRoute.IsNetwork () && - tempRoute.GetDestNetwork () == a.CombineMask(amask) ) - { - route = tempRoute; - return true; - } - else if ( tempRoute.IsDefault () ) - { - route = tempRoute; - return true; - } - } - return false; -} - } // namespace ns3 diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 00f14f7ba..0cd1d129e 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -449,16 +449,16 @@ public: */ virtual void SetDown (uint32_t i) = 0; -/** - * Convenience functions (Doxygen still needed) - * - * Return the ifIndex corresponding to the Ipv4Address provided. - */ - static uint32_t GetIfIndexByAddress (Ptr node, Ipv4Address a, - Ipv4Mask amask = Ipv4Mask("255.255.255.255")); - - static bool GetRouteToDestination (Ptr node, Ipv4Route& route, - Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255")); + /** + * \brief Convenience function to return the ifIndex corresponding + * to the Ipv4Address provided + * + * \param addr Ipv4Address + * \param mask corresponding Ipv4Mask + * \returns ifIndex corresponding to a/amask + */ + virtual uint32_t GetIfIndexByAddress (Ipv4Address addr, + Ipv4Mask mask = Ipv4Mask("255.255.255.255")); }; } // namespace ns3 diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index ed61f7f5c..b666fcb8c 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -1172,7 +1172,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) // we're looking for. If we find one, return the corresponding interface // index. // - return (Ipv4::GetIfIndexByAddress (node, a, amask) ); + return (ipv4->GetIfIndexByAddress (a, amask) ); } } // From c114ad9aa746d97d311a5e12a7c6bb26d9d61c4a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 8 Nov 2007 23:08:00 -0800 Subject: [PATCH 06/13] minor fix for bug95; also const operators for DataRate --- src/common/data-rate.cc | 30 +++++++++++++++++++ src/common/data-rate.h | 6 ++++ src/devices/csma/csma-net-device.cc | 5 +++- .../point-to-point-net-device.cc | 5 +++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index 832fa98cb..a472d10c2 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -150,31 +150,61 @@ bool DataRate::operator < (const DataRate& rhs) return m_bps (const DataRate& rhs) { return m_bps>rhs.m_bps; } +bool DataRate::operator > (const DataRate& rhs) const +{ + return m_bps>rhs.m_bps; +} + bool DataRate::operator >= (const DataRate& rhs) { return m_bps>=rhs.m_bps; } +bool DataRate::operator >= (const DataRate& rhs) const +{ + return m_bps>=rhs.m_bps; +} + bool DataRate::operator == (const DataRate& rhs) { return m_bps==rhs.m_bps; } +bool DataRate::operator == (const DataRate& rhs) const +{ + return m_bps==rhs.m_bps; +} + bool DataRate::operator != (const DataRate& rhs) { return m_bps!=rhs.m_bps; } +bool DataRate::operator != (const DataRate& rhs) const +{ + return m_bps!=rhs.m_bps; +} + double DataRate::CalculateTxTime(uint32_t bytes) const { return static_cast(bytes)*8/m_bps; diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 1e5db50f9..1c1fb18d2 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -73,11 +73,17 @@ class DataRate DataRate (const std::string s); bool operator < (const DataRate& rhs); + bool operator < (const DataRate& rhs) const; bool operator <= (const DataRate& rhs); + bool operator <= (const DataRate& rhs) const; bool operator > (const DataRate& rhs); + bool operator > (const DataRate& rhs) const; bool operator >= (const DataRate& rhs); + bool operator >= (const DataRate& rhs) const; bool operator == (const DataRate& rhs); + bool operator == (const DataRate& rhs) const; bool operator != (const DataRate& rhs); + bool operator != (const DataRate& rhs) const; /** * \brief Calculate transmission time diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 903bb6cb6..b636bd097 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -198,7 +198,10 @@ void CsmaNetDevice::SetDataRate (DataRate bps) { NS_LOG_FUNCTION; - m_bps = bps; + if (!m_channel || bps <= m_channel->GetDataRate ()) + { + m_bps = bps; + } } void 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 66525b7a1..8d3478751 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 @@ -151,7 +151,10 @@ void PointToPointNetDevice::DoDispose() void PointToPointNetDevice::SetDataRate(const DataRate& bps) { NS_LOG_FUNCTION; - m_bps = bps; + if (!m_channel || bps <= m_channel->GetDataRate ()) + { + m_bps = bps; + } } void PointToPointNetDevice::SetInterframeGap(const Time& t) From 79f4bb679e4b70f958ce185a2e8a7b21e3ae77fe Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:17:43 -0800 Subject: [PATCH 07/13] get rid of non-const operators in DataRate --- src/common/data-rate.cc | 30 ------------------------------ src/common/data-rate.h | 6 ------ 2 files changed, 36 deletions(-) diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index a472d10c2..5e8358804 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -145,61 +145,31 @@ uint64_t DataRate::Parse(const std::string s) return v; } -bool DataRate::operator < (const DataRate& rhs) -{ - return m_bps (const DataRate& rhs) -{ - return m_bps>rhs.m_bps; -} - bool DataRate::operator > (const DataRate& rhs) const { return m_bps>rhs.m_bps; } -bool DataRate::operator >= (const DataRate& rhs) -{ - return m_bps>=rhs.m_bps; -} - bool DataRate::operator >= (const DataRate& rhs) const { return m_bps>=rhs.m_bps; } -bool DataRate::operator == (const DataRate& rhs) -{ - return m_bps==rhs.m_bps; -} - bool DataRate::operator == (const DataRate& rhs) const { return m_bps==rhs.m_bps; } -bool DataRate::operator != (const DataRate& rhs) -{ - return m_bps!=rhs.m_bps; -} - bool DataRate::operator != (const DataRate& rhs) const { return m_bps!=rhs.m_bps; diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 1c1fb18d2..3607f4916 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -72,17 +72,11 @@ class DataRate */ DataRate (const std::string s); - bool operator < (const DataRate& rhs); bool operator < (const DataRate& rhs) const; - bool operator <= (const DataRate& rhs); bool operator <= (const DataRate& rhs) const; - bool operator > (const DataRate& rhs); bool operator > (const DataRate& rhs) const; - bool operator >= (const DataRate& rhs); bool operator >= (const DataRate& rhs) const; - bool operator == (const DataRate& rhs); bool operator == (const DataRate& rhs) const; - bool operator != (const DataRate& rhs); bool operator != (const DataRate& rhs) const; /** From a53e880346dfa26ef60f7ae0b8492d2335e50586 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:29:27 -0800 Subject: [PATCH 08/13] Change default scheduler to Map from List (bug 90) --- src/simulator/scheduler-list.cc | 2 +- src/simulator/scheduler-map.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simulator/scheduler-list.cc b/src/simulator/scheduler-list.cc index 8fa57f473..191eb49b0 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/scheduler-list.cc @@ -32,7 +32,7 @@ static class SchedulerListFactory : public SchedulerFactory public: SchedulerListFactory () { - SchedulerFactory::AddDefault (this, "List"); + SchedulerFactory::Add (this, "List"); } private: virtual Scheduler *DoCreate (void) const diff --git a/src/simulator/scheduler-map.cc b/src/simulator/scheduler-map.cc index 5e20ff8d6..078167ec4 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/scheduler-map.cc @@ -43,7 +43,7 @@ static class SchedulerMapFactory : public SchedulerFactory public: SchedulerMapFactory () { - SchedulerFactory::Add (this, "Map"); + SchedulerFactory::AddDefault (this, "Map"); } private: virtual Scheduler *DoCreate (void) const From 2e68155c6da9a0640c38a4f31bbf5f08871e2513 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:59:14 -0800 Subject: [PATCH 09/13] nicer logging of parameters (bug 79 patch from Gustavo) --- samples/main-channel.cc | 8 +- src/applications/onoff/onoff-application.cc | 6 +- src/applications/udp-echo/udp-echo-client.cc | 12 +- src/applications/udp-echo/udp-echo-server.cc | 6 +- src/common/packet-metadata.cc | 4 +- src/core/log.cc | 5 + src/core/log.h | 108 +++++++++++++++++- src/devices/csma/csma-channel.cc | 22 ++-- src/devices/csma/csma-net-device.cc | 14 +-- .../point-to-point/point-to-point-channel.cc | 10 +- .../point-to-point-net-device.cc | 10 +- src/internet-node/arp-ipv4-interface.cc | 2 +- src/internet-node/ipv4-end-point-demux.cc | 20 ++-- src/internet-node/ipv4-interface.cc | 8 +- src/internet-node/ipv4-l3-protocol.cc | 85 ++++++-------- src/internet-node/ipv4-loopback-interface.cc | 2 +- src/internet-node/ipv4-static-routing.cc | 5 +- src/internet-node/udp-l4-protocol.cc | 17 ++- src/internet-node/udp-socket.cc | 14 +-- src/node/channel.cc | 4 +- src/node/drop-tail-queue.cc | 8 +- src/node/queue.cc | 8 +- src/routing/global-routing/candidate-queue.cc | 2 +- .../global-route-manager-impl.cc | 2 +- .../global-routing/global-router-interface.cc | 6 +- 25 files changed, 240 insertions(+), 148 deletions(-) diff --git a/samples/main-channel.cc b/samples/main-channel.cc index 99ceb04ec..025f1c3a8 100644 --- a/samples/main-channel.cc +++ b/samples/main-channel.cc @@ -73,7 +73,7 @@ FakeInternetNode::Doit (void) FakeInternetNode::UpperDoSendUp (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_INFO ("**** Receive inbound packet"); m_dtqInbound.Enqueue(p); return m_dtqInbound.Dequeue(p); @@ -83,7 +83,7 @@ FakeInternetNode::UpperDoSendUp (Packet &p) FakeInternetNode::UpperDoPull (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return m_dtqOutbound.Dequeue(p); } @@ -142,7 +142,7 @@ FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper) FakePhysicalLayer::UpperDoSendUp (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_ASSERT(m_upperPartner); return m_upperPartner->UpperSendUp(p); @@ -152,7 +152,7 @@ FakePhysicalLayer::UpperDoSendUp (Packet &p) FakePhysicalLayer::UpperDoPull (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return m_dtqOutbound.Dequeue(p); } diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 29f3d9d04..8fa315fc9 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -109,7 +109,7 @@ void OnOffApplication::SetMaxBytes(uint32_t maxBytes) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << maxBytes << ")"); + NS_LOG_PARAMS (this << maxBytes); m_maxBytes = maxBytes; } @@ -117,7 +117,7 @@ void OnOffApplication::SetDefaultRate (const DataRate &rate) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &rate << ")"); + NS_LOG_PARAMS (&rate); g_defaultRate.SetValue (rate); } @@ -125,7 +125,7 @@ void OnOffApplication::SetDefaultSize (uint32_t size) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << size << ")"); + NS_LOG_PARAMS (size); g_defaultSize.SetValue (size); } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index a5489ef2c..35a52e7b4 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -40,9 +40,8 @@ UdpEchoClient::UdpEchoClient ( Application(n) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << serverAddress << - ", " << serverPort << ", " << count << ", " << interval << - ", " << size << ")"); + NS_LOG_PARAMS (this << n << serverAddress << serverPort << count + << interval << size); Construct (n, serverAddress, serverPort, count, interval, size); } @@ -62,9 +61,8 @@ UdpEchoClient::Construct ( uint32_t size) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << serverAddress << - ", " << serverPort << ", " << count << ", " << interval << - ", " << size << ")"); + NS_LOG_PARAMS (this << n << serverAddress << serverPort + << count << interval << size); m_node = n; m_serverAddress = serverAddress; @@ -154,7 +152,7 @@ UdpEchoClient::Receive( const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); + NS_LOG_PARAMS (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 2538013cf..5d2d5b361 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -38,7 +38,7 @@ UdpEchoServer::UdpEchoServer ( Application(n) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << port << ")"); + NS_LOG_PARAMS (this << n << port); Construct (n, port); } @@ -54,7 +54,7 @@ UdpEchoServer::Construct ( uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << port << ")"); + NS_LOG_PARAMS (this << n << port); m_node = n; m_port = port; @@ -106,7 +106,7 @@ UdpEchoServer::Receive( const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); + NS_LOG_PARAMS (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index ebb5850ba..0f6541f75 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -703,7 +703,7 @@ PacketMetadata::DoAddHeader (uint32_t uid, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; item.next = m_head; @@ -723,7 +723,7 @@ PacketMetadata::DoRemoveHeader (uint32_t uid, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; struct PacketMetadata::ExtraItem extraItem; uint32_t read = ReadItems (m_head, &item, &extraItem); diff --git a/src/core/log.cc b/src/core/log.cc index de43712cf..0edf8eabd 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -341,6 +341,11 @@ LogComponentPrintList (void) } } + +ParameterLogger g_parameterLogger; +EndParameterListStruct EndParameterList; + + } // namespace ns3 #endif // NS3_LOG_ENABLE diff --git a/src/core/log.h b/src/core/log.h index d4cf9542e..7d12c3009 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -75,6 +75,7 @@ #endif + /** * \ingroup logging * \param msg message to output @@ -88,6 +89,84 @@ #ifdef NS3_LOG_ENABLE + +namespace ns3 { + +struct EndParameterListStruct {}; +extern EndParameterListStruct EndParameterList; + +struct ParameterName +{ + const char *name; + ParameterName (const char *name_) : name (name_) {} +}; + +class ParameterLogger : public std::ostream +{ + int m_itemNumber; + const char *m_parameterName; +public: + ParameterLogger () + : m_itemNumber (0) + {} + + template + ParameterLogger& operator<< (T param) + { + switch (m_itemNumber) + { + case 0: // first item is actually the function name + if (m_parameterName) + { + std::clog << m_parameterName << "=" << param; + m_parameterName = 0; + } + else + { + std::clog << param; + } + break; + case 1: + if (m_parameterName) + { + std::clog << ", " << m_parameterName << "=" << param; + m_parameterName = 0; + } + else + { + std::clog << ", " << param; + } + break; + default: // parameter following a previous parameter + std::clog << ", " << param; + break; + } + m_itemNumber++; + return *this; + } + + ParameterLogger& + operator << (ParameterName paramName) + { + m_parameterName = paramName.name; + return *this; + } + + ParameterLogger& + operator << (EndParameterListStruct dummy) + { + std::clog << ")" << std::endl; + m_itemNumber = 0; + return *this; + } +}; + +extern ParameterLogger g_parameterLogger; + +} + + + /** * \param level the log level * \param msg the message to log @@ -142,8 +221,33 @@ #define NS_LOG_FUNCTION \ NS_LOG_F(ns3::LOG_FUNCTION) -#define NS_LOG_PARAM(msg) \ - NS_LOG(ns3::LOG_PARAM, msg) + + +#define NS_LOG_PARAMS(parameters) \ + do \ + { \ + if (g_log.IsEnabled (ns3::LOG_PARAM)) \ + { \ + g_parameterLogger << __PRETTY_FUNCTION__ \ + << parameters \ + << EndParameterList; \ + } \ + } \ + while (false) + + +#define NS_LOG_PARAMS_BEGIN() \ + if (g_log.IsEnabled (ns3::LOG_PARAM)) \ + { \ + g_parameterLogger << __PRETTY_FUNCTION__; + +#define NS_LOG_PARAM(param) \ + g_parameterLogger << ParameterName (#param) << param; + +#define NS_LOG_PARAMS_END() \ + g_parameterLogger << EndParameterList; \ + } + #define NS_LOG_LOGIC(msg) \ NS_LOG(ns3::LOG_LOGIC, msg) diff --git a/src/devices/csma/csma-channel.cc b/src/devices/csma/csma-channel.cc index 598884104..63ca27ea7 100644 --- a/src/devices/csma/csma-channel.cc +++ b/src/devices/csma/csma-channel.cc @@ -68,8 +68,7 @@ CsmaChannel::CsmaChannel( m_delay (delay) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << - ", " << delay << ")"); + NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay); Init(); } @@ -83,8 +82,7 @@ CsmaChannel::CsmaChannel( m_delay (delay) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << delay << - ")"); + NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay); Init(); } @@ -97,7 +95,7 @@ int32_t CsmaChannel::Attach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); CsmaDeviceRec rec(device); @@ -110,7 +108,7 @@ bool CsmaChannel::Reattach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -136,7 +134,7 @@ bool CsmaChannel::Reattach(uint32_t deviceId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << deviceId << ")"); + NS_LOG_PARAMS (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -158,7 +156,7 @@ bool CsmaChannel::Detach(uint32_t deviceId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << deviceId << ")"); + NS_LOG_PARAMS (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -189,7 +187,7 @@ bool CsmaChannel::Detach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -208,7 +206,7 @@ bool CsmaChannel::TransmitStart(Packet& p, uint32_t srcId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << srcId << ")"); + NS_LOG_PARAMS (this << &p << srcId); NS_LOG_INFO ("UID is " << p.GetUid () << ")"); if (m_state != IDLE) @@ -240,7 +238,7 @@ bool CsmaChannel::TransmitEnd() { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &m_currentPkt << ", " << m_currentSrc << ")"); + NS_LOG_PARAMS (this << &m_currentPkt << m_currentSrc); NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == TRANSMITTING); @@ -266,7 +264,7 @@ void CsmaChannel::PropagationCompleteEvent() { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &m_currentPkt << ")"); + NS_LOG_PARAMS (this << &m_currentPkt); NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == PROPAGATING); diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index b636bd097..fef638271 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -87,7 +87,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node) m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = IP_ARP; Init(true, true); } @@ -99,7 +99,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = encapMode; Init(true, true); @@ -112,7 +112,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, m_bps (DataRate (0xffffffff)) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = encapMode; Init(sendEnable, receiveEnable); @@ -145,7 +145,7 @@ CsmaNetDevice& CsmaNetDevice::operator= (const CsmaNetDevice nd) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &nd << ")"); + NS_LOG_PARAMS (this << &nd); return *this; } */ @@ -513,7 +513,7 @@ bool CsmaNetDevice::Attach (Ptr ch) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ch << ")"); + NS_LOG_PARAMS (this << &ch); m_channel = ch; @@ -532,7 +532,7 @@ void CsmaNetDevice::AddQueue (Ptr q) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << q << ")"); + NS_LOG_PARAMS (this << q); m_queue = q; } @@ -649,7 +649,7 @@ Address CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << multicastGroup << ")"); + NS_LOG_PARAMS (this << multicastGroup); // // First, get the generic multicast address. // 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 d224a8df8..3760848fb 100644 --- a/src/devices/point-to-point/point-to-point-channel.cc +++ b/src/devices/point-to-point/point-to-point-channel.cc @@ -52,8 +52,7 @@ PointToPointChannel::PointToPointChannel( m_nDevices(0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << - ", " << delay << ")"); + NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay); } PointToPointChannel::PointToPointChannel( @@ -67,15 +66,14 @@ PointToPointChannel::PointToPointChannel( m_nDevices(0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << - delay << ")"); + NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay); } void PointToPointChannel::Attach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); NS_ASSERT(device != 0); @@ -99,7 +97,7 @@ PointToPointChannel::TransmitStart(Packet& p, const Time& txTime) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << src << ")"); + NS_LOG_PARAMS (this << &p << src); NS_LOG_LOGIC ("UID is " << p.GetUid () << ")"); NS_ASSERT(m_link[0].m_state != INITIALIZING); 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 8d3478751..e28b2350c 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 @@ -99,7 +99,7 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node, m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); // // XXX BUGBUG // @@ -201,7 +201,7 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, PointToPointNetDevice::TransmitStart (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_LOGIC ("UID is " << p.GetUid () << ")"); // // This function is called to start the process of transmitting a packet. @@ -262,7 +262,7 @@ bool PointToPointNetDevice::Attach (Ptr ch) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ch << ")"); + NS_LOG_PARAMS (this << &ch); m_channel = ch; @@ -289,7 +289,7 @@ PointToPointNetDevice::Attach (Ptr ch) void PointToPointNetDevice::AddQueue (Ptr q) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << q << ")"); + NS_LOG_PARAMS (this << q); m_queue = q; } @@ -306,7 +306,7 @@ void PointToPointNetDevice::AddReceiveErrorModel (Ptr em) void PointToPointNetDevice::Receive (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); uint16_t protocol = 0; Packet packet = p; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 8d80c5711..3dc95f5a4 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -64,7 +64,7 @@ void ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << dest << ")"); + NS_LOG_PARAMS (this << &p << dest); NS_ASSERT (GetDevice () != 0); if (GetDevice ()->NeedsArp ()) diff --git a/src/internet-node/ipv4-end-point-demux.cc b/src/internet-node/ipv4-end-point-demux.cc index 8ad8c6a3f..ddf64cc51 100644 --- a/src/internet-node/ipv4-end-point-demux.cc +++ b/src/internet-node/ipv4-end-point-demux.cc @@ -93,7 +93,7 @@ Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << this << ", " << address << ")"); + NS_LOG_PARAMS (this << address); uint16_t port = AllocateEphemeralPort (); if (port == 0) { @@ -117,7 +117,7 @@ Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << this << ", " << address << ", " << port << ")"); + NS_LOG_PARAMS (this << address << port); if (LookupLocal (address, port)) { NS_LOG_WARN ("Duplicate address/port; failing."); @@ -134,10 +134,7 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(localAddress=" << localAddress - << ", localPort=" << localPort - << ", peerAddress=" << peerAddress - << ", peerPort=" << peerPort << ")"); + NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if ((*i)->GetLocalPort () == localPort && @@ -189,8 +186,15 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, Ipv4EndPoint *generic = 0; EndPoints retval; - NS_LOG_PARAM ("(daddr=" << daddr << ", dport=" << dport - << ", saddr=" << saddr << ", sport=" << sport << ")"); + //NS_LOG_PARAMS (this << daddr << dport << saddr << sport); + NS_LOG_PARAMS_BEGIN (); + NS_LOG_PARAM (this); + NS_LOG_PARAM (daddr); + NS_LOG_PARAM (dport); + NS_LOG_PARAM (saddr); + NS_LOG_PARAM (sport); + NS_LOG_PARAM (incomingInterface); + NS_LOG_PARAMS_END (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index bcc346394..81e6bca65 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -41,7 +41,7 @@ Ipv4Interface::Ipv4Interface (Ptr nd) m_metric(1) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &nd << ")"); + NS_LOG_PARAMS (this << &nd); } Ipv4Interface::~Ipv4Interface () @@ -68,7 +68,7 @@ void Ipv4Interface::SetAddress (Ipv4Address a) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << a << ")"); + NS_LOG_PARAMS (this << a); m_address = a; } @@ -76,7 +76,7 @@ void Ipv4Interface::SetNetworkMask (Ipv4Mask mask) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << mask << ")"); + NS_LOG_PARAMS (this << mask); m_netmask = mask; } @@ -101,7 +101,7 @@ void Ipv4Interface::SetMetric (uint16_t metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << metric << ")"); + NS_LOG_PARAMS ("(" << metric << ")"); m_metric = metric; } diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 908a7bb99..367a03895 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -233,7 +233,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << dest << ", " << nextHop << ", " << interface << ")"); + NS_LOG_PARAMS (this << dest << nextHop << interface); m_staticRouting->AddHostRouteTo (dest, nextHop, interface); } @@ -242,7 +242,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << dest << ", " << interface << ")"); + NS_LOG_PARAMS (this << dest << interface); m_staticRouting->AddHostRouteTo (dest, interface); } @@ -253,8 +253,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << nextHop << - ", " << interface << ")"); + NS_LOG_PARAMS (this << network << networkMask << nextHop << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface); } @@ -264,8 +263,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << interface << - ")"); + NS_LOG_PARAMS (this << network << networkMask << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, interface); } @@ -274,7 +272,7 @@ Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << nextHop << ", " << interface << ")"); + NS_LOG_PARAMS (this << nextHop << interface); m_staticRouting->SetDefaultRoute (nextHop, interface); } @@ -285,7 +283,7 @@ Ipv4L3Protocol::Lookup ( Ipv4RoutingProtocol::RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ipHeader << ", " << &packet << &routeReply << ")"); + NS_LOG_PARAMS (this << &ipHeader << &packet << &routeReply); Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply); } @@ -298,8 +296,7 @@ Ipv4L3Protocol::Lookup ( Ipv4RoutingProtocol::RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << ", " << &ipHeader << ", " << &packet << - &routeReply << ")"); + NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply); for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin (); @@ -348,7 +345,7 @@ Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, int priority) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &routingProtocol << ", " << priority << ")"); + NS_LOG_PARAMS (this << &routingProtocol << priority); m_routingProtocols.push_back (std::pair > (-priority, routingProtocol)); m_routingProtocols.sort (); @@ -372,7 +369,7 @@ void Ipv4L3Protocol::RemoveRoute (uint32_t index) { NS_LOG_FUNCTION; - NS_LOG_PARAM("(" << index << ")"); + NS_LOG_PARAMS (this << index); m_staticRouting->RemoveRoute (index); } @@ -383,8 +380,7 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, std::vector outputInterfaces) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << - ", " << &outputInterfaces << ")"); + NS_LOG_PARAMS (this << origin << group << inputInterface << &outputInterfaces); m_staticRouting->AddMulticastRoute (origin, group, inputInterface, outputInterfaces); @@ -394,7 +390,7 @@ void Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << outputInterface << ")"); + NS_LOG_PARAMS (this << outputInterface); m_staticRouting->SetDefaultMulticastRoute (outputInterface); } @@ -410,7 +406,7 @@ Ipv4MulticastRoute * Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); return m_staticRouting->GetMulticastRoute (index); } @@ -420,8 +416,7 @@ Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin, uint32_t inputInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << - ")"); + NS_LOG_PARAMS (this << origin << group << inputInterface); m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface); } @@ -429,7 +424,7 @@ void Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); m_staticRouting->RemoveMulticastRoute (index); } @@ -437,7 +432,7 @@ uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ")"); + NS_LOG_PARAMS (this << &device); Ptr interface = Create (m_node, device); return AddIpv4Interface (interface); } @@ -446,7 +441,7 @@ uint32_t Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << interface << ")"); + NS_LOG_PARAMS (this << interface); uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; @@ -457,7 +452,7 @@ Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); uint32_t tmp = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { @@ -481,7 +476,7 @@ uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << addr << ")"); + NS_LOG_PARAMS (this << addr); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -503,7 +498,7 @@ uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << addr << ", " << mask << ")"); + NS_LOG_PARAMS (this << addr << mask); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -525,7 +520,7 @@ Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ")"); + NS_LOG_PARAMS (this << &device); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { if ((*i)->GetDevice () == device) @@ -540,8 +535,7 @@ void Ipv4L3Protocol::Receive( Ptr device, const Packet& p, uint16_t protocol, const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ", " << &p << ", " << protocol << ", " << - from << ")"); + NS_LOG_PARAMS (this << &device << &p << protocol << from); NS_LOG_LOGIC ("Packet from " << from); @@ -585,8 +579,7 @@ Ipv4L3Protocol::Send (Packet const &packet, uint8_t protocol) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << ", " << - destination << ", " << protocol << ")"); + NS_LOG_PARAMS (this << &packet << source << destination << protocol); Ipv4Header ipHeader; @@ -637,8 +630,7 @@ Ipv4L3Protocol::SendRealOut (bool found, Ipv4Header const &ipHeader) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << found << ", " << &route << ", " << &packet << - &ipHeader << ")"); + NS_LOG_PARAMS (this << found << &route << &packet << &ipHeader); if (!found) { @@ -673,8 +665,7 @@ Ipv4L3Protocol::Forwarding ( Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << ", " << &packet << ", " << &ipHeader << - ", " << device << ")"); + NS_LOG_PARAMS (ifIndex << &packet << &ipHeader<< device); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -751,7 +742,7 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip, Ptr incomingInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << &ip << ")"); + NS_LOG_PARAMS (this << &p << &ip); Ptr demux = m_node->QueryInterface (Ipv4L4Demux::iid); Ptr protocol = demux->GetProtocol (ip.GetProtocol ()); @@ -762,7 +753,7 @@ void Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ")"); + NS_LOG_PARAMS (this << origin << group); m_multicastGroups.push_back( std::pair (origin, group)); } @@ -771,7 +762,7 @@ void Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ")"); + NS_LOG_PARAMS (this << origin << group); for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin (); i != m_multicastGroups.end (); @@ -789,7 +780,7 @@ void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << address << ")"); + NS_LOG_PARAMS (this << i << address); Ptr interface = GetInterface (i); interface->SetAddress (address); } @@ -798,7 +789,7 @@ void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << mask << ")"); + NS_LOG_PARAMS (this << i << mask); Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } @@ -807,7 +798,7 @@ Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } @@ -816,7 +807,7 @@ Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetAddress (); } @@ -825,7 +816,7 @@ void Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << metric << ")"); + NS_LOG_PARAMS ("(" << i << ", " << metric << ")"); Ptr interface = GetInterface (i); interface->SetMetric (metric); } @@ -834,7 +825,7 @@ uint16_t Ipv4L3Protocol::GetMetric (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS ("(" << i << ")"); Ptr interface = GetInterface (i); return interface->GetMetric (); } @@ -844,7 +835,7 @@ Ipv4L3Protocol::GetIfIndexForDestination ( Ipv4Address destination, uint32_t& ifIndex) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")"); + NS_LOG_PARAMS (this << 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 @@ -911,7 +902,7 @@ uint16_t Ipv4L3Protocol::GetMtu (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetMtu (); } @@ -920,7 +911,7 @@ bool Ipv4L3Protocol::IsUp (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->IsUp (); } @@ -929,7 +920,7 @@ void Ipv4L3Protocol::SetUp (uint32_t i) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); interface->SetUp (); @@ -948,7 +939,7 @@ void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifaceIndex << ")"); + NS_LOG_PARAMS (this << ifaceIndex); Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index eb59a662d..30f18ad9e 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -47,7 +47,7 @@ void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << dest << ")"); + NS_LOG_PARAMS (this << &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 6b7d8671d..8636631d8 100644 --- a/src/internet-node/ipv4-static-routing.cc +++ b/src/internet-node/ipv4-static-routing.cc @@ -522,8 +522,7 @@ Ipv4StaticRouting::RequestRoute ( RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << &ipHeader << ", " << &packet << ", " << - &routeReply << ")"); + NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply); NS_LOG_LOGIC ("source = " << ipHeader.GetSource ()); @@ -576,7 +575,7 @@ bool Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")"); + NS_LOG_PARAMS (this << 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. diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index cbf8cbf52..cd7246536 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -83,7 +83,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ")"); + NS_LOG_PARAMS (this << address); return m_endPoints->Allocate (address); } @@ -91,7 +91,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << port << ")"); + NS_LOG_PARAMS (this << port); return m_endPoints->Allocate (port); } @@ -99,7 +99,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ", " << port << ")"); + NS_LOG_PARAMS (this << address << port); return m_endPoints->Allocate (address, port); } Ipv4EndPoint * @@ -107,8 +107,7 @@ UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << localAddress << ", " << localPort << ", " << - peerAddress << ", " << peerPort << ")"); + NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); return m_endPoints->Allocate (localAddress, localPort, peerAddress, peerPort); } @@ -117,7 +116,7 @@ void UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << endPoint << ")"); + NS_LOG_PARAMS (this << endPoint); m_endPoints->DeAllocate (endPoint); } @@ -128,8 +127,7 @@ UdpL4Protocol::Receive(Packet& packet, Ptr interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination << - ")"); + NS_LOG_PARAMS (this << &packet << source << destination); UdpHeader udpHeader; packet.RemoveHeader (udpHeader); @@ -149,8 +147,7 @@ UdpL4Protocol::Send (Packet packet, uint16_t sport, uint16_t dport) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << saddr << ", " << daddr << ", " << - sport << ", " << dport << ")"); + NS_LOG_PARAMS (this << &packet << saddr << daddr << sport << dport); UdpHeader udpHeader; udpHeader.SetDestination (dport); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index d6c968d80..ff695cbfd 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -117,7 +117,7 @@ int UdpSocket::Bind (const Address &address) { NS_LOG_FUNCTION; - NS_LOG_PARAM("(" << address << ")"); + NS_LOG_PARAMS (this << address); if (!InetSocketAddress::IsMatchingType (address)) { @@ -175,7 +175,7 @@ int UdpSocket::Connect(const Address & address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ")"); + NS_LOG_PARAMS (this << address); Ipv4Route routeToDest; InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = transport.GetIpv4 (); @@ -190,7 +190,7 @@ int UdpSocket::Send (const Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (!m_connected) { @@ -226,7 +226,7 @@ int UdpSocket::DoSendTo (const Packet &p, const Address &address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << address << ")"); + NS_LOG_PARAMS (this << &p << address); if (!m_connected) { @@ -248,7 +248,7 @@ int UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << dest << ", " << port << ")"); + NS_LOG_PARAMS (this << &p << dest << port); Ipv4Route routeToDest; @@ -308,7 +308,7 @@ int UdpSocket::SendTo(const Address &address, const Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ", " << &p << ")"); + NS_LOG_PARAMS (this << address << &p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); @@ -319,7 +319,7 @@ void UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << ipv4 << ", " << port << ")"); + NS_LOG_PARAMS (this << &packet << ipv4 << port); if (m_shutdownRecv) { diff --git a/src/node/channel.cc b/src/node/channel.cc index b571e6123..740b8edec 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -37,7 +37,7 @@ Channel::Channel (std::string name) : m_name(name) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ")"); + NS_LOG_PARAMS (this << name); SetInterfaceId (Channel::iid); } @@ -50,7 +50,7 @@ Channel::~Channel () Channel::SetName(std::string name) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ")"); + NS_LOG_PARAMS (this << name); m_name = name; } diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 8b5ceea79..a4fb979bb 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -45,7 +45,7 @@ void DropTailQueue::SetMaxPackets (uint32_t npackets) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << npackets << ")"); + NS_LOG_PARAMS (this << npackets); m_maxPackets = npackets; } @@ -61,7 +61,7 @@ bool DropTailQueue::DoEnqueue (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.size () >= m_maxPackets) { @@ -78,7 +78,7 @@ bool DropTailQueue::DoDequeue (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.empty()) { @@ -98,7 +98,7 @@ bool DropTailQueue::DoPeek (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.empty()) { diff --git a/src/node/queue.cc b/src/node/queue.cc index 4a622c2b0..ab7f8f894 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -139,7 +139,7 @@ bool Queue::Enqueue (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_LOGIC ("m_traceEnqueue (p)"); m_traceEnqueue (p); @@ -157,7 +157,7 @@ bool Queue::Dequeue (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); bool retval = DoDequeue (p); @@ -189,7 +189,7 @@ bool Queue::Peek (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return DoPeek (p); } @@ -264,7 +264,7 @@ void Queue::Drop (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); m_nTotalDroppedPackets++; m_nTotalDroppedBytes += p.GetSize (); diff --git a/src/routing/global-routing/candidate-queue.cc b/src/routing/global-routing/candidate-queue.cc index e6d3b552e..403c2e9b7 100644 --- a/src/routing/global-routing/candidate-queue.cc +++ b/src/routing/global-routing/candidate-queue.cc @@ -52,7 +52,7 @@ CandidateQueue::Clear (void) CandidateQueue::Push (SPFVertex *vNew) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << vNew << ")"); + NS_LOG_PARAMS (this << vNew); CandidateList_t::iterator i = m_candidates.begin (); diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index b666fcb8c..57a17f828 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -975,7 +975,7 @@ GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << root << ")"); + NS_LOG_PARAMS (this << root); SPFVertex *v; // diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index ee49733c1..9ade5d010 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -58,8 +58,7 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( m_metric (metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << linkType << ", " << linkId << ", " << linkData << - ", " << metric << ")"); + NS_LOG_PARAMS (this << linkType << linkId << linkData << metric); } GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord () @@ -157,8 +156,7 @@ GlobalRoutingLSA::GlobalRoutingLSA ( m_status(status) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << status << ", " << linkStateId << ", " << - advertisingRtr << ")"); + NS_LOG_PARAMS (this << status << linkStateId << advertisingRtr); } GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) From c1544ba7c4791594243c2155d019418a95b09adb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:15:16 +0100 Subject: [PATCH 10/13] check for Time bounds --- src/simulator/time.cc | 74 ++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/src/simulator/time.cc b/src/simulator/time.cc index a58a54925..e4a41dd9a 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -354,62 +354,62 @@ TimeTests::~TimeTests () bool TimeTests::RunTests (void) { - bool ok = true; + bool result = true; Time t0, t1; - CheckOld(&ok); + CheckOld(&result); t0 = MilliSeconds ((uint64_t)10.0); t1 = MilliSeconds ((uint64_t)11.0); - CheckOperations(t0, t1, &ok); + CheckOperations(t0, t1, &result); // t0 = Seconds ((uint64_t)10.0); // t1 = Seconds ((uint64_t)11.0); - // CheckOperations(t0, t1, &ok); + // CheckOperations(t0, t1, &result); - CheckConversions((uint64_t)5, &ok); - CheckConversions((uint64_t)0, &ok); - CheckConversions((uint64_t)783, &ok); - CheckConversions((uint64_t)1132, &ok); - // CheckConversions((uint64_t)3341039, &ok); + CheckConversions((uint64_t)5, &result); + CheckConversions((uint64_t)0, &result); + CheckConversions((uint64_t)783, &result); + CheckConversions((uint64_t)1132, &result); + // CheckConversions((uint64_t)3341039, &result); // Now vary the precision and check the conversions if (TimeStepPrecision::Get () != TimeStepPrecision::NS) { - ok = false; + result = false; } - CheckPrecision(TimeStepPrecision::US, 7, &ok); + CheckPrecision(TimeStepPrecision::US, 7, &result); - CheckConversions((uint64_t)7, &ok); - CheckConversions((uint64_t)546, &ok); - CheckConversions((uint64_t)6231, &ok); - // CheckConversions((uint64_t)1234639, &ok); + CheckConversions((uint64_t)7, &result); + CheckConversions((uint64_t)546, &result); + CheckConversions((uint64_t)6231, &result); + // CheckConversions((uint64_t)1234639, &result); - CheckPrecision(TimeStepPrecision::MS, 3, &ok); + CheckPrecision(TimeStepPrecision::MS, 3, &result); - CheckConversions((uint64_t)3, &ok); - CheckConversions((uint64_t)134, &ok); - CheckConversions((uint64_t)2341, &ok); - // CheckConversions((uint64_t)8956239, &ok); + CheckConversions((uint64_t)3, &result); + CheckConversions((uint64_t)134, &result); + CheckConversions((uint64_t)2341, &result); + // CheckConversions((uint64_t)8956239, &result); - CheckPrecision(TimeStepPrecision::PS, 21, &ok); + CheckPrecision(TimeStepPrecision::PS, 21, &result); - CheckConversions((uint64_t)4, &ok); - CheckConversions((uint64_t)342, &ok); - CheckConversions((uint64_t)1327, &ok); - // CheckConversions((uint64_t)5439627, &ok); + CheckConversions((uint64_t)4, &result); + CheckConversions((uint64_t)342, &result); + CheckConversions((uint64_t)1327, &result); + // CheckConversions((uint64_t)5439627, &result); - CheckPrecision(TimeStepPrecision::NS, 12, &ok); - CheckConversions((uint64_t)12, &ok); + CheckPrecision(TimeStepPrecision::NS, 12, &result); + CheckConversions((uint64_t)12, &result); - CheckPrecision(TimeStepPrecision::S, 7, &ok); - CheckConversions((uint64_t)7, &ok); + CheckPrecision(TimeStepPrecision::S, 7, &result); + CheckConversions((uint64_t)7, &result); - CheckPrecision(TimeStepPrecision::FS, 5, &ok); - CheckConversions((uint64_t)5, &ok); + CheckPrecision(TimeStepPrecision::FS, 5, &result); + CheckConversions((uint64_t)5, &result); TimeStepPrecision::Set (TimeStepPrecision::NS); @@ -420,7 +420,17 @@ bool TimeTests::RunTests (void) DefaultValue::Bind ("TimeStepPrecision", "PS"); DefaultValue::Bind ("TimeStepPrecision", "FS"); - return ok; + + Time tooBig = TimeStep (0x8000000000000000LL); + NS_TEST_ASSERT (tooBig.IsNegative ()); + tooBig = TimeStep (0xffffffffffffffffLL); + NS_TEST_ASSERT (tooBig.IsNegative ()); + tooBig = TimeStep (0x7fffffffffffffffLL); + NS_TEST_ASSERT (tooBig.IsPositive ()); + tooBig += TimeStep (1); + NS_TEST_ASSERT (tooBig.IsNegative ()); + + return result; } void TimeTests::CheckOld (bool *ok) From 587d573a0437c6a99204a1438eab1aed2bd47419 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 10:16:26 +0000 Subject: [PATCH 11/13] Add some missing NS_LOG_PARAM* definitions in optimized build --- src/core/log.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/log.h b/src/core/log.h index 7d12c3009..72c429bda 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -268,7 +268,10 @@ extern ParameterLogger g_parameterLogger; #define NS_LOG_DEBUG(msg) #define NS_LOG_INFO(msg) #define NS_LOG_FUNCTION -#define NS_LOG_PARAM(msg) +#define NS_LOG_PARAMS(parameters) +#define NS_LOG_PARAMS_BEGIN() +#define NS_LOG_PARAM(param) +#define NS_LOG_PARAMS_END() #define NS_LOG_LOGIC(msg) #define NS_LOG_UNCOND(msg) From fc099a35ab7c8dd054d79661611f82787ba6cd00 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 15:42:07 +0000 Subject: [PATCH 12/13] Add DropTailQueue unit tests. --- src/node/drop-tail-queue.cc | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index a4fb979bb..7b88231ab 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -111,4 +111,69 @@ DropTailQueue::DoPeek (Packet& p) return true; } +} // namespace ns3 + + +#ifdef RUN_SELF_TESTS + +#include "ns3/test.h" + +namespace ns3 { + +class DropTailQueueTest: public Test { +public: + virtual bool RunTests (void); + DropTailQueueTest (); +}; + + +DropTailQueueTest::DropTailQueueTest () + : Test ("DropTailQueue") {} + + +bool +DropTailQueueTest::RunTests (void) +{ + bool result = true; + + DropTailQueue queue; + queue.SetMaxPackets (3); + + Packet p1, p2, p3, p4; + + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0); + queue.Enqueue (p1); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1); + queue.Enqueue (p2); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2); + queue.Enqueue (p3); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3); + queue.Enqueue (p4); // will be dropped + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3); + + Packet p; + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p1.GetUid ()); + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p2.GetUid ()); + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p3.GetUid ()); + + NS_TEST_ASSERT (!queue.Dequeue (p)); + + return result; +} + + +static DropTailQueueTest gDropTailQueueTest; + }; // namespace ns3 + +#endif /* RUN_SELF_TESTS */ + From 11a58a55c367a68b969eff96aa76e57b4883799c Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 16:08:28 +0000 Subject: [PATCH 13/13] Add a few NS_LOG_LOGIC calls in PacketSocket::SendTo () --- src/node/packet-socket.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 448b84334..000d95966 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -222,22 +222,26 @@ PacketSocket::SendTo(const Address &address, const Packet &p) PacketSocketAddress ad; if (m_state == STATE_CLOSED) { + NS_LOG_LOGIC ("ERROR_BADF"); m_errno = ERROR_BADF; return -1; } if (m_state == STATE_OPEN) { // XXX should return another error here. + NS_LOG_LOGIC ("ERROR_INVAL"); m_errno = ERROR_INVAL; return -1; } if (m_shutdownSend) { + NS_LOG_LOGIC ("ERROR_SHUTDOWN"); m_errno = ERROR_SHUTDOWN; return -1; } if (!PacketSocketAddress::IsMatchingType (address)) { + NS_LOG_LOGIC ("ERROR_AFNOSUPPORT"); m_errno = ERROR_AFNOSUPPORT; return -1; } @@ -250,6 +254,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); if (!device->Send (p, dest, ad.GetProtocol ())) { + NS_LOG_LOGIC ("error: NetDevice::Send error"); error = true; } } @@ -260,6 +265,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) Ptr device = m_node->GetDevice (i); if (!device->Send (p, dest, ad.GetProtocol ())) { + NS_LOG_LOGIC ("error: NetDevice::Send error"); error = true; } } @@ -271,6 +277,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) if (error) { + NS_LOG_LOGIC ("ERROR_INVAL 2"); m_errno = ERROR_INVAL; return -1; }