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 <oasys/util/StringBuffer.h>
00022 #include <oasys/util/OptParser.h>
00023
00024 #include "bundling/BundleDaemon.h"
00025 #include "routing/BundleRouter.h"
00026 #include "prophet/QueuePolicy.h"
00027 #include "prophet/FwdStrategy.h"
00028 #include "prophet/Params.h"
00029
00030 #include "routing/ProphetRouter.h"
00031
00032 #include "ProphetCommand.h"
00033
00034 namespace dtn {
00035
00036 ProphetCommand::ProphetCommand()
00037 : TclCommand("prophet")
00038 {
00039 bind_var(new oasys::DoubleOpt("encounter",
00040 &ProphetRouter::params_.encounter_,
00041 "val",
00042 "predictability initialization constant "
00043 "(between 0 and 1)"));
00044
00045 bind_var(new oasys::DoubleOpt("beta", &ProphetRouter::params_.beta_,
00046 "val",
00047 "weight factor for transitive predictability "
00048 "(between 0 and 1)"));
00049
00050 bind_var(new oasys::DoubleOpt("gamma", &ProphetRouter::params_.gamma_,
00051 "val",
00052 "weight factor for predictability aging "
00053 "(between 0 and 1)"));
00054
00055 bind_var(new oasys::UIntOpt("kappa", &ProphetRouter::params_.kappa_,
00056 "val",
00057 "scaling factor for aging equation"));
00058
00059 bind_var(new oasys::UIntOpt("hello_dead", &ProphetRouter::params_.hello_dead_,
00060 "num",
00061 "number of HELLO intervals before "
00062 "peer considered unreachable"));
00063
00064 bind_var(new oasys::UIntOpt("max_forward",
00065 &ProphetRouter::params_.max_forward_,
00066 "num",
00067 "max times to forward bundle using GTMX"));
00068
00069 bind_var(new oasys::UIntOpt("min_forward",
00070 &ProphetRouter::params_.min_forward_,
00071 "num",
00072 "min times to forward bundle using LEPR"));
00073
00074 bind_var(new oasys::UIntOpt("age_period", &ProphetRouter::params_.age_period_,
00075 "val",
00076 "timer setting for aging algorithm and "
00077 "Prophet ACK expiry"));
00078
00079 bind_var(new oasys::BoolOpt("relay_node",
00080 &ProphetRouter::params_.relay_node_,
00081 "whether this node forwards bundles "
00082 "to other Prophet nodes"));
00083
00084 bind_var(new oasys::BoolOpt("internet_gw",
00085 &ProphetRouter::params_.internet_gw_,
00086 "whether this node forwards bundles to "
00087 "Internet domain"));
00088
00089
00090 bind_var(new oasys::DoubleOpt("epsilon", &ProphetRouter::params_.epsilon_,
00091 "val",
00092 "lower limit on predictability before "
00093 "dropping route"));
00094
00095 add_to_help("queue_policy=<policy>",
00096 "set queue policy to one of the following:\n"
00097 "\tfifo\tfirst in first out\n"
00098 "\tmofo\tevict most forwarded first\n"
00099 "\tmopr\tevict most favorably forwarded first\n"
00100 "\tlmopr\tevict most favorably forwarded first (linear increase)\n"
00101 "\tshli\tevict shortest lifetime first\n"
00102 "\tlepr\tevice least probable first\n");
00103
00104 add_to_help("fwd_strategy=<strategy>",
00105 "set forwarding strategy to one of the following:\n"
00106 "\tgrtr\tforward if remote's P is greater\n"
00107 "\tgtmx\tforward if \"grtr\" and NF < NF_Max\n"
00108 "\tgrtr_plus\tforward if \"grtr\" and P > P_Max\n"
00109 "\tgtmx_plus\tforward if \"grtr_plus\" and NF < NF_Max\n"
00110 "\tgrtr_sort\tforward if \"grtr\" and sort desc by P_remote - P_local\n"
00111 "\tgrtr_max\tforward if \"grtr\" and sort desc by P_remote\n");
00112
00113 add_to_help("hello_interval=<interval>",
00114 "maximum delay between protocol messages, in 100ms units,"
00115 " ranging from 1 to 255 (100 ms to 25.5s)");
00116
00117 add_to_help("max_route=<number>",
00118 "maximum number of routes for Prophet to retain"
00119 " (set to 0 to disable quota)");
00120 }
00121
00122 int
00123 ProphetCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00124 {
00125 (void)interp;
00126
00127 if (argc != 2)
00128 {
00129 resultf("prophet: wrong number of arguments, got %d looking for 2",
00130 argc);
00131 return TCL_ERROR;
00132 }
00133
00134 const char* cmd = argv[1];
00135
00136
00137 argc -= 1;
00138 argv += 1;
00139
00140 oasys::OptParser p;
00141 const char* invalid = NULL;
00142
00143 if (strncmp(cmd,"fwd_strategy",strlen("fwd_strategy")) == 0)
00144 {
00145 oasys::EnumOpt::Case FwdStrategyCases[] =
00146 {
00147 {"grtr", prophet::FwdStrategy::GRTR},
00148 {"gtmx", prophet::FwdStrategy::GTMX},
00149 {"grtr_plus", prophet::FwdStrategy::GRTR_PLUS},
00150 {"gtmx_plus", prophet::FwdStrategy::GTMX_PLUS},
00151 {"grtr_sort", prophet::FwdStrategy::GRTR_SORT},
00152 {"grtr_max", prophet::FwdStrategy::GRTR_MAX},
00153 {0, 0}
00154 };
00155 int fs_pass = ProphetRouter::params_.fs_;
00156 p.addopt(new oasys::EnumOpt("fwd_strategy",
00157 FwdStrategyCases, &fs_pass, "",
00158 "forwarding strategies"));
00159 if (! p.parse(argc,argv,&invalid))
00160 {
00161 resultf("bad parameter for fwd_strategy: %s",invalid);
00162 return TCL_ERROR;
00163 }
00164
00165 ProphetRouter::params_.fs_ =
00166 (prophet::FwdStrategy::fwd_strategy_t)fs_pass;
00167
00168 resultf("fwd_strategy set to %s",
00169 prophet::FwdStrategy::fs_to_str(ProphetRouter::params_.fs_));
00170 }
00171 else
00172 if (strncmp(cmd,"queue_policy",strlen("queue_policy")) == 0)
00173 {
00174 oasys::EnumOpt::Case QueuePolicyCases[] =
00175 {
00176 {"fifo", prophet::QueuePolicy::FIFO},
00177 {"mofo", prophet::QueuePolicy::MOFO},
00178 {"mopr", prophet::QueuePolicy::MOPR},
00179 {"lmopr", prophet::QueuePolicy::LINEAR_MOPR},
00180 {"shli", prophet::QueuePolicy::SHLI},
00181 {"lepr", prophet::QueuePolicy::LEPR},
00182 {0, 0}
00183 };
00184 int qp_pass;
00185 p.addopt(new oasys::EnumOpt("queue_policy",
00186 QueuePolicyCases, &qp_pass, "",
00187 "queueing policies as put forth by Prophet, March 2006"));
00188 if (! p.parse(argc,argv,&invalid))
00189 {
00190 resultf("bad parameter for queue_policy: %s",invalid);
00191 return TCL_ERROR;
00192 }
00193
00194 prophet::QueuePolicy::q_policy_t qp =
00195 (prophet::QueuePolicy::q_policy_t)qp_pass;
00196
00197 ProphetRouter::params_.qp_ = qp;
00198 if (ProphetRouter::is_init())
00199 {
00200 ProphetRouter* r = dynamic_cast<ProphetRouter*>(
00201 BundleDaemon::instance()->router());
00202 if (r != NULL)
00203 r->set_queue_policy();
00204 }
00205 resultf("queue_policy set to %s", prophet::QueuePolicy::qp_to_str(qp));
00206 }
00207 else
00208 if (strncmp(cmd,"hello_interval",strlen("hello_interval")) == 0)
00209 {
00210 u_int8_t hello_interval;
00211 p.addopt(new oasys::UInt8Opt("hello_interval",
00212 &hello_interval,"seconds",
00213 "100s of milliseconds between HELLO beacons (between 1 "
00214 "and 255)"));
00215
00216 if (! p.parse(argc,argv,&invalid))
00217 {
00218 resultf("bad parameter for hello_interval: %s",invalid);
00219 return TCL_ERROR;
00220 }
00221
00222 ProphetRouter::params_.hello_interval_ = hello_interval;
00223 if (ProphetRouter::is_init())
00224 {
00225 ProphetRouter* r = dynamic_cast<ProphetRouter*>(
00226 BundleDaemon::instance()->router());
00227 if (r != NULL)
00228 r->set_hello_interval();
00229 }
00230 resultf("hello_interval set to %d",hello_interval);
00231 }
00232 else
00233 if (strncmp(cmd,"max_route",strlen("max_route")) == 0)
00234 {
00235 u_int max_route;
00236 p.addopt(new oasys::UIntOpt("max_route",
00237 &max_route, "maximum number",
00238 "maximum number of routes for Prophet to retain"));
00239
00240 if (! p.parse(argc,argv,&invalid))
00241 {
00242 resultf("bad parameter for hello_interval: %s",invalid);
00243 return TCL_ERROR;
00244 }
00245
00246 ProphetRouter::params_.max_table_size_ = max_route;
00247 if (ProphetRouter::is_init())
00248 {
00249 ProphetRouter* r = dynamic_cast<ProphetRouter*>(
00250 BundleDaemon::instance()->router());
00251 if (r != NULL)
00252 r->set_max_route();
00253 }
00254 resultf("max_route set to %u",max_route);
00255 }
00256
00257 return TCL_OK;
00258 }
00259
00260 }