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