nse.agent.tcl 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
# -*- tcl -*-
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#

######################################################################
# nse.agent.tcl
#
#
######################################################################

Class Agent

# Agent
Agent instproc init {args} {
    var_import GLOBALS::last_class
    var_import GLOBALS::last_cmd

    $self set nseconfig {}
    $self set classname "Agent"
    $self set objname $self
    $self set node {}
    $self set application {}
    $self set destination {}
    $self set ip {}
    $self set port {}

    $self instvar classname

    if { $last_cmd == {} } {
	if { $args == {} } {
	    $self set createcmd "\[new $classname]"
	} else {
	    $self set createcmd "\[new $classname $args]"
	}
    } else {
	$self set createcmd $last_cmd
    }

    real_set last_class $self
}
Agent instproc set_node {node} {
    $self set node $node
}
Agent instproc get_node {} {
    $self instvar node
    return $node
}
Agent instproc set_application {application} { 
    $self set application $application
}

Agent instproc connect {dst} {
    $self instvar destination
    $self instvar nseconfig
    $self instvar objname
    
    real_set destination $dst
    real_set sim [lindex [Simulator info instances] 0]
    append nseconfig "\$[$sim set objname] ip-connect \$$objname [$dst set ip] [$dst set port]\n"
}

Agent instproc unknown {m args} {

    $self instvar nseconfig
    $self instvar objname

    append nseconfig "\$$objname $m $args\n"
}

Class Application

# Application
Application instproc init {args} {
    var_import GLOBALS::last_class
    var_import GLOBALS::last_cmd

    $self set nseconfig {}
    $self set classname "Application"
    $self set objname $self

    $self instvar classname

    if { $last_cmd == {} } {
	if { $args == {} } {
	    $self set createcmd "\[new $classname]"
	} else {
	    $self set createcmd "\[new $classname $args]"
	}
    } else {
	$self set createcmd $last_cmd
    }

    real_set last_class $self
}

Application instproc attach-agent {agent} {
    $self set agent $agent
    $agent set_application $self
    $self instvar objname
    $self instvar createcmd
    $self instvar nseconfig

    append nseconfig "\$$objname attach-agent \$[$agent set objname]\n"
}

Application instproc get_node {} {
    $self instvar agent
    return [$agent get_node]
}

Application instproc unknown {m args} {

    $self instvar nseconfig
    $self instvar objname

    append nseconfig "\$$objname $m $args\n"
}