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