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 <stdio.h>
00022 #include <unistd.h>
00023 #include <errno.h>
00024 #include <strings.h>
00025 #include <stdlib.h>
00026 #include <sys/time.h>
00027
00028 #include <string>
00029 #include <oasys/debug/Log.h>
00030
00031 #include "dtn_api.h"
00032 #include "TcaController.h"
00033
00034 static const int debug = 1;
00035
00036 static const int MAX_TTL = 604800;
00037
00038
00039 static const char* progname;
00040 static std::string node_type = "mobile";
00041 static bool tidy = false;
00042 static std::string link_id;
00043 static std::string ask_addr;
00044 static std::string adv_string;
00045 static int registry_ttl = MAX_TTL;
00046 static int control_ttl = MAX_TTL;
00047
00048
00049 static TcaController::Role role = TcaController::TCA_MOBILE;
00050
00051
00052 void
00053 print_usage()
00054 {
00055 fprintf(stderr, "usage: %s [opts]\n"
00056 "options:\n"
00057 " -h help\n"
00058 " -n <node_type: mobile | router | gateway> (default = mobile)\n"
00059 " -l <link_addr> local contact addr (required for gateway only)\n"
00060 " -a <link_addr> send ask on startup\n"
00061 " -d <adv_string> string to send in response to ASK\n"
00062 " -r <time in seconds> TTL for Registry entries (default = 604800)\n"
00063 " -e <time in seconds> control bundle expiration time (default = 604800)\n"
00064 " -t tidy (discard pending bundles on startup)\n",
00065 progname);
00066 fprintf(stderr, "usage: %s [-h] -t <node_type: mobile | router |"
00067 " gateway>\n", progname);
00068 exit(1);
00069 }
00070
00071
00072 void
00073 parse_options(int argc, const char **argv)
00074 {
00075 bool done = false;
00076 int c;
00077
00078 progname = argv[0];
00079
00080 while (!done)
00081 {
00082 c = getopt(argc, (char **) argv, "htn:l:a:d:r:e:");
00083
00084 switch (c)
00085 {
00086 case 'h':
00087 print_usage();
00088 exit(0);
00089 break;
00090 case 't':
00091 tidy = true;
00092 break;
00093 case 'n':
00094 {
00095 node_type = optarg;
00096 if (node_type == "mobile")
00097 role = TcaController::TCA_MOBILE;
00098 else if (node_type == "router")
00099 role = TcaController::TCA_ROUTER;
00100 else if (node_type == "gateway")
00101 role = TcaController::TCA_GATEWAY;
00102 else
00103 fprintf(stderr, "unknown node type '%s'\n",
00104 node_type.c_str());
00105 }
00106 break;
00107 case 'l':
00108 link_id = optarg;
00109 break;
00110 case 'a':
00111 ask_addr = optarg;
00112
00113 break;
00114 case 'd':
00115 adv_string = optarg;
00116
00117 break;
00118 case 'r':
00119 {
00120 int n = atoi(optarg);
00121 if (n<=0 || n >MAX_TTL)
00122 {
00123 fprintf(stderr, "registry TTL out of range (1..%d)\n",
00124 MAX_TTL);
00125 registry_ttl = MAX_TTL;
00126 }
00127 else
00128 {
00129 registry_ttl = n;
00130 }
00131 }
00132 break;
00133 case 'e':
00134 {
00135 int n = atoi(optarg);
00136 if (n<=0 || n >MAX_TTL)
00137 {
00138 fprintf(stderr, "control bundle TTL out of range (1..%d)\n",
00139 MAX_TTL);
00140 control_ttl = MAX_TTL;
00141 }
00142 else
00143 {
00144 control_ttl = n;
00145 }
00146 }
00147 break;
00148 case -1:
00149 done = true;
00150 break;
00151 default:
00152 print_usage();
00153 break;
00154 }
00155 }
00156
00157 if (optind < argc)
00158 {
00159 fprintf(stderr, "unsupported argument '%s'\n", argv[optind]);
00160 exit(1);
00161 }
00162
00163
00164 printf("using options:\n");
00165 printf(" node_type = '%s'\n", node_type.c_str());
00166 printf(" link_id = '%s'\n", link_id.c_str());
00167 printf(" ask_addr = '%s'\n", ask_addr.c_str());
00168 printf(" adv_string = '%s'\n", adv_string.c_str());
00169 printf(" registry_ttl = %d\n", registry_ttl);
00170 printf(" control_ttl = %d\n", control_ttl);
00171 if (tidy) printf(" tidy = true\n");
00172 else printf(" tidy = false\n");
00173
00174 }
00175
00176
00177
00178 int
00179 main(int argc, const char** argv)
00180 {
00181 oasys::Log::init("-", oasys::LOG_NOTICE, "", "~/.tcadebug");
00182 log_notice_p("/tca/admin", "tca_admin starting up");
00183
00184 parse_options(argc, argv);
00185
00186 TcaController controller(role, link_id, ask_addr, adv_string,
00187 registry_ttl, control_ttl);
00188
00189 if (!controller.init(tidy))
00190 {
00191 exit(1);
00192 }
00193
00194 controller.run();
00195
00196 return 0;
00197 }
00198
00199
00200