What is Network Simulator NS2

how to install network simulator ns2 and how to use ns2 network simulator | download free pdf
NancyWest Profile Pic
NancyWest,Germany,Professional
Published Date:12-07-2017
Your Website URL(Optional)
Comment
Introduction to Network Simulator NS2Teerawat Issariyakul • Ekram Hossain Introduction to Network Simulator NS2 Second Edition 123Teerawat Issariyakul Ekram Hossain TOT Public Company Limited Department of Electrical 89/2 Moo 3 and Computer Engineering Chaengwattana Rd. University of Manitoba Thungsonghong, Laksi 75A Chancellor’s Circle 15 Bangkok 10210 Thailand Winnipeg, MB R3T 5V6 iteerawathotmail.com Canada ns2ultimate.com ekramee.umanitoba.ca ISBN 978-1-4614-1405-6 e-ISBN 978-1-4614-1406-3 DOI 10.1007/978-1-4614-1406-3 Springer New York Dordrecht Heidelberg London Library of Congress Control Number: 2011940220 © Springer Science+Business Media, LLC 2012 All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer Science+Business Media, LLC, 233 Spring Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)To our familiesPreface 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. About NS2 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 viiviii Preface 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 communica- tion 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 Com- munications,” “Wireless Communications and Networking,” and “Special Topics on Telecommunications.”Preface ix Book Summary 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 themake 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 transport- layer 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 To Everyone If you have not done so, we highly recommend you to visit the following online 1 websites and learn what you can do with NS2. � Marc Greis’ Tutorial: http://www.isi.edu/nsnam/ns/tutorial � NS2 by Example: http://perform.wpi.edu/NS To Beginners 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 component implementation. 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, respectively. 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 usemake utility in Chap. 2. To Instructors 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 following guidelines: � Chapters 8, 14,and 10 can be skipped without greatly impairing the content of the course. � The instructor may pack two chapters into one lecture: Chaps. 1–2 and 4–5. 1 Some of these contents is available in Chap. 2.Preface xi We also provide exercises at the end of each chapter. The instructors may use these exercises to set up assignments, laboratory exercises, or examination questions. What’s New in This Second Edition In this Second edition of this book, we correct the grammatical and typological errors. We add more materials on general computer network simulation into Chap. 1. We clean up the terminologies, include more examples, and rewrite Chaps. 6 and 15. At the end of each chapter, we provide exercises which can be used as assignments, laboratory exercises, and examination questions. In Appendix A, we include most of the information that NS2 beginners need to know about Tcl, OTcl, and AWK. During the NS2 learning process, readers may encounter BSD-linked lists and bit level CCC functions. Readers may find the information about these two basic CCC components in Appendix C. As of this writing, the latest NS2 version is 2.35. This version is not fully backward-compatible with version 2.29 used as a reference in the first edition of this book. Therefore, we address the compatibility issues on the link error modules in Chap. 15 and ARQ modules in Chap. 13. We have received numerous requests to deal with wireless networking. In this regard, we develop a new chapter, namely, Wireless Mobile Ad Hoc Networks (Chap. 12). In this chapter, we explain both packet forwarding over wireless links and node mobility mechanism. The information about wireless trace formats is given in Chap. 14. We have also developed companion online resources for this book. They contain useful NS2 information such as updates, discussion boards, detailed explanation on various topics, presentation slides, questions and answers, book corrections, and so on. The readers are highly encouraged to visit and join our online community at � Website: http://ns2ultimate.com � Facebook Fan Page: http://www.facebook.com/pages/Teerawat-Issariyakul/358240861417 � Twitter feed: http://twitter.com/T Bear  � Lecture notes: http://www.ece.ubc.ca/ teerawat/NS2.htm TOT Public Company Limited Teerawat Issariyakul University of Manitoba Ekram HossainAcknowledgment In this second edition, we would like to express our sincere gratitude toward our colleagues at TOT Public Company Limited, and the graduate students of the “Wireless Communications, Networks, and Services Research Group” at the University of Manitoba. We are deeply obliged to audience and followers at the NS2 website, the Facebook page, and the Twitter feed, as well as those who read the previous edition of this book and took time contacting us. Your comments and questions help us improve the content of the book in a big way. We are especially thankful to Nestor Michael C. Tiglao who went so far to help us locate the typographical errors. We would like to thank Springer, the publisher of the book, for giving us an opportunity to share our knowledge and skill with our technical community. Special thanks go to Brett Kurzman, Springer’s agent, who has keenly worked with us from the beginning to the end. Last, but by no means the least, we would like to thank our families and friends for their understanding and continual moral support. We are forever indebted to all the members of Issariyakul and Hossain families. Thank you for giving us love, support, encouragement, and most of all for never stopping to believe in us. Thank you for not abandoning us and always being there for us, even if we have not given you time you deserved, and even have disappeared in a pile of NS2 codes. xiiiContents 1 Simulation of Computer Networks ....................................... 1 1.1 Computer Networks and the Layering Concept .................... 1 1.1.1 Layering Concept ......................................... 2 1.1.2 OSI and TCP/IP Reference Models ...................... 4 1.2 System Modeling..................................................... 5 1.2.1 Analytical Approach ...................................... 6 1.2.2 Simulation Approach...................................... 6 1.3 Basics of Computer Network Simulation ........................... 6 1.3.1 Simulation Components .................................. 7 1.3.2 Simulation Performance .................................. 9 1.3.3 Confidence Interval ....................................... 9 1.3.4 Choices for Network Simulation Tools .................. 9 1.4 Time-Dependent Simulation ......................................... 11 1.4.1 Time-Driven Simulation .................................. 12 1.4.2 Event-Driven Simulation ................................. 13 1.5 A Simulation Example: A Single-Channel Queuing System ...... 14 1.5.1 Entities..................................................... 14 1.5.2 State Global Variables..................................... 15 1.5.3 Resource ................................................... 15 1.5.4 Events...................................................... 15 1.5.5 Simulation Performance Measures and Statistics Gatherers ................................... 16 1.5.6 Simulation Program ....................................... 16 1.6 Chapter Summary .................................................... 19 1.7 Exercises.............................................................. 20 2 Introduction to Network Simulator 2 (NS2) ............................. 21 2.1 Introduction........................................................... 21 2.2 Basic Architecture.................................................... 22 xvxvi Contents 2.3 Installation ............................................................ 23 2.3.1 Installing an All-In-One NS2 Suite on Unix-Based Systems................................... 24 2.3.2 Installing an All-In-One NS2 Suite on Windows-Based Systems.............................. 24 2.4 Directories and Convention .......................................... 25 2.4.1 Directories ................................................. 25 2.4.2 Convention ................................................ 25 2.5 Running NS2 Simulation ............................................ 27 2.5.1 NS2 Program Invocation.................................. 27 2.5.2 Main NS2 Simulation Steps .............................. 28 2.6 A Simulation Example ............................................... 29 2.7 Including C++ Modules into NS2 and themake Utility ........... 35 2.7.1 An Invocation of amake Utility ......................... 35 2.7.2 Amake Descriptor File................................... 35 2.7.3 NS2 Descriptor File ....................................... 38 2.8 Chapter Summary .................................................... 38 2.9 Exercises.............................................................. 39 3 Linkage Between OTcl and CCC in NS2 ................................ 41 3.1 The Two-Language Concept in NS2 ................................ 42 3.1.1 The Natures of OTcl and CCC Programming Languages ................................. 42 3.1.2 CCC Programming Styles and Its Application in NS2 ..................................................... 43 3.2 Class Binding......................................................... 46 3.2.1 Class Binding Process .................................... 46 3.2.2 Defining Your Own Class Binding ....................... 47 3.2.3 Naming Convention for ClassTclClass .............. 48 3.3 Variable Binding...................................................... 48 3.3.1 Variable Binding Methodology........................... 48 3.3.2 Setting the Default Values ................................ 49 3.3.3 NS2 Data Types ........................................... 50 3.3.4 Class Instvar ............................................... 53 3.4 Execution of CCC Statements from the OTcl Domain ............ 53 3.4.1 OTcl Commands in a Nutshell............................ 53 3.4.2 The Internal Mechanism of OTcl Commands ........... 55 3.4.3 An Alternative for OTcl Command Invocation .......... 59 3.4.4 Non-OOP Tcl Command ................................. 59 3.4.5 Invoking a TclCommand.................................. 59 3.5 Shadow Object Construction Process ............................... 62 3.5.1 A Handle of a TclObject .................................. 62 3.5.2 TclObjects Construction Process ......................... 63 3.5.3 TclObjects Destruction Process .......................... 67Contents xvii 3.6 Access the OTcl Domain from the CCC Domain.................. 67 3.6.1 Obtain a Reference to the Tcl Interpreter ................ 68 3.6.2 Execution of Tcl Statements .............................. 68 3.6.3 Pass or Receive Results to/from the Interpreter.......... 69 3.6.4 TclObject Reference Retrieval............................ 71 3.7 Translation of Tcl Code .............................................. 72 3.8 Chapter Summary .................................................... 73 3.9 Exercises.............................................................. 73 4 Implementation of Discrete-Event Simulation in NS2.................. 77 4.1 NS2 Simulation Concept............................................. 77 4.2 Events and Handlers ................................................. 78 4.2.1 An Overview of Events and Handlers.................... 78 4.2.2 ClassNsObject: A Child Class of Class Handler.................................................. 79 4.2.3 Classes Packet andAtEvent: Child Classes of ClassEvent .................................. 80 4.3 The Scheduler ........................................................ 82 4.3.1 Main Components of the Scheduler ...................... 82 4.3.2 Data Encapsulation and Polymorphism Concepts ....... 82 4.3.3 Main Functions of the Scheduler ......................... 83 4.3.4 Two Auxiliary Functions.................................. 85 4.3.5 Dynamics of the Unique ID of an Event ................. 86 4.3.6 Scheduling–Dispatching Mechanism .................... 86 4.3.7 Null Event and Dummy Event Scheduling............... 88 4.4 The Simulator ........................................................ 89 4.4.1 Main Components of a Simulation ....................... 89 4.4.2 Retrieving the Instance of the Simulator ................. 90 4.4.3 Simulator Initialization ................................... 91 4.4.4 Running Simulation ....................................... 92 4.4.5 Instprocs of OTcl Class Simulator........................ 93 4.5 Chapter Summary .................................................... 93 4.6 Exercises.............................................................. 94 5 Network Objects: Creation, Configuration, and Packet Forwarding .................................................... 97 5.1 Overview of NS2 Components ...................................... 98 5.1.1 Functionality-Based Classification of NS2 Modules .... 98 5.1.2 CCC Class Hierarchy .................................... 98 5.2 NsObjects: A Network Object Template ............................ 100 5.2.1 ClassNsObject ......................................... 100 5.2.2 Packet Forwarding Mechanism of NsObjects............ 101 5.3 Connectors............................................................ 101 5.3.1 Class Declaration.......................................... 102 5.3.2 OTcl Configuration Commands .......................... 103 5.3.3 Packet Forwarding Mechanism of Connectors .......... 106xviii Contents 5.4 Chapter Summary .................................................... 108 5.5 Exercises.............................................................. 109 6 Nodes as Routers or Computer Hosts .................................... 111 6.1 An Overview of Nodes in NS2 ...................................... 111 6.1.1 Routing Concept and Terminology....................... 111 6.1.2 Architecture of a Node.................................... 112 6.1.3 Default Nodes and Node Configuration Interface ....... 113 6.2 Classifiers: Multi-Target Packet Forwarders ........................ 114 6.2.1 ClassClassifier and Its Main Components......... 114 6.2.2 Port Classifiers ............................................ 118 6.2.3 Hash Classifiers ........................................... 119 6.2.4 Creating Your Own Classifiers ........................... 125 6.3 Routing Modules ..................................................... 125 6.3.1 An Overview of Routing Modules ....................... 125 6.3.2 CCC ClassRoutingModule.......................... 126 6.3.3 OTcl ClassRtModule ................................... 129 6.3.4 Built-in Routing Modules................................. 131 6.4 Route Logic........................................................... 132 6.4.1 CCC Implementation..................................... 132 6.4.2 OTcl Implementation ..................................... 133 6.5 Node Construction and Configuration............................... 134 6.5.1 Key Variables of the OTcl ClassNode and Their Relationship .................................... 135 6.5.2 Installing Classifiers in a Node ........................... 137 6.5.3 Bridging a Node to a Transport Layer Protocol ......... 138 6.5.4 Adding/Deleting a Routing Rule ......................... 140 6.5.5 Node Construction and Configuration.................... 140 6.6 Chapter Summary .................................................... 147 6.7 Exercises.............................................................. 148 7 Link and Buffer Management ............................................ 151 7.1 Introduction to SimpleLink Objects ................................. 151 7.1.1 Main Components of a SimpleLink ...................... 151 7.1.2 Instprocs for Configuring aSimpleLink Object...... 153 7.1.3 The Constructor of ClassSimpleLink ................ 154 7.2 Modeling Packet Departure.......................................... 155 7.2.1 Packet Departure Mechanism............................. 155 7.2.2 CCC ClassLinkDelay ................................ 156 7.3 Buffer Management .................................................. 158 7.3.1 ClassPacketQueue: A Model for Packet Buffering.. 159 7.3.2 Queue Handler ............................................ 160 7.3.3 Queue Blocking and Callback Mechanism .............. 161 7.3.4 ClassDropTail: A Child Class of ClassQueue...... 163Contents xix 7.4 A Sample Two-Node Network....................................... 165 7.4.1 Network Construction..................................... 165 7.4.2 Packet Flow Mechanism .................................. 165 7.5 Chapter Summary .................................................... 166 7.6 Exercises.............................................................. 167 8 Packets, Packet Headers, and Header Format .......................... 169 8.1 An Overview of Packet Modeling Principle ........................ 169 8.1.1 Packet Architecture ....................................... 169 8.1.2 A Packet as an Event: A Delayed Packet Reception Event ........................................... 172 8.1.3 A Link List of Packets .................................... 173 8.1.4 Free Packet List ........................................... 174 8.2 Packet Allocation and Deallocation ................................. 175 8.2.1 Packet Allocation.......................................... 175 8.2.2 Packet Deallocation ....................................... 178 8.3 Packet Header ........................................................ 180 8.3.1 An Overview of First Level Packet Composition: Offseting Protocol-Specific Header on the Packet Header ............................. 181 8.3.2 Common Packet Header .................................. 182 8.3.3 IP Packet Header .......................................... 183 8.3.4 Payload Type .............................................. 184 8.3.5 Protocol-Specific Headers ................................ 186 8.3.6 Packet Header Access Mechanism ....................... 190 8.3.7 Packet Header Manager................................... 193 8.3.8 Protocol-Specific Header Composition and Packet Header Construction.......................... 194 8.4 Data Payload.......................................................... 200 8.5 Customizing Packets ................................................. 202 8.5.1 Creating Your Own Packet................................ 202 8.5.2 Activate/Deactivate a Protocol-Specific Header ......... 205 8.6 Chapter Summary .................................................... 206 8.7 Exercises.............................................................. 207 9 Transport Control Protocols Part 1: An Overview and User Datagram Protocol Implementation .......... 209 9.1 UDP and TCP Basics ................................................ 209 9.1.1 UDP Basics................................................ 209 9.1.2 TCP Basics ................................................ 210 9.2 Basic Agents.......................................................... 214 9.2.1 Applications, Agents, and a Low-Level Network ....... 215 9.2.2 Agent Configuration ...................................... 217 9.2.3 Internal Mechanism for Agents........................... 218 9.2.4 Guidelines to Define a New Transport Layer Agent..... 222

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.