com/site/journalofcomputing WWW.JOURNALOFCOMPUTING.ORG


Tools for Creating TCL Script in Network Simulator 2(NS-2)
Mohammad Reza Nouri rad Department of Computer Engineering Islamic Azad University, Khorramabad Branch, Iran Reza Kourdy Department of Computer Engineering Islamic Azad University, Khorramabad Branch, Iran .

Abstract— Network researchers have used the Ns-2 network simulator for a long-time for implementing and analysing novel ideas and new approaches emerging in computer networks. Simulations in NS-2 through TCL scripts performed. Through these scripts, all aspects of the simulation have defined. One of the problems in Ns-2 is creating TCL script to simulate desired specification of the network. Before TCL script generator built, the only way to use ns-2 was to write TCL code to describe nodes, links and other network objects. This paper presents an application programs for simulate networks like network on chip and scenarios to supporting Quality of Service, create TCL script comfortable and extracting desired result from output files.

Index Terms—TCL script generator, Network Simulator 2 (Ns-2), nostrum mesh topology, Trace.

A widespread methodology for performance analysis in the field of communication systems engineering is network simulation. Network Simulator 2 (NS2) is one of the most popular tools in academia for evaluation of network, protocols and topologies. It has become virtually the standard of network simulation. It represents a discrete, event-based simulator that has an ability to be easily extendible and modifiable due to its open source nature. However, a major shortcoming of NS2 is its limited scalability in terms of memory usage and simulation runtime which get worsen due to further post processing of huge, multi-format output files [1]. NS-2 is an open source, object-oriented and discrete event driven network simulator written in C++ and OTcl. It is a very common and widely used tool to simulate small and large area networks [2]. Tcl scripts are widely used in NS-2 simulation tool. Researchers use Tcl scripts to set up a wired or wireless communication network, and then run these scripts via the NS-2 for getting the simulation results [3]. Since Tcl scripts are widely used, we have implemented a new tool which is MyTool for generating Tcl scripts file. In this work, introduce the specific characteristics of MyTool and discuss its features compared with NSG2 (NS-2 Scenarios Generator 2) [4]. In order to optimize the proposal and the validation of new QoS architectures and technologies, Simulation seems to be the best solution when considering the deployment efforts, cost and scalability. Unfortunately, the existing platforms and tools for simulating QoS-based networks either do not support all the architectures and technologies or do not fully support their characteristics. Basically, a simulation life-cycle can be divided into three phases: specification of the scenario, simulation of the events and analysis of the results of the simulation [5]. Our NoC is a scalable packet switched communication platform for single chip systems. The NoC architecture consists of a mesh of switches together with some resources. Resources Are Heterogeneous or can be homogeneously. A resource can be intellectual properties (IPs). We use nostrum Mesh architecture of two-dimension 4*4 architecture [6], with equal link delay that implemented in real world that shown in Fig. 1. The square nodes stand for IPs and the circle nodes stand for switches. This topology has easily scaled to different sizes.

2.1 NS2 Scenarios Generator (NSG)
NS2 Scenarios Generator (NSG) is a Java based tool that runs on any platform and can generate TCL Scripts for Wired as well as Wireless Scenarios for Network Simultor - 2. The procedure to execute these TCL Scripts on NS-2 is same as those of manually written TCL Scripts. Some of the main features of NS2 Scenarios Generator (NSG) are as mentioned below:  Creating Wired and Wireless nodes just by drag and drop.  Creating Simplex and Duplex links for wired network.  Creating Grid, Random and Chain topologies.  Creating TCP and UDP agents. Also supports TCP Tahoe, TCP Reno, TCP New-Reno and TCP Vegas.  Supports Ad Hoc routing protocols such as DSDV, AODV, DSR and TORA.  Supports FTP and CBR applications.  Supports node mobility.  Setting the packet size, start time of simulation, end time of simulation, transmission range and interference range in case of wireless networks, etc.  Setting other network parameters such as bandwidth, etc for wireless scenarios [7]. The Snapshot of NSG is as shown below:



2.3 Ns-2 Workbench
Ns Bench makes NS-2 simulation development and analysis faster and easier for students and researchers without losing the flexibility or expressiveness gained by writing a script. Ns Bench Features was as below:  Nodes, simplex/duplex links and LANs  Agents: TCP,UDP, TCPSink, TCP/Fack, TCP/FullTcp, TCP/Newreno, TCP/Reno, TCP/Sack1, TCPSink, TCPSink/Sack1, TCPSink/DelAck, TCPSink/Sack1/DelAck, TCP/Vegas, Null Agent.  Applications/Traffic: FTP, Telent, Http/Server, Http/Client, Http/Cache, webtraf, Traffic/CBR, Traffic/Pareto, Traffic/Exponential.  Services: Multicast, Packet Scheduling, RED, DiffServ.  Creating "Groups" concept to compensate for "loops".  Scenario generator.  Link Monitors.  Loss Models.  Routing Protocols[9]. The Snapshot of NsBebch is as shown below:

