SimCommand.cc

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 #include <stdlib.h>
00040 
00041 #include "NodeCommand.h"
00042 #include "SimCommand.h"
00043 #include "Simulator.h"
00044 #include "Topology.h"
00045 
00046 #include "routing/BundleRouter.h"
00047 
00048 // #include "SimConvergenceLayer.h"
00049 // #include "TrAgent.h"
00050 
00051 using namespace dtn;
00052 
00053 namespace dtnsim {
00054 
00055 SimCommand::SimCommand()
00056     : TclCommand("sim")
00057 {
00058     bind_d("runtill", &Simulator::runtill_, "Run simulation for this many steps.");
00059     bind_s("route_type", &BundleRouter::Config.type_, "static",
00060         "What type of router to use.");
00061 }
00062 
00063 int
00064 SimCommand::exec(int argc, const char** argv, Tcl_Interp* tclinterp)
00065 {
00066     (void)tclinterp;
00067     if (argc < 3) {
00068         wrong_num_args(argc, argv, 2, 3, 11);
00069         return TCL_ERROR;
00070     }
00071     
00072     // pull out the time and subcommand
00073     char* end;
00074     double time = strtod(argv[1], &end);
00075     if (*end != '\0') {
00076         resultf("time value '%s' invalid", argv[1]);
00077         return TCL_ERROR;
00078     }
00079     const char* cmd = argv[2];
00080     
00081     if (strcmp(cmd, "create_node") == 0) {
00082         // sim <time> node create <name>
00083         if (argc < 4) {
00084             wrong_num_args(argc, argv, 2, 4, 4);
00085             return TCL_ERROR;
00086         }
00087 
00088         if (time != 0) {
00089             resultf("all nodes must be created at time 0");
00090             return TCL_ERROR;
00091         }
00092 
00093         const char* name = argv[3];
00094 
00095         // make sure no tcl command already exists with the given name
00096         oasys::TclCommandInterp* interp = oasys::TclCommandInterp::instance();
00097         if (interp->lookup(name)) {
00098             resultf("error creating node %s: tcl command already exists",
00099                     name);
00100             return TCL_ERROR;
00101         }
00102         
00103         Node* node = Topology::create_node(name);
00104 
00105         NodeCommand* cmd = new NodeCommand(node);
00106         interp->reg(cmd);
00107         
00108         return TCL_OK;
00109     }
00110     
00111 //     if (strcmp(cmd, "create_consumer") == 0) {
00112 //         if (argc < 4) {
00113 //             wrong_num_args(argc, argv, 2, 4, 4);
00114 //             return TCL_ERROR;
00115 //         }
00116 //         int id = atoi(argv[3]) ;
00117 //         Topology::create_consumer(id);       
00118 //         log_info("create_consumer %d \n",id);
00119 //     }
00120     
00121 //     // simulator time create_contact <id> <src> <dst> <bw> <delay> <isup> <up> <down>
00122 //     if (strcmp(cmd, "create_contact") == 0) {
00123 //         if (argc < 11) {
00124 //             wrong_num_args(argc, argv, 2, 11, 11);
00125 //             return TCL_ERROR;
00126 //         }
00127         
00128 //         int id = atoi(argv[3]) ;
00129 //         int src = atoi(argv[4]) ;
00130 //         int dst = atoi(argv[5]) ;
00131 //         int  bw = atoi(argv[6]) ;
00132 //         int delay = atoi(argv[7]) ;
00133 //         int isup =  atoi(argv[8]) ;
00134 //         int up = atoi(argv[9]) ;
00135 //         int down = atoi(argv[10]) ;
00136         
00137 //         Topology::create_contact(id,src,dst,bw,delay,isup,up,down);
00138 //         log_info("new contact: (%d->%d), param:[%d,%d] \n",src,dst,bw,delay);
00139 
00140 
00141 
00142         
00143         
00144 //     }
00145     
00146 //     // simulator time tr <size> <batch> <reps> <gap>
00147 //     if (strcmp(cmd, "create_tr") == 0) {
00148 //         if (argc < 9) {
00149 //             wrong_num_args(argc, argv, 2, 9,9);
00150 //             return TCL_ERROR;
00151 //         }
00152 //         int src = atoi(argv[3]) ;
00153 //         int dst = atoi(argv[4]) ;
00154 //         int size = atoi(argv[5]) ;
00155 //         int batch = atoi(argv[6]) ;
00156 //         int reps = atoi(argv[7]) ;
00157 //         int gap = atoi(argv[8]) ;
00158 //         TrAgent* tr = new TrAgent(time,src,dst,size,batch,reps,gap);
00159 //         tr->start();
00160 //         log_info("creating traffic btw (src,dst) (%d,%d)",src,dst);
00161 //     }
00162     
00163     
00164 //     if (strcmp(cmd, "cup") == 0) {
00165 //         int id = atoi(argv[3]) ;
00166 //         bool forever = false;
00167 //         if (argc == 5) {
00168 //             if (atoi(argv[4]) != 0) forever = true;
00169 //         }
00170 //         Event_contact_up* e = 
00171 //             new Event_contact_up(time,Topology::contact(id));
00172 //         e->forever_ = forever;
00173 //         Simulator::post(e);
00174 //     }
00175 
00176     
00177 //     if (strcmp(cmd, "cdown") == 0) {
00178 //         int id = atoi(argv[3]) ;
00179 //         bool forever = false;
00180 //         if (argc == 5) {
00181 //             if (atoi(argv[4]) != 0) forever = true;
00182 //         }
00183         
00184 //         Event_contact_down* e = 
00185 //             new Event_contact_down(time,Topology::contact(id));
00186 //         e->forever_ = forever;
00187 //         Simulator::post(e);
00188 //     }
00189     
00190 //     if (strcmp(cmd, "print_stats") == 0) {
00191 //         Event_print_stats* e = 
00192 //             new Event_print_stats(time,Simulator::instance());
00193 //         log_info("COM: print_stats at:%3f event:%p",time,e);
00194 //         Simulator::post(e);
00195 //     }
00196 
00197     resultf("sim: unsupported subcommand %s", cmd);
00198     return TCL_ERROR;
00199 }
00200 
00201 
00202 } // namespace dtnsim

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1