📄 ospf_sim.tcl
字号:
pack $w.fb -side bottom -fill x pack $w.f0 -fill x label $w.f0.id -text "Interface address : " pack $w.f0.id -side left entry $w.f0.id_e -width 20 -textvariable add_interface_addr pack $w.f0.id_e -side right pack $w.f1 -fill x label $w.f1.id -text "Interface Cost : " pack $w.f1.id -side left entry $w.f1.id_e -width 20 -textvariable add_interface_cost pack $w.f1.id_e -side right set add_interface_ospf 1 checkbutton $w.passive -text "passive" -variable add_interface_passive checkbutton $w.ospf -text "OSPF enabled" -variable add_interface_ospf pack $w.passive $w.ospf -side top button $w.fb.ok -text "OK" -command [list add_interface_complete $w] button $w.fb.quit -text "Quit" -command [list destroy $w] pack $w.fb.quit $w.fb.ok -side left -expand 1}proc add_interface_complete {w} { global add_interface_router add_interface_addr global add_interface_cost interface_index ifc_att global add_interface_passive add_interface_ospf destroy $w put_message "interface $add_interface_router $add_interface_addr $add_interface_cost $add_interface_passive $add_interface_ospf" interface $add_interface_router $add_interface_addr $add_interface_cost \ $add_interface_passive $add_interface_ospf set i $interface_index sendifc $add_interface_router $ifc_att($i,port) $ifc_att($i,type) \ $ifc_att($i,area) $ifc_att($i,addr) $ifc_att($i,cost) \ $i $ifc_att($i,prefix) $ifc_att($i,demand) $ifc_att($i,enabled) \ $ifc_att($i,passive) $ifc_att($i,ospf) $ifc_att($i,drpri)}################################################################ Add a point-to-point interface# Takes place in the following steps# AddPP - clicks on router #1# add_PP_menu - inputs parameters (address, cost)# AddPP - clicks on router #2# add_PP_menu - inputs parameters (address, cost)# add_PP_complete - finishes up###############################################################proc AddPP {rtrno w} { global add_pp_rtrno set add_pp_rtrno $rtrno put_message "Double left click on router no. $rtrno" .map bind rtr <Double-Button-1> { global node_binding set curNode [.map find withtag current] add_PP_menu $node_binding($curNode) } if {$rtrno == 2} { destroy $w }}proc add_PP_menu {id} { global add_pp_rtrno add_pp_router1 add_pp_router2 global add_pp_addr1 add_pp_addr2 global add_pp_cost1 add_pp_cost2 global add_pp_area add_pp_demand .map bind rtr <Double-Button-1> {} put_message "" set w .addinterface toplevel $w wm title $w "Add Point-to-Point interface" if {$add_pp_rtrno == 1} { set add_pp_router1 $id set rtr $add_pp_router1 set cmd [list AddPP 2 $w] } else { set add_pp_router2 $id set rtr $add_pp_router2 set cmd [list add_PP_complete $w] } label $w.hdr -wraplength 2i -justify left -text "You are adding a point-to-point interface on router $rtr." pack $w.hdr -side top frame $w.f0 frame $w.f1 frame $w.f2 pack $w.f2 -side bottom -fill x pack $w.f0 -fill x label $w.f0.id -text "Interface address : " pack $w.f0.id -side left entry $w.f0.id_e -width 20 -textvariable add_pp_addr$add_pp_rtrno pack $w.f0.id_e -side right pack $w.f1 -fill x label $w.f1.id -text "Interface Cost : " pack $w.f1.id -side left entry $w.f1.id_e -width 20 -textvariable add_pp_cost$add_pp_rtrno pack $w.f1.id_e -side right if {$add_pp_rtrno == 1} { frame $w.f3 pack $w.f3 -fill x label $w.f3.id -text "Area ID : " pack $w.f3.id -side left entry $w.f3.id_e -width 20 -textvariable add_pp_area pack $w.f3.id_e -side right checkbutton $w.demand -text "Demand link" -variable add_pp_demand pack $w.demand -side top -pady 2 -anchor e } button $w.f2.ok -text "OK" -command $cmd button $w.f2.quit -text "Quit" -command [list destroy $w] pack $w.f2.quit $w.f2.ok -side left -expand 1}proc add_PP_complete {w} { global add_pp_router1 add_pp_router2 global add_pp_addr1 add_pp_addr2 global add_pp_cost1 add_pp_cost2 global add_pp_area add_pp_demand global interface_index ifc_att destroy $w put_message "pplink $add_pp_router1 $add_pp_addr1 $add_pp_cost1 $add_pp_router2 $add_pp_addr2 $add_pp_cost2 $add_pp_area $add_pp_demand" pplink $add_pp_router1 $add_pp_addr1 $add_pp_cost1 $add_pp_router2 $add_pp_addr2 $add_pp_cost2 $add_pp_area $add_pp_demand set i [expr $interface_index-1] sendifc $add_pp_router1 $ifc_att($i,port) $ifc_att($i,type) \ $ifc_att($i,area) $ifc_att($i,addr) $ifc_att($i,cost) \ $i $ifc_att($i,prefix) $ifc_att($i,demand) \ $ifc_att($i,enabled) $ifc_att($i,passive) $ifc_att($i,ospf) \ $ifc_att($i,drpri) incr i sendifc $add_pp_router2 $ifc_att($i,port) $ifc_att($i,type) \ $ifc_att($i,area) $ifc_att($i,addr) $ifc_att($i,cost) \ $i $ifc_att($i,prefix) $ifc_att($i,demand) \ $ifc_att($i,enabled) $ifc_att($i,passive) $ifc_att($i,ospf) \ $ifc_att($i,drpri)}################################################################ Add a static route to a simulated router.###############################################################proc add_static_menu {rtr} { global add_static_router global add_static_prefix add_static_nexth add_static_cost global add_static_type2 add_static_noadv set add_static_router $rtr set w .addstatic toplevel $w wm title $w "Add Static Route" label $w.hdr -wraplength 2i -justify left -text "You are adding a static route on router $add_static_router." pack $w.hdr -side top frame $w.f0 frame $w.f1 frame $w.f2 frame $w.fb pack $w.fb -side bottom -fill x pack $w.f0 -fill x label $w.f0.id -text "IP Prefix : " pack $w.f0.id -side left entry $w.f0.id_e -width 20 -textvariable add_static_prefix pack $w.f0.id_e -side right pack $w.f1 -fill x label $w.f1.id -text "Next Hop Address : " pack $w.f1.id -side left entry $w.f1.id_e -width 20 -textvariable add_static_nexth pack $w.f1.id_e -side right pack $w.f2 -fill x label $w.f2.id -text "Cost : " pack $w.f2.id -side left entry $w.f2.id_e -width 20 -textvariable add_static_cost pack $w.f2.id_e -side right set add_static_type2 1 checkbutton $w.type2 -text "Type 2 metric" -variable add_static_type2 checkbutton $w.noadv -text "Don't advertise" -variable add_static_noadv pack $w.type2 $w.noadv -side top button $w.fb.ok -text "OK" -command [list add_static_complete $w] button $w.fb.quit -text "Quit" -command [list destroy $w] pack $w.fb.quit $w.fb.ok -side left -expand 1}proc add_static_complete {w} { global add_static_router global add_static_prefix add_static_nexth add_static_cost global add_static_type2 add_static_noadv global route_index route_att destroy $w set type2 [expr $add_static_type2+1] put_message "extrt $add_static_router $add_static_prefix $add_static_nexth $type2 $add_static_cost $add_static_noadv" extrt $add_static_router $add_static_prefix $add_static_nexth $type2 $add_static_cost $add_static_noadv set r $route_index sendextrt $add_static_router $route_att($r,prefix) $route_att($r,nh) \ $route_att($r,etype) $route_att($r,cost) $route_att($r,noadv)}################################################################ Toggle the operational status of an interface# Mostly done in C++, here we just have to have# the user click on the router###############################################################proc ToggleInterface {} { put_message "Double left click on interface/link" .map bind ifc <Double-Button-1> { global ifc_binding set curIfc [.map find withtag current] set i $ifc_binding($curIfc) if {$ifc_att($i,enabled) == 0} { set ifc_att($i,enabled) 1 } else { set ifc_att($i,enabled) 0 } redraw_interface $i sendifc $ifc_att($i,rtr) $ifc_att($i,port) $ifc_att($i,type) \ $ifc_att($i,area) $ifc_att($i,addr) $ifc_att($i,cost) \ $i $ifc_att($i,prefix) $ifc_att($i,demand) \ $ifc_att($i,enabled) $ifc_att($i,passive) $ifc_att($i,ospf) \ $ifc_att($i,drpri) put_message "" }}################################################################ Start a ping/traceroute session from a particular router# Query for the destination and TTL###############################################################proc ping {rtrid} { global session_type session_command global PING set session_type $PING set session_command "ping" start_session $rtrid}proc tr {rtrid} { global session_type session_command global TRACEROUTE set session_type $TRACEROUTE set session_command "traceroute" start_session $rtrid}proc start_session {rtrid} { global session_src session_src_addr session_dest session_ttl global session_type session_command bind .map <Button-1> {} put_message "" set session_src $rtrid set session_src_addr "0.0.0.0" set session_ttl "64" set w .session_menu toplevel $w wm title $w "Start $session_command on $rtrid" frame $w.f0 frame $w.f1 frame $w.f2 pack $w.f2 -side bottom -fill x if {$session_command == "ping"} { frame $w.f3 pack $w.f3 -fill x label $w.f3.id -text "Source : " pack $w.f3.id -side left entry $w.f3.id_e -width 20 -textvariable session_src_addr pack $w.f3.id_e -side right } pack $w.f0 -fill x label $w.f0.id -text "Destination : " pack $w.f0.id -side left entry $w.f0.id_e -width 20 -textvariable session_dest pack $w.f0.id_e -side right pack $w.f1 -fill x label $w.f1.id -text "Maximum TTL : " pack $w.f1.id -side left entry $w.f1.id_e -width 3 -textvariable session_ttl pack $w.f1.id_e -side right button $w.f2.ok -text "OK" -command [list ${session_command}_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 ping_menu_complete {w} { global session_src session_src_addr session_dest session_ttl global session_ids session_stats global sec session_menu_complete $w set session_stats($session_ids,src) $session_src set session_stats($session_ids,dest) $session_dest set session_stats($session_ids,start) $sec set session_stats($session_ids,rcvd) 0 put_message "start_ping $session_src $session_src_addr $session_dest $session_ttl $session_ids" start_ping $session_src $session_src_addr $session_dest $session_ttl $session_ids print_session $session_ids "% ping -s $session_src_addr $session_dest \n"}proc traceroute_menu_complete {w} { global session_src session_src_addr session_dest session_ttl session_ids session_menu_complete $w put_message "start_traceroute $session_src $session_src_addr $session_dest $session_ttl $session_ids" start_traceroute $session_src $session_src_addr $session_dest $session_ttl $session_ids print_session $session_ids "% traceroute $session_dest \n"}################################################################ Multicast traceroute. After selecting the router# to run the mtrace, click on the destination network and then# input the source, group, and TTL###############################################################proc mtrace {rtrid} { global session_src global session_type session_command global MTRACE set session_type $MTRACE set session_command "mtrace" set session_src $rtrid put_message "Double left click on destination network" .map bind net <Double-Button-1> { global node_binding set curNode [.map find withtag current] start_mtrace_session $node_binding($curNode) put_message "" .map bind net <Double-Button-1> {} }}proc start_mtrace_session {cidr} { global session_src session_src_addr session_dest global session_type session_command mtrace_group mtrace_cidr bind .map <Button-1> {} put_message "" set mtrace_cidr $cidr set w .session_menu toplevel $w wm title $w "Start mtrace on $session_src" frame $w.f0 frame $w.f1 frame $w.f2 pack $w.f2 -side bottom -fill x frame $w.f3 pack $w.f3 -fill x label $w.f3.id -text "Source : " pack $w.f3.id -side left entry $w.f3.id_e -width 20 -textvariable session_src_addr pack $w.f3.id_e -side right pack $w.f0 -fill x label $w.f0.id -text "Multicast Group : " pack $w.f0.id -side left entry $w.f0.id_e -width 20 -textvariable mtrace_group pack $w.f0.id_e -side right button $w.f2.ok -text "OK" -command [list mtrace_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 mtrace_menu_complete {w} { session_menu_complete $w global session_src session_src_addr session_ids global session_type session_command mtrace_group mtrace_cidr global network_att put_message "start_mtrace $session_src $session_src_addr $mtrace_cidr $mtrace_group $session_ids $network_att($mtrace_cidr,port)" start_mtrace $session_src $session_src_addr $mtrace_cidr $mtrace_group $session_ids $network_att($mtrace_cidr,port) print_session $session_ids "% mtrace $session_src_addr $mtrace_cidr $mtrace_group \n"}proc session_menu_complete {w} { global session_src session_src_addr session_dest session_ttl global session_ids global sessions session_attr global session_type session_command session_group destroy $w incr session_ids lappend sessions $session_ids set session_attr($session_ids,type) $session_type set w .session$session_ids toplevel $w wm title $w "Router $session_src" frame $w.f1 frame $w.f2 text $w.f1.text -relief raised -bd 2 -yscrollcommand "$w.f1.scroll set" scrollbar $w.f1.scroll -command "$w.f1.text yview" button $w.f2.stop -text "Stop" -command [list sess_summ $session_ids] pack $w.f1 -side top -expand 1 -fill both pack $w.f2 -side bottom -fill x pack $w.f1.scroll -side right -fill y pack $w.f1.text -side left pack $w.f2.stop -side right}################################################################ Summarize the ping session, and then stop it###############################################################proc ping_reply {s_id src seq ttl milli} { global session_stats session_attr PING
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -