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