OTCL in NS2 projects reflects the significance of OTCL [Object oriented extension of TCL] in NS-2. TCL (Tool command language) is a scripting language used for setting up the configuration and designing part of NS2. We have emphasized on NS2 projects as NS-2 simulation is primarily based on two languages i.e. C++ and OTCL. One must be aware of these two languages to accomplish a project in NS2. We have develop nearly 1000+ projects in NS-2 for students from all over the world. Our immense experience and expertise, makes us world no.1 institute with more than 50+ branches worldwide.

We believe in project based learning approach i.e. along with project, we provide complete tutoring support on the basics of NS-2 programming, so that students will enhance their skills and potential under our guidance. We can assure you that you will never regret for committing your work with us, as we have a record of 5000+ successful stories in the past 7 years. Approach us today and experience our immense guidance and support to enhance your academic performance and grades.


  • OTCL is an extension to TCL/TK for object oriented programming, written in C++
  • NS2 is actually an OTCL programming language interpreter, consist of built in library of Network Simulation objects
  • By adding object definitions in C++ source code, OTCL library of objects can be extended.
  • OTCL can run on platforms like Unix, Windows, FreeBSD, Solaris, Linux etc
  • OTCL features:
    • Designed to be dynamically extensible
    • Powerful programming language with fairly portable implementation
    • Builds on TCL syntax and concepts
  • OTCL compiles to four binary results:
    • Otclsh [tclsh loaded with OTCL]
    • Libotcl.a[OTCL library for adding OTCL to TCL application ]
    • Owish[wish loaded with OTCL]
    • Libotcl.so[shared version of OTCL library for dynamically loading OTCL into TCL shells]
  • Comparison with C++:

                 -Instead of Constructor in C++, we use init intsproc in OTCL. Similarly for destructor in C++, we use destroy instproc in OTCL. Unlike constructor and destructor methods, init and destroy methods do not combine with base classes automatically, it needs to be compiled explicitly using next.

                  -An Instead of a single class declaration as in C++, OTCL uses multiple definitions. Each method definition with instproc adds a method to a class and each variable definition [with instvar in method body] adds an instance variable to an object.

                 -Unlike C++, OTCL methods are always virtual and called through an object.

                 -In C++, Shadowed methods are called by naming them explicitly, instead of that in OTCL, it is called using next. Next searches the shadowed method in the inheritance graph and allows the method to combine without having any naming dependencies.

               -There is no exact analogue for static methods and variables in OTCL. Shared variables are placed on the class objects and accessed by using $Class. This behavior can be inherited or instead of using inheritance, proc method can be used on the class object.


  • Defining a class:

Class MyName // to define a class that inherits from an object

Class MyName –superclass Name// To define a class that inherits from class “name”

  • To define a Member function:

// To define a member function
  MyName instproc memberfn 2 {}
puts “in member function 2” }
// To create a new object “MyFirst” in a member function 1
set myobj [ new  Myfirst ]
$ myobj  memberfn 1

  •  To create a member variable of OTCL Class:

set myobj [ new MyClass ]  //To define a member variable “myobj”of class “MyClass”

set myNode [ new  Node ]  //To define a variable “myNode” of the class “Node”

  •  To invoke a member methods:

          //To invoke method “Method1” in an object with parameters [param1…]

Set  MyVar [ new MyClass ] 
$ MyVar Method1 param1 param2 …..

  •  To create a constructor

Class MyNode MyNode instproc init {} {
$ self next$ self instvar datamem1set datamem1 “Hello”  } 
MyNode  instproc p {} { $ self instvar datamem1 puts $ datamem1 }

  •  To use #include[used to include utility function]

caller.tcl ……………………….source ./callee.tcl 
Puts “Hello”  We have provided few basic commands used in OTCL for students reference. In NS2, OTCL is used by creating a link between TCL and C++.   For example, create a TCPClass for Agent/TCP in C++ [TCP.cc]


TcpClass() : TclClass(“Agent/TCP”) {}

 TclObject* create(int , const char*const*) {

 return (new TcpAgent());

 }Void TcpAgent::traceAll() {}

Now, call it in TCL using the following command:

 set tcp [new Agent/TCP]

      Here, we have linked an object to TCL script, making it OTCL [Object oriented extension of TCL] script. This way C++ is used to create an OTCL script in NS-2. Hope that you would have got an idea about OTCL in NS2 projects. For further tutoring service on OTCL, approach our experts through our online tutoring service. Our experts will serve you with all their knowledge and expertise to offer you a platform to learn and explore. Get our aid anytime as we are here for you at 24/7.