From b1369636d3fedc4f69fb492065450706e53f3983 Mon Sep 17 00:00:00 2001 From: marko Date: Mon, 7 May 2007 23:06:06 +0000 Subject: [PATCH] Refactor the mechanism for creating netgraph-based pseudo interfaces (ng_iface and ng_eiface) so that: a) we don't need a specialized version of ngctl userland utility; b) that in FreeBSD 7.0 netgraph nodes are not renamed when interfaces are assigned to other vimages; Introduce a helper array "ngnodemap" which provides name mapping between kernel view of netgraph space, and IMUNES view of node naming. When creating links, do not insert a ng_pipe node between the endpoints, given that ng_pipe is not yet ported to FreeBSD 7.0. Instead, endpoint nodes are connected back to back, which means that currently we will be able to construct topologies, but not emulate link properties and impairments. Use vimageCleanup instead of cleanupCfg, since it seems that the later is defunct, at least on FreeBSD 7.0 Bug found by: Submitted by: Requested by: Reviewed by: Approved by: Obtained from: --- exec.tcl | 69 +++++++++++++++++--------------------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/exec.tcl b/exec.tcl index fbcfbd1..43ed756 100755 --- a/exec.tcl +++ b/exec.tcl @@ -1,4 +1,4 @@ -# $Id: exec.tcl,v 1.47 2007/05/07 08:43:20 ana Exp $ +# $Id: exec.tcl,v 1.48 2007/05/07 23:06:06 marko Exp $ # Copyright 2004, 2005 University of Zagreb, Croatia. All rights reserved. # @@ -159,8 +159,7 @@ proc setOperMode { mode } { } } else { if {$oper_mode != "edit"} { - #vimageCleanup - cleanupCfg + vimageCleanup .menubar.tools entryconfigure "Auto rearrange all" -state normal .menubar.tools entryconfigure "Auto rearrange selected" -state normal } @@ -229,13 +228,9 @@ proc statline {line} { # * name -- the name of the new interface #**** proc createIfc {type hook} { - catch {nexec ngctl mkpeer $type $hook $hook | tail -1} resp - foreach elem [split [lindex [split $resp "\{\}"] 1]] { - if {[string equal -length 6 $elem "name=\""]} { - set name [string range $elem 6 [expr [string length $elem] - 2]] - return $name - } - } + catch { exec ngctl mkpeer $type $hook $hook } + catch { exec ngctl l | fgrep " Name: " | cut -c9-23 | xargs echo } nglist + return [lindex $nglist 1] } @@ -260,13 +255,14 @@ proc l3node.instantiate { eid node } { set node_id "$eid\_$node" nexec vimage -c $node_id nexec vimage $node_id hostname [getNodeName $node] + global ngnodemap foreach ifc [ifcList $node] { switch -exact [string range $ifc 0 2] { eth { set ifid [createIfc eiface ether] nexec vimage -i $node_id $ifid $ifc - nexec vimage $node_id ifconfig $ifc + nexec vimage $node_id ifconfig $ifid name $ifc set ether 40:00:aa:aa:$mac_byte4:$mac_byte5 incr mac_byte5 if { $mac_byte5 >= 100 } { @@ -274,6 +270,7 @@ proc l3node.instantiate { eid node } { incr mac_byte4 } nexec vimage $node_id ifconfig $ifc link $ether + set ngnodemap($ifc@$node_id) $ifid } ser { set ifnum [string range $ifc 3 end] @@ -283,7 +280,8 @@ proc l3node.instantiate { eid node } { nexec ngctl msg $ifid: broadcast nexec ngctl name $ifid:inet hdlc$ifnum\@$node_id nexec vimage -i $node_id $ifid $ifc - nexec vimage $node_id ifconfig $ifc + nexec vimage $node_id ifconfig $ifid name $ifc + set ngnodemap($ifc@$node_id) $ifid } } } @@ -499,14 +497,14 @@ proc deployCfg {} { global node_list link_list supp_router_models global mac_byte4 mac_byte5 global remote_exec + global ngnodemap set mac_byte4 0 set mac_byte5 0 set t_start [clock seconds] - #vimageCleanup - cleanupCfg + vimageCleanup catch { nexec mv /etc/resolv.conf /etc/resolv.conf.bak } catch { nexec kldload ng_ether } @@ -553,42 +551,17 @@ proc deployCfg {} { set ber [expr [getLinkBER $link] + 0] set dup [expr [getLinkDup $link] + 0] - set ngpeer1 \ - [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 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 ngpeer2 \ - [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 0] + [lindex [[typemodel $lnode1].nghook $eid $lnode1 $ifname1] 1] set nghook2 \ - [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 1] - nexec ngctl mkpeer $ngpeer1: pipe $nghook1 upper - nexec ngctl name $ngpeer1:$nghook1 $lname - nexec ngctl connect $lname: $ngpeer2: lower $nghook2 - - # Ethernet frame has a 14-byte header - this is a temp. hack!!! - nexec ngctl msg $lname: setcfg "{ header_offset=14 }" - - # Link parameters - ;# Not working: execSetLinkParams $eid $link - nexec 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] - } - } + [lindex [[typemodel $lnode2].nghook $eid $lnode2 $ifname2] 1] + nexec ngctl connect $ngpeer1: $ngpeer2: $nghook1 $nghook2 } nexec rm -fr /var/run/quagga -- 2.39.5