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