forked from NDN-Routing/NLSR0.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nlsr_npl.c
199 lines (159 loc) · 3.58 KB
/
nlsr_npl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <assert.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ccn/ccn.h>
#include <ccn/uri.h>
#include <ccn/keystore.h>
#include <ccn/signing.h>
#include <ccn/schedule.h>
#include <ccn/hashtb.h>
#include "nlsr.h"
#include "nlsr_npl.h"
#include "utility.h"
void
add_name_to_npl(struct name_prefix *np)
{
struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
int res;
hashtb_start(nlsr->npl, e);
res = hashtb_seek(e, np->name, np->length, 0);
if(res == HT_NEW_ENTRY)
{
npe=e->data;
npe->np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
npe->np->length=np->length;
npe->np->name=(char *)calloc(np->length,sizeof(char));
memcpy(npe->np->name,np->name,np->length);
npe->name_lsa_id=0;
}
hashtb_end(e);
}
int
does_name_exist_in_npl(struct name_prefix *np)
{
int ret=0;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
int res;
hashtb_start(nlsr->npl, e);
res = hashtb_seek(e, np->name, np->length, 0);
if(res == HT_NEW_ENTRY)
{
hashtb_delete(e);
ret=0;
}
else
{
ret=1;
}
hashtb_end(e);
return ret;
}
long int
get_lsa_id_from_npl(struct name_prefix *np)
{
int ret=0;
struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
int res;
hashtb_start(nlsr->npl, e);
res = hashtb_seek(e, np->name, np->length, 0);
if(res == HT_NEW_ENTRY)
{
hashtb_delete(e);
ret=0;
}
else
{
npe=e->data;
ret=npe->name_lsa_id;
}
hashtb_end(e);
return ret;
}
void
print_name_prefix_from_npl(void)
{
if ( nlsr->debugging )
printf("print_name_prefix_from_npl called \n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n");
int i, npl_element;
//struct name_prefix *np;
struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
hashtb_start(nlsr->npl, e);
npl_element=hashtb_n(nlsr->npl);
for(i=0;i<npl_element;i++)
{
npe=e->data;
if ( nlsr->debugging )
printf("Name Prefix: %s and Length: %d and LSA Id: %ld\n",npe->np->name,npe->np->length,npe->name_lsa_id);
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length);
hashtb_next(e);
}
hashtb_end(e);
if ( nlsr->debugging )
printf("\n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
}
void
update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id)
{
struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
int res;
hashtb_start(nlsr->npl, e);
res = hashtb_seek(e, np->name, np->length, 0);
if(res == HT_OLD_ENTRY)
{
npe=e->data;
npe->name_lsa_id=nlsa_id;
}
else
{
hashtb_delete(e);
}
hashtb_end(e);
}
void
destroy_npl_entry_component(struct name_prefix_list_entry *npe)
{
if (npe->np->name)
free(npe->np->name);
if(npe->np)
free(npe->np);
}
void
destroy_npl(void)
{
int i, npl_element;
struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
hashtb_start(nlsr->npl, e);
npl_element=hashtb_n(nlsr->npl);
for(i=0;i<npl_element;i++)
{
npe=e->data;
destroy_npl_entry_component(npe);
hashtb_next(e);
}
hashtb_end(e);
if ( nlsr->npl)
hashtb_destroy(&nlsr->npl);
}