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