Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > d9faa203c2b0b6fbb179d93daaea81b7 > files > 1745

libdtn-devel-2.6.0-1mdv2009.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: dtnsim.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<h1>dtnsim.cc</h1><a href="dtnsim_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2004-2006 Intel Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;oasys/debug/Log.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;oasys/tclcmd/TclCommand.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;oasys/util/Getopt.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;oasys/util/Random.h&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="dtn-version_8h.html">dtn-version.h</a>"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="ConnCommand_8h.html">ConnCommand.h</a>"</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="Simulator_8h.html">Simulator.h</a>"</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="SimCommand_8h.html">SimCommand.h</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="SimConvergenceLayer_8h.html">SimConvergenceLayer.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="ContactManager_8h.html">contacts/ContactManager.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="RouteCommand_8h.html">cmd/RouteCommand.h</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="StorageCommand_8h.html">cmd/StorageCommand.h</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="SchemeTable_8h.html">naming/SchemeTable.h</a>"</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="BundleTimestamp_8h.html">servlib/bundling/BundleTimestamp.h</a>"</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include "<a class="code" href="BundleProtocol_8h.html">servlib/bundling/BundleProtocol.h</a>"</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include "oasys/storage/MemoryStore.h"</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include "oasys/storage/StorageConfig.h"</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include "oasys/util/App.h"</span>
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="keyword">using namespace </span>dtn;
<a name="l00047"></a>00047 <span class="keyword">using namespace </span>dtnsim;
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="classDTNSim.html">00049</a> <span class="keyword">class </span><a class="code" href="classDTNSim.html">DTNSim</a> : <span class="keyword">public</span> oasys::App {
<a name="l00050"></a>00050 <span class="keyword">public</span>:
<a name="l00051"></a>00051     <a class="code" href="classDTNSim.html#949f6eb6493a6512d458673c8145ae86">DTNSim</a>();
<a name="l00052"></a>00052     <span class="keywordtype">void</span> <a class="code" href="classDTNSim.html#ce9803e14db0a316fa13d5c34cdd4c16">fill_options</a>();
<a name="l00053"></a>00053     <span class="keywordtype">void</span> <a class="code" href="classDTNSim.html#9359cd074b3fa398c89c67f4d1eebcc1">validate_options</a>(<span class="keywordtype">int</span> argc,
<a name="l00054"></a>00054                           <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[],
<a name="l00055"></a>00055                           <span class="keywordtype">int</span> remainder);
<a name="l00056"></a>00056     <span class="keywordtype">int</span> <a class="code" href="classDTNSim.html#040994ed54708fc6ef4f808f437daec2">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[]);
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 <span class="keyword">protected</span>:
<a name="l00059"></a><a class="code" href="classDTNSim.html#4d880d10b720a19a2bb16e5a4efd704b">00059</a>     <span class="keywordtype">bool</span> <a class="code" href="classDTNSim.html#4d880d10b720a19a2bb16e5a4efd704b">console_</a>;
<a name="l00060"></a><a class="code" href="classDTNSim.html#bbcf6a280e582d97aba5483ee8ad70d6">00060</a>     std::string <a class="code" href="classDTNSim.html#bbcf6a280e582d97aba5483ee8ad70d6">testopts_</a>;
<a name="l00061"></a>00061 };
<a name="l00062"></a>00062     
<a name="l00063"></a>00063 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00064"></a><a class="code" href="classDTNSim.html#949f6eb6493a6512d458673c8145ae86">00064</a> <a class="code" href="classDTNSim.html#949f6eb6493a6512d458673c8145ae86">DTNSim::DTNSim</a>()
<a name="l00065"></a>00065     : App(<span class="stringliteral">"DTNSim"</span>, <span class="stringliteral">"dtnsim"</span>, <a class="code" href="dtnd_8cc.html#ae46a12fba1b20fe0278beb099ae28ee">dtn_version</a>),
<a name="l00066"></a>00066       console_(false)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068     random_seed_     = 123456789;
<a name="l00069"></a>00069     random_seed_set_ = <span class="keyword">true</span>;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00073"></a>00073 <span class="keywordtype">void</span>
<a name="l00074"></a><a class="code" href="classDTNSim.html#ce9803e14db0a316fa13d5c34cdd4c16">00074</a> <a class="code" href="classDTNSim.html#ce9803e14db0a316fa13d5c34cdd4c16">DTNSim::fill_options</a>()
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076     App::fill_default_options(CONF_FILE_OPT);
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     opts_.addopt(
<a name="l00079"></a>00079         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'C'</span>, <span class="stringliteral">"console"</span>, &amp;<a class="code" href="classDTNSim.html#4d880d10b720a19a2bb16e5a4efd704b">console_</a>,
<a name="l00080"></a>00080                            <span class="stringliteral">"run the tcl console after simulation exits"</span>));
<a name="l00081"></a>00081 
<a name="l00082"></a>00082     opts_.addopt(
<a name="l00083"></a>00083         <span class="keyword">new</span> oasys::StringOpt(<span class="charliteral">'O'</span>, <span class="stringliteral">"opts"</span>, &amp;<a class="code" href="classDTNSim.html#bbcf6a280e582d97aba5483ee8ad70d6">testopts_</a>,
<a name="l00084"></a>00084                              <span class="stringliteral">"&lt;opts&gt;"</span>, <span class="stringliteral">"simulation options"</span>));
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00088"></a>00088 <span class="keywordtype">void</span>
<a name="l00089"></a><a class="code" href="classDTNSim.html#9359cd074b3fa398c89c67f4d1eebcc1">00089</a> <a class="code" href="classDTNSim.html#9359cd074b3fa398c89c67f4d1eebcc1">DTNSim::validate_options</a>(<span class="keywordtype">int</span> argc,
<a name="l00090"></a>00090                          <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[],
<a name="l00091"></a>00091                          <span class="keywordtype">int</span> remainder)
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093     <span class="keywordflow">if</span> (!conf_file_set_ &amp;&amp; remainder != argc) {
<a name="l00094"></a>00094         conf_file_.assign(argv[remainder]);
<a name="l00095"></a>00095         conf_file_set_ = <span class="keyword">true</span>;
<a name="l00096"></a>00096         remainder++;
<a name="l00097"></a>00097     }
<a name="l00098"></a>00098 
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (remainder != argc) {
<a name="l00100"></a>00100         fprintf(stderr, <span class="stringliteral">"invalid argument '%s'\n"</span>, argv[remainder]);
<a name="l00101"></a>00101         opts_.usage(<span class="stringliteral">"dtnsim"</span>);
<a name="l00102"></a>00102         exit(1);
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="keywordflow">if</span> (!conf_file_set_) {
<a name="l00106"></a>00106         fprintf(stderr, <span class="stringliteral">"must set the simulator conf file\n"</span>);
<a name="l00107"></a>00107         opts_.usage(<span class="stringliteral">"dtnsim"</span>);
<a name="l00108"></a>00108         exit(1);
<a name="l00109"></a>00109     }
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00113"></a>00113 <span class="keywordtype">int</span>
<a name="l00114"></a><a class="code" href="classDTNSim.html#040994ed54708fc6ef4f808f437daec2">00114</a> <a class="code" href="classDTNSim.html#040994ed54708fc6ef4f808f437daec2">DTNSim::main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[])
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116     init_app(argc, argv);
<a name="l00117"></a>00117     
<a name="l00118"></a>00118     <span class="comment">// reset timeval conversion, so timestamps are ok </span>
<a name="l00119"></a>00119     <a class="code" href="structdtn_1_1BundleTimestamp.html#f6d62d5c9d0a4dc2d4848ccbc925b497" title="The number of seconds between 1/1/1970 and 1/1/2000.">dtn::BundleTimestamp::TIMEVAL_CONVERSION</a> = 0;
<a name="l00120"></a>00120     
<a name="l00121"></a>00121     <span class="comment">// Initialize the simulator first and foremost since it's needed</span>
<a name="l00122"></a>00122     <span class="comment">// for LogSim::gettimeofday</span>
<a name="l00123"></a>00123     Simulator::create();
<a name="l00124"></a>00124     
<a name="l00125"></a>00125     <span class="comment">// Set up the command interpreter and all global commands (i.e.</span>
<a name="l00126"></a>00126     <span class="comment">// all the ones that aren't node-specific)</span>
<a name="l00127"></a>00127     <span class="keywordflow">if</span> (oasys::TclCommandInterp::init(argv[0]) != 0)
<a name="l00128"></a>00128     {
<a name="l00129"></a>00129         log_crit(<span class="stringliteral">"Can't init TCL"</span>);
<a name="l00130"></a>00130         exit(1);
<a name="l00131"></a>00131     }
<a name="l00132"></a>00132     oasys::TclCommandInterp* interp = oasys::TclCommandInterp::instance();
<a name="l00133"></a>00133     interp-&gt;reg(<span class="keyword">new</span> <a class="code" href="classdtnsim_1_1ConnCommand.html" title="Class to control the conn.">ConnCommand</a>()); 
<a name="l00134"></a>00134     interp-&gt;reg(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RouteCommand.html" title="The &amp;quot;route&amp;quot; command.">dtn::RouteCommand</a>());
<a name="l00135"></a>00135     interp-&gt;reg(<span class="keyword">new</span> <a class="code" href="classdtnsim_1_1SimCommand.html" title="Class to control the sim.">SimCommand</a>());
<a name="l00136"></a>00136     log_info(<span class="stringliteral">"registered dtnsim commands"</span>);
<a name="l00137"></a>00137 
<a name="l00138"></a>00138     <span class="comment">// set up all the real singleton components</span>
<a name="l00139"></a>00139     SchemeTable::create();
<a name="l00140"></a>00140     SimConvergenceLayer::init();
<a name="l00141"></a>00141     ConvergenceLayer::add_clayer(SimConvergenceLayer::instance());
<a name="l00142"></a>00142     BundleProtocol::init_default_processors();
<a name="l00143"></a>00143     log_info(<span class="stringliteral">"intialized dtnsim components"</span>);
<a name="l00144"></a>00144 
<a name="l00145"></a>00145     <span class="comment">// seed random number generator in tcl as well</span>
<a name="l00146"></a>00146     oasys::StringBuffer seed_cmd(<span class="stringliteral">"expr srand(%u)"</span>, random_seed_);
<a name="l00147"></a>00147     interp-&gt;exec_command(seed_cmd.c_str());
<a name="l00148"></a>00148     
<a name="l00149"></a>00149     <span class="comment">// pass command line options through to the simulation test file</span>
<a name="l00150"></a>00150     oasys::StringBuffer opts_cmd(<span class="stringliteral">"set opts \"%s\""</span>, <a class="code" href="classDTNSim.html#bbcf6a280e582d97aba5483ee8ad70d6">testopts_</a>.c_str());
<a name="l00151"></a>00151     interp-&gt;exec_command(opts_cmd.c_str());
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">// parse the simulation file</span>
<a name="l00154"></a>00154     log_info(<span class="stringliteral">"parsing configuration file %s..."</span>, conf_file_.c_str());
<a name="l00155"></a>00155     <span class="keywordflow">if</span> (interp-&gt;exec_file(conf_file_.c_str()) != 0) {
<a name="l00156"></a>00156         log_err(<span class="stringliteral">"error in configuration file, exiting..."</span>);
<a name="l00157"></a>00157         exit(1);
<a name="l00158"></a>00158     }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160     <span class="comment">// Run the event loop of simulator</span>
<a name="l00161"></a>00161     Simulator::instance()-&gt;run();
<a name="l00162"></a>00162 
<a name="l00163"></a>00163     <span class="keywordflow">if</span> (<a class="code" href="classDTNSim.html#4d880d10b720a19a2bb16e5a4efd704b">console_</a>) {
<a name="l00164"></a>00164         <span class="comment">// Run the command interpreter loop</span>
<a name="l00165"></a>00165         oasys::TclCommandInterp::instance()-&gt;exec_command(
<a name="l00166"></a>00166             <span class="stringliteral">"puts \"Simulation complete -- entering console (Control-D to exit)...\""</span>);
<a name="l00167"></a>00167         Simulator::instance()-&gt;run_console(<span class="keyword">true</span>);
<a name="l00168"></a>00168     }
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     <span class="keywordflow">return</span> 0;
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00174"></a><a class="code" href="dtnsim_8cc.html#f3ed9c200de85b53c94cd18764b246a2">00174</a> <span class="keywordtype">int</span> <a class="code" href="classDTNSim.html#040994ed54708fc6ef4f808f437daec2">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[])
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176     <a class="code" href="classDTNSim.html">DTNSim</a> d;
<a name="l00177"></a>00177     <span class="keywordflow">return</span> d.<a class="code" href="classDTNSim.html#040994ed54708fc6ef4f808f437daec2">main</a>(argc, argv);
<a name="l00178"></a>00178 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:45 2008 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>