akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdlib.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 7 | #include <sys/stat.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 8 | #include <assert.h> |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 9 | #include <sys/types.h> |
| 10 | #include <signal.h> |
| 11 | #include <sys/socket.h> |
| 12 | #include <sys/un.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <sys/ioctl.h> |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 15 | #include <netinet/in.h> |
| 16 | #include <netdb.h> |
| 17 | #include <arpa/inet.h> |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 18 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 22 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 23 | #include <ccn/ccn.h> |
| 24 | #include <ccn/uri.h> |
| 25 | #include <ccn/keystore.h> |
| 26 | #include <ccn/signing.h> |
| 27 | #include <ccn/schedule.h> |
| 28 | #include <ccn/hashtb.h> |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 29 | #include <ccn/sync.h> |
| 30 | #include <ccn/seqwriter.h> |
akmhoque | 184dde0 | 2013-02-14 15:53:24 -0600 | [diff] [blame] | 31 | #include <ccn/ccn_private.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 32 | |
| 33 | #include "nlsr.h" |
| 34 | #include "nlsr_ndn.h" |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 35 | #include "nlsr_lsdb.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 36 | #include "utility.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 37 | #include "nlsr_npl.h" |
| 38 | #include "nlsr_adl.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 39 | #include "nlsr_npt.h" |
| 40 | #include "nlsr_route.h" |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 41 | #include "nlsr_sync.h" |
| 42 | #include "nlsr_face.h" |
| 43 | #include "nlsr_fib.h" |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 44 | #include "nlsr_km.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 45 | |
| 46 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 47 | #define ON_ERROR_DESTROY(resval) \ |
| 48 | { \ |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 49 | if ((resval) < 0) { \ |
| 50 | nlsr_destroy(); \ |
| 51 | exit(1);\ |
| 52 | } \ |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | #define ON_ERROR_EXIT(resval) \ |
| 57 | { \ |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 58 | if ((resval) < 0) { \ |
| 59 | exit(1); \ |
| 60 | } \ |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 61 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 62 | |
| 63 | struct option longopts[] = |
| 64 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 65 | { "daemon", no_argument, NULL, 'd'}, |
| 66 | { "config_file", required_argument, NULL, 'f'}, |
| 67 | { "api_port", required_argument, NULL, 'p'}, |
| 68 | { "help", no_argument, NULL, 'h'}, |
| 69 | { 0 } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 72 | static int |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 73 | usage(char *progname) |
| 74 | { |
| 75 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 76 | printf("Usage: %s [OPTIONS...]\n\ |
| 77 | NDN routing....\n\ |
| 78 | -d, --daemon Run in daemon mode\n\ |
| 79 | -f, --config_file Specify configuration file name\n\ |
| 80 | -p, --api_port port where api client will connect\n\ |
| 81 | -h, --help Display this help message\n", progname); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 82 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 83 | exit(1); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void ndn_rtr_gettime(const struct ccn_gettime *self, struct ccn_timeval *result) |
| 87 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 88 | struct timeval now = {0}; |
| 89 | gettimeofday(&now, 0); |
| 90 | result->s = now.tv_sec; |
| 91 | result->micros = now.tv_usec; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static struct ccn_gettime ndn_rtr_ticker = { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 95 | "timer", |
| 96 | &ndn_rtr_gettime, |
| 97 | 1000000, |
| 98 | NULL |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 99 | }; |
| 100 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 101 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 102 | nlsr_lock(void) |
| 103 | { |
| 104 | nlsr->semaphor=NLSR_LOCKED; |
| 105 | } |
| 106 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 107 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 108 | nlsr_unlock(void) |
| 109 | { |
| 110 | nlsr->semaphor=NLSR_UNLOCKED; |
| 111 | } |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 112 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 113 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 114 | nlsr_stop_signal_handler(int sig) |
akmhoque | 42098b1 | 2012-08-27 22:54:23 -0500 | [diff] [blame] | 115 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 116 | signal(sig, SIG_IGN); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 117 | nlsr_destroy(); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 118 | exit(0); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 121 | void |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 122 | daemonize_nlsr(void) |
| 123 | { |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 124 | //int ret; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 125 | pid_t process_id = 0; |
| 126 | pid_t sid = 0; |
| 127 | process_id = fork(); |
| 128 | if (process_id < 0) |
| 129 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 130 | printf("Daemonization failed!\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 131 | ON_ERROR_DESTROY(process_id); |
| 132 | } |
| 133 | if (process_id > 0) |
| 134 | { |
| 135 | printf("Process daemonized. Process id: %d \n", process_id); |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 136 | //ret=process_id; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 137 | exit(0); |
| 138 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 139 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 140 | umask(0); |
| 141 | sid = setsid(); |
| 142 | if(sid < 0) |
| 143 | { |
| 144 | ON_ERROR_DESTROY(sid); |
| 145 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 146 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 147 | chdir("/"); |
akmhoque | b63a41e | 2013-03-01 12:00:20 -0600 | [diff] [blame] | 148 | //close(STDIN_FILENO); |
| 149 | //close(STDOUT_FILENO); |
| 150 | //close(STDERR_FILENO); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 153 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 154 | process_command_ccnneighbor(char *command) |
| 155 | { |
| 156 | if(command==NULL) |
| 157 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 158 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | char *rem; |
| 162 | const char *sep=" \t\n"; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 163 | char *rtr_name; |
| 164 | char *nbr_ip_addr; |
| 165 | int is_ip_configured=0; |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 166 | char *ip_addr=(char *)calloc(20,sizeof(char)); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 167 | |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 168 | rtr_name=strtok_r(command,sep,&rem); |
| 169 | if(rtr_name==NULL) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 170 | { |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 171 | printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n"); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 172 | return; |
| 173 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 174 | if ( rtr_name[strlen(rtr_name)-1] == '/' ) |
| 175 | { |
| 176 | rtr_name[strlen(rtr_name)-1]='\0'; |
| 177 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 178 | |
| 179 | if (rem != NULL ) |
| 180 | { |
| 181 | nbr_ip_addr=strtok_r(NULL,sep,&rem); |
akmhoque | 958ccf7 | 2013-02-11 10:42:03 -0600 | [diff] [blame] | 182 | if ( nbr_ip_addr != NULL) |
| 183 | is_ip_configured=1; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 184 | } |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 185 | struct name_prefix *nbr=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
| 186 | nbr->name=(char *)calloc(strlen(rtr_name)+1,sizeof(char)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 187 | memcpy(nbr->name,rtr_name,strlen(rtr_name)+1); |
| 188 | nbr->length=strlen(rtr_name)+1; |
| 189 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 190 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 191 | if ( !is_ip_configured ) |
| 192 | { |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 193 | struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 194 | get_host_name_from_command_string(nbr_name,nbr->name,0); |
akmhoque | 018692c | 2013-02-11 11:33:39 -0600 | [diff] [blame] | 195 | if ( nlsr->debugging) |
| 196 | printf("Hostname of neighbor: %s ",nbr_name->name); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 197 | get_ip_from_hostname_02(nbr_name->name,ip_addr); |
akmhoque | 018692c | 2013-02-11 11:33:39 -0600 | [diff] [blame] | 198 | if ( nlsr->debugging) |
| 199 | printf("IP Address: %s \n",ip_addr); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 200 | free(nbr_name->name); |
| 201 | free(nbr_name); |
| 202 | } |
| 203 | else |
| 204 | { |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 205 | memcpy(ip_addr,nbr_ip_addr,strlen(nbr_ip_addr)+1); |
akmhoque | 018692c | 2013-02-11 11:33:39 -0600 | [diff] [blame] | 206 | if (nlsr->debugging) |
| 207 | { |
| 208 | printf("Name of neighbor: %s ",nbr->name); |
| 209 | printf("IP Address: %s \n",ip_addr); |
| 210 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 211 | } |
| 212 | add_nbr_to_adl(nbr,0,ip_addr); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 213 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 214 | free(ip_addr); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 215 | free(nbr->name); |
| 216 | free(nbr); |
| 217 | } |
| 218 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 219 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 220 | process_command_ccnname(char *command) |
| 221 | { |
| 222 | |
| 223 | if(command==NULL) |
| 224 | { |
| 225 | printf(" Wrong Command Format ( ccnname /name/prefix)\n"); |
| 226 | return; |
| 227 | } |
| 228 | char *rem; |
| 229 | const char *sep=" \t\n"; |
| 230 | char *name; |
| 231 | name=strtok_r(command,sep,&rem); |
| 232 | if(name==NULL) |
| 233 | { |
| 234 | printf(" Wrong Command Format ( ccnname /name/prefix/ )\n"); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | printf("Name Prefix: %s \n",name); |
| 239 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 240 | if ( name[strlen(name)-1] == '/' ) |
| 241 | name[strlen(name)-1]='\0'; |
| 242 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 243 | struct name_prefix *np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
| 244 | np->name=(char *)calloc(strlen(name)+1,sizeof(char)); |
| 245 | //memset(np->name,0,strlen(name)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 246 | memcpy(np->name,name,strlen(name)+1); |
| 247 | np->length=strlen(name)+1; |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 248 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 249 | add_name_to_npl(np); |
akmhoque | 28c4502 | 2012-08-09 15:38:02 -0500 | [diff] [blame] | 250 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 251 | free(np->name); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 252 | free(np); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 253 | } |
| 254 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 255 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 256 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 257 | process_command_router_name(char *command) |
| 258 | { |
| 259 | if(command==NULL) |
| 260 | { |
| 261 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 262 | return; |
| 263 | } |
| 264 | char *rem; |
| 265 | const char *sep=" \t\n"; |
| 266 | char *rtr_name; |
| 267 | |
| 268 | rtr_name=strtok_r(command,sep,&rem); |
| 269 | if(rtr_name==NULL) |
| 270 | { |
| 271 | printf(" Wrong Command Format ( router-name /router/name )\n"); |
| 272 | return; |
| 273 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 274 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 275 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 276 | if ( rtr_name[strlen(rtr_name)-1] == '/' ) |
| 277 | rtr_name[strlen(rtr_name)-1]='\0'; |
| 278 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 279 | nlsr->router_name=(char *)calloc(strlen(rtr_name)+1,sizeof(char)); |
| 280 | //memset(nlsr->router_name,0,strlen(rtr_name)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 281 | memcpy(nlsr->router_name,rtr_name,strlen(rtr_name)+1); |
| 282 | |
| 283 | |
| 284 | } |
| 285 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 286 | |
| 287 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 288 | process_command_interest_retry(char *command) |
| 289 | { |
| 290 | if(command==NULL) |
| 291 | { |
| 292 | printf(" Wrong Command Format ( interest-retry number )\n"); |
| 293 | return; |
| 294 | } |
| 295 | char *rem; |
| 296 | const char *sep=" \t\n"; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 297 | char *retry; |
| 298 | long int retry_number; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 299 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 300 | retry=strtok_r(command,sep,&rem); |
| 301 | if(retry==NULL) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 302 | { |
| 303 | printf(" Wrong Command Format ( interest-retry number)\n"); |
| 304 | return; |
| 305 | } |
| 306 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 307 | retry_number=atoi(retry); |
| 308 | if ( retry_number >= 1 && retry_number<=10 ) |
| 309 | { |
| 310 | nlsr->interest_retry=retry_number; |
| 311 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 312 | |
| 313 | } |
| 314 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 315 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 316 | process_command_interest_resend_time(char *command) |
| 317 | { |
| 318 | if(command==NULL) |
| 319 | { |
| 320 | printf(" Wrong Command Format ( interest-resend-time secs )\n"); |
| 321 | return; |
| 322 | } |
| 323 | char *rem; |
| 324 | const char *sep=" \t\n"; |
| 325 | char *secs; |
| 326 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 327 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 328 | secs=strtok_r(command,sep,&rem); |
| 329 | if(secs==NULL) |
| 330 | { |
| 331 | printf(" Wrong Command Format ( interest-resend-time secs)\n"); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | seconds=atoi(secs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 336 | if ( seconds <= 60 && seconds >= 1 ) |
| 337 | { |
| 338 | nlsr->interest_resend_time=seconds; |
| 339 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 340 | } |
| 341 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 342 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 343 | void |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 344 | process_command_lsa_refresh_time(char *command) |
| 345 | { |
| 346 | if(command==NULL) |
| 347 | { |
| 348 | printf(" Wrong Command Format ( lsa-refresh-time secs )\n"); |
| 349 | return; |
| 350 | } |
| 351 | char *rem; |
| 352 | const char *sep=" \t\n"; |
| 353 | char *secs; |
| 354 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 355 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 356 | secs=strtok_r(command,sep,&rem); |
| 357 | if(secs==NULL) |
| 358 | { |
| 359 | printf(" Wrong Command Format ( lsa-refresh-time secs)\n"); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | seconds=atoi(secs); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 364 | if ( seconds >= 240) |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 365 | { |
| 366 | nlsr->lsa_refresh_time=seconds; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 367 | if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 ) |
| 368 | { |
| 369 | nlsr->router_dead_interval=2*nlsr->lsa_refresh_time; |
| 370 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | } |
| 374 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 375 | void |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 376 | process_command_router_dead_interval(char *command) |
| 377 | { |
| 378 | if(command==NULL) |
| 379 | { |
| 380 | printf(" Wrong Command Format ( router-dead-interval secs )\n"); |
| 381 | return; |
| 382 | } |
| 383 | char *rem; |
| 384 | const char *sep=" \t\n"; |
| 385 | char *secs; |
| 386 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 387 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 388 | secs=strtok_r(command,sep,&rem); |
| 389 | if(secs==NULL) |
| 390 | { |
| 391 | printf(" Wrong Command Format ( router-dead-interval secs)\n"); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | seconds=atoi(secs); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 396 | if ( seconds >= 480 ) |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 397 | { |
| 398 | nlsr->router_dead_interval=seconds; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 399 | if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 ) |
| 400 | { |
| 401 | nlsr->router_dead_interval=2*nlsr->lsa_refresh_time; |
| 402 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 406 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 407 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 408 | process_command_max_faces_per_prefix(char *command) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 409 | { |
| 410 | if(command==NULL) |
| 411 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 412 | printf(" Wrong Command Format ( max-faces-per-prefix n )\n"); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | char *rem; |
| 416 | const char *sep=" \t\n"; |
| 417 | char *num; |
| 418 | long int number; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 419 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 420 | num=strtok_r(command,sep,&rem); |
| 421 | if(num==NULL) |
| 422 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 423 | printf(" Wrong Command Format ( max-faces-per-prefix n)\n"); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 424 | return; |
| 425 | } |
| 426 | |
| 427 | number=atoi(num); |
| 428 | if ( number >= 0 && number <= 60 ) |
| 429 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 430 | nlsr->max_faces_per_prefix=number; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | } |
| 434 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 435 | void |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 436 | process_command_logdir(char *command) |
| 437 | { |
| 438 | if(command==NULL) |
| 439 | { |
| 440 | printf(" Wrong Command Format ( logdir /path/to/logdir )\n"); |
| 441 | return; |
| 442 | } |
| 443 | char *rem; |
| 444 | const char *sep=" \t\n"; |
| 445 | char *dir; |
| 446 | |
| 447 | dir=strtok_r(command,sep,&rem); |
| 448 | if(dir==NULL) |
| 449 | { |
| 450 | printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n"); |
| 451 | return; |
| 452 | } |
akmhoque | 0b60ba9 | 2013-02-25 17:55:35 -0600 | [diff] [blame] | 453 | //if ( nlsr->logDir) |
| 454 | //free(nlsr->logDir); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 455 | nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 456 | memcpy(nlsr->logDir,dir,strlen(dir)+1); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 457 | } |
| 458 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 459 | void |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 460 | process_command_detailed_log(char *command) |
| 461 | { |
| 462 | if(command==NULL) |
| 463 | { |
| 464 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 465 | return; |
| 466 | } |
| 467 | char *rem; |
| 468 | const char *sep=" \t\n"; |
| 469 | char *on_off; |
| 470 | |
| 471 | on_off=strtok_r(command,sep,&rem); |
| 472 | if(on_off==NULL) |
| 473 | { |
| 474 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 475 | return; |
| 476 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 477 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 478 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0) |
| 479 | { |
| 480 | nlsr->detailed_logging=1; |
| 481 | } |
| 482 | } |
| 483 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 484 | void |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 485 | process_command_debug(char *command) |
| 486 | { |
| 487 | if(command==NULL) |
| 488 | { |
| 489 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 490 | return; |
| 491 | } |
| 492 | char *rem; |
| 493 | const char *sep=" \t\n"; |
| 494 | char *on_off; |
| 495 | |
| 496 | on_off=strtok_r(command,sep,&rem); |
| 497 | if(on_off==NULL) |
| 498 | { |
| 499 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 500 | return; |
| 501 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 502 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 503 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 504 | { |
| 505 | nlsr->debugging=1; |
| 506 | } |
| 507 | } |
| 508 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 509 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 510 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 511 | process_command_topo_prefix(char *command) |
| 512 | { |
| 513 | if(command==NULL) |
| 514 | { |
| 515 | printf(" Wrong Command Format ( topo-prefix )\n"); |
| 516 | return; |
| 517 | } |
| 518 | char *rem; |
| 519 | const char *sep=" \t\n"; |
| 520 | char *topo_prefix; |
| 521 | |
| 522 | topo_prefix=strtok_r(command,sep,&rem); |
| 523 | if(topo_prefix==NULL) |
| 524 | { |
| 525 | printf(" Wrong Command Format ( topo-prefix /name/prefix )\n"); |
| 526 | return; |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | if( nlsr->topo_prefix != NULL) |
| 531 | free(nlsr->topo_prefix); |
| 532 | if ( topo_prefix[strlen(topo_prefix)-1] == '/' ) |
| 533 | topo_prefix[strlen(topo_prefix)-1]='\0'; |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 534 | //if(nlsr->topo_prefix) |
| 535 | //free(nlsr->topo_prefix); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 536 | nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 537 | memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 538 | printf ("Topo prefix is: %s\n", nlsr->topo_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 543 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 544 | process_command_slice_prefix(char *command) |
| 545 | { |
| 546 | if(command==NULL) |
| 547 | { |
| 548 | printf(" Wrong Command Format ( slice-prefix /name/prefix )\n"); |
| 549 | return; |
| 550 | } |
| 551 | char *rem; |
| 552 | const char *sep=" \t\n"; |
| 553 | char *slice_prefix; |
| 554 | |
| 555 | slice_prefix=strtok_r(command,sep,&rem); |
| 556 | if(slice_prefix==NULL) |
| 557 | { |
| 558 | printf(" Wrong Command Format ( slice-prefix /name/prefix )\n"); |
| 559 | return; |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | if ( nlsr->slice_prefix != NULL) |
| 564 | free(nlsr->slice_prefix); |
| 565 | if ( slice_prefix[strlen(slice_prefix)-1] == '/' ) |
| 566 | slice_prefix[strlen(slice_prefix)-1]='\0'; |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 567 | nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 568 | memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 569 | printf("Slice prefix: %s \n",nlsr->slice_prefix); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | |
| 574 | void |
| 575 | process_command_root_key_prefix(char *command) |
| 576 | { |
| 577 | if(command==NULL) |
| 578 | { |
| 579 | printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n"); |
| 580 | return; |
| 581 | } |
| 582 | char *rem; |
| 583 | const char *sep=" \t\n"; |
| 584 | char *root_key_prefix; |
| 585 | |
| 586 | root_key_prefix=strtok_r(command,sep,&rem); |
| 587 | if(root_key_prefix==NULL) |
| 588 | { |
| 589 | printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n"); |
| 590 | return; |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | if ( nlsr->root_key_prefix != NULL) |
| 595 | free(nlsr->root_key_prefix); |
| 596 | if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' ) |
| 597 | root_key_prefix[strlen(root_key_prefix)-1]='\0'; |
| 598 | nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char)); |
| 599 | memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1); |
| 600 | printf("Root key prefix: %s \n",nlsr->root_key_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 604 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 605 | process_command_hyperbolic_routing(char *command) |
| 606 | { |
| 607 | if(command==NULL) |
| 608 | { |
| 609 | printf(" Wrong Command Format ( hyperbolic-routing on)\n"); |
| 610 | return; |
| 611 | } |
| 612 | char *rem; |
| 613 | const char *sep=" \t\n"; |
| 614 | char *on_off; |
| 615 | |
| 616 | on_off=strtok_r(command,sep,&rem); |
| 617 | if(on_off==NULL) |
| 618 | { |
| 619 | printf(" Wrong Command Format ( hyperbolic-routing on )\n"); |
| 620 | return; |
| 621 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 622 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 623 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 624 | { |
| 625 | nlsr->is_hyperbolic_calc=1; |
| 626 | } |
| 627 | } |
| 628 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 629 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 630 | process_command_hyperbolic_cordinate(char *command) |
| 631 | { |
| 632 | if(command==NULL) |
| 633 | { |
| 634 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | char *rem; |
| 639 | const char *sep=" \t\n\r"; |
| 640 | char *radious; |
| 641 | char *theta; |
| 642 | |
| 643 | radious=strtok_r(command,sep,&rem); |
| 644 | if (radious == NULL ) |
| 645 | { |
| 646 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | theta=strtok_r(NULL,sep,&rem); |
| 651 | if (theta == NULL ) |
| 652 | { |
| 653 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | nlsr->cor_r=strtof(radious,NULL); |
| 658 | nlsr->cor_theta=strtof(theta,NULL); |
| 659 | |
| 660 | } |
| 661 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 662 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 663 | process_command_tunnel_type(char *command) |
| 664 | { |
| 665 | if(command==NULL) |
| 666 | { |
| 667 | printf(" Wrong Command Format ( tunnel-type udp/tcp)\n"); |
| 668 | return; |
| 669 | } |
| 670 | char *rem; |
| 671 | const char *sep=" \t\n"; |
| 672 | char *on_off; |
| 673 | |
| 674 | on_off=strtok_r(command,sep,&rem); |
| 675 | if(on_off==NULL) |
| 676 | { |
| 677 | printf(" Wrong Command Format ( tunnel-type udp/tcp )\n"); |
| 678 | return; |
| 679 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 680 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 681 | if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 ) |
| 682 | { |
| 683 | nlsr->tunnel_type=IPPROTO_TCP; |
| 684 | } |
| 685 | else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 ) |
| 686 | { |
| 687 | nlsr->tunnel_type=IPPROTO_UDP; |
| 688 | } |
| 689 | } |
| 690 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 691 | void |
| 692 | process_command_keystore_passphrase(char *command) |
| 693 | { |
| 694 | if(command==NULL) |
| 695 | { |
| 696 | printf(" Wrong Command Format ( keystore-passphrase passphrase )\n"); |
| 697 | return; |
| 698 | } |
| 699 | char *rem; |
| 700 | const char *sep=" \t\n"; |
| 701 | char *passphrase; |
| 702 | |
| 703 | passphrase=strtok_r(command,sep,&rem); |
| 704 | if(passphrase==NULL) |
| 705 | { |
| 706 | printf(" Wrong Command Format ( keystore-passphrase passphrase )\n"); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | if( nlsr->keystore_passphrase) |
| 711 | free(nlsr->keystore_passphrase); |
| 712 | nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char)); |
| 713 | memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase)); |
| 714 | |
| 715 | |
| 716 | } |
| 717 | |
| 718 | |
| 719 | void |
| 720 | process_command_keystore_path(char *command) |
| 721 | { |
| 722 | if(command==NULL) |
| 723 | { |
| 724 | printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n"); |
| 725 | return; |
| 726 | } |
| 727 | char *rem; |
| 728 | const char *sep=" \t\n"; |
| 729 | char *path; |
| 730 | |
| 731 | path=strtok_r(command,sep,&rem); |
| 732 | if(path==NULL) |
| 733 | { |
| 734 | printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n"); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | if( nlsr->keystore_path) |
| 739 | free(nlsr->keystore_path); |
| 740 | nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char)); |
| 741 | memcpy(nlsr->keystore_path,path,strlen(path)); |
| 742 | |
| 743 | } |
| 744 | |
| 745 | |
| 746 | |
| 747 | void |
| 748 | process_command_site_name(char *command) |
| 749 | { |
| 750 | if(command==NULL) |
| 751 | { |
| 752 | printf(" Wrong Command Format ( site-name site/name/prefix )\n"); |
| 753 | return; |
| 754 | } |
| 755 | char *rem; |
| 756 | const char *sep=" \t\n"; |
| 757 | char *site_name; |
| 758 | |
| 759 | site_name=strtok_r(command,sep,&rem); |
| 760 | if(site_name==NULL) |
| 761 | { |
| 762 | printf(" Wrong Command Format ( site-name site/name/prefix )\n"); |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | if( nlsr->site_name) |
| 767 | free(nlsr->site_name); |
| 768 | |
| 769 | if ( site_name[strlen(site_name)-1] == '/' ) |
| 770 | site_name[strlen(site_name)-1]='\0'; |
| 771 | |
| 772 | nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char)); |
| 773 | memcpy(nlsr->site_name,site_name,strlen(site_name)); |
| 774 | printf("Site Name prefix: %s \n",nlsr->site_name); |
| 775 | |
| 776 | } |
| 777 | |
| 778 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 779 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 780 | process_conf_command(char *command) |
| 781 | { |
| 782 | const char *separators=" \t\n"; |
| 783 | char *remainder=NULL; |
| 784 | char *cmd_type=NULL; |
| 785 | |
| 786 | if(command==NULL || strlen(command)==0 || command[0]=='!') |
| 787 | return; |
| 788 | |
| 789 | cmd_type=strtok_r(command,separators,&remainder); |
| 790 | |
| 791 | if(!strcmp(cmd_type,"router-name") ) |
| 792 | { |
| 793 | process_command_router_name(remainder); |
| 794 | } |
| 795 | else if(!strcmp(cmd_type,"ccnneighbor") ) |
| 796 | { |
| 797 | process_command_ccnneighbor(remainder); |
| 798 | } |
| 799 | else if(!strcmp(cmd_type,"ccnname") ) |
| 800 | { |
| 801 | process_command_ccnname(remainder); |
| 802 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 803 | else if(!strcmp(cmd_type,"interest-retry") ) |
| 804 | { |
| 805 | process_command_interest_retry(remainder); |
| 806 | } |
| 807 | else if(!strcmp(cmd_type,"interest-resend-time") ) |
| 808 | { |
| 809 | process_command_interest_resend_time(remainder); |
| 810 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 811 | else if(!strcmp(cmd_type,"lsa-refresh-time") ) |
| 812 | { |
| 813 | process_command_lsa_refresh_time(remainder); |
| 814 | } |
| 815 | else if(!strcmp(cmd_type,"router-dead-interval") ) |
| 816 | { |
| 817 | process_command_router_dead_interval(remainder); |
| 818 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 819 | else if(!strcmp(cmd_type,"max-faces-per-prefix") ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 820 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 821 | process_command_max_faces_per_prefix(remainder); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 822 | } |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 823 | else if(!strcmp(cmd_type,"logdir") ) |
| 824 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 825 | process_command_logdir(remainder); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 826 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 827 | else if(!strcmp(cmd_type,"detailed-log") ) |
| 828 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 829 | process_command_detailed_log(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 830 | } |
| 831 | else if(!strcmp(cmd_type,"debug") ) |
| 832 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 833 | process_command_debug(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 834 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 835 | else if(!strcmp(cmd_type,"topo-prefix") ) |
| 836 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 837 | process_command_topo_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 838 | } |
| 839 | else if(!strcmp(cmd_type,"slice-prefix") ) |
| 840 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 841 | process_command_slice_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 842 | } |
| 843 | else if(!strcmp(cmd_type,"hyperbolic-cordinate") ) |
| 844 | { |
| 845 | process_command_hyperbolic_cordinate(remainder); |
| 846 | } |
| 847 | else if(!strcmp(cmd_type,"hyperbolic-routing") ) |
| 848 | { |
| 849 | process_command_hyperbolic_routing(remainder); |
| 850 | } |
| 851 | else if(!strcmp(cmd_type,"tunnel-type") ) |
| 852 | { |
| 853 | process_command_tunnel_type(remainder); |
| 854 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 855 | else if(!strcmp(cmd_type,"site-name") ) |
| 856 | { |
| 857 | process_command_site_name(remainder); |
| 858 | } |
| 859 | else if(!strcmp(cmd_type,"keystore-path") ) |
| 860 | { |
| 861 | process_command_keystore_path(remainder); |
| 862 | } |
| 863 | else if(!strcmp(cmd_type,"keystore-passphrase") ) |
| 864 | { |
| 865 | process_command_keystore_passphrase(remainder); |
| 866 | } |
| 867 | else if(!strcmp(cmd_type,"root-key-prefix") ) |
| 868 | { |
| 869 | process_command_root_key_prefix(remainder); |
| 870 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 871 | else |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 872 | { |
| 873 | printf("Wrong configuration Command %s \n",cmd_type); |
| 874 | } |
| 875 | } |
| 876 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 877 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 878 | int |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 879 | readConfigFile(const char *filename) |
| 880 | { |
| 881 | FILE *cfg; |
| 882 | char buf[1024]; |
| 883 | int len; |
| 884 | |
| 885 | cfg=fopen(filename, "r"); |
| 886 | |
| 887 | if(cfg == NULL) |
| 888 | { |
| 889 | printf("\nConfiguration File does not exists\n"); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 890 | return -1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | while(fgets((char *)buf, sizeof(buf), cfg)) |
| 894 | { |
| 895 | len=strlen(buf); |
| 896 | if(buf[len-1] == '\n') |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 897 | buf[len-1]='\0'; |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 898 | if ( buf[0] != '#' && buf[0] != '!') |
| 899 | process_conf_command(buf); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | fclose(cfg); |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 907 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 908 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 909 | add_faces_for_nbrs(void) |
| 910 | { |
| 911 | int i, adl_element; |
| 912 | struct ndn_neighbor *nbr; |
| 913 | |
| 914 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 915 | struct hashtb_enumerator *e = ⅇ |
| 916 | |
| 917 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 918 | adl_element=hashtb_n(nlsr->adl); |
| 919 | |
| 920 | for(i=0;i<adl_element;i++) |
| 921 | { |
| 922 | nbr=e->data; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 923 | int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr->neighbor->name, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 924 | (const char *)nbr->ip_address, 9695,nlsr->tunnel_type); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 925 | update_face_to_adl_for_nbr(nbr->neighbor->name, face_id); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 926 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 927 | (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 928 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 929 | (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 930 | hashtb_next(e); |
| 931 | } |
| 932 | |
| 933 | hashtb_end(e); |
| 934 | |
| 935 | } |
| 936 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 937 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 938 | destroy_faces_for_nbrs(void) |
| 939 | { |
| 940 | int i, adl_element; |
| 941 | struct ndn_neighbor *nbr; |
| 942 | |
| 943 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 944 | struct hashtb_enumerator *e = ⅇ |
| 945 | |
| 946 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 947 | adl_element=hashtb_n(nlsr->adl); |
| 948 | |
| 949 | for(i=0;i<adl_element;i++) |
| 950 | { |
| 951 | nbr=e->data; |
| 952 | if ( nbr->face > 0 ) |
| 953 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 954 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 955 | (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face,(~0U) >> 1); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 956 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 957 | (const char *)nbr->neighbor->name,OP_UNREG,nbr->face,(~0U) >> 1); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 958 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 959 | (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face,(~0U) >> 1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 960 | } |
| 961 | hashtb_next(e); |
| 962 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 963 | hashtb_end(e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 964 | } |
| 965 | |
akmhoque | ad6d569 | 2013-03-11 19:43:33 -0500 | [diff] [blame] | 966 | |
| 967 | char * |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 968 | process_api_client_command(char *command) |
| 969 | { |
| 970 | char *msg; |
| 971 | msg=(char *)malloc(100); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 972 | memset(msg,0,100); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 973 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 974 | const char *sep=" \t\n"; |
| 975 | char *rem=NULL; |
| 976 | char *cmd_type=NULL; |
| 977 | char *op_type=NULL; |
| 978 | char *name=NULL; |
| 979 | char *face=NULL; |
| 980 | int face_id; |
| 981 | int res; |
| 982 | |
| 983 | op_type=strtok_r(command,sep,&rem); |
| 984 | cmd_type=strtok_r(NULL,sep,&rem); |
| 985 | name=strtok_r(NULL,sep,&rem); |
| 986 | if ( name[strlen(name)-1] == '/' ) |
| 987 | name[strlen(name)-1]='\0'; |
| 988 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 989 | struct name_prefix *np=(struct name_prefix *) calloc (1, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 990 | sizeof(struct name_prefix )); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 991 | np->name = (char *) calloc (strlen(name)+1,sizeof(char)); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 992 | memcpy(np->name,name,strlen(name)+1); |
| 993 | np->length=strlen(name)+1; |
| 994 | |
| 995 | if ( strcmp(cmd_type,"name")!= 0 ) |
| 996 | { |
| 997 | face=strtok_r(NULL,sep,&rem); |
| 998 | sscanf(face,"face%d",&face_id); |
| 999 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1000 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1001 | if ( strcmp(cmd_type,"name")== 0 ) |
| 1002 | { |
| 1003 | if ( strcmp(op_type,"del") == 0 ) |
| 1004 | { |
| 1005 | res=does_name_exist_in_npl(np); |
| 1006 | if ( res == 0) |
| 1007 | { |
| 1008 | sprintf(msg,"Name %s does not exist !!",name); |
| 1009 | } |
| 1010 | else |
| 1011 | { |
| 1012 | long int ls_id=get_lsa_id_from_npl(np); |
| 1013 | if ( ls_id != 0 ) |
| 1014 | { |
| 1015 | make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id); |
| 1016 | sprintf(msg,"Name %s has been deleted and Advertised.",name); |
| 1017 | } |
| 1018 | else |
| 1019 | { |
| 1020 | sprintf(msg,"Name %s does not have an Name LSA yet !!",name); |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | else if ( strcmp(op_type,"add") == 0 ) |
| 1025 | { |
| 1026 | res=does_name_exist_in_npl(np); |
| 1027 | if ( res == 0) |
| 1028 | { |
| 1029 | add_name_to_npl(np); |
| 1030 | build_and_install_single_name_lsa(np); |
| 1031 | sprintf(msg,"Name %s has been added to advertise.",name); |
| 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | sprintf(msg,"Name %s has already been advertised from this router !!",name); |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | else if ( strcmp(cmd_type,"neighbor") == 0 ) |
| 1040 | { |
| 1041 | if ( strcmp(op_type,"del") == 0 ) |
| 1042 | { |
| 1043 | res=is_neighbor(np->name); |
| 1044 | if ( res == 0) |
| 1045 | { |
| 1046 | sprintf(msg,"Neighbor %s does not exist !!",name); |
| 1047 | } |
| 1048 | else |
| 1049 | { |
| 1050 | update_adjacent_status_to_adl(np,NBR_DOWN); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1051 | int face_id=get_next_hop_face_from_adl(np->name); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 1052 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id,(~0U) >> 1); |
| 1053 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id,(~0U) >> 1); |
| 1054 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_UNREG, face_id,(~0U) >> 1); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1055 | delete_nbr_from_adl(np); |
| 1056 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 1057 | { |
| 1058 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 1059 | nlsr->is_build_adj_lsa_sheduled=1; |
| 1060 | } |
| 1061 | sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name); |
| 1062 | } |
| 1063 | } |
| 1064 | else if ( strcmp(op_type,"add") == 0 ) |
| 1065 | { |
| 1066 | res=is_neighbor(np->name); |
| 1067 | if ( res == 0 ) |
| 1068 | { |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1069 | struct name_prefix *nbr_name=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1070 | get_host_name_from_command_string(nbr_name,np->name,0); |
| 1071 | printf("Hostname of neighbor: %s ",nbr_name->name); |
| 1072 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1073 | char *ip_addr=(char *)calloc(20,sizeof(char)); |
| 1074 | //memset(ip_addr,0,20); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1075 | get_ip_from_hostname_02(nbr_name->name,ip_addr); |
| 1076 | printf("IP Address: %s \n",ip_addr); |
| 1077 | int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type); |
| 1078 | update_face_to_adl_for_nbr(nbr_name->name, face_id); |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 1079 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id,(~0U) >> 1); |
| 1080 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1081 | |
| 1082 | add_nbr_to_adl(np,face_id,ip_addr); |
| 1083 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1084 | sprintf(msg,"Neighbor %s has been added to adjacency list.",name); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1085 | free(ip_addr); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1086 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1087 | } |
| 1088 | else |
| 1089 | { |
| 1090 | sprintf(msg,"Neighbor %s already exists in adjacency list.",name); |
| 1091 | } |
| 1092 | } |
| 1093 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1094 | |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 1095 | |
| 1096 | return msg; |
| 1097 | } |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1098 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1099 | int |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1100 | nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd) |
| 1101 | { |
| 1102 | struct timeval timeout; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1103 | if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 ) |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1104 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1105 | timeout.tv_sec=0; |
| 1106 | timeout.tv_usec=time_out_micro_sec; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1107 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1108 | else |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1109 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1110 | timeout.tv_sec = 0; |
| 1111 | timeout.tv_usec = 500000; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1112 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1113 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1114 | int fd; |
| 1115 | int nread; |
| 1116 | int result; |
| 1117 | fd_set testfds; |
| 1118 | unsigned int client_len; |
| 1119 | int client_sockfd; |
| 1120 | char recv_buffer[1024]; |
| 1121 | bzero(recv_buffer,1024); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1122 | struct sockaddr_in client_address; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1123 | |
| 1124 | testfds=nlsr->readfds; |
| 1125 | result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1126 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1127 | for(fd = 0; fd < FD_SETSIZE && result > 0; fd++) |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1128 | { |
| 1129 | if(FD_ISSET(fd,&testfds)) |
| 1130 | { |
| 1131 | if ( fd == ccn_fd ) |
| 1132 | { |
| 1133 | return 0; |
| 1134 | } |
| 1135 | else if(fd == nlsr->nlsr_api_server_sock_fd) |
| 1136 | { |
| 1137 | client_len = sizeof(client_address); |
| 1138 | client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len); |
| 1139 | FD_SET(client_sockfd, &nlsr->readfds); |
| 1140 | } |
| 1141 | else |
| 1142 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1143 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1144 | ioctl(fd, FIONREAD, &nread); |
| 1145 | if(nread == 0) |
| 1146 | { |
| 1147 | close(fd); |
| 1148 | FD_CLR(fd, &nlsr->readfds); |
| 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | recv(fd, recv_buffer, 1024, 0); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1153 | printf("Received Data from NLSR API cleint: %s \n",recv_buffer); |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 1154 | char *msg=process_api_client_command(recv_buffer); |
| 1155 | send(fd, msg, strlen(msg),0); |
| 1156 | free(msg); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1157 | close(fd); |
| 1158 | FD_CLR(fd, &nlsr->readfds); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1167 | int |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1168 | check_config_validity() |
| 1169 | { |
| 1170 | if (nlsr->router_name == NULL ) |
| 1171 | { |
| 1172 | fprintf(stderr,"Router name has not been configured :(\n"); |
| 1173 | return -1; |
| 1174 | } |
| 1175 | if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) ) |
| 1176 | { |
| 1177 | fprintf(stderr,"Hyperbolic codinate has not been defined :(\n"); |
| 1178 | return -1; |
| 1179 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1180 | if (nlsr->site_name == NULL ) |
| 1181 | { |
| 1182 | fprintf(stderr,"Site name has not been configured :(\n"); |
| 1183 | return -1; |
| 1184 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1185 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1186 | return 0; |
| 1187 | } |
| 1188 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1189 | void |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 1190 | nlsr_destroy( void ) |
| 1191 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1192 | if ( nlsr->debugging ) |
| 1193 | { |
| 1194 | printf("Freeing Allocated Memory....\n"); |
| 1195 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1196 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n"); |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 1197 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1198 | /* Destroying all face created by nlsr in CCND */ |
| 1199 | destroy_all_face_by_nlsr(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1200 | destroy_faces_for_nbrs(); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1201 | |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 1202 | |
akmhoque | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1203 | destroy_adl(); |
akmhoque | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1204 | destroy_npl(); |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 1205 | destroy_lsdb(); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1206 | destroy_npt(); |
| 1207 | destroy_routing_table(); |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 1208 | destroy_keys(); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1209 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1210 | if ( nlsr->slice != NULL ) |
| 1211 | ccns_slice_destroy(&nlsr->slice); |
akmhoque | e48d707 | 2013-03-15 19:44:27 -0500 | [diff] [blame] | 1212 | if ( nlsr->ccns != NULL ) |
| 1213 | ccns_close(&nlsr->ccns, NULL, NULL); |
akmhoque | 0ddc8b2 | 2013-03-15 20:23:28 -0500 | [diff] [blame] | 1214 | if (nlsr->closure != NULL ) |
| 1215 | free(nlsr->closure); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1216 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1217 | close(nlsr->nlsr_api_server_sock_fd); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1218 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1219 | ccn_destroy(&nlsr->ccn); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1220 | |
| 1221 | free(nlsr->root_key_prefix); |
| 1222 | free(nlsr->keystore_path); |
| 1223 | free(nlsr->keystore_passphrase); |
| 1224 | if( nlsr->site_name ) |
| 1225 | free(nlsr->site_name); |
| 1226 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1227 | free(nlsr->router_name); |
akmhoque | 83a94da | 2013-03-15 01:38:21 -0500 | [diff] [blame] | 1228 | |
| 1229 | |
| 1230 | free(nlsr->slice_prefix); |
| 1231 | free(nlsr->topo_prefix); |
| 1232 | free(nlsr->logDir); |
| 1233 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1234 | if ( nlsr->debugging ) |
| 1235 | { |
| 1236 | printf("Finished freeing allocated memory\n"); |
| 1237 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1238 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1239 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1240 | free(nlsr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1241 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 1242 | } |
| 1243 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1244 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1245 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1246 | void |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1247 | init_api_server(int ccn_fd) |
| 1248 | { |
| 1249 | int server_sockfd; |
| 1250 | int server_len; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1251 | struct sockaddr_in server_address; |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1252 | unsigned int yes=1; |
| 1253 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1254 | server_sockfd = socket(AF_INET, SOCK_STREAM, 0); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1255 | |
| 1256 | int flags = fcntl(server_sockfd, F_GETFL, 0); |
| 1257 | fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags); |
| 1258 | |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1259 | if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) |
| 1260 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1261 | ON_ERROR_DESTROY(-1); |
| 1262 | } |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1263 | |
| 1264 | server_address.sin_family = AF_INET; |
Adam Alyyan | b5fff37 | 2013-01-09 14:32:52 -0600 | [diff] [blame] | 1265 | server_address.sin_addr.s_addr = INADDR_ANY; |
| 1266 | server_address.sin_port = htons(nlsr->api_port); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1267 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1268 | server_len = sizeof(server_address); |
| 1269 | bind(server_sockfd, (struct sockaddr *)&server_address, server_len); |
| 1270 | listen(server_sockfd, 100); |
| 1271 | FD_ZERO(&nlsr->readfds); |
| 1272 | FD_SET(server_sockfd, &nlsr->readfds); |
| 1273 | FD_SET(ccn_fd, &nlsr->readfds); |
| 1274 | nlsr->nlsr_api_server_sock_fd=server_sockfd; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1275 | } |
| 1276 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1277 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1278 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1279 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1280 | if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1281 | { |
| 1282 | perror("SIGQUIT install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1283 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1284 | } |
| 1285 | if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1286 | { |
| 1287 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1288 | return -1; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1289 | } |
| 1290 | if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1291 | { |
| 1292 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1293 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1294 | } |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1295 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1296 | nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr)); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1297 | |
akmhoque | ae38886 | 2013-03-15 01:46:22 -0500 | [diff] [blame] | 1298 | nlsr->adl= hashtb_create(sizeof(struct ndn_neighbor), NULL); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1299 | nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1300 | nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL); |
| 1301 | nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL); |
akmhoque | 237239c | 2013-03-18 10:29:26 -0500 | [diff] [blame] | 1302 | nlsr->keys = hashtb_create(sizeof(struct nlsr_key), NULL); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1303 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1304 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase)); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1305 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL); |
| 1306 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL); |
| 1307 | nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 1308 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1309 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1310 | |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1311 | nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2(); |
| 1312 | |
| 1313 | nlsr->in_interest.p = &incoming_interest; |
| 1314 | nlsr->in_content.p = &incoming_content; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1315 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1316 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 1317 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1318 | nlsr->adj_build_flag=0; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1319 | nlsr->adj_build_count=0; |
| 1320 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1321 | nlsr->is_send_lsdb_interest_scheduled=0; |
| 1322 | nlsr->is_route_calculation_scheduled=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1323 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1324 | nlsr->detailed_logging=0; |
| 1325 | nlsr->debugging=0; |
| 1326 | |
akmhoque | b8dbba8 | 2013-03-11 11:34:17 -0500 | [diff] [blame] | 1327 | nlsr->isStrictHierchicalKeyCheck=1; |
| 1328 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1329 | nlsr->interest_retry = INTEREST_RETRY; |
| 1330 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1331 | nlsr->lsa_refresh_time=LSA_REFRESH_TIME; |
| 1332 | nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1333 | nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1334 | nlsr->semaphor=NLSR_UNLOCKED; |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1335 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1336 | nlsr->api_port=API_PORT; |
| 1337 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1338 | nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1339 | memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr")); |
| 1340 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1341 | nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1342 | memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA")); |
| 1343 | |
| 1344 | nlsr->is_hyperbolic_calc=0; |
| 1345 | nlsr->cor_r=-1.0; |
| 1346 | nlsr->cor_theta=-1.0; |
| 1347 | |
| 1348 | nlsr->tunnel_type=IPPROTO_UDP; |
| 1349 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1350 | nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char)); |
| 1351 | memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys")); |
| 1352 | nlsr->keystore_path=get_current_user_default_keystore(); |
| 1353 | nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1 |
| 1354 | ,sizeof(char)); |
| 1355 | memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.", |
| 1356 | strlen("Th1s1sn0t8g00dp8ssw0rd.")); |
| 1357 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1358 | return 0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1359 | } |
| 1360 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1361 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1362 | main(int argc, char *argv[]) |
| 1363 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1364 | int res, ret; |
| 1365 | char *config_file; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1366 | int daemon_mode=0; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1367 | int port=0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1368 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1369 | while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1370 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1371 | switch (res) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1372 | { |
| 1373 | case 'd': |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1374 | daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1375 | break; |
| 1376 | case 'f': |
| 1377 | config_file = optarg; |
| 1378 | break; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1379 | case 'p': |
| 1380 | port = atoi(optarg); |
| 1381 | break; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1382 | case 'h': |
| 1383 | default: |
| 1384 | usage(argv[0]); |
| 1385 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1386 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1387 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1388 | ret = init_nlsr(); |
| 1389 | ON_ERROR_EXIT(ret); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1390 | |
| 1391 | if ( port !=0 ) |
| 1392 | nlsr->api_port=port; |
| 1393 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1394 | ON_ERROR_DESTROY(readConfigFile(config_file)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1395 | |
| 1396 | ON_ERROR_DESTROY(check_config_validity()); |
| 1397 | |
| 1398 | print_adjacent_from_adl(); |
| 1399 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1400 | if ( daemon_mode == 1 ) |
| 1401 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1402 | nlsr->debugging=0; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1403 | daemonize_nlsr(); |
| 1404 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1405 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1406 | startLogging(nlsr->logDir); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1407 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1408 | nlsr->ccn=ccn_create(); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1409 | int ccn_fd=ccn_connect(nlsr->ccn, NULL); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1410 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1411 | if(ccn_fd == -1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1412 | { |
| 1413 | fprintf(stderr,"Could not connect to ccnd\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1414 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1415 | ON_ERROR_DESTROY(-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1416 | } |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1417 | |
| 1418 | init_api_server(ccn_fd); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1419 | |
| 1420 | res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1421 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1422 | if(res<0) |
| 1423 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1424 | fprintf(stderr, "Can not create slice for prefix %s\n", |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1425 | nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1426 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for" |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1427 | "prefix %s\n",nlsr->slice_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1428 | ON_ERROR_DESTROY(res); |
| 1429 | } |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1430 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1431 | struct ccn_charbuf *router_prefix; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1432 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1433 | router_prefix=ccn_charbuf_create(); |
| 1434 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1435 | if(res<0) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1436 | { |
| 1437 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1438 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1439 | "Bad ccn URI: %s\n", nlsr->router_name); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1440 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1441 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1442 | |
| 1443 | ccn_name_append_str(router_prefix,"nlsr"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1444 | nlsr->in_interest.data=nlsr->router_name; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1445 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 1446 | if ( res < 0 ) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1447 | { |
| 1448 | fprintf(stderr,"Failed to register interest for router\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1449 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1450 | "Failed to register interest for router\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1451 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1452 | } |
| 1453 | ccn_charbuf_destroy(&router_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1454 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1455 | if ( nlsr->debugging ) |
| 1456 | printf("Router Name : %s\n",nlsr->router_name); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1457 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1458 | if ( nlsr->debugging ) |
| 1459 | printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1460 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1461 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1462 | add_faces_for_nbrs(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1463 | print_name_prefix_from_npl(); |
| 1464 | print_adjacent_from_adl(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1465 | build_and_install_name_lsas(); |
| 1466 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1467 | print_name_lsdb(); |
| 1468 | if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0) |
| 1469 | { |
| 1470 | build_and_install_cor_lsa(); |
| 1471 | } |
| 1472 | write_name_lsdb_to_repo(nlsr->slice_prefix); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1473 | |
| 1474 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
akmhoque | 184dde0 | 2013-02-14 15:53:24 -0600 | [diff] [blame] | 1475 | ccn_set_schedule(nlsr->ccn,nlsr->sched); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1476 | nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1477 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1478 | |
akmhoque | 0678c5d | 2013-02-18 11:03:31 -0600 | [diff] [blame] | 1479 | res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix); |
| 1480 | ON_ERROR_DESTROY(res); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 1481 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1482 | while(1) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1483 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1484 | if ( nlsr->semaphor == NLSR_UNLOCKED ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1485 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1486 | if( nlsr->sched != NULL ) |
| 1487 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1488 | long int micro_sec=ccn_schedule_run(nlsr->sched); |
| 1489 | res=nlsr_api_server_poll(micro_sec,ccn_fd); |
| 1490 | ON_ERROR_DESTROY(res); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1491 | } |
| 1492 | if(nlsr->ccn != NULL) |
| 1493 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1494 | res = ccn_run(nlsr->ccn, 1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1495 | } |
| 1496 | if (!(nlsr->sched && nlsr->ccn)) |
| 1497 | { |
| 1498 | break; |
| 1499 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1500 | } |
| 1501 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1502 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1503 | return 0; |
| 1504 | } |
| 1505 | |