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 fdda66c49..45fb3bab3 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 d0a4f4457..a7d989b0f 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 f7db8ea9b..1d7446ff3 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 2b5153f8b..0722b7578 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 cb28e8855..87e3833b1 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,9 +163,9 @@ 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)); + "Bounds", RectangleValue (Rectangle (0, 1000, 0, 1000)), + "Speed", RandomVariableValue (ConstantVariable (2000)), + "Pause", RandomVariableValue (ConstantVariable (0.2))); mobility.Layout (backbone); /////////////////////////////////////////////////////////////////////////// @@ -194,8 +194,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 nodes in our container @@ -269,9 +269,9 @@ 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)); + "Bounds", RectangleValue (Rectangle (-25, 25, -25, 25)), + "Speed", RandomVariableValue (ConstantVariable (30)), + "Pause", RandomVariableValue (ConstantVariable (0.4))); mobility.Layout (infra); } /////////////////////////////////////////////////////////////////////////// @@ -304,8 +304,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 5d4b5f34c..88209a727 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 249523391..fb9e262d1 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 36c91f2f4..88644376e 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 4c85d605a..3a07d7dcd 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 5c7f27e6a..27a81006e 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 d568e38c4..49475ae0c 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 cc5a4e9b3..12bac5241 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 914439601..fe8608074 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 9c4a3617e..a49713624 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 022f02c6b..8d9676732 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.Layout (c); diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 6a536d5fb..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")); + "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 5542b9bb9..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", 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 a26085c65..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 ()) ; 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 6ae38a86d..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 ()) ; 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/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 9de7a838b..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 ()) ; @@ -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 ()) ; 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 17f1b55ee..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 @@ -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/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 bdde3f165..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 @@ -141,6 +181,7 @@ private: friend Ptr CopyObject (Ptr object); friend class ObjectFactory; + friend class AggregateIterator; Ptr DoGetObject (TypeId tid) const; bool Check (void) const; @@ -247,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 ()); @@ -339,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 bdefcf8ee..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 ()) ; diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 25f65e6f5..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.", 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 85886c63a..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 ()) ; 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 adb6e8f6f..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.", 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 9cf6707a6..9eee9cb9d 100644 --- a/src/devices/wifi/dca-txop.cc +++ b/src/devices/wifi/dca-txop.cc @@ -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 ()) diff --git a/src/devices/wifi/ideal-wifi-manager.cc b/src/devices/wifi/ideal-wifi-manager.cc index 2d8e42acc..235d887af 100644 --- a/src/devices/wifi/ideal-wifi-manager.cc +++ b/src/devices/wifi/ideal-wifi-manager.cc @@ -35,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 ()) ; diff --git a/src/devices/wifi/jakes-propagation-loss-model.cc b/src/devices/wifi/jakes-propagation-loss-model.cc index 079e334a8..12d549fe2 100644 --- a/src/devices/wifi/jakes-propagation-loss-model.cc +++ b/src/devices/wifi/jakes-propagation-loss-model.cc @@ -131,22 +131,22 @@ JakesPropagationLossModel::GetTypeId (void) .AddConstructor () .AddAttribute ("NumberOfRaysPerPath", "The number of rays to use by default for compute the fading coeficent for a given path (default is 1)", - Uinteger (1), + UintegerValue (1), MakeUintegerAccessor (&JakesPropagationLossModel::m_nRays), MakeUintegerChecker ()) .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/nqap-wifi-mac.cc b/src/devices/wifi/nqap-wifi-mac.cc index 930ccef04..e156d2f3b 100644 --- a/src/devices/wifi/nqap-wifi-mac.cc +++ b/src/devices/wifi/nqap-wifi-mac.cc @@ -44,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 ()) diff --git a/src/devices/wifi/nqsta-wifi-mac.cc b/src/devices/wifi/nqsta-wifi-mac.cc index 0cd151dd2..100908fb3 100644 --- a/src/devices/wifi/nqsta-wifi-mac.cc +++ b/src/devices/wifi/nqsta-wifi-mac.cc @@ -63,21 +63,21 @@ NqstaWifiMac::GetTypeId (void) .SetParent () .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 ()) ; 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-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 1fac496c9..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")) 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/helper/csma-helper.cc b/src/helper/csma-helper.cc index 7efa559ba..246581a5f 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 e83d98c82..4214eb86e 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/mobility-helper.cc b/src/helper/mobility-helper.cc index 94ade79c7..a4a23811f 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::Layout (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 8f4543325..e1f9edb64 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 fd9ee396d..2024b1717 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 4176608d1..2bc54086e 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 261c8fce6..edff703c4 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/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index d99e68969..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 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 5c6e4aa05..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; } 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/rtt-estimator.cc b/src/internet-node/rtt-estimator.cc index 2a2594894..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 ()) ; @@ -178,7 +178,7 @@ RttMeanDeviation::GetTypeId (void) .AddConstructor () .AddAttribute ("Gain", "XXX", - Double (0.1), + DoubleValue (0.1), MakeDoubleAccessor (&RttMeanDeviation::gain), MakeDoubleChecker ()) ; diff --git a/src/internet-node/tcp-l4-protocol.cc b/src/internet-node/tcp-l4-protocol.cc index c7fdccbd1..653575db0 100644 --- a/src/internet-node/tcp-l4-protocol.cc +++ b/src/internet-node/tcp-l4-protocol.cc @@ -325,7 +325,7 @@ TcpL4Protocol::GetTypeId (void) .SetParent () .AddAttribute ("RttEstimatorFactory", "How RttEstimator objects are created.", - GetDefaultRttEstimatorFactory (), + ObjectFactoryValue (GetDefaultRttEstimatorFactory ()), MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), MakeObjectFactoryChecker ()) ; diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 945268b27..ac52efd2d 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -1161,7 +1161,7 @@ void TcpSocket::ReTxTimeout () // 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 } 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 d05f45143..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 ()) ; 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 957f21e01..3db5f1c8d 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -166,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/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 3af0b5ccf..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 ()) ; @@ -129,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.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 08e3b6f3f..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; } 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/queue.cc b/src/node/queue.cc index d4d5c0323..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; 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/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 614bf5dff..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.", diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index 10a1e5169..8fef4231c 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -437,8 +437,6 @@ public: static uint64_t UnitsToTimestep (uint64_t unitValue, uint64_t unitFactor); - TimeUnit (Attribute value); - operator Attribute () const; private: HighPrecision m_data; @@ -670,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 4628a9310..fdd17154e 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -23,6 +23,7 @@ #include "event-impl.h" #include "ns3/ptr.h" +#include "ns3/pointer.h" #include "ns3/assert.h" #include "ns3/log.h" @@ -49,6 +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; } 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/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index 814b58245..297b94d34 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 03606c677..512bf7377 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 4db6f500c..2c87f36c9 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 c5b56cb66..a4ec55c32 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 a71d20052..ea04405d5 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 71a8582e6..94da53614 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 573e78b2c..8a99a9a6b 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/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; }