Fig . 1. NSG to create nostrum mesh 4*4 NoC.

2.2 Visual Network Simulator (VNS)
The Visual Network Simulator (VNS) tool, centered on the NSG2 tool capabilities, was developed aiming to facilitate the creation of network simulation scenarios to be executed over ns-2. Two important innovations of VNS, compared to other similar tools are: 1) The support to Differentiated Services (DiffServ) scenarios. 2) It provides a simple and intuitive set of icons to represent the components of a network. Examples of these icons are the hosts, the routers and an Internet cloud, each with a different symbol. Some others important functionalities of VNS were also taken into account, such as:  Adding and configuration of links, agents and traffic sources.  Modeling network scenarios with support to multicast.  Selection of a dynamic routing protocol.  Definition of the simulation output as an animation and/or graphics.  Edition of the Tcl script generated.  Saving the defined simulation scenario [8]. The Snapshot of VNS is as shown below:

Fig . 3. NsBebch to create nostrum mesh 4*4 NoC.

2.4 Network Simulation by Mouse (NSBM)
NSBM,  developed  in  java,  is  a  graphical  tool  that  is  used  to  generate  TCL  script  using  a  mouse.  Nodes  and  links can be created with a single mouse click. When the  program  is  started,  a  screen  appears  with  all  the  tools  available  on  it  [10].  In  fact,  you  can  draw  a  network  to‐ pology with multiple nodes with only a few mouse clicks.  Afterwards  you  click  on  a  button  and  there  is  the  TCL  code, almost ready for use with the ns. The NSBM engine  for generate TCL script is as shown below:   
Fig . 2. VNS to create nostrum mesh 4*4 NoC.



The Snapshot of NSBM is as shown below:

Fig . 4. NSBM engine for create Tcl Script.

The xml files are a very important part of NSBM. All information about applications, agents, queues, links, their properties, and their compatibility are stored there. In order to extend the functionality of NSBM, you can simply change the xml files and you practicaly end up with a new application of your choice. A new Java API called Java Architecture for XML Binding (JAXB) can make it easier to access XML documents from applications written in the Java programming language. NSBM used in order to process the XML configuration data. It must provide many functions, which are specified only in the configuration data at run time. Because the classes are implementation-specific, classes generated by the binding compiler in one JAXB implementation will probably not work with another JAXB implementation. So if you change to another JAXB implementation, you should rebind the schema with the binding compiler provided by that implementation. The content objects are instances of the classes produced by the binding compiler. In addition to providing a binding compiler, a JAXB implementation must provide runtime APIs for JAXB-related operations such as marshalling. The APIs are provided as part of a binding framework [12] (see fig .5).

Fig . 6. NSBM engine for create Tcl Script.

2.5 Writing Tcl Script
Another way to create the nostrum topology is that write TCL script in an editor like notepad++ as below:

# Create links row-by-row (switches-switches) For {set i 1} {$i <= $x} {incr i} { For {set j 1} {$j <= [expr $x-1]} {incr j} { $ns duplex-link $sw([expr $i*10+$j]) $sw([expr $i*10+$j+1]) $max_bandwidth_switch $linkDelay_switch DropTail }} #Create links Column-By-Column (switchesswitches) For {set j 1} {$j <= $x} {incr j} { For {set i 1} {$i <= [expr $x-1]} {incr i} { $ns duplex-link $sw([expr $i*10+$j]) $sw([expr ($i+1)*10+$j]) $max_bandwidth_switch $linkDelay_switch DropTail $ns duplex-link-op $sw([expr $i*10+$j]) $sw([expr ($i+1)*10+$j]) queuePos $queuePosition_switch} $ns queue-limit $sw([expr $i*10+$j]) $sw([expr ($i+1)*10+$j]) $Qlimit_switch_switch }} # create links (switches-Resources) For {set j 1} {$j <= $x} {incr j} { For {set i 1} {$i <= $x} {incr i} { $ns duplex-link $sw([expr $i*10+$j]) $Res([expr $i*10+$j]) $max_bandwidth_Resource $linkDelay_Resource DropTail }} This OTCL script was for create mesh topology that connect switches row by row, column by column and then connect a resource to each switch for transmission.

