OTcl Full Form in Ns2

             The object oriented TCL is called as OTcl and it is similar to C++ and the object oriented version of C. Additionally, the fundamental architecture and syntax based on OTcl are similar to the process of Tcl. It is considered as the interpreted programming language and the OTcl program is capable to run the process in short of required complication. While implementing the process the interpreter is used to translate the OTcl instructions towards the machine code and that is comprehensible for the operating system. The OTcl code that is mainly functioning slowly when it is compared with the C++ code process and it includes the changing process.

Class and Inheritance in OTcl

Class [-superclass & < superclassname>]

             The abovementioned syntax is functional in OTcl and it is the class. The square bracket is the representation of optional argument and the OTcl is considered as the recognition class <classname> as a child class of class <superclassname>.

              For instance, the general network node is considered and it is equipped with mobility where the node is denoted as the mobile node. The pronouncement of a class node and its child class mobile is highlighted in the following. This declaration permits class mobile to the following objectives.

  • Capabilities
  • Moving to itself
  • Inherit capabilities of class Node
  • Receiving packets

Class Node

Class Mobile -superclass Node

TCL Written in C++

           Here, our research professionals have enlisted the classes that are accessible in the Tcl and it includes six significant classes. They are highlighted in the following along with its specifications.

  • Class EmbeddedTcl translates OTcl scripts into C++ codes (Defined in files ̃tclcl/tclcl.h, ̃tclcl/Tcl.cc, and ̃tclcl/tclAppInit.cc)
  • Class TclObject is the base class for all C++ simulation objects in the compiled hierarchy (defined in file ̃tclcl/Tcl.cc)
  • Class TclClass maps class names in the interpreted hierarchy to class names in the compiled hierarchy (Defined in files ̃tclcl/tclcl.h and tclcl/Tcl.cc)
  • Class TclCommand provides a global access to the compiled hierarchy from the interpreted hierarchy (Defined in files ̃tclcl/tclcl.h and ̃tclcl/Tcl.cc)
  • Class InstVar binds member variables in both the hierarchies together (Defined in file ̃tclcl/Tcl.cc)
  • Class Tcl provides methods to access the interpreted hierarchy (from the compiled hierarchy; Defined in files ̃tclcl/tclcl.h and ̃tclcl/Tcl.cc)

OTcl Sample Script

          In the following, our research professionals have highlighted the script of OTcl just by implementing all the above mentioned key notes and it is beneficial for the research scholars to develop their research in Ns2 using OTcl and this sample OTcl script enlisted the following.

  • Creates 2 nodes add a duplex link between the two with relevant parameters
  • Adds a UDP agent and UDP Sink agent to nodes 0 and 1 respectively
  • Adds a CBR traffic application to the UDP agent
  • Connects the agents and run the simulation for 5 seconds
  • Calls NAM to animate this topology
# Create a simulator object
set ns [new Simulator]
# Open the nam trace file, associated with nf, log everything as nam output in nf
set nf [open out.nam w]
$ns namtrace-all $nf
# Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms
DropTail #Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.1
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
# Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
# Run the simulation
$ns run

        Our research team updates their knowledge to produce the finest research results. In fact, we have 20+ years of experience in this field. In this period of time, we accomplished substantial research projects in various research fields for the research scholars. So, make use of all our research guidance just by contacting us.