00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #include <errno.h>
00022 #include <string>
00023 #include <sys/time.h>
00024
00025 #include <oasys/debug/Log.h>
00026 #include <oasys/tclcmd/TclCommand.h>
00027 #include <oasys/util/Getopt.h>
00028 #include <oasys/util/Random.h>
00029
00030 #include "dtn-version.h"
00031 #include "ConnCommand.h"
00032 #include "Simulator.h"
00033 #include "SimCommand.h"
00034 #include "SimConvergenceLayer.h"
00035 #include "contacts/ContactManager.h"
00036 #include "cmd/RouteCommand.h"
00037 #include "cmd/StorageCommand.h"
00038 #include "naming/SchemeTable.h"
00039
00040 #include "servlib/bundling/BundleTimestamp.h"
00041 #include "servlib/bundling/BundleProtocol.h"
00042 #include "oasys/storage/MemoryStore.h"
00043 #include "oasys/storage/StorageConfig.h"
00044 #include "oasys/util/App.h"
00045
00046 using namespace dtn;
00047 using namespace dtnsim;
00048
00049 class DTNSim : public oasys::App {
00050 public:
00051 DTNSim();
00052 void fill_options();
00053 void validate_options(int argc,
00054 char* const argv[],
00055 int remainder);
00056 int main(int argc, char* const argv[]);
00057
00058 protected:
00059 bool console_;
00060 std::string testopts_;
00061 };
00062
00063
00064 DTNSim::DTNSim()
00065 : App("DTNSim", "dtnsim", dtn_version),
00066 console_(false)
00067 {
00068 random_seed_ = 123456789;
00069 random_seed_set_ = true;
00070 }
00071
00072
00073 void
00074 DTNSim::fill_options()
00075 {
00076 App::fill_default_options(CONF_FILE_OPT);
00077
00078 opts_.addopt(
00079 new oasys::BoolOpt('C', "console", &console_,
00080 "run the tcl console after simulation exits"));
00081
00082 opts_.addopt(
00083 new oasys::StringOpt('O', "opts", &testopts_,
00084 "<opts>", "simulation options"));
00085 }
00086
00087
00088 void
00089 DTNSim::validate_options(int argc,
00090 char* const argv[],
00091 int remainder)
00092 {
00093 if (!conf_file_set_ && remainder != argc) {
00094 conf_file_.assign(argv[remainder]);
00095 conf_file_set_ = true;
00096 remainder++;
00097 }
00098
00099 if (remainder != argc) {
00100 fprintf(stderr, "invalid argument '%s'\n", argv[remainder]);
00101 opts_.usage("dtnsim");
00102 exit(1);
00103 }
00104
00105 if (!conf_file_set_) {
00106 fprintf(stderr, "must set the simulator conf file\n");
00107 opts_.usage("dtnsim");
00108 exit(1);
00109 }
00110 }
00111
00112
00113 int
00114 DTNSim::main(int argc, char* const argv[])
00115 {
00116 init_app(argc, argv);
00117
00118
00119 dtn::BundleTimestamp::TIMEVAL_CONVERSION = 0;
00120
00121
00122
00123 Simulator::create();
00124
00125
00126
00127 if (oasys::TclCommandInterp::init(argv[0]) != 0)
00128 {
00129 log_crit("Can't init TCL");
00130 exit(1);
00131 }
00132 oasys::TclCommandInterp* interp = oasys::TclCommandInterp::instance();
00133 interp->reg(new ConnCommand());
00134 interp->reg(new dtn::RouteCommand());
00135 interp->reg(new SimCommand());
00136 log_info("registered dtnsim commands");
00137
00138
00139 SchemeTable::create();
00140 SimConvergenceLayer::init();
00141 ConvergenceLayer::add_clayer(SimConvergenceLayer::instance());
00142 BundleProtocol::init_default_processors();
00143 log_info("intialized dtnsim components");
00144
00145
00146 oasys::StringBuffer seed_cmd("expr srand(%u)", random_seed_);
00147 interp->exec_command(seed_cmd.c_str());
00148
00149
00150 oasys::StringBuffer opts_cmd("set opts \"%s\"", testopts_.c_str());
00151 interp->exec_command(opts_cmd.c_str());
00152
00153
00154 log_info("parsing configuration file %s...", conf_file_.c_str());
00155 if (interp->exec_file(conf_file_.c_str()) != 0) {
00156 log_err("error in configuration file, exiting...");
00157 exit(1);
00158 }
00159
00160
00161 Simulator::instance()->run();
00162
00163 if (console_) {
00164
00165 oasys::TclCommandInterp::instance()->exec_command(
00166 "puts \"Simulation complete -- entering console (Control-D to exit)...\"");
00167 Simulator::instance()->run_console(true);
00168 }
00169
00170 return 0;
00171 }
00172
00173
00174 int main(int argc, char* const argv[])
00175 {
00176 DTNSim d;
00177 return d.main(argc, argv);
00178 }