A Discrete-Event Network Simulator
API
ns3::IidManager Class Reference

TypeId information manager. More...

+ Inheritance diagram for ns3::IidManager:
+ Collaboration diagram for ns3::IidManager:

Classes

struct  IidInformation
 The information record about a single type id. More...
 

Public Member Functions

void AddAttribute (uint16_t uid, std::string name, std::string help, uint32_t flags, Ptr< const AttributeValue > initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker, TypeId::SupportLevel supportLevel=TypeId::SUPPORTED, const std::string &supportMsg="")
 Record a new attribute in a type id. More...
 
void AddConstructor (uint16_t uid, Callback< ObjectBase * > callback)
 Add a constructor Callback to this type id. More...
 
void AddTraceSource (uint16_t uid, std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback, TypeId::SupportLevel supportLevel=TypeId::SUPPORTED, const std::string &supportMsg="")
 Record a new TraceSource. More...
 
uint16_t AllocateUid (std::string name)
 Create a new unique type id. More...
 
TypeId::AttributeInformation GetAttribute (uint16_t uid, std::size_t i) const
 Get Attribute information by index. More...
 
std::size_t GetAttributeN (uint16_t uid) const
 Get the number of attributes. More...
 
Callback< ObjectBase * > GetConstructor (uint16_t uid) const
 Get the constructor Callback of a type id. More...
 
std::string GetGroupName (uint16_t uid) const
 Get the group name of a type id. More...
 
TypeId::hash_t GetHash (uint16_t uid) const
 Get the hash of a type id. More...
 
std::string GetName (uint16_t uid) const
 Get the name of a type id. More...
 
uint16_t GetParent (uint16_t uid) const
 Get the parent of a type id. More...
 
uint16_t GetRegistered (uint16_t i) const
 Get a type id by index. More...
 
uint16_t GetRegisteredN () const
 Get the total number of type ids. More...
 
std::size_t GetSize (uint16_t uid) const
 Get the size of a type id. More...
 
TypeId::TraceSourceInformation GetTraceSource (uint16_t uid, std::size_t i) const
 Get the trace source by index. More...
 
std::size_t GetTraceSourceN (uint16_t uid) const
 Get the number of Trace sources. More...
 
uint16_t GetUid (std::string name) const
 Get a type id by name. More...
 
uint16_t GetUid (TypeId::hash_t hash) const
 Get a type id by hash value. More...
 
bool HasConstructor (uint16_t uid) const
 Check if a type id has a constructor Callback. More...
 
void HideFromDocumentation (uint16_t uid)
 Mark this type id to be excluded from documentation. More...
 
bool MustHideFromDocumentation (uint16_t uid) const
 Check if this TypeId should not be listed in documentation. More...
 
void SetAttributeInitialValue (uint16_t uid, std::size_t i, Ptr< const AttributeValue > initialValue)
 Set the initial value of an Attribute. More...
 
void SetGroupName (uint16_t uid, std::string groupName)
 Set the group name of a type id. More...
 
void SetParent (uint16_t uid, uint16_t parent)
 Set the parent of a type id. More...
 
void SetSize (uint16_t uid, std::size_t size)
 Set the size of the object class referred to by this id. More...
 
- Public Member Functions inherited from ns3::Singleton< IidManager >
 Singleton (const Singleton< IidManager > &)=delete
 
Singletonoperator= (const Singleton< IidManager > &)=delete
 

Private Types

enum  { HashChainFlag = 0x80000000 }
 IidManager constants. More...
 
typedef std::map< TypeId::hash_t, uint16_t > hashmap_t
 Type of the by-hash index. More...
 
typedef std::vector< IidInformation >::const_iterator Iterator
 Iterator type. More...
 
typedef std::map< std::string, uint16_t > namemap_t
 Type of the by-name index. More...
 

Private Member Functions

bool HasAttribute (uint16_t uid, std::string name)
 Check if a type id has a given Attribute. More...
 
bool HasTraceSource (uint16_t uid, std::string name)
 Check if a type id has a given TraceSource. More...
 