Fig . 5. Java Architecture for XML Binding (JAXB).



The nostrum model [6], that with above TCL code creates in network animator (nam) is as shown below:

Fig . 9. Files and Mode submenu for TCL script generate in VNS.

Fig . 7. Nostrum mesh 4*4 NoC created by Writing TCL.

Although all the NSG2, VNS, NSBench and NSBM create TCL script, but these TCL scrip generator programs has the Difference and likeness with each other as below:  Likeness: all of them were on way application to create TCL script, thus if we change the created TCL script by another program like "notepad++", we cannot load TCL script to these programs.  Difference: NSG2 has not a choice to save its code, to load again and change the topology and other features of the simulation. However, VNS, NSBench and NSBM have this choice (see Fig .9, Fig .10, and Fig .11). This means that reusability of the NSG2 was less than the other programs. We show these choices as below figures.

Fig . 10. Files submenu for TCL script generate in Ns Workbench.

Fig . 11. Files submenu for TCL script generate in NSBM.

Fig . 8. Mode submenu for TCL script generate in NSG2.

As shown in Fig .8 – Fig .11, all mentioned TCL script generator can create TCL code that used in NS-2. Just NSG2 has no feature for save and open previous simulation code. Although reusability of NSG2 was the less, related to other TCL script generators. But when topology was more complex or has a perfect graph relatively, NSG2 create the topology in the less time, this means that NSG2 was user more friendly relatived to others.



The other difference in mentioned TCL script generator was the TCL code like create the node that shown in fig 12. And fig .13. This means that TCL script that create by NSBM was more flexible related to other TCL Script generators.

Fig . 14. Ns workbench in supporting QoS.

Fig . 12. NSBM create procedural TCL script.

But the other Tcl script generator create each node separately as below:

Fig . 15.VNS in supporting QoS.

By the result of this section we can say that we can create desired topologies with mentioned programs or by writing TCL sctipt in an editor like "notepad++".

Fig . 13. TCL create by NSG2, VNS and NsBench.


4.1 Trace File in NS-2
NS2 currently supports a number of different types of trace files. In addition to its own format, NS2 also has the Nam trace format, which contains the necessary information from the simulation to drive the Nam visualizer. Both of these trace formats are very specific when it comes to giving details about the events that occur during an NS2 simulation [12]. The only support for data collection in ns-2 is represented by traces and monitors. Traces record events related to the generation, enqueueing, forwarding, and dropping of packets. Each event corresponds to a line of ASCII characters, which contains information on the event type and the information stored into the packet [13]. Generally, the researchers have to understand most events to analyze the trace file. The simulation steps as shown below:

As a result by changing the parameters of procedure in TCL script that created by NSBM, we can change the granularity of our topology or other specification of simulation easily. The other difference between mentioned TCL script generator was the supporting Quality of services (Qos) that can implemented by diffserv services. Just VNS and Ns workbench can support them in different ways that shown in Fig .14 and Fig .15 respectively. The other difference between them was specifications of each of the tcl script generator that we mentioned these specification separately.



Trace-file data explanation briefly is as below:

Fig . 16. Kinds of output format in NS-2.

1 -Operation performed in the simulation 2 -Simulation time of event occurrence 3 -Node 1 of what is being traced 4 -Node 2 of what is being traced 5 -Packet type 6 -Packet size 7 -Flags 8 -IP flow identifier 9 -Packet source node address 10 -Packet destination node address 11 -Sequence number 12 -Unique packet identifier 2. Monitoring
Queue monitoring refers to the capability of tracking the dynamics of packets at a queue (or other object). A queue monitor tracks packet arrival/departure/drop statistics, and may optionally compute averages of these values. Monitoring was useful tools to find detail information about queue; in fact, it is a queue monitor as below:

Thus, NS-2 provides three kinds of formats for wired networks: Tracing, Monitoring and NAM trace file.

1. Tracing
An example of trace file is as shown below:

Fig . 19. Link based monitoring. Fig . 17.Data in trace file.

This format is consider easy to read because the events grouped together to provide information about experience. Usually normal trace file consist of 12 columns for each line. The events that available in normal trace file as shown below:

Monitoring may be applied to all packets (aggregate statistics), or per-flow statistics (using a Flow Monitor). The QueueMonitor/ED/Flowmon class is responsible for managing the creation of new flow objects when packets arrive on previously unknown flows and for updating existing flow objects [14]. The flow-monitor trace format is as shown below:

Fig . 18. Trace file format.

Fig . 20. Flow Monitor trace format.



The flow-monitor defines a trace format, which may be uses by post-processing scripts to determine various counts on a per-flow basis.

