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