00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <errno.h>
00040 #include <string>
00041 #include <sys/time.h>
00042
00043 #include <oasys/debug/Log.h>
00044 #include <oasys/tclcmd/TclCommand.h>
00045 #include <oasys/util/Getopt.h>
00046 #include <oasys/util/Random.h>
00047
00048 #include "ConnCommand.h"
00049 #include "Simulator.h"
00050 #include "SimCommand.h"
00051 #include "SimConvergenceLayer.h"
00052 #include "contacts/ContactManager.h"
00053 #include "cmd/ParamCommand.h"
00054 #include "naming/SchemeTable.h"
00055
00059 namespace dtnsim {}
00060
00061 using namespace dtn;
00062 using namespace dtnsim;
00063
00064 int
00065 main(int argc, char** argv)
00066 {
00067
00068 int random_seed;
00069 bool random_seed_set = false;
00070 std::string conf_file;
00071 bool conf_file_set = false;
00072 std::string logfile("-");
00073 std::string loglevelstr;
00074 oasys::log_level_t loglevel;
00075
00076 oasys::Getopt::addopt(
00077 new oasys::StringOpt('c', "conf", &conf_file, "<conf>",
00078 "set the configuration file", &conf_file_set));
00079
00080 oasys::Getopt::addopt(
00081 new oasys::IntOpt('s', "seed", &random_seed, "seed",
00082 "random number generator seed", &random_seed_set));
00083
00084 oasys::Getopt::addopt(
00085 new oasys::StringOpt('o', "output", &logfile, "<output>",
00086 "file name for logging output "
00087 "(default - indicates stdout)"));
00088
00089 oasys::Getopt::addopt(
00090 new oasys::StringOpt('l', NULL, &loglevelstr, "<level>",
00091 "default log level [debug|warn|info|crit]"));
00092
00093 oasys::Getopt::getopt(argv[0], argc, argv);
00094
00095 int remainder = oasys::Getopt::getopt(argv[0], argc, argv);
00096
00097 if (!conf_file_set && remainder != argc) {
00098 conf_file.assign(argv[remainder]);
00099 conf_file_set = true;
00100 remainder++;
00101 }
00102
00103 if (remainder != argc) {
00104 fprintf(stderr, "invalid argument '%s'\n", argv[remainder]);
00105 oasys::Getopt::usage("dtnsim");
00106 exit(1);
00107 }
00108
00109 if (!conf_file_set) {
00110 fprintf(stderr, "must set the simulator conf file\n");
00111 oasys::Getopt::usage("dtnsim");
00112 exit(1);
00113 }
00114
00115
00116 if (loglevelstr.length() == 0) {
00117 loglevel = LOG_DEFAULT_THRESHOLD;
00118 } else {
00119 loglevel = oasys::str2level(loglevelstr.c_str());
00120 if (loglevel == oasys::LOG_INVALID) {
00121 fprintf(stderr, "invalid level value '%s' for -l option, "
00122 "expected debug | info | warning | error | crit\n",
00123 loglevelstr.c_str());
00124 exit(1);
00125 }
00126 }
00127
00128
00129
00130 Simulator* s = new Simulator();
00131 Simulator::init(s);
00132
00133
00134 oasys::Log::init("-", loglevel, "--");
00135 log_info("/sim", "dtn simulator initializing...");
00136
00137
00138 if (!random_seed_set) {
00139 struct timeval tv;
00140 gettimeofday(&tv, NULL);
00141 random_seed = tv.tv_usec;
00142 }
00143 log_info("/sim", "random seed is %u\n", random_seed);
00144 oasys::Random::seed(random_seed);
00145
00146
00147 oasys::TclCommandInterp::init(argv[0]);
00148 oasys::TclCommandInterp* interp = oasys::TclCommandInterp::instance();
00149 interp->reg(new ConnCommand());
00150 interp->reg(new ParamCommand());
00151 interp->reg(new SimCommand());
00152
00153
00154 SchemeTable::create();
00155 SimConvergenceLayer::init();
00156 ConvergenceLayer::add_clayer(SimConvergenceLayer::instance());
00157
00158 if (interp->exec_file(conf_file.c_str()) != 0) {
00159 log_err("/sim", "error in configuration file, exiting...");
00160 exit(1);
00161 }
00162
00163
00164 Simulator::instance()->run();
00165 }