blob: 0b645bcb9144ad59a0840cc81165832a0a4887fd [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);
39
40 hnbr = e->data;
41
42 hnbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
43 hnbr->neighbor->name=(char *)malloc(nbr->neighbor->length);
44 memcpy(hnbr->neighbor->name,nbr->neighbor->name,nbr->neighbor->length);
akmhoque6dc9a242012-08-21 11:23:57 -040045 hnbr->last_lsdb_version=(char *)malloc(15);
akmhoque8a5babe2012-08-16 17:39:33 -050046
47 hnbr->neighbor->length=nbr->neighbor->length;
48 hnbr->face=nbr->face;
49 hnbr->status=nbr->status;
akmhoque6dc9a242012-08-21 11:23:57 -040050 memcpy(hnbr->last_lsdb_version,"00000000000000",14);
51 memcpy(hnbr->last_lsdb_version+strlen(hnbr->last_lsdb_version),"\0",1);
akmhoque8a5babe2012-08-16 17:39:33 -050052
53 struct hashtb_param param_luq = {0};
54 hnbr->lsa_update_queue=hashtb_create(200, &param_luq);
55
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;
akmhoque6dc9a242012-08-21 11:23:57 -040079 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 -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;
akmhoqueb9ae9d92012-08-21 11:45:45 -040094 char *name=ccn_charbuf_as_string(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -050095 struct ndn_neighbor *nnbr;
96
97 struct hashtb_enumerator ee;
98 struct hashtb_enumerator *e = &ee;
99
100 hashtb_start(nlsr->adl, e);
akmhoqueb9ae9d92012-08-21 11:45:45 -0400101 //res = hashtb_seek(e, nbr->buf, nbr->length, 0);
102 res = hashtb_seek(e, name,strlen(name) , 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500103
akmhoqueb9ae9d92012-08-21 11:45:45 -0400104 //printf("Nbr: %s Length:%d\n",nbr->buf, (int)nbr->length);
105 printf("Nbr: %s Length: %d\n",name, (int) strlen(name));
akmhoque918ff9a2012-08-21 11:34:49 -0400106
akmhoque6dc9a242012-08-21 11:23:57 -0400107 assert( res == HT_OLD_ENTRY);
akmhoque8a5babe2012-08-16 17:39:33 -0500108
109 nnbr=e->data;
110 nnbr->status=status;
111
112 hashtb_end(e);
113}
114
115
116void
akmhoque6dc9a242012-08-21 11:23:57 -0400117update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, char *version)
akmhoque8a5babe2012-08-16 17:39:33 -0500118{
119 printf("update_adjacent_status_to_adl called \n");
120
121 int res;
akmhoque71b552d2012-08-21 11:44:34 -0400122 char *name=ccn_charbuf_as_string(nbr);
akmhoque8a5babe2012-08-16 17:39:33 -0500123 struct ndn_neighbor *nnbr;
124
125 struct hashtb_enumerator ee;
126 struct hashtb_enumerator *e = &ee;
127
128 hashtb_start(nlsr->adl, e);
akmhoque71b552d2012-08-21 11:44:34 -0400129 //res = hashtb_seek(e, nbr->buf, nbr->length, 0);
130 res = hashtb_seek(e, name,strlen(name) , 0);
akmhoque918ff9a2012-08-21 11:34:49 -0400131
akmhoque71b552d2012-08-21 11:44:34 -0400132 //printf("Nbr: %s Length:%d\n",nbr->buf, (int)nbr->length);
133 printf("Nbr: %s Length: %d\n",name, (int) strlen(name));
akmhoque8a5babe2012-08-16 17:39:33 -0500134
akmhoque6dc9a242012-08-21 11:23:57 -0400135 assert( res == HT_OLD_ENTRY);
akmhoque8a5babe2012-08-16 17:39:33 -0500136
137 nnbr=e->data;
akmhoque6dc9a242012-08-21 11:23:57 -0400138 memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
139
akmhoque8a5babe2012-08-16 17:39:33 -0500140 hashtb_end(e);
141}