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