IidManager::IidInformationLookupInformation (uint16_t uid) const
 Retrieve the information record for a type. More...
 

Static Private Member Functions

static TypeId::hash_t Hasher (const std::string name)
 Hashing function. More...
 

Private Attributes

hashmap_t m_hashmap
 The by-hash index. More...
 
std::vector< IidInformationm_information
 The container of all type id records. More...
 
namemap_t m_namemap
 The by-name index. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ns3::Singleton< IidManager >
static IidManagerGet ()
 Get a pointer to the singleton instance. More...
 
- Protected Member Functions inherited from ns3::Singleton< IidManager >
 Singleton ()
 Constructor. More...
 
virtual ~Singleton ()
 Destructor. More...
 

Detailed Description

TypeId information manager.

Information records are stored in a vector. Name and hash lookup are performed by maps to the vector index.

Internal:
Hash Chaining

We require all types to produce distinct hashes. What if we encounter two types that produce the same hash value? As we move to a federated distribution model (the App store), it becomes increasingly likely that the core ns3 team won't discover this in test builds. Therefore, we need to handle this case explicitly.

Note, we expect this to be extremely rare. As of this writing we have ~400 < 2^9 types, so the probability of getting a collision when we introduce a new type is ~2^9/2^31 = 2^-22, assuming we reserve 31 bits for the hash, and one bit for chaining. Even with double the number of types the probability of having a collision is only 2 x 10^-4. The probability for a three-fold collision is 1 x 10^-10.

Therefore, we'll handle one collision explicitly by reserving the high order bit of the hash value, and assert on higher level collisions. The three-fold collision probability should be an acceptablly small error rate.

Definition at line 78 of file type-id.cc.

Member Typedef Documentation

◆ hashmap_t

typedef std::map<TypeId::hash_t, uint16_t> ns3::IidManager::hashmap_t
private

Type of the by-hash index.

Definition at line 343 of file type-id.cc.

◆ Iterator

typedef std::vector<IidInformation>::const_iterator ns3::IidManager::Iterator
private

Iterator type.

Definition at line 325 of file type-id.cc.

◆ namemap_t

typedef std::map<std::string, uint16_t> ns3::IidManager::namemap_t
private

Type of the by-name index.

Definition at line 338 of file type-id.cc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

IidManager constants.

Enumerator
HashChainFlag 

Hash chaining flag.

To handle the first collision, we reserve the high bit as a chain flag.

Definition at line 348 of file type-id.cc.

Member Function Documentation

◆ AddAttribute()

void ns3::IidManager::AddAttribute ( uint16_t  uid,
std::string  name,
std::string  help,
uint32_t  flags,
Ptr< const AttributeValue initialValue,
Ptr< const AttributeAccessor accessor,
Ptr< const AttributeChecker checker,
TypeId::SupportLevel  supportLevel = TypeId::SUPPORTED,
const std::string &  supportMsg = "" 
)

Record a new attribute in a type id.

Parameters
[in]uidThe id.
[in]nameThe name of the new attribute
[in]helpSome help text which describes the purpose of this attribute.
[in]flagsFlags which describe how this attribute can be read and/or written.
[in]initialValueThe initial value for this attribute.
[in]accessorAn instance of the associated AttributeAccessor subclass.
[in]checkerAn instance of the associated AttributeChecker subclass.
[in]supportLevelThe support/deprecation status for this attribute.
[in]supportMsgUpgrade hint if this attribute is no longer supported.

Definition at line 654 of file type-id.cc.

References ns3::TypeId::AttributeInformation::accessor, ns3::IidManager::IidInformation::attributes, ns3::TypeId::AttributeInformation::checker, ns3::TypeId::AttributeInformation::flags, HasAttribute(), ns3::TypeId::AttributeInformation::help, check-style-clang-format::help, IID, IIDL, ns3::TypeId::AttributeInformation::initialValue, LookupInformation(), ns3::IidManager::IidInformation::name, ns3::TypeId::AttributeInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::TypeId::AttributeInformation::originalInitialValue, ns3::TypeId::AttributeInformation::supportLevel, and ns3::TypeId::AttributeInformation::supportMsg.

