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