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