TODO: implement links that can bind nodes in different canvases.
Bug found by:
Submitted by:
Requested by:
Reviewed by:
Approved by:
Obtained from:
proc removeCanvas { canvas } {
- global canvass $canvas
+ global canvas_list $canvas
- set i [lsearch $canvass $canvas]
- set canvass [lreplace $canvass $i $i]
+ set i [lsearch $canvas_list $canvas]
+ set canvas_list [lreplace $canvas_list $i $i]
set $canvas {}
return
}
proc newCanvas { name } {
- global canvass
+ global canvas_list
- set canvas c0
+ set canvas [newObjectId canvas]
global $canvas
- lappend canvass $canvas
- set $canvas {name default}
+ lappend canvas_list $canvas
+ set $canvas [list "name $name"]
return
}
+
+
+proc getCanvasName { canvas } {
+ global $canvas
+
+ return [lrange [lsearch -inline [set $canvas] "name *"] 1 end]
+}
proc dumpCfg {method dest} {
- global nodes links canvass
+ global node_list link_list canvas_list
global showIfNames showNodeLabels showLinkLabels
global showIfIPaddrs showIfIPv6addrs
- foreach node $nodes {
+ foreach node $node_list {
global $node
upvar 0 $node lnode
dumpputs $method $dest "node $node \{"
dumpputs $method $dest ""
}
- foreach link $links {
+ foreach link $link_list {
global $link
upvar 0 $link llink
dumpputs $method $dest "link $link \{"
dumpputs $method $dest ""
}
- foreach canvas $canvass {
+ foreach canvas $canvas_list {
global $canvas
upvar 0 $canvas lcanvas
dumpputs $method $dest "canvas $canvas \{"
proc loadCfg { cfg } {
- global nodes links canvass
+ global node_list link_list canvas_list
global showIfNames showNodeLabels showLinkLabels
global showIfIPaddrs showIfIPv6addrs
# Cleanup first - this also automatically deletes all associated links
- # XXX remove this - Tk polution!
- foreach node $nodes {
- removeGUINode $node
+ foreach node $node_list {
+ removeNode $node
}
- foreach canvas $canvass {
+ foreach canvas $canvas_list {
removeCanvas $canvas
}
set object $entry
global $object
if {"$class" == "node"} {
- lappend nodes $object
+ lappend node_list $object
}
if {"$class" == "link"} {
- lappend links $object
+ lappend link_list $object
}
if {"$class" == "canvas"} {
- lappend canvass $object
+ lappend canvas_list $object
}
if {"$class" == "option"} {
# for future use
proc newObjectId { type } {
- global nodes links canvass
+ global node_list link_list canvas_list
set mark [string range [set type] 0 0]
set id 0
- while {[lsearch [set [set type]s] "$mark$id"] != -1} {
+ while {[lsearch [set [set type]_list] "$mark$id"] != -1} {
incr id
}
return $mark$id
proc redrawAll {} {
- global nodes links
+ global node_list link_list background sizex sizey
+ global curcanvas
- foreach node $nodes {
- drawNode $node
+ .c delete all
+ set background [.c create rectangle 0 0 $sizex $sizey \
+ -fill white -tags "background"]
+ .c lower $background
+
+ foreach node $node_list {
+ if { [getNodeCanvas $node] == $curcanvas } {
+ drawNode $node
+ }
}
- foreach link $links {
+
+ foreach link $link_list {
+ set nodes [linkPeers $link]
+ if { [getNodeCanvas [lindex $nodes 0]] != $curcanvas ||
+ [getNodeCanvas [lindex $nodes 1]] != $curcanvas } {
+ continue
+ }
drawLink $link
redrawLink $link
updateLinkLabel $link
}
+
+ refreshCanvasMenu
+
return
}
proc redrawAllLinks {} {
- global links
+ global link_list curcanvas
- foreach link $links {
+ foreach link $link_list {
+ set nodes [linkPeers $link]
+ if { [getNodeCanvas [lindex $nodes 0]] != $curcanvas ||
+ [getNodeCanvas [lindex $nodes 1]] != $curcanvas } {
+ continue
+ }
redrawLink $link
}
return
global oper_mode env eid
set node [lindex [$c gettags {node && current}] 1]
- set node_id $eid\_$node
if { $node != "" && $oper_mode == "exec" } {
+ set node_id $eid\_$node
set cmd [[typemodel $node].shellcmd $node]
if { $cmd != "" } {
nexec xterm -sb -rightbar \
proc button1 { c x y button} {
- global nodes curcanvas
+ global node_list curcanvas
global activetool newlink curobj changed def_router_model
global router pc host lanswitch frswitch rj45 hub
global lastX lastY
! ]
}
lappend $node "network-config [list $nconfig]"
- lappend nodes $node
+ lappend node_list $node
setNodeCanvas $node $curcanvas
setNodeCoords $node "$x $y"
set dy 32
proc button1-release { c x y } {
- global links nodes
+ global link_list node_list
global activetool newlink curobj grid
global changed undolog undolevel redolevel selectbox selected
global lastX lastY sizex sizey
}
- foreach link $links {
+ foreach link $link_list {
global $link
if { [$c find withtag "link && $lnode1 && $lnode2"] != "" } {
set regular no
lappend $link "bandwidth $defSerBandwidth"
lappend $link "delay $defSerDelay"
}
- lappend links $link
+ lappend link_list $link
drawLink $link
updateLinkLabel $link
if { $lannode != "" } {
proc linkEnter {c} {
- global activetool links
+ global activetool link_list
set link [lindex [$c gettags current] 1]
- if { [lsearch $links $link] == -1 } {
+ if { [lsearch $link_list $link] == -1 } {
return
}
set line "$link: [getLinkBandwidthString $link] [getLinkDelayString $link]"
proc rearrange { mode } {
- global nodes links autorearrange_enabled sizex sizey
+ global link_list autorearrange_enabled sizex sizey curcanvas
set c .c
set autorearrange_enabled 1
set fy_t($other) [expr $fy_t($other) - $p_fy]
}
- foreach link $links {
+ foreach link $link_list {
+ set nodes [linkPeers $link]
+ if { [getNodeCanvas [lindex $nodes 0]] != $curcanvas ||
+ [getNodeCanvas [lindex $nodes 1]] != $curcanvas } {
+ continue
+ }
set peers [linkPeers $link]
set coords0 [getNodeCoords [lindex $peers 0]]
set coords1 [getNodeCoords [lindex $peers 1]]
.bottom.mbuf config -text ""
}
+
+proc refreshCanvasMenu {} {
+ global canvas_list curcanvas
+
+ .menubar.canvas delete 0 end
+ foreach canvas $canvas_list {
+ .menubar.canvas add radiobutton -label [getCanvasName $canvas] \
+ -command redrawAll -indicatoron true \
+ -value $canvas -variable curcanvas
+ }
+}
proc setOperMode { mode } {
- global oper_mode activetool nodes
+ global oper_mode activetool node_list
global nmbufs nmbclusters
# Verify that links to external interfaces are properly configured
set extifcs [nexec ifconfig -l]
set extifcs \
[lreplace $extifcs [lsearch $extifcs lo0] [lsearch $extifcs lo0]]
- foreach node $nodes {
+ foreach node $node_list {
if { [nodeType $node] == "rj45" } {
set i [lsearch $extifcs [getNodeName $node]]
if { $i < 0 } {
proc deployCfg {} {
global eid
- global nodes links supp_router_models
+ global node_list link_list supp_router_models
global mac_byte4 mac_byte5
set mac_byte4 0
catch { nexec kldload ng_iface }
catch { nexec kldload ng_eiface }
- foreach node $nodes {
+ foreach node $node_list {
set node_id "$eid\_$node"
set type [nodeType $node]
set name [getNodeName $node]
[typemodel $node].instantiate $eid $node
}
- foreach link $links {
+ foreach link $link_list {
statline "Creating link $link"
set lnode1 [lindex [linkPeers $link] 0]
set lnode2 [lindex [linkPeers $link] 1]
catch { nexec cp /dev/null /usr/local/etc/quagga/$file }
}
- foreach node $nodes {
+ foreach node $node_list {
global $node
statline "Configuring node [getNodeName $node]"
set node_id "$eid\_$node"
}
}
- statline "Network topology instantiated in [expr [clock seconds] - $t_start] seconds ([llength $nodes] nodes and [llength $links] links)."
+ statline "Network topology instantiated in [expr [clock seconds] - $t_start] seconds ([llength $node_list] nodes and [llength $link_list] links)."
}
proc linkByIfc { node ifc } {
- global links
+ global link_list
set peer [peerByIfc $node $ifc]
- foreach link $links {
+ foreach link $link_list {
set endpoints [linkPeers $link]
if { $endpoints == "$node $peer" } {
set dir downstream
#
# Global variables are initialized here
#
-
-set eid e0
-
-set nodes {}
-set links {}
+set node_list {}
+set link_list {}
+set canvas_list {}
set prefs {}
-set canvass {}
-newCanvas default
-
-set newlink ""
-set selectbox ""
-set selected ""
-
-set undolevel 0
-set redolevel 0
-set undolog(0) ""
-set changed 0
-set badentry 0
-set cursorState 0
-set clock_seconds 0
-set oper_mode edit
-set grid 24
-set sizex 1024
-set sizey 768
-set curcanvas [lindex $canvass 0]
-set autorearrange_enabled 0
-
-# Some default values
-set defLinkColor red
-set defLinkWidth 2
-set defEthBandwidth 100000000
-set defSerBandwidth 2048000
-set defSerDelay 2500
-set showIfNames 1
-set showIfIPaddrs 1
-set showIfIPv6addrs 1
-set showNodeLabels 1
-set showLinkLabels 1
-
-set supp_router_models "xorp quagga static"
-set def_router_model quagga
+set eid e0
#
#
+#
+# GUI-related global variables
+#
+
+set newlink ""
+set selectbox ""
+set selected ""
+newCanvas default
+
+set undolevel 0
+set redolevel 0
+set undolog(0) ""
+set changed 0
+set badentry 0
+set cursorState 0
+set clock_seconds 0
+set oper_mode edit
+set grid 24
+set sizex 1024
+set sizey 768
+set curcanvas [lindex $canvas_list 0]
+set autorearrange_enabled 0
+
+#
+# Initialize a few variables to default values
+#
+set defLinkColor red
+set defLinkWidth 2
+set defEthBandwidth 100000000
+set defSerBandwidth 2048000
+set defSerDelay 2500
+set showIfNames 1
+set showIfIPaddrs 1
+set showIfIPv6addrs 1
+set showNodeLabels 1
+set showLinkLabels 1
+
+set supp_router_models "xorp quagga static"
+set def_router_model quagga
+
+
#
# Window / canvas setup section
#
-wm minsize . 640 480
+wm minsize . 640 400
wm geometry . 800x600
wm title . IMUNES
.menubar add cascade -label File -underline 0 -menu .menubar.file
.menubar add cascade -label Edit -underline 0 -menu .menubar.edit
-#.menubar add cascade -label Canvas -underline 0 -menu .menubar.canvas
+.menubar add cascade -label Canvas -underline 0 -menu .menubar.canvas
.menubar add cascade -label Tools -underline 0 -menu .menubar.tools
.menubar add cascade -label View -underline 0 -menu .menubar.view
.menubar add cascade -label Experiment -underline 1 -menu .menubar.experiment
.menubar.edit add command -label "Redo" -underline 0 \
-accelerator "Ctrl+Y" -command redo
bind . <Control-y> redo
+.menubar.edit add separator
+.menubar.edit add command -label "New canvas" -underline 0 \
+ -command {
+ newCanvas unnamed
+ refreshCanvasMenu
+ }
#
set c [canvas .c -relief sunken -bd 1 \
-scrollregion "-32 -32 [expr $sizex + 32] [expr $sizey + 32]" \
-xscrollcommand ".hscroll set" -yscrollcommand ".vscroll set"]
-set background [.c create rectangle 0 0 $sizex $sizey \
- -fill white -tags "background"]
-.c lower $background
scrollbar .hscroll -orient horiz -command "$c xview"
scrollbar .vscroll -command "$c yview"
pack .grid -expand yes -fill both -padx 0 -pady 0
$c bind node <Double-1> "popupConfigDialog $c"
$c bind nodelabel <Double-1> "popupConfigDialog $c"
$c bind link <Double-1> "popupConfigDialog $c"
-#$c bind link <Double-3> "startethereal $c"
$c bind link <B3-ButtonRelease> "startethereal $c"
-#$c bind linklabel <Double-3> "startethereal $c"
$c bind linklabel <B3-ButtonRelease> "startethereal $c"
$c bind linklabel <Double-1> "popupConfigDialog $c"
bind $c <1> "button1 $c %x %y none"
bind $c <4> "$c yview scroll 1 units"
bind $c <5> "$c yview scroll -1 units"
+
+#
+# Done with initialization, draw an empty canvas
+#
+refreshCanvasMenu
+redrawAll
proc findFreeIPv4net { mask } {
- global nodes
+ global node_list
set ipnets {}
- foreach node $nodes {
+ foreach node $node_list {
foreach ifc [ifcList $node] {
set ipnet [lrange [split [getIfcIPv4addr $node $ifc] .] 0 2]
if {[lsearch $ipnets $ipnet] == -1} {
proc findFreeIPv6net { mask } {
- global nodes
+ global node_list
set ipnets {}
- foreach node $nodes {
+ foreach node $node_list {
foreach ifc [ifcList $node] {
set ipnet [lrange [split [getIfcIPv6addr $node $ifc] :] 0 3]
if {[lsearch $ipnets $ipnet] == -1} {
proc linkByPeers { node1 node2 } {
- global links
+ global link_list
- foreach link $links {
+ foreach link $link_list {
set peers [linkPeers $link]
if { $peers == "$node1 $node2" || $peers == "$node2 $node1" } {
return $link
proc removeLink { link } {
- global links $link
+ global link_list $link
set pnodes [linkPeers $link]
foreach node $pnodes {
set $node [lreplace [set $node] $i $i]
}
unset $link
- set i [lsearch -exact $links $link]
- set links [lreplace $links $i $i]
+ set i [lsearch -exact $link_list $link]
+ set link_list [lreplace $link_list $i $i]
return
}
proc removeNode { node } {
- global nodes $node
+ global node_list $node
foreach ifc [ifcList $node] {
set peer [peerByIfc $node $ifc]
removeLink $link
}
unset $node
- set i [lsearch -exact $nodes $node]
- set nodes [lreplace $nodes $i $i]
+ set i [lsearch -exact $node_list $node]
+ set node_list [lreplace $node_list $i $i]
return
}