blob: 1be3fc202123154c188e9a347820fd4ee4b2a289 [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");
29 printf("Neighbor: %s Length: %d Face: %d Status: %d\n",nbr->neighbor->name,nbr->neighbor->length,nbr->face, nbr->status);
30
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);
38 res = hashtb_seek(e, nbr->neighbor->name , 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;
akmhoque8a5babe2012-08-16 17:39:33 -050044
akmhoquee7c4b6d2012-08-21 12:30:25 -040045 hnbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
46 hnbr->neighbor->name=(char *)malloc(nbr->neighbor->length);
47 memcpy(hnbr->neighbor->name,nbr->neighbor->name,nbr->neighbor->length);
48 hnbr->last_lsdb_version=(char *)malloc(15);
akmhoque8a5babe2012-08-16 17:39:33 -050049
akmhoquee7c4b6d2012-08-21 12:30:25 -040050 hnbr->neighbor->length=nbr->neighbor->length;
51 hnbr->face=nbr->face;
52 hnbr->status=nbr->status;
53 memcpy(hnbr->last_lsdb_version,"00000000000000",14);
54 memcpy(hnbr->last_lsdb_version+strlen(hnbr->last_lsdb_version),"\0",1);
akmhoque8a5babe2012-08-16 17:39:33 -050055
akmhoquee7c4b6d2012-08-21 12:30:25 -040056 struct hashtb_param param_luq = {0};
57 hnbr->lsa_update_queue=hashtb_create(200, &param_luq);
58 }
akmhoque8a5babe2012-08-16 17:39:33 -050059
60 hashtb_end(e);
61
62 printf("\n");
63
64
65}
66
67void
68print_adjacent_from_adl(void)
69{
70 printf("print_adjacent_from_adl called \n");
71 int i, adl_element;
72 struct ndn_neighbor *nbr;
73
74 struct hashtb_enumerator ee;
75 struct hashtb_enumerator *e = &ee;
76
77 hashtb_start(nlsr->adl, e);
78 adl_element=hashtb_n(nlsr->adl);
79
80 for(i=0;i<adl_element;i++)
81 {
82 nbr=e->data;
akmhoque6dc9a242012-08-21 11:23:57 -040083 printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %s \n",nbr->neighbor->name,nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version);
akmhoque8a5babe2012-08-16 17:39:33 -050084 hashtb_next(e);
85 }
86
87 hashtb_end(e);
88
89 printf("\n");
90}
91
92void
93update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status)
94{
95 printf("update_adjacent_status_to_adl called \n");
96
97 int res;
98 struct ndn_neighbor *nnbr;
99
100 struct hashtb_enumerator ee;
101 struct hashtb_enumerator *e = &ee;
102
103 hashtb_start(nlsr->adl, e);
akmhoque50206fc2012-08-21 11:49:12 -0400104 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
akmhoque50206fc2012-08-21 11:49:12 -0400105
akmhoque918ff9a2012-08-21 11:34:49 -0400106
akmhoquee7c4b6d2012-08-21 12:30:25 -0400107 if (res == HT_OLD_ENTRY)
108 {
109 nnbr=e->data;
110 nnbr->status=status;
111 }
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
akmhoque6dc9a242012-08-21 11:23:57 -0400122update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, char *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;
138 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
139 }
akmhoqueb903ded2012-08-21 12:56:28 -0400140 else if(res == HT_NEW_ENTRY)
141 {
142 hashtb_delete(e);
143 }
144
akmhoque8a5babe2012-08-16 17:39:33 -0500145 hashtb_end(e);
146}