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 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 285 | /* |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 286 | void |
| 287 | process_command_lsdb_synch_interval(char *command) |
| 288 | { |
| 289 | if(command==NULL) |
| 290 | { |
| 291 | printf(" Wrong Command Format ( lsdb-synch-interval secs )\n"); |
| 292 | return; |
| 293 | } |
| 294 | char *rem; |
| 295 | const char *sep=" \t\n"; |
| 296 | char *secs; |
| 297 | long int seconds; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 298 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 299 | secs=strtok_r(command,sep,&rem); |
| 300 | if(secs==NULL) |
| 301 | { |
| 302 | printf(" Wrong Command Format ( lsdb-synch-interval secs)\n"); |
| 303 | return; |
| 304 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 305 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 306 | seconds=atoi(secs); |
| 307 | if ( seconds >= 120 && seconds <= 3600 ) |
| 308 | { |
| 309 | nlsr->lsdb_synch_interval=seconds; |
| 310 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 311 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 312 | } |
| 313 | */ |
| 314 | |
| 315 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 316 | process_command_interest_retry(char *command) |
| 317 | { |
| 318 | if(command==NULL) |
| 319 | { |
| 320 | printf(" Wrong Command Format ( interest-retry number )\n"); |
| 321 | return; |
| 322 | } |
| 323 | char *rem; |
| 324 | const char *sep=" \t\n"; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 325 | char *retry; |
| 326 | long int retry_number; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 327 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 328 | retry=strtok_r(command,sep,&rem); |
| 329 | if(retry==NULL) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 330 | { |
| 331 | printf(" Wrong Command Format ( interest-retry number)\n"); |
| 332 | return; |
| 333 | } |
| 334 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 335 | retry_number=atoi(retry); |
| 336 | if ( retry_number >= 1 && retry_number<=10 ) |
| 337 | { |
| 338 | nlsr->interest_retry=retry_number; |
| 339 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 340 | |
| 341 | } |
| 342 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 343 | void |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 344 | process_command_interest_resend_time(char *command) |
| 345 | { |
| 346 | if(command==NULL) |
| 347 | { |
| 348 | printf(" Wrong Command Format ( interest-resend-time secs )\n"); |
| 349 | return; |
| 350 | } |
| 351 | char *rem; |
| 352 | const char *sep=" \t\n"; |
| 353 | char *secs; |
| 354 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 355 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 356 | secs=strtok_r(command,sep,&rem); |
| 357 | if(secs==NULL) |
| 358 | { |
| 359 | printf(" Wrong Command Format ( interest-resend-time secs)\n"); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | seconds=atoi(secs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 364 | if ( seconds <= 60 && seconds >= 1 ) |
| 365 | { |
| 366 | nlsr->interest_resend_time=seconds; |
| 367 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 368 | } |
| 369 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 370 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 371 | void |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 372 | process_command_lsa_refresh_time(char *command) |
| 373 | { |
| 374 | if(command==NULL) |
| 375 | { |
| 376 | printf(" Wrong Command Format ( lsa-refresh-time secs )\n"); |
| 377 | return; |
| 378 | } |
| 379 | char *rem; |
| 380 | const char *sep=" \t\n"; |
| 381 | char *secs; |
| 382 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 383 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 384 | secs=strtok_r(command,sep,&rem); |
| 385 | if(secs==NULL) |
| 386 | { |
| 387 | printf(" Wrong Command Format ( lsa-refresh-time secs)\n"); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | seconds=atoi(secs); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 392 | if ( seconds >= 240) |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 393 | { |
| 394 | nlsr->lsa_refresh_time=seconds; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 395 | if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 ) |
| 396 | { |
| 397 | nlsr->router_dead_interval=2*nlsr->lsa_refresh_time; |
| 398 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | } |
| 402 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 403 | void |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 404 | process_command_router_dead_interval(char *command) |
| 405 | { |
| 406 | if(command==NULL) |
| 407 | { |
| 408 | printf(" Wrong Command Format ( router-dead-interval secs )\n"); |
| 409 | return; |
| 410 | } |
| 411 | char *rem; |
| 412 | const char *sep=" \t\n"; |
| 413 | char *secs; |
| 414 | long int seconds; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 415 | |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 416 | secs=strtok_r(command,sep,&rem); |
| 417 | if(secs==NULL) |
| 418 | { |
| 419 | printf(" Wrong Command Format ( router-dead-interval secs)\n"); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | seconds=atoi(secs); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 424 | if ( seconds >= 480 ) |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 425 | { |
| 426 | nlsr->router_dead_interval=seconds; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 427 | if ( nlsr->router_dead_interval < nlsr->lsa_refresh_time * 2 ) |
| 428 | { |
| 429 | nlsr->router_dead_interval=2*nlsr->lsa_refresh_time; |
| 430 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 434 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 435 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 436 | process_command_max_faces_per_prefix(char *command) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 437 | { |
| 438 | if(command==NULL) |
| 439 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 440 | printf(" Wrong Command Format ( max-faces-per-prefix n )\n"); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 441 | return; |
| 442 | } |
| 443 | char *rem; |
| 444 | const char *sep=" \t\n"; |
| 445 | char *num; |
| 446 | long int number; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 447 | |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 448 | num=strtok_r(command,sep,&rem); |
| 449 | if(num==NULL) |
| 450 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 451 | printf(" Wrong Command Format ( max-faces-per-prefix n)\n"); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | |
| 455 | number=atoi(num); |
| 456 | if ( number >= 0 && number <= 60 ) |
| 457 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 458 | nlsr->max_faces_per_prefix=number; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | } |
| 462 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 463 | void |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 464 | process_command_logdir(char *command) |
| 465 | { |
| 466 | if(command==NULL) |
| 467 | { |
| 468 | printf(" Wrong Command Format ( logdir /path/to/logdir )\n"); |
| 469 | return; |
| 470 | } |
| 471 | char *rem; |
| 472 | const char *sep=" \t\n"; |
| 473 | char *dir; |
| 474 | |
| 475 | dir=strtok_r(command,sep,&rem); |
| 476 | if(dir==NULL) |
| 477 | { |
| 478 | printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n"); |
| 479 | return; |
| 480 | } |
akmhoque | 0b60ba9 | 2013-02-25 17:55:35 -0600 | [diff] [blame] | 481 | //if ( nlsr->logDir) |
| 482 | //free(nlsr->logDir); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 483 | nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 484 | memcpy(nlsr->logDir,dir,strlen(dir)+1); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 485 | } |
| 486 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 487 | void |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 488 | process_command_detailed_log(char *command) |
| 489 | { |
| 490 | if(command==NULL) |
| 491 | { |
| 492 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 493 | return; |
| 494 | } |
| 495 | char *rem; |
| 496 | const char *sep=" \t\n"; |
| 497 | char *on_off; |
| 498 | |
| 499 | on_off=strtok_r(command,sep,&rem); |
| 500 | if(on_off==NULL) |
| 501 | { |
| 502 | printf(" Wrong Command Format ( detailed-log on/off )\n"); |
| 503 | return; |
| 504 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 505 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 506 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0) |
| 507 | { |
| 508 | nlsr->detailed_logging=1; |
| 509 | } |
| 510 | } |
| 511 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 512 | void |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 513 | process_command_debug(char *command) |
| 514 | { |
| 515 | if(command==NULL) |
| 516 | { |
| 517 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 518 | return; |
| 519 | } |
| 520 | char *rem; |
| 521 | const char *sep=" \t\n"; |
| 522 | char *on_off; |
| 523 | |
| 524 | on_off=strtok_r(command,sep,&rem); |
| 525 | if(on_off==NULL) |
| 526 | { |
| 527 | printf(" Wrong Command Format ( debug on/off )\n"); |
| 528 | return; |
| 529 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 530 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 531 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 532 | { |
| 533 | nlsr->debugging=1; |
| 534 | } |
| 535 | } |
| 536 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 537 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 538 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 539 | process_command_topo_prefix(char *command) |
| 540 | { |
| 541 | if(command==NULL) |
| 542 | { |
| 543 | printf(" Wrong Command Format ( topo-prefix )\n"); |
| 544 | return; |
| 545 | } |
| 546 | char *rem; |
| 547 | const char *sep=" \t\n"; |
| 548 | char *topo_prefix; |
| 549 | |
| 550 | topo_prefix=strtok_r(command,sep,&rem); |
| 551 | if(topo_prefix==NULL) |
| 552 | { |
| 553 | printf(" Wrong Command Format ( topo-prefix /name/prefix )\n"); |
| 554 | return; |
| 555 | } |
| 556 | else |
| 557 | { |
| 558 | if( nlsr->topo_prefix != NULL) |
| 559 | free(nlsr->topo_prefix); |
| 560 | if ( topo_prefix[strlen(topo_prefix)-1] == '/' ) |
| 561 | topo_prefix[strlen(topo_prefix)-1]='\0'; |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 562 | //if(nlsr->topo_prefix) |
| 563 | //free(nlsr->topo_prefix); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 564 | nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 565 | memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 566 | printf ("Topo prefix is: %s", nlsr->topo_prefix);; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 571 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 572 | process_command_slice_prefix(char *command) |
| 573 | { |
| 574 | if(command==NULL) |
| 575 | { |
| 576 | printf(" Wrong Command Format ( slice-prefix /name/prefix )\n"); |
| 577 | return; |
| 578 | } |
| 579 | char *rem; |
| 580 | const char *sep=" \t\n"; |
| 581 | char *slice_prefix; |
| 582 | |
| 583 | slice_prefix=strtok_r(command,sep,&rem); |
| 584 | if(slice_prefix==NULL) |
| 585 | { |
| 586 | printf(" Wrong Command Format ( slice-prefix /name/prefix )\n"); |
| 587 | return; |
| 588 | } |
| 589 | else |
| 590 | { |
| 591 | if ( nlsr->slice_prefix != NULL) |
| 592 | free(nlsr->slice_prefix); |
| 593 | if ( slice_prefix[strlen(slice_prefix)-1] == '/' ) |
| 594 | slice_prefix[strlen(slice_prefix)-1]='\0'; |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 595 | //if( nlsr->slice_prefix) |
| 596 | //free(nlsr->slice_prefix); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 597 | nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char)); |
akmhoque | 6682ca3 | 2013-02-22 00:29:35 -0600 | [diff] [blame] | 598 | memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 602 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 603 | process_command_hyperbolic_routing(char *command) |
| 604 | { |
| 605 | if(command==NULL) |
| 606 | { |
| 607 | printf(" Wrong Command Format ( hyperbolic-routing on)\n"); |
| 608 | return; |
| 609 | } |
| 610 | char *rem; |
| 611 | const char *sep=" \t\n"; |
| 612 | char *on_off; |
| 613 | |
| 614 | on_off=strtok_r(command,sep,&rem); |
| 615 | if(on_off==NULL) |
| 616 | { |
| 617 | printf(" Wrong Command Format ( hyperbolic-routing on )\n"); |
| 618 | return; |
| 619 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 620 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 621 | if ( strcmp(on_off,"ON") == 0 || strcmp(on_off,"on") == 0 ) |
| 622 | { |
| 623 | nlsr->is_hyperbolic_calc=1; |
| 624 | } |
| 625 | } |
| 626 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 627 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 628 | process_command_hyperbolic_cordinate(char *command) |
| 629 | { |
| 630 | if(command==NULL) |
| 631 | { |
| 632 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | char *rem; |
| 637 | const char *sep=" \t\n\r"; |
| 638 | char *radious; |
| 639 | char *theta; |
| 640 | |
| 641 | radious=strtok_r(command,sep,&rem); |
| 642 | if (radious == NULL ) |
| 643 | { |
| 644 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | theta=strtok_r(NULL,sep,&rem); |
| 649 | if (theta == NULL ) |
| 650 | { |
| 651 | printf(" Wrong Command Format ( hyperbolic r 0 )\n"); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | nlsr->cor_r=strtof(radious,NULL); |
| 656 | nlsr->cor_theta=strtof(theta,NULL); |
| 657 | |
| 658 | } |
| 659 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 660 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 661 | process_command_tunnel_type(char *command) |
| 662 | { |
| 663 | if(command==NULL) |
| 664 | { |
| 665 | printf(" Wrong Command Format ( tunnel-type udp/tcp)\n"); |
| 666 | return; |
| 667 | } |
| 668 | char *rem; |
| 669 | const char *sep=" \t\n"; |
| 670 | char *on_off; |
| 671 | |
| 672 | on_off=strtok_r(command,sep,&rem); |
| 673 | if(on_off==NULL) |
| 674 | { |
| 675 | printf(" Wrong Command Format ( tunnel-type udp/tcp )\n"); |
| 676 | return; |
| 677 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 678 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 679 | if ( strcmp(on_off,"TCP") == 0 || strcmp(on_off,"tcp") == 0 ) |
| 680 | { |
| 681 | nlsr->tunnel_type=IPPROTO_TCP; |
| 682 | } |
| 683 | else if ( strcmp(on_off,"UDP") == 0 || strcmp(on_off,"udp") == 0 ) |
| 684 | { |
| 685 | nlsr->tunnel_type=IPPROTO_UDP; |
| 686 | } |
| 687 | } |
| 688 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 689 | void |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 690 | process_conf_command(char *command) |
| 691 | { |
| 692 | const char *separators=" \t\n"; |
| 693 | char *remainder=NULL; |
| 694 | char *cmd_type=NULL; |
| 695 | |
| 696 | if(command==NULL || strlen(command)==0 || command[0]=='!') |
| 697 | return; |
| 698 | |
| 699 | cmd_type=strtok_r(command,separators,&remainder); |
| 700 | |
| 701 | if(!strcmp(cmd_type,"router-name") ) |
| 702 | { |
| 703 | process_command_router_name(remainder); |
| 704 | } |
| 705 | else if(!strcmp(cmd_type,"ccnneighbor") ) |
| 706 | { |
| 707 | process_command_ccnneighbor(remainder); |
| 708 | } |
| 709 | else if(!strcmp(cmd_type,"ccnname") ) |
| 710 | { |
| 711 | process_command_ccnname(remainder); |
| 712 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 713 | else if(!strcmp(cmd_type,"interest-retry") ) |
| 714 | { |
| 715 | process_command_interest_retry(remainder); |
| 716 | } |
| 717 | else if(!strcmp(cmd_type,"interest-resend-time") ) |
| 718 | { |
| 719 | process_command_interest_resend_time(remainder); |
| 720 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 721 | else if(!strcmp(cmd_type,"lsa-refresh-time") ) |
| 722 | { |
| 723 | process_command_lsa_refresh_time(remainder); |
| 724 | } |
| 725 | else if(!strcmp(cmd_type,"router-dead-interval") ) |
| 726 | { |
| 727 | process_command_router_dead_interval(remainder); |
| 728 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 729 | else if(!strcmp(cmd_type,"max-faces-per-prefix") ) |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 730 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 731 | process_command_max_faces_per_prefix(remainder); |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 732 | } |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 733 | else if(!strcmp(cmd_type,"logdir") ) |
| 734 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 735 | process_command_logdir(remainder); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 736 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 737 | else if(!strcmp(cmd_type,"detailed-log") ) |
| 738 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 739 | process_command_detailed_log(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 740 | } |
| 741 | else if(!strcmp(cmd_type,"debug") ) |
| 742 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 743 | process_command_debug(remainder); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 744 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 745 | else if(!strcmp(cmd_type,"topo-prefix") ) |
| 746 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 747 | process_command_topo_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 748 | } |
| 749 | else if(!strcmp(cmd_type,"slice-prefix") ) |
| 750 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 751 | process_command_slice_prefix(remainder); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 752 | } |
| 753 | else if(!strcmp(cmd_type,"hyperbolic-cordinate") ) |
| 754 | { |
| 755 | process_command_hyperbolic_cordinate(remainder); |
| 756 | } |
| 757 | else if(!strcmp(cmd_type,"hyperbolic-routing") ) |
| 758 | { |
| 759 | process_command_hyperbolic_routing(remainder); |
| 760 | } |
| 761 | else if(!strcmp(cmd_type,"tunnel-type") ) |
| 762 | { |
| 763 | process_command_tunnel_type(remainder); |
| 764 | } |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 765 | else |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 766 | { |
| 767 | printf("Wrong configuration Command %s \n",cmd_type); |
| 768 | } |
| 769 | } |
| 770 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 771 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 772 | int |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 773 | readConfigFile(const char *filename) |
| 774 | { |
| 775 | FILE *cfg; |
| 776 | char buf[1024]; |
| 777 | int len; |
| 778 | |
| 779 | cfg=fopen(filename, "r"); |
| 780 | |
| 781 | if(cfg == NULL) |
| 782 | { |
| 783 | printf("\nConfiguration File does not exists\n"); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 784 | return -1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | while(fgets((char *)buf, sizeof(buf), cfg)) |
| 788 | { |
| 789 | len=strlen(buf); |
| 790 | if(buf[len-1] == '\n') |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 791 | buf[len-1]='\0'; |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 792 | if ( buf[0] != '#' && buf[0] != '!') |
| 793 | process_conf_command(buf); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | fclose(cfg); |
| 797 | |
| 798 | return 0; |
| 799 | } |
| 800 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 801 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 802 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 803 | add_faces_for_nbrs(void) |
| 804 | { |
| 805 | int i, adl_element; |
| 806 | struct ndn_neighbor *nbr; |
| 807 | |
| 808 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 809 | struct hashtb_enumerator *e = ⅇ |
| 810 | |
| 811 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 812 | adl_element=hashtb_n(nlsr->adl); |
| 813 | |
| 814 | for(i=0;i<adl_element;i++) |
| 815 | { |
| 816 | nbr=e->data; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 817 | 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] | 818 | (const char *)nbr->ip_address, 9695,nlsr->tunnel_type); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 819 | update_face_to_adl_for_nbr(nbr->neighbor->name, face_id); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 820 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
| 821 | (const char *)nlsr->topo_prefix, OP_REG, face_id); |
| 822 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
| 823 | (const char *)nlsr->slice_prefix, OP_REG, face_id); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 824 | hashtb_next(e); |
| 825 | } |
| 826 | |
| 827 | hashtb_end(e); |
| 828 | |
| 829 | } |
| 830 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 831 | void |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 832 | destroy_faces_for_nbrs(void) |
| 833 | { |
| 834 | int i, adl_element; |
| 835 | struct ndn_neighbor *nbr; |
| 836 | |
| 837 | struct hashtb_enumerator ee; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 838 | struct hashtb_enumerator *e = ⅇ |
| 839 | |
| 840 | hashtb_start(nlsr->adl, e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 841 | adl_element=hashtb_n(nlsr->adl); |
| 842 | |
| 843 | for(i=0;i<adl_element;i++) |
| 844 | { |
| 845 | nbr=e->data; |
| 846 | if ( nbr->face > 0 ) |
| 847 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 848 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
| 849 | (const char *)nlsr->topo_prefix, OP_UNREG, nbr->face); |
| 850 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
| 851 | (const char *)nbr->neighbor->name,OP_UNREG,nbr->face); |
| 852 | add_delete_ccn_face_by_face_id(nlsr->ccn, |
| 853 | (const char *)nlsr->slice_prefix, OP_UNREG, nbr->face); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 854 | } |
| 855 | hashtb_next(e); |
| 856 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 857 | hashtb_end(e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 858 | } |
| 859 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 860 | char * |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 861 | process_api_client_command(char *command) |
| 862 | { |
| 863 | char *msg; |
| 864 | msg=(char *)malloc(100); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 865 | memset(msg,0,100); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 866 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 867 | const char *sep=" \t\n"; |
| 868 | char *rem=NULL; |
| 869 | char *cmd_type=NULL; |
| 870 | char *op_type=NULL; |
| 871 | char *name=NULL; |
| 872 | char *face=NULL; |
| 873 | int face_id; |
| 874 | int res; |
| 875 | |
| 876 | op_type=strtok_r(command,sep,&rem); |
| 877 | cmd_type=strtok_r(NULL,sep,&rem); |
| 878 | name=strtok_r(NULL,sep,&rem); |
| 879 | if ( name[strlen(name)-1] == '/' ) |
| 880 | name[strlen(name)-1]='\0'; |
| 881 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 882 | struct name_prefix *np=(struct name_prefix *) calloc (1, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 883 | sizeof(struct name_prefix )); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 884 | np->name = (char *) calloc (strlen(name)+1,sizeof(char)); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 885 | memcpy(np->name,name,strlen(name)+1); |
| 886 | np->length=strlen(name)+1; |
| 887 | |
| 888 | if ( strcmp(cmd_type,"name")!= 0 ) |
| 889 | { |
| 890 | face=strtok_r(NULL,sep,&rem); |
| 891 | sscanf(face,"face%d",&face_id); |
| 892 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 893 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 894 | if ( strcmp(cmd_type,"name")== 0 ) |
| 895 | { |
| 896 | if ( strcmp(op_type,"del") == 0 ) |
| 897 | { |
| 898 | res=does_name_exist_in_npl(np); |
| 899 | if ( res == 0) |
| 900 | { |
| 901 | sprintf(msg,"Name %s does not exist !!",name); |
| 902 | } |
| 903 | else |
| 904 | { |
| 905 | long int ls_id=get_lsa_id_from_npl(np); |
| 906 | if ( ls_id != 0 ) |
| 907 | { |
| 908 | make_name_lsa_invalid(np,LS_TYPE_NAME,ls_id); |
| 909 | sprintf(msg,"Name %s has been deleted and Advertised.",name); |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | sprintf(msg,"Name %s does not have an Name LSA yet !!",name); |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | else if ( strcmp(op_type,"add") == 0 ) |
| 918 | { |
| 919 | res=does_name_exist_in_npl(np); |
| 920 | if ( res == 0) |
| 921 | { |
| 922 | add_name_to_npl(np); |
| 923 | build_and_install_single_name_lsa(np); |
| 924 | sprintf(msg,"Name %s has been added to advertise.",name); |
| 925 | } |
| 926 | else |
| 927 | { |
| 928 | sprintf(msg,"Name %s has already been advertised from this router !!",name); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | else if ( strcmp(cmd_type,"neighbor") == 0 ) |
| 933 | { |
| 934 | if ( strcmp(op_type,"del") == 0 ) |
| 935 | { |
| 936 | res=is_neighbor(np->name); |
| 937 | if ( res == 0) |
| 938 | { |
| 939 | sprintf(msg,"Neighbor %s does not exist !!",name); |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | update_adjacent_status_to_adl(np,NBR_DOWN); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 944 | int face_id=get_next_hop_face_from_adl(np->name); |
| 945 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)np->name, OP_UNREG, face_id); |
| 946 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_UNREG, face_id); |
| 947 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_UNREG, face_id); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 948 | delete_nbr_from_adl(np); |
| 949 | if(!nlsr->is_build_adj_lsa_sheduled) |
| 950 | { |
| 951 | nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1000, &build_and_install_adj_lsa, NULL, 0); |
| 952 | nlsr->is_build_adj_lsa_sheduled=1; |
| 953 | } |
| 954 | sprintf(msg,"Neighbor %s has been deleted from adjacency list.",name); |
| 955 | } |
| 956 | } |
| 957 | else if ( strcmp(op_type,"add") == 0 ) |
| 958 | { |
| 959 | res=is_neighbor(np->name); |
| 960 | if ( res == 0 ) |
| 961 | { |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 962 | 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] | 963 | get_host_name_from_command_string(nbr_name,np->name,0); |
| 964 | printf("Hostname of neighbor: %s ",nbr_name->name); |
| 965 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 966 | char *ip_addr=(char *)calloc(20,sizeof(char)); |
| 967 | //memset(ip_addr,0,20); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 968 | get_ip_from_hostname_02(nbr_name->name,ip_addr); |
| 969 | printf("IP Address: %s \n",ip_addr); |
| 970 | int face_id=add_ccn_face(nlsr->ccn, (const char *)nbr_name->name, (const char *)ip_addr, 9695,nlsr->tunnel_type); |
| 971 | update_face_to_adl_for_nbr(nbr_name->name, face_id); |
| 972 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->topo_prefix, OP_REG, face_id); |
| 973 | add_delete_ccn_face_by_face_id(nlsr->ccn, (const char *)nlsr->slice_prefix, OP_REG, face_id); |
| 974 | |
| 975 | add_nbr_to_adl(np,face_id,ip_addr); |
| 976 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 977 | sprintf(msg,"Neighbor %s has been added to adjacency list.",name); |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 978 | free(ip_addr); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 979 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 980 | } |
| 981 | else |
| 982 | { |
| 983 | sprintf(msg,"Neighbor %s already exists in adjacency list.",name); |
| 984 | } |
| 985 | } |
| 986 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 987 | |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 988 | |
| 989 | return msg; |
| 990 | } |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 991 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 992 | int |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 993 | nlsr_api_server_poll(long int time_out_micro_sec, int ccn_fd) |
| 994 | { |
| 995 | struct timeval timeout; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 996 | if (time_out_micro_sec< 500000 && time_out_micro_sec> 0 ) |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 997 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 998 | timeout.tv_sec=0; |
| 999 | timeout.tv_usec=time_out_micro_sec; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1000 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1001 | else |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1002 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1003 | timeout.tv_sec = 0; |
| 1004 | timeout.tv_usec = 500000; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1005 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1006 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1007 | int fd; |
| 1008 | int nread; |
| 1009 | int result; |
| 1010 | fd_set testfds; |
| 1011 | unsigned int client_len; |
| 1012 | int client_sockfd; |
| 1013 | char recv_buffer[1024]; |
| 1014 | bzero(recv_buffer,1024); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1015 | struct sockaddr_in client_address; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1016 | |
| 1017 | testfds=nlsr->readfds; |
| 1018 | result = select(FD_SETSIZE, &testfds, NULL,NULL, &timeout); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1019 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1020 | for(fd = 0; fd < FD_SETSIZE && result > 0; fd++) |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1021 | { |
| 1022 | if(FD_ISSET(fd,&testfds)) |
| 1023 | { |
| 1024 | if ( fd == ccn_fd ) |
| 1025 | { |
| 1026 | return 0; |
| 1027 | } |
| 1028 | else if(fd == nlsr->nlsr_api_server_sock_fd) |
| 1029 | { |
| 1030 | client_len = sizeof(client_address); |
| 1031 | client_sockfd = accept(nlsr->nlsr_api_server_sock_fd,(struct sockaddr *)&client_address, &client_len); |
| 1032 | FD_SET(client_sockfd, &nlsr->readfds); |
| 1033 | } |
| 1034 | else |
| 1035 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1036 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1037 | ioctl(fd, FIONREAD, &nread); |
| 1038 | if(nread == 0) |
| 1039 | { |
| 1040 | close(fd); |
| 1041 | FD_CLR(fd, &nlsr->readfds); |
| 1042 | } |
| 1043 | else |
| 1044 | { |
| 1045 | recv(fd, recv_buffer, 1024, 0); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1046 | printf("Received Data from NLSR API cleint: %s \n",recv_buffer); |
akmhoque | 562caef | 2012-11-09 13:29:06 -0600 | [diff] [blame] | 1047 | char *msg=process_api_client_command(recv_buffer); |
| 1048 | send(fd, msg, strlen(msg),0); |
| 1049 | free(msg); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1050 | close(fd); |
| 1051 | FD_CLR(fd, &nlsr->readfds); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1060 | int |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1061 | check_config_validity() |
| 1062 | { |
| 1063 | if (nlsr->router_name == NULL ) |
| 1064 | { |
| 1065 | fprintf(stderr,"Router name has not been configured :(\n"); |
| 1066 | return -1; |
| 1067 | } |
| 1068 | if ( nlsr->is_hyperbolic_calc == 1 && (nlsr->cor_r == -1.0 && nlsr->cor_theta== -1.0) ) |
| 1069 | { |
| 1070 | fprintf(stderr,"Hyperbolic codinate has not been defined :(\n"); |
| 1071 | return -1; |
| 1072 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1073 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1074 | return 0; |
| 1075 | } |
| 1076 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1077 | void |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 1078 | nlsr_destroy( void ) |
| 1079 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1080 | if ( nlsr->debugging ) |
| 1081 | { |
| 1082 | printf("Freeing Allocated Memory....\n"); |
| 1083 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1084 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Freeing Allocated Memory....\n"); |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 1085 | |
akmhoque | fbfd098 | 2012-09-09 20:59:03 -0500 | [diff] [blame] | 1086 | /* Destroying all face created by nlsr in CCND */ |
| 1087 | destroy_all_face_by_nlsr(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1088 | destroy_faces_for_nbrs(); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1089 | |
akmhoque | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1090 | destroy_adl(); |
akmhoque | e6f98a1 | 2013-02-22 10:33:26 -0600 | [diff] [blame] | 1091 | destroy_npl(); |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 1092 | destroy_lsdb(); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1093 | destroy_npt(); |
| 1094 | destroy_routing_table(); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1095 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1096 | if ( nlsr->ccns != NULL ) |
| 1097 | ccns_close(&nlsr->ccns, NULL, NULL); |
| 1098 | if ( nlsr->slice != NULL ) |
| 1099 | ccns_slice_destroy(&nlsr->slice); |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 1100 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1101 | close(nlsr->nlsr_api_server_sock_fd); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1102 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1103 | ccn_destroy(&nlsr->ccn); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1104 | free(nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1105 | if ( nlsr->debugging ) |
| 1106 | { |
| 1107 | printf("Finished freeing allocated memory\n"); |
| 1108 | } |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1109 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Finished freeing allocated memory\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1110 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1111 | free(nlsr); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1112 | |
akmhoque | 386081b | 2012-08-10 10:53:21 -0500 | [diff] [blame] | 1113 | } |
| 1114 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1115 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1116 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1117 | void |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1118 | init_api_server(int ccn_fd) |
| 1119 | { |
| 1120 | int server_sockfd; |
| 1121 | int server_len; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1122 | struct sockaddr_in server_address; |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1123 | unsigned int yes=1; |
| 1124 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1125 | server_sockfd = socket(AF_INET, SOCK_STREAM, 0); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1126 | |
| 1127 | int flags = fcntl(server_sockfd, F_GETFL, 0); |
| 1128 | fcntl(server_sockfd, F_SETFL, O_NONBLOCK|flags); |
| 1129 | |
akmhoque | f31f13b | 2012-11-16 09:42:24 -0600 | [diff] [blame] | 1130 | if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) |
| 1131 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1132 | ON_ERROR_DESTROY(-1); |
| 1133 | } |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1134 | |
| 1135 | server_address.sin_family = AF_INET; |
Adam Alyyan | b5fff37 | 2013-01-09 14:32:52 -0600 | [diff] [blame] | 1136 | server_address.sin_addr.s_addr = INADDR_ANY; |
| 1137 | server_address.sin_port = htons(nlsr->api_port); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1138 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1139 | server_len = sizeof(server_address); |
| 1140 | bind(server_sockfd, (struct sockaddr *)&server_address, server_len); |
| 1141 | listen(server_sockfd, 100); |
| 1142 | FD_ZERO(&nlsr->readfds); |
| 1143 | FD_SET(server_sockfd, &nlsr->readfds); |
| 1144 | FD_SET(ccn_fd, &nlsr->readfds); |
| 1145 | nlsr->nlsr_api_server_sock_fd=server_sockfd; |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1146 | } |
| 1147 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1148 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1149 | init_nlsr(void) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1150 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1151 | if (signal(SIGQUIT, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1152 | { |
| 1153 | perror("SIGQUIT install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1154 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1155 | } |
| 1156 | if (signal(SIGTERM, nlsr_stop_signal_handler ) == SIG_ERR) |
| 1157 | { |
| 1158 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1159 | return -1; |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1160 | } |
| 1161 | if (signal(SIGINT, nlsr_stop_signal_handler ) == SIG_ERR) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1162 | { |
| 1163 | perror("SIGTERM install error\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1164 | return -1; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1165 | } |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1166 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1167 | nlsr=(struct nlsr *)calloc(1,sizeof(struct nlsr)); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1168 | |
| 1169 | nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), NULL); |
| 1170 | nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1171 | nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL); |
| 1172 | nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL); |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1173 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1174 | nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase)); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1175 | nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL); |
| 1176 | nlsr->lsdb->name_lsdb = hashtb_create(sizeof(struct nlsa), NULL); |
| 1177 | nlsr->lsdb->cor_lsdb = hashtb_create(sizeof(struct clsa), NULL); |
akmhoque | 07dd8cc | 2012-08-16 10:23:01 -0500 | [diff] [blame] | 1178 | |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1179 | /* |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1180 | char *time_stamp=(char *) calloc (20,sizeof(char)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1181 | get_current_timestamp_micro(time_stamp); |
| 1182 | nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1183 | memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1184 | free(time_stamp); |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1185 | */ |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1186 | |
akmhoque | 54a14f4 | 2013-02-24 06:16:20 -0600 | [diff] [blame] | 1187 | nlsr->lsdb->lsdb_version=get_current_timestamp_micro_v2(); |
| 1188 | |
| 1189 | nlsr->in_interest.p = &incoming_interest; |
| 1190 | nlsr->in_content.p = &incoming_content; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1191 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1192 | nlsr->is_synch_init=1; |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 1193 | nlsr->nlsa_id=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1194 | nlsr->adj_build_flag=0; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1195 | nlsr->adj_build_count=0; |
| 1196 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1197 | nlsr->is_send_lsdb_interest_scheduled=0; |
| 1198 | nlsr->is_route_calculation_scheduled=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1199 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1200 | nlsr->detailed_logging=0; |
| 1201 | nlsr->debugging=0; |
| 1202 | |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1203 | nlsr->interest_retry = INTEREST_RETRY; |
| 1204 | nlsr->interest_resend_time = INTEREST_RESEND_TIME; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1205 | nlsr->lsa_refresh_time=LSA_REFRESH_TIME; |
| 1206 | nlsr->router_dead_interval=ROUTER_DEAD_INTERVAL; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1207 | nlsr->max_faces_per_prefix=MAX_FACES_PER_PREFIX; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1208 | nlsr->semaphor=NLSR_UNLOCKED; |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1209 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1210 | nlsr->api_port=API_PORT; |
| 1211 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1212 | nlsr->topo_prefix=(char *)calloc(strlen("/ndn/routing/nlsr")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1213 | memcpy(nlsr->topo_prefix,"/ndn/routing/nlsr",strlen("/ndn/routing/nlsr")); |
| 1214 | |
akmhoque | 7c234e0 | 2013-02-13 11:23:56 -0600 | [diff] [blame] | 1215 | nlsr->slice_prefix=(char *)calloc(strlen("/ndn/routing/nlsr/LSA")+1,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1216 | memcpy(nlsr->slice_prefix,"/ndn/routing/nlsr/LSA",strlen("/ndn/routing/nlsr/LSA")); |
| 1217 | |
| 1218 | nlsr->is_hyperbolic_calc=0; |
| 1219 | nlsr->cor_r=-1.0; |
| 1220 | nlsr->cor_theta=-1.0; |
| 1221 | |
| 1222 | nlsr->tunnel_type=IPPROTO_UDP; |
| 1223 | |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1224 | return 0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1225 | } |
| 1226 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1227 | int |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1228 | main(int argc, char *argv[]) |
| 1229 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1230 | int res, ret; |
| 1231 | char *config_file; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1232 | int daemon_mode=0; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1233 | int port=0; |
akmhoque | 902d57e | 2012-08-17 09:24:38 -0500 | [diff] [blame] | 1234 | |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1235 | while ((res = getopt_long(argc, argv, "df:p:h", longopts, 0)) != -1) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1236 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1237 | switch (res) |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1238 | { |
| 1239 | case 'd': |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1240 | daemon_mode = 1; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1241 | break; |
| 1242 | case 'f': |
| 1243 | config_file = optarg; |
| 1244 | break; |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1245 | case 'p': |
| 1246 | port = atoi(optarg); |
| 1247 | break; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1248 | case 'h': |
| 1249 | default: |
| 1250 | usage(argv[0]); |
| 1251 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1252 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1253 | |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1254 | ret = init_nlsr(); |
| 1255 | ON_ERROR_EXIT(ret); |
akmhoque | 9504180 | 2012-11-16 09:18:02 -0600 | [diff] [blame] | 1256 | |
| 1257 | if ( port !=0 ) |
| 1258 | nlsr->api_port=port; |
| 1259 | |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1260 | ON_ERROR_DESTROY(readConfigFile(config_file)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1261 | |
| 1262 | ON_ERROR_DESTROY(check_config_validity()); |
| 1263 | |
| 1264 | print_adjacent_from_adl(); |
| 1265 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1266 | if ( daemon_mode == 1 ) |
| 1267 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1268 | nlsr->debugging=0; |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1269 | daemonize_nlsr(); |
| 1270 | } |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1271 | |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1272 | startLogging(nlsr->logDir); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1273 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1274 | nlsr->ccn=ccn_create(); |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1275 | int ccn_fd=ccn_connect(nlsr->ccn, NULL); |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1276 | |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1277 | if(ccn_fd == -1) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1278 | { |
| 1279 | fprintf(stderr,"Could not connect to ccnd\n"); |
akmhoque | bfefef2 | 2012-09-26 10:09:34 -0500 | [diff] [blame] | 1280 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Could not connect to ccnd\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1281 | ON_ERROR_DESTROY(-1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1282 | } |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1283 | |
| 1284 | init_api_server(ccn_fd); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1285 | |
| 1286 | res=create_sync_slice(nlsr->topo_prefix, nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1287 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1288 | if(res<0) |
| 1289 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1290 | fprintf(stderr, "Can not create slice for prefix %s\n", |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1291 | nlsr->slice_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1292 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not create slice for" |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1293 | "prefix %s\n",nlsr->slice_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1294 | ON_ERROR_DESTROY(res); |
| 1295 | } |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1296 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1297 | struct ccn_charbuf *router_prefix; |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1298 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1299 | router_prefix=ccn_charbuf_create(); |
| 1300 | res=ccn_name_from_uri(router_prefix,nlsr->router_name); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1301 | if(res<0) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1302 | { |
| 1303 | fprintf(stderr, "Bad ccn URI: %s\n",nlsr->router_name); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1304 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1305 | "Bad ccn URI: %s\n", nlsr->router_name); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1306 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1307 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1308 | |
| 1309 | ccn_name_append_str(router_prefix,"nlsr"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1310 | nlsr->in_interest.data=nlsr->router_name; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1311 | res=ccn_set_interest_filter(nlsr->ccn,router_prefix,&nlsr->in_interest); |
| 1312 | if ( res < 0 ) |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1313 | { |
| 1314 | fprintf(stderr,"Failed to register interest for router\n"); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1315 | writeLogg(__FILE__,__FUNCTION__,__LINE__, |
Obaid Amin | 0e9a300 | 2013-02-20 14:55:37 -0600 | [diff] [blame] | 1316 | "Failed to register interest for router\n"); |
akmhoque | 81c25e0 | 2012-09-10 14:50:33 -0500 | [diff] [blame] | 1317 | ON_ERROR_DESTROY(res); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1318 | } |
| 1319 | ccn_charbuf_destroy(&router_prefix); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1320 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1321 | if ( nlsr->debugging ) |
| 1322 | printf("Router Name : %s\n",nlsr->router_name); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1323 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Router Name : %s\n",nlsr->router_name); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1324 | if ( nlsr->debugging ) |
| 1325 | printf("lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1326 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"lsdb_version: %s\n",nlsr->lsdb->lsdb_version); |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1327 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1328 | add_faces_for_nbrs(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1329 | print_name_prefix_from_npl(); |
| 1330 | print_adjacent_from_adl(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1331 | build_and_install_name_lsas(); |
| 1332 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1333 | print_name_lsdb(); |
| 1334 | if ( nlsr->cor_r != -1.0 && nlsr->cor_theta != -1.0) |
| 1335 | { |
| 1336 | build_and_install_cor_lsa(); |
| 1337 | } |
| 1338 | write_name_lsdb_to_repo(nlsr->slice_prefix); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1339 | |
| 1340 | nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker); |
akmhoque | 184dde0 | 2013-02-14 15:53:24 -0600 | [diff] [blame] | 1341 | ccn_set_schedule(nlsr->ccn,nlsr->sched); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1342 | 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] | 1343 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1344 | |
akmhoque | 0678c5d | 2013-02-18 11:03:31 -0600 | [diff] [blame] | 1345 | res=sync_monitor(nlsr->topo_prefix,nlsr->slice_prefix); |
| 1346 | ON_ERROR_DESTROY(res); |
akmhoque | 1c9b92f | 2012-08-13 10:57:50 -0500 | [diff] [blame] | 1347 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1348 | while(1) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1349 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1350 | if ( nlsr->semaphor == NLSR_UNLOCKED ) |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1351 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1352 | if( nlsr->sched != NULL ) |
| 1353 | { |
akmhoque | 1771c41 | 2012-11-09 13:06:08 -0600 | [diff] [blame] | 1354 | long int micro_sec=ccn_schedule_run(nlsr->sched); |
| 1355 | res=nlsr_api_server_poll(micro_sec,ccn_fd); |
| 1356 | ON_ERROR_DESTROY(res); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1357 | } |
| 1358 | if(nlsr->ccn != NULL) |
| 1359 | { |
Obaid Amin | 2a928a5 | 2013-02-20 11:06:51 -0600 | [diff] [blame] | 1360 | res = ccn_run(nlsr->ccn, 1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1361 | } |
| 1362 | if (!(nlsr->sched && nlsr->ccn)) |
| 1363 | { |
| 1364 | break; |
| 1365 | } |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 1366 | } |
| 1367 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1368 | } |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1369 | return 0; |
| 1370 | } |
| 1371 | |