diff --git a/doc/doxygen.conf b/doc/doxygen.conf index c75378433..b4d10dab9 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -496,7 +496,6 @@ WARN_LOGFILE = INPUT = doc/modules \ doc/main.h \ doc/introspected-doxygen.h \ - doc/tracing.h \ doc/howtos/ \ src @@ -1047,13 +1046,13 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. -EXPAND_ONLY_PREDEF = NO +EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. @@ -1090,7 +1089,9 @@ PREDEFINED = RUN_SELF_TESTS \ # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = ATTRIBUTE_VALUE_DEFINE \ + ATTRIBUTE_VALUE_DEFINE_WITH_NAME \ + ATTRIBUTE_HELPER_HEADER_2 # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all function-like macros that are alone diff --git a/doc/modules b/doc/modules index 94d46635c..2f55fff30 100644 --- a/doc/modules +++ b/doc/modules @@ -15,12 +15,13 @@ * - a class to register regression tests with the test manager: ns3::Test and ns3::TestManager * - debugging facilities: \ref logging, \ref assert, \ref error * - \ref randomvariable + * - a base class for objects which need to support per-instance "attributes" and + * trace sources: ns3::ObjectBase * - a base class for objects which need to support reference counting - * and QueryInterface: ns3::Object and ns3::InterfaceId - * - a set of low-level trace facilities integrated in the ns3::Object system: \ref tracing - * - a ns3::ComponentManager which can be used to manage the creation - * of any object which derives from ns3::Object through an ns3::ClassId + * and dynamic object aggregation: ns3::Object * - a smart-pointer class ns3::Ptr designed to work together with ns3::Object + * - a configuration class used to set and control all attributes and trace sources + * in a simulation: ns3::Config. * * @defgroup common Common * The "core" module contains: @@ -61,5 +62,4 @@ * @brief Constants you can change * * @defgroup contrib Contrib - */ - + */ \ No newline at end of file diff --git a/doc/tracing.h b/doc/tracing.h deleted file mode 100644 index aa15d9401..000000000 --- a/doc/tracing.h +++ /dev/null @@ -1,584 +0,0 @@ -/** - * \ingroup core - * \defgroup TraceSourceList List of trace sources - */ - -/** - * \ingroup core - * \defgroup tracing Tracing - * - * The flexibility of the ns-3 tracing system comes at the cost of quite - * a bit of complexity so, before trying to use the low-level aspects - * of the tracing API, it is important to focus on some basic definitions: - * - * - A trace source is an object instance which can report trace events - * to a set of listening trace sinks. - * - * - A trace sink is a user-provided callback (a function) which can - * be connected to a set of trace sources to receive the events generated - * by each trace source. - * - * - A trace resolver is an object which allows users to establish - * connections between a set of trace sources and a set of trace sinks. - * - * \section TraceSource Generating Trace Events - * - * So, what does it look like in practice ? First, let's look at trace - * sources. We have two types of trace sources: numeric, and, normal - * trace sources. Numeric trace sources behave as normal c++ integers - * or c++ floating point numbers except that they report as trace events - * each change of their value. For example: - * \code - * class MyModel - * { - * public: - * void DoSomething (void) - * { - * // use the "int" trace source just - * // like any other "int" variable. - * m_cwnd *= 2; - * m_cwnd += 4; - * if (m_cwnd > 100) - * { - * // do something. - * } - * } - * private: - * // declare an instance of a "int" trace source - * SVTraceSource m_cwnd; - * }; - * \endcode - * Normal trace sources, on the other hand, allow you to trace the - * call of arbitrary functions and methods, as shown below. They are - * typically used to track "rx", "tx", or "drop" events but could - * also be used to track route change events, or position change - * events: - * \code - * class MyModel - * { - * public: - * void DoSomething (Ptr packet) - * { - * // report this event on packet - * m_doSomething (packet); - * // do something - * } - * private: - * // report every "something" function call. - * CallbackTraceSource > m_doSomething; - * }; - * \endcode - * Every type of trace source derives from the ns3::TraceSource base class. - * As of today, the set of concrete subclasses is relatively short: - * ns3::CallbackTraceSource, ns3::SvTraceSource, ns3::UvTraceSource, and, - * ns3::FvTraceSource. - * - * \section TraceSink Receiving Trace Events - * - * To receive these trace events, a user should specify a set of trace sinks. - * For example, to receive the "int" and the "something" events shown in the - * examples above, a user would declare the following functions: - * \code - * // oldValue and newValue contain the previous and new values of - * // the connected SVTraceSource trace source. - * void - * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue) - * { - * // for example, print the new value: - * std::cout << "cwnd=" << newValue << std::endl; - * } - * void - * DoSomethingTraceSink (const TraceContext &context, Ptr packet) - * { - * // for example, print the packet - * std::cout << "packet " << packet->Print () << std::endl; - * } - * \endcode - * Each of these sink function takes, as a first argument, a reference to a - * const TraceContext object. This context object contains information which - * describes the instance of the connected trace source: that information is - * setup during the connection process and does not change afterwards - * The type and the number of the other arguments to each trace sink depends - * on the type of the connected trace source: it conveys per-event information - * from the trace source to the trace sink. For example, UVTraceSource and - * SVTraceSource trace sources require two extra arguments. The former requires - * two unsigned 64 bit integers while the latter requires two signed 64 bit - * integers. More generally, users can consult the \ref TraceSourceList - * to figure out the arguments which a trace sink is required to receive - * for each trace source: a signature of the user trace sink must match - * _exactly_ the signature documented in the \ref TraceSourceList. - * - * - * \section TraceSourceSimpleExport A simple way to connect Trace Sources with Trace Sinks - * - * The crux of the complexity of the ns-3 tracing system comes from its - * flexible system used to connect trace sources to trace sinks but what is really - * nice about it is that it is not necessary to use it to setup simple traces. - * - * The simplest way to export a set of trace sources to a user, for example, - * during the early prototyping phases of a system, is to add a set of public methods - * to give to your users access to the trace source object instances you use to generate - * trace events: - * \code - * class MyModel - * { - * public: - * void DoSomething (Ptr packet) - * { - * // report this event on packet - * m_doSomething (packet); - * // do something - * } - * CallbackTraceSource> *PeekSomethingTraceSource (void) const - * { - * return &m_doSomething - * } - * private: - * // report every "something" function call. - * CallbackTraceSource> m_doSomething; - * }; - * \endcode - * If your users hold a pointer to an instance of MyModel, and if they want to connect - * a MySomethingSink, they can simply do the following which invokes the - * TraceSource::AddCallback method and creates a Callback object from the user's - * sink with the MakeCallback function. - * \code - * void - * MySomethingSink (const TraceContext &context, Ptr packet) - * { - * // do whatever you want. - * } - * MyModel *model = ...; - * CallbackTraceSource> *source = model->PeekSomethingTraceSource (); - * source->AddCallback (MakeCallback (&MySomethingSink)); - * \endcode - * - * The full power of the tracing system comes however from its ns3::NodeList::Connect - * method which is described in the following sections. - * - * \section TraceConnection Connecting Trace Sources to Trace Sinks - * - * If a trace source is integrated in the ns-3 trace connection facility, a user - * should call the ns3::NodeList::ConnectWithoutContext method to establish a connection between - * a trace sink and a set of matching trace sources. The second argument to that - * method is a callback to the user's trace sink. - * That callback is easy to construct: call ns3::MakeCallback and you are done. The - * first argument is a string whose format is similar to a unix path and which is - * used to uniquely identify the set of trace sources you want to connect to. - * The set of acceptable path strings is also documented in the \ref TraceSourceList. - * - * So, what does this look like from the perspective of a user ? If we wanted to - * connect to a trace source defined somewhere deep into the a set of NetDevice objects - * located in some nodes of the system, we could write the following: - * \code - * void - * DoSomethingTraceSink (const TraceContext &context, Ptr packet) - * { - * // for example, print the packet - * std::cout << "packet: " << packet->Print () << std::endl; - * } - * // connect the above sink to a matching trace source - * NodeList::ConnectWithoutContext ("/nodes/* /devices/* /rx", MakeCallback (&DoSomethingTraceSink)); - * \endcode - * - * The connection path string "/nodes/* /devices/* /rx" matches the "rx" trace source - * located in every netdevice located in every node. The syntax of that path string - * is loosely based on regular expressions so, a user could conceivably connect - * to the trace sources present in only one node identified by node index: - * "/nodex/3/devices/* /rx". - * - * The matching algorithm used here is very useful since it allows you to connect - * at once a large set of trace sources to a single sink but it introduces another - * problem: it becomes impossible when you receive an event in your trace sink to - * know from _which_ trace source the event is coming from. In our example, the - * trace source might be coming from the NetDevice number 2 of Node 10 or Netdevice - * number 0 of Node 5. In both cases, you might need to know which of these NetDevice - * is generating this event, if only to generate some ascii trace dump. Another - * similar use-case is that you might have connected the same trace sink to - * multiple types of events which have the same signature: it is quite common - * to receive all tx, rx, and drop events in the same trace sink and that would be - * quite trivial to achieve with a string such as: "/nodes/* /devices/* /*" - * - * The source of a trace event can be retrieved from a trace sink using - * different means: the simplest - * way to get this information is to use the builtin printing facility of - * the TraceContext object: - * \code - * void - * DoSomethingTraceSink (const TraceContext &context, Ptr packet) - * { - * // for example, print the packet - * std::cout << "context=\"" << context << "\" packet: " << packet->Print () << std::endl; - * } - * \endcode - * The above code is going to generate output which looks like the following: - * \code - * context="nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... - * context="nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ... - * ... - * \endcode - * - * Another more advanced way to get information out of a TraceContext is to call its - * ns3::TraceContext::GetElement method. This method takes as its first and only - * argument an instance of the object we want to read and the list of available - * object instances we can read from a TraceContext is documented, once again, - * in the \ref TraceSourceList. For example, we could write the following to - * generate adhoc trace output: - * \code - * void DeviceRxSink (const TraceContext &context, Ptr packet) - * { - * NodeListIndex nodeIndex; - * NodeNetDeviceIndex deviceIndex; - * context.GetElement (nodeIndex); - * context.GetElement (deviceIndex); - * std::cout << "node-index=" << nodeIndex.Get (); - * std::cout << ", device-index=" << deviceIndex.Get (); - * std::cout << ", packet: " << packet->Print (); - * std::cout << std::endl; - * } - * \endcode - * - * \section ExportingTraceSources Exporting new Trace Sources - * - * Using existing trace sources to connect them to a set of adhoc trace sinks - * is not really complicated but, setting up new trace sources which can hook - * in this automatic connection system is a bit more complicated. - * - * So far, we know that a model author can generate trace events really easily: - * \code - * class MyModel - * { - * public: - * void DoSomething (Ptr packet) - * { - * // report this event on packet with value - * m_doSomething (packet); - * // do something - * } - * private: - * // report every "something" function call. - * CallbackTraceSource> m_doSomething; - * }; - * \endcode - * - * To make these new trace sources available to the rest of the connection system, - * the first step is to make sure that your model object derives from the ns3::Object - * base class either directly (as shown below) or indirectly through another base class: - * \code - * class MyModel : public Object {...}; - * // or: - * class SomeOtherObject : public Object {...}; - * class MyModel : public SomeOtherObject {...}; - * \endcode - * - * This is pretty trivial and lays the ground for the second step: overriding the - * ns3::Object::GetTraceResolver method: - * \code - * class MyModel : public MyParent - * { - * public: - * // declare overriden method - * virtual Ptr GetTraceResolver (void) const; - * private: - * // the new trace source to export. - * CallbackTraceSource> m_rxSource; - * }; - * \endcode - * - * To implement this method, you could attempt to implement a new subclass of - * the ns3::TraceResolver base class and return an instance from this method but - * this would be very hard. Instead, you should use the helper class - * ns3::CompositeTraceResolver to register your trace sources and chain up to - * your parent: - * \code - * Ptr - * MyModel::GetTraceResolver (void) const - * { - * // create an empty trace resolver - * Ptr resolver = Create (); - * // register m_rxSource - * resolver->AddSource ("rx", // the name of the trace source in the path string - * TraceDoc ("some help text to explain the purpose of this trace source", - * "Packet", // the type of the first argument to the trace source - * "the purpose of the first argument", - * "type-of-second-argument", "purpose-of-second-argument"), - * m_rxSource // the trace source itself is registered - * ); - * // make sure we include the trace sources implemented in the parent. - * resolver->SetParentResolver (MyParent::GetTraceResolver ()); - * return resolver; - * } - * \endcode - * - * Once you have written that code, you must make sure that this new method GetTraceResolver - * is going to be called at some point by the tracing system. If your model is located somewhere - * deep in MAC or PHY layer, that is, it is part of a NetDevice implementation, all you - * have to do is to make sure that your model is registered as a "composite" of your NetDevice - * subclass: - * \code - * class MyNetDevice : public NetDevice - * { - * public: - * Ptr GetTraceResolver (void) const; - * private: - * Ptr m_model; - * }; - * - * Ptr - * MyNetDevice::GetTraceResolver (void) const - * { - * Ptr resolver = ...; - * // register other trace source - * ... - * // register now your model as a "composite" - * resolver->AddComposite ("my-model", m_model); - * // chain up to parent. - * resolver->SetParentResolver (NetDevice::GetTraceResolver ()); - * return resolver; - * } - * \endcode - * - * The code above will make your "rx" trace source appear under the - * /nodes/xx/devices/xx/my-model/rx namespace path. - * - * If you have implemented a new layer 3 or 4 protocol object, the process to - * export your trace sources is quite similar. You need to subclass from - * ns3::Object, override the ns3::Object::GetTraceResolver method, make - * sure you chain up to your parent's GetTraceResolver method, and, finally, - * make sure that someone calls your new GetTraceResolver method. How to accomplish - * the latter should be documented in the node's API documentation which describes - * how to implement a new layer 3 or 4 protocol object. - * - * \section AdvancedTraceContext Creating new Trace Context Elements - * - * The last important feature which model developers need to understand - * is how to provide extra context information to trace sinks. For example, - * if your model exports both rx and tx trace sources which share the same - * signature, it is quite natural for a user to connect to a single trace sink - * to both of them with a trace path string such as "/nodes/* /devices/* /(rx|tx)". - * In this case, it becomes necessary to be able, from the trace sink function, - * to tell which event triggered the call to the trace sink: a rx or a tx event. - * - * That example is detailed below with a TX, a RX, and a DROP source: - * \code - * class MyModel - * { - * private: - * CallbackTraceSource> m_rxSource; - * CallbackTraceSource> m_txSource; - * CallbackTraceSource> m_dropSource; - * }; - * \endcode - * When a single sink is connected to all 3 sources here, one might want - * to write code like the following: - * \code - * void DeviceRxSink (const TraceContext &context, Ptr &packet) - * { - * switch (type) { - * case RX: - * std::cout << "rx" << std::endl; - * break; - * case TX: - * std::cout << "tx" << std::endl; - * break; - * case DROP: - * std::cout << "drop" << std::endl; - * break; - * } - * \endcode - * - * \subsection AdvancedTraceContextSimpleSolution The simple solution - * - * The simplest way to do achieve the result shown above is to include - * in the trace source an extra explicit argument which describes the source event: - * - define a small enum with 3 values - * - change the signature of m_rxSource, m_txSource, and m_dropSource to include - * the enum - * - pass the enum value in each event - * - * The resulting code is shown below: - * \code - * class MyModel - * { - * public: - * // define the trace type enum. - * enum TraceType { - * RX, - * TX, - * DROP - * }; - * private: - * // generate events - * void NotifyRxPacket (Ptr p) { - * m_rxSource (p, MyModel::RX); - * } - * void NotifyTxPacket (Ptr p) { - * m_rxSource (p, MyModel::TX); - * } - * void NotifyDropPacket (Ptr p) { - * m_rxSource (p, MyModel::DROP); - * } - * CallbackTraceSource,enum TraceType> m_rxSource; - * CallbackTraceSource,enum TraceType> m_txSource; - * CallbackTraceSource,enum TraceType> m_dropSource; - * }; - * \endcode - * These 3 new sources can be connected easily to a new trace sink: - * \code - * void ASimpleTraceSink (const TraceContext &context, Ptr packet, enum MyModel::TraceType type) - * { - * // here, read the "type" argument - * } - * \endcode - * - * This solution works but it makes it impossible to connect a single trace sink to a set - * of trace sources which represent "rx" events in different NetDevice objects since - * each of them will define a different enum type with different values: since the - * trace sink signature must match exactly the trace source signature, it is impossible - * to connect at the same time to all "rx" events of different NetDevice. - * - * \subsection AdvancedTraceContextFancySolution The more complex and generic solution - * - * There is, hopefully, a way to get the best of both worlds, that is, to allow a - * user to connect to a lot of trace source events of the same kind but coming from different - * implementations and to allow the user to differentiate between these different - * implementations. - * - * Rather than define an adhoc enum type with a list of trace sources, you can also - * define a new ns3::TraceContextElement for your source sources. For example, if you - * define a new MyModelTraceType class which contains the type of trace, your users can - * then write trace sink code which looks like this: - * \code - * void AFancyTraceSink (const TraceContext &context, Ptr packet) - * { - * MyModelTraceType type; - * if (context.GetElement (type)) - * { - * switch (type.Get ()) - * { - * case MyModelTraceType::RX: - * std::cout << "rx" << std::endl; - * break; - * case MyModelTraceType::TX: - * std::cout << "tx" << std::endl; - * break; - * case MyModelTraceType::DROP: - * std::cout << "drop" << std::endl; - * break; - * } - * } - * } - * \endcode - * - * Of course, since the type of trace is stored in the TraceContext, your users can - * also take the shortcut which uses the printing functionality of the TraceContext: - * \code - * void ALessFancyTraceSink (const TraceContext &context, Ptr packet) - * { - * std::cout << "context=\"" << context << "\" packet: " << packet->Print () << std::endl; - * } - * \endcode - * which will generate something like the following when the trace source comes - * from MyModel: - * \code - * context="my-model-rx" packet: ... - * \endcode - * - * The first step to achieve this is to define and implement a new - * subclass of the ns3::TraceContextElement base class. The exact list of - * public methods which must be implemented is described in the API - * documentation of the ns3::TraceContextElement class. - * \code - * class MyModelTraceType : public TraceContextElement - * { - * public: - * enum Type { - * RX, - * TX, - * DROP - * }; - * // called from MyModel::GetTraceResolver - * MyModelTraceType (enum Type type); - * // needed for by the tracing subsystem. - * MyModelTraceType (); - * // called from trace sink - * enum Type Get (void) const; - * // needed by the tracing subsystem - * static uint16_t GetUid (void); - * // needed by the tracing subsystem to - * // print the content of a TraceContext - * void Print (std::ostream &os) const; - * // needed by the tracing subsystem to - * // generate the doxygen documentation. - * std::string GetTypeName (void) const; - * private: - * enum Type m_type; - * }; - * \endcode - * The implementation does not require much thinking: - * \code - * MyModelTraceType::MyModelTraceType () - * : m_type (RX) - * {// an arbitrary default value. - * } - * MyModelTraceType::MyModelTraceType (enum Type type) - * : m_type (type) - * {} - * enum MyModelTraceType::Type - * MyModelTraceType::Get (void) const - * { - * return m_type; - * } - * uint16_t - * MyModelTraceType::GetUid (void) - * { - * // use protected TraceContextElement::AllocateUid method - * // the input string is used to uniquely identify this new subclass - * static uint16_t uid = AllocateUid ("ns3::MyModelTraceType"); - * return uid; - * } - * void - * MyModelTraceType::Print (std::ostream &os) const - * { - * // this method is invoked by the print function of a TraceContext - * // if it contains an instance of this TraceContextElement. - * switch (m_type) { - * case RX: os << "rx"; break; - * // ... - * } - * } - * std::string - * MyModelTraceType::GetTypeName (void) const - * { - * // This method should return a fully-qualified c++ typename - * // This method is used only for documentation purposes to - * // generate the content of the Trace Source List. - * return "ns3::MyModelTraceType"; - * } - * \endcode - * - * Once this subclass is implemented, the work is almost completed: you - * just need to pass an instance of that class as the last argument of - * the ns3::CompositeTraceResolver::AddSource method as shown below: - * \code - * Ptr - * MyModel::GetTraceResolver (void) const - * { - * // create an empty trace resolver - * Ptr resolver = Create (); - * // register m_rxSource - * resolver->AddSource ("rx", // the name of the trace source in the path string - * TraceDoc ("some help text to explain the purpose of this trace source", - * "Packet", // the type of the first argument to the trace source - * "the purpose of the first argument", - * "type-of-second-argument", "purpose-of-second-argument"), - * m_rxSource, // the trace source itself is registered - * // the TraceContextElement associated to this trace source. - * MyModelTraceType (MyModelTraceType::RX) - * ); - * // make sure we include the trace sources implemented in the parent. - * resolver->SetParentResolver (MyParent::GetTraceResolver ()); - * return resolver; - * } - * \endcode - */ diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index e1d5d4698..9585bf06d 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -68,8 +68,8 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Build Topology."); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate(5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds(2)); + csma.SetChannelParameter ("BitRate", DataRateValue (DataRate(5000000))); + csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds(2))); NetDeviceContainer n0 = csma.Install (c0); NetDeviceContainer n1 = csma.Install (c1); @@ -95,8 +95,8 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Create Applications."); OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer app = onoff.Install (c0.Get (0)); // Start the application diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 1d9e2f94c..870494809 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -59,7 +59,7 @@ main (int argc, char *argv[]) // Set up default values for the simulation. // // Select Ethernet II-style encapsulation (no LLC/Snap header) - Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", String ("IpArp")); + Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("IpArp")); // Allow the user to override any of the defaults at // run-time, via command-line arguments @@ -75,8 +75,8 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Build Topology."); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", DataRateValue (DataRate (5000000))); + csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); // We will use these NetDevice containers later, for IP addressing NetDeviceContainer nd0 = csma.Install (c0); // First LAN @@ -142,10 +142,10 @@ main (int argc, char *argv[]) // every few seconds OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (multicastGroup, multicastPort))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); - onoff.SetAttribute ("DataRate", DataRate ("255b/s")); - onoff.SetAttribute ("PacketSize", Uinteger (128)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s"))); + onoff.SetAttribute ("PacketSize", UintegerValue (128)); ApplicationContainer srcC = onoff.Install (c0.Get (0)); @@ -157,7 +157,7 @@ main (int argc, char *argv[]) // Create an optional packet sink to receive these packets PacketSinkHelper sink ("ns3::Udp", - Address (InetSocketAddress (Ipv4Address::GetAny(), multicastPort))); + InetSocketAddress (Ipv4Address::GetAny(), multicastPort)); ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 // Start the sink diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index f95effdda..d75df160c 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -66,8 +66,8 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Build Topology"); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", DataRateValue (5000000)); + csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); // // Now fill out the topology by creating the net devices required to connect // the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will @@ -97,8 +97,8 @@ main (int argc, char *argv[]) OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer app = onoff.Install (c.Get (0)); // Start the application @@ -114,7 +114,7 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n0, starting at time 1.1 seconds // onoff.SetAttribute ("Remote", - Address (InetSocketAddress (Ipv4Address ("10.1.1.1"), port))); + AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.1"), port))); ApplicationContainer app2 = onoff.Install (c.Get (3)); sink.Install (c.Get (0)); diff --git a/examples/csma-packet-socket.cc b/examples/csma-packet-socket.cc index cf748520d..dfc267e0f 100644 --- a/examples/csma-packet-socket.cc +++ b/examples/csma-packet-socket.cc @@ -70,13 +70,13 @@ main (int argc, char *argv[]) // create the shared medium used by all csma devices. NS_LOG_INFO ("Create channels."); - Ptr channel = CreateObject ("BitRate", DataRate(5000000), - "Delay", MilliSeconds(2)); + Ptr channel = CreateObject ("BitRate", DataRateValue (DataRate(5000000)), + "Delay", TimeValue (MilliSeconds(2))); // use a helper function to connect our nodes to the shared channel. NS_LOG_INFO ("Build Topology."); CsmaHelper csma; - csma.SetDeviceParameter ("EncapsulationMode", String ("Llc")); + csma.SetDeviceParameter ("EncapsulationMode", StringValue ("Llc")); NetDeviceContainer devs = csma.Install (c, channel); NS_LOG_INFO ("Create Applications."); @@ -86,8 +86,8 @@ main (int argc, char *argv[]) socket.SetPhysicalAddress (devs.Get (1)->GetAddress ()); socket.SetProtocol (2); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); - onoff.SetAttribute ("OnTime", ConstantVariable (1.0)); - onoff.SetAttribute ("OffTime", ConstantVariable (0.0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); @@ -96,8 +96,8 @@ main (int argc, char *argv[]) socket.SetSingleDevice (devs.Get (3)->GetIfIndex ()); socket.SetPhysicalAddress (devs.Get (0)->GetAddress ()); socket.SetProtocol (3); - onoff.SetAttribute ("Remote", Address (socket)); - onoff.SetAttribute ("OffTime", ConstantVariable (0.0)); + onoff.SetAttribute ("Remote", AddressValue (socket)); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); apps = onoff.Install (c.Get (3)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index 2c665cb0c..764c7e3a5 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -51,8 +51,8 @@ NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample"); int main (int argc, char *argv[]) { - Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); - Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); // Allow the user to override any of the defaults and the above // Bind ()s at run-time, via command-line arguments @@ -73,20 +73,20 @@ main (int argc, char *argv[]) // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (5000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (2)); + p2p.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + p2p.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d2 = p2p.Install (n1n2); - p2p.SetChannelParameter ("BitRate", DataRate (1500000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (10)); + p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps")); + p2p.SetChannelParameter ("Delay", StringValue ("10ms")); NetDeviceContainer d5d6 = p2p.Install (n5n6); // We create the channels first without any IP addressing information CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + csma.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer d2345 = csma.Install (n2345); // Later, we add IP addresses. @@ -113,11 +113,11 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::Udp", - Address (InetSocketAddress (i5i6.GetAddress (1), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); - onoff.SetAttribute ("DataRate", DataRate("300bps")); - onoff.SetAttribute ("PacketSize", Uinteger (50)); + InetSocketAddress (i5i6.GetAddress (1), port)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff.SetAttribute ("DataRate", StringValue ("300bps")); + onoff.SetAttribute ("PacketSize", UintegerValue (50)); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index eb4b5f357..515a1a455 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -96,8 +96,8 @@ main (int argc, char *argv[]) // Simulation defaults are typically set next, before command line // arguments are parsed. // - Config::SetDefault ("ns3::OnOffApplication::PacketSize", String ("210")); - Config::SetDefault ("ns3::OnOffApplication::DataRate", String ("448kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("210")); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); // // For convenience, we add the local variables to the command line argument @@ -163,10 +163,10 @@ main (int argc, char *argv[]) positionAlloc->Add (Vector (5.0, 0.0, 0.0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel", - "Bounds", Rectangle (0, 1000, 0, 1000), - "Speed", ConstantVariable (2000), - "Pause", ConstantVariable (0.2)); - mobility.Install (backbone); + "Bounds", RectangleValue (Rectangle (0, 1000, 0, 1000)), + "Speed", RandomVariableValue (ConstantVariable (2000)), + "Pause", RandomVariableValue (ConstantVariable (0.2))); + mobility.Layout (backbone); /////////////////////////////////////////////////////////////////////////// // // @@ -196,8 +196,8 @@ main (int argc, char *argv[]) // collection. // CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", DataRateValue (DataRate (5000000))); + csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer lanDevices = csma.Install (lan); // // Add the IPv4 protocol stack to the new LAN nodes @@ -272,10 +272,10 @@ main (int argc, char *argv[]) mobility.PushReferenceMobilityModel (backbone.Get (i)); mobility.SetPositionAllocator (subnetAlloc); mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel", - "Bounds", Rectangle (-25, 25, -25, 25), - "Speed", ConstantVariable (30), - "Pause", ConstantVariable (0.4)); - mobility.Install (infra); + "Bounds", RectangleValue (Rectangle (-25, 25, -25, 25)), + "Speed", RandomVariableValue (ConstantVariable (30)), + "Pause", RandomVariableValue (ConstantVariable (0.4))); + mobility.Layout (infra); } /////////////////////////////////////////////////////////////////////////// // // @@ -307,8 +307,8 @@ main (int argc, char *argv[]) OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (remoteAddr, port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (appSource); apps.Start (Seconds (3.0)); apps.Stop (Seconds (20.0)); diff --git a/examples/simple-alternate-routing.cc b/examples/simple-alternate-routing.cc index 34e1981cd..dd83323c8 100644 --- a/examples/simple-alternate-routing.cc +++ b/examples/simple-alternate-routing.cc @@ -62,8 +62,8 @@ main (int argc, char *argv[]) // RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); - Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); - Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("300b/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("300b/s")); // The below metric, if set to 3 or higher, will cause packets between // n1 and n3 to take the 2-hop route through n2 @@ -97,17 +97,17 @@ main (int argc, char *argv[]) // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (5000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (2)); + p2p.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + p2p.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d2 = p2p.Install (n1n2); - p2p.SetChannelParameter ("BitRate", DataRate(1500000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (10)); + p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps")); + p2p.SetChannelParameter ("Delay", StringValue ("10ms")); NetDeviceContainer d3d2 = p2p.Install (n3n2); - p2p.SetChannelParameter ("Delay", MilliSeconds (100)); + p2p.SetChannelParameter ("Delay", StringValue ("100ms")); NetDeviceContainer d1d3 = p2p.Install (n1n3); InternetStackHelper internet; @@ -143,8 +143,8 @@ main (int argc, char *argv[]) // Create a flow from n3 to n1, starting at time 1.1 seconds OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (i1i2.GetAddress (0), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (c.Get (3)); apps.Start (Seconds (1.1)); diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index 72a9e4638..617666d12 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -65,11 +65,11 @@ main (int argc, char *argv[]) RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); // Set a few parameters - Config::SetDefault ("ns3::RateErrorModel::ErrorRate", Double (0.01)); - Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", String ("EU_PKT")); + Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01)); + Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT")); - Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); - Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s"))); // Allow the user to override any of the defaults and the above @@ -92,14 +92,14 @@ main (int argc, char *argv[]) // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (5000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (2)); + p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate (5000000))); + p2p.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d2 = p2p.Install (n1n2); - p2p.SetChannelParameter ("BitRate", DataRate (1500000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (10)); + p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate (1500000))); + p2p.SetChannelParameter ("Delay", TimeValue (MilliSeconds (10))); NetDeviceContainer d3d2 = p2p.Install (n3n2); // Later, we add IP addresses. @@ -124,8 +124,8 @@ main (int argc, char *argv[]) OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (i3i2.GetAddress (1), port))); - onoff.SetAttribute ("OnTime", ConstantVariable(1)); - onoff.SetAttribute ("OffTime", ConstantVariable(0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start(Seconds(1.0)); @@ -140,14 +140,14 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n1, starting at time 1.1 seconds onoff.SetAttribute ("Remote", - Address (InetSocketAddress (i1i2.GetAddress (0), port))); + AddressValue (InetSocketAddress (i1i2.GetAddress (0), port))); apps = onoff.Install (c.Get (3)); apps.Start(Seconds(1.1)); apps.Stop (Seconds(10.0)); // Create a packet sink to receive these packets sink.SetAttribute ("Local", - Address (InetSocketAddress (Ipv4Address::GetAny (), port))); + AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port))); apps = sink.Install (c.Get (1)); apps.Start (Seconds (1.1)); apps.Stop (Seconds (10.0)); @@ -157,9 +157,9 @@ main (int argc, char *argv[]) // // Create an ErrorModel based on the implementation (constructor) // specified by the default classId - Ptr em = CreateObject ("RanVar", UniformVariable (0.0, 1.0), - "ErrorRate", Double (0.001)); - d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", em); + Ptr em = CreateObject ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)), + "ErrorRate", DoubleValue (0.001)); + d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (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 @@ -169,7 +169,7 @@ main (int argc, char *argv[]) // This time, we'll explicitly create the error model we want Ptr pem = CreateObject (); pem->SetList (sampleList); - d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", pem); + d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); std::ofstream ascii; ascii.open ("simple-error-model.tr"); diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index 19e86c70e..aa33d090b 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -67,8 +67,8 @@ main (int argc, char *argv[]) RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); // Set up some default values for the simulation. Use the - Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); - Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30); @@ -92,14 +92,14 @@ main (int argc, char *argv[]) // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (5000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (2)); + p2p.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + p2p.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d2 = p2p.Install (n1n2); - p2p.SetChannelParameter ("BitRate", DataRate (1500000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (10)); + p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps")); + p2p.SetChannelParameter ("Delay", StringValue ("10ms")); NetDeviceContainer d3d2 = p2p.Install (n3n2); // Later, we add IP addresses. @@ -124,8 +124,8 @@ main (int argc, char *argv[]) uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::Udp", Address (InetSocketAddress (i3i2.GetAddress (0), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); @@ -139,7 +139,7 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n1, starting at time 1.1 seconds onoff.SetAttribute ("Remote", - Address (InetSocketAddress (i1i2.GetAddress (0), port))); + AddressValue (InetSocketAddress (i1i2.GetAddress (0), port))); apps = onoff.Install (c.Get (3)); apps.Start (Seconds (1.1)); apps.Stop (Seconds (10.0)); diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index de6a63224..8c78030a6 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -67,8 +67,8 @@ main (int argc, char *argv[]) // Set up some default values for the simulation. Use the - Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); - Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30); @@ -93,12 +93,12 @@ main (int argc, char *argv[]) // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (5000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (2)); + p2p.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + p2p.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer nd02 = p2p.Install (n02); NetDeviceContainer nd12 = p2p.Install (n12); - p2p.SetChannelParameter ("BitRate", DataRate (1500000)); - p2p.SetChannelParameter ("Delay", MilliSeconds (10)); + p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps")); + p2p.SetChannelParameter ("Delay", StringValue ("10ms")); NetDeviceContainer nd32 = p2p.Install (n32); NetDeviceContainer nd34 = p2p.Install (n34); @@ -128,9 +128,9 @@ main (int argc, char *argv[]) uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::Udp", - Address (InetSocketAddress (i34.GetAddress (1), port))); - onoff.SetAttribute ("OnTime", ConstantVariable (1)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + InetSocketAddress (i34.GetAddress (1), port)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); @@ -138,7 +138,7 @@ main (int argc, char *argv[]) // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::Udp", - Address (InetSocketAddress (Ipv4Address::GetAny (), port))); + InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (c.Get (3)); apps.Start (Seconds (1.0)); @@ -146,7 +146,7 @@ main (int argc, char *argv[]) // Create a similar flow from n3 to n1, starting at time 1.1 seconds onoff.SetAttribute ("Remote", - Address (InetSocketAddress (i12.GetAddress (0), port))); + AddressValue (InetSocketAddress (i12.GetAddress (0), port))); apps = onoff.Install (c.Get (3)); apps.Start (Seconds (1.1)); apps.Stop (Seconds (10.0)); diff --git a/examples/tcp-large-transfer.cc b/examples/tcp-large-transfer.cc index d7982cf75..cd304fc57 100644 --- a/examples/tcp-large-transfer.cc +++ b/examples/tcp-large-transfer.cc @@ -137,8 +137,8 @@ int main (int argc, char *argv[]) // We create the channels first without any IP addressing information PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate(10000000)); - p2p.SetChannelParameter ("Delay", MilliSeconds(10)); + p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate(10000000))); + p2p.SetChannelParameter ("Delay", TimeValue (MilliSeconds(10))); NetDeviceContainer dev0 = p2p.Install (c0); NetDeviceContainer dev1 = p2p.Install (c1); @@ -170,7 +170,7 @@ int main (int argc, char *argv[]) // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::Tcp", - Address (InetSocketAddress (Ipv4Address::GetAny (), servPort))); + InetSocketAddress (Ipv4Address::GetAny (), servPort)); ApplicationContainer apps = sink.Install (c1.Get (1)); apps.Start (Seconds (0.0)); diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 0bcaded48..001e2a621 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -87,8 +87,8 @@ main (int argc, char *argv[]) // Explicitly create the channels required by the topology (shown above). // CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate(5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", DataRateValue (DataRate(5000000))); + csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer d = csma.Install (n); Ipv4AddressHelper ipv4; @@ -119,9 +119,9 @@ main (int argc, char *argv[]) Time interPacketInterval = Seconds (1.); UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (maxPacketCount)); - client.SetAppAttribute ("Interval", interPacketInterval); - client.SetAppAttribute ("PacketSize", Uinteger (packetSize)); + client.SetAppAttribute ("MaxPackets", UintegerValue (maxPacketCount)); + client.SetAppAttribute ("Interval", TimeValue (interPacketInterval)); + client.SetAppAttribute ("PacketSize", UintegerValue (packetSize)); apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index 06ac048b0..0244d8160 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -134,10 +134,10 @@ Experiment::Run (const WifiHelper &wifi) socket.SetProtocol (1); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); - onoff.SetAttribute ("OnTime", ConstantVariable (250)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); - onoff.SetAttribute ("DataRate", DataRate (60000000)); - onoff.SetAttribute ("PacketSize", Uinteger (2000)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000))); + onoff.SetAttribute ("PacketSize", UintegerValue (2000)); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (0.5)); @@ -156,8 +156,8 @@ Experiment::Run (const WifiHelper &wifi) int main (int argc, char *argv[]) { // disable fragmentation - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", String ("2200")); - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", String ("2200")); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); CommandLine cmd; cmd.Parse (argc, argv); @@ -174,56 +174,56 @@ int main (int argc, char *argv[]) NS_LOG_DEBUG ("54"); experiment = Experiment ("54mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-54mbs")); + "DataMode", StringValue ("wifia-54mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("48"); experiment = Experiment ("48mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-48mbs")); + "DataMode", StringValue ("wifia-48mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("36"); experiment = Experiment ("36mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-36mbs")); + "DataMode", StringValue ("wifia-36mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("24"); experiment = Experiment ("24mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-24mbs")); + "DataMode", StringValue ("wifia-24mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("18"); experiment = Experiment ("18mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-18mbs")); + "DataMode", StringValue ("wifia-18mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("12"); experiment = Experiment ("12mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-12mbs")); + "DataMode", StringValue ("wifia-12mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("9"); experiment = Experiment ("9mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-9mbs")); + "DataMode", StringValue ("wifia-9mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); NS_LOG_DEBUG ("6"); experiment = Experiment ("6mb"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", String ("wifia-6mbs")); + "DataMode", StringValue ("wifia-6mbs")); dataset = experiment.Run (wifi); gnuplot.AddDataset (dataset); @@ -231,7 +231,7 @@ int main (int argc, char *argv[]) gnuplot = Gnuplot ("rate-control.png"); - Config::SetDefault ("ns3::WifiPhy::Standard", String ("holland")); + Config::SetDefault ("ns3::WifiPhy::Standard", StringValue ("holland")); NS_LOG_DEBUG ("arf"); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index db91a1e80..7c2c266fa 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -113,9 +113,9 @@ int main (int argc, char *argv[]) Packet::EnableMetadata (); // enable rts cts all the time. - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", String ("0")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0")); // disable fragmentation - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", String ("2200")); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); WifiHelper wifi; MobilityHelper mobility; @@ -141,13 +141,14 @@ int main (int argc, char *argv[]) wifi.SetPhy ("ns3::WifiPhy"); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); // setup stas. - wifi.SetMac ("ns3::NqstaWifiMac", "Ssid", ssid, - "ActiveProbing", Boolean (false)); + wifi.SetMac ("ns3::NqstaWifiMac", + "Ssid", SsidValue (ssid), + "ActiveProbing", BooleanValue (false)); staDevs = wifi.Install (stas, channel); // setup ap. - wifi.SetMac ("ns3::NqapWifiMac", "Ssid", ssid, - "BeaconGeneration", Boolean (true), - "BeaconInterval", Seconds (2.5)); + wifi.SetMac ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid), + "BeaconGeneration", BooleanValue (true), + "BeaconInterval", TimeValue (Seconds (2.5))); wifi.Install (ap, channel); // mobility. @@ -162,8 +163,8 @@ int main (int argc, char *argv[]) socket.SetProtocol (1); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); - onoff.SetAttribute ("OnTime", ConstantVariable (42)); - onoff.SetAttribute ("OffTime", ConstantVariable (0)); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); ApplicationContainer apps = onoff.Install (stas.Get (0)); apps.Start (Seconds (0.5)); diff --git a/samples/main-attribute-value.cc b/samples/main-attribute-value.cc index 2a1841951..c3624d9b8 100644 --- a/samples/main-attribute-value.cc +++ b/samples/main-attribute-value.cc @@ -24,6 +24,7 @@ #include "ns3/config.h" #include "ns3/uinteger.h" #include "ns3/string.h" +#include "ns3/pointer.h" #include "ns3/simulator.h" #include "ns3/node.h" @@ -50,10 +51,10 @@ main (int argc, char *argv[]) // (this default can be observed in the function DropTailQueue::GetTypeId) // // Here, we set it to 80 packets. We could use one of two value types: - // a string-based value or a Uinteger value - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", String ("80")); + // a string-based value or a UintegerValue value + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("80")); // The below function call is redundant - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", Uinteger(80)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (80)); // Allow the user to override any of the defaults and the above // SetDefaults() at run-time, via command-line arguments @@ -87,7 +88,9 @@ main (int argc, char *argv[]) // First, we observe that we can get a pointer to the (base class) // queue via the PointToPointNetDevice attributes, where it is called // TxQueue - Ptr txQueue = net0->GetAttribute ("TxQueue"); + PointerValue ptr; + net0->GetAttribute ("TxQueue", ptr); + Ptr txQueue = ptr.Get (); // Using the GetObject function, we can perform a safe downcast // to a DropTailQueue, where MaxPackets is a member @@ -100,18 +103,19 @@ main (int argc, char *argv[]) // the attribute system stores values and not disparate types. // Here, the attribute value is assigned to a Uinteger, and // the Get() method on this value produces the (unwrapped) uint32_t. - Uinteger limit = dtq->GetAttribute ("MaxPackets"); + UintegerValue limit; + dtq->GetAttribute ("MaxPackets", limit); NS_LOG_INFO ("1. dtq limit: " << limit.Get () << " packets"); // Note that the above downcast is not really needed; we could have // done the same using the Ptr even though the attribute // is a member of the subclass - limit = txQueue->GetAttribute ("MaxPackets"); + txQueue->GetAttribute ("MaxPackets", limit); NS_LOG_INFO ("2. txQueue limit: " << limit.Get () << " packets"); // Now, let's set it to another value (60 packets) - txQueue->SetAttribute("MaxPackets", Uinteger (60)); - limit = txQueue->GetAttribute ("MaxPackets"); + txQueue->SetAttribute("MaxPackets", UintegerValue (60)); + txQueue->GetAttribute ("MaxPackets", limit); NS_LOG_INFO ("3. txQueue limit changed: " << limit.Get () << " packets"); // 2. Namespace-based access @@ -121,18 +125,18 @@ main (int argc, char *argv[]) // namespace; this approach is useful if one doesn't have access to // the underlying pointers and would like to configure a specific // attribute with a single statement. - Config::Set ("/NodeList/0/DeviceList/0/TxQueue/MaxPackets", Uinteger (25)); - limit = txQueue->GetAttribute ("MaxPackets"); + Config::Set ("/NodeList/0/DeviceList/0/TxQueue/MaxPackets", UintegerValue (25)); + txQueue->GetAttribute ("MaxPackets", limit); NS_LOG_INFO ("4. txQueue limit changed through namespace: " << - limit.Get () << " packets"); + limit.Get () << " packets"); // we could have also used wildcards to set this value for all nodes // and all net devices (which in this simple example has the same // effect as the previous Set()) - Config::Set ("/NodeList/*/DeviceList/*/TxQueue/MaxPackets", Uinteger (15)); - limit = txQueue->GetAttribute ("MaxPackets"); + Config::Set ("/NodeList/*/DeviceList/*/TxQueue/MaxPackets", UintegerValue (15)); + txQueue->GetAttribute ("MaxPackets", limit); NS_LOG_INFO ("5. txQueue limit changed through wildcarded namespace: " << - limit.Get () << " packets"); + limit.Get () << " packets"); Simulator::Destroy (); } diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index d1ca99e2b..e1c6ce6d2 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -23,12 +23,12 @@ int main (int argc, char *argv[]) // the x interval between each object is 5 meters // and the y interval between each object is 20 meters mobility.SetPositionAllocator ("ns3::GridPositionAllocator", - "MinX", Double (-100.0), - "MinY", Double (-100.0), - "DeltaX", Double (5.0), - "DeltaY", Double (20.0), - "GridWidth", Uinteger (20), - "LayoutType", String ("RowFirst")); + "MinX", DoubleValue (-100.0), + "MinY", DoubleValue (-100.0), + "DeltaX", DoubleValue (5.0), + "DeltaY", DoubleValue (20.0), + "GridWidth", UintegerValue (20), + "LayoutType", StringValue ("RowFirst")); // each object will be attached a static position. // i.e., once set by the "position allocator", the // position will never change. diff --git a/samples/main-propagation-loss.cc b/samples/main-propagation-loss.cc index 7f998a8ad..2ab140bfa 100644 --- a/samples/main-propagation-loss.cc +++ b/samples/main-propagation-loss.cc @@ -51,8 +51,8 @@ PrintOne (double minTxpower, double maxTxpower, double stepTxpower, double min, int main (int argc, char *argv[]) { - Config::SetGlobal ("LogDistancePropagationLossModel::ReferenceDistance", String ("1.0")); - Config::SetGlobal ("LogDistancePropagationLossModel::Exponent", String ("4")); + Config::SetGlobal ("LogDistancePropagationLossModel::ReferenceDistance", StringValue ("1.0")); + Config::SetGlobal ("LogDistancePropagationLossModel::Exponent", StringValue ("4")); PrintOne (-10, 20, 5, 0, 10000, 2); diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index a83b8deef..ec34d1ec8 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -27,9 +27,9 @@ int main (int argc, char *argv[]) MobilityHelper mobility; mobility.EnableNotifier (); mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", - "X", String ("100.0"), - "Y", String ("100.0"), - "Rho", String ("Uniform:0:30")); + "X", StringValue ("100.0"), + "Y", StringValue ("100.0"), + "Rho", StringValue ("Uniform:0:30")); mobility.SetMobilityModel ("ns3::StaticMobilityModel"); mobility.Install (c); diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index d234b8645..4e951c2d6 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -19,10 +19,10 @@ CourseChange (ns3::TraceContext const&, Ptr mobility) int main (int argc, char *argv[]) { - Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Mode", String ("Time")); - Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Time", String ("2s")); - Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Speed", String ("Constant:1.0")); - Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Bounds", String ("0:200:0:100")); + Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Mode", StringValue ("Time")); + Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Time", StringValue ("2s")); + Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Speed", StringValue ("Constant:1.0")); + Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Bounds", StringValue ("0:200:0:100")); CommandLine cmd; cmd.Parse (argc, argv); @@ -33,17 +33,17 @@ int main (int argc, char *argv[]) MobilityHelper mobility; mobility.EnableNotifier (); mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", - "X", String ("100.0"), - "Y", String ("100.0"), - "Rho", String ("Uniform:0:30")); + "X", StringValue ("100.0"), + "Y", StringValue ("100.0"), + "Rho", StringValue ("Uniform:0:30")); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", - "Mode", String ("Time"), - "Time", String ("2s"), - "Speed", String ("Constant:1.0"), - "Bounds", String ("0:200:0:100")); - mobility.InstallAll (); + "Mode", StringValue ("Time"), + "Time", StringValue ("2s"), + "Speed", StringValue ("Constant:1.0"), + "Bounds", StringValue ("0:200:0:100")); + mobility.LayoutAll (); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", - MakeCallback (&CourseChange)); + MakeCallback (&CourseChange)); Simulator::StopAt (Seconds (100.0)); diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 2d9ada4f8..311c30519 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -52,34 +52,34 @@ OnOffApplication::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("DataRate", "The data rate in on state.", - DataRate ("500kb/s"), + DataRateValue (DataRate ("500kb/s")), MakeDataRateAccessor (&OnOffApplication::m_cbrRate), MakeDataRateChecker ()) .AddAttribute ("PacketSize", "The size of packets sent in on state", - Uinteger (512), + UintegerValue (512), MakeUintegerAccessor (&OnOffApplication::m_pktSize), MakeUintegerChecker (1)) .AddAttribute ("Remote", "The address of the destination", - Address (), + AddressValue (), MakeAddressAccessor (&OnOffApplication::m_peer), MakeAddressChecker ()) .AddAttribute ("OnTime", "A RandomVariable used to pick the duration of the 'On' state.", - ConstantVariable (1.0), + RandomVariableValue (ConstantVariable (1.0)), MakeRandomVariableAccessor (&OnOffApplication::m_onTime), MakeRandomVariableChecker ()) .AddAttribute ("OffTime", "A RandomVariable used to pick the duration of the 'Off' state.", - ConstantVariable (1.0), + RandomVariableValue (ConstantVariable (1.0)), MakeRandomVariableAccessor (&OnOffApplication::m_offTime), MakeRandomVariableChecker ()) .AddAttribute ("MaxBytes", "The total number of bytes to send. Once these bytes are sent, " "no packet is sent again, even in on state. The value zero means " "that there is no limit.", - Uinteger (0), + UintegerValue (0), MakeUintegerAccessor (&OnOffApplication::m_maxBytes), MakeUintegerChecker ()) .AddAttribute ("Protocol", "The type of protocol to use.", - Udp::GetTypeId (), + TypeIdValue (Udp::GetTypeId ()), MakeTypeIdAccessor (&OnOffApplication::m_tid), MakeTypeIdChecker ()) .AddTraceSource ("Tx", "A new packet is created and is sent", @@ -91,7 +91,7 @@ OnOffApplication::GetTypeId (void) OnOffApplication::OnOffApplication () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_socket = 0; m_connected = false; m_residualBits = 0; @@ -101,14 +101,13 @@ OnOffApplication::OnOffApplication () OnOffApplication::~OnOffApplication() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void OnOffApplication::SetMaxBytes(uint32_t maxBytes) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << maxBytes); + NS_LOG_FUNCTION (this << maxBytes); m_maxBytes = maxBytes; } @@ -116,7 +115,7 @@ OnOffApplication::SetMaxBytes(uint32_t maxBytes) void OnOffApplication::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_socket = 0; // chain up @@ -126,7 +125,7 @@ OnOffApplication::DoDispose (void) // Application Methods void OnOffApplication::StartApplication() // Called at time specified by Start { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // Create the socket if not already if (!m_socket) @@ -146,7 +145,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Start void OnOffApplication::StopApplication() // Called at time specified by Stop { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_sendEvent.IsRunning ()) { // Cancel the pending send packet event @@ -161,14 +160,14 @@ void OnOffApplication::StopApplication() // Called at time specified by Stop // Event handlers void OnOffApplication::StartSending() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ScheduleNextTx(); // Schedule the send packet event } void OnOffApplication::StopSending() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Simulator::Cancel(m_sendEvent); } @@ -176,7 +175,7 @@ void OnOffApplication::StopSending() // Private helpers void OnOffApplication::ScheduleNextTx() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_maxBytes == 0 || m_totBytes < m_maxBytes) { @@ -196,7 +195,7 @@ void OnOffApplication::ScheduleNextTx() void OnOffApplication::ScheduleStartEvent() { // Schedules the event to start sending data (switch to the "On" state) - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Time offInterval = Seconds(m_offTime.GetValue()); NS_LOG_LOGIC ("start at " << offInterval); @@ -205,7 +204,7 @@ void OnOffApplication::ScheduleStartEvent() void OnOffApplication::ScheduleStopEvent() { // Schedules the event to stop sending data (switch to "Off" state) - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Time onInterval = Seconds(m_onTime.GetValue()); NS_LOG_LOGIC ("stop at " << onInterval); @@ -215,7 +214,7 @@ void OnOffApplication::ScheduleStopEvent() void OnOffApplication::SendPacket() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("sending packet at " << Simulator::Now()); NS_ASSERT (m_sendEvent.IsExpired ()); Ptr packet = Create (m_pktSize); @@ -229,7 +228,7 @@ void OnOffApplication::SendPacket() void OnOffApplication::ConnectionSucceeded(Ptr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_connected = true; ScheduleStartEvent(); @@ -237,7 +236,7 @@ void OnOffApplication::ConnectionSucceeded(Ptr) void OnOffApplication::ConnectionFailed(Ptr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); cout << "OnOffApplication, Connection Failed" << endl; } diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 650909381..6b768978b 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -43,11 +43,11 @@ PacketSink::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Local", "The Address on which to Bind the rx socket.", - Address (), + AddressValue (), MakeAddressAccessor (&PacketSink::m_local), MakeAddressChecker ()) .AddAttribute ("Protocol", "The type id of the protocol to use for the rx socket.", - Udp::GetTypeId (), + TypeIdValue (Udp::GetTypeId ()), MakeTypeIdAccessor (&PacketSink::m_tid), MakeTypeIdChecker ()) .AddTraceSource ("Rx", "A packet has been received", diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 5bbf56c80..6d122d872 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -38,23 +38,23 @@ UdpEchoClient::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("MaxPackets", "XXX", - Uinteger (100), + UintegerValue (100), MakeUintegerAccessor (&UdpEchoClient::m_count), MakeUintegerChecker ()) .AddAttribute ("Interval", "XXX", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&UdpEchoClient::m_interval), MakeTimeChecker ()) .AddAttribute ("RemoteIpv4", "XXX", - Ipv4Address (), + Ipv4AddressValue (), MakeIpv4AddressAccessor (&UdpEchoClient::m_peerAddress), MakeIpv4AddressChecker ()) .AddAttribute ("RemotePort", "XXX", - Uinteger (0), + UintegerValue (0), MakeUintegerAccessor (&UdpEchoClient::m_peerPort), MakeUintegerChecker ()) .AddAttribute ("PacketSize", "Size of packets generated", - Uinteger (100), + UintegerValue (100), MakeUintegerAccessor (&UdpEchoClient::m_size), MakeUintegerChecker ()) ; @@ -63,7 +63,7 @@ UdpEchoClient::GetTypeId (void) UdpEchoClient::UdpEchoClient () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_sent = 0; m_socket = 0; m_sendEvent = EventId (); @@ -71,7 +71,7 @@ UdpEchoClient::UdpEchoClient () UdpEchoClient::~UdpEchoClient() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -84,14 +84,14 @@ UdpEchoClient::SetRemote (Ipv4Address ip, uint16_t port) void UdpEchoClient::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Application::DoDispose (); } void UdpEchoClient::StartApplication (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_socket) { @@ -111,7 +111,7 @@ UdpEchoClient::StartApplication (void) void UdpEchoClient::StopApplication () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_socket) { @@ -125,14 +125,14 @@ UdpEchoClient::StopApplication () void UdpEchoClient::ScheduleTransmit (Time dt) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_sendEvent = Simulator::Schedule(dt, &UdpEchoClient::Send, this); } void UdpEchoClient::Send (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (m_sendEvent.IsExpired ()); @@ -154,8 +154,7 @@ UdpEchoClient::Receive( Ptr packet, const Address &from) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << socket << packet << from); + NS_LOG_FUNCTION (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index 22aeeb485..9a924edc2 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -29,6 +29,11 @@ namespace ns3 { class Socket; class Packet; +/** + * \brief A Udp Echo client + * + * Every packet sent should be returned by the server and received here. + */ class UdpEchoClient : public Application { public: diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index c188dcc0e..3535c3ffc 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -40,7 +40,7 @@ UdpEchoServer::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Port", "Port on which we listen for incoming packets.", - Uinteger (9), + UintegerValue (9), MakeUintegerAccessor (&UdpEchoServer::m_port), MakeUintegerChecker ()) ; @@ -49,25 +49,25 @@ UdpEchoServer::GetTypeId (void) UdpEchoServer::UdpEchoServer () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } UdpEchoServer::~UdpEchoServer() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void UdpEchoServer::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Application::DoDispose (); } void UdpEchoServer::StartApplication (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_socket) { @@ -85,7 +85,7 @@ UdpEchoServer::StartApplication (void) void UdpEchoServer::StopApplication () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_socket) { @@ -100,8 +100,7 @@ UdpEchoServer::Receive( Ptr packet, const Address &from) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << socket << packet << from); + NS_LOG_FUNCTION (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h index 860849fab..e0f55b4cd 100644 --- a/src/applications/udp-echo/udp-echo-server.h +++ b/src/applications/udp-echo/udp-echo-server.h @@ -29,6 +29,11 @@ namespace ns3 { class Socket; class Packet; +/** + * \brief A Udp Echo server + * + * Every packet received is sent back. + */ class UdpEchoServer : public Application { public: diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 6e242e97c..4c5efe725 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -461,6 +461,40 @@ Buffer::AddAtEnd (uint32_t end) NS_ASSERT (CheckInternalState ()); } +void +Buffer::AddAtEnd (const Buffer &o) +{ + if (m_end == m_zeroAreaEnd && + o.m_start == o.m_zeroAreaStart && + o.m_zeroAreaEnd - o.m_zeroAreaStart > 0) + { + /** + * This is an optimization which kicks in when + * we attempt to aggregate two buffers which contain + * adjacent zero areas. + */ + uint32_t zeroSize = o.m_zeroAreaEnd - o.m_zeroAreaStart; + m_zeroAreaEnd += zeroSize; + m_end = m_zeroAreaEnd; + uint32_t endData = o.m_end - o.m_zeroAreaEnd; + AddAtEnd (endData); + Buffer::Iterator dst = End (); + dst.Prev (endData); + Buffer::Iterator src = o.End (); + src.Prev (endData); + dst.Write (src, o.End ()); + return; + } + Buffer dst = CreateFullCopy (); + Buffer src = o.CreateFullCopy (); + + dst.AddAtEnd (src.GetSize ()); + Buffer::Iterator destStart = dst.End (); + destStart.Prev (src.GetSize ()); + destStart.Write (src.Begin (), src.End ()); + *this = dst; +} + void Buffer::RemoveAtStart (uint32_t start) { @@ -544,14 +578,6 @@ Buffer Buffer::CreateFragment (uint32_t start, uint32_t length) const { NS_ASSERT (CheckInternalState ()); - uint32_t zeroStart = m_zeroAreaStart - m_start; - uint32_t zeroEnd = zeroStart + m_zeroAreaEnd; - if (m_zeroAreaEnd != 0 && - start + length > zeroStart && - start <= zeroEnd) - { - TransformIntoRealBuffer (); - } Buffer tmp = *this; tmp.RemoveAtStart (start); tmp.RemoveAtEnd (GetSize () - (start + length)); @@ -563,7 +589,7 @@ Buffer Buffer::CreateFullCopy (void) const { NS_ASSERT (CheckInternalState ()); - if (m_zeroAreaEnd != 0) + if (m_zeroAreaEnd - m_zeroAreaStart != 0) { Buffer tmp; tmp.AddAtStart (m_zeroAreaEnd - m_zeroAreaStart); @@ -1331,6 +1357,21 @@ BufferTest::RunTests (void) NS_TEST_ASSERT (memcmp (inputBuffer.PeekData (), outputBuffer.PeekData (), chunkSize) == 0); } + buffer = Buffer (5); + buffer.AddAtEnd (2); + i = buffer.End (); + i.Prev (2); + i.WriteU8 (0); + i.WriteU8 (0x66); + ENSURE_WRITTEN_BYTES (buffer, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + Buffer frag0 = buffer.CreateFragment (0, 2); + ENSURE_WRITTEN_BYTES (frag0, 2, 0x00, 0x00); + Buffer frag1 = buffer.CreateFragment (2, 5); + ENSURE_WRITTEN_BYTES (frag1, 5, 0x00, 0x00, 0x00, 0x00, 0x66); + frag0.AddAtEnd (frag1); + ENSURE_WRITTEN_BYTES (buffer, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + ENSURE_WRITTEN_BYTES (frag0, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + return result; } diff --git a/src/common/buffer.h b/src/common/buffer.h index e2b9a0d53..3f8409aff 100644 --- a/src/common/buffer.h +++ b/src/common/buffer.h @@ -410,6 +410,8 @@ public: * pointing to this Buffer. */ void AddAtEnd (uint32_t end); + + void AddAtEnd (const Buffer &o); /** * \param start size to remove * diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 595565bf1..90a81ace8 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -89,6 +89,11 @@ private: std::ostream &operator << (std::ostream &os, const DataRate &rate); std::istream &operator >> (std::istream &is, DataRate &rate); +/** + * \class ns3::DataRateValue + * \brief hold objects of type ns3::DataRate + */ + ATTRIBUTE_HELPER_HEADER_2 (DataRate); /** diff --git a/src/common/error-model.cc b/src/common/error-model.cc index 4796b473b..77b5854ef 100644 --- a/src/common/error-model.cc +++ b/src/common/error-model.cc @@ -42,7 +42,7 @@ TypeId ErrorModel::GetTypeId (void) static TypeId tid = TypeId ("ns3::ErrorModel") .SetParent () .AddAttribute ("IsEnabled", "Whether this ErrorModel is enabled or not.", - Boolean (true), + BooleanValue (true), MakeBooleanAccessor (&ErrorModel::m_enable), MakeBooleanChecker ()) ; @@ -52,18 +52,18 @@ TypeId ErrorModel::GetTypeId (void) ErrorModel::ErrorModel () : m_enable (true) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } ErrorModel::~ErrorModel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } bool ErrorModel::IsCorrupt (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); bool result; // Insert any pre-conditions here result = DoCorrupt (p); @@ -74,28 +74,28 @@ ErrorModel::IsCorrupt (Ptr p) void ErrorModel::Reset (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); DoReset (); } void ErrorModel::Enable (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_enable = true; } void ErrorModel::Disable (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_enable = false; } bool ErrorModel::IsEnabled (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_enable; } @@ -111,17 +111,17 @@ TypeId RateErrorModel::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("ErrorUnit", "The error unit", - Enum (EU_BYTE), + EnumValue (EU_BYTE), MakeEnumAccessor (&RateErrorModel::m_unit), MakeEnumChecker (EU_BYTE, "EU_BYTE", EU_PKT, "EU_PKT", EU_BIT, "EU_BIT")) .AddAttribute ("ErrorRate", "The error rate.", - Double (0.0), + DoubleValue (0.0), MakeDoubleAccessor (&RateErrorModel::m_rate), MakeDoubleChecker ()) .AddAttribute ("RanVar", "The decision variable attached to this error model.", - UniformVariable (0.0, 1.0), + RandomVariableValue (UniformVariable (0.0, 1.0)), MakeRandomVariableAccessor (&RateErrorModel::m_ranvar), MakeRandomVariableChecker ()) ; @@ -131,53 +131,53 @@ TypeId RateErrorModel::GetTypeId (void) RateErrorModel::RateErrorModel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } RateErrorModel::~RateErrorModel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } enum ErrorUnit RateErrorModel::GetUnit (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_unit; } void RateErrorModel::SetUnit (enum ErrorUnit error_unit) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_unit = error_unit; } double RateErrorModel::GetRate (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_rate; } void RateErrorModel::SetRate (double rate) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_rate = rate; } void RateErrorModel::SetRandomVariable (const RandomVariable &ranvar) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_ranvar = ranvar; } bool RateErrorModel::DoCorrupt (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_enable) { return false; @@ -200,14 +200,14 @@ RateErrorModel::DoCorrupt (Ptr p) bool RateErrorModel::DoCorruptPkt (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return (m_ranvar.GetValue () < m_rate); } bool RateErrorModel::DoCorruptByte (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // compute pkt error rate, assume uniformly distributed byte error double per = 1 - pow (1.0 - m_rate, p->GetSize ()); return (m_ranvar.GetValue () < per); @@ -216,7 +216,7 @@ RateErrorModel::DoCorruptByte (Ptr p) bool RateErrorModel::DoCorruptBit(Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // 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); @@ -225,7 +225,7 @@ RateErrorModel::DoCorruptBit(Ptr p) void RateErrorModel::DoReset (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); /* re-initialize any state; no-op for now */ } @@ -246,25 +246,25 @@ TypeId ListErrorModel::GetTypeId (void) ListErrorModel::ListErrorModel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } ListErrorModel::~ListErrorModel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } std::list ListErrorModel::GetList (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_packetList; } void ListErrorModel::SetList (const std::list &packetlist) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_packetList = packetlist; } @@ -274,7 +274,7 @@ ListErrorModel::SetList (const std::list &packetlist) bool ListErrorModel::DoCorrupt (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_enable) { return false; @@ -294,7 +294,7 @@ ListErrorModel::DoCorrupt (Ptr p) void ListErrorModel::DoReset (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_packetList.clear(); } diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index 103061d81..0582577ef 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -649,7 +649,7 @@ PacketMetadata::DoAddHeader (uint32_t uid, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAMS ("uid=" << uid << "size=" << size << ""); + NS_LOG_FUNCTION ("uid=" << uid << "size=" << size << ""); struct PacketMetadata::SmallItem item; item.next = m_head; @@ -670,7 +670,7 @@ PacketMetadata::RemoveHeader (const Header &header, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_FUNCTION ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; struct PacketMetadata::ExtraItem extraItem; uint32_t read = ReadItems (m_head, &item, &extraItem); @@ -708,7 +708,7 @@ PacketMetadata::AddTrailer (const Trailer &trailer, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_FUNCTION ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; item.next = 0xffff; item.prev = m_tail; @@ -728,7 +728,7 @@ PacketMetadata::RemoveTrailer (const Trailer &trailer, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_FUNCTION ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; struct PacketMetadata::ExtraItem extraItem; uint32_t read = ReadItems (m_tail, &item, &extraItem); diff --git a/src/common/packet.cc b/src/common/packet.cc index 0ad8fb508..1e980c351 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -159,14 +159,7 @@ Packet::RemoveTrailer (Trailer &trailer) void Packet::AddAtEnd (Ptr packet) { - Buffer src = packet->m_buffer.CreateFullCopy (); - Buffer dst = m_buffer.CreateFullCopy (); - - dst.AddAtEnd (src.GetSize ()); - Buffer::Iterator destStart = dst.End (); - destStart.Prev (src.GetSize ()); - destStart.Write (src.Begin (), src.End ()); - m_buffer = dst; + m_buffer.AddAtEnd (packet->m_buffer); /** * XXX: we might need to merge the tag list of the * other packet into the current packet. diff --git a/src/contrib/config-store.cc b/src/contrib/config-store.cc new file mode 100644 index 000000000..b07fb5282 --- /dev/null +++ b/src/contrib/config-store.cc @@ -0,0 +1,205 @@ +#include "config-store.h" +#include "ns3/string.h" +#include "ns3/config.h" +#include "ns3/object-vector.h" +#include "ns3/pointer.h" +#include "ns3/log.h" +#include +#include +#include +#include + +NS_LOG_COMPONENT_DEFINE ("ConfigStore"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (ConfigStore); + +TypeId +ConfigStore::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::ConfigStore") + .SetParent () + .AddAttribute ("LoadFilename", + "The file where the configuration should be loaded from.", + StringValue (""), + MakeStringAccessor (&ConfigStore::m_loadFilename), + MakeStringChecker ()) + .AddAttribute ("StoreFilename", + "The file where the configuration should be stored to.", + StringValue (""), + MakeStringAccessor (&ConfigStore::m_storeFilename), + MakeStringChecker ()) + ; + return tid; +} +TypeId +ConfigStore::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + + +ConfigStore::ConfigStore () +{ + ObjectBase::ConstructSelf (AttributeList ()); +} + +void +ConfigStore::LoadFrom (std::string filename) +{ + std::ifstream is; + is.open (filename.c_str (), std::ios::in); + std::string path, value; + while (is.good()) + { + is >> path >> value; + NS_LOG_DEBUG (path << "=" << value); + Config::Set (path, StringValue (value)); + } +} +void +ConfigStore::StoreTo (std::string filename) +{ + std::ofstream os; + os.open (filename.c_str (), std::ios::out); + for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i) + { + Ptr object = Config::GetRootNamespaceObject (i); + Store (os, object); + } + os.close (); + NS_ASSERT (m_currentPath.empty ()); + NS_ASSERT (m_examined.empty ()); + exit (0); +} + +bool +ConfigStore::IsExamined (Ptr object) +{ + for (uint32_t i = 0; i < m_examined.size (); ++i) + { + if (object == m_examined[i]) + { + return true; + } + } + return false; +} + +std::string +ConfigStore::GetCurrentPath (std::string attr) const +{ + std::ostringstream oss; + for (uint32_t i = 0; i < m_currentPath.size (); ++i) + { + oss << "/" << m_currentPath[i]; + } + oss << "/" << attr; + return oss.str (); +} + +void +ConfigStore::Store (std::ostream &os, Ptr object) +{ + if (IsExamined (object)) + { + return; + } + TypeId tid = object->GetInstanceTypeId (); + m_currentPath.push_back ("$" + tid.GetName ()); + NS_LOG_DEBUG ("store " << tid.GetName ()); + for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) + { + Ptr checker = tid.GetAttributeChecker (i); + const PointerChecker *ptrChecker = dynamic_cast (PeekPointer (checker)); + if (ptrChecker != 0) + { + NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i)); + PointerValue ptr; + object->GetAttribute (tid.GetAttributeName (i), ptr); + Ptr tmp = ptr.Get (); + if (tmp != 0) + { + m_currentPath.push_back (tid.GetAttributeName (i)); + m_examined.push_back (object); + Store (os, tmp); + m_examined.pop_back (); + m_currentPath.pop_back (); + } + continue; + } + // attempt to cast to an object vector. + const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (checker)); + if (vectorChecker != 0) + { + NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i)); + ObjectVectorValue vector; + object->GetAttribute (tid.GetAttributeName (i), vector); + for (uint32_t j = 0; j < vector.GetN (); ++j) + { + NS_LOG_DEBUG ("vector attribute item " << j); + Ptr tmp = vector.Get (j); + std::ostringstream oss; + oss << tid.GetAttributeName (i) << "/" << j; + m_currentPath.push_back (oss.str ()); + m_examined.push_back (object); + Store (os, tmp); + m_examined.pop_back (); + m_currentPath.pop_back (); + } + continue; + } + uint32_t flags = tid.GetAttributeFlags (i); + Ptr accessor = tid.GetAttributeAccessor (i); + if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () && + (flags & TypeId::ATTR_SET) && accessor->HasSetter ()) + { + StringValue str; + object->GetAttribute (tid.GetAttributeName (i), str); + os << GetCurrentPath (tid.GetAttributeName (i)) << " " << str.Get () << std::endl; + } + else + { + NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i)); + } + } + Object::AggregateIterator iter = object->GetAggregateIterator (); + bool recursiveAggregate = false; + while (iter.HasNext ()) + { + Ptr tmp = iter.Next (); + if (IsExamined (tmp)) + { + recursiveAggregate = true; + } + } + if (!recursiveAggregate) + { + iter = object->GetAggregateIterator (); + while (iter.HasNext ()) + { + Ptr tmp = iter.Next (); + m_examined.push_back (object); + Store (os, tmp); + m_examined.pop_back (); + } + } + m_currentPath.pop_back (); +} + + +void +ConfigStore::Configure (void) +{ + if (m_loadFilename != "") + { + LoadFrom (m_loadFilename); + } + if (m_storeFilename != "") + { + StoreTo (m_storeFilename); + } +} + +} // namespace ns3 diff --git a/src/contrib/config-store.h b/src/contrib/config-store.h new file mode 100644 index 000000000..03501cfc6 --- /dev/null +++ b/src/contrib/config-store.h @@ -0,0 +1,44 @@ +#ifndef CONFIG_STORE_H +#define CONFIG_STORE_H + +#include "ns3/object-base.h" +#include "ns3/object.h" +#include + +namespace ns3 { + +/** + * \brief Store and load simulation attribute configuration + * + */ +class ConfigStore : public ObjectBase +{ +public: + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + + ConfigStore (); + + /** + * Depending on which attribute was set: + * - Store simulation configuration in file and exit + * - Load simulation configuration from file and proceed. + */ + void Configure (void); + +private: + void LoadFrom (std::string filename); + void StoreTo (std::string filename); + void Store (std::ostream &os, Ptr object); + bool IsExamined (Ptr object); + std::string GetCurrentPath (std::string attr) const; + + std::string m_loadFilename; + std::string m_storeFilename; + std::vector > m_examined; + std::vector m_currentPath; +}; + +} // namespace ns3 + +#endif /* CONFIG_STORE_H */ diff --git a/src/contrib/wscript b/src/contrib/wscript index 223077d38..557242867 100644 --- a/src/contrib/wscript +++ b/src/contrib/wscript @@ -6,6 +6,7 @@ def build(bld): 'event-garbage-collector.cc', 'gnuplot.cc', 'delay-jitter-estimation.cc', + 'config-store.cc', ] headers = bld.create_obj('ns3header') @@ -14,4 +15,5 @@ def build(bld): 'event-garbage-collector.h', 'gnuplot.h', 'delay-jitter-estimation.h', + 'config-store.h', ] diff --git a/src/core/attribute-accessor-helper.h b/src/core/attribute-accessor-helper.h index c77f595e2..1e0223b09 100644 --- a/src/core/attribute-accessor-helper.h +++ b/src/core/attribute-accessor-helper.h @@ -48,8 +48,8 @@ class AccessorHelper : public AttributeAccessor public: AccessorHelper () {} - virtual bool Set (ObjectBase * object, Attribute val) const { - const U *value = val.DynCast (); + virtual bool Set (ObjectBase * object, const AttributeValue & val) const { + const U *value = dynamic_cast (&val); if (value == 0) { return false; @@ -62,8 +62,8 @@ public: return DoSet (obj, value); } - virtual bool Get (const ObjectBase * object, Attribute val) const { - U *value = val.DynCast (); + virtual bool Get (const ObjectBase * object, AttributeValue &val) const { + U *value = dynamic_cast (&val); if (value == 0) { return false; @@ -76,7 +76,6 @@ public: return DoGet (obj, value); } - private: virtual bool DoSet (T *object, const U *v) const = 0; virtual bool DoGet (const T *object, U *v) const = 0; @@ -102,6 +101,12 @@ DoMakeAccessorHelperOne (U T::*memberVariable) v->Set (object->*m_memberVariable); return true; } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return true; + } U T::*m_memberVariable; }; @@ -127,6 +132,12 @@ DoMakeAccessorHelperOne (U (T::*getter) (void) const) v->Set ((object->*m_getter) ()); return true; } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return false; + } U (T::*m_getter) (void) const; }; return Ptr (new MemberMethod (getter), false); @@ -152,6 +163,12 @@ DoMakeAccessorHelperOne (void (T::*setter) (U)) virtual bool DoGet (const T *object, V *v) const { return false; } + virtual bool HasGetter (void) const { + return false; + } + virtual bool HasSetter (void) const { + return true; + } void (T::*m_setter) (U); }; return Ptr (new MemberMethod (setter), false); @@ -180,6 +197,12 @@ DoMakeAccessorHelperTwo (void (T::*setter) (U), v->Set ((object->*m_getter) ()); return true; } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return true; + } void (T::*m_setter) (U); V (T::*m_getter) (void) const; }; diff --git a/src/core/attribute-helper.h b/src/core/attribute-helper.h index 6a83d1df8..1b31326b0 100644 --- a/src/core/attribute-helper.h +++ b/src/core/attribute-helper.h @@ -29,28 +29,40 @@ namespace ns3 { template Ptr -MakeSimpleAttributeChecker (std::string name) +MakeSimpleAttributeChecker (std::string name, std::string underlying) { struct SimpleAttributeChecker : public BASE { - virtual bool Check (Attribute value) const { - return value.DynCast () != 0; + virtual bool Check (const AttributeValue &value) const { + return dynamic_cast (&value) != 0; } - virtual std::string GetType (void) const { + virtual std::string GetValueTypeName (void) const { return m_type; } - virtual bool HasTypeConstraints (void) const { - return false; + virtual bool HasUnderlyingTypeInformation (void) const { + return true; } - virtual std::string GetTypeConstraints (void) const { - return ""; + virtual std::string GetUnderlyingTypeInformation (void) const { + return m_underlying; } - virtual Attribute Create (void) const { - return Attribute::Create (); + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const T *src = dynamic_cast (&source); + T *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; } std::string m_type; + std::string m_underlying; } *checker = new SimpleAttributeChecker (); checker->m_type = name; + checker->m_underlying = underlying; return Ptr (checker, false); } @@ -98,6 +110,22 @@ MakeSimpleAttributeChecker (std::string name) return MakeAccessorHelper (a1, a2); \ } +#define ATTRIBUTE_VALUE_DEFINE_WITH_NAME(type,name) \ + class name##Value : public AttributeValue \ + { \ + public: \ + name##Value (); \ + name##Value (const type &value); \ + void Set (const type &value); \ + type Get (void) const; \ + virtual Ptr Copy (void) const; \ + virtual std::string SerializeToString (Ptr checker) const; \ + virtual bool DeserializeFromString (std::string value, Ptr checker); \ + private: \ + type m_value; \ + }; + + /** * \ingroup AttributeHelper * \param type the name of the class. @@ -106,21 +134,8 @@ MakeSimpleAttributeChecker (std::string name) * This macro is typically invoked in a class header. */ #define ATTRIBUTE_VALUE_DEFINE(type) \ - class type##Value : public AttributeValue \ - { \ - public: \ - type##Value (); \ - type##Value (const type &value); \ - void Set (const type &value); \ - type Get (void) const; \ - virtual Attribute Copy (void) const; \ - virtual std::string SerializeToString (Ptr checker) const; \ - virtual bool DeserializeFromString (std::string value, Ptr checker); \ - type##Value (Attribute value); \ - operator Attribute () const; \ - private: \ - type m_value; \ - }; + ATTRIBUTE_VALUE_DEFINE_WITH_NAME (type,type) + /** * \ingroup AttributeHelper @@ -130,9 +145,7 @@ MakeSimpleAttributeChecker (std::string name) * from instances of type Attribute. * Typically invoked from xxx.h. */ -#define ATTRIBUTE_CONVERTER_DEFINE(type) \ - type (Attribute value); \ - operator Attribute () const; +#define ATTRIBUTE_CONVERTER_DEFINE(type) /** * \ingroup AttributeHelper @@ -146,42 +159,34 @@ MakeSimpleAttributeChecker (std::string name) class type##Checker : public AttributeChecker {}; \ Ptr Make##type##Checker (void); \ -/** - * \ingroup AttributeHelper - * \param type the name of the class - * - * This macro implements the XXXValue class (without the - * XXXValue::SerializeToString and XXXValue::DeserializeFromString - * methods). - * Typically invoked from xxx.cc. - */ -#define ATTRIBUTE_VALUE_IMPLEMENT_NO_SERIALIZE(type) \ - type##Value::type##Value () \ + +#define ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type,name) \ + name##Value::name##Value () \ : m_value () {} \ - type##Value::type##Value (const type &value) \ + name##Value::name##Value (const type &value) \ : m_value (value) {} \ - void type##Value::Set (const type &v) { \ + void name##Value::Set (const type &v) { \ m_value = v; \ } \ - type type##Value::Get (void) const { \ + type name##Value::Get (void) const { \ return m_value; \ } \ - Attribute \ - type##Value::Copy (void) const { \ - return Attribute::Create (*this); \ + Ptr \ + name##Value::Copy (void) const { \ + return ns3::Create (*this); \ + } \ + std::string \ + name##Value::SerializeToString (Ptr checker) const { \ + std::ostringstream oss; \ + oss << m_value; \ + return oss.str (); \ } \ - type##Value::type##Value (Attribute value) \ - { \ - type##Value *v = value.DynCast (); \ - if (v == 0) \ - { \ - NS_FATAL_ERROR ("Unexpected type of value. Expected \"" << #type << "Value\""); \ - } \ - m_value = v->Get (); \ - } \ - type##Value::operator Attribute () const \ - { \ - return Attribute::Create (*this); \ + bool \ + name##Value::DeserializeFromString (std::string value, Ptr checker) { \ + std::istringstream iss; \ + iss.str (value); \ + iss >> m_value; \ + return !iss.bad () && !iss.fail (); \ } /** @@ -194,20 +199,8 @@ MakeSimpleAttributeChecker (std::string name) * Typically invoked from xxx.cc. */ #define ATTRIBUTE_VALUE_IMPLEMENT(type) \ - std::string \ - type##Value::SerializeToString (Ptr checker) const { \ - std::ostringstream oss; \ - oss << m_value; \ - return oss.str (); \ - } \ - bool \ - type##Value::DeserializeFromString (std::string value, Ptr checker) { \ - std::istringstream iss; \ - iss.str (value); \ - iss >> m_value; \ - return !iss.bad () && !iss.fail (); \ - } \ - ATTRIBUTE_VALUE_IMPLEMENT_NO_SERIALIZE (type) + ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(type,type) + /** * \ingroup AttributeHelper @@ -219,9 +212,16 @@ MakeSimpleAttributeChecker (std::string name) #define ATTRIBUTE_CHECKER_IMPLEMENT(type) \ Ptr Make##type##Checker (void) \ { \ - return MakeSimpleAttributeChecker (#type); \ + return MakeSimpleAttributeChecker (#type "Value", #type); \ } \ +#define ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME(type,name) \ + Ptr Make##type##Checker (void) \ + { \ + return MakeSimpleAttributeChecker (#type "Value", name); \ + } \ + + /** * \ingroup AttributeHelper * \param type the name of the class @@ -229,20 +229,7 @@ MakeSimpleAttributeChecker (std::string name) * This macro implements the conversion operators to and from * instances of type Attribute. Typically invoked from xxx.cc. */ -#define ATTRIBUTE_CONVERTER_IMPLEMENT(type) \ - type::type (Attribute value) \ - { \ - const type##Value *v = value.DynCast (); \ - if (v == 0) \ - { \ - NS_FATAL_ERROR ("Unexpected type of value. Expected \"" << #type << "Value\""); \ - } \ - *this = v->Get (); \ - } \ - type::operator Attribute () const \ - { \ - return Attribute::Create (*this); \ - } +#define ATTRIBUTE_CONVERTER_IMPLEMENT(type) /** @@ -252,8 +239,7 @@ MakeSimpleAttributeChecker (std::string name) * This macro should be invoked from a public section of the class * declaration. */ -#define ATTRIBUTE_HELPER_HEADER_1(type) \ - ATTRIBUTE_CONVERTER_DEFINE (type) +#define ATTRIBUTE_HELPER_HEADER_1(type) /** * \ingroup AttributeHelper diff --git a/src/core/attribute-list.cc b/src/core/attribute-list.cc index c32ad4d91..2ec595d3a 100644 --- a/src/core/attribute-list.cc +++ b/src/core/attribute-list.cc @@ -36,7 +36,7 @@ AttributeList::AttributeList (const AttributeList &o) { struct Attr attr; attr.checker = i->checker; - attr.value = i->value.Copy (); + attr.value = i->value->Copy (); m_attributes.push_back (attr); } } @@ -48,7 +48,7 @@ AttributeList::operator = (const AttributeList &o) { struct Attr attr; attr.checker = i->checker; - attr.value = i->value.Copy (); + attr.value = i->value->Copy (); m_attributes.push_back (attr); } return *this; @@ -59,7 +59,7 @@ AttributeList::~AttributeList () } void -AttributeList::Set (std::string name, Attribute value) +AttributeList::Set (std::string name, const AttributeValue &value) { struct TypeId::AttributeInfo info; bool ok = TypeId::LookupAttributeByFullName (name, &info); @@ -74,7 +74,7 @@ AttributeList::Set (std::string name, Attribute value) } } bool -AttributeList::SetFailSafe (std::string name, Attribute value) +AttributeList::SetFailSafe (std::string name, const AttributeValue &value) { struct TypeId::AttributeInfo info; bool ok = TypeId::LookupAttributeByFullName (name, &info); @@ -86,7 +86,7 @@ AttributeList::SetFailSafe (std::string name, Attribute value) return ok; } void -AttributeList::SetWithTid (TypeId tid, std::string name, Attribute value) +AttributeList::SetWithTid (TypeId tid, std::string name, const AttributeValue & value) { struct TypeId::AttributeInfo info; bool ok = tid.LookupAttributeByName (name, &info); @@ -102,7 +102,7 @@ AttributeList::SetWithTid (TypeId tid, std::string name, Attribute value) } void -AttributeList::DoSetOne (Ptr checker, Attribute value) +AttributeList::DoSetOne (Ptr checker, const AttributeValue &value) { // get rid of any previous value stored in this // vector of values. @@ -121,36 +121,38 @@ AttributeList::DoSetOne (Ptr checker, Attribute value) m_attributes.push_back (attr); } bool -AttributeList::DoSet (struct TypeId::AttributeInfo *info, Attribute value) +AttributeList::DoSet (struct TypeId::AttributeInfo *info, const AttributeValue &value) { if (info->checker == 0) { return false; } bool ok = info->checker->Check (value); + if (ok) + { + DoSetOne (info->checker, value); + return true; + } + + // attempt to convert to string. + const StringValue *str = dynamic_cast (&value); + if (str == 0) + { + return false; + } + // attempt to convert back to value. + Ptr v = info->checker->Create (); + ok = v->DeserializeFromString (str->Get (), info->checker); if (!ok) { - // attempt to convert to string. - const StringValue *str = value.DynCast (); - if (str == 0) - { - return false; - } - // attempt to convert back to value. - Attribute v = info->checker->Create (); - ok = v.DeserializeFromString (str->Get ().Get (), info->checker); - if (!ok) - { - return false; - } - ok = info->checker->Check (v); - if (!ok) - { - return false; - } - value = v; + return false; } - DoSetOne (info->checker, value); + ok = info->checker->Check (*v); + if (!ok) + { + return false; + } + DoSetOne (info->checker, *v); return true; } void @@ -187,10 +189,11 @@ std::string AttributeList::SerializeToString (void) const { std::ostringstream oss; - for (Attrs::const_iterator i = m_attributes.begin (); i != m_attributes.end (); i++) + for (Attrs::const_iterator i = m_attributes.begin (); i != m_attributes.end ();) { std::string name = LookupAttributeFullNameByChecker (i->checker); - oss << name << "=" << i->value.SerializeToString (i->checker); + oss << name << "=" << i->value->SerializeToString (i->checker); + i++; if (i != m_attributes.end ()) { oss << "|"; @@ -235,8 +238,8 @@ AttributeList::DeserializeFromString (std::string str) value = str.substr (equal+1, next - (equal+1)); cur++; } - Attribute val = info.checker->Create (); - bool ok = val.DeserializeFromString (value, info.checker); + Ptr val = info.checker->Create (); + bool ok = val->DeserializeFromString (value, info.checker); if (!ok) { // XXX invalid value @@ -244,7 +247,7 @@ AttributeList::DeserializeFromString (std::string str) } else { - DoSetOne (info.checker, val); + DoSetOne (info.checker, *val); } } } diff --git a/src/core/attribute-list.h b/src/core/attribute-list.h index 3531c5ed3..922a5dbaf 100644 --- a/src/core/attribute-list.h +++ b/src/core/attribute-list.h @@ -48,14 +48,14 @@ public: * value of that attribute. If any of these checks fails, * the program terminates with a message. */ - void Set (std::string name, Attribute value); + void Set (std::string name, const AttributeValue &value); /** * \param name the full name of the attribute to set * \param value the value to set * \returns true if the requested attribute exists and could be * stored, false otherwise. */ - bool SetFailSafe (std::string name, Attribute value); + bool SetFailSafe (std::string name, const AttributeValue &value); /** * \param tid the TypeId associated to this attribute * \param name the name (not full!) of the attribute @@ -66,7 +66,7 @@ public: * value of that attribute. If any of these checks fails, * the program terminates with a message. */ - void SetWithTid (TypeId tid, std::string name, Attribute value); + void SetWithTid (TypeId tid, std::string name, const AttributeValue &value); /** * Clear the content of this instance. @@ -92,7 +92,7 @@ private: friend class ObjectBase; struct Attr { Ptr checker; - Attribute value; + Ptr value; }; typedef std::vector Attrs; typedef Attrs::iterator Iterator; @@ -100,8 +100,8 @@ private: - bool DoSet (struct TypeId::AttributeInfo *info, Attribute param); - void DoSetOne (Ptr checker, Attribute param); + bool DoSet (struct TypeId::AttributeInfo *info, const AttributeValue ¶m); + void DoSetOne (Ptr checker, const AttributeValue ¶m); std::string LookupAttributeFullNameByChecker (Ptr checker) const; Attrs m_attributes; diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index 9a2a38a4a..e1c694a3d 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -30,6 +30,7 @@ #include "object-vector.h" #include "traced-value.h" #include "trace-source-accessor.h" +#include "pointer.h" namespace ns3 { @@ -37,7 +38,6 @@ class ValueClassTest { public: ValueClassTest () {} - ATTRIBUTE_HELPER_HEADER_1 (ValueClassTest); private: int m_v; }; @@ -90,7 +90,7 @@ public: class AttributeObjectTest : public Object { public: - enum TestEnum { + enum Test_e { TEST_A, TEST_B, TEST_C @@ -100,69 +100,65 @@ public: .SetParent () .HideFromDocumentation () .AddAttribute ("TestBoolName", "help text", - Boolean (false), + BooleanValue (false), MakeBooleanAccessor (&AttributeObjectTest::m_boolTest), MakeBooleanChecker ()) .AddAttribute ("TestBoolA", "help text", - Boolean (false), + BooleanValue (false), MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB, &AttributeObjectTest::DoGetTestB), MakeBooleanChecker ()) - .AddAttribute ("TestPtr", "help text", - Ptr (0), - MakePtrAccessor (&AttributeObjectTest::m_derived), - MakePtrChecker ()) .AddAttribute ("TestInt16", "help text", - Integer (-2), + IntegerValue (-2), MakeIntegerAccessor (&AttributeObjectTest::m_int16), MakeIntegerChecker ()) .AddAttribute ("TestInt16WithBounds", "help text", - Integer (-2), + IntegerValue (-2), MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds), MakeIntegerChecker (-5, 10)) .AddAttribute ("TestInt16SetGet", "help text", - Integer (6), + IntegerValue (6), MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16, &AttributeObjectTest::DoGetInt16), MakeIntegerChecker ()) .AddAttribute ("TestUint8", "help text", - Uinteger (1), + UintegerValue (1), MakeUintegerAccessor (&AttributeObjectTest::m_uint8), MakeUintegerChecker ()) .AddAttribute ("TestEnum", "help text", - Enum (TEST_A), + EnumValue (TEST_A), MakeEnumAccessor (&AttributeObjectTest::m_enum), MakeEnumChecker (TEST_A, "TestA", TEST_B, "TestB", TEST_C, "TestC")) .AddAttribute ("TestRandom", "help text", - ConstantVariable (1.0), + RandomVariableValue (ConstantVariable (1.0)), MakeRandomVariableAccessor (&AttributeObjectTest::m_random), MakeRandomVariableChecker ()) .AddAttribute ("TestFloat", "help text", - Double (-1.1), + DoubleValue (-1.1), MakeDoubleAccessor (&AttributeObjectTest::m_float), MakeDoubleChecker ()) .AddAttribute ("TestVector1", "help text", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("TestVector2", "help text", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN, &AttributeObjectTest::DoGetVector), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("IntegerTraceSource1", "help text", - Integer (-2), + IntegerValue (-2), MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1), MakeIntegerChecker ()) .AddAttribute ("IntegerTraceSource2", "help text", - Integer (-2), + IntegerValue (-2), MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc, &AttributeObjectTest::DoGetIntSrc), MakeIntegerChecker ()) .AddAttribute ("ValueClassSource", "help text", - ValueClassTest (), + ValueClassTestValue (ValueClassTest ()), MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc), MakeValueClassTestChecker ()) .AddTraceSource ("Source1", "help test", @@ -171,6 +167,10 @@ public: MakeTraceSourceAccessor (&AttributeObjectTest::m_cb)) .AddTraceSource ("ValueSource", "help text", MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc)) + .AddAttribute ("Pointer", "XXX", + PointerValue (), + MakePointerAccessor (&AttributeObjectTest::m_ptr), + MakePointerChecker ()) ; return tid; @@ -214,13 +214,12 @@ private: } bool m_boolTestA; bool m_boolTest; - Ptr m_derived; int16_t m_int16; int16_t m_int16WithBounds; int16_t m_int16SetGet; uint8_t m_uint8; float m_float; - enum TestEnum m_enum; + enum Test_e m_enum; RandomVariable m_random; std::vector > m_vector1; std::vector > m_vector2; @@ -228,25 +227,24 @@ private: TracedValue m_intSrc2; TracedCallback m_cb; TracedValue m_valueSrc; + Ptr m_ptr; }; -#define CHECK_GET_STR(p,name,value) \ - { \ - std::string expected = value; \ - std::string got; \ - bool ok = p->GetAttributeAsStringFailSafe (name, got); \ - NS_TEST_ASSERT (ok); \ - NS_TEST_ASSERT_EQUAL (got, expected); \ +#define CHECK_GET_STR(p,name,value) \ + { \ + std::string expected = value; \ + StringValue got; \ + bool ok = p->GetAttributeFailSafe (name, got); \ + NS_TEST_ASSERT (ok); \ + NS_TEST_ASSERT_EQUAL (got.Get (), expected); \ } #define CHECK_GET_PARAM(p,name,type,value) \ { \ const type expected = value; \ - type got = value; \ - Attribute v; \ - bool ok = p->GetAttributeFailSafe (name, v); \ + type got; \ + bool ok = p->GetAttributeFailSafe (name, got); \ NS_TEST_ASSERT (ok); \ - got = v; \ NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ()); \ } @@ -262,211 +260,199 @@ AttributeTest::RunTests (void) AttributeList params; Ptr p; - NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", String ("false"))); + NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"))); p = CreateObject (params); CHECK_GET_STR (p, "TestBoolName", "false"); - CHECK_GET_PARAM (p, "TestBoolName", Boolean, false); + CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", String ("true"))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", StringValue ("true"))); CHECK_GET_STR (p, "TestBoolName", "true"); - CHECK_GET_PARAM (p, "TestBoolName", Boolean, true); + CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", Boolean (false))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", BooleanValue (false))); CHECK_GET_STR (p, "TestBoolName", "false"); - CHECK_GET_PARAM (p, "TestBoolName", Boolean, false); + CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false); - p = CreateObject ("TestBoolName", String ("true")); + p = CreateObject ("TestBoolName", StringValue ("true")); CHECK_GET_STR (p, "TestBoolName", "true"); - CHECK_GET_PARAM (p, "TestBoolName", Boolean, true); + CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true); - p = CreateObject ("TestBoolName", Boolean (true)); + p = CreateObject ("TestBoolName", BooleanValue (true)); CHECK_GET_STR (p, "TestBoolName", "true"); - CHECK_GET_PARAM (p, "TestBoolName", Boolean, true); + CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", String ("false"))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("false"))); CHECK_GET_STR (p, "TestBoolA", "false"); - CHECK_GET_PARAM (p, "TestBoolA", Boolean, false); + CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, false); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", String ("true"))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("true"))); CHECK_GET_STR (p, "TestBoolA", "true"); - CHECK_GET_PARAM (p, "TestBoolA", Boolean, true); + CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, true); - Ptr derived = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (derived == 0); - derived = Create (); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestPtr", derived)); - Ptr stored = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (stored == derived); - Ptr storedBase = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (stored == storedBase); - Ptr x = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (x == 0); - - p = CreateObject ("TestPtr", Create ()); - NS_TEST_ASSERT (p != 0); - derived = 0; - derived = p->GetAttribute ("TestPtr"); - NS_TEST_ASSERT (derived != 0); - CHECK_GET_STR (p, "TestInt16", "-2"); - CHECK_GET_PARAM (p, "TestInt16", Integer, -2); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -2); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", String ("-5"))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", StringValue ("-5"))); CHECK_GET_STR (p, "TestInt16", "-5"); - CHECK_GET_PARAM (p, "TestInt16", Integer, -5); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -5); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", Integer (+2))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (+2))); CHECK_GET_STR (p, "TestInt16", "2"); - CHECK_GET_PARAM (p, "TestInt16", Integer, +2); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, +2); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", Integer (-32768))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (-32768))); CHECK_GET_STR (p, "TestInt16", "-32768"); - CHECK_GET_PARAM (p, "TestInt16", Integer, -32768); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", Integer (-32769))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (-32769))); CHECK_GET_STR (p, "TestInt16", "-32768"); - CHECK_GET_PARAM (p, "TestInt16", Integer, -32768); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", Integer (32767))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (32767))); CHECK_GET_STR (p, "TestInt16", "32767"); - CHECK_GET_PARAM (p, "TestInt16", Integer, 32767); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", Integer (32768))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (32768))); CHECK_GET_STR (p, "TestInt16", "32767"); - CHECK_GET_PARAM (p, "TestInt16", Integer, 32767); + CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", Integer (10))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10))); CHECK_GET_STR (p, "TestInt16WithBounds", "10"); - CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, 10); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", Integer (11))); + CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11))); CHECK_GET_STR (p, "TestInt16WithBounds", "10"); - CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, 10); + CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", Integer (-5))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5))); CHECK_GET_STR (p, "TestInt16WithBounds", "-5"); - CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, -5); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", Integer (-6))); + CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6))); CHECK_GET_STR (p, "TestInt16WithBounds", "-5"); - CHECK_GET_PARAM (p, "TestInt16WithBounds", Integer, -5); + CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5); CHECK_GET_STR (p, "TestInt16SetGet", "6"); - CHECK_GET_PARAM (p, "TestInt16SetGet", Integer, 6); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", Integer (0))); + CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 6); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", IntegerValue (0))); CHECK_GET_STR (p, "TestInt16SetGet", "0"); - CHECK_GET_PARAM (p, "TestInt16SetGet", Integer, 0); + CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 0); CHECK_GET_STR (p, "TestUint8", "1"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 1); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", Uinteger (0))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 1); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (0))); CHECK_GET_STR (p, "TestUint8", "0"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 0); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", Uinteger (255))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 0); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (255))); CHECK_GET_STR (p, "TestUint8", "255"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", String ("255"))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", StringValue ("255"))); CHECK_GET_STR (p, "TestUint8", "255"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", String ("256"))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("256"))); CHECK_GET_STR (p, "TestUint8", "255"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", String ("-1"))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("-1"))); CHECK_GET_STR (p, "TestUint8", "255"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", Uinteger ((uint64_t)-1))); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", UintegerValue ((uint64_t)-1))); CHECK_GET_STR (p, "TestUint8", "255"); - CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255); + CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255); CHECK_GET_STR (p, "TestFloat", "-1.1"); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", Double ((float)+2.3))); - CHECK_GET_PARAM (p, "TestFloat", Double, (float)+2.3); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)+2.3))); + CHECK_GET_PARAM (p, "TestFloat", DoubleValue, (float)+2.3); CHECK_GET_STR (p, "TestEnum", "TestA"); - CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_A); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", Enum (AttributeObjectTest::TEST_C))); + CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_A); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C))); CHECK_GET_STR (p, "TestEnum", "TestC"); - CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_C); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", String ("TestB"))); + CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_C); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", StringValue ("TestB"))); CHECK_GET_STR (p, "TestEnum", "TestB"); - CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", String ("TestD"))); + CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", StringValue ("TestD"))); CHECK_GET_STR (p, "TestEnum", "TestB"); - CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); - NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", Enum (5))); + CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B); + NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", EnumValue (5))); CHECK_GET_STR (p, "TestEnum", "TestB"); - CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B); + CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B); - RandomVariable ran = p->GetAttribute ("TestRandom"); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", UniformVariable (0.0, 1.0))); - NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", ConstantVariable (10.0))); + RandomVariableValue ran; + p->GetAttribute ("TestRandom", ran); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0.0, 1.0)))); + NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.0)))); { - ObjectVector vector = p->GetAttribute ("TestVector1"); + ObjectVectorValue vector; + p->GetAttribute ("TestVector1", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); p->AddToVector1 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); - vector = p->GetAttribute ("TestVector1"); + p->GetAttribute ("TestVector1", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); Ptr a = vector.Get (0); NS_TEST_ASSERT_UNEQUAL (a, 0); p->AddToVector1 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); - vector = p->GetAttribute ("TestVector1"); + p->GetAttribute ("TestVector1", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 2); } { - ObjectVector vector = p->GetAttribute ("TestVector2"); + ObjectVectorValue vector; + p->GetAttribute ("TestVector2", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); p->AddToVector2 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 0); - vector = p->GetAttribute ("TestVector2"); + p->GetAttribute ("TestVector2", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); Ptr a = vector.Get (0); NS_TEST_ASSERT_UNEQUAL (a, 0); p->AddToVector2 (); NS_TEST_ASSERT_EQUAL (vector.GetN (), 1); - vector = p->GetAttribute ("TestVector2"); + p->GetAttribute ("TestVector2", vector); NS_TEST_ASSERT_EQUAL (vector.GetN (), 2); } - NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", String ("true"))); + NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true"))); p = CreateObject (); - Boolean boolV = p->GetAttribute ("TestBoolName"); - NS_TEST_ASSERT_EQUAL (boolV, Boolean (true)); + BooleanValue boolV; + p->GetAttribute ("TestBoolName", boolV); + NS_TEST_ASSERT_EQUAL (boolV.Get (), true); - NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", String ("false"))); + NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"))); p = CreateObject (); - boolV = p->GetAttribute ("TestBoolName"); - NS_TEST_ASSERT_EQUAL (boolV, Boolean (false)); + p->GetAttribute ("TestBoolName", boolV); + NS_TEST_ASSERT_EQUAL (boolV.Get (), false); - Integer i = p->GetAttribute ("IntegerTraceSource1"); + IntegerValue i; + p->GetAttribute ("IntegerTraceSource1", i); NS_TEST_ASSERT_EQUAL (i.Get (), -2); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (+5))); - i = p->GetAttribute ("IntegerTraceSource1"); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (+5))); + p->GetAttribute ("IntegerTraceSource1", i); NS_TEST_ASSERT_EQUAL (i.Get (), +5); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (127))); - NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (128))); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (-128))); - NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (-129))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129))); - i = p->GetAttribute ("IntegerTraceSource2"); + p->GetAttribute ("IntegerTraceSource2", i); NS_TEST_ASSERT_EQUAL (i.Get (), -2); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", Integer (+5))); - i = p->GetAttribute ("IntegerTraceSource2"); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (+5))); + p->GetAttribute ("IntegerTraceSource2", i); NS_TEST_ASSERT_EQUAL (i.Get (), +5); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", Integer (127))); - NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", Integer (128))); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", Integer (-128))); - NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", Integer (-129))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128))); + NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129))); m_got1 = -2; - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (-1))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1))); NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this))); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (0))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0))); NS_TEST_ASSERT_EQUAL (m_got1, 0); NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this))); - NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", Integer (1))); + NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1))); NS_TEST_ASSERT_EQUAL (m_got1, 0); m_got2 = 4.3; @@ -481,8 +467,29 @@ AttributeTest::RunTests (void) NS_TEST_ASSERT_EQUAL (m_got2, 1.0); NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this))); - + PointerValue ptr; + p->GetAttribute ("Pointer", ptr); + Ptr derived = ptr.Get (); + NS_TEST_ASSERT (derived == 0); + derived = Create (); + NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", PointerValue (derived))); + p->GetAttribute ("Pointer", ptr); + Ptr stored = ptr.Get (); + NS_TEST_ASSERT (stored == derived); + p->GetAttribute ("Pointer", ptr); + Ptr storedBase = ptr.Get (); + NS_TEST_ASSERT (stored == storedBase); + p->GetAttribute ("Pointer", ptr); + Ptr x = ptr.Get (); + NS_TEST_ASSERT (x == 0); + + p = CreateObject ("Pointer", PointerValue (Create ())); + NS_TEST_ASSERT (p != 0); + derived = 0; + p->GetAttribute ("Pointer", ptr); + derived = ptr.Get (); + NS_TEST_ASSERT (derived != 0); return result; } diff --git a/src/core/attribute.cc b/src/core/attribute.cc index 453a05cb3..ac0590c95 100644 --- a/src/core/attribute.cc +++ b/src/core/attribute.cc @@ -27,164 +27,38 @@ NS_LOG_COMPONENT_DEFINE ("AttributeValue"); namespace ns3 { AttributeValue::AttributeValue () - : m_count (1) {} -AttributeValue::AttributeValue (const AttributeValue &o) - : m_count (1) -{} -AttributeValue & -AttributeValue::operator = (const AttributeValue &o) -{ - return *this; -} AttributeValue::~AttributeValue () {} -/*************************************************************** - * Big interesting warning. - * ------------------------ - * - * One might wonder why we re-implement a smart pointer below - * in the Attribute class. This is a very good question and the answer - * is unfortunately pretty complicated. - * - * 1) We could have requested the user to use Ptr and save us - * a lot of pain. This, however, does not work because our smart - * pointer needs a special constructor which can be used to convert - * objects of type Ptr into a PtrValue to hold the pointer. - * - * 2) We could have made the m_value member variable below a Ptr - * rather than store a raw pointer. This, however, does not work - * because this would mean that the constructor Attribute (AttributeValue *) - * should be morphed into Attribute (Ptr) which, unfortunately, - * would conflict with the template constructor Attribute (Ptr)... - * - * This is definitely not fun. - */ -Attribute::Attribute () - : m_value (0) -{} -Attribute::Attribute (const Attribute &o) - : m_value (o.m_value) -{ - if (m_value != 0) - { - m_value->m_count++; - NS_LOG_DEBUG ("this="< checker) +{ + return true; } -bool -PtrValueBase::DeserializeFromString (std::string value, Ptr checker) -{ - // XXX - return false; -} } // namespace ns3 diff --git a/src/core/attribute.h b/src/core/attribute.h index 687d772c0..7061f1a70 100644 --- a/src/core/attribute.h +++ b/src/core/attribute.h @@ -23,6 +23,7 @@ #include #include #include "ptr.h" +#include "ref-count-base.h" namespace ns3 { @@ -34,23 +35,20 @@ class ObjectBase; /** * \brief Hold a value for an Attribute. * - * Instances of this class are usually created by Attribute::Create<> and - * should always be wrapped into an Attribute object. + * Instances of this class should always be wrapped into an Attribute object. * Most subclasses of this base class are implemented by the * ATTRIBUTE_HELPER_* macros. */ -class AttributeValue +class AttributeValue : public RefCountBase { public: AttributeValue (); - AttributeValue (const AttributeValue &o); - AttributeValue &operator = (const AttributeValue &o); virtual ~AttributeValue (); /** * \returns a deep copy of this class, wrapped into an Attribute object. */ - virtual Attribute Copy (void) const = 0; + virtual Ptr Copy (void) const = 0; /** * \param checker the checker associated to the attribute * \returns a string representation of this value. @@ -75,80 +73,6 @@ public: * the EnumValue::SerializeToString code. */ virtual bool DeserializeFromString (std::string value, Ptr checker) = 0; -private: - friend class Attribute; - uint32_t m_count; -}; - -/** - * \brief an opaque wrapper around a value to set or retrieved - * from an attribute. - * - * This class is really a smart pointer to an instance of AttributeValue. - * Of course, the question is "why not use a Ptr" ?. The - * answer is long and complicated but the crux of the issue is that if we - * do not reproduce the smart pointer code in this class, we cannot provide - * transparent handling of Ptr values through the attribute system. - */ -class Attribute -{ -public: - Attribute (); - Attribute (const Attribute &o); - Attribute &operator = (const Attribute &o); - ~Attribute (); - - /** - * Forward to AttributeValue::Copy - */ - Attribute Copy (void) const; - /** - * Forward to AttributeValue::SerializeToString - */ - std::string SerializeToString (Ptr checker) const; - /** - * Forward to AttributeValue::DeserializeFromString - */ - bool DeserializeFromString (std::string value, Ptr checker); - - /** - * \returns a new Attribute object which wraps an instance of the requested - * subclass of AttributeValue. - */ - template - static Attribute Create (void); - /** - * \param a1 a value to pass through to the constructor of the class T. - * \returns a new Attribute object which wraps an instance of the requested - * subclass of AttributeValue. - */ - template - static Attribute Create (T1 a1); - - /** - * This method performs a dynamic_cast on the underlying AttributeValue. - * This method is typically used to implement conversion operators - * from the type Attribute. In most cases, these conversion operators - * will be generated for you by the ATTRIBUTE_HELPER_* macros. - * \returns the casted pointer. - */ - template - T DynCast (void) const; - - /** - * \param pointer a pointer to convert into an Attribute. - */ - template - Attribute (Ptr pointer); - /** - * \returns a pointer converted from this Attribute instance. - */ - template - operator Ptr (); - -private: - Attribute (AttributeValue *value); - AttributeValue *m_value; }; /** @@ -159,12 +83,10 @@ private: * of this base class are usually provided through the MakeAccessorHelper * template functions, hidden behind an ATTRIBUTE_HELPER_* macro. */ -class AttributeAccessor +class AttributeAccessor : public RefCountBase { public: AttributeAccessor (); - void Ref (void) const; - void Unref (void) const; virtual ~AttributeAccessor (); /** @@ -175,7 +97,7 @@ public: * This method expects that the caller has checked that the input value is * valid with AttributeChecker::Check. */ - virtual bool Set (ObjectBase * object, Attribute value) const = 0; + virtual bool Set (ObjectBase * object, const AttributeValue &value) const = 0; /** * \param object the object instance to get the value from * \param attribute a pointer to where the value should be set. @@ -185,9 +107,18 @@ public: * This method expects that the caller has checked that the input value is * valid with AttributeChecker::Check. */ - virtual bool Get (const ObjectBase * object, Attribute attribute) const = 0; -private: - mutable uint32_t m_count; + virtual bool Get (const ObjectBase * object, AttributeValue &attribute) const = 0; + + /** + * \return true if this accessor supports the Get operation, false + * otherwise. + */ + virtual bool HasGetter (void) const = 0; + /** + * \return true if this accessor supports the Set operation, false + * otherwise. + */ + virtual bool HasSetter (void) const = 0; }; /** @@ -202,12 +133,10 @@ private: * Most subclasses of this base class are implemented by the * ATTRIBUTE_HELPER_* macros. */ -class AttributeChecker +class AttributeChecker : public RefCountBase { public: AttributeChecker (); - void Ref (void) const; - void Unref (void) const; virtual ~AttributeChecker (); /** * \param value a pointer to the value to check @@ -215,10 +144,29 @@ public: * and if its value is within the requested range. Returns * false otherwise. */ - virtual bool Check (Attribute value) const = 0; - virtual std::string GetType (void) const = 0; - virtual bool HasTypeConstraints (void) const = 0; - virtual std::string GetTypeConstraints (void) const = 0; + virtual bool Check (const AttributeValue &value) const = 0; + /** + * \returns the c++ fully-qualified typename of the subclass + * of the ns3::AttributeValue base class which is associated + * to this checker. + * + * A typical return value here is FooValue where Foo is the name of the + * type being wrapped. + */ + virtual std::string GetValueTypeName (void) const = 0; + /** + * \returns true if this checker has information about the underlying + * C++ type, false otherwise. + * + * If this method returns false, the return value of the GetUnderlyingTypeInformation + * method cannot be relied upon. + */ + virtual bool HasUnderlyingTypeInformation (void) const = 0; + /** + * \returns a human-readable representation of information about + * the underlying C++ type. + */ + virtual std::string GetUnderlyingTypeInformation (void) const = 0; /** * \returns a new instance of an AttributeValue (wrapper in an Attribute * instance) which matches the type of the underlying attribute. @@ -226,314 +174,22 @@ public: * This method is typically used to create a temporary variable prior * to calling Attribute::DeserializeFromString. */ - virtual Attribute Create (void) const = 0; -private: - mutable uint32_t m_count; + virtual Ptr Create (void) const = 0; + + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const = 0; + }; -template -Ptr -MakePtrAccessor (Ptr T::*memberVariable); - -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr)); -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const); -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr), - Ptr (T::*getter) (void) const); -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const, - void (T::*setter) (Ptr)); - - - -class PtrChecker : public AttributeChecker {}; - -template -Ptr MakePtrChecker (void); - - - -} // namespace ns3 - -namespace ns3 { - -/******************************************************** - * The class used to access the pointer stored in a - * PtrValue AttributeValue instance. - ********************************************************/ - -class PtrValueBase : public AttributeValue +class EmptyAttributeValue : public AttributeValue { public: - virtual ObjectBase *PeekObjectBase (void) const = 0; - virtual bool SetObjectBase (ObjectBase *object) = 0; + EmptyAttributeValue (); +private: + virtual Ptr Copy (void) const; virtual std::string SerializeToString (Ptr checker) const; virtual bool DeserializeFromString (std::string value, Ptr checker); }; -/******************************************************** - * Store the content of a Ptr in a AttributeValue - ********************************************************/ - -namespace internal { - -template -class PtrValue : public PtrValueBase -{ -public: - PtrValue () - : m_pointer () {} - PtrValue (Ptr pointer) - : m_pointer (pointer) {} - - virtual ObjectBase *PeekObjectBase (void) const { - return PeekPointer (m_pointer); - } - virtual bool SetObjectBase (ObjectBase *object) { - T *ptr = dynamic_cast (object); - if (ptr == 0) - { - return false; - } - m_pointer = ptr; - return true; - } - virtual Attribute Copy (void) const { - return Attribute::Create > (*this); - } -private: - Ptr m_pointer; -}; - -template -class APtrChecker : public PtrChecker -{ - virtual bool Check (Attribute val) const { - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - if (value->PeekObjectBase () == 0) - { - return true; - } - T *ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - return true; - } - virtual std::string GetType (void) const { - // XXX: we should be able to return better information - return "Ptr<>"; - } - virtual bool HasTypeConstraints (void) const { - return false; - } - virtual std::string GetTypeConstraints (void) const { - return ""; - } - virtual Attribute Create (void) const { - return Attribute::Create > (); - } -}; - -/******************************************************** - * The Accessor associated to - * PtrValue - ********************************************************/ - -template -class PtrAccessor : public AttributeAccessor -{ -public: - virtual ~PtrAccessor () {} - virtual bool Set (ObjectBase * object, Attribute val) const { - T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - const PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - Ptr ptr = dynamic_cast (value->PeekObjectBase ()); - if (ptr == 0) - { - return false; - } - DoSet (obj, ptr); - return true; - } - virtual bool Get (const ObjectBase * object, Attribute val) const { - const T *obj = dynamic_cast (object); - if (obj == 0) - { - return false; - } - PtrValueBase *value = val.DynCast (); - if (value == 0) - { - return false; - } - return value->SetObjectBase (PeekPointer (DoGet (obj))); - } -private: - virtual void DoSet (T *object, Ptr value) const = 0; - virtual Ptr DoGet (const T *object) const = 0; -}; - -} // namespace internal - -/******************************************************** - * The implementation of the Attribute - * class template methods. - ********************************************************/ - -template -Attribute -Attribute::Create (void) -{ - return Attribute (new T ()); -} -template -Attribute -Attribute::Create (T1 a1) -{ - return Attribute (new T (a1)); -} - -template -T -Attribute::DynCast (void) const -{ - return dynamic_cast (m_value); -} - -template -Attribute::Attribute (Ptr pointer) - : m_value (new internal::PtrValue (pointer)) -{} -template -Attribute::operator Ptr () -{ - PtrValueBase *value = DynCast (); - if (value == 0) - { - return 0; - } - ObjectBase *objectBase = value->PeekObjectBase (); - T *obj = dynamic_cast (objectBase); - if (obj == 0) - { - return 0; - } - return obj; -} - - - -template -Ptr -MakePtrAccessor (Ptr T::*memberVariable) -{ - struct MemberVariable : public internal::PtrAccessor - { - Ptr T::*m_memberVariable; - virtual void DoSet (T *object, Ptr value) const { - (object->*m_memberVariable) = value; - } - virtual Ptr DoGet (const T *object) const { - return object->*m_memberVariable; - } - } *spec = new MemberVariable (); - spec->m_memberVariable = memberVariable; - return Ptr (spec, false); -} - -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr)) -{ - struct MemberMethod : public internal::PtrAccessor - { - void (T::*m_setter) (Ptr); - virtual void DoSet (T *object, Ptr value) const { - (object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return 0; - //return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_setter = setter; - return Ptr (spec, false); -} - -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const) -{ - struct MemberMethod : public internal::PtrAccessor - { - Ptr (T::*m_getter) (void) const; - virtual void DoSet (T *object, Ptr value) const { - //(object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_getter = getter; - return Ptr (spec, false); -} -template -Ptr -MakePtrAccessor (void (T::*setter) (Ptr), - Ptr (T::*getter) (void) const) -{ - return MakePtrAccessor (getter, setter); -} -template -Ptr -MakePtrAccessor (Ptr (T::*getter) (void) const, - void (T::*setter) (Ptr)) -{ - struct MemberMethod : public internal::PtrAccessor - { - void (T::*m_setter) (Ptr); - Ptr (T::*m_getter) (void) const; - virtual void DoSet (T *object, Ptr value) const { - (object->*m_setter) (value); - } - virtual Ptr DoGet (const T *object) const { - return (object->*m_getter) (); - } - } *spec = new MemberMethod (); - spec->m_setter = setter; - spec->m_getter = getter; - return Ptr (spec, false); -} - - - -template -Ptr -MakePtrChecker (void) -{ - return Create > (); -} - } // namespace ns3 #endif /* ATTRIBUTE_H */ diff --git a/src/core/boolean.cc b/src/core/boolean.cc index 46abc79f3..1f2a8848f 100644 --- a/src/core/boolean.cc +++ b/src/core/boolean.cc @@ -22,28 +22,28 @@ namespace ns3 { -Boolean::Boolean () +BooleanValue::BooleanValue () : m_value (false) {} -Boolean::Boolean (bool value) +BooleanValue::BooleanValue (bool value) : m_value (value) {} void -Boolean::Set (bool value) +BooleanValue::Set (bool value) { m_value = value; } bool -Boolean::Get (void) const +BooleanValue::Get (void) const { return m_value; } -Boolean::operator bool () const +BooleanValue::operator bool () const { return m_value; } -std::ostream & operator << (std::ostream &os, const Boolean &value) +std::ostream & operator << (std::ostream &os, const BooleanValue &value) { if (value.Get ()) { @@ -55,31 +55,48 @@ std::ostream & operator << (std::ostream &os, const Boolean &value) } return os; } -std::istream & operator >> (std::istream &is, Boolean &value) + +Ptr +BooleanValue::Copy (void) const { - std::string v; - is >> v; - if (v == "true" || - v == "1" || - v == "t") + return Create (*this); +} +std::string +BooleanValue::SerializeToString (Ptr checker) const +{ + if (m_value) { - value.Set (true); + return "true"; + } + else + { + return "false"; } - else if (v == "false" || - v == "0" || - v == "f") +} +bool +BooleanValue::DeserializeFromString (std::string value, Ptr checker) +{ + if (value == "true" || + value == "1" || + value == "t") { - value.Set (false); + m_value = true; + return true; + } + else if (value == "false" || + value == "0" || + value == "f") + { + m_value = false; + return true; } else { - is.setstate (std::ios_base::badbit); + return false; } - return is; } -ATTRIBUTE_CONVERTER_IMPLEMENT (Boolean); -ATTRIBUTE_VALUE_IMPLEMENT (Boolean); -ATTRIBUTE_CHECKER_IMPLEMENT (Boolean); + +ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (Boolean,"bool"); } // namespace ns3 diff --git a/src/core/boolean.h b/src/core/boolean.h index 74885e089..d4186b391 100644 --- a/src/core/boolean.h +++ b/src/core/boolean.h @@ -28,28 +28,30 @@ namespace ns3 { /** * \brief Hold a bool native type * + * \anchor bool + * * This class can be used to hold bool variables * which must go through the Attribute system. */ -class Boolean +class BooleanValue : public AttributeValue { public: - Boolean (); - Boolean (bool value); + BooleanValue (); + BooleanValue (bool value); void Set (bool value); bool Get (void) const; - + operator bool () const; - ATTRIBUTE_CONVERTER_DEFINE (Boolean); + virtual Ptr Copy (void) const; + virtual std::string SerializeToString (Ptr checker) const; + virtual bool DeserializeFromString (std::string value, Ptr checker); private: bool m_value; }; -std::ostream & operator << (std::ostream &os, const Boolean &value); -std::istream & operator >> (std::istream &is, Boolean &value); +std::ostream & operator << (std::ostream &os, const BooleanValue &value); -ATTRIBUTE_VALUE_DEFINE (Boolean); ATTRIBUTE_CHECKER_DEFINE (Boolean); ATTRIBUTE_ACCESSOR_DEFINE (Boolean); diff --git a/src/core/command-line.cc b/src/core/command-line.cc index eb2852623..63fc18657 100644 --- a/src/core/command-line.cc +++ b/src/core/command-line.cc @@ -21,6 +21,7 @@ #include "log.h" #include "config.h" #include "global-value.h" +#include "type-id.h" #include "string.h" #include @@ -41,7 +42,7 @@ CommandLine::Item::~Item () {} void -CommandLine::Parse (int &iargc, char *argv[]) const +CommandLine::Parse (int iargc, char *argv[]) const { int argc = iargc; for (argc--, argv++; argc > 0; argc--, argv++) @@ -109,8 +110,9 @@ CommandLine::PrintGlobals (void) const { std::cout << " --" << (*i)->GetName () << "=["; Ptr checker = (*i)->GetChecker (); - Attribute value = (*i)->GetValue (); - std::cout << value.SerializeToString (checker) << "]: " + StringValue v; + (*i)->GetValue (v); + std::cout << v.Get () << "]: " << (*i)->GetHelp () << std::endl; } exit (0); @@ -128,8 +130,8 @@ CommandLine::PrintAttributes (std::string type) const { std::cout << " --"< checker = tid.GetAttributeChecker (i); - Attribute initial = tid.GetAttributeInitialValue (i); - std::cout << initial.SerializeToString (checker) << "]: " + Ptr initial = tid.GetAttributeInitialValue (i); + std::cout << initial->SerializeToString (checker) << "]: " << tid.GetAttributeHelp (i) << std::endl; } exit (0); @@ -243,8 +245,8 @@ CommandLine::HandleArgument (std::string name, std::string value) const } } } - if (!Config::SetGlobalFailSafe (name, String (value)) - && !Config::SetDefaultFailSafe (name, String (value))) + if (!Config::SetGlobalFailSafe (name, StringValue (value)) + && !Config::SetDefaultFailSafe (name, StringValue (value))) { std::cerr << "Invalid command-line arguments: --"< @@ -125,7 +126,7 @@ public: void Resolve (Ptr root); private: void DoResolve (std::string path, Ptr root); - void DoArrayResolve (std::string path, const ObjectVector &vector); + void DoArrayResolve (std::string path, const ObjectVectorValue &vector); void DoResolveOne (Ptr object, std::string name); std::string GetResolvedPath (std::string name) const; virtual void DoOne (Ptr object, std::string path, std::string name) = 0; @@ -213,14 +214,13 @@ Resolver::DoResolve (std::string path, Ptr root) return; } // attempt to cast to a pointer checker. - const PtrChecker *ptr = dynamic_cast (PeekPointer (info.checker)); + const PointerChecker *ptr = dynamic_cast (PeekPointer (info.checker)); if (ptr != 0) { NS_LOG_DEBUG ("GetAttribute(ptr)="<. We really need to fix this by thinking seriously about our - // object hierarchy. - Ptr object = root->GetAttribute (item); + PointerValue ptr; + root->GetAttribute (item, ptr); + Ptr object = ptr.Get (); if (object == 0) { NS_LOG_ERROR ("Requested object name=\""< root) if (vectorChecker != 0) { NS_LOG_DEBUG ("GetAttribute(vector)="<GetAttribute (item); + ObjectVectorValue vector; + root->GetAttribute (item, vector); m_workStack.push_back (item); DoArrayResolve (pathLeft, vector); m_workStack.pop_back (); @@ -248,7 +249,7 @@ Resolver::DoResolve (std::string path, Ptr root) } void -Resolver::DoArrayResolve (std::string path, const ObjectVector &vector) +Resolver::DoArrayResolve (std::string path, const ObjectVectorValue &vector) { NS_ASSERT (path != ""); std::string::size_type pos = path.find ("/"); @@ -284,7 +285,7 @@ Resolver::DoArrayResolve (std::string path, const ObjectVector &vector) class ConfigImpl { public: - void Set (std::string path, Attribute value); + void Set (std::string path, const AttributeValue &value); void ConnectWithoutContext (std::string path, const CallbackBase &cb); void Connect (std::string path, const CallbackBase &cb); void DisconnectWithoutContext (std::string path, const CallbackBase &cb); @@ -292,6 +293,9 @@ public: void RegisterRootNamespaceObject (Ptr obj); void UnregisterRootNamespaceObject (Ptr obj); + + uint32_t GetRootNamespaceObjectN (void) const; + Ptr GetRootNamespaceObject (uint32_t i) const; private: typedef std::vector > Roots; @@ -299,19 +303,19 @@ private: }; void -ConfigImpl::Set (std::string path, Attribute value) +ConfigImpl::Set (std::string path, const AttributeValue &value) { class SetResolver : public Resolver { public: - SetResolver (std::string path, Attribute value) + SetResolver (std::string path, const AttributeValue &value) : Resolver (path), - m_value (value) {} + m_value (value.Copy ()) {} private: virtual void DoOne (Ptr object, std::string path, std::string name) { - object->SetAttribute (name, m_value); + object->SetAttribute (name, *m_value); } - Attribute m_value; + Ptr m_value; } resolver = SetResolver (path, value); for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) { @@ -417,26 +421,36 @@ ConfigImpl::UnregisterRootNamespaceObject (Ptr obj) } } +uint32_t +ConfigImpl::GetRootNamespaceObjectN (void) const +{ + return m_roots.size (); +} +Ptr +ConfigImpl::GetRootNamespaceObject (uint32_t i) const +{ + return m_roots[i]; +} namespace Config { -void Set (std::string path, Attribute value) +void Set (std::string path, const AttributeValue &value) { Singleton::Get ()->Set (path, value); } -void SetDefault (std::string name, Attribute value) +void SetDefault (std::string name, const AttributeValue &value) { AttributeList::GetGlobal ()->Set (name, value); } -bool SetDefaultFailSafe (std::string name, Attribute value) +bool SetDefaultFailSafe (std::string name, const AttributeValue &value) { return AttributeList::GetGlobal ()->SetFailSafe (name, value); } -void SetGlobal (std::string name, Attribute value) +void SetGlobal (std::string name, const AttributeValue &value) { GlobalValue::Bind (name, value); } -bool SetGlobalFailSafe (std::string name, Attribute value) +bool SetGlobalFailSafe (std::string name, const AttributeValue &value) { return GlobalValue::BindFailSafe (name, value); } @@ -469,6 +483,17 @@ void UnregisterRootNamespaceObject (Ptr obj) Singleton::Get ()->UnregisterRootNamespaceObject (obj); } +uint32_t GetRootNamespaceObjectN (void) +{ + return Singleton::Get ()->GetRootNamespaceObjectN (); +} + +Ptr GetRootNamespaceObject (uint32_t i) +{ + return Singleton::Get ()->GetRootNamespaceObject (i); +} + + } // namespace Config } // namespace ns3 @@ -512,31 +537,31 @@ TypeId MyNode::GetTypeId (void) static TypeId tid = TypeId ("MyNode") .SetParent () .AddAttribute ("NodesA", "", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&MyNode::m_nodesA), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("NodesB", "", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&MyNode::m_nodesB), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("NodeA", "", - Ptr (0), - MakePtrAccessor (&MyNode::m_nodeA), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&MyNode::m_nodeA), + MakePointerChecker ()) .AddAttribute ("NodeB", "", - Ptr (0), - MakePtrAccessor (&MyNode::m_nodeB), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&MyNode::m_nodeB), + MakePointerChecker ()) .AddAttribute ("A", "", - Integer (10), + IntegerValue (10), MakeIntegerAccessor (&MyNode::m_a), MakeIntegerChecker ()) .AddAttribute ("B", "", - Integer (9), + IntegerValue (9), MakeIntegerAccessor (&MyNode::m_b), MakeIntegerChecker ()) .AddAttribute ("Source", "XX", - Integer (-1), + IntegerValue (-1), MakeIntegerAccessor (&MyNode::m_trace), MakeIntegerChecker ()) .AddTraceSource ("Source", "XX", @@ -615,44 +640,45 @@ ConfigTest::RunTests (void) Ptr root = CreateObject (); Config::RegisterRootNamespaceObject (root); - Config::Set ("/A", Integer (1)); - Config::Set ("/B", Integer (-1)); - Integer v = root->GetAttribute ("A"); + Config::Set ("/A", IntegerValue (1)); + Config::Set ("/B", IntegerValue (-1)); + IntegerValue v; + root->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 1); - v = root->GetAttribute ("B"); + root->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), -1); Ptr a = CreateObject (); root->SetNodeA (a); - Config::Set ("/NodeA/A", Integer (2)); - Config::Set ("/NodeA/B", Integer (-2)); - v = a->GetAttribute ("A"); + Config::Set ("/NodeA/A", IntegerValue (2)); + Config::Set ("/NodeA/B", IntegerValue (-2)); + a->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 2); - v = a->GetAttribute ("B"); + a->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), -2); - Config::Set ("/NodeB/A", Integer (3)); - Config::Set ("/NodeB/B", Integer (-3)); - v = a->GetAttribute ("A"); + Config::Set ("/NodeB/A", IntegerValue (3)); + Config::Set ("/NodeB/B", IntegerValue (-3)); + a->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 2); - v = a->GetAttribute ("B"); + a->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), -2); Ptr b = CreateObject (); a->SetNodeB (b); - Config::Set ("/NodeA/NodeB/A", Integer (4)); - Config::Set ("/NodeA/NodeB/B", Integer (-4)); - v = b->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/A", IntegerValue (4)); + Config::Set ("/NodeA/NodeB/B", IntegerValue (-4)); + b->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 4); - v = b->GetAttribute ("B"); + b->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), -4); Ptr c = CreateObject (); root->SetNodeB (c); - Config::Set ("/NodeB/A", Integer (5)); - Config::Set ("/NodeB/B", Integer (-5)); - v = c->GetAttribute ("A"); + Config::Set ("/NodeB/A", IntegerValue (5)); + Config::Set ("/NodeB/B", IntegerValue (-5)); + c->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 5); - v = c->GetAttribute ("B"); + c->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), -5); @@ -664,49 +690,49 @@ ConfigTest::RunTests (void) b->AddNodeB (d1); b->AddNodeB (d2); b->AddNodeB (d3); - Config::Set ("/NodeA/NodeB/NodesB/0/A", Integer (-11)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/0/A", IntegerValue (-11)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -11); - v = d0->GetAttribute ("B"); + d0->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), 9); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), 10); - v = d1->GetAttribute ("B"); + d1->GetAttribute ("B", v); NS_TEST_ASSERT_EQUAL (v.Get (), 9); - Config::Set ("/NodeA/NodeB/NodesB/0|1/A", Integer (-12)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/0|1/A", IntegerValue (-12)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -12); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -12); - Config::Set ("/NodeA/NodeB/NodesB/|0|1|/A", Integer (-13)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/|0|1|/A", IntegerValue (-13)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -13); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -13); - Config::Set ("/NodeA/NodeB/NodesB/[0-2]/A", Integer (-14)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/[0-2]/A", IntegerValue (-14)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -14); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -14); - v = d2->GetAttribute ("A"); + d2->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -14); - Config::Set ("/NodeA/NodeB/NodesB/[1-3]/A", Integer (-15)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/[1-3]/A", IntegerValue (-15)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -14); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -15); - v = d2->GetAttribute ("A"); + d2->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -15); - v = d3->GetAttribute ("A"); + d3->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -15); - Config::Set ("/NodeA/NodeB/NodesB/[0-1]|3/A", Integer (-16)); - v = d0->GetAttribute ("A"); + Config::Set ("/NodeA/NodeB/NodesB/[0-1]|3/A", IntegerValue (-16)); + d0->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -16); - v = d1->GetAttribute ("A"); + d1->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -16); - v = d2->GetAttribute ("A"); + d2->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -15); - v = d3->GetAttribute ("A"); + d3->GetAttribute ("A", v); NS_TEST_ASSERT_EQUAL (v.Get (), -16); @@ -714,17 +740,17 @@ ConfigTest::RunTests (void) MakeCallback (&ConfigTest::ChangeNotification, this)); m_traceNotification = 0; // this should trigger no notification - d2->SetAttribute ("Source", Integer (-2)); + d2->SetAttribute ("Source", IntegerValue (-2)); NS_TEST_ASSERT_EQUAL (m_traceNotification, 0); m_traceNotification = 0; // this should trigger a notification - d1->SetAttribute ("Source", Integer (-3)); + d1->SetAttribute ("Source", IntegerValue (-3)); NS_TEST_ASSERT_EQUAL (m_traceNotification, -3); Config::DisconnectWithoutContext ("/NodeA/NodeB/NodesB/[0-1]|3/Source", MakeCallback (&ConfigTest::ChangeNotification, this)); m_traceNotification = 0; // this should _not_ trigger a notification - d1->SetAttribute ("Source", Integer (-4)); + d1->SetAttribute ("Source", IntegerValue (-4)); NS_TEST_ASSERT_EQUAL (m_traceNotification, 0); @@ -732,25 +758,25 @@ ConfigTest::RunTests (void) MakeCallback (&ConfigTest::ChangeNotificationWithPath, this)); m_traceNotification = 0; // this should trigger no notification - d2->SetAttribute ("Source", Integer (-2)); + d2->SetAttribute ("Source", IntegerValue (-2)); NS_TEST_ASSERT_EQUAL (m_traceNotification, 0); m_traceNotification = 0; m_tracePath = ""; // this should trigger a notification - d1->SetAttribute ("Source", Integer (-3)); + d1->SetAttribute ("Source", IntegerValue (-3)); NS_TEST_ASSERT_EQUAL (m_traceNotification, -3); NS_TEST_ASSERT_EQUAL (m_tracePath, "/NodeA/NodeB/NodesB/1/Source") m_traceNotification = 0; m_tracePath = ""; // this should trigger a notification - d3->SetAttribute ("Source", Integer (-3)); + d3->SetAttribute ("Source", IntegerValue (-3)); NS_TEST_ASSERT_EQUAL (m_traceNotification, -3); NS_TEST_ASSERT_EQUAL (m_tracePath, "/NodeA/NodeB/NodesB/3/Source"); Config::Disconnect ("/NodeA/NodeB/NodesB/[0-1]|3/Source", MakeCallback (&ConfigTest::ChangeNotificationWithPath, this)); m_traceNotification = 0; // this should _not_ trigger a notification - d1->SetAttribute ("Source", Integer (-4)); + d1->SetAttribute ("Source", IntegerValue (-4)); NS_TEST_ASSERT_EQUAL (m_traceNotification, 0); diff --git a/src/core/config.h b/src/core/config.h index 7b8120270..6346b071b 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -20,13 +20,15 @@ #ifndef CONFIG_H #define CONFIG_H -#include "attribute.h" #include "ptr.h" -#include "object.h" #include namespace ns3 { +class AttributeValue; +class Object; +class CallbackBase; + namespace Config { /** @@ -37,7 +39,7 @@ namespace Config { * match the input path and will then set their value to the input * value. */ -void Set (std::string path, Attribute value); +void Set (std::string path, const AttributeValue &value); /** * \param name the full name of the attribute * \param value the value to set. @@ -46,7 +48,7 @@ void Set (std::string path, Attribute value); * matching attribute. This method cannot fail: it will * crash if the input attribute name or value is invalid. */ -void SetDefault (std::string name, Attribute value); +void SetDefault (std::string name, const AttributeValue &value); /** * \param name the full name of the attribute * \param value the value to set. @@ -55,21 +57,21 @@ void SetDefault (std::string name, Attribute value); * This method overrides the initial value of the * matching attribute. */ -bool SetDefaultFailSafe (std::string name, Attribute value); +bool SetDefaultFailSafe (std::string name, const AttributeValue &value); /** * \param name the name of the requested GlobalValue. * \param value the value to set * * This method is equivalent to GlobalValue::Bind */ -void SetGlobal (std::string name, Attribute value); +void SetGlobal (std::string name, const AttributeValue &value); /** * \param name the name of the requested GlobalValue. * \param value the value to set * * This method is equivalent to GlobalValue::BindFailSafe */ -bool SetGlobalFailSafe (std::string name, Attribute value); +bool SetGlobalFailSafe (std::string name, const AttributeValue &value); /** * \param path a path to match trace sources. * \param cb the callback to connect to the matching trace sources. @@ -118,6 +120,17 @@ void RegisterRootNamespaceObject (Ptr obj); */ void UnregisterRootNamespaceObject (Ptr obj); +/** + * \returns the number of registered root namespace objects. + */ +uint32_t GetRootNamespaceObjectN (void); + +/** + * \param i the index of the requested object. + * \returns the requested root namespace object + */ +Ptr GetRootNamespaceObject (uint32_t i); + } // namespace Config } // namespace ns3 diff --git a/src/core/double.cc b/src/core/double.cc index 937220560..5daf62718 100644 --- a/src/core/double.cc +++ b/src/core/double.cc @@ -23,40 +23,7 @@ namespace ns3 { -Double::Double () -{} -Double::Double (double value) - : m_value (value) -{} -void -Double::Set (double value) -{ - m_value = value; -} -double -Double::Get (void) const -{ - return m_value; -} -Double::operator double () const -{ - return m_value; -} -std::ostream & operator << (std::ostream &os, const Double &value) -{ - os << value.Get (); - return os; -} -std::istream & operator >> (std::istream &is, Double &value) -{ - double v; - is >> v; - value.Set (v); - return is; -} - -ATTRIBUTE_VALUE_IMPLEMENT (Double); -ATTRIBUTE_CONVERTER_IMPLEMENT (Double); +ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (double, Double); namespace internal { @@ -68,27 +35,37 @@ Ptr MakeDoubleChecker (double min, double max, std::stri : m_minValue (minValue), m_maxValue (maxValue), m_name (name) {} - virtual bool Check (Attribute value) const { - const DoubleValue *v = value.DynCast (); + virtual bool Check (const AttributeValue &value) const { + const DoubleValue *v = dynamic_cast (&value); if (v == 0) { return false; } return v->Get () >= m_minValue && v->Get () <= m_maxValue; } - virtual std::string GetType (void) const { - return m_name; + virtual std::string GetValueTypeName (void) const { + return "ns3::DoubleValue"; } - virtual bool HasTypeConstraints (void) const { + virtual bool HasUnderlyingTypeInformation (void) const { return true; } - virtual std::string GetTypeConstraints (void) const { + virtual std::string GetUnderlyingTypeInformation (void) const { std::ostringstream oss; - oss << m_minValue << ":" << m_maxValue; + oss << m_name << " " << m_minValue << ":" << m_maxValue; return oss.str (); } - virtual Attribute Create (void) const { - return Attribute::Create (); + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const DoubleValue *src = dynamic_cast (&source); + DoubleValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; } double m_minValue; double m_maxValue; diff --git a/src/core/double.h b/src/core/double.h index e5ab55bd3..60de64150 100644 --- a/src/core/double.h +++ b/src/core/double.h @@ -27,31 +27,15 @@ namespace ns3 { /** + * \class ns3::DoubleValue * \brief Hold an floating point type * + * \anchor double * This class can be used to hold variables of floating point type * such as 'double' or 'float'. The internal format is 'double'. */ -class Double -{ -public: - Double (); - Double (double value); - void Set (double value); - double Get (void) const; - - operator double () const; - - ATTRIBUTE_CONVERTER_DEFINE (Double); -private: - double m_value; -}; - -std::ostream & operator << (std::ostream &os, const Double &value); -std::istream & operator >> (std::istream &is, Double &value); - -ATTRIBUTE_VALUE_DEFINE (Double); +ATTRIBUTE_VALUE_DEFINE_WITH_NAME (double, Double); ATTRIBUTE_ACCESSOR_DEFINE (Double); template diff --git a/src/core/enum.cc b/src/core/enum.cc index b8b484b59..58cc9fcc8 100644 --- a/src/core/enum.cc +++ b/src/core/enum.cc @@ -23,30 +23,30 @@ namespace ns3 { -Enum::Enum () +EnumValue::EnumValue () : m_v () {} -Enum::Enum (int v) +EnumValue::EnumValue (int v) : m_v (v) {} void -Enum::Set (int v) +EnumValue::Set (int v) { m_v = v; } int -Enum::Get (void) const +EnumValue::Get (void) const { return m_v; } -Attribute -Enum::Copy (void) const +Ptr +EnumValue::Copy (void) const { - return Attribute::Create (*this); + return ns3::Create (*this); } std::string -Enum::SerializeToString (Ptr checker) const +EnumValue::SerializeToString (Ptr checker) const { const EnumChecker *p = dynamic_cast (PeekPointer (checker)); NS_ASSERT (p != 0); @@ -63,7 +63,7 @@ Enum::SerializeToString (Ptr checker) const return ""; } bool -Enum::DeserializeFromString (std::string value, Ptr checker) +EnumValue::DeserializeFromString (std::string value, Ptr checker) { const EnumChecker *p = dynamic_cast (PeekPointer (checker)); NS_ASSERT (p != 0); @@ -78,22 +78,6 @@ Enum::DeserializeFromString (std::string value, Ptr chec return false; } -Enum::Enum (Attribute value) -{ - const Enum *v = value.DynCast (); - if (v == 0) - { - NS_FATAL_ERROR ("assigning non-Enum value to Enum value."); - } - m_v = v->m_v; -} -Enum::operator Attribute () const -{ - return Attribute::Create (*this); -} - - - EnumChecker::EnumChecker () {} @@ -108,9 +92,9 @@ EnumChecker::Add (int v, std::string name) m_valueSet.push_back (std::make_pair (v, name)); } bool -EnumChecker::Check (Attribute value) const +EnumChecker::Check (const AttributeValue &value) const { - const Enum *p = value.DynCast (); + const EnumValue *p = dynamic_cast (&value); if (p == 0) { return false; @@ -125,17 +109,17 @@ EnumChecker::Check (Attribute value) const return false; } std::string -EnumChecker::GetType (void) const +EnumChecker::GetValueTypeName (void) const { - return "Enum"; + return "ns3::EnumValue"; } bool -EnumChecker::HasTypeConstraints (void) const +EnumChecker::HasUnderlyingTypeInformation (void) const { return true; } std::string -EnumChecker::GetTypeConstraints (void) const +EnumChecker::GetUnderlyingTypeInformation (void) const { std::ostringstream oss; for (ValueSet::const_iterator i = m_valueSet.begin (); i != m_valueSet.end ();) @@ -149,10 +133,23 @@ EnumChecker::GetTypeConstraints (void) const } return oss.str (); } -Attribute +Ptr EnumChecker::Create (void) const { - return Attribute::Create (); + return ns3::Create (); +} + +bool +EnumChecker::Copy (const AttributeValue &source, AttributeValue &destination) const +{ + const EnumValue *src = dynamic_cast (&source); + EnumValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; } diff --git a/src/core/enum.h b/src/core/enum.h index 80e86b2a2..4cea3134a 100644 --- a/src/core/enum.h +++ b/src/core/enum.h @@ -32,20 +32,18 @@ namespace ns3 { * This class can be used to hold variables of any kind * of enum. */ -class Enum : public AttributeValue +class EnumValue : public AttributeValue { public: - Enum (); - Enum (int v); + EnumValue (); + EnumValue (int v); void Set (int v); int Get (void) const; - virtual Attribute Copy (void) const; + virtual Ptr Copy (void) const; virtual std::string SerializeToString (Ptr checker) const; virtual bool DeserializeFromString (std::string value, Ptr checker); - Enum (Attribute value); - operator Attribute () const; private: int m_v; }; @@ -58,14 +56,15 @@ public: void AddDefault (int v, std::string name); void Add (int v, std::string name); - virtual bool Check (Attribute value) const; - virtual std::string GetType (void) const; - virtual bool HasTypeConstraints (void) const; - virtual std::string GetTypeConstraints (void) const; - virtual Attribute Create (void) const; + virtual bool Check (const AttributeValue &value) const; + virtual std::string GetValueTypeName (void) const; + virtual bool HasUnderlyingTypeInformation (void) const; + virtual std::string GetUnderlyingTypeInformation (void) const; + virtual Ptr Create (void) const; + virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const; private: - friend class Enum; + friend class EnumValue; typedef std::list > ValueSet; ValueSet m_valueSet; }; @@ -97,13 +96,13 @@ namespace ns3 { template Ptr MakeEnumAccessor (T1 a1) { - return MakeAccessorHelper (a1); + return MakeAccessorHelper (a1); } template Ptr MakeEnumAccessor (T1 a1, T2 a2) { - return MakeAccessorHelper (a1, a2); + return MakeAccessorHelper (a1, a2); } } // namespace ns3 diff --git a/src/core/global-value.cc b/src/core/global-value.cc index a5acfc174..041a0c432 100644 --- a/src/core/global-value.cc +++ b/src/core/global-value.cc @@ -25,11 +25,11 @@ namespace ns3 { GlobalValue::GlobalValue (std::string name, std::string help, - Attribute initialValue, + const AttributeValue &initialValue, Ptr checker) : m_name (name), m_help (help), - m_initialValue (initialValue), + m_initialValue (initialValue.Copy ()), m_checker (checker) { if (m_checker == 0) @@ -49,10 +49,20 @@ GlobalValue::GetHelp (void) const { return m_help; } -Attribute -GlobalValue::GetValue (void) const +void +GlobalValue::GetValue (AttributeValue &value) const { - return m_initialValue; + bool ok = m_checker->Copy (*m_initialValue, value); + if (ok) + { + return; + } + StringValue *str = dynamic_cast (&value); + if (str == 0) + { + NS_FATAL_ERROR ("GlobalValue name="<Set (m_initialValue->SerializeToString (m_checker)); } Ptr GlobalValue::GetChecker (void) const @@ -61,37 +71,37 @@ GlobalValue::GetChecker (void) const } bool -GlobalValue::SetValue (Attribute value) +GlobalValue::SetValue (const AttributeValue &value) { if (m_checker->Check (value)) { - m_initialValue = value; + m_initialValue = value.Copy (); return true; } // attempt to convert to string. - const StringValue *str = value.DynCast (); + const StringValue *str = dynamic_cast (&value); if (str == 0) { return false; } // attempt to convert back to value. - Attribute v = m_checker->Create (); - bool ok = v.DeserializeFromString (str->Get ().Get (), m_checker); + Ptr v = m_checker->Create (); + bool ok = v->DeserializeFromString (str->Get (), m_checker); if (!ok) { return false; } - ok = m_checker->Check (v); + ok = m_checker->Check (*v); if (!ok) { return false; } - m_initialValue = v; + m_checker->Copy (*v, *PeekPointer (m_initialValue)); return true; } void -GlobalValue::Bind (std::string name, Attribute value) +GlobalValue::Bind (std::string name, const AttributeValue &value) { for (Iterator i = Begin (); i != End (); i++) { @@ -107,7 +117,7 @@ GlobalValue::Bind (std::string name, Attribute value) NS_FATAL_ERROR ("Non-existant global value: "< ()); - NS_TEST_ASSERT_EQUAL (10, Uinteger (uint.GetValue ()).Get ()); + UintegerValue v; + uint.GetValue (v); + NS_TEST_ASSERT_EQUAL (10, v.Get ()); GlobalValue::Vector *vector = GlobalValue::GetVector (); for (GlobalValue::Vector::iterator i = vector->begin (); i != vector->end (); ++i) diff --git a/src/core/global-value.h b/src/core/global-value.h index 5e58f93e2..db1a82854 100644 --- a/src/core/global-value.h +++ b/src/core/global-value.h @@ -51,8 +51,8 @@ public: * value matches the requested type constraints. */ GlobalValue (std::string name, std::string help, - Attribute initialValue, - Ptr checker); + const AttributeValue &initialValue, + Ptr checker); /** * \returns the name of this GlobalValue. @@ -65,7 +65,7 @@ public: /** * \returns the current value of this GlobalValue. */ - Attribute GetValue (void) const; + void GetValue (AttributeValue &value) const; /** * \returns the checker associated to this GlobalValue. */ @@ -73,7 +73,7 @@ public: /** * \param value the new value to set in this GlobalValue. */ - bool SetValue (Attribute value); + bool SetValue (const AttributeValue &value); /** * \param name the name of the global value @@ -84,7 +84,7 @@ public: * * This method cannot fail. It will crash if the input is not valid. */ - static void Bind (std::string name, Attribute value); + static void Bind (std::string name, const AttributeValue &value); /** * \param name the name of the global value @@ -94,7 +94,7 @@ public: * Iterate over the set of GlobalValues until a matching name is found * and then set its value with GlobalValue::SetValue. */ - static bool BindFailSafe (std::string name, Attribute value); + static bool BindFailSafe (std::string name, const AttributeValue &value); /** * \returns an iterator which represents a pointer to the first GlobalValue registered. @@ -109,7 +109,7 @@ private: static Vector *GetVector (void); std::string m_name; std::string m_help; - Attribute m_initialValue; + Ptr m_initialValue; Ptr m_checker; }; diff --git a/src/core/integer.cc b/src/core/integer.cc index 98fc6eaf8..d78a9eda9 100644 --- a/src/core/integer.cc +++ b/src/core/integer.cc @@ -23,44 +23,7 @@ namespace ns3 { -Integer::Integer (int64_t value) - : m_value (value) -{} -Integer::Integer () - : m_value (0) -{} -void -Integer::Set (int64_t value) -{ - m_value = value; -} -int64_t -Integer::Get (void) const -{ - return m_value; -} - -Integer::operator int64_t () const -{ - return m_value; -} - -ATTRIBUTE_VALUE_IMPLEMENT (Integer); - -std::ostream &operator << (std::ostream &os, const Integer &integer) -{ - os << integer.Get (); - return os; -} -std::istream &operator >> (std::istream &is, Integer &integer) -{ - int64_t v; - is >> v; - integer.Set (v); - return is; -} - -ATTRIBUTE_CONVERTER_IMPLEMENT (Integer); +ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (int64_t, Integer); namespace internal { @@ -73,27 +36,37 @@ MakeIntegerChecker (int64_t min, int64_t max, std::string name) : m_minValue (minValue), m_maxValue (maxValue), m_name (name) {} - virtual bool Check (Attribute value) const { - const IntegerValue *v = value.DynCast (); + virtual bool Check (const AttributeValue &value) const { + const IntegerValue *v = dynamic_cast (&value); if (v == 0) { return false; } - return v->Get ().Get () >= m_minValue && v->Get ().Get() <= m_maxValue; + return v->Get () >= m_minValue && v->Get () <= m_maxValue; } - virtual std::string GetType (void) const { - return m_name; + virtual std::string GetValueTypeName (void) const { + return "ns3::IntegerValue"; } - virtual bool HasTypeConstraints (void) const { + virtual bool HasUnderlyingTypeInformation (void) const { return true; } - virtual std::string GetTypeConstraints (void) const { + virtual std::string GetUnderlyingTypeInformation (void) const { std::ostringstream oss; - oss << m_minValue << ":" << m_maxValue; + oss << m_name << " " << m_minValue << ":" << m_maxValue; return oss.str (); } - virtual Attribute Create (void) const { - return Attribute::Create (); + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &src, AttributeValue &dst) const { + const IntegerValue *source = dynamic_cast (&src); + IntegerValue *destination = dynamic_cast (&dst); + if (source == 0 || destination == 0) + { + return false; + } + *destination = *source; + return true; } int64_t m_minValue; int64_t m_maxValue; diff --git a/src/core/integer.h b/src/core/integer.h index eab6d7032..ea7a20c0e 100644 --- a/src/core/integer.h +++ b/src/core/integer.h @@ -27,30 +27,20 @@ namespace ns3 { /** + * \class ns3::IntegerValue * \brief Hold a signed integer type * + * \anchor int8_t + * \anchor int16_t + * \anchor int32_t + * \anchor int64_t + * * This class can be used to hold variables of signed integer * type such as int8_t, int16_t, int32_t, int64_t, or, * int, etc. */ -class Integer -{ -public: - Integer (int64_t value); - Integer (); - void Set (int64_t value); - int64_t Get (void) const; - operator int64_t () const; - ATTRIBUTE_CONVERTER_DEFINE (Integer); -private: - int64_t m_value; -}; - -std::ostream &operator << (std::ostream &os, const Integer &integer); -std::istream &operator >> (std::istream &is, Integer &integer); - -ATTRIBUTE_VALUE_DEFINE(Integer); +ATTRIBUTE_VALUE_DEFINE_WITH_NAME(int64_t, Integer); ATTRIBUTE_ACCESSOR_DEFINE(Integer); template diff --git a/src/core/log.cc b/src/core/log.cc index 5e4492ba7..d15c0aab7 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -18,8 +18,6 @@ * Author: Mathieu Lacage */ -// What about print-list!!!!!!??????? - #ifdef NS3_LOG_ENABLE #include @@ -36,6 +34,8 @@ namespace ns3 { +LogTimePrinter g_logTimePrinter = 0; + typedef std::list > ComponentList; typedef std::list >::iterator ComponentListI; @@ -67,7 +67,7 @@ PrintList::PrintList () std::string::size_type next = 0; while (next != std::string::npos) { - next = env.find_first_of (";", cur); + next = env.find_first_of (":", cur); std::string tmp = std::string (env, cur, next-cur); if (tmp == "print-list") { @@ -115,7 +115,7 @@ LogComponent::EnvVarCheck (char const * name) std::string::size_type next = 0; while (next != std::string::npos) { - next = env.find_first_of (";", cur); + next = env.find_first_of (":", cur); std::string tmp = std::string (env, cur, next-cur); std::string::size_type equal = tmp.find ("="); std::string component; @@ -124,7 +124,8 @@ LogComponent::EnvVarCheck (char const * name) component = tmp; if (component == myName || component == "*") { - Enable (LOG_DEBUG); + int level = LOG_ALL | LOG_PREFIX_TIME | LOG_PREFIX_FUNC; + Enable ((enum LogLevel)level); return; } } @@ -161,10 +162,6 @@ LogComponent::EnvVarCheck (char const * name) { level |= LOG_FUNCTION; } - else if (lev == "param") - { - level |= LOG_PARAM; - } else if (lev == "logic") { level |= LOG_LOGIC; @@ -173,9 +170,13 @@ LogComponent::EnvVarCheck (char const * name) { level |= LOG_ALL; } - else if (lev == "prefix") + else if (lev == "prefix_func") { - level |= LOG_PREFIX_ALL; + level |= LOG_PREFIX_FUNC; + } + else if (lev == "prefix_time") + { + level |= LOG_PREFIX_TIME; } else if (lev == "level_error") { @@ -197,10 +198,6 @@ LogComponent::EnvVarCheck (char const * name) { level |= LOG_LEVEL_FUNCTION; } - else if (lev == "level_param") - { - level |= LOG_LEVEL_PARAM; - } else if (lev == "level_logic") { level |= LOG_LEVEL_LOGIC; @@ -342,10 +339,6 @@ LogComponentPrintList (void) { std::cout << "|function"; } - if (i->second->IsEnabled (LOG_PARAM)) - { - std::cout << "|param"; - } if (i->second->IsEnabled (LOG_LOGIC)) { std::cout << "|logic"; @@ -358,10 +351,20 @@ LogComponentPrintList (void) } } +void LogRegisterTimePrinter (LogTimePrinter printer) +{ + g_logTimePrinter = printer; +} +LogTimePrinter LogGetTimePrinter(void) +{ + return g_logTimePrinter; +} -ParameterLogger g_parameterLogger; -EndParameterListStruct EndParameterList; +ParameterLogger::ParameterLogger (std::ostream &os) + : m_itemNumber (0), + m_os (os) +{} } // namespace ns3 diff --git a/src/core/log.h b/src/core/log.h index ca5e510cf..f95f8a760 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -24,6 +24,9 @@ #include #include +#ifdef NS3_LOG_ENABLE + + /** * \ingroup core * \defgroup logging Logging @@ -35,22 +38,20 @@ * messages, use the ns3::LogComponentEnable * function or use the NS_LOG environment variable * - * Use the environment variable NS_LOG to define a ';'-separated list of + * Use the environment variable NS_LOG to define a ':'-separated list of * logging components to enable. For example (using bash syntax), - * NS_LOG="OlsrAgent" would enable one component; - * NS_LOG="OlsrAgent;Ipv4L3Protocol" would enable two - * components, etc. NS_LOG="*" will enable all available log components. - * For each component, the "debug" log level is enabled by default. + * NS_LOG="OlsrAgent" would enable one component at all log levels. + * NS_LOG="OlsrAgent:Ipv4L3Protocol" would enable two components, + * at all log levels, etc. + * NS_LOG="*" will enable all available log components at all levels. * - * To obtain more components than just debug log level, more components - * can be enabled selectively with the following - * syntax: NS_LOG='Component1=func|param|warn;Component2=error|debug' - * This example would enable the 'func', 'param', and 'warn' log + * To control more selectively the log levels for each component, use + * this syntax: NS_LOG='Component1=func|warn:Component2=error|debug' + * This example would enable the 'func', and 'warn' log * levels for 'Component1' and the 'error' and 'debug' log levels * for 'Component2'. The wildcard can be used here as well. For example * NS_LOG='*=level_all|prefix' would enable all log levels and prefix all * prints with the component and function names. - * */ /** @@ -65,111 +66,30 @@ * ns3::LogComponentDisable functions or with the NS_LOG * environment variable. */ - -#ifdef NS3_LOG_ENABLE - -#define NS_LOG_COMPONENT_DEFINE(name) \ +#define NS_LOG_COMPONENT_DEFINE(name) \ static ns3::LogComponent g_log = ns3::LogComponent (name) -#else +#define APPEND_TIME_PREFIX \ + if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) \ + { \ + LogTimePrinter printer = LogGetTimePrinter (); \ + if (printer != 0) \ + { \ + (*printer) (std::clog); \ + std::clog << " "; \ + } \ + } -#define NS_LOG_COMPONENT_DEFINE(name) - -#endif +#define APPEND_FUNC_PREFIX \ + if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) \ + { \ + std::clog << g_log.Name () << ":" << \ + __FUNCTION__ << "(): "; \ + } \ /** * \ingroup logging - * \param msg message to output - * - * Generate logging output in the "log component" of the - * current file. i.e., every call to NS_LOG from within - * a file implicitely generates out within the component - * defined with the NS_LOG_COMPONENT_DEFINE macro in the - * same file. - */ - -#ifdef NS3_LOG_ENABLE - - -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 - std::clog << param << " ("; - break; - case 1: // first parameter - if (m_parameterName) - { - std::clog << m_parameterName << "=" << param; - m_parameterName = 0; - } - else - { - std::clog << param; - } - break; - default: // parameter following a previous parameter - if (m_parameterName) - { - std::clog << ", " << m_parameterName << "=" << param; - m_parameterName = 0; - } - else - { - 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 * @@ -187,73 +107,113 @@ extern ParameterLogger g_parameterLogger; { \ if (g_log.IsEnabled (level)) \ { \ - if (g_log.IsEnabled (ns3::LOG_PREFIX_ALL)) \ - { \ - std::clog << g_log.Name () << ":" << \ - __FUNCTION__ << "(): "; \ - } \ + APPEND_TIME_PREFIX; \ + APPEND_FUNC_PREFIX; \ std::clog << msg << std::endl; \ } \ } \ while (false) -#define NS_LOG_F(level) \ +/** + * \ingroup logging + * \param msg the message to log + * + * Use \ref NS_LOG to output a message of level LOG_ERROR. + */ +#define NS_LOG_ERROR(msg) \ + NS_LOG(ns3::LOG_ERROR, msg) + +/** + * \ingroup logging + * \param msg the message to log + * + * Use \ref NS_LOG to output a message of level LOG_WARN. + */ +#define NS_LOG_WARN(msg) \ + NS_LOG(ns3::LOG_WARN, msg) + +/** + * \ingroup logging + * \param msg the message to log + * + * Use \ref NS_LOG to output a message of level LOG_DEBUG. + */ +#define NS_LOG_DEBUG(msg) \ + NS_LOG(ns3::LOG_DEBUG, msg) + +/** + * \ingroup logging + * \param msg the message to log + * + * Use \ref NS_LOG to output a message of level LOG_INFO. + */ +#define NS_LOG_INFO(msg) \ + NS_LOG(ns3::LOG_INFO, msg) + +/** + * \ingroup logging + * + * Output the name of the function. + */ +#define NS_LOG_FUNCTION_NOARGS() \ do \ { \ - if (g_log.IsEnabled (level)) \ + if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \ { \ - std::clog << g_log.Name () << ":" << __FUNCTION__ << \ - "()" << std::endl; \ + APPEND_TIME_PREFIX; \ + std::clog << g_log.Name () << ":" \ + << __FUNCTION__ << "()" << std::endl; \ } \ } \ while (false) -#define NS_LOG_ERROR(msg) \ - NS_LOG(ns3::LOG_ERROR, msg) -#define NS_LOG_WARN(msg) \ - NS_LOG(ns3::LOG_WARN, msg) - -#define NS_LOG_DEBUG(msg) \ - NS_LOG(ns3::LOG_DEBUG, msg) - -#define NS_LOG_INFO(msg) \ - NS_LOG(ns3::LOG_INFO, msg) - -#define NS_LOG_FUNCTION \ - NS_LOG_F(ns3::LOG_FUNCTION) - - - -#define NS_LOG_PARAMS(parameters) \ +/** + * \ingroup logging + * \param parameters the parameters to output. + * + * If log level LOG_FUNCTION is enabled, this macro will output + * all input parameters separated by ", ". + * + * Typical usage looks like: + * \code + * NS_LOG_FUNCTION (aNumber< + ParameterLogger& operator<< (T param) + { + switch (m_itemNumber) + { + case 0: // first parameter + m_os << param; + break; + default: // parameter following a previous parameter + m_os << ", " << param; + break; + } + m_itemNumber++; + return *this; + } +}; } // namespace ns3 +#else /* LOG_ENABLE */ + +#define NS_LOG_COMPONENT_DEFINE(component) +#define NS_LOG(level, msg) +#define NS_LOG_ERROR(msg) +#define NS_LOG_WARN(msg) +#define NS_LOG_DEBUG(msg) +#define NS_LOG_INFO(msg) +#define NS_LOG_FUNCTION_NOARGS() +#define NS_LOG_FUNCTION(msg) +#define NS_LOG_LOGIC(msg) +#define NS_LOG_UNCOND(msg) + +#define LogComponentPrintList +#define LogComponentEnable(name,level) +#define LogComponentDisable(name,level) +#define LogComponentEnableAll(level) +#define LogComponentDisableAll(level) +#define LogRegisterTimePrinter(printer) + +#endif /* LOG_ENABLE */ + #endif // __LOG_H__ diff --git a/src/core/object-base.cc b/src/core/object-base.cc index 09f736628..e5a256612 100644 --- a/src/core/object-base.cc +++ b/src/core/object-base.cc @@ -20,6 +20,7 @@ #include "object-base.h" #include "log.h" #include "trace-source-accessor.h" +#include "attribute-list.h" #include "string.h" NS_LOG_COMPONENT_DEFINE ("ObjectBase"); @@ -58,8 +59,8 @@ ObjectBase::ConstructSelf (const AttributeList &attributes) NS_LOG_DEBUG ("construct tid="<checker == checker) { // We have a matching attribute value. - DoSet (paramSpec, initial, checker, j->value); + DoSet (accessor, checker, *j->value); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\""); found = true; @@ -91,7 +92,7 @@ ObjectBase::ConstructSelf (const AttributeList &attributes) if (j->checker == checker) { // We have a matching attribute value. - DoSet (paramSpec, initial, checker, j->value); + DoSet (accessor, checker, *j->value); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\" from global"); found = true; @@ -102,7 +103,7 @@ ObjectBase::ConstructSelf (const AttributeList &attributes) if (!found) { // No matching attribute value so we set the default value. - paramSpec->Set (this, initial); + DoSet (accessor, checker, *initial); NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<< tid.GetAttributeName (i)<<"\" from initial value."); } @@ -113,37 +114,39 @@ ObjectBase::ConstructSelf (const AttributeList &attributes) } bool -ObjectBase::DoSet (Ptr spec, Attribute initialValue, - Ptr checker, Attribute value) +ObjectBase::DoSet (Ptr spec, + Ptr checker, + const AttributeValue &value) { bool ok = checker->Check (value); + if (ok) + { + ok = spec->Set (this, value); + return ok; + } + // attempt to convert to string + const StringValue *str = dynamic_cast (&value); + if (str == 0) + { + return false; + } + // attempt to convert back from string. + Ptr v = checker->Create (); + ok = v->DeserializeFromString (str->Get (), checker); if (!ok) { - // attempt to convert to string - const StringValue *str = value.DynCast (); - if (str == 0) - { - return false; - } - // attempt to convert back from string. - Attribute v = checker->Create (); - ok = v.DeserializeFromString (str->Get ().Get (), checker); - if (!ok) - { - return false; - } - ok = checker->Check (v); - if (!ok) - { - return false; - } - value = v; + return false; } - ok = spec->Set (this, value); + ok = checker->Check (*v); + if (!ok) + { + return false; + } + ok = spec->Set (this, *v); return ok; } void -ObjectBase::SetAttribute (std::string name, Attribute value) +ObjectBase::SetAttribute (std::string name, const AttributeValue &value) { struct TypeId::AttributeInfo info; TypeId tid = GetInstanceTypeId (); @@ -151,17 +154,18 @@ ObjectBase::SetAttribute (std::string name, Attribute value) { NS_FATAL_ERROR ("Attribute name="< v = info.checker->Create (); + ok = info.accessor->Get (this, *PeekPointer (v)); + if (!ok) + { + NS_FATAL_ERROR ("Attribute name="<Set (v->SerializeToString (info.checker)); } + bool -ObjectBase::GetAttributeFailSafe (std::string name, Attribute &value) const +ObjectBase::GetAttributeFailSafe (std::string name, AttributeValue &value) const { struct TypeId::AttributeInfo info; TypeId tid = GetInstanceTypeId (); @@ -251,13 +224,29 @@ ObjectBase::GetAttributeFailSafe (std::string name, Attribute &value) const { return false; } - if (!(info.flags & TypeId::ATTR_GET)) + if (!(info.flags & TypeId::ATTR_GET) || + !info.accessor->HasGetter ()) { return false; } - value = info.checker->Create (); bool ok = info.accessor->Get (this, value); - return ok; + if (ok) + { + return true; + } + StringValue *str = dynamic_cast (&value); + if (str == 0) + { + return false; + } + Ptr v = info.checker->Create (); + ok = info.accessor->Get (this, *PeekPointer (v)); + if (!ok) + { + return false; + } + str->Set (v->SerializeToString (info.checker)); + return true; } bool diff --git a/src/core/object-base.h b/src/core/object-base.h index fdedd9a89..27dd4f735 100644 --- a/src/core/object-base.h +++ b/src/core/object-base.h @@ -22,7 +22,6 @@ #include "type-id.h" #include "callback.h" -#include "attribute-list.h" #include /** @@ -40,6 +39,8 @@ namespace ns3 { +class AttributeList; + /** * \brief implement the ns-3 type and attribute system * @@ -72,35 +73,22 @@ public: * Set a single attribute. This cannot fail: if the input is invalid, * it will crash immediately. */ - void SetAttribute (std::string name, Attribute value); + void SetAttribute (std::string name, const AttributeValue &value); /** * \param name the name of the attribute to set * \param value the name of the attribute to set * \returns true if the requested attribute exists and could be set, * false otherwise. */ - bool SetAttributeFailSafe (std::string name, Attribute value); - /** - * \param name the name of the attribute to read - * \returns true if the requested attribute was found, false otherwise. - * - * If the input attribute name does not exist, this method crashes. - */ - std::string GetAttributeAsString (std::string name) const; + bool SetAttributeFailSafe (std::string name, const AttributeValue &value); /** * \param name the name of the attribute to read + * \param value a reference to the value where the result should be stored. * \returns the attribute read. * * If the input attribute name does not exist, this method crashes. */ - Attribute GetAttribute (std::string name) const; - - /** - * \param name the name of the attribute to read - * \param value the string where the result value should be stored - * \returns true if the requested attribute was found, false otherwise. - */ - bool GetAttributeAsStringFailSafe (std::string name, std::string &value) const; + void GetAttribute (std::string name, AttributeValue &value) const; /** * \param name the name of the attribute to read * \param attribute the attribute where the result value should be stored @@ -108,7 +96,7 @@ public: * * If the input attribute name does not exist, this method crashes. */ - bool GetAttributeFailSafe (std::string name, Attribute &attribute) const; + bool GetAttributeFailSafe (std::string name, AttributeValue &attribute) const; /** * \param name the name of the targetted trace source @@ -163,8 +151,9 @@ protected: void ConstructSelf (const AttributeList &attributes); private: - bool DoSet (Ptr spec, Attribute intialValue, - Ptr checker, Attribute value); + bool DoSet (Ptr spec, + Ptr checker, + const AttributeValue &value); }; diff --git a/src/core/object-factory.cc b/src/core/object-factory.cc index ebdf5e20c..297e6132d 100644 --- a/src/core/object-factory.cc +++ b/src/core/object-factory.cc @@ -41,7 +41,7 @@ ObjectFactory::SetTypeId (const char *tid) m_tid = TypeId::LookupByName (tid); } void -ObjectFactory::Set (std::string name, Attribute value) +ObjectFactory::Set (std::string name, const AttributeValue &value) { if (name == "") { @@ -70,12 +70,22 @@ ObjectFactory::Create (void) const std::ostream & operator << (std::ostream &os, const ObjectFactory &factory) { - // XXX + os << factory.m_tid.GetName () << "[" << factory.m_parameters.SerializeToString () << "]"; return os; } std::istream & operator >> (std::istream &is, ObjectFactory &factory) { - // XXX + std::string v; + is >> v; + std::string::size_type lbracket, rbracket; + lbracket = v.find ("["); + rbracket = v.find ("]"); + NS_ASSERT (lbracket != std::string::npos); + NS_ASSERT (rbracket != std::string::npos); + std::string tid = v.substr (0, lbracket); + std::string parameters = v.substr (lbracket+1,rbracket-(lbracket+1)); + factory.SetTypeId (tid); + factory.m_parameters.DeserializeFromString (parameters); return is; } diff --git a/src/core/object-factory.h b/src/core/object-factory.h index 5bb0fd40b..ccfdc4177 100644 --- a/src/core/object-factory.h +++ b/src/core/object-factory.h @@ -20,11 +20,14 @@ #ifndef OBJECT_FACTORY_H #define OBJECT_FACTORY_H -#include "attribute.h" +#include "attribute-list.h" #include "object.h" +#include "type-id.h" namespace ns3 { +class AttributeValue; + /** * \brief instantiate subclasses of ns3::Object. * @@ -52,7 +55,7 @@ public: * \param name the name of the attribute to set during object construction * \param value the value of the attribute to set during object construction */ - void Set (std::string name, Attribute value); + void Set (std::string name, const AttributeValue &value); /** * \returns the currently-selected TypeId to use to create an object @@ -76,6 +79,9 @@ public: ATTRIBUTE_HELPER_HEADER_1 (ObjectFactory); private: + friend std::ostream & operator << (std::ostream &os, const ObjectFactory &factory); + friend std::istream & operator >> (std::istream &is, ObjectFactory &factory); + TypeId m_tid; AttributeList m_parameters; }; @@ -83,6 +89,11 @@ private: std::ostream & operator << (std::ostream &os, const ObjectFactory &factory); std::istream & operator >> (std::istream &is, ObjectFactory &factory); +/** + * \class ns3::ObjectFactoryValue + * \brief hold objects of type ns3::ObjectFactory + */ + ATTRIBUTE_HELPER_HEADER_2 (ObjectFactory); } // namespace ns3 diff --git a/src/core/object-vector.cc b/src/core/object-vector.cc index 618946fac..bca66f8af 100644 --- a/src/core/object-vector.cc +++ b/src/core/object-vector.cc @@ -2,63 +2,34 @@ namespace ns3 { -ObjectVector::ObjectVector () +ObjectVectorValue::ObjectVectorValue () {} -ObjectVector::Iterator -ObjectVector::Begin (void) const +ObjectVectorValue::Iterator +ObjectVectorValue::Begin (void) const { return m_objects.begin (); } -ObjectVector::Iterator -ObjectVector::End (void) const +ObjectVectorValue::Iterator +ObjectVectorValue::End (void) const { return m_objects.end (); } uint32_t -ObjectVector::GetN (void) const +ObjectVectorValue::GetN (void) const { return m_objects.size (); } Ptr -ObjectVector::Get (uint32_t i) const +ObjectVectorValue::Get (uint32_t i) const { return m_objects[i]; } -ObjectVector::ObjectVector (Attribute value) -{ - const ObjectVectorValue *v = value.DynCast (); - if (v == 0) - { - NS_FATAL_ERROR ("Expected value of type ObjectVectorValue."); - } - *this = v->Get (); -} - -ObjectVector::operator Attribute () const -{ - return Attribute::Create (); -} - -ObjectVectorValue::ObjectVectorValue () - : m_vector () -{} - -ObjectVectorValue::ObjectVectorValue (const ObjectVector &vector) - : m_vector (vector) -{} - -ObjectVector -ObjectVectorValue::Get (void) const -{ - return m_vector; -} - -Attribute +Ptr ObjectVectorValue::Copy (void) const { - return Attribute::Create (*this); + return ns3::Create (*this); } std::string ObjectVectorValue::SerializeToString (Ptr checker) const @@ -69,25 +40,25 @@ ObjectVectorValue::SerializeToString (Ptr checker) const bool ObjectVectorValue::DeserializeFromString (std::string value, Ptr checker) { - // XXX ?? Can we implement this correctly ?? I doubt it very much. + NS_FATAL_ERROR ("cannot deserialize a vector of object pointers."); return true; } bool -ObjectVectorAccessor::Set (ObjectBase * object, Attribute value) const +ObjectVectorAccessor::Set (ObjectBase * object, const AttributeValue & value) const { // not allowed. return false; } bool -ObjectVectorAccessor::Get (const ObjectBase * object, Attribute value) const +ObjectVectorAccessor::Get (const ObjectBase * object, AttributeValue &value) const { - ObjectVectorValue *v = value.DynCast (); + ObjectVectorValue *v = dynamic_cast (&value); if (v == 0) { return false; } - v->m_vector.m_objects.clear (); + v->m_objects.clear (); uint32_t n; bool ok = DoGetN (object, &n); if (!ok) @@ -97,11 +68,19 @@ ObjectVectorAccessor::Get (const ObjectBase * object, Attribute value) const for (uint32_t i = 0; i < n; i++) { Ptr o = DoGet (object, i); - v->m_vector.m_objects.push_back (o); + v->m_objects.push_back (o); } return true; } - -ATTRIBUTE_CHECKER_IMPLEMENT (ObjectVector); +bool +ObjectVectorAccessor::HasGetter (void) const +{ + return true; +} +bool +ObjectVectorAccessor::HasSetter (void) const +{ + return false; +} } // name diff --git a/src/core/object-vector.h b/src/core/object-vector.h index 6f43b8c9f..5f79ae73d 100644 --- a/src/core/object-vector.h +++ b/src/core/object-vector.h @@ -5,24 +5,44 @@ #include "object.h" #include "ptr.h" #include "attribute.h" -#include "attribute-helper.h" namespace ns3 { -class ObjectVector +/** + * \brief contain a vector of ns3::Object pointers. + * + * This class it used to get attribute access to an array of + * ns3::Object pointers. + */ +class ObjectVectorValue : public AttributeValue { public: typedef std::vector >::const_iterator Iterator; - ObjectVector (); + ObjectVectorValue (); + /** + * \returns an iterator to the first object contained in this vector + */ Iterator Begin (void) const; + /** + * \returns an iterator to the last object contained in this vector + */ Iterator End (void) const; + /** + * \returns the number of objects contained in this vector. + */ uint32_t GetN (void) const; + /** + * \param i the index of the requested object. + * \returns the requested object + */ Ptr Get (uint32_t i) const; - ObjectVector (Attribute value); - operator Attribute () const; + virtual Ptr Copy (void) const; + virtual std::string SerializeToString (Ptr checker) const; + virtual bool DeserializeFromString (std::string value, Ptr checker); + private: friend class ObjectVectorAccessor; std::vector > m_objects; @@ -42,35 +62,65 @@ Ptr MakeObjectVectorAccessor (INDEX (T::*getN) (void) const, Ptr (T::*get) (INDEX) const); +class ObjectVectorChecker : public AttributeChecker +{ +public: + virtual TypeId GetItemTypeId (void) const = 0; +}; -ATTRIBUTE_CHECKER_DEFINE (ObjectVector); +template +Ptr MakeObjectVectorChecker (void); } // namespace ns3 namespace ns3 { -class ObjectVectorValue : public AttributeValue +namespace internal { + +template +class AnObjectVectorChecker : public ObjectVectorChecker { public: - ObjectVectorValue (); - ObjectVectorValue (const ObjectVector &vector); - - ObjectVector Get (void) const; - - virtual Attribute Copy (void) const; - virtual std::string SerializeToString (Ptr checker) const; - virtual bool DeserializeFromString (std::string value, Ptr checker); - -private: - friend class ObjectVectorAccessor; - ObjectVector m_vector; + virtual TypeId GetItemTypeId (void) const { + return T::GetTypeId (); + } + virtual bool Check (const AttributeValue &value) const { + return dynamic_cast (&value) != 0; + } + virtual std::string GetValueTypeName (void) const { + return "ns3::ObjectVectorValue"; + } + virtual bool HasUnderlyingTypeInformation (void) const { + return true; + } + virtual std::string GetUnderlyingTypeInformation (void) const { + return "ns3::Ptr< " + T::GetTypeId ().GetName () + " >"; + } + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const ObjectVectorValue *src = dynamic_cast (&source); + ObjectVectorValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; + } }; +} // namespace internal + + class ObjectVectorAccessor : public AttributeAccessor { public: - virtual bool Set (ObjectBase * object, Attribute value) const; - virtual bool Get (const ObjectBase * object, Attribute value) const; + virtual bool Set (ObjectBase * object, const AttributeValue &value) const; + virtual bool Get (const ObjectBase * object, AttributeValue &value) const; + virtual bool HasGetter (void) const; + virtual bool HasSetter (void) const; private: virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const = 0; virtual Ptr DoGet (const ObjectBase *object, uint32_t i) const = 0; @@ -150,6 +200,13 @@ MakeObjectVectorAccessor (INDEX (T::*getN) (void) const, return MakeObjectVectorAccessor (get, getN); } +template +Ptr MakeObjectVectorChecker (void) +{ + return Create > (); +} + + } // namespace ns3 #endif /* OBJECT_VECTOR_H */ diff --git a/src/core/object.cc b/src/core/object.cc index 25f812829..ede4e43ba 100644 --- a/src/core/object.cc +++ b/src/core/object.cc @@ -37,6 +37,32 @@ namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (Object); +Object::AggregateIterator::AggregateIterator () + : m_first (0), + m_current (0) +{} + +bool +Object::AggregateIterator::HasNext (void) const +{ + if (m_current != 0 && m_current->m_next != PeekPointer (m_first)) + { + return true; + } + return false; +} +Ptr +Object::AggregateIterator::Next (void) +{ + m_current = m_current->m_next; + return m_current; +} +Object::AggregateIterator::AggregateIterator (Ptr first) + : m_first (first), + m_current (first) +{} + + TypeId Object::GetInstanceTypeId (void) const { @@ -129,6 +155,12 @@ Object::AggregateObject (Ptr o) NS_ASSERT (o->CheckLoose ()); } +Object::AggregateIterator +Object::GetAggregateIterator (void) const +{ + return AggregateIterator (this); +} + void Object::SetTypeId (TypeId tid) { diff --git a/src/core/object.h b/src/core/object.h index 099b26bbb..00d8036ba 100644 --- a/src/core/object.h +++ b/src/core/object.h @@ -47,6 +47,36 @@ class Object : public ObjectBase public: static TypeId GetTypeId (void); + /** + * \brief Iterate over the objects aggregated to an ns3::Object. + * + * This iterator does not allow you to iterate over the initial + * object used to call Object::GetAggregateIterator. + * + * Note: this is a java-style iterator. + */ + class AggregateIterator + { + public: + AggregateIterator (); + + /** + * \returns true if HasNext can be called and return a non-null + * pointer, false otherwise. + */ + bool HasNext (void) const; + + /** + * \returns the next aggregated object. + */ + Ptr Next (void); + private: + friend class Object; + AggregateIterator (Ptr first); + Ptr m_first; + Ptr m_current; + }; + Object (); virtual ~Object (); @@ -100,6 +130,16 @@ public: */ void AggregateObject (Ptr other); + /** + * \returns an iterator to the first object aggregated to this + * object. + * + * If no objects are aggregated to this object, then, the returned + * iterator will be empty and AggregateIterator::HasNext will + * always return false. + */ + AggregateIterator GetAggregateIterator (void) const; + protected: /** * This method is called by Object::Dispose or by the object's @@ -137,8 +177,11 @@ private: friend Ptr CreateObject (const AttributeList &attributes); template friend Ptr CopyObject (Ptr object); + template + friend Ptr CopyObject (Ptr object); friend class ObjectFactory; + friend class AggregateIterator; Ptr DoGetObject (TypeId tid) const; bool Check (void) const; @@ -203,8 +246,11 @@ private: * and returns the new instance. */ template +Ptr CopyObject (Ptr object); +template Ptr CopyObject (Ptr object); + /** * \param attributes a list of attributes to set on the * object during construction. @@ -242,15 +288,15 @@ Ptr CreateObject (const AttributeList &attributes); */ template Ptr -CreateObject (std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute (), - std::string n5 = "", Attribute v5 = Attribute (), - std::string n6 = "", Attribute v6 = Attribute (), - std::string n7 = "", Attribute v7 = Attribute (), - std::string n8 = "", Attribute v8 = Attribute (), - std::string n9 = "", Attribute v9 = Attribute ()); +CreateObject (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue & v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue & v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue & v7 = EmptyAttributeValue (), + std::string n8 = "", const AttributeValue & v8 = EmptyAttributeValue (), + std::string n9 = "", const AttributeValue & v9 = EmptyAttributeValue ()); @@ -314,6 +360,14 @@ Ptr CopyObject (Ptr object) return p; } +template +Ptr CopyObject (Ptr object) +{ + Ptr p = Ptr (new T (*PeekPointer (object)), false); + NS_ASSERT (p->m_tid == object->m_tid); + return p; +} + template Ptr CreateObject (const AttributeList &attributes) @@ -326,16 +380,15 @@ Ptr CreateObject (const AttributeList &attributes) template Ptr -CreateObject (std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute (), - std::string n5 = "", Attribute v5 = Attribute (), - std::string n6 = "", Attribute v6 = Attribute (), - std::string n7 = "", Attribute v7 = Attribute (), - std::string n8 = "", Attribute v8 = Attribute (), - std::string n9 = "", Attribute v9 = Attribute ()) - +CreateObject (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue & v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue & v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue & v7 = EmptyAttributeValue (), + std::string n8 = "", const AttributeValue & v8 = EmptyAttributeValue (), + std::string n9 = "", const AttributeValue & v9 = EmptyAttributeValue ()) { AttributeList attributes; if (n1 == "") diff --git a/src/core/pointer.cc b/src/core/pointer.cc new file mode 100644 index 000000000..f941d6089 --- /dev/null +++ b/src/core/pointer.cc @@ -0,0 +1,64 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#include "pointer.h" + +namespace ns3 { + +PointerValue::PointerValue () + : m_value () +{} + +PointerValue::PointerValue (Ptr object) + : m_value (object) +{} + +void +PointerValue::SetObject (Ptr object) +{ + m_value = object; +} + +Ptr +PointerValue::GetObject (void) const +{ + return m_value; +} + +Ptr +PointerValue::Copy (void) const +{ + return Create (*this); +} +std::string +PointerValue::SerializeToString (Ptr checker) const +{ + std::ostringstream oss; + oss << m_value; + return oss.str (); +} + +bool +PointerValue::DeserializeFromString (std::string value, Ptr checker) +{ + NS_FATAL_ERROR ("It is not possible to deserialize a pointer."); + return false; +} + +} // namespace ns3 diff --git a/src/core/pointer.h b/src/core/pointer.h new file mode 100644 index 000000000..83ddac3a2 --- /dev/null +++ b/src/core/pointer.h @@ -0,0 +1,338 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + */ +#ifndef NS_POINTER_H +#define NS_POINTER_H + +#include "attribute.h" +#include "object.h" + +namespace ns3 { + +/** + * \brief hold objects of type Ptr + */ +class PointerValue : public AttributeValue +{ +public: + PointerValue (); + + PointerValue (Ptr object); + + void SetObject (Ptr object); + + Ptr GetObject (void) const; + + template + PointerValue (const Ptr &object); + + template + void Set (const Ptr &object); + + template + Ptr Get (void) const; + + template + operator Ptr () const; + + virtual Ptr Copy (void) const; + virtual std::string SerializeToString (Ptr checker) const; + virtual bool DeserializeFromString (std::string value, Ptr checker); + +private: + Ptr m_value; +}; + +template +Ptr +MakePointerAccessor (Ptr T::*memberVariable); +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr)); +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const); +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr), + Ptr (T::*getter) (void) const); +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const, + void (T::*setter) (Ptr)); + +class PointerChecker : public AttributeChecker +{ +public: + virtual TypeId GetPointeeTypeId (void) const = 0; +}; +template +Ptr MakePointerChecker (void); + +} // namespace ns3 + +namespace ns3 { + + +namespace internal { + +template +class APointerChecker : public PointerChecker +{ + virtual bool Check (const AttributeValue &val) const { + const PointerValue *value = dynamic_cast (&val); + if (value == 0) + { + return false; + } + if (value->GetObject () == 0) + { + return true; + } + T *ptr = dynamic_cast (PeekPointer (value->GetObject ())); + if (ptr == 0) + { + return false; + } + return true; + } + virtual std::string GetValueTypeName (void) const { + return "ns3::PointerValue"; + } + virtual bool HasUnderlyingTypeInformation (void) const { + return true; + } + virtual std::string GetUnderlyingTypeInformation (void) const { + TypeId tid = T::GetTypeId (); + return "ns3::Ptr< " + tid.GetName () + " >"; + } + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const PointerValue *src = dynamic_cast (&source); + PointerValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; + } + virtual TypeId GetPointeeTypeId (void) const { + return T::GetTypeId (); + } +}; + +/******************************************************** + * The Accessor associated to + * PointerValue + ********************************************************/ + +template +class PointerAccessor : public AttributeAccessor +{ +public: + virtual ~PointerAccessor () {} + virtual bool Set (ObjectBase * object, const AttributeValue &val) const { + T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + const PointerValue *value = dynamic_cast (&val); + if (value == 0) + { + return false; + } + Ptr ptr = dynamic_cast (PeekPointer (value->GetObject ())); + if (ptr == 0) + { + return false; + } + DoSet (obj, ptr); + return true; + } + virtual bool Get (const ObjectBase * object, AttributeValue &val) const { + const T *obj = dynamic_cast (object); + if (obj == 0) + { + return false; + } + PointerValue *value = dynamic_cast (&val); + if (value == 0) + { + return false; + } + value->Set (DoGet (obj)); + return true; + } +private: + virtual void DoSet (T *object, Ptr value) const = 0; + virtual Ptr DoGet (const T *object) const = 0; +}; + +} // namespace internal + + +template +PointerValue::PointerValue (const Ptr &object) +{ + m_value = object; +} + +template +void +PointerValue::Set (const Ptr &object) +{ + m_value = object; +} + +template +Ptr +PointerValue::Get (void) const +{ + T *v = dynamic_cast (PeekPointer (m_value)); + return v; +} + +template +PointerValue::operator Ptr () const +{ + return Get (); +} + + +template +Ptr +MakePointerAccessor (Ptr T::*memberVariable) +{ + struct MemberVariable : public internal::PointerAccessor + { + Ptr T::*m_memberVariable; + virtual void DoSet (T *object, Ptr value) const { + (object->*m_memberVariable) = value; + } + virtual Ptr DoGet (const T *object) const { + return object->*m_memberVariable; + } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return true; + } + } *spec = new MemberVariable (); + spec->m_memberVariable = memberVariable; + return Ptr (spec, false); +} + +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr)) +{ + struct MemberMethod : public internal::PointerAccessor + { + void (T::*m_setter) (Ptr); + virtual void DoSet (T *object, Ptr value) const { + (object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return 0; + //return (object->*m_getter) (); + } + virtual bool HasGetter (void) const { + return false; + } + virtual bool HasSetter (void) const { + return true; + } + } *spec = new MemberMethod (); + spec->m_setter = setter; + return Ptr (spec, false); +} + +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const) +{ + struct MemberMethod : public internal::PointerAccessor + { + Ptr (T::*m_getter) (void) const; + virtual void DoSet (T *object, Ptr value) const { + //(object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return (object->*m_getter) (); + } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return false; + } + } *spec = new MemberMethod (); + spec->m_getter = getter; + return Ptr (spec, false); +} +template +Ptr +MakePointerAccessor (void (T::*setter) (Ptr), + Ptr (T::*getter) (void) const) +{ + return MakePointerAccessor (getter, setter); +} +template +Ptr +MakePointerAccessor (Ptr (T::*getter) (void) const, + void (T::*setter) (Ptr)) +{ + struct MemberMethod : public internal::PointerAccessor + { + void (T::*m_setter) (Ptr); + Ptr (T::*m_getter) (void) const; + virtual void DoSet (T *object, Ptr value) const { + (object->*m_setter) (value); + } + virtual Ptr DoGet (const T *object) const { + return (object->*m_getter) (); + } + virtual bool HasGetter (void) const { + return true; + } + virtual bool HasSetter (void) const { + return true; + } + } *spec = new MemberMethod (); + spec->m_setter = setter; + spec->m_getter = getter; + return Ptr (spec, false); +} + +template +Ptr +MakePointerChecker (void) +{ + return Create > (); +} + + +} // namespace ns3 + +#endif /* NS_POINTER_H */ diff --git a/src/core/ptr.h b/src/core/ptr.h index ea0f67aca..7aca41da4 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -447,7 +447,6 @@ Ptr::operator * () return *m_ptr; } - template bool Ptr::operator! () diff --git a/src/core/random-variable.cc b/src/core/random-variable.cc index 6ac64288d..dfa369564 100644 --- a/src/core/random-variable.cc +++ b/src/core/random-variable.cc @@ -299,20 +299,6 @@ RandomVariable::Peek (void) const { return m_variable; } -RandomVariable::RandomVariable (Attribute value) - : m_variable (0) -{ - const RandomVariableValue *v = value.DynCast (); - if (v == 0) - { - NS_FATAL_ERROR ("Unexpected type of value. Expected \"RandomVariableValue\""); - } - *this = v->Get (); -} -RandomVariable::operator Attribute () const -{ - return Attribute::Create (*this); -} ATTRIBUTE_VALUE_IMPLEMENT (RandomVariable); ATTRIBUTE_CHECKER_IMPLEMENT (RandomVariable); @@ -1267,7 +1253,7 @@ EmpiricalVariable::CDF(double v, double c) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -// Integer EmpiricalVariableImpl methods +// IntegerValue EmpiricalVariableImpl methods class IntEmpiricalVariableImpl : public EmpiricalVariableImpl { public: diff --git a/src/core/random-variable.h b/src/core/random-variable.h index 9a9aa7be4..4abb36bdb 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -163,10 +163,6 @@ public: */ static void SetRunNumber(uint32_t n); - - RandomVariable (Attribute value); - operator Attribute () const; - private: friend std::ostream &operator << (std::ostream &os, const RandomVariable &var); friend std::istream &operator >> (std::istream &os, RandomVariable &var); @@ -666,6 +662,11 @@ public: std::ostream &operator << (std::ostream &os, const RandomVariable &var); std::istream &operator >> (std::istream &os, RandomVariable &var); +/** + * \class ns3::RandomVariableValue + * \brief hold objects of type ns3::RandomVariable + */ + ATTRIBUTE_VALUE_DEFINE (RandomVariable); ATTRIBUTE_CHECKER_DEFINE (RandomVariable); ATTRIBUTE_ACCESSOR_DEFINE (RandomVariable); diff --git a/src/core/ref-count-base.cc b/src/core/ref-count-base.cc index c641b206c..d376894f6 100644 --- a/src/core/ref-count-base.cc +++ b/src/core/ref-count-base.cc @@ -30,6 +30,15 @@ RefCountBase::RefCountBase() { } +RefCountBase::RefCountBase (const RefCountBase &o) + : m_count (1) +{} +RefCountBase & +RefCountBase::operator = (const RefCountBase &o) +{ + return *this; +} + RefCountBase::~RefCountBase () { } diff --git a/src/core/ref-count-base.h b/src/core/ref-count-base.h index 54915a2c6..4ce8440c9 100644 --- a/src/core/ref-count-base.h +++ b/src/core/ref-count-base.h @@ -41,6 +41,8 @@ class RefCountBase { public: RefCountBase(); + RefCountBase (const RefCountBase &o); + RefCountBase &operator = (const RefCountBase &o); virtual ~RefCountBase (); /** * Increment the reference count. This method should not be called diff --git a/src/core/string.cc b/src/core/string.cc index 4fd0ddd3e..fbd70e2be 100644 --- a/src/core/string.cc +++ b/src/core/string.cc @@ -2,44 +2,8 @@ namespace ns3 { -String::String () - : m_value () -{} -String::String (const char *value) - : m_value (value) -{} -String::String (std::string value) - : m_value (value) -{} -void -String::Set (std::string value) -{ - m_value = value; -} -void -String::Set (const char *value) -{ - m_value = value; -} -std::string -String::Get (void) const -{ - return m_value; -} - -std::ostream & operator << (std::ostream &os, const String &value) -{ - os << value.Get (); - return os; -} -std::istream &operator >> (std::istream &is, String &value) -{ - std::string str; - is >> str; - value = String (str); - return is; -} - -ATTRIBUTE_HELPER_CPP (String); +ATTRIBUTE_CHECKER_IMPLEMENT_WITH_NAME (String, "std::string"); +ATTRIBUTE_CONVERTER_IMPLEMENT (String); +ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME (std::string, String); } // namespace ns3 diff --git a/src/core/string.h b/src/core/string.h index 4d4c81075..65d21590f 100644 --- a/src/core/string.h +++ b/src/core/string.h @@ -7,30 +7,16 @@ namespace ns3 { /** + * \class ns3::StringValue * \brief hold variables of type string * * This class can be used to hold variables of type string, * that is, either char * or std::string. */ -class String -{ -public: - String (); - String (const char *value); - String (std::string value); - void Set (std::string value); - void Set (const char *value); - std::string Get (void) const; - ATTRIBUTE_HELPER_HEADER_1 (String); -private: - std::string m_value; -}; - -std::ostream & operator << (std::ostream &os, const String &value); -std::istream &operator >> (std::istream &is, String &value); - -ATTRIBUTE_HELPER_HEADER_2 (String); +ATTRIBUTE_VALUE_DEFINE_WITH_NAME (std::string, String); +ATTRIBUTE_ACCESSOR_DEFINE (String); +ATTRIBUTE_CHECKER_DEFINE (String); } // namespace ns3 diff --git a/src/core/traced-value.h b/src/core/traced-value.h index 1e45aeaec..0015e39aa 100644 --- a/src/core/traced-value.h +++ b/src/core/traced-value.h @@ -1,3 +1,22 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006,2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ #ifndef TRACED_VALUE_H #define TRACED_VALUE_H @@ -41,25 +60,25 @@ public: Set (o.m_v); return *this; } - TracedValue (const Integer &value) + TracedValue (const IntegerValue &value) : m_v (value.Get ()) {} - operator Integer () const { - return Integer (m_v); + operator IntegerValue () const { + return IntegerValue (m_v); } - TracedValue (const Uinteger &value) + TracedValue (const UintegerValue &value) : m_v (value.Get ()) {} - operator Uinteger () const { - return Uinteger (m_v); + operator UintegerValue () const { + return UintegerValue (m_v); } - TracedValue (const Boolean &value) + TracedValue (const BooleanValue &value) : m_v (value.Get ()) {} - operator Boolean () const { - return Boolean (m_v); + operator BooleanValue () const { + return BooleanValue (m_v); } - TracedValue (const Enum &value) + TracedValue (const EnumValue &value) : m_v (value.Get ()) {} - operator Enum () const { - return Enum (m_v); + operator EnumValue () const { + return EnumValue (m_v); } void ConnectWithoutContext (const CallbackBase &cb) { m_cb.ConnectWithoutContext (cb); diff --git a/src/core/type-id.cc b/src/core/type-id.cc index 819b8ec97..6234cb628 100644 --- a/src/core/type-id.cc +++ b/src/core/type-id.cc @@ -50,14 +50,14 @@ public: std::string name, std::string help, uint32_t flags, - ns3::Attribute initialValue, + ns3::Ptr initialValue, ns3::Ptr spec, ns3::Ptr checker); uint32_t GetAttributeN (uint16_t uid) const; std::string GetAttributeName (uint16_t uid, uint32_t i) const; std::string GetAttributeHelp (uint16_t uid, uint32_t i) const; uint32_t GetAttributeFlags (uint16_t uid, uint32_t i) const; - ns3::Attribute GetAttributeInitialValue (uint16_t uid, uint32_t i) const; + ns3::Ptr GetAttributeInitialValue (uint16_t uid, uint32_t i) const; ns3::Ptr GetAttributeAccessor (uint16_t uid, uint32_t i) const; ns3::Ptr GetAttributeChecker (uint16_t uid, uint32_t i) const; void AddTraceSource (uint16_t uid, @@ -75,7 +75,7 @@ private: std::string name; std::string help; uint32_t flags; - ns3::Attribute initialValue; + ns3::Ptr initialValue; ns3::Ptr param; ns3::Ptr checker; }; @@ -236,7 +236,7 @@ IidManager::AddAttribute (uint16_t uid, std::string name, std::string help, uint32_t flags, - ns3::Attribute initialValue, + ns3::Ptr initialValue, ns3::Ptr spec, ns3::Ptr checker) { @@ -288,7 +288,7 @@ IidManager::GetAttributeFlags (uint16_t uid, uint32_t i) const NS_ASSERT (i < information->attributes.size ()); return information->attributes[i].flags; } -ns3::Attribute +ns3::Ptr IidManager::GetAttributeInitialValue (uint16_t uid, uint32_t i) const { struct IidInformation *information = LookupInformation (uid); @@ -480,7 +480,7 @@ TypeId::IsChildOf (TypeId other) const { tmp = tmp.GetParent (); } - return tmp == other; + return tmp == other && *this != other; } std::string TypeId::GetGroupName (void) const @@ -512,11 +512,11 @@ TypeId::DoAddConstructor (Callback cb) TypeId TypeId::AddAttribute (std::string name, std::string help, - Attribute initialValue, + const AttributeValue &initialValue, Ptr param, Ptr checker) { - Singleton::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue, param, checker); + Singleton::Get ()->AddAttribute (m_tid, name, help, ATTR_SGC, initialValue.Copy (), param, checker); return *this; } @@ -524,11 +524,11 @@ TypeId TypeId::AddAttribute (std::string name, std::string help, uint32_t flags, - Attribute initialValue, + const AttributeValue &initialValue, Ptr param, Ptr checker) { - Singleton::Get ()->AddAttribute (m_tid, name, help, flags, initialValue, param, checker); + Singleton::Get ()->AddAttribute (m_tid, name, help, flags, initialValue.Copy (), param, checker); return *this; } @@ -569,10 +569,10 @@ TypeId::GetAttributeFullName (uint32_t i) const { return GetName () + "::" + GetAttributeName (i); } -Attribute +Ptr TypeId::GetAttributeInitialValue (uint32_t i) const { - Attribute value = Singleton::Get ()->GetAttributeInitialValue (m_tid, i); + Ptr value = Singleton::Get ()->GetAttributeInitialValue (m_tid, i); return value; } Ptr @@ -696,4 +696,9 @@ bool operator != (TypeId a, TypeId b) return a.m_tid != b.m_tid; } +bool operator < (TypeId a, TypeId b) +{ + return a.m_tid < b.m_tid; +} + } // namespace ns3 diff --git a/src/core/type-id.h b/src/core/type-id.h index 159479168..56ef2de94 100644 --- a/src/core/type-id.h +++ b/src/core/type-id.h @@ -163,7 +163,7 @@ public: * \returns the value with which the associated attribute * is initialized. */ - Attribute GetAttributeInitialValue (uint32_t i) const; + Ptr GetAttributeInitialValue (uint32_t i) const; /** * \param i index into attribute array. * \returns the flags associated to the requested attribute. @@ -264,7 +264,7 @@ public: */ TypeId AddAttribute (std::string name, std::string help, - Attribute initialValue, + const AttributeValue &initialValue, Ptr accessor, Ptr checker); @@ -283,7 +283,7 @@ public: TypeId AddAttribute (std::string name, std::string help, uint32_t flags, - Attribute initialValue, + const AttributeValue &initialValue, Ptr accessor, Ptr checker); @@ -308,7 +308,7 @@ public: // The accessor associated to the attribute. Ptr accessor; // The initial value associated to the attribute. - Attribute initialValue; + Ptr initialValue; // The set of access control flags associated to the attribute. uint32_t flags; // The checker associated to the attribute. @@ -357,6 +357,7 @@ private: friend class AttributeList; friend bool operator == (TypeId a, TypeId b); friend bool operator != (TypeId a, TypeId b); + friend bool operator < (TypeId a, TypeId b); /** @@ -375,6 +376,15 @@ private: std::ostream & operator << (std::ostream &os, TypeId tid); std::istream & operator >> (std::istream &is, TypeId &tid); +bool operator == (TypeId a, TypeId b); +bool operator != (TypeId a, TypeId b); +bool operator < (TypeId a, TypeId b); + +/** + * \class ns3::TypeIdValue + * \brief hold objects of type ns3::TypeId + */ + ATTRIBUTE_HELPER_HEADER_2 (TypeId); diff --git a/src/core/uinteger.cc b/src/core/uinteger.cc index 1e8625169..fd43ca990 100644 --- a/src/core/uinteger.cc +++ b/src/core/uinteger.cc @@ -23,40 +23,7 @@ namespace ns3 { -Uinteger::Uinteger (uint64_t value) - : m_value (value) -{} -Uinteger::Uinteger () -{} -void -Uinteger::Set (uint64_t value) -{ - m_value = value; -} -uint64_t -Uinteger::Get (void) const -{ - return m_value; -} -Uinteger::operator uint64_t () const -{ - return m_value; -} -std::ostream & operator << (std::ostream &os, const Uinteger &uinteger) -{ - os << uinteger.Get (); - return os; -} -std::istream & operator >> (std::istream &is, Uinteger &uinteger) -{ - uint64_t v; - is >> v; - uinteger.Set (v); - return is; -} - -ATTRIBUTE_CONVERTER_IMPLEMENT(Uinteger); -ATTRIBUTE_VALUE_IMPLEMENT(Uinteger); +ATTRIBUTE_VALUE_IMPLEMENT_WITH_NAME(uint64_t,Uinteger); namespace internal { @@ -68,27 +35,37 @@ Ptr MakeUintegerChecker (uint64_t min, uint64_t max, std : m_minValue (minValue), m_maxValue (maxValue), m_name (name) {} - virtual bool Check (Attribute value) const { - const UintegerValue *v = value.DynCast (); + virtual bool Check (const AttributeValue &value) const { + const UintegerValue *v = dynamic_cast (&value); if (v == 0) { return false; } - return v->Get ().Get () >= m_minValue && v->Get ().Get () <= m_maxValue; + return v->Get () >= m_minValue && v->Get () <= m_maxValue; } - virtual std::string GetType (void) const { - return m_name; + virtual std::string GetValueTypeName (void) const { + return "ns3::UintegerValue"; } - virtual bool HasTypeConstraints (void) const { + virtual bool HasUnderlyingTypeInformation (void) const { return true; } - virtual std::string GetTypeConstraints (void) const { + virtual std::string GetUnderlyingTypeInformation (void) const { std::ostringstream oss; - oss << m_minValue << ":" << m_maxValue; + oss << m_name << " " << m_minValue << ":" << m_maxValue; return oss.str (); } - virtual Attribute Create (void) const { - return Attribute::Create (); + virtual Ptr Create (void) const { + return ns3::Create (); + } + virtual bool Copy (const AttributeValue &source, AttributeValue &destination) const { + const UintegerValue *src = dynamic_cast (&source); + UintegerValue *dst = dynamic_cast (&destination); + if (src == 0 || dst == 0) + { + return false; + } + *dst = *src; + return true; } uint64_t m_minValue; uint64_t m_maxValue; diff --git a/src/core/uinteger.h b/src/core/uinteger.h index 3c1503951..f6565b309 100644 --- a/src/core/uinteger.h +++ b/src/core/uinteger.h @@ -27,32 +27,20 @@ namespace ns3 { /** + * \class ns3::UintegerValue * \brief Hold an unsigned integer type * + * \anchor uint8_t + * \anchor uint16_t + * \anchor uint32_t + * \anchor uint64_t + * * This class can be used to hold variables of unsigned integer * type such as uint8_t, uint16_t, uint32_t, uint64_t, or, * unsigned int, etc. */ -class Uinteger -{ -public: - Uinteger (uint64_t value); - Uinteger (); - void Set (uint64_t value); - uint64_t Get (void) const; - - operator uint64_t () const; - - ATTRIBUTE_CONVERTER_DEFINE (Uinteger); -private: - uint64_t m_value; -}; - -std::ostream & operator << (std::ostream &os, const Uinteger &uinteger); -std::istream & operator >> (std::istream &is, Uinteger &uinteger); - -ATTRIBUTE_VALUE_DEFINE (Uinteger); +ATTRIBUTE_VALUE_DEFINE_WITH_NAME (uint64_t, Uinteger); ATTRIBUTE_ACCESSOR_DEFINE (Uinteger); template diff --git a/src/core/wscript b/src/core/wscript index 97eed7fd8..bf7ca3b5d 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -46,14 +46,15 @@ def build(bld): 'type-traits-test.cc', 'attribute.cc', 'boolean.cc', - 'attribute-test.cc', 'integer.cc', 'uinteger.cc', 'enum.cc', 'double.cc', 'string.cc', - 'object-factory.cc', + 'pointer.cc', 'object-vector.cc', + 'attribute-test.cc', + 'object-factory.cc', 'global-value.cc', 'traced-callback.cc', 'trace-source-accessor.cc', @@ -100,6 +101,7 @@ def build(bld): 'double.h', 'enum.h', 'string.h', + 'pointer.h', 'object-factory.h', 'attribute-helper.h', 'global-value.h', diff --git a/src/devices/csma/csma-channel.cc b/src/devices/csma/csma-channel.cc index c381f36a1..a17c9db1d 100644 --- a/src/devices/csma/csma-channel.cc +++ b/src/devices/csma/csma-channel.cc @@ -53,11 +53,11 @@ CsmaChannel::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("BitRate", "The maximum bitrate of the channel", - DataRate (0xffffffff), + DataRateValue (DataRate (0xffffffff)), MakeDataRateAccessor (&CsmaChannel::m_bps), MakeDataRateChecker ()) .AddAttribute ("Delay", "Transmission delay through the channel", - Seconds (0), + TimeValue (Seconds (0)), MakeTimeAccessor (&CsmaChannel::m_delay), MakeTimeChecker ()) ; @@ -71,7 +71,7 @@ CsmaChannel::CsmaChannel() : Channel ("Csma Channel") { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_state = IDLE; m_deviceList.clear(); } @@ -79,8 +79,7 @@ CsmaChannel::CsmaChannel() int32_t CsmaChannel::Attach(Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << device); + NS_LOG_FUNCTION (this << device); NS_ASSERT(device != 0); CsmaDeviceRec rec(device); @@ -92,8 +91,7 @@ CsmaChannel::Attach(Ptr device) bool CsmaChannel::Reattach(Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << device); + NS_LOG_FUNCTION (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -118,8 +116,7 @@ CsmaChannel::Reattach(Ptr device) bool CsmaChannel::Reattach(uint32_t deviceId) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << deviceId); + NS_LOG_FUNCTION (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -140,8 +137,7 @@ CsmaChannel::Reattach(uint32_t deviceId) bool CsmaChannel::Detach(uint32_t deviceId) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << deviceId); + NS_LOG_FUNCTION (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -171,8 +167,7 @@ CsmaChannel::Detach(uint32_t deviceId) bool CsmaChannel::Detach(Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << device); + NS_LOG_FUNCTION (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -190,8 +185,7 @@ CsmaChannel::Detach(Ptr device) bool CsmaChannel::TransmitStart(Ptr p, uint32_t srcId) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << srcId); + NS_LOG_FUNCTION (this << p << srcId); NS_LOG_INFO ("UID is " << p->GetUid () << ")"); if (m_state != IDLE) @@ -222,8 +216,7 @@ CsmaChannel::IsActive(uint32_t deviceId) bool CsmaChannel::TransmitEnd() { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << m_currentPkt << m_currentSrc); + NS_LOG_FUNCTION (this << m_currentPkt << m_currentSrc); NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); NS_ASSERT(m_state == TRANSMITTING); @@ -248,8 +241,7 @@ CsmaChannel::TransmitEnd() void CsmaChannel::PropagationCompleteEvent() { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << m_currentPkt); + NS_LOG_FUNCTION (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 8553dc618..dc2c4c720 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -27,6 +27,7 @@ #include "ns3/error-model.h" #include "ns3/enum.h" #include "ns3/boolean.h" +#include "ns3/pointer.h" #include "ns3/trace-source-accessor.h" #include "csma-net-device.h" #include "csma-channel.h" @@ -45,36 +46,36 @@ CsmaNetDevice::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Address", "The address of this device.", - Mac48Address ("ff:ff:ff:ff:ff:ff"), + Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), MakeMac48AddressAccessor (&CsmaNetDevice::m_address), MakeMac48AddressChecker ()) .AddAttribute ("EncapsulationMode", "The mode of link-layer encapsulation to use.", - Enum (LLC), + EnumValue (LLC), MakeEnumAccessor (&CsmaNetDevice::m_encapMode), MakeEnumChecker (ETHERNET_V1, "EthernetV1", IP_ARP, "IpArp", RAW, "Raw", LLC, "Llc")) .AddAttribute ("SendEnable", "should tx be enabled ?", - Boolean (true), + BooleanValue (true), MakeBooleanAccessor (&CsmaNetDevice::m_sendEnable), MakeBooleanChecker ()) .AddAttribute ("ReceiveEnable", "should rx be enabled ?", - Boolean (true), + BooleanValue (true), MakeBooleanAccessor (&CsmaNetDevice::m_receiveEnable), MakeBooleanChecker ()) .AddAttribute ("DataRate", "XXX", - DataRate (0xffffffff), + DataRateValue (DataRate (0xffffffff)), MakeDataRateAccessor (&CsmaNetDevice::m_bps), MakeDataRateChecker ()) .AddAttribute ("RxErrorModel", "XXX", - Ptr (0), - MakePtrAccessor (&CsmaNetDevice::m_receiveErrorModel), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&CsmaNetDevice::m_receiveErrorModel), + MakePointerChecker ()) .AddAttribute ("TxQueue", "XXX", - Ptr (0), - MakePtrAccessor (&CsmaNetDevice::m_queue), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&CsmaNetDevice::m_queue), + MakePointerChecker ()) .AddTraceSource ("Rx", "Receive MAC packet.", MakeTraceSourceAccessor (&CsmaNetDevice::m_rxTrace)) .AddTraceSource ("Drop", "Drop MAC packet.", @@ -88,8 +89,7 @@ CsmaNetDevice::CsmaNetDevice () m_linkUp (false), m_mtu (0xffff) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); m_txMachineState = READY; m_tInterframeGap = Seconds(0); m_channel = 0; @@ -97,14 +97,14 @@ CsmaNetDevice::CsmaNetDevice () CsmaNetDevice::~CsmaNetDevice() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_queue = 0; } void CsmaNetDevice::DoDispose () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_channel = 0; m_node = 0; NetDevice::DoDispose (); @@ -119,35 +119,35 @@ CsmaNetDevice::SetAddress (Mac48Address self) void CsmaNetDevice::SetSendEnable (bool sendEnable) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_sendEnable = sendEnable; } void CsmaNetDevice::SetReceiveEnable (bool receiveEnable) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_receiveEnable = receiveEnable; } bool CsmaNetDevice::IsSendEnabled (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return (m_sendEnable); } bool CsmaNetDevice::IsReceiveEnabled (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return (m_receiveEnable); } void CsmaNetDevice::SetDataRate (DataRate bps) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_channel || bps <= m_channel->GetDataRate ()) { m_bps = bps; @@ -157,7 +157,7 @@ CsmaNetDevice::SetDataRate (DataRate bps) void CsmaNetDevice::SetInterframeGap (Time t) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_tInterframeGap = t; } @@ -166,7 +166,7 @@ CsmaNetDevice::SetBackoffParams (Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t ceiling, uint32_t maxRetries) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_backoff.m_slotTime = slotTime; m_backoff.m_minSlots = minSlots; m_backoff.m_maxSlots = maxSlots; @@ -178,7 +178,7 @@ void CsmaNetDevice::AddHeader (Ptr p, Mac48Address dest, uint16_t protocolNumber) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_encapMode == RAW) { return; @@ -217,7 +217,7 @@ CsmaNetDevice::AddHeader (Ptr p, Mac48Address dest, bool CsmaNetDevice::ProcessHeader (Ptr p, uint16_t & param) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_encapMode == RAW) { return true; @@ -256,7 +256,7 @@ CsmaNetDevice::ProcessHeader (Ptr p, uint16_t & param) void CsmaNetDevice::TransmitStart () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt); NS_LOG_LOGIC ("UID is " << m_currentPkt->GetUid ()); // @@ -323,7 +323,7 @@ CsmaNetDevice::TransmitStart () void CsmaNetDevice::TransmitAbort (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")"); // Try to transmit a new packet @@ -337,7 +337,7 @@ CsmaNetDevice::TransmitAbort (void) void CsmaNetDevice::TransmitCompleteEvent (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // This function is called to finish the process of transmitting a packet. // We need to tell the channel that we've stopped wiggling the wire and @@ -363,7 +363,7 @@ CsmaNetDevice::TransmitCompleteEvent (void) void CsmaNetDevice::TransmitReadyEvent (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // This function is called to enable the transmitter after the interframe // gap has passed. If there are pending transmissions, we use this opportunity @@ -388,8 +388,7 @@ CsmaNetDevice::TransmitReadyEvent (void) bool CsmaNetDevice::Attach (Ptr ch) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &ch); + NS_LOG_FUNCTION (this << &ch); m_channel = ch; @@ -407,16 +406,14 @@ CsmaNetDevice::Attach (Ptr ch) void CsmaNetDevice::AddQueue (Ptr q) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << q); + NS_LOG_FUNCTION (this << q); m_queue = q; } void CsmaNetDevice::AddReceiveErrorModel (Ptr em) { - NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << em << ")"); + NS_LOG_FUNCTION (em); m_receiveErrorModel = em; } @@ -424,7 +421,7 @@ void CsmaNetDevice::AddReceiveErrorModel (Ptr em) void CsmaNetDevice::Receive (Ptr packet) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); EthernetHeader header (false); EthernetTrailer trailer; @@ -522,7 +519,7 @@ CsmaNetDevice::Receive (Ptr packet) Ptr CsmaNetDevice::GetQueue(void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_queue; } @@ -610,8 +607,7 @@ CsmaNetDevice::GetMulticast (void) const Address CsmaNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << multicastGroup); + NS_LOG_FUNCTION (this << multicastGroup); // // First, get the generic multicast address. // @@ -667,7 +663,7 @@ CsmaNetDevice::IsPointToPoint (void) const bool CsmaNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNumber) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("p=" << packet); NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")"); 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 5a055000d..83a7abb46 100644 --- a/src/devices/point-to-point/point-to-point-channel.cc +++ b/src/devices/point-to-point/point-to-point-channel.cc @@ -37,11 +37,11 @@ PointToPointChannel::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("BitRate", "The maximum bitrate of the channel", - DataRate (0xffffffff), + DataRateValue (DataRate (0xffffffff)), MakeDataRateAccessor (&PointToPointChannel::m_bps), MakeDataRateChecker ()) .AddAttribute ("Delay", "Transmission delay through the channel", - Seconds (0), + TimeValue (Seconds (0)), MakeTimeAccessor (&PointToPointChannel::m_delay), MakeTimeChecker ()) ; @@ -56,14 +56,13 @@ PointToPointChannel::PointToPointChannel() Channel ("PointToPoint Channel"), m_nDevices(0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void PointToPointChannel::Attach(Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << device); + NS_LOG_FUNCTION (this << device); NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); NS_ASSERT(device != 0); @@ -86,8 +85,7 @@ PointToPointChannel::TransmitStart(Ptr p, Ptr src, const Time& txTime) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << src); + NS_LOG_FUNCTION (this << p << src); NS_LOG_LOGIC ("UID is " << p->GetUid () << ")"); NS_ASSERT(m_link[0].m_state != INITIALIZING); @@ -107,14 +105,14 @@ PointToPointChannel::TransmitStart(Ptr p, uint32_t PointToPointChannel::GetNDevices (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_nDevices; } Ptr PointToPointChannel::GetPointToPointDevice (uint32_t i) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT(i < 2); return m_link[i].m_src; } @@ -122,21 +120,21 @@ PointToPointChannel::GetPointToPointDevice (uint32_t i) const const DataRate& PointToPointChannel::GetDataRate (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_bps; } const Time& PointToPointChannel::GetDelay (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_delay; } Ptr PointToPointChannel::GetDevice (uint32_t i) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return GetPointToPointDevice (i); } 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 49bbd8551..b59b9d2b4 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/llc-snap-header.h" #include "ns3/error-model.h" #include "ns3/trace-source-accessor.h" +#include "ns3/pointer.h" #include "point-to-point-net-device.h" #include "point-to-point-channel.h" @@ -42,23 +43,23 @@ PointToPointNetDevice::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Address", "The address of this device.", - Mac48Address ("ff:ff:ff:ff:ff:ff"), + Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), MakeMac48AddressAccessor (&PointToPointNetDevice::m_address), MakeMac48AddressChecker ()) .AddAttribute ("DataRate", "The default data rate for point to point links", - DataRate ("10Mb/s"), + DataRateValue (DataRate ("10Mb/s")), MakeDataRateAccessor (&PointToPointNetDevice::m_bps), MakeDataRateChecker ()) .AddAttribute ("ReceiveErrorModel", "XXX", - Ptr (0), - MakePtrAccessor (&PointToPointNetDevice::m_receiveErrorModel), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&PointToPointNetDevice::m_receiveErrorModel), + MakePointerChecker ()) .AddAttribute ("TxQueue", "XXX", - Ptr (0), - MakePtrAccessor (&PointToPointNetDevice::m_queue), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&PointToPointNetDevice::m_queue), + MakePointerChecker ()) .AddAttribute ("InterframeGap", "XXX", - Seconds (0.0), + TimeValue (Seconds (0.0)), MakeTimeAccessor (&PointToPointNetDevice::m_tInterframeGap), MakeTimeChecker ()) .AddTraceSource ("Rx", "Receive MAC packet.", @@ -79,8 +80,7 @@ PointToPointNetDevice::PointToPointNetDevice () m_linkUp (false), m_mtu (0xffff) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); } PointToPointNetDevice::~PointToPointNetDevice () @@ -95,7 +95,7 @@ PointToPointNetDevice::SetAddress (Mac48Address self) void PointToPointNetDevice::AddHeader(Ptr p, uint16_t protocolNumber) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); LlcSnapHeader llc; llc.SetType (protocolNumber); p->AddHeader (llc); @@ -104,7 +104,7 @@ PointToPointNetDevice::AddHeader(Ptr p, uint16_t protocolNumber) bool PointToPointNetDevice::ProcessHeader(Ptr p, uint16_t& param) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); LlcSnapHeader llc; p->RemoveHeader (llc); @@ -115,7 +115,7 @@ PointToPointNetDevice::ProcessHeader(Ptr p, uint16_t& param) void PointToPointNetDevice::DoDispose() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_node = 0; m_channel = 0; m_receiveErrorModel = 0; @@ -124,7 +124,7 @@ void PointToPointNetDevice::DoDispose() void PointToPointNetDevice::SetDataRate(const DataRate& bps) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_channel || bps <= m_channel->GetDataRate ()) { m_bps = bps; @@ -133,15 +133,14 @@ void PointToPointNetDevice::SetDataRate(const DataRate& bps) void PointToPointNetDevice::SetInterframeGap(const Time& t) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_tInterframeGap = t; } bool PointToPointNetDevice::TransmitStart (Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p); + NS_LOG_FUNCTION (this << p); NS_LOG_LOGIC ("UID is " << p->GetUid () << ")"); // // This function is called to start the process of transmitting a packet. @@ -164,7 +163,7 @@ PointToPointNetDevice::TransmitStart (Ptr p) void PointToPointNetDevice::TransmitComplete (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // This function is called to finish the process of transmitting a packet. // We need to tell the channel that we've stopped wiggling the wire and @@ -184,8 +183,7 @@ void PointToPointNetDevice::TransmitComplete (void) bool PointToPointNetDevice::Attach (Ptr ch) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &ch); + NS_LOG_FUNCTION (this << &ch); m_channel = ch; @@ -211,24 +209,21 @@ PointToPointNetDevice::Attach (Ptr ch) void PointToPointNetDevice::AddQueue (Ptr q) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << q); + NS_LOG_FUNCTION (this << q); m_queue = q; } void PointToPointNetDevice::AddReceiveErrorModel (Ptr em) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS ("(" << em << ")"); + NS_LOG_FUNCTION ("(" << em << ")"); m_receiveErrorModel = em; } void PointToPointNetDevice::Receive (Ptr packet) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet); + NS_LOG_FUNCTION (this << packet); uint16_t protocol = 0; if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) @@ -246,7 +241,7 @@ void PointToPointNetDevice::Receive (Ptr packet) Ptr PointToPointNetDevice::GetQueue(void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_queue; } @@ -344,7 +339,7 @@ PointToPointNetDevice::IsPointToPoint (void) const bool PointToPointNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNumber) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest); NS_LOG_LOGIC ("UID is " << packet->GetUid ()); diff --git a/src/devices/wifi/aarf-wifi-manager.cc b/src/devices/wifi/aarf-wifi-manager.cc index 3f0f376f6..23451d704 100644 --- a/src/devices/wifi/aarf-wifi-manager.cc +++ b/src/devices/wifi/aarf-wifi-manager.cc @@ -37,27 +37,27 @@ AarfWifiManager::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.", - Double (2.0), + DoubleValue (2.0), MakeDoubleAccessor (&AarfWifiManager::m_successK), MakeDoubleChecker ()) .AddAttribute ("TimerK", "Multiplication factor for the timer threshold in the AARF algorithm.", - Double (2.0), + DoubleValue (2.0), MakeDoubleAccessor (&AarfWifiManager::m_timerK), MakeDoubleChecker ()) .AddAttribute ("MaxSuccessThreshold", "Maximum value of the success threshold in the AARF algorithm.", - Uinteger (60), + UintegerValue (60), MakeUintegerAccessor (&AarfWifiManager::m_maxSuccessThreshold), MakeUintegerChecker ()) .AddAttribute ("MinTimerThreshold", "The minimum value for the 'timer' threshold in the AARF algorithm.", - Uinteger (15), + UintegerValue (15), MakeUintegerAccessor (&AarfWifiManager::m_minTimerThreshold), MakeUintegerChecker ()) .AddAttribute ("MinSuccessThreshold", "The minimum value for the success threshold in the AARF algorithm.", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&AarfWifiManager::m_minSuccessThreshold), MakeUintegerChecker ()) ; diff --git a/src/devices/wifi/amrr-wifi-manager.cc b/src/devices/wifi/amrr-wifi-manager.cc index f486a16ae..05f0ae2e8 100644 --- a/src/devices/wifi/amrr-wifi-manager.cc +++ b/src/devices/wifi/amrr-wifi-manager.cc @@ -38,27 +38,27 @@ AmrrWifiManager::GetTypeId (void) .AddConstructor () .AddAttribute ("UpdatePeriod", "The interval between decisions about rate control changes", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod), MakeTimeChecker ()) .AddAttribute ("FailureRatio", "Ratio of minimum erronous transmissions needed to switch to a lower rate", - Double (1.0/3.0), + DoubleValue (1.0/3.0), MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio), MakeDoubleChecker (0.0, 1.0)) .AddAttribute ("SuccessRatio", "Ratio of maximum erronous transmissions needed to switch to a higher rate", - Double (1.0/10.0), + DoubleValue (1.0/10.0), MakeDoubleAccessor (&AmrrWifiManager::m_successRatio), MakeDoubleChecker (0.0, 1.0)) .AddAttribute ("MaxSuccessThreshold", "Maximum number of consecutive success periods needed to switch to a higher rate", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold), MakeUintegerChecker ()) .AddAttribute ("MinSuccessThreshold", "Minimum number of consecutive success periods needed to switch to a higher rate", - Uinteger (1), + UintegerValue (1), MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold), MakeUintegerChecker ()) ; diff --git a/src/devices/wifi/amrr-wifi-manager.h b/src/devices/wifi/amrr-wifi-manager.h index 5fa4aede1..c639f6666 100644 --- a/src/devices/wifi/amrr-wifi-manager.h +++ b/src/devices/wifi/amrr-wifi-manager.h @@ -25,6 +25,14 @@ namespace ns3 { +/** + * \brief AMRR Rate control algorithm + * + * This class implements the AMRR rate control algorithm which + * was initially described in IEEE 802.11 Rate Adaptation: + * A Practical Approach, by M. Lacage, M.H. Manshaei, and + * T. Turletti. + */ class AmrrWifiManager : public WifiRemoteStationManager { public: diff --git a/src/devices/wifi/arf-wifi-manager.cc b/src/devices/wifi/arf-wifi-manager.cc index bb410089b..e20e0b73e 100644 --- a/src/devices/wifi/arf-wifi-manager.cc +++ b/src/devices/wifi/arf-wifi-manager.cc @@ -228,12 +228,12 @@ ArfWifiManager::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("TimerThreshold", "The 'timer' threshold in the ARF algorithm.", - Uinteger (15), + UintegerValue (15), MakeUintegerAccessor (&ArfWifiManager::m_timerThreshold), MakeUintegerChecker ()) .AddAttribute ("SuccessThreshold", "The minimum number of sucessfull transmissions to try a new rate.", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&ArfWifiManager::m_successThreshold), MakeUintegerChecker ()) ; diff --git a/src/devices/wifi/constant-rate-wifi-manager.cc b/src/devices/wifi/constant-rate-wifi-manager.cc index f81a40676..d8586c77b 100644 --- a/src/devices/wifi/constant-rate-wifi-manager.cc +++ b/src/devices/wifi/constant-rate-wifi-manager.cc @@ -78,11 +78,11 @@ ConstantRateWifiManager::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("DataMode", "XXX", - String ("wifia-6mbs"), + StringValue ("wifia-6mbs"), MakeWifiModeAccessor (&ConstantRateWifiManager::m_dataMode), MakeWifiModeChecker ()) .AddAttribute ("ControlMode", "XXX", - String ("wifia-6mbs"), + StringValue ("wifia-6mbs"), MakeWifiModeAccessor (&ConstantRateWifiManager::m_ctlMode), MakeWifiModeChecker ()) ; diff --git a/src/devices/wifi/dca-txop.cc b/src/devices/wifi/dca-txop.cc index 170b4b3c5..9eee9cb9d 100644 --- a/src/devices/wifi/dca-txop.cc +++ b/src/devices/wifi/dca-txop.cc @@ -37,7 +37,7 @@ NS_LOG_COMPONENT_DEFINE ("DcaTxop"); #define MY_DEBUG(x) \ - NS_LOG_DEBUG (Simulator::Now () << " " << m_low->GetMac ()->GetAddress () << " " << x) + NS_LOG_DEBUG (m_low->GetMac ()->GetAddress () << " " << x) namespace ns3 { @@ -100,17 +100,17 @@ DcaTxop::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("MinCw", "XXX", - Uinteger (15), + UintegerValue (15), MakeUintegerAccessor (&DcaTxop::SetMinCw, &DcaTxop::GetMinCw), MakeUintegerChecker ()) .AddAttribute ("MaxCw", "XXX", - Uinteger (1023), + UintegerValue (1023), MakeUintegerAccessor (&DcaTxop::SetMaxCw, &DcaTxop::GetMaxCw), MakeUintegerChecker ()) .AddAttribute ("Aifsn", "XXX", - Uinteger (2), + UintegerValue (2), MakeUintegerAccessor (&DcaTxop::SetAifsn, &DcaTxop::GetAifsn), MakeUintegerChecker ()) @@ -122,6 +122,7 @@ DcaTxop::DcaTxop () : m_manager (0), m_currentPacket (0) { + NS_LOG_FUNCTION (this); m_transmissionListener = new DcaTxop::TransmissionListener (this); m_dcf = new DcaTxop::Dcf (this); m_queue = CreateObject (); @@ -130,11 +131,14 @@ DcaTxop::DcaTxop () } DcaTxop::~DcaTxop () -{} +{ + NS_LOG_FUNCTION (this); +} void DcaTxop::DoDispose (void) { + NS_LOG_FUNCTION (this); delete m_transmissionListener; delete m_dcf; delete m_rng; @@ -151,6 +155,7 @@ DcaTxop::DoDispose (void) void DcaTxop::SetManager (DcfManager *manager) { + NS_LOG_FUNCTION (this << manager); m_manager = manager; m_manager->Add (m_dcf); } @@ -158,11 +163,13 @@ DcaTxop::SetManager (DcfManager *manager) void DcaTxop::SetLow (Ptr low) { + NS_LOG_FUNCTION (this << low); m_low = low; } void DcaTxop::SetWifiRemoteStationManager (Ptr remoteManager) { + NS_LOG_FUNCTION (this << remoteManager); m_stationManager = remoteManager; } void @@ -179,26 +186,31 @@ DcaTxop::SetTxFailedCallback (TxFailed callback) void DcaTxop::SetMaxQueueSize (uint32_t size) { + NS_LOG_FUNCTION (this << size); m_queue->SetMaxSize (size); } void DcaTxop::SetMaxQueueDelay (Time delay) { + NS_LOG_FUNCTION (this << delay); m_queue->SetMaxDelay (delay); } void DcaTxop::SetMinCw (uint32_t minCw) { + NS_LOG_FUNCTION (this << minCw); m_dcf->SetCwMin (minCw); } void DcaTxop::SetMaxCw (uint32_t maxCw) { + NS_LOG_FUNCTION (this << maxCw); m_dcf->SetCwMax (maxCw); } void DcaTxop::SetAifsn (uint32_t aifsn) { + NS_LOG_FUNCTION (this << aifsn); m_dcf->SetAifsn (aifsn); } uint32_t @@ -220,6 +232,7 @@ DcaTxop::GetAifsn (void) const void DcaTxop::Queue (Ptr packet, WifiMacHeader const &hdr) { + NS_LOG_FUNCTION (this << packet << &hdr); WifiMacTrailer fcs; uint32_t fullPacketSize = hdr.GetSerializedSize () + packet->GetSize () + fcs.GetSerializedSize (); WifiRemoteStation *station = GetStation (hdr.GetAddr1 ()); @@ -237,6 +250,7 @@ DcaTxop::GetStation (Mac48Address ad) const void DcaTxop::RestartAccessIfNeeded (void) { + NS_LOG_FUNCTION (this); if ((m_currentPacket != 0 || !m_queue->IsEmpty ()) && !m_dcf->IsAccessRequested ()) @@ -248,6 +262,7 @@ DcaTxop::RestartAccessIfNeeded (void) void DcaTxop::StartAccessIfNeeded (void) { + NS_LOG_FUNCTION (this); if (m_currentPacket == 0 && !m_queue->IsEmpty () && !m_dcf->IsAccessRequested ()) @@ -350,6 +365,7 @@ DcaTxop::NeedsAccess (void) const void DcaTxop::NotifyAccessGranted (void) { + NS_LOG_FUNCTION (this); if (m_currentPacket == 0) { if (m_queue->IsEmpty ()) @@ -383,6 +399,7 @@ DcaTxop::NotifyAccessGranted (void) m_currentPacket = 0; m_dcf->ResetCw (); m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + StartAccessIfNeeded (); MY_DEBUG ("tx broadcast"); } else @@ -429,11 +446,13 @@ DcaTxop::NotifyAccessGranted (void) void DcaTxop::NotifyInternalCollision (void) { + NS_LOG_FUNCTION (this); NotifyCollision (); } void DcaTxop::NotifyCollision (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("collision"); m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); RestartAccessIfNeeded (); @@ -442,11 +461,13 @@ DcaTxop::NotifyCollision (void) void DcaTxop::GotCts (double snr, WifiMode txMode) { + NS_LOG_FUNCTION (this << snr << txMode); MY_DEBUG ("got cts"); } void DcaTxop::MissedCts (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("missed cts"); if (!NeedRtsRetransmission ()) { @@ -467,6 +488,7 @@ DcaTxop::MissedCts (void) void DcaTxop::GotAck (double snr, WifiMode txMode) { + NS_LOG_FUNCTION (this << snr << txMode); if (!NeedFragmentation () || IsLastFragment ()) { @@ -492,6 +514,7 @@ DcaTxop::GotAck (double snr, WifiMode txMode) void DcaTxop::MissedAck (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("missed ack"); if (!NeedDataRetransmission ()) { @@ -518,6 +541,7 @@ DcaTxop::MissedAck (void) void DcaTxop::StartNext (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("start next packet fragment"); /* this callback is used only for fragments. */ NextFragment (); @@ -541,6 +565,7 @@ DcaTxop::StartNext (void) void DcaTxop::Cancel (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("transmission cancelled"); /** * This happens in only one case: in an AP, you have two DcaTxop: diff --git a/src/devices/wifi/ideal-wifi-manager.cc b/src/devices/wifi/ideal-wifi-manager.cc index 313673a90..235d887af 100644 --- a/src/devices/wifi/ideal-wifi-manager.cc +++ b/src/devices/wifi/ideal-wifi-manager.cc @@ -23,17 +23,6 @@ #include "ns3/double.h" #include -#define noIDEAL_DEBUG 1 - -#ifdef IDEAL_DEBUG -#include -# define TRACE(x) \ -std::cout << "IDEAL TRACE " << x << std::endl; -#else -# define TRACE(x) -#endif - - namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager); @@ -46,7 +35,7 @@ IdealWifiManager::GetTypeId (void) .AddConstructor () .AddAttribute ("BerThreshold", "The maximum Bit Error Rate acceptable at any transmission mode", - Double (10e-6), + DoubleValue (10e-6), MakeDoubleAccessor (&IdealWifiManager::m_ber), MakeDoubleChecker ()) ; @@ -115,13 +104,11 @@ IdealWifiRemoteStation::DoReportDataFailed (void) void IdealWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) { - TRACE ("got cts for rts snr="< ()) .AddAttribute ("NumberOfOscillatorsPerRay", "The number of oscillators to use by default for compute the coeficent for a given ray of a given path (default is 4)", - Uinteger (4), + UintegerValue (4), MakeUintegerAccessor (&JakesPropagationLossModel::m_nOscillators), MakeUintegerChecker ()) .AddAttribute ("DopplerFreq", "The doppler frequency in Hz (f_d = v / lambda = v * f / c, the defualt is 0)", - Double(0.0), + DoubleValue (0.0), MakeDoubleAccessor (&JakesPropagationLossModel::m_fd), MakeDoubleChecker ()) .AddAttribute ("Distribution", "The distribution to choose the initial phases.", - ConstantVariable (1.0), + RandomVariableValue (ConstantVariable (1.0)), MakeRandomVariableAccessor (&JakesPropagationLossModel::m_variable), MakeRandomVariableChecker ()) ; diff --git a/src/devices/wifi/mac-low.cc b/src/devices/wifi/mac-low.cc index 925b3f2c8..cfeb812f2 100644 --- a/src/devices/wifi/mac-low.cc +++ b/src/devices/wifi/mac-low.cc @@ -33,7 +33,7 @@ NS_LOG_COMPONENT_DEFINE ("MacLow"); #define MY_DEBUG(x) \ - NS_LOG_DEBUG (Simulator::Now () << " " << m_mac->GetAddress () << " " << x) + NS_LOG_DEBUG (m_mac->GetAddress () << " " << x) namespace ns3 { @@ -215,7 +215,30 @@ MacLowTransmissionParameters::GetNextPacketSize (void) const return m_nextSize; } - +std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms) +{ + os << "[" + << "send rts=" << params.m_sendRts << ", " + << "next size=" << params.m_nextSize << ", " + << "dur=" << params.m_overrideDurationId << ", " + << "ack="; + switch (params.m_waitAck) { + case MacLowTransmissionParameters::ACK_NONE: + os << "none"; + break; + case MacLowTransmissionParameters::ACK_NORMAL: + os << "normal"; + break; + case MacLowTransmissionParameters::ACK_FAST: + os << "fast"; + break; + case MacLowTransmissionParameters::ACK_SUPER_FAST: + os << "super-fast"; + break; + } + os << "]"; + return os; +} MacLow::MacLow () : m_normalAckTimeoutEvent (), @@ -230,16 +253,20 @@ MacLow::MacLow () m_currentPacket (0), m_listener (0) { + NS_LOG_FUNCTION (this); m_lastNavDuration = Seconds (0); m_lastNavStart = Seconds (0); } MacLow::~MacLow () -{} +{ + NS_LOG_FUNCTION (this); +} void MacLow::DoDispose (void) { + NS_LOG_FUNCTION (this); CancelAllEvents (); m_phy = 0; m_mac = 0; @@ -249,6 +276,7 @@ MacLow::DoDispose (void) void MacLow::CancelAllEvents (void) { + NS_LOG_FUNCTION (this); bool oneRunning = false; if (m_normalAckTimeoutEvent.IsRunning ()) { @@ -339,9 +367,10 @@ MacLow::RegisterNavListener (MacLowNavListener *listener) void MacLow::StartTransmission (Ptr packet, WifiMacHeader const*hdr, - MacLowTransmissionParameters parameters, + MacLowTransmissionParameters params, MacLowTransmissionListener *listener) { + NS_LOG_FUNCTION (this << packet << hdr << params << listener); /* m_currentPacket is not NULL because someone started * a transmission and was interrupted before one of: * - ctsTimeout @@ -360,7 +389,7 @@ MacLow::StartTransmission (Ptr packet, m_currentHdr = *hdr; CancelAllEvents (); m_listener = listener; - m_txParams = parameters; + m_txParams = params; //NS_ASSERT (m_phy->IsStateIdle ()); @@ -383,6 +412,7 @@ MacLow::StartTransmission (Ptr packet, void MacLow::ReceiveError (Ptr packet, double rxSnr) { + NS_LOG_FUNCTION (this << packet << rxSnr); MY_DEBUG ("rx failed "); if (m_txParams.MustWaitFastAck ()) { @@ -396,6 +426,7 @@ MacLow::ReceiveError (Ptr packet, double rxSnr) void MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamble preamble) { + NS_LOG_FUNCTION (this << packet << rxSnr << txMode << preamble); /* A packet is received from the PHY. * When we have handled this packet, * we handle any packet present in the @@ -754,6 +785,7 @@ void MacLow::ForwardDown (Ptr packet, WifiMacHeader const* hdr, WifiMode txMode) { + NS_LOG_FUNCTION (this << packet << hdr << txMode); MY_DEBUG ("send " << hdr->GetTypeString () << ", to=" << hdr->GetAddr1 () << ", size=" << packet->GetSize () << @@ -773,6 +805,7 @@ MacLow::ForwardDown (Ptr packet, WifiMacHeader const* hdr, void MacLow::CtsTimeout (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("cts timeout"); // XXX: should check that there was no rx start before now. // we should restart a new cts timeout now until the expected @@ -787,6 +820,7 @@ MacLow::CtsTimeout (void) void MacLow::NormalAckTimeout (void) { + NS_LOG_FUNCTION (this); MY_DEBUG ("normal ack timeout"); // XXX: should check that there was no rx start before now. // we should restart a new ack timeout now until the expected @@ -800,6 +834,7 @@ MacLow::NormalAckTimeout (void) void MacLow::FastAckTimeout (void) { + NS_LOG_FUNCTION (this); WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); station->ReportDataFailed (); MacLowTransmissionListener *listener = m_listener; @@ -817,6 +852,7 @@ MacLow::FastAckTimeout (void) void MacLow::SuperFastAckTimeout () { + NS_LOG_FUNCTION (this); WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); station->ReportDataFailed (); MacLowTransmissionListener *listener = m_listener; @@ -836,6 +872,7 @@ MacLow::SuperFastAckTimeout () void MacLow::SendRtsForPacket (void) { + NS_LOG_FUNCTION (this); /* send an RTS for this packet. */ WifiMacHeader rts; rts.SetType (WIFI_MAC_CTL_RTS); @@ -917,6 +954,7 @@ MacLow::StartDataTxTimers (void) void MacLow::SendDataPacket (void) { + NS_LOG_FUNCTION (this); /* send this packet directly. No RTS is needed. */ StartDataTxTimers (); @@ -977,6 +1015,7 @@ MacLow::GetStation (Mac48Address ad) const void MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, double rtsSnr) { + NS_LOG_FUNCTION (this); /* send a CTS when you receive a RTS * right after SIFS. */ @@ -1007,6 +1046,7 @@ MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, void MacLow::SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode) { + NS_LOG_FUNCTION (this); /* send the third step in a * RTS/CTS/DATA/ACK hanshake */ @@ -1043,6 +1083,7 @@ MacLow::WaitSifsAfterEndTx (void) void MacLow::FastAckFailedTimeout (void) { + NS_LOG_FUNCTION (this); MacLowTransmissionListener *listener = m_listener; m_listener = 0; listener->MissedAck (); @@ -1052,6 +1093,7 @@ MacLow::FastAckFailedTimeout (void) void MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMode, double dataSnr) { + NS_LOG_FUNCTION (this); /* send an ACK when you receive * a packet after SIFS. */ diff --git a/src/devices/wifi/mac-low.h b/src/devices/wifi/mac-low.h index 61d22380f..5da165114 100644 --- a/src/devices/wifi/mac-low.h +++ b/src/devices/wifi/mac-low.h @@ -22,6 +22,7 @@ #include #include +#include #include "wifi-mac-header.h" #include "wifi-mode.h" @@ -252,6 +253,7 @@ public: uint32_t GetNextPacketSize (void) const; private: + friend std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms); uint32_t m_nextSize; enum { ACK_NONE, @@ -263,6 +265,8 @@ private: Time m_overrideDurationId; }; +std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms); + /** * \brief handle RTS/CTS/DATA/ACK transactions. diff --git a/src/devices/wifi/mac-rx-middle.cc b/src/devices/wifi/mac-rx-middle.cc index 56c9594a6..6aeefe494 100644 --- a/src/devices/wifi/mac-rx-middle.cc +++ b/src/devices/wifi/mac-rx-middle.cc @@ -29,8 +29,6 @@ NS_LOG_COMPONENT_DEFINE ("MacRxMiddle"); -#define TRACE(x) NS_LOG_DEBUG(Simulator::Now () << " " << x) - namespace ns3 { @@ -99,10 +97,13 @@ public: MacRxMiddle::MacRxMiddle () -{} +{ + NS_LOG_FUNCTION_NOARGS (); +} MacRxMiddle::~MacRxMiddle () { + NS_LOG_FUNCTION_NOARGS (); for (OriginatorsI i = m_originatorStatus.begin (); i != m_originatorStatus.end (); i++) { @@ -122,16 +123,18 @@ MacRxMiddle::~MacRxMiddle () void MacRxMiddle::SetForwardCallback (ForwardUpCallback callback) { + NS_LOG_FUNCTION_NOARGS (); m_callback = callback; } bool MacRxMiddle::SequenceControlSmaller (int seqca, int seqcb) { + NS_LOG_FUNCTION (seqca << seqcb); int seqa = seqca >> 4; int seqb = seqcb >> 4; int delta = seqb - seqa; - TRACE ("seqb="< packet, WifiMacHeader const*hdr, { if (originator->IsNextFragment (hdr->GetSequenceControl ())) { - TRACE ("accumulate last fragment seq="<GetSequenceNumber ()<< + NS_LOG_DEBUG ("accumulate last fragment seq="<GetSequenceNumber ()<< ", frag="<GetFragmentNumber ()<< ", size="<GetSize ()); Ptr p = originator->AccumulateLastFragment (packet); @@ -227,7 +233,7 @@ MacRxMiddle::HandleFragments (Ptr packet, WifiMacHeader const*hdr, } else { - TRACE ("non-ordered fragment"); + NS_LOG_DEBUG ("non-ordered fragment"); return 0; } } @@ -236,7 +242,7 @@ MacRxMiddle::HandleFragments (Ptr packet, WifiMacHeader const*hdr, { if (hdr->IsMoreFragments ()) { - TRACE ("accumulate first fragment seq="<GetSequenceNumber ()<< + NS_LOG_DEBUG ("accumulate first fragment seq="<GetSequenceNumber ()<< ", frag="<GetFragmentNumber ()<< ", size="<GetSize ()); originator->AccumulateFirstFragment (packet); @@ -253,6 +259,7 @@ MacRxMiddle::HandleFragments (Ptr packet, WifiMacHeader const*hdr, void MacRxMiddle::Receive (Ptr packet, WifiMacHeader const *hdr) { + NS_LOG_FUNCTION (packet << hdr); OriginatorRxStatus *originator = Lookup (hdr); if (hdr->IsData ()) { @@ -272,7 +279,7 @@ MacRxMiddle::Receive (Ptr packet, WifiMacHeader const *hdr) // filter duplicates. if (IsDuplicate (hdr, originator)) { - TRACE ("duplicate from="<GetAddr2 ()<< + NS_LOG_DEBUG ("duplicate from="<GetAddr2 ()<< ", seq="<GetSequenceNumber ()<< ", frag="<GetFragmentNumber ()); return; @@ -282,7 +289,7 @@ MacRxMiddle::Receive (Ptr packet, WifiMacHeader const *hdr) { return; } - TRACE ("forwarding data from="<GetAddr2 ()<< + NS_LOG_DEBUG ("forwarding data from="<GetAddr2 ()<< ", seq="<GetSequenceNumber ()<< ", frag="<GetFragmentNumber ()); if (!hdr->GetAddr1 ().IsBroadcast ()) @@ -293,7 +300,7 @@ MacRxMiddle::Receive (Ptr packet, WifiMacHeader const *hdr) } else { - TRACE ("forwarding "<GetTypeString ()<< + NS_LOG_DEBUG ("forwarding "<GetTypeString ()<< ", from="<GetAddr2 ()<< ", seq="<GetSequenceNumber ()<< ", frag="<GetFragmentNumber ()); diff --git a/src/devices/wifi/nqap-wifi-mac.cc b/src/devices/wifi/nqap-wifi-mac.cc index afa725c19..e156d2f3b 100644 --- a/src/devices/wifi/nqap-wifi-mac.cc +++ b/src/devices/wifi/nqap-wifi-mac.cc @@ -33,9 +33,6 @@ NS_LOG_COMPONENT_DEFINE ("NqapWifiMac"); -#define TRACE(x) \ - NS_LOG_DEBUG(Simulator::Now () << " " << GetAddress () << " " << x); - namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (NqapWifiMac); @@ -47,11 +44,11 @@ NqapWifiMac::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("BeaconInterval", "Delay between two beacons", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&NqapWifiMac::m_beaconInterval), MakeTimeChecker ()) .AddAttribute ("BeaconGeneration", "Whether or not beacons are generated.", - Boolean (false), + BooleanValue (false), MakeBooleanAccessor (&NqapWifiMac::SetBeaconGeneration, &NqapWifiMac::GetBeaconGeneration), MakeBooleanChecker ()) @@ -61,6 +58,7 @@ NqapWifiMac::GetTypeId (void) NqapWifiMac::NqapWifiMac () { + NS_LOG_FUNCTION (this); m_rxMiddle = new MacRxMiddle (); m_rxMiddle->SetForwardCallback (MakeCallback (&NqapWifiMac::Receive, this)); @@ -82,11 +80,14 @@ NqapWifiMac::NqapWifiMac () m_beaconDca->SetManager (m_dcfManager); } NqapWifiMac::~NqapWifiMac () -{} +{ + NS_LOG_FUNCTION (this); +} void NqapWifiMac::DoDispose (void) { + NS_LOG_FUNCTION (this); delete m_rxMiddle; delete m_dcfManager; m_rxMiddle = 0; @@ -102,6 +103,7 @@ NqapWifiMac::DoDispose (void) void NqapWifiMac::SetBeaconGeneration (bool enable) { + NS_LOG_FUNCTION (this << enable); if (enable) { m_beaconEvent = Simulator::ScheduleNow (&NqapWifiMac::SendOneBeacon, this); @@ -121,18 +123,21 @@ NqapWifiMac::GetBeaconGeneration (void) const void NqapWifiMac::SetSlot (Time slotTime) { + NS_LOG_FUNCTION (this << slotTime); m_dcfManager->SetSlot (slotTime); m_slot = slotTime; } void NqapWifiMac::SetSifs (Time sifs) { + NS_LOG_FUNCTION (this << sifs); m_dcfManager->SetSifs (sifs); m_sifs = sifs; } void NqapWifiMac::SetEifsNoDifs (Time eifsNoDifs) { + NS_LOG_FUNCTION (this << eifsNoDifs); m_dcfManager->SetEifsNoDifs (eifsNoDifs); m_eifsNoDifs = eifsNoDifs; } @@ -156,6 +161,7 @@ NqapWifiMac::GetEifsNoDifs (void) const void NqapWifiMac::SetWifiPhy (Ptr phy) { + NS_LOG_FUNCTION (this << phy); m_phy = phy; m_dcfManager->SetupPhyListener (phy); m_low->SetPhy (phy); @@ -163,6 +169,7 @@ NqapWifiMac::SetWifiPhy (Ptr phy) void NqapWifiMac::SetWifiRemoteStationManager (Ptr stationManager) { + NS_LOG_FUNCTION (this << stationManager); m_stationManager = stationManager; m_dca->SetWifiRemoteStationManager (stationManager); m_beaconDca->SetWifiRemoteStationManager (stationManager); @@ -171,11 +178,13 @@ NqapWifiMac::SetWifiRemoteStationManager (Ptr stationM void NqapWifiMac::SetForwardUpCallback (Callback, const Mac48Address &> upCallback) { + NS_LOG_FUNCTION (this); m_upCallback = upCallback; } void NqapWifiMac::SetLinkUpCallback (Callback linkUp) { + NS_LOG_FUNCTION (this); if (!linkUp.IsNull ()) { linkUp (); @@ -183,7 +192,9 @@ NqapWifiMac::SetLinkUpCallback (Callback linkUp) } void NqapWifiMac::SetLinkDownCallback (Callback linkDown) -{} +{ + NS_LOG_FUNCTION (this); +} Mac48Address NqapWifiMac::GetAddress (void) const { @@ -202,11 +213,13 @@ NqapWifiMac::GetBssid (void) const void NqapWifiMac::SetAddress (Mac48Address address) { + NS_LOG_FUNCTION (address); m_address = address; } void NqapWifiMac::SetSsid (Ssid ssid) { + NS_LOG_FUNCTION (ssid); m_ssid = ssid; } @@ -214,21 +227,25 @@ NqapWifiMac::SetSsid (Ssid ssid) void NqapWifiMac::SetBeaconInterval (Time interval) { + NS_LOG_FUNCTION (this << interval); m_beaconInterval = interval; } void NqapWifiMac::StartBeaconing (void) { + NS_LOG_FUNCTION (this); SendOneBeacon (); } void NqapWifiMac::ForwardUp (Ptr packet, Mac48Address from) { + NS_LOG_FUNCTION (this << packet << from); m_upCallback (packet, from); } void NqapWifiMac::ForwardDown (Ptr packet, Mac48Address from, Mac48Address to) { + NS_LOG_FUNCTION (this << packet << from << to); WifiMacHeader hdr; hdr.SetTypeData (); hdr.SetAddr1 (to); @@ -241,6 +258,7 @@ NqapWifiMac::ForwardDown (Ptr packet, Mac48Address from, Mac48Addr void NqapWifiMac::Enqueue (Ptr packet, Mac48Address to) { + NS_LOG_FUNCTION (this << packet << to); ForwardDown (packet, GetAddress (), to); } SupportedRates @@ -265,7 +283,7 @@ NqapWifiMac::GetSupportedRates (void) const void NqapWifiMac::SendProbeResp (Mac48Address to) { - TRACE ("send probe response to="< () .AddConstructor () .AddAttribute ("ProbeRequestTimeout", "XXX", - Seconds (0.5), + TimeValue (Seconds (0.5)), MakeTimeAccessor (&NqstaWifiMac::m_probeRequestTimeout), MakeTimeChecker ()) .AddAttribute ("AssocRequestTimeout", "XXX", - Seconds (0.5), + TimeValue (Seconds (0.5)), MakeTimeAccessor (&NqstaWifiMac::m_assocRequestTimeout), MakeTimeChecker ()) .AddAttribute ("MaxMissedBeacons", "Number of beacons which much be consecutively missed before " "we attempt to restart association.", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&NqstaWifiMac::m_maxMissedBeacons), MakeUintegerChecker ()) .AddAttribute ("ActiveProbing", "XXX", - Boolean (false), + BooleanValue (false), MakeBooleanAccessor (&NqstaWifiMac::SetActiveProbing), MakeBooleanChecker ()) ; @@ -94,6 +91,7 @@ NqstaWifiMac::NqstaWifiMac () m_assocRequestEvent (), m_beaconWatchdogEnd (Seconds (0.0)) { + NS_LOG_FUNCTION (this); m_rxMiddle = new MacRxMiddle (); m_rxMiddle->SetForwardCallback (MakeCallback (&NqstaWifiMac::Receive, this)); @@ -110,11 +108,14 @@ NqstaWifiMac::NqstaWifiMac () } NqstaWifiMac::~NqstaWifiMac () -{} +{ + NS_LOG_FUNCTION (this); +} void NqstaWifiMac::DoDispose (void) { + NS_LOG_FUNCTION (this); delete m_rxMiddle; delete m_dcfManager; m_rxMiddle = 0; @@ -128,18 +129,21 @@ NqstaWifiMac::DoDispose (void) void NqstaWifiMac::SetSlot (Time slotTime) { + NS_LOG_FUNCTION (this << slotTime); m_dcfManager->SetSlot (slotTime); m_slot = slotTime; } void NqstaWifiMac::SetSifs (Time sifs) { + NS_LOG_FUNCTION (this << sifs); m_dcfManager->SetSifs (sifs); m_sifs = sifs; } void NqstaWifiMac::SetEifsNoDifs (Time eifsNoDifs) { + NS_LOG_FUNCTION (this << eifsNoDifs); m_dcfManager->SetEifsNoDifs (eifsNoDifs); m_eifsNoDifs = eifsNoDifs; } @@ -206,33 +210,39 @@ NqstaWifiMac::GetBssid (void) const void NqstaWifiMac::SetAddress (Mac48Address address) { + NS_LOG_FUNCTION (this << address); m_address = address; } void NqstaWifiMac::SetSsid (Ssid ssid) { + NS_LOG_FUNCTION (this << ssid); m_ssid = ssid; } void NqstaWifiMac::SetMaxMissedBeacons (uint32_t missed) { + NS_LOG_FUNCTION (this << missed); m_maxMissedBeacons = missed; } void NqstaWifiMac::SetProbeRequestTimeout (Time timeout) { + NS_LOG_FUNCTION (this << timeout); m_probeRequestTimeout = timeout; } void NqstaWifiMac::SetAssocRequestTimeout (Time timeout) { + NS_LOG_FUNCTION (this << timeout); m_assocRequestTimeout = timeout; } void NqstaWifiMac::StartActiveAssociation (void) { + NS_LOG_FUNCTION (this); TryToEnsureAssociated (); } @@ -245,11 +255,13 @@ NqstaWifiMac::GetBroadcastBssid (void) void NqstaWifiMac::SetBssid (Mac48Address bssid) { + NS_LOG_FUNCTION (this << bssid); m_bssid = bssid; } void NqstaWifiMac::SetActiveProbing (bool enable) { + NS_LOG_FUNCTION (this << enable); if (enable) { TryToEnsureAssociated (); @@ -262,12 +274,13 @@ NqstaWifiMac::SetActiveProbing (bool enable) void NqstaWifiMac::ForwardUp (Ptr packet, const Mac48Address &address) { + NS_LOG_FUNCTION (this << packet << address); m_forwardUp (packet, address); } void NqstaWifiMac::SendProbeRequest (void) { - TRACE ("send probe request"); + NS_LOG_FUNCTION (this); WifiMacHeader hdr; hdr.SetProbeReq (); hdr.SetAddr1 (GetBroadcastBssid ()); @@ -290,7 +303,7 @@ NqstaWifiMac::SendProbeRequest (void) void NqstaWifiMac::SendAssociationRequest (void) { - TRACE ("send assoc request to=" << GetBssid ()); + NS_LOG_FUNCTION (this << GetBssid ()); WifiMacHeader hdr; hdr.SetAssocReq (); hdr.SetAddr1 (GetBssid ()); @@ -312,6 +325,7 @@ NqstaWifiMac::SendAssociationRequest (void) void NqstaWifiMac::TryToEnsureAssociated (void) { + NS_LOG_FUNCTION (this); switch (m_state) { case ASSOCIATED: return; @@ -351,37 +365,40 @@ NqstaWifiMac::TryToEnsureAssociated (void) void NqstaWifiMac::AssocRequestTimeout (void) { - TRACE ("assoc request timeout"); + NS_LOG_FUNCTION (this); m_state = WAIT_ASSOC_RESP; SendAssociationRequest (); } void NqstaWifiMac::ProbeRequestTimeout (void) { - TRACE ("probe request timeout"); + NS_LOG_FUNCTION (this); m_state = WAIT_PROBE_RESP; SendProbeRequest (); } void NqstaWifiMac::MissedBeacons (void) { + NS_LOG_FUNCTION (this); if (m_beaconWatchdogEnd > Simulator::Now ()) { m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (), &NqstaWifiMac::MissedBeacons, this); return; } - TRACE ("beacon missed"); + NS_LOG_DEBUG ("beacon missed"); m_state = BEACON_MISSED; TryToEnsureAssociated (); } void NqstaWifiMac::RestartBeaconWatchdog (Time delay) { + NS_LOG_FUNCTION (this << delay); m_beaconWatchdogEnd = std::max (Simulator::Now () + delay, m_beaconWatchdogEnd); if (Simulator::GetDelayLeft (m_beaconWatchdog) < delay && m_beaconWatchdog.IsExpired ()) { + NS_LOG_DEBUG ("really restart watchdog."); m_beaconWatchdog = Simulator::Schedule (delay, &NqstaWifiMac::MissedBeacons, this); } } @@ -394,12 +411,13 @@ NqstaWifiMac::IsAssociated (void) void NqstaWifiMac::Enqueue (Ptr packet, Mac48Address to) { + NS_LOG_FUNCTION (this << packet << to); if (!IsAssociated ()) { TryToEnsureAssociated (); return; } - //TRACE ("enqueue size="<GetSize ()<<", to="<Lookup (hdr->GetAddr2 ()); for (uint32_t i = 0; i < m_phy->GetNModes (); i++) @@ -509,7 +528,7 @@ NqstaWifiMac::Receive (Ptr packet, WifiMacHeader const *hdr) } else { - TRACE ("assoc refused"); + NS_LOG_DEBUG ("assoc refused"); m_state = REFUSED; } } diff --git a/src/devices/wifi/onoe-wifi-manager.cc b/src/devices/wifi/onoe-wifi-manager.cc index 618d452e5..c12846505 100644 --- a/src/devices/wifi/onoe-wifi-manager.cc +++ b/src/devices/wifi/onoe-wifi-manager.cc @@ -37,15 +37,15 @@ OnoeWifiManager::GetTypeId (void) .AddConstructor () .AddAttribute ("UpdatePeriod", "The interval between decisions about rate control changes", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&OnoeWifiManager::m_updatePeriod), MakeTimeChecker ()) .AddAttribute ("RaiseThreshold", "XXX", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&OnoeWifiManager::m_raiseThreshold), MakeUintegerChecker ()) .AddAttribute ("AddCreditThreshold", "Add credit threshold", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&OnoeWifiManager::m_addCreditThreshold), MakeUintegerChecker ()) ; diff --git a/src/devices/wifi/onoe-wifi-manager.h b/src/devices/wifi/onoe-wifi-manager.h index de1a0952c..68eb5a7f7 100644 --- a/src/devices/wifi/onoe-wifi-manager.h +++ b/src/devices/wifi/onoe-wifi-manager.h @@ -25,6 +25,15 @@ namespace ns3 { +/** + * \brief an implementation of rate control algorithm developed + * by Atsushi Onoe + * + * This algorithm is well known because it has been used as the default + * rate control algorithm for the madwifi driver. I am not aware of + * any publication or reference about this algorithm beyond the madwifi + * source code. + */ class OnoeWifiManager : public WifiRemoteStationManager { public: @@ -41,15 +50,6 @@ private: uint32_t m_raiseThreshold; }; -/** - * \brief an implementation of rate control algorithm developed - * by Atsushi Onoe - * - * This algorithm is well known because it has been used as the default - * rate control algorithm for the madwifi driver. I am not aware of - * any publication or reference about this algorithm beyond the madwifi - * source code. - */ class OnoeWifiRemoteStation : public WifiRemoteStation { public: diff --git a/src/devices/wifi/propagation-delay-model.cc b/src/devices/wifi/propagation-delay-model.cc index 73d3611d9..548651326 100644 --- a/src/devices/wifi/propagation-delay-model.cc +++ b/src/devices/wifi/propagation-delay-model.cc @@ -24,6 +24,17 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (PropagationDelayModel); + +TypeId +PropagationDelayModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::PropagationDelayModel") + .SetParent () + ; + return tid; +} + PropagationDelayModel::~PropagationDelayModel () {} @@ -37,7 +48,7 @@ RandomPropagationDelayModel::GetTypeId (void) .AddConstructor () .AddAttribute ("Variable", "The random variable which generates random delays (s).", - UniformVariable (0.0, 1.0), + RandomVariableValue (UniformVariable (0.0, 1.0)), MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable), MakeRandomVariableChecker ()) ; @@ -63,7 +74,7 @@ ConstantSpeedPropagationDelayModel::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Speed", "The speed (m/s)", - Double (300000000.0), + DoubleValue (300000000.0), MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed), MakeDoubleChecker ()) ; diff --git a/src/devices/wifi/propagation-delay-model.h b/src/devices/wifi/propagation-delay-model.h index 966447edb..c912d6d1a 100644 --- a/src/devices/wifi/propagation-delay-model.h +++ b/src/devices/wifi/propagation-delay-model.h @@ -35,6 +35,7 @@ class MobilityModel; class PropagationDelayModel : public Object { public: + static TypeId GetTypeId (void); virtual ~PropagationDelayModel (); /** * \param a the source diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc index e522f0517..5071c12cb 100644 --- a/src/devices/wifi/propagation-loss-model.cc +++ b/src/devices/wifi/propagation-loss-model.cc @@ -22,6 +22,7 @@ #include "ns3/mobility-model.h" #include "ns3/static-mobility-model.h" #include "ns3/double.h" +#include "ns3/pointer.h" #include NS_LOG_COMPONENT_DEFINE ("PropagationLossModel"); @@ -31,17 +32,31 @@ namespace ns3 { const double FriisPropagationLossModel::PI = 3.1415; +NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel); + +TypeId +PropagationLossModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::PropagationLossModel") + .SetParent () + ; + return tid; +} + + PropagationLossModel::~PropagationLossModel () {} +NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel); + TypeId RandomPropagationLossModel::GetTypeId (void) { - static TypeId tid = TypeId ("RandomPropagationLossModel") + static TypeId tid = TypeId ("ns3::RandomPropagationLossModel") .SetParent () .AddConstructor () .AddAttribute ("Variable", "XXX", - ConstantVariable (1.0), + RandomVariableValue (ConstantVariable (1.0)), MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable), MakeRandomVariableChecker ()) ; @@ -62,24 +77,26 @@ RandomPropagationLossModel::GetLoss (Ptr a, return rxc; } +NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel); + TypeId FriisPropagationLossModel::GetTypeId (void) { - static TypeId tid = TypeId ("FriisPropagationLossModel") + static TypeId tid = TypeId ("ns3::FriisPropagationLossModel") .SetParent () .AddConstructor () .AddAttribute ("Lambda", "The wavelength (default is 5.15 GHz at 300 000 km/s).", - Double (300000000.0 / 5.150e9), + DoubleValue (300000000.0 / 5.150e9), MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda), MakeDoubleChecker ()) .AddAttribute ("SystemLoss", "The system loss", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss), MakeDoubleChecker ()) .AddAttribute ("MinDistance", "The distance under which the propagation model refuses to give results (m)", - Double (0.5), + DoubleValue (0.5), MakeDoubleAccessor (&FriisPropagationLossModel::m_minDistance), MakeDoubleChecker ()) ; @@ -174,27 +191,29 @@ FriisPropagationLossModel::GetLoss (Ptr a, return pr; } +NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel); + TypeId LogDistancePropagationLossModel::GetTypeId (void) { - static TypeId tid = TypeId ("LogDistancePropagationLossModel") + static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel") .SetParent () .AddConstructor () .AddAttribute ("Exponent", "The exponent of the Path Loss propagation model", - Double (3.0), + DoubleValue (3.0), MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent), MakeDoubleChecker ()) .AddAttribute ("ReferenceDistance", "The distance at which the reference loss is calculated (m)", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance), MakeDoubleChecker ()) .AddAttribute ("ReferenceModel", "The reference model at the reference distance.", - Ptr (0), - MakePtrAccessor (&LogDistancePropagationLossModel::m_reference), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&LogDistancePropagationLossModel::m_reference), + MakePointerChecker ()) ; return tid; @@ -249,10 +268,10 @@ LogDistancePropagationLossModel::GetLoss (Ptr a, */ static Ptr zero = CreateObject ("Position", - Vector (0.0, 0.0, 0.0)); + VectorValue (Vector (0.0, 0.0, 0.0))); static Ptr reference = CreateObject ("Position", - Vector (m_referenceDistance, 0.0, 0.0)); + VectorValue (Vector (m_referenceDistance, 0.0, 0.0))); double ref = m_reference->GetLoss (zero, reference); double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance); double rxc = ref - pathLossDb; diff --git a/src/devices/wifi/propagation-loss-model.h b/src/devices/wifi/propagation-loss-model.h index 9dd5795b2..4ff7eac25 100644 --- a/src/devices/wifi/propagation-loss-model.h +++ b/src/devices/wifi/propagation-loss-model.h @@ -36,6 +36,8 @@ class MobilityModel; class PropagationLossModel : public Object { public: + static TypeId GetTypeId (void); + virtual ~PropagationLossModel (); /** * \param a the mobility model of the source diff --git a/src/devices/wifi/rraa-wifi-manager.cc b/src/devices/wifi/rraa-wifi-manager.cc index 262ff186f..dba6b51f2 100644 --- a/src/devices/wifi/rraa-wifi-manager.cc +++ b/src/devices/wifi/rraa-wifi-manager.cc @@ -193,122 +193,122 @@ RraaWifiManager::GetTypeId (void) .AddConstructor () .AddAttribute ("Basic", "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA wil be used", - Boolean (false), + BooleanValue (false), MakeBooleanAccessor (&RraaWifiManager::m_basic), MakeBooleanChecker ()) .AddAttribute ("Timeout", "Timeout for the RRAA BASIC loss estimaton block (s)", - Seconds (0.05), + TimeValue (Seconds (0.05)), MakeTimeAccessor (&RraaWifiManager::m_timeout), MakeTimeChecker ()) .AddAttribute ("ewndFor54mbps", "ewnd parameter for 54 Mbs data mode", - Uinteger (40), + UintegerValue (40), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor54), MakeUintegerChecker ()) .AddAttribute ("ewndFor48mbps", "ewnd parameter for 48 Mbs data mode", - Uinteger (40), + UintegerValue (40), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor48), MakeUintegerChecker ()) .AddAttribute ("ewndFor36mbps", "ewnd parameter for 36 Mbs data mode", - Uinteger (40), + UintegerValue (40), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor36), MakeUintegerChecker ()) .AddAttribute ("ewndFor24mbps", "ewnd parameter for 24 Mbs data mode", - Uinteger (40), + UintegerValue (40), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor24), MakeUintegerChecker ()) .AddAttribute ("ewndFor18mbps", "ewnd parameter for 18 Mbs data mode", - Uinteger (20), + UintegerValue (20), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor18), MakeUintegerChecker ()) .AddAttribute ("ewndFor12mbps", "ewnd parameter for 12 Mbs data mode", - Uinteger (20), + UintegerValue (20), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor12), MakeUintegerChecker ()) .AddAttribute ("ewndFor9mbps", "ewnd parameter for 9 Mbs data mode", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor9), MakeUintegerChecker ()) .AddAttribute ("ewndFor6mbps", "ewnd parameter for 6 Mbs data mode", - Uinteger (6), + UintegerValue (6), MakeUintegerAccessor (&RraaWifiManager::m_ewndfor6), MakeUintegerChecker ()) .AddAttribute ("poriFor48mbps", "Pori parameter for 48 Mbs data mode", - Double (0.047), + DoubleValue (0.047), MakeDoubleAccessor (&RraaWifiManager::m_porifor48), MakeDoubleChecker ()) .AddAttribute ("poriFor36mbps", "Pori parameter for 36 Mbs data mode", - Double (0.115), + DoubleValue (0.115), MakeDoubleAccessor (&RraaWifiManager::m_porifor36), MakeDoubleChecker ()) .AddAttribute ("poriFor24mbps", "Pori parameter for 24 Mbs data mode", - Double (0.1681), + DoubleValue (0.1681), MakeDoubleAccessor (&RraaWifiManager::m_porifor24), MakeDoubleChecker ()) .AddAttribute ("poriFor18mbps", "Pori parameter for 18 Mbs data mode", - Double (0.1325), + DoubleValue (0.1325), MakeDoubleAccessor (&RraaWifiManager::m_porifor18), MakeDoubleChecker ()) .AddAttribute ("poriFor12mbps", "Pori parameter for 12 Mbs data mode", - Double (0.1861), + DoubleValue (0.1861), MakeDoubleAccessor (&RraaWifiManager::m_porifor12), MakeDoubleChecker ()) .AddAttribute ("poriFor9mbps", "Pori parameter for 9 Mbs data mode", - Double (0.1434), + DoubleValue (0.1434), MakeDoubleAccessor (&RraaWifiManager::m_porifor9), MakeDoubleChecker ()) .AddAttribute ("poriFor6mbps", "Pori parameter for 6 Mbs data mode", - Double (0.5), + DoubleValue (0.5), MakeDoubleAccessor (&RraaWifiManager::m_porifor6), MakeDoubleChecker ()) .AddAttribute ("pmtlFor54mbps", "Pmtl parameter for 54 Mbs data mode", - Double (0.094), + DoubleValue (0.094), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor54), MakeDoubleChecker ()) .AddAttribute ("pmtlFor48mbps", "Pmtl parameter for 48 Mbs data mode", - Double (0.23), + DoubleValue (0.23), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor48), MakeDoubleChecker ()) .AddAttribute ("pmtlFor36mbps", "Pmtl parameter for 36 Mbs data mode", - Double (0.3363), + DoubleValue (0.3363), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor36), MakeDoubleChecker ()) .AddAttribute ("pmtlFor24mbps", "Pmtl parameter for 24 Mbs data mode", - Double (0.265), + DoubleValue (0.265), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor24), MakeDoubleChecker ()) .AddAttribute ("pmtlFor18mbps", "Pmtl parameter for 18 Mbs data mode", - Double (0.3722), + DoubleValue (0.3722), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor18), MakeDoubleChecker ()) .AddAttribute ("pmtlFor12mbps", "Pmtl parameter for 12 Mbs data mode", - Double(0.2868), + DoubleValue (0.2868), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor12), MakeDoubleChecker ()) .AddAttribute ("pmtlFor9mbps", "Pmtl parameter for 9 Mbs data mode", - Double (0.3932), + DoubleValue (0.3932), MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor9), MakeDoubleChecker ()) ; diff --git a/src/devices/wifi/ssid.h b/src/devices/wifi/ssid.h index 5040a6193..0feed168b 100644 --- a/src/devices/wifi/ssid.h +++ b/src/devices/wifi/ssid.h @@ -26,6 +26,10 @@ namespace ns3 { +/** + * \brief a IEEE 802.11 SSID + * + */ class Ssid { public: @@ -54,6 +58,11 @@ private: std::ostream &operator << (std::ostream &os, const Ssid &ssid); std::istream &operator >> (std::istream &is, Ssid &ssid); +/** + * \class ns3::SsidValue + * \brief hold objects of type ns3::Ssid + */ + ATTRIBUTE_HELPER_HEADER_2 (Ssid); } // namespace ns3 diff --git a/src/devices/wifi/wifi-channel.cc b/src/devices/wifi/wifi-channel.cc index cec9770ad..e4184aee3 100644 --- a/src/devices/wifi/wifi-channel.cc +++ b/src/devices/wifi/wifi-channel.cc @@ -23,6 +23,7 @@ #include "ns3/net-device.h" #include "ns3/node.h" #include "ns3/log.h" +#include "ns3/pointer.h" #include "wifi-channel.h" #include "propagation-loss-model.h" #include "propagation-delay-model.h" @@ -32,19 +33,19 @@ NS_LOG_COMPONENT_DEFINE ("WifiChannel"); namespace ns3 { TypeId -WifiChannel::GetTypdId (void) +WifiChannel::GetTypeId (void) { static TypeId tid = TypeId ("ns3::WifiChannel") - .SetParent () + .SetParent () .AddConstructor () .AddAttribute ("PropagationLossModel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiChannel::m_loss), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&WifiChannel::m_loss), + MakePointerChecker ()) .AddAttribute ("PropagationDelayModel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiChannel::m_delay), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&WifiChannel::m_delay), + MakePointerChecker ()) ; return tid; } diff --git a/src/devices/wifi/wifi-channel.h b/src/devices/wifi/wifi-channel.h index d07438108..fa2fc4a0d 100644 --- a/src/devices/wifi/wifi-channel.h +++ b/src/devices/wifi/wifi-channel.h @@ -47,7 +47,7 @@ class PropagationDelayModel; class WifiChannel : public Channel { public: - static TypeId GetTypdId (void); + static TypeId GetTypeId (void); WifiChannel (); virtual ~WifiChannel (); diff --git a/src/devices/wifi/wifi-mac-header.cc b/src/devices/wifi/wifi-mac-header.cc index 4dd62de1f..cd9f8c7c6 100644 --- a/src/devices/wifi/wifi-mac-header.cc +++ b/src/devices/wifi/wifi-mac-header.cc @@ -21,17 +21,6 @@ #include "ns3/address-utils.h" #include "wifi-mac-header.h" -#define MAC80211HEADER_DEBUG 1 - -#ifdef MAC80211HEADER_DEBUG -#include -# define TRACE(x) \ -std::Cout << "MAC80211HEADER " << x << std::Endl; -#else -# define TRACE(x) -#endif - - namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (WifiMacHeader); diff --git a/src/devices/wifi/wifi-mac-queue.cc b/src/devices/wifi/wifi-mac-queue.cc index 4e2f6a6bb..ec300b76a 100644 --- a/src/devices/wifi/wifi-mac-queue.cc +++ b/src/devices/wifi/wifi-mac-queue.cc @@ -40,12 +40,12 @@ WifiMacQueue::GetTypeId (void) static TypeId tid = TypeId ("WifiMacQueue") .SetParent () .AddConstructor () - .AddAttribute ("MaxPacketNumber", "XXX", - Uinteger (400), + .AddAttribute ("MaxPacketNumber", "If a packet arrives when there are already this number of packets, it is dropped.", + UintegerValue (400), MakeUintegerAccessor (&WifiMacQueue::m_maxSize), MakeUintegerChecker ()) - .AddAttribute ("MaxDelay", "XXX", - Seconds (10.0), + .AddAttribute ("MaxDelay", "If a packet stays longer than this delay in the queue, it is dropped.", + TimeValue (Seconds (10.0)), MakeTimeAccessor (&WifiMacQueue::m_maxDelay), MakeTimeChecker ()) ; diff --git a/src/devices/wifi/wifi-mac.cc b/src/devices/wifi/wifi-mac.cc index 837e96222..d2b8764fe 100644 --- a/src/devices/wifi/wifi-mac.cc +++ b/src/devices/wifi/wifi-mac.cc @@ -74,42 +74,42 @@ WifiMac::GetTypeId (void) static TypeId tid = TypeId ("ns3::WifiMac") .SetParent () .AddAttribute ("CtsTimeout", "XXX", - GetDefaultCtsAckTimeout (), + TimeValue (GetDefaultCtsAckTimeout ()), MakeTimeAccessor (&WifiMac::m_ctsTimeout), MakeTimeChecker ()) .AddAttribute ("AckTimeout", "XXX", - GetDefaultCtsAckTimeout (), + TimeValue (GetDefaultCtsAckTimeout ()), MakeTimeAccessor (&WifiMac::m_ackTimeout), MakeTimeChecker ()) .AddAttribute ("Sifs", "XXX", - GetDefaultSifs (), + TimeValue (GetDefaultSifs ()), MakeTimeAccessor (&WifiMac::SetSifs, &WifiMac::GetSifs), MakeTimeChecker ()) .AddAttribute ("EifsNoDifs", "XXX", - GetDefaultEifsNoDifs (), + TimeValue (GetDefaultEifsNoDifs ()), MakeTimeAccessor (&WifiMac::SetEifsNoDifs, &WifiMac::GetEifsNoDifs), MakeTimeChecker ()) .AddAttribute ("Slot", "XXX", - GetDefaultSlot (), + TimeValue (GetDefaultSlot ()), MakeTimeAccessor (&WifiMac::SetSlot, &WifiMac::GetSlot), MakeTimeChecker ()) .AddAttribute ("Pifs", "XXX", - GetDefaultSifs () + GetDefaultSlot (), + TimeValue (GetDefaultSifs () + GetDefaultSlot ()), MakeTimeAccessor (&WifiMac::m_pifs), MakeTimeChecker ()) .AddAttribute ("MaxPropagationDelay", "XXX", - GetDefaultMaxPropagationDelay (), + TimeValue (GetDefaultMaxPropagationDelay ()), MakeTimeAccessor (&WifiMac::m_maxPropagationDelay), MakeTimeChecker ()) .AddAttribute ("MaxMsduSize", "XXX", - Uinteger (2304), + UintegerValue (2304), MakeUintegerAccessor (&WifiMac::m_maxMsduSize), MakeUintegerChecker (1,2304)) .AddAttribute ("Ssid", "XXX", - Ssid ("default"), + SsidValue (Ssid ("default")), MakeSsidAccessor (&WifiMac::GetSsid, &WifiMac::SetSsid), MakeSsidChecker ()) diff --git a/src/devices/wifi/wifi-mode.h b/src/devices/wifi/wifi-mode.h index c2ec75cc6..9b15a203e 100644 --- a/src/devices/wifi/wifi-mode.h +++ b/src/devices/wifi/wifi-mode.h @@ -118,6 +118,11 @@ bool operator == (const WifiMode &a, const WifiMode &b); std::ostream & operator << (std::ostream & os, const WifiMode &mode); std::istream & operator >> (std::istream &is, WifiMode &mode); +/** + * \class ns3::WifiModeValue + * \brief hold objects of type ns3::WifiMode + */ + ATTRIBUTE_HELPER_HEADER_2 (WifiMode); /** diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index 8475dcea0..f3bcad80d 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -25,39 +25,42 @@ #include "ns3/llc-snap-header.h" #include "ns3/packet.h" #include "ns3/uinteger.h" +#include "ns3/pointer.h" #include "ns3/node.h" #include "ns3/trace-source-accessor.h" namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (WifiNetDevice); + TypeId WifiNetDevice::GetTypeId (void) { static TypeId tid = TypeId ("ns3::WifiNetDevice") .SetParent () - .AddAttribute ("Channel", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::DoGetChannel, - &WifiNetDevice::SetChannel), - MakePtrChecker ()) - .AddAttribute ("Phy", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::GetPhy, - &WifiNetDevice::SetPhy), - MakePtrChecker ()) - .AddAttribute ("Mac", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::GetMac, - &WifiNetDevice::SetMac), - MakePtrChecker ()) - .AddAttribute ("RemoteStationManager", "XXX", - Ptr (0), - MakePtrAccessor (&WifiNetDevice::SetRemoteStationManager, - &WifiNetDevice::GetRemoteStationManager), - MakePtrChecker ()) - .AddTraceSource ("Rx", "XXX", + .AddAttribute ("Channel", "The channel attached to this device", + PointerValue (), + MakePointerAccessor (&WifiNetDevice::DoGetChannel, + &WifiNetDevice::SetChannel), + MakePointerChecker ()) + .AddAttribute ("Phy", "The PHY layer attached to this device.", + PointerValue (), + MakePointerAccessor (&WifiNetDevice::GetPhy, + &WifiNetDevice::SetPhy), + MakePointerChecker ()) + .AddAttribute ("Mac", "The MAC layer attached to this device.", + PointerValue (), + MakePointerAccessor (&WifiNetDevice::GetMac, + &WifiNetDevice::SetMac), + MakePointerChecker ()) + .AddAttribute ("RemoteStationManager", "The station manager attached to this device.", + PointerValue (), + MakePointerAccessor (&WifiNetDevice::SetRemoteStationManager, + &WifiNetDevice::GetRemoteStationManager), + MakePointerChecker ()) + .AddTraceSource ("Rx", "Received payload from the MAC layer.", MakeTraceSourceAccessor (&WifiNetDevice::m_rxLogger)) - .AddTraceSource ("Tx", "XXX", + .AddTraceSource ("Tx", "Send payload to the MAC layer.", MakeTraceSourceAccessor (&WifiNetDevice::m_txLogger)) ; return tid; @@ -204,8 +207,9 @@ WifiNetDevice::GetAddress (void) const bool WifiNetDevice::SetMtu (const uint16_t mtu) { - Uinteger maxMsduSize = m_mac->GetAttribute ("MaxMsduSize"); - if (mtu > maxMsduSize && mtu > 0) + UintegerValue maxMsduSize; + m_mac->GetAttribute ("MaxMsduSize", maxMsduSize); + if (mtu > maxMsduSize.Get () || mtu == 0) { return false; } @@ -217,8 +221,9 @@ WifiNetDevice::GetMtu (void) const { if (m_mtu == 0) { - Uinteger maxMsduSize = m_mac->GetAttribute ("MaxMsduSize"); - m_mtu = maxMsduSize; + UintegerValue maxMsduSize; + m_mac->GetAttribute ("MaxMsduSize", maxMsduSize); + m_mtu = maxMsduSize.Get (); } return m_mtu; } diff --git a/src/devices/wifi/wifi-phy.cc b/src/devices/wifi/wifi-phy.cc index dbb22ebc0..dabe077f6 100644 --- a/src/devices/wifi/wifi-phy.cc +++ b/src/devices/wifi/wifi-phy.cc @@ -187,48 +187,48 @@ WifiPhy::GetTypeId (void) .AddAttribute ("EnergyDetectionThreshold", "The energy of a received signal should be higher than " "this threshold (dbm) to allow the PHY layer to detect the signal.", - Double (-140.0), + DoubleValue (-140.0), MakeDoubleAccessor (&WifiPhy::SetEdThreshold, &WifiPhy::GetEdThreshold), MakeDoubleChecker ()) .AddAttribute ("TxGain", "Transmission gain (dB).", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&WifiPhy::SetTxGain, &WifiPhy::GetTxGain), MakeDoubleChecker ()) .AddAttribute ("RxGain", "Reception gain (dB).", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&WifiPhy::SetRxGain, &WifiPhy::GetRxGain), MakeDoubleChecker ()) .AddAttribute ("TxPowerLevels", "Number of transmission power levels available between " "TxPowerBase and TxPowerEnd included.", - Uinteger (1), + UintegerValue (1), MakeUintegerAccessor (&WifiPhy::m_nTxPower), MakeUintegerChecker ()) .AddAttribute ("TxPowerEnd", "Maximum available transmission level (dbm).", - Double (16.0206), + DoubleValue (16.0206), MakeDoubleAccessor (&WifiPhy::SetTxPowerEnd, &WifiPhy::GetTxPowerEnd), MakeDoubleChecker ()) .AddAttribute ("TxPowerStart", "Minimum available transmission level (dbm).", - Double (16.0206), + DoubleValue (16.0206), MakeDoubleAccessor (&WifiPhy::SetTxPowerStart, &WifiPhy::GetTxPowerStart), MakeDoubleChecker ()) .AddAttribute ("RxNoise", "Ratio of energy lost by receiver (dB).", - Double (7), + DoubleValue (7), MakeDoubleAccessor (&WifiPhy::SetRxNoise, &WifiPhy::GetRxNoise), MakeDoubleChecker ()) .AddAttribute ("Standard", "XXX", - Enum (WIFI_PHY_STANDARD_80211a), + EnumValue (WIFI_PHY_STANDARD_80211a), MakeEnumAccessor (&WifiPhy::SetStandard), MakeEnumChecker (WIFI_PHY_STANDARD_80211a, "802.11a", WIFI_PHY_STANDARD_holland, "holland")) @@ -258,14 +258,19 @@ WifiPhy::WifiPhy () m_previousStateChangeTime (Seconds (0)), m_endSyncEvent (), m_random (0.0, 1.0) -{} +{ + NS_LOG_FUNCTION (this); +} WifiPhy::~WifiPhy () -{} +{ + NS_LOG_FUNCTION (this); +} void WifiPhy::DoDispose (void) { + NS_LOG_FUNCTION (this); m_channel = 0; m_events.clear (); m_modes.clear (); @@ -274,6 +279,7 @@ WifiPhy::DoDispose (void) void WifiPhy::SetStandard (enum WifiPhyStandard standard) { + NS_LOG_FUNCTION (this << standard); m_standard = standard; switch (standard) { case WIFI_PHY_STANDARD_80211a: @@ -292,36 +298,43 @@ WifiPhy::SetStandard (enum WifiPhyStandard standard) void WifiPhy::SetRxNoise (double db) { + NS_LOG_FUNCTION (this << db); m_rxNoiseRatio = DbToRatio (db); } void WifiPhy::SetTxPowerStart (double start) { + NS_LOG_FUNCTION (this << start); m_txPowerBaseDbm = start; } void WifiPhy::SetTxPowerEnd (double end) { + NS_LOG_FUNCTION (this << end); m_txPowerEndDbm = end; } void WifiPhy::SetNTxPower (uint32_t n) { + NS_LOG_FUNCTION (this << n); m_nTxPower = n; } void WifiPhy::SetTxGain (double gain) { + NS_LOG_FUNCTION (this << gain); m_txGainDb = gain; } void WifiPhy::SetRxGain (double gain) { + NS_LOG_FUNCTION (this << gain); m_rxGainDb = gain; } void WifiPhy::SetEdThreshold (double threshold) { + NS_LOG_FUNCTION (this << threshold); m_edThresholdW = DbmToW (threshold); } double @@ -384,6 +397,7 @@ WifiPhy::StartReceivePacket (Ptr packet, WifiMode txMode, enum WifiPreamble preamble) { + NS_LOG_FUNCTION (this << packet << rxPowerDbm << txMode << preamble); rxPowerDbm += m_rxGainDb; double rxPowerW = DbmToW (rxPowerDbm); Time rxDuration = CalculateTxDuration (packet->GetSize (), txMode, preamble); @@ -472,6 +486,7 @@ WifiPhy::StartReceivePacket (Ptr packet, void WifiPhy::SendPacket (Ptr packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower) { + NS_LOG_FUNCTION (this << packet << txMode << preamble << txPower); /* Transmission can happen if: * - we are syncing on a packet. It is the responsability of the * MAC layer to avoid doing this but the PHY does nothing to @@ -529,6 +544,7 @@ WifiPhy::CalculateSnr (WifiMode txMode, double ber) const void WifiPhy::Configure80211aParameters (void) { + NS_LOG_FUNCTION (this); m_plcpLongPreambleDelayUs = 16; m_plcpShortPreambleDelayUs = 16; m_longPlcpHeaderMode = g_6mba; @@ -558,6 +574,7 @@ WifiPhy::PrintModes (void) const void WifiPhy::Configure80211a (void) { + NS_LOG_FUNCTION (this); Configure80211aParameters (); m_modes.push_back (g_6mba); m_modes.push_back (g_9mba); @@ -574,6 +591,7 @@ WifiPhy::Configure80211a (void) void WifiPhy::ConfigureHolland (void) { + NS_LOG_FUNCTION (this); Configure80211aParameters (); m_modes.push_back (g_6mba); m_modes.push_back (g_12mba); @@ -1329,6 +1347,7 @@ WifiPhy::CalculatePer (Ptr event, NiChanges *ni) const void WifiPhy::EndSync (Ptr packet, Ptr event) { + NS_LOG_FUNCTION (this << packet << event); NS_ASSERT (IsStateSync ()); NS_ASSERT (event->GetEndTime () == Simulator::Now ()); diff --git a/src/devices/wifi/wifi-remote-station-manager.cc b/src/devices/wifi/wifi-remote-station-manager.cc index 704239008..5e793b9ee 100644 --- a/src/devices/wifi/wifi-remote-station-manager.cc +++ b/src/devices/wifi/wifi-remote-station-manager.cc @@ -127,23 +127,23 @@ WifiRemoteStationManager::GetTypeId (void) static TypeId tid = TypeId ("ns3::WifiRemoteStationManager") .SetParent () .AddAttribute ("IsLowLatency", "XXX", - Boolean (true), + BooleanValue (true), MakeBooleanAccessor (&WifiRemoteStationManager::m_isLowLatency), MakeBooleanChecker ()) .AddAttribute ("MaxSsrc", "XXX", - Uinteger (7), + UintegerValue (7), MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSsrc), MakeUintegerChecker ()) .AddAttribute ("MaxSlrc", "XXX", - Uinteger (7), + UintegerValue (7), MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSlrc), MakeUintegerChecker ()) .AddAttribute ("RtsCtsThreshold", "XXX", - Uinteger (1500), + UintegerValue (1500), MakeUintegerAccessor (&WifiRemoteStationManager::m_rtsCtsThreshold), MakeUintegerChecker ()) .AddAttribute ("FragmentationThreshold", "XXX", - Uinteger (1500), + UintegerValue (1500), MakeUintegerAccessor (&WifiRemoteStationManager::m_fragmentationThreshold), MakeUintegerChecker ()) ; diff --git a/src/devices/wifi/wifi-trace.cc b/src/devices/wifi/wifi-trace.cc deleted file mode 100644 index 7a03784e1..000000000 --- a/src/devices/wifi/wifi-trace.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Federico Maguolo - */ -#include "wifi-trace.h" - -#include "ns3/trace-context.h" -#include "ns3/simulator.h" -#include "ns3/node.h" -#include "ns3/node-list.h" -#include "ns3/packet.h" -#include "ns3/queue.h" - -namespace ns3 { - -WifiTrace::WifiTrace (std::string filename) -{ - m_os.open (filename.c_str ()); -} - -WifiTrace::WifiTrace () -{} - -WifiTrace::~WifiTrace () -{ - if (m_os.is_open ()) - m_os.close (); -} - -void -WifiTrace::TraceAllNetDeviceRx (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/rx", - MakeCallback (&WifiTrace::LogDevRx, this)); -} - -void -WifiTrace::TraceAllNetDeviceTx (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/tx", - MakeCallback (&WifiTrace::LogDevTx, this)); -} - -void -WifiTrace::TraceAllPhy (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/*/state", - MakeCallback (&WifiTrace::LogPhy, this)); -} - -void -WifiTrace::TraceAllErrors (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/*/error", - MakeCallback (&WifiTrace::LogErrors, this)); -} - -void -WifiTrace::TraceAckTimeouts (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/*/ackTimeout", - MakeCallback (&WifiTrace::LogAckTimeout, this)); -} - -void -WifiTrace::TraceCtsTimeouts (void) -{ - Packet::EnableMetadata (); - NodeList::ConnectWithoutContext ("/nodes/*/devices/*/*/ctsTimeout", - MakeCallback (&WifiTrace::LogCtsTimeout, this)); -} - -void -WifiTrace::LogDevRx (TraceContext const &context, Ptr p, Mac48Address addr) -{ - if (!m_os.is_open ()) - return; - m_os << "r " << Simulator::Now ().GetSeconds () << " "; - uint8_t buf[6]; - addr.CopyTo (buf); - for (uint8_t i = 0; i < 6; i++) { - m_os << (buf[i] + 0); - if (i < 5) - m_os << "."; - } - m_os << " "; - context.Print (m_os); - m_os << " pkt-uid=" << p->GetUid () << " "; - p->Print (m_os); - m_os << std::endl; -} - -void -WifiTrace::LogDevTx (TraceContext const &context, Ptr p, Mac48Address addr) -{ - if (!m_os.is_open ()) - return; - m_os << "s " << Simulator::Now ().GetSeconds () << " "; - uint8_t buf[6]; - addr.CopyTo (buf); - for (uint8_t i = 0; i < 6; i++) { - m_os << (buf[i] + 0); - if (i < 5) - m_os << "."; - } - m_os << " "; - context.Print (m_os); - m_os << " pkt-uid=" << p->GetUid () << " "; - p->Print (m_os); - m_os << std::endl; -} - -void -WifiTrace::LogErrors (TraceContext const &context, Ptr p) -{ - if (!m_os.is_open ()) - return; - m_os << "d " << Simulator::Now ().GetSeconds () << " "; - context.Print (m_os); - m_os << " pkt-uid=" << p->GetUid () << " "; - p->Print (m_os); - m_os << std::endl; -} - -void -WifiTrace::LogPhy (TraceContext const &context, Time s, Time d, WifiPhy::State state) -{ - if (!m_os.is_open ()) - return; - int prec = m_os.precision (); - m_os.precision (9); - m_os << "PHY " << Simulator::Now ().GetSeconds () << " "; - context.Print (m_os); - switch(state) - { - case WifiPhy::SYNC: - m_os << " SYNC"; - break; - case WifiPhy::TX: - m_os << " TX"; - break; - case WifiPhy::CCA_BUSY: - m_os << " CCA_BUSY"; - break; - case WifiPhy::IDLE: - m_os << " IDLE"; - break; - } - m_os << " t=" << s.GetSeconds () << " d=" << d.GetMicroSeconds (); - m_os << std::endl; - m_os.precision (prec); -} - -void -WifiTrace::LogAckTimeout (TraceContext const &context, uint32_t a) -{ - if (!m_os.is_open ()) - return; - m_os << "ACK timeout " << Simulator::Now ().GetSeconds () << " "; - context.Print (m_os); - m_os << " attemps=" << (a+0); - m_os << std::endl; -} - -void -WifiTrace::LogCtsTimeout (TraceContext const &context, uint32_t a) -{ - if (!m_os.is_open ()) - return; - m_os << "CTS timeout " << Simulator::Now ().GetSeconds () << " "; - context.Print (m_os); - m_os << " attemps=" << (a+0); - m_os << std::endl; -} - -}//namespace ns3 diff --git a/src/devices/wifi/wifi-trace.h b/src/devices/wifi/wifi-trace.h deleted file mode 100644 index ee9a3626e..000000000 --- a/src/devices/wifi/wifi-trace.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Federico Maguolo - */ -#ifndef WIFI_TRACE_H -#define WIFI_TRACE_H - -#include -#include -#include "ns3/wifi-phy.h" -#include "ns3/mac48-address.h" -//#include "ns3/ptr.h" - -namespace ns3 { - -class Packet; -class TraceContext; - -class WifiTrace -{ -public: - WifiTrace (std::string filename); - WifiTrace (); - virtual ~WifiTrace (); - void TraceAllNetDeviceRx (void); - void TraceAllNetDeviceTx (void); - void TraceAllPhy (void); - void TraceAllErrors (void); - void TraceAckTimeouts (void); - void TraceCtsTimeouts (void); -protected: - virtual void LogErrors (TraceContext const &context, Ptr p); - virtual void LogDevRx (TraceContext const &context, Ptr p, Mac48Address addr); - virtual void LogDevTx (TraceContext const &context, Ptr p, Mac48Address addr); - virtual void LogPhy (TraceContext const &context, Time s, Time d, WifiPhy::State state); - virtual void LogAckTimeout (TraceContext const &context, uint32_t a); - virtual void LogCtsTimeout (TraceContext const &context, uint32_t a); -private: - std::ofstream m_os; -}; - -}//namespace ns3 - -#endif /* ASCII_TRACE_H */ diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index e77fac629..89711a426 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -54,7 +54,6 @@ def build(bld): 'wifi-preamble.h', 'wifi-phy-standard.h', 'wifi-phy.h', - 'wifi-trace.h', 'wifi-remote-station-manager.h', 'arf-wifi-manager.h', 'aarf-wifi-manager.h', diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index c86665589..d0c210090 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -39,10 +39,10 @@ CsmaHelper::CsmaHelper () void CsmaHelper::SetQueue (std::string type, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4) { m_queueFactory.SetTypeId (type); m_queueFactory.Set (n1, v1); @@ -52,13 +52,13 @@ CsmaHelper::SetQueue (std::string type, } void -CsmaHelper::SetDeviceParameter (std::string n1, Attribute v1) +CsmaHelper::SetDeviceParameter (std::string n1, const AttributeValue &v1) { m_deviceFactory.Set (n1, v1); } void -CsmaHelper::SetChannelParameter (std::string n1, Attribute v1) +CsmaHelper::SetChannelParameter (std::string n1, const AttributeValue &v1) { m_channelFactory.Set (n1, v1); } diff --git a/src/helper/csma-helper.h b/src/helper/csma-helper.h index ae4057549..2a2822f3b 100644 --- a/src/helper/csma-helper.h +++ b/src/helper/csma-helper.h @@ -56,10 +56,10 @@ public: * CsmaNetDevice created through CsmaHelper::Install. */ void SetQueue (std::string type, - std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute ()); + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); /** * \param n1 the name of the attribute to set @@ -68,7 +68,7 @@ public: * Set these parameters on each ns3::CsmaNetDevice created * by CsmaHelper::Install */ - void SetDeviceParameter (std::string n1, Attribute v1); + void SetDeviceParameter (std::string n1, const AttributeValue &v1); /** * \param n1 the name of the attribute to set @@ -77,7 +77,7 @@ public: * Set these parameters on each ns3::CsmaChannel created * by CsmaHelper::Install */ - void SetChannelParameter (std::string n1, Attribute v1); + void SetChannelParameter (std::string n1, const AttributeValue &v1); /** * \param filename filename prefix to use for pcap files. diff --git a/src/helper/ipv4-address-helper.cc b/src/helper/ipv4-address-helper.cc index c1802f288..d58a814ec 100644 --- a/src/helper/ipv4-address-helper.cc +++ b/src/helper/ipv4-address-helper.cc @@ -31,7 +31,7 @@ namespace ns3 { Ipv4AddressHelper::Ipv4AddressHelper () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // Set the default values to an illegal state. Do this so the client is @@ -52,7 +52,7 @@ Ipv4AddressHelper::SetBase ( const Ipv4Mask mask, const Ipv4Address address) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_network = network.GetHostOrder (); m_mask = mask.GetHostOrder (); @@ -114,7 +114,7 @@ Ipv4AddressHelper::NewAddress (void) Ipv4Address Ipv4AddressHelper::NewNetwork (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ++m_network; m_address = m_base; return Ipv4Address (m_network << m_shift); @@ -123,7 +123,7 @@ Ipv4AddressHelper::NewNetwork (void) Ipv4InterfaceContainer Ipv4AddressHelper::Assign (const NetDeviceContainer &c) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4InterfaceContainer retval; for (uint32_t i = 0; i < c.GetN (); ++i) { Ptr device = c.Get (i); @@ -156,7 +156,7 @@ const uint32_t N_BITS = 32; uint32_t Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (uint32_t i = 0; i < N_BITS; ++i) { if (maskbits & 1) diff --git a/src/helper/mobility-helper.cc b/src/helper/mobility-helper.cc index 3fbe38197..04cb4bef6 100644 --- a/src/helper/mobility-helper.cc +++ b/src/helper/mobility-helper.cc @@ -23,6 +23,7 @@ #include "ns3/position-allocator.h" #include "ns3/hierarchical-mobility-model.h" #include "ns3/log.h" +#include "ns3/pointer.h" namespace ns3 { @@ -31,8 +32,9 @@ NS_LOG_COMPONENT_DEFINE ("MobilityHelper"); MobilityHelper::MobilityHelper () : m_notifierEnabled (false) { - m_position = CreateObject ("X", ConstantVariable (0.0), - "Y", ConstantVariable (0.0)); + m_position = CreateObject + ("X", RandomVariableValue (ConstantVariable (0.0)), + "Y", RandomVariableValue (ConstantVariable (0.0))); m_mobility.SetTypeId ("ns3::StaticMobilityModel"); } MobilityHelper::~MobilityHelper () @@ -54,15 +56,15 @@ MobilityHelper::SetPositionAllocator (Ptr allocator) } void MobilityHelper::SetPositionAllocator (std::string type, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4, - std::string n5, Attribute v5, - std::string n6, Attribute v6, - std::string n7, Attribute v7, - std::string n8, Attribute v8, - std::string n9, Attribute v9) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7, + std::string n8, const AttributeValue &v8, + std::string n9, const AttributeValue &v9) { ObjectFactory pos; pos.SetTypeId (type); @@ -80,15 +82,15 @@ MobilityHelper::SetPositionAllocator (std::string type, void MobilityHelper::SetMobilityModel (std::string type, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4, - std::string n5, Attribute v5, - std::string n6, Attribute v6, - std::string n7, Attribute v7, - std::string n8, Attribute v8, - std::string n9, Attribute v9) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7, + std::string n8, const AttributeValue &v8, + std::string n9, const AttributeValue &v9) { m_mobility.SetTypeId (type); m_mobility.Set (n1, v1); @@ -146,8 +148,8 @@ MobilityHelper::Install (NodeContainer c) // we need to setup a hierarchical mobility model Ptr parent = m_mobilityStack.back (); Ptr hierarchical = - CreateObject ("Child", model, - "Parent", parent); + CreateObject ("Child", PointerValue (model), + "Parent", PointerValue (parent)); object->AggregateObject (hierarchical); NS_LOG_DEBUG ("node="< node); diff --git a/src/helper/on-off-helper.cc b/src/helper/on-off-helper.cc index 33bc3dd36..121edaa45 100644 --- a/src/helper/on-off-helper.cc +++ b/src/helper/on-off-helper.cc @@ -27,12 +27,12 @@ namespace ns3 { OnOffHelper::OnOffHelper (std::string protocol, Address address) { m_factory.SetTypeId ("ns3::OnOffApplication"); - m_factory.Set ("Protocol", String(protocol)); - m_factory.Set ("Remote", address); + m_factory.Set ("Protocol", StringValue (protocol)); + m_factory.Set ("Remote", AddressValue (address)); } void -OnOffHelper::SetAttribute (std::string name, Attribute value) +OnOffHelper::SetAttribute (std::string name, const AttributeValue &value) { m_factory.Set (name, value); } diff --git a/src/helper/on-off-helper.h b/src/helper/on-off-helper.h index 20bf2f402..a36ab49a5 100644 --- a/src/helper/on-off-helper.h +++ b/src/helper/on-off-helper.h @@ -36,7 +36,7 @@ class OnOffHelper public: OnOffHelper (std::string protocol, Address address); - void SetAttribute (std::string name, Attribute value); + void SetAttribute (std::string name, const AttributeValue &value); ApplicationContainer Install (NodeContainer c); diff --git a/src/helper/packet-sink-helper.cc b/src/helper/packet-sink-helper.cc index 011fc9e3b..45f1d17a6 100644 --- a/src/helper/packet-sink-helper.cc +++ b/src/helper/packet-sink-helper.cc @@ -26,12 +26,12 @@ namespace ns3 { PacketSinkHelper::PacketSinkHelper (std::string protocol, Address address) { m_factory.SetTypeId ("ns3::PacketSink"); - m_factory.Set ("Protocol", String(protocol)); - m_factory.Set ("Local", address); + m_factory.Set ("Protocol", StringValue (protocol)); + m_factory.Set ("Local", AddressValue (address)); } void -PacketSinkHelper::SetAttribute (std::string name, Attribute value) +PacketSinkHelper::SetAttribute (std::string name, const AttributeValue &value) { m_factory.Set (name, value); } diff --git a/src/helper/packet-sink-helper.h b/src/helper/packet-sink-helper.h index 3bcd671ef..d91bc4c59 100644 --- a/src/helper/packet-sink-helper.h +++ b/src/helper/packet-sink-helper.h @@ -32,7 +32,7 @@ class PacketSinkHelper public: PacketSinkHelper (std::string protocol, Address address); - void SetAttribute (std::string name, Attribute value); + void SetAttribute (std::string name, const AttributeValue &value); ApplicationContainer Install (NodeContainer c); private: diff --git a/src/helper/point-to-point-helper.cc b/src/helper/point-to-point-helper.cc index 34689895c..2cf5bde16 100644 --- a/src/helper/point-to-point-helper.cc +++ b/src/helper/point-to-point-helper.cc @@ -39,10 +39,10 @@ PointToPointHelper::PointToPointHelper () void PointToPointHelper::SetQueue (std::string type, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4) { m_queueFactory.SetTypeId (type); m_queueFactory.Set (n1, v1); @@ -52,13 +52,13 @@ PointToPointHelper::SetQueue (std::string type, } void -PointToPointHelper::SetDeviceParameter (std::string n1, Attribute v1) +PointToPointHelper::SetDeviceParameter (std::string n1, const AttributeValue &v1) { m_deviceFactory.Set (n1, v1); } void -PointToPointHelper::SetChannelParameter (std::string n1, Attribute v1) +PointToPointHelper::SetChannelParameter (std::string n1, const AttributeValue &v1) { m_channelFactory.Set (n1, v1); } diff --git a/src/helper/point-to-point-helper.h b/src/helper/point-to-point-helper.h index 487942692..f945a144f 100644 --- a/src/helper/point-to-point-helper.h +++ b/src/helper/point-to-point-helper.h @@ -56,10 +56,10 @@ public: * PointToPointNetDevice created through PointToPointHelper::Install. */ void SetQueue (std::string type, - std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute ()); + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); /** * \param name the name of the attribute to set @@ -68,7 +68,7 @@ public: * Set these parameters on each ns3::PointToPointNetDevice created * by PointToPointHelper::Install */ - void SetDeviceParameter (std::string name, Attribute value); + void SetDeviceParameter (std::string name, const AttributeValue &value); /** * \param name the name of the attribute to set * \param value the value of the attribute to set @@ -76,7 +76,7 @@ public: * Set these parameters on each ns3::PointToPointChannel created * by PointToPointHelper::Install */ - void SetChannelParameter (std::string name, Attribute value); + void SetChannelParameter (std::string name, const AttributeValue &value); /** * \param filename filename prefix to use for pcap files. diff --git a/src/helper/udp-echo-helper.cc b/src/helper/udp-echo-helper.cc index 8285aadc8..ef5f59777 100644 --- a/src/helper/udp-echo-helper.cc +++ b/src/helper/udp-echo-helper.cc @@ -40,7 +40,7 @@ UdpEchoServerHelper::Install (NodeContainer c) for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr node = *i; - Ptr server = CreateObject ("Port", Uinteger (m_port)); + Ptr server = CreateObject ("Port", UintegerValue (m_port)); node->AddApplication (server); apps.Add (server); } @@ -58,7 +58,7 @@ UdpEchoClientHelper::SetRemote (Ipv4Address ip, uint16_t port) m_remotePort = port; } void -UdpEchoClientHelper::SetAppAttribute (std::string name, Attribute value) +UdpEchoClientHelper::SetAppAttribute (std::string name, const AttributeValue &value) { m_factory.Set (name, value); } diff --git a/src/helper/udp-echo-helper.h b/src/helper/udp-echo-helper.h index 645342869..ef13c959a 100644 --- a/src/helper/udp-echo-helper.h +++ b/src/helper/udp-echo-helper.h @@ -44,7 +44,7 @@ public: UdpEchoClientHelper (); void SetRemote (Ipv4Address ip, uint16_t port); - void SetAppAttribute (std::string name, Attribute value); + void SetAppAttribute (std::string name, const AttributeValue &value); ApplicationContainer Install (NodeContainer c); private: ObjectFactory m_factory; diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index 6fb069d04..a2d59d2fb 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -78,14 +78,14 @@ WifiHelper::WifiHelper () void WifiHelper::SetRemoteStationManager (std::string type, - std::string n0, Attribute v0, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4, - std::string n5, Attribute v5, - std::string n6, Attribute v6, - std::string n7, Attribute v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_stationManager = ObjectFactory (); m_stationManager.SetTypeId (type); @@ -101,14 +101,14 @@ WifiHelper::SetRemoteStationManager (std::string type, void WifiHelper::SetMac (std::string type, - std::string n0, Attribute v0, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4, - std::string n5, Attribute v5, - std::string n6, Attribute v6, - std::string n7, Attribute v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_mac = ObjectFactory (); m_mac.SetTypeId (type); @@ -124,14 +124,14 @@ WifiHelper::SetMac (std::string type, void WifiHelper::SetPhy (std::string type, - std::string n0, Attribute v0, - std::string n1, Attribute v1, - std::string n2, Attribute v2, - std::string n3, Attribute v3, - std::string n4, Attribute v4, - std::string n5, Attribute v5, - std::string n6, Attribute v6, - std::string n7, Attribute v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_phy = ObjectFactory (); m_phy.SetTypeId (type); diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index 2cc1108c3..35ec3141b 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -65,14 +65,14 @@ public: * in the requested station manager. */ void SetRemoteStationManager (std::string type, - std::string n0 = "", Attribute v0 = Attribute (), - std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute (), - std::string n5 = "", Attribute v5 = Attribute (), - std::string n6 = "", Attribute v6 = Attribute (), - std::string n7 = "", Attribute v7 = Attribute ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * \param type the type of ns3::WifiMac to create. @@ -97,14 +97,14 @@ public: * in the requested mac. */ void SetMac (std::string type, - std::string n0 = "", Attribute v0 = Attribute (), - std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute (), - std::string n5 = "", Attribute v5 = Attribute (), - std::string n6 = "", Attribute v6 = Attribute (), - std::string n7 = "", Attribute v7 = Attribute ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * \param phyType the type of ns3::WifiPhy to create. @@ -129,14 +129,14 @@ public: * in the requested phy. */ void SetPhy (std::string phyType, - std::string n0 = "", Attribute v0 = Attribute (), - std::string n1 = "", Attribute v1 = Attribute (), - std::string n2 = "", Attribute v2 = Attribute (), - std::string n3 = "", Attribute v3 = Attribute (), - std::string n4 = "", Attribute v4 = Attribute (), - std::string n5 = "", Attribute v5 = Attribute (), - std::string n6 = "", Attribute v6 = Attribute (), - std::string n7 = "", Attribute v7 = Attribute ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index bd52d676d..5a8e19514 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -35,12 +35,12 @@ namespace ns3 { ArpIpv4Interface::ArpIpv4Interface () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } ArpIpv4Interface::~ArpIpv4Interface () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -70,8 +70,7 @@ ArpIpv4Interface::GetDevice (void) const void ArpIpv4Interface::SendTo (Ptr p, Ipv4Address dest) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << dest); + NS_LOG_FUNCTION (this << p << dest); NS_ASSERT (GetDevice () != 0); if (GetDevice ()->NeedsArp ()) diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index 6dc017623..5b9bb8858 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -47,12 +47,12 @@ ArpL3Protocol::GetTypeId (void) ArpL3Protocol::ArpL3Protocol () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } ArpL3Protocol::~ArpL3Protocol () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -64,7 +64,7 @@ ArpL3Protocol::SetNode (Ptr node) void ArpL3Protocol::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) { delete *i; @@ -77,7 +77,7 @@ ArpL3Protocol::DoDispose (void) ArpCache * ArpL3Protocol::FindCache (Ptr device) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++) { if ((*i)->GetDevice () == device) @@ -97,7 +97,7 @@ ArpL3Protocol::FindCache (Ptr device) void ArpL3Protocol::Receive(Ptr device, Ptr packet, uint16_t protocol, const Address &from) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ArpCache *cache = FindCache (device); ArpHeader arp; packet->RemoveHeader (arp); @@ -108,6 +108,11 @@ ArpL3Protocol::Receive(Ptr device, Ptr packet, uint16_t proto arp.GetDestinationIpv4Address () << "; we have address " << cache->GetInterface ()->GetAddress ()); + /** + * Note: we do not update the ARP cache when we receive an ARP request + * from an unknown node. See bug #107 + */ + if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { @@ -161,7 +166,7 @@ ArpL3Protocol::Lookup (Ptr packet, Ipv4Address destination, Ptr device, Address *hardwareDestination) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ArpCache *cache = FindCache (device); ArpCache::Entry *entry = cache->Lookup (destination); if (entry != 0) @@ -230,7 +235,7 @@ ArpL3Protocol::Lookup (Ptr packet, Ipv4Address destination, void ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ArpHeader arp; NS_LOG_LOGIC ("ARP: sending request from node "<GetId ()<< " || src: " << cache->GetDevice ()->GetAddress () << @@ -249,7 +254,7 @@ ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) void ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ArpHeader arp; NS_LOG_LOGIC ("ARP: sending reply from node "<GetId ()<< "|| src: " << cache->GetDevice ()->GetAddress () << diff --git a/src/internet-node/ipv4-end-point-demux.cc b/src/internet-node/ipv4-end-point-demux.cc index 9c305ccf2..3d3f779be 100644 --- a/src/internet-node/ipv4-end-point-demux.cc +++ b/src/internet-node/ipv4-end-point-demux.cc @@ -29,12 +29,12 @@ NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux"); Ipv4EndPointDemux::Ipv4EndPointDemux () : m_ephemeral (49152) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } Ipv4EndPointDemux::~Ipv4EndPointDemux () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { Ipv4EndPoint *endPoint = *i; @@ -46,7 +46,7 @@ Ipv4EndPointDemux::~Ipv4EndPointDemux () bool Ipv4EndPointDemux::LookupPortLocal (uint16_t port) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if ((*i)->GetLocalPort () == port) @@ -60,7 +60,7 @@ Ipv4EndPointDemux::LookupPortLocal (uint16_t port) bool Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if ((*i)->GetLocalPort () == port && @@ -75,7 +75,7 @@ Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port) Ipv4EndPoint * Ipv4EndPointDemux::Allocate (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint16_t port = AllocateEphemeralPort (); if (port == 0) { @@ -91,8 +91,7 @@ Ipv4EndPointDemux::Allocate (void) Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address); + NS_LOG_FUNCTION (this << address); uint16_t port = AllocateEphemeralPort (); if (port == 0) { @@ -108,8 +107,7 @@ Ipv4EndPointDemux::Allocate (Ipv4Address address) Ipv4EndPoint * Ipv4EndPointDemux::Allocate (uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << port); + NS_LOG_FUNCTION (this << port); return Allocate (Ipv4Address::GetAny (), port); } @@ -117,8 +115,7 @@ Ipv4EndPointDemux::Allocate (uint16_t port) Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address << port); + NS_LOG_FUNCTION (this << address << port); if (LookupLocal (address, port)) { NS_LOG_WARN ("Duplicate address/port; failing."); @@ -134,8 +131,7 @@ Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); + NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if ((*i)->GetLocalPort () == localPort && @@ -160,7 +156,7 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, void Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if (*i == endPoint) @@ -182,21 +178,13 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr incomingInterface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); EndPoints retval1; // Matches exact on local port, wildcards on others EndPoints retval2; // Matches exact on local port/adder, wildcards on others EndPoints retval3; // Matches all but local address EndPoints retval4; // Exact match on all 4 - //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 (); + NS_LOG_FUNCTION (this << daddr << dport << saddr << sport << incomingInterface); NS_LOG_DEBUG ("Looking up endpoint for destination address " << daddr); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { @@ -284,7 +272,7 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, uint16_t Ipv4EndPointDemux::AllocateEphemeralPort (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint16_t port = m_ephemeral; do { diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index aead13ad0..9a9566b01 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -28,6 +28,15 @@ NS_LOG_COMPONENT_DEFINE ("Ipv4Interface"); namespace ns3 { +TypeId +Ipv4Interface::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::Ipv4Interface") + .SetParent () + ; + return tid; +} + /** * By default, Ipv4 interface are created in the "down" state * with ip address 192.168.0.1 and a matching mask. Before @@ -38,42 +47,39 @@ Ipv4Interface::Ipv4Interface () : m_ifup(false), m_metric(1) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); } Ipv4Interface::~Ipv4Interface () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void Ipv4Interface::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Object::DoDispose (); } void Ipv4Interface::SetAddress (Ipv4Address a) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << a); + NS_LOG_FUNCTION (this << a); m_address = a; } void Ipv4Interface::SetNetworkMask (Ipv4Mask mask) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << mask); + NS_LOG_FUNCTION (this << mask); m_netmask = mask; } Ipv4Address Ipv4Interface::GetBroadcast (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t mask = m_netmask.GetHostOrder (); uint32_t address = m_address.GetHostOrder (); Ipv4Address broadcast = Ipv4Address (address | (~mask)); @@ -83,36 +89,35 @@ Ipv4Interface::GetBroadcast (void) const Ipv4Mask Ipv4Interface::GetNetworkMask (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_netmask; } void Ipv4Interface::SetMetric (uint16_t metric) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS ("(" << metric << ")"); + NS_LOG_FUNCTION (metric); m_metric = metric; } uint16_t Ipv4Interface::GetMetric (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_metric; } Ipv4Address Ipv4Interface::GetAddress (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_address; } uint16_t Ipv4Interface::GetMtu (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (GetDevice () == 0) { uint32_t mtu = (1<<16) - 1; @@ -129,28 +134,28 @@ Ipv4Interface::GetMtu (void) const bool Ipv4Interface::IsUp (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_ifup; } bool Ipv4Interface::IsDown (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return !m_ifup; } void Ipv4Interface::SetUp (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_ifup = true; } void Ipv4Interface::SetDown (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_ifup = false; } @@ -158,7 +163,7 @@ Ipv4Interface::SetDown (void) void Ipv4Interface::Send(Ptr p, Ipv4Address dest) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (IsUp()) { NS_LOG_LOGIC ("SendTo"); SendTo(p, dest); diff --git a/src/internet-node/ipv4-interface.h b/src/internet-node/ipv4-interface.h index b802ea1e4..04828a3e6 100644 --- a/src/internet-node/ipv4-interface.h +++ b/src/internet-node/ipv4-interface.h @@ -63,6 +63,8 @@ class TraceContext; class Ipv4Interface : public Object { public: + static TypeId GetTypeId (void); + Ipv4Interface (); virtual ~Ipv4Interface(); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 105995369..9188a358e 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -52,7 +52,7 @@ Ipv4L3Protocol::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.", - Uinteger (64), + UintegerValue (64), MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl), MakeUintegerChecker ()) .AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.", @@ -62,9 +62,9 @@ Ipv4L3Protocol::GetTypeId (void) .AddTraceSource ("Drop", "Drop ipv4 packet", MakeTraceSourceAccessor (&Ipv4L3Protocol::m_dropTrace)) .AddAttribute ("InterfaceList", "The set of Ipv4 interfaces associated to this Ipv4 stack.", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) ; return tid; } @@ -73,14 +73,14 @@ Ipv4L3Protocol::Ipv4L3Protocol() : m_nInterfaces (0), m_identification (0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_staticRouting = CreateObject (); AddRoutingProtocol (m_staticRouting, 0); } Ipv4L3Protocol::~Ipv4L3Protocol () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -93,7 +93,7 @@ Ipv4L3Protocol::SetNode (Ptr node) void Ipv4L3Protocol::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_interfaces.clear (); m_node = 0; m_staticRouting->Dispose (); @@ -104,7 +104,7 @@ Ipv4L3Protocol::DoDispose (void) void Ipv4L3Protocol::SetupLoopback (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr interface = CreateObject (); interface->SetNode (m_node); @@ -118,7 +118,7 @@ Ipv4L3Protocol::SetupLoopback (void) void Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_defaultTtl = ttl; } @@ -128,8 +128,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << dest << nextHop << interface); + NS_LOG_FUNCTION (this << dest << nextHop << interface); m_staticRouting->AddHostRouteTo (dest, nextHop, interface); } @@ -137,8 +136,7 @@ void Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << dest << interface); + NS_LOG_FUNCTION (this << dest << interface); m_staticRouting->AddHostRouteTo (dest, interface); } @@ -148,8 +146,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << network << networkMask << nextHop << interface); + NS_LOG_FUNCTION (this << network << networkMask << nextHop << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface); } @@ -158,8 +155,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkMask, uint32_t interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << network << networkMask << interface); + NS_LOG_FUNCTION (this << network << networkMask << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, interface); } @@ -167,8 +163,7 @@ void Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << nextHop << interface); + NS_LOG_FUNCTION (this << nextHop << interface); m_staticRouting->SetDefaultRoute (nextHop, interface); } @@ -178,8 +173,7 @@ Ipv4L3Protocol::Lookup ( Ptr packet, Ipv4RoutingProtocol::RouteReplyCallback routeReply) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &ipHeader << packet << &routeReply); + NS_LOG_FUNCTION (this << &ipHeader << packet << &routeReply); Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply); } @@ -191,8 +185,7 @@ Ipv4L3Protocol::Lookup ( Ptr packet, Ipv4RoutingProtocol::RouteReplyCallback routeReply) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << ifIndex << &ipHeader << packet << &routeReply); + NS_LOG_FUNCTION (this << ifIndex << &ipHeader << packet << &routeReply); for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin (); @@ -240,8 +233,7 @@ void Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, int priority) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &routingProtocol << priority); + NS_LOG_FUNCTION (this << &routingProtocol << priority); m_routingProtocols.push_back (std::pair > (-priority, routingProtocol)); m_routingProtocols.sort (); @@ -250,22 +242,21 @@ Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, uint32_t Ipv4L3Protocol::GetNRoutes (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_staticRouting->GetNRoutes (); } Ipv4Route * Ipv4L3Protocol::GetRoute (uint32_t index) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_staticRouting->GetRoute (index); } void Ipv4L3Protocol::RemoveRoute (uint32_t index) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << index); + NS_LOG_FUNCTION (this << index); m_staticRouting->RemoveRoute (index); } @@ -275,8 +266,7 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, uint32_t inputInterface, std::vector outputInterfaces) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << origin << group << inputInterface << &outputInterfaces); + NS_LOG_FUNCTION (this << origin << group << inputInterface << &outputInterfaces); m_staticRouting->AddMulticastRoute (origin, group, inputInterface, outputInterfaces); @@ -285,8 +275,7 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, void Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << outputInterface); + NS_LOG_FUNCTION (this << outputInterface); m_staticRouting->SetDefaultMulticastRoute (outputInterface); } @@ -294,15 +283,14 @@ Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface) uint32_t Ipv4L3Protocol::GetNMulticastRoutes (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_staticRouting->GetNMulticastRoutes (); } Ipv4MulticastRoute * Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << index); + NS_LOG_FUNCTION (this << index); return m_staticRouting->GetMulticastRoute (index); } @@ -311,24 +299,21 @@ Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin, Ipv4Address group, uint32_t inputInterface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << origin << group << inputInterface); + NS_LOG_FUNCTION (this << origin << group << inputInterface); m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface); } void Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << index); + NS_LOG_FUNCTION (this << index); m_staticRouting->RemoveMulticastRoute (index); } uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &device); + NS_LOG_FUNCTION (this << &device); Ptr interface = CreateObject (); interface->SetNode (m_node); interface->SetDevice (device); @@ -338,8 +323,7 @@ Ipv4L3Protocol::AddInterface (Ptr device) uint32_t Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << interface); + NS_LOG_FUNCTION (this << interface); uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; @@ -349,8 +333,7 @@ Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << index); + NS_LOG_FUNCTION (this << index); uint32_t tmp = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { @@ -366,15 +349,14 @@ Ipv4L3Protocol::GetInterface (uint32_t index) const uint32_t Ipv4L3Protocol::GetNInterfaces (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_nInterfaces; } uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << addr); + NS_LOG_FUNCTION (this << addr); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -395,8 +377,7 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << addr << mask); + NS_LOG_FUNCTION (this << addr << mask); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -417,8 +398,7 @@ Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const int32_t Ipv4L3Protocol::FindInterfaceIndexForDevice (Ptr device) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << device); + NS_LOG_FUNCTION (this << device); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -437,8 +417,7 @@ Ipv4L3Protocol::FindInterfaceIndexForDevice (Ptr device) const Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &device); + NS_LOG_FUNCTION (this << &device); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { if ((*i)->GetDevice () == device) @@ -452,8 +431,7 @@ Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) void Ipv4L3Protocol::Receive( Ptr device, Ptr packet, uint16_t protocol, const Address &from) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << &device << packet << protocol << from); + NS_LOG_FUNCTION (this << &device << packet << protocol << from); NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ()); @@ -494,8 +472,7 @@ Ipv4L3Protocol::Send (Ptr packet, Ipv4Address destination, uint8_t protocol) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << source << destination << protocol); + NS_LOG_FUNCTION (this << packet << source << destination << protocol); Ipv4Header ipHeader; @@ -545,8 +522,7 @@ Ipv4L3Protocol::SendRealOut (bool found, Ptr packet, Ipv4Header const &ipHeader) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << found << &route << packet << &ipHeader); + NS_LOG_FUNCTION (this << found << &route << packet << &ipHeader); packet->AddHeader (ipHeader); if (!found) @@ -580,8 +556,7 @@ Ipv4L3Protocol::Forwarding ( Ipv4Header &ipHeader, Ptr device) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (ifIndex << packet << &ipHeader<< device); + NS_LOG_FUNCTION (ifIndex << packet << &ipHeader<< device); NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ()); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -661,8 +636,7 @@ void Ipv4L3Protocol::ForwardUp (Ptr p, Ipv4Header const&ip, Ptr incomingInterface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << &ip); + NS_LOG_FUNCTION (this << p << &ip); Ptr demux = m_node->GetObject (); Ptr protocol = demux->GetProtocol (ip.GetProtocol ()); @@ -672,8 +646,7 @@ Ipv4L3Protocol::ForwardUp (Ptr p, Ipv4Header const&ip, void Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << origin << group); + NS_LOG_FUNCTION (this << origin << group); m_multicastGroups.push_back( std::pair (origin, group)); } @@ -681,8 +654,7 @@ Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) void Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << origin << group); + NS_LOG_FUNCTION (this << origin << group); for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin (); i != m_multicastGroups.end (); @@ -699,8 +671,7 @@ Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i << address); + NS_LOG_FUNCTION (this << i << address); Ptr interface = GetInterface (i); interface->SetAddress (address); } @@ -708,8 +679,7 @@ Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i << mask); + NS_LOG_FUNCTION (this << i << mask); Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } @@ -717,8 +687,7 @@ Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i); + NS_LOG_FUNCTION (this << i); Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } @@ -726,8 +695,7 @@ Ipv4L3Protocol::GetNetworkMask (uint32_t i) const Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i); + NS_LOG_FUNCTION (this << i); Ptr interface = GetInterface (i); return interface->GetAddress (); } @@ -735,8 +703,7 @@ Ipv4L3Protocol::GetAddress (uint32_t i) const void Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS ("(" << i << ", " << metric << ")"); + NS_LOG_FUNCTION (i << metric); Ptr interface = GetInterface (i); interface->SetMetric (metric); } @@ -744,8 +711,7 @@ Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric) uint16_t Ipv4L3Protocol::GetMetric (uint32_t i) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS ("(" << i << ")"); + NS_LOG_FUNCTION (i); Ptr interface = GetInterface (i); return interface->GetMetric (); } @@ -754,8 +720,7 @@ bool Ipv4L3Protocol::GetIfIndexForDestination ( Ipv4Address destination, uint32_t& ifIndex) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << destination << &ifIndex); + NS_LOG_FUNCTION (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 @@ -824,8 +789,7 @@ Ipv4L3Protocol::GetIfIndexForDestination ( uint16_t Ipv4L3Protocol::GetMtu (uint32_t i) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i); + NS_LOG_FUNCTION (this << i); Ptr interface = GetInterface (i); return interface->GetMtu (); } @@ -833,8 +797,7 @@ Ipv4L3Protocol::GetMtu (uint32_t i) const bool Ipv4L3Protocol::IsUp (uint32_t i) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i); + NS_LOG_FUNCTION (this << i); Ptr interface = GetInterface (i); return interface->IsUp (); } @@ -842,8 +805,7 @@ Ipv4L3Protocol::IsUp (uint32_t i) const void Ipv4L3Protocol::SetUp (uint32_t i) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << i); + NS_LOG_FUNCTION (this << i); Ptr interface = GetInterface (i); interface->SetUp (); @@ -861,8 +823,7 @@ Ipv4L3Protocol::SetUp (uint32_t i) void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << ifaceIndex); + NS_LOG_FUNCTION (this << ifaceIndex); Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index b869d1f2d..969dc09ca 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -41,6 +41,9 @@ class Ipv4Route; class Node; +/** + * \brief Implement the Ipv4 layer. + */ class Ipv4L3Protocol : public Object { public: diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index 693cbbd59..a40614891 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -37,9 +37,9 @@ Ipv4L4Demux::GetTypeId (void) static TypeId tid = TypeId ("ns3::Ipv4L4Demux") .SetParent () .AddAttribute ("Protocols", "The set of protocols registered with this demux.", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&Ipv4L4Demux::m_protocols), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) ; return tid; } diff --git a/src/internet-node/ipv4-l4-protocol.cc b/src/internet-node/ipv4-l4-protocol.cc index d3d6b0036..662dc37b3 100644 --- a/src/internet-node/ipv4-l4-protocol.cc +++ b/src/internet-node/ipv4-l4-protocol.cc @@ -34,11 +34,11 @@ Ipv4L4Protocol::GetTypeId (void) static TypeId tid = TypeId ("ns3::Ipv4L4Protocol") .SetParent () .AddAttribute ("ProtocolNumber", "The Ipv4 protocol number.", - Uinteger (0), + UintegerValue (0), MakeUintegerAccessor (&Ipv4L4Protocol::GetProtocolNumber), MakeUintegerChecker ()) .AddAttribute ("Version", "The version of the protocol.", - Uinteger (0), + UintegerValue (0), MakeUintegerAccessor (&Ipv4L4Protocol::GetVersion), MakeUintegerChecker ()) ; diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index b97dd7923..68acda205 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -34,12 +34,12 @@ namespace ns3 { Ipv4LoopbackInterface::Ipv4LoopbackInterface () : m_node (0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } Ipv4LoopbackInterface::~Ipv4LoopbackInterface () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (m_node != 0); } @@ -58,8 +58,7 @@ Ipv4LoopbackInterface::SetNode (Ptr node) void Ipv4LoopbackInterface::SendTo (Ptr packet, Ipv4Address dest) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << dest); + NS_LOG_FUNCTION (this << packet << dest); Ptr ipv4 = m_node->GetObject (); diff --git a/src/internet-node/ipv4-static-routing.cc b/src/internet-node/ipv4-static-routing.cc index 454fe950e..ba3f27c35 100644 --- a/src/internet-node/ipv4-static-routing.cc +++ b/src/internet-node/ipv4-static-routing.cc @@ -29,7 +29,7 @@ namespace ns3 { Ipv4StaticRouting::Ipv4StaticRouting () : m_defaultRoute (0), m_defaultMulticastRoute (0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -37,7 +37,7 @@ Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface); m_hostRoutes.push_back (route); @@ -47,7 +47,7 @@ void Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateHostRouteTo (dest, interface); m_hostRoutes.push_back (route); @@ -59,7 +59,7 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateNetworkRouteTo (network, networkMask, @@ -73,7 +73,7 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkMask, uint32_t interface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateNetworkRouteTo (network, networkMask, @@ -85,7 +85,7 @@ void Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, uint32_t interface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Route *route = new Ipv4Route (); *route = Ipv4Route::CreateDefaultRoute (nextHop, interface); delete m_defaultRoute; @@ -98,7 +98,7 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, uint32_t inputInterface, std::vector outputInterfaces) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4MulticastRoute *route = new Ipv4MulticastRoute (); *route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group, inputInterface, outputInterfaces); @@ -108,7 +108,7 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, void Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ipv4Address origin = Ipv4Address::GetAny (); Ipv4Address group = Ipv4Address::GetAny (); uint32_t inputInterface = Ipv4RoutingProtocol::IF_INDEX_ANY; @@ -127,14 +127,14 @@ Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface) uint32_t Ipv4StaticRouting::GetNMulticastRoutes (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_multicastRoutes.size () + m_defaultMulticastRoute ? 1 : 0; } Ipv4MulticastRoute * Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG(index < m_multicastRoutes.size (), "Ipv4StaticRouting::GetMulticastRoute (): Index out of range"); // @@ -182,7 +182,7 @@ Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const Ipv4MulticastRoute * Ipv4StaticRouting::GetDefaultMulticastRoute () const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_defaultMulticastRoute != 0) { return m_defaultMulticastRoute; @@ -195,7 +195,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (MulticastRoutesI i = m_multicastRoutes.begin (); i != m_multicastRoutes.end (); i++) @@ -216,7 +216,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, void Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // From an external point of view the default route appears to be in slot 0 // of the routing table. The implementation, however, puts it in a separate @@ -261,7 +261,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index) Ipv4Route * Ipv4StaticRouting::LookupStatic (Ipv4Address dest) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (HostRoutesCI i = m_hostRoutes.begin (); i != m_hostRoutes.end (); i++) @@ -298,7 +298,7 @@ Ipv4StaticRouting::LookupStatic ( Ipv4Address group, uint32_t ifIndex) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // We treat the "any" address (typically 0.0.0.0) as a wildcard in our matching // scheme. @@ -400,7 +400,7 @@ Ipv4StaticRouting::LookupStatic ( uint32_t Ipv4StaticRouting::GetNRoutes (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t n = 0; if (m_defaultRoute != 0) { @@ -414,7 +414,7 @@ Ipv4StaticRouting::GetNRoutes (void) Ipv4Route * Ipv4StaticRouting::GetDefaultRoute () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_defaultRoute != 0) { return m_defaultRoute; @@ -428,7 +428,7 @@ Ipv4StaticRouting::GetDefaultRoute () Ipv4Route * Ipv4StaticRouting::GetRoute (uint32_t index) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (index == 0 && m_defaultRoute != 0) { return m_defaultRoute; @@ -470,7 +470,7 @@ Ipv4StaticRouting::GetRoute (uint32_t index) void Ipv4StaticRouting::RemoveRoute (uint32_t index) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (index == 0 && m_defaultRoute != 0) { delete m_defaultRoute; @@ -520,8 +520,7 @@ Ipv4StaticRouting::RequestRoute ( Ptr packet, RouteReplyCallback routeReply) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << ifIndex << &ipHeader << packet << &routeReply); + NS_LOG_FUNCTION (this << ifIndex << &ipHeader << packet << &routeReply); NS_LOG_LOGIC ("source = " << ipHeader.GetSource ()); @@ -573,8 +572,7 @@ Ipv4StaticRouting::RequestRoute ( bool Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << destination << &ifIndex); + NS_LOG_FUNCTION (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. @@ -621,7 +619,7 @@ Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) void Ipv4StaticRouting::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (HostRoutesI i = m_hostRoutes.begin (); i != m_hostRoutes.end (); i = m_hostRoutes.erase (i)) diff --git a/src/internet-node/rtt-estimator.cc b/src/internet-node/rtt-estimator.cc index 728d85e7f..e6a849c7b 100644 --- a/src/internet-node/rtt-estimator.cc +++ b/src/internet-node/rtt-estimator.cc @@ -43,12 +43,12 @@ RttEstimator::GetTypeId (void) .SetParent () .AddAttribute ("MaxMultiplier", "XXX", - Double (64.0), + DoubleValue (64.0), MakeDoubleAccessor (&RttEstimator::m_maxMultiplier), MakeDoubleChecker ()) .AddAttribute ("InitialEstimation", "XXX", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&RttEstimator::est), MakeTimeChecker ()) ; @@ -74,12 +74,9 @@ RttEstimator::RttEstimator () : next (1), history (), //note next=1 everywhere since first segment will have sequence 1 } -RttEstimator::RttEstimator (Time e) : next (1), history (), est (e), - nSamples (0), multiplier (1.0) -{ } - RttEstimator::RttEstimator(const RttEstimator& c) - : next(c.next), history(c.history), est(c.est), nSamples(c.nSamples), + : Object (c), next(c.next), history(c.history), + m_maxMultiplier (c.m_maxMultiplier), est(c.est), nSamples(c.nSamples), multiplier(c.multiplier) {} @@ -144,6 +141,10 @@ void RttEstimator::ClearSent () void RttEstimator::IncreaseMultiplier () { + double a; + a = multiplier * 2.0; + double b; + b = m_maxMultiplier * 2.0; multiplier = std::min (multiplier * 2.0, m_maxMultiplier); } @@ -177,7 +178,7 @@ RttMeanDeviation::GetTypeId (void) .AddConstructor () .AddAttribute ("Gain", "XXX", - Double (0.1), + DoubleValue (0.1), MakeDoubleAccessor (&RttMeanDeviation::gain), MakeDoubleChecker ()) ; @@ -223,7 +224,7 @@ Time RttMeanDeviation::RetransmitTimeout () Ptr RttMeanDeviation::Copy () const { - return Create (*this); + return CopyObject (this); } void RttMeanDeviation::Reset () diff --git a/src/internet-node/rtt-estimator.h b/src/internet-node/rtt-estimator.h index 84fea6c7e..9daf4584f 100644 --- a/src/internet-node/rtt-estimator.h +++ b/src/internet-node/rtt-estimator.h @@ -51,7 +51,6 @@ public: static TypeId GetTypeId (void); RttEstimator(); - RttEstimator(Time e); RttEstimator(const RttEstimator&); // Copy constructor virtual ~RttEstimator(); @@ -71,7 +70,6 @@ private: SequenceNumber next; // Next expected sequence to be sent RttHistory_t history; // List of sent packet double m_maxMultiplier; - Time m_initialEstimate; public: Time est; // Current estimate uint32_t nSamples;// Number of samples diff --git a/src/internet-node/tcp-l4-protocol.cc b/src/internet-node/tcp-l4-protocol.cc index 70dc3de20..653575db0 100644 --- a/src/internet-node/tcp-l4-protocol.cc +++ b/src/internet-node/tcp-l4-protocol.cc @@ -49,7 +49,7 @@ TcpStateMachine::TcpStateMachine() : aT (LAST_STATE, StateActionVec_t(LAST_EVENT)), eV (MAX_FLAGS) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // Create the state table // Closed state @@ -290,15 +290,13 @@ TcpStateMachine::TcpStateMachine() SA TcpStateMachine::Lookup (States_t s, Events_t e) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << s << e); + NS_LOG_FUNCTION (this << s << e); return aT[s][e]; } Events_t TcpStateMachine::FlagsEvent (uint8_t f) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << f); + NS_LOG_FUNCTION (this << f); // Lookup event from flags if (f >= MAX_FLAGS) return BAD_FLAGS; return eV[f]; // Look up flags event @@ -327,7 +325,7 @@ TcpL4Protocol::GetTypeId (void) .SetParent () .AddAttribute ("RttEstimatorFactory", "How RttEstimator objects are created.", - GetDefaultRttEstimatorFactory (), + ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), MakeObjectFactoryChecker ()) ; @@ -337,13 +335,13 @@ TcpL4Protocol::GetTypeId (void) TcpL4Protocol::TcpL4Protocol () : m_endPoints (new Ipv4EndPointDemux ()) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Made a TcpL4Protocol "< TcpL4Protocol::CreateSocket (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr rtt = m_rttFactory.Create (); Ptr socket = CreateObject (); socket->SetNode (m_node); @@ -391,31 +389,28 @@ TcpL4Protocol::CreateSocket (void) Ipv4EndPoint * TcpL4Protocol::Allocate (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_endPoints->Allocate (); } Ipv4EndPoint * TcpL4Protocol::Allocate (Ipv4Address address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address); + NS_LOG_FUNCTION (this << address); return m_endPoints->Allocate (address); } Ipv4EndPoint * TcpL4Protocol::Allocate (uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << port); + NS_LOG_FUNCTION (this << port); return m_endPoints->Allocate (port); } Ipv4EndPoint * TcpL4Protocol::Allocate (Ipv4Address address, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address << port); + NS_LOG_FUNCTION (this << address << port); return m_endPoints->Allocate (address, port); } @@ -423,8 +418,7 @@ Ipv4EndPoint * TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); + NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort); return m_endPoints->Allocate (localAddress, localPort, peerAddress, peerPort); } @@ -432,8 +426,7 @@ TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, void TcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << endPoint); + NS_LOG_FUNCTION (this << endPoint); m_endPoints->DeAllocate (endPoint); } @@ -443,8 +436,7 @@ TcpL4Protocol::Receive (Ptr packet, Ipv4Address const &destination, Ptr incomingInterface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << source << destination << incomingInterface); + NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface); TcpHeader tcpHeader; //these two do a peek, so that the packet can be forwarded up @@ -481,8 +473,7 @@ TcpL4Protocol::Send (Ptr packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << saddr << daddr << sport << dport); + NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); TcpHeader tcpHeader; tcpHeader.SetDestinationPort (dport); @@ -512,8 +503,7 @@ TcpL4Protocol::SendPacket (Ptr packet, TcpHeader outgoingHeader, << " ack " << outgoingHeader.GetAckNumber() << " flags " << std::hex << (int)outgoingHeader.GetFlags() << std::dec << " data size " << packet->GetSize()); - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << saddr << daddr); + NS_LOG_FUNCTION (this << packet << saddr << daddr); // XXX outgoingHeader cannot be logged outgoingHeader.SetLength (5); //header length in units of 32bit words diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 58495f5bf..ac52efd2d 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -80,8 +80,7 @@ TcpSocket::GetTypeId () m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); } @@ -125,7 +124,7 @@ TcpSocket::TcpSocket(const TcpSocket& sock) m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); //copy the pending data if necessary if(sock.m_pendingData) @@ -143,8 +142,7 @@ TcpSocket::TcpSocket(const TcpSocket& sock) TcpSocket::~TcpSocket () { - NS_LOG_FUNCTION; - NS_LOG_PARAMS(this); + NS_LOG_FUNCTION(this); m_node = 0; if (m_endPoint != 0) { @@ -198,21 +196,21 @@ TcpSocket::SetRtt (Ptr rtt) enum Socket::SocketErrno TcpSocket::GetErrno (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_errno; } Ptr TcpSocket::GetNode (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_node; } void TcpSocket::Destroy (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_node = 0; m_endPoint = 0; m_tcp = 0; @@ -221,7 +219,7 @@ TcpSocket::Destroy (void) int TcpSocket::FinishBind (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) { return -1; @@ -236,15 +234,14 @@ TcpSocket::FinishBind (void) int TcpSocket::Bind (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_endPoint = m_tcp->Allocate (); return FinishBind (); } int TcpSocket::Bind (const Address &address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this< p) //p here is just data, no headers int TcpSocket::Send (const uint8_t* buf, uint32_t size) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << buf << size); + NS_LOG_FUNCTION (this << buf << size); if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) { // Ok to buffer some data to send if (!m_pendingData) @@ -390,8 +385,7 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) int TcpSocket::DoSendTo (Ptr p, const Address &address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << address); + NS_LOG_FUNCTION (this << p << address); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); @@ -400,8 +394,7 @@ int TcpSocket::DoSendTo (Ptr p, const Address &address) int TcpSocket::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << ipv4 << port); + NS_LOG_FUNCTION (this << p << ipv4 << port); if (m_endPoint == 0) { if (Bind () == -1) @@ -425,8 +418,7 @@ int TcpSocket::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) int TcpSocket::SendTo (const Address &address, Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address << p); + NS_LOG_FUNCTION (this << address << p); if (!m_connected) { m_errno = ERROR_NOTCONN; @@ -441,8 +433,7 @@ TcpSocket::SendTo (const Address &address, Ptr p) int TcpSocket::Listen (uint32_t q) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << q); + NS_LOG_FUNCTION (this << q); Actions_t action = ProcessEvent (APP_LISTEN); ProcessAction (action); return 0; @@ -457,8 +448,7 @@ TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) " sport " << m_endPoint->GetPeerPort() << " saddr " << m_endPoint->GetPeerAddress()); - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << ipv4 << port); + NS_LOG_FUNCTION (this << packet << ipv4 << port); if (m_shutdownRecv) { return; @@ -486,8 +476,7 @@ TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) Actions_t TcpSocket::ProcessEvent (Events_t e) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << e); + NS_LOG_FUNCTION (this << e); States_t saveState = m_state; NS_LOG_LOGIC ("TcpSocket " << this << " processing event " << e); // simulation singleton is a way to get a single global static instance of a @@ -538,8 +527,7 @@ Actions_t TcpSocket::ProcessEvent (Events_t e) void TcpSocket::SendEmptyPacket (uint8_t flags) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << flags); + NS_LOG_FUNCTION (this << flags); Ptr p = Create (); TcpHeader header; @@ -569,8 +557,7 @@ void TcpSocket::SendEmptyPacket (uint8_t flags) bool TcpSocket::ProcessAction (Actions_t a) { // These actions do not require a packet or any TCP Headers - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << a); + NS_LOG_FUNCTION (this << a); switch (a) { case NO_ACT: @@ -648,8 +635,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, const TcpHeader& tcpHeader, const Address& fromAddress) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << a << p << fromAddress); + NS_LOG_FUNCTION (this << a << p << fromAddress); uint32_t localIfIndex; Ptr ipv4 = m_node->GetObject (); switch (a) @@ -695,6 +681,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, // TCP SYN consumes one byte m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1); m_nextTxSequence = tcpHeader.GetAckNumber (); + m_firstPendingSequence = m_nextTxSequence; //bug 166 NS_LOG_DEBUG ("TcpSocket " << this << " ACK_TX_1" << " nextRxSeq " << m_nextRxSequence); SendEmptyPacket (TcpHeader::ACK); @@ -813,8 +800,7 @@ void TcpSocket::ConnectionSucceeded() bool TcpSocket::SendPendingData (bool withAck) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << withAck); + NS_LOG_FUNCTION (this << withAck); NS_LOG_LOGIC ("ENTERING SendPendingData"); if (!m_pendingData) { @@ -900,26 +886,26 @@ bool TcpSocket::SendPendingData (bool withAck) uint32_t TcpSocket::UnAckDataCount () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_nextTxSequence - m_highestRxAck; } uint32_t TcpSocket::BytesInFlight () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_highTxMark - m_highestRxAck; } uint32_t TcpSocket::Window () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("TcpSocket::Window() "< p, const TcpHeader& tcpHeader, const Address& fromAddress) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << "tcpHeader " << fromAddress); + NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress); NS_LOG_LOGIC ("TcpSocket " << this << " NewRx," << " seq " << tcpHeader.GetSequenceNumber() << " ack " << tcpHeader.GetAckNumber() @@ -1077,8 +1062,7 @@ void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) { // CommonNewAck is called only for "New" (non-duplicate) acks // and MUST be called by any subclass, from the NewAck function // Always cancel any pending re-tx timer on new acknowledgement - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << ack << skipTimer); + NS_LOG_FUNCTION (this << ack << skipTimer); //DEBUG(1,(cout << "TCP " << this << "Cancelling retx timer " << endl)); if (!skipTimer) { @@ -1121,8 +1105,7 @@ Ptr TcpSocket::Copy () void TcpSocket::NewAck (SequenceNumber seq) { // New acknowledgement up to sequence number "seq" // Adjust congestion window in response to new ack's received - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << seq); + NS_LOG_FUNCTION (this << seq); NS_LOG_LOGIC ("TcpSocket " << this << " NewAck " << " seq " << seq << " cWnd " << m_cWnd @@ -1149,8 +1132,7 @@ void TcpSocket::NewAck (SequenceNumber seq) void TcpSocket::DupAck (const TcpHeader& t, uint32_t count) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << "t " << count); + NS_LOG_FUNCTION (this << "t " << count); NS_LOG_LOGIC ("TcpSocket " << this << " DupAck " << t.GetAckNumber () << ", count " << count << ", time " << Simulator::Now ()); @@ -1172,15 +1154,14 @@ void TcpSocket::DupAck (const TcpHeader& t, uint32_t count) void TcpSocket::ReTxTimeout () { // Retransmit timeout - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); m_ssThresh = Window () / 2; // Per RFC2581 m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize); // Set cWnd to segSize on timeout, per rfc2581 // Collapse congestion window (re-enter slowstart) m_cWnd = m_segmentSize; m_nextTxSequence = m_highestRxAck; // Start from highest Ack - m_rtt->IncreaseMultiplier (); // Double timeout value for next retx timer + m_rtt->IncreaseMultiplier (); // DoubleValue timeout value for next retx timer Retransmit (); // Retransmit the packet } @@ -1200,8 +1181,7 @@ void TcpSocket::LastAckTimeout () void TcpSocket::Retransmit () { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); uint8_t flags = TcpHeader::NONE; if (m_state == SYN_SENT) { diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index 2259cd632..424908712 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -52,12 +52,12 @@ UdpL4Protocol::GetTypeId (void) UdpL4Protocol::UdpL4Protocol () : m_endPoints (new Ipv4EndPointDemux ()) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } UdpL4Protocol::~UdpL4Protocol () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -81,7 +81,7 @@ UdpL4Protocol::GetVersion (void) const void UdpL4Protocol::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_endPoints != 0) { delete m_endPoints; @@ -94,7 +94,7 @@ UdpL4Protocol::DoDispose (void) Ptr UdpL4Protocol::CreateSocket (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr socket = CreateObject (); socket->SetNode (m_node); socket->SetUdp (this); @@ -104,39 +104,35 @@ UdpL4Protocol::CreateSocket (void) Ipv4EndPoint * UdpL4Protocol::Allocate (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_endPoints->Allocate (); } Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address); + NS_LOG_FUNCTION (this << address); return m_endPoints->Allocate (address); } Ipv4EndPoint * UdpL4Protocol::Allocate (uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << port); + NS_LOG_FUNCTION (this << port); return m_endPoints->Allocate (port); } Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address << port); + NS_LOG_FUNCTION (this << address << port); return m_endPoints->Allocate (address, port); } Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); + NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort); return m_endPoints->Allocate (localAddress, localPort, peerAddress, peerPort); } @@ -144,8 +140,7 @@ UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, void UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << endPoint); + NS_LOG_FUNCTION (this << endPoint); m_endPoints->DeAllocate (endPoint); } @@ -155,8 +150,7 @@ UdpL4Protocol::Receive(Ptr packet, Ipv4Address const &destination, Ptr interface) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << source << destination); + NS_LOG_FUNCTION (this << packet << source << destination); UdpHeader udpHeader; packet->RemoveHeader (udpHeader); @@ -175,8 +169,7 @@ UdpL4Protocol::Send (Ptr packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << saddr << daddr << sport << dport); + NS_LOG_FUNCTION (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 383870c34..951a8c73f 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -42,12 +42,12 @@ UdpSocket::UdpSocket () m_shutdownRecv (false), m_connected (false) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } UdpSocket::~UdpSocket () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_node = 0; if (m_endPoint != 0) @@ -83,21 +83,21 @@ UdpSocket::SetUdp (Ptr udp) enum Socket::SocketErrno UdpSocket::GetErrno (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_errno; } Ptr UdpSocket::GetNode (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_node; } void UdpSocket::Destroy (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_node = 0; m_endPoint = 0; m_udp = 0; @@ -106,7 +106,7 @@ UdpSocket::Destroy (void) int UdpSocket::FinishBind (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) { return -1; @@ -119,7 +119,7 @@ UdpSocket::FinishBind (void) int UdpSocket::Bind (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_endPoint = m_udp->Allocate (); return FinishBind (); } @@ -127,8 +127,7 @@ UdpSocket::Bind (void) int UdpSocket::Bind (const Address &address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address); + NS_LOG_FUNCTION (this << address); if (!InetSocketAddress::IsMatchingType (address)) { @@ -161,7 +160,7 @@ UdpSocket::Bind (const Address &address) int UdpSocket::ShutdownSend (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_shutdownSend = true; return 0; } @@ -169,7 +168,7 @@ UdpSocket::ShutdownSend (void) int UdpSocket::ShutdownRecv (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_shutdownRecv = false; return 0; } @@ -177,7 +176,7 @@ UdpSocket::ShutdownRecv (void) int UdpSocket::Close(void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NotifyCloseCompleted (); return 0; } @@ -185,8 +184,7 @@ UdpSocket::Close(void) int UdpSocket::Connect(const Address & address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address); + NS_LOG_FUNCTION (this << address); Ipv4Route routeToDest; InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = transport.GetIpv4 (); @@ -200,8 +198,7 @@ UdpSocket::Connect(const Address & address) int UdpSocket::Send (Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p); + NS_LOG_FUNCTION (this << p); if (!m_connected) { @@ -214,7 +211,7 @@ UdpSocket::Send (Ptr p) int UdpSocket::DoSend (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) { if (Bind () == -1) @@ -236,8 +233,7 @@ UdpSocket::DoSend (Ptr p) int UdpSocket::DoSendTo (Ptr p, const Address &address) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << address); + NS_LOG_FUNCTION (this << p << address); if (!m_connected) { @@ -258,8 +254,7 @@ UdpSocket::DoSendTo (Ptr p, const Address &address) int UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p << dest << port); + NS_LOG_FUNCTION (this << p << dest << port); Ipv4Route routeToDest; @@ -300,14 +295,15 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) NotifyDataSent (p->GetSize ()); } NS_LOG_LOGIC ("Limited broadcast end."); + return p->GetSize(); } else if (ipv4->GetIfIndexForDestination(dest, localIfIndex)) { NS_LOG_LOGIC ("Route exists"); - m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest, + m_udp->Send (p->Copy (), ipv4->GetAddress (localIfIndex), dest, m_endPoint->GetLocalPort (), port); NotifyDataSent (p->GetSize ()); - return 0; + return p->GetSize();; } else { @@ -322,8 +318,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) int UdpSocket::SendTo(const Address &address, Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << address << p); + NS_LOG_FUNCTION (this << address << p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); @@ -333,8 +328,7 @@ UdpSocket::SendTo(const Address &address, Ptr p) void UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << packet << ipv4 << port); + NS_LOG_FUNCTION (this << packet << ipv4 << port); if (m_shutdownRecv) { @@ -478,7 +472,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("10.0.0.1"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); // second interface should receive it @@ -489,7 +483,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); // second socket should not receive it (it is bound specifically to the second interface's address @@ -509,7 +503,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123); diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index 5c25afb0c..b1fadc473 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -19,6 +19,7 @@ */ #include "hierarchical-mobility-model.h" #include "mobility-model-notifier.h" +#include "ns3/pointer.h" namespace ns3 { @@ -31,13 +32,13 @@ HierarchicalMobilityModel::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("Child", "The child mobility model.", - Ptr (0), - MakePtrAccessor (&HierarchicalMobilityModel::SetChild), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&HierarchicalMobilityModel::SetChild), + MakePointerChecker ()) .AddAttribute ("Parent", "The parent mobility model.", - Ptr (0), - MakePtrAccessor (&HierarchicalMobilityModel::SetParent), - MakePtrChecker ()) + PointerValue (), + MakePointerAccessor (&HierarchicalMobilityModel::SetParent), + MakePointerChecker ()) ; return tid; } diff --git a/src/mobility/mobility-model.cc b/src/mobility/mobility-model.cc index 7548aa5f6..ddfc3592f 100644 --- a/src/mobility/mobility-model.cc +++ b/src/mobility/mobility-model.cc @@ -30,13 +30,13 @@ MobilityModel::GetTypeId (void) .SetParent () .AddAttribute ("Position", "The current position of the mobility model.", TypeId::ATTR_SGC, - Vector (0.0, 0.0, 0.0), + VectorValue (Vector (0.0, 0.0, 0.0)), MakeVectorAccessor (&MobilityModel::SetPosition, &MobilityModel::GetPosition), MakeVectorChecker ()) .AddAttribute ("Velocity", "The current velocity of the mobility model.", TypeId::ATTR_GET, - Vector (0.0, 0.0, 0.0), // ignored initial value. + VectorValue (Vector (0.0, 0.0, 0.0)), // ignored initial value. MakeVectorAccessor (&MobilityModel::GetVelocity), MakeVectorChecker ()) ; diff --git a/src/mobility/position-allocator.cc b/src/mobility/position-allocator.cc index 75cb37be6..0bf06f863 100644 --- a/src/mobility/position-allocator.cc +++ b/src/mobility/position-allocator.cc @@ -83,27 +83,27 @@ GridPositionAllocator::GetTypeId (void) .SetGroupName ("Mobility") .AddConstructor () .AddAttribute ("GridWidth", "The number of objects layed out on a line.", - Uinteger (10), + UintegerValue (10), MakeUintegerAccessor (&GridPositionAllocator::m_n), MakeUintegerChecker ()) .AddAttribute ("MinX", "The x coordinate where the grid starts.", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&GridPositionAllocator::m_xMin), MakeDoubleChecker ()) .AddAttribute ("MinY", "The y coordinate where the grid starts.", - Double (0.0), + DoubleValue (0.0), MakeDoubleAccessor (&GridPositionAllocator::m_yMin), MakeDoubleChecker ()) .AddAttribute ("DeltaX", "The x space between objects.", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&GridPositionAllocator::m_deltaX), MakeDoubleChecker ()) .AddAttribute ("DeltaY", "The y space between objects.", - Double (1.0), + DoubleValue (1.0), MakeDoubleAccessor (&GridPositionAllocator::m_deltaY), MakeDoubleChecker ()) .AddAttribute ("LayoutType", "The type of layout.", - Enum (ROW_FIRST), + EnumValue (ROW_FIRST), MakeEnumAccessor (&GridPositionAllocator::m_layoutType), MakeEnumChecker (ROW_FIRST, "RowFirst", COLUMN_FIRST, "ColumnFirst")) @@ -206,12 +206,12 @@ RandomRectanglePositionAllocator::GetTypeId (void) .AddConstructor () .AddAttribute ("X", "A random variable which represents the x coordinate of a position in a random rectangle.", - UniformVariable (0.0, 1.0), + RandomVariableValue (UniformVariable (0.0, 1.0)), MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_x), MakeRandomVariableChecker ()) .AddAttribute ("Y", "A random variable which represents the y coordinate of a position in a random rectangle.", - UniformVariable (0.0, 1.0), + RandomVariableValue (UniformVariable (0.0, 1.0)), MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_y), MakeRandomVariableChecker ()); return tid; @@ -252,22 +252,22 @@ RandomDiscPositionAllocator::GetTypeId (void) .AddConstructor () .AddAttribute ("Theta", "A random variable which represents the angle (gradients) of a position in a random disc.", - UniformVariable (0.0, 6.2830), + RandomVariableValue (UniformVariable (0.0, 6.2830)), MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_theta), MakeRandomVariableChecker ()) .AddAttribute ("Rho", "A random variable which represents the radius of a position in a random disc.", - UniformVariable (0.0, 200.0), + RandomVariableValue (UniformVariable (0.0, 200.0)), MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_rho), MakeRandomVariableChecker ()) .AddAttribute ("X", "The x coordinate of the center of the random position disc.", - Double (0.0), + DoubleValue (0.0), MakeDoubleAccessor (&RandomDiscPositionAllocator::m_x), MakeDoubleChecker ()) .AddAttribute ("Y", "The y coordinate of the center of the random position disc.", - Double (0.0), + DoubleValue (0.0), MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y), MakeDoubleChecker ()) ; diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index d49bd7a62..3ae572073 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -40,15 +40,15 @@ RandomDirection2dMobilityModel::GetTypeId (void) .SetGroupName ("Mobility") .AddConstructor () .AddAttribute ("Bounds", "The 2d bounding area", - Rectangle (-100, 100, -100, 100), + RectangleValue (Rectangle (-100, 100, -100, 100)), MakeRectangleAccessor (&RandomDirection2dMobilityModel::m_bounds), MakeRectangleChecker ()) .AddAttribute ("Speed", "A random variable to control the speed (m/s).", - UniformVariable (1.0, 2.0), + RandomVariableValue (UniformVariable (1.0, 2.0)), MakeRandomVariableAccessor (&RandomDirection2dMobilityModel::m_speed), MakeRandomVariableChecker ()) .AddAttribute ("Pause", "A random variable to control the pause (s).", - ConstantVariable (2.0), + RandomVariableValue (ConstantVariable (2.0)), MakeRandomVariableAccessor (&RandomDirection2dMobilityModel::m_pause), MakeRandomVariableChecker ()) ; @@ -85,7 +85,7 @@ RandomDirection2dMobilityModel::BeginPause (void) void RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); double speed = m_speed.GetValue (); const Vector vector (std::cos (direction) * speed, std::sin (direction) * speed, diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 41ea8d654..59824a4f1 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -19,6 +19,7 @@ */ #include "random-walk-2d-mobility-model.h" #include "ns3/enum.h" +#include "ns3/double.h" #include "ns3/simulator.h" #include "ns3/log.h" #include @@ -38,34 +39,34 @@ RandomWalk2dMobilityModel::GetTypeId (void) .AddConstructor () .AddAttribute ("Bounds", "Bounds of the area to cruise.", - Rectangle (0.0, 0.0, 100.0, 100.0), + RectangleValue (Rectangle (0.0, 0.0, 100.0, 100.0)), MakeRectangleAccessor (&RandomWalk2dMobilityModel::m_bounds), MakeRectangleChecker ()) .AddAttribute ("Time", "Change current direction and speed after moving for this delay.", - Seconds (1.0), + TimeValue (Seconds (1.0)), MakeTimeAccessor (&RandomWalk2dMobilityModel::m_modeTime), MakeTimeChecker ()) .AddAttribute ("Distance", "Change current direction and speed after moving for this distance.", - Seconds (1.0), - MakeTimeAccessor (&RandomWalk2dMobilityModel::m_modeTime), - MakeTimeChecker ()) + DoubleValue (1.0), + MakeDoubleAccessor (&RandomWalk2dMobilityModel::m_modeDistance), + MakeDoubleChecker ()) .AddAttribute ("Mode", "The mode indicates the condition used to " "change the current speed and direction", - Enum (RandomWalk2dMobilityModel::MODE_DISTANCE), + EnumValue (RandomWalk2dMobilityModel::MODE_DISTANCE), MakeEnumAccessor (&RandomWalk2dMobilityModel::m_mode), MakeEnumChecker (RandomWalk2dMobilityModel::MODE_DISTANCE, "Distance", RandomWalk2dMobilityModel::MODE_TIME, "Time")) .AddAttribute ("Direction", "A random variable used to pick the direction (gradients).", - UniformVariable (0.0, 6.283184), + RandomVariableValue (UniformVariable (0.0, 6.283184)), MakeRandomVariableAccessor (&RandomWalk2dMobilityModel::m_direction), MakeRandomVariableChecker ()) .AddAttribute ("Speed", "A random variable used to pick the speed (m/s).", - UniformVariable (2.0, 4.0), + RandomVariableValue (UniformVariable (2.0, 4.0)), MakeRandomVariableAccessor (&RandomWalk2dMobilityModel::m_speed), MakeRandomVariableChecker ()); return tid; diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index d5d98e299..fd29f82e9 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -20,6 +20,7 @@ #include #include "ns3/simulator.h" #include "ns3/random-variable.h" +#include "ns3/pointer.h" #include "random-waypoint-mobility-model.h" #include "position-allocator.h" @@ -36,19 +37,19 @@ RandomWaypointMobilityModel::GetTypeId (void) .AddConstructor () .AddAttribute ("Speed", "A random variable used to pick the speed of a random waypoint model.", - UniformVariable (0.3, 0.7), + RandomVariableValue (UniformVariable (0.3, 0.7)), MakeRandomVariableAccessor (&RandomWaypointMobilityModel::m_speed), MakeRandomVariableChecker ()) .AddAttribute ("Pause", "A random variable used to pick the pause of a random waypoint model.", - ConstantVariable (2.0), + RandomVariableValue (ConstantVariable (2.0)), MakeRandomVariableAccessor (&RandomWaypointMobilityModel::m_pause), MakeRandomVariableChecker ()) .AddAttribute ("Position", "The position model used to pick a destination point.", - Ptr (0), - MakePtrAccessor (&RandomWaypointMobilityModel::m_position), - MakePtrChecker ()); + PointerValue (), + MakePointerAccessor (&RandomWaypointMobilityModel::m_position), + MakePointerChecker ()); return tid; } diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index 024339715..3777ee1a6 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -68,6 +68,11 @@ public: std::ostream &operator << (std::ostream &os, const Rectangle &rectangle); std::istream &operator >> (std::istream &is, Rectangle &rectangle); +/** + * \class ns3::RectangleValue + * \brief hold objects of type ns3::Rectangle + */ + ATTRIBUTE_HELPER_HEADER_2 (Rectangle); } // namespace ns3 diff --git a/src/mobility/vector.h b/src/mobility/vector.h index 7d97689b3..3517f7d36 100644 --- a/src/mobility/vector.h +++ b/src/mobility/vector.h @@ -63,6 +63,11 @@ public: double CalculateDistance (const Vector &a, const Vector &b); +/** + * \class ns3::VectorValue + * \brief hold objects of type ns3::Vector + */ + ATTRIBUTE_HELPER_HEADER_2 (Vector); std::ostream &operator << (std::ostream &os, const Vector &vector); diff --git a/src/node/address.cc b/src/node/address.cc index c27e0608b..3db5f1c8d 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -109,12 +109,28 @@ Address::Register (void) ATTRIBUTE_HELPER_CPP (Address); + bool operator == (const Address &a, const Address &b) { - NS_ASSERT (a.m_type == b.m_type || - a.m_type == 0 || - b.m_type == 0); - NS_ASSERT (a.GetLength() == b.GetLength()); + /* Two addresses can be equal even if their types are + * different if one of the two types is zero. a type of + * zero identifies an Address which might contain meaningful + * payload but for which the type field could not be set because + * we did not know it. This can typically happen in the ARP + * layer where we receive an address from an ArpHeader but + * we do not know its type: we really want to be able to + * compare addresses without knowing their real type. + */ + if (a.m_type != b.m_type && + a.m_type != 0 && + b.m_type != 0) + { + return false; + } + if (a.m_len != b.m_len) + { + return false; + } return memcmp (a.m_data, b.m_data, a.m_len) == 0; } bool operator != (const Address &a, const Address &b) @@ -123,9 +139,16 @@ bool operator != (const Address &a, const Address &b) } bool operator < (const Address &a, const Address &b) { - NS_ASSERT (a.m_type == b.m_type || - a.m_type == 0 || - b.m_type == 0); + // XXX: it is not clear to me how to order based on type. + // so, we do not compare the types here but we should. + if (a.m_len < b.m_len) + { + return true; + } + else if (a.m_len > b.m_len) + { + return false; + } NS_ASSERT (a.GetLength() == b.GetLength()); for (uint8_t i = 0; i < a.GetLength(); i++) { @@ -143,27 +166,63 @@ bool operator < (const Address &a, const Address &b) std::ostream& operator<< (std::ostream& os, const Address & address) { - if (address.m_len == 0) - { - os << "NULL-ADDRESS"; - return os; - } os.setf (std::ios::hex, std::ios::basefield); os.fill('0'); - for (uint8_t i=0; i < (address.m_len-1); i++) + os << std::setw(2) << (uint32_t) address.m_type << "-" << std::setw(2) << (uint32_t) address.m_len << "-"; + for (uint8_t i = 0; i < (address.m_len-1); ++i) { os << std::setw(2) << (uint32_t)address.m_data[i] << ":"; } // Final byte not suffixed by ":" - os << std::setw(2) << (uint32_t)address.m_data[address.m_len-1]; + os << std::setw(2) << (uint32_t) address.m_data[address.m_len-1]; os.setf (std::ios::dec, std::ios::basefield); os.fill(' '); return os; } +static uint8_t +AsInt (std::string v) +{ + std::istringstream iss; + iss.str (v); + uint32_t retval; + iss >> std::hex >> retval >> std::dec; + return retval; +} + std::istream& operator>> (std::istream& is, Address & address) { - // XXX: need to be able to parse this. + std::string v; + is >> v; + std::string::size_type firstDash, secondDash; + firstDash = v.find ("-"); + secondDash = v.find ("-", firstDash+1); + std::string type = v.substr (0, firstDash-0); + std::string len = v.substr (firstDash+1, secondDash-(firstDash+1)); + + address.m_type = AsInt (type); + address.m_len = AsInt (len); + NS_ASSERT (address.m_len <= Address::MAX_SIZE); + + std::string::size_type col = secondDash + 1; + for (uint8_t i = 0; i < address.m_len; ++i) + { + std::string tmp; + std::string::size_type next; + next = v.find (":", col); + if (next == std::string::npos) + { + tmp = v.substr (col, v.size ()-col); + address.m_data[i] = AsInt (tmp); + break; + } + else + { + tmp = v.substr (col, next-col); + address.m_data[i] = AsInt (tmp); + col = next + 1; + } + } return is; } diff --git a/src/node/address.h b/src/node/address.h index c8c3c256b..e5b6c82e3 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -159,12 +159,18 @@ private: friend bool operator == (const Address &a, const Address &b); friend bool operator < (const Address &a, const Address &b); friend std::ostream& operator<< (std::ostream& os, const Address & address); + friend std::istream& operator>> (std::istream& is, Address & address); uint8_t m_type; uint8_t m_len; uint8_t m_data[MAX_SIZE]; }; +/** + * \class ns3::AddressValue + * \brief hold objects of type ns3::Address + */ + ATTRIBUTE_HELPER_HEADER_2 (Address); bool operator == (const Address &a, const Address &b); diff --git a/src/node/channel.cc b/src/node/channel.cc index 2e8eb50ba..6f23bad49 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -37,33 +37,31 @@ Channel::GetTypeId (void) Channel::Channel () : m_name("Channel") { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } Channel::Channel (std::string name) : m_name(name) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << name); + NS_LOG_FUNCTION (this << name); } Channel::~Channel () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void Channel::SetName(std::string name) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << name); + NS_LOG_FUNCTION (this << name); m_name = name; } std::string Channel::GetName(void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_name; } diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 0002e2339..8c5a0a8cf 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -32,7 +32,7 @@ TypeId DropTailQueue::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("MaxPackets", "The maximum number of packets accepted by this DropTailQueue.", - Uinteger (100), + UintegerValue (100), MakeUintegerAccessor (&DropTailQueue::m_maxPackets), MakeUintegerChecker ()) ; @@ -44,19 +44,18 @@ DropTailQueue::DropTailQueue () : Queue (), m_packets () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } DropTailQueue::~DropTailQueue () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } bool DropTailQueue::DoEnqueue (Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p); + NS_LOG_FUNCTION (this << p); if (m_packets.size () >= m_maxPackets) { @@ -72,8 +71,7 @@ DropTailQueue::DoEnqueue (Ptr p) Ptr DropTailQueue::DoDequeue (void) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); if (m_packets.empty()) { @@ -92,8 +90,7 @@ DropTailQueue::DoDequeue (void) Ptr DropTailQueue::DoPeek (void) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); if (m_packets.empty()) { @@ -132,7 +129,7 @@ DropTailQueueTest::RunTests (void) bool result = true; Ptr queue = CreateObject (); - NS_TEST_ASSERT (queue->SetAttributeFailSafe ("MaxPackets", Uinteger (3))); + NS_TEST_ASSERT (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3))); Ptr p1, p2, p3, p4; p1 = Create (); diff --git a/src/node/ipv4-address-generator.cc b/src/node/ipv4-address-generator.cc index 292407223..527425b25 100644 --- a/src/node/ipv4-address-generator.cc +++ b/src/node/ipv4-address-generator.cc @@ -78,14 +78,14 @@ private: Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl () : m_entries (), m_test (false) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Reset (); } void Ipv4AddressGeneratorImpl::Reset (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t mask = 0; // @@ -123,7 +123,7 @@ Ipv4AddressGeneratorImpl::Reset (void) Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void @@ -132,7 +132,7 @@ Ipv4AddressGeneratorImpl::Init ( const Ipv4Mask mask, const Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // We're going to be playing with the actual bits in the network and mask so // pull them out into ints. @@ -170,7 +170,7 @@ Ipv4AddressGeneratorImpl::Init ( Ipv4AddressGeneratorImpl::GetNetwork ( const Ipv4Mask mask) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t index = MaskToIndex (mask); return Ipv4Address (m_netTable[index].network << m_netTable[index].shift); @@ -180,7 +180,7 @@ Ipv4AddressGeneratorImpl::GetNetwork ( Ipv4AddressGeneratorImpl::NextNetwork ( const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // The way this is expected to be used is that an address and network prefix // are initialized, and then NextAddress() is called repeatedly to set the @@ -200,7 +200,7 @@ Ipv4AddressGeneratorImpl::InitAddress ( const Ipv4Address addr, const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t index = MaskToIndex (mask); uint32_t addrBits = addr.GetHostOrder (); @@ -215,7 +215,7 @@ Ipv4AddressGeneratorImpl::InitAddress ( Ipv4AddressGeneratorImpl::GetAddress ( const Ipv4Mask mask) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t index = MaskToIndex (mask); @@ -227,7 +227,7 @@ Ipv4AddressGeneratorImpl::GetAddress ( Ipv4Address Ipv4AddressGeneratorImpl::NextAddress (const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // The way this is expected to be used is that an address and network prefix // are initialized, and then NextAddress() is called repeatedly to set the @@ -256,7 +256,7 @@ Ipv4AddressGeneratorImpl::NextAddress (const Ipv4Mask mask) bool Ipv4AddressGeneratorImpl::AddAllocated (const Ipv4Address address) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t addr = address.GetHostOrder (); @@ -347,7 +347,7 @@ Ipv4AddressGeneratorImpl::AddAllocated (const Ipv4Address address) void Ipv4AddressGeneratorImpl::TestMode (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_test = true; } @@ -390,7 +390,7 @@ Ipv4AddressGenerator::Init ( const Ipv4Mask mask, const Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); SimulationSingleton::Get () ->Init (net, mask, addr); @@ -399,7 +399,7 @@ Ipv4AddressGenerator::Init ( Ipv4Address Ipv4AddressGenerator::NextNetwork (const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->NextNetwork (mask); @@ -408,7 +408,7 @@ Ipv4AddressGenerator::NextNetwork (const Ipv4Mask mask) Ipv4Address Ipv4AddressGenerator::GetNetwork (const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->GetNetwork (mask); @@ -419,7 +419,7 @@ Ipv4AddressGenerator::InitAddress ( const Ipv4Address addr, const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); SimulationSingleton::Get () ->InitAddress (addr, mask); @@ -428,7 +428,7 @@ Ipv4AddressGenerator::InitAddress ( Ipv4Address Ipv4AddressGenerator::GetAddress (const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->GetAddress (mask); @@ -437,7 +437,7 @@ Ipv4AddressGenerator::GetAddress (const Ipv4Mask mask) Ipv4Address Ipv4AddressGenerator::NextAddress (const Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->NextAddress (mask); @@ -446,7 +446,7 @@ Ipv4AddressGenerator::NextAddress (const Ipv4Mask mask) void Ipv4AddressGenerator::Reset (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->Reset (); @@ -455,7 +455,7 @@ Ipv4AddressGenerator::Reset (void) bool Ipv4AddressGenerator::AddAllocated (const Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return SimulationSingleton::Get () ->AddAllocated (addr); @@ -464,7 +464,7 @@ Ipv4AddressGenerator::AddAllocated (const Ipv4Address addr) void Ipv4AddressGenerator::TestMode (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); SimulationSingleton::Get () ->TestMode (); diff --git a/src/node/ipv4-address.h b/src/node/ipv4-address.h index 669f8904a..fc2dc7fe7 100644 --- a/src/node/ipv4-address.h +++ b/src/node/ipv4-address.h @@ -185,6 +185,15 @@ private: uint32_t m_mask; }; +/** + * \class ns3::Ipv4AddressValue + * \brief hold objects of type ns3::Ipv4Address + */ +/** + * \class ns3::Ipv4MaskValue + * \brief hold objects of type ns3::Ipv4Mask + */ + ATTRIBUTE_HELPER_HEADER_2 (Ipv4Address); ATTRIBUTE_HELPER_HEADER_2 (Ipv4Mask); diff --git a/src/node/mac48-address.cc b/src/node/mac48-address.cc index a65941470..9683f80d1 100644 --- a/src/node/mac48-address.cc +++ b/src/node/mac48-address.cc @@ -200,9 +200,40 @@ std::ostream& operator<< (std::ostream& os, const Mac48Address & address) return os; } -std::istream& operator>> (std::istream& is, const Mac48Address & address) +static uint8_t +AsInt (std::string v) { - // XXX ! + std::istringstream iss; + iss.str (v); + uint32_t retval; + iss >> std::hex >> retval >> std::dec; + return retval; +} + +std::istream& operator>> (std::istream& is, Mac48Address & address) +{ + std::string v; + is >> v; + + std::string::size_type col = 0; + for (uint8_t i = 0; i < 6; ++i) + { + std::string tmp; + std::string::size_type next; + next = v.find (":", col); + if (next == std::string::npos) + { + tmp = v.substr (col, v.size ()-col); + address.m_address[i] = AsInt (tmp); + break; + } + else + { + tmp = v.substr (col, next-col); + address.m_address[i] = AsInt (tmp); + col = next + 1; + } + } return is; } diff --git a/src/node/mac48-address.h b/src/node/mac48-address.h index d7077eb88..6227e2e1b 100644 --- a/src/node/mac48-address.h +++ b/src/node/mac48-address.h @@ -107,17 +107,23 @@ private: static uint8_t GetType (void); friend bool operator < (const Mac48Address &a, const Mac48Address &b); friend bool operator == (const Mac48Address &a, const Mac48Address &b); + friend std::istream& operator>> (std::istream& is, Mac48Address & address); uint8_t m_address[6]; }; +/** + * \class ns3::Mac48AddressValue + * \brief hold objects of type ns3::Mac48Address + */ + ATTRIBUTE_HELPER_HEADER_2 (Mac48Address); bool operator == (const Mac48Address &a, const Mac48Address &b); bool operator != (const Mac48Address &a, const Mac48Address &b); bool operator < (const Mac48Address &a, const Mac48Address &b); std::ostream& operator<< (std::ostream& os, const Mac48Address & address); -std::istream& operator>> (std::istream& is, const Mac48Address & address); +std::istream& operator>> (std::istream& is, Mac48Address & address); } // namespace ns3 diff --git a/src/node/node-list.cc b/src/node/node-list.cc index e687fe5fc..e99a94b35 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -30,9 +30,8 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("NodeList"); - /** - * The private node list used by the static-based API + * \brief private implementation detail of the NodeList API. */ class NodeListPriv : public Object { @@ -55,15 +54,17 @@ private: std::vector > m_nodes; }; +NS_OBJECT_ENSURE_REGISTERED (NodeListPriv); + TypeId NodeListPriv::GetTypeId (void) { - static TypeId tid = TypeId ("NodeListPriv") + static TypeId tid = TypeId ("ns3::NodeListPriv") .SetParent () .AddAttribute ("NodeList", "The list of all nodes created during the simulation.", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&NodeListPriv::m_nodes), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) ; return tid; } @@ -88,7 +89,7 @@ NodeListPriv::DoGet (void) void NodeListPriv::Delete (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Config::UnregisterRootNamespaceObject (Get ()); (*DoGet ()) = 0; } @@ -96,11 +97,11 @@ NodeListPriv::Delete (void) NodeListPriv::NodeListPriv () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } NodeListPriv::~NodeListPriv () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (std::vector >::iterator i = m_nodes.begin (); i != m_nodes.end (); i++) { diff --git a/src/node/node.cc b/src/node/node.cc index d11bbe58b..456e13a95 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -37,16 +37,16 @@ Node::GetTypeId (void) static TypeId tid = TypeId ("ns3::Node") .SetParent () .AddAttribute ("DeviceList", "The list of devices associated to this Node.", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&Node::m_devices), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("ApplicationList", "The list of applications associated to this Node.", - ObjectVector (), + ObjectVectorValue (), MakeObjectVectorAccessor (&Node::m_applications), - MakeObjectVectorChecker ()) + MakeObjectVectorChecker ()) .AddAttribute ("Id", "The id (unique integer) of this Node.", TypeId::ATTR_GET, // allow only getting it. - Uinteger (0), + UintegerValue (0), MakeUintegerAccessor (&Node::m_id), MakeUintegerChecker ()) ; diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 3d7c09ec5..7d3578475 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -31,8 +31,7 @@ namespace ns3 { PacketSocket::PacketSocket () { - NS_LOG_FUNCTION; - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_state = STATE_OPEN; m_shutdownSend = false; m_shutdownRecv = false; @@ -47,34 +46,34 @@ PacketSocket::SetNode (Ptr node) PacketSocket::~PacketSocket () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void PacketSocket::DoDispose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_device = 0; } enum Socket::SocketErrno PacketSocket::GetErrno (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_errno; } Ptr PacketSocket::GetNode (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_node; } int PacketSocket::Bind (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); PacketSocketAddress address; address.SetProtocol (0); address.SetAllDevices (); @@ -84,7 +83,7 @@ PacketSocket::Bind (void) int PacketSocket::Bind (const Address &address) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!PacketSocketAddress::IsMatchingType (address)) { m_errno = ERROR_INVAL; @@ -97,7 +96,7 @@ PacketSocket::Bind (const Address &address) int PacketSocket::DoBind (const PacketSocketAddress &address) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_state == STATE_BOUND || m_state == STATE_CONNECTED) { @@ -130,7 +129,7 @@ PacketSocket::DoBind (const PacketSocketAddress &address) int PacketSocket::ShutdownSend (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_state == STATE_CLOSED) { m_errno = ERROR_BADF; @@ -143,7 +142,7 @@ PacketSocket::ShutdownSend (void) int PacketSocket::ShutdownRecv (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_state == STATE_CLOSED) { m_errno = ERROR_BADF; @@ -156,7 +155,7 @@ PacketSocket::ShutdownRecv (void) int PacketSocket::Close(void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_state == STATE_CLOSED) { m_errno = ERROR_BADF; @@ -170,7 +169,7 @@ PacketSocket::Close(void) int PacketSocket::Connect(const Address &ad) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); PacketSocketAddress address; if (m_state == STATE_CLOSED) { @@ -205,7 +204,7 @@ PacketSocket::Connect(const Address &ad) int PacketSocket::Send (Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_state == STATE_OPEN || m_state == STATE_BOUND) { @@ -218,7 +217,7 @@ PacketSocket::Send (Ptr p) int PacketSocket::SendTo(const Address &address, Ptr p) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); PacketSocketAddress ad; if (m_state == STATE_CLOSED) { @@ -291,7 +290,7 @@ void PacketSocket::ForwardUp (Ptr device, Ptr packet, uint16_t protocol, const Address &from) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_shutdownRecv) { return; diff --git a/src/node/queue.cc b/src/node/queue.cc index 5b1852d8b..6aa0f4c45 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -31,11 +31,11 @@ Queue::GetTypeId (void) { static TypeId tid = TypeId ("ns3::Queue") .SetParent () - .AddTraceSource ("Enqueue", "XXX", + .AddTraceSource ("Enqueue", "Enqueue a packet in the queue.", MakeTraceSourceAccessor (&Queue::m_traceEnqueue)) - .AddTraceSource ("Dequeue", "XXX", + .AddTraceSource ("Dequeue", "Dequeue a packet from the queue.", MakeTraceSourceAccessor (&Queue::m_traceDequeue)) - .AddTraceSource ("Drop", "XXX", + .AddTraceSource ("Drop", "Drop a packet stored in the queue.", MakeTraceSourceAccessor (&Queue::m_traceDrop)) ; return tid; @@ -49,20 +49,19 @@ Queue::Queue() : m_nTotalDroppedBytes(0), m_nTotalDroppedPackets(0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } Queue::~Queue() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } bool Queue::Enqueue (Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p); + NS_LOG_FUNCTION (this << p); NS_LOG_LOGIC ("m_traceEnqueue (p)"); m_traceEnqueue (p); @@ -79,8 +78,7 @@ Queue::Enqueue (Ptr p) Ptr Queue::Dequeue (void) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); Ptr packet = DoDequeue (); @@ -102,15 +100,14 @@ Queue::Dequeue (void) void Queue::DequeueAll (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG (0, "Don't know what to do with dequeued packets!"); } Ptr Queue::Peek (void) const { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this); + NS_LOG_FUNCTION (this); return DoPeek (); } @@ -118,7 +115,7 @@ Queue::Peek (void) const uint32_t Queue::GetNPackets (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("returns " << m_nPackets); return m_nPackets; } @@ -126,7 +123,7 @@ Queue::GetNPackets (void) const uint32_t Queue::GetNBytes (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC (" returns " << m_nBytes); return m_nBytes; } @@ -134,7 +131,7 @@ Queue::GetNBytes (void) const bool Queue::IsEmpty (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("returns " << (m_nPackets == 0)); return m_nPackets == 0; } @@ -142,7 +139,7 @@ Queue::IsEmpty (void) const uint32_t Queue::GetTotalReceivedBytes (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("returns " << m_nTotalReceivedBytes); return m_nTotalReceivedBytes; } @@ -150,7 +147,7 @@ Queue::GetTotalReceivedBytes (void) const uint32_t Queue::GetTotalReceivedPackets (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("returns " << m_nTotalReceivedPackets); return m_nTotalReceivedPackets; } @@ -158,7 +155,7 @@ Queue::GetTotalReceivedPackets (void) const uint32_t Queue:: GetTotalDroppedBytes (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("returns " << m_nTotalDroppedBytes); return m_nTotalDroppedBytes; } @@ -166,7 +163,7 @@ Queue:: GetTotalDroppedBytes (void) const uint32_t Queue::GetTotalDroppedPackets (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("returns " << m_nTotalDroppedPackets); return m_nTotalDroppedPackets; } @@ -174,7 +171,7 @@ Queue::GetTotalDroppedPackets (void) const void Queue::ResetStatistics (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_nTotalReceivedBytes = 0; m_nTotalReceivedPackets = 0; m_nTotalDroppedBytes = 0; @@ -184,8 +181,7 @@ Queue::ResetStatistics (void) void Queue::Drop (Ptr p) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << p); + NS_LOG_FUNCTION (this << p); m_nTotalDroppedPackets++; m_nTotalDroppedBytes += p->GetSize (); diff --git a/src/node/socket.cc b/src/node/socket.cc index b909aa1e2..0bf9e95b4 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -30,13 +30,13 @@ namespace ns3 { Socket::~Socket () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } void Socket::SetCloseCallback (Callback > closeCompleted) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_closeCompleted = closeCompleted; } @@ -46,7 +46,7 @@ Socket::SetConnectCallback ( Callback > connectionFailed, Callback > halfClose) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_connectionSucceeded = connectionSucceeded; m_connectionFailed = connectionFailed; m_halfClose = halfClose; @@ -58,7 +58,7 @@ Socket::SetAcceptCallback ( Callback, const Address&> newConnectionCreated, Callback > closeRequested) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_connectionRequest = connectionRequest; m_newConnectionCreated = newConnectionCreated; m_closeRequested = closeRequested; @@ -67,20 +67,20 @@ Socket::SetAcceptCallback ( void Socket::SetSendCallback (Callback, uint32_t> dataSent) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_dataSent = dataSent; } void Socket::SetRecvCallback (Callback, Ptr,const Address&> receivedData) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_receivedData = receivedData; } int Socket::Send (const uint8_t* buf, uint32_t size) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr p; if (buf) { @@ -95,7 +95,7 @@ int Socket::Send (const uint8_t* buf, uint32_t size) int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr p; if(buf) { @@ -117,7 +117,7 @@ int Socket::Listen(uint32_t queueLimit) void Socket::NotifyCloseCompleted (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_closeCompleted.IsNull ()) { m_closeCompleted (this); @@ -127,7 +127,7 @@ Socket::NotifyCloseCompleted (void) void Socket::NotifyConnectionSucceeded (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_connectionSucceeded.IsNull ()) { m_connectionSucceeded (this); @@ -137,7 +137,7 @@ Socket::NotifyConnectionSucceeded (void) void Socket::NotifyConnectionFailed (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_connectionFailed.IsNull ()) { m_connectionFailed (this); @@ -147,7 +147,7 @@ Socket::NotifyConnectionFailed (void) void Socket::NotifyHalfClose (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_halfClose.IsNull ()) { m_halfClose (this); @@ -157,7 +157,7 @@ Socket::NotifyHalfClose (void) bool Socket::NotifyConnectionRequest (const Address &from) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_connectionRequest.IsNull ()) { return m_connectionRequest (this, from); @@ -175,7 +175,7 @@ Socket::NotifyConnectionRequest (const Address &from) void Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_newConnectionCreated.IsNull ()) { m_newConnectionCreated (socket, from); @@ -185,7 +185,7 @@ Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) void Socket::NotifyCloseRequested (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_closeRequested.IsNull ()) { m_closeRequested (this); @@ -195,7 +195,7 @@ Socket::NotifyCloseRequested (void) void Socket::NotifyDataSent (uint32_t size) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_dataSent.IsNull ()) { m_dataSent (this, size); @@ -205,7 +205,7 @@ Socket::NotifyDataSent (uint32_t size) void Socket::NotifyDataReceived (Ptr p, const Address &from) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (!m_receivedData.IsNull ()) { m_receivedData (this, p, from); diff --git a/src/node/tcp.cc b/src/node/tcp.cc index e3fb9ced9..77e02362f 100644 --- a/src/node/tcp.cc +++ b/src/node/tcp.cc @@ -32,52 +32,52 @@ Tcp::GetTypeId (void) .SetParent () .AddAttribute ("DefaultSegmentSize", "Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", - Uinteger (536), + UintegerValue (536), MakeUintegerAccessor (&Tcp::m_defaultSegSize), MakeUintegerChecker ()) .AddAttribute ("DefaultAdvertisedWindowSize", "Default TCP advertised window size (bytes)", - Uinteger (0xffff), + UintegerValue (0xffff), MakeUintegerAccessor (&Tcp::m_defaultAdvWin), MakeUintegerChecker ()) .AddAttribute ("DefaultSlowStartThreshold", "Default TCP slow start threshold (bytes)", - Uinteger (0xffff), + UintegerValue (0xffff), MakeUintegerAccessor (&Tcp::m_defaultSsThresh), MakeUintegerChecker ()) .AddAttribute ("DefaultTxBufferSize", "Default TCP maximum transmit buffer size (bytes)", - Uinteger (0xffffffffl), + UintegerValue (0xffffffffl), MakeUintegerAccessor (&Tcp::m_defaultTxBuffer), MakeUintegerChecker ()) .AddAttribute ("DefaultRxBufferSize", "Default TCP maximum receive buffer size (bytes)", - Uinteger (0xffffffffl), + UintegerValue (0xffffffffl), MakeUintegerAccessor (&Tcp::m_defaultRxBuffer), MakeUintegerChecker ()) .AddAttribute ("DefaultInitialCongestionWindowSize", "Default TCP initial congestion window size (segments)", - Uinteger (1), + UintegerValue (1), MakeUintegerAccessor (&Tcp::m_defaultInitialCwnd), MakeUintegerChecker ()) .AddAttribute ("DefaultConnTimeout", "Default TCP retransmission timeout when opening connection (seconds)", - Uinteger (3), + UintegerValue (3), MakeUintegerAccessor (&Tcp::m_defaultConnTimeout), MakeUintegerChecker ()) .AddAttribute ("DefaultConnCount", "Default number of connection attempts (SYN retransmissions) before returning failure", - Uinteger (6), + UintegerValue (6), MakeUintegerAccessor (&Tcp::m_defaultConnCount), MakeUintegerChecker ()) .AddAttribute ("DefaultDelAckTimeout", "Default timeout value for TCP delayed acks, in seconds", - Double (0.2), + DoubleValue (0.2), MakeDoubleAccessor (&Tcp::m_defaultDelAckTimeout), MakeDoubleChecker ()) .AddAttribute ("DefaultDelAckCount", "Default number of packets to wait before sending a TCP ack", - Uinteger (2), + UintegerValue (2), MakeUintegerAccessor (&Tcp::m_defaultDelAckCount), MakeUintegerChecker ()) ; diff --git a/src/routing/global-routing/candidate-queue.cc b/src/routing/global-routing/candidate-queue.cc index 242e427ae..4f5b3cf27 100644 --- a/src/routing/global-routing/candidate-queue.cc +++ b/src/routing/global-routing/candidate-queue.cc @@ -28,19 +28,19 @@ namespace ns3 { CandidateQueue::CandidateQueue() : m_candidates () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } CandidateQueue::~CandidateQueue() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Clear (); } void CandidateQueue::Clear (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); while (!m_candidates.empty ()) { SPFVertex *p = Pop (); @@ -52,8 +52,7 @@ CandidateQueue::Clear (void) void CandidateQueue::Push (SPFVertex *vNew) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << vNew); + NS_LOG_FUNCTION (this << vNew); CandidateList_t::iterator i = m_candidates.begin (); @@ -71,7 +70,7 @@ CandidateQueue::Push (SPFVertex *vNew) SPFVertex * CandidateQueue::Pop (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_candidates.empty ()) { return 0; @@ -85,7 +84,7 @@ CandidateQueue::Pop (void) SPFVertex * CandidateQueue::Top (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_candidates.empty ()) { return 0; @@ -97,21 +96,21 @@ CandidateQueue::Top (void) const bool CandidateQueue::Empty (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_candidates.empty (); } uint32_t CandidateQueue::Size (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_candidates.size (); } SPFVertex * CandidateQueue::Find (const Ipv4Address addr) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); CandidateList_t::const_iterator i = m_candidates.begin (); for (; i != m_candidates.end (); i++) @@ -129,7 +128,7 @@ CandidateQueue::Find (const Ipv4Address addr) const void CandidateQueue::Reorder (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); std::list temp; while (!m_candidates.empty ()) { diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index 9381c1cff..68d5dc43a 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -54,7 +54,7 @@ SPFVertex::SPFVertex () : m_parent (0), m_children () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : @@ -66,7 +66,7 @@ SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : m_parent (0), m_children () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) { NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter"); @@ -81,7 +81,7 @@ SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : SPFVertex::~SPFVertex () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for ( ListOfSPFVertex_t::iterator i = m_children.begin (); i != m_children.end (); i++) @@ -97,112 +97,112 @@ SPFVertex::~SPFVertex () void SPFVertex::SetVertexType (SPFVertex::VertexType type) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_vertexType = type; } SPFVertex::VertexType SPFVertex::GetVertexType (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_vertexType; } void SPFVertex::SetVertexId (Ipv4Address id) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_vertexId = id; } Ipv4Address SPFVertex::GetVertexId (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_vertexId; } void SPFVertex::SetLSA (GlobalRoutingLSA* lsa) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_lsa = lsa; } GlobalRoutingLSA* SPFVertex::GetLSA (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_lsa; } void SPFVertex::SetDistanceFromRoot (uint32_t distance) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_distanceFromRoot = distance; } uint32_t SPFVertex::GetDistanceFromRoot (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_distanceFromRoot; } void SPFVertex::SetOutgoingTypeId (uint32_t id) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_rootOif = id; } uint32_t SPFVertex::GetOutgoingTypeId (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_rootOif; } void SPFVertex::SetNextHop (Ipv4Address nextHop) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_nextHop = nextHop; } Ipv4Address SPFVertex::GetNextHop (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_nextHop; } void SPFVertex::SetParent (SPFVertex* parent) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_parent = parent; } SPFVertex* SPFVertex::GetParent (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_parent; } uint32_t SPFVertex::GetNChildren (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_children.size (); } SPFVertex* SPFVertex::GetChild (uint32_t n) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t j = 0; for ( ListOfSPFVertex_t::const_iterator i = m_children.begin (); @@ -221,7 +221,7 @@ SPFVertex::GetChild (uint32_t n) const uint32_t SPFVertex::AddChild (SPFVertex* child) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_children.push_back (child); return m_children.size (); } @@ -236,12 +236,12 @@ GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : m_database () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); LSDBMap_t::iterator i; for (i= m_database.begin (); i!= m_database.end (); i++) { @@ -256,7 +256,7 @@ GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB () void GlobalRouteManagerLSDB::Initialize () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); LSDBMap_t::iterator i; for (i= m_database.begin (); i!= m_database.end (); i++) { @@ -268,14 +268,14 @@ GlobalRouteManagerLSDB::Initialize () void GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_database.insert (LSDBPair_t (addr, lsa)); } GlobalRoutingLSA* GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // Look up an LSA by its address. // @@ -293,7 +293,7 @@ GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const GlobalRoutingLSA* GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // Look up an LSA by its address. // @@ -325,13 +325,13 @@ GlobalRouteManagerImpl::GlobalRouteManagerImpl () : m_spfroot (0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_lsdb = new GlobalRouteManagerLSDB (); } GlobalRouteManagerImpl::~GlobalRouteManagerImpl () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_lsdb) { delete m_lsdb; @@ -341,7 +341,7 @@ GlobalRouteManagerImpl::~GlobalRouteManagerImpl () void GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); if (m_lsdb) { delete m_lsdb; @@ -359,7 +359,7 @@ GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb) void GlobalRouteManagerImpl::SelectRouterNodes () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) { Ptr node = *i; @@ -383,7 +383,7 @@ GlobalRouteManagerImpl::SelectRouterNodes () void GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // Walk the list of nodes looking for the GlobalRouter Interface. // @@ -464,7 +464,7 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () void GlobalRouteManagerImpl::InitializeRoutes () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // Walk the list of nodes in the system. // @@ -504,7 +504,7 @@ GlobalRouteManagerImpl::InitializeRoutes () void GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); SPFVertex* w = 0; GlobalRoutingLSA* w_lsa = 0; @@ -706,7 +706,7 @@ GlobalRouteManagerImpl::SPFNexthopCalculation ( GlobalRoutingLinkRecord* l, uint32_t distance) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // If w is a NetworkVertex, l should be null /* @@ -891,7 +891,7 @@ GlobalRouteManagerImpl::SPFGetNextLink ( SPFVertex* w, GlobalRoutingLinkRecord* prev_link) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); bool skip = true; bool found_prev_link = false; @@ -966,7 +966,7 @@ GlobalRouteManagerImpl::SPFGetNextLink ( void GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); SPFCalculate (root); } @@ -974,8 +974,7 @@ GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) void GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << root); + NS_LOG_FUNCTION (this << root); SPFVertex *v; // @@ -1124,7 +1123,7 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) uint32_t GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); // // We have an IP address and a vertex ID of the root of the SPF tree. // The question is what interface index does this address correspond to. @@ -1200,7 +1199,7 @@ GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask) void GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG (m_spfroot, "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set"); @@ -1317,7 +1316,7 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) void GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG (m_spfroot, "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set"); @@ -1410,7 +1409,7 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) void GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); v->GetParent ()->AddChild (v); } diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index 500aca863..cda479043 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -43,7 +43,7 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord () m_linkType (Unknown), m_metric (0) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( @@ -57,47 +57,46 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( m_linkType (linkType), m_metric (metric) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << linkType << linkId << linkData << metric); + NS_LOG_FUNCTION (this << linkType << linkId << linkData << metric); } GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } Ipv4Address GlobalRoutingLinkRecord::GetLinkId (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkId; } void GlobalRoutingLinkRecord::SetLinkId (Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_linkId = addr; } Ipv4Address GlobalRoutingLinkRecord::GetLinkData (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkData; } void GlobalRoutingLinkRecord::SetLinkData (Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_linkData = addr; } GlobalRoutingLinkRecord::LinkType GlobalRoutingLinkRecord::GetLinkType (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkType; } @@ -105,21 +104,21 @@ GlobalRoutingLinkRecord::GetLinkType (void) const GlobalRoutingLinkRecord::SetLinkType ( GlobalRoutingLinkRecord::LinkType linkType) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_linkType = linkType; } uint16_t GlobalRoutingLinkRecord::GetMetric (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_metric; } void GlobalRoutingLinkRecord::SetMetric (uint16_t metric) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_metric = metric; } @@ -139,7 +138,7 @@ GlobalRoutingLSA::GlobalRoutingLSA() m_attachedRouters(), m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); } GlobalRoutingLSA::GlobalRoutingLSA ( @@ -155,8 +154,7 @@ GlobalRoutingLSA::GlobalRoutingLSA ( m_attachedRouters(), m_status(status) { - NS_LOG_FUNCTION; - NS_LOG_PARAMS (this << status << linkStateId << advertisingRtr); + NS_LOG_FUNCTION (this << status << linkStateId << advertisingRtr); } GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) @@ -165,7 +163,7 @@ GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) m_networkLSANetworkMask(lsa.m_networkLSANetworkMask), m_status(lsa.m_status) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG(IsEmpty(), "GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor"); CopyLinkRecords (lsa); @@ -174,7 +172,7 @@ GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) GlobalRoutingLSA& GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_lsType = lsa.m_lsType; m_linkStateId = lsa.m_linkStateId; m_advertisingRtr = lsa.m_advertisingRtr; @@ -189,7 +187,7 @@ GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa) void GlobalRoutingLSA::CopyLinkRecords (const GlobalRoutingLSA& lsa) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin (); i != lsa.m_linkRecords.end (); i++) @@ -211,14 +209,14 @@ GlobalRoutingLSA::CopyLinkRecords (const GlobalRoutingLSA& lsa) GlobalRoutingLSA::~GlobalRoutingLSA() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ClearLinkRecords (); } void GlobalRoutingLSA::ClearLinkRecords(void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin (); i != m_linkRecords.end (); i++) @@ -238,7 +236,7 @@ GlobalRoutingLSA::ClearLinkRecords(void) uint32_t GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_linkRecords.push_back (lr); return m_linkRecords.size (); } @@ -246,14 +244,14 @@ GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr) uint32_t GlobalRoutingLSA::GetNLinkRecords (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkRecords.size (); } GlobalRoutingLinkRecord * GlobalRoutingLSA::GetLinkRecord (uint32_t n) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t j = 0; for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin (); i != m_linkRecords.end (); @@ -271,77 +269,77 @@ GlobalRoutingLSA::GetLinkRecord (uint32_t n) const bool GlobalRoutingLSA::IsEmpty (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkRecords.size () == 0; } GlobalRoutingLSA::LSType GlobalRoutingLSA::GetLSType (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_lsType; } void GlobalRoutingLSA::SetLSType (GlobalRoutingLSA::LSType typ) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_lsType = typ; } Ipv4Address GlobalRoutingLSA::GetLinkStateId (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_linkStateId; } void GlobalRoutingLSA::SetLinkStateId (Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_linkStateId = addr; } Ipv4Address GlobalRoutingLSA::GetAdvertisingRouter (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_advertisingRtr; } void GlobalRoutingLSA::SetAdvertisingRouter (Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_advertisingRtr = addr; } void GlobalRoutingLSA::SetNetworkLSANetworkMask (Ipv4Mask mask) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_networkLSANetworkMask = mask; } Ipv4Mask GlobalRoutingLSA::GetNetworkLSANetworkMask (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_networkLSANetworkMask; } GlobalRoutingLSA::SPFStatus GlobalRoutingLSA::GetStatus (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_status; } uint32_t GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_attachedRouters.push_back (addr); return m_attachedRouters.size (); } @@ -349,14 +347,14 @@ GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr) uint32_t GlobalRoutingLSA::GetNAttachedRouters (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_attachedRouters.size (); } Ipv4Address GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); uint32_t j = 0; for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); i != m_attachedRouters.end (); @@ -375,7 +373,7 @@ GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const void GlobalRoutingLSA::SetStatus (GlobalRoutingLSA::SPFStatus status) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_status = status; } @@ -444,27 +442,27 @@ GlobalRouter::GetTypeId (void) GlobalRouter::GlobalRouter () : m_LSAs() { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_routerId.Set(GlobalRouteManager::AllocateRouterId ()); } GlobalRouter::~GlobalRouter () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); ClearLSAs(); } void GlobalRouter::DoDispose () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Object::DoDispose (); } void GlobalRouter::ClearLSAs () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); for ( ListOfLSAs_t::iterator i = m_LSAs.begin (); i != m_LSAs.end (); i++) @@ -484,7 +482,7 @@ GlobalRouter::ClearLSAs () Ipv4Address GlobalRouter::GetRouterId (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_routerId; } @@ -495,7 +493,7 @@ GlobalRouter::GetRouterId (void) const uint32_t GlobalRouter::DiscoverLSAs (void) { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); NS_LOG_LOGIC("For node " << node->GetId () ); NS_ASSERT_MSG(node, @@ -765,7 +763,7 @@ GlobalRouter::FindDesignatedRouterForLink (Ptr node, uint32_t GlobalRouter::GetNumLSAs (void) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); return m_LSAs.size (); } @@ -775,7 +773,7 @@ GlobalRouter::GetNumLSAs (void) const bool GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG(lsa.IsEmpty(), "GlobalRouter::GetLSA (): Must pass empty LSA"); // // All of the work was done in GetNumLSAs. All we have to do here is to @@ -805,7 +803,7 @@ GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const Ptr GlobalRouter::GetAdjacent(Ptr nd, Ptr ch) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices"); // @@ -841,7 +839,7 @@ GlobalRouter::GetAdjacent(Ptr nd, Ptr ch) const uint32_t GlobalRouter::FindIfIndexForDevice(Ptr node, Ptr nd) const { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); Ptr ipv4 = node->GetObject (); NS_ASSERT_MSG(ipv4, "QI for interface failed"); for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 79b5ae02c..5c27a7d6b 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -157,19 +157,19 @@ AgentImpl::GetTypeId (void) .SetParent () .AddConstructor () .AddAttribute ("HelloInterval", "XXX", - OLSR_HELLO_INTERVAL, + TimeValue (OLSR_HELLO_INTERVAL), MakeTimeAccessor (&AgentImpl::m_helloInterval), MakeTimeChecker ()) .AddAttribute ("TcInterval", "XXX", - OLSR_TC_INTERVAL, + TimeValue (OLSR_TC_INTERVAL), MakeTimeAccessor (&AgentImpl::m_tcInterval), MakeTimeChecker ()) .AddAttribute ("MidInterval", "XXX", - OLSR_MID_INTERVAL, + TimeValue (OLSR_MID_INTERVAL), MakeTimeAccessor (&AgentImpl::m_midInterval), MakeTimeChecker ()) .AddAttribute ("Willingness", "XXX", - Uinteger (OLSR_WILL_DEFAULT), + UintegerValue (OLSR_WILL_DEFAULT), MakeUintegerAccessor (&AgentImpl::m_willingness), MakeUintegerChecker ()) .AddTraceSource ("Rx", "Receive OLSR packet.", @@ -572,12 +572,15 @@ AgentImpl::MprComputation() // (not in RFC but I think is needed: remove the 2-hop // neighbors reachable by the MPR from N2) for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } } @@ -617,12 +620,15 @@ AgentImpl::MprComputation() } // Remove the nodes from N2 which are now covered by a node in the MPR set. for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ()) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } @@ -699,12 +705,15 @@ AgentImpl::MprComputation() { mprSet.insert (max->neighborMainAddr); for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } } diff --git a/src/routing/olsr/olsr-state.cc b/src/routing/olsr/olsr-state.cc index 545407a4b..ad4cb8723 100644 --- a/src/routing/olsr/olsr-state.cc +++ b/src/routing/olsr/olsr-state.cc @@ -64,12 +64,15 @@ void OlsrState::EraseMprSelectorTuples (const Ipv4Address &mainAddr) { for (MprSelectorSet::iterator it = m_mprSelectorSet.begin (); - it != m_mprSelectorSet.end (); it++) + it != m_mprSelectorSet.end ();) { if (it->mainAddr == mainAddr) { it = m_mprSelectorSet.erase (it); - it--; + } + else + { + it++; } } } @@ -203,15 +206,18 @@ OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr, const Ipv4Address &twoHopNeighborAddr) { for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin (); - it != m_twoHopNeighborSet.end (); it++) + it != m_twoHopNeighborSet.end ();) { if (it->neighborMainAddr == neighborMainAddr && it->twoHopNeighborAddr == twoHopNeighborAddr) { it = m_twoHopNeighborSet.erase (it); - it--; // FIXME: is this correct in the case 'it' pointed to the first element? m_modified = true; } + else + { + it++; + } } } @@ -219,13 +225,17 @@ void OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr) { for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin (); - it != m_twoHopNeighborSet.end (); it++) + it != m_twoHopNeighborSet.end ();) { - if (it->neighborMainAddr == neighborMainAddr) { - it = m_twoHopNeighborSet.erase (it); - it--; - m_modified = true; - } + if (it->neighborMainAddr == neighborMainAddr) + { + it = m_twoHopNeighborSet.erase (it); + m_modified = true; + } + else + { + it++; + } } } @@ -385,14 +395,17 @@ void OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn) { for (TopologySet::iterator it = m_topologySet.begin(); - it != m_topologySet.end(); it++) + it != m_topologySet.end();) { if (it->lastAddr == lastAddr && it->sequenceNumber < ansn) { it = m_topologySet.erase (it); - it--; m_modified = true; } + else + { + it++; + } } } diff --git a/src/routing/olsr/routing-table.cc b/src/routing/olsr/routing-table.cc index 8c993eea1..3fed01438 100644 --- a/src/routing/olsr/routing-table.cc +++ b/src/routing/olsr/routing-table.cc @@ -40,7 +40,7 @@ NS_LOG_COMPONENT_DEFINE ("OlsrRoutingTable"); void RoutingTable::Clear () { - NS_LOG_FUNCTION; + NS_LOG_FUNCTION_NOARGS (); m_table.clear (); } @@ -183,14 +183,7 @@ RoutingTable::AddEntry (Ipv4Address const &dest, uint32_t interface, uint32_t distance) { - NS_LOG_PARAMS_BEGIN (); - NS_LOG_PARAM (this); - NS_LOG_PARAM (dest); - NS_LOG_PARAM (next); - NS_LOG_PARAM (interface); - NS_LOG_PARAM (distance); - NS_LOG_PARAM (m_mainAddress); - NS_LOG_PARAMS_END (); + NS_LOG_FUNCTION (this << dest << next << interface << distance << m_mainAddress); NS_ASSERT (distance > 0); @@ -209,14 +202,7 @@ RoutingTable::AddEntry (Ipv4Address const &dest, Ipv4Address const &interfaceAddress, uint32_t distance) { - NS_LOG_PARAMS_BEGIN (); - NS_LOG_PARAM (this); - NS_LOG_PARAM (dest); - NS_LOG_PARAM (next); - NS_LOG_PARAM (interfaceAddress); - NS_LOG_PARAM (distance); - NS_LOG_PARAM (m_mainAddress); - NS_LOG_PARAMS_END (); + NS_LOG_FUNCTION (this << dest << next << interfaceAddress << distance << m_mainAddress); NS_ASSERT (distance > 0); NS_ASSERT (m_ipv4); diff --git a/src/simulator/scheduler-heap.cc b/src/simulator/heap-scheduler.cc similarity index 84% rename from src/simulator/scheduler-heap.cc rename to src/simulator/heap-scheduler.cc index d26f8a959..41f174d39 100644 --- a/src/simulator/scheduler-heap.cc +++ b/src/simulator/heap-scheduler.cc @@ -31,7 +31,7 @@ * to move one if statement out of the loop. */ -#include "scheduler-heap.h" +#include "heap-scheduler.h" #include "event-impl.h" #include "ns3/assert.h" @@ -52,7 +52,7 @@ std::cout << "HEAP TRACE " << x << std::endl; namespace ns3 { -SchedulerHeap::SchedulerHeap () +HeapScheduler::HeapScheduler () { // we purposedly waste an item at the start of // the array to make sure the indexes in the @@ -61,57 +61,57 @@ SchedulerHeap::SchedulerHeap () m_heap.push_back (std::make_pair (static_cast(0), emptyKey)); } -SchedulerHeap::~SchedulerHeap () +HeapScheduler::~HeapScheduler () {} uint32_t -SchedulerHeap::Parent (uint32_t id) const +HeapScheduler::Parent (uint32_t id) const { return id / 2; } uint32_t -SchedulerHeap::Sibling (uint32_t id) const +HeapScheduler::Sibling (uint32_t id) const { return id + 1; } uint32_t -SchedulerHeap::LeftChild (uint32_t id) const +HeapScheduler::LeftChild (uint32_t id) const { return id * 2; } uint32_t -SchedulerHeap::RightChild (uint32_t id) const +HeapScheduler::RightChild (uint32_t id) const { return id * 2 + 1; } uint32_t -SchedulerHeap::Root (void) const +HeapScheduler::Root (void) const { return 1; } bool -SchedulerHeap::IsRoot (uint32_t id) const +HeapScheduler::IsRoot (uint32_t id) const { return (id == Root ())?true:false; } uint32_t -SchedulerHeap::Last (void) const +HeapScheduler::Last (void) const { return m_heap.size () - 1; } bool -SchedulerHeap::IsBottom (uint32_t id) const +HeapScheduler::IsBottom (uint32_t id) const { return (id >= m_heap.size ())?true:false; } void -SchedulerHeap::Exch (uint32_t a, uint32_t b) +HeapScheduler::Exch (uint32_t a, uint32_t b) { NS_ASSERT (b < m_heap.size () && a < m_heap.size ()); TRACE ("Exch " << a << ", " << b); @@ -121,7 +121,7 @@ SchedulerHeap::Exch (uint32_t a, uint32_t b) } bool -SchedulerHeap::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const +HeapScheduler::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const { if (a->m_ts < b->m_ts) { @@ -142,25 +142,25 @@ SchedulerHeap::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey } bool -SchedulerHeap::IsLessStrictly (uint32_t a, uint32_t b) const +HeapScheduler::IsLessStrictly (uint32_t a, uint32_t b) const { return IsLowerStrictly (&m_heap[a].second, &m_heap[b].second); } uint32_t -SchedulerHeap::Smallest (uint32_t a, uint32_t b) const +HeapScheduler::Smallest (uint32_t a, uint32_t b) const { return IsLessStrictly (a,b)?a:b; } bool -SchedulerHeap::IsEmpty (void) const +HeapScheduler::IsEmpty (void) const { return (m_heap.size () == 1)?true:false; } void -SchedulerHeap::BottomUp (void) +HeapScheduler::BottomUp (void) { uint32_t index = Last (); while (!IsRoot (index) && @@ -172,7 +172,7 @@ SchedulerHeap::BottomUp (void) } void -SchedulerHeap::TopDown (uint32_t start) +HeapScheduler::TopDown (uint32_t start) { uint32_t index = start; uint32_t right = RightChild (index); @@ -207,7 +207,7 @@ SchedulerHeap::TopDown (uint32_t start) void -SchedulerHeap::Insert (const EventId &id) +HeapScheduler::Insert (const EventId &id) { // acquire single ref EventImpl *event = id.PeekEventImpl (); @@ -220,13 +220,13 @@ SchedulerHeap::Insert (const EventId &id) } EventId -SchedulerHeap::PeekNext (void) const +HeapScheduler::PeekNext (void) const { std::pair next = m_heap[Root ()]; return EventId (next.first, next.second.m_ts, next.second.m_uid); } EventId -SchedulerHeap::RemoveNext (void) +HeapScheduler::RemoveNext (void) { std::pair next = m_heap[Root ()]; Exch (Root (), Last ()); @@ -237,7 +237,7 @@ SchedulerHeap::RemoveNext (void) bool -SchedulerHeap::Remove (const EventId &id) +HeapScheduler::Remove (const EventId &id) { uint32_t uid = id.GetUid (); for (uint32_t i = 1; i < m_heap.size (); i++) diff --git a/src/simulator/scheduler-heap.h b/src/simulator/heap-scheduler.h similarity index 95% rename from src/simulator/scheduler-heap.h rename to src/simulator/heap-scheduler.h index 3b2f74f32..20e8165e7 100644 --- a/src/simulator/scheduler-heap.h +++ b/src/simulator/heap-scheduler.h @@ -29,10 +29,10 @@ namespace ns3 { class EventHolder; -class SchedulerHeap : public Scheduler { +class HeapScheduler : public Scheduler { public: - SchedulerHeap (); - virtual ~SchedulerHeap (); + HeapScheduler (); + virtual ~HeapScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; diff --git a/src/simulator/scheduler-list.cc b/src/simulator/list-scheduler.cc similarity index 87% rename from src/simulator/scheduler-list.cc rename to src/simulator/list-scheduler.cc index 3514b2519..78459434a 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/list-scheduler.cc @@ -18,7 +18,7 @@ * Author: Mathieu Lacage */ -#include "scheduler-list.h" +#include "list-scheduler.h" #include "event-impl.h" #include #include @@ -27,13 +27,13 @@ namespace ns3 { -SchedulerList::SchedulerList () +ListScheduler::ListScheduler () {} -SchedulerList::~SchedulerList () +ListScheduler::~ListScheduler () {} bool -SchedulerList::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const +ListScheduler::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const { if (a->m_ts < b->m_ts) { @@ -51,7 +51,7 @@ SchedulerList::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b } void -SchedulerList::Insert (const EventId &id) +ListScheduler::Insert (const EventId &id) { Scheduler::EventKey key; // acquire refcount on EventImpl @@ -70,19 +70,19 @@ SchedulerList::Insert (const EventId &id) m_events.push_back (std::make_pair (event, key)); } bool -SchedulerList::IsEmpty (void) const +ListScheduler::IsEmpty (void) const { return m_events.empty (); } EventId -SchedulerList::PeekNext (void) const +ListScheduler::PeekNext (void) const { std::pair next = m_events.front (); return EventId (next.first, next.second.m_ts, next.second.m_uid); } EventId -SchedulerList::RemoveNext (void) +ListScheduler::RemoveNext (void) { std::pair next = m_events.front (); m_events.pop_front (); @@ -90,7 +90,7 @@ SchedulerList::RemoveNext (void) } bool -SchedulerList::Remove (const EventId &id) +ListScheduler::Remove (const EventId &id) { for (EventsI i = m_events.begin (); i != m_events.end (); i++) { diff --git a/src/simulator/scheduler-list.h b/src/simulator/list-scheduler.h similarity index 94% rename from src/simulator/scheduler-list.h rename to src/simulator/list-scheduler.h index 86dfc991f..c4e70398b 100644 --- a/src/simulator/scheduler-list.h +++ b/src/simulator/list-scheduler.h @@ -31,10 +31,10 @@ namespace ns3 { class EventImpl; -class SchedulerList : public Scheduler { +class ListScheduler : public Scheduler { public: - SchedulerList (); - virtual ~SchedulerList (); + ListScheduler (); + virtual ~ListScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; diff --git a/src/simulator/scheduler-map.cc b/src/simulator/map-scheduler.cc similarity index 88% rename from src/simulator/scheduler-map.cc rename to src/simulator/map-scheduler.cc index 0c5024c9b..9726c4b66 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/map-scheduler.cc @@ -19,7 +19,7 @@ * The idea to use a std c++ map came from GTNetS */ -#include "scheduler-map.h" +#include "map-scheduler.h" #include "event-impl.h" #include "ns3/assert.h" #include @@ -37,9 +37,9 @@ std::cout << "MAP TRACE " << x << std::endl; namespace ns3 { -SchedulerMap::SchedulerMap () +MapScheduler::MapScheduler () {} -SchedulerMap::~SchedulerMap () +MapScheduler::~MapScheduler () {} /* Note the invariants which this function must provide: @@ -48,7 +48,7 @@ SchedulerMap::~SchedulerMap () * - transitivity: f(x,y) and f(y,z) => f(x,z) */ bool -SchedulerMap::EventKeyCompare::operator () (struct EventKey const&a, struct EventKey const&b) +MapScheduler::EventKeyCompare::operator () (struct EventKey const&a, struct EventKey const&b) { if (a.m_ts < b.m_ts) { @@ -71,7 +71,7 @@ SchedulerMap::EventKeyCompare::operator () (struct EventKey const&a, struct Even void -SchedulerMap::Insert (const EventId &id) +MapScheduler::Insert (const EventId &id) { // acquire a single ref EventImpl *event = id.PeekEventImpl (); @@ -85,13 +85,13 @@ SchedulerMap::Insert (const EventId &id) } bool -SchedulerMap::IsEmpty (void) const +MapScheduler::IsEmpty (void) const { return m_list.empty (); } EventId -SchedulerMap::PeekNext (void) const +MapScheduler::PeekNext (void) const { EventMapCI i = m_list.begin (); NS_ASSERT (i != m_list.end ()); @@ -99,7 +99,7 @@ SchedulerMap::PeekNext (void) const return EventId (i->second, i->first.m_ts, i->first.m_uid); } EventId -SchedulerMap::RemoveNext (void) +MapScheduler::RemoveNext (void) { EventMapI i = m_list.begin (); std::pair next = *i; @@ -108,7 +108,7 @@ SchedulerMap::RemoveNext (void) } bool -SchedulerMap::Remove (const EventId &id) +MapScheduler::Remove (const EventId &id) { Scheduler::EventKey key; key.m_ts = id.GetTs (); diff --git a/src/simulator/scheduler-map.h b/src/simulator/map-scheduler.h similarity index 84% rename from src/simulator/scheduler-map.h rename to src/simulator/map-scheduler.h index 56e3587d0..cc49ecd34 100644 --- a/src/simulator/scheduler-map.h +++ b/src/simulator/map-scheduler.h @@ -30,10 +30,10 @@ namespace ns3 { class EventImpl; -class SchedulerMap : public Scheduler { +class MapScheduler : public Scheduler { public: - SchedulerMap (); - virtual ~SchedulerMap (); + MapScheduler (); + virtual ~MapScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; @@ -47,9 +47,9 @@ private: bool operator () (struct EventKey const&a, struct EventKey const&b); }; - typedef std::map EventMap; - typedef std::map::iterator EventMapI; - typedef std::map::const_iterator EventMapCI; + typedef std::map EventMap; + typedef std::map::iterator EventMapI; + typedef std::map::const_iterator EventMapCI; EventMap m_list; diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index d679790db..8fef4231c 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -274,6 +274,7 @@ TimeUnit operator * (TimeUnit const &lhs, TimeUnit const &rhs) template TimeUnit operator / (TimeUnit const &lhs, TimeUnit const &rhs) { + NS_ASSERT (rhs.GetHighPrecision ().GetDouble () != 0); HighPrecision retval = lhs.GetHighPrecision (); retval.Div (rhs.GetHighPrecision ()); return TimeUnit (retval); @@ -436,8 +437,6 @@ public: static uint64_t UnitsToTimestep (uint64_t unitValue, uint64_t unitFactor); - TimeUnit (Attribute value); - operator Attribute () const; private: HighPrecision m_data; @@ -669,6 +668,12 @@ typedef TimeUnit<0> Scalar; typedef TimeUnit<-1> TimeInvert; typedef TimeUnit<2> TimeSquare; +/** + * \class ns3::TimeValue + * \brief hold objects of type ns3::Time + */ + + ATTRIBUTE_ACCESSOR_DEFINE (Time); ATTRIBUTE_VALUE_DEFINE (Time); ATTRIBUTE_CHECKER_DEFINE (Time); diff --git a/src/simulator/scheduler.cc b/src/simulator/scheduler.cc index 8008772cd..0f4953836 100644 --- a/src/simulator/scheduler.cc +++ b/src/simulator/scheduler.cc @@ -29,7 +29,7 @@ Scheduler::~Scheduler () TypeId Scheduler::GetTypeId (void) { - static TypeId tid = TypeId ("Scheduler") + static TypeId tid = TypeId ("ns3::Scheduler") .SetParent () ; return tid; diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index aa2a0be93..fdd17154e 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -23,7 +23,9 @@ #include "event-impl.h" #include "ns3/ptr.h" +#include "ns3/pointer.h" #include "ns3/assert.h" +#include "ns3/log.h" #include @@ -48,7 +50,9 @@ std::cout << "SIMU TRACE " << x << std::endl; namespace ns3 { - +/** + * \brief private implementation detail of the Simulator API. + */ class SimulatorPrivate : public Object { public: @@ -99,19 +103,21 @@ private: int m_unscheduledEvents; }; +NS_OBJECT_ENSURE_REGISTERED (SimulatorPrivate); + TypeId SimulatorPrivate::GetTypeId (void) { - static TypeId tid = TypeId ("SimulatorPrivate") + static TypeId tid = TypeId ("ns3::SimulatorPrivate") .SetParent () .AddConstructor () .AddAttribute ("Scheduler", - "XXX", - Ptr (0), + "The Scheduler used to handle all simulation events.", + PointerValue (), // XXX: allow getting the scheduler too. - MakePtrAccessor (&SimulatorPrivate::SetScheduler), - MakePtrChecker ()) + MakePointerAccessor (&SimulatorPrivate::SetScheduler), + MakePointerChecker ()) ; return tid; } @@ -393,9 +399,7 @@ SimulatorPrivate::GetMaximumSimulationTime (void) const }; // namespace ns3 -#include "scheduler-list.h" -#include "scheduler-heap.h" -#include "scheduler-map.h" +#include "map-scheduler.h" namespace ns3 { @@ -411,14 +415,22 @@ void Simulator::EnableLogTo (char const *filename) GetPriv ()->EnableLogTo (filename); } +#ifdef NS3_LOG_ENABLE +static void +TimePrinter (std::ostream &os) +{ + os << Simulator::Now (); +} +#endif /* NS3_LOG_ENABLE */ Ptr Simulator::GetPriv (void) { if (m_priv == 0) { + LogRegisterTimePrinter (&TimePrinter); m_priv = CreateObject (); - Ptr scheduler = CreateObject (); + Ptr scheduler = CreateObject (); m_priv->SetScheduler (scheduler); } TRACE_S ("priv " << m_priv); @@ -564,6 +576,8 @@ Simulator::GetMaximumSimulationTime (void) #include "ns3/test.h" #include "ns3/ptr.h" +#include "list-scheduler.h" +#include "heap-scheduler.h" namespace ns3 { @@ -934,19 +948,19 @@ SimulatorTests::RunTests (void) bool result = true; Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; } Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; } Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; diff --git a/src/simulator/time.cc b/src/simulator/time.cc index 9474e417e..7dc3a8646 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -41,7 +41,7 @@ static uint64_t g_tsPrecFactor = NS_FACTOR; static GlobalValue g_precisionDefaultValue ("TimeStepPrecision", "The time unit of the internal 64 bit integer time.", - Enum (NS), + EnumValue (NS), MakeEnumChecker (NS, "NS", S, "S", MS, "MS", @@ -53,14 +53,15 @@ static GlobalValue g_precisionDefaultValue ("TimeStepPrecision", precision_t Get (void) { - Enum v = g_precisionDefaultValue.GetValue (); + EnumValue v; + g_precisionDefaultValue.GetValue (v); return (precision_t) v.Get (); } void Set (precision_t precision) { - g_precisionDefaultValue.SetValue (Enum (precision)); + g_precisionDefaultValue.SetValue (EnumValue (precision)); g_tsPrecFactor = (uint64_t)pow(10, precision); } @@ -230,7 +231,7 @@ std::istream& operator>> (std::istream& is, Time & time) is.setstate (std::ios_base::failbit); return is; } - std::string trailer = value.substr(n, value.size ()-1-n); + std::string trailer = value.substr(n, value.size ()-n); std::istringstream iss; iss.str (value.substr(0, n)); @@ -301,20 +302,6 @@ TimeUnit<1>::UnitsToTimestep (uint64_t unitValue, return unitValue; } -TimeUnit<1>::TimeUnit (Attribute value) -{ - const TimeValue *v = value.DynCast (); - if (v == 0) - { - NS_FATAL_ERROR ("Unexpected type of value. Expected \"TimeValue\""); - } - *this = v->Get (); -} -TimeUnit<1>::operator Attribute () const -{ - return Attribute::Create (*this); -} - ATTRIBUTE_VALUE_IMPLEMENT (Time); ATTRIBUTE_CHECKER_IMPLEMENT (Time); @@ -491,12 +478,12 @@ bool TimeTests::RunTests (void) TimeStepPrecision::Set (TimeStepPrecision::NS); - Config::SetGlobal ("TimeStepPrecision", String ("S")); - Config::SetGlobal ("TimeStepPrecision", String ("MS")); - Config::SetGlobal ("TimeStepPrecision", String ("US")); - Config::SetGlobal ("TimeStepPrecision", String ("NS")); - Config::SetGlobal ("TimeStepPrecision", String ("PS")); - Config::SetGlobal ("TimeStepPrecision", String ("FS")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("S")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("MS")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("US")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("NS")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("PS")); + Config::SetGlobal ("TimeStepPrecision", StringValue ("FS")); Time tooBig = TimeStep (0x8000000000000000LL); diff --git a/src/simulator/wscript b/src/simulator/wscript index 5d6963394..d41c5a356 100644 --- a/src/simulator/wscript +++ b/src/simulator/wscript @@ -53,9 +53,9 @@ def build(bld): 'time.cc', 'event-id.cc', 'scheduler.cc', - 'scheduler-list.cc', - 'scheduler-heap.cc', - 'scheduler-map.cc', + 'list-scheduler.cc', + 'map-scheduler.cc', + 'heap-scheduler.cc', 'event-impl.cc', 'simulator.cc', 'timer.cc', @@ -71,9 +71,9 @@ def build(bld): 'event-impl.h', 'simulator.h', 'scheduler.h', - 'scheduler-list.h', - 'scheduler-map.h', - 'scheduler-heap.h', + 'list-scheduler.h', + 'map-scheduler.h', + 'heap-scheduler.h', 'simulation-singleton.h', 'timer.h', 'timer-impl.h', diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index 246c8d516..04f4bae84 100644 --- a/tutorial/tutorial-bus-network.cc +++ b/tutorial/tutorial-bus-network.cc @@ -40,8 +40,8 @@ main (int argc, char *argv[]) internet.Install (n); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate(10000000)); - csma.SetChannelParameter ("Delay", MilliSeconds(20)); + csma.SetChannelParameter ("BitRate", StringValue ("10Mbps")); + csma.SetChannelParameter ("Delay", StringValue ("10ms")); NetDeviceContainer nd = csma.Install (n); Ipv4AddressHelper ipv4; @@ -51,9 +51,9 @@ main (int argc, char *argv[]) uint32_t port = 7; UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-csma-echo-ascii-trace.cc b/tutorial/tutorial-csma-echo-ascii-trace.cc index d5efb6c68..f4af8afb9 100644 --- a/tutorial/tutorial-csma-echo-ascii-trace.cc +++ b/tutorial/tutorial-csma-echo-ascii-trace.cc @@ -38,8 +38,8 @@ main (int argc, char *argv[]) internet.Install (n); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", StringValue ("5Mpbs")); + csma.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer nd = csma.Install (n); Ipv4AddressHelper ipv4; @@ -50,9 +50,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-csma-echo-pcap-trace.cc b/tutorial/tutorial-csma-echo-pcap-trace.cc index 2e7f87917..55c6c73fd 100644 --- a/tutorial/tutorial-csma-echo-pcap-trace.cc +++ b/tutorial/tutorial-csma-echo-pcap-trace.cc @@ -36,8 +36,8 @@ main (int argc, char *argv[]) internet.Install (n); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + csma.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer nd = csma.Install (n); Ipv4AddressHelper ipv4; @@ -48,9 +48,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("2s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-csma-echo.cc b/tutorial/tutorial-csma-echo.cc index 0f2aebdda..3e00efb5e 100644 --- a/tutorial/tutorial-csma-echo.cc +++ b/tutorial/tutorial-csma-echo.cc @@ -36,8 +36,8 @@ main (int argc, char *argv[]) internet.Install (n); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (5000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", StringValue ("5Mbps")); + csma.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer nd = csma.Install (n); Ipv4AddressHelper ipv4; @@ -48,9 +48,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-linear-dumbbell.cc b/tutorial/tutorial-linear-dumbbell.cc index 68c5ab2b8..860c036ef 100644 --- a/tutorial/tutorial-linear-dumbbell.cc +++ b/tutorial/tutorial-linear-dumbbell.cc @@ -53,8 +53,8 @@ main (int argc, char *argv[]) internet.Install (lan1); CsmaHelper csma; - csma.SetChannelParameter ("BitRate", DataRate (10000000)); - csma.SetChannelParameter ("Delay", MilliSeconds (2)); + csma.SetChannelParameter ("BitRate", StringValue ("10Mbps")); + csma.SetChannelParameter ("Delay", StringValue ("2ms")); NetDeviceContainer dev1 = csma.Install (lan1); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); @@ -78,8 +78,8 @@ main (int argc, char *argv[]) // NodeContainer backbone = NodeContainer (lan1.Get (3), lan2.Get (0)); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (38400)); - p2p.SetChannelParameter ("Delay", MilliSeconds (20)); + p2p.SetChannelParameter ("BitRate", StringValue ("38400bps")); + p2p.SetChannelParameter ("Delay", StringValue ("20ms")); NetDeviceContainer dev3 = p2p.Install (backbone); ipv4.SetBase ("10.1.3.0", "255.255.255.0"); ipv4.Assign (dev3); @@ -95,9 +95,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i2.GetAddress (0), port); - client.SetAppAttribute ("MaxPackets", Uinteger (100)); - client.SetAppAttribute ("Interval", Seconds (0.01)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (100)); + client.SetAppAttribute ("Interval", StringValue ("10ms")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (lan1.Get (0)); apps.Start (Seconds(2.)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-point-to-point.cc b/tutorial/tutorial-point-to-point.cc index 5c8913cf7..66d0fe5df 100644 --- a/tutorial/tutorial-point-to-point.cc +++ b/tutorial/tutorial-point-to-point.cc @@ -45,8 +45,8 @@ main (int argc, char *argv[]) internet.Install (n); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (38400)); - p2p.SetChannelParameter ("Delay", MilliSeconds (20)); + p2p.SetChannelParameter ("BitRate", StringValue ("38400bps")); + p2p.SetChannelParameter ("Delay", StringValue ("20ms")); NetDeviceContainer nd = p2p.Install (n); Ipv4AddressHelper ipv4; @@ -56,9 +56,9 @@ main (int argc, char *argv[]) uint16_t port = 7; UdpEchoClientHelper client; client.SetRemote (i.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc index ec7e6ceef..59399b569 100644 --- a/tutorial/tutorial-star-routing.cc +++ b/tutorial/tutorial-star-routing.cc @@ -56,8 +56,8 @@ main (int argc, char *argv[]) internet.Install (n); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (38400)); - p2p.SetChannelParameter ("Delay", MilliSeconds (20)); + p2p.SetChannelParameter ("BitRate", StringValue ("38400bps")); + p2p.SetChannelParameter ("Delay", StringValue ("20ms")); NetDeviceContainer d01 = p2p.Install (n01); NetDeviceContainer d02 = p2p.Install (n02); @@ -90,9 +90,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i01.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index 2f5b5721e..9c3f78c18 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -55,8 +55,8 @@ main (int argc, char *argv[]) internet.Install (n); PointToPointHelper p2p; - p2p.SetChannelParameter ("BitRate", DataRate (38400)); - p2p.SetChannelParameter ("Delay", MilliSeconds (20)); + p2p.SetChannelParameter ("BitRate", StringValue ("38400bps")); + p2p.SetChannelParameter ("Delay", StringValue ("20ms")); NetDeviceContainer d01 = p2p.Install (n01); NetDeviceContainer d02 = p2p.Install (n02); @@ -89,9 +89,9 @@ main (int argc, char *argv[]) UdpEchoClientHelper client; client.SetRemote (i01.GetAddress (1), port); - client.SetAppAttribute ("MaxPackets", Uinteger (1)); - client.SetAppAttribute ("Interval", Seconds (1.0)); - client.SetAppAttribute ("PacketSize", Uinteger (1024)); + client.SetAppAttribute ("MaxPackets", UintegerValue (1)); + client.SetAppAttribute ("Interval", StringValue ("1s")); + client.SetAppAttribute ("PacketSize", UintegerValue (1024)); apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); diff --git a/utils/bench-simulator.cc b/utils/bench-simulator.cc index 2bfdd686f..6b9eb2c2b 100644 --- a/utils/bench-simulator.cc +++ b/utils/bench-simulator.cc @@ -18,11 +18,8 @@ * Author: Mathieu Lacage */ -#include "ns3/simulator.h" -#include "ns3/scheduler-list.h" -#include "ns3/scheduler-map.h" -#include "ns3/scheduler-heap.h" -#include "ns3/system-wall-clock-ms.h" +#include "ns3/simulator-module.h" +#include "ns3/core-module.h" #include #include #include @@ -161,15 +158,15 @@ int main (int argc, char *argv[]) { if (strcmp ("--list", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--heap", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--map", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--debug", argv[0]) == 0) { diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index 4ec34ea9c..e76629571 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -1,8 +1,15 @@ #include #include "ns3/object.h" +#include "ns3/pointer.h" +#include "ns3/object-vector.h" +#include "ns3/config.h" +#include "ns3/log.h" +#include "ns3/helper-module.h" using namespace ns3; +NS_LOG_COMPONENT_DEFINE ("Main"); + void PrintAttributes (TypeId tid, std::ostream &os) { @@ -12,35 +19,237 @@ PrintAttributes (TypeId tid, std::ostream &os) os << "
  • " << tid.GetAttributeName (j) << ": " << tid.GetAttributeHelp (j) << std::endl; Ptr checker = tid.GetAttributeChecker (j); - os << "
      " << std::endl << "
    • Type: " << checker->GetType (); - if (checker->HasTypeConstraints ()) + os << "
        " << std::endl + << "
      • Set with class: \\ref " << checker->GetValueTypeName () << "
      • " << std::endl; + if (checker->HasUnderlyingTypeInformation ()) { - os << " -> " << checker->GetTypeConstraints (); + os << "
      • Underlying type: \\ref " << checker->GetUnderlyingTypeInformation () << "
      • " << std::endl; } - os << "" << std::endl; uint32_t flags = tid.GetAttributeFlags (j); - os << "
      • Flags: "; - if (flags & TypeId::ATTR_SET) + Ptr accessor = tid.GetAttributeAccessor (j); + if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ()) { - os << "write "; + Ptr initial = tid.GetAttributeInitialValue (j); + os << "
      • Initial value: " << initial->SerializeToString (checker) << "
      • " << std::endl; } - if (flags & TypeId::ATTR_GET) - { - os << "read "; - } - if (flags & TypeId::ATTR_CONSTRUCT) + os << "
      • Flags: "; + if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ()) { os << "construct "; } + if (flags & TypeId::ATTR_SET && accessor->HasSetter ()) + { + os << "write "; + } + if (flags & TypeId::ATTR_GET && accessor->HasGetter ()) + { + os << "read "; + } + os << "
      • " << std::endl; os << "
      " << std::endl; } os << "
    " << std::endl; } +void +PrintTraceSources (TypeId tid, std::ostream &os) +{ + os << "
      "<" << tid.GetTraceSourceName (i) << ": " + << tid.GetTraceSourceHelp (i) + << std::endl; + os << "" << std::endl; + } + os << "
    "< Get (TypeId tid); + +private: + std::string GetCurrentPath (void) const; + void DoGather (TypeId tid); + void RecordOutput (TypeId tid); + bool HasAlreadyBeenProcessed (TypeId tid) const; + std::vector > m_output; + std::vector m_currentPath; + std::vector m_alreadyProcessed; + std::vector > m_aggregates; +}; + +void +StaticInformation::RecordAggregationInfo (std::string a, std::string b) +{ + m_aggregates.push_back (std::make_pair (TypeId::LookupByName (a), TypeId::LookupByName (b))); +} + +void +StaticInformation::Print (void) const +{ + for (std::vector >::const_iterator i = m_output.begin (); i != m_output.end (); ++i) + { + std::pair item = *i; + std::cout << item.first.GetName () << " -> " << item.second << std::endl; + } +} + +std::string +StaticInformation::GetCurrentPath (void) const +{ + std::ostringstream oss; + for (std::vector::const_iterator i = m_currentPath.begin (); i != m_currentPath.end (); ++i) + { + std::string item = *i; + oss << "/" << item; + } + return oss.str (); +} + +void +StaticInformation::RecordOutput (TypeId tid) +{ + m_output.push_back (std::make_pair (tid, GetCurrentPath ())); +} + +bool +StaticInformation::HasAlreadyBeenProcessed (TypeId tid) const +{ + for (uint32_t i = 0; i < m_alreadyProcessed.size (); ++i) + { + if (m_alreadyProcessed[i] == tid) + { + return true; + } + } + return false; +} + +std::vector +StaticInformation::Get (TypeId tid) +{ + std::vector paths; + for (uint32_t i = 0; i < m_output.size (); ++i) + { + std::pair tmp = m_output[i]; + if (tmp.first == tid) + { + paths.push_back (tmp.second); + } + } + return paths; +} + +void +StaticInformation::Gather (TypeId tid) +{ + DoGather (tid); + + std::sort (m_output.begin (), m_output.end ()); + m_output.erase (std::unique (m_output.begin (), m_output.end ()), m_output.end ()); +} + +void +StaticInformation::DoGather (TypeId tid) +{ + NS_LOG_FUNCTION (this); + if (HasAlreadyBeenProcessed (tid)) + { + return; + } + RecordOutput (tid); + for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) + { + Ptr checker = tid.GetAttributeChecker (i); + const PointerChecker *ptrChecker = dynamic_cast (PeekPointer (checker)); + if (ptrChecker != 0) + { + TypeId pointee = ptrChecker->GetPointeeTypeId (); + m_currentPath.push_back (tid.GetAttributeName (i)); + m_alreadyProcessed.push_back (tid); + DoGather (pointee); + m_alreadyProcessed.pop_back (); + m_currentPath.pop_back (); + continue; + } + // attempt to cast to an object vector. + const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (checker)); + if (vectorChecker != 0) + { + TypeId item = vectorChecker->GetItemTypeId (); + m_currentPath.push_back (tid.GetAttributeName (i) + "/[i]"); + m_alreadyProcessed.push_back (tid); + DoGather (item); + m_alreadyProcessed.pop_back (); + m_currentPath.pop_back (); + continue; + } + } + for (uint32_t j = 0; j < TypeId::GetRegisteredN (); j++) + { + TypeId child = TypeId::GetRegistered (j); + if (child.IsChildOf (tid)) + { + m_currentPath.push_back ("$%" + child.GetName ()); + m_alreadyProcessed.push_back (tid); + DoGather (child); + m_alreadyProcessed.pop_back (); + m_currentPath.pop_back (); + } + } + for (uint32_t k = 0; k < m_aggregates.size (); ++k) + { + std::pair tmp = m_aggregates[k]; + if (tmp.first == tid || tmp.second == tid) + { + TypeId other; + if (tmp.first == tid) + { + other = tmp.second; + } + if (tmp.second == tid) + { + other = tmp.first; + } + // Note: we insert a % in the path below to ensure that doxygen does not + // attempt to resolve the typeid names included in the string. + m_currentPath.push_back ("$%" + other.GetName ()); + m_alreadyProcessed.push_back (tid); + DoGather (other); + m_alreadyProcessed.pop_back (); + m_currentPath.pop_back (); + } + } +} int main (int argc, char *argv[]) { + NodeContainer c; c.Create (1); + + StaticInformation info; + info.RecordAggregationInfo ("ns3::Node", "ns3::Tcp"); + info.RecordAggregationInfo ("ns3::Node", "ns3::Udp"); + info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory"); + info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::Agent"); + info.RecordAggregationInfo ("ns3::Node", "ns3::MobilityModel"); + info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L4Demux"); + info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L3Protocol"); + info.RecordAggregationInfo ("ns3::Node", "ns3::ArpL3Protocol"); + + for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i) + { + Ptr object = Config::GetRootNamespaceObject (i); + info.Gather (object->GetInstanceTypeId ()); + } for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++) { @@ -51,43 +260,111 @@ int main (int argc, char *argv[]) continue; } std::cout << "\\fn static TypeId " << tid.GetName () << "::GetTypeId (void)" << std::endl; - std::cout << "\\brief This method returns the TypeId associated to \\ref " << tid.GetName () << std::endl << std::endl; + std::cout << "\\brief This method returns the TypeId associated to \\ref " << tid.GetName () + << std::endl << std::endl; + std::vector paths = info.Get (tid); + if (!paths.empty ()) + { + std::cout << "This object is accessible through the following paths with Config::Set and Config::Connect:" + << std::endl; + std::cout << "
      " << std::endl; + for (uint32_t k = 0; k < paths.size (); ++k) + { + std::string path = paths[k]; + std::cout << "
    • " << path << "
    • " << std::endl; + } + std::cout << "
    " << std::endl; + } if (tid.GetAttributeN () == 0) { - std::cout << "No Attributes defined for this type." << std::endl; + std::cout << "No Attributes defined for this type.
    " << std::endl; } else { - std::cout << "Attributes defined for this type:" << std::endl; + std::cout << "Attributes defined for this type:
    " << std::endl; PrintAttributes (tid, std::cout); } - bool hasAttributesInParent = false; - TypeId tmp = tid.GetParent (); - while (tmp.GetParent () != tmp) + { + TypeId tmp = tid.GetParent (); + while (tmp.GetParent () != tmp) + { + if (tmp.GetAttributeN () != 0) + { + std::cout << "Attributes defined in parent class " << tmp.GetName () << ":
    " << std::endl; + PrintAttributes (tmp, std::cout); + } + tmp = tmp.GetParent (); + } + } + if (tid.GetTraceSourceN () == 0) { - if (tmp.GetAttributeN () != 0) - { - hasAttributesInParent = true; - } - tmp = tmp.GetParent (); + std::cout << "No TraceSources defined for this type.
    " << std::endl; } - if (hasAttributesInParent) + else { - std::cout << "Attributes defined in parent classes:
    " << std::endl; - tmp = tid.GetParent (); - while (tmp.GetParent () != tmp) - { - if (tmp.GetAttributeN () != 0) - { - std::cout << tmp.GetName () << std::endl; - PrintAttributes (tmp, std::cout); - } - tmp = tmp.GetParent (); - } + std::cout << "TraceSources defined for this type:
    " << std::endl; + PrintTraceSources (tid, std::cout); } + { + TypeId tmp = tid.GetParent (); + while (tmp.GetParent () != tmp) + { + if (tmp.GetTraceSourceN () != 0) + { + std::cout << "TraceSources defined in parent class " << tmp.GetName () << ":
    " << std::endl; + PrintTraceSources (tmp, std::cout); + } + tmp = tmp.GetParent (); + } + } std::cout << "*/" << std::endl; } + std::cout << "/*!" << std::endl + << "\\ingroup core" << std::endl + << "\\defgroup TraceSourceList The list of all trace sources." << std::endl; + for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) + { + TypeId tid = TypeId::GetRegistered (i); + if (tid.GetTraceSourceN () == 0 || + tid.MustHideFromDocumentation ()) + { + continue; + } + std::cout << "" << tid.GetName () << "
    " << std::endl + << "
      " << std::endl; + for (uint32_t j = 0; j < tid.GetTraceSourceN (); ++j) + { + std::cout << "
    • " << tid.GetTraceSourceName (j) << ": " << tid.GetTraceSourceHelp (j) << "
    • " << std::endl; + } + std::cout << "
    " << std::endl; + } + std::cout << "*/" << std::endl; + + + std::cout << "/*!" << std::endl + << "\\ingroup core" << std::endl + << "\\defgroup AttributeList The list of all attributes." << std::endl; + for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) + { + TypeId tid = TypeId::GetRegistered (i); + if (tid.GetAttributeN () == 0 || + tid.MustHideFromDocumentation ()) + { + continue; + } + std::cout << "" << tid.GetName () << "
    " << std::endl + << "
      " << std::endl; + for (uint32_t j = 0; j < tid.GetAttributeN (); ++j) + { + std::cout << "
    • " << tid.GetAttributeName (j) << ": " << tid.GetAttributeHelp (j) << "
    • " << std::endl; + } + std::cout << "
    " << std::endl; + } + std::cout << "*/" << std::endl; + + + return 0; } diff --git a/utils/replay-simulation.cc b/utils/replay-simulation.cc index 00fb6d1d3..1ce94dab9 100644 --- a/utils/replay-simulation.cc +++ b/utils/replay-simulation.cc @@ -18,12 +18,8 @@ * Author: Mathieu Lacage */ -#include "ns3/simulator.h" -#include "ns3/scheduler-list.h" -#include "ns3/scheduler-map.h" -#include "ns3/scheduler-heap.h" -#include "ns3/nstime.h" -#include "ns3/system-wall-clock-ms.h" +#include "ns3/simulator-module.h" +#include "ns3/core-module.h" #include #include #include @@ -317,15 +313,15 @@ int main (int argc, char *argv[]) { if (is_map) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (is_list) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (is_heap) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } log.Run (); Simulator::Destroy (); diff --git a/wscript b/wscript index 02682e459..b803d1381 100644 --- a/wscript +++ b/wscript @@ -340,9 +340,6 @@ def shutdown(): run_program(Params.g_options.run, get_command_template()) raise SystemExit(0) - if Params.g_options.command_template: - Params.fatal("Option --command-template requires the option --run to be given") - def _run_waf_check(): ## generate the trace sources list docs env = Params.g_build.env_of_name('default') @@ -755,9 +752,11 @@ def run_regression(): _dir = os.getcwd() os.chdir(REGRESSION_TRACES_DIR_NAME) try: - os.system("hg pull " + REGRESSION_TRACES_REPO + REGRESSION_TRACES_DIR_NAME + " > /dev/null 2>&1") + result = os.system("hg -q pull %s && hg -q update" % (REGRESSION_TRACES_REPO + REGRESSION_TRACES_DIR_NAME)) finally: os.chdir("..") + if result: + Params.fatal("Synchronizing reference traces using Mercurial failed.") else: print "Synchronizing reference traces from web." urllib.urlretrieve(REGRESSION_TRACES_URL + REGRESSION_TRACES_TAR_NAME, REGRESSION_TRACES_TAR_NAME)