blob: de6ad0799e31396b723a1d8d61c482153f16427f [file] [log] [blame]
akmhoque8a5babe2012-08-16 17:39:33 -05001#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"
21#include "nlsr_ndn.h"
22#include "utility.h"
23#include "nlsr_adl.h"
24
25void
26add_adjacent_to_adl(struct ndn_neighbor *nbr)
27{
28 printf("\nadd_adjacent_to_adl called\n");
akmhoquea6817692012-08-21 13:50:01 -040029 printf("Neighbor: %s Length: %d Face: %d Status: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status);
akmhoque8a5babe2012-08-16 17:39:33 -050030
31 struct ndn_neighbor *hnbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*));
32
33 struct hashtb_enumerator ee;
34 struct hashtb_enumerator *e = &ee;
35 int res;
36
37 hashtb_start(nlsr->adl, e);
akmhoquea6817692012-08-21 13:50:01 -040038 res = hashtb_seek(e, nbr->neighbor->buf , nbr->neighbor->length, 0);
akmhoque2852a222012-08-21 12:09:00 -040039
akmhoquee7c4b6d2012-08-21 12:30:25 -040040 if(res == HT_NEW_ENTRY )
41 {
akmhoque8a5babe2012-08-16 17:39:33 -050042
akmhoquee7c4b6d2012-08-21 12:30:25 -040043 hnbr = e->data;
akmhoquea6817692012-08-21 13:50:01 -040044 hnbr->neighbor=ccn_charbuf_create();
akmhoquea6817692012-08-21 13:50:01 -040045 ccn_charbuf_append_string(hnbr->neighbor,ccn_charbuf_as_string(nbr->neighbor));
akmhoque8a5babe2012-08-16 17:39:33 -050046
akmhoquee7c4b6d2012-08-21 12:30:25 -040047 hnbr->face=nbr->face;
48 hnbr->status=nbr->status;
akmhoquef6432c22012-08-21 13:18:05 -040049 hnbr->last_lsdb_version=0;
akmhoqued79438d2012-08-27 13:31:42 -050050 hnbr->info_interest_timed_out=0;
akmhoque8a5babe2012-08-16 17:39:33 -050051
akmhoquee7c4b6d2012-08-21 12:30:25 -040052 struct hashtb_param param_luq = {0};
53 hnbr->lsa_update_queue=hashtb_create(200, &param_luq);
54 }
akmhoque8a5babe2012-08-16 17:39:33 -050055
56 hashtb_end(e);
57
58 printf("\n");
59
60
61}
62
63void
64print_adjacent_from_adl(void)
65{
66 printf("print_adjacent_from_adl called \n");
67 int i, adl_element;
68 struct ndn_neighbor *nbr;
69
70 struct hashtb_enumerator ee;
71 struct hashtb_enumerator *e = &ee;
72
73 hashtb_start(nlsr->adl, e);
74 adl_element=hashtb_n(nlsr->adl);
75
76 for(i=0;i<adl_element;i++)
77 {
78 nbr=e->data;
akmhoqued79438d2012-08-27 13:31:42 -050079 printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %ld Interest Timed Out: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version,nbr->info_interest_timed_out);
akmhoque8a5babe2012-08-16 17:39:33 -050080 hashtb_next(e);
81 }
82
83 hashtb_end(e);
84
85 printf("\n");
86}
87
88void
89update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status)
90{
91 printf("update_adjacent_status_to_adl called \n");
92
93 int res;
94 struct ndn_neighbor *nnbr;
95
96 struct hashtb_enumerator ee;
97 struct hashtb_enumerator *e = &ee;
98
99 hashtb_start(nlsr->adl, e);
akmhoque50206fc2012-08-21 11:49:12 -0400100 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
akmhoque50206fc2012-08-21 11:49:12 -0400101
akmhoque918ff9a2012-08-21 11:34:49 -0400102
akmhoquee7c4b6d2012-08-21 12:30:25 -0400103 if (res == HT_OLD_ENTRY)
104 {
105 nnbr=e->data;
akmhoque42098b12012-08-27 22:54:23 -0500106 if ( nnbr->status!=status )
107 {
108 nnbr->status=status;
109 nlsr->adj_build_flag++;
110 }
akmhoquee7c4b6d2012-08-21 12:30:25 -0400111 }
akmhoqueb903ded2012-08-21 12:56:28 -0400112 else if(res == HT_NEW_ENTRY)
113 {
114 hashtb_delete(e);
115 }
akmhoque8a5babe2012-08-16 17:39:33 -0500116
117 hashtb_end(e);
118}
119
120
121void
akmhoquef6432c22012-08-21 13:18:05 -0400122update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version)
akmhoque8a5babe2012-08-16 17:39:33 -0500123{
124 printf("update_adjacent_status_to_adl called \n");
125
126 int res;
127 struct ndn_neighbor *nnbr;
128
129 struct hashtb_enumerator ee;
130 struct hashtb_enumerator *e = &ee;
131
132 hashtb_start(nlsr->adl, e);
akmhoque2852a222012-08-21 12:09:00 -0400133 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500134
akmhoquee7c4b6d2012-08-21 12:30:25 -0400135 if( res == HT_OLD_ENTRY )
136 {
137 nnbr=e->data;
akmhoquef6432c22012-08-21 13:18:05 -0400138 nnbr->last_lsdb_version = version;
139 //memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoquee7c4b6d2012-08-21 12:30:25 -0400140 }
akmhoqueb903ded2012-08-21 12:56:28 -0400141 else if(res == HT_NEW_ENTRY)
142 {
143 hashtb_delete(e);
144 }
145
akmhoque8a5babe2012-08-16 17:39:33 -0500146 hashtb_end(e);
147}
akmhoqued79438d2012-08-27 13:31:42 -0500148
149void
150update_adjacent_timed_out_to_adl(struct ccn_charbuf *nbr, int increment)
151{
152 printf("update_adjacent_timed_out_to_adl called \n");
153
154 int res;
155 struct ndn_neighbor *nnbr;
156
157 struct hashtb_enumerator ee;
158 struct hashtb_enumerator *e = &ee;
159
160 hashtb_start(nlsr->adl, e);
161 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
162
163 if( res == HT_OLD_ENTRY )
164 {
165 nnbr=e->data;
166 nnbr->info_interest_timed_out += increment;
167 }
168 else if(res == HT_NEW_ENTRY)
169 {
170 hashtb_delete(e);
171 }
172
173 hashtb_end(e);
174}
175
176void
177update_adjacent_timed_out_zero_to_adl(struct ccn_charbuf *nbr)
178{
179
180 printf("update_adjacent_timed_out_zero_to_adl called \n");
181 int time_out_number=get_timed_out_number(nbr);
182 update_adjacent_timed_out_to_adl(nbr,-time_out_number);
183
184}
185
186
187int
188get_timed_out_number(struct ccn_charbuf *nbr)
189{
190
191 printf("get_timed_out_number called \n");
192
193 int res,ret=-1;
194 struct ndn_neighbor *nnbr;
195
196 struct hashtb_enumerator ee;
197 struct hashtb_enumerator *e = &ee;
198
199 hashtb_start(nlsr->adl, e);
200 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
201
202 if( res == HT_OLD_ENTRY )
203 {
204 nnbr=e->data;
205 ret=nnbr->info_interest_timed_out;
206 }
207 else if(res == HT_NEW_ENTRY)
208 {
209 hashtb_delete(e);
210 }
211
212 hashtb_end(e);
213
214 return ret;
215
216}