akmhoque | f1161eb | 2012-08-21 09:37:21 -0400 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <assert.h> |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include <config.h> |
| 10 | #endif |
| 11 | |
| 12 | |
| 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
| 20 | #include "nlsr.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 21 | #include "nlsr_ndn.h" |
akmhoque | f1161eb | 2012-08-21 09:37:21 -0400 | [diff] [blame] | 22 | #include "nlsr_lsdb.h" |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 23 | #include "utility.h" |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 24 | #include "nlsr_npl.h" |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 25 | #include "nlsr_adl.h" |
akmhoque | 29c1db5 | 2012-09-07 14:47:43 -0500 | [diff] [blame] | 26 | #include "nlsr_route.h" |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 27 | #include "nlsr_npt.h" |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 28 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 29 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 30 | set_new_lsdb_version(void) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 31 | { |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 32 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 33 | char *time_stamp=(char *)malloc(20); |
| 34 | memset(time_stamp,0,20); |
| 35 | get_current_timestamp_micro(time_stamp); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 36 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 37 | free(nlsr->lsdb->lsdb_version); |
| 38 | nlsr->lsdb->lsdb_version=(char *)malloc(strlen(time_stamp)+1); |
| 39 | memset(nlsr->lsdb->lsdb_version,0,strlen(time_stamp)+1); |
| 40 | memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1); |
| 41 | |
| 42 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 43 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 44 | } |
| 45 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 46 | void |
| 47 | make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id) |
| 48 | { |
| 49 | |
| 50 | |
| 51 | printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id); |
| 52 | |
| 53 | char lst[2]; |
| 54 | memset(lst,0,2); |
| 55 | sprintf(lst,"%d",ls_type); |
| 56 | |
| 57 | char lsid[10]; |
| 58 | memset(lsid,0,10); |
| 59 | sprintf(lsid,"%ld",ls_id); |
| 60 | |
| 61 | memcpy(key+strlen(key),orig_router,strlen(orig_router)); |
| 62 | memcpy(key+strlen(key),"/",1); |
| 63 | memcpy(key+strlen(key),lst,strlen(lst)); |
| 64 | memcpy(key+strlen(key),"/",1); |
| 65 | memcpy(key+strlen(key),lsid,strlen(lsid)); |
| 66 | |
| 67 | printf("Key: %s\n",key); |
| 68 | |
| 69 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 70 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 71 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 72 | build_and_install_name_lsas(void) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 73 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 74 | printf("build_and_install_name_lsas called \n"); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 75 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 76 | int i, npl_element; |
| 77 | struct name_prefix *np; |
| 78 | |
| 79 | struct hashtb_enumerator ee; |
| 80 | struct hashtb_enumerator *e = ⅇ |
| 81 | |
| 82 | hashtb_start(nlsr->npl, e); |
| 83 | npl_element=hashtb_n(nlsr->npl); |
| 84 | |
| 85 | for(i=0;i<npl_element;i++) |
| 86 | { |
| 87 | np=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 88 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 89 | build_name_lsa(name_lsa,np); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 90 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 91 | install_name_lsa(name_lsa); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 92 | free(name_lsa->header->orig_router->name); |
| 93 | free(name_lsa->header->orig_router); |
| 94 | free(name_lsa->header); |
| 95 | free(name_lsa->name_prefix->name); |
| 96 | free(name_lsa->name_prefix); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 97 | free(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 98 | hashtb_next(e); |
| 99 | } |
| 100 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 101 | hashtb_end(e); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 102 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 103 | } |
| 104 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 105 | void |
| 106 | build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np) |
| 107 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 108 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 109 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 110 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 111 | char *time_stamp=(char *)malloc(20); |
| 112 | memset(time_stamp,0,20); |
| 113 | get_current_timestamp_micro(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 114 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 115 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 116 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 117 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 118 | |
| 119 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 120 | |
| 121 | name_lsa->header->ls_id=++nlsr->nlsa_id; |
| 122 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 123 | name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 124 | memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 125 | memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 126 | name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 127 | name_lsa->header->isValid=1; |
| 128 | |
| 129 | |
| 130 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 131 | name_lsa->name_prefix->name=(char *)malloc(np->length); |
| 132 | memcpy(name_lsa->name_prefix->name,np->name,np->length); |
| 133 | name_lsa->name_prefix->length=np->length; |
| 134 | |
| 135 | } |
| 136 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 137 | void |
| 138 | install_name_lsa(struct nlsa *name_lsa) |
| 139 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 140 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 141 | char *time_stamp=(char *)malloc(20); |
| 142 | memset(time_stamp,0,20); |
| 143 | get_current_timestamp_micro(time_stamp); |
| 144 | long int lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
| 145 | |
| 146 | printf("time difference: %ld \n",lsa_life_time); |
| 147 | |
| 148 | |
| 149 | char lst[2]; |
| 150 | memset(lst,0,2); |
| 151 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 152 | |
| 153 | char lsid[10]; |
| 154 | memset(lsid,0,10); |
| 155 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 156 | |
| 157 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 158 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 159 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 160 | |
| 161 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 162 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 163 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 164 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 165 | struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 166 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 167 | struct hashtb_enumerator ee; |
| 168 | struct hashtb_enumerator *e = ⅇ |
| 169 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 170 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 171 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 172 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 173 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 174 | if(res == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 175 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 176 | |
| 177 | printf("New Name LSA... Adding to LSDB\n"); |
| 178 | new_name_lsa = e->data; |
| 179 | |
| 180 | new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free |
| 181 | new_name_lsa->header->ls_type=name_lsa->header->ls_type; |
| 182 | |
| 183 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 184 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 185 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 186 | |
| 187 | new_name_lsa->header->ls_id=name_lsa->header->ls_id; |
| 188 | new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 189 | new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length); |
| 190 | memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length); |
| 191 | new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length; |
| 192 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 193 | |
| 194 | |
| 195 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 196 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 197 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 198 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 199 | |
| 200 | printf("New Name LSA Added....\n"); |
| 201 | |
| 202 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 203 | set_new_lsdb_version(); |
| 204 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 205 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 206 | //struct hashtb *face_list; |
| 207 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
akmhoque | d515212 | 2012-09-19 06:44:23 -0500 | [diff] [blame] | 208 | |
| 209 | //printf("Next hop: %d \n",next_hop); |
| 210 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 211 | if ( num_next_hop < 0 ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 212 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 213 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 214 | if ( check == HT_NEW_ENTRY ) |
| 215 | { |
| 216 | printf("Added in npt \n"); |
| 217 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 218 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 219 | else |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 220 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 221 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 222 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 223 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
| 224 | printf("Printing from install_name_lsa \n"); |
| 225 | int j; |
| 226 | for(j=0;j<num_next_hop;j++) |
| 227 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 228 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 229 | if ( check == HT_NEW_ENTRY ) |
| 230 | { |
| 231 | printf("Added in npt \n"); |
| 232 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 233 | free(faces); |
| 234 | free(route_costs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 235 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 236 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 237 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 238 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 239 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 240 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 241 | |
| 242 | } |
| 243 | else if(res == HT_OLD_ENTRY) |
| 244 | { |
| 245 | new_name_lsa=e->data; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 246 | if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 247 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 248 | printf("Older Adj LSA. Discarded...\n"); |
| 249 | } |
| 250 | else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 ) |
| 251 | { |
| 252 | printf("Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 253 | } |
| 254 | else |
| 255 | { |
| 256 | if ( name_lsa->header->isValid == 0 ) |
| 257 | { |
| 258 | // have to call to delete npt table entry |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame^] | 259 | delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 260 | |
| 261 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0) |
| 262 | { |
| 263 | hashtb_delete(e); |
| 264 | printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 269 | free(new_name_lsa->header->orig_time); |
| 270 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 271 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 272 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 273 | } |
| 274 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 275 | set_new_lsdb_version(); |
| 276 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | int is_npt_update=0; |
| 281 | if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 ) |
| 282 | { |
| 283 | is_npt_update=1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame^] | 284 | delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // copying LSA content with header |
| 288 | |
| 289 | free(new_name_lsa->header->orig_time); |
| 290 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 291 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 292 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 293 | |
| 294 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 295 | |
| 296 | free(new_name_lsa->name_prefix->name); |
| 297 | free(new_name_lsa->name_prefix); |
| 298 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 299 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 300 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 301 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 302 | |
| 303 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 304 | set_new_lsdb_version(); |
| 305 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 306 | |
| 307 | if( is_npt_update == 1 ) |
| 308 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 309 | //struct hashtb *face_list; |
| 310 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
| 311 | if ( num_next_hop < 0 ) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 312 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 313 | |
| 314 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 315 | if ( check == HT_NEW_ENTRY ) |
| 316 | { |
| 317 | printf("Added in npt \n"); |
| 318 | } |
| 319 | } |
| 320 | else |
| 321 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 322 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 323 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 324 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
| 325 | printf("Printing from install_name_lsa \n"); |
| 326 | int j; |
| 327 | for(j=0;j<num_next_hop;j++) |
| 328 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 329 | |
| 330 | int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 331 | if ( check == HT_NEW_ENTRY ) |
| 332 | { |
| 333 | printf("Added in npt \n"); |
| 334 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 335 | free(faces); |
| 336 | free(route_costs); |
| 337 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 338 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 339 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 344 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 345 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 346 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 347 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 348 | free(key); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 352 | void |
| 353 | print_name_lsa(struct nlsa *name_lsa) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 354 | { |
| 355 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 356 | printf("-----------Name LSA Content---------------\n"); |
| 357 | printf(" Origination Router : %s\n",name_lsa->header->orig_router->name); |
| 358 | printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
| 359 | printf(" LS Type : %d\n",name_lsa->header->ls_type); |
| 360 | printf(" LS Id : %ld\n",name_lsa->header->ls_id); |
| 361 | printf(" Origination Time : %s\n",name_lsa->header->orig_time); |
| 362 | printf(" Is Valid : %d\n",name_lsa->header->isValid); |
| 363 | printf(" LSA Data \n"); |
| 364 | printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name); |
| 365 | printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 366 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 367 | printf("\n"); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void |
| 371 | print_name_lsdb(void) |
| 372 | { |
| 373 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 374 | int i, name_lsdb_element; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 375 | struct nlsa *name_lsa; |
| 376 | |
| 377 | struct hashtb_enumerator ee; |
| 378 | struct hashtb_enumerator *e = ⅇ |
| 379 | |
| 380 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 381 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 382 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 383 | for(i=0;i<name_lsdb_element;i++) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 384 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 385 | printf("-----------Name LSA (%d)---------------\n",i+1); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 386 | name_lsa=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 387 | print_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 388 | hashtb_next(e); |
| 389 | } |
| 390 | |
| 391 | hashtb_end(e); |
| 392 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 393 | printf("\n"); |
| 394 | } |
| 395 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 396 | |
| 397 | void |
| 398 | build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 399 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 400 | printf("build_and_install_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 401 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 402 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 403 | build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np); |
| 404 | print_name_lsa(name_lsa); |
| 405 | install_name_lsa(name_lsa); |
| 406 | print_name_lsdb(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 407 | print_npt(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 408 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 409 | free(name_lsa->header->orig_router->name); |
| 410 | free(name_lsa->header->orig_router); |
| 411 | free(name_lsa->header); |
| 412 | free(name_lsa->name_prefix->name); |
| 413 | free(name_lsa->name_prefix); |
| 414 | free(name_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 415 | |
| 416 | } |
| 417 | |
| 418 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 419 | build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 420 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 421 | printf("build_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 422 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 423 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 424 | name_lsa->header->ls_type=LS_TYPE_NAME; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 425 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 426 | name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 427 | memset(name_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 428 | memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 429 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 430 | name_lsa->header->ls_id=ls_id; |
| 431 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 432 | name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 433 | memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 434 | memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 435 | name_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 436 | name_lsa->header->isValid=isValid; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 437 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 438 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 439 | name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1); |
| 440 | memset(name_lsa->name_prefix->name,0,strlen(np)+1); |
| 441 | memcpy(name_lsa->name_prefix->name,np,strlen(np)+1); |
| 442 | name_lsa->name_prefix->length=strlen(np)+1; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 443 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 444 | |
| 445 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 446 | |
| 447 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 448 | void |
| 449 | make_adj_lsa_key(char *key,struct alsa *adj_lsa) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 450 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 451 | memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 452 | memcpy(key+strlen(key),"/",1); |
| 453 | char ls_type[2]; |
| 454 | sprintf(ls_type,"%d",adj_lsa->header->ls_type); |
| 455 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 456 | key[strlen(key)]='\0'; |
| 457 | } |
| 458 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 459 | int |
| 460 | build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 461 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 462 | if(flags == CCN_SCHEDULE_CANCEL) |
| 463 | { |
| 464 | return -1; |
| 465 | } |
| 466 | |
| 467 | nlsr_lock(); |
| 468 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 469 | printf("build_and_install_adj_lsa called \n"); |
| 470 | |
| 471 | printf("adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 472 | |
| 473 | if(nlsr->adj_build_flag > 0) |
| 474 | { |
| 475 | printf("is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 476 | if ( is_adj_lsa_build()> 0) |
| 477 | { |
| 478 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 479 | build_adj_lsa(adj_lsa); |
| 480 | install_adj_lsa(adj_lsa); |
| 481 | |
| 482 | free(adj_lsa->header->orig_router->name); |
| 483 | free(adj_lsa->header->orig_router); |
| 484 | free(adj_lsa->header->orig_time); |
| 485 | free(adj_lsa->header); |
| 486 | free(adj_lsa->body); |
| 487 | free(adj_lsa); |
| 488 | nlsr->adj_build_flag=0; |
| 489 | print_adj_lsdb(); |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | printf("Can not build adj LSA now\n"); |
| 494 | } |
| 495 | } |
| 496 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 497 | |
| 498 | nlsr_unlock(); |
| 499 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | void |
| 505 | build_adj_lsa(struct alsa * adj_lsa) |
| 506 | { |
| 507 | printf("build_adj_lsa called \n"); |
| 508 | |
| 509 | int no_link=no_active_nbr(); |
| 510 | printf("Number of link in Adjacent LSA: %d\n",no_link); |
| 511 | |
| 512 | /*Filling Up Header Data */ |
| 513 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 514 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 515 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 516 | memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 517 | memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 518 | adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 519 | |
| 520 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 521 | |
| 522 | char *time_stamp=(char *)malloc(20); |
| 523 | memset(time_stamp,0,20); |
| 524 | get_current_timestamp_micro(time_stamp); |
| 525 | |
| 526 | adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 527 | memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 528 | memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 529 | free(time_stamp); |
| 530 | |
| 531 | |
| 532 | /* Filling Up Body Data */ |
| 533 | |
| 534 | adj_lsa->no_link=no_link; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 535 | |
| 536 | |
| 537 | struct ccn_charbuf *c=ccn_charbuf_create(); |
| 538 | get_active_nbr_adj_data(c); |
| 539 | char *data=ccn_charbuf_as_string(c); |
| 540 | |
| 541 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 542 | memset(adj_lsa->body,0,strlen(data)+1); |
| 543 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 544 | ccn_charbuf_destroy(&c); |
| 545 | |
| 546 | |
| 547 | |
| 548 | if( !nlsr->is_send_lsdb_interest_scheduled ) |
| 549 | { |
| 550 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0); |
| 551 | nlsr->is_send_lsdb_interest_scheduled=1; |
| 552 | } |
| 553 | |
| 554 | nlsr->adj_build_count++; |
| 555 | |
| 556 | |
| 557 | } |
| 558 | |
| 559 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 560 | void |
| 561 | install_adj_lsa(struct alsa * adj_lsa) |
| 562 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 563 | printf("install_adj_lsa called \n"); |
| 564 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 565 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 566 | char *time_stamp=(char *)malloc(20); |
| 567 | memset(time_stamp,0,20); |
| 568 | get_current_timestamp_micro(time_stamp); |
| 569 | long int lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 570 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 571 | printf("time difference: %ld \n",lsa_life_time); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 572 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 573 | |
| 574 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 575 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 576 | make_adj_lsa_key(key,adj_lsa); |
| 577 | printf("Adjacent LSA key: %s \n",key); |
| 578 | |
| 579 | struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 580 | |
| 581 | struct hashtb_enumerator ee; |
| 582 | struct hashtb_enumerator *e = ⅇ |
| 583 | int res; |
| 584 | |
| 585 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 586 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 587 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 588 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 589 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 590 | if(res == HT_NEW_ENTRY) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 591 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 592 | if ( adj_lsa->no_link > 0) |
| 593 | { |
| 594 | printf("New ADJ LSA... Adding to LSDB\n"); |
| 595 | new_adj_lsa = e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 596 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 597 | new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 598 | new_adj_lsa->header->ls_type=adj_lsa->header->ls_type; |
| 599 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 600 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 601 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 602 | new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 603 | new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length); |
| 604 | memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 605 | new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 606 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 607 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 608 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 609 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 610 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 611 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 612 | |
| 613 | add_next_hop_router(new_adj_lsa->header->orig_router->name); |
| 614 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | hashtb_delete(e); |
| 619 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 620 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 621 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 622 | set_new_lsdb_version(); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 623 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 624 | } |
| 625 | else if(res == HT_OLD_ENTRY) |
| 626 | { |
| 627 | new_adj_lsa = e->data; |
| 628 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 629 | { |
| 630 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 631 | } |
| 632 | else |
| 633 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 634 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 635 | if ( adj_lsa->no_link > 0) |
| 636 | { |
| 637 | new_adj_lsa = e->data; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 638 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 639 | free(new_adj_lsa->header->orig_time); |
| 640 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 641 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 642 | |
| 643 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 644 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 645 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 646 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 647 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 648 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 649 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
| 650 | } |
| 651 | else |
| 652 | { |
| 653 | hashtb_delete(e); |
| 654 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 655 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 656 | set_new_lsdb_version(); |
| 657 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | } |
| 661 | hashtb_end(e); |
| 662 | |
| 663 | if ( !nlsr->is_route_calculation_scheduled ) |
| 664 | { |
| 665 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 666 | nlsr->is_route_calculation_scheduled=1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 667 | } |
| 668 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 669 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 670 | free(key); |
| 671 | |
| 672 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | void |
| 676 | print_adj_lsa_body(const char *body, int no_link) |
| 677 | { |
| 678 | int i=0; |
| 679 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 680 | memset( lsa_data,0,strlen(body)+1); |
| 681 | memcpy(lsa_data,body,strlen(body)+1); |
| 682 | char *sep="|"; |
| 683 | char *rem; |
| 684 | char *rtr_id; |
| 685 | char *length; |
| 686 | char *face; |
| 687 | char *metric; |
| 688 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 689 | if(no_link >0 ) |
| 690 | { |
| 691 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 692 | length=strtok_r(NULL,sep,&rem); |
| 693 | face=strtok_r(NULL,sep,&rem); |
| 694 | metric=strtok_r(NULL,sep,&rem); |
| 695 | |
| 696 | printf(" Link %d \n",i+1); |
| 697 | printf(" Neighbor : %s \n",rtr_id); |
| 698 | printf(" Neighbor Length : %s \n",length); |
| 699 | printf(" Connecting Face : %s \n",face); |
| 700 | printf(" Metric : %s \n",metric); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 701 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 702 | |
| 703 | for(i=1;i<no_link;i++) |
| 704 | { |
| 705 | rtr_id=strtok_r(NULL,sep,&rem); |
| 706 | length=strtok_r(NULL,sep,&rem); |
| 707 | face=strtok_r(NULL,sep,&rem); |
| 708 | metric=strtok_r(NULL,sep,&rem); |
| 709 | printf(" Link %d \n",i+1); |
| 710 | printf(" Neighbor : %s \n",rtr_id); |
| 711 | printf(" Neighbor Length : %s \n",length); |
| 712 | printf(" Connecting Face : %s \n",face); |
| 713 | printf(" Metric : %s \n",metric); |
| 714 | |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | free(lsa_data); |
| 719 | } |
| 720 | |
| 721 | void |
| 722 | print_adj_lsa(struct alsa * adj_lsa) |
| 723 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 724 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 725 | printf("print_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 726 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 727 | printf("-----------ADJ LSA Content---------------\n"); |
| 728 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 729 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 730 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 731 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 732 | printf(" Lsa Data:\n"); |
| 733 | printf(" No of Link : %d\n",adj_lsa->no_link); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 734 | |
| 735 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 736 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 737 | /* |
| 738 | struct link *templ=adj_lsa->links; |
| 739 | int i; |
| 740 | |
| 741 | for(i=0 ; i< adj_lsa->no_link ; i++) |
| 742 | { |
| 743 | printf(" Link %d \n",i+1); |
| 744 | printf(" Neighbor : %s \n",templ->nbr->name); |
| 745 | printf(" Neighbor Length : %d \n",templ->nbr->length); |
| 746 | printf(" Connecting Face : %d \n",templ->face); |
| 747 | printf(" Metric : %d \n",templ->metric); |
| 748 | |
| 749 | templ++; |
| 750 | } |
| 751 | */ |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 752 | printf("\n"); |
| 753 | |
| 754 | } |
| 755 | |
| 756 | void |
| 757 | print_adj_lsdb(void) |
| 758 | { |
| 759 | printf("print_name_lsdb called \n"); |
| 760 | int i, adj_lsdb_element; |
| 761 | struct alsa *adj_lsa; |
| 762 | |
| 763 | struct hashtb_enumerator ee; |
| 764 | struct hashtb_enumerator *e = ⅇ |
| 765 | |
| 766 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 767 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 768 | |
| 769 | for(i=0;i<adj_lsdb_element;i++) |
| 770 | { |
| 771 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
| 772 | adj_lsa=e->data; |
| 773 | print_adj_lsa(adj_lsa); |
| 774 | hashtb_next(e); |
| 775 | } |
| 776 | |
| 777 | hashtb_end(e); |
| 778 | |
| 779 | printf("\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 783 | build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 784 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 785 | printf("build_and_install_others_adj_lsa called \n"); |
| 786 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 787 | build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data); |
| 788 | //print_adj_lsa(adj_lsa); |
| 789 | install_adj_lsa(adj_lsa); |
| 790 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 791 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 792 | free(adj_lsa->header->orig_router->name); |
| 793 | free(adj_lsa->header->orig_router); |
| 794 | free(adj_lsa->header->orig_time); |
| 795 | free(adj_lsa->header); |
| 796 | free(adj_lsa->body); |
| 797 | free(adj_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 798 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 799 | print_adj_lsdb(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 800 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 801 | } |
| 802 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 803 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 804 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 805 | build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 806 | { |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 807 | printf("build_others_adj_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 808 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 809 | /*Filling Up Header Data */ |
| 810 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 811 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 812 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 813 | memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 814 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 815 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 816 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 817 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 818 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 819 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 820 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 821 | adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 822 | memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 823 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 824 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 825 | adj_lsa->no_link=no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 826 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 827 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 828 | memset(adj_lsa->body,0,strlen(data)+1); |
| 829 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 830 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 831 | } |
| 832 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 833 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 834 | long int |
| 835 | get_name_lsdb_num_element(void) |
| 836 | { |
| 837 | long int num_element; |
| 838 | |
| 839 | |
| 840 | struct hashtb_enumerator ee; |
| 841 | struct hashtb_enumerator *e = ⅇ |
| 842 | |
| 843 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 844 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 845 | hashtb_end(e); |
| 846 | |
| 847 | return num_element; |
| 848 | } |
| 849 | |
| 850 | long int |
| 851 | get_adj_lsdb_num_element(void) |
| 852 | { |
| 853 | long int num_element; |
| 854 | |
| 855 | |
| 856 | struct hashtb_enumerator ee; |
| 857 | struct hashtb_enumerator *e = ⅇ |
| 858 | |
| 859 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 860 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 861 | hashtb_end(e); |
| 862 | |
| 863 | return num_element; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 864 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 865 | |
| 866 | void |
| 867 | get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data) |
| 868 | { |
| 869 | printf("get_name_lsdb_summary called \n"); |
| 870 | int i, name_lsdb_element; |
| 871 | |
| 872 | struct nlsa *name_lsa; |
| 873 | struct hashtb_enumerator ee; |
| 874 | struct hashtb_enumerator *e = ⅇ |
| 875 | |
| 876 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 877 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 878 | |
| 879 | for(i=0;i<name_lsdb_element;i++) |
| 880 | { |
| 881 | name_lsa=e->data; |
| 882 | |
| 883 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name); |
| 884 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 885 | |
| 886 | char *lst=(char *)malloc(20); |
| 887 | memset(lst,0,20); |
| 888 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 889 | ccn_charbuf_append_string(name_lsdb_data,lst); |
| 890 | free(lst); |
| 891 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 892 | |
| 893 | char *lsid=(char *)malloc(20); |
| 894 | memset(lsid,0,20); |
| 895 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 896 | ccn_charbuf_append_string(name_lsdb_data,lsid); |
| 897 | free(lsid); |
| 898 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 899 | |
| 900 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time); |
| 901 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 902 | |
| 903 | hashtb_next(e); |
| 904 | } |
| 905 | |
| 906 | hashtb_end(e); |
| 907 | |
| 908 | } |
| 909 | |
| 910 | |
| 911 | void |
| 912 | get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data) |
| 913 | { |
| 914 | printf("get_adj_lsdb_summary called \n"); |
| 915 | int i, adj_lsdb_element; |
| 916 | struct alsa *adj_lsa; |
| 917 | |
| 918 | struct hashtb_enumerator ee; |
| 919 | struct hashtb_enumerator *e = ⅇ |
| 920 | |
| 921 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 922 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 923 | |
| 924 | for(i=0;i<adj_lsdb_element;i++) |
| 925 | { |
| 926 | adj_lsa=e->data; |
| 927 | |
| 928 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name); |
| 929 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 930 | |
| 931 | char *lst=(char *)malloc(20); |
| 932 | memset(lst,0,20); |
| 933 | sprintf(lst,"%d",adj_lsa->header->ls_type); |
| 934 | ccn_charbuf_append_string(adj_lsdb_data,lst); |
| 935 | free(lst); |
| 936 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 937 | |
| 938 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time); |
| 939 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 940 | |
| 941 | hashtb_next(e); |
| 942 | } |
| 943 | |
| 944 | hashtb_end(e); |
| 945 | } |
| 946 | |
| 947 | |
| 948 | void |
| 949 | get_lsdb_summary(struct ccn_charbuf *lsdb_data) |
| 950 | { |
| 951 | struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create(); |
| 952 | struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create(); |
| 953 | |
| 954 | get_name_lsdb_summary(name_lsdb_data); |
| 955 | get_adj_lsdb_summary(adj_lsdb_data); |
| 956 | |
| 957 | long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element(); |
| 958 | char *num_element=(char *)malloc(15); |
| 959 | memset(num_element,0,15); |
| 960 | sprintf(num_element,"%ld",num_lsa); |
| 961 | |
| 962 | if( num_lsa > 0) |
| 963 | { |
| 964 | ccn_charbuf_append_string(lsdb_data,num_element); |
| 965 | ccn_charbuf_append_string(lsdb_data,"|"); |
| 966 | } |
| 967 | if(name_lsdb_data->length>0) |
| 968 | { |
| 969 | char *data1=ccn_charbuf_as_string(name_lsdb_data); |
| 970 | ccn_charbuf_append_string(lsdb_data,(char *)data1); |
| 971 | } |
| 972 | if(adj_lsdb_data->length>0) |
| 973 | { |
| 974 | char *data2=ccn_charbuf_as_string(adj_lsdb_data); |
| 975 | ccn_charbuf_append_string(lsdb_data,(char *)data2); |
| 976 | } |
| 977 | ccn_charbuf_destroy(&name_lsdb_data); |
| 978 | ccn_charbuf_destroy(&adj_lsdb_data); |
| 979 | free(num_element); |
| 980 | |
| 981 | } |
| 982 | |
| 983 | int |
| 984 | check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time) |
| 985 | { |
| 986 | int ret=0; |
| 987 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 988 | ccn_charbuf_append_string(key,orig_router); |
| 989 | ccn_charbuf_append_string(key,"/"); |
| 990 | ccn_charbuf_append_string(key,lst); |
| 991 | ccn_charbuf_append_string(key,"/"); |
| 992 | ccn_charbuf_append_string(key,lsid); |
| 993 | |
| 994 | int res; |
| 995 | struct nlsa *name_lsa; |
| 996 | |
| 997 | struct hashtb_enumerator ee; |
| 998 | struct hashtb_enumerator *e = ⅇ |
| 999 | |
| 1000 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1001 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1002 | |
| 1003 | if( res == HT_NEW_ENTRY ) |
| 1004 | { |
| 1005 | hashtb_delete(e); |
| 1006 | ret=1; |
| 1007 | |
| 1008 | } |
| 1009 | else if(res == HT_OLD_ENTRY) |
| 1010 | { |
| 1011 | name_lsa=e->data; |
| 1012 | if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 ) |
| 1013 | { |
| 1014 | ret=1; |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | hashtb_end(e); |
| 1019 | |
| 1020 | ccn_charbuf_destroy(&key); |
| 1021 | |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
| 1025 | int |
| 1026 | check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time) |
| 1027 | { |
| 1028 | int ret=0; |
| 1029 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1030 | ccn_charbuf_append_string(key,orig_router); |
| 1031 | ccn_charbuf_append_string(key,"/"); |
| 1032 | ccn_charbuf_append_string(key,lst); |
| 1033 | |
| 1034 | int res; |
| 1035 | struct alsa *adj_lsa; |
| 1036 | |
| 1037 | struct hashtb_enumerator ee; |
| 1038 | struct hashtb_enumerator *e = ⅇ |
| 1039 | |
| 1040 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1041 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1042 | |
| 1043 | if( res == HT_NEW_ENTRY ) |
| 1044 | { |
| 1045 | hashtb_delete(e); |
| 1046 | ret=1; |
| 1047 | |
| 1048 | } |
| 1049 | else if(res == HT_OLD_ENTRY) |
| 1050 | { |
| 1051 | adj_lsa=e->data; |
| 1052 | if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 ) |
| 1053 | { |
| 1054 | ret=1; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | hashtb_end(e); |
| 1059 | |
| 1060 | ccn_charbuf_destroy(&key); |
| 1061 | |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | void |
| 1066 | get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId) |
| 1067 | { |
| 1068 | printf("get_name_lsa_data called \n"); |
| 1069 | |
| 1070 | struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 1071 | |
| 1072 | struct hashtb_enumerator ee; |
| 1073 | struct hashtb_enumerator *e = ⅇ |
| 1074 | int res; |
| 1075 | |
| 1076 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1077 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1078 | |
| 1079 | if( res == HT_OLD_ENTRY ) |
| 1080 | { |
| 1081 | name_lsa=e->data; |
| 1082 | printf("NAME LSA found\n"); |
| 1083 | |
| 1084 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 1085 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1086 | |
| 1087 | char *temp_length=(char *)malloc(20); |
| 1088 | memset(temp_length,0,20); |
| 1089 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 1090 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1091 | free(temp_length); |
| 1092 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1093 | |
| 1094 | char *temp_ltype=(char *)malloc(20); |
| 1095 | memset(temp_ltype,0,20); |
| 1096 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 1097 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1098 | free(temp_ltype); |
| 1099 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1100 | |
| 1101 | char *temp_lsid=(char *)malloc(20); |
| 1102 | memset(temp_lsid,0,20); |
| 1103 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 1104 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 1105 | free(temp_lsid); |
| 1106 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1107 | |
| 1108 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time); |
| 1109 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1110 | |
| 1111 | char *temp_valid=(char *)malloc(20); |
| 1112 | memset(temp_valid,0,20); |
| 1113 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 1114 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 1115 | free(temp_valid); |
| 1116 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1117 | |
| 1118 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 1119 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1120 | |
| 1121 | char *temp_npl=(char *)malloc(20); |
| 1122 | memset(temp_npl,0,20); |
| 1123 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 1124 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 1125 | free(temp_npl); |
| 1126 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1127 | |
| 1128 | } |
| 1129 | else if(res == HT_NEW_ENTRY) |
| 1130 | { |
| 1131 | hashtb_delete(e); |
| 1132 | } |
| 1133 | |
| 1134 | hashtb_end(e); |
| 1135 | } |
| 1136 | |
| 1137 | void |
| 1138 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 1139 | { |
| 1140 | printf("get_adj_lsa_data called \n"); |
| 1141 | |
| 1142 | struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 1143 | |
| 1144 | struct hashtb_enumerator ee; |
| 1145 | struct hashtb_enumerator *e = ⅇ |
| 1146 | int res; |
| 1147 | |
| 1148 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1149 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1150 | |
| 1151 | if( res == HT_OLD_ENTRY ) |
| 1152 | { |
| 1153 | adj_lsa=e->data; |
| 1154 | printf("NAME LSA found\n"); |
| 1155 | |
| 1156 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 1157 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1158 | |
| 1159 | char *temp_length=(char *)malloc(20); |
| 1160 | memset(temp_length,0,20); |
| 1161 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 1162 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1163 | free(temp_length); |
| 1164 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1165 | |
| 1166 | char *temp_ltype=(char *)malloc(20); |
| 1167 | memset(temp_ltype,0,20); |
| 1168 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 1169 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1170 | free(temp_ltype); |
| 1171 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1172 | |
| 1173 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 1174 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1175 | |
| 1176 | char *temp_nl=(char *)malloc(20); |
| 1177 | memset(temp_nl,0,20); |
| 1178 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 1179 | ccn_charbuf_append_string(lsa_data,temp_nl); |
| 1180 | free(temp_nl); |
| 1181 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1182 | |
| 1183 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 1184 | |
| 1185 | |
| 1186 | } |
| 1187 | else if(res == HT_NEW_ENTRY) |
| 1188 | { |
| 1189 | hashtb_delete(e); |
| 1190 | } |
| 1191 | |
| 1192 | hashtb_end(e); |
| 1193 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1194 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1195 | int |
| 1196 | delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1197 | { |
| 1198 | printf("delete_name_lsa called \n"); |
| 1199 | |
| 1200 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1201 | { |
| 1202 | return -1; |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | nlsr_lock(); |
| 1208 | |
| 1209 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1210 | |
| 1211 | struct nlsa *nlsa; |
| 1212 | |
| 1213 | struct hashtb_enumerator ee; |
| 1214 | struct hashtb_enumerator *e = ⅇ |
| 1215 | |
| 1216 | int res; |
| 1217 | |
| 1218 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1219 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1220 | |
| 1221 | if( res == HT_OLD_ENTRY ) |
| 1222 | { |
| 1223 | nlsa=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame^] | 1224 | delete_npt_entry_by_router_and_name_prefix(nlsa->header->orig_router->name, nlsa->name_prefix->name); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1225 | hashtb_delete(e); |
| 1226 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame^] | 1227 | else if( res == HT_NEW_ENTRY ) |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1228 | { |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1229 | hashtb_delete(e); |
| 1230 | } |
| 1231 | hashtb_end(e); |
| 1232 | |
| 1233 | |
| 1234 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1235 | set_new_lsdb_version(); |
| 1236 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1237 | |
| 1238 | //print_name_lsdb(); |
| 1239 | |
| 1240 | nlsr_unlock(); |
| 1241 | |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
| 1245 | int |
| 1246 | delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1247 | { |
| 1248 | printf("delete_adj_lsa called \n"); |
| 1249 | |
| 1250 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1251 | { |
| 1252 | return -1; |
| 1253 | } |
| 1254 | nlsr_lock(); |
| 1255 | |
| 1256 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1257 | |
| 1258 | struct hashtb_enumerator ee; |
| 1259 | struct hashtb_enumerator *e = ⅇ |
| 1260 | int res; |
| 1261 | |
| 1262 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1263 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1264 | |
| 1265 | if( res == HT_OLD_ENTRY ) |
| 1266 | { |
| 1267 | hashtb_delete(e); |
| 1268 | } |
| 1269 | else if( res == HT_OLD_ENTRY ) |
| 1270 | { |
| 1271 | hashtb_delete(e); |
| 1272 | } |
| 1273 | hashtb_end(e); |
| 1274 | |
| 1275 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1276 | set_new_lsdb_version(); |
| 1277 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1278 | |
| 1279 | if ( !nlsr->is_route_calculation_scheduled) |
| 1280 | { |
| 1281 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1282 | nlsr->is_route_calculation_scheduled=1; |
| 1283 | } |
| 1284 | |
| 1285 | //print_adj_lsdb(); |
| 1286 | |
| 1287 | nlsr_unlock(); |
| 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1292 | void |
| 1293 | refresh_name_lsdb(void) |
| 1294 | { |
| 1295 | printf("refresh_name_lsdb called \n"); |
| 1296 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1297 | //int lsa_change_count=0; |
| 1298 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1299 | char *time_stamp=(char *)malloc(20); |
| 1300 | memset(time_stamp,0,20); |
| 1301 | get_current_timestamp_micro(time_stamp); |
| 1302 | |
| 1303 | long int lsa_life_time; |
| 1304 | |
| 1305 | int i, name_lsdb_element; |
| 1306 | struct nlsa *name_lsa; |
| 1307 | |
| 1308 | struct hashtb_enumerator ee; |
| 1309 | struct hashtb_enumerator *e = ⅇ |
| 1310 | |
| 1311 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1312 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1313 | |
| 1314 | for(i=0;i<name_lsdb_element;i++) |
| 1315 | { |
| 1316 | name_lsa=e->data; |
| 1317 | |
| 1318 | lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1319 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1320 | |
| 1321 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1322 | { |
| 1323 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1324 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1325 | if ( name_lsa->header->isValid == NAME_LSA_VALID ) |
| 1326 | { |
| 1327 | printf("Own Name LSA need to be refrshed\n"); |
| 1328 | char *current_time_stamp=(char *)malloc(20); |
| 1329 | memset(current_time_stamp,0,20); |
| 1330 | get_current_timestamp_micro(current_time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1331 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1332 | free(name_lsa->header->orig_time); |
| 1333 | name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1334 | memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1335 | memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1336 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1337 | free(current_time_stamp); |
| 1338 | } |
| 1339 | else |
| 1340 | { |
| 1341 | char lst[2]; |
| 1342 | memset(lst,0,2); |
| 1343 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1344 | |
| 1345 | char lsid[10]; |
| 1346 | memset(lsid,0,10); |
| 1347 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1348 | |
| 1349 | |
| 1350 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1351 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1352 | |
| 1353 | |
| 1354 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 1355 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1356 | |
| 1357 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1358 | } |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1359 | |
| 1360 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1361 | set_new_lsdb_version(); |
| 1362 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1363 | |
| 1364 | print_name_lsdb(); |
| 1365 | //lsa_change_count++; |
| 1366 | } |
| 1367 | } |
| 1368 | else |
| 1369 | { |
| 1370 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1371 | { |
| 1372 | printf("Others Name LSA need to be deleted\n"); |
| 1373 | |
| 1374 | char lst[2]; |
| 1375 | memset(lst,0,2); |
| 1376 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1377 | |
| 1378 | char lsid[10]; |
| 1379 | memset(lsid,0,10); |
| 1380 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1381 | |
| 1382 | |
| 1383 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1384 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1385 | |
| 1386 | |
| 1387 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 1388 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1389 | |
| 1390 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1391 | //lsa_change_count++; |
| 1392 | } |
| 1393 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1394 | |
| 1395 | hashtb_next(e); |
| 1396 | } |
| 1397 | |
| 1398 | hashtb_end(e); |
| 1399 | |
| 1400 | free(time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1401 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1402 | |
| 1403 | } |
| 1404 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1405 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1406 | refresh_adj_lsdb(void) |
| 1407 | { |
| 1408 | printf("refresh_adj_lsdb called \n"); |
| 1409 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1410 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1411 | char *time_stamp=(char *)malloc(20); |
| 1412 | memset(time_stamp,0,20); |
| 1413 | get_current_timestamp_micro(time_stamp); |
| 1414 | |
| 1415 | long int lsa_life_time; |
| 1416 | |
| 1417 | int i, adj_lsdb_element; |
| 1418 | struct alsa *adj_lsa; |
| 1419 | |
| 1420 | struct hashtb_enumerator ee; |
| 1421 | struct hashtb_enumerator *e = ⅇ |
| 1422 | |
| 1423 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1424 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1425 | |
| 1426 | for(i=0;i<adj_lsdb_element;i++) |
| 1427 | { |
| 1428 | adj_lsa=e->data; |
| 1429 | |
| 1430 | lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
| 1431 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1432 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1433 | if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1434 | { |
| 1435 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1436 | { |
| 1437 | printf("Own Adj LSA need to be refrshed\n"); |
| 1438 | |
| 1439 | char *current_time_stamp=(char *)malloc(20); |
| 1440 | memset(current_time_stamp,0,20); |
| 1441 | get_current_timestamp_micro(current_time_stamp); |
| 1442 | |
| 1443 | free(adj_lsa->header->orig_time); |
| 1444 | adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1445 | memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1446 | memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1447 | |
| 1448 | free(current_time_stamp); |
| 1449 | |
| 1450 | |
| 1451 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1452 | set_new_lsdb_version(); |
| 1453 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1454 | |
| 1455 | print_adj_lsdb(); |
| 1456 | } |
| 1457 | } |
| 1458 | else |
| 1459 | { |
| 1460 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1461 | { |
| 1462 | printf("Others Adj LSA need to be deleted\n"); |
| 1463 | |
| 1464 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 1465 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 1466 | make_adj_lsa_key(key,adj_lsa); |
| 1467 | printf("Adjacent LSA key: %s \n",key); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1468 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1474 | hashtb_next(e); |
| 1475 | } |
| 1476 | |
| 1477 | hashtb_end(e); |
| 1478 | |
| 1479 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | int |
| 1483 | refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1484 | { |
| 1485 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1486 | { |
| 1487 | return -1; |
| 1488 | } |
| 1489 | |
| 1490 | nlsr_lock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1491 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1492 | printf("refresh_lsdb called \n"); |
| 1493 | |
| 1494 | refresh_name_lsdb(); |
| 1495 | refresh_adj_lsdb(); |
| 1496 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1497 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1498 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1499 | nlsr_unlock(); |
| 1500 | return 0; |
| 1501 | } |