blob: 5c36699c2a338f10ff3c89cd9779c6fabfb876bc [file] [log] [blame]
akmhoque03004e62012-09-06 01:12:28 -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_npl.h"
akmhoque1771c412012-11-09 13:06:08 -060022#include "utility.h"
akmhoque03004e62012-09-06 01:12:28 -050023
24
akmhoquee6f98a12013-02-22 10:33:26 -060025
akmhoque03004e62012-09-06 01:12:28 -050026void
27add_name_to_npl(struct name_prefix *np)
28{
akmhoquee6f98a12013-02-22 10:33:26 -060029 struct name_prefix_list_entry *npe;
akmhoque03004e62012-09-06 01:12:28 -050030 struct hashtb_enumerator ee;
31 struct hashtb_enumerator *e = &ee;
32 int res;
33
34 hashtb_start(nlsr->npl, e);
35 res = hashtb_seek(e, np->name, np->length, 0);
36
37 if(res == HT_NEW_ENTRY)
38 {
akmhoque3171d652012-11-13 11:44:33 -060039 npe=e->data;
akmhoquee6f98a12013-02-22 10:33:26 -060040 npe->np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
akmhoque3171d652012-11-13 11:44:33 -060041 npe->np->length=np->length;
akmhoquee6f98a12013-02-22 10:33:26 -060042 npe->np->name=(char *)calloc(np->length,sizeof(char));
akmhoque3171d652012-11-13 11:44:33 -060043 memcpy(npe->np->name,np->name,np->length);
44 npe->name_lsa_id=0;
akmhoque03004e62012-09-06 01:12:28 -050045 }
46
47 hashtb_end(e);
48
49}
50
akmhoque3171d652012-11-13 11:44:33 -060051int
52does_name_exist_in_npl(struct name_prefix *np)
53{
54 int ret=0;
akmhoque3171d652012-11-13 11:44:33 -060055 struct hashtb_enumerator ee;
56 struct hashtb_enumerator *e = &ee;
57 int res;
58
59 hashtb_start(nlsr->npl, e);
60 res = hashtb_seek(e, np->name, np->length, 0);
61
62 if(res == HT_NEW_ENTRY)
63 {
64 hashtb_delete(e);
65 ret=0;
66 }
67 else
68 {
69 ret=1;
70 }
71 hashtb_end(e);
72
73 return ret;
74
75}
76
77
78long int
79get_lsa_id_from_npl(struct name_prefix *np)
80{
81 int ret=0;
82
83 struct name_prefix_list_entry *npe;
84
85 struct hashtb_enumerator ee;
86 struct hashtb_enumerator *e = &ee;
87 int res;
88
89 hashtb_start(nlsr->npl, e);
90 res = hashtb_seek(e, np->name, np->length, 0);
91
92 if(res == HT_NEW_ENTRY)
93 {
94 hashtb_delete(e);
95 ret=0;
96 }
97 else
98 {
99 npe=e->data;
100 ret=npe->name_lsa_id;
101 }
102 hashtb_end(e);
103
104 return ret;
105
106}
akmhoque03004e62012-09-06 01:12:28 -0500107
108void
109print_name_prefix_from_npl(void)
110{
akmhoque1771c412012-11-09 13:06:08 -0600111 if ( nlsr->debugging )
112 printf("print_name_prefix_from_npl called \n");
113 if ( nlsr->detailed_logging )
114 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n");
akmhoque03004e62012-09-06 01:12:28 -0500115 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600116 //struct name_prefix *np;
117 struct name_prefix_list_entry *npe;
akmhoque03004e62012-09-06 01:12:28 -0500118
119 struct hashtb_enumerator ee;
120 struct hashtb_enumerator *e = &ee;
121
122 hashtb_start(nlsr->npl, e);
123 npl_element=hashtb_n(nlsr->npl);
124
125 for(i=0;i<npl_element;i++)
126 {
akmhoque3171d652012-11-13 11:44:33 -0600127 npe=e->data;
akmhoque1771c412012-11-09 13:06:08 -0600128 if ( nlsr->debugging )
akmhoque3171d652012-11-13 11:44:33 -0600129 printf("Name Prefix: %s and Length: %d and LSA Id: %ld\n",npe->np->name,npe->np->length,npe->name_lsa_id);
akmhoque1771c412012-11-09 13:06:08 -0600130 if ( nlsr->detailed_logging )
akmhoque3171d652012-11-13 11:44:33 -0600131 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length);
akmhoque03004e62012-09-06 01:12:28 -0500132 hashtb_next(e);
133 }
134
135 hashtb_end(e);
136
akmhoque3171d652012-11-13 11:44:33 -0600137 if ( nlsr->debugging )
138 printf("\n");
139 if ( nlsr->detailed_logging )
140 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
141}
142
143void
144update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id)
145{
146 struct name_prefix_list_entry *npe;
147 struct hashtb_enumerator ee;
148 struct hashtb_enumerator *e = &ee;
149 int res;
150
151 hashtb_start(nlsr->npl, e);
152 res = hashtb_seek(e, np->name, np->length, 0);
153
154 if(res == HT_OLD_ENTRY)
155 {
156 npe=e->data;
157 npe->name_lsa_id=nlsa_id;
158 }
159 else
160 {
161 hashtb_delete(e);
162 }
163
164 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500165}
166
akmhoquee6f98a12013-02-22 10:33:26 -0600167void
168destroy_npl_entry_component(struct name_prefix_list_entry *npe)
169{
170 if (npe->np->name)
171 free(npe->np->name);
172 if(npe->np)
173 free(npe->np);
174}
175
176void
177destroy_npl(void)
178{
179 int i, npl_element;
180 struct name_prefix_list_entry *npe;
181
182 struct hashtb_enumerator ee;
183 struct hashtb_enumerator *e = &ee;
184
185 hashtb_start(nlsr->npl, e);
186 npl_element=hashtb_n(nlsr->npl);
187
188 for(i=0;i<npl_element;i++)
189 {
190 npe=e->data;
191 destroy_npl_entry_component(npe);
192 hashtb_next(e);
193 }
194
195 hashtb_end(e);
196
197 if ( nlsr->npl)
198 hashtb_destroy(&nlsr->npl);
199}