rundemo 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. #!/bin/sh
  2. # the next line restarts using wish (on cygwin, use wish84 or the like) \
  3. exec wish "$0" "$@"
  4. #==========================================================================
  5. # DEMO
  6. # part of OMNeT++
  7. #==========================================================================
  8. #--------------------------------------------------------------
  9. # Copyright (C) 1992-2003 Andras Varga
  10. #
  11. # This file is distributed WITHOUT ANY WARRANTY. See the file
  12. # `license' for details on this and other legal matters.
  13. #--------------------------------------------------------------
  14. #
  15. # Configuration
  16. #
  17. set wantScrollbar 1
  18. set unixbrowser "firefox"
  19. #set unixbrowser "mozilla"
  20. #set unixbrowser "konqueror"
  21. #set unixbrowser "netscape"
  22. #
  23. # title line: {"title"}
  24. # program line: {"name" "directory" "unix-command" "windows-command"}
  25. # readme line: {"name" "readme-file"}
  26. # docu line: {"name" "readme-file" "html-file"}
  27. # separator: {}
  28. #
  29. set i 0
  30. set first ""
  31. foreach line {
  32. {"INET Framework"}
  33. {"About..." "README" "../doc/index.html"}
  34. {"Ethernet"}
  35. {"ARP Test" "ethernet/arptest" "./run" "run"}
  36. {"ARP Test 2" "ethernet/arptest2" "./run" "run"}
  37. {"LANs: mixed Ethernet" "ethernet/lans" "./run mixed.ini" "run mixed.ini"}
  38. {"LANs: Ethernet bus" "ethernet/lans" "./run bus.ini" "run bus.ini"}
  39. {"LANs: hub" "ethernet/lans" "./run hub.ini" "run hub.ini"}
  40. {"LANs: switch" "ethernet/lans" "./run switch.ini" "run switch.ini"}
  41. {"LANs: duplexswitch" "ethernet/lans" "./run duplexswitch.ini" "run duplexswitch.ini"}
  42. {"LANs: two hosts" "ethernet/lans" "./run twoHosts.ini" "run twoHosts.ini"}
  43. {"LANs: very large LAN" "ethernet/lans" "./run largeNet.ini" "run largeNet.ini"}
  44. {"INET"}
  45. {"NClients/Telnet" "inet/nclients" "./run" "run"}
  46. {"NClients/HTTP" "inet/nclients" "./run basicHTTP.ini" "run basicHTTP.ini"}
  47. {"NClients/file transfer" "inet/nclients" "./run filetransfer.ini" "run filetransfer.ini"}
  48. {"FlatNet" "inet/flatnet" "./run" "run"}
  49. {"KIDSNw1" "inet/kidsnw1" "./run" "run"}
  50. {"Multicast" "inet/multicast" "./run" "run"}
  51. {"RouterPerf" "inet/routerperf" "./run" "run"}
  52. {"BulkTransfer" "inet/bulktransfer" "./run" "run"}
  53. {"RedTest" "inet/redtest" "./run" "run"}
  54. {"TcpSack" "inet/tcpsack" "./run" "run"}
  55. {"TcpTimestamps" "inet/tcptimestamps" "./run" "run"}
  56. {"TcpWindowScale" "inet/tcpwindowscale" "./run" "run"}
  57. {"TcpClientServer" "inet/tcpclientserver" "./run" "run"}
  58. {"BER" "inet/ber" "./run" "run"}
  59. {"IPv6 (work in progress)"}
  60. {"NClients" "ipv6/nclients" "./run" "run"}
  61. {"DemoNetworkEth" "ipv6/demonetworketh" "./run" "run"}
  62. {"Mobile IPv6" "ipv6/mobileipv6" "./run" "run"}
  63. {"SCTP"}
  64. {"NClients" "sctp/nclients" "./run" "run"}
  65. {"Multi-homing" "sctp/multihomed" "./run" "run"}
  66. {"Emulation"}
  67. {"Traceroute" "emulation/traceroute" "./run" "run"}
  68. {"ExtClient" "emulation/extclient" "./run" "run"}
  69. {"ExtServer" "emulation/extserver" "./run" "run"}
  70. {"Ad-hoc"}
  71. {"Mobility models" "adhoc/mobility" "./run" "run"}
  72. {"802.11b ad-hoc" "adhoc/ieee80211" "./run" "run"}
  73. {"802.11b ad-hoc (MF impl.)" "adhoc/mf80211" "./run" "run"}
  74. {"Wireless"}
  75. {"802.11 AP and hosts" "wireless/lan80211" "./run" "run"}
  76. {"802.11 handover" "wireless/handover" "./run" "run"}
  77. {"802.11 thruput test" "wireless/throughput" "./run" "run"}
  78. {"802.11 thruput test 2" "wireless/hosttohost" "./run" "run"}
  79. {"MPLS/RSVP-TE"}
  80. {"TestTE/failure" "mpls/testte_failure" "./run" "run"}
  81. {"TestTE/reroute" "mpls/testte_reroute" "./run" "run"}
  82. {"TestTE/routing" "mpls/testte_routing" "./run" "run"}
  83. {"TestTE/tunnel " "mpls/testte_tunnel" "./run" "run"}
  84. {"LDP/test" "mpls/ldp" "./run" "run"}
  85. {"Net37" "mpls/net37" "./run" "run"}
  86. {"OSPFv2"}
  87. {"SimpleTest" "ospfv2/simpletest" "./run" "run"}
  88. {"Areas" "ospfv2/areas" "./run" "run"}
  89. {"Backbone" "ospfv2/backbone" "./run" "run"}
  90. {"FullTest" "ospfv2/fulltest" "./run" "run"}
  91. } {
  92. lappend samples $i
  93. if {[llength $line]==0} {
  94. set db($i,type) "spacer"
  95. } elseif {[llength $line]==1} {
  96. set db($i,type) "heading"
  97. set db($i,title) [lindex $line 0]
  98. } elseif {[llength $line]==2} {
  99. set db($i,type) "readme"
  100. set db($i,title) [lindex $line 0]
  101. set db($i,readme) [lindex $line 1]
  102. if {$first==""} {set first $i}
  103. } elseif {[llength $line]==3} {
  104. set db($i,type) "docu"
  105. set db($i,title) [lindex $line 0]
  106. set db($i,readme) [lindex $line 1]
  107. set db($i,docu) [lindex $line 2]
  108. if {$first==""} {set first $i}
  109. } elseif {[llength $line]==4} {
  110. set db($i,type) "program"
  111. set db($i,title) [lindex $line 0]
  112. set db($i,dir) [lindex $line 1]
  113. set db($i,uprog) [lindex $line 2]
  114. set db($i,wprog) [lindex $line 3]
  115. if {$first==""} {set first $i}
  116. } else {
  117. tk_messageBox -title {Error} -type ok -icon error -message "Error in table: wrong #items in {$line}"
  118. exit
  119. }
  120. incr i
  121. }
  122. proc createWindow {} {
  123. global wantScrollbar samples first db fonts colors
  124. wm focusmodel . passive
  125. wm minsize . 1 1
  126. wm overrideredirect . 0
  127. wm resizable . 1 1
  128. wm deiconify .
  129. wm title . "OMNeT++ Demo Simulations"
  130. wm protocol . WM_DELETE_WINDOW {exit}
  131. wm geometry . "650x400"
  132. #################################
  133. # Menu bar
  134. #################################
  135. menu .menubar
  136. . config -menu .menubar
  137. # Create menus
  138. foreach i {
  139. {filemenu -label File -underline 0}
  140. {helpmenu -label Help -underline 0}
  141. } {
  142. eval .menubar add cascade -menu .menubar.$i
  143. menu ".menubar.[lindex $i 0]" -tearoff 0
  144. }
  145. # File menu
  146. foreach i {
  147. {command -command exit -label Exit -underline 1}
  148. } {
  149. eval .menubar.filemenu add $i
  150. }
  151. # Help menu
  152. foreach i {
  153. {command -command helpAbout -label {About OMNeT++} -underline 0}
  154. } {
  155. eval .menubar.helpmenu add $i
  156. }
  157. #################################
  158. # Create main display area
  159. #################################
  160. frame .sel -bd 2 -relief groove
  161. frame .main -bd 2 -relief groove
  162. pack .sel -expand 0 -fill y -side left -padx 2
  163. pack .main -expand 1 -fill both -side right -padx 2
  164. frame .main.up
  165. frame .main.lo
  166. frame .main.mid
  167. pack .main.up -expand 0 -fill x -side top
  168. pack .main.lo -expand 0 -fill x -side bottom
  169. pack .main.mid -expand 1 -fill both -side top
  170. label .main.up.banner -bg $colors(banner) -relief groove -font $fonts(bold)
  171. pack .main.up.banner -fill x -side top
  172. text .main.mid.text -yscrollcommand ".main.mid.sb set" -width 80 -height 20 -wrap none
  173. scrollbar .main.mid.sb -command ".main.mid.text yview"
  174. pack .main.mid.sb -anchor center -expand 0 -fill y -side right
  175. pack .main.mid.text -anchor center -expand 1 -fill both -side left
  176. button .main.lo.start -font $fonts(bold) -bg $colors(startbutton)
  177. pack .main.lo.start -expand 1 -fill x -padx 10 -pady 6
  178. canvas .sel.c -width 200
  179. pack .sel.c -side left -expand yes -fill both
  180. if {$wantScrollbar} {
  181. .sel.c config -yscrollcommand ".sel.s set"
  182. scrollbar .sel.s -command ".sel.c yview"
  183. pack .sel.s -side right -fill y
  184. }
  185. frame .sel.c.f
  186. .sel.c create window 0 0 -anchor nw -window .sel.c.f
  187. set f .sel.c.f
  188. #label $f.banner -text "Sample simulations:" -bg $colors(banner) -relief groove -font $fonts(bold)
  189. #pack $f.banner -fill x -side top
  190. foreach i $samples {
  191. if {$db($i,type)=="spacer"} {
  192. frame $f.$i -relief flat
  193. pack $f.$i -fill x -side top -pady 5
  194. } elseif {$db($i,type)=="heading"} {
  195. label $f.$i -text $db($i,title) -bg $colors(banner) -relief groove -font $fonts(bold)
  196. pack $f.$i -fill x -side top -padx 5 -pady 5
  197. } elseif {$db($i,type)=="readme" || $db($i,type)=="docu" || $db($i,type)=="program"} {
  198. button $f.$i -text $db($i,title) -bd 1 -command "showDemo $i"
  199. pack $f.$i -fill x -side top -padx 5 -pady 2
  200. } else {
  201. tk_messageBox -title {Error} -type ok -icon error -message "internal error: wrong type '$db($i,type)'"
  202. exit
  203. }
  204. }
  205. update
  206. .sel.c config -width [winfo width .sel.c.f]
  207. .sel.c config -scrollregion "0 0 0 [winfo height .sel.c.f]"
  208. showDemo $first
  209. }
  210. proc helpAbout {} {
  211. tk_messageBox -title {About} -type ok -icon info -message {Demo simulations for OMNEST/OMNeT++.}
  212. }
  213. proc showDemo {sample} {
  214. global samples db colors tcl_platform
  215. set f .sel.c.f
  216. foreach i $samples {
  217. if {$db($i,type)=="readme" || $db($i,type)=="docu" || $db($i,type)=="program"} {
  218. $f.$i config -relief raised -bg $colors(unselbutton)
  219. }
  220. }
  221. $f.$sample config -relief sunken -bg $colors(selbutton)
  222. if {$db($sample,type)=="readme"} {
  223. .main.up.banner config -text "$db($sample,title)"
  224. pack forget .main.lo
  225. loadFile .main.mid.text $db($sample,readme)
  226. } elseif {$db($sample,type)=="docu"} {
  227. .main.up.banner config -text "$db($sample,title)"
  228. .main.lo.start config -text "Open documentation\n($db($sample,docu))"
  229. .main.lo.start config -command "openDocu $sample"
  230. pack forget .main.lo
  231. pack .main.lo -expand 0 -fill x -side bottom -before .main.mid
  232. loadFile .main.mid.text $db($sample,readme)
  233. } elseif {$db($sample,type)=="program"} {
  234. if {$tcl_platform(platform)=="unix"} {
  235. set cmd "cd $db($sample,dir); $db($sample,uprog)"
  236. } else {
  237. set cmd "cd $db($sample,dir); $db($sample,wprog)"
  238. }
  239. .main.up.banner config -text "$db($sample,title) README"
  240. .main.lo.start config -text "Launch $db($sample,title)\n($cmd)"
  241. .main.lo.start config -command "runSample $sample"
  242. pack forget .main.lo
  243. pack .main.lo -expand 0 -fill x -side bottom -before .main.mid
  244. loadFile .main.mid.text "$db($sample,dir)/README"
  245. } else {
  246. tk_messageBox -title {Error} -type ok -icon error -message "internal error: wrong type '$db($sample,type)'"
  247. exit
  248. }
  249. }
  250. proc loadFile {t filename} {
  251. $t delete 1.0 end
  252. if [catch {
  253. # try with ".txt" suffix as well
  254. if [catch {set f [open $filename r]}] {set f [open "$filename.txt" r]}
  255. set contents [read $f]
  256. close $f
  257. } err] {
  258. #tk_messageBox -title {OMNeT++ Demo} -type ok -icon error -message "Cannot display README: $err"
  259. return
  260. }
  261. $t insert end $contents
  262. $t mark set insert 1.0
  263. }
  264. proc runSample {sample} {
  265. global samples db tcl_platform
  266. if {$tcl_platform(platform) == "unix"} {
  267. set prog $db($sample,uprog)
  268. } else {
  269. set prog "cmd /c $db($sample,wprog)"
  270. }
  271. set pwd [pwd]
  272. if [catch {
  273. cd $db($sample,dir)
  274. #exec $prog &
  275. #exec [lindex $prog 0] [lindex $prog 1] [lrange $prog 2 end] &
  276. eval exec $prog &
  277. } err] {
  278. tk_messageBox -title {OMNeT++ Demo} -type ok -icon error -message "Error running the simulation program: $err"
  279. }
  280. cd $pwd
  281. }
  282. proc openDocu {sample} {
  283. global samples db tcl_platform unixbrowser
  284. if [catch {
  285. if {$tcl_platform(platform) == "windows"} {
  286. exec cmd.exe /c start $db($sample,docu)
  287. } else {
  288. exec $unixbrowser $db($sample,docu) &
  289. }
  290. } err] {
  291. tk_messageBox -title {OMNeT++ Demo} -type ok -icon error -message "Error running the simulation program: $err"
  292. }
  293. }
  294. #===================================================================
  295. # GENERIC BINDINGS
  296. #===================================================================
  297. proc generic_bindings {} {
  298. bind Button <Return> {tkButtonInvoke %W}
  299. }
  300. #===================================================================
  301. # FONT BINDINGS
  302. #===================================================================
  303. proc font_bindings {} {
  304. global fonts tcl_platform colors
  305. set colors(banner) #e0e0a0
  306. set colors(unselbutton) #c0c0c0
  307. set colors(selbutton) #ffffff
  308. set colors(startbutton) #e0e0a0
  309. #
  310. # fonts() array elements:
  311. # normal: menus, labels etc
  312. # bold: buttons
  313. # icon: toolbar 'icons'
  314. # big: STOP button
  315. # msgname: message name during animation
  316. # fixed: text windows and listboxes
  317. #
  318. if {$tcl_platform(platform) == "unix"} {
  319. set fonts(normal) -Adobe-Helvetica-Medium-R-Normal-*-12-*-*-*-*-*-*-*
  320. set fonts(bold) -Adobe-Helvetica-Bold-R-Normal-*-12-*-*-*-*-*-*-*
  321. set fonts(icon) -Adobe-Times-Bold-I-Normal-*-12-*-*-*-*-*-*-*
  322. set fonts(big) -Adobe-Helvetica-Medium-R-Normal-*-18-*-*-*-*-*-*-*
  323. set fonts(msgname) -Adobe-Helvetica-Medium-R-Normal-*-12-*-*-*-*-*-*-*
  324. set fonts(fixed) fixed
  325. set fonts(balloon) -Adobe-Helvetica-Medium-R-Normal-*-12-*-*-*-*-*-*-*
  326. } else {
  327. # Windows, Mac
  328. set fonts(normal) -Adobe-Helvetica-Medium-R-Normal-*-*-140-*-*-*-*-*-*
  329. set fonts(bold) -Adobe-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
  330. set fonts(icon) -Adobe-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
  331. set fonts(big) -Adobe-Helvetica-Medium-R-Normal-*-*-180-*-*-*-*-*-*
  332. set fonts(msgname) -Adobe-Helvetica-Medium-R-Normal-*-*-140-*-*-*-*-*-*
  333. set fonts(fixed) FixedSys
  334. set fonts(balloon) -Adobe-Helvetica-Medium-R-Normal-*-*-140-*-*-*-*-*-*
  335. }
  336. if {$tcl_platform(platform) == "unix"} {
  337. option add *Scrollbar.width 12
  338. option add *Menubutton.font $fonts(normal)
  339. option add *Menu.font $fonts(normal)
  340. option add *Label.font $fonts(normal)
  341. option add *Entry.font $fonts(normal)
  342. option add *Listbox.font $fonts(fixed)
  343. option add *Text.font $fonts(fixed)
  344. option add *Button.font $fonts(bold)
  345. }
  346. }
  347. proc checkVersion {} {
  348. global tk_version tk_patchLevel
  349. catch {package require Tk}
  350. if {$tk_version<8.0} {
  351. wm deiconify .
  352. wm title . "Bad news..."
  353. frame .f
  354. pack .f -expand 1 -fill both -padx 2 -pady 2
  355. label .f.l1 -text "Your version of Tcl/Tk is too old!"
  356. label .f.l2 -text "Tcl/Tk 8.0 or later required."
  357. button .f.b -text "OK" -command {exit}
  358. pack .f.l1 .f.l2 -side top -padx 5
  359. pack .f.b -side top -pady 5
  360. focus .f.b
  361. wm protocol . WM_DELETE_WINDOW {exit}
  362. tkwait variable ok
  363. }
  364. if {[string compare $tk_patchLevel "8.0p1"]<0} {
  365. tk_messageBox -title {Warning} -type ok -icon warning \
  366. -message {Old Tcl/Tk version. At least 8.0p1 is strongly recommended!}
  367. }
  368. }
  369. set tk_strictMotif 1
  370. cd [file dirname [info script]]
  371. checkVersion
  372. generic_bindings
  373. font_bindings
  374. createWindow