ProphetCommand.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Baylor University
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #include <oasys/util/StringBuffer.h>
00018 #include <oasys/util/OptParser.h>
00019 
00020 #include "ProphetCommand.h"
00021 #include "routing/BundleRouter.h"
00022 #include "routing/Prophet.h"
00023 #include "routing/ProphetRouter.h"
00024 
00025 namespace dtn {
00026 
00027 ProphetCommand::ProphetCommand()
00028     : TclCommand("prophet")
00029 {
00030     bind_var(new oasys::DoubleOpt("encounter",
00031                                   &ProphetRouter::params_.encounter_,
00032                                   "val",
00033                                   "predictability initialization constant "
00034                                   "(between 0 and 1)"));
00035 
00036     bind_var(new oasys::DoubleOpt("beta", &ProphetRouter::params_.beta_, 
00037                                   "val",
00038                                   "weight factor for transitive predictability "
00039                                   "(between 0 and 1)"));
00040 
00041     bind_var(new oasys::DoubleOpt("gamma", &ProphetRouter::params_.gamma_, 
00042                                   "val",
00043                                   "weight factor for predictability aging "
00044                                   "(between 0 and 1)"));
00045 
00046     bind_var(new oasys::UIntOpt("kappa", &ProphetRouter::params_.kappa_, 
00047                                 "val",
00048                                 "scaling factor for aging equation"));
00049 
00050     bind_var(new oasys::UIntOpt("hello_dead", &ProphetRouter::params_.hello_dead_,
00051                                 "num",
00052                                 "number of HELLO intervals before "
00053                                 "peer considered unreachable"));
00054 
00055     bind_var(new oasys::UIntOpt("max_forward",
00056                                 &ProphetRouter::params_.max_forward_,
00057                                 "num",
00058                                 "max times to forward bundle using GTMX"));
00059 
00060     bind_var(new oasys::UIntOpt("min_forward",
00061                                 &ProphetRouter::params_.min_forward_,
00062                                 "num",
00063                                 "min times to forward bundle using LEPR"));
00064 
00065     bind_var(new oasys::UIntOpt("age_period", &ProphetRouter::params_.age_period_,
00066                                 "val",
00067                                 "timer setting for aging algorithm and "
00068                                 "Prophet ACK expiry"));
00069 
00070     bind_var(new oasys::BoolOpt("relay_node",
00071                                 &ProphetRouter::params_.relay_node_,
00072                                 "whether this node forwards bundles "
00073                                 "outside Prophet domain"));
00074 
00075     bind_var(new oasys::BoolOpt("custody_node",
00076                                 &ProphetRouter::params_.custody_node_,
00077                                 "whether this node will accept "
00078                                 "custody transfers"));
00079 
00080     bind_var(new oasys::BoolOpt("internet_gw",
00081                                 &ProphetRouter::params_.internet_gw_,
00082                                 "whether this node forwards bundles to "
00083                                 "Internet domain"));
00084 
00085     // smallest double that can fit into 8 bits:  0.0039
00086     bind_var(new oasys::DoubleOpt("epsilon", &ProphetRouter::params_.epsilon_,
00087                                   "val",
00088                                   "lower limit on predictability before "
00089                                   "dropping route"));
00090 
00091     add_to_help("queue_policy <policy>",
00092                 "set queue policy to one of the following:\n"
00093                 "\tfifo\tfirst in first out\n"
00094                 "\tmofo\tevict most forwarded first\n"
00095                 "\tmopr\tevict most favorably forwarded first\n"
00096                 "\tlmopr\tevict most favorably forwarded first (linear increase)\n"
00097                 "\tshli\tevict shortest lifetime first\n"
00098                 "\tlepr\tevice least probable first\n");
00099 
00100     add_to_help("fwd_strategy <strategy>",
00101                 "set forwarding strategy to one of the following:\n"
00102                 "\tgrtr\tforward if remote's P is greater\n"
00103                 "\tgtmx\tforward if \"grtr\" and NF < NF_Max\n"
00104                 "\tgrtr_plus\tforward if \"grtr\" and P > P_Max\n"
00105                 "\tgtmx_plus\tforward if \"grtr_plus\" and NF < NF_Max\n"
00106                 "\tgrtr_sort\tforward if \"grtr\" and sort desc by P_remote - P_local\n"
00107                 "\tgrtr_max\tforward if \"grtr\" and sort desc by P_remote\n");
00108 
00109     add_to_help("max_usage <bytes>","set upper limit on bundle store utilization");
00110 }
00111 
00112 int
00113 ProphetCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00114 {
00115     (void)interp;
00116     
00117     /*
00118        wish list:
00119             - define a Prophet node: EID, pvalue, custody, relay, internet
00120             - define "show" command for each Prophet variable
00121      */
00122 
00123     if (argc != 2)
00124     {
00125         resultf("prophet: wrong number of arguments, got %d looking for 2",
00126                 argc);
00127         return TCL_ERROR;
00128     }
00129 
00130     const char* cmd = argv[1];
00131 
00132     // scoot past "prophet foo" to the value
00133     argc -= 1;
00134     argv += 1;
00135 
00136     oasys::OptParser p;
00137     const char* invalid = NULL;
00138 
00139     if (strncmp(cmd,"fwd_strategy",strlen("fwd_strategy")) == 0)
00140     {
00141         oasys::EnumOpt::Case FwdStrategyCases[] =
00142         {
00143             {"grtr",      Prophet::GRTR},
00144             {"gtmx",      Prophet::GTMX},
00145             {"grtr_plus", Prophet::GRTR_PLUS},
00146             {"gtmx_plus", Prophet::GTMX_PLUS},
00147             {"grtr_sort", Prophet::GRTR_SORT},
00148             {"grtr_max",  Prophet::GRTR_MAX},
00149             {0, 0}
00150         };
00151         p.addopt(new oasys::EnumOpt("fwd_strategy",
00152                     FwdStrategyCases, (int*)&ProphetRouter::params_.fs_, "",
00153                     "forwarding strategies"));
00154         if (! p.parse(argc,argv,&invalid))
00155         {
00156             resultf("bad parameter for fwd_strategy: %s",invalid);
00157             return TCL_ERROR;
00158         }
00159 
00160         resultf("fwd_strategy set to %s",
00161                 Prophet::fs_to_str(ProphetRouter::params_.fs_));
00162     }
00163     else
00164     if (strncmp(cmd,"queue_policy",strlen("queue_policy")) == 0)
00165     {
00166         oasys::EnumOpt::Case QueuePolicyCases[] =
00167         {
00168             {"fifo",        Prophet::FIFO},
00169             {"mofo",        Prophet::MOFO},
00170             {"mopr",        Prophet::MOPR},
00171             {"lmopr",       Prophet::LINEAR_MOPR},
00172             {"shli",        Prophet::SHLI},
00173             {"lepr",        Prophet::LEPR},
00174             {0, 0}
00175         };
00176         Prophet::q_policy_t qp;
00177         p.addopt(new oasys::EnumOpt("queue_policy",
00178                     QueuePolicyCases, (int*)&qp, "",
00179                     "queueing policies as put forth by Prophet, March 2006"));
00180         if (! p.parse(argc,argv,&invalid))
00181         {
00182             resultf("bad parameter for queue_policy: %s",invalid);
00183             return TCL_ERROR;
00184         }
00185 
00186         // if instance exists, post a change
00187         if (ProphetController::is_init())
00188             ProphetController::instance()->handle_queue_policy_change(qp);
00189         else 
00190         // else push to params where it will get picked up at init time
00191             ProphetRouter::params_.qp_ = qp;
00192 
00193         resultf("queue_policy set to %s", Prophet::qp_to_str(qp));
00194     }
00195     else
00196     if (strncmp(cmd,"hello_interval",strlen("hello_interval")) == 0)
00197     {
00198         u_int8_t hello_interval;
00199         p.addopt(new oasys::UInt8Opt("hello_interval",
00200                  &hello_interval,"100s of milliseconds",
00201                  "100ms time units between HELLO beacons (1 - 255)"));
00202 
00203         if (! p.parse(argc,argv,&invalid))
00204         {
00205             resultf("bad parameter for hello_interval: %s",invalid);
00206             return TCL_ERROR;
00207         }
00208 
00209         if (ProphetController::is_init())
00210             ProphetController::instance()->handle_hello_interval_change(
00211                 hello_interval);
00212         else
00213             ProphetRouter::params_.hello_interval_ = hello_interval;
00214 
00215         resultf("hello_interval set to %d",hello_interval);
00216     }
00217     else
00218     if (strncmp(cmd,"max_usage",strlen("max_usage")) == 0)
00219     {
00220         u_int max_usage;
00221         p.addopt(new oasys::UIntOpt("max_usage",
00222                  &max_usage,"usage in bytes",
00223                  "upper limit on Bundle storage utilization"));
00224 
00225         if (! p.parse(argc,argv,&invalid))
00226         {
00227             resultf("bad parameter for max_usage: %s",invalid);
00228             return TCL_ERROR;
00229         }
00230 
00231         if (ProphetController::is_init())
00232             ProphetController::instance()->handle_max_usage_change(max_usage);
00233         else
00234             ProphetRouter::params_.max_usage_ = max_usage;
00235 
00236         resultf("max_usage set to %d",max_usage);
00237     }
00238 
00239     return TCL_OK;
00240 }
00241 
00242 } // namespace dtn

Generated on Sat Sep 8 08:36:17 2007 for DTN Reference Implementation by  doxygen 1.5.3