From d3b78121d569e9fcf018dd2dbd004e596f2aa09a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kosta=20Pribi=C4=87?= Date: Wed, 9 Sep 2009 13:45:51 +0200 Subject: [PATCH] implementiran hub kao L2 bridge, za sada radi samo sa jednim linkom (portom) treba dodati detekciju da vec postoji hub kod dodavanja linka (porta) --- imunes.tcl | 2 +- linkcfg.tcl | 8 ++- linux/exec.tcl | 64 +++++++++++++++----- linux/hub.tcl | 157 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+), 19 deletions(-) create mode 100755 linux/hub.tcl diff --git a/imunes.tcl b/imunes.tcl index 4fd9dd8..c3a3429 100755 --- a/imunes.tcl +++ b/imunes.tcl @@ -151,7 +151,7 @@ if { $gui_unix && $gui_linux } { # source "$ROOTDIR/$LIBDIR/static.tcl" # source "$ROOTDIR/$LIBDIR/pc.tcl" source "$ROOTDIR/$LIBDIR/linux/host.tcl" -# source "$ROOTDIR/$LIBDIR/hub.tcl" + source "$ROOTDIR/$LIBDIR/linux/hub.tcl" # source "$ROOTDIR/$LIBDIR/lanswitch.tcl" # source "$ROOTDIR/$LIBDIR/rj45.tcl" } else { diff --git a/linkcfg.tcl b/linkcfg.tcl index 82ecc57..78c51d3 100755 --- a/linkcfg.tcl +++ b/linkcfg.tcl @@ -690,6 +690,10 @@ proc newLink { lnode1 lnode2 } { set ifname2 [newIfc [chooseIfName $lnode2 $lnode1] $lnode2] lappend $lnode2 "interface-peer {$ifname2 $lnode1}" + puts "Create link" + puts " nodetype 1: [nodeType $lnode1]" + puts " nodetype 2: [nodeType $lnode2]" + lappend $link "nodes {$lnode1 $lnode2}" if { ([nodeType $lnode1] == "lanswitch" || \ [nodeType $lnode2] == "lanswitch" || \ @@ -711,8 +715,8 @@ proc newLink { lnode1 lnode2 } { } if { [nodeType $lnode1] != "pseudo" && [[typemodel $lnode2].layer] == "NETWORK" } { - autoIPv4addr $lnode2 $ifname2 - autoIPv6addr $lnode2 $ifname2 + autoIPv4addr $lnode2 $ifname2 + autoIPv6addr $lnode2 $ifname2 } if { [nodeType $lnode1] != "router" && [nodeType $lnode2] != "pseudo" && diff --git a/linux/exec.tcl b/linux/exec.tcl index 2acff90..7a7c3b7 100755 --- a/linux/exec.tcl +++ b/linux/exec.tcl @@ -690,17 +690,41 @@ proc deployCfg {} { # puts " nexec vimage $eid ngctl connect $lname: $ngpeer2: lower $nghook2 " # puts ">>>>>>>>>>kreiranje linkova" - set host_if_a $ngpeer1 - set host_if_b $ngpeer2 - set bridge $lname + - puts "\nCreating bridge $bridge" - nexec brctl addbr $bridge - nexec brctl addif $bridge $host_if_a - nexec brctl addif $bridge $host_if_b - nexec ifconfig $bridge up - puts " Bridge $bridge is up, connected interfaces $host_if_a and $host_if_b" + if { [[typemodel $lnode1].layer] == "LINK" || [[typemodel $lnode2].layer] == "LINK" } { + #slucaj kad se spaja na L2 uredjaj (hub) + + if { [[typemodel $lnode1].layer] == "LINK" } { + set port_if $ngpeer2 + set bridge $lnode1 + } else { + set port_if $ngpeer1 + set bridge $lnode2 + } + + puts "\nCreating bridge $bridge (L2 hub emulation)" + + nexec brctl addbr $bridge + nexec brctl addif $bridge $port_if + nexec ifconfig $bridge up + puts " L2 device $bridge is up, connected interface port_if" + + } else { + # Slucaj kad se radi link izmedju dva L3 uredjaja (standardno) + set host_if_a $ngpeer1 + set host_if_b $ngpeer2 + set bridge $lname + + puts "\nCreating bridge $bridge" + + nexec brctl addbr $bridge + nexec brctl addif $bridge $host_if_a + nexec brctl addif $bridge $host_if_b + nexec ifconfig $bridge up + puts " Bridge $bridge is up, connected interfaces $host_if_a and $host_if_b" + } # FreeBSD-specific # # Ethernet frame has a 14-byte header - this is a temp. hack!!! @@ -853,21 +877,29 @@ proc vimageCleanup { eid } { # OpenVZ - samo nam treba popis nodeova za pogasiti upvar 0 ::cf::[set ::curcfg]::node_list node_list + puts "Stopping VEs and destroying private enviroments..." foreach node $node_list { - set stattxt "Stopping VE $node" - statline $stattxt - nexec vzctl stop $node - set stattxt "Destroying VE $node" - statline $stattxt - nexec vzctl destroy $node + if { [[typemodel $node].layer] != "LINK" } { + set stattxt "Stopping VE $node" + statline $stattxt + nexec vzctl stop $node + set stattxt "Destroying VE $node" + statline $stattxt + nexec vzctl destroy $node + } else { + # L2 uredjaji kao hub i switch se u OpenVZ varijanti emulirajusa bridge + # suceljem a ne sa VEom, stoga nema se sta gasiti + puts " Node $node is a L2 device emulated with a bridge. Stopping pending bridge cleanup." } - + } + puts " Done." #TODO: prebaciti u tcl kod, error handling i modificirati da ne # brise bridgeove bez diskriminacije nego one koje je imunes # napravio puts "\nBridge cleanup in main host" catch { nexec ./bridge_cleanup.sh } + puts " Done." # FreeBSD metoda: diff --git a/linux/hub.tcl b/linux/hub.tcl new file mode 100755 index 0000000..04eb596 --- /dev/null +++ b/linux/hub.tcl @@ -0,0 +1,157 @@ +# +# Copyright 2005-2008 University of Zagreb, Croatia. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# This work was supported in part by Croatian Ministry of Science +# and Technology through the research contract #IP-2003-143. +# + +# $Id: hub.tcl,v 1.15 2009/03/17 14:35:19 marko Exp $ + + +#****h* imunes/hub.tcl +# NAME +# hub.tcl -- defines hub specific procedures +# FUNCTION +# This module is used to define all the hub specific procedures. +# NOTES +# Procedures in this module start with the keyword hub and +# end with function specific part that is the same for all the +# node types that work on the same layer. +#**** + +set MODULE hub + +#****f* hub.tcl/hub.layer +# NAME +# hub.layer +# SYNOPSIS +# set layer [hub.layer] +# FUNCTION +# Returns the layer on which the hub operates +# i.e. returns LINK. +# RESULT +# * layer -- set to LINK +#**** + +proc $MODULE.layer {} { + return LINK +} + +#****f* hub.tcl/hub.instantiate +# NAME +# hub.instantiate +# SYNOPSIS +# hub.instantiate $eid $node_id +# FUNCTION +# Procedure hub.instantiate cretaes a new netgraph node +# of the type hub. The name of the netgraph node is in form +# of exprimentId_nodeId. +# INPUTS +# * eid - experiment id +# * node_id - id of the node (type of the node is hub) +#**** + +proc $MODULE.instantiate { eid node } { + upvar 0 ::cf::[set ::curcfg]::ngnodemap ngnodemap + puts "\nhub.INSTANTIATE" + #puts " catch {exec vimage $eid ngctl mkpeer hub anchor anchor | tail -1} resp" + #puts " catch {exec vimage $eid ngctl l | fgrep \" Name: \" | cut -c51-58 | xargs echo } nglist" + #set id [lindex $nglist 0] + + #puts " >>> id = $id" + #puts " catch {exec vimage $eid ngctl name \[$id\]: $node}" + set ngnodemap($eid\.$node) $node + puts " >>>$eid\.$node $node" +} + +#****f* hub.tcl/hub.start +# NAME +# hub.start +# SYNOPSIS +# hub.start $eid $node_id +# FUNCTION +# Starts a new hub. Since hub has no starting code, +# this procedure does nothing. +# INPUTS +# * eid - experiment id +# * node_id - id of the node (type of the node is hub) +#**** +proc $MODULE.start { eid node } { +} + +#****f* hub.tcl/hub.shutdown +# NAME +# hub.shutdown +# SYNOPSIS +# hub.shutdown $eid $node_id +# FUNCTION +# Shutdowns a hub. Since hub has no shutdown code, +# this procedure does nothing. +# INPUTS +# * eid - experiment id +# * node_id - id of the node (type of the node is hub) +#**** +proc $MODULE.shutdown { eid node } { +} + +#****f* hub.tcl/hub.destroy +# NAME +# hub.destroy +# SYNOPSIS +# hub.destroy $eid $node_id +# FUNCTION +# Destroys a hub. Destroys the netgraph node that represents +# the hub by sending a shutdown message. +# INPUTS +# * eid - experiment id +# * node_id - id of the node (type of the node is hub) +#**** +proc $MODULE.destroy { eid node } { + catch { nexec vimage $eid ngctl msg $node: shutdown } +} + +#****f* hub.tcl/hub.nghook +# NAME +# hub.nghook +# SYNOPSIS +# hub.nghook $eid $node_id $ifc +# FUNCTION +# Returns the id of the netgraph node and the name of the +# netgraph hook which is used for connecting two netgraph +# nodes. Netgraph node name is in format experimentId_nodeId +# and the netgraph hook is in the form of linkN, where N is +# interface number. +# INPUTS +# * eid - experiment id +# * node_id - node id +# * ifc - interface name +# RESULT +# * nghook - the list containing netgraph node id and the +# netgraph hook (ngNode ngHook). +#**** + +proc $MODULE.nghook { eid node ifc } { + set ifunit [string range $ifc 1 end] + return [list $eid\.$node link$ifunit] +} -- 2.39.5