Motivation for Writing This Book
First of all, we would like to thank you for your interest in this book. This book was
motivated by our frustration when we were graduate students. We were pushed to
work with NS2, when we did not know what to do. We looked over the Internet, but,
at the time, there were very little material on the Internet. We posted our question
on every mailing list, every online forums we can think of. We did not find most of
what we were looking for. We spent days and nights on many operating systems just
to make NS2 run on one of the systems we have. We spent an endless amount of
time, trying to understand the way NS2 moves a packet from one node to another.
We did not succeed. So we were running out of time we pushed out and submitted
our project/thesis as it was. Our program was as good as it was necessary to close
the project. We were not satisfied with our knowledge about NS2.
After the graduation, we revisited NS2 and tried to understand it more. Bits
by bits, we began to understand how NS2 does a certain thing, but perhaps more
importantly why NS2 does so. From our experience, it takes months, if not years, to
truly understand NS2.
We would not be surprised if our story above sounds particularly familiar to you.
In fact, we expected you to experience a part, if not all, of our unpleasant experience.
We wrote this book to ease your pain caused by NS2. We hope that this book can
reduce your NS2 learning curve from years to months, or from months to weeks.
NS2 is an open-source event-driven simulator designed specifically for research
in computer communication networks. Since its inception in 1989, NS2 has
continuously gained tremendous interest from industry, academia, and government.
Having been under constant investigation and enhancement for years, NS2 now
contains modules for numerous network components such as routing, transport
layer protocol, and application. To investigate network performance, researchers can
simply use an easy-to-use scripting language to configure a network, and observe
results generated by NS2. Undoubtedly, NS2 has become the most widely used open
source network simulator, and one of the most widely used network simulators.
Unfortunately, most research needs simulation modules which are beyond the
scope of the built-in NS2 modules. Incorporating these modules into NS2 requires
profound understanding of NS2 architecture. Currently, most NS2 beginners rely
on online tutorials. Most of the available information mainly explains how to
configure a network and collect results, but does not include sufficient information
for building additional modules in NS2. Despite its details about NS2 modules, the
formal documentation of NS2 is mainly written as a reference book, and does not
provide much information for beginners. The lack of guidelines for extending NS2
is perhaps the greatest obstacle, which discourages numerous researchers from using
NS2. At the time of this writing, there is no official guide book which can help the
beginners understand the architecture of NS2 in depth.
About This Book
This book is designed to be an NS2 primer. It provides information required to
install NS2, run simple examples, modify the existing NS2 modules, and create as
well as incorporate new modules into NS2. To this end, the details of several built-in
NS2 modules are explained in a comprehensive manner.
NS2 by itself contains numerous modules. As time elapses, researchers keep
developing new NS2 modules. This book does not include the details of all NS2
modules, but does so for selected modules necessary to understand the basics of
NS2. We believe that once the basics of NS2 are grasped, the readers can go
through other documentations, and readily understand the details of other NS2
components. The details of Network AniMator (NAM) and Xgraph are also omitted
here. We understand that these two tools are nice to have and could greatly facilitate
simulation and analysis of computer networks. However, we believe that they are
not essential to the understanding of the NS2 concept, and their information are
widely available through most of the online tutorials.
This textbook can be used by researchers who need to use NS2 for communication network performance evaluation based on simulation. Also, it can be used as
a reference textbook for laboratory works for a senior undergraduate level course
or a graduate level course on telecommunication networks offered in Electrical
and Computer Engineering and Computer Science Programs. Potential courses
include “Network Simulation and Modeling,” “Computer Networks,” “Data Communications,” “Wireless Communications and Networking,” and “Special Topics on
This book starts off with an introduction to network simulation in Chap. 1. We
briefly discuss about computer networks and the layering concept. Then we
give board statements on system analysis approaches. As one of the two main
approaches, simulation can be carried out in time-driven and event-driven modes.
The latter is the one NS2 was developed.
Chapter 2 provides an overview of Network Simulator 2 (NS2). Shown in this
chapter are the two-language NS2 architecture, NS2 directory, and the conventions
used in this book, and NS2 installation guidelines for UNIX and Windows systems.
We also present a three-step simulation formulation as well as a simple example of
NS2 simulation. Finally, we demonstrate how to use the make utility to incorporate
new modules into NS2.
Chapter 3 explains the details of the NS2 two language structure, which
consists of the following six main CCC classes: Tcl, Instvar, TclObject,
TclClass, TclCommand, and EmbeddedTcl. Chapters 4 and 5 present the
very main simulation concept of NS2. While Chap. 4 explains implementation of
event-driven simulation in NS2, Chap. 5 focuses on network objects as well as
packet forwarding mechanism.
Chapters 6–11 present the following six most widely used NS2 modules. First,
nodes (Chap. 6) act as routers and computer hosts. Second, links, particularly
SimpleLink objects (Chap. 7), deliver packets from one network object to
another. They model packet transmission time as well as packet buffering. Third,
packets (Chap. 8) contain necessary information in its header. Fourth, agents
(Chaps. 9–10) are responsible for generating packets. NS2 has two main transportlayer agents: TCP and UDP agents. Finally, applications (Chap. 11) model the user
demand for data transmission.
Up to Chap. 11, the book focuses mainly on wired networks. Chapter 12
demonstrates how NS2 implements Wireless Mobile Ad Hoc Networks. Discussion
of packet forwarding via wireless links and node mobility is given in this chapter.
After discussing all the NS components, Chap. 13 demonstrates how a new
module is developed and integrated into NS2 through two following examples:
Automatic Repeat reQuest (ARQ) and packet schedulers.
Chapter 14 summarizes the postsimulation process, which consists of three main
parts: debugging, variable and packet tracing, and result compilation.
Chapter 15 presents three helper modules: Timers, random number generators,
and error models. It also discusses the concepts of two bit-wise operations – namely,
bit masking and bit shifting, which are used throughout NS2.
Finally, Appendices A and B provide programming details which could be useful
for the beginners. These details include an introduction to Tcl, OTcl, and AWK
programming languages as well as a review of the polymorphism OOP concept.
Last but not the least, Appendix C explains the BSD link list as well as bit level
functions used throughout this book.x Preface
How to Read This Book
If you have not done so, we highly recommend you to visit the following online
websites and learn what you can do with NS2.1
• Marc Greis’ Tutorial: http://www.isi.edu/nsnam/ns/tutorial
• NS2 by Example: http://perform.wpi.edu/NS
Start simple. Learning how NS2 pass a packet from one end of a communication
link to another is more challenging than what you might have imagined. In fact, if
there is only one goal you should set, it is to understand this seemingly simple NS2
mechanism. Once you grasp this concept, you can quickly and effortlessly learn
other NS2 mechanism.
In particular, the following steps are suggested for beginners:
Step 1 (The Basic): Learn how NS2 pass packets from one object to another
from within a SimpleLink. Visit Chap. 7 for SimpleLink implementation.
You may need to visit Chaps. 4–5 for details of scheduler and Network
Step 2 (CBR and UDP): These are two high-layer components which is easy to
learn. Look for the contents about UDP and CBR in Chaps. 9 and 11,
Step 3 (New Module): Next, visit Chap. 13 to learn how to build new modules into
NS2. There are two examples in this chapter. Note that you may need to
learn how to use make utility in Chap. 2.
This book contains 15 chapters. Different chapters may consume different amount
of lecturing time. Generally, it requires more than 15 classes to cover the entire
book. We suggest instructors to emphasize/omit the contents of this book at their
discretion. In order to manage time efficiently, the instructors may follow the
• Chapters 8, 14, and 10 can be skipped without greatly impairing the content of
• The instructor may pack two chapters into one lecture: Chaps. 1–2 and 4–5.
We also provide exercises at the end of each chapter. The instructors may
use these exercises to set up assignments, laboratory exercises, or examination
فهرستی برای این کتاب ثبت نشده است.