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 | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 566 | //if( nlsr->slice_prefix) |
| 567 | //free(nlsr->slice_prefix); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 568 | nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 569 | memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 570 | printf("Slice prefix: %s \n",nlsr->slice_prefix); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | |
| 575 | void |
| 576 | process_command_root_key_prefix(char *command) |
| 577 | { |
| 578 | if(command==NULL) |
| 579 | { |
| 580 | printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n"); |
| 581 | return; |
| 582 | } |
| 583 | char *rem; |
| 584 | const char *sep=" \t\n"; |
| 585 | char *root_key_prefix; |
| 586 | |
| 587 | root_key_prefix=strtok_r(command,sep,&rem); |
| 588 | if(root_key_prefix==NULL) |
| 589 | { |
| 590 | printf(" Wrong Command Format ( root-key-prefix /name/prefix )\n"); |
| 591 | return; |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | if ( nlsr->root_key_prefix != NULL) |
| 596 | free(nlsr->root_key_prefix); |
| 597 | if ( root_key_prefix[strlen(root_key_prefix)-1] == '/' ) |
| 598 | root_key_prefix[strlen(root_key_prefix)-1]='\0'; |
| 599 | nlsr->root_key_prefix=(char *)calloc(strlen(root_key_prefix)+1,sizeof(char)); |
| 600 | memcpy(nlsr->root_key_prefix,root_key_prefix,strlen(root_key_prefix)+1); |
| 601 | printf("Root key prefix: %s \n",nlsr->root_key_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 605 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 606 | process_command_hyperbolic_routing(char *command) |
| 607 | { |
| 608 | if(command==NULL) |
| 609 | { |
| 610 | printf(" Wrong Command Format ( hyperbolic-routing on)\n"); |
| 611 | return; |
| 612 | } |
| 613 | char *rem; |
| 614 | const char *sep=" \t\n"; |
| 615 | char *on_off; |
| 616 | |
| 617 | on_off=strtok_r(command,sep,&rem); |
| 618 | if(on_off==NULL) |
| 619 | { |
| 620 | printf(" Wrong Command Format ( hyperbolic-routing on )\n"); |
| 621 | return; |
| 622 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 623 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 624 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 625 | { |
| 626 | nlsr->is_hyperbolic_calc=1; |
| 627 | } |
| 628 | } |
| 629 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 630 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 631 | process_command_hyperbolic_cordinate(char *command) |
| 632 | { |
| 633 | if(command==NULL) |
| 634 | { |
| 635 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | char *rem; |
| 640 | const char *sep=" \t\n\r"; |
| 641 | char *radious; |
| 642 | char *theta; |
| 643 | |
| 644 | radious=strtok_r(command,sep,&rem); |
| 645 | if (radious == NULL ) |
| 646 | { |
| 647 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | theta=strtok_r(NULL,sep,&rem); |
| 652 | if (theta == NULL ) |
| 653 | { |
| 654 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | nlsr->cor_r=strtof(radious,NULL); |
| 659 | nlsr->cor_theta=strtof(theta,NULL); |
| 660 | |
| 661 | } |
| 662 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 663 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 664 | process_command_tunnel_type(char *command) |
| 665 | { |
| 666 | if(command==NULL) |
| 667 | { |
| 668 | printf(" Wrong Command Format ( tunnel-type udp/tcp)\n"); |
| 669 | return; |
| 670 | } |
| 671 | char *rem; |
| 672 | const char *sep=" \t\n"; |
| 673 | char *on_off; |
| 674 | |
| 675 | on_off=strtok_r(command,sep,&rem); |
| 676 | if(on_off==NULL) |
| 677 | { |
| 678 | printf(" Wrong Command Format ( tunnel-type udp/tcp )\n"); |
| 679 | return; |
| 680 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 681 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 682 | if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 ) |
| 683 | { |
| 684 | nlsr->tunnel_type=IPPROTO_TCP; |
| 685 | } |
| 686 | else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 ) |
| 687 | { |
| 688 | nlsr->tunnel_type=IPPROTO_UDP; |
| 689 | } |
| 690 | } |
| 691 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 692 | void |
| 693 | process_command_keystore_passphrase(char *command) |
| 694 | { |
| 695 | if(command==NULL) |
| 696 | { |
| 697 | printf(" Wrong Command Format ( keystore-passphrase passphrase )\n"); |
| 698 | return; |
| 699 | } |
| 700 | char *rem; |
| 701 | const char *sep=" \t\n"; |
| 702 | char *passphrase; |
| 703 | |
| 704 | passphrase=strtok_r(command,sep,&rem); |
| 705 | if(passphrase==NULL) |
| 706 | { |
| 707 | printf(" Wrong Command Format ( keystore-passphrase passphrase )\n"); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | if( nlsr->keystore_passphrase) |
| 712 | free(nlsr->keystore_passphrase); |
| 713 | nlsr->keystore_passphrase=(char *)calloc(strlen(passphrase)+1,sizeof(char)); |
| 714 | memcpy(nlsr->keystore_passphrase,passphrase,strlen(passphrase)); |
| 715 | |
| 716 | |
| 717 | } |
| 718 | |
| 719 | |
| 720 | void |
| 721 | process_command_keystore_path(char *command) |
| 722 | { |
| 723 | if(command==NULL) |
| 724 | { |
| 725 | printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n"); |
| 726 | return; |
| 727 | } |
| 728 | char *rem; |
| 729 | const char *sep=" \t\n"; |
| 730 | char *path; |
| 731 | |
| 732 | path=strtok_r(command,sep,&rem); |
| 733 | if(path==NULL) |
| 734 | { |
| 735 | printf(" Wrong Command Format ( keystore-path path/to/.ccnx_keystore )\n"); |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | if( nlsr->keystore_path) |
| 740 | free(nlsr->keystore_path); |
| 741 | nlsr->keystore_path=(char *)calloc(strlen(path)+1,sizeof(char)); |
| 742 | memcpy(nlsr->keystore_path,path,strlen(path)); |
| 743 | |
| 744 | } |
| 745 | |
| 746 | |
| 747 | |
| 748 | void |
| 749 | process_command_site_name(char *command) |
| 750 | { |
| 751 | if(command==NULL) |
| 752 | { |
| 753 | printf(" Wrong Command Format ( site-name site/name/prefix )\n"); |
| 754 | return; |
| 755 | } |
| 756 | char *rem; |
| 757 | const char *sep=" \t\n"; |
| 758 | char *site_name; |
| 759 | |
| 760 | site_name=strtok_r(command,sep,&rem); |
| 761 | if(site_name==NULL) |
| 762 | { |
| 763 | printf(" Wrong Command Format ( site-name site/name/prefix )\n"); |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | if( nlsr->site_name) |
| 768 | free(nlsr->site_name); |
| 769 | |
| 770 | if ( site_name[strlen(site_name)-1] == '/' ) |
| 771 | site_name[strlen(site_name)-1]='\0'; |
| 772 | |
| 773 | nlsr->site_name=(char *)calloc(strlen(site_name)+1,sizeof(char)); |
| 774 | memcpy(nlsr->site_name,site_name,strlen(site_name)); |
| 775 | printf("Site Name prefix: %s \n",nlsr->site_name); |
| 776 | |
| 777 | } |
| 778 | |
| 779 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 780 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 781 | process_conf_command(char *command) |
| 782 | { |
| 783 | const char *separators=" \t\n"; |
| 784 | char *remainder=NULL; |
| 785 | char *cmd_type=NULL; |
| 786 | |
| 787 | if(command==NULL || strlen(command)==0 || command[0]=='!') |
| 788 | return; |
| 789 | |
| 790 | cmd_type=strtok_r(command,separators,&remainder); |
| 791 | |
| 792 | if(!strcmp(cmd_type,"router-name") ) |
| 793 | { |
| 794 | process_command_router_name(remainder); |
| 795 | } |
| 796 | else if(!strcmp(cmd_type,"ccnneighbor") ) |
| 797 | { |
| 798 | process_command_ccnneighbor(remainder); |
| 799 | } |
| 800 | else if(!strcmp(cmd_type,"ccnname") ) |
| 801 | { |
| 802 | process_command_ccnname(remainder); |
| 803 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 804 | else if(!strcmp(cmd_type,"interest-retry") ) |
| 805 | { |
| 806 | process_command_interest_retry(remainder); |
| 807 | } |
| 808 | else if(!strcmp(cmd_type,"interest-resend-time") ) |
| 809 | { |
| 810 | process_command_interest_resend_time(remainder); |
| 811 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 812 | else if(!strcmp(cmd_type,"lsa-refresh-time") ) |
| 813 | { |
| 814 | process_command_lsa_refresh_time(remainder); |
| 815 | } |
| 816 | else if(!strcmp(cmd_type,"router-dead-interval") ) |
| 817 | { |
| 818 | process_command_router_dead_interval(remainder); |
| 819 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 820 | else if(!strcmp(cmd_type,"max-faces-per-prefix") ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 821 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 822 | process_command_max_faces_per_prefix(remainder); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 823 | } |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 824 | else if(!strcmp(cmd_type,"logdir") ) |
| 825 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 826 | process_command_logdir(remainder); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 827 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 828 | else if(!strcmp(cmd_type,"detailed-log") ) |
| 829 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 830 | process_command_detailed_log(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 831 | } |
| 832 | else if(!strcmp(cmd_type,"debug") ) |
| 833 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 834 | process_command_debug(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 835 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 836 | else if(!strcmp(cmd_type,"topo-prefix") ) |
| 837 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 838 | process_command_topo_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 839 | } |
| 840 | else if(!strcmp(cmd_type,"slice-prefix") ) |
| 841 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 842 | process_command_slice_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 843 | } |
| 844 | else if(!strcmp(cmd_type,"hyperbolic-cordinate") ) |
| 845 | { |
| 846 | process_command_hyperbolic_cordinate(remainder); |
| 847 | } |
| 848 | else if(!strcmp(cmd_type,"hyperbolic-routing") ) |
| 849 | { |
| 850 | process_command_hyperbolic_routing(remainder); |
| 851 | } |
| 852 | else if(!strcmp(cmd_type,"tunnel-type") ) |
| 853 | { |
| 854 | process_command_tunnel_type(remainder); |
| 855 | } |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 856 | else if(!strcmp(cmd_type,"site-name") ) |
| 857 | { |
| 858 | process_command_site_name(remainder); |
| 859 | } |
| 860 | else if(!strcmp(cmd_type,"keystore-path") ) |
| 861 | { |
| 862 | process_command_keystore_path(remainder); |
| 863 | } |
| 864 | else if(!strcmp(cmd_type,"keystore-passphrase") ) |
| 865 | { |
| 866 | process_command_keystore_passphrase(remainder); |
| 867 | } |
| 868 | else if(!strcmp(cmd_type,"root-key-prefix") ) |
| 869 | { |
| 870 | process_command_root_key_prefix(remainder); |
| 871 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 872 | else |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 873 | { |
| 874 | printf("Wrong configuration Command %s \n",cmd_type); |
| 875 | } |
| 876 | } |
| 877 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 878 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 879 | int |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 880 | readConfigFile(const char *filename) |
| 881 | { |
| 882 | FILE *cfg; |
| 883 | char buf[1024]; |
| 884 | int len; |
| 885 | |
| 886 | cfg=fopen(filename, "r"); |
| 887 | |
| 888 | if(cfg == NULL) |
| 889 | { |
| 890 | printf("\nConfiguration File does not exists\n"); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 891 | return -1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | while(fgets((char *)buf, sizeof(buf), cfg)) |
| 895 | { |
| 896 | len=strlen(buf); |
| 897 | if(buf[len-1] == '\n') |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 898 | buf[len-1]='\0'; |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 899 | if ( buf[0] != '#' && buf[0] != '!') |
| 900 | process_conf_command(buf); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | fclose(cfg); |
| 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 908 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 909 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 910 | add_faces_for_nbrs(void) |
| 911 | { |
| 912 | int i, adl_element; |
| 913 | struct ndn_neighbor *nbr; |
| 914 | |
| 915 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 916 | struct hashtb_enumerator *e = ⅇ |
| 917 | |
| 918 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 919 | adl_element=hashtb_n(nlsr->adl); |
| 920 | |
| 921 | for(i=0;i<adl_element;i++) |
| 922 | { |
| 923 | nbr=e->data; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 924 | 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] | 925 | (const char *)nbr->ip_address, 9695,nlsr->tunnel_type); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 926 | update_face_to_adl_for_nbr(nbr->neighbor->name, face_id); |
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->topo_prefix, OP_REG, face_id,(~0U) >> 1); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 929 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 930 | (const char *)nlsr->slice_prefix, OP_REG, face_id,(~0U) >> 1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 931 | hashtb_next(e); |
| 932 | } |
| 933 | |
| 934 | hashtb_end(e); |
| 935 | |
| 936 | } |
| 937 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 938 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 939 | destroy_faces_for_nbrs(void) |
| 940 | { |
| 941 | int i, adl_element; |
| 942 | struct ndn_neighbor *nbr; |
| 943 | |
| 944 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 945 | struct hashtb_enumerator *e = ⅇ |
| 946 | |
| 947 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 948 | adl_element=hashtb_n(nlsr->adl); |
| 949 | |
| 950 | for(i=0;i<adl_element;i++) |
| 951 | { |
| 952 | nbr=e->data; |
| 953 | if ( nbr->face > 0 ) |
| 954 | { |
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 *)nlsr->topo_prefix, 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 *)nbr->neighbor->name,OP_UNREG,nbr->face,(~0U) >> 1); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 959 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
akmhoque | 483c1eb | 2013-03-08 00:51:09 -0600 | [diff] [blame] | 960 | (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face,(~0U) >> 1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 961 | } |
| 962 | hashtb_next(e); |
| 963 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 964 | hashtb_end(e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 965 | } |
| 966 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 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 | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1202 | destroy_adl(); |
akmhoque | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1203 | destroy_npl(); |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 1204 | destroy_lsdb(); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1205 | destroy_npt(); |
| 1206 | destroy_routing_table(); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1207 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1208 | if ( nlsr->ccns != NULL ) |
| 1209 | ccns_close(&nlsr->ccns, NULL, NULL); |
| 1210 | if ( nlsr->slice != NULL ) |
| 1211 | ccns_slice_destroy(&nlsr->slice); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1212 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1213 | close(nlsr->nlsr_api_server_sock_fd); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1214 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1215 | ccn_destroy(&nlsr->ccn); |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1216 | |
| 1217 | free(nlsr->root_key_prefix); |
| 1218 | free(nlsr->keystore_path); |
| 1219 | free(nlsr->keystore_passphrase); |
| 1220 | if( nlsr->site_name ) |
| 1221 | free(nlsr->site_name); |
| 1222 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1223 | free(nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1224 | if ( nlsr->debugging ) |
| 1225 | { |
| 1226 | printf("Finished freeing allocated memory\n"); |
| 1227 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1228 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1229 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1230 | free(nlsr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1231 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 1232 | } |
| 1233 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1234 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1235 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1236 | void |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1237 | init_api_server(int ccn_fd) |
| 1238 | { |
| 1239 | int server_sockfd; |
| 1240 | int server_len; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1241 | struct sockaddr_in server_address; |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1242 | unsigned int yes=1; |
| 1243 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1244 | server_sockfd = socket(AF_INET, SOCK_STREAM, 0); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1245 | |
| 1246 | int flags = fcntl(server_sockfd, F_GETFL, 0); |
| 1247 | fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags); |
| 1248 | |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1249 | if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) |
| 1250 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1251 | ON_ERROR_DESTROY(-1); |
| 1252 | } |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1253 | |
| 1254 | server_address.sin_family = AF_INET; |
Adam Alyyan | b5fff37 | 2013-01-09 14:32:52 -0600 | [diff] [blame] | 1255 | server_address.sin_addr.s_addr = INADDR_ANY; |
| 1256 | server_address.sin_port = htons(nlsr->api_port); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1257 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1258 | server_len = sizeof(server_address); |
| 1259 | bind(server_sockfd, (struct sockaddr *)&server_address, server_len); |
| 1260 | listen(server_sockfd, 100); |
| 1261 | FD_ZERO(&nlsr->readfds); |
| 1262 | FD_SET(server_sockfd, &nlsr->readfds); |
| 1263 | FD_SET(ccn_fd, &nlsr->readfds); |
| 1264 | nlsr->nlsr_api_server_sock_fd=server_sockfd; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1265 | } |
| 1266 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1267 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1268 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1269 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1270 | if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1271 | { |
| 1272 | perror("SIGQUIT install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1273 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1274 | } |
| 1275 | if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1276 | { |
| 1277 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1278 | return -1; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1279 | } |
| 1280 | if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1281 | { |
| 1282 | perror("SIGTERM 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 | } |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1285 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1286 | nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr)); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1287 | |
| 1288 | nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), NULL); |
| 1289 | nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1290 | nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL); |
| 1291 | nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1292 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1293 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase)); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1294 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL); |
| 1295 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL); |
| 1296 | nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 1297 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1298 | |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1299 | |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1300 | nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2(); |
| 1301 | |
| 1302 | nlsr->in_interest.p = &incoming_interest; |
| 1303 | nlsr->in_content.p = &incoming_content; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1304 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1305 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 1306 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1307 | nlsr->adj_build_flag=0; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1308 | nlsr->adj_build_count=0; |
| 1309 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1310 | nlsr->is_send_lsdb_interest_scheduled=0; |
| 1311 | nlsr->is_route_calculation_scheduled=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1312 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1313 | nlsr->detailed_logging=0; |
| 1314 | nlsr->debugging=0; |
| 1315 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1316 | nlsr->interest_retry = INTEREST_RETRY; |
| 1317 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1318 | nlsr->lsa_refresh_time=LSA_REFRESH_TIME; |
| 1319 | nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1320 | nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1321 | nlsr->semaphor=NLSR_UNLOCKED; |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1322 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1323 | nlsr->api_port=API_PORT; |
| 1324 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1325 | nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1326 | memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr")); |
| 1327 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1328 | nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1329 | memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA")); |
| 1330 | |
| 1331 | nlsr->is_hyperbolic_calc=0; |
| 1332 | nlsr->cor_r=-1.0; |
| 1333 | nlsr->cor_theta=-1.0; |
| 1334 | |
| 1335 | nlsr->tunnel_type=IPPROTO_UDP; |
| 1336 | |
akmhoque | 7adb277 | 2013-03-05 16:30:59 -0600 | [diff] [blame] | 1337 | nlsr->root_key_prefix=(char *)calloc(strlen("/ndn/keys")+1,sizeof(char)); |
| 1338 | memcpy(nlsr->root_key_prefix,"/ndn/keys",strlen("/ndn/keys")); |
| 1339 | nlsr->keystore_path=get_current_user_default_keystore(); |
| 1340 | nlsr->keystore_passphrase=(char *)calloc(strlen("Th1s1sn0t8g00dp8ssw0rd.")+1 |
| 1341 | ,sizeof(char)); |
| 1342 | memcpy(nlsr->keystore_passphrase,"Th1s1sn0t8g00dp8ssw0rd.", |
| 1343 | strlen("Th1s1sn0t8g00dp8ssw0rd.")); |
| 1344 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1345 | return 0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1346 | } |
| 1347 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1348 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1349 | main(int argc, char *argv[]) |
| 1350 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1351 | int res, ret; |
| 1352 | char *config_file; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1353 | int daemon_mode=0; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1354 | int port=0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1355 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1356 | while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1357 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1358 | switch (res) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1359 | { |
| 1360 | case 'd': |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1361 | daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1362 | break; |
| 1363 | case 'f': |
| 1364 | config_file = optarg; |
| 1365 | break; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1366 | case 'p': |
| 1367 | port = atoi(optarg); |
| 1368 | break; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1369 | case 'h': |
| 1370 | default: |
| 1371 | usage(argv[0]); |
| 1372 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1373 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1374 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1375 | ret = init_nlsr(); |
| 1376 | ON_ERROR_EXIT(ret); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1377 | |
| 1378 | if ( port !=0 ) |
| 1379 | nlsr->api_port=port; |
| 1380 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1381 | ON_ERROR_DESTROY(readConfigFile(config_file)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1382 | |
| 1383 | ON_ERROR_DESTROY(check_config_validity()); |
| 1384 | |
| 1385 | print_adjacent_from_adl(); |
| 1386 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1387 | if ( daemon_mode == 1 ) |
| 1388 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1389 | nlsr->debugging=0; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1390 | daemonize_nlsr(); |
| 1391 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1392 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1393 | startLogging(nlsr->logDir); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1394 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1395 | nlsr->ccn=ccn_create(); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1396 | int ccn_fd=ccn_connect(nlsr->ccn, NULL); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1397 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1398 | if(ccn_fd == -1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1399 | { |
| 1400 | fprintf(stderr,"Could not connect to ccnd\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1401 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1402 | ON_ERROR_DESTROY(-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1403 | } |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1404 | |
| 1405 | init_api_server(ccn_fd); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1406 | |
| 1407 | res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1408 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1409 | if(res<0) |
| 1410 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1411 | fprintf(stderr, "Can not create slice for prefix %s\n", |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1412 | nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1413 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for" |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1414 | "prefix %s\n",nlsr->slice_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1415 | ON_ERROR_DESTROY(res); |
| 1416 | } |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1417 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1418 | struct ccn_charbuf *router_prefix; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1419 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1420 | router_prefix=ccn_charbuf_create(); |
| 1421 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1422 | if(res<0) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1423 | { |
| 1424 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1425 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1426 | "Bad ccn URI: %s\n", nlsr->router_name); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1427 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1428 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1429 | |
| 1430 | ccn_name_append_str(router_prefix,"nlsr"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1431 | nlsr->in_interest.data=nlsr->router_name; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1432 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 1433 | if ( res < 0 ) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1434 | { |
| 1435 | fprintf(stderr,"Failed to register interest for router\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1436 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1437 | "Failed to register interest for router\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1438 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1439 | } |
| 1440 | ccn_charbuf_destroy(&router_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1441 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1442 | if ( nlsr->debugging ) |
| 1443 | printf("Router Name : %s\n",nlsr->router_name); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1444 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1445 | if ( nlsr->debugging ) |
| 1446 | printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1447 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1448 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1449 | add_faces_for_nbrs(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1450 | print_name_prefix_from_npl(); |
| 1451 | print_adjacent_from_adl(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1452 | build_and_install_name_lsas(); |
| 1453 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1454 | print_name_lsdb(); |
| 1455 | if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0) |
| 1456 | { |
| 1457 | build_and_install_cor_lsa(); |
| 1458 | } |
| 1459 | write_name_lsdb_to_repo(nlsr->slice_prefix); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1460 | |
| 1461 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
akmhoque | 184dde0 | 2013-02-14 15:53:24 -0600 | [diff] [blame] | 1462 | ccn_set_schedule(nlsr->ccn,nlsr->sched); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1463 | 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] | 1464 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1465 | |
akmhoque | 0678c5d | 2013-02-18 11:03:31 -0600 | [diff] [blame] | 1466 | res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix); |
| 1467 | ON_ERROR_DESTROY(res); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 1468 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1469 | while(1) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1470 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1471 | if ( nlsr->semaphor == NLSR_UNLOCKED ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1472 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1473 | if( nlsr->sched != NULL ) |
| 1474 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1475 | long int micro_sec=ccn_schedule_run(nlsr->sched); |
| 1476 | res=nlsr_api_server_poll(micro_sec,ccn_fd); |
| 1477 | ON_ERROR_DESTROY(res); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1478 | } |
| 1479 | if(nlsr->ccn != NULL) |
| 1480 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1481 | res = ccn_run(nlsr->ccn, 1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1482 | } |
| 1483 | if (!(nlsr->sched && nlsr->ccn)) |
| 1484 | { |
| 1485 | break; |
| 1486 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1489 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1490 | return 0; |
| 1491 | } |
| 1492 | |