📄 ospf_sim.tcl
字号:
################################################################ OSPFD routing simulator# Copyright (C) 1998, 1999 by John T. Moy# # This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.###############################################################global {node_att}global {routers}global {router_att}global {areas}global {area_att}global {port_index}global {networks}global {network_att}global {interface_index}global {ifc_att}global {vlink_index}global {vlink_att}global {aggregate_index}global {aggr_att}global {route_index}global {route_att}global {host_index}global {host_att}global {neighbor_index}global {nbr_att}global {vlinks}global {sessions}global {session_ids}global {random_refresh_flag}set routers {}set areas {}set networks {}set vlinks {}set sessions {}set interface_index 0set pplink_index 0set vlink_index 0set aggregate_index 0set route_index 0set host_index 0set neighbor_index 0set port_index 0set session_ids 0set random_refresh_flag 0set PING 0set TRACEROUTE 1set MTRACE 2set DEST_UNREACH 3set TTL_EXPIRED 11############################################################## Commands that can be present in the simulation# configuration file:# router %rtr_id %x %y %mospf# host %rtr_id %x %y# interface %rtr_id %addr %cost %passive %run_ospf# broadcast %prefix %area %x %y# nbma %prefix %area %x %y# ptmp %prefix %area %x %y# pplink %rtr_id1 %addr1 %cost1 %rtr_id2 %addr2 %cost2 %area# vlink %rtr_id1 %rtr_id2 %area# drpri %rtr_id %addr %priority# aggr %rtr_id %area %prefix %noadv# stub %area %default_cost %import# extrt %rtr_id %prefix %nh %etype %cost %noadv# loopback %rtr_id %prefix %area# neighbor %rtr_id %addr %drpri# membership %prefix %group# PPAdjLimit %rtr_id %nadj## Almost all of these operations can also be accomplished# through the GUI.################################################################proc router {rtr_id x y mospf} { global router_att set router_att($rtr_id,host) 0 set router_att($rtr_id,mospf) $mospf set router_att($rtr_id,PPAdjLimit) 0 router_or_host $rtr_id $x $y}proc host {rtr_id x y} { global router_att set router_att($rtr_id,host) 1 set router_att($rtr_id,mospf) 0 set router_att($rtr_id,PPAdjLimit) 0 router_or_host $rtr_id $x $y}proc router_or_host {rtr_id x y} { global routers router_att node_att if {[lsearch $routers $rtr_id] == -1} { set node_att($rtr_id,interfaces) {} set router_att($rtr_id,areas) {} set router_att($rtr_id,pplinks) {} set router_att($rtr_id,vlinks) {} set router_att($rtr_id,aggrs) {} set router_att($rtr_id,extrts) {} set router_att($rtr_id,hosts) {} set router_att($rtr_id,nbrs) {} } set node_att($rtr_id,x) $x set node_att($rtr_id,y) $y draw_router $rtr_id if {[lsearch $routers $rtr_id] == -1} { lappend routers $rtr_id startrtr $rtr_id }}################################################################ Broadcast, NBMA and Point-to-MultiPoint# networks are are built from the network command.# If the area has not yet been defined, define it# here.###############################################################proc network {prefix area x y demand} { global networks network_att port_index areas area_att node_att if {[lsearch $networks $prefix] != -1} { return 0; } lappend networks $prefix incr port_index set node_att($prefix,x) $x set node_att($prefix,y) $y set node_att($prefix,interfaces) {} set network_att($prefix,port) $port_index set network_att($prefix,type) "broadcast" set network_att($prefix,area) $area set network_att($prefix,demand) $demand set network_att($prefix,groups) {} if {[lsearch $areas $area] == -1} { lappend areas $area set area_att($area,stub) 0 set area_att($area,default_cost) 1 set area_att($area,import) 1 } draw_network $prefix return -1}proc broadcast {prefix area x y demand} { global network_att if {[network $prefix $area $x $y $demand] != -1} { return; } set network_att($prefix,type) "broadcast"}proc nbma {prefix area x y demand} { global network_att if {[network $prefix $area $x $y $demand] != -1} { return; } set network_att($prefix,type) "nbma"}proc ptmp {prefix area x y demand} { global network_att if {[network $prefix $area $x $y $demand] != -1} { return; } set network_att($prefix,type) "ptmp"}################################################################ The interface command is used to define attachments# from a router to a broadcast, NBMA or Point-to-MultiPoint# network.# The network must be defined before# giving this command. The prefix_match command is# implemented in C++, and does the obvious.###############################################################proc interface {rtr_id addr cost passive ospf} { global networks router_att interface_index node_att global network_att ifc_att set net_found 0 foreach prefix $networks { if {[prefix_match $prefix $addr] == 0} { set net_found 1 break; } } if {$net_found == 0} { put_message "Can't find net for $addr" return; } incr interface_index lappend node_att($rtr_id,interfaces) $interface_index lappend node_att($prefix,interfaces) $interface_index set ifc_att($interface_index,port) $network_att($prefix,port) set ifc_att($interface_index,type) $network_att($prefix,type) set ifc_att($interface_index,area) $network_att($prefix,area) set ifc_att($interface_index,addr) $addr set ifc_att($interface_index,prefix) $prefix set ifc_att($interface_index,cost) $cost set ifc_att($interface_index,demand) $network_att($prefix,demand) set ifc_att($interface_index,enabled) 1 set ifc_att($interface_index,passive) $passive set ifc_att($interface_index,drpri) 1 set ifc_att($interface_index,ospf) $ospf set ifc_att($interface_index,rtr) $rtr_id set area $network_att($prefix,area) if {[lsearch $router_att($rtr_id,areas) $area] == -1} { lappend router_att($rtr_id,areas) $area } draw_interface $interface_index $rtr_id $prefix add_mapping $addr $rtr_id add_net_membership $network_att($prefix,port) $rtr_id}################################################################ Point-to-point link between two routers.# If unnumbered, set addr1 and addr2 to 0.0.0.0###############################################################proc pplink {rtr_id1 addr1 cost1 rtr_id2 addr2 cost2 area demand} { global router_att ifc_att interface_index port_index node_att global areas area_att if {[lsearch $areas $area] == -1} { lappend areas $area set area_att($area,stub) 0 set area_att($area,default_cost) 1 set area_att($area,import) 1 } incr interface_index set index1 $interface_index incr port_index lappend node_att($rtr_id1,interfaces) $interface_index set ifc_att($interface_index,oifc) [expr $interface_index+1] set ifc_att($interface_index,ortr) $rtr_id2 set ifc_att($interface_index,port) $port_index set ifc_att($interface_index,type) "pp" set ifc_att($interface_index,area) $area set ifc_att($interface_index,addr) $addr1 set ifc_att($interface_index,prefix) "0.0.0.0/0" set ifc_att($interface_index,cost) $cost1 set ifc_att($interface_index,demand) $demand set ifc_att($interface_index,enabled) 1 set ifc_att($interface_index,passive) 0 set ifc_att($interface_index,drpri) 0 set ifc_att($interface_index,ospf) 1 set ifc_att($interface_index,rtr) $rtr_id1 add_mapping $addr1 $rtr_id1 add_net_membership $port_index $rtr_id1 if {[lsearch $router_att($rtr_id1,areas) $area] == -1} { lappend router_att($rtr_id1,areas) $area } incr interface_index lappend node_att($rtr_id2,interfaces) $interface_index set ifc_att($interface_index,oifc) 0 set ifc_att($interface_index,ortr) $rtr_id1 set ifc_att($interface_index,port) $port_index set ifc_att($interface_index,type) "pp" set ifc_att($interface_index,area) $area set ifc_att($interface_index,addr) $addr2 set ifc_att($interface_index,prefix) "0.0.0.0/0" set ifc_att($interface_index,cost) $cost2 set ifc_att($interface_index,demand) $demand set ifc_att($interface_index,enabled) 1 set ifc_att($interface_index,passive) 0 set ifc_att($interface_index,drpri) 0 set ifc_att($interface_index,ospf) 1 set ifc_att($interface_index,rtr) $rtr_id2 add_mapping $addr2 $rtr_id2 add_net_membership $port_index $rtr_id2 if {[lsearch $router_att($rtr_id2,areas) $area] == -1} { lappend router_att($rtr_id2,areas) $area } draw_pplink $index1 $rtr_id1 $interface_index $rtr_id2}################################################################ Virtual link between two routers# Specify router ID of two endpoints and the transit# area.###############################################################proc vlink {rtr_id1 rtr_id2 area} { global router_att vlink_index vlink_att vlinks incr vlink_index lappend router_att($rtr_id1,vlinks) $vlink_index lappend vlinks $vlink_index set vlink_att($vlink_index,area) $area set vlink_att($vlink_index,endpt) $rtr_id2 set vlink_att($vlink_index,end0) $rtr_id1 incr vlink_index lappend router_att($rtr_id2,vlinks) $vlink_index set vlink_att($vlink_index,area) $area set vlink_att($vlink_index,endpt) $rtr_id1}################################################################ Set DR priority of a given interface, identified# by the router's Router ID and the interface's address###############################################################proc drpri {rtr_id addr priority} { global ifc_att node_att foreach i $node_att($rtr_id,interfaces) { if {$ifc_att($i,addr) == $addr} { set ifc_att($i,drpri) $priority } }}################################################################ Address aggregation in an area border router# Last argument says whether to advertise (noadv=0)# or suppress the aggregate,###############################################################proc aggr {rtr_id area prefix noadv} { global router_att aggregate_index aggr_att incr aggregate_index lappend router_att($rtr_id,aggrs) $aggregate_index set aggr_att($aggregate_index,area) $area set aggr_att($aggregate_index,prefix) $prefix set aggr_att($aggregate_index,noadv) $noadv}################################################################ Configure an area as a stub# Must specify default cost to advertise,# and whether to import summary-LSAs.###############################################################proc stub {area default_cost import} { global areas area_att if {[lsearch $areas $area] == -1} { lappend areas $area } set area_att($area,stub) 1 set area_att($area,default_cost) $default_cost set area_att($area,import) $import}################################################################ Add an external route.# To be advertised by a specific router.###############################################################proc extrt {rtr_id prefix nh etype cost noadv} { global router_att route_index route_att incr route_index lappend router_att($rtr_id,extrts) $route_index set route_att($route_index,prefix) $prefix set route_att($route_index,nh) $nh set route_att($route_index,etype) $etype set route_att($route_index,cost) $cost set route_att($route_index,noadv) $noadv}################################################################ Add a loopback address. Area that the# address belongs to is specified, but the# cost is assumed to be 0.###############################################################proc loopback {rtr_id prefix area} { global router_att host_index host_att incr host_index lappend router_att($rtr_id,hosts) $host_index set host_att($host_index,prefix) $prefix set host_att($host_index,area) $area add_mapping $prefix $rtr_id}################################################################ Add a statically configured neighbor.# Used on NBMA or non-broadcast interfaces.# DR priority (really, whether it is non-zero)# must also be specified.###############################################################proc neighbor {rtr_id addr drpri} { global router_att neighbor_index nbr_att incr neighbor_index lappend router_att($rtr_id,nbrs) $neighbor_index set nbr_att($neighbor_index,addr) $addr set nbr_att($neighbor_index,drpri) $drpri}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -