nsenode.tcl 3.66 KB
Newer Older
1
# -*- tcl -*-
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2002, 2006 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23 24
#

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
######################################################################
# nsenode.tcl
#
# This defines the NSENode class.  Instances of this class are created by
# the 'nsenode' method of Simulator.  
# This node supports a method make-simulated and when invoked with
# code in-between {} as an argument, treats the code as simulated
# and runs NSE on the physical NSENode with the provided script
######################################################################

Class NSENode -superclass Node

# need to have a single namespace for simulated node names
# lets have simulated node -> nsenode map

# need to support simulated to real node links, simulated to simulated
# across nse nodes => we need a duplex-link specialization even in
# child interpreters

# routing must be
# manually enabled so that a RAW IP packet written should automatically
# make it out

NSENode instproc init {s} {

    set new_classes(NSENode) {}
    $self next $s
    $self set nseconfig ""
    $self set simcode_present 0
}

NSENode instproc make-simulated {args} {

    var_import ::GLOBALS::simulated
    var_import ::GLOBALS::curnsenode
    $self instvar nseconfig
    $self instvar simcode_present

    set simulated 1
    set curnsenode $self
    global script
    set script [string trim $args "\{\}"]

    if { $script == {} } {
	set simulated 0
	set curnsenode ""
	return
    }

    set simcode_present 1

    # we ignore any type of errors coz they have
    # been caught when we ran the script through NSE
    catch {uplevel 1 eval $script}

    append nseconfig $script

    set simulated 0
    set curnsenode ""
}

NSENode instproc updatedb {DB} {
    $self instvar nseconfig
    $self instvar simcode_present
89
    var_import ::GLOBALS::sim_osname
90 91 92 93 94 95 96 97 98 99 100

    # for all the simulated nodes, we need to find out if
    # they are connected to a real node and if so, find the
    # ip address of the port on nsenode

    foreach node [Node info instances] {
	if { [$node set simulated] == 1 && [$node set nsenode] == $self } {

	    append nseconfig "\n\n\$$node set simulated 1\n"
	    append nseconfig "\$$node set nsenode $self\n"
	    
101 102 103 104 105 106 107 108 109
	    set nsenode_vportlist [$node set nsenode_vportlist]
	    if { $nsenode_vportlist != {} } {
		append nseconfig "\$$node set nsenode_vportlist \[list $nsenode_vportlist]\n"

		set ipaddrlist {}
		foreach v $nsenode_vportlist {
		    lappend ipaddrlist [$self ip $v]
		}
		append nseconfig "\$$node set nsenode_ipaddrlist \[list $ipaddrlist]\n\n"
110 111 112 113 114 115 116 117
	    }
	}
    }

    if { $simcode_present == 1 } {
	append nseconfig "set simcode_present $simcode_present\n\n"
    }

118 119 120 121 122
    # We prefer to get a pc850 if available to take advantage of more CPU horsepower
    tb-make-soft-vtype pcnsenode {pc850}
    tb-set-hardware $self pcnsenode

    # NSE code runs only FreeBSD as of now. 
123
    $self set osid $sim_osname
124 125

    # The Node class's updatedb method updates the DB
126 127
    $self next $DB
}