#!/usr/bin/perl # Program to convert a inet topology to ns format # Usage: inet2ns < inet.topo > ns.topo # Usage in ns : source ns.topo in your tcl script and then # call the procedure to create the topology using # create-topology linkbw [scaling factor for delay] # Assumptions: Eucliedian distance between the nodes is in miles. # Hence propogation delay = distance / speed of light (186 x 10^3 miles/sec) #Read first line for number of nodes and links chomp(\$line = ); (\$nodes, \$links) = split(' ',\$line); print "proc create-topology { linkBW {sf 1} } {\n"; print "\tglobal ns\n"; print "\n\t#Create \$nodes nodes in the topology\n"; print "\tfor {set i 0} {\\$i < \$nodes} {incr i} {\n"; print "\t\tset n(\\$i) [\\$ns node]\n"; print "\t}\n\n\n"; print "\t#Create \$links edges in the topology\n"; #Skip all the location information for (\$i=0; \$i<\$nodes;\$i++){ \$line = ; \$ref->[\$i] = 0; } for (\$i=0;\$i<\$links;\$i++){ chomp(\$line=); (\$n1, \$n2, \$delay) = split(' ', \$line); \$ref->[\$n1]++; \$ref->[\$n2]++; \$delay = \$delay / 186; printf("\t\\$ns duplex-link \\$n(%d) \\$n(%d) \\$linkBW [expr \\$sf * %.3f]ms DropTail\n",\$n1,\$n2,\$delay); } print "\n}\n";