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