A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
type-id.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#include "type-id.h"
20
21#include "hash.h"
22#include "log.h" // NS_ASSERT and NS_LOG
23#include "singleton.h"
25
26#include <iomanip>
27#include <map>
28#include <sstream>
29#include <vector>
30
31/**
32 * \file
33 * \ingroup object
34 * ns3::TypeId and ns3::IidManager implementations.
35 */
36
37/*********************************************************************
38 * Helper code
39 *********************************************************************/
40
41namespace ns3
42{
43
45
46// IidManager needs to be in ns3 namespace for NS_ASSERT and NS_LOG
47// to find g_log
48
49/**
50 * \ingroup object
51 * \brief TypeId information manager
52 *
53 * Information records are stored in a vector. Name and hash lookup
54 * are performed by maps to the vector index.
55 *
56 * \internal
57 * <b>Hash Chaining</b>
58 *
59 * We require all types to produce distinct hashes. What if we encounter
60 * two types that produce the same hash value? As we move to a
61 * federated distribution model (the App store), it becomes increasingly
62 * likely that the core ns3 team *won't* discover this in test builds.
63 * Therefore, we need to handle this case explicitly.
64 *
65 * Note, we expect this to be *extremely* rare. As of this writing we
66 * have ~400 < 2^9 types, so the probability of getting a collision
67 * when we introduce a new type is ~2^9/2^31 = 2^-22, assuming we
68 * reserve 31 bits for the hash, and one bit for chaining. Even with
69 * double the number of types the probability of having a collision
70 * is only 2 x 10^-4. The probability for a three-fold collision is
71 * 1 x 10^-10.
72 *
73 * Therefore, we'll handle one collision explicitly by reserving
74 * the high order bit of the hash value, and assert on higher level
75 * collisions. The three-fold collision probability should be an
76 * acceptablly small error rate.
77 */
78class IidManager : public Singleton<IidManager>
79{
80 public:
81 /**
82 * Create a new unique type id.
83 * \param [in] name The name of this type id.
84 * \returns The id.
85 */
86 uint16_t AllocateUid(std::string name);
87 /**
88 * Set the parent of a type id.
89 * \param [in] uid The id.
90 * \param [in] parent The id of the parent.
91 */
92 void SetParent(uint16_t uid, uint16_t parent);
93 /**
94 * Set the group name of a type id.
95 * \param [in] uid The id.
96 * \param [in] groupName The group name.
97 */
98 void SetGroupName(uint16_t uid, std::string groupName);
99 /**
100 * Set the size of the object class referred to by this id.
101 * \param [in] uid The id.
102 * \param [in] size The object size.
103 */
104 void SetSize(uint16_t uid, std::size_t size);
105 /**
106 * Add a constructor Callback to this type id.
107 * \param [in] uid The id.
108 * \param [in] callback The Callback for the constructor.
109 */
110 void AddConstructor(uint16_t uid, Callback<ObjectBase*> callback);
111 /**
112 * Mark this type id to be excluded from documentation.
113 * \param [in] uid The id.
114 */
115 void HideFromDocumentation(uint16_t uid);
116 /**
117 * Get a type id by name.
118 * \param [in] name The type id to find.
119 * \returns The type id. A type id of 0 means \pname{name} wasn't found.
120 */
121 uint16_t GetUid(std::string name) const;
122 /**
123 * Get a type id by hash value.
124 * \param [in] hash The type id to find.
125 * \returns The type id. A type id of 0 means \pname{hash} wasn't found.
126 */
127 uint16_t GetUid(TypeId::hash_t hash) const;
128 /**
129 * Get the name of a type id.
130 * \param [in] uid The id.
131 * \returns The name of the type id.
132 */
133 std::string GetName(uint16_t uid) const;
134 /**
135 * Get the hash of a type id.
136 * \param [in] uid The id.
137 * \returns The hash of the type id.
138 */
139 TypeId::hash_t GetHash(uint16_t uid) const;
140 /**
141 * Get the parent of a type id.
142 * \param [in] uid The id.
143 * \returns The parent type id of the type id.
144 */
145 uint16_t GetParent(uint16_t uid) const;
146 /**
147 * Get the group name of a type id.
148 * \param [in] uid The id.
149 * \returns The group name of the type id.
150 */
151 std::string GetGroupName(uint16_t uid) const;
152 /**
153 * Get the size of a type id.
154 * \param [in] uid The id.
155 * \returns The size of the type id.
156 */
157 std::size_t GetSize(uint16_t uid) const;
158 /**
159 * Get the constructor Callback of a type id.
160 * \param [in] uid The id.
161 * \returns The constructor Callback of the type id.
162 */
163 Callback<ObjectBase*> GetConstructor(uint16_t uid) const;
164 /**
165 * Check if a type id has a constructor Callback.
166 * \param [in] uid The id.
167 * \returns \c true if the type id has a constructor Callback.
168 */
169 bool HasConstructor(uint16_t uid) const;
170 /**
171 * Get the total number of type ids.
172 * \returns The total number.
173 */
174 uint16_t GetRegisteredN() const;
175 /**
176 * Get a type id by index.
177 *
178 * The type id value 0 indicates not registered, so there is an offset
179 * of 1 between the index and the type id value. This function converts
180 * from an index to the type id value.
181 * \param [in] i The index.
182 * \returns The type id.
183 */
184 uint16_t GetRegistered(uint16_t i) const;
185 /**
186 * Record a new attribute in a type id.
187 * \param [in] uid The id.
188 * \param [in] name The name of the new attribute
189 * \param [in] help Some help text which describes the purpose of this
190 * attribute.
191 * \param [in] flags Flags which describe how this attribute can be
192 * read and/or written.
193 * \param [in] initialValue The initial value for this attribute.
194 * \param [in] accessor An instance of the associated AttributeAccessor
195 * subclass.
196 * \param [in] checker An instance of the associated AttributeChecker
197 * subclass.
198 * \param [in] supportLevel The support/deprecation status for this attribute.
199 * \param [in] supportMsg Upgrade hint if this attribute is no longer supported.
200 */
201 void AddAttribute(uint16_t uid,
202 std::string name,
203 std::string help,
204 uint32_t flags,
205 Ptr<const AttributeValue> initialValue,
209 const std::string& supportMsg = "");
210 /**
211 * Set the initial value of an Attribute.
212 * \param [in] uid The id.
213 * \param [in] i The attribute to manipulate
214 * \param [in] initialValue The new initial value to use for this attribute.
215 */
216 void SetAttributeInitialValue(uint16_t uid,
217 std::size_t i,
218 Ptr<const AttributeValue> initialValue);
219 /**
220 * Get the number of attributes.
221 * \param [in] uid The id.
222 * \returns The number of attributes associated to this TypeId
223 */
224 std::size_t GetAttributeN(uint16_t uid) const;
225 /**
226 * Get Attribute information by index.
227 * \param [in] uid The id.
228 * \param [in] i Index into attribute array
229 * \returns The information associated to attribute whose index is \pname{i}.
230 */
231 TypeId::AttributeInformation GetAttribute(uint16_t uid, std::size_t i) const;
232 /**
233 * Record a new TraceSource.
234 * \param [in] uid The id.
235 * \param [in] name The name of the new trace source
236 * \param [in] help Some help text which describes the purpose of this
237 * trace source.
238 * \param [in] accessor A pointer to a TraceSourceAccessor which can be
239 * used to connect/disconnect sinks to this trace source.
240 * \param [in] callback Fully qualified typedef name for the callback
241 * signature. Generally this should begin with the
242 * "ns3::" namespace qualifier.
243 * \param [in] supportLevel The support/deprecation status for this attribute.
244 * \param [in] supportMsg Upgrade hint if this attribute is no longer supported.
245 */
246 void AddTraceSource(uint16_t uid,
247 std::string name,
248 std::string help,
250 std::string callback,
252 const std::string& supportMsg = "");
253 /**
254 * Get the number of Trace sources.
255 * \param [in] uid The id.
256 * \returns The number of trace sources defined in this TypeId.
257 */
258 std::size_t GetTraceSourceN(uint16_t uid) const;
259 /**
260 * Get the trace source by index.
261 * \param [in] uid The id.
262 * \param [in] i Index into trace source array.
263 * \returns Detailed information about the requested trace source.
264 */
265 TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, std::size_t i) const;
266 /**
267 * Check if this TypeId should not be listed in documentation.
268 * \param [in] uid The id.
269 * \returns \c true if this TypeId should be hidden from the user.
270 */
271 bool MustHideFromDocumentation(uint16_t uid) const;
272
273 private:
274 /**
275 * Check if a type id has a given TraceSource.
276 * \param [in] uid The id.
277 * \param [in] name The TraceSource name.
278 * \returns \c true if \pname{uid} has the TraceSource \pname{name}.
279 */
280 bool HasTraceSource(uint16_t uid, std::string name);
281 /**
282 * Check if a type id has a given Attribute.
283 * \param [in] uid The id.
284 * \param [in] name The Attribute name.
285 * \returns \c true if \pname{uid} has the Attribute \pname{name}.
286 */
287 bool HasAttribute(uint16_t uid, std::string name);
288 /**
289 * Hashing function.
290 * \param [in] name The type id name.
291 * \returns The hashed value of \pname{name}.
292 */
293 static TypeId::hash_t Hasher(const std::string name);
294
295 /** The information record about a single type id. */
297 {
298 /** The type id name. */
299 std::string name;
300 /** The type id hash value. */
302 /** The parent type id. */
303 uint16_t parent;
304 /** The group name. */
305 std::string groupName;
306 /** The size of the object represented by this type id. */
307 std::size_t size;
308 /** \c true if a constructor Callback has been registered. */
310 /** The constructor Callback. */
312 /** \c true if this type should be omitted from documentation. */
314 /** The container of Attributes. */
315 std::vector<TypeId::AttributeInformation> attributes;
316 /** The container of TraceSources. */
317 std::vector<TypeId::TraceSourceInformation> traceSources;
318 /** Support level/deprecation. */
320 /** Support message. */
321 std::string supportMsg;
322 };
323
324 /** Iterator type. */
325 typedef std::vector<IidInformation>::const_iterator Iterator;
326
327 /**
328 * Retrieve the information record for a type.
329 * \param [in] uid The id.
330 * \returns The information record.
331 */
333
334 /** The container of all type id records. */
335 std::vector<IidInformation> m_information;
336
337 /** Type of the by-name index. */
338 typedef std::map<std::string, uint16_t> namemap_t;
339 /** The by-name index. */
341
342 /** Type of the by-hash index. */
343 typedef std::map<TypeId::hash_t, uint16_t> hashmap_t;
344 /** The by-hash index. */
346
347 /** IidManager constants. */
348 enum
349 {
350 /**
351 * Hash chaining flag.
352 *
353 * To handle the first collision, we reserve the high bit as a
354 * chain flag.
355 */
356 HashChainFlag = 0x80000000
357 };
358};
359
360// static
362IidManager::Hasher(const std::string name)
363{
364 static ns3::Hasher hasher(Create<Hash::Function::Murmur3>());
365 return hasher.clear().GetHash32(name);
366}
367
368/**
369 * \ingroup object
370 * \internal
371 * IidManager shorthand for use in NS_LOG
372 */
373#define IID "IidManager"
374/**
375 * \ingroup object
376 * \internal
377 * IidManager shorthand for use in NS_LOG
378 */
379#define IIDL IID << ": "
380
381uint16_t
382IidManager::AllocateUid(std::string name)
383{
384 NS_LOG_FUNCTION(IID << name);
385 // Type names are definitive: equal names are equal types
386 NS_ABORT_MSG_UNLESS(m_namemap.count(name) == 0,
387 "Trying to allocate twice the same uid: " << name);
388
389 TypeId::hash_t hash = Hasher(name) & (~HashChainFlag);
390 if (m_hashmap.count(hash) == 1)
391 {
392 NS_LOG_ERROR("Hash chaining TypeId for '"
393 << name << "'. "
394 << "This is not a bug, but is extremely unlikely. "
395 << "Please contact the ns3 developers.");
396 // ns3 developer contacted about this message:
397 // You have four options (in order of difficulty):
398 // 1. Let it ride, and play the odds that a third collision
399 // never appears.
400 // 2. Change the name of the new (or old) tag, even trivially, to
401 // remove the collision.
402 // 3. Switch to 64-bit hashes.
403 // 4. Implement 2-bit (or higher) chaining.
404 //
405 // Oh, by the way, I owe you a beer, since I bet Mathieu that
406 // this would never happen.. -- Peter Barnes, LLNL
407
408 NS_ASSERT_MSG(m_hashmap.count(hash | HashChainFlag) == 0,
409 "Triplicate hash detected while chaining TypeId for '"
410 << name << "'. Please contact the ns3 developers for assistance.");
411 // ns3 developer contacted about this message:
412 // You have three options: #2-4 above.
413 //
414 // Oh, by the way, I have no idea how this crazy hashing idea got
415 // into ns3. -- Peter Barnes, LLNL
416
417 // Alphabetize the two types, so it's deterministic
419 if (name > hinfo->name)
420 { // new type gets chained
421 NS_LOG_LOGIC(IIDL << "New TypeId '" << name << "' getting chained.");
422 hash = hash | HashChainFlag;
423 }
424 else
425 { // chain old type
426 NS_LOG_LOGIC(IIDL << "Old TypeId '" << hinfo->name << "' getting chained.");
427 uint16_t oldUid = GetUid(hinfo->hash);
428 m_hashmap.erase(m_hashmap.find(hinfo->hash));
429 hinfo->hash = hash | HashChainFlag;
430 m_hashmap.insert(std::make_pair(hinfo->hash, oldUid));
431 // leave new hash unchained
432 }
433 }
434
435 IidInformation information;
436 information.name = name;
437 information.hash = hash;
438 information.parent = 0;
439 information.groupName = "";
440 information.size = (std::size_t)(-1);
441 information.hasConstructor = false;
442 information.mustHideFromDocumentation = false;
443 information.supportLevel = TypeId::SUPPORTED;
444 m_information.push_back(information);
445 std::size_t tuid = m_information.size();
446 NS_ASSERT(tuid <= 0xffff);
447 auto uid = static_cast<uint16_t>(tuid);
448
449 // Add to both maps:
450 m_namemap.insert(std::make_pair(name, uid));
451 m_hashmap.insert(std::make_pair(hash, uid));
452 NS_LOG_LOGIC(IIDL << uid);
453 return uid;
454}
455
458{
459 NS_LOG_FUNCTION(IID << uid);
460 NS_ASSERT_MSG(uid <= m_information.size() && uid != 0,
461 "The uid " << uid << " for this TypeId is invalid");
462 NS_LOG_LOGIC(IIDL << m_information[uid - 1].name);
463 return const_cast<IidInformation*>(&m_information[uid - 1]);
464}
465
466void
467IidManager::SetParent(uint16_t uid, uint16_t parent)
468{
469 NS_LOG_FUNCTION(IID << uid << parent);
470 NS_ASSERT(parent <= m_information.size());
471 IidInformation* information = LookupInformation(uid);
472 information->parent = parent;
473}
474
475void
476IidManager::SetGroupName(uint16_t uid, std::string groupName)
477{
478 NS_LOG_FUNCTION(IID << uid << groupName);
479 IidInformation* information = LookupInformation(uid);
480 information->groupName = groupName;
481}
482
483void
484IidManager::SetSize(uint16_t uid, std::size_t size)
485{
486 NS_LOG_FUNCTION(IID << uid << size);
487 IidInformation* information = LookupInformation(uid);
488 information->size = size;
489}
490
491void
493{
494 NS_LOG_FUNCTION(IID << uid);
495 IidInformation* information = LookupInformation(uid);
496 information->mustHideFromDocumentation = true;
497}
498
499void
501{
502 NS_LOG_FUNCTION(IID << uid << &callback);
503 IidInformation* information = LookupInformation(uid);
504 if (information->hasConstructor)
505 {
506 NS_FATAL_ERROR(information->name << " already has a constructor.");
507 }
508 information->hasConstructor = true;
509 information->constructor = callback;
510}
511
512uint16_t
513IidManager::GetUid(std::string name) const
514{
515 NS_LOG_FUNCTION(IID << name);
516 uint16_t uid = 0;
517 auto it = m_namemap.find(name);
518 if (it != m_namemap.end())
519 {
520 uid = it->second;
521 }
522 NS_LOG_LOGIC(IIDL << uid);
523 return uid;
524}
525
526uint16_t
528{
529 NS_LOG_FUNCTION(IID << hash);
530 auto it = m_hashmap.find(hash);
531 uint16_t uid = 0;
532 if (it != m_hashmap.end())
533 {
534 uid = it->second;
535 }
536 NS_LOG_LOGIC(IIDL << uid);
537 return uid;
538}
539
540std::string
541IidManager::GetName(uint16_t uid) const
542{
543 NS_LOG_FUNCTION(IID << uid);
544 IidInformation* information = LookupInformation(uid);
545 NS_LOG_LOGIC(IIDL << information->name);
546 return information->name;
547}
548
550IidManager::GetHash(uint16_t uid) const
551{
552 NS_LOG_FUNCTION(IID << uid);
553 IidInformation* information = LookupInformation(uid);
554 TypeId::hash_t hash = information->hash;
555 NS_LOG_LOGIC(IIDL << hash);
556 return hash;
557}
558
559uint16_t
560IidManager::GetParent(uint16_t uid) const
561{
562 NS_LOG_FUNCTION(IID << uid);
563 IidInformation* information = LookupInformation(uid);
564 uint16_t pid = information->parent;
565 NS_LOG_LOGIC(IIDL << pid);
566 return pid;
567}
568
569std::string
570IidManager::GetGroupName(uint16_t uid) const
571{
572 NS_LOG_FUNCTION(IID << uid);
573 IidInformation* information = LookupInformation(uid);
574 NS_LOG_LOGIC(IIDL << information->groupName);
575 return information->groupName;
576}
577
578std::size_t
579IidManager::GetSize(uint16_t uid) const
580{
581 NS_LOG_FUNCTION(IID << uid);
582 IidInformation* information = LookupInformation(uid);
583 std::size_t size = information->size;
584 NS_LOG_LOGIC(IIDL << size);
585 return size;
586}
587
589IidManager::GetConstructor(uint16_t uid) const
590{
591 NS_LOG_FUNCTION(IID << uid);
592 IidInformation* information = LookupInformation(uid);
593 if (!information->hasConstructor)
594 {
595 NS_FATAL_ERROR("Requested constructor for " << information->name
596 << " but it does not have one.");
597 }
598 return information->constructor;
599}
600
601bool
602IidManager::HasConstructor(uint16_t uid) const
603{
604 NS_LOG_FUNCTION(IID << uid);
605 IidInformation* information = LookupInformation(uid);
606 bool hasC = information->hasConstructor;
607 NS_LOG_LOGIC(IIDL << hasC);
608 return hasC;
609}
610
611uint16_t
613{
615 return static_cast<uint16_t>(m_information.size());
616}
617
618uint16_t
620{
621 NS_LOG_FUNCTION(IID << i);
622 return i + 1;
623}
624
625bool
626IidManager::HasAttribute(uint16_t uid, std::string name)
627{
628 NS_LOG_FUNCTION(IID << uid << name);
629 IidInformation* information = LookupInformation(uid);
630 while (true)
631 {
632 for (auto i = information->attributes.begin(); i != information->attributes.end(); ++i)
633 {
634 if (i->name == name)
635 {
636 NS_LOG_LOGIC(IIDL << true);
637 return true;
638 }
639 }
640 IidInformation* parent = LookupInformation(information->parent);
641 if (parent == information)
642 {
643 // top of inheritance tree
644 NS_LOG_LOGIC(IIDL << false);
645 return false;
646 }
647 // check parent
648 information = parent;
649 }
650 NS_LOG_LOGIC(IIDL << false);
651 return false;
652}
653
654void
656 std::string name,
657 std::string help,
658 uint32_t flags,
659 Ptr<const AttributeValue> initialValue,
662 TypeId::SupportLevel supportLevel,
663 const std::string& supportMsg)
664{
665 NS_LOG_FUNCTION(IID << uid << name << help << flags << initialValue << accessor << checker
666 << supportLevel << supportMsg);
667 IidInformation* information = LookupInformation(uid);
668 if (name.find(' ') != std::string::npos)
669 {
670 NS_FATAL_ERROR("Attribute name \"" << name << "\" may not contain spaces ' ', "
671 << "encountered when registering TypeId \""
672 << information->name << "\"");
673 }
674 if (HasAttribute(uid, name))
675 {
676 NS_FATAL_ERROR("Attribute \"" << name << "\" already registered on tid=\""
677 << information->name << "\"");
678 }
680 info.name = name;
681 info.help = help;
682 info.flags = flags;
683 info.initialValue = initialValue;
684 info.originalInitialValue = initialValue;
685 info.accessor = accessor;
686 info.checker = checker;
687 info.supportLevel = supportLevel;
688 info.supportMsg = supportMsg;
689 information->attributes.push_back(info);
690 NS_LOG_LOGIC(IIDL << information->attributes.size() - 1);
691}
692
693void
695 std::size_t i,
696 Ptr<const AttributeValue> initialValue)
697{
698 NS_LOG_FUNCTION(IID << uid << i << initialValue);
699 IidInformation* information = LookupInformation(uid);
700 NS_ASSERT(i < information->attributes.size());
701 information->attributes[i].initialValue = initialValue;
702}
703
704std::size_t
705IidManager::GetAttributeN(uint16_t uid) const
706{
707 NS_LOG_FUNCTION(IID << uid);
708 IidInformation* information = LookupInformation(uid);
709 std::size_t size = information->attributes.size();
710 NS_LOG_LOGIC(IIDL << size);
711 return size;
712}
713
715IidManager::GetAttribute(uint16_t uid, std::size_t i) const
716{
717 NS_LOG_FUNCTION(IID << uid << i);
718 IidInformation* information = LookupInformation(uid);
719 NS_ASSERT(i < information->attributes.size());
720 NS_LOG_LOGIC(IIDL << information->name);
721 return information->attributes[i];
722}
723
724bool
725IidManager::HasTraceSource(uint16_t uid, std::string name)
726{
727 NS_LOG_FUNCTION(IID << uid << name);
728 IidInformation* information = LookupInformation(uid);
729 while (true)
730 {
731 for (auto i = information->traceSources.begin(); i != information->traceSources.end(); ++i)
732 {
733 if (i->name == name)
734 {
735 NS_LOG_LOGIC(IIDL << true);
736 return true;
737 }
738 }
739 IidInformation* parent = LookupInformation(information->parent);
740 if (parent == information)
741 {
742 // top of inheritance tree
743 NS_LOG_LOGIC(IIDL << false);
744 return false;
745 }
746 // check parent
747 information = parent;
748 }
749 NS_LOG_LOGIC(IIDL << false);
750 return false;
751}
752
753void
755 std::string name,
756 std::string help,
758 std::string callback,
759 TypeId::SupportLevel supportLevel,
760 const std::string& supportMsg)
761{
762 NS_LOG_FUNCTION(IID << uid << name << help << accessor << callback << supportLevel
763 << supportMsg);
764 IidInformation* information = LookupInformation(uid);
765 if (HasTraceSource(uid, name))
766 {
767 NS_FATAL_ERROR("Trace source \"" << name << "\" already registered on tid=\""
768 << information->name << "\"");
769 }
771 source.name = name;
772 source.help = help;
773 source.accessor = accessor;
774 source.callback = callback;
775 source.supportLevel = supportLevel;
776 source.supportMsg = supportMsg;
777 information->traceSources.push_back(source);
778 NS_LOG_LOGIC(IIDL << information->traceSources.size() - 1);
779}
780
781std::size_t
783{
784 NS_LOG_FUNCTION(IID << uid);
785 IidInformation* information = LookupInformation(uid);
786 std::size_t size = information->traceSources.size();
787 NS_LOG_LOGIC(IIDL << size);
788 return size;
789}
790
792IidManager::GetTraceSource(uint16_t uid, std::size_t i) const
793{
794 NS_LOG_FUNCTION(IID << uid << i);
795 IidInformation* information = LookupInformation(uid);
796 NS_ASSERT(i < information->traceSources.size());
797 NS_LOG_LOGIC(IIDL << information->name);
798 return information->traceSources[i];
799}
800
801bool
803{
804 NS_LOG_FUNCTION(IID << uid);
805 IidInformation* information = LookupInformation(uid);
806 bool hide = information->mustHideFromDocumentation;
807 NS_LOG_LOGIC(IIDL << hide);
808 return hide;
809}
810
811} // namespace ns3
812
813namespace ns3
814{
815
816/*********************************************************************
817 * The TypeId class
818 *********************************************************************/
819
820TypeId::TypeId(const std::string& name)
821{
822 NS_LOG_FUNCTION(this << name);
823 uint16_t uid = IidManager::Get()->AllocateUid(name);
824 NS_LOG_LOGIC(uid);
825 NS_ASSERT(uid != 0);
826 m_tid = uid;
827}
828
829TypeId::TypeId(uint16_t tid)
830 : m_tid(tid)
831{
832 NS_LOG_FUNCTION(this << tid);
833}
834
835TypeId
836TypeId::LookupByName(std::string name)
837{
838 NS_LOG_FUNCTION(name);
839 uint16_t uid = IidManager::Get()->GetUid(name);
840 NS_ASSERT_MSG(uid != 0, "Assert in TypeId::LookupByName: " << name << " not found");
841 return TypeId(uid);
842}
843
844bool
846{
847 NS_LOG_FUNCTION(name << tid->GetUid());
848 uint16_t uid = IidManager::Get()->GetUid(name);
849 if (uid == 0)
850 {
851 return false;
852 }
853 *tid = TypeId(uid);
854 return true;
855}
856
857TypeId
859{
860 uint16_t uid = IidManager::Get()->GetUid(hash);
861 NS_ASSERT_MSG(uid != 0,
862 "Assert in TypeId::LookupByHash: 0x" << std::hex << hash << std::dec
863 << " not found");
864 return TypeId(uid);
865}
866
867bool
869{
870 uint16_t uid = IidManager::Get()->GetUid(hash);
871 if (uid == 0)
872 {
873 return false;
874 }
875 *tid = TypeId(uid);
876 return true;
877}
878
879uint16_t
881{
884}
885
886TypeId
888{
891}
892
893bool
895{
896 NS_LOG_FUNCTION(this << name << info);
897 TypeId tid;
898 TypeId nextTid = *this;
899 do
900 {
901 tid = nextTid;
902 for (std::size_t i = 0; i < tid.GetAttributeN(); i++)
903 {
905 if (tmp.name == name)
906 {
908 {
909 *info = tmp;
910 return true;
911 }
912 else if (tmp.supportLevel == TypeId::DEPRECATED)
913 {
914 std::cerr << "Attribute '" << name << "' is deprecated: " << tmp.supportMsg
915 << std::endl;
916 *info = tmp;
917 return true;
918 }
919 else if (tmp.supportLevel == TypeId::OBSOLETE)
920 {
921 NS_FATAL_ERROR("Attribute '" << name << "' is obsolete, with no fallback: "
922 << tmp.supportMsg);
923 }
924 }
925 }
926 nextTid = tid.GetParent();
927 } while (nextTid != tid);
928 return false;
929}
930
931TypeId
933{
934 NS_LOG_FUNCTION(this << tid.GetUid());
936 return *this;
937}
938
939TypeId
940TypeId::SetGroupName(std::string groupName)
941{
942 NS_LOG_FUNCTION(this << groupName);
943 IidManager::Get()->SetGroupName(m_tid, groupName);
944 return *this;
945}
946
947TypeId
948TypeId::SetSize(std::size_t size)
949{
950 NS_LOG_FUNCTION(this << size);
951 IidManager::Get()->SetSize(m_tid, size);
952 return *this;
953}
954
955TypeId
957{
958 NS_LOG_FUNCTION(this);
959 uint16_t parent = IidManager::Get()->GetParent(m_tid);
960 return TypeId(parent);
961}
962
963bool
965{
966 NS_LOG_FUNCTION(this);
967 uint16_t parent = IidManager::Get()->GetParent(m_tid);
968 return parent != m_tid;
969}
970
971bool
973{
974 NS_LOG_FUNCTION(this << other.GetUid());
975 TypeId tmp = *this;
976 while (tmp != other && tmp != tmp.GetParent())
977 {
978 tmp = tmp.GetParent();
979 }
980 return tmp == other && *this != other;
981}
982
983std::string
985{
986 NS_LOG_FUNCTION(this);
987 std::string groupName = IidManager::Get()->GetGroupName(m_tid);
988 return groupName;
989}
990
991std::string
993{
994 NS_LOG_FUNCTION(this);
995 std::string name = IidManager::Get()->GetName(m_tid);
996 return name;
997}
998
1001{
1003 return hash;
1004}
1005
1006std::size_t
1008{
1009 NS_LOG_FUNCTION(this);
1010 std::size_t size = IidManager::Get()->GetSize(m_tid);
1011 return size;
1012}
1013
1014bool
1016{
1017 NS_LOG_FUNCTION(this);
1018 bool hasConstructor = IidManager::Get()->HasConstructor(m_tid);
1019 return hasConstructor;
1020}
1021
1022void
1024{
1025 NS_LOG_FUNCTION(this << &cb);
1027}
1028
1029TypeId
1030TypeId::AddAttribute(std::string name,
1031 std::string help,
1032 const AttributeValue& initialValue,
1035 SupportLevel supportLevel,
1036 const std::string& supportMsg)
1037{
1038 NS_LOG_FUNCTION(this << name << help << &initialValue << accessor << checker << supportLevel
1039 << supportMsg);
1041 name,
1042 help,
1043 ATTR_SGC,
1044 initialValue.Copy(),
1045 accessor,
1046 checker,
1047 supportLevel,
1048 supportMsg);
1049 return *this;
1050}
1051
1052TypeId
1053TypeId::AddAttribute(std::string name,
1054 std::string help,
1055 uint32_t flags,
1056 const AttributeValue& initialValue,
1059 SupportLevel supportLevel,
1060 const std::string& supportMsg)
1061{
1062 NS_LOG_FUNCTION(this << name << help << flags << &initialValue << accessor << checker
1063 << supportLevel << supportMsg);
1065 name,
1066 help,
1067 flags,
1068 initialValue.Copy(),
1069 accessor,
1070 checker,
1071 supportLevel,
1072 supportMsg);
1073 return *this;
1074}
1075
1076bool
1078{
1079 NS_LOG_FUNCTION(this << i << initialValue);
1080 IidManager::Get()->SetAttributeInitialValue(m_tid, i, initialValue);
1081 return true;
1082}
1083
1086{
1087 NS_LOG_FUNCTION(this);
1089 return cb;
1090}
1091
1092bool
1094{
1095 NS_LOG_FUNCTION(this);
1097 return mustHide;
1098}
1099
1100std::size_t
1102{
1103 NS_LOG_FUNCTION(this);
1104 std::size_t n = IidManager::Get()->GetAttributeN(m_tid);
1105 return n;
1106}
1107
1109TypeId::GetAttribute(std::size_t i) const
1110{
1111 NS_LOG_FUNCTION(this << i);
1112 return IidManager::Get()->GetAttribute(m_tid, i);
1113}
1114
1115std::string
1117{
1118 NS_LOG_FUNCTION(this << i);
1120 return GetName() + "::" + info.name;
1121}
1122
1123std::size_t
1125{
1126 NS_LOG_FUNCTION(this);
1128}
1129
1131TypeId::GetTraceSource(std::size_t i) const
1132{
1133 NS_LOG_FUNCTION(this << i);
1134 return IidManager::Get()->GetTraceSource(m_tid, i);
1135}
1136
1137TypeId
1138TypeId::AddTraceSource(std::string name,
1139 std::string help,
1141 std::string callback,
1142 SupportLevel supportLevel,
1143 const std::string& supportMsg)
1144{
1145 NS_LOG_FUNCTION(this << name << help << accessor << callback << supportLevel << supportMsg);
1147 ->AddTraceSource(m_tid, name, help, accessor, callback, supportLevel, supportMsg);
1148 return *this;
1149}
1150
1151TypeId
1153{
1154 NS_LOG_FUNCTION(this);
1156 return *this;
1157}
1158
1161{
1162 NS_LOG_FUNCTION(this << name);
1163 TypeId tid;
1164 TypeId nextTid = *this;
1166 do
1167 {
1168 tid = nextTid;
1169 for (std::size_t i = 0; i < tid.GetTraceSourceN(); i++)
1170 {
1171 tmp = tid.GetTraceSource(i);
1172 if (tmp.name == name)
1173 {
1175 {
1176 *info = tmp;
1177 return tmp.accessor;
1178 }
1179 else if (tmp.supportLevel == TypeId::DEPRECATED)
1180 {
1181 std::cerr << "TraceSource '" << name << "' is deprecated: " << tmp.supportMsg
1182 << std::endl;
1183 *info = tmp;
1184 return tmp.accessor;
1185 }
1186 else if (tmp.supportLevel == TypeId::OBSOLETE)
1187 {
1188 NS_FATAL_ERROR("TraceSource '" << name << "' is obsolete, with no fallback: "
1189 << tmp.supportMsg);
1190 }
1191 }
1192 }
1193 nextTid = tid.GetParent();
1194 } while (nextTid != tid);
1195 return nullptr;
1196}
1197
1199TypeId::LookupTraceSourceByName(std::string name) const
1200{
1202 return LookupTraceSourceByName(name, &info);
1203}
1204
1205uint16_t
1207{
1208 NS_LOG_FUNCTION(this);
1209 return m_tid;
1210}
1211
1212void
1213TypeId::SetUid(uint16_t uid)
1214{
1215 NS_LOG_FUNCTION(this << uid);
1216 m_tid = uid;
1217}
1218
1219/**
1220 * \brief Insertion operator for TypeId
1221 * \param [in] os the output stream
1222 * \param [in] tid the TypeId
1223 * \returns the updated output stream.
1224 */
1225std::ostream&
1226operator<<(std::ostream& os, TypeId tid)
1227{
1228 os << tid.GetName();
1229 return os;
1230}
1231
1232/**
1233 * \brief Extraction operator for TypeId
1234 * \param [in] is the input stream
1235 * \param [out] tid the TypeId value
1236 * \returns the updated input stream.
1237 */
1238std::istream&
1239operator>>(std::istream& is, TypeId& tid)
1240{
1241 std::string tidString;
1242 is >> tidString;
1243 bool ok = TypeId::LookupByNameFailSafe(tidString, &tid);
1244 if (!ok)
1245 {
1246 is.setstate(std::ios_base::badbit);
1247 }
1248 return is;
1249}
1250
1252
1253bool
1255{
1256 return a.m_tid < b.m_tid;
1257}
1258
1259} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
virtual Ptr< AttributeValue > Copy() const =0
Callback template class.
Definition: callback.h:438
Generic Hash function interface.
Definition: hash.h:87
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
Definition: hash.h:236
Hasher & clear()
Restore initial state.
Definition: hash.cc:56
TypeId information manager.
Definition: type-id.cc:79
@ HashChainFlag
Hash chaining flag.
Definition: type-id.cc:356
TypeId::hash_t GetHash(uint16_t uid) const
Get the hash of a type id.
Definition: type-id.cc:550
std::map< TypeId::hash_t, uint16_t > hashmap_t
Type of the by-hash index.
Definition: type-id.cc:343
std::vector< IidInformation >::const_iterator Iterator
Iterator type.
Definition: type-id.cc:325
uint16_t GetRegisteredN() const
Get the total number of type ids.
Definition: type-id.cc:612
uint16_t GetParent(uint16_t uid) const
Get the parent of a type id.
Definition: type-id.cc:560
std::map< std::string, uint16_t > namemap_t
Type of the by-name index.
Definition: type-id.cc:338
void SetAttributeInitialValue(uint16_t uid, std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:694
void SetGroupName(uint16_t uid, std::string groupName)
Set the group name of a type id.
Definition: type-id.cc:476
void SetParent(uint16_t uid, uint16_t parent)
Set the parent of a type id.
Definition: type-id.cc:467
std::vector< IidInformation > m_information
The container of all type id records.
Definition: type-id.cc:335
void SetSize(uint16_t uid, std::size_t size)
Set the size of the object class referred to by this id.
Definition: type-id.cc:484
std::string GetGroupName(uint16_t uid) const
Get the group name of a type id.
Definition: type-id.cc:570
bool HasTraceSource(uint16_t uid, std::string name)
Check if a type id has a given TraceSource.
Definition: type-id.cc:725
uint16_t GetRegistered(uint16_t i) const
Get a type id by index.
Definition: type-id.cc:619
Callback< ObjectBase * > GetConstructor(uint16_t uid) const
Get the constructor Callback of a type id.
Definition: type-id.cc:589
std::size_t GetAttributeN(uint16_t uid) const
Get the number of attributes.
Definition: type-id.cc:705
uint16_t GetUid(std::string name) const
Get a type id by name.
Definition: type-id.cc:513
void AddConstructor(uint16_t uid, Callback< ObjectBase * > callback)
Add a constructor Callback to this type id.
Definition: type-id.cc:500
void HideFromDocumentation(uint16_t uid)
Mark this type id to be excluded from documentation.
Definition: type-id.cc:492
std::string GetName(uint16_t uid) const
Get the name of a type id.
Definition: type-id.cc:541
std::size_t GetTraceSourceN(uint16_t uid) const
Get the number of Trace sources.
Definition: type-id.cc:782
std::size_t GetSize(uint16_t uid) const
Get the size of a type id.
Definition: type-id.cc:579
TypeId::TraceSourceInformation GetTraceSource(uint16_t uid, std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:792
bool MustHideFromDocumentation(uint16_t uid) const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:802
IidManager::IidInformation * LookupInformation(uint16_t uid) const
Retrieve the information record for a type.
Definition: type-id.cc:457
bool HasConstructor(uint16_t uid) const
Check if a type id has a constructor Callback.
Definition: type-id.cc:602
bool HasAttribute(uint16_t uid, std::string name)
Check if a type id has a given Attribute.
Definition: type-id.cc:626
static TypeId::hash_t Hasher(const std::string name)
Hashing function.
Definition: type-id.cc:362
hashmap_t m_hashmap
The by-hash index.
Definition: type-id.cc:345
uint16_t AllocateUid(std::string name)
Create a new unique type id.
Definition: type-id.cc:382
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.
Definition: type-id.cc:655
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.
Definition: type-id.cc:754
TypeId::AttributeInformation GetAttribute(uint16_t uid, std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:715
namemap_t m_namemap
The by-name index.
Definition: type-id.cc:340
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template singleton.
Definition: singleton.h:68
static IidManager * Get()
Get a pointer to the singleton instance.
Definition: singleton.h:107
a unique identifier for an interface.
Definition: type-id.h:59
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition: type-id.cc:972
std::size_t GetTraceSourceN() const
Get the number of Trace sources.
Definition: type-id.cc:1124
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1077
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:836
bool HasParent() const
Check if this TypeId has a parent.
Definition: type-id.cc:964
TypeId SetSize(std::size_t size)
Set the size of this type.
Definition: type-id.cc:948
hash_t GetHash() const
Get the hash.
Definition: type-id.cc:1000
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor, std::string callback, SupportLevel supportLevel=SUPPORTED, const std::string &supportMsg="")
Record a new TraceSource.
Definition: type-id.cc:1138
bool MustHideFromDocumentation() const
Check if this TypeId should not be listed in documentation.
Definition: type-id.cc:1093
@ ATTR_SGC
The attribute can be read, and written at any time.
Definition: type-id.h:67
static bool LookupByHashFailSafe(hash_t hash, TypeId *tid)
Get a TypeId by hash.
Definition: type-id.cc:868
TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition: type-id.cc:1131
std::string GetGroupName() const
Get the group name.
Definition: type-id.cc:984
TypeId HideFromDocumentation()
Hide this TypeId from documentation.
Definition: type-id.cc:1152
Callback< ObjectBase * > GetConstructor() const
Get the constructor callback.
Definition: type-id.cc:1085
static uint16_t GetRegisteredN()
Get the number of registered TypeIds.
Definition: type-id.cc:880
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1116
bool HasConstructor() const
Check if this TypeId has a constructor.
Definition: type-id.cc:1015
std::size_t GetAttributeN() const
Get the number of attributes.
Definition: type-id.cc:1101
TypeId GetParent() const
Get the parent of this TypeId.
Definition: type-id.cc:956
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
Definition: type-id.cc:1213
uint16_t m_tid
The TypeId value.
Definition: type-id.h:565
TypeId SetGroupName(std::string groupName)
Set the group name.
Definition: type-id.cc:940
static TypeId LookupByHash(hash_t hash)
Get a TypeId by hash.
Definition: type-id.cc:858
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:887
std::size_t GetSize() const
Get the size of this object.
Definition: type-id.cc:1007
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
Find a TraceSource by name.
Definition: type-id.cc:1199
uint32_t hash_t
Type of hash values.
Definition: type-id.h:120
TypeId()
Default constructor.
Definition: type-id.h:605
TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1109
uint16_t GetUid() const
Get the internal id of this TypeId.
Definition: type-id.cc:1206
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:845
SupportLevel
The level of support or deprecation for attributes or trace sources.
Definition: type-id.h:73
@ SUPPORTED
Attribute or trace source is currently used.
Definition: type-id.h:74
@ OBSOLETE
Attribute or trace source is not used anymore; simulation fails.
Definition: type-id.h:76
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:75
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker, SupportLevel supportLevel=SUPPORTED, const std::string &supportMsg="")
Record in this TypeId the fact that a new attribute exists.
Definition: type-id.cc:1030
bool LookupAttributeByName(std::string name, AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:894
std::string GetName() const
Get the name.
Definition: type-id.cc:992
TypeId SetParent()
Set the parent TypeId.
Definition: type-id.h:644
void DoAddConstructor(Callback< ObjectBase * > callback)
Implementation for AddConstructor().
Definition: type-id.cc:1023
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define IIDL
Definition: type-id.cc:379
#define IID
Definition: type-id.cc:373
ns3::Hasher, ns3::Hash32() and ns3::Hash64() function declarations.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
ns3::Singleton declaration and template implementation.
The information record about a single type id.
Definition: type-id.cc:297
std::string groupName
The group name.
Definition: type-id.cc:305
uint16_t parent
The parent type id.
Definition: type-id.cc:303
std::vector< TypeId::TraceSourceInformation > traceSources
The container of TraceSources.
Definition: type-id.cc:317
std::size_t size
The size of the object represented by this type id.
Definition: type-id.cc:307
std::string supportMsg
Support message.
Definition: type-id.cc:321
std::string name
The type id name.
Definition: type-id.cc:299
std::vector< TypeId::AttributeInformation > attributes
The container of Attributes.
Definition: type-id.cc:315
Callback< ObjectBase * > constructor
The constructor Callback.
Definition: type-id.cc:311
bool hasConstructor
true if a constructor Callback has been registered.
Definition: type-id.cc:309
bool mustHideFromDocumentation
true if this type should be omitted from documentation.
Definition: type-id.cc:313
TypeId::hash_t hash
The type id hash value.
Definition: type-id.cc:301
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.cc:319
Attribute implementation.
Definition: type-id.h:81
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:89
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:97
std::string name
Attribute name.
Definition: type-id.h:83
Ptr< const AttributeAccessor > accessor
Accessor object.
Definition: type-id.h:93
uint32_t flags
AttributeFlags value.
Definition: type-id.h:87
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:95
std::string supportMsg
Support message.
Definition: type-id.h:99
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:91
std::string help
Attribute help string.
Definition: type-id.h:85
TraceSource implementation.
Definition: type-id.h:104
std::string name
Trace name.
Definition: type-id.h:106
std::string supportMsg
Support message.
Definition: type-id.h:116
std::string help
Trace help string.
Definition: type-id.h:108
Ptr< const TraceSourceAccessor > accessor
Trace accessor.
Definition: type-id.h:112
std::string callback
Callback function signature type.
Definition: type-id.h:110
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition: type-id.h:114
ns3::TraceSourceAccessor and ns3::MakeTraceSourceAccessor declarations.
ns3::TypeId declaration; inline and template implementations.