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