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