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