blob: 6c18921069e41ac9d255b3d8d5de19694536ea07 [file] [log] [blame]
akmhoquef1161eb2012-08-21 09:37:21 -04001#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"
akmhoque03004e62012-09-06 01:12:28 -050021#include "nlsr_ndn.h"
akmhoquef1161eb2012-08-21 09:37:21 -040022#include "nlsr_lsdb.h"
akmhoquef71d9082012-08-22 12:51:53 -040023#include "utility.h"
akmhoque03004e62012-09-06 01:12:28 -050024#include "nlsr_npl.h"
akmhoque53f64222012-09-05 13:57:51 -050025#include "nlsr_adl.h"
akmhoque29c1db52012-09-07 14:47:43 -050026#include "nlsr_route.h"
akmhoque3560cb62012-09-09 10:52:30 -050027#include "nlsr_npt.h"
akmhoqueb77b95f2013-02-08 12:28:47 -060028#include "nlsr_sync.h"
akmhoque438b07e2012-08-21 10:13:57 -040029
akmhoque0ab71642013-02-21 10:10:33 -060030/**
31* LSDB version is updated to last updated timestamp
32*/
33
akmhoquef71d9082012-08-22 12:51:53 -040034void
akmhoque53f64222012-09-05 13:57:51 -050035set_new_lsdb_version(void)
akmhoquef71d9082012-08-22 12:51:53 -040036{
akmhoque6682ca32013-02-22 00:29:35 -060037 //char *time_stamp=(char *)malloc(20);
38 //memset(time_stamp,0,20);
39 //get_current_timestamp_micro(time_stamp);
akmhoquef71d9082012-08-22 12:51:53 -040040
akmhoque6682ca32013-02-22 00:29:35 -060041 char *time_stamp=get_current_timestamp_micro_v2();
akmhoque03004e62012-09-06 01:12:28 -050042 free(nlsr->lsdb->lsdb_version);
akmhoque6682ca32013-02-22 00:29:35 -060043 nlsr->lsdb->lsdb_version=(char *)calloc(strlen(time_stamp)+1,sizeof(char));
akmhoque03004e62012-09-06 01:12:28 -050044 memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -050045 free(time_stamp);
akmhoque6682ca32013-02-22 00:29:35 -060046 //memcpy(nlsr->lsdb->lsdb_version,time_stamp,strlen(time_stamp)+1);
47
48 //free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -050049
akmhoquef71d9082012-08-22 12:51:53 -040050}
51
akmhoque0ab71642013-02-21 10:10:33 -060052/**
53* Make key for storing Name LSA in Name LSDB
54*/
55
akmhoque03004e62012-09-06 01:12:28 -050056void
57make_name_lsa_key(char *key, char *orig_router, int ls_type, long int ls_id)
58{
59
akmhoque03004e62012-09-06 01:12:28 -050060 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));
akmhoque03004e62012-09-06 01:12:28 -050073
akmhoqueb77b95f2013-02-08 12:28:47 -060074 if ( nlsr->debugging )
75 printf("name LSA Key: %s\n", key);
76}
77
akmhoque0ab71642013-02-21 10:10:33 -060078/**
79* Make content name prefix for Name LSA to store in repo
80*/
akmhoqueb77b95f2013-02-08 12:28:47 -060081
82void
akmhoque0ab71642013-02-21 10:10:33 -060083make_name_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
84 long int ls_id,char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -060085{
akmhoque0ab71642013-02-21 10:10:33 -060086 sprintf(key,"%s%s/lsType.%d/lsId.%ld/%s",slice_prefix, orig_router, ls_type,
87 ls_id, orig_time);
akmhoqueb77b95f2013-02-08 12:28:47 -060088
89 if ( nlsr->debugging )
90 printf("Name LSA prefix for repo content: %s\n",key);
91}
92
akmhoque0ab71642013-02-21 10:10:33 -060093/**
94* Make content name prefix for Adj LSA to store in repo
95*/
96
akmhoqueb77b95f2013-02-08 12:28:47 -060097void
akmhoque0ab71642013-02-21 10:10:33 -060098make_adj_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
99 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600100{
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
akmhoque0ab71642013-02-21 10:10:33 -0600108/**
109* Make content name prefix for Cor LSA to store in repo
110*/
111
akmhoqueb77b95f2013-02-08 12:28:47 -0600112void
akmhoque0ab71642013-02-21 10:10:33 -0600113make_cor_lsa_prefix_for_repo(char *key, char *orig_router, int ls_type,
114 char *orig_time,char *slice_prefix)
akmhoqueb77b95f2013-02-08 12:28:47 -0600115{
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);
akmhoque03004e62012-09-06 01:12:28 -0500121}
akmhoque53f64222012-09-05 13:57:51 -0500122
akmhoque0ab71642013-02-21 10:10:33 -0600123/**
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
akmhoquef71d9082012-08-22 12:51:53 -0400129void
akmhoque53f64222012-09-05 13:57:51 -0500130build_and_install_name_lsas(void)
akmhoquef71d9082012-08-22 12:51:53 -0400131{
akmhoque7b791452012-10-30 11:24:56 -0500132 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");
akmhoquef71d9082012-08-22 12:51:53 -0400136
akmhoquef71d9082012-08-22 12:51:53 -0400137 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600138 struct name_prefix_list_entry *npe;
akmhoquef71d9082012-08-22 12:51:53 -0400139
140 struct hashtb_enumerator ee;
141 struct hashtb_enumerator *e = &ee;
142
143 hashtb_start(nlsr->npl, e);
144 npl_element=hashtb_n(nlsr->npl);
145
146 for(i=0;i<npl_element;i++)
147 {
akmhoque3171d652012-11-13 11:44:33 -0600148 npe=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500149 struct nlsa *name_lsa=(struct nlsa *)malloc(sizeof( struct nlsa ));
akmhoque3171d652012-11-13 11:44:33 -0600150 build_name_lsa(name_lsa,npe->np);
akmhoque03004e62012-09-06 01:12:28 -0500151
akmhoquef71d9082012-08-22 12:51:53 -0400152 install_name_lsa(name_lsa);
akmhoque3171d652012-11-13 11:44:33 -0600153 update_nlsa_id_for_name_in_npl(npe->np,name_lsa->header->ls_id);
akmhoque54d86112013-02-21 16:42:34 -0600154 //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);
akmhoquef71d9082012-08-22 12:51:53 -0400160 hashtb_next(e);
161 }
162
akmhoque53f64222012-09-05 13:57:51 -0500163 hashtb_end(e);
akmhoque3171d652012-11-13 11:44:33 -0600164
165 print_name_prefix_from_npl();
166
167}
168
akmhoque0ab71642013-02-21 10:10:33 -0600169/**
170* Build and Install one Name LSA Use ful for API
171*/
172
akmhoque3171d652012-11-13 11:44:33 -0600173void
174build_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
akmhoque54d86112013-02-21 16:42:34 -0600187 //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);
akmhoque3171d652012-11-13 11:44:33 -0600192 free(name_lsa);
193
194 print_name_prefix_from_npl();
akmhoquef71d9082012-08-22 12:51:53 -0400195
akmhoquef71d9082012-08-22 12:51:53 -0400196}
197
akmhoque53f64222012-09-05 13:57:51 -0500198void
199build_name_lsa(struct nlsa *name_lsa, struct name_prefix *np)
200{
akmhoque53f64222012-09-05 13:57:51 -0500201 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
202 name_lsa->header->ls_type=LS_TYPE_NAME;
203
akmhoque03004e62012-09-06 01:12:28 -0500204 char *time_stamp=(char *)malloc(20);
205 memset(time_stamp,0,20);
206 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500207
akmhoque03004e62012-09-06 01:12:28 -0500208 name_lsa->header->orig_time=(char *)malloc(strlen(time_stamp)+1); //free
akmhoque53f64222012-09-05 13:57:51 -0500209 memset(name_lsa->header->orig_time,0,strlen(time_stamp)+1);
210 memcpy(name_lsa->header->orig_time,time_stamp,strlen(time_stamp)+1);
akmhoque03004e62012-09-06 01:12:28 -0500211
212 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500213
214 name_lsa->header->ls_id=++nlsr->nlsa_id;
215 name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoque03004e62012-09-06 01:12:28 -0500216 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;
akmhoque53f64222012-09-05 13:57:51 -0500220 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
akmhoque53f64222012-09-05 13:57:51 -0500230void
231install_name_lsa(struct nlsa *name_lsa)
232{
akmhoque53f64222012-09-05 13:57:51 -0500233
akmhoque54d86112013-02-21 16:42:34 -0600234 /*char *time_stamp=(char *)malloc(20);
akmhoqueffacaa82012-09-13 17:48:30 -0500235 memset(time_stamp,0,20);
akmhoque54d86112013-02-21 16:42:34 -0600236 get_current_timestamp_micro(time_stamp);*/
akmhoqueffacaa82012-09-13 17:48:30 -0500237
238
akmhoque0ab71642013-02-21 10:10:33 -0600239 char lst[2];
240 memset(lst,0,2);
241 sprintf(lst,"%d",name_lsa->header->ls_type);
akmhoqueffacaa82012-09-13 17:48:30 -0500242
akmhoque0ab71642013-02-21 10:10:33 -0600243 char lsid[10];
244 memset(lsid,0,10);
245 sprintf(lsid,"%ld",name_lsa->header->ls_id);
akmhoque3171d652012-11-13 11:44:33 -0600246
akmhoque0ab71642013-02-21 10:10:33 -0600247 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);
akmhoque53f64222012-09-05 13:57:51 -0500250
akmhoque0ab71642013-02-21 10:10:33 -0600251 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
akmhoque8876e982013-02-21 13:35:46 -0600256 struct nlsa *new_name_lsa; //=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque53f64222012-09-05 13:57:51 -0500257
akmhoque0ab71642013-02-21 10:10:33 -0600258 struct hashtb_enumerator ee;
259 struct hashtb_enumerator *e = &ee;
260 int res;
akmhoque53f64222012-09-05 13:57:51 -0500261
akmhoque0ab71642013-02-21 10:10:33 -0600262 hashtb_start(nlsr->lsdb->name_lsdb, e);
263 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500264
akmhoque0ab71642013-02-21 10:10:33 -0600265 if(res == HT_NEW_ENTRY )
akmhoque3560cb62012-09-09 10:52:30 -0500266 {
akmhoqueffacaa82012-09-13 17:48:30 -0500267
akmhoque7b791452012-10-30 11:24:56 -0500268 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
akmhoqueffacaa82012-09-13 17:48:30 -0500274 new_name_lsa = e->data;
akmhoque54d86112013-02-21 16:42:34 -0600275 //memcpy(e->data, name_lsa, sizeof(name_lsa));
akmhoque8876e982013-02-21 13:35:46 -0600276
akmhoque54d86112013-02-21 16:42:34 -0600277
akmhoque0ab71642013-02-21 10:10:33 -0600278 new_name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
akmhoqueffacaa82012-09-13 17:48:30 -0500279 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);
akmhoque8876e982013-02-21 13:35:46 -0600283 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time)+1);
akmhoqueffacaa82012-09-13 17:48:30 -0500284
285 new_name_lsa->header->ls_id=name_lsa->header->ls_id;
akmhoque0ab71642013-02-21 10:10:33 -0600286 new_name_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500287 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
akmhoque0ab71642013-02-21 10:10:33 -0600293 new_name_lsa->name_prefix=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
akmhoqueffacaa82012-09-13 17:48:30 -0500294 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;
akmhoque8876e982013-02-21 13:35:46 -0600297
akmhoqueffacaa82012-09-13 17:48:30 -0500298
akmhoque7b791452012-10-30 11:24:56 -0500299 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 }
akmhoque54d86112013-02-21 16:42:34 -0600309
akmhoqueffacaa82012-09-13 17:48:30 -0500310 set_new_lsdb_version();
akmhoque54d86112013-02-21 16:42:34 -0600311
akmhoque7b791452012-10-30 11:24:56 -0500312 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500316
akmhoque9e9fc722012-09-26 14:03:25 -0500317
akmhoquede61ba92012-09-20 22:19:12 -0500318 int num_next_hop=get_number_of_next_hop(new_name_lsa->header->orig_router->name);
akmhoquede61ba92012-09-20 22:19:12 -0500319 if ( num_next_hop < 0 )
akmhoque3560cb62012-09-09 10:52:30 -0500320 {
akmhoquede61ba92012-09-20 22:19:12 -0500321 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500322 if ( check == HT_NEW_ENTRY )
323 {
akmhoque7b791452012-10-30 11:24:56 -0500324 if ( nlsr->debugging )
325 printf("Added in npt \n");
326 if ( nlsr->detailed_logging )
327 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500328 }
akmhoque3560cb62012-09-09 10:52:30 -0500329 }
akmhoqueffacaa82012-09-13 17:48:30 -0500330 else
akmhoque3560cb62012-09-09 10:52:30 -0500331 {
akmhoquede61ba92012-09-20 22:19:12 -0500332 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);
akmhoque7b791452012-10-30 11:24:56 -0500335 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 }
akmhoquede61ba92012-09-20 22:19:12 -0500349 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500350 if ( check == HT_NEW_ENTRY )
351 {
akmhoque7b791452012-10-30 11:24:56 -0500352 if ( nlsr->debugging )
353 printf("Added in npt \n");
354 if ( nlsr->detailed_logging )
355 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500356 }
akmhoquede61ba92012-09-20 22:19:12 -0500357 free(faces);
358 free(route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500359
akmhoque3560cb62012-09-09 10:52:30 -0500360 }
akmhoquede61ba92012-09-20 22:19:12 -0500361
akmhoque9e9fc722012-09-26 14:03:25 -0500362 writeLogg(__FILE__,__FUNCTION__,__LINE__," Name-LSA\n");
363 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adding name lsa\n");
akmhoque54d86112013-02-21 16:42:34 -0600364 //write_log_for_name_lsa(new_name_lsa);
akmhoque9e9fc722012-09-26 14:03:25 -0500365 writeLogg(__FILE__,__FUNCTION__,__LINE__," name_lsa_end\n");
akmhoqueffacaa82012-09-13 17:48:30 -0500366
akmhoque54d86112013-02-21 16:42:34 -0600367 //free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -0500368
369 }
370 else if(res == HT_OLD_ENTRY)
371 {
372 new_name_lsa=e->data;
akmhoque14b3f342012-09-14 10:39:02 -0500373 if(strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time)<0)
akmhoqueffacaa82012-09-13 17:48:30 -0500374 {
akmhoque7b791452012-10-30 11:24:56 -0500375 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");
akmhoque14b3f342012-09-14 10:39:02 -0500379 }
380 else if( strcmp(name_lsa->header->orig_time,new_name_lsa->header->orig_time) == 0 )
381 {
akmhoque7b791452012-10-30 11:24:56 -0500382 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");
akmhoqueffacaa82012-09-13 17:48:30 -0500386 }
387 else
388 {
389 if ( name_lsa->header->isValid == 0 )
390 {
391 // have to call to delete npt table entry
akmhoque3cced642012-09-24 16:20:20 -0500392 delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500393
394 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name)!= 0)
395 {
akmhoque9e9fc722012-09-26 14:03:25 -0500396 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
akmhoqueffacaa82012-09-13 17:48:30 -0500401 hashtb_delete(e);
akmhoque7b791452012-10-30 11:24:56 -0500402 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500406 }
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 }
akmhoque7b791452012-10-30 11:24:56 -0500415 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500419 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500420 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500424 }
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;
akmhoque3cced642012-09-24 16:20:20 -0500431 delete_npt_entry_by_router_and_name_prefix(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name);
akmhoqueffacaa82012-09-13 17:48:30 -0500432 }
433
434 // copying LSA content with header
akmhoque9e9fc722012-09-26 14:03:25 -0500435 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
akmhoqueffacaa82012-09-13 17:48:30 -0500440
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);
akmhoque0ab71642013-02-21 10:10:33 -0600444 memcpy(new_name_lsa->header->orig_time,name_lsa->header->orig_time,strlen(name_lsa->header->orig_time));
akmhoqueffacaa82012-09-13 17:48:30 -0500445
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
akmhoque9e9fc722012-09-26 14:03:25 -0500455
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
akmhoque7b791452012-10-30 11:24:56 -0500461 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
akmhoqueffacaa82012-09-13 17:48:30 -0500466 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500467
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
akmhoqueffacaa82012-09-13 17:48:30 -0500473
474 if( is_npt_update == 1 )
475 {
akmhoquede61ba92012-09-20 22:19:12 -0500476 //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 )
akmhoqueffacaa82012-09-13 17:48:30 -0500479 {
akmhoquede61ba92012-09-20 22:19:12 -0500480
481 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,NO_NEXT_HOP,NULL,NULL);
akmhoqueffacaa82012-09-13 17:48:30 -0500482 if ( check == HT_NEW_ENTRY )
483 {
akmhoque7b791452012-10-30 11:24:56 -0500484 if ( nlsr->debugging )
485 printf("Added in npt \n");
486 if ( nlsr->detailed_logging )
487 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500488 }
489 }
490 else
491 {
akmhoquede61ba92012-09-20 22:19:12 -0500492 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);
akmhoque7b791452012-10-30 11:24:56 -0500495
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++)
akmhoquede61ba92012-09-20 22:19:12 -0500501 printf("Face: %d Route Cost: %d \n",faces[j],route_costs[j]);
akmhoque7b791452012-10-30 11:24:56 -0500502 }
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
akmhoquede61ba92012-09-20 22:19:12 -0500511
512 int check=add_npt_entry(new_name_lsa->header->orig_router->name,new_name_lsa->name_prefix->name,next_hop,faces,route_costs);
akmhoqueffacaa82012-09-13 17:48:30 -0500513 if ( check == HT_NEW_ENTRY )
514 {
akmhoque7b791452012-10-30 11:24:56 -0500515 if ( nlsr->debugging )
516 printf("Added in npt \n");
517 if ( nlsr->detailed_logging )
518 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Added in npt \n");
akmhoqueffacaa82012-09-13 17:48:30 -0500519 }
akmhoquede61ba92012-09-20 22:19:12 -0500520 free(faces);
521 free(route_costs);
522
akmhoqueffacaa82012-09-13 17:48:30 -0500523 }
akmhoquede61ba92012-09-20 22:19:12 -0500524
akmhoqueffacaa82012-09-13 17:48:30 -0500525 }
526 }
527 }
528
akmhoque3560cb62012-09-09 10:52:30 -0500529 }
akmhoque53f64222012-09-05 13:57:51 -0500530
akmhoqueffacaa82012-09-13 17:48:30 -0500531 hashtb_end(e);
akmhoque53f64222012-09-05 13:57:51 -0500532
akmhoque569a93d2013-02-21 10:19:54 -0600533 //free(key);
akmhoque53f64222012-09-05 13:57:51 -0500534}
535
akmhoque9e9fc722012-09-26 14:03:25 -0500536void
537write_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);
akmhoque34b99f92012-09-27 12:24:27 -0500543 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);
akmhoque9e9fc722012-09-26 14:03:25 -0500547 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}
akmhoque53f64222012-09-05 13:57:51 -0500552
akmhoque03004e62012-09-06 01:12:28 -0500553void
554print_name_lsa(struct nlsa *name_lsa)
akmhoque53f64222012-09-05 13:57:51 -0500555{
akmhoque53f64222012-09-05 13:57:51 -0500556
akmhoque7b791452012-10-30 11:24:56 -0500557 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 }
akmhoquef71d9082012-08-22 12:51:53 -0400572}
573
574void
575print_name_lsdb(void)
576{
akmhoque7b791452012-10-30 11:24:56 -0500577 if ( nlsr->debugging )
578 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -0500579 int i, name_lsdb_element;
akmhoquef71d9082012-08-22 12:51:53 -0400580 struct nlsa *name_lsa;
581
582 struct hashtb_enumerator ee;
583 struct hashtb_enumerator *e = &ee;
584
585 hashtb_start(nlsr->lsdb->name_lsdb, e);
akmhoque53f64222012-09-05 13:57:51 -0500586 name_lsdb_element=hashtb_n(nlsr->lsdb->name_lsdb);
akmhoquef71d9082012-08-22 12:51:53 -0400587
akmhoque53f64222012-09-05 13:57:51 -0500588 for(i=0;i<name_lsdb_element;i++)
akmhoquef71d9082012-08-22 12:51:53 -0400589 {
akmhoque7b791452012-10-30 11:24:56 -0500590 if ( nlsr->debugging )
591 printf("-----------Name LSA (%d)---------------\n",i+1);
akmhoquef71d9082012-08-22 12:51:53 -0400592 name_lsa=e->data;
akmhoque53f64222012-09-05 13:57:51 -0500593 print_name_lsa(name_lsa);
akmhoquef71d9082012-08-22 12:51:53 -0400594 hashtb_next(e);
595 }
596
597 hashtb_end(e);
598
akmhoque3171d652012-11-13 11:44:33 -0600599 if ( nlsr->debugging )
600 printf("\n");
601 if ( nlsr->detailed_logging )
602 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -0500603}
604
akmhoque03004e62012-09-06 01:12:28 -0500605
606void
607build_and_install_others_name_lsa(char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500608{
akmhoque7b791452012-10-30 11:24:56 -0500609 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");
akmhoque53f64222012-09-05 13:57:51 -0500613
akmhoque03004e62012-09-06 01:12:28 -0500614 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();
akmhoquede61ba92012-09-20 22:19:12 -0500619 print_npt();
akmhoque53f64222012-09-05 13:57:51 -0500620
akmhoque03004e62012-09-06 01:12:28 -0500621 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);
akmhoque53f64222012-09-05 13:57:51 -0500627
628}
629
630void
akmhoque03004e62012-09-06 01:12:28 -0500631build_others_name_lsa(struct nlsa *name_lsa, char *orig_router,int ls_type,long int ls_id,char *orig_time, int isValid,char *np)
akmhoque53f64222012-09-05 13:57:51 -0500632{
akmhoque7b791452012-10-30 11:24:56 -0500633 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");
akmhoque53f64222012-09-05 13:57:51 -0500637
akmhoque03004e62012-09-06 01:12:28 -0500638 name_lsa->header=(struct nlsa_header *)malloc(sizeof(struct nlsa_header ));
639 name_lsa->header->ls_type=LS_TYPE_NAME;
akmhoque53f64222012-09-05 13:57:51 -0500640
akmhoque03004e62012-09-06 01:12:28 -0500641 name_lsa->header->orig_time=(char *)malloc(strlen(orig_time)+1);
642 memset(name_lsa->header->orig_time,0,strlen(orig_time)+1);
akmhoque0ab71642013-02-21 10:10:33 -0600643 memcpy(name_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoque53f64222012-09-05 13:57:51 -0500644
akmhoque03004e62012-09-06 01:12:28 -0500645 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);
akmhoque0ab71642013-02-21 10:10:33 -0600649 memcpy(name_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoque03004e62012-09-06 01:12:28 -0500650 name_lsa->header->orig_router->length=strlen(orig_router)+1;
651 name_lsa->header->isValid=isValid;
akmhoque53f64222012-09-05 13:57:51 -0500652
akmhoque03004e62012-09-06 01:12:28 -0500653 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);
akmhoque0ab71642013-02-21 10:10:33 -0600656 memcpy(name_lsa->name_prefix->name,np,strlen(np));
akmhoque03004e62012-09-06 01:12:28 -0500657 name_lsa->name_prefix->length=strlen(np)+1;
akmhoquef71d9082012-08-22 12:51:53 -0400658}
akmhoqued79438d2012-08-27 13:31:42 -0500659
660
akmhoqueb77b95f2013-02-08 12:28:47 -0600661void
662make_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}
akmhoqueffacaa82012-09-13 17:48:30 -0500671
672
akmhoque53f64222012-09-05 13:57:51 -0500673void
674make_adj_lsa_key(char *key,struct alsa *adj_lsa)
akmhoqued79438d2012-08-27 13:31:42 -0500675{
akmhoque53f64222012-09-05 13:57:51 -0500676 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
akmhoque03004e62012-09-06 01:12:28 -0500684int
685build_and_install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
686{
akmhoqueffacaa82012-09-13 17:48:30 -0500687 if(flags == CCN_SCHEDULE_CANCEL)
688 {
689 return -1;
690 }
691
692 nlsr_lock();
693
akmhoque7b791452012-10-30 11:24:56 -0500694 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);
akmhoque03004e62012-09-06 01:12:28 -0500703
704 if(nlsr->adj_build_flag > 0)
705 {
akmhoque7b791452012-10-30 11:24:56 -0500706 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
akmhoque03004e62012-09-06 01:12:28 -0500711 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
akmhoqueb77b95f2013-02-08 12:28:47 -0600717 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
akmhoque569a93d2013-02-21 10:19:54 -0600743 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -0600744 free(repo_key);
745 free(lsaid->name);
746 free(lsaid);
747
748
749
akmhoque03004e62012-09-06 01:12:28 -0500750 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 {
akmhoque7b791452012-10-30 11:24:56 -0500761 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");
akmhoque03004e62012-09-06 01:12:28 -0500765 }
766 }
767 nlsr->is_build_adj_lsa_sheduled=0;
akmhoqueffacaa82012-09-13 17:48:30 -0500768
769 nlsr_unlock();
770
akmhoque03004e62012-09-06 01:12:28 -0500771 return 0;
772}
773
774
775void
776build_adj_lsa(struct alsa * adj_lsa)
777{
akmhoque7b791452012-10-30 11:24:56 -0500778 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");
akmhoque03004e62012-09-06 01:12:28 -0500782
783 int no_link=no_active_nbr();
akmhoque7b791452012-10-30 11:24:56 -0500784
akmhoque03004e62012-09-06 01:12:28 -0500785 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
akmhoque03004e62012-09-06 01:12:28 -0500803 adj_lsa->no_link=no_link;
akmhoque03004e62012-09-06 01:12:28 -0500804
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
akmhoque03004e62012-09-06 01:12:28 -0500815 nlsr->adj_build_count++;
816
817
818}
819
820
akmhoque53f64222012-09-05 13:57:51 -0500821void
822install_adj_lsa(struct alsa * adj_lsa)
823{
akmhoqued79438d2012-08-27 13:31:42 -0500824
akmhoque7b791452012-10-30 11:24:56 -0500825 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
akmhoque03004e62012-09-06 01:12:28 -0500830
akmhoqueffacaa82012-09-13 17:48:30 -0500831 char *time_stamp=(char *)malloc(20);
832 memset(time_stamp,0,20);
833 get_current_timestamp_micro(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500834
akmhoqueffacaa82012-09-13 17:48:30 -0500835
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);
akmhoqueffacaa82012-09-13 17:48:30 -0500839
akmhoque8876e982013-02-21 13:35:46 -0600840 struct alsa *new_adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
akmhoqueffacaa82012-09-13 17:48:30 -0500841
842 struct hashtb_enumerator ee;
843 struct hashtb_enumerator *e = &ee;
844 int res;
845
846 hashtb_start(nlsr->lsdb->adj_lsdb, e);
847 res = hashtb_seek(e, key, strlen(key), 0);
akmhoque53f64222012-09-05 13:57:51 -0500848
akmhoque03004e62012-09-06 01:12:28 -0500849
akmhoque53f64222012-09-05 13:57:51 -0500850
akmhoque62c0c192012-09-24 07:49:25 -0500851 if(res == HT_NEW_ENTRY)
akmhoque53f64222012-09-05 13:57:51 -0500852 {
akmhoque62c0c192012-09-24 07:49:25 -0500853 if ( adj_lsa->no_link > 0)
854 {
akmhoque3171d652012-11-13 11:44:33 -0600855 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");
akmhoque62c0c192012-09-24 07:49:25 -0500859 new_adj_lsa = e->data;
akmhoque53f64222012-09-05 13:57:51 -0500860
akmhoque62c0c192012-09-24 07:49:25 -0500861 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500865
akmhoque62c0c192012-09-24 07:49:25 -0500866 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;
akmhoque53f64222012-09-05 13:57:51 -0500870
akmhoque62c0c192012-09-24 07:49:25 -0500871 new_adj_lsa->no_link=adj_lsa->no_link;
akmhoqueffacaa82012-09-13 17:48:30 -0500872
akmhoque62c0c192012-09-24 07:49:25 -0500873 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);
akmhoque9e9fc722012-09-26 14:03:25 -0500879
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");
akmhoque62c0c192012-09-24 07:49:25 -0500884 }
885 else
886 {
887 hashtb_delete(e);
888 }
akmhoque53f64222012-09-05 13:57:51 -0500889
akmhoque7b791452012-10-30 11:24:56 -0500890 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
akmhoque53f64222012-09-05 13:57:51 -0500895 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500896
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
akmhoqueffacaa82012-09-13 17:48:30 -0500902 }
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 {
akmhoque7b791452012-10-30 11:24:56 -0500908 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");
akmhoqueffacaa82012-09-13 17:48:30 -0500912 }
913 else
914 {
akmhoqueffacaa82012-09-13 17:48:30 -0500915
akmhoque62c0c192012-09-24 07:49:25 -0500916 if ( adj_lsa->no_link > 0)
917 {
akmhoque9e9fc722012-09-26 14:03:25 -0500918 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");
akmhoqueffacaa82012-09-13 17:48:30 -0500922
akmhoque62c0c192012-09-24 07:49:25 -0500923 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;
akmhoqueffacaa82012-09-13 17:48:30 -0500928
akmhoque62c0c192012-09-24 07:49:25 -0500929 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);
akmhoqueffacaa82012-09-13 17:48:30 -0500932
akmhoque62c0c192012-09-24 07:49:25 -0500933 add_next_hop_from_lsa_adj_body(new_adj_lsa->body,new_adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -0500934
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");
akmhoque62c0c192012-09-24 07:49:25 -0500939 }
940 else
941 {
akmhoque9e9fc722012-09-26 14:03:25 -0500942 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
akmhoque62c0c192012-09-24 07:49:25 -0500947 hashtb_delete(e);
948 }
akmhoque7b791452012-10-30 11:24:56 -0500949
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
akmhoqueffacaa82012-09-13 17:48:30 -0500955 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -0500956
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);
akmhoqueffacaa82012-09-13 17:48:30 -0500961 }
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;
akmhoque53f64222012-09-05 13:57:51 -0500970 }
971
akmhoque03004e62012-09-06 01:12:28 -0500972
akmhoque569a93d2013-02-21 10:19:54 -0600973 //free(key);
akmhoqueffacaa82012-09-13 17:48:30 -0500974
975 free(time_stamp);
akmhoque53f64222012-09-05 13:57:51 -0500976}
977
978void
akmhoque9e9fc722012-09-26 14:03:25 -0500979write_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;
akmhoqueb28579d2013-02-12 11:15:52 -0600989 //char *face;
akmhoque9e9fc722012-09-26 14:03:25 -0500990 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);
akmhoque866c2222013-02-12 10:49:33 -0600996 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -0500997 metric=strtok_r(NULL,sep,&rem);
998
999 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001000 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1001 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001002 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001003 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001004
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);
akmhoqueb28579d2013-02-12 11:15:52 -06001010 //face=strtok_r(NULL,sep,&rem);
akmhoque9e9fc722012-09-26 14:03:25 -05001011 metric=strtok_r(NULL,sep,&rem);
1012 writeLogg(__FILE__,__FUNCTION__,__LINE__," Link %d \n",i+1);
akmhoque34b99f92012-09-27 12:24:27 -05001013 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router: %s \n",rtr_id);
1014 writeLogg(__FILE__,__FUNCTION__,__LINE__," Adjacent Router Length: %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001015 //writeLogg(__FILE__,__FUNCTION__,__LINE__," Connecting Face: %s \n",face);
akmhoque34b99f92012-09-27 12:24:27 -05001016 writeLogg(__FILE__,__FUNCTION__,__LINE__," Metric: %s \n",metric);
akmhoque9e9fc722012-09-26 14:03:25 -05001017
1018 }
1019 }
1020
1021 free(lsa_data);
1022}
1023
1024
1025void
1026write_log_for_adj_lsa(struct alsa * adj_lsa)
1027{
1028 writeLogg(__FILE__,__FUNCTION__,__LINE__,"-----------Adj LSA Content---------------\n");
akmhoque34b99f92012-09-27 12:24:27 -05001029 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);
akmhoque9e9fc722012-09-26 14:03:25 -05001033 writeLogg(__FILE__,__FUNCTION__,__LINE__," Lsa Data:\n");
akmhoque34b99f92012-09-27 12:24:27 -05001034 writeLogg(__FILE__,__FUNCTION__,__LINE__," No of Link: %d\n",adj_lsa->no_link);
akmhoque9e9fc722012-09-26 14:03:25 -05001035
1036 write_log_for_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1037
1038 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
1039
1040}
1041
1042void
akmhoque53f64222012-09-05 13:57:51 -05001043print_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;
akmhoqueb28579d2013-02-12 11:15:52 -06001053 //char *face;
akmhoque53f64222012-09-05 13:57:51 -05001054 char *metric;
1055
akmhoque53f64222012-09-05 13:57:51 -05001056 if(no_link >0 )
1057 {
1058 rtr_id=strtok_r(lsa_data,sep,&rem);
1059 length=strtok_r(NULL,sep,&rem);
akmhoque866c2222013-02-12 10:49:33 -06001060 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001061 metric=strtok_r(NULL,sep,&rem);
1062
akmhoqueb77b95f2013-02-08 12:28:47 -06001063 if ( nlsr->debugging ) {
1064 printf(" Link %d \n",i+1);
1065 printf(" Neighbor : %s \n",rtr_id);
1066 printf(" Neighbor Length : %s \n",length);
akmhoque866c2222013-02-12 10:49:33 -06001067 //printf(" Connecting Face : %s \n",face);
akmhoqueb77b95f2013-02-08 12:28:47 -06001068 printf(" Metric : %s \n",metric);
1069 }
akmhoque53f64222012-09-05 13:57:51 -05001070
1071 for(i=1;i<no_link;i++)
1072 {
1073 rtr_id=strtok_r(NULL,sep,&rem);
1074 length=strtok_r(NULL,sep,&rem);
akmhoqueb28579d2013-02-12 11:15:52 -06001075 //face=strtok_r(NULL,sep,&rem);
akmhoque53f64222012-09-05 13:57:51 -05001076 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);
akmhoque866c2222013-02-12 10:49:33 -06001080 //printf(" Connecting Face : %s \n",face);
akmhoque53f64222012-09-05 13:57:51 -05001081 printf(" Metric : %s \n",metric);
1082
1083 }
1084 }
1085
1086 free(lsa_data);
1087}
1088
1089void
1090print_adj_lsa(struct alsa * adj_lsa)
1091{
akmhoque7b791452012-10-30 11:24:56 -05001092 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);
akmhoque53f64222012-09-05 13:57:51 -05001101
akmhoque7b791452012-10-30 11:24:56 -05001102 print_adj_lsa_body(adj_lsa->body,adj_lsa->no_link);
1103 printf("\n");
1104 }
akmhoque53f64222012-09-05 13:57:51 -05001105
1106}
1107
1108void
1109print_adj_lsdb(void)
1110{
akmhoque7b791452012-10-30 11:24:56 -05001111 if ( nlsr->debugging )
1112 printf("print_name_lsdb called \n");
akmhoque53f64222012-09-05 13:57:51 -05001113 int i, adj_lsdb_element;
1114 struct alsa *adj_lsa;
1115
1116 struct hashtb_enumerator ee;
1117 struct hashtb_enumerator *e = &ee;
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 {
akmhoque7b791452012-10-30 11:24:56 -05001124 if ( nlsr->debugging )
1125 printf("-----------Adj LSA (%d)---------------\n",i+1);
akmhoque53f64222012-09-05 13:57:51 -05001126 adj_lsa=e->data;
1127 print_adj_lsa(adj_lsa);
1128 hashtb_next(e);
1129 }
1130
1131 hashtb_end(e);
1132
akmhoque3171d652012-11-13 11:44:33 -06001133 if ( nlsr->debugging )
1134 printf("\n");
1135 if ( nlsr->detailed_logging )
1136 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
akmhoque53f64222012-09-05 13:57:51 -05001137}
1138
1139void
akmhoque03004e62012-09-06 01:12:28 -05001140build_and_install_others_adj_lsa(char *orig_router,int ls_type,char *orig_time, int no_link,char *data)
akmhoque53f64222012-09-05 13:57:51 -05001141{
akmhoque7b791452012-10-30 11:24:56 -05001142 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");
akmhoque03004e62012-09-06 01:12:28 -05001146 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);
akmhoque03004e62012-09-06 01:12:28 -05001148 install_adj_lsa(adj_lsa);
1149
akmhoque53f64222012-09-05 13:57:51 -05001150
akmhoque03004e62012-09-06 01:12:28 -05001151 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);
akmhoque53f64222012-09-05 13:57:51 -05001157
akmhoque03004e62012-09-06 01:12:28 -05001158 print_adj_lsdb();
akmhoque53f64222012-09-05 13:57:51 -05001159
akmhoque53f64222012-09-05 13:57:51 -05001160}
1161
akmhoque03004e62012-09-06 01:12:28 -05001162
akmhoque53f64222012-09-05 13:57:51 -05001163void
akmhoque03004e62012-09-06 01:12:28 -05001164build_others_adj_lsa(struct alsa *adj_lsa,char *orig_router,int ls_type,char *orig_time,int no_link,char *data)
akmhoque53f64222012-09-05 13:57:51 -05001165{
akmhoque7b791452012-10-30 11:24:56 -05001166 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");
akmhoque53f64222012-09-05 13:57:51 -05001170
akmhoque03004e62012-09-06 01:12:28 -05001171 /*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);
akmhoque53f64222012-09-05 13:57:51 -05001177
akmhoque03004e62012-09-06 01:12:28 -05001178 adj_lsa->header->orig_router->length=strlen(orig_router)+1;
akmhoque53f64222012-09-05 13:57:51 -05001179
akmhoque53f64222012-09-05 13:57:51 -05001180
akmhoque03004e62012-09-06 01:12:28 -05001181 adj_lsa->header->ls_type=(unsigned)LS_TYPE_ADJ;
akmhoque53f64222012-09-05 13:57:51 -05001182
akmhoque03004e62012-09-06 01:12:28 -05001183 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);
akmhoque53f64222012-09-05 13:57:51 -05001186
akmhoque03004e62012-09-06 01:12:28 -05001187 adj_lsa->no_link=no_link;
akmhoque53f64222012-09-05 13:57:51 -05001188
akmhoque03004e62012-09-06 01:12:28 -05001189 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);
akmhoque53f64222012-09-05 13:57:51 -05001192
akmhoque53f64222012-09-05 13:57:51 -05001193}
1194
akmhoque03004e62012-09-06 01:12:28 -05001195
akmhoque53f64222012-09-05 13:57:51 -05001196long int
1197get_name_lsdb_num_element(void)
1198{
1199 long int num_element;
1200
1201
1202 struct hashtb_enumerator ee;
1203 struct hashtb_enumerator *e = &ee;
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
1212long int
1213get_adj_lsdb_num_element(void)
1214{
1215 long int num_element;
1216
1217
1218 struct hashtb_enumerator ee;
1219 struct hashtb_enumerator *e = &ee;
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;
akmhoqued79438d2012-08-27 13:31:42 -05001226}
akmhoque03004e62012-09-06 01:12:28 -05001227
akmhoque03004e62012-09-06 01:12:28 -05001228
1229int
1230check_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 = &ee;
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
1271int
1272check_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 = &ee;
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
akmhoqueb77b95f2013-02-08 12:28:47 -06001311int
1312check_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 = &ee;
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
akmhoque03004e62012-09-06 01:12:28 -05001351void
1352get_name_lsa_data(struct ccn_charbuf *lsa_data, struct name_prefix *lsaId)
1353{
akmhoque7b791452012-10-30 11:24:56 -05001354 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");
akmhoque03004e62012-09-06 01:12:28 -05001358
akmhoque8876e982013-02-21 13:35:46 -06001359 struct nlsa *name_lsa;//=(struct nlsa*)malloc(sizeof(struct nlsa ));
akmhoque03004e62012-09-06 01:12:28 -05001360
1361 struct hashtb_enumerator ee;
1362 struct hashtb_enumerator *e = &ee;
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;
akmhoqueb77b95f2013-02-08 12:28:47 -06001371
akmhoque7b791452012-10-30 11:24:56 -05001372 if ( nlsr->debugging )
1373 printf("NAME LSA found \n");
1374 if ( nlsr->detailed_logging )
1375 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001376
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
1430void
1431get_adj_lsa_data(struct ccn_charbuf *lsa_data,struct name_prefix *lsaId)
1432{
akmhoque7b791452012-10-30 11:24:56 -05001433 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");
akmhoque03004e62012-09-06 01:12:28 -05001437
1438 struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
1439
1440 struct hashtb_enumerator ee;
1441 struct hashtb_enumerator *e = &ee;
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;
akmhoque7b791452012-10-30 11:24:56 -05001450
1451 if ( nlsr->debugging )
1452 printf("Adj LSA found \n");
1453 if ( nlsr->detailed_logging )
1454 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Adj LSA found \n");
akmhoque03004e62012-09-06 01:12:28 -05001455
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);
akmhoque03004e62012-09-06 01:12:28 -05001463 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001464 free(temp_length);
akmhoque03004e62012-09-06 01:12:28 -05001465
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);
akmhoque03004e62012-09-06 01:12:28 -05001470 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001471 free(temp_ltype);
akmhoque03004e62012-09-06 01:12:28 -05001472
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);
akmhoque03004e62012-09-06 01:12:28 -05001480 ccn_charbuf_append_string(lsa_data,"|");
akmhoqueb77b95f2013-02-08 12:28:47 -06001481 free(temp_nl);
akmhoque03004e62012-09-06 01:12:28 -05001482
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}
akmhoqueffacaa82012-09-13 17:48:30 -05001494
akmhoque3171d652012-11-13 11:44:33 -06001495void
1496make_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);
akmhoqueb77b95f2013-02-08 12:28:47 -06001519
1520 if ( nlsr->debugging )
1521 printf("Key:%s Length:%d\n",key,(int)strlen(key));
akmhoque3171d652012-11-13 11:44:33 -06001522
1523 struct nlsa *nlsa;
1524
1525 struct hashtb_enumerator ee;
1526 struct hashtb_enumerator *e = &ee;
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
akmhoque866c2222013-02-12 10:49:33 -06001566//int
1567//delete_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1568int
1569delete_name_lsa(char *orig_router, char *name_prefix)
akmhoqueda5b6832012-09-13 22:33:55 -05001570{
akmhoqueb77b95f2013-02-08 12:28:47 -06001571
akmhoque7b791452012-10-30 11:24:56 -05001572 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");
akmhoque866c2222013-02-12 10:49:33 -06001576 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001577 if(flags == CCN_SCHEDULE_CANCEL)
1578 {
1579 return -1;
1580 }
1581
1582
1583
1584 nlsr_lock();
1585
akmhoque7b791452012-10-30 11:24:56 -05001586 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);
akmhoqueda5b6832012-09-13 22:33:55 -05001590
1591 struct nlsa *nlsa;
1592
1593 struct hashtb_enumerator ee;
1594 struct hashtb_enumerator *e = &ee;
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;
akmhoque866c2222013-02-12 10:49:33 -06001604 */
1605 delete_npt_entry_by_router_and_name_prefix(orig_router, name_prefix);
1606 /*
akmhoque9e9fc722012-09-26 14:03:25 -05001607 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
akmhoqueda5b6832012-09-13 22:33:55 -05001612 hashtb_delete(e);
1613 }
akmhoque3cced642012-09-24 16:20:20 -05001614 else if( res == HT_NEW_ENTRY )
akmhoqueda5b6832012-09-13 22:33:55 -05001615 {
akmhoqueda5b6832012-09-13 22:33:55 -05001616 hashtb_delete(e);
1617 }
1618 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001619 */
akmhoqueda5b6832012-09-13 22:33:55 -05001620
akmhoque7b791452012-10-30 11:24:56 -05001621 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
akmhoqueda5b6832012-09-13 22:33:55 -05001626 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001627
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);
akmhoqueda5b6832012-09-13 22:33:55 -05001632
akmhoque866c2222013-02-12 10:49:33 -06001633 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001634
1635 return 0;
1636}
1637
akmhoque866c2222013-02-12 10:49:33 -06001638//int
1639//delete_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
1640int delete_adj_lsa()
akmhoqueda5b6832012-09-13 22:33:55 -05001641{
akmhoque866c2222013-02-12 10:49:33 -06001642
akmhoque7b791452012-10-30 11:24:56 -05001643 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");
akmhoque866c2222013-02-12 10:49:33 -06001647
1648 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001649 if(flags == CCN_SCHEDULE_CANCEL)
1650 {
1651 return -1;
1652 }
1653 nlsr_lock();
1654
akmhoque7b791452012-10-30 11:24:56 -05001655 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);
akmhoqueda5b6832012-09-13 22:33:55 -05001659
akmhoque9e9fc722012-09-26 14:03:25 -05001660 struct alsa *alsa;
akmhoqueda5b6832012-09-13 22:33:55 -05001661 struct hashtb_enumerator ee;
1662 struct hashtb_enumerator *e = &ee;
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 {
akmhoque9e9fc722012-09-26 14:03:25 -05001670 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
akmhoqueda5b6832012-09-13 22:33:55 -05001676 hashtb_delete(e);
1677 }
1678 else if( res == HT_OLD_ENTRY )
1679 {
1680 hashtb_delete(e);
1681 }
1682 hashtb_end(e);
akmhoque866c2222013-02-12 10:49:33 -06001683 */
akmhoqueda5b6832012-09-13 22:33:55 -05001684
akmhoque7b791452012-10-30 11:24:56 -05001685 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
akmhoqueda5b6832012-09-13 22:33:55 -05001690 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001691
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
akmhoqueda5b6832012-09-13 22:33:55 -05001697
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
akmhoque866c2222013-02-12 10:49:33 -06001704 //nlsr_unlock();
akmhoqueda5b6832012-09-13 22:33:55 -05001705
1706 return 0;
1707}
1708
akmhoqueffacaa82012-09-13 17:48:30 -05001709void
1710refresh_name_lsdb(void)
1711{
akmhoque7b791452012-10-30 11:24:56 -05001712 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");
akmhoqueffacaa82012-09-13 17:48:30 -05001716
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 = &ee;
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);
akmhoque7b791452012-10-30 11:24:56 -05001737 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);
akmhoqueda5b6832012-09-13 22:33:55 -05001741
1742 if ( strcmp(name_lsa->header->orig_router->name,nlsr->router_name) == 0)
1743 {
1744 if ( lsa_life_time > nlsr->lsa_refresh_time )
1745 {
akmhoque14b3f342012-09-14 10:39:02 -05001746 if ( name_lsa->header->isValid == NAME_LSA_VALID )
1747 {
akmhoque7b791452012-10-30 11:24:56 -05001748 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");
akmhoquea98c2142012-10-25 15:22:24 -05001752
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
akmhoque14b3f342012-09-14 10:39:02 -05001759 char *current_time_stamp=(char *)malloc(20);
1760 memset(current_time_stamp,0,20);
1761 get_current_timestamp_micro(current_time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001762
akmhoque14b3f342012-09-14 10:39:02 -05001763 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);
akmhoquea98c2142012-10-25 15:22:24 -05001767
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");
akmhoqueda5b6832012-09-13 22:33:55 -05001772
akmhoque14b3f342012-09-14 10:39:02 -05001773 free(current_time_stamp);
akmhoque866c2222013-02-12 10:49:33 -06001774
1775 hashtb_next(e);
akmhoque14b3f342012-09-14 10:39:02 -05001776 }
1777 else
akmhoque866c2222013-02-12 10:49:33 -06001778 { /*
akmhoque14b3f342012-09-14 10:39:02 -05001779 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
akmhoque866c2222013-02-12 10:49:33 -06001787
akmhoque14b3f342012-09-14 10:39:02 -05001788 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);
akmhoque14b3f342012-09-14 10:39:02 -05001793
1794 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001795 */
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++;
akmhoque14b3f342012-09-14 10:39:02 -05001803 }
akmhoqueda5b6832012-09-13 22:33:55 -05001804
akmhoque7b791452012-10-30 11:24:56 -05001805 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
akmhoqueda5b6832012-09-13 22:33:55 -05001810 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001811
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
akmhoqueda5b6832012-09-13 22:33:55 -05001818
1819 print_name_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001820 }
1821 else
1822 {
1823 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001824 }
1825 }
1826 else
1827 {
1828 if ( lsa_life_time > nlsr->router_dead_interval )
1829 {
akmhoque7b791452012-10-30 11:24:56 -05001830 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");
akmhoqueda5b6832012-09-13 22:33:55 -05001834
akmhoque866c2222013-02-12 10:49:33 -06001835 /*char lst[2];
akmhoqueda5b6832012-09-13 22:33:55 -05001836 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);
akmhoqueda5b6832012-09-13 22:33:55 -05001849
1850 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_name_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001851 */
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);
akmhoqueda5b6832012-09-13 22:33:55 -05001863 }
1864 }
akmhoque866c2222013-02-12 10:49:33 -06001865 /*else
1866 {
1867 hashtb_next(e);
1868 }*/
akmhoqueffacaa82012-09-13 17:48:30 -05001869 }
1870
1871 hashtb_end(e);
1872
1873 free(time_stamp);
akmhoqueda5b6832012-09-13 22:33:55 -05001874
akmhoqueffacaa82012-09-13 17:48:30 -05001875
1876}
1877
akmhoqueda5b6832012-09-13 22:33:55 -05001878void
akmhoqueffacaa82012-09-13 17:48:30 -05001879refresh_adj_lsdb(void)
1880{
akmhoqueffacaa82012-09-13 17:48:30 -05001881
akmhoque7b791452012-10-30 11:24:56 -05001882 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");
akmhoqueda5b6832012-09-13 22:33:55 -05001886
akmhoqueffacaa82012-09-13 17:48:30 -05001887 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 = &ee;
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
akmhoqueb77b95f2013-02-08 12:28:47 -06001906 lsa_life_time=get_time_diff(time_stamp,adj_lsa->header->orig_time);
akmhoque7b791452012-10-30 11:24:56 -05001907
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);
akmhoqueffacaa82012-09-13 17:48:30 -05001912
akmhoqueda5b6832012-09-13 22:33:55 -05001913 if ( strcmp(adj_lsa->header->orig_router->name,nlsr->router_name) == 0)
1914 {
1915 if ( lsa_life_time > nlsr->lsa_refresh_time )
1916 {
akmhoque7b791452012-10-30 11:24:56 -05001917 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");
akmhoqueda5b6832012-09-13 22:33:55 -05001921
akmhoquea98c2142012-10-25 15:22:24 -05001922 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
akmhoqueda5b6832012-09-13 22:33:55 -05001927 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
akmhoquea98c2142012-10-25 15:22:24 -05001938 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");
akmhoqueda5b6832012-09-13 22:33:55 -05001942
akmhoque7b791452012-10-30 11:24:56 -05001943 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
akmhoqueda5b6832012-09-13 22:33:55 -05001948 set_new_lsdb_version();
akmhoque7b791452012-10-30 11:24:56 -05001949
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);
akmhoqueda5b6832012-09-13 22:33:55 -05001954
1955 print_adj_lsdb();
akmhoque866c2222013-02-12 10:49:33 -06001956
1957
akmhoqueda5b6832012-09-13 22:33:55 -05001958 }
akmhoque866c2222013-02-12 10:49:33 -06001959
1960 hashtb_next(e);
akmhoqueda5b6832012-09-13 22:33:55 -05001961 }
1962 else
1963 {
1964 if ( lsa_life_time > nlsr->router_dead_interval )
1965 {
akmhoque7b791452012-10-30 11:24:56 -05001966
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");
akmhoque866c2222013-02-12 10:49:33 -06001971 /*
akmhoqueda5b6832012-09-13 22:33:55 -05001972 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);
akmhoqueb77b95f2013-02-08 12:28:47 -06001975
akmhoqueda5b6832012-09-13 22:33:55 -05001976 nlsr->event = ccn_schedule_event(nlsr->sched, 10, &delete_adj_lsa, (void *)key, 0);
akmhoque866c2222013-02-12 10:49:33 -06001977 */
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);
akmhoqueda5b6832012-09-13 22:33:55 -05001991 }
1992 }
1993
1994
1995
akmhoque866c2222013-02-12 10:49:33 -06001996 //hashtb_next(e);
akmhoqueffacaa82012-09-13 17:48:30 -05001997 }
1998
1999 hashtb_end(e);
2000
2001 free(time_stamp);
akmhoqueffacaa82012-09-13 17:48:30 -05002002}
2003
akmhoqueb77b95f2013-02-08 12:28:47 -06002004
2005void
2006refresh_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 = &ee;
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();
akmhoque866c2222013-02-12 10:49:33 -06002083 }
2084
2085 hashtb_next(e);
akmhoqueb77b95f2013-02-08 12:28:47 -06002086 }
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 }
akmhoque866c2222013-02-12 10:49:33 -06002100 else
2101 {
2102 hashtb_next(e);
2103 }
akmhoqueb77b95f2013-02-08 12:28:47 -06002104 }
2105
2106
akmhoque866c2222013-02-12 10:49:33 -06002107
akmhoqueb77b95f2013-02-08 12:28:47 -06002108 }
2109
2110 hashtb_end(e);
2111
2112 free(time_stamp);
2113}
2114
akmhoqueffacaa82012-09-13 17:48:30 -05002115int
2116refresh_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();
akmhoqueda5b6832012-09-13 22:33:55 -05002124
akmhoque7b791452012-10-30 11:24:56 -05002125 if ( nlsr->debugging )
2126 printf("refresh_lsdb called\n");
2127 if ( nlsr->detailed_logging )
2128 writeLogg(__FILE__,__FUNCTION__,__LINE__,"refresh_lsdb called\n");
akmhoqueffacaa82012-09-13 17:48:30 -05002129
2130 refresh_name_lsdb();
2131 refresh_adj_lsdb();
akmhoque8876e982013-02-21 13:35:46 -06002132 //refresh_cor_lsdb();
akmhoqueffacaa82012-09-13 17:48:30 -05002133
akmhoqueffacaa82012-09-13 17:48:30 -05002134 nlsr->event = ccn_schedule_event(nlsr->sched, 60000000, &refresh_lsdb, NULL, 0);
akmhoqueda5b6832012-09-13 22:33:55 -05002135
akmhoqueffacaa82012-09-13 17:48:30 -05002136 nlsr_unlock();
2137 return 0;
2138}
akmhoqueb77b95f2013-02-08 12:28:47 -06002139
2140void
2141write_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 )
akmhoque323b5e92013-02-21 13:55:15 -06002151 printf("Adj LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
akmhoqueb77b95f2013-02-08 12:28:47 -06002152
akmhoque0800eda2013-02-21 14:17:52 -06002153 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002154
akmhoque323b5e92013-02-21 13:55:15 -06002155
2156 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002157}
2158
2159void
2160write_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
akmhoque0800eda2013-02-21 14:17:52 -06002173
akmhoque323b5e92013-02-21 13:55:15 -06002174
akmhoque0800eda2013-02-21 14:17:52 -06002175 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_content_prefix);
akmhoqueb77b95f2013-02-08 12:28:47 -06002176
akmhoque4f85aab2013-02-21 13:58:50 -06002177 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002178}
2179
2180
2181void
2182write_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 = &ee;
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
2245void
2246print_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
2263void
2264print_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 = &ee;
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
2291void
2292install_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
akmhoque569a93d2013-02-21 10:19:54 -06002305 char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
2306 memset(key,0,cor_lsa->header->orig_router->length+4);
akmhoqueb77b95f2013-02-08 12:28:47 -06002307 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 = &ee;
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
akmhoque8876e982013-02-21 13:35:46 -06002324 struct clsa *new_cor_lsa;//=(struct clsa *)malloc(sizeof( struct clsa ));
akmhoqueb77b95f2013-02-08 12:28:47 -06002325 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
akmhoque569a93d2013-02-21 10:19:54 -06002350 //free(key);
akmhoqueb77b95f2013-02-08 12:28:47 -06002351
2352}
2353
2354void
2355build_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
2380void
2381build_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);
akmhoque569a93d2013-02-21 10:19:54 -06002388 memcpy(cor_lsa->header->orig_time,orig_time,strlen(orig_time));
akmhoqueb77b95f2013-02-08 12:28:47 -06002389
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);
akmhoque569a93d2013-02-21 10:19:54 -06002393 memcpy(cor_lsa->header->orig_router->name,orig_router,strlen(orig_router));
akmhoqueb77b95f2013-02-08 12:28:47 -06002394 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
2401void
2402build_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();
akmhoque569a93d2013-02-21 10:19:54 -06002409
2410 free(cor_lsa->header->orig_router->name);
akmhoqueb77b95f2013-02-08 12:28:47 -06002411 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
2419void
2420build_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
2441void
2442get_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 = &ee;
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
2510void
2511write_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);
akmhoque323b5e92013-02-21 13:55:15 -06002525
akmhoqueb77b95f2013-02-08 12:28:47 -06002526 if ( nlsr->debugging )
akmhoque0800eda2013-02-21 14:17:52 -06002527 printf("Cor LSA Data: %s \n",ccn_charbuf_as_string(lsa_data));
2528
akmhoqueb77b95f2013-02-08 12:28:47 -06002529 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
akmhoque0800eda2013-02-21 14:17:52 -06002539 write_data_to_repo(ccn_charbuf_as_string(lsa_data), repo_key);
2540
akmhoqueb77b95f2013-02-08 12:28:47 -06002541
2542
2543
2544 free(lst);
2545 free(key);
2546 free(repo_key);
akmhoque4f85aab2013-02-21 13:58:50 -06002547 ccn_charbuf_destroy(&lsa_data);
akmhoqueb77b95f2013-02-08 12:28:47 -06002548}
2549
2550void
2551make_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
2562double
2563get_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 = &ee;
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
2594double
2595get_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 = &ee;
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}