Referenced by ns3::TypeId::AddAttribute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddConstructor()

void ns3::IidManager::AddConstructor ( uint16_t  uid,
Callback< ObjectBase * >  callback 
)

Add a constructor Callback to this type id.

Parameters
[in]uidThe id.
[in]callbackThe Callback for the constructor.

Definition at line 499 of file type-id.cc.

References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, IID, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::DoAddConstructor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddTraceSource()

void ns3::IidManager::AddTraceSource ( uint16_t  uid,
std::string  name,
std::string  help,
Ptr< const TraceSourceAccessor accessor,
std::string  callback,
TypeId::SupportLevel  supportLevel = TypeId::SUPPORTED,
const std::string &  supportMsg = "" 
)

Record a new TraceSource.

Parameters
[in]uidThe id.
[in]nameThe name of the new trace source
[in]helpSome help text which describes the purpose of this trace source.
[in]accessorA pointer to a TraceSourceAccessor which can be used to connect/disconnect sinks to this trace source.
[in]callbackFully qualified typedef name for the callback signature. Generally this should begin with the "ns3::" namespace qualifier.
[in]supportLevelThe support/deprecation status for this attribute.
[in]supportMsgUpgrade hint if this attribute is no longer supported.

Definition at line 753 of file type-id.cc.

References ns3::TypeId::TraceSourceInformation::accessor, ns3::TypeId::TraceSourceInformation::callback, HasTraceSource(), ns3::TypeId::TraceSourceInformation::help, check-style-clang-format::help, IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, ns3::TypeId::TraceSourceInformation::name, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::TypeId::TraceSourceInformation::supportLevel, ns3::TypeId::TraceSourceInformation::supportMsg, and ns3::IidManager::IidInformation::traceSources.

Referenced by ns3::TypeId::AddTraceSource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AllocateUid()

◆ GetAttribute()

TypeId::AttributeInformation ns3::IidManager::GetAttribute ( uint16_t  uid,
std::size_t  i 
) const

Get Attribute information by index.

Parameters
[in]uidThe id.
[in]iIndex into attribute array
Returns
The information associated to attribute whose index is i.

Definition at line 714 of file type-id.cc.

References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::GetAttribute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAttributeN()

std::size_t ns3::IidManager::GetAttributeN ( uint16_t  uid) const

Get the number of attributes.

Parameters
[in]uidThe id.
Returns
The number of attributes associated to this TypeId

Definition at line 704 of file type-id.cc.

References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::GetAttributeN().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetConstructor()

Callback< ObjectBase * > ns3::IidManager::GetConstructor ( uint16_t  uid) const

Get the constructor Callback of a type id.

Parameters
[in]uidThe id.
Returns
The constructor Callback of the type id.

Definition at line 588 of file type-id.cc.

References ns3::IidManager::IidInformation::constructor, ns3::IidManager::IidInformation::hasConstructor, IID, LookupInformation(), ns3::IidManager::IidInformation::name, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::GetConstructor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetGroupName()

std::string ns3::IidManager::GetGroupName ( uint16_t  uid) const

Get the group name of a type id.

Parameters
[in]uidThe id.
Returns
The group name of the type id.

Definition at line 569 of file type-id.cc.

References ns3::IidManager::IidInformation::groupName, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::GetGroupName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetHash()

TypeId::hash_t ns3::IidManager::GetHash ( uint16_t  uid) const

Get the hash of a type id.

Parameters
[in]uidThe id.
Returns
The hash of the type id.

Definition at line 549 of file type-id.cc.

References nlohmann::detail::hash(), ns3::IidManager::IidInformation::hash, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::GetHash().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetName()

std::string ns3::IidManager::GetName ( uint16_t  uid) const

Get the name of a type id.

Parameters
[in]uidThe id.
Returns
The name of the type id.

Definition at line 540 of file type-id.cc.

References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::GetName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetParent()

