3. Conventional Class
categorization
Two-language structure
NS2 consists of two languages: C++ and OTcl
The simplest form ➠ Standalone classes
C O
C.1 C.2 O.1 O.2
C++ classes OTcl classes
www.ns2ultimate.com
4. Conventional class
categorization
But clearly, there can be more than on class
hierarchy in both the domains
C O
C.1 C.2 O.1 O.2
C++ classes OTcl classes
www.ns2ultimate.com
5. Conventional class
categorization
But clearly, there can be more than on class
hierarchy in both the domains
D P
D.1 D.2 P.1 P.2
C O
C.1 C.2 O.1 O.2
C++ classes OTcl classes
www.ns2ultimate.com
6. Conventional object
categorization
Classes in the C++ domain can be bound to
class in the OTcl domain
D P
D.1 D.2 P.1 P.2
C O
C.1 C.2 O.1 O.2
bind
C++ classes OTcl classes
www.ns2ultimate.com
7. Conventional class
categorization
And, binding can be quite arbitrary
D P
D.1 D.2 P.1 P.2
bind
C O
C.1 C.2 O.1 O.2
bind
C++ classes OTcl classes
www.ns2ultimate.com
8. Conventional class
categorization
Now we have two categories of classes:
“bound” and “standalone”
D P
D.1 D.2 P.1 P.2 Standalone
bind OTcl classes
C O
Standalone
C++ classes
C.1 C.2 O.1 O.2
bind
www.ns2ultimate.com
9. Conventional class
categorization
Now we have two categories of classes:
“bound” and “standalone”
D P
D.1 D.2 P.1 P.2 Standalone
bind OTcl classes
bound
C O
Standalone classes
C++ classes
C.1 C.2 O.1 O.2
bind
www.ns2ultimate.com
10. Conventional class
categorization
Bound C++ = Compiled classes
Bound OTcl = Interpreted classes
Standalone
bind OTcl classes
C O
Standalone
C++ classes
C.1 C.2 O.1 O.2
bind
www.ns2ultimate.com
11. Conventional class
categorization
Bound C++ = Compiled classes
Bound OTcl = Interpreted classes
Standalone
bind OTcl classes
C O
Standalone
C++ classes
C.1 C.2 O.1 O.2
bind
Compiled Interpreted
classes classes
www.ns2ultimate.com
12. Conventional class
categorization
C++ OTcl
Compiled Interpreted
Bound
classes classes
Standalone C++ classes OTcl classes
www.ns2ultimate.com
14. Simulation class
categorization
Six main categories
Base C++ Class Characteristic
TclObject Compiled classes
Handler Default actions
NsObject Receive packets
Packet Packet reception event
Event scheduler: put events on the simulation time line
Scheduler
and execute default actions at the right time.
Others None of the above, e.g., Routing, timers, etc.
www.ns2ultimate.com
15. related objects were discussed in Chapter 4. The packet-related objects will
Simulation class
be discussed in Chapter 8. The main helper objects will be discussed in
Chapter 15.
categorization
5.1.2 C++ Class Hierarchy
This section gives an overview of C++ class hierarchies. The entire hierarchy
consists of over 100 C++ classes and struct data types. Here, we only show
Six main categories
a part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the
complete class hierarchy.
OTcl Interface Default Action
TclObject Handler
Simulator PacketQueue NsObject AtHandler QueueHandler
RoutingModule
Network Component
Classifier Connector LanRouter
Uni-directional Point-to-
point Object Connector
Queue Agent ErrorModel LinkDelay Trace
Fig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes
www.ns2ultimate.com
in boxes with thick solid lines).
16. Simulation class
categorization
Six main categories
Base C++ Class Characteristic
TclObject Compiled classes
Handler Default actions
NsObject Receive packets (= Default action)
Packet Packet reception event
Event scheduler: put events on the simulation time
Scheduler
line and execute default actions at the right time.
Others None of the above, e.g., Routing, timers, etc.
www.ns2ultimate.com
18. example: packet
transmission
Sending a packet from an Agent object to a
Queue object
Packet
Agent Queue
www.ns2ultimate.com
19. example: packet
transmission
Class hierarchy
NsObject ➠ Agent and Queue
Event ➠ Packet
NsObject
Event
Packet
Agent Queue
www.ns2ultimate.com
20. For more
information
about NS2
P l e a s e s e e
t h i s b o o k
f r o m
S p r i n g e r
T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009
or visit www.ns2ultimate.com