]> git.entuzijast.net Git - imunes.git/commitdiff
vratili original FreeBSD host.tcl i exec.tcl, a dodali Linux verzije u linux/; dodali...
authornuma <numa@numa-ubuntu-vm.(none)>
Fri, 4 Sep 2009 13:17:14 +0000 (15:17 +0200)
committernuma <numa@numa-ubuntu-vm.(none)>
Fri, 4 Sep 2009 13:17:14 +0000 (15:17 +0200)
exec.tcl
host.tcl

index 2812c627b2dac3e4a9658f1d340842a58ca7dc72..61bdd69aa2ff8a4389427d2e4ff43d86f72d4d7c 100755 (executable)
--- a/exec.tcl
+++ b/exec.tcl
@@ -64,7 +64,6 @@ proc nexec { args } {
     if { $remote_exec } {
        rexec $execSock $args   
     } else {
-       puts "-- running: $args"
        eval exec $args
     }
 }
@@ -100,8 +99,6 @@ proc setOperMode { mode } {
     global activetool
     global editor_only remote_exec execSock
 
-       puts "setOperMode $mode"
-
     if { $mode == "exec" } { ;# let's try something, sockets should be opened
        nexec id -u
        if { $editor_only } { ;# if set in nexec or open_exec_sockets
@@ -112,11 +109,9 @@ proc setOperMode { mode } {
 
     # Verify that links to external interfaces are properly configured
     if { $mode == "exec" } {
-       # space-separated popis interfacea (BSD ifconfig -l)
-       set extifcs [nexec ./ifconfig-l]
-       # izbaci loopback interface iz popisa (BSD lo)
+       set extifcs [nexec ifconfig -l]
        set extifcs \
-           [lreplace $extifcs [lsearch $extifcs lo] [lsearch $extifcs lo]]
+           [lreplace $extifcs [lsearch $extifcs lo0] [lsearch $extifcs lo0]]
        foreach node $node_list {
            if { [nodeType $node] == "rj45" } {
                set i [lsearch $extifcs [getNodeName $node]]
@@ -231,14 +226,8 @@ proc statline {line} {
 #   * name -- the name of the new interface
 #****
 proc createIfc { eid type hook } {
-    puts "usli u createIfc $eid $type $hook"
-
-# FreeBSD-specific:
-#    puts "    izvrsili bismo exec printf mkpeer $type $hook $hook \n show .$hook | vimage $eid ngctl -f -"
-#    puts "    izvadili bi drugi element iz toga"
-#    return fake_if_id
-#    catch { exec printf "mkpeer $type $hook $hook \n show .$hook" | vimage $eid ngctl -f - } nglist
-#    return [lindex $nglist 1]
+    catch { exec printf "mkpeer $type $hook $hook \n show .$hook" | vimage $eid ngctl -f - } nglist
+    return [lindex $nglist 1]
 }
 
 
@@ -262,102 +251,63 @@ proc l3node.instantiate { eid node } {
     upvar 0 ::cf::[set ::curcfg]::ngnodemap ngnodemap
     global mac_byte4 mac_byte5
 
-       puts "l3node.instantiate $eid $node"
-
     set node_id "$eid\.$node"
-# OpenVZ VE ID moze biti samo numericki, dok nas node_id sadrzi
-# delimiter tocku i slovo n, pa te znakove moramo izbaciti
-    set openvz_node_id $eid[string range $node 1 end]
-
-# ovdje bismo mogli napraviti OpenVZ conf file za ovaj node
-# ali pustamo vzctl create da ga sam automatski izgenerira iz
-# vps-basic sample datoteke u /etc/vz/conf/
-
-#    puts "    nexec vimage -c $node_id                                "
-    nexec vzctl create $openvz_node_id --ostemplate imunes-openvz
-
-# Dodjela naseg kratkog node ida njegovom numerickom VE ID-u opcijom --name
-# TODO: ako bude potreban support za vise paralelenih eksperimenata,
-# trebat ce VE name podesiti s prefiksom $eid (i analogno u vimageCleanup)
-    nexec vzctl set $openvz_node_id --name $node --save
-
-#    puts "    nexec vimage $node_id hostname [getNodeName $node]      "
-    nexec vzctl set $node --hostname [getNodeName $node] --save
-
-# feature FreeBSD-a only (expandanje @ u symlinkovima kao node id)
-#    puts "    nexec vimage $node_id sysctl vfs.morphing_symlinks=1    "
-
-    nexec vzctl start $node
+    nexec vimage -c $node_id
+    nexec vimage $node_id hostname [getNodeName $node]
+    nexec vimage $node_id sysctl vfs.morphing_symlinks=1
 
     foreach ifc [ifcList $node] {
        switch -exact [string range $ifc 0 2] {
            eth {
-# FreeBSD-specific:
-#              set ifid [createIfc $eid eiface ether]
-#              puts "  nexec vimage $eid vimage -i $node $ifid $ifc    "
-
-# na Linuxu ne moramo pokrenuti createIfc, samo postaviti ovaj standardni format
-# koji ide u vzctl --netif_add
-               set ifid "to_${node}_${ifc}"
+               set ifid [createIfc $eid eiface ether]
+               nexec vimage $eid vimage -i $node $ifid $ifc
 
                set peer [peerByIfc $node $ifc]
-
-               puts "vidimo node: $node ifclist: $ifc peer: $peer"
-
                if { [nodeType $peer] == "rj45" } {
-# TODO: RJ-45 nodes zasad ne podrzavamo
-#                  set peerifc [getNodeName $peer]
-#                  set ether [nexec ifconfig $peerifc | fgrep "ether " | cut -c8-]
+                   set peerifc [getNodeName $peer]
+                   set ether [nexec ifconfig $peerifc | fgrep "ether " | cut -c8-]
                } else {
-                   # vzctl ne prima ako nije properly padded
-                   set ether 40:00:aa:aa:[format %02x $mac_byte4]:[format %02x $mac_byte5]
-                   set host_ether 40:00:aa:ff:[format %02x $mac_byte4]:[format %02x $mac_byte5]
+                   set ether 40:00:aa:aa:$mac_byte4:$mac_byte5
                    incr mac_byte5
                    if { $mac_byte5 >= 100 } {
                        set mac_byte5 0
                        incr mac_byte4
                    }
                }
-#              puts "  nexec vimage $node_id ifconfig $ifc link $ether "
-               nexec vzctl {set} $node --netif_add $ifc,$ether,$ifid,$host_ether
+               nexec vimage $node_id ifconfig $ifc link $ether
                set ngnodemap($ifc@$node_id) $ifid
            }
            ser {
-# TODO: serial interfaceove zasad ne podrzavamo
-#              set ifnum [string range $ifc 3 end]
-#              set ifid [createIfc $eid iface inet]
-#              nexec vimage $eid ngctl mkpeer $ifid: cisco inet inet
-#              nexec vimage $eid ngctl connect $ifid: $ifid:inet inet6 inet6
-#              nexec vimage $eid ngctl msg $ifid: broadcast
-#              nexec vimage $eid ngctl name $ifid:inet hdlc$ifnum\@$node
-#              nexec vimage $eid vimage -i $node $ifid $ifc
-#              set ngnodemap(hdlc$ifnum@$node_id) hdlc$ifnum\@$node
+               set ifnum [string range $ifc 3 end]
+               set ifid [createIfc $eid iface inet]
+               nexec vimage $eid ngctl mkpeer $ifid: cisco inet inet
+               nexec vimage $eid ngctl connect $ifid: $ifid:inet inet6 inet6
+               nexec vimage $eid ngctl msg $ifid: broadcast
+               nexec vimage $eid ngctl name $ifid:inet hdlc$ifnum\@$node
+               nexec vimage $eid vimage -i $node $ifid $ifc
+               set ngnodemap(hdlc$ifnum@$node_id) hdlc$ifnum\@$node
            }
        }
     }
 
-# TODO: OpenVZ CPU tuning
-#    set cpuconf [getNodeCPUConf $node]
-#    set cpumin [lindex [lsearch -inline $cpuconf {min *}] 1]
-#    set cpumax [lindex [lsearch -inline $cpuconf {max *}] 1]
-#    set cpuweight [lindex [lsearch -inline $cpuconf {weight *}] 1]
-#    if { $cpumin != "" } {
-#      puts "  nexec vimage -m $node_id cpumin $cpumin         "
-#    }
-#    if { $cpumax != "" } {
-#      puts "  nexec vimage -m $node_id cpumax $cpumax         "
-#    }
-#    if { $cpuweight != "" } {
-#      puts "  nexec vimage -m $node_id cpuweight $cpuweight   "
-#    }
-
-# FreeBSD-only
-#      puts "  
-#    nexec vimage $node_id sysctl net.inet.icmp.bmcastecho=1
-#    nexec vimage $node_id sysctl net.inet.icmp.icmplim=0
-#    nexec vimage $node_id ifconfig lo0 inet localhost
-#    nexec vimage $node_id route add 224.0.0.0/4 localhost
-#                                                              "
+    set cpuconf [getNodeCPUConf $node]
+    set cpumin [lindex [lsearch -inline $cpuconf {min *}] 1]
+    set cpumax [lindex [lsearch -inline $cpuconf {max *}] 1]
+    set cpuweight [lindex [lsearch -inline $cpuconf {weight *}] 1]
+    if { $cpumin != "" } {
+       nexec vimage -m $node_id cpumin $cpumin
+    }
+    if { $cpumax != "" } {
+       nexec vimage -m $node_id cpumax $cpumax
+    }
+    if { $cpuweight != "" } {
+       nexec vimage -m $node_id cpuweight $cpuweight
+    }
+
+    nexec vimage $node_id sysctl net.inet.icmp.bmcastecho=1
+    nexec vimage $node_id sysctl net.inet.icmp.icmplim=0
+    nexec vimage $node_id ifconfig lo0 inet localhost
+    nexec vimage $node_id route add 224.0.0.0/4 localhost
 }
 
 
@@ -407,24 +357,16 @@ proc l3node.start { eid node } {
     global remote_exec execSock
     global viewcustomid
     
-       puts "l3node.start $eid $node"
-    
     set node_id "$eid\.$node"
+    set node_dir "/tmp/$eid/$node"
 
-# na FreeBSD-u vimagei imaju shared filesystem
-# na Linuxu VEovi to nemaju
-#    set node_dir "/tmp/$eid/$node"
-
-#    puts "    would recreate node_dir (/tmp/$eid/$node)"
-#    nexec rm -fr $node_dir
-#    nexec mkdir $node_dir
-#    nexec chmod 1777 $node_dir
-
-# TODO: konfiguriranje MTU-a zasad ne podrzavamo (kao ni ostale L2 parametre)
-#    foreach ifc [ifcList $node] {
-#      set mtu [getIfcMTU $node $ifc]
-#      puts "  nexec vimage $node_id ifconfig $ifc mtu $mtu    "
-#    }
+    nexec rm -fr $node_dir
+    nexec mkdir $node_dir
+    nexec chmod 1777 $node_dir
+    foreach ifc [ifcList $node] {
+       set mtu [getIfcMTU $node $ifc]
+       nexec vimage $node_id ifconfig $ifc mtu $mtu
+    }
 
     set check [info exists viewcustomid]
     if { $check == 0 } {
@@ -453,37 +395,31 @@ proc l3node.start { eid node } {
 
     set ipsecCfg ""
     if { [getIpsecEnabled $node] == true } {
-# TODO: ipsec zasad ne podrzavamo
-       puts "  would do the ipsecenabled stuff"
-#
-#      set setkeycfg [ipsecCfggen $node]
-#      set setkeyFileId [open $node_dir/setkey.conf w+]
-#      foreach line $setkeycfg {
-#          puts $setkeyFileId $line
-#      }
-#      close $setkeyFileId
-
-#      set errorstr ""
-#      set error [catch "nexec vimage $node_id setkey -f \
-#          $node_dir/setkey.conf" errorstr]
-#      if { $error == "1" } {
-#          setkeyError $node_id $errorstr
-#      }
+       set setkeycfg [ipsecCfggen $node]
+       set setkeyFileId [open $node_dir/setkey.conf w+]
+       foreach line $setkeycfg {
+           puts $setkeyFileId $line
+       }
+       close $setkeyFileId
+
+       set errorstr ""
+       set error [catch "nexec vimage $node_id setkey -f \
+           $node_dir/setkey.conf" errorstr]
+       if { $error == "1" } {
+           setkeyError $node_id $errorstr
+       }
     }
     
     if { $bootcmd == "" || $bootcfg =="" } {
        set bootcfg [[typemodel $node].cfggen $node]
        set bootcmd [[typemodel $node].bootcmd $node]
     }
-    puts "     imamo typemodel=[typemodel $node]"
-#    puts "bootcfg=$bootcfg i bootcmd=$bootcmd"
     if { ! $remote_exec } {
-#      puts "  would write node_dir/boot.conf"
-#      set fileId [open $node_dir/boot.conf w]
-#      foreach line $bootcfg {
-#          puts $fileId $line
-#      }
-#      close $fileId
+       set fileId [open $node_dir/boot.conf w]
+       foreach line $bootcfg {
+           puts $fileId $line
+       }
+       close $fileId
     } else {
        nexec create_conf_file $node_dir/boot.conf
        foreach line $bootcfg {
@@ -492,21 +428,7 @@ proc l3node.start { eid node } {
        nexec close_conf_file
     }
 
-#    puts "    would execute bootcmd boot.conf in $node_id"
-#    catch nexec vimage $node_id $bootcmd $node_dir/boot.conf >& $node_dir/out.log &"
-
-    foreach line $bootcfg {
-       puts "  executing on $node: $line"
-       set command $line
-       if { "$command" != "" } {
-           catch { nexec vzctl exec $node $command } ret
-           if { $ret != "TCL_OK" } {
-               puts "          $ret"
-               # TODO: proper GUI message box, plus batch mode handling
-            }
-        }
-    }
-
+    catch "nexec vimage $node_id $bootcmd $node_dir/boot.conf >& $node_dir/out.log &"
 }
 
 #****f* exec.tcl/l3node.shutdown 
@@ -524,13 +446,13 @@ proc l3node.start { eid node } {
 #****
 proc l3node.shutdown { eid node } {
     set node_id "$eid\.$node"
-    puts "nexec vimage $node_id kill -9 -1 2> /dev/null"
+    catch "nexec vimage $node_id kill -9 -1 2> /dev/null"
     foreach ifc [ifcList $node] {
        foreach ipv4 [getIfcIPv4addr $node $ifc] {
-           puts "nexec vimage $node_id ifconfig $ifc $ipv4 -alias"
+           catch "nexec vimage $node_id ifconfig $ifc $ipv4 -alias"
        }
        foreach ipv6 [getIfcIPv6addr $node $ifc] {
-           puts "nexec vimage $node_id ifconfig $ifc inet6 $ipv6 -alias"
+           catch "nexec vimage $node_id ifconfig $ifc inet6 $ipv6 -alias"
        }
     }
 }
@@ -552,21 +474,16 @@ proc l3node.shutdown { eid node } {
 proc l3node.destroy { eid node } {
     set node_id $node
     foreach ifc [ifcList $node] {
-       puts " nexec vimage $eid ngctl msg $ifc@$node_id: shutdown "
-       
+       catch { nexec vimage $eid ngctl msg $ifc@$node_id: shutdown }
        set ifnum [string range $ifc 3 end]
        set ifname [string range $ifc 0 2]
        if { $ifname == "ser" } {
-           puts " nexec vimage $eid ngctl msg hdlc$ifnum@$node_id: shutdown "
+           catch { nexec vimage $eid ngctl msg hdlc$ifnum@$node_id: shutdown }
        }
     }
-    puts "nexec vimage -d $node_id"
-    nexec vzctl stop $node
-    nexec vzctl destroy $node
-
-# FreeBSD only node_dir:
-#    set node_dir "/tmp/$eid/$node"
-#    nexec rm -fr $node_dir
+    catch {nexec vimage -d $node_id}
+    set node_dir "/tmp/$eid/$node"
+    nexec rm -fr $node_dir
 }
 
 
@@ -591,8 +508,6 @@ proc deployCfg {} {
     global remote_exec
     global eid_base
 
-       puts "deployCfg"
-
     set mac_byte4 0
     set mac_byte5 0
 
@@ -600,25 +515,20 @@ proc deployCfg {} {
 
     set t_start [clock seconds]
 
-# na FreeBSD-u napravi jedan osnovni vimage unutar kojeg ce drzati
-# network peeringe izmedju nodeova
-# na Linuxu to necemo napraviti jer ne mozemo dirati network linkove
-# jednog VEa iz drugog, pa ce to sve biti na parent hostu
-#    puts " nexec vimage -c $eid "
-#    puts " nexec rm -fr /tmp/$eid "
-#    puts " nexec mkdir /tmp/$eid "
-
-#    puts { nexec kldload ng_ether }
-#    puts { nexec kldload ng_iface }
-#    puts { nexec kldload ng_eiface }
-#    puts { nexec kldload ng_cisco }
-#    puts { nexec kldload ng_pipe }
-#    puts { nexec kldload ng_hub }
-#    puts { nexec kldload ng_bridge }
-#    puts { nexec kldload ng_socket }
+    catch { nexec vimage -c $eid }
+    catch { nexec rm -fr /tmp/$eid }
+    catch { nexec mkdir /tmp/$eid }
+
+    catch { nexec kldload ng_ether }
+    catch { nexec kldload ng_iface }
+    catch { nexec kldload ng_eiface }
+    catch { nexec kldload ng_cisco }
+    catch { nexec kldload ng_pipe }
+    catch { nexec kldload ng_hub }
+    catch { nexec kldload ng_bridge }
+    catch { nexec kldload ng_socket }
 
     foreach node $node_list {
-       # OpenVZ VE name format su brojke (bez tocaka)
        set node_id "$eid\.$node"
        set type [nodeType $node]
        set name [getNodeName $node]
@@ -628,89 +538,85 @@ proc deployCfg {} {
        }
     }
 
-## TODO: podesavanje L2 parametara linka ne podrzavamo
-
-#    for { set pending_links $link_list } { $pending_links != "" } {} {
-#      set link [lindex $pending_links 0]
-#      set i [lsearch -exact $pending_links $link]
-#      set pending_links [lreplace $pending_links $i $i]
-
-#      set lnode1 [lindex [linkPeers $link] 0]
-#      set lnode2 [lindex [linkPeers $link] 1]
-#      set ifname1 [ifcByPeer $lnode1 $lnode2]
-#      set ifname2 [ifcByPeer $lnode2 $lnode1]
-
-#      if { [getLinkMirror $link] != "" } {
-#          set mirror_link [getLinkMirror $link]
-#          set i [lsearch -exact $pending_links $mirror_link]
-#          set pending_links [lreplace $pending_links $i $i]
-
-#          statline "Creating link $link/$mirror_link"
-
-#          set p_lnode2 $lnode2
-#          set lnode2 [lindex [linkPeers $mirror_link] 0]
-#          set ifname2 [ifcByPeer $lnode2 [getNodeMirror $p_lnode2]]
-#      } else {
-#          statline "Creating link $link"
-#      }
-
-#      set lname $lnode1-$lnode2
-#      set bandwidth [expr [getLinkBandwidth $link] + 0]
-#      set delay [expr [getLinkDelay $link] + 0]
-#      set ber [expr [getLinkBER $link] + 0]
-#      set dup [expr [getLinkDup $link] + 0]
-
-#      set peer1 \
-#          [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 0]
-#      set peer2 \
-#          [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 0]
-#      set ngpeer1 $ngnodemap($peer1)
-#      set ngpeer2 $ngnodemap($peer2)
-#      set nghook1 \
-#          [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 1]
-#      set nghook2 \
-#          [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 1]
-
-#      puts "  nexec vimage $eid ngctl mkpeer $ngpeer1: pipe $nghook1 upper            "
-#      puts "  nexec vimage $eid ngctl name $ngpeer1:$nghook1 $lname                   "
-#      puts "  nexec vimage $eid ngctl connect $lname: $ngpeer2: lower $nghook2        "
-
-# FreeBSD-specific
-#      # Ethernet frame has a 14-byte header - this is a temp. hack!!!
-#      puts "  nexec vimage $eid ngctl msg $lname: setcfg { header_offset=14 } "
-
-#      # Link parameters
-#      puts "  nexec vimage $eid ngctl msg $lname: setcfg 
-#          { bandwidth=$bandwidth delay=$delay 
-#          upstream={ BER=$ber duplicate=$dup } 
-#          downstream={ BER=$ber duplicate=$dup } }                                    "
-
-#      # Queues
-#      foreach node [list $lnode1 $lnode2] {
-#          if { $node == $lnode1 } {
-#              set ifc $ifname1
-#          } else {
-#              set ifc $ifname2
-#          }
-
-#          if { [nodeType $lnode1] != "rj45" && \
-#              [nodeType $lnode2] != "rj45" } {
-#              execSetIfcQDisc $eid $node $ifc [getIfcQDisc $node $ifc]
-#              execSetIfcQDrop $eid $node $ifc [getIfcQDrop $node $ifc]
-#              execSetIfcQLen $eid $node $ifc [getIfcQLen $node $ifc]
-#          }
-#      }
-#    }
-
-#    # XXX move those to some quagga specific script
-#    # XXX race if starting two imunes instances simultaneously
-#    nexec rm -fr /var/run/quagga
-#    nexec rm -f /usr/local/etc/quagga/Quagga.conf
-#    puts { nexec ln -s /tmp/$eid/@ /var/run/quagga }
-#    puts { nexec ln -s /tmp/$eid/@/boot.conf /usr/local/etc/quagga/Quagga.conf }
-#    foreach file { bgpd ospfd ospf6d ripd ripngd vtysh zebra } {
-#      puts { nexec cp /dev/null /usr/local/etc/quagga/$file.conf }
-#    }
+    for { set pending_links $link_list } { $pending_links != "" } {} {
+       set link [lindex $pending_links 0]
+       set i [lsearch -exact $pending_links $link]
+       set pending_links [lreplace $pending_links $i $i]
+
+       set lnode1 [lindex [linkPeers $link] 0]
+       set lnode2 [lindex [linkPeers $link] 1]
+       set ifname1 [ifcByPeer $lnode1 $lnode2]
+       set ifname2 [ifcByPeer $lnode2 $lnode1]
+
+       if { [getLinkMirror $link] != "" } {
+           set mirror_link [getLinkMirror $link]
+           set i [lsearch -exact $pending_links $mirror_link]
+           set pending_links [lreplace $pending_links $i $i]
+
+           statline "Creating link $link/$mirror_link"
+
+           set p_lnode2 $lnode2
+           set lnode2 [lindex [linkPeers $mirror_link] 0]
+           set ifname2 [ifcByPeer $lnode2 [getNodeMirror $p_lnode2]]
+       } else {
+           statline "Creating link $link"
+       }
+
+       set lname $lnode1-$lnode2
+       set bandwidth [expr [getLinkBandwidth $link] + 0]
+       set delay [expr [getLinkDelay $link] + 0]
+       set ber [expr [getLinkBER $link] + 0]
+       set dup [expr [getLinkDup $link] + 0]
+
+       set peer1 \
+           [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 0]
+       set peer2 \
+           [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 0]
+       set ngpeer1 $ngnodemap($peer1)
+       set ngpeer2 $ngnodemap($peer2)
+       set nghook1 \
+           [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 1]
+       set nghook2 \
+           [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 1]
+       nexec vimage $eid ngctl mkpeer $ngpeer1: pipe $nghook1 upper
+       nexec vimage $eid ngctl name $ngpeer1:$nghook1 $lname
+       nexec vimage $eid ngctl connect $lname: $ngpeer2: lower $nghook2
+
+       # Ethernet frame has a 14-byte header - this is a temp. hack!!!
+       nexec vimage $eid ngctl msg $lname: setcfg "{ header_offset=14 }"
+
+       # Link parameters
+       nexec vimage $eid ngctl msg $lname: setcfg \
+           "{ bandwidth=$bandwidth delay=$delay \
+           upstream={ BER=$ber duplicate=$dup } \
+           downstream={ BER=$ber duplicate=$dup } }"
+
+       # Queues
+       foreach node [list $lnode1 $lnode2] {
+           if { $node == $lnode1 } {
+               set ifc $ifname1
+           } else {
+               set ifc $ifname2
+           }
+
+           if { [nodeType $lnode1] != "rj45" && \
+               [nodeType $lnode2] != "rj45" } {
+               execSetIfcQDisc $eid $node $ifc [getIfcQDisc $node $ifc]
+               execSetIfcQDrop $eid $node $ifc [getIfcQDrop $node $ifc]
+               execSetIfcQLen $eid $node $ifc [getIfcQLen $node $ifc]
+           }
+       }
+    }
+
+    # XXX move those to some quagga specific script
+    # XXX race if starting two imunes instances simultaneously
+    nexec rm -fr /var/run/quagga
+    nexec rm -f /usr/local/etc/quagga/Quagga.conf
+    catch { nexec ln -s /tmp/$eid/@ /var/run/quagga }
+    catch { nexec ln -s /tmp/$eid/@/boot.conf /usr/local/etc/quagga/Quagga.conf }
+    foreach file { bgpd ospfd ospf6d ripd ripngd vtysh zebra } {
+       catch { nexec cp /dev/null /usr/local/etc/quagga/$file.conf }
+    }
 
     foreach node $node_list {
        upvar 0 ::cf::[set ::curcfg]::$node $node
@@ -739,119 +645,91 @@ proc vimageCleanup { eid } {
     global .c
     global execMode
 
-       puts "vimageCleanup $eid"
-
     set t_start [clock seconds]
+    if { [catch {nexec vimage $eid vimage -lr | fgrep -v "    " | cut -d: -f 1} res] != 0 } {
+       return
+    }
+    set vimages [join $res]
+    set defindex [lsearch $vimages .]
+    set vimages [lreplace $vimages $defindex $defindex]
 
-## FreeBSD-only bug workaround:
-#    puts " would check vimage $eid vimage -lr \| fgrep -v \"    \" \| cut -d: -f 1"
-#    if { [ catch {nexec vimage $eid vimage -lr | fgrep -v "    " | cut -d: -f 1} res] != 0 } {
-#      return
-#    }
-#    set vimages [join $res]
-#    set defindex [lsearch $vimages .]
-#    set vimages [lreplace $vimages $defindex $defindex]
-
-#    # Wait for TIME_WAIT timeout in all vimages
-#    set vrti 1
-#    set sec 60
-
-#    if { $execMode == "batch" } {
-#        puts "\nDue to the known bug we must wait for TIME_WAIT expiration on virtual nodes (up to 60 sec). "
-#        puts "Please don't try killing the process."
-#    } else {
-#        # wm title $wi "Please wait ..."
-#        set w .timewait
-#        puts {destroy $w}
-#        toplevel $w -takefocus 1
-#        wm geometry $w +150+150
-#        wm title $w "Please wait ..."
-#        message $w.msg -justify left -aspect 1200 \
-#         -text "\nDue to the known bug we must wait for TIME_WAIT expiration on virtual nodes (up to 60 sec). 
-#Please don't try killing the process.
-#(countdown on status line)\n"
-#        pack $w.msg
-#        update
-#        grab $w
-#    } 
-#    while { $vrti == 1 } {
-#        set vrti 0
-#        foreach vimage $vimages {
-#            puts "vimage $vimage...\n"
-#            puts "checking netstat -an -f inet | fgrep WAIT..."
-#            while { [catch {nexec vimage $eid.$vimage netstat -an -f inet | fgrep "WAIT"} odg] == 0} {
-#                set vrti 1
-#                # puts "vimage $vimage: \n$odg\n"
-#                after 2000 
-#                set sec [expr $sec - 2]
-#                if { $execMode == "batch" } {
-#                    puts -nonewline "."
-#                    flush stdout
-#                } else {
-#                    statline "~ $sec sec ..."
-#                    pack $w.msg
-#                    update
-#                }
-#            }
-#        }
-#    }
-#    if { $execMode == "batch" } {
-#        puts ""
-#    } else {
-#        destroy .timewait
-#    }
-
-# FreeBSD vimage only
-#    # Kill all processes in all vimages
-#    foreach vimage $vimages {
-#      set stattxt "Terminating processes in vimage $vimage"
-#      statline $stattxt
-#      puts "nexec vimage $eid.$vimage kill -9 -1 2> /dev/null"
-#    }
-
-# FreeBSD netgraph only
-#    # Detach / destroy / reassign interfaces pipe, eiface, iface, bridge
-#      puts "running vimage $eid ngctl l | tail -n +3"
-#    set ngnodes [split [nexec vimage $eid ngctl l | tail -n +3] "
-#"]
-#    foreach ngline $ngnodes {
-#      set node [lindex [eval list $ngline] 1]
-#      statline "Shutting down netgraph node $node"
-#      puts "nexec vimage $eid ngctl msg $node: shutdown"
-#    }
-
-    # Shut down all vimages
+    # Wait for TIME_WAIT timeout in all vimages
+    set vrti 1
+    set sec 60
 
-    # OpenVZ - samo nam treba popis nodeova za pogasiti
-    upvar 0 ::cf::[set ::curcfg]::node_list node_list
-    foreach node $node_list {
-       set stattxt "Stopping VE $node"
-       statline $stattxt
-       nexec vzctl stop $node
-       set stattxt "Destroying VE $node"
+    if { $execMode == "batch" } {
+        puts "\nDue to the known bug we must wait for TIME_WAIT expiration on virtual nodes (up to 60 sec). "
+        puts "Please don't try killing the process."
+    } else {
+        # wm title $wi "Please wait ..."
+        set w .timewait
+        catch {destroy $w}
+        toplevel $w -takefocus 1
+        wm geometry $w +150+150
+        wm title $w "Please wait ..."
+        message $w.msg -justify left -aspect 1200 \
+         -text "\nDue to the known bug we must wait for TIME_WAIT expiration on virtual nodes (up to 60 sec). 
+Please don't try killing the process.
+(countdown on status line)\n"
+        pack $w.msg
+        update
+        grab $w
+    } 
+    while { $vrti == 1 } {
+        set vrti 0
+        foreach vimage $vimages {
+            # puts "vimage $vimage...\n"
+            while { [catch {nexec vimage $eid.$vimage netstat -an -f inet | fgrep "WAIT"} odg] == 0} {
+                set vrti 1
+                # puts "vimage $vimage: \n$odg\n"
+                after 2000 
+                set sec [expr $sec - 2]
+                if { $execMode == "batch" } {
+                    puts -nonewline "."
+                    flush stdout
+                } else {
+                    statline "~ $sec sec ..."
+                    pack $w.msg
+                    update
+                }
+            }
+        }
+    }
+    if { $execMode == "batch" } {
+        puts ""
+    } else {
+        destroy .timewait
+    }
+    # Kill all processes in all vimages
+    foreach vimage $vimages {
+       set stattxt "Terminating processes in vimage $vimage"
        statline $stattxt
-       nexec vzctl destroy $node
+       catch {nexec vimage $eid.$vimage kill -9 -1 2> /dev/null}
     }
 
-       puts "*** missing bridge cleanup in main host"
-
-# FreeBSD metoda:
-#    foreach vimage $vimages {
-#      set stattxt "Shutting down vimage $vimage"
-#      statline $stattxt
-#      puts "nexec vimage $eid.$vimage kill -9 -1 2> /dev/null"
-#      while { [catch {nexec vimage -d $eid.$vimage}] } {
-#          set stattxt $stattxt.
-#          statline $stattxt
-#          puts "nexec vimage $eid.$vimage kill -9 -1 2> /dev/null"
-#      }
-#    }
-#    puts " nexec vimage -d $eid "
-
-#    puts " nexec rm -f /usr/local/etc/quagga/Quagga.conf "
-
-# FreeBSD-only ciscenje eid tmp dira
-#    nexec rm -fr "/tmp/$eid"
+    # Detach / destroy / reassign interfaces pipe, eiface, iface, bridge
+    set ngnodes [split [nexec vimage $eid ngctl l | tail -n +3] "
+"]
+    foreach ngline $ngnodes {
+       set node [lindex [eval list $ngline] 1]
+       statline "Shutting down netgraph node $node"
+       catch "nexec vimage $eid ngctl msg $node: shutdown"
+    }
+
+    # Shut down all vimages
+    foreach vimage $vimages {
+       set stattxt "Shutting down vimage $vimage"
+       statline $stattxt
+       catch {nexec vimage $eid.$vimage kill -9 -1 2> /dev/null}
+       while { [catch {nexec vimage -d $eid.$vimage}] } {
+           set stattxt $stattxt.
+           statline $stattxt
+           catch {nexec vimage $eid.$vimage kill -9 -1 2> /dev/null}
+       }
+    }
+    catch { nexec vimage -d $eid }
+    catch { nexec rm -f /usr/local/etc/quagga/Quagga.conf }
+    nexec rm -fr "/tmp/$eid"
     statline "Cleanup completed in [expr [clock seconds] - $t_start] seconds."
 }
 
@@ -872,10 +750,6 @@ proc vimageCleanup { eid } {
 #   qdisc -- queuing discipline
 #****
 proc execSetIfcQDisc { eid node ifc qdisc } {
-
-       puts "execSetIfcQDisc $eid $node $ifc $qdisc"
-       return
-       
     set target [linkByIfc $node $ifc]
     set peers [linkPeers [lindex $target 0]]
     set dir [lindex $target 1]
@@ -914,10 +788,6 @@ proc execSetIfcQDisc { eid node ifc qdisc } {
 #   qdrop -- queue dropping policy
 #****
 proc execSetIfcQDrop { eid node ifc qdrop } {
-
-       puts "execSetIfcQDrop $eid $node $ifc $qdrop"
-       return
-
     set target [linkByIfc $node $ifc]
     set peers [linkPeers [lindex $target 0]]
     set dir [lindex $target 1]
@@ -955,10 +825,6 @@ proc execSetIfcQDrop { eid node ifc qdrop } {
 #   qlen -- new queue's length
 #****
 proc execSetIfcQLen { eid node ifc qlen } {
-
-       puts "execSetIfcQLen $eid $node $ifc $qlen"
-       return
-
     set target [linkByIfc $node $ifc]
     set peers [linkPeers [lindex $target 0]]
     set dir [lindex $target 1]
@@ -992,10 +858,6 @@ proc execSetIfcQLen { eid node ifc qlen } {
 #   link -- link id
 #****
 proc execSetLinkParams { eid link } {
-
-       puts "execSetLinkParams $eid $link"
-       return
-
     set lnode1 [lindex [linkPeers $link] 0]
     set lnode2 [lindex [linkPeers $link] 1]
     set lname $lnode1-$lnode2
@@ -1065,7 +927,7 @@ proc openFwrd { lPort rPort rHost } {
 proc closeFwrd { pid } {
     global tcl_platform platform
     if { $tcl_platform(platform) == "unix" } {
-       puts {eval exec kill $pid}
+       catch {eval exec kill $pid}
        return ""
     }
 }
index 9cf1813ef70f64ea25fe08047abffb03a0da570b..e762bb92b7449014410c769526734e9f457187a1 100755 (executable)
--- a/host.tcl
+++ b/host.tcl
@@ -105,20 +105,17 @@ proc $MODULE.cfggen { node } {
     # Temporary fix to enable multiple inetd and rpcbind processes 
     # (in different vimages). Sholud be removed if each vimage is running
     # in separate file system.
-
-    # In Linux/OpenVZ each node is indeed running in a separate file system.
-
     #
     # Before startup ...
-#    lappend cfg "rm -f /var/run/inetd.pid" 
-#    lappend cfg "rm -f /var/run/rpcbind.lock" 
+    lappend cfg "rm -f /var/run/inetd.pid" 
+    lappend cfg "rm -f /var/run/rpcbind.lock" 
 
-#    lappend cfg "rpcbind"
-#    lappend cfg "inetd"
+    lappend cfg "rpcbind"
+    lappend cfg "inetd"
 
     # ... and after startup.
-#    lappend cfg "rm -f /var/run/inetd.pid" 
-#    lappend cfg "rm -f /var/run/rpcbind.lock" 
+    lappend cfg "rm -f /var/run/inetd.pid" 
+    lappend cfg "rm -f /var/run/rpcbind.lock" 
 
     return $cfg
 }