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