# The Network Simulator ns-2: Topology Generation

Topology generation is required for network simulations. In NS-2 you may create a topology for simulation using one of the following methods:

## Inet Topology Generator

• Generating graphs from Inet topology generator
Download the Inet Topology Generator from University of Michigan and create a internet topology using the configuration parameter.

• Conversion of Inet output to ns-2 format
Use inet2ns to convert the inet topology to ns.
The command to execute the script is: inet2ns < inet.topology > ns.topology

## Georgia Tech Internetwork Topology Models

• Generating graphs from GT-ITM topology generator.
The GT-ITM topology generator can be used to create flat random graphs and two types of hierarchical graphs, the N-level and transit-stub. Take a look at the examples in Daniel Zappala's homepage. Also look at the documents under docs subdirectory of GT-ITM's distribution.
For example, we need to create a transit-stub graph with 200 nodes. So we create a specification file, say ts200, that goes like this:
```	  ## Comments :
## <#method keyword> <#number of graphs> [<#initial seed>]
## <#stubs/xit> <#t-s edges> <#s-s edges>
## <#n> <#scale> <#edgemethod> <#alpha> [<#beta>] [<#gamma>]
## number of nodes = 1*8* (1 + 4*6) = 200
ts 10 47
4 0 0
1 20 3 1.0
8 20 3 0.8
6 10 3 0.5
```

On running 'itm ts200', 10 transit-stub graphs with 200 nodes each will be created starting with initial seed 47. line 4 0 0 means each transit node will have 4 stub domains connected to it;there shall be no extra transit-stub edges and no extra stub-stub edges. Line 1 20 3 1.0 means there will 1 transit domain in each graph. Line 8 20 3 0.8 says each transit domain will have, on an average, 8 transit nodes with an edge between each pair of node with a probability of 0.8 and line 6 10 3 0.42 says every stub domain shall have, on an average, 6 nodes each with an edge between every pair with a probability of 0.5.
For a more complete description of the parameter specification file see models.ps file under docs subdirectory.
The graphs produced are named as ts200-[0 to 9].gb and are in Stanford Graph Base Output format. This needs to be converted to tcl format for ns-2 to interpret it correctly.

• Conversion of GT-ITM output to ns-2 format
Download the sgb2ns conversion program. Follow instructions in the README file and create the sgb2ns executible. Note that sgb2ns should be expanded in the gt-itm directory, and its executibles will be placed in gt-itm/bin subdirectory. This distribution also contains ts2ns and sgb2hier as described below.
Modify sgb2ns's Makefile to make macro GT_ITM to point to the right path and correct Stanford Graphics Base library name installed in your system(e.g libgd.a, libgb4.a or libgb5.a etc). The library also comes as a part of gt-itm distribution. Under any circumstance it should reside under gt-itm/lib.
sgb2ns converts the sgb output to tcl output.
Usage : sgb2ns ts200-0.gb ts200.tcl

A modification to sgb2ns contributed by Yunxi Shi separates transit nodes from stub nodes when using transit-stub networks. The file (ts2ns.c) is included in sgb2ns distribution.

• Conversion of GT-ITM output to ns-2 hierarchical format
Download Padma Haldar's hierarchical converter package; it's included the sgb2ns distribution above. The package consists of sgb2hierns.c (the converter file) and example files t1000-0.gb (sgb file for 1000 nodes transit-stub) and hts1000.tcl (hierarchical topology converted from t1000-0.gb).
sgb2hierns converts the sgb output to a hierarchical topology in a tcl format suitable for ns-2.
Usage : sgb2hierns ts1000-0.gb hts1000.tcl
In order to use the scenario generator you would need the revised sgb2comns, which is also included in the sgb2ns distribution.

## Tiers Topology Generator

• Generating graphs from Tiers Topology Generator
or
Pavlin's modified version of Tiers-v1.1. This modified version allows the random generator to be specified as an input parameter. (You can check the *.org files for the difference).
The tiers random generator is seen to have produced different results under FreeBSD and sunos for the same input parameters.

• Conversion of Tiers output to ns-2 format
Use Pavlin's awk script tiers2ns.awk to convert the output of tiers into ns-2 scripts. The same file (tiers2ns.awk) is also present under tiers/bin of the Tiers1.1 distribution.
Also available now is tiers2ns-lan.awk for converting LAN topologies.

## Other Topology Generators

• BRITE from Boston University.

## Generating topology By Hand

Smaller and simpler topologies are easier to be created by hand. Below is given an example taken from test-suite.tcl from ns/tcl/ex directory. For more information refer to ns Notes and Documentation (now renamed as ns Manual) (available in PostScript format) and take a look at other example files in ns/tcl/ex directory.

Simple Topology Generation by Hand

```# Create a simple four node topology:
#
#        s1
#         \
#  8Mb,5ms \  0.8Mb,100ms
#           r1 --------- k1
#  8Mb,5ms /
#         /
#        s2
#
proc create_testnet { } {
global s1 s2 r1 k1
set s1 [ns node]
set s2 [ns node]
set r1 [ns node]
set k1 [ns node]

ns_duplex \$s1 \$r1 8Mb 5ms drop-tail
ns_duplex \$s2 \$r1 8Mb 5ms drop-tail
set L [ns_duplex \$r1 \$k1 800Kb 100ms drop-tail]
[lindex \$L 0] set queue-limit 6
[lindex \$L 1] set queue-limit 6
}
```