uint16_t ns3::IidManager::GetParent ( uint16_t  uid) const

Get the parent of a type id.

Parameters
[in]uidThe id.
Returns
The parent type id of the type id.

Definition at line 559 of file type-id.cc.

References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::parent.

Referenced by ns3::TypeId::GetParent(), and ns3::TypeId::HasParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRegistered()

uint16_t ns3::IidManager::GetRegistered ( uint16_t  i) const

Get a type id by index.

The type id value 0 indicates not registered, so there is an offset of 1 between the index and the type id value. This function converts from an index to the type id value.

Parameters
[in]iThe index.
Returns
The type id.

Definition at line 618 of file type-id.cc.

References IID, and NS_LOG_FUNCTION.

◆ GetRegisteredN()

uint16_t ns3::IidManager::GetRegisteredN ( ) const

Get the total number of type ids.

Returns
The total number.

Definition at line 611 of file type-id.cc.

References IID, m_information, and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::GetRegisteredN().

+ Here is the caller graph for this function:

◆ GetSize()

std::size_t ns3::IidManager::GetSize ( uint16_t  uid) const

Get the size of a type id.

Parameters
[in]uidThe id.
Returns
The size of the type id.

Definition at line 578 of file type-id.cc.

References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::size.

Referenced by ns3::TypeId::GetSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTraceSource()

TypeId::TraceSourceInformation ns3::IidManager::GetTraceSource ( uint16_t  uid,
std::size_t  i 
) const

Get the trace source by index.

Parameters
[in]uidThe id.
[in]iIndex into trace source array.
Returns
Detailed information about the requested trace source.

Definition at line 791 of file type-id.cc.

References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::name, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::traceSources.

Referenced by ns3::TypeId::GetTraceSource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTraceSourceN()

std::size_t ns3::IidManager::GetTraceSourceN ( uint16_t  uid) const

Get the number of Trace sources.

Parameters
[in]uidThe id.
Returns
The number of trace sources defined in this TypeId.

Definition at line 781 of file type-id.cc.

References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::traceSources.

Referenced by ns3::TypeId::GetTraceSourceN().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetUid() [1/2]

uint16_t ns3::IidManager::GetUid ( std::string  name) const

Get a type id by name.

Parameters
[in]nameThe type id to find.
Returns
The type id. A type id of 0 means name wasn't found.

Definition at line 512 of file type-id.cc.

References IID, IIDL, m_namemap, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by AllocateUid(), ns3::TypeId::LookupByHash(), ns3::TypeId::LookupByHashFailSafe(), ns3::TypeId::LookupByName(), and ns3::TypeId::LookupByNameFailSafe().

+ Here is the caller graph for this function:

◆ GetUid() [2/2]

uint16_t ns3::IidManager::GetUid ( TypeId::hash_t  hash) const

Get a type id by hash value.

Parameters
[in]hashThe type id to find.
Returns
The type id. A type id of 0 means hash wasn't found.

Definition at line 526 of file type-id.cc.

References nlohmann::detail::hash(), IID, IIDL, m_hashmap, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

+ Here is the call graph for this function:

◆ HasAttribute()

bool ns3::IidManager::HasAttribute ( uint16_t  uid,
std::string  name 
)
private

Check if a type id has a given Attribute.

Parameters
[in]uidThe id.
[in]nameThe Attribute name.
Returns
true if uid has the Attribute name.

Definition at line 625 of file type-id.cc.

References ns3::IidManager::IidInformation::attributes, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::IidManager::IidInformation::parent.

Referenced by AddAttribute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasConstructor()

bool ns3::IidManager::HasConstructor ( uint16_t  uid) const

Check if a type id has a constructor Callback.

Parameters
[in]uidThe id.
Returns
true if the type id has a constructor Callback.

Definition at line 601 of file type-id.cc.

References ns3::IidManager::IidInformation::hasConstructor, IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::HasConstructor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Hasher()

TypeId::hash_t ns3::IidManager::Hasher ( const std::string  name)
staticprivate

