blob: a2e227111af1410c2f6df565ac8eaf3b549ae65c [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
25void
26add_name_to_npl(struct name_prefix *np)
27{
akmhoque3171d652012-11-13 11:44:33 -060028 struct name_prefix_list_entry *npe=(struct name_prefix_list_entry *)malloc(sizeof(struct name_prefix_list_entry));
29 //struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
akmhoque03004e62012-09-06 01:12:28 -050030
31 struct hashtb_enumerator ee;
32 struct hashtb_enumerator *e = &ee;
33 int res;
34
35 hashtb_start(nlsr->npl, e);
36 res = hashtb_seek(e, np->name, np->length, 0);
37
38 if(res == HT_NEW_ENTRY)
39 {
akmhoque3171d652012-11-13 11:44:33 -060040 npe=e->data;
41 npe->np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
42 npe->np->length=np->length;
43 npe->np->name=(char *)malloc(np->length);
44 memcpy(npe->np->name,np->name,np->length);
45 npe->name_lsa_id=0;
46 //hnp = e->data;
47 //hnp->length=np->length;
48 //hnp->name=(char *)malloc(np->length); //free
49 //memcpy(hnp->name,np->name,np->length);
akmhoque03004e62012-09-06 01:12:28 -050050 }
51
52 hashtb_end(e);
53
54}
55
akmhoque3171d652012-11-13 11:44:33 -060056int
57does_name_exist_in_npl(struct name_prefix *np)
58{
59 int ret=0;
60
61 //struct name_prefix_entry *npe;
62
63 struct hashtb_enumerator ee;
64 struct hashtb_enumerator *e = &ee;
65 int res;
66
67 hashtb_start(nlsr->npl, e);
68 res = hashtb_seek(e, np->name, np->length, 0);
69
70 if(res == HT_NEW_ENTRY)
71 {
72 hashtb_delete(e);
73 ret=0;
74 }
75 else
76 {
77 ret=1;
78 }
79 hashtb_end(e);
80
81 return ret;
82
83}
84
85
86long int
87get_lsa_id_from_npl(struct name_prefix *np)
88{
89 int ret=0;
90
91 struct name_prefix_list_entry *npe;
92
93 struct hashtb_enumerator ee;
94 struct hashtb_enumerator *e = &ee;
95 int res;
96
97 hashtb_start(nlsr->npl, e);
98 res = hashtb_seek(e, np->name, np->length, 0);
99
100 if(res == HT_NEW_ENTRY)
101 {
102 hashtb_delete(e);
103 ret=0;
104 }
105 else
106 {
107 npe=e->data;
108 ret=npe->name_lsa_id;
109 }
110 hashtb_end(e);
111
112 return ret;
113
114}
akmhoque03004e62012-09-06 01:12:28 -0500115
116void
117print_name_prefix_from_npl(void)
118{
akmhoque1771c412012-11-09 13:06:08 -0600119 if ( nlsr->debugging )
120 printf("print_name_prefix_from_npl called \n");
121 if ( nlsr->detailed_logging )
122 writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n");
akmhoque03004e62012-09-06 01:12:28 -0500123 int i, npl_element;
akmhoque3171d652012-11-13 11:44:33 -0600124 //struct name_prefix *np;
125 struct name_prefix_list_entry *npe;
akmhoque03004e62012-09-06 01:12:28 -0500126
127 struct hashtb_enumerator ee;
128 struct hashtb_enumerator *e = &ee;
129
130 hashtb_start(nlsr->npl, e);
131 npl_element=hashtb_n(nlsr->npl);
132
133 for(i=0;i<npl_element;i++)
134 {
akmhoque3171d652012-11-13 11:44:33 -0600135 npe=e->data;
akmhoque1771c412012-11-09 13:06:08 -0600136 if ( nlsr->debugging )
akmhoque3171d652012-11-13 11:44:33 -0600137 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 -0600138 if ( nlsr->detailed_logging )
akmhoque3171d652012-11-13 11:44:33 -0600139 writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length);
akmhoque03004e62012-09-06 01:12:28 -0500140 hashtb_next(e);
141 }
142
143 hashtb_end(e);
144
akmhoque3171d652012-11-13 11:44:33 -0600145 if ( nlsr->debugging )
146 printf("\n");
147 if ( nlsr->detailed_logging )
148 writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
149}
150
151void
152update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id)
153{
154 struct name_prefix_list_entry *npe;
155 struct hashtb_enumerator ee;
156 struct hashtb_enumerator *e = &ee;
157 int res;
158
159 hashtb_start(nlsr->npl, e);
160 res = hashtb_seek(e, np->name, np->length, 0);
161
162 if(res == HT_OLD_ENTRY)
163 {
164 npe=e->data;
165 npe->name_lsa_id=nlsa_id;
166 }
167 else
168 {
169 hashtb_delete(e);
170 }
171
172 hashtb_end(e);
akmhoque03004e62012-09-06 01:12:28 -0500173}
174