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 | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 28 | #include "nlsr_sync.h" |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 29 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 30 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 31 | set_new_lsdb_version(void) |
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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 50 | char lst[2]; |
| 51 | memset(lst,0,2); |
| 52 | sprintf(lst,"%d",ls_type); |
| 53 | |
| 54 | char lsid[10]; |
| 55 | memset(lsid,0,10); |
| 56 | sprintf(lsid,"%ld",ls_id); |
| 57 | |
| 58 | memcpy(key+strlen(key),orig_router,strlen(orig_router)); |
| 59 | memcpy(key+strlen(key),"/",1); |
| 60 | memcpy(key+strlen(key),lst,strlen(lst)); |
| 61 | memcpy(key+strlen(key),"/",1); |
| 62 | memcpy(key+strlen(key),lsid,strlen(lsid)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 63 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 64 | if ( nlsr->debugging ) |
| 65 | printf("name LSA Key: %s\n", key); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void |
| 70 | make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, long int ls_id,char *orig_time,char *slice_prefix) |
| 71 | { |
| 72 | sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type, ls_id, orig_time); |
| 73 | |
| 74 | if ( nlsr->debugging ) |
| 75 | printf("Name LSA prefix for repo content: %s\n",key); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, char *orig_time,char *slice_prefix) |
| 80 | { |
| 81 | |
| 82 | sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time ); |
| 83 | |
| 84 | if ( nlsr->debugging ) |
| 85 | printf("Name LSA prefix for repo content:%s\n",key); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type, char *orig_time,char *slice_prefix) |
| 90 | { |
| 91 | |
| 92 | sprintf(key,"%s%s/lsType.%d/%s",slice_prefix,orig_router,ls_type, orig_time ); |
| 93 | |
| 94 | if ( nlsr->debugging ) |
| 95 | printf("Cor LSA prefix for repo content:%s\n",key); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 96 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 97 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 98 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 99 | build_and_install_name_lsas(void) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 100 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 101 | if ( nlsr->debugging ) |
| 102 | printf("build_and_install_name_lsas called \n"); |
| 103 | if ( nlsr->detailed_logging ) |
| 104 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_name_lsas called\n"); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 105 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 106 | int i, npl_element; |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 107 | struct name_prefix_list_entry *npe; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 108 | |
| 109 | struct hashtb_enumerator ee; |
| 110 | struct hashtb_enumerator *e = ⅇ |
| 111 | |
| 112 | hashtb_start(nlsr->npl, e); |
| 113 | npl_element=hashtb_n(nlsr->npl); |
| 114 | |
| 115 | for(i=0;i<npl_element;i++) |
| 116 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 117 | npe=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 118 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 119 | build_name_lsa(name_lsa,npe->np); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 120 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 121 | install_name_lsa(name_lsa); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 122 | 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] | 123 | free(name_lsa->header->orig_router->name); |
| 124 | free(name_lsa->header->orig_router); |
| 125 | free(name_lsa->header); |
| 126 | free(name_lsa->name_prefix->name); |
| 127 | free(name_lsa->name_prefix); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 128 | free(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 129 | hashtb_next(e); |
| 130 | } |
| 131 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 132 | hashtb_end(e); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 133 | |
| 134 | print_name_prefix_from_npl(); |
| 135 | |
| 136 | } |
| 137 | |
| 138 | void |
| 139 | build_and_install_single_name_lsa(struct name_prefix *np) |
| 140 | { |
| 141 | if ( nlsr->debugging ) |
| 142 | printf("build_and_install_single_name_lsa called \n"); |
| 143 | if ( nlsr->detailed_logging ) |
| 144 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_single_name_lsa called\n"); |
| 145 | |
| 146 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 147 | build_name_lsa(name_lsa,np); |
| 148 | |
| 149 | install_name_lsa(name_lsa); |
| 150 | update_nlsa_id_for_name_in_npl(np,name_lsa->header->ls_id); |
| 151 | |
| 152 | free(name_lsa->header->orig_router->name); |
| 153 | free(name_lsa->header->orig_router); |
| 154 | free(name_lsa->header); |
| 155 | free(name_lsa->name_prefix->name); |
| 156 | free(name_lsa->name_prefix); |
| 157 | free(name_lsa); |
| 158 | |
| 159 | print_name_prefix_from_npl(); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 160 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 161 | } |
| 162 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 163 | void |
| 164 | build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np) |
| 165 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 166 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 167 | name_lsa->header->ls_type=LS_TYPE_NAME; |
| 168 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 169 | char *time_stamp=(char *)malloc(20); |
| 170 | memset(time_stamp,0,20); |
| 171 | get_current_timestamp_micro(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 172 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 173 | name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 174 | memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 175 | memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 176 | |
| 177 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 178 | |
| 179 | name_lsa->header->ls_id=++nlsr->nlsa_id; |
| 180 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 181 | name_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 182 | memset(name_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 183 | memcpy(name_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 184 | name_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 185 | name_lsa->header->isValid=1; |
| 186 | |
| 187 | |
| 188 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 189 | name_lsa->name_prefix->name=(char *)malloc(np->length); |
| 190 | memcpy(name_lsa->name_prefix->name,np->name,np->length); |
| 191 | name_lsa->name_prefix->length=np->length; |
| 192 | |
| 193 | } |
| 194 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 195 | void |
| 196 | install_name_lsa(struct nlsa *name_lsa) |
| 197 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 198 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 199 | char *time_stamp=(char *)malloc(20); |
| 200 | memset(time_stamp,0,20); |
| 201 | get_current_timestamp_micro(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 202 | |
| 203 | |
| 204 | char lst[2]; |
| 205 | memset(lst,0,2); |
| 206 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 207 | |
| 208 | char lsid[10]; |
| 209 | memset(lsid,0,10); |
| 210 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 211 | |
| 212 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 213 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 214 | 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] | 215 | |
| 216 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 217 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 218 | if ( nlsr->debugging ) |
| 219 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
| 220 | if ( nlsr->detailed_logging ) |
| 221 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Key:%s Length:%d\n",key,(int)strlen(key)); |
| 222 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 223 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 224 | struct nlsa *new_name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); //free |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 225 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 226 | struct hashtb_enumerator ee; |
| 227 | struct hashtb_enumerator *e = ⅇ |
| 228 | int res; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 229 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 230 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 231 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 232 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 233 | if(res == HT_NEW_ENTRY ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 234 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 235 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 236 | if ( nlsr->debugging ) |
| 237 | printf("New Name LSA... Adding to LSDB\n"); |
| 238 | if ( nlsr->detailed_logging ) |
| 239 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA... Adding to LSDB\n"); |
| 240 | |
| 241 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 242 | new_name_lsa = e->data; |
| 243 | |
| 244 | new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); //free |
| 245 | new_name_lsa->header->ls_type=name_lsa->header->ls_type; |
| 246 | |
| 247 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 248 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 249 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 250 | |
| 251 | new_name_lsa->header->ls_id=name_lsa->header->ls_id; |
| 252 | new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 253 | new_name_lsa->header->orig_router->name=(char *)malloc(name_lsa->header->orig_router->length); |
| 254 | memcpy(new_name_lsa->header->orig_router->name,name_lsa->header->orig_router->name,name_lsa->header->orig_router->length); |
| 255 | new_name_lsa->header->orig_router->length=name_lsa->header->orig_router->length; |
| 256 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 257 | |
| 258 | |
| 259 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free |
| 260 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 261 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 262 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 263 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 264 | if ( nlsr->debugging ) |
| 265 | { |
| 266 | printf("New Name LSA Added....\n"); |
| 267 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 268 | } |
| 269 | if ( nlsr->detailed_logging ) |
| 270 | { |
| 271 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Name LSA Added....\n"); |
| 272 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 273 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 274 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 275 | if ( nlsr->debugging ) |
| 276 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 277 | if ( nlsr->detailed_logging ) |
| 278 | 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] | 279 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 280 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 281 | 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] | 282 | if ( num_next_hop < 0 ) |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 283 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 284 | 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] | 285 | if ( check == HT_NEW_ENTRY ) |
| 286 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 287 | if ( nlsr->debugging ) |
| 288 | printf("Added in npt \n"); |
| 289 | if ( nlsr->detailed_logging ) |
| 290 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 291 | } |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 292 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 293 | else |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 294 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 295 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 296 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 297 | 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] | 298 | if ( nlsr->debugging ) |
| 299 | { |
| 300 | printf("Printing from install_name_lsa \n"); |
| 301 | int j; |
| 302 | for(j=0;j<num_next_hop;j++) |
| 303 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 304 | } |
| 305 | if ( nlsr->detailed_logging ) |
| 306 | { |
| 307 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 308 | int j; |
| 309 | for(j=0;j<num_next_hop;j++) |
| 310 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 311 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 312 | 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] | 313 | if ( check == HT_NEW_ENTRY ) |
| 314 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 315 | if ( nlsr->debugging ) |
| 316 | printf("Added in npt \n"); |
| 317 | if ( nlsr->detailed_logging ) |
| 318 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 319 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 320 | free(faces); |
| 321 | free(route_costs); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 322 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 323 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 324 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 325 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 326 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 327 | write_log_for_name_lsa(new_name_lsa); |
| 328 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 329 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 330 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 331 | |
| 332 | } |
| 333 | else if(res == HT_OLD_ENTRY) |
| 334 | { |
| 335 | new_name_lsa=e->data; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 336 | 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] | 337 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 338 | if ( nlsr->debugging ) |
| 339 | printf("Older Adj LSA. Discarded... \n"); |
| 340 | if ( nlsr->detailed_logging ) |
| 341 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older Adj LSA. Discarded...\n"); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 342 | } |
| 343 | else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 ) |
| 344 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 345 | if ( nlsr->debugging ) |
| 346 | printf("Duplicate Adj LSA. Discarded... \n"); |
| 347 | if ( nlsr->detailed_logging ) |
| 348 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 349 | } |
| 350 | else |
| 351 | { |
| 352 | if ( name_lsa->header->isValid == 0 ) |
| 353 | { |
| 354 | // have to call to delete npt table entry |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 355 | 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] | 356 | |
| 357 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0) |
| 358 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 359 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 360 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 361 | write_log_for_name_lsa(new_name_lsa); |
| 362 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 363 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 364 | hashtb_delete(e); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 365 | if ( nlsr->debugging ) |
| 366 | printf("isValid bit not set for Router %s so LSA Deleted from LSDB\n",name_lsa->header->orig_router->name); |
| 367 | if ( nlsr->detailed_logging ) |
| 368 | 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] | 369 | } |
| 370 | else |
| 371 | { |
| 372 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 373 | free(new_name_lsa->header->orig_time); |
| 374 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 375 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 376 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 377 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 378 | if ( nlsr->debugging ) |
| 379 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 380 | if ( nlsr->detailed_logging ) |
| 381 | 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] | 382 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 383 | if ( nlsr->debugging ) |
| 384 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 385 | if ( nlsr->detailed_logging ) |
| 386 | 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] | 387 | } |
| 388 | else |
| 389 | { |
| 390 | int is_npt_update=0; |
| 391 | if ( strcmp(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name) != 0 ) |
| 392 | { |
| 393 | is_npt_update=1; |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 394 | 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] | 395 | } |
| 396 | |
| 397 | // copying LSA content with header |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 398 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 399 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 400 | write_log_for_name_lsa(new_name_lsa); |
| 401 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 402 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 403 | |
| 404 | free(new_name_lsa->header->orig_time); |
| 405 | new_name_lsa->header->orig_time=(char *)malloc(strlen(name_lsa->header->orig_time)+1); |
| 406 | memset(new_name_lsa->header->orig_time,0,strlen(name_lsa->header->orig_time)+1); |
| 407 | memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1); |
| 408 | |
| 409 | new_name_lsa->header->isValid=name_lsa->header->isValid; |
| 410 | |
| 411 | free(new_name_lsa->name_prefix->name); |
| 412 | free(new_name_lsa->name_prefix); |
| 413 | new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 414 | new_name_lsa->name_prefix->name=(char *)malloc(name_lsa->name_prefix->length); |
| 415 | memcpy(new_name_lsa->name_prefix->name,name_lsa->name_prefix->name,name_lsa->name_prefix->length); |
| 416 | new_name_lsa->name_prefix->length=name_lsa->name_prefix->length; |
| 417 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 418 | |
| 419 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 420 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 421 | write_log_for_name_lsa(new_name_lsa); |
| 422 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 423 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 424 | if ( nlsr->debugging ) |
| 425 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 426 | if ( nlsr->detailed_logging ) |
| 427 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 428 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 429 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 430 | |
| 431 | if ( nlsr->debugging ) |
| 432 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 433 | if ( nlsr->detailed_logging ) |
| 434 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 435 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 436 | |
| 437 | if( is_npt_update == 1 ) |
| 438 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 439 | //struct hashtb *face_list; |
| 440 | int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name); |
| 441 | if ( num_next_hop < 0 ) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 442 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 443 | |
| 444 | 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] | 445 | if ( check == HT_NEW_ENTRY ) |
| 446 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 447 | if ( nlsr->debugging ) |
| 448 | printf("Added in npt \n"); |
| 449 | if ( nlsr->detailed_logging ) |
| 450 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | else |
| 454 | { |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 455 | int *faces=malloc(num_next_hop*sizeof(int)); |
| 456 | int *route_costs=malloc(num_next_hop*sizeof(int)); |
| 457 | 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] | 458 | |
| 459 | if ( nlsr->debugging ) |
| 460 | { |
| 461 | printf("Printing from install_name_lsa \n"); |
| 462 | int j; |
| 463 | for(j=0;j<num_next_hop;j++) |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 464 | printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 465 | } |
| 466 | if ( nlsr->detailed_logging ) |
| 467 | { |
| 468 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Printing from install_name_lsa \n"); |
| 469 | int j; |
| 470 | for(j=0;j<num_next_hop;j++) |
| 471 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face: %d Route Cost: %d \n",faces[j],route_costs[j]); |
| 472 | } |
| 473 | |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 474 | |
| 475 | 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] | 476 | if ( check == HT_NEW_ENTRY ) |
| 477 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 478 | if ( nlsr->debugging ) |
| 479 | printf("Added in npt \n"); |
| 480 | if ( nlsr->detailed_logging ) |
| 481 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 482 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 483 | free(faces); |
| 484 | free(route_costs); |
| 485 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 486 | } |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 487 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
akmhoque | 3560cb6 | 2012-09-09 10:52:30 -0500 | [diff] [blame] | 492 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 493 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 494 | hashtb_end(e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 495 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 496 | free(key); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 497 | } |
| 498 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 499 | void |
| 500 | write_log_for_name_lsa(struct nlsa *name_lsa) |
| 501 | { |
| 502 | |
| 503 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Name LSA Content---------------\n"); |
| 504 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",name_lsa->header->orig_router->name); |
| 505 | 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] | 506 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",name_lsa->header->ls_type); |
| 507 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Id: %ld\n",name_lsa->header->ls_id); |
| 508 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",name_lsa->header->orig_time); |
| 509 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Is Valid: %d\n",name_lsa->header->isValid); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 510 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LSA Data \n"); |
| 511 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix: %s\n",name_lsa->name_prefix->name); |
| 512 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name Prefix Length: %d\n",name_lsa->name_prefix->length); |
| 513 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 514 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 515 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 516 | void |
| 517 | print_name_lsa(struct nlsa *name_lsa) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 518 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 519 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 520 | if ( nlsr->debugging ) |
| 521 | { |
| 522 | printf("-----------Name LSA Content---------------\n"); |
| 523 | printf(" Origination Router : %s\n",name_lsa->header->orig_router->name); |
| 524 | printf(" Origination Router Length: %d\n",name_lsa->header->orig_router->length); |
| 525 | printf(" LS Type : %d\n",name_lsa->header->ls_type); |
| 526 | printf(" LS Id : %ld\n",name_lsa->header->ls_id); |
| 527 | printf(" Origination Time : %s\n",name_lsa->header->orig_time); |
| 528 | printf(" Is Valid : %d\n",name_lsa->header->isValid); |
| 529 | printf(" LSA Data \n"); |
| 530 | printf(" Name Prefix: : %s\n",name_lsa->name_prefix->name); |
| 531 | printf(" Name Prefix Length : %d\n",name_lsa->name_prefix->length); |
| 532 | |
| 533 | printf("\n"); |
| 534 | } |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void |
| 538 | print_name_lsdb(void) |
| 539 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 540 | if ( nlsr->debugging ) |
| 541 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 542 | int i, name_lsdb_element; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 543 | struct nlsa *name_lsa; |
| 544 | |
| 545 | struct hashtb_enumerator ee; |
| 546 | struct hashtb_enumerator *e = ⅇ |
| 547 | |
| 548 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 549 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 550 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 551 | for(i=0;i<name_lsdb_element;i++) |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 552 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 553 | if ( nlsr->debugging ) |
| 554 | printf("-----------Name LSA (%d)---------------\n",i+1); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 555 | name_lsa=e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 556 | print_name_lsa(name_lsa); |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 557 | hashtb_next(e); |
| 558 | } |
| 559 | |
| 560 | hashtb_end(e); |
| 561 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 562 | if ( nlsr->debugging ) |
| 563 | printf("\n"); |
| 564 | if ( nlsr->detailed_logging ) |
| 565 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 566 | } |
| 567 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 568 | |
| 569 | void |
| 570 | 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] | 571 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 572 | if ( nlsr->debugging ) |
| 573 | printf("build_and_install_others_name_lsa called \n"); |
| 574 | if ( nlsr->detailed_logging ) |
| 575 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 576 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 577 | struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa )); |
| 578 | build_others_name_lsa(name_lsa,orig_router,ls_type,ls_id,orig_time, isValid,np); |
| 579 | print_name_lsa(name_lsa); |
| 580 | install_name_lsa(name_lsa); |
| 581 | print_name_lsdb(); |
akmhoque | de61ba9 | 2012-09-20 22:19:12 -0500 | [diff] [blame] | 582 | print_npt(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 583 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 584 | free(name_lsa->header->orig_router->name); |
| 585 | free(name_lsa->header->orig_router); |
| 586 | free(name_lsa->header); |
| 587 | free(name_lsa->name_prefix->name); |
| 588 | free(name_lsa->name_prefix); |
| 589 | free(name_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 590 | |
| 591 | } |
| 592 | |
| 593 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 594 | 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] | 595 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 596 | if ( nlsr->debugging ) |
| 597 | printf("build_others_name_lsa called\n"); |
| 598 | if ( nlsr->detailed_logging ) |
| 599 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_name_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 600 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 601 | name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header )); |
| 602 | name_lsa->header->ls_type=LS_TYPE_NAME; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 603 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 604 | name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 605 | memset(name_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 606 | memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 607 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 608 | name_lsa->header->ls_id=ls_id; |
| 609 | name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 610 | name_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 611 | memset(name_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 612 | memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 613 | name_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 614 | name_lsa->header->isValid=isValid; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 615 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 616 | name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 617 | name_lsa->name_prefix->name=(char *)malloc(strlen(np)+1); |
| 618 | memset(name_lsa->name_prefix->name,0,strlen(np)+1); |
| 619 | memcpy(name_lsa->name_prefix->name,np,strlen(np)+1); |
| 620 | name_lsa->name_prefix->length=strlen(np)+1; |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 621 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 622 | |
| 623 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 624 | void |
| 625 | make_cor_lsa_key(char *key,struct clsa *cor_lsa) |
| 626 | { |
| 627 | memcpy(key+strlen(key),cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->length); |
| 628 | memcpy(key+strlen(key),"/",1); |
| 629 | char ls_type[2]; |
| 630 | sprintf(ls_type,"%d",cor_lsa->header->ls_type); |
| 631 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 632 | key[strlen(key)]='\0'; |
| 633 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 634 | |
| 635 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 636 | void |
| 637 | make_adj_lsa_key(char *key,struct alsa *adj_lsa) |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 638 | { |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 639 | memcpy(key+strlen(key),adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 640 | memcpy(key+strlen(key),"/",1); |
| 641 | char ls_type[2]; |
| 642 | sprintf(ls_type,"%d",adj_lsa->header->ls_type); |
| 643 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 644 | key[strlen(key)]='\0'; |
| 645 | } |
| 646 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 647 | int |
| 648 | build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 649 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 650 | if(flags == CCN_SCHEDULE_CANCEL) |
| 651 | { |
| 652 | return -1; |
| 653 | } |
| 654 | |
| 655 | nlsr_lock(); |
| 656 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 657 | if ( nlsr->debugging ) |
| 658 | printf("build_and_install_adj_lsa called \n"); |
| 659 | if ( nlsr->detailed_logging ) |
| 660 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_adj_lsa called \n"); |
| 661 | |
| 662 | if ( nlsr->debugging ) |
| 663 | printf("adj_build_flag = %d \n",nlsr->adj_build_flag); |
| 664 | if ( nlsr->detailed_logging ) |
| 665 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"adj_build_flag = %d \n",nlsr->adj_build_flag); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 666 | |
| 667 | if(nlsr->adj_build_flag > 0) |
| 668 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 669 | if ( nlsr->debugging ) |
| 670 | printf("is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 671 | if ( nlsr->detailed_logging ) |
| 672 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"is_adj_lsa_build = %d \n",is_adj_lsa_build()); |
| 673 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 674 | if ( is_adj_lsa_build()> 0) |
| 675 | { |
| 676 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 677 | build_adj_lsa(adj_lsa); |
| 678 | install_adj_lsa(adj_lsa); |
| 679 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 680 | char lst[2]; |
| 681 | memset(lst,0,2); |
| 682 | sprintf(lst,"%d",LS_TYPE_ADJ); |
| 683 | |
| 684 | char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15); |
| 685 | memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(adj_lsa->header->orig_time)+strlen(adj_lsa->header->orig_router->name) + strlen(lst) + 5+15); |
| 686 | make_adj_lsa_prefix_for_repo(repo_key, adj_lsa->header->orig_router->name,LS_TYPE_ADJ,adj_lsa->header->orig_time,nlsr->slice_prefix); |
| 687 | |
| 688 | if ( nlsr->debugging ) |
| 689 | printf("Adj LSA Repo Key: %s \n",repo_key); |
| 690 | |
| 691 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 692 | memset(key,0,adj_lsa->header->orig_router->length+2+2); |
| 693 | make_adj_lsa_key(key,adj_lsa); |
| 694 | if ( nlsr->debugging ) |
| 695 | printf("Adj LSA: %s \n",key); |
| 696 | |
| 697 | struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix)); |
| 698 | lsaid->name=(char *)malloc(strlen(key)+1); |
| 699 | memset(lsaid->name, 0, strlen(key)+1); |
| 700 | memcpy(lsaid->name,key,strlen(key)); |
| 701 | lsaid->length=strlen(key)+1; |
| 702 | |
| 703 | |
| 704 | write_adj_lsa_to_repo(repo_key, lsaid); |
| 705 | |
| 706 | free(key); |
| 707 | free(repo_key); |
| 708 | free(lsaid->name); |
| 709 | free(lsaid); |
| 710 | |
| 711 | |
| 712 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 713 | free(adj_lsa->header->orig_router->name); |
| 714 | free(adj_lsa->header->orig_router); |
| 715 | free(adj_lsa->header->orig_time); |
| 716 | free(adj_lsa->header); |
| 717 | free(adj_lsa->body); |
| 718 | free(adj_lsa); |
| 719 | nlsr->adj_build_flag=0; |
| 720 | print_adj_lsdb(); |
| 721 | } |
| 722 | else |
| 723 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 724 | if ( nlsr->debugging ) |
| 725 | printf("Can not build adj LSA now\n"); |
| 726 | if ( nlsr->detailed_logging ) |
| 727 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Can not build adj LSA now\n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | nlsr->is_build_adj_lsa_sheduled=0; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 731 | |
| 732 | nlsr_unlock(); |
| 733 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | |
| 738 | void |
| 739 | build_adj_lsa(struct alsa * adj_lsa) |
| 740 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 741 | if ( nlsr->debugging ) |
| 742 | printf("build_adj_lsa called \n"); |
| 743 | if ( nlsr->detailed_logging ) |
| 744 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 745 | |
| 746 | int no_link=no_active_nbr(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 747 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 748 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 749 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 750 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 751 | memset(adj_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 752 | memcpy(adj_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 753 | adj_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 754 | |
| 755 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
| 756 | |
| 757 | char *time_stamp=(char *)malloc(20); |
| 758 | memset(time_stamp,0,20); |
| 759 | get_current_timestamp_micro(time_stamp); |
| 760 | |
| 761 | adj_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); |
| 762 | memset(adj_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 763 | memcpy(adj_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 764 | free(time_stamp); |
| 765 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 766 | adj_lsa->no_link=no_link; |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 767 | |
| 768 | |
| 769 | struct ccn_charbuf *c=ccn_charbuf_create(); |
| 770 | get_active_nbr_adj_data(c); |
| 771 | char *data=ccn_charbuf_as_string(c); |
| 772 | |
| 773 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 774 | memset(adj_lsa->body,0,strlen(data)+1); |
| 775 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
| 776 | ccn_charbuf_destroy(&c); |
| 777 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 778 | nlsr->adj_build_count++; |
| 779 | |
| 780 | |
| 781 | } |
| 782 | |
| 783 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 784 | void |
| 785 | install_adj_lsa(struct alsa * adj_lsa) |
| 786 | { |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 787 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 788 | if ( nlsr->debugging ) |
| 789 | printf("install_adj_lsa called \n"); |
| 790 | if ( nlsr->detailed_logging ) |
| 791 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_adj_lsa called \n"); |
| 792 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 793 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 794 | char *time_stamp=(char *)malloc(20); |
| 795 | memset(time_stamp,0,20); |
| 796 | get_current_timestamp_micro(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 797 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 798 | |
| 799 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 800 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 801 | make_adj_lsa_key(key,adj_lsa); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 802 | |
| 803 | struct alsa *new_adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 804 | |
| 805 | struct hashtb_enumerator ee; |
| 806 | struct hashtb_enumerator *e = ⅇ |
| 807 | int res; |
| 808 | |
| 809 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 810 | res = hashtb_seek(e, key, strlen(key), 0); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 811 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 812 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 813 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 814 | if(res == HT_NEW_ENTRY) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 815 | { |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 816 | if ( adj_lsa->no_link > 0) |
| 817 | { |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 818 | if ( nlsr->debugging ) |
| 819 | printf("New ADJ LSA... Adding to LSDB\n"); |
| 820 | if ( nlsr->detailed_logging ) |
| 821 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New ADJ LSA... Adding to LSDB\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 822 | new_adj_lsa = e->data; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 823 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 824 | new_adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 825 | new_adj_lsa->header->ls_type=adj_lsa->header->ls_type; |
| 826 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 827 | 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] | 828 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 829 | new_adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 830 | new_adj_lsa->header->orig_router->name=(char *)malloc(adj_lsa->header->orig_router->length); |
| 831 | memcpy(new_adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->name,adj_lsa->header->orig_router->length); |
| 832 | new_adj_lsa->header->orig_router->length=adj_lsa->header->orig_router->length; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 833 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 834 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 835 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 836 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 837 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 838 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 839 | |
| 840 | add_next_hop_router(new_adj_lsa->header->orig_router->name); |
| 841 | 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] | 842 | |
| 843 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 844 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 845 | write_log_for_adj_lsa(new_adj_lsa); |
| 846 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 847 | } |
| 848 | else |
| 849 | { |
| 850 | hashtb_delete(e); |
| 851 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 852 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 853 | if ( nlsr->debugging ) |
| 854 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 855 | if ( nlsr->detailed_logging ) |
| 856 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 857 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 858 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 859 | |
| 860 | if ( nlsr->debugging ) |
| 861 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 862 | if ( nlsr->detailed_logging ) |
| 863 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 864 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 865 | } |
| 866 | else if(res == HT_OLD_ENTRY) |
| 867 | { |
| 868 | new_adj_lsa = e->data; |
| 869 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 870 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 871 | if ( nlsr->debugging ) |
| 872 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 873 | if ( nlsr->detailed_logging ) |
| 874 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 875 | } |
| 876 | else |
| 877 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 878 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 879 | if ( adj_lsa->no_link > 0) |
| 880 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 881 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 882 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 883 | write_log_for_adj_lsa(new_adj_lsa); |
| 884 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 885 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 886 | free(new_adj_lsa->header->orig_time); |
| 887 | new_adj_lsa->header->orig_time=(char *)malloc(strlen(adj_lsa->header->orig_time)+1); |
| 888 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 889 | |
| 890 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 891 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 892 | new_adj_lsa->body=(char *)malloc(strlen(adj_lsa->body)+1); |
| 893 | memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
| 894 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 895 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 896 | 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] | 897 | |
| 898 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 899 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 900 | write_log_for_adj_lsa(new_adj_lsa); |
| 901 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 902 | } |
| 903 | else |
| 904 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 905 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 906 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 907 | write_log_for_adj_lsa(new_adj_lsa); |
| 908 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 909 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 910 | hashtb_delete(e); |
| 911 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 912 | |
| 913 | if ( nlsr->debugging ) |
| 914 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 915 | if ( nlsr->detailed_logging ) |
| 916 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 917 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 918 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 919 | |
| 920 | if ( nlsr->debugging ) |
| 921 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 922 | if ( nlsr->detailed_logging ) |
| 923 | 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] | 924 | } |
| 925 | |
| 926 | } |
| 927 | hashtb_end(e); |
| 928 | |
| 929 | if ( !nlsr->is_route_calculation_scheduled ) |
| 930 | { |
| 931 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 932 | nlsr->is_route_calculation_scheduled=1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 933 | } |
| 934 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 935 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 936 | free(key); |
| 937 | |
| 938 | free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | void |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 942 | write_log_for_adj_lsa_body(const char *body, int no_link) |
| 943 | { |
| 944 | int i=0; |
| 945 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 946 | memset( lsa_data,0,strlen(body)+1); |
| 947 | memcpy(lsa_data,body,strlen(body)+1); |
| 948 | char *sep="|"; |
| 949 | char *rem; |
| 950 | char *rtr_id; |
| 951 | char *length; |
| 952 | char *face; |
| 953 | char *metric; |
| 954 | |
| 955 | if(no_link >0 ) |
| 956 | { |
| 957 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 958 | length=strtok_r(NULL,sep,&rem); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 959 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 960 | metric=strtok_r(NULL,sep,&rem); |
| 961 | |
| 962 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 963 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 964 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 965 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 966 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 967 | |
| 968 | |
| 969 | for(i=1;i<no_link;i++) |
| 970 | { |
| 971 | rtr_id=strtok_r(NULL,sep,&rem); |
| 972 | length=strtok_r(NULL,sep,&rem); |
| 973 | face=strtok_r(NULL,sep,&rem); |
| 974 | metric=strtok_r(NULL,sep,&rem); |
| 975 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 976 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 977 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 978 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 979 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 980 | |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | free(lsa_data); |
| 985 | } |
| 986 | |
| 987 | |
| 988 | void |
| 989 | write_log_for_adj_lsa(struct alsa * adj_lsa) |
| 990 | { |
| 991 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 992 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name); |
| 993 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 994 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type); |
| 995 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 996 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 997 | writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 998 | |
| 999 | write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1000 | |
| 1001 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 1002 | |
| 1003 | } |
| 1004 | |
| 1005 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1006 | print_adj_lsa_body(const char *body, int no_link) |
| 1007 | { |
| 1008 | int i=0; |
| 1009 | char *lsa_data=(char *)malloc(strlen(body)+1); |
| 1010 | memset( lsa_data,0,strlen(body)+1); |
| 1011 | memcpy(lsa_data,body,strlen(body)+1); |
| 1012 | char *sep="|"; |
| 1013 | char *rem; |
| 1014 | char *rtr_id; |
| 1015 | char *length; |
| 1016 | char *face; |
| 1017 | char *metric; |
| 1018 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1019 | if(no_link >0 ) |
| 1020 | { |
| 1021 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 1022 | length=strtok_r(NULL,sep,&rem); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1023 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1024 | metric=strtok_r(NULL,sep,&rem); |
| 1025 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1026 | if ( nlsr->debugging ) { |
| 1027 | printf(" Link %d \n",i+1); |
| 1028 | printf(" Neighbor : %s \n",rtr_id); |
| 1029 | printf(" Neighbor Length : %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1030 | //printf(" Connecting Face : %s \n",face); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1031 | printf(" Metric : %s \n",metric); |
| 1032 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1033 | |
| 1034 | for(i=1;i<no_link;i++) |
| 1035 | { |
| 1036 | rtr_id=strtok_r(NULL,sep,&rem); |
| 1037 | length=strtok_r(NULL,sep,&rem); |
| 1038 | face=strtok_r(NULL,sep,&rem); |
| 1039 | metric=strtok_r(NULL,sep,&rem); |
| 1040 | printf(" Link %d \n",i+1); |
| 1041 | printf(" Neighbor : %s \n",rtr_id); |
| 1042 | printf(" Neighbor Length : %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1043 | //printf(" Connecting Face : %s \n",face); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1044 | printf(" Metric : %s \n",metric); |
| 1045 | |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | free(lsa_data); |
| 1050 | } |
| 1051 | |
| 1052 | void |
| 1053 | print_adj_lsa(struct alsa * adj_lsa) |
| 1054 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1055 | if ( nlsr->debugging ) |
| 1056 | { |
| 1057 | printf("-----------ADJ LSA Content---------------\n"); |
| 1058 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 1059 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 1060 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 1061 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
| 1062 | printf(" Lsa Data:\n"); |
| 1063 | printf(" No of Link : %d\n",adj_lsa->no_link); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1064 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1065 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1066 | printf("\n"); |
| 1067 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1068 | |
| 1069 | } |
| 1070 | |
| 1071 | void |
| 1072 | print_adj_lsdb(void) |
| 1073 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1074 | if ( nlsr->debugging ) |
| 1075 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1076 | int i, adj_lsdb_element; |
| 1077 | struct alsa *adj_lsa; |
| 1078 | |
| 1079 | struct hashtb_enumerator ee; |
| 1080 | struct hashtb_enumerator *e = ⅇ |
| 1081 | |
| 1082 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1083 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1084 | |
| 1085 | for(i=0;i<adj_lsdb_element;i++) |
| 1086 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1087 | if ( nlsr->debugging ) |
| 1088 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1089 | adj_lsa=e->data; |
| 1090 | print_adj_lsa(adj_lsa); |
| 1091 | hashtb_next(e); |
| 1092 | } |
| 1093 | |
| 1094 | hashtb_end(e); |
| 1095 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1096 | if ( nlsr->debugging ) |
| 1097 | printf("\n"); |
| 1098 | if ( nlsr->detailed_logging ) |
| 1099 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1103 | 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] | 1104 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1105 | if ( nlsr->debugging ) |
| 1106 | printf("build_and_install_others_adj_lsa called \n"); |
| 1107 | if ( nlsr->detailed_logging ) |
| 1108 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1109 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 1110 | build_others_adj_lsa(adj_lsa,orig_router,ls_type,orig_time,no_link,data); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1111 | install_adj_lsa(adj_lsa); |
| 1112 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1113 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1114 | free(adj_lsa->header->orig_router->name); |
| 1115 | free(adj_lsa->header->orig_router); |
| 1116 | free(adj_lsa->header->orig_time); |
| 1117 | free(adj_lsa->header); |
| 1118 | free(adj_lsa->body); |
| 1119 | free(adj_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1120 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1121 | print_adj_lsdb(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1122 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1123 | } |
| 1124 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1125 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1126 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1127 | 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] | 1128 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1129 | if ( nlsr->debugging ) |
| 1130 | printf("build_others_adj_lsa called \n"); |
| 1131 | if ( nlsr->detailed_logging ) |
| 1132 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1133 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1134 | /*Filling Up Header Data */ |
| 1135 | adj_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 1136 | adj_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 1137 | adj_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 1138 | memset(adj_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 1139 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1140 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1141 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1142 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1143 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1144 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1145 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1146 | adj_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 1147 | memset(adj_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 1148 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1149 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1150 | adj_lsa->no_link=no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1151 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1152 | adj_lsa->body=(char *)malloc(strlen(data)+1); |
| 1153 | memset(adj_lsa->body,0,strlen(data)+1); |
| 1154 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1155 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1156 | } |
| 1157 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1158 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1159 | long int |
| 1160 | get_name_lsdb_num_element(void) |
| 1161 | { |
| 1162 | long int num_element; |
| 1163 | |
| 1164 | |
| 1165 | struct hashtb_enumerator ee; |
| 1166 | struct hashtb_enumerator *e = ⅇ |
| 1167 | |
| 1168 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1169 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1170 | hashtb_end(e); |
| 1171 | |
| 1172 | return num_element; |
| 1173 | } |
| 1174 | |
| 1175 | long int |
| 1176 | get_adj_lsdb_num_element(void) |
| 1177 | { |
| 1178 | long int num_element; |
| 1179 | |
| 1180 | |
| 1181 | struct hashtb_enumerator ee; |
| 1182 | struct hashtb_enumerator *e = ⅇ |
| 1183 | |
| 1184 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1185 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1186 | hashtb_end(e); |
| 1187 | |
| 1188 | return num_element; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1189 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1190 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1191 | |
| 1192 | int |
| 1193 | check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time) |
| 1194 | { |
| 1195 | int ret=0; |
| 1196 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1197 | ccn_charbuf_append_string(key,orig_router); |
| 1198 | ccn_charbuf_append_string(key,"/"); |
| 1199 | ccn_charbuf_append_string(key,lst); |
| 1200 | ccn_charbuf_append_string(key,"/"); |
| 1201 | ccn_charbuf_append_string(key,lsid); |
| 1202 | |
| 1203 | int res; |
| 1204 | struct nlsa *name_lsa; |
| 1205 | |
| 1206 | struct hashtb_enumerator ee; |
| 1207 | struct hashtb_enumerator *e = ⅇ |
| 1208 | |
| 1209 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1210 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1211 | |
| 1212 | if( res == HT_NEW_ENTRY ) |
| 1213 | { |
| 1214 | hashtb_delete(e); |
| 1215 | ret=1; |
| 1216 | |
| 1217 | } |
| 1218 | else if(res == HT_OLD_ENTRY) |
| 1219 | { |
| 1220 | name_lsa=e->data; |
| 1221 | if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 ) |
| 1222 | { |
| 1223 | ret=1; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | hashtb_end(e); |
| 1228 | |
| 1229 | ccn_charbuf_destroy(&key); |
| 1230 | |
| 1231 | return ret; |
| 1232 | } |
| 1233 | |
| 1234 | int |
| 1235 | check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time) |
| 1236 | { |
| 1237 | int ret=0; |
| 1238 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1239 | ccn_charbuf_append_string(key,orig_router); |
| 1240 | ccn_charbuf_append_string(key,"/"); |
| 1241 | ccn_charbuf_append_string(key,lst); |
| 1242 | |
| 1243 | int res; |
| 1244 | struct alsa *adj_lsa; |
| 1245 | |
| 1246 | struct hashtb_enumerator ee; |
| 1247 | struct hashtb_enumerator *e = ⅇ |
| 1248 | |
| 1249 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1250 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1251 | |
| 1252 | if( res == HT_NEW_ENTRY ) |
| 1253 | { |
| 1254 | hashtb_delete(e); |
| 1255 | ret=1; |
| 1256 | |
| 1257 | } |
| 1258 | else if(res == HT_OLD_ENTRY) |
| 1259 | { |
| 1260 | adj_lsa=e->data; |
| 1261 | if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 ) |
| 1262 | { |
| 1263 | ret=1; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | hashtb_end(e); |
| 1268 | |
| 1269 | ccn_charbuf_destroy(&key); |
| 1270 | |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1274 | int |
| 1275 | check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time) |
| 1276 | { |
| 1277 | int ret=0; |
| 1278 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1279 | ccn_charbuf_append_string(key,orig_router); |
| 1280 | ccn_charbuf_append_string(key,"/"); |
| 1281 | ccn_charbuf_append_string(key,lst); |
| 1282 | |
| 1283 | int res; |
| 1284 | struct clsa *cor_lsa; |
| 1285 | |
| 1286 | struct hashtb_enumerator ee; |
| 1287 | struct hashtb_enumerator *e = ⅇ |
| 1288 | |
| 1289 | hashtb_start(nlsr->lsdb->cor_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 | cor_lsa=e->data; |
| 1301 | if( strcmp ( orig_time , cor_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 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1314 | void |
| 1315 | get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId) |
| 1316 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1317 | if ( nlsr->debugging ) |
| 1318 | printf("get_name_lsa_data called \n"); |
| 1319 | if ( nlsr->detailed_logging ) |
| 1320 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1321 | |
| 1322 | struct nlsa *name_lsa=(struct nlsa*)malloc(sizeof(struct nlsa )); |
| 1323 | |
| 1324 | struct hashtb_enumerator ee; |
| 1325 | struct hashtb_enumerator *e = ⅇ |
| 1326 | int res; |
| 1327 | |
| 1328 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1329 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1330 | |
| 1331 | if( res == HT_OLD_ENTRY ) |
| 1332 | { |
| 1333 | name_lsa=e->data; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1334 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1335 | if ( nlsr->debugging ) |
| 1336 | printf("NAME LSA found \n"); |
| 1337 | if ( nlsr->detailed_logging ) |
| 1338 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1339 | |
| 1340 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 1341 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1342 | |
| 1343 | char *temp_length=(char *)malloc(20); |
| 1344 | memset(temp_length,0,20); |
| 1345 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 1346 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1347 | free(temp_length); |
| 1348 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1349 | |
| 1350 | char *temp_ltype=(char *)malloc(20); |
| 1351 | memset(temp_ltype,0,20); |
| 1352 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 1353 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1354 | free(temp_ltype); |
| 1355 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1356 | |
| 1357 | char *temp_lsid=(char *)malloc(20); |
| 1358 | memset(temp_lsid,0,20); |
| 1359 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 1360 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 1361 | free(temp_lsid); |
| 1362 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1363 | |
| 1364 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time); |
| 1365 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1366 | |
| 1367 | char *temp_valid=(char *)malloc(20); |
| 1368 | memset(temp_valid,0,20); |
| 1369 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 1370 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 1371 | free(temp_valid); |
| 1372 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1373 | |
| 1374 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 1375 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1376 | |
| 1377 | char *temp_npl=(char *)malloc(20); |
| 1378 | memset(temp_npl,0,20); |
| 1379 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 1380 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 1381 | free(temp_npl); |
| 1382 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1383 | |
| 1384 | } |
| 1385 | else if(res == HT_NEW_ENTRY) |
| 1386 | { |
| 1387 | hashtb_delete(e); |
| 1388 | } |
| 1389 | |
| 1390 | hashtb_end(e); |
| 1391 | } |
| 1392 | |
| 1393 | void |
| 1394 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 1395 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1396 | if ( nlsr->debugging ) |
| 1397 | printf("get_adj_lsa_data called \n"); |
| 1398 | if ( nlsr->detailed_logging ) |
| 1399 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1400 | |
| 1401 | struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa )); |
| 1402 | |
| 1403 | struct hashtb_enumerator ee; |
| 1404 | struct hashtb_enumerator *e = ⅇ |
| 1405 | int res; |
| 1406 | |
| 1407 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1408 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1409 | |
| 1410 | if( res == HT_OLD_ENTRY ) |
| 1411 | { |
| 1412 | adj_lsa=e->data; |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1413 | |
| 1414 | if ( nlsr->debugging ) |
| 1415 | printf("Adj LSA found \n"); |
| 1416 | if ( nlsr->detailed_logging ) |
| 1417 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1418 | |
| 1419 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 1420 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1421 | |
| 1422 | char *temp_length=(char *)malloc(20); |
| 1423 | memset(temp_length,0,20); |
| 1424 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 1425 | ccn_charbuf_append_string(lsa_data,temp_length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1426 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1427 | free(temp_length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1428 | |
| 1429 | char *temp_ltype=(char *)malloc(20); |
| 1430 | memset(temp_ltype,0,20); |
| 1431 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 1432 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1433 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1434 | free(temp_ltype); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1435 | |
| 1436 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 1437 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1438 | |
| 1439 | char *temp_nl=(char *)malloc(20); |
| 1440 | memset(temp_nl,0,20); |
| 1441 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 1442 | ccn_charbuf_append_string(lsa_data,temp_nl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1443 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1444 | free(temp_nl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1445 | |
| 1446 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 1447 | |
| 1448 | |
| 1449 | } |
| 1450 | else if(res == HT_NEW_ENTRY) |
| 1451 | { |
| 1452 | hashtb_delete(e); |
| 1453 | } |
| 1454 | |
| 1455 | hashtb_end(e); |
| 1456 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1457 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1458 | void |
| 1459 | make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id) |
| 1460 | { |
| 1461 | |
| 1462 | if ( nlsr->debugging ) |
| 1463 | printf("make_name_lsa_invalid called \n"); |
| 1464 | if ( nlsr->detailed_logging ) |
| 1465 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n"); |
| 1466 | |
| 1467 | |
| 1468 | char lst[2]; |
| 1469 | memset(lst,0,2); |
| 1470 | sprintf(lst,"%d",ls_type); |
| 1471 | |
| 1472 | char lsid[10]; |
| 1473 | memset(lsid,0,10); |
| 1474 | sprintf(lsid,"%ld",ls_id); |
| 1475 | |
| 1476 | |
| 1477 | char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1478 | memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1479 | |
| 1480 | |
| 1481 | make_name_lsa_key(key, np->name,ls_type,ls_id); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1482 | |
| 1483 | if ( nlsr->debugging ) |
| 1484 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1485 | |
| 1486 | struct nlsa *nlsa; |
| 1487 | |
| 1488 | struct hashtb_enumerator ee; |
| 1489 | struct hashtb_enumerator *e = ⅇ |
| 1490 | |
| 1491 | int res; |
| 1492 | |
| 1493 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1494 | res = hashtb_seek(e, key,strlen(key) , 0); |
| 1495 | |
| 1496 | if( res == HT_OLD_ENTRY ) |
| 1497 | { |
| 1498 | nlsa=e->data; |
| 1499 | |
| 1500 | nlsa->header->isValid=0; |
| 1501 | |
| 1502 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1503 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1504 | write_log_for_name_lsa(nlsa); |
| 1505 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1506 | |
| 1507 | hashtb_delete(e); |
| 1508 | } |
| 1509 | else if( res == HT_NEW_ENTRY ) |
| 1510 | { |
| 1511 | hashtb_delete(e); |
| 1512 | } |
| 1513 | hashtb_end(e); |
| 1514 | |
| 1515 | if ( nlsr->debugging ) |
| 1516 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1517 | if ( nlsr->detailed_logging ) |
| 1518 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1519 | |
| 1520 | set_new_lsdb_version(); |
| 1521 | |
| 1522 | if ( nlsr->debugging ) |
| 1523 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1524 | if ( nlsr->detailed_logging ) |
| 1525 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1526 | |
| 1527 | } |
| 1528 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1529 | //int |
| 1530 | //delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1531 | int |
| 1532 | delete_name_lsa(char *orig_router, char *name_prefix) |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1533 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1534 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1535 | if ( nlsr->debugging ) |
| 1536 | printf("delete_name_lsa called \n"); |
| 1537 | if ( nlsr->detailed_logging ) |
| 1538 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1539 | /* |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1540 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1541 | { |
| 1542 | return -1; |
| 1543 | } |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | nlsr_lock(); |
| 1548 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1549 | if ( nlsr->debugging ) |
| 1550 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1551 | if ( nlsr->detailed_logging ) |
| 1552 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1553 | |
| 1554 | struct nlsa *nlsa; |
| 1555 | |
| 1556 | struct hashtb_enumerator ee; |
| 1557 | struct hashtb_enumerator *e = ⅇ |
| 1558 | |
| 1559 | int res; |
| 1560 | |
| 1561 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1562 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1563 | |
| 1564 | if( res == HT_OLD_ENTRY ) |
| 1565 | { |
| 1566 | nlsa=e->data; |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1567 | */ |
| 1568 | delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix); |
| 1569 | /* |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1570 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1571 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1572 | write_log_for_name_lsa(nlsa); |
| 1573 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1574 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1575 | hashtb_delete(e); |
| 1576 | } |
akmhoque | 3cced64 | 2012-09-24 16:20:20 -0500 | [diff] [blame] | 1577 | else if( res == HT_NEW_ENTRY ) |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1578 | { |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1579 | hashtb_delete(e); |
| 1580 | } |
| 1581 | hashtb_end(e); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1582 | */ |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1583 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1584 | if ( nlsr->debugging ) |
| 1585 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1586 | if ( nlsr->detailed_logging ) |
| 1587 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1588 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1589 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1590 | |
| 1591 | if ( nlsr->debugging ) |
| 1592 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1593 | if ( nlsr->detailed_logging ) |
| 1594 | 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] | 1595 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1596 | //nlsr_unlock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1597 | |
| 1598 | return 0; |
| 1599 | } |
| 1600 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1601 | //int |
| 1602 | //delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1603 | int delete_adj_lsa() |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1604 | { |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1605 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1606 | if ( nlsr->debugging ) |
| 1607 | printf("delete_adj_lsa called \n"); |
| 1608 | if ( nlsr->detailed_logging ) |
| 1609 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1610 | |
| 1611 | /* |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1612 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1613 | { |
| 1614 | return -1; |
| 1615 | } |
| 1616 | nlsr_lock(); |
| 1617 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1618 | if ( nlsr->debugging ) |
| 1619 | printf("LSA Key: %s \n",(char *)ev->evdata); |
| 1620 | if ( nlsr->detailed_logging ) |
| 1621 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Key: %s \n",(char *)ev->evdata); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1622 | |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1623 | struct alsa *alsa; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1624 | struct hashtb_enumerator ee; |
| 1625 | struct hashtb_enumerator *e = ⅇ |
| 1626 | int res; |
| 1627 | |
| 1628 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1629 | res = hashtb_seek(e, (char *)ev->evdata, strlen((char *)ev->evdata), 0); |
| 1630 | |
| 1631 | if( res == HT_OLD_ENTRY ) |
| 1632 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1633 | alsa=e->data; |
| 1634 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1635 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1636 | write_log_for_adj_lsa(alsa); |
| 1637 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1638 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1639 | hashtb_delete(e); |
| 1640 | } |
| 1641 | else if( res == HT_OLD_ENTRY ) |
| 1642 | { |
| 1643 | hashtb_delete(e); |
| 1644 | } |
| 1645 | hashtb_end(e); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1646 | */ |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1647 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1648 | if ( nlsr->debugging ) |
| 1649 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1650 | if ( nlsr->detailed_logging ) |
| 1651 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1652 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1653 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1654 | |
| 1655 | if ( nlsr->debugging ) |
| 1656 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1657 | if ( nlsr->detailed_logging ) |
| 1658 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1659 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1660 | |
| 1661 | if ( !nlsr->is_route_calculation_scheduled) |
| 1662 | { |
| 1663 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1664 | nlsr->is_route_calculation_scheduled=1; |
| 1665 | } |
| 1666 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1667 | //nlsr_unlock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1668 | |
| 1669 | return 0; |
| 1670 | } |
| 1671 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1672 | void |
| 1673 | refresh_name_lsdb(void) |
| 1674 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1675 | if ( nlsr->debugging ) |
| 1676 | printf("refresh_name_lsdb called \n"); |
| 1677 | if ( nlsr->detailed_logging ) |
| 1678 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1679 | |
| 1680 | char *time_stamp=(char *)malloc(20); |
| 1681 | memset(time_stamp,0,20); |
| 1682 | get_current_timestamp_micro(time_stamp); |
| 1683 | |
| 1684 | long int lsa_life_time; |
| 1685 | |
| 1686 | int i, name_lsdb_element; |
| 1687 | struct nlsa *name_lsa; |
| 1688 | |
| 1689 | struct hashtb_enumerator ee; |
| 1690 | struct hashtb_enumerator *e = ⅇ |
| 1691 | |
| 1692 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1693 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1694 | |
| 1695 | for(i=0;i<name_lsdb_element;i++) |
| 1696 | { |
| 1697 | name_lsa=e->data; |
| 1698 | |
| 1699 | lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1700 | if ( nlsr->debugging ) |
| 1701 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1702 | if ( nlsr->detailed_logging ) |
| 1703 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1704 | |
| 1705 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1706 | { |
| 1707 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1708 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1709 | if ( name_lsa->header->isValid == NAME_LSA_VALID ) |
| 1710 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1711 | if ( nlsr->debugging ) |
| 1712 | printf("Own Name LSA need to be refrshed\n"); |
| 1713 | if ( nlsr->detailed_logging ) |
| 1714 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n"); |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1715 | |
| 1716 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1717 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1718 | write_log_for_name_lsa(name_lsa); |
| 1719 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1720 | |
| 1721 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1722 | char *current_time_stamp=(char *)malloc(20); |
| 1723 | memset(current_time_stamp,0,20); |
| 1724 | get_current_timestamp_micro(current_time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1725 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1726 | free(name_lsa->header->orig_time); |
| 1727 | name_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1728 | memset(name_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1729 | 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] | 1730 | |
| 1731 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1732 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 1733 | write_log_for_name_lsa(name_lsa); |
| 1734 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1735 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1736 | free(current_time_stamp); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1737 | |
| 1738 | hashtb_next(e); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1739 | } |
| 1740 | else |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1741 | { /* |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1742 | char lst[2]; |
| 1743 | memset(lst,0,2); |
| 1744 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1745 | |
| 1746 | char lsid[10]; |
| 1747 | memset(lsid,0,10); |
| 1748 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1749 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1750 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1751 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1752 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1753 | |
| 1754 | |
| 1755 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1756 | |
| 1757 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1758 | */ |
| 1759 | delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name); |
| 1760 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1761 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1762 | write_log_for_name_lsa(name_lsa); |
| 1763 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1764 | hashtb_delete(e); |
| 1765 | i++; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1766 | } |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1767 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1768 | if ( nlsr->debugging ) |
| 1769 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1770 | if ( nlsr->detailed_logging ) |
| 1771 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1772 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1773 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1774 | |
| 1775 | if ( nlsr->debugging ) |
| 1776 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1777 | if ( nlsr->detailed_logging ) |
| 1778 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1779 | |
| 1780 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1781 | |
| 1782 | print_name_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | else |
| 1790 | { |
| 1791 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1792 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1793 | if ( nlsr->debugging ) |
| 1794 | printf("Others Name LSA need to be deleted\n"); |
| 1795 | if ( nlsr->detailed_logging ) |
| 1796 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1797 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1798 | /*char lst[2]; |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1799 | memset(lst,0,2); |
| 1800 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 1801 | |
| 1802 | char lsid[10]; |
| 1803 | memset(lsid,0,10); |
| 1804 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 1805 | |
| 1806 | |
| 1807 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1808 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1809 | |
| 1810 | |
| 1811 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1812 | |
| 1813 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1814 | */ |
| 1815 | delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name); |
| 1816 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1817 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1818 | write_log_for_name_lsa(name_lsa); |
| 1819 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1820 | hashtb_delete(e); |
| 1821 | i++; |
| 1822 | } |
| 1823 | else |
| 1824 | { |
| 1825 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1826 | } |
| 1827 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1828 | /*else |
| 1829 | { |
| 1830 | hashtb_next(e); |
| 1831 | }*/ |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | hashtb_end(e); |
| 1835 | |
| 1836 | free(time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1837 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1838 | |
| 1839 | } |
| 1840 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1841 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1842 | refresh_adj_lsdb(void) |
| 1843 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1844 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1845 | if ( nlsr->debugging ) |
| 1846 | printf("refresh_adj_lsdb called \n"); |
| 1847 | if ( nlsr->detailed_logging ) |
| 1848 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1849 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1850 | char *time_stamp=(char *)malloc(20); |
| 1851 | memset(time_stamp,0,20); |
| 1852 | get_current_timestamp_micro(time_stamp); |
| 1853 | |
| 1854 | long int lsa_life_time; |
| 1855 | |
| 1856 | int i, adj_lsdb_element; |
| 1857 | struct alsa *adj_lsa; |
| 1858 | |
| 1859 | struct hashtb_enumerator ee; |
| 1860 | struct hashtb_enumerator *e = ⅇ |
| 1861 | |
| 1862 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1863 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1864 | |
| 1865 | for(i=0;i<adj_lsdb_element;i++) |
| 1866 | { |
| 1867 | adj_lsa=e->data; |
| 1868 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1869 | lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1870 | |
| 1871 | if ( nlsr->debugging ) |
| 1872 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1873 | if ( nlsr->detailed_logging ) |
| 1874 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1875 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1876 | if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1877 | { |
| 1878 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1879 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1880 | if ( nlsr->debugging ) |
| 1881 | printf("Own Adj LSA need to be refrshed\n"); |
| 1882 | if ( nlsr->detailed_logging ) |
| 1883 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1884 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1885 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1886 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1887 | write_log_for_adj_lsa(adj_lsa); |
| 1888 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1889 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1890 | char *current_time_stamp=(char *)malloc(20); |
| 1891 | memset(current_time_stamp,0,20); |
| 1892 | get_current_timestamp_micro(current_time_stamp); |
| 1893 | |
| 1894 | free(adj_lsa->header->orig_time); |
| 1895 | adj_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1896 | memset(adj_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1897 | memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1898 | |
| 1899 | free(current_time_stamp); |
| 1900 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1901 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1902 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 1903 | write_log_for_adj_lsa(adj_lsa); |
| 1904 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1905 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1906 | if ( nlsr->debugging ) |
| 1907 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1908 | if ( nlsr->detailed_logging ) |
| 1909 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1910 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1911 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1912 | |
| 1913 | if ( nlsr->debugging ) |
| 1914 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1915 | if ( nlsr->detailed_logging ) |
| 1916 | 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] | 1917 | |
| 1918 | print_adj_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1919 | |
| 1920 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1921 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1922 | |
| 1923 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1924 | } |
| 1925 | else |
| 1926 | { |
| 1927 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1928 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1929 | |
| 1930 | if ( nlsr->debugging ) |
| 1931 | printf("Others Adj LSA need to be deleted\n"); |
| 1932 | if ( nlsr->detailed_logging ) |
| 1933 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1934 | /* |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1935 | char *key=(char *)malloc(adj_lsa->header->orig_router->length+2+2); |
| 1936 | memset(key,0,adj_lsa->header->orig_router->length+2); |
| 1937 | make_adj_lsa_key(key,adj_lsa); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1938 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1939 | nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1940 | */ |
| 1941 | |
| 1942 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1943 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1944 | write_log_for_adj_lsa(adj_lsa); |
| 1945 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1946 | delete_adj_lsa(); |
| 1947 | hashtb_delete(e); |
| 1948 | i++; |
| 1949 | |
| 1950 | } |
| 1951 | else |
| 1952 | { |
| 1953 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1959 | //hashtb_next(e); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | hashtb_end(e); |
| 1963 | |
| 1964 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1965 | } |
| 1966 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1967 | |
| 1968 | void |
| 1969 | refresh_cor_lsdb(void) |
| 1970 | { |
| 1971 | |
| 1972 | if ( nlsr->debugging ) |
| 1973 | printf("refresh_cor_lsdb called \n"); |
| 1974 | if ( nlsr->detailed_logging ) |
| 1975 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n"); |
| 1976 | |
| 1977 | char *time_stamp=(char *)malloc(20); |
| 1978 | memset(time_stamp,0,20); |
| 1979 | get_current_timestamp_micro(time_stamp); |
| 1980 | |
| 1981 | long int lsa_life_time; |
| 1982 | |
| 1983 | int i, cor_lsdb_element; |
| 1984 | struct clsa *cor_lsa; |
| 1985 | |
| 1986 | struct hashtb_enumerator ee; |
| 1987 | struct hashtb_enumerator *e = ⅇ |
| 1988 | |
| 1989 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 1990 | cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb); |
| 1991 | |
| 1992 | for(i=0;i<cor_lsdb_element;i++) |
| 1993 | { |
| 1994 | cor_lsa=e->data; |
| 1995 | |
| 1996 | lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time); |
| 1997 | |
| 1998 | if ( nlsr->debugging ) |
| 1999 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 2000 | if ( nlsr->detailed_logging ) |
| 2001 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
| 2002 | |
| 2003 | if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 2004 | { |
| 2005 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 2006 | { |
| 2007 | if ( nlsr->debugging ) |
| 2008 | printf("Own Cor LSA need to be refrshed\n"); |
| 2009 | if ( nlsr->detailed_logging ) |
| 2010 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n"); |
| 2011 | |
| 2012 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 2013 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 2014 | //write_log_for_adj_lsa(adj_lsa); |
| 2015 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 2016 | |
| 2017 | char *current_time_stamp=(char *)malloc(20); |
| 2018 | memset(current_time_stamp,0,20); |
| 2019 | get_current_timestamp_micro(current_time_stamp); |
| 2020 | |
| 2021 | free(cor_lsa->header->orig_time); |
| 2022 | cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 2023 | memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 2024 | memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 2025 | |
| 2026 | free(current_time_stamp); |
| 2027 | |
| 2028 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 2029 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 2030 | //write_log_for_adj_lsa(adj_lsa); |
| 2031 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 2032 | |
| 2033 | if ( nlsr->debugging ) |
| 2034 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 2035 | if ( nlsr->detailed_logging ) |
| 2036 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 2037 | |
| 2038 | set_new_lsdb_version(); |
| 2039 | |
| 2040 | if ( nlsr->debugging ) |
| 2041 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 2042 | if ( nlsr->detailed_logging ) |
| 2043 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 2044 | |
| 2045 | print_adj_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | hashtb_next(e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2049 | } |
| 2050 | else |
| 2051 | { |
| 2052 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 2053 | { |
| 2054 | |
| 2055 | if ( nlsr->debugging ) |
| 2056 | printf("Others Adj LSA need to be deleted\n"); |
| 2057 | if ( nlsr->detailed_logging ) |
| 2058 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
| 2059 | |
| 2060 | hashtb_delete(e); |
| 2061 | i++; |
| 2062 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 2063 | else |
| 2064 | { |
| 2065 | hashtb_next(e); |
| 2066 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 2070 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | hashtb_end(e); |
| 2074 | |
| 2075 | free(time_stamp); |
| 2076 | } |
| 2077 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2078 | int |
| 2079 | refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 2080 | { |
| 2081 | if(flags == CCN_SCHEDULE_CANCEL) |
| 2082 | { |
| 2083 | return -1; |
| 2084 | } |
| 2085 | |
| 2086 | nlsr_lock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 2087 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 2088 | if ( nlsr->debugging ) |
| 2089 | printf("refresh_lsdb called\n"); |
| 2090 | if ( nlsr->detailed_logging ) |
| 2091 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2092 | |
| 2093 | refresh_name_lsdb(); |
| 2094 | refresh_adj_lsdb(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2095 | refresh_cor_lsdb(); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2096 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2097 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 2098 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2099 | nlsr_unlock(); |
| 2100 | return 0; |
| 2101 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2102 | |
| 2103 | void |
| 2104 | write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id) |
| 2105 | { |
| 2106 | if ( nlsr->debugging ) |
| 2107 | printf("write_adj_lsa_to_repo called\n"); |
| 2108 | if ( nlsr->debugging ) |
| 2109 | printf("Content Prefix: %s\n",repo_content_prefix); |
| 2110 | |
| 2111 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2112 | get_adj_lsa_data(lsa_data,lsa_id); |
| 2113 | if ( nlsr->debugging ) |
| 2114 | printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2115 | |
| 2116 | write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix); |
| 2117 | |
| 2118 | ccn_charbuf_destroy(&lsa_data); |
| 2119 | } |
| 2120 | |
| 2121 | void |
| 2122 | write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id) |
| 2123 | { |
| 2124 | if ( nlsr->debugging ) |
| 2125 | printf("write_name_lsa_to_repo called\n"); |
| 2126 | if ( nlsr->debugging ) |
| 2127 | printf("Content Prefix: %s\n",repo_content_prefix); |
| 2128 | |
| 2129 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2130 | get_name_lsa_data(lsa_data,lsa_id); |
| 2131 | |
| 2132 | if ( nlsr->debugging ) |
| 2133 | printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2134 | |
| 2135 | write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix); |
| 2136 | |
| 2137 | ccn_charbuf_destroy(&lsa_data); |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | void |
| 2142 | write_name_lsdb_to_repo(char *slice_prefix) |
| 2143 | { |
| 2144 | int i, name_lsdb_element; |
| 2145 | |
| 2146 | struct nlsa *name_lsa; |
| 2147 | struct hashtb_enumerator ee; |
| 2148 | struct hashtb_enumerator *e = ⅇ |
| 2149 | |
| 2150 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 2151 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 2152 | |
| 2153 | for(i=0;i<name_lsdb_element;i++) |
| 2154 | { |
| 2155 | name_lsa=e->data; |
| 2156 | |
| 2157 | char lst[2]; |
| 2158 | memset(lst,0,2); |
| 2159 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 2160 | |
| 2161 | char lsid[10]; |
| 2162 | memset(lsid,0,10); |
| 2163 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 2164 | |
| 2165 | |
| 2166 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2167 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2168 | |
| 2169 | |
| 2170 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 2171 | |
| 2172 | if ( nlsr->debugging ) |
| 2173 | printf("Name LSA Key: %s \n",key); |
| 2174 | |
| 2175 | |
| 2176 | char *repo_key=(char *)malloc(strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15); |
| 2177 | memset(repo_key,0,strlen(slice_prefix)+1+strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1+strlen(name_lsa->header->orig_time)+1+15); |
| 2178 | make_name_lsa_prefix_for_repo(repo_key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id,name_lsa->header->orig_time,slice_prefix); |
| 2179 | |
| 2180 | if ( nlsr->debugging ) |
| 2181 | printf("Name LSA Repo Key: %s \n",repo_key); |
| 2182 | |
| 2183 | struct name_prefix *lsaid=(struct name_prefix *)malloc(sizeof(struct name_prefix)); |
| 2184 | lsaid->name=(char *)malloc(strlen(key)+1); |
| 2185 | memset(lsaid->name, 0, strlen(key)+1); |
| 2186 | memcpy(lsaid->name,key,strlen(key)); |
| 2187 | lsaid->length=strlen(key)+1; |
| 2188 | |
| 2189 | |
| 2190 | write_name_lsa_to_repo(repo_key, lsaid); |
| 2191 | |
| 2192 | free(key); |
| 2193 | free(repo_key); |
| 2194 | free(lsaid->name); |
| 2195 | free(lsaid); |
| 2196 | |
| 2197 | hashtb_next(e); |
| 2198 | } |
| 2199 | |
| 2200 | hashtb_end(e); |
| 2201 | |
| 2202 | |
| 2203 | } |
| 2204 | |
| 2205 | void |
| 2206 | print_cor_lsa(struct clsa *cor_lsa) |
| 2207 | { |
| 2208 | if ( nlsr->debugging ) |
| 2209 | { |
| 2210 | printf("-----------Cor LSA Content---------------\n"); |
| 2211 | printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name); |
| 2212 | printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length); |
| 2213 | printf(" LS Type : %d\n",cor_lsa->header->ls_type); |
| 2214 | printf(" Origination Time : %s\n",cor_lsa->header->orig_time); |
| 2215 | printf(" LSA Data \n"); |
| 2216 | printf(" Cor R: : %f\n",cor_lsa->cor_r); |
| 2217 | printf(" Cor Theta : %f\n",cor_lsa->cor_theta); |
| 2218 | |
| 2219 | printf("\n"); |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | void |
| 2224 | print_cor_lsdb() |
| 2225 | { |
| 2226 | |
| 2227 | if ( nlsr->debugging ) |
| 2228 | printf("print_cor_lsdb called \n"); |
| 2229 | |
| 2230 | struct hashtb_enumerator ee; |
| 2231 | struct hashtb_enumerator *e = ⅇ |
| 2232 | |
| 2233 | int i=1; |
| 2234 | |
| 2235 | for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e)) |
| 2236 | { |
| 2237 | if ( nlsr->debugging ) |
| 2238 | printf("-----------Cor LSA (%d)---------------\n",i); |
| 2239 | struct clsa *cor_lsa=e->data; |
| 2240 | print_cor_lsa(cor_lsa); |
| 2241 | i++; |
| 2242 | } |
| 2243 | hashtb_end(e); |
| 2244 | |
| 2245 | if ( nlsr->debugging ) |
| 2246 | printf("\n"); |
| 2247 | if ( nlsr->detailed_logging ) |
| 2248 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 2249 | } |
| 2250 | |
| 2251 | void |
| 2252 | install_cor_lsa(struct clsa *cor_lsa) |
| 2253 | { |
| 2254 | if ( nlsr->debugging ) |
| 2255 | printf("install_cor_lsa called \n"); |
| 2256 | if ( nlsr->detailed_logging ) |
| 2257 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n"); |
| 2258 | |
| 2259 | |
| 2260 | char *time_stamp=(char *)malloc(20); |
| 2261 | memset(time_stamp,0,20); |
| 2262 | get_current_timestamp_micro(time_stamp); |
| 2263 | |
| 2264 | |
| 2265 | char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2); |
| 2266 | memset(key,0,cor_lsa->header->orig_router->length+2); |
| 2267 | make_cor_lsa_key(key,cor_lsa); |
| 2268 | |
| 2269 | if ( nlsr->debugging ) |
| 2270 | printf("Cor LSA key: %s \n",key); |
| 2271 | |
| 2272 | struct hashtb_enumerator ee; |
| 2273 | struct hashtb_enumerator *e = ⅇ |
| 2274 | int res; |
| 2275 | |
| 2276 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2277 | res = hashtb_seek(e, key, strlen(key), 0); |
| 2278 | |
| 2279 | if ( res == HT_NEW_ENTRY ) |
| 2280 | { |
| 2281 | if ( nlsr->debugging ) |
| 2282 | printf("New Cor LSA... \n"); |
| 2283 | |
| 2284 | struct clsa *new_cor_lsa=(struct clsa *)malloc(sizeof( struct clsa )); |
| 2285 | new_cor_lsa=e->data; |
| 2286 | new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2287 | |
| 2288 | new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 2289 | new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1); |
| 2290 | memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1); |
| 2291 | memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1); |
| 2292 | new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length; |
| 2293 | |
| 2294 | new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free |
| 2295 | memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1); |
| 2296 | memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1); |
| 2297 | |
| 2298 | new_cor_lsa->header->ls_type=cor_lsa->header->ls_type; |
| 2299 | |
| 2300 | new_cor_lsa->cor_r=cor_lsa->cor_r; |
| 2301 | new_cor_lsa->cor_theta=cor_lsa->cor_theta; |
| 2302 | } |
| 2303 | else if ( res == HT_OLD_ENTRY ) |
| 2304 | { |
| 2305 | if ( nlsr->debugging ) |
| 2306 | printf("Cor LSA exists (Old)... \n"); |
| 2307 | } |
| 2308 | hashtb_end(e); |
| 2309 | |
| 2310 | free(key); |
| 2311 | |
| 2312 | } |
| 2313 | |
| 2314 | void |
| 2315 | build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta) |
| 2316 | { |
| 2317 | cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2318 | cor_lsa->header->ls_type=LS_TYPE_COR; |
| 2319 | |
| 2320 | char *time_stamp=(char *)malloc(20); |
| 2321 | memset(time_stamp,0,20); |
| 2322 | get_current_timestamp_micro(time_stamp); |
| 2323 | |
| 2324 | cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
| 2325 | memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 2326 | memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 2327 | free(time_stamp); |
| 2328 | |
| 2329 | cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 2330 | cor_lsa->header->orig_router->name=(char *)malloc(strlen(nlsr->router_name)+1); |
| 2331 | memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 2332 | memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 2333 | cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 2334 | |
| 2335 | cor_lsa->cor_r=cor_r; |
| 2336 | cor_lsa->cor_theta=cor_theta; |
| 2337 | |
| 2338 | } |
| 2339 | |
| 2340 | void |
| 2341 | build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta) |
| 2342 | { |
| 2343 | cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2344 | cor_lsa->header->ls_type=ls_type; |
| 2345 | |
| 2346 | cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 2347 | memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1); |
| 2348 | memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
| 2349 | |
| 2350 | cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 2351 | cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 2352 | memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
| 2353 | memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
| 2354 | cor_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 2355 | |
| 2356 | cor_lsa->cor_r=cor_r; |
| 2357 | cor_lsa->cor_theta=cor_theta; |
| 2358 | |
| 2359 | } |
| 2360 | |
| 2361 | void |
| 2362 | build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta) |
| 2363 | { |
| 2364 | struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa )); |
| 2365 | build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta); |
| 2366 | install_cor_lsa(cor_lsa); |
| 2367 | |
| 2368 | print_cor_lsdb(); |
| 2369 | |
| 2370 | free(cor_lsa->header->orig_router); |
| 2371 | free(cor_lsa->header->orig_time); |
| 2372 | free(cor_lsa->header); |
| 2373 | free(cor_lsa); |
| 2374 | |
| 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | void |
| 2379 | build_and_install_cor_lsa() |
| 2380 | { |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa )); |
| 2385 | |
| 2386 | build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta); |
| 2387 | install_cor_lsa(cor_lsa); |
| 2388 | |
| 2389 | write_cor_lsa_to_repo(cor_lsa); |
| 2390 | |
| 2391 | print_cor_lsdb(); |
| 2392 | |
| 2393 | free(cor_lsa->header->orig_router); |
| 2394 | free(cor_lsa->header->orig_time); |
| 2395 | free(cor_lsa->header); |
| 2396 | free(cor_lsa); |
| 2397 | |
| 2398 | } |
| 2399 | |
| 2400 | void |
| 2401 | get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key) |
| 2402 | { |
| 2403 | if ( nlsr->debugging ) |
| 2404 | printf("get_cor_lsa_data called \n"); |
| 2405 | if ( nlsr->detailed_logging ) |
| 2406 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
| 2407 | |
| 2408 | struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa )); |
| 2409 | |
| 2410 | struct hashtb_enumerator ee; |
| 2411 | struct hashtb_enumerator *e = ⅇ |
| 2412 | int res; |
| 2413 | |
| 2414 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2415 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2416 | |
| 2417 | if( res == HT_OLD_ENTRY ) |
| 2418 | { |
| 2419 | cor_lsa=e->data; |
| 2420 | |
| 2421 | if ( nlsr->debugging ) |
| 2422 | printf("Cor LSA found \n"); |
| 2423 | if ( nlsr->detailed_logging ) |
| 2424 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n"); |
| 2425 | |
| 2426 | ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name); |
| 2427 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2428 | |
| 2429 | char *temp_length=(char *)malloc(20); |
| 2430 | memset(temp_length,0,20); |
| 2431 | sprintf(temp_length,"%d",cor_lsa->header->orig_router->length); |
| 2432 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 2433 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2434 | free(temp_length); |
| 2435 | |
| 2436 | char *temp_ltype=(char *)malloc(20); |
| 2437 | memset(temp_ltype,0,20); |
| 2438 | sprintf(temp_ltype,"%d",cor_lsa->header->ls_type); |
| 2439 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 2440 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2441 | free(temp_ltype); |
| 2442 | |
| 2443 | ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time); |
| 2444 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2445 | |
| 2446 | char *cor_r=(char *)malloc(20); |
| 2447 | memset(cor_r,0,20); |
| 2448 | sprintf(cor_r,"%f",cor_lsa->cor_r); |
| 2449 | ccn_charbuf_append_string(lsa_data,cor_r); |
| 2450 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2451 | free(cor_r); |
| 2452 | |
| 2453 | char *cor_theta=(char *)malloc(20); |
| 2454 | memset(cor_theta,0,20); |
| 2455 | sprintf(cor_theta,"%f",cor_lsa->cor_theta); |
| 2456 | ccn_charbuf_append_string(lsa_data,cor_theta); |
| 2457 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2458 | free(cor_theta); |
| 2459 | |
| 2460 | } |
| 2461 | else if(res == HT_NEW_ENTRY) |
| 2462 | { |
| 2463 | hashtb_delete(e); |
| 2464 | } |
| 2465 | |
| 2466 | hashtb_end(e); |
| 2467 | } |
| 2468 | |
| 2469 | void |
| 2470 | write_cor_lsa_to_repo(struct clsa *cor_lsa) |
| 2471 | { |
| 2472 | |
| 2473 | |
| 2474 | if ( nlsr->debugging ) |
| 2475 | printf("write_cor_lsa_to_repo called\n"); |
| 2476 | |
| 2477 | |
| 2478 | char *key=(char *)malloc(cor_lsa->header->orig_router->length+2+2); |
| 2479 | memset(key,0,cor_lsa->header->orig_router->length+2+2); |
| 2480 | make_cor_lsa_key(key,cor_lsa); |
| 2481 | |
| 2482 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2483 | get_cor_lsa_data(lsa_data,key); |
| 2484 | |
| 2485 | if ( nlsr->debugging ) |
| 2486 | printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2487 | char *lst=(char *)malloc(20); |
| 2488 | memset(lst,0,20); |
| 2489 | sprintf(lst,"%d",cor_lsa->header->ls_type); |
| 2490 | char *repo_key=(char *)malloc(strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15); |
| 2491 | memset(repo_key, 0, strlen(nlsr->slice_prefix)+strlen(cor_lsa->header->orig_time)+strlen(cor_lsa->header->orig_router->name) + strlen(lst) + 5+15); |
| 2492 | make_cor_lsa_prefix_for_repo(repo_key, cor_lsa->header->orig_router->name,LS_TYPE_COR,cor_lsa->header->orig_time,nlsr->slice_prefix); |
| 2493 | |
| 2494 | if ( nlsr->debugging ) |
| 2495 | printf("Cor LSA Repo Key: %s \n",repo_key); |
| 2496 | |
| 2497 | write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key); |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | free(lst); |
| 2502 | free(key); |
| 2503 | free(repo_key); |
| 2504 | ccn_charbuf_destroy(&lsa_data); |
| 2505 | } |
| 2506 | |
| 2507 | void |
| 2508 | make_cor_lsa_key_by_router_name(char *key,char *router_name) |
| 2509 | { |
| 2510 | memcpy(key+strlen(key),router_name,strlen(router_name)); |
| 2511 | memcpy(key+strlen(key),"/",1); |
| 2512 | char ls_type[2]; |
| 2513 | sprintf(ls_type,"%d",LS_TYPE_COR); |
| 2514 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 2515 | key[strlen(key)]='\0'; |
| 2516 | } |
| 2517 | |
| 2518 | |
| 2519 | double |
| 2520 | get_hyperbolic_r(char *router) |
| 2521 | { |
| 2522 | double ret=-1.0; |
| 2523 | char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char)); |
| 2524 | make_cor_lsa_key_by_router_name(cor_lsa_key,router); |
| 2525 | |
| 2526 | |
| 2527 | struct clsa *cor_lsa; |
| 2528 | struct hashtb_enumerator ee; |
| 2529 | struct hashtb_enumerator *e = ⅇ |
| 2530 | int res; |
| 2531 | |
| 2532 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2533 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2534 | |
| 2535 | if ( res == HT_OLD_ENTRY) |
| 2536 | { |
| 2537 | cor_lsa=e->data; |
| 2538 | ret=cor_lsa->cor_r; |
| 2539 | } |
| 2540 | else if(res == HT_NEW_ENTRY) |
| 2541 | { |
| 2542 | hashtb_delete(e); |
| 2543 | } |
| 2544 | |
| 2545 | hashtb_end(e); |
| 2546 | |
| 2547 | free(cor_lsa_key); |
| 2548 | return ret; |
| 2549 | } |
| 2550 | |
| 2551 | double |
| 2552 | get_hyperbolic_theta(char *router) |
| 2553 | { |
| 2554 | double ret=-1.0; |
| 2555 | char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char)); |
| 2556 | make_cor_lsa_key_by_router_name(cor_lsa_key,router); |
| 2557 | |
| 2558 | struct clsa *cor_lsa; |
| 2559 | struct hashtb_enumerator ee; |
| 2560 | struct hashtb_enumerator *e = ⅇ |
| 2561 | int res; |
| 2562 | |
| 2563 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2564 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2565 | |
| 2566 | if ( res == HT_OLD_ENTRY) |
| 2567 | { |
| 2568 | cor_lsa=e->data; |
| 2569 | ret=cor_lsa->cor_theta; |
| 2570 | } |
| 2571 | else if(res == HT_NEW_ENTRY) |
| 2572 | { |
| 2573 | hashtb_delete(e); |
| 2574 | } |
| 2575 | |
| 2576 | hashtb_end(e); |
| 2577 | |
| 2578 | free(cor_lsa_key); |
| 2579 | return ret; |
| 2580 | } |