Purpose: Defining A Class in Otcl
Purpose: Defining A Class in Otcl
NS2 is discrete event simulator used to simulate real time network traffic and topology for
analysis. For researcher it is proven to be great tool. NS2 has been developed in C++ and
TCL. Otcl which is object oriented TCL, also used in NS2. For simulation purpose TCL
programming is used and for adding new module C++ is used. This tutorial is targeted for
students who wants to learn NS2 but don't have much knowledge.
1. TCL Programming
2. OTcl Programming
3. NS2 Commands
Purpose
NS (version 2) is an object-oriented, discrete event driven network simulator developed at UC
Berkely written in C++ and OTcl. NS is primarily useful for simulating local and wide area networks.
Although NS is fairly easy to use once you get to know the simulator, it is quite difficult for a first
time user, because there are few user-friendly manuals. Even though there is a lot of documentation
written by the developers which has in depth explanation of the simulator, it is written with the depth
of a skilled NS user. The purpose of this project is to give a new user some basic idea of how the
simultor works, how to setup simulation networks, where to look for further information about
network components in simulator codes, how to create new network components, etc., mainly by
giving simple examples and brief explanations based on our experiences. Although all the usage of the
simulator or possible network simulation setups may not be covered in this project, the project should
help a new user to get started quickly.
Defining a Class in OTcl
Objects are instances of class. Class can be thought as used defined data type and objects as
variable of that data type. In OTcl new class can be created by using Class command.
Syntax:
Class <class_name>
class' data member can be defined by using set command with object name. These data members have
public visibility.
Syntax:
<object-name> set <attribute-name> <attribute-value>
Use OTcl
- For configuration, setup, or one time simulation, or
- To run simulation with existing NS2 modules.
This option is preferable for most beginners, since it does not involve complicated internal mechanism
of NS2. Unfortunately, existing NS2 modules are fairly limited. This option is perhaps not sufficient
for most researchers.
Use C++
- When you are dealing with a packet, or when you need to modify existing NS2 modules.
This option perhaps discourages most of the beginners from using NS2. This book particularly aims at
helping the readers understand the structure of NS2 and feel more comfortable in modifying NS2
modules.
ns Directory Structure
Basic Tcl
variables:
set x 10
puts x is $x
functions and expressions:
set y [pow x 2]
set y [expr x*x]
control flow:
if {$x > 0} { return $x } else {
return [expr -$x] }
while { $x > 0 } {
puts $x
incr x 1
}
procedures:
proc pow {x n} {
if {$n == 1} { return $x }
set part [pow x [expr $n-1]]
return [expr $x*$part]
}
Also lists, associative arrays, etc.
=> can use a real programming language to build network topologies, traffic models, etc.
Basic otcl
Class Person
# constructor: