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