blob: c55efe4d34c55961148039ba018c385b06ff364f [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");
akmhoquea6817692012-08-21 13:50:01 -040029 printf("Neighbor: %s Length: %d Face: %d Status: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status);
akmhoque8a5babe2012-08-16 17:39:33 -050030
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);
akmhoquea6817692012-08-21 13:50:01 -040038 res = hashtb_seek(e, nbr->neighbor->buf , 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;
akmhoquea6817692012-08-21 13:50:01 -040044 hnbr->neighbor=ccn_charbuf_create();
45 //res=ccn_name_from_uri(hnbr->neighbor,ccn_charbuf_as_string(nbr->neighbor));
46 ccn_charbuf_append_string(hnbr->neighbor,ccn_charbuf_as_string(nbr->neighbor));
47
48 //hnbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
49 //hnbr->neighbor->name=(char *)malloc(nbr->neighbor->length);
50 //memcpy(hnbr->neighbor->name,nbr->neighbor->name,nbr->neighbor->length);
51 //hnbr->neighbor->name[nbr->neighbor->length]='\0';
akmhoquef6432c22012-08-21 13:18:05 -040052 //hnbr->last_lsdb_version=(char *)malloc(15);
akmhoquea6817692012-08-21 13:50:01 -040053 //hnbr->neighbor->length=nbr->neighbor->length;
akmhoque8a5babe2012-08-16 17:39:33 -050054
akmhoquee7c4b6d2012-08-21 12:30:25 -040055 hnbr->face=nbr->face;
56 hnbr->status=nbr->status;
akmhoquef6432c22012-08-21 13:18:05 -040057 //memcpy(hnbr->last_lsdb_version,"00000000000000",14);
58 //memcpy(hnbr->last_lsdb_version+strlen(hnbr->last_lsdb_version),"\0",1);
59 hnbr->last_lsdb_version=0;
akmhoque8a5babe2012-08-16 17:39:33 -050060
akmhoquee7c4b6d2012-08-21 12:30:25 -040061 struct hashtb_param param_luq = {0};
62 hnbr->lsa_update_queue=hashtb_create(200, &param_luq);
63 }
akmhoque8a5babe2012-08-16 17:39:33 -050064
65 hashtb_end(e);
66
67 printf("\n");
68
69
70}
71
72void
73print_adjacent_from_adl(void)
74{
75 printf("print_adjacent_from_adl called \n");
76 int i, adl_element;
77 struct ndn_neighbor *nbr;
78
79 struct hashtb_enumerator ee;
80 struct hashtb_enumerator *e = &ee;
81
82 hashtb_start(nlsr->adl, e);
83 adl_element=hashtb_n(nlsr->adl);
84
85 for(i=0;i<adl_element;i++)
86 {
87 nbr=e->data;
akmhoquea6817692012-08-21 13:50:01 -040088 printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %ld \n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version);
akmhoque8a5babe2012-08-16 17:39:33 -050089 hashtb_next(e);
90 }
91
92 hashtb_end(e);
93
94 printf("\n");
95}
96
97void
98update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status)
99{
100 printf("update_adjacent_status_to_adl called \n");
101
102 int res;
103 struct ndn_neighbor *nnbr;
104
105 struct hashtb_enumerator ee;
106 struct hashtb_enumerator *e = &ee;
107
108 hashtb_start(nlsr->adl, e);
akmhoque50206fc2012-08-21 11:49:12 -0400109 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
akmhoque50206fc2012-08-21 11:49:12 -0400110
akmhoque918ff9a2012-08-21 11:34:49 -0400111
akmhoquee7c4b6d2012-08-21 12:30:25 -0400112 if (res == HT_OLD_ENTRY)
113 {
114 nnbr=e->data;
115 nnbr->status=status;
116 }
akmhoqueb903ded2012-08-21 12:56:28 -0400117 else if(res == HT_NEW_ENTRY)
118 {
119 hashtb_delete(e);
120 }
akmhoque8a5babe2012-08-16 17:39:33 -0500121
122 hashtb_end(e);
123}
124
125
126void
akmhoquef6432c22012-08-21 13:18:05 -0400127update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version)
akmhoque8a5babe2012-08-16 17:39:33 -0500128{
129 printf("update_adjacent_status_to_adl called \n");
130
131 int res;
132 struct ndn_neighbor *nnbr;
133
134 struct hashtb_enumerator ee;
135 struct hashtb_enumerator *e = &ee;
136
137 hashtb_start(nlsr->adl, e);
akmhoque2852a222012-08-21 12:09:00 -0400138 res = hashtb_seek(e, nbr->buf, nbr->length, 0);
akmhoque8a5babe2012-08-16 17:39:33 -0500139
akmhoquee7c4b6d2012-08-21 12:30:25 -0400140 if( res == HT_OLD_ENTRY )
141 {
142 nnbr=e->data;
akmhoquef6432c22012-08-21 13:18:05 -0400143 nnbr->last_lsdb_version = version;
144 //memcpy(nnbr->last_lsdb_version,version,strlen(version)+1);
akmhoquee7c4b6d2012-08-21 12:30:25 -0400145 }
akmhoqueb903ded2012-08-21 12:56:28 -0400146 else if(res == HT_NEW_ENTRY)
147 {
148 hashtb_delete(e);
149 }
150
akmhoque8a5babe2012-08-16 17:39:33 -0500151 hashtb_end(e);
152}