⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf_sim.tcl

📁 BCAST Implementation for NS2
💻 TCL
📖 第 1 页 / 共 4 页
字号:
    if {$session_attr($s_id,type) != $PING} {	return    }    incr session_stats($s_id,rcvd)    print_session $s_id "Echo Reply from $src, icmp_seq=$seq, ttl=$ttl, time=$milli ms\n"}################################################################ Summarize the ping session, and then stop it###############################################################proc sess_summ {s_id} {    global sessions session_stats session_attr    global sec    global PING    if {$session_attr($s_id,type) != $PING} {	return    }    print_session $s_id "\n"    print_session $s_id "---- $session_stats($s_id,dest) ping statistics ----\n"    set x [expr $sec-$session_stats($s_id,start)]    print_session $s_id "Duration: $x seconds, Responses received: $session_stats($s_id,rcvd) \n"    set i [lsearch $sessions $s_id]    set sessions [lreplace $sessions $i $i]    stop_ping $session_stats($s_id,src) $s_id}################################################################ Process ICMP errors received for a particular session# Could be for a ping, or for a traceroute.###############################################################proc icmp_error {s_id src type code milli} {    global sessions session_attr    global PING DEST_UNREACH TTL_EXPIRED TRACEROUTE    if {[lsearch $sessions $s_id] == -1} {	return;    }    if {$session_attr($s_id,type) == $PING} {	if {$type == $DEST_UNREACH} {	    print_session $s_id "Destination unreachable from $src \n"	}	if {$type == $TTL_EXPIRED} {	    print_session $s_id "TTL expired from $src \n"	}    }    if {$session_attr($s_id,type) == $TRACEROUTE} {	if {$session_attr($s_id,response_from) != $src} {	    set session_attr($s_id,response_from) $src	    print_session $s_id " $src"	}	print_session $s_id " $milli ms"	if {$type == $DEST_UNREACH} {	    print_session $s_id " !H"	}    }}############################################################### New set of probes are being sent for a traceroute.# Display the TTL, and clear the response address so that# a new one will be displayed.##############################################################proc traceroute_ttl {s_id ttl} {    global sessions session_attr    if {[lsearch $sessions $s_id] == -1} {	return;    }    set session_attr($s_id,response_from) "0.0.0.0"    set msg [format "\n%2d " $ttl]    print_session $s_id $msg}################################################################ Log ping/traceroute stats into a scrolling text window###############################################################proc print_session {s_id str} {    global sessions    if {[lsearch $sessions $s_id] == -1} {	return;    }    set w .session$s_id    $w.f1.text insert end "$str"    $w.f1.text yview moveto 1.0}################################################################ Select a router using the mouse,# and then execute the specified command###############################################################proc Group {join} {    global group_cmd    put_message "Double left click on network"    set group_cmd $join    .map bind net <Double-Button-1> {	global node_binding	set curNode [.map find withtag current]	GroupMenu $node_binding($curNode)	put_message ""	.map bind net <Double-Button-1> {}    }}proc GroupMenu {cidr} {    global group_cmd group_addr source_net    set w .group_menu    toplevel $w    set source_net $cidr    if {$group_cmd == 0} {	wm title $w "Join group on $cidr"    } else {	wm title $w "Leave group on $cidr"    }    frame $w.f0    frame $w.f2    pack $w.f2 -side bottom -fill x    pack $w.f0 -fill x    label $w.f0.id -text "Group :      "    pack  $w.f0.id -side left    entry $w.f0.id_e -width 20 -textvariable group_addr    pack  $w.f0.id_e -side right    button $w.f2.ok -text "OK" -command [list group_menu_complete $w]    button $w.f2.quit -text "Quit" -command [list destroy $w]    pack $w.f2.quit $w.f2.ok -side left -expand 1}proc group_menu_complete {w} {    global group_cmd group_addr source_net    global network_att node_att ifc_att    destroy $w    set prefix $source_net    if {$group_cmd == 0} {	if {[lsearch $network_att($prefix,groups) $group_addr] != -1} {	    return	}	lappend network_att($prefix,groups) $group_addr	set command "sendgrp"    } else {	if {[lsearch $network_att($prefix,groups) $group_addr] == -1} {	    return	}	set j [lsearch $network_att($prefix,groups) $group_addr]	set network_att($prefix,groups) [lreplace $network_att($prefix,groups) $j $j]	set command "leavegrp"    }    foreach i $node_att($prefix,interfaces) {	set rtr_id $ifc_att($i,rtr)	$command $rtr_id $group_addr $ifc_att($i,port)    }}################################################################ Color a router a particular color###############################################################proc color_router {id color} {    .map itemconfigure rtrbox$id -fill $color}################################################################ Quit the simulation###############################################################proc ExitSim {} {    destroy .}################################################################ Store the name of the config file###############################################################proc ConfigFile {file} {    global config_file    set config_file $file    wm title . "OSPF Simulator: $file"    .mbar.file entryconfigure "Save" -state normal}################################################################ Save the current map to a new file of the user's choosing###############################################################proc SaveMaptoFile {} {    global config_file new_file    set w .saveas    toplevel $w    wm title $w "Save As"    label $w.hdr -wraplength 2i -justify left -text "Specify the new config file in which to save the map. This file name will also be used in all future save commands."    pack $w.hdr -side top    frame $w.f0    frame $w.f2    pack $w.f2 -side bottom -fill x    pack $w.f0 -fill x    label $w.f0.id -text "New config file :      "    pack  $w.f0.id -side left    entry $w.f0.id_e -width 20 -textvariable new_file    pack  $w.f0.id_e -side right    button $w.f2.ok -text "OK" -command [list SaveAsDone $w]    button $w.f2.quit -text "Quit" -command [list destroy $w]    pack $w.f2.quit $w.f2.ok -side left -expand 1}proc SaveAsDone {w} {    global new_file    destroy $w    ConfigFile $new_file    SaveMap}################################################################ Save the current map to the same file that the user originally# opened, or if specified, the file that the map was saved to# This should mirror the logic in sendcfg{}###############################################################proc SaveMap {} {    global config_file    global routers networks    global router_att area_att ifc_att vlink_att vlinks    global aggr_att route_att host_att nbr_att node_att    global network_att aggr_att route_att nbr_att    global host_att random_refresh_flag    set f [open $config_file w]    if {$random_refresh_flag != 0} {	puts $f "random_refresh"    }    foreach id $routers {	if {$router_att($id,host) == 0} {	    puts $f [concat "router" $id $node_att($id,x) $node_att($id,y) \		    $router_att($id,mospf)]	} else {	    puts $f [concat "host" $id $node_att($id,x) $node_att($id,y) \		    $router_att($id,mospf)]	}	if {$router_att($id,PPAdjLimit) != 0} {	    puts $f [concat "PPAdjLimit" $id $router_att($id,PPAdjLimit)]	}    }    foreach net $networks {	if {$network_att($net,type) == "broadcast"} {	    puts $f [concat "broadcast" $net $network_att($net,area) $node_att($net,x) \		    $node_att($net,y) $network_att($net,demand)]	}	if {$network_att($net,type) == "nbma"} {	    puts $f [concat "nbma" $net $network_att($net,area) $node_att($net,x) \		    $node_att($net,y) $network_att($net,demand)]	}	if {$network_att($net,type) == "ptmp"} {	    puts $f [concat "ptmp" $net $network_att($net,area) $node_att($net,x) \		    $node_att($net,y) $network_att($net,demand)]	}	foreach group $network_att($net,groups) {	    puts $f [concat "membership" $net $group]	}    }    foreach id $routers {	foreach ifc $node_att($id,interfaces) {	    if {$ifc_att($ifc,type) != "pp"} {		puts $f [concat "interface" $id $ifc_att($ifc,addr) \			$ifc_att($ifc,cost) $ifc_att($ifc,passive) \			$ifc_att($ifc,ospf)] 		if {$ifc_att($ifc,drpri) != 1} {		    puts $f [concat "drpri" $id $ifc_att($ifc,addr) \			    $ifc_att($ifc,drpri)]		}	    } else {		if {$ifc_att($ifc,oifc) != 0} {		    set oid $ifc_att($ifc,ortr)		    set oifc $ifc_att($ifc,oifc)		    puts $f [concat "pplink" $id $ifc_att($ifc,addr) \			    $ifc_att($ifc,cost) $oid $ifc_att($oifc,addr) \			    $ifc_att($oifc,cost) $ifc_att($ifc,area) \			    $ifc_att($ifc,demand)]		}	    }	}	foreach n $router_att($id,nbrs) {	    puts $f [concat "neighbor" $id $nbr_att($n,addr) \		    $nbr_att($n,drpri)]	}	foreach agg $router_att($id,aggrs) {	    puts $f [concat "aggr" $id $aggr_att($agg,area) \		    $aggr_att($agg,prefix) $aggr_att($agg,noadv)]	}	foreach r $router_att($id,extrts) {	    puts $f [concat "extrt" $id $route_att($r,prefix) \		    $route_att($r,nh) $route_att($r,etype) \		    $route_att($r,cost) $route_att($r,noadv)]	}	foreach h $router_att($id,hosts) {	    puts $f [concat loopback $id $host_att($h,prefix) \		    $host_att($h,area)]	}    }    foreach vl $vlinks {	puts $f [concat vlink $vlink_att($vl,end0) $vlink_att($vl,endpt) \		$vlink_att($vl,area)]    }    close $f}# Add a virtual link, from the graphical interfaceproc AddVL {} {}# main routine# create the map and all the bindingswm title . "OSPF Simulator: *scratch*"wm iconname . "ospf"menu .mbar -tearoff 0menu .mbar.file -tearoff 0.mbar add cascade -label "File" -underline 0 -menu .mbar.file.mbar.file add command -label "Save" -command "SaveMap" -state disabled.mbar.file add command -label "Save As" -command "SaveMaptoFile".mbar.file add command -label "Exit" -command "ExitSim" -underline 0menu .mbar.add -tearoff 0.mbar add cascade -label "Add" -underline 0 -menu .mbar.add.mbar.add add command -label "Router" -command "AddRouter".mbar.add add command -label "Network" -command "AddNetwork".mbar.add add command -label "Interface" -command [list SelectRouter add_interface_menu].mbar.add add command -label "PPlink" -command [list AddPP 1 -1]#.mbar.add add command -label "Neighbor" -command "AddNeighbor".mbar.add add command -label "Virtual Link" -command "AddVL".mbar.add add command -label "Static Route" -command [list SelectRouter add_static_menu]menu .mbar.toggle -tearoff 0.mbar add cascade -label "Router" -underline 0 -menu .mbar.toggle.mbar.toggle add command -label "Toggle" -command [list SelectRouter togglertr].mbar.toggle add command -label "Restart" -command [list SelectRouter rstrtr].mbar.toggle add command -label "Hitless Restart" -command [list SelectRouter hitlessrtr].mbar.toggle add command -label "Toggle Interface" -command "ToggleInterface"menu .mbar.sim.mbar add cascade -label "Simulation" -underline 0 -menu .mbar.sim.mbar.sim add command -label "Resume" -command "time_resume".mbar.sim add command -label "Stop" -command "time_stop" -underline 2menu .mbar.utilities -tearoff 0.mbar add cascade -label "Utilities" -underline 0 -menu .mbar.utilities.mbar.utilities add command -label "Ping" -command [list SelectRouter ping].mbar.utilities add command -label "Traceroute" -command [list SelectRouter tr].mbar.utilities add command -label "MTrace" -command [list SelectRouter mtrace].mbar.utilities add command -label "Join Group" -command [list Group 0].mbar.utilities add command -label "Leave Group" -command [list Group 1]. configure -menu .mbar# then the mapframe .mapgridscrollbar .hscroll -orient horiz -command ".map xview"scrollbar .vscroll -command ".map yview"canvas .map -height 350 -width 600 -scrollregion {0 0 2000 2000} \	-xscrollcommand ".hscroll set" \	-yscrollcommand ".vscroll set"pack .mapgrid -side top -expand 1 -fill bothgrid rowconfig .mapgrid 0 -weight 1 -minsize 0grid columnconfig .mapgrid 0 -weight 1 -minsize 0grid .map -padx 1 -in .mapgrid -pady 1 \	-row 0 -column 0  -rowspan 1 -columnspan 1 -sticky newsgrid .hscroll -padx 1 -in .mapgrid -pady 1 \	-row 1 -column 0  -rowspan 1 -columnspan 1 -sticky newsgrid .vscroll -padx 1 -in .mapgrid -pady 1 \	-row 0 -column 1  -rowspan 1 -columnspan 1 -sticky news# then the messages, and time, at the bottomframe .trailer -relief raised -bd 2pack .trailer -fill xmessage .trailer.message -width 16c -justify left -text "Welcome to the OSPF Simulator!"pack .trailer.message -fill x -side leftlabel .trailer.time -text "Time 0.0"pack .trailer.time -side right# button bindings.map bind node <Button-1> {    set curX %x    set curY %y}.map bind node <B1-Motion> {    global node_binding    set curNode [.map find withtag current]    set id $node_binding($curNode)    move_node $id [expr %x-$curX] [expr %y-$curY]    set curX %x    set curY %y}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -