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