diff --git a/src/core/model/config.cc b/src/core/model/config.cc --- a/src/core/model/config.cc +++ b/src/core/model/config.cc @@ -776,6 +776,32 @@ return Singleton::Get ()->GetRootNamespaceObject (i); } +std::string GetDefault (const std::string attributePath) +{ + NS_LOG_FUNCTION (attributePath); + // Attribute name is last token + size_t colon = attributePath.rfind ("::"); + const std::string typeName = attributePath.substr (0, colon); + NS_LOG_DEBUG ("typeName: '" << typeName << "', colon: " << colon); + + TypeId tid; + if (!TypeId::LookupByNameFailSafe (typeName, &tid)) + { + NS_FATAL_ERROR ("Unknown type=" << typeName); + } + + const std::string attrName = attributePath.substr (colon + 2); + struct TypeId::AttributeInformation info; + if (!tid.LookupAttributeByName (attrName, &info)) + { + NS_FATAL_ERROR ("Attribute not found: " << attributePath); + } + + std::string defValue = info.initialValue->SerializeToString (info.checker); + + return defValue; +} + } // namespace Config } // namespace ns3 diff --git a/src/core/model/config.h b/src/core/model/config.h --- a/src/core/model/config.h +++ b/src/core/model/config.h @@ -247,6 +247,18 @@ */ Ptr GetRootNamespaceObject (uint32_t i); +/** + * Get the current default value for an attribute. + * + * The current default is the initial value which would be + * used by new instances of the type, including any + * CommandLine configuration. + * + * \param attributePath The configuration path for the attribute. + * \returns The default value, serialized to a string. + */ + std::string GetDefault (const std::string attributePath); + } // namespace Config } // namespace ns3