Hashing function.

Parameters
[in]nameThe type id name.
Returns
The hashed value of name.

Definition at line 362 of file type-id.cc.

References ns3::Hasher::clear(), and ns3::Hasher::GetHash32().

Referenced by AllocateUid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasTraceSource()

bool ns3::IidManager::HasTraceSource ( uint16_t  uid,
std::string  name 
)
private

Check if a type id has a given TraceSource.

Parameters
[in]uidThe id.
[in]nameThe TraceSource name.
Returns
true if uid has the TraceSource name.

Definition at line 724 of file type-id.cc.

References IID, IIDL, LookupInformation(), NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::IidManager::IidInformation::parent, and ns3::IidManager::IidInformation::traceSources.

Referenced by AddTraceSource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HideFromDocumentation()

void ns3::IidManager::HideFromDocumentation ( uint16_t  uid)

Mark this type id to be excluded from documentation.

Parameters
[in]uidThe id.

Definition at line 491 of file type-id.cc.

References IID, LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::HideFromDocumentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LookupInformation()

IidManager::IidInformation * ns3::IidManager::LookupInformation ( uint16_t  uid) const
private

◆ MustHideFromDocumentation()

bool ns3::IidManager::MustHideFromDocumentation ( uint16_t  uid) const

Check if this TypeId should not be listed in documentation.

Parameters
[in]uidThe id.
Returns
true if this TypeId should be hidden from the user.

Definition at line 801 of file type-id.cc.

References IID, IIDL, LookupInformation(), ns3::IidManager::IidInformation::mustHideFromDocumentation, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::TypeId::MustHideFromDocumentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAttributeInitialValue()

void ns3::IidManager::SetAttributeInitialValue ( uint16_t  uid,
std::size_t  i,
Ptr< const AttributeValue initialValue 
)

Set the initial value of an Attribute.

Parameters
[in]uidThe id.
[in]iThe attribute to manipulate
[in]initialValueThe new initial value to use for this attribute.

Definition at line 693 of file type-id.cc.

References ns3::IidManager::IidInformation::attributes, IID, LookupInformation(), NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::SetAttributeInitialValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetGroupName()

void ns3::IidManager::SetGroupName ( uint16_t  uid,
std::string  groupName 
)

Set the group name of a type id.

Parameters
[in]uidThe id.
[in]groupNameThe group name.

Definition at line 475 of file type-id.cc.

References ns3::IidManager::IidInformation::groupName, IID, LookupInformation(), and NS_LOG_FUNCTION.

Referenced by ns3::TypeId::SetGroupName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetParent()

void ns3::IidManager::SetParent ( uint16_t  uid,
uint16_t  parent 
)

Set the parent of a type id.

Parameters
[in]uidThe id.
[in]parentThe id of the parent.

Definition at line 466 of file type-id.cc.

References IID, LookupInformation(), m_information, NS_ASSERT, NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::parent.

Referenced by ns3::TypeId::SetParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSize()

void ns3::IidManager::SetSize ( uint16_t  uid,
std::size_t  size 
)

Set the size of the object class referred to by this id.

Parameters
[in]uidThe id.
[in]sizeThe object size.

Definition at line 483 of file type-id.cc.

References IID, LookupInformation(), NS_LOG_FUNCTION, and ns3::IidManager::IidInformation::size.

Referenced by ns3::TypeId::SetSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_hashmap

hashmap_t ns3::IidManager::m_hashmap
private

The by-hash index.

Definition at line 345 of file type-id.cc.

Referenced by AllocateUid(), and GetUid().

◆ m_information

std::vector<IidInformation> ns3::IidManager::m_information
private

The container of all type id records.

Definition at line 335 of file type-id.cc.

Referenced by AllocateUid(), GetRegisteredN(), LookupInformation(), and SetParent().

◆ m_namemap

namemap_t ns3::IidManager::m_namemap
private

The by-name index.

Definition at line 340 of file type-id.cc.

Referenced by AllocateUid(), and GetUid().


The documentation for this class was generated from the following file: