]> git.entuzijast.net Git - imunes.git/commitdiff
Implementirana podrska za PC node.
authorKosta Pribić <kosta.pribic@gmail.com>
Thu, 10 Sep 2009 19:52:54 +0000 (21:52 +0200)
committerKosta Pribić <kosta.pribic@gmail.com>
Thu, 10 Sep 2009 19:52:54 +0000 (21:52 +0200)
imunes.tcl
linux/host.tcl
linux/pc.tcl [new file with mode: 0755]

index 10d43f3cfe3ed54b06699000c15b492024f50213..66fed15203d9bff12b1c0be0834bbc6bdfc28d2d 100755 (executable)
@@ -149,7 +149,7 @@ if { $gui_unix && $gui_linux } {
 #    source "$ROOTDIR/$LIBDIR/quagga.tcl"
 #    source "$ROOTDIR/$LIBDIR/xorp.tcl"
 #    source "$ROOTDIR/$LIBDIR/static.tcl"
-#    source "$ROOTDIR/$LIBDIR/pc.tcl"
+    source "$ROOTDIR/$LIBDIR/linux/pc.tcl"
     source "$ROOTDIR/$LIBDIR/linux/host.tcl"
     source "$ROOTDIR/$LIBDIR/linux/hub.tcl"
 #    source "$ROOTDIR/$LIBDIR/lanswitch.tcl"
index 9401913c3a727febb78d55bac150390104e0ba31..8b6bc786626f218298dee2bd31a3d3eab64d4330 100755 (executable)
@@ -167,14 +167,14 @@ proc $MODULE.shellcmd { node } {
     # duljina je uvijek 3
 
     if { [llength $ret] == 3 } {
-       return [lindex $ret 1]
-    } else {
-       set ret [nexec whereis -b tcsh]
-       if { [llength $ret] == 2 } {
            return [lindex $ret 1]
-       } else {
-           return "/bin/sh"
-       }
+    } else {
+           set ret [nexec whereis -b tcsh]
+           if { [llength $ret] == 2 } {
+               return [lindex $ret 1]
+           } else {
+               return "/bin/sh"
+           }
     }
 }
 
diff --git a/linux/pc.tcl b/linux/pc.tcl
new file mode 100755 (executable)
index 0000000..1abcb19
--- /dev/null
@@ -0,0 +1,253 @@
+#
+# 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: pc.tcl,v 1.17 2008/01/02 12:08:46 marko Exp $
+
+
+#****h* imunes/pc.tcl
+# NAME
+#  pc.tcl -- defines pc specific procedures
+# FUNCTION
+#  This module is used to define all the pc specific procedures.
+# NOTES
+#  Procedures in this module start with the keyword pc and
+#  end with function specific part that is the same for all the node
+#  types that work on the same layer.
+#****
+
+set MODULE pc
+
+#****f* pc.tcl/pc.layer
+# NAME
+#   pc.layer  
+# SYNOPSIS
+#   set layer [pc.layer]
+# FUNCTION
+#   Returns the layer on which the pc communicates
+#   i.e. returns NETWORK. 
+# RESULT
+#   * layer -- set to NETWORK
+#****
+
+proc $MODULE.layer {} {
+    return NETWORK
+}
+
+#****f* pc.tcl/pc.cfggen
+# NAME
+#   pc.cfggen  
+# SYNOPSIS
+#   set config [pc.cfggen $node_id]
+# FUNCTION
+#   Returns the generated configuration. This configuration represents
+#   the configuration loaded on the booting time of the virtual nodes
+#   and it is closly related to the procedure pc.bootcmd
+#   Foreach interface in the interface list of the node ip address is
+#   configured and each static route from the simulator is added.
+# INPUTS
+#   * node_id - id of the node (type of the node is pc)
+# RESULT
+#   * congif -- generated configuration 
+#****
+
+proc $MODULE.cfggen { node } {
+    upvar 0 ::cf::[set ::curcfg]::$node $node
+
+    set cfg {}
+
+    foreach ifc [ifcList $node] {
+       set addr [getIfcIPv4addr $node $ifc]
+           if { $addr != "" } {
+               lappend cfg "ifconfig $ifc inet $addr"
+           }
+           set addr [getIfcIPv6addr $node $ifc]
+           if { $addr != "" } {
+               lappend cfg "ifconfig $ifc add $addr"
+           }
+    }
+
+    #localhost se sam za sebe nece dici u OpenVZ
+    lappend cfg "ifconfig lo 127.0.0.1 netmask 255.0.0.0"
+    
+    foreach statrte [getStatIPv4routes $node] {
+           lappend cfg "route -q add -inet $statrte"
+    }
+    foreach statrte [getStatIPv6routes $node] {
+           lappend cfg "route -q add -inet6 $statrte"
+    }
+    return $cfg
+}
+
+#****f* pc.tcl/pc.bootcmd
+# NAME
+#   pc.bootcmd
+# SYNOPSIS
+#   set appl [pc.bootcmd $node_id]
+# FUNCTION
+#   Procedure bootcmd returns the application that reads and 
+#   employes the configuration generated in pc.cfggen.
+#   In this case (procedure pc.bootcmd) specific application
+#   is /bin/sh
+# INPUTS
+#   * node_id - id of the node (type of the node is pc)
+# RESULT
+#   * appl -- application that reads the configuration (/bin/sh) 
+#****
+
+proc $MODULE.bootcmd { node } {
+    return "/bin/sh"
+}
+
+#****f* pc.tcl/pc.shellcmd
+# NAME
+#   pc.shellcmd
+# SYNOPSIS
+#   set shell [pc.shellcmd $node_id]
+# FUNCTION
+#   Procedure shellcmd returns the shell that will be opened
+#   as a default shell for the system. 
+#   Procedure pc.shellcmd searches the system for bash shell,
+#   if it is not found the sh shell is used insted.
+# INPUTS
+#   * node_id - id of the node (type of the node is pc)
+# RESULT
+#   * shell -- defalut shell for the pc 
+#****
+
+proc $MODULE.shellcmd { node } {
+    set ret [nexec whereis -b bash]
+    # OpenVZ, $ret ce biti bash: /bin/bash /etc/bash.bashrc
+    # duljina je uvijek 3
+
+    if { [llength $ret] == 3 } {
+           return [lindex $ret 1]
+    } else {
+           set ret [nexec whereis -b tcsh]
+           if { [llength $ret] == 2 } {
+               return [lindex $ret 1]
+           } else {
+               return "/bin/sh"
+           }
+    }
+}
+
+#****f* pc.tcl/pc.instantiate
+# NAME
+#   pc.instantiate
+# SYNOPSIS
+#   pc.instantiate $eid $node_id
+# FUNCTION
+#   Procedure instantiate creates a new virtaul node
+#   for a given node in imunes. 
+#   Procedure pc.instantiate cretaes a new virtual node
+#   with all the interfaces and CPU parameters as defined
+#   in imunes. 
+# INPUTS
+#   * eid - experiment id
+#   * node_id - id of the node (type of the node is pc)
+#****
+
+proc $MODULE.instantiate { eid node } {
+    l3node.instantiate $eid $node
+}
+
+
+#****f* pc.tcl/pc.start
+# NAME
+#   pc.start
+# SYNOPSIS
+#   pc.start $eid $node_id
+# FUNCTION
+#   Starts a new pc. The node can be started if it is instantiated. 
+#   Simulates the booting proces of a pc, by calling l3node.start 
+#   procedure.
+# INPUTS
+#   * eid - experiment id
+#   * node_id - id of the node (type of the node is pc)
+#****
+proc $MODULE.start { eid node } {
+    l3node.start $eid $node
+}
+
+#****f* pc.tcl/pc.shutdown
+# NAME
+#   pc.shutdown
+# SYNOPSIS
+#   pc.shutdown $eid $node_id
+# FUNCTION
+#   Shutdowns a pc. Simulates the shutdown proces of a pc, 
+#   by calling the l3node.shutdown procedure.
+# INPUTS
+#   * eid - experiment id
+#   * node_id - id of the node (type of the node is pc)
+#****
+proc $MODULE.shutdown { eid node } {
+    l3node.shutdown $eid $node
+}
+
+
+#****f* pc.tcl/pc.destroy
+# NAME
+#   pc.destroy
+# SYNOPSIS
+#   pc.destroy $eid $node_id
+# FUNCTION
+#   Destroys a pc. Destroys all the interfaces of the pc 
+#   and the vimage itself by calling l3node.destroy procedure. 
+# INPUTS
+#   * eid - experiment id
+#   * node_id - id of the node (type of the node is pc)
+#****
+proc $MODULE.destroy { eid node } {
+    l3node.destroy $eid $node
+}
+
+
+#****f* pc.tcl/pc.nghook
+# NAME
+#   pc.nghook
+# SYNOPSIS
+#   pc.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. This procedure calls l3node.hook procedure and
+#   passes the result of that procedure.
+# 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 } {
+    return [l3node.nghook $eid $node $ifc]
+}
+