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 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 51 | //printf("Orig Router: %s LS Type: %d LS Id: %ld\n",orig_router,ls_type,ls_id); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 67 | //printf("Key: %s\n",key); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 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 | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 74 | if ( nlsr->debugging ) |
| 75 | printf("build_and_install_name_lsas called \n"); |
| 76 | if ( nlsr->detailed_logging ) |
| 77 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n"); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 78 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 79 | int i, npl_element; |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 80 | //struct name_prefix *np; |
| 81 | struct name_prefix_list_entry *npe; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 82 | |
| 83 | struct hashtb_enumerator ee; |
| 84 | struct hashtb_enumerator *e = ⅇ |
| 85 | |
| 86 | hashtb_start(nlsr->npl, e); |
| 87 | npl_element=hashtb_n(nlsr->npl); |
| 88 | |
| 89 | for(i=0;i<npl_element;i++) |
| 90 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 91 | npe=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 92 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 93 | build_name_lsa(name_lsa,npe->np); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 94 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 95 | install_name_lsa(name_lsa); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 96 | update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 97 | free(name_lsa->header->orig_router->name); |
| 98 | free(name_lsa->header->orig_router); |
| 99 | free(name_lsa->header); |
| 100 | free(name_lsa->name_prefix->name); |
| 101 | free(name_lsa->name_prefix); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 102 | free(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 103 | hashtb_next(e); |
| 104 | } |
| 105 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 106 | hashtb_end(e); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 107 | |
| 108 | print_name_prefix_from_npl(); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | build_and_install_single_name_lsa(struct name_prefix *np) |
| 114 | { |
| 115 | if ( nlsr->debugging ) |
| 116 | printf("build_and_install_single_name_lsa called \n"); |
| 117 | if ( nlsr->detailed_logging ) |
| 118 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n"); |
| 119 | |
| 120 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 121 | build_name_lsa(name_lsa,np); |
| 122 | |
| 123 | install_name_lsa(name_lsa); |
| 124 | update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id); |
| 125 | |
| 126 | free(name_lsa->header->orig_router->name); |
| 127 | free(name_lsa->header->orig_router); |
| 128 | free(name_lsa->header); |
| 129 | free(name_lsa->name_prefix->name); |
| 130 | free(name_lsa->name_prefix); |
| 131 | free(name_lsa); |
| 132 | |
| 133 | print_name_prefix_from_npl(); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 134 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 135 | } |
| 136 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 137 | void |
| 138 | build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np) |
| 139 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 140 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 141 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 142 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 143 | char *time_stamp=(char *)malloc(20); |
| 144 | memset(time_stamp,0,20); |
| 145 | get_current_timestamp_micro(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 146 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 147 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 148 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 149 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 150 | |
| 151 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 152 | |
| 153 | name_lsa->header->ls_id=++nlsr->nlsa_id; |
| 154 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 155 | name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 156 | memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 157 | memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 158 | name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 159 | name_lsa->header->isValid=1; |
| 160 | |
| 161 | |
| 162 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 163 | name_lsa->name_prefix->name=(char *)malloc(np->length); |
| 164 | memcpy(name_lsa->name_prefix->name,np->name,np->length); |
| 165 | name_lsa->name_prefix->length=np->length; |
| 166 | |
| 167 | } |
| 168 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 169 | void |
| 170 | install_name_lsa(struct nlsa *name_lsa) |
| 171 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 172 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 173 | char *time_stamp=(char *)malloc(20); |
| 174 | memset(time_stamp,0,20); |
| 175 | get_current_timestamp_micro(time_stamp); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 176 | //long int lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 177 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 178 | //printf("time difference: %ld \n",lsa_life_time); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 179 | |
| 180 | |
| 181 | char lst[2]; |
| 182 | memset(lst,0,2); |
| 183 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 184 | |
| 185 | char lsid[10]; |
| 186 | memset(lsid,0,10); |
| 187 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 188 | |
| 189 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 190 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 191 | 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] | 192 | |
| 193 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 194 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 195 | if ( nlsr->debugging ) |
| 196 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 197 | if ( nlsr->detailed_logging ) |
| 198 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key)); |
| 199 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 200 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 201 | struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 202 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 203 | struct hashtb_enumerator ee; |
| 204 | struct hashtb_enumerator *e = ⅇ |
| 205 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 206 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 207 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 208 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 209 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 210 | if(res == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 211 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 212 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 213 | if ( nlsr->debugging ) |
| 214 | printf("New Name LSA... Adding to LSDB\n"); |
| 215 | if ( nlsr->detailed_logging ) |
| 216 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n"); |
| 217 | |
| 218 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 219 | new_name_lsa = e->data; |
| 220 | |
| 221 | new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free |
| 222 | new_name_lsa->header->ls_type=name_lsa->header->ls_type; |
| 223 | |
| 224 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 225 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 226 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 227 | |
| 228 | new_name_lsa->header->ls_id=name_lsa->header->ls_id; |
| 229 | new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 230 | new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length); |
| 231 | memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length); |
| 232 | new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length; |
| 233 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 234 | |
| 235 | |
| 236 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 237 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 238 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 239 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 240 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 241 | if ( nlsr->debugging ) |
| 242 | { |
| 243 | printf("New Name LSA Added....\n"); |
| 244 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 245 | } |
| 246 | if ( nlsr->detailed_logging ) |
| 247 | { |
| 248 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n"); |
| 249 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 250 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 251 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 252 | if ( nlsr->debugging ) |
| 253 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 254 | if ( nlsr->detailed_logging ) |
| 255 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 256 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 257 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 258 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 259 | if ( num_next_hop < 0 ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 260 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 261 | 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] | 262 | if ( check == HT_NEW_ENTRY ) |
| 263 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 264 | if ( nlsr->debugging ) |
| 265 | printf("Added in npt \n"); |
| 266 | if ( nlsr->detailed_logging ) |
| 267 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 268 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 269 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 270 | else |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 271 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 272 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 273 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 274 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 275 | if ( nlsr->debugging ) |
| 276 | { |
| 277 | printf("Printing from install_name_lsa \n"); |
| 278 | int j; |
| 279 | for(j=0;j<num_next_hop;j++) |
| 280 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 281 | } |
| 282 | if ( nlsr->detailed_logging ) |
| 283 | { |
| 284 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 285 | int j; |
| 286 | for(j=0;j<num_next_hop;j++) |
| 287 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 288 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 289 | 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] | 290 | if ( check == HT_NEW_ENTRY ) |
| 291 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 292 | if ( nlsr->debugging ) |
| 293 | printf("Added in npt \n"); |
| 294 | if ( nlsr->detailed_logging ) |
| 295 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 296 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 297 | free(faces); |
| 298 | free(route_costs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 299 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 300 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 301 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 302 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 303 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 304 | write_log_for_name_lsa(new_name_lsa); |
| 305 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 306 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 307 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 308 | |
| 309 | } |
| 310 | else if(res == HT_OLD_ENTRY) |
| 311 | { |
| 312 | new_name_lsa=e->data; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 313 | 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] | 314 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 315 | if ( nlsr->debugging ) |
| 316 | printf("Older Adj LSA. Discarded... \n"); |
| 317 | if ( nlsr->detailed_logging ) |
| 318 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 319 | } |
| 320 | else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 ) |
| 321 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 322 | if ( nlsr->debugging ) |
| 323 | printf("Duplicate Adj LSA. Discarded... \n"); |
| 324 | if ( nlsr->detailed_logging ) |
| 325 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
| 329 | if ( name_lsa->header->isValid == 0 ) |
| 330 | { |
| 331 | // have to call to delete npt table entry |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 332 | 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] | 333 | |
| 334 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0) |
| 335 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 336 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 337 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 338 | write_log_for_name_lsa(new_name_lsa); |
| 339 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 340 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 341 | hashtb_delete(e); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 342 | if ( nlsr->debugging ) |
| 343 | printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
| 344 | if ( nlsr->detailed_logging ) |
| 345 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 346 | } |
| 347 | else |
| 348 | { |
| 349 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 350 | free(new_name_lsa->header->orig_time); |
| 351 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 352 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 353 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 354 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 355 | if ( nlsr->debugging ) |
| 356 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 357 | if ( nlsr->detailed_logging ) |
| 358 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 359 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 360 | if ( nlsr->debugging ) |
| 361 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 362 | if ( nlsr->detailed_logging ) |
| 363 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
| 367 | int is_npt_update=0; |
| 368 | if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 ) |
| 369 | { |
| 370 | is_npt_update=1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 371 | 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] | 372 | } |
| 373 | |
| 374 | // copying LSA content with header |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 375 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 376 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 377 | write_log_for_name_lsa(new_name_lsa); |
| 378 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 379 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 380 | |
| 381 | free(new_name_lsa->header->orig_time); |
| 382 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 383 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 384 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 385 | |
| 386 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 387 | |
| 388 | free(new_name_lsa->name_prefix->name); |
| 389 | free(new_name_lsa->name_prefix); |
| 390 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 391 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 392 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 393 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 394 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 395 | |
| 396 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 397 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 398 | write_log_for_name_lsa(new_name_lsa); |
| 399 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 400 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 401 | if ( nlsr->debugging ) |
| 402 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 403 | if ( nlsr->detailed_logging ) |
| 404 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 405 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 406 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 407 | |
| 408 | if ( nlsr->debugging ) |
| 409 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 410 | if ( nlsr->detailed_logging ) |
| 411 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 412 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 413 | |
| 414 | if( is_npt_update == 1 ) |
| 415 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 416 | //struct hashtb *face_list; |
| 417 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
| 418 | if ( num_next_hop < 0 ) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 419 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 420 | |
| 421 | 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] | 422 | if ( check == HT_NEW_ENTRY ) |
| 423 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 424 | if ( nlsr->debugging ) |
| 425 | printf("Added in npt \n"); |
| 426 | if ( nlsr->detailed_logging ) |
| 427 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | else |
| 431 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 432 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 433 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 434 | int next_hop=get_next_hop(new_name_lsa->header->orig_router->name,faces,route_costs); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 435 | |
| 436 | if ( nlsr->debugging ) |
| 437 | { |
| 438 | printf("Printing from install_name_lsa \n"); |
| 439 | int j; |
| 440 | for(j=0;j<num_next_hop;j++) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 441 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 442 | } |
| 443 | if ( nlsr->detailed_logging ) |
| 444 | { |
| 445 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 446 | int j; |
| 447 | for(j=0;j<num_next_hop;j++) |
| 448 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 449 | } |
| 450 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 451 | |
| 452 | 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] | 453 | if ( check == HT_NEW_ENTRY ) |
| 454 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 455 | //printf("Added in npt \n"); |
| 456 | if ( nlsr->debugging ) |
| 457 | printf("Added in npt \n"); |
| 458 | if ( nlsr->detailed_logging ) |
| 459 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 460 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 461 | free(faces); |
| 462 | free(route_costs); |
| 463 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 464 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 465 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 470 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 471 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 472 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 473 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 474 | free(key); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 475 | } |
| 476 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 477 | void |
| 478 | write_log_for_name_lsa(struct nlsa *name_lsa) |
| 479 | { |
| 480 | |
| 481 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n"); |
| 482 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name); |
| 483 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 484 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type); |
| 485 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id); |
| 486 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time); |
| 487 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 488 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n"); |
| 489 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name); |
| 490 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length); |
| 491 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 492 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 493 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 494 | void |
| 495 | print_name_lsa(struct nlsa *name_lsa) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 496 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 497 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 498 | if ( nlsr->debugging ) |
| 499 | { |
| 500 | printf("-----------Name LSA Content---------------\n"); |
| 501 | printf(" Origination Router : %s\n",name_lsa->header->orig_router->name); |
| 502 | printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
| 503 | printf(" LS Type : %d\n",name_lsa->header->ls_type); |
| 504 | printf(" LS Id : %ld\n",name_lsa->header->ls_id); |
| 505 | printf(" Origination Time : %s\n",name_lsa->header->orig_time); |
| 506 | printf(" Is Valid : %d\n",name_lsa->header->isValid); |
| 507 | printf(" LSA Data \n"); |
| 508 | printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name); |
| 509 | printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length); |
| 510 | |
| 511 | printf("\n"); |
| 512 | } |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | void |
| 516 | print_name_lsdb(void) |
| 517 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 518 | if ( nlsr->debugging ) |
| 519 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 520 | int i, name_lsdb_element; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 521 | struct nlsa *name_lsa; |
| 522 | |
| 523 | struct hashtb_enumerator ee; |
| 524 | struct hashtb_enumerator *e = ⅇ |
| 525 | |
| 526 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 527 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 528 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 529 | for(i=0;i<name_lsdb_element;i++) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 530 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 531 | if ( nlsr->debugging ) |
| 532 | printf("-----------Name LSA (%d)---------------\n",i+1); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 533 | name_lsa=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 534 | print_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 535 | hashtb_next(e); |
| 536 | } |
| 537 | |
| 538 | hashtb_end(e); |
| 539 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 540 | if ( nlsr->debugging ) |
| 541 | printf("\n"); |
| 542 | if ( nlsr->detailed_logging ) |
| 543 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 544 | } |
| 545 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 546 | |
| 547 | void |
| 548 | 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] | 549 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 550 | if ( nlsr->debugging ) |
| 551 | printf("build_and_install_others_name_lsa called \n"); |
| 552 | if ( nlsr->detailed_logging ) |
| 553 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 554 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 555 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 556 | build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np); |
| 557 | print_name_lsa(name_lsa); |
| 558 | install_name_lsa(name_lsa); |
| 559 | print_name_lsdb(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 560 | print_npt(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 561 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 562 | free(name_lsa->header->orig_router->name); |
| 563 | free(name_lsa->header->orig_router); |
| 564 | free(name_lsa->header); |
| 565 | free(name_lsa->name_prefix->name); |
| 566 | free(name_lsa->name_prefix); |
| 567 | free(name_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 568 | |
| 569 | } |
| 570 | |
| 571 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 572 | 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] | 573 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 574 | if ( nlsr->debugging ) |
| 575 | printf("build_others_name_lsa called\n"); |
| 576 | if ( nlsr->detailed_logging ) |
| 577 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 578 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 579 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 580 | name_lsa->header->ls_type=LS_TYPE_NAME; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 581 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 582 | name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 583 | memset(name_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 584 | memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 585 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 586 | name_lsa->header->ls_id=ls_id; |
| 587 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 588 | name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 589 | memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 590 | memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 591 | name_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 592 | name_lsa->header->isValid=isValid; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 593 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 594 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 595 | name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1); |
| 596 | memset(name_lsa->name_prefix->name,0,strlen(np)+1); |
| 597 | memcpy(name_lsa->name_prefix->name,np,strlen(np)+1); |
| 598 | name_lsa->name_prefix->length=strlen(np)+1; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 599 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 600 | |
| 601 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 602 | |
| 603 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 604 | void |
| 605 | make_adj_lsa_key(char *key,struct alsa *adj_lsa) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 606 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 607 | memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 608 | memcpy(key+strlen(key),"/",1); |
| 609 | char ls_type[2]; |
| 610 | sprintf(ls_type,"%d",adj_lsa->header->ls_type); |
| 611 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 612 | key[strlen(key)]='\0'; |
| 613 | } |
| 614 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 615 | int |
| 616 | build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 617 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 618 | if(flags == CCN_SCHEDULE_CANCEL) |
| 619 | { |
| 620 | return -1; |
| 621 | } |
| 622 | |
| 623 | nlsr_lock(); |
| 624 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 625 | if ( nlsr->debugging ) |
| 626 | printf("build_and_install_adj_lsa called \n"); |
| 627 | if ( nlsr->detailed_logging ) |
| 628 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n"); |
| 629 | |
| 630 | if ( nlsr->debugging ) |
| 631 | printf("adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 632 | if ( nlsr->detailed_logging ) |
| 633 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 634 | |
| 635 | if(nlsr->adj_build_flag > 0) |
| 636 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 637 | if ( nlsr->debugging ) |
| 638 | printf("is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 639 | if ( nlsr->detailed_logging ) |
| 640 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 641 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 642 | if ( is_adj_lsa_build()> 0) |
| 643 | { |
| 644 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 645 | build_adj_lsa(adj_lsa); |
| 646 | install_adj_lsa(adj_lsa); |
| 647 | |
| 648 | free(adj_lsa->header->orig_router->name); |
| 649 | free(adj_lsa->header->orig_router); |
| 650 | free(adj_lsa->header->orig_time); |
| 651 | free(adj_lsa->header); |
| 652 | free(adj_lsa->body); |
| 653 | free(adj_lsa); |
| 654 | nlsr->adj_build_flag=0; |
| 655 | print_adj_lsdb(); |
| 656 | } |
| 657 | else |
| 658 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 659 | if ( nlsr->debugging ) |
| 660 | printf("Can not build adj LSA now\n"); |
| 661 | if ( nlsr->detailed_logging ) |
| 662 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 666 | |
| 667 | nlsr_unlock(); |
| 668 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | void |
| 674 | build_adj_lsa(struct alsa * adj_lsa) |
| 675 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 676 | if ( nlsr->debugging ) |
| 677 | printf("build_adj_lsa called \n"); |
| 678 | if ( nlsr->detailed_logging ) |
| 679 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 680 | |
| 681 | int no_link=no_active_nbr(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 682 | |
| 683 | //printf("Number of link in Adjacent LSA: %d\n",no_link); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 684 | |
| 685 | /*Filling Up Header Data */ |
| 686 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 687 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 688 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 689 | memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 690 | memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 691 | adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 692 | |
| 693 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 694 | |
| 695 | char *time_stamp=(char *)malloc(20); |
| 696 | memset(time_stamp,0,20); |
| 697 | get_current_timestamp_micro(time_stamp); |
| 698 | |
| 699 | adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 700 | memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 701 | memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 702 | free(time_stamp); |
| 703 | |
| 704 | |
| 705 | /* Filling Up Body Data */ |
| 706 | |
| 707 | adj_lsa->no_link=no_link; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 708 | |
| 709 | |
| 710 | struct ccn_charbuf *c=ccn_charbuf_create(); |
| 711 | get_active_nbr_adj_data(c); |
| 712 | char *data=ccn_charbuf_as_string(c); |
| 713 | |
| 714 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 715 | memset(adj_lsa->body,0,strlen(data)+1); |
| 716 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 717 | ccn_charbuf_destroy(&c); |
| 718 | |
| 719 | |
| 720 | |
| 721 | if( !nlsr->is_send_lsdb_interest_scheduled ) |
| 722 | { |
| 723 | nlsr->event_send_lsdb_interest= ccn_schedule_event(nlsr->sched, 1000, &send_lsdb_interest, NULL, 0); |
| 724 | nlsr->is_send_lsdb_interest_scheduled=1; |
| 725 | } |
| 726 | |
| 727 | nlsr->adj_build_count++; |
| 728 | |
| 729 | |
| 730 | } |
| 731 | |
| 732 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 733 | void |
| 734 | install_adj_lsa(struct alsa * adj_lsa) |
| 735 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 736 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 737 | if ( nlsr->debugging ) |
| 738 | printf("install_adj_lsa called \n"); |
| 739 | if ( nlsr->detailed_logging ) |
| 740 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n"); |
| 741 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 742 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 743 | char *time_stamp=(char *)malloc(20); |
| 744 | memset(time_stamp,0,20); |
| 745 | get_current_timestamp_micro(time_stamp); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 746 | //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] | 747 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 748 | //printf("time difference: %ld \n",lsa_life_time); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 749 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 750 | |
| 751 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 752 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 753 | make_adj_lsa_key(key,adj_lsa); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 754 | //printf("Adjacent LSA key: %s \n",key); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 755 | |
| 756 | struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 757 | |
| 758 | struct hashtb_enumerator ee; |
| 759 | struct hashtb_enumerator *e = ⅇ |
| 760 | int res; |
| 761 | |
| 762 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 763 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 764 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 765 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 766 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 767 | if(res == HT_NEW_ENTRY) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 768 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 769 | if ( adj_lsa->no_link > 0) |
| 770 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 771 | if ( nlsr->debugging ) |
| 772 | printf("New ADJ LSA... Adding to LSDB\n"); |
| 773 | if ( nlsr->detailed_logging ) |
| 774 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 775 | new_adj_lsa = e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 776 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 777 | new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 778 | new_adj_lsa->header->ls_type=adj_lsa->header->ls_type; |
| 779 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 780 | 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] | 781 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 782 | new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 783 | new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length); |
| 784 | memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 785 | new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 786 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 787 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 788 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 789 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 790 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 791 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 792 | |
| 793 | add_next_hop_router(new_adj_lsa->header->orig_router->name); |
| 794 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 795 | |
| 796 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 797 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 798 | write_log_for_adj_lsa(new_adj_lsa); |
| 799 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 800 | } |
| 801 | else |
| 802 | { |
| 803 | hashtb_delete(e); |
| 804 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 805 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 806 | if ( nlsr->debugging ) |
| 807 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 808 | if ( nlsr->detailed_logging ) |
| 809 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 810 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 811 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 812 | |
| 813 | if ( nlsr->debugging ) |
| 814 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 815 | if ( nlsr->detailed_logging ) |
| 816 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 817 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 818 | } |
| 819 | else if(res == HT_OLD_ENTRY) |
| 820 | { |
| 821 | new_adj_lsa = e->data; |
| 822 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 823 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 824 | if ( nlsr->debugging ) |
| 825 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 826 | if ( nlsr->detailed_logging ) |
| 827 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 828 | } |
| 829 | else |
| 830 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 831 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 832 | if ( adj_lsa->no_link > 0) |
| 833 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 834 | //new_adj_lsa = e->data; |
| 835 | |
| 836 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 837 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 838 | write_log_for_adj_lsa(new_adj_lsa); |
| 839 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 840 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 841 | free(new_adj_lsa->header->orig_time); |
| 842 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 843 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 844 | |
| 845 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 846 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 847 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 848 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 849 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 850 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 851 | add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 852 | |
| 853 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 854 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 855 | write_log_for_adj_lsa(new_adj_lsa); |
| 856 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 857 | } |
| 858 | else |
| 859 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 860 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 861 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 862 | write_log_for_adj_lsa(new_adj_lsa); |
| 863 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 864 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 865 | hashtb_delete(e); |
| 866 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 867 | |
| 868 | if ( nlsr->debugging ) |
| 869 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 870 | if ( nlsr->detailed_logging ) |
| 871 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 872 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 873 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 874 | |
| 875 | if ( nlsr->debugging ) |
| 876 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 877 | if ( nlsr->detailed_logging ) |
| 878 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | } |
| 882 | hashtb_end(e); |
| 883 | |
| 884 | if ( !nlsr->is_route_calculation_scheduled ) |
| 885 | { |
| 886 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 887 | nlsr->is_route_calculation_scheduled=1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 888 | } |
| 889 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 890 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 891 | free(key); |
| 892 | |
| 893 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | void |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 897 | write_log_for_adj_lsa_body(const char *body, int no_link) |
| 898 | { |
| 899 | int i=0; |
| 900 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 901 | memset( lsa_data,0,strlen(body)+1); |
| 902 | memcpy(lsa_data,body,strlen(body)+1); |
| 903 | char *sep="|"; |
| 904 | char *rem; |
| 905 | char *rtr_id; |
| 906 | char *length; |
| 907 | char *face; |
| 908 | char *metric; |
| 909 | |
| 910 | if(no_link >0 ) |
| 911 | { |
| 912 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 913 | length=strtok_r(NULL,sep,&rem); |
| 914 | face=strtok_r(NULL,sep,&rem); |
| 915 | metric=strtok_r(NULL,sep,&rem); |
| 916 | |
| 917 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 918 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 919 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
| 920 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
| 921 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 922 | |
| 923 | |
| 924 | for(i=1;i<no_link;i++) |
| 925 | { |
| 926 | rtr_id=strtok_r(NULL,sep,&rem); |
| 927 | length=strtok_r(NULL,sep,&rem); |
| 928 | face=strtok_r(NULL,sep,&rem); |
| 929 | metric=strtok_r(NULL,sep,&rem); |
| 930 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 931 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 932 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
| 933 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
| 934 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 935 | |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | free(lsa_data); |
| 940 | } |
| 941 | |
| 942 | |
| 943 | void |
| 944 | write_log_for_adj_lsa(struct alsa * adj_lsa) |
| 945 | { |
| 946 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 947 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name); |
| 948 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 949 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type); |
| 950 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 951 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 952 | writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 953 | |
| 954 | write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 955 | |
| 956 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 957 | |
| 958 | } |
| 959 | |
| 960 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 961 | print_adj_lsa_body(const char *body, int no_link) |
| 962 | { |
| 963 | int i=0; |
| 964 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 965 | memset( lsa_data,0,strlen(body)+1); |
| 966 | memcpy(lsa_data,body,strlen(body)+1); |
| 967 | char *sep="|"; |
| 968 | char *rem; |
| 969 | char *rtr_id; |
| 970 | char *length; |
| 971 | char *face; |
| 972 | char *metric; |
| 973 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 974 | if(no_link >0 ) |
| 975 | { |
| 976 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 977 | length=strtok_r(NULL,sep,&rem); |
| 978 | face=strtok_r(NULL,sep,&rem); |
| 979 | metric=strtok_r(NULL,sep,&rem); |
| 980 | |
| 981 | printf(" Link %d \n",i+1); |
| 982 | printf(" Neighbor : %s \n",rtr_id); |
| 983 | printf(" Neighbor Length : %s \n",length); |
| 984 | printf(" Connecting Face : %s \n",face); |
| 985 | printf(" Metric : %s \n",metric); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 986 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 987 | |
| 988 | for(i=1;i<no_link;i++) |
| 989 | { |
| 990 | rtr_id=strtok_r(NULL,sep,&rem); |
| 991 | length=strtok_r(NULL,sep,&rem); |
| 992 | face=strtok_r(NULL,sep,&rem); |
| 993 | metric=strtok_r(NULL,sep,&rem); |
| 994 | printf(" Link %d \n",i+1); |
| 995 | printf(" Neighbor : %s \n",rtr_id); |
| 996 | printf(" Neighbor Length : %s \n",length); |
| 997 | printf(" Connecting Face : %s \n",face); |
| 998 | printf(" Metric : %s \n",metric); |
| 999 | |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | free(lsa_data); |
| 1004 | } |
| 1005 | |
| 1006 | void |
| 1007 | print_adj_lsa(struct alsa * adj_lsa) |
| 1008 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1009 | if ( nlsr->debugging ) |
| 1010 | { |
| 1011 | printf("-----------ADJ LSA Content---------------\n"); |
| 1012 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 1013 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 1014 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 1015 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
| 1016 | printf(" Lsa Data:\n"); |
| 1017 | printf(" No of Link : %d\n",adj_lsa->no_link); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1018 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1019 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1020 | printf("\n"); |
| 1021 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1022 | |
| 1023 | } |
| 1024 | |
| 1025 | void |
| 1026 | print_adj_lsdb(void) |
| 1027 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1028 | if ( nlsr->debugging ) |
| 1029 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1030 | int i, adj_lsdb_element; |
| 1031 | struct alsa *adj_lsa; |
| 1032 | |
| 1033 | struct hashtb_enumerator ee; |
| 1034 | struct hashtb_enumerator *e = ⅇ |
| 1035 | |
| 1036 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1037 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1038 | |
| 1039 | for(i=0;i<adj_lsdb_element;i++) |
| 1040 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1041 | if ( nlsr->debugging ) |
| 1042 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1043 | adj_lsa=e->data; |
| 1044 | print_adj_lsa(adj_lsa); |
| 1045 | hashtb_next(e); |
| 1046 | } |
| 1047 | |
| 1048 | hashtb_end(e); |
| 1049 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1050 | if ( nlsr->debugging ) |
| 1051 | printf("\n"); |
| 1052 | if ( nlsr->detailed_logging ) |
| 1053 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1057 | 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] | 1058 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1059 | if ( nlsr->debugging ) |
| 1060 | printf("build_and_install_others_adj_lsa called \n"); |
| 1061 | if ( nlsr->detailed_logging ) |
| 1062 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1063 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 1064 | build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data); |
| 1065 | //print_adj_lsa(adj_lsa); |
| 1066 | install_adj_lsa(adj_lsa); |
| 1067 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1068 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1069 | free(adj_lsa->header->orig_router->name); |
| 1070 | free(adj_lsa->header->orig_router); |
| 1071 | free(adj_lsa->header->orig_time); |
| 1072 | free(adj_lsa->header); |
| 1073 | free(adj_lsa->body); |
| 1074 | free(adj_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1075 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1076 | print_adj_lsdb(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1077 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1078 | } |
| 1079 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1080 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1081 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1082 | 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] | 1083 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1084 | //printf("build_others_adj_lsa called \n"); |
| 1085 | if ( nlsr->debugging ) |
| 1086 | printf("build_others_adj_lsa called \n"); |
| 1087 | if ( nlsr->detailed_logging ) |
| 1088 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1089 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1090 | /*Filling Up Header Data */ |
| 1091 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 1092 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1093 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 1094 | memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 1095 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1096 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1097 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1098 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1099 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1100 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1101 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1102 | adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 1103 | memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 1104 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1105 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1106 | adj_lsa->no_link=no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1107 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1108 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 1109 | memset(adj_lsa->body,0,strlen(data)+1); |
| 1110 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1111 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1112 | } |
| 1113 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1114 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1115 | long int |
| 1116 | get_name_lsdb_num_element(void) |
| 1117 | { |
| 1118 | long int num_element; |
| 1119 | |
| 1120 | |
| 1121 | struct hashtb_enumerator ee; |
| 1122 | struct hashtb_enumerator *e = ⅇ |
| 1123 | |
| 1124 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1125 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1126 | hashtb_end(e); |
| 1127 | |
| 1128 | return num_element; |
| 1129 | } |
| 1130 | |
| 1131 | long int |
| 1132 | get_adj_lsdb_num_element(void) |
| 1133 | { |
| 1134 | long int num_element; |
| 1135 | |
| 1136 | |
| 1137 | struct hashtb_enumerator ee; |
| 1138 | struct hashtb_enumerator *e = ⅇ |
| 1139 | |
| 1140 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1141 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1142 | hashtb_end(e); |
| 1143 | |
| 1144 | return num_element; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1145 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1146 | |
| 1147 | void |
| 1148 | get_name_lsdb_summary(struct ccn_charbuf *name_lsdb_data) |
| 1149 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1150 | //printf("get_name_lsdb_summary called \n"); |
| 1151 | if ( nlsr->debugging ) |
| 1152 | printf("get_name_lsdb_summary called \n"); |
| 1153 | if ( nlsr->detailed_logging ) |
| 1154 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsdb_summary called \n"); |
| 1155 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1156 | int i, name_lsdb_element; |
| 1157 | |
| 1158 | struct nlsa *name_lsa; |
| 1159 | struct hashtb_enumerator ee; |
| 1160 | struct hashtb_enumerator *e = ⅇ |
| 1161 | |
| 1162 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1163 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1164 | |
| 1165 | for(i=0;i<name_lsdb_element;i++) |
| 1166 | { |
| 1167 | name_lsa=e->data; |
| 1168 | |
| 1169 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_router->name); |
| 1170 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1171 | |
| 1172 | char *lst=(char *)malloc(20); |
| 1173 | memset(lst,0,20); |
| 1174 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1175 | ccn_charbuf_append_string(name_lsdb_data,lst); |
| 1176 | free(lst); |
| 1177 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1178 | |
| 1179 | char *lsid=(char *)malloc(20); |
| 1180 | memset(lsid,0,20); |
| 1181 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1182 | ccn_charbuf_append_string(name_lsdb_data,lsid); |
| 1183 | free(lsid); |
| 1184 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1185 | |
| 1186 | ccn_charbuf_append_string(name_lsdb_data,name_lsa->header->orig_time); |
| 1187 | ccn_charbuf_append_string(name_lsdb_data,"|"); |
| 1188 | |
| 1189 | hashtb_next(e); |
| 1190 | } |
| 1191 | |
| 1192 | hashtb_end(e); |
| 1193 | |
| 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | void |
| 1198 | get_adj_lsdb_summary(struct ccn_charbuf *adj_lsdb_data) |
| 1199 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1200 | if ( nlsr->debugging ) |
| 1201 | printf("get_adj_lsdb_summary called \n"); |
| 1202 | if ( nlsr->detailed_logging ) |
| 1203 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsdb_summary called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1204 | int i, adj_lsdb_element; |
| 1205 | struct alsa *adj_lsa; |
| 1206 | |
| 1207 | struct hashtb_enumerator ee; |
| 1208 | struct hashtb_enumerator *e = ⅇ |
| 1209 | |
| 1210 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1211 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1212 | |
| 1213 | for(i=0;i<adj_lsdb_element;i++) |
| 1214 | { |
| 1215 | adj_lsa=e->data; |
| 1216 | |
| 1217 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_router->name); |
| 1218 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1219 | |
| 1220 | char *lst=(char *)malloc(20); |
| 1221 | memset(lst,0,20); |
| 1222 | sprintf(lst,"%d",adj_lsa->header->ls_type); |
| 1223 | ccn_charbuf_append_string(adj_lsdb_data,lst); |
| 1224 | free(lst); |
| 1225 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1226 | |
| 1227 | ccn_charbuf_append_string(adj_lsdb_data,adj_lsa->header->orig_time); |
| 1228 | ccn_charbuf_append_string(adj_lsdb_data,"|"); |
| 1229 | |
| 1230 | hashtb_next(e); |
| 1231 | } |
| 1232 | |
| 1233 | hashtb_end(e); |
| 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | void |
| 1238 | get_lsdb_summary(struct ccn_charbuf *lsdb_data) |
| 1239 | { |
| 1240 | struct ccn_charbuf *name_lsdb_data=ccn_charbuf_create(); |
| 1241 | struct ccn_charbuf *adj_lsdb_data=ccn_charbuf_create(); |
| 1242 | |
| 1243 | get_name_lsdb_summary(name_lsdb_data); |
| 1244 | get_adj_lsdb_summary(adj_lsdb_data); |
| 1245 | |
| 1246 | long int num_lsa=get_name_lsdb_num_element() + get_adj_lsdb_num_element(); |
| 1247 | char *num_element=(char *)malloc(15); |
| 1248 | memset(num_element,0,15); |
| 1249 | sprintf(num_element,"%ld",num_lsa); |
| 1250 | |
| 1251 | if( num_lsa > 0) |
| 1252 | { |
| 1253 | ccn_charbuf_append_string(lsdb_data,num_element); |
| 1254 | ccn_charbuf_append_string(lsdb_data,"|"); |
| 1255 | } |
| 1256 | if(name_lsdb_data->length>0) |
| 1257 | { |
| 1258 | char *data1=ccn_charbuf_as_string(name_lsdb_data); |
| 1259 | ccn_charbuf_append_string(lsdb_data,(char *)data1); |
| 1260 | } |
| 1261 | if(adj_lsdb_data->length>0) |
| 1262 | { |
| 1263 | char *data2=ccn_charbuf_as_string(adj_lsdb_data); |
| 1264 | ccn_charbuf_append_string(lsdb_data,(char *)data2); |
| 1265 | } |
| 1266 | ccn_charbuf_destroy(&name_lsdb_data); |
| 1267 | ccn_charbuf_destroy(&adj_lsdb_data); |
| 1268 | free(num_element); |
| 1269 | |
| 1270 | } |
| 1271 | |
| 1272 | int |
| 1273 | check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time) |
| 1274 | { |
| 1275 | int ret=0; |
| 1276 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1277 | ccn_charbuf_append_string(key,orig_router); |
| 1278 | ccn_charbuf_append_string(key,"/"); |
| 1279 | ccn_charbuf_append_string(key,lst); |
| 1280 | ccn_charbuf_append_string(key,"/"); |
| 1281 | ccn_charbuf_append_string(key,lsid); |
| 1282 | |
| 1283 | int res; |
| 1284 | struct nlsa *name_lsa; |
| 1285 | |
| 1286 | struct hashtb_enumerator ee; |
| 1287 | struct hashtb_enumerator *e = ⅇ |
| 1288 | |
| 1289 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1290 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1291 | |
| 1292 | if( res == HT_NEW_ENTRY ) |
| 1293 | { |
| 1294 | hashtb_delete(e); |
| 1295 | ret=1; |
| 1296 | |
| 1297 | } |
| 1298 | else if(res == HT_OLD_ENTRY) |
| 1299 | { |
| 1300 | name_lsa=e->data; |
| 1301 | if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 ) |
| 1302 | { |
| 1303 | ret=1; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | hashtb_end(e); |
| 1308 | |
| 1309 | ccn_charbuf_destroy(&key); |
| 1310 | |
| 1311 | return ret; |
| 1312 | } |
| 1313 | |
| 1314 | int |
| 1315 | check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time) |
| 1316 | { |
| 1317 | int ret=0; |
| 1318 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1319 | ccn_charbuf_append_string(key,orig_router); |
| 1320 | ccn_charbuf_append_string(key,"/"); |
| 1321 | ccn_charbuf_append_string(key,lst); |
| 1322 | |
| 1323 | int res; |
| 1324 | struct alsa *adj_lsa; |
| 1325 | |
| 1326 | struct hashtb_enumerator ee; |
| 1327 | struct hashtb_enumerator *e = ⅇ |
| 1328 | |
| 1329 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1330 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1331 | |
| 1332 | if( res == HT_NEW_ENTRY ) |
| 1333 | { |
| 1334 | hashtb_delete(e); |
| 1335 | ret=1; |
| 1336 | |
| 1337 | } |
| 1338 | else if(res == HT_OLD_ENTRY) |
| 1339 | { |
| 1340 | adj_lsa=e->data; |
| 1341 | if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 ) |
| 1342 | { |
| 1343 | ret=1; |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | hashtb_end(e); |
| 1348 | |
| 1349 | ccn_charbuf_destroy(&key); |
| 1350 | |
| 1351 | return ret; |
| 1352 | } |
| 1353 | |
| 1354 | void |
| 1355 | get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId) |
| 1356 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1357 | //printf("get_name_lsa_data called \n"); |
| 1358 | if ( nlsr->debugging ) |
| 1359 | printf("get_name_lsa_data called \n"); |
| 1360 | if ( nlsr->detailed_logging ) |
| 1361 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1362 | |
| 1363 | struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 1364 | |
| 1365 | struct hashtb_enumerator ee; |
| 1366 | struct hashtb_enumerator *e = ⅇ |
| 1367 | int res; |
| 1368 | |
| 1369 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1370 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1371 | |
| 1372 | if( res == HT_OLD_ENTRY ) |
| 1373 | { |
| 1374 | name_lsa=e->data; |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1375 | //printf("NAME LSA found\n"); |
| 1376 | |
| 1377 | if ( nlsr->debugging ) |
| 1378 | printf("NAME LSA found \n"); |
| 1379 | if ( nlsr->detailed_logging ) |
| 1380 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1381 | |
| 1382 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 1383 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1384 | |
| 1385 | char *temp_length=(char *)malloc(20); |
| 1386 | memset(temp_length,0,20); |
| 1387 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 1388 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1389 | free(temp_length); |
| 1390 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1391 | |
| 1392 | char *temp_ltype=(char *)malloc(20); |
| 1393 | memset(temp_ltype,0,20); |
| 1394 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 1395 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1396 | free(temp_ltype); |
| 1397 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1398 | |
| 1399 | char *temp_lsid=(char *)malloc(20); |
| 1400 | memset(temp_lsid,0,20); |
| 1401 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 1402 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 1403 | free(temp_lsid); |
| 1404 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1405 | |
| 1406 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time); |
| 1407 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1408 | |
| 1409 | char *temp_valid=(char *)malloc(20); |
| 1410 | memset(temp_valid,0,20); |
| 1411 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 1412 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 1413 | free(temp_valid); |
| 1414 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1415 | |
| 1416 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 1417 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1418 | |
| 1419 | char *temp_npl=(char *)malloc(20); |
| 1420 | memset(temp_npl,0,20); |
| 1421 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 1422 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 1423 | free(temp_npl); |
| 1424 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1425 | |
| 1426 | } |
| 1427 | else if(res == HT_NEW_ENTRY) |
| 1428 | { |
| 1429 | hashtb_delete(e); |
| 1430 | } |
| 1431 | |
| 1432 | hashtb_end(e); |
| 1433 | } |
| 1434 | |
| 1435 | void |
| 1436 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 1437 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1438 | if ( nlsr->debugging ) |
| 1439 | printf("get_adj_lsa_data called \n"); |
| 1440 | if ( nlsr->detailed_logging ) |
| 1441 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1442 | |
| 1443 | struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 1444 | |
| 1445 | struct hashtb_enumerator ee; |
| 1446 | struct hashtb_enumerator *e = ⅇ |
| 1447 | int res; |
| 1448 | |
| 1449 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1450 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1451 | |
| 1452 | if( res == HT_OLD_ENTRY ) |
| 1453 | { |
| 1454 | adj_lsa=e->data; |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1455 | //printf("Adj LSA found\n"); |
| 1456 | |
| 1457 | if ( nlsr->debugging ) |
| 1458 | printf("Adj LSA found \n"); |
| 1459 | if ( nlsr->detailed_logging ) |
| 1460 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1461 | |
| 1462 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 1463 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1464 | |
| 1465 | char *temp_length=(char *)malloc(20); |
| 1466 | memset(temp_length,0,20); |
| 1467 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 1468 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1469 | free(temp_length); |
| 1470 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1471 | |
| 1472 | char *temp_ltype=(char *)malloc(20); |
| 1473 | memset(temp_ltype,0,20); |
| 1474 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 1475 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1476 | free(temp_ltype); |
| 1477 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1478 | |
| 1479 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 1480 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1481 | |
| 1482 | char *temp_nl=(char *)malloc(20); |
| 1483 | memset(temp_nl,0,20); |
| 1484 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 1485 | ccn_charbuf_append_string(lsa_data,temp_nl); |
| 1486 | free(temp_nl); |
| 1487 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1488 | |
| 1489 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 1490 | |
| 1491 | |
| 1492 | } |
| 1493 | else if(res == HT_NEW_ENTRY) |
| 1494 | { |
| 1495 | hashtb_delete(e); |
| 1496 | } |
| 1497 | |
| 1498 | hashtb_end(e); |
| 1499 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1500 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1501 | void |
| 1502 | make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id) |
| 1503 | { |
| 1504 | |
| 1505 | if ( nlsr->debugging ) |
| 1506 | printf("make_name_lsa_invalid called \n"); |
| 1507 | if ( nlsr->detailed_logging ) |
| 1508 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n"); |
| 1509 | |
| 1510 | |
| 1511 | char lst[2]; |
| 1512 | memset(lst,0,2); |
| 1513 | sprintf(lst,"%d",ls_type); |
| 1514 | |
| 1515 | char lsid[10]; |
| 1516 | memset(lsid,0,10); |
| 1517 | sprintf(lsid,"%ld",ls_id); |
| 1518 | |
| 1519 | |
| 1520 | char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1521 | memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1522 | |
| 1523 | |
| 1524 | make_name_lsa_key(key, np->name,ls_type,ls_id); |
| 1525 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 1526 | |
| 1527 | struct nlsa *nlsa; |
| 1528 | |
| 1529 | struct hashtb_enumerator ee; |
| 1530 | struct hashtb_enumerator *e = ⅇ |
| 1531 | |
| 1532 | int res; |
| 1533 | |
| 1534 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1535 | res = hashtb_seek(e, key,strlen(key) , 0); |
| 1536 | |
| 1537 | if( res == HT_OLD_ENTRY ) |
| 1538 | { |
| 1539 | nlsa=e->data; |
| 1540 | |
| 1541 | nlsa->header->isValid=0; |
| 1542 | |
| 1543 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1544 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1545 | write_log_for_name_lsa(nlsa); |
| 1546 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1547 | |
| 1548 | hashtb_delete(e); |
| 1549 | } |
| 1550 | else if( res == HT_NEW_ENTRY ) |
| 1551 | { |
| 1552 | hashtb_delete(e); |
| 1553 | } |
| 1554 | hashtb_end(e); |
| 1555 | |
| 1556 | if ( nlsr->debugging ) |
| 1557 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1558 | if ( nlsr->detailed_logging ) |
| 1559 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1560 | |
| 1561 | set_new_lsdb_version(); |
| 1562 | |
| 1563 | if ( nlsr->debugging ) |
| 1564 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1565 | if ( nlsr->detailed_logging ) |
| 1566 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1567 | |
| 1568 | } |
| 1569 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1570 | int |
| 1571 | delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1572 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1573 | //printf("delete_name_lsa called \n"); |
| 1574 | |
| 1575 | if ( nlsr->debugging ) |
| 1576 | printf("delete_name_lsa called \n"); |
| 1577 | if ( nlsr->detailed_logging ) |
| 1578 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1579 | |
| 1580 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1581 | { |
| 1582 | return -1; |
| 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | nlsr_lock(); |
| 1588 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1589 | if ( nlsr->debugging ) |
| 1590 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1591 | if ( nlsr->detailed_logging ) |
| 1592 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1593 | |
| 1594 | struct nlsa *nlsa; |
| 1595 | |
| 1596 | struct hashtb_enumerator ee; |
| 1597 | struct hashtb_enumerator *e = ⅇ |
| 1598 | |
| 1599 | int res; |
| 1600 | |
| 1601 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1602 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1603 | |
| 1604 | if( res == HT_OLD_ENTRY ) |
| 1605 | { |
| 1606 | nlsa=e->data; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1607 | delete_npt_entry_by_router_and_name_prefix(nlsa->header->orig_router->name, nlsa->name_prefix->name); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1608 | |
| 1609 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1610 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1611 | write_log_for_name_lsa(nlsa); |
| 1612 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1613 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1614 | hashtb_delete(e); |
| 1615 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1616 | else if( res == HT_NEW_ENTRY ) |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1617 | { |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1618 | hashtb_delete(e); |
| 1619 | } |
| 1620 | hashtb_end(e); |
| 1621 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1622 | if ( nlsr->debugging ) |
| 1623 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1624 | if ( nlsr->detailed_logging ) |
| 1625 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1626 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1627 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1628 | |
| 1629 | if ( nlsr->debugging ) |
| 1630 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1631 | if ( nlsr->detailed_logging ) |
| 1632 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1633 | |
| 1634 | //print_name_lsdb(); |
| 1635 | |
| 1636 | nlsr_unlock(); |
| 1637 | |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | int |
| 1642 | delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1643 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1644 | //printf("delete_adj_lsa called \n"); |
| 1645 | |
| 1646 | if ( nlsr->debugging ) |
| 1647 | printf("delete_adj_lsa called \n"); |
| 1648 | if ( nlsr->detailed_logging ) |
| 1649 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1650 | |
| 1651 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1652 | { |
| 1653 | return -1; |
| 1654 | } |
| 1655 | nlsr_lock(); |
| 1656 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1657 | //printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1658 | |
| 1659 | if ( nlsr->debugging ) |
| 1660 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1661 | if ( nlsr->detailed_logging ) |
| 1662 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1663 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1664 | struct alsa *alsa; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1665 | struct hashtb_enumerator ee; |
| 1666 | struct hashtb_enumerator *e = ⅇ |
| 1667 | int res; |
| 1668 | |
| 1669 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1670 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1671 | |
| 1672 | if( res == HT_OLD_ENTRY ) |
| 1673 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1674 | alsa=e->data; |
| 1675 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1676 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1677 | write_log_for_adj_lsa(alsa); |
| 1678 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1679 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1680 | hashtb_delete(e); |
| 1681 | } |
| 1682 | else if( res == HT_OLD_ENTRY ) |
| 1683 | { |
| 1684 | hashtb_delete(e); |
| 1685 | } |
| 1686 | hashtb_end(e); |
| 1687 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1688 | if ( nlsr->debugging ) |
| 1689 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1690 | if ( nlsr->detailed_logging ) |
| 1691 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1692 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1693 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1694 | |
| 1695 | if ( nlsr->debugging ) |
| 1696 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1697 | if ( nlsr->detailed_logging ) |
| 1698 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1699 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1700 | |
| 1701 | if ( !nlsr->is_route_calculation_scheduled) |
| 1702 | { |
| 1703 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1704 | nlsr->is_route_calculation_scheduled=1; |
| 1705 | } |
| 1706 | |
| 1707 | //print_adj_lsdb(); |
| 1708 | |
| 1709 | nlsr_unlock(); |
| 1710 | |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1714 | void |
| 1715 | refresh_name_lsdb(void) |
| 1716 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1717 | //printf("refresh_name_lsdb called \n"); |
| 1718 | |
| 1719 | if ( nlsr->debugging ) |
| 1720 | printf("refresh_name_lsdb called \n"); |
| 1721 | if ( nlsr->detailed_logging ) |
| 1722 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1723 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1724 | //int lsa_change_count=0; |
| 1725 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1726 | char *time_stamp=(char *)malloc(20); |
| 1727 | memset(time_stamp,0,20); |
| 1728 | get_current_timestamp_micro(time_stamp); |
| 1729 | |
| 1730 | long int lsa_life_time; |
| 1731 | |
| 1732 | int i, name_lsdb_element; |
| 1733 | struct nlsa *name_lsa; |
| 1734 | |
| 1735 | struct hashtb_enumerator ee; |
| 1736 | struct hashtb_enumerator *e = ⅇ |
| 1737 | |
| 1738 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1739 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1740 | |
| 1741 | for(i=0;i<name_lsdb_element;i++) |
| 1742 | { |
| 1743 | name_lsa=e->data; |
| 1744 | |
| 1745 | lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1746 | if ( nlsr->debugging ) |
| 1747 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1748 | if ( nlsr->detailed_logging ) |
| 1749 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1750 | |
| 1751 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1752 | { |
| 1753 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1754 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1755 | if ( name_lsa->header->isValid == NAME_LSA_VALID ) |
| 1756 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1757 | if ( nlsr->debugging ) |
| 1758 | printf("Own Name LSA need to be refrshed\n"); |
| 1759 | if ( nlsr->detailed_logging ) |
| 1760 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n"); |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1761 | |
| 1762 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1763 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1764 | write_log_for_name_lsa(name_lsa); |
| 1765 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1766 | |
| 1767 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1768 | char *current_time_stamp=(char *)malloc(20); |
| 1769 | memset(current_time_stamp,0,20); |
| 1770 | get_current_timestamp_micro(current_time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1771 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1772 | free(name_lsa->header->orig_time); |
| 1773 | name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1774 | memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1775 | memcpy(name_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1776 | |
| 1777 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1778 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 1779 | write_log_for_name_lsa(name_lsa); |
| 1780 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1781 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1782 | free(current_time_stamp); |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | char lst[2]; |
| 1787 | memset(lst,0,2); |
| 1788 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1789 | |
| 1790 | char lsid[10]; |
| 1791 | memset(lsid,0,10); |
| 1792 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1793 | |
| 1794 | |
| 1795 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1796 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1797 | |
| 1798 | |
| 1799 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1800 | //printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1801 | |
| 1802 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1803 | } |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1804 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1805 | if ( nlsr->debugging ) |
| 1806 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1807 | if ( nlsr->detailed_logging ) |
| 1808 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1809 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1810 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1811 | |
| 1812 | if ( nlsr->debugging ) |
| 1813 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1814 | if ( nlsr->detailed_logging ) |
| 1815 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1816 | |
| 1817 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1818 | |
| 1819 | print_name_lsdb(); |
| 1820 | //lsa_change_count++; |
| 1821 | } |
| 1822 | } |
| 1823 | else |
| 1824 | { |
| 1825 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1826 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1827 | if ( nlsr->debugging ) |
| 1828 | printf("Others Name LSA need to be deleted\n"); |
| 1829 | if ( nlsr->detailed_logging ) |
| 1830 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1831 | |
| 1832 | char lst[2]; |
| 1833 | memset(lst,0,2); |
| 1834 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1835 | |
| 1836 | char lsid[10]; |
| 1837 | memset(lsid,0,10); |
| 1838 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1839 | |
| 1840 | |
| 1841 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1842 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1843 | |
| 1844 | |
| 1845 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1846 | //printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1847 | |
| 1848 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
| 1849 | //lsa_change_count++; |
| 1850 | } |
| 1851 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1852 | |
| 1853 | hashtb_next(e); |
| 1854 | } |
| 1855 | |
| 1856 | hashtb_end(e); |
| 1857 | |
| 1858 | free(time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1859 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1860 | |
| 1861 | } |
| 1862 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1863 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1864 | refresh_adj_lsdb(void) |
| 1865 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1866 | //printf("refresh_adj_lsdb called \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1867 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1868 | if ( nlsr->debugging ) |
| 1869 | printf("refresh_adj_lsdb called \n"); |
| 1870 | if ( nlsr->detailed_logging ) |
| 1871 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1872 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1873 | char *time_stamp=(char *)malloc(20); |
| 1874 | memset(time_stamp,0,20); |
| 1875 | get_current_timestamp_micro(time_stamp); |
| 1876 | |
| 1877 | long int lsa_life_time; |
| 1878 | |
| 1879 | int i, adj_lsdb_element; |
| 1880 | struct alsa *adj_lsa; |
| 1881 | |
| 1882 | struct hashtb_enumerator ee; |
| 1883 | struct hashtb_enumerator *e = ⅇ |
| 1884 | |
| 1885 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1886 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1887 | |
| 1888 | for(i=0;i<adj_lsdb_element;i++) |
| 1889 | { |
| 1890 | adj_lsa=e->data; |
| 1891 | |
| 1892 | lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1893 | //printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1894 | |
| 1895 | if ( nlsr->debugging ) |
| 1896 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1897 | if ( nlsr->detailed_logging ) |
| 1898 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1899 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1900 | if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1901 | { |
| 1902 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1903 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1904 | //printf("Own Adj LSA need to be refrshed\n"); |
| 1905 | if ( nlsr->debugging ) |
| 1906 | printf("Own Adj LSA need to be refrshed\n"); |
| 1907 | if ( nlsr->detailed_logging ) |
| 1908 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1909 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1910 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1911 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1912 | write_log_for_adj_lsa(adj_lsa); |
| 1913 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1914 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1915 | char *current_time_stamp=(char *)malloc(20); |
| 1916 | memset(current_time_stamp,0,20); |
| 1917 | get_current_timestamp_micro(current_time_stamp); |
| 1918 | |
| 1919 | free(adj_lsa->header->orig_time); |
| 1920 | adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1921 | memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1922 | memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1923 | |
| 1924 | free(current_time_stamp); |
| 1925 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1926 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1927 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 1928 | write_log_for_adj_lsa(adj_lsa); |
| 1929 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1930 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1931 | if ( nlsr->debugging ) |
| 1932 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1933 | if ( nlsr->detailed_logging ) |
| 1934 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1935 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1936 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1937 | |
| 1938 | if ( nlsr->debugging ) |
| 1939 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1940 | if ( nlsr->detailed_logging ) |
| 1941 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1942 | |
| 1943 | print_adj_lsdb(); |
| 1944 | } |
| 1945 | } |
| 1946 | else |
| 1947 | { |
| 1948 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1949 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1950 | //printf("Others Adj LSA need to be deleted\n"); |
| 1951 | |
| 1952 | if ( nlsr->debugging ) |
| 1953 | printf("Others Adj LSA need to be deleted\n"); |
| 1954 | if ( nlsr->detailed_logging ) |
| 1955 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1956 | |
| 1957 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 1958 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 1959 | make_adj_lsa_key(key,adj_lsa); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1960 | //printf("Adjacent LSA key: %s \n",key); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1961 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0); |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | |
| 1966 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1967 | hashtb_next(e); |
| 1968 | } |
| 1969 | |
| 1970 | hashtb_end(e); |
| 1971 | |
| 1972 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | int |
| 1976 | refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1977 | { |
| 1978 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1979 | { |
| 1980 | return -1; |
| 1981 | } |
| 1982 | |
| 1983 | nlsr_lock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1984 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1985 | //printf("refresh_lsdb called \n"); |
| 1986 | |
| 1987 | if ( nlsr->debugging ) |
| 1988 | printf("refresh_lsdb called\n"); |
| 1989 | if ( nlsr->detailed_logging ) |
| 1990 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1991 | |
| 1992 | refresh_name_lsdb(); |
| 1993 | refresh_adj_lsdb(); |
| 1994 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1995 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1996 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1997 | nlsr_unlock(); |
| 1998 | return 0; |
| 1999 | } |