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 | 0b60ba9 | 2013-02-25 17:55:35 -0600 | [diff] [blame] | 906 | //if(new_adj_lsa->body ) |
| 907 | //free(new_adj_lsa->body); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 908 | new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char)); |
| 909 | //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 910 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
| 911 | |
| 912 | add_next_hop_router(new_adj_lsa->header->orig_router->name); |
| 913 | 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] | 914 | |
| 915 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 916 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 917 | write_log_for_adj_lsa(new_adj_lsa); |
| 918 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 919 | } |
| 920 | else |
| 921 | { |
| 922 | hashtb_delete(e); |
| 923 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 924 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 925 | if ( nlsr->debugging ) |
| 926 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 927 | if ( nlsr->detailed_logging ) |
| 928 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 929 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 930 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 931 | |
| 932 | if ( nlsr->debugging ) |
| 933 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 934 | if ( nlsr->detailed_logging ) |
| 935 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 936 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 937 | } |
| 938 | else if(res == HT_OLD_ENTRY) |
| 939 | { |
| 940 | new_adj_lsa = e->data; |
| 941 | if(strcmp(adj_lsa->header->orig_time,new_adj_lsa->header->orig_time)<=0) |
| 942 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 943 | if ( nlsr->debugging ) |
| 944 | printf("Older/Duplicate Adj LSA. Discarded...\n"); |
| 945 | if ( nlsr->detailed_logging ) |
| 946 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Older/Duplicate Adj LSA. Discarded...\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 947 | } |
| 948 | else |
| 949 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 950 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 951 | if ( adj_lsa->no_link > 0) |
| 952 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 953 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 954 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 955 | write_log_for_adj_lsa(new_adj_lsa); |
| 956 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 957 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 958 | free(new_adj_lsa->header->orig_time); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 959 | 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] | 960 | memcpy(new_adj_lsa->header->orig_time,adj_lsa->header->orig_time,strlen(adj_lsa->header->orig_time)+1); |
| 961 | |
| 962 | new_adj_lsa->no_link=adj_lsa->no_link; |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 963 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 964 | new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char)); |
| 965 | //memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 966 | memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 967 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 968 | 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] | 969 | |
| 970 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 971 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 972 | write_log_for_adj_lsa(new_adj_lsa); |
| 973 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 974 | } |
| 975 | else |
| 976 | { |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 977 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 978 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 979 | write_log_for_adj_lsa(new_adj_lsa); |
| 980 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 981 | |
akmhoque | 62c0c19 | 2012-09-24 07:49:25 -0500 | [diff] [blame] | 982 | hashtb_delete(e); |
| 983 | } |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 984 | |
| 985 | if ( nlsr->debugging ) |
| 986 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 987 | if ( nlsr->detailed_logging ) |
| 988 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 989 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 990 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 991 | |
| 992 | if ( nlsr->debugging ) |
| 993 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 994 | if ( nlsr->detailed_logging ) |
| 995 | 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] | 996 | } |
| 997 | |
| 998 | } |
| 999 | hashtb_end(e); |
| 1000 | |
| 1001 | if ( !nlsr->is_route_calculation_scheduled ) |
| 1002 | { |
| 1003 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1004 | nlsr->is_route_calculation_scheduled=1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1005 | } |
| 1006 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1007 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1008 | free(key); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1009 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1010 | //free(time_stamp); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | void |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1014 | write_log_for_adj_lsa_body(const char *body, int no_link) |
| 1015 | { |
| 1016 | int i=0; |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1017 | char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char)); |
| 1018 | //memset( lsa_data,0,strlen(body)+1); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1019 | memcpy(lsa_data,body,strlen(body)+1); |
| 1020 | char *sep="|"; |
| 1021 | char *rem; |
| 1022 | char *rtr_id; |
| 1023 | char *length; |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 1024 | //char *face; |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1025 | char *metric; |
| 1026 | |
| 1027 | if(no_link >0 ) |
| 1028 | { |
| 1029 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 1030 | length=strtok_r(NULL,sep,&rem); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1031 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1032 | metric=strtok_r(NULL,sep,&rem); |
| 1033 | |
| 1034 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1035 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 1036 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1037 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1038 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1039 | |
| 1040 | |
| 1041 | for(i=1;i<no_link;i++) |
| 1042 | { |
| 1043 | rtr_id=strtok_r(NULL,sep,&rem); |
| 1044 | length=strtok_r(NULL,sep,&rem); |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 1045 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1046 | metric=strtok_r(NULL,sep,&rem); |
| 1047 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1048 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id); |
| 1049 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1050 | //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1051 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1052 | |
| 1053 | } |
| 1054 | } |
| 1055 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1056 | if(lsa_data) |
| 1057 | free(lsa_data); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | void |
| 1062 | write_log_for_adj_lsa(struct alsa * adj_lsa) |
| 1063 | { |
| 1064 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1065 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router: %s\n",adj_lsa->header->orig_router->name); |
| 1066 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 1067 | writeLogg(__FILE__,__FUNCTION__,__LINE__," LS Type: %d\n",adj_lsa->header->ls_type); |
| 1068 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Origination Time: %s\n",adj_lsa->header->orig_time); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1069 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n"); |
akmhoque | 34b99f9 | 2012-09-27 12:24:27 -0500 | [diff] [blame] | 1070 | writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link); |
akmhoque | 9e9fc72 | 2012-09-26 14:03:25 -0500 | [diff] [blame] | 1071 | |
| 1072 | write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1073 | |
| 1074 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 1075 | |
| 1076 | } |
| 1077 | |
| 1078 | void |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1079 | print_adj_lsa_body(const char *body, int no_link) |
| 1080 | { |
| 1081 | int i=0; |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1082 | char *lsa_data=(char *)calloc(strlen(body)+1,sizeof(char)); |
| 1083 | //memset( lsa_data,0,strlen(body)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1084 | memcpy(lsa_data,body,strlen(body)+1); |
| 1085 | char *sep="|"; |
| 1086 | char *rem; |
| 1087 | char *rtr_id; |
| 1088 | char *length; |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 1089 | //char *face; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1090 | char *metric; |
| 1091 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1092 | if(no_link >0 ) |
| 1093 | { |
| 1094 | rtr_id=strtok_r(lsa_data,sep,&rem); |
| 1095 | length=strtok_r(NULL,sep,&rem); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1096 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1097 | metric=strtok_r(NULL,sep,&rem); |
| 1098 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1099 | if ( nlsr->debugging ) { |
| 1100 | printf(" Link %d \n",i+1); |
| 1101 | printf(" Neighbor : %s \n",rtr_id); |
| 1102 | printf(" Neighbor Length : %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1103 | //printf(" Connecting Face : %s \n",face); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1104 | printf(" Metric : %s \n",metric); |
| 1105 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1106 | |
| 1107 | for(i=1;i<no_link;i++) |
| 1108 | { |
| 1109 | rtr_id=strtok_r(NULL,sep,&rem); |
| 1110 | length=strtok_r(NULL,sep,&rem); |
akmhoque | b28579d | 2013-02-12 11:15:52 -0600 | [diff] [blame] | 1111 | //face=strtok_r(NULL,sep,&rem); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1112 | metric=strtok_r(NULL,sep,&rem); |
| 1113 | printf(" Link %d \n",i+1); |
| 1114 | printf(" Neighbor : %s \n",rtr_id); |
| 1115 | printf(" Neighbor Length : %s \n",length); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1116 | //printf(" Connecting Face : %s \n",face); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1117 | printf(" Metric : %s \n",metric); |
| 1118 | |
| 1119 | } |
| 1120 | } |
| 1121 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1122 | if( lsa_data ) |
| 1123 | free(lsa_data); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void |
| 1127 | print_adj_lsa(struct alsa * adj_lsa) |
| 1128 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1129 | if ( nlsr->debugging ) |
| 1130 | { |
| 1131 | printf("-----------ADJ LSA Content---------------\n"); |
| 1132 | printf(" Origination Router : %s\n",adj_lsa->header->orig_router->name); |
| 1133 | printf(" Origination Router Length: %d\n",adj_lsa->header->orig_router->length); |
| 1134 | printf(" LS Type : %d\n",adj_lsa->header->ls_type); |
| 1135 | printf(" Origination Time : %s\n",adj_lsa->header->orig_time); |
| 1136 | printf(" Lsa Data:\n"); |
| 1137 | printf(" No of Link : %d\n",adj_lsa->no_link); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1138 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1139 | print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link); |
| 1140 | printf("\n"); |
| 1141 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1142 | |
| 1143 | } |
| 1144 | |
| 1145 | void |
| 1146 | print_adj_lsdb(void) |
| 1147 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1148 | if ( nlsr->debugging ) |
| 1149 | printf("print_name_lsdb called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1150 | int i, adj_lsdb_element; |
| 1151 | struct alsa *adj_lsa; |
| 1152 | |
| 1153 | struct hashtb_enumerator ee; |
| 1154 | struct hashtb_enumerator *e = ⅇ |
| 1155 | |
| 1156 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1157 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1158 | |
| 1159 | for(i=0;i<adj_lsdb_element;i++) |
| 1160 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1161 | if ( nlsr->debugging ) |
| 1162 | printf("-----------Adj LSA (%d)---------------\n",i+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1163 | adj_lsa=e->data; |
| 1164 | print_adj_lsa(adj_lsa); |
| 1165 | hashtb_next(e); |
| 1166 | } |
| 1167 | |
| 1168 | hashtb_end(e); |
| 1169 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1170 | if ( nlsr->debugging ) |
| 1171 | printf("\n"); |
| 1172 | if ( nlsr->detailed_logging ) |
| 1173 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1177 | 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] | 1178 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1179 | if ( nlsr->debugging ) |
| 1180 | printf("build_and_install_others_adj_lsa called \n"); |
| 1181 | if ( nlsr->detailed_logging ) |
| 1182 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_and_install_others_adj_lsa called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1183 | struct alsa *adj_lsa=(struct alsa *)malloc(sizeof( struct alsa )); |
| 1184 | 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] | 1185 | install_adj_lsa(adj_lsa); |
| 1186 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1187 | destroy_adj_lsa(adj_lsa); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1188 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1189 | print_adj_lsdb(); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1190 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1191 | } |
| 1192 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1193 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1194 | void |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1195 | 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] | 1196 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1197 | if ( nlsr->debugging ) |
| 1198 | printf("build_others_adj_lsa called \n"); |
| 1199 | if ( nlsr->detailed_logging ) |
| 1200 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"build_others_adj_lsa called \n"); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1201 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1202 | /*Filling Up Header Data */ |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1203 | adj_lsa->header=(struct alsa_header *)calloc(1,sizeof(struct alsa_header )); |
| 1204 | adj_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
| 1205 | 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] | 1206 | memcpy(adj_lsa->header->orig_router->name,orig_router,strlen(orig_router)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1207 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1208 | adj_lsa->header->orig_router->length=strlen(orig_router)+1; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1209 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1210 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1211 | adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1212 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1213 | adj_lsa->header->orig_time=(char *)calloc(strlen(orig_time)+1,sizeof(char)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1214 | memcpy(adj_lsa->header->orig_time,orig_time,strlen(orig_time)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1215 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1216 | adj_lsa->no_link=no_link; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1217 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1218 | adj_lsa->body=(char *)calloc(strlen(data)+1,sizeof(char)); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1219 | memcpy(adj_lsa->body,(char *)data,strlen(data)+1); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1220 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1221 | } |
| 1222 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1223 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 1224 | long int |
| 1225 | get_name_lsdb_num_element(void) |
| 1226 | { |
| 1227 | long int num_element; |
| 1228 | |
| 1229 | |
| 1230 | struct hashtb_enumerator ee; |
| 1231 | struct hashtb_enumerator *e = ⅇ |
| 1232 | |
| 1233 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1234 | num_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1235 | hashtb_end(e); |
| 1236 | |
| 1237 | return num_element; |
| 1238 | } |
| 1239 | |
| 1240 | long int |
| 1241 | get_adj_lsdb_num_element(void) |
| 1242 | { |
| 1243 | long int num_element; |
| 1244 | |
| 1245 | |
| 1246 | struct hashtb_enumerator ee; |
| 1247 | struct hashtb_enumerator *e = ⅇ |
| 1248 | |
| 1249 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1250 | num_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1251 | hashtb_end(e); |
| 1252 | |
| 1253 | return num_element; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 1254 | } |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1255 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1256 | |
| 1257 | int |
| 1258 | check_is_new_name_lsa(char *orig_router,char *lst,char *lsid,char *orig_time) |
| 1259 | { |
| 1260 | int ret=0; |
| 1261 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1262 | ccn_charbuf_append_string(key,orig_router); |
| 1263 | ccn_charbuf_append_string(key,"/"); |
| 1264 | ccn_charbuf_append_string(key,lst); |
| 1265 | ccn_charbuf_append_string(key,"/"); |
| 1266 | ccn_charbuf_append_string(key,lsid); |
| 1267 | |
| 1268 | int res; |
| 1269 | struct nlsa *name_lsa; |
| 1270 | |
| 1271 | struct hashtb_enumerator ee; |
| 1272 | struct hashtb_enumerator *e = ⅇ |
| 1273 | |
| 1274 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1275 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1276 | |
| 1277 | if( res == HT_NEW_ENTRY ) |
| 1278 | { |
| 1279 | hashtb_delete(e); |
| 1280 | ret=1; |
| 1281 | |
| 1282 | } |
| 1283 | else if(res == HT_OLD_ENTRY) |
| 1284 | { |
| 1285 | name_lsa=e->data; |
| 1286 | if( strcmp ( orig_time , name_lsa->header->orig_time ) > 0 ) |
| 1287 | { |
| 1288 | ret=1; |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | hashtb_end(e); |
| 1293 | |
| 1294 | ccn_charbuf_destroy(&key); |
| 1295 | |
| 1296 | return ret; |
| 1297 | } |
| 1298 | |
| 1299 | int |
| 1300 | check_is_new_adj_lsa(char *orig_router,char *lst,char *orig_time) |
| 1301 | { |
| 1302 | int ret=0; |
| 1303 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1304 | ccn_charbuf_append_string(key,orig_router); |
| 1305 | ccn_charbuf_append_string(key,"/"); |
| 1306 | ccn_charbuf_append_string(key,lst); |
| 1307 | |
| 1308 | int res; |
| 1309 | struct alsa *adj_lsa; |
| 1310 | |
| 1311 | struct hashtb_enumerator ee; |
| 1312 | struct hashtb_enumerator *e = ⅇ |
| 1313 | |
| 1314 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1315 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1316 | |
| 1317 | if( res == HT_NEW_ENTRY ) |
| 1318 | { |
| 1319 | hashtb_delete(e); |
| 1320 | ret=1; |
| 1321 | |
| 1322 | } |
| 1323 | else if(res == HT_OLD_ENTRY) |
| 1324 | { |
| 1325 | adj_lsa=e->data; |
| 1326 | if( strcmp ( orig_time , adj_lsa->header->orig_time ) > 0 ) |
| 1327 | { |
| 1328 | ret=1; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | hashtb_end(e); |
| 1333 | |
| 1334 | ccn_charbuf_destroy(&key); |
| 1335 | |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1339 | int |
| 1340 | check_is_new_cor_lsa(char *orig_router,char *lst,char *orig_time) |
| 1341 | { |
| 1342 | int ret=0; |
| 1343 | struct ccn_charbuf *key=ccn_charbuf_create(); |
| 1344 | ccn_charbuf_append_string(key,orig_router); |
| 1345 | ccn_charbuf_append_string(key,"/"); |
| 1346 | ccn_charbuf_append_string(key,lst); |
| 1347 | |
| 1348 | int res; |
| 1349 | struct clsa *cor_lsa; |
| 1350 | |
| 1351 | struct hashtb_enumerator ee; |
| 1352 | struct hashtb_enumerator *e = ⅇ |
| 1353 | |
| 1354 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 1355 | res = hashtb_seek(e, ccn_charbuf_as_string(key), key->length, 0); |
| 1356 | |
| 1357 | if( res == HT_NEW_ENTRY ) |
| 1358 | { |
| 1359 | hashtb_delete(e); |
| 1360 | ret=1; |
| 1361 | |
| 1362 | } |
| 1363 | else if(res == HT_OLD_ENTRY) |
| 1364 | { |
| 1365 | cor_lsa=e->data; |
| 1366 | if( strcmp ( orig_time , cor_lsa->header->orig_time ) > 0 ) |
| 1367 | { |
| 1368 | ret=1; |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | hashtb_end(e); |
| 1373 | |
| 1374 | ccn_charbuf_destroy(&key); |
| 1375 | |
| 1376 | return ret; |
| 1377 | } |
| 1378 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1379 | void |
| 1380 | get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId) |
| 1381 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1382 | if ( nlsr->debugging ) |
| 1383 | printf("get_name_lsa_data called \n"); |
| 1384 | if ( nlsr->detailed_logging ) |
| 1385 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_name_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1386 | |
akmhoque | 8876e98 | 2013-02-21 13:35:46 -0600 | [diff] [blame] | 1387 | struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1388 | |
| 1389 | struct hashtb_enumerator ee; |
| 1390 | struct hashtb_enumerator *e = ⅇ |
| 1391 | int res; |
| 1392 | |
| 1393 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1394 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1395 | |
| 1396 | if( res == HT_OLD_ENTRY ) |
| 1397 | { |
| 1398 | name_lsa=e->data; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1399 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1400 | if ( nlsr->debugging ) |
| 1401 | printf("NAME LSA found \n"); |
| 1402 | if ( nlsr->detailed_logging ) |
| 1403 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1404 | |
| 1405 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_router->name); |
| 1406 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1407 | |
| 1408 | char *temp_length=(char *)malloc(20); |
| 1409 | memset(temp_length,0,20); |
| 1410 | sprintf(temp_length,"%d",name_lsa->header->orig_router->length); |
| 1411 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 1412 | free(temp_length); |
| 1413 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1414 | |
| 1415 | char *temp_ltype=(char *)malloc(20); |
| 1416 | memset(temp_ltype,0,20); |
| 1417 | sprintf(temp_ltype,"%d",name_lsa->header->ls_type); |
| 1418 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 1419 | free(temp_ltype); |
| 1420 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1421 | |
| 1422 | char *temp_lsid=(char *)malloc(20); |
| 1423 | memset(temp_lsid,0,20); |
| 1424 | sprintf(temp_lsid,"%ld",name_lsa->header->ls_id); |
| 1425 | ccn_charbuf_append_string(lsa_data,temp_lsid); |
| 1426 | free(temp_lsid); |
| 1427 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1428 | |
| 1429 | ccn_charbuf_append_string(lsa_data,name_lsa->header->orig_time); |
| 1430 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1431 | |
| 1432 | char *temp_valid=(char *)malloc(20); |
| 1433 | memset(temp_valid,0,20); |
| 1434 | sprintf(temp_valid,"%d",name_lsa->header->isValid); |
| 1435 | ccn_charbuf_append_string(lsa_data,temp_valid); |
| 1436 | free(temp_valid); |
| 1437 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1438 | |
| 1439 | ccn_charbuf_append_string(lsa_data,name_lsa->name_prefix->name); |
| 1440 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1441 | |
| 1442 | char *temp_npl=(char *)malloc(20); |
| 1443 | memset(temp_npl,0,20); |
| 1444 | sprintf(temp_npl,"%d",name_lsa->name_prefix->length); |
| 1445 | ccn_charbuf_append_string(lsa_data,temp_npl); |
| 1446 | free(temp_npl); |
| 1447 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1448 | |
| 1449 | } |
| 1450 | else if(res == HT_NEW_ENTRY) |
| 1451 | { |
| 1452 | hashtb_delete(e); |
| 1453 | } |
| 1454 | |
| 1455 | hashtb_end(e); |
| 1456 | } |
| 1457 | |
| 1458 | void |
| 1459 | get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId) |
| 1460 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1461 | if ( nlsr->debugging ) |
| 1462 | printf("get_adj_lsa_data called \n"); |
| 1463 | if ( nlsr->detailed_logging ) |
| 1464 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1465 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 1466 | struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa )); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1467 | |
| 1468 | struct hashtb_enumerator ee; |
| 1469 | struct hashtb_enumerator *e = ⅇ |
| 1470 | int res; |
| 1471 | |
| 1472 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1473 | res = hashtb_seek(e, lsaId->name, lsaId->length-1, 0); |
| 1474 | |
| 1475 | if( res == HT_OLD_ENTRY ) |
| 1476 | { |
| 1477 | adj_lsa=e->data; |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1478 | |
| 1479 | if ( nlsr->debugging ) |
| 1480 | printf("Adj LSA found \n"); |
| 1481 | if ( nlsr->detailed_logging ) |
| 1482 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n"); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1483 | |
| 1484 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_router->name); |
| 1485 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1486 | |
| 1487 | char *temp_length=(char *)malloc(20); |
| 1488 | memset(temp_length,0,20); |
| 1489 | sprintf(temp_length,"%d",adj_lsa->header->orig_router->length); |
| 1490 | ccn_charbuf_append_string(lsa_data,temp_length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1491 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1492 | free(temp_length); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1493 | |
| 1494 | char *temp_ltype=(char *)malloc(20); |
| 1495 | memset(temp_ltype,0,20); |
| 1496 | sprintf(temp_ltype,"%d",adj_lsa->header->ls_type); |
| 1497 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1498 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1499 | free(temp_ltype); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1500 | |
| 1501 | ccn_charbuf_append_string(lsa_data,adj_lsa->header->orig_time); |
| 1502 | ccn_charbuf_append_string(lsa_data,"|"); |
| 1503 | |
| 1504 | char *temp_nl=(char *)malloc(20); |
| 1505 | memset(temp_nl,0,20); |
| 1506 | sprintf(temp_nl,"%d",adj_lsa->no_link); |
| 1507 | ccn_charbuf_append_string(lsa_data,temp_nl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1508 | ccn_charbuf_append_string(lsa_data,"|"); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1509 | free(temp_nl); |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 1510 | |
| 1511 | ccn_charbuf_append_string(lsa_data,adj_lsa->body); |
| 1512 | |
| 1513 | |
| 1514 | } |
| 1515 | else if(res == HT_NEW_ENTRY) |
| 1516 | { |
| 1517 | hashtb_delete(e); |
| 1518 | } |
| 1519 | |
| 1520 | hashtb_end(e); |
| 1521 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1522 | |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1523 | void |
| 1524 | make_name_lsa_invalid(struct name_prefix *np,int ls_type, long int ls_id) |
| 1525 | { |
| 1526 | |
| 1527 | if ( nlsr->debugging ) |
| 1528 | printf("make_name_lsa_invalid called \n"); |
| 1529 | if ( nlsr->detailed_logging ) |
| 1530 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"make_name_lsa_invalid called \n"); |
| 1531 | |
| 1532 | |
| 1533 | char lst[2]; |
| 1534 | memset(lst,0,2); |
| 1535 | sprintf(lst,"%d",ls_type); |
| 1536 | |
| 1537 | char lsid[10]; |
| 1538 | memset(lsid,0,10); |
| 1539 | sprintf(lsid,"%ld",ls_id); |
| 1540 | |
| 1541 | |
| 1542 | char *key=(char *)malloc(strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1543 | memset(key,0,strlen(np->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 1544 | |
| 1545 | |
| 1546 | make_name_lsa_key(key, np->name,ls_type,ls_id); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1547 | |
| 1548 | if ( nlsr->debugging ) |
| 1549 | printf("Key:%s Length:%d\n",key,(int)strlen(key)); |
akmhoque | 3171d65 | 2012-11-13 11:44:33 -0600 | [diff] [blame] | 1550 | |
| 1551 | struct nlsa *nlsa; |
| 1552 | |
| 1553 | struct hashtb_enumerator ee; |
| 1554 | struct hashtb_enumerator *e = ⅇ |
| 1555 | |
| 1556 | int res; |
| 1557 | |
| 1558 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1559 | res = hashtb_seek(e, key,strlen(key) , 0); |
| 1560 | |
| 1561 | if( res == HT_OLD_ENTRY ) |
| 1562 | { |
| 1563 | nlsa=e->data; |
| 1564 | |
| 1565 | nlsa->header->isValid=0; |
| 1566 | |
| 1567 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1568 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1569 | write_log_for_name_lsa(nlsa); |
| 1570 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1571 | |
| 1572 | hashtb_delete(e); |
| 1573 | } |
| 1574 | else if( res == HT_NEW_ENTRY ) |
| 1575 | { |
| 1576 | hashtb_delete(e); |
| 1577 | } |
| 1578 | hashtb_end(e); |
| 1579 | |
| 1580 | if ( nlsr->debugging ) |
| 1581 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1582 | if ( nlsr->detailed_logging ) |
| 1583 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1584 | |
| 1585 | set_new_lsdb_version(); |
| 1586 | |
| 1587 | if ( nlsr->debugging ) |
| 1588 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1589 | if ( nlsr->detailed_logging ) |
| 1590 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1591 | |
| 1592 | } |
| 1593 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1594 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1595 | int |
| 1596 | delete_name_lsa(char *orig_router, char *name_prefix) |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1597 | { |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1598 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1599 | if ( nlsr->debugging ) |
| 1600 | printf("delete_name_lsa called \n"); |
| 1601 | if ( nlsr->detailed_logging ) |
| 1602 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_name_lsa called \n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1603 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1604 | delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1605 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1606 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1607 | if ( nlsr->debugging ) |
| 1608 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1609 | if ( nlsr->detailed_logging ) |
| 1610 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1611 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1612 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1613 | |
| 1614 | if ( nlsr->debugging ) |
| 1615 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1616 | if ( nlsr->detailed_logging ) |
| 1617 | 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] | 1618 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1623 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1624 | int delete_adj_lsa() |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1625 | { |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1626 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1627 | if ( nlsr->debugging ) |
| 1628 | printf("delete_adj_lsa called \n"); |
| 1629 | if ( nlsr->detailed_logging ) |
| 1630 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"delete_adj_lsa called \n"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1631 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1632 | if ( nlsr->debugging ) |
| 1633 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1634 | if ( nlsr->detailed_logging ) |
| 1635 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1636 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1637 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1638 | |
| 1639 | if ( nlsr->debugging ) |
| 1640 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1641 | if ( nlsr->detailed_logging ) |
| 1642 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1643 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1644 | |
| 1645 | if ( !nlsr->is_route_calculation_scheduled) |
| 1646 | { |
| 1647 | nlsr->event_calculate_route = ccn_schedule_event(nlsr->sched, 1000000, &route_calculate, NULL, 0); |
| 1648 | nlsr->is_route_calculation_scheduled=1; |
| 1649 | } |
| 1650 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1651 | return 0; |
| 1652 | } |
| 1653 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1654 | void |
| 1655 | refresh_name_lsdb(void) |
| 1656 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1657 | if ( nlsr->debugging ) |
| 1658 | printf("refresh_name_lsdb called \n"); |
| 1659 | if ( nlsr->detailed_logging ) |
| 1660 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_name_lsdb called \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1661 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1662 | char *time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1663 | |
| 1664 | long int lsa_life_time; |
| 1665 | |
| 1666 | int i, name_lsdb_element; |
| 1667 | struct nlsa *name_lsa; |
| 1668 | |
| 1669 | struct hashtb_enumerator ee; |
| 1670 | struct hashtb_enumerator *e = ⅇ |
| 1671 | |
| 1672 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 1673 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 1674 | |
| 1675 | for(i=0;i<name_lsdb_element;i++) |
| 1676 | { |
| 1677 | name_lsa=e->data; |
| 1678 | |
| 1679 | lsa_life_time=get_time_diff(time_stamp,name_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1680 | if ( nlsr->debugging ) |
| 1681 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1682 | if ( nlsr->detailed_logging ) |
| 1683 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1684 | |
| 1685 | if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1686 | { |
| 1687 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1688 | { |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1689 | if ( name_lsa->header->isValid == NAME_LSA_VALID ) |
| 1690 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1691 | if ( nlsr->debugging ) |
| 1692 | printf("Own Name LSA need to be refrshed\n"); |
| 1693 | if ( nlsr->detailed_logging ) |
| 1694 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Name LSA need to be refrshed\n"); |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1695 | |
| 1696 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1697 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1698 | write_log_for_name_lsa(name_lsa); |
| 1699 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
| 1700 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1701 | char *current_time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1702 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1703 | free(name_lsa->header->orig_time); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1704 | 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] | 1705 | 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] | 1706 | |
| 1707 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1708 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n"); |
| 1709 | write_log_for_name_lsa(name_lsa); |
| 1710 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1711 | |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1712 | free(current_time_stamp); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1713 | |
| 1714 | hashtb_next(e); |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1715 | } |
| 1716 | else |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1717 | { |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1718 | delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name); |
| 1719 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1720 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1721 | write_log_for_name_lsa(name_lsa); |
| 1722 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1723 | |
| 1724 | destroy_name_lsa_component(name_lsa); |
| 1725 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1726 | hashtb_delete(e); |
| 1727 | i++; |
akmhoque | 14b3f34 | 2012-09-14 10:39:02 -0500 | [diff] [blame] | 1728 | } |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1729 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1730 | if ( nlsr->debugging ) |
| 1731 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1732 | if ( nlsr->detailed_logging ) |
| 1733 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1734 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1735 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1736 | |
| 1737 | if ( nlsr->debugging ) |
| 1738 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1739 | if ( nlsr->detailed_logging ) |
| 1740 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1741 | |
| 1742 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1743 | |
| 1744 | print_name_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1745 | } |
| 1746 | else |
| 1747 | { |
| 1748 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | else |
| 1752 | { |
| 1753 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1754 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1755 | if ( nlsr->debugging ) |
| 1756 | printf("Others Name LSA need to be deleted\n"); |
| 1757 | if ( nlsr->detailed_logging ) |
| 1758 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Name LSA need to be deleted\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1759 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1760 | delete_name_lsa(name_lsa->header->orig_router->name, name_lsa->name_prefix->name); |
| 1761 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n"); |
| 1762 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting name lsa\n"); |
| 1763 | write_log_for_name_lsa(name_lsa); |
| 1764 | writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n"); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1765 | |
| 1766 | destroy_name_lsa_component(name_lsa); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1767 | hashtb_delete(e); |
| 1768 | i++; |
| 1769 | } |
| 1770 | else |
| 1771 | { |
| 1772 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1773 | } |
| 1774 | } |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | hashtb_end(e); |
| 1778 | |
| 1779 | free(time_stamp); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1780 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1781 | |
| 1782 | } |
| 1783 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1784 | void |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1785 | refresh_adj_lsdb(void) |
| 1786 | { |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1787 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1788 | if ( nlsr->debugging ) |
| 1789 | printf("refresh_adj_lsdb called \n"); |
| 1790 | if ( nlsr->detailed_logging ) |
| 1791 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_adj_lsdb called \n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1792 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1793 | char *time_stamp=get_current_timestamp_micro_v2(); |
| 1794 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1795 | long int lsa_life_time; |
| 1796 | |
| 1797 | int i, adj_lsdb_element; |
| 1798 | struct alsa *adj_lsa; |
| 1799 | |
| 1800 | struct hashtb_enumerator ee; |
| 1801 | struct hashtb_enumerator *e = ⅇ |
| 1802 | |
| 1803 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 1804 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 1805 | |
| 1806 | for(i=0;i<adj_lsdb_element;i++) |
| 1807 | { |
| 1808 | adj_lsa=e->data; |
| 1809 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1810 | lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1811 | |
| 1812 | if ( nlsr->debugging ) |
| 1813 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1814 | if ( nlsr->detailed_logging ) |
| 1815 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1816 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1817 | if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1818 | { |
| 1819 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1820 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1821 | if ( nlsr->debugging ) |
| 1822 | printf("Own Adj LSA need to be refrshed\n"); |
| 1823 | if ( nlsr->detailed_logging ) |
| 1824 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Adj LSA need to be refrshed\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1825 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1826 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1827 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1828 | write_log_for_adj_lsa(adj_lsa); |
| 1829 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1830 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1831 | char *current_time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1832 | |
| 1833 | free(adj_lsa->header->orig_time); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1834 | 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] | 1835 | memcpy(adj_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1836 | |
| 1837 | free(current_time_stamp); |
| 1838 | |
akmhoque | a98c214 | 2012-10-25 15:22:24 -0500 | [diff] [blame] | 1839 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1840 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding adj lsa\n"); |
| 1841 | write_log_for_adj_lsa(adj_lsa); |
| 1842 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1843 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1844 | if ( nlsr->debugging ) |
| 1845 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1846 | if ( nlsr->detailed_logging ) |
| 1847 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1848 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1849 | set_new_lsdb_version(); |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1850 | |
| 1851 | if ( nlsr->debugging ) |
| 1852 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1853 | if ( nlsr->detailed_logging ) |
| 1854 | 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] | 1855 | |
| 1856 | print_adj_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1857 | |
| 1858 | |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1859 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1860 | |
| 1861 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1866 | { |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 1867 | |
| 1868 | if ( nlsr->debugging ) |
| 1869 | printf("Others Adj LSA need to be deleted\n"); |
| 1870 | if ( nlsr->detailed_logging ) |
| 1871 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1872 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Adj-LSA\n"); |
| 1873 | writeLogg(__FILE__,__FUNCTION__,__LINE__," Deleting adj lsa\n"); |
| 1874 | write_log_for_adj_lsa(adj_lsa); |
| 1875 | writeLogg(__FILE__,__FUNCTION__,__LINE__," adj_lsa_end\n"); |
| 1876 | delete_adj_lsa(); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1877 | |
| 1878 | destroy_adj_lsa_component(adj_lsa); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1879 | hashtb_delete(e); |
| 1880 | i++; |
| 1881 | |
| 1882 | } |
| 1883 | else |
| 1884 | { |
| 1885 | hashtb_next(e); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 1886 | } |
| 1887 | } |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1888 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | hashtb_end(e); |
| 1892 | |
| 1893 | free(time_stamp); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1894 | } |
| 1895 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1896 | |
| 1897 | void |
| 1898 | refresh_cor_lsdb(void) |
| 1899 | { |
| 1900 | |
| 1901 | if ( nlsr->debugging ) |
| 1902 | printf("refresh_cor_lsdb called \n"); |
| 1903 | if ( nlsr->detailed_logging ) |
| 1904 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_cor_lsdb called \n"); |
| 1905 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1906 | char *time_stamp=get_current_timestamp_micro_v2(); |
| 1907 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1908 | long int lsa_life_time; |
| 1909 | |
| 1910 | int i, cor_lsdb_element; |
| 1911 | struct clsa *cor_lsa; |
| 1912 | |
| 1913 | struct hashtb_enumerator ee; |
| 1914 | struct hashtb_enumerator *e = ⅇ |
| 1915 | |
| 1916 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 1917 | cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb); |
| 1918 | |
| 1919 | for(i=0;i<cor_lsdb_element;i++) |
| 1920 | { |
| 1921 | cor_lsa=e->data; |
| 1922 | |
| 1923 | lsa_life_time=get_time_diff(time_stamp,cor_lsa->header->orig_time); |
| 1924 | |
| 1925 | if ( nlsr->debugging ) |
| 1926 | printf("LSA Life Time: %ld \n",lsa_life_time); |
| 1927 | if ( nlsr->detailed_logging ) |
| 1928 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Life Time: %ld \n",lsa_life_time); |
| 1929 | |
| 1930 | if ( strcmp(cor_lsa->header->orig_router->name,nlsr->router_name) == 0) |
| 1931 | { |
| 1932 | if ( lsa_life_time > nlsr->lsa_refresh_time ) |
| 1933 | { |
| 1934 | if ( nlsr->debugging ) |
| 1935 | printf("Own Cor LSA need to be refrshed\n"); |
| 1936 | if ( nlsr->detailed_logging ) |
| 1937 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Own Cor LSA need to be refrshed\n"); |
| 1938 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1939 | char *current_time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1940 | |
| 1941 | free(cor_lsa->header->orig_time); |
| 1942 | cor_lsa->header->orig_time=(char *)malloc(strlen(current_time_stamp)+1); //free |
| 1943 | memset(cor_lsa->header->orig_time,0,strlen(current_time_stamp)+1); |
| 1944 | memcpy(cor_lsa->header->orig_time,current_time_stamp,strlen(current_time_stamp)+1); |
| 1945 | |
| 1946 | free(current_time_stamp); |
| 1947 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1948 | if ( nlsr->debugging ) |
| 1949 | printf("Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1950 | if ( nlsr->detailed_logging ) |
| 1951 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Old Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1952 | |
| 1953 | set_new_lsdb_version(); |
| 1954 | |
| 1955 | if ( nlsr->debugging ) |
| 1956 | printf("New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1957 | if ( nlsr->detailed_logging ) |
| 1958 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"New Version Number of LSDB: %s \n",nlsr->lsdb->lsdb_version); |
| 1959 | |
| 1960 | print_adj_lsdb(); |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | hashtb_next(e); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1964 | } |
| 1965 | else |
| 1966 | { |
| 1967 | if ( lsa_life_time > nlsr->router_dead_interval ) |
| 1968 | { |
| 1969 | |
| 1970 | if ( nlsr->debugging ) |
| 1971 | printf("Others Adj LSA need to be deleted\n"); |
| 1972 | if ( nlsr->detailed_logging ) |
| 1973 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Others Adj LSA need to be deleted\n"); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 1974 | |
| 1975 | destroy_cor_lsa_component(cor_lsa); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1976 | hashtb_delete(e); |
| 1977 | i++; |
| 1978 | } |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1979 | else |
| 1980 | { |
| 1981 | hashtb_next(e); |
| 1982 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | |
akmhoque | 866c222 | 2013-02-12 10:49:33 -0600 | [diff] [blame] | 1986 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | hashtb_end(e); |
| 1990 | |
| 1991 | free(time_stamp); |
| 1992 | } |
| 1993 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 1994 | int |
| 1995 | refresh_lsdb(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags) |
| 1996 | { |
| 1997 | if(flags == CCN_SCHEDULE_CANCEL) |
| 1998 | { |
| 1999 | return -1; |
| 2000 | } |
| 2001 | |
| 2002 | nlsr_lock(); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 2003 | |
akmhoque | 7b79145 | 2012-10-30 11:24:56 -0500 | [diff] [blame] | 2004 | if ( nlsr->debugging ) |
| 2005 | printf("refresh_lsdb called\n"); |
| 2006 | if ( nlsr->detailed_logging ) |
| 2007 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n"); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2008 | |
| 2009 | refresh_name_lsdb(); |
| 2010 | refresh_adj_lsdb(); |
| 2011 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2012 | nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0); |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 2013 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 2014 | nlsr_unlock(); |
| 2015 | return 0; |
| 2016 | } |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2017 | |
| 2018 | void |
| 2019 | write_adj_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id) |
| 2020 | { |
| 2021 | if ( nlsr->debugging ) |
| 2022 | printf("write_adj_lsa_to_repo called\n"); |
| 2023 | if ( nlsr->debugging ) |
| 2024 | printf("Content Prefix: %s\n",repo_content_prefix); |
| 2025 | |
| 2026 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2027 | get_adj_lsa_data(lsa_data,lsa_id); |
| 2028 | if ( nlsr->debugging ) |
akmhoque | 323b5e9 | 2013-02-21 13:55:15 -0600 | [diff] [blame] | 2029 | printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2030 | |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 2031 | char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char)); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2032 | data=ccn_charbuf_as_string(lsa_data); |
| 2033 | data[strlen(data)]='\0'; |
| 2034 | |
| 2035 | write_data_to_repo(data, repo_content_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2036 | |
akmhoque | 323b5e9 | 2013-02-21 13:55:15 -0600 | [diff] [blame] | 2037 | |
akmhoque | aa2adc1 | 2013-02-25 17:42:28 -0600 | [diff] [blame] | 2038 | //ccn_charbuf_destroy(&lsa_data); |
| 2039 | //free(data); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void |
| 2043 | write_name_lsa_to_repo(char *repo_content_prefix, struct name_prefix *lsa_id) |
| 2044 | { |
| 2045 | if ( nlsr->debugging ) |
| 2046 | printf("write_name_lsa_to_repo called\n"); |
| 2047 | if ( nlsr->debugging ) |
| 2048 | printf("Content Prefix: %s\n",repo_content_prefix); |
| 2049 | |
| 2050 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2051 | get_name_lsa_data(lsa_data,lsa_id); |
| 2052 | |
| 2053 | if ( nlsr->debugging ) |
| 2054 | printf("Name LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2055 | |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 2056 | char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char)); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2057 | data=ccn_charbuf_as_string(lsa_data); |
| 2058 | data[strlen(data)]='\0'; |
akmhoque | 323b5e9 | 2013-02-21 13:55:15 -0600 | [diff] [blame] | 2059 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2060 | write_data_to_repo(data, repo_content_prefix); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2061 | |
akmhoque | aa2adc1 | 2013-02-25 17:42:28 -0600 | [diff] [blame] | 2062 | //ccn_charbuf_destroy(&lsa_data); |
| 2063 | //free(data); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
| 2067 | void |
| 2068 | write_name_lsdb_to_repo(char *slice_prefix) |
| 2069 | { |
| 2070 | int i, name_lsdb_element; |
| 2071 | |
| 2072 | struct nlsa *name_lsa; |
| 2073 | struct hashtb_enumerator ee; |
| 2074 | struct hashtb_enumerator *e = ⅇ |
| 2075 | |
| 2076 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 2077 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 2078 | |
| 2079 | for(i=0;i<name_lsdb_element;i++) |
| 2080 | { |
| 2081 | name_lsa=e->data; |
| 2082 | |
| 2083 | char lst[2]; |
| 2084 | memset(lst,0,2); |
| 2085 | sprintf(lst,"%d",name_lsa->header->ls_type); |
| 2086 | |
| 2087 | char lsid[10]; |
| 2088 | memset(lsid,0,10); |
| 2089 | sprintf(lsid,"%ld",name_lsa->header->ls_id); |
| 2090 | |
| 2091 | |
| 2092 | char *key=(char *)malloc(strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2093 | memset(key,0,strlen(name_lsa->header->orig_router->name)+1+strlen(lst)+1+strlen(lsid)+1); |
| 2094 | |
| 2095 | |
| 2096 | make_name_lsa_key(key, name_lsa->header->orig_router->name,name_lsa->header->ls_type,name_lsa->header->ls_id); |
| 2097 | |
| 2098 | if ( nlsr->debugging ) |
| 2099 | printf("Name LSA Key: %s \n",key); |
| 2100 | |
| 2101 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2102 | 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] | 2103 | 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); |
| 2104 | |
| 2105 | if ( nlsr->debugging ) |
| 2106 | printf("Name LSA Repo Key: %s \n",repo_key); |
| 2107 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2108 | struct name_prefix *lsaid=(struct name_prefix *)calloc(1,sizeof(struct name_prefix)); |
| 2109 | lsaid->name=(char *)calloc(strlen(key)+1,sizeof(char)); |
| 2110 | memcpy(lsaid->name,key,strlen(key)+1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2111 | lsaid->length=strlen(key)+1; |
| 2112 | |
| 2113 | |
| 2114 | write_name_lsa_to_repo(repo_key, lsaid); |
| 2115 | |
| 2116 | free(key); |
| 2117 | free(repo_key); |
| 2118 | free(lsaid->name); |
| 2119 | free(lsaid); |
| 2120 | |
| 2121 | hashtb_next(e); |
| 2122 | } |
| 2123 | |
| 2124 | hashtb_end(e); |
| 2125 | |
| 2126 | |
| 2127 | } |
| 2128 | |
| 2129 | void |
| 2130 | print_cor_lsa(struct clsa *cor_lsa) |
| 2131 | { |
| 2132 | if ( nlsr->debugging ) |
| 2133 | { |
| 2134 | printf("-----------Cor LSA Content---------------\n"); |
| 2135 | printf(" Origination Router : %s\n",cor_lsa->header->orig_router->name); |
| 2136 | printf(" Origination Router Length: %d\n",cor_lsa->header->orig_router->length); |
| 2137 | printf(" LS Type : %d\n",cor_lsa->header->ls_type); |
| 2138 | printf(" Origination Time : %s\n",cor_lsa->header->orig_time); |
| 2139 | printf(" LSA Data \n"); |
| 2140 | printf(" Cor R: : %f\n",cor_lsa->cor_r); |
| 2141 | printf(" Cor Theta : %f\n",cor_lsa->cor_theta); |
| 2142 | |
| 2143 | printf("\n"); |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | void |
| 2148 | print_cor_lsdb() |
| 2149 | { |
| 2150 | |
| 2151 | if ( nlsr->debugging ) |
| 2152 | printf("print_cor_lsdb called \n"); |
| 2153 | |
| 2154 | struct hashtb_enumerator ee; |
| 2155 | struct hashtb_enumerator *e = ⅇ |
| 2156 | |
| 2157 | int i=1; |
| 2158 | |
| 2159 | for (hashtb_start(nlsr->lsdb->cor_lsdb, e); e->key != NULL; hashtb_next(e)) |
| 2160 | { |
| 2161 | if ( nlsr->debugging ) |
| 2162 | printf("-----------Cor LSA (%d)---------------\n",i); |
| 2163 | struct clsa *cor_lsa=e->data; |
| 2164 | print_cor_lsa(cor_lsa); |
| 2165 | i++; |
| 2166 | } |
| 2167 | hashtb_end(e); |
| 2168 | |
| 2169 | if ( nlsr->debugging ) |
| 2170 | printf("\n"); |
| 2171 | if ( nlsr->detailed_logging ) |
| 2172 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n"); |
| 2173 | } |
| 2174 | |
| 2175 | void |
| 2176 | install_cor_lsa(struct clsa *cor_lsa) |
| 2177 | { |
| 2178 | if ( nlsr->debugging ) |
| 2179 | printf("install_cor_lsa called \n"); |
| 2180 | if ( nlsr->detailed_logging ) |
| 2181 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n"); |
| 2182 | |
| 2183 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 2184 | //char *time_stamp=(char *)malloc(20); |
| 2185 | //memset(time_stamp,0,20); |
| 2186 | //get_current_timestamp_micro(time_stamp); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2187 | |
| 2188 | |
akmhoque | 569a93d | 2013-02-21 10:19:54 -0600 | [diff] [blame] | 2189 | char *key=(char *)malloc(cor_lsa->header->orig_router->length+4); |
| 2190 | memset(key,0,cor_lsa->header->orig_router->length+4); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2191 | make_cor_lsa_key(key,cor_lsa); |
| 2192 | |
| 2193 | if ( nlsr->debugging ) |
| 2194 | printf("Cor LSA key: %s \n",key); |
| 2195 | |
| 2196 | struct hashtb_enumerator ee; |
| 2197 | struct hashtb_enumerator *e = ⅇ |
| 2198 | int res; |
| 2199 | |
| 2200 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2201 | res = hashtb_seek(e, key, strlen(key), 0); |
| 2202 | |
| 2203 | if ( res == HT_NEW_ENTRY ) |
| 2204 | { |
| 2205 | if ( nlsr->debugging ) |
| 2206 | printf("New Cor LSA... \n"); |
| 2207 | |
akmhoque | 8876e98 | 2013-02-21 13:35:46 -0600 | [diff] [blame] | 2208 | struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa )); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2209 | new_cor_lsa=e->data; |
| 2210 | new_cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2211 | |
| 2212 | new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 2213 | new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1); |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 2214 | //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2215 | memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1); |
| 2216 | new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length; |
| 2217 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 2218 | //new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free |
| 2219 | //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1); |
| 2220 | //memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1); |
| 2221 | new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2222 | |
| 2223 | new_cor_lsa->header->ls_type=cor_lsa->header->ls_type; |
| 2224 | |
| 2225 | new_cor_lsa->cor_r=cor_lsa->cor_r; |
| 2226 | new_cor_lsa->cor_theta=cor_lsa->cor_theta; |
| 2227 | } |
| 2228 | else if ( res == HT_OLD_ENTRY ) |
| 2229 | { |
| 2230 | if ( nlsr->debugging ) |
| 2231 | printf("Cor LSA exists (Old)... \n"); |
| 2232 | } |
| 2233 | hashtb_end(e); |
| 2234 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2235 | free(key); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2236 | |
| 2237 | } |
| 2238 | |
| 2239 | void |
| 2240 | build_cor_lsa(struct clsa *cor_lsa, double cor_r, double cor_theta) |
| 2241 | { |
| 2242 | cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2243 | cor_lsa->header->ls_type=LS_TYPE_COR; |
| 2244 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2245 | char *time_stamp=get_current_timestamp_micro_v2(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2246 | cor_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free |
| 2247 | memset(cor_lsa->header->orig_time,0,strlen(time_stamp)+1); |
| 2248 | memcpy(cor_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1); |
| 2249 | free(time_stamp); |
| 2250 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2251 | cor_lsa->header->orig_router=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); |
| 2252 | 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] | 2253 | memset(cor_lsa->header->orig_router->name,0,strlen(nlsr->router_name)+1); |
| 2254 | memcpy(cor_lsa->header->orig_router->name,nlsr->router_name,strlen(nlsr->router_name)+1); |
| 2255 | cor_lsa->header->orig_router->length=strlen(nlsr->router_name)+1; |
| 2256 | |
| 2257 | cor_lsa->cor_r=cor_r; |
| 2258 | cor_lsa->cor_theta=cor_theta; |
| 2259 | |
| 2260 | } |
| 2261 | |
| 2262 | void |
| 2263 | build_others_cor_lsa(struct clsa *cor_lsa,char *orig_router, int ls_type,char *orig_time, double cor_r, double cor_theta) |
| 2264 | { |
| 2265 | cor_lsa->header=(struct alsa_header *)malloc(sizeof(struct alsa_header )); |
| 2266 | cor_lsa->header->ls_type=ls_type; |
| 2267 | |
| 2268 | cor_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1); |
| 2269 | memset(cor_lsa->header->orig_time,0,strlen(orig_time)+1); |
akmhoque | 569a93d | 2013-02-21 10:19:54 -0600 | [diff] [blame] | 2270 | memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2271 | |
| 2272 | cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix )); |
| 2273 | cor_lsa->header->orig_router->name=(char *)malloc(strlen(orig_router)+1); |
| 2274 | memset(cor_lsa->header->orig_router->name,0,strlen(orig_router)+1); |
akmhoque | 569a93d | 2013-02-21 10:19:54 -0600 | [diff] [blame] | 2275 | memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2276 | cor_lsa->header->orig_router->length=strlen(orig_router)+1; |
| 2277 | |
| 2278 | cor_lsa->cor_r=cor_r; |
| 2279 | cor_lsa->cor_theta=cor_theta; |
| 2280 | |
| 2281 | } |
| 2282 | |
| 2283 | void |
| 2284 | build_and_install_others_cor_lsa(char *orig_router,int ls_type,char *orig_time, double cor_r, double cor_theta) |
| 2285 | { |
| 2286 | struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa )); |
| 2287 | build_others_cor_lsa(cor_lsa,orig_router,ls_type, orig_time, cor_r, cor_theta); |
| 2288 | install_cor_lsa(cor_lsa); |
| 2289 | |
| 2290 | print_cor_lsdb(); |
akmhoque | 569a93d | 2013-02-21 10:19:54 -0600 | [diff] [blame] | 2291 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2292 | destroy_cor_lsa(cor_lsa); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | |
| 2296 | void |
| 2297 | build_and_install_cor_lsa() |
| 2298 | { |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | struct clsa *cor_lsa=(struct clsa *)malloc(sizeof( struct clsa )); |
| 2303 | |
| 2304 | build_cor_lsa(cor_lsa,nlsr->cor_r,nlsr->cor_theta); |
| 2305 | install_cor_lsa(cor_lsa); |
| 2306 | |
| 2307 | write_cor_lsa_to_repo(cor_lsa); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2308 | destroy_cor_lsa(cor_lsa); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2309 | |
| 2310 | print_cor_lsdb(); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2311 | |
| 2312 | } |
| 2313 | |
| 2314 | void |
| 2315 | get_cor_lsa_data(struct ccn_charbuf *lsa_data,char *cor_lsa_key) |
| 2316 | { |
| 2317 | if ( nlsr->debugging ) |
| 2318 | printf("get_cor_lsa_data called \n"); |
| 2319 | if ( nlsr->detailed_logging ) |
| 2320 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n"); |
| 2321 | |
akmhoque | cecba94 | 2013-02-25 17:33:34 -0600 | [diff] [blame] | 2322 | struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa )); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2323 | |
| 2324 | struct hashtb_enumerator ee; |
| 2325 | struct hashtb_enumerator *e = ⅇ |
| 2326 | int res; |
| 2327 | |
| 2328 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2329 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2330 | |
| 2331 | if( res == HT_OLD_ENTRY ) |
| 2332 | { |
| 2333 | cor_lsa=e->data; |
| 2334 | |
| 2335 | if ( nlsr->debugging ) |
| 2336 | printf("Cor LSA found \n"); |
| 2337 | if ( nlsr->detailed_logging ) |
| 2338 | writeLogg(__FILE__,__FUNCTION__,__LINE__,"Cor LSA found \n"); |
| 2339 | |
| 2340 | ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_router->name); |
| 2341 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2342 | |
| 2343 | char *temp_length=(char *)malloc(20); |
| 2344 | memset(temp_length,0,20); |
| 2345 | sprintf(temp_length,"%d",cor_lsa->header->orig_router->length); |
| 2346 | ccn_charbuf_append_string(lsa_data,temp_length); |
| 2347 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2348 | free(temp_length); |
| 2349 | |
| 2350 | char *temp_ltype=(char *)malloc(20); |
| 2351 | memset(temp_ltype,0,20); |
| 2352 | sprintf(temp_ltype,"%d",cor_lsa->header->ls_type); |
| 2353 | ccn_charbuf_append_string(lsa_data,temp_ltype); |
| 2354 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2355 | free(temp_ltype); |
| 2356 | |
| 2357 | ccn_charbuf_append_string(lsa_data,cor_lsa->header->orig_time); |
| 2358 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2359 | |
| 2360 | char *cor_r=(char *)malloc(20); |
| 2361 | memset(cor_r,0,20); |
| 2362 | sprintf(cor_r,"%f",cor_lsa->cor_r); |
| 2363 | ccn_charbuf_append_string(lsa_data,cor_r); |
| 2364 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2365 | free(cor_r); |
| 2366 | |
| 2367 | char *cor_theta=(char *)malloc(20); |
| 2368 | memset(cor_theta,0,20); |
| 2369 | sprintf(cor_theta,"%f",cor_lsa->cor_theta); |
| 2370 | ccn_charbuf_append_string(lsa_data,cor_theta); |
| 2371 | ccn_charbuf_append_string(lsa_data,"|"); |
| 2372 | free(cor_theta); |
| 2373 | |
| 2374 | } |
| 2375 | else if(res == HT_NEW_ENTRY) |
| 2376 | { |
| 2377 | hashtb_delete(e); |
| 2378 | } |
| 2379 | |
| 2380 | hashtb_end(e); |
| 2381 | } |
| 2382 | |
| 2383 | void |
| 2384 | write_cor_lsa_to_repo(struct clsa *cor_lsa) |
| 2385 | { |
| 2386 | |
| 2387 | |
| 2388 | if ( nlsr->debugging ) |
| 2389 | printf("write_cor_lsa_to_repo called\n"); |
| 2390 | |
| 2391 | |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2392 | char *key=(char *)calloc(cor_lsa->header->orig_router->length+4,sizeof(char)); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2393 | make_cor_lsa_key(key,cor_lsa); |
| 2394 | |
| 2395 | struct ccn_charbuf *lsa_data=ccn_charbuf_create(); |
| 2396 | get_cor_lsa_data(lsa_data,key); |
akmhoque | 323b5e9 | 2013-02-21 13:55:15 -0600 | [diff] [blame] | 2397 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2398 | if ( nlsr->debugging ) |
akmhoque | 0800eda | 2013-02-21 14:17:52 -0600 | [diff] [blame] | 2399 | printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data)); |
| 2400 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2401 | char *lst=(char *)malloc(20); |
| 2402 | memset(lst,0,20); |
| 2403 | sprintf(lst,"%d",cor_lsa->header->ls_type); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2404 | 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] | 2405 | 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); |
| 2406 | |
| 2407 | if ( nlsr->debugging ) |
| 2408 | printf("Cor LSA Repo Key: %s \n",repo_key); |
| 2409 | |
akmhoque | 829228c | 2013-02-25 17:39:40 -0600 | [diff] [blame] | 2410 | char *data;//=calloc(strlen(ccn_charbuf_as_string(lsa_data))+1,sizeof(char)); |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2411 | data=ccn_charbuf_as_string(lsa_data); |
| 2412 | data[strlen(data)]='\0'; |
| 2413 | |
| 2414 | write_data_to_repo(data, repo_key); |
akmhoque | 0800eda | 2013-02-21 14:17:52 -0600 | [diff] [blame] | 2415 | |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2416 | |
| 2417 | |
| 2418 | |
| 2419 | free(lst); |
| 2420 | free(key); |
| 2421 | free(repo_key); |
akmhoque | aa2adc1 | 2013-02-25 17:42:28 -0600 | [diff] [blame] | 2422 | //free(data); |
| 2423 | //ccn_charbuf_destroy(&lsa_data); |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | void |
| 2427 | make_cor_lsa_key_by_router_name(char *key,char *router_name) |
| 2428 | { |
| 2429 | memcpy(key+strlen(key),router_name,strlen(router_name)); |
| 2430 | memcpy(key+strlen(key),"/",1); |
| 2431 | char ls_type[2]; |
| 2432 | sprintf(ls_type,"%d",LS_TYPE_COR); |
| 2433 | memcpy(key+strlen(key),ls_type,strlen(ls_type)); |
| 2434 | key[strlen(key)]='\0'; |
| 2435 | } |
| 2436 | |
| 2437 | |
| 2438 | double |
| 2439 | get_hyperbolic_r(char *router) |
| 2440 | { |
| 2441 | double ret=-1.0; |
| 2442 | char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char)); |
| 2443 | make_cor_lsa_key_by_router_name(cor_lsa_key,router); |
| 2444 | |
| 2445 | |
| 2446 | struct clsa *cor_lsa; |
| 2447 | struct hashtb_enumerator ee; |
| 2448 | struct hashtb_enumerator *e = ⅇ |
| 2449 | int res; |
| 2450 | |
| 2451 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2452 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2453 | |
| 2454 | if ( res == HT_OLD_ENTRY) |
| 2455 | { |
| 2456 | cor_lsa=e->data; |
| 2457 | ret=cor_lsa->cor_r; |
| 2458 | } |
| 2459 | else if(res == HT_NEW_ENTRY) |
| 2460 | { |
| 2461 | hashtb_delete(e); |
| 2462 | } |
| 2463 | |
| 2464 | hashtb_end(e); |
| 2465 | |
| 2466 | free(cor_lsa_key); |
| 2467 | return ret; |
| 2468 | } |
| 2469 | |
| 2470 | double |
| 2471 | get_hyperbolic_theta(char *router) |
| 2472 | { |
akmhoque | f5537b4 | 2013-02-22 08:33:32 -0600 | [diff] [blame] | 2473 | double ret=-1.0; |
akmhoque | b77b95f | 2013-02-08 12:28:47 -0600 | [diff] [blame] | 2474 | char *cor_lsa_key=(char *)calloc(strlen(router)+4,sizeof(char)); |
| 2475 | make_cor_lsa_key_by_router_name(cor_lsa_key,router); |
| 2476 | |
| 2477 | struct clsa *cor_lsa; |
| 2478 | struct hashtb_enumerator ee; |
| 2479 | struct hashtb_enumerator *e = ⅇ |
| 2480 | int res; |
| 2481 | |
| 2482 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2483 | res = hashtb_seek(e, cor_lsa_key, strlen(cor_lsa_key), 0); |
| 2484 | |
| 2485 | if ( res == HT_OLD_ENTRY) |
| 2486 | { |
| 2487 | cor_lsa=e->data; |
| 2488 | ret=cor_lsa->cor_theta; |
| 2489 | } |
| 2490 | else if(res == HT_NEW_ENTRY) |
| 2491 | { |
| 2492 | hashtb_delete(e); |
| 2493 | } |
| 2494 | |
| 2495 | hashtb_end(e); |
| 2496 | |
| 2497 | free(cor_lsa_key); |
| 2498 | return ret; |
| 2499 | } |
akmhoque | ad58478 | 2013-02-22 10:56:03 -0600 | [diff] [blame] | 2500 | |
| 2501 | |
| 2502 | void |
| 2503 | destroy_name_lsdb(void) |
| 2504 | { |
| 2505 | int i, name_lsdb_element; |
| 2506 | struct nlsa *name_lsa; |
| 2507 | |
| 2508 | struct hashtb_enumerator ee; |
| 2509 | struct hashtb_enumerator *e = ⅇ |
| 2510 | |
| 2511 | hashtb_start(nlsr->lsdb->name_lsdb, e); |
| 2512 | name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb); |
| 2513 | |
| 2514 | for(i=0;i<name_lsdb_element;i++) |
| 2515 | { |
| 2516 | name_lsa=e->data; |
| 2517 | destroy_name_lsa_component(name_lsa); |
| 2518 | hashtb_next(e); |
| 2519 | } |
| 2520 | |
| 2521 | hashtb_end(e); |
| 2522 | |
| 2523 | if ( nlsr->lsdb->name_lsdb ) |
| 2524 | hashtb_destroy(&nlsr->lsdb->name_lsdb); |
| 2525 | } |
| 2526 | |
| 2527 | void |
| 2528 | destroy_adj_lsdb(void) |
| 2529 | { |
| 2530 | int i, adj_lsdb_element; |
| 2531 | struct alsa *adj_lsa; |
| 2532 | |
| 2533 | struct hashtb_enumerator ee; |
| 2534 | struct hashtb_enumerator *e = ⅇ |
| 2535 | |
| 2536 | hashtb_start(nlsr->lsdb->adj_lsdb, e); |
| 2537 | adj_lsdb_element=hashtb_n(nlsr->lsdb->adj_lsdb); |
| 2538 | |
| 2539 | for(i=0;i<adj_lsdb_element;i++) |
| 2540 | { |
| 2541 | adj_lsa=e->data; |
| 2542 | destroy_adj_lsa_component(adj_lsa); |
| 2543 | hashtb_next(e); |
| 2544 | } |
| 2545 | |
| 2546 | hashtb_end(e); |
| 2547 | if(nlsr->lsdb->adj_lsdb ) |
| 2548 | hashtb_destroy(&nlsr->lsdb->adj_lsdb); |
| 2549 | } |
| 2550 | |
| 2551 | void |
| 2552 | destroy_cor_lsdb(void) |
| 2553 | { |
| 2554 | int i, cor_lsdb_element; |
| 2555 | struct clsa *cor_lsa; |
| 2556 | |
| 2557 | struct hashtb_enumerator ee; |
| 2558 | struct hashtb_enumerator *e = ⅇ |
| 2559 | |
| 2560 | hashtb_start(nlsr->lsdb->cor_lsdb, e); |
| 2561 | cor_lsdb_element=hashtb_n(nlsr->lsdb->cor_lsdb); |
| 2562 | |
| 2563 | for(i=0;i<cor_lsdb_element;i++) |
| 2564 | { |
| 2565 | cor_lsa=e->data; |
| 2566 | destroy_cor_lsa_component(cor_lsa); |
| 2567 | hashtb_next(e); |
| 2568 | } |
| 2569 | |
| 2570 | hashtb_end(e); |
| 2571 | if(nlsr->lsdb->cor_lsdb ) |
| 2572 | hashtb_destroy(&nlsr->lsdb->cor_lsdb); |
| 2573 | } |
| 2574 | |
| 2575 | void |
| 2576 | destroy_lsdb(void) |
| 2577 | { |
| 2578 | destroy_name_lsdb(); |
| 2579 | destroy_adj_lsdb(); |
| 2580 | destroy_cor_lsdb(); |
| 2581 | |
| 2582 | if ( nlsr->lsdb->lsdb_version ) |
| 2583 | free(nlsr->lsdb->lsdb_version); |
| 2584 | if ( nlsr->lsdb ) |
| 2585 | free(nlsr->lsdb); |
| 2586 | } |