3. NAM
nam trace files which are used by nam for visualization of ns simulations. The nam trace file should contain topology information like nodes, links, queues, node connectivity etc as well as packet trace information. A nam trace file has a basic format to it. Each line is a nam event. The first character on the line defines the type of event and is followed by several flags to set options on that event. There are 2 sections in that file, static initial configuration events and animation events. All events with -t * in them are configuration events and should be at the beginning of the file [15]. An example of NAM file is as shown below:

Fig . 22. Three main building blocks in Awk file.

After the awk file written we can extracting desired result from trace file as following command: $gawk –f loss.awk This command extract number of packets sent and lost from trace file with the name "" that created by trace file (see Fig .17, Fig .18 and Fig .22).



Fig . 21. NAM trace file format.

As shown in Fig .21, when a line in nam file start with (+, -, r, d and h), this line is packet animaion event. Thus we can consider this event for infomation about that packet. This means that information in NAM file was like a trace file with specific format.

Simulation technology has the problem of not actually reflecting obstacles and limitations in the real network environment as it operates in ideal network environment. Because of poor documentation and NS2 has not a good compiler for help and solving the syntax error of TCL code, creating TCL scipt by mentioned TCL scipt generator caused to reduce the time of creating simulation script code. By using awk command, we can search and extract the result from trace file like as trace and NAM file.

4.2 Post processing
To ease the process of extracting data for performance study, we must to extracting and presenting trace files for the network simulation environment of NS-2. Then we can present meaningful data in the form of graph, table and report for network performance study. Extract desired data from trace file can to be perform by TCL script code in TCL script file, or by awk command. The awk utilities allows users to do operation on data files i.e. Filtering data column by column, averaging the value, summation, and data reformatting tasks. In this software, the utility is used for data extraction, calculation of performance parameter, and reorganization of the results data so it will be compatible with the tools used in presentation layer [16]. In order to show how awk command was work we show three main building blocks, with description in an awk file as below:

[1] Rahimi, M.J, Parveen S, Morshed, M, Khan, M.R, Sarker P, " Development of the smart QoS monitors to enhance the performance of the NS2 Network Simulator" , 2010 13th International Conference on Computer and Information Technology (ICCIT), IEEE, 23-25 Dec. 2010. M. Ali, M. Welzl, A. Adnan, F. Nadeem , " Using the NS-2 Network simulator for Evaluating Network on Chips (NoC)" InternationalConference on Emerging Technologies, pp.506 – 512, 2006. Jia Huang, Shahnasser H, "Intelligent Vehicle Mobility Tcl Script Generator for NS-2 Simulation", 2010 Second WRI Global Congress on Intelligent Systems (GCIS), , pp.341–344, IEEE,16-17 Dec. 2010. Jia Huang, Hamid Shahnasser, "A preprocessor Tcl script generator for NS-2 communication network simulation", 2011 International Conference on Communications and Information Technology (ICCIT), pp.184–187, IEEE, 29-31 March 2011. Marques, E.M.D., Placido, R.A.S.A., Sampaio, P.N.M., " Visual Network Simulator (VNS): A GUI to QoS simulation for the ns-2 simulator", IEEE/ACS International Conference on Computer Systems and Applications, 2009. AICCSA 2009, pp.342–349, IEEE, 10-13 May 2009. Nostrum, P. Wu, "NS2 Scenarios Generator 2", available from





[6] [7]



[8] [9]


[11] [12]


[14] [15] [16], 2008. E. Al-Shaer, "nsBench -- Graphical User Interface for Network Simulator",, 2005. M. Welzl, M. Ali, and S. Hessler: "Network Simulation By Mouse (NSBM): "A GUI Approach for Teaching Computer Networks with the ns-2 Simulator", Proceedings of the International Conference on Interactive Computer Aided Learning (ICL 2006), 26--28 September 2006, Villach, Austria. s/jaxb/ N.J. Schmidt, P. Kemper, "Phrase based browsing for simulation traces of network protocols", In Proc. 2008 Winter Simulation Conference, Miami, FL, USA, December, 2008,pp. 2811–2819. C. Cicconetti, E. Mingozzi, and G. Stea, “An integrated framework for enabling effective data collection and statistical analysis with ns2", in IP network simulator workshop on ns-2, Italy: ACM, 2006,pp.1-11. g_Support. Umair Salleh , Zulkifli Ishak , Norashidah Md Din , Md Zaini Jamaludin," Trace Analyzer for NS-2", Shah Alam Malaysia, IEEE, 27- 28 June, 2006.

Sign up to vote on this title
UsefulNot useful