akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 1 | #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 | |
| 25 | void |
| 26 | add_adjacent_to_adl(struct ndn_neighbor *nbr) |
| 27 | { |
| 28 | printf("\nadd_adjacent_to_adl called\n"); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 29 | printf("Neighbor: %s Length: %d Face: %d Status: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 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 = ⅇ |
| 35 | int res; |
| 36 | |
| 37 | hashtb_start(nlsr->adl, e); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 38 | res = hashtb_seek(e, nbr->neighbor->buf , nbr->neighbor->length, 0); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 39 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 40 | if(res == HT_NEW_ENTRY ) |
| 41 | { |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 42 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 43 | hnbr = e->data; |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 44 | hnbr->neighbor=ccn_charbuf_create(); |
akmhoque | a681769 | 2012-08-21 13:50:01 -0400 | [diff] [blame] | 45 | ccn_charbuf_append_string(hnbr->neighbor,ccn_charbuf_as_string(nbr->neighbor)); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 46 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 47 | hnbr->face=nbr->face; |
| 48 | hnbr->status=nbr->status; |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 49 | hnbr->last_lsdb_version=0; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 50 | hnbr->info_interest_timed_out=0; |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 51 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 52 | struct hashtb_param param_luq = {0}; |
| 53 | hnbr->lsa_update_queue=hashtb_create(200, ¶m_luq); |
| 54 | } |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 55 | |
| 56 | hashtb_end(e); |
| 57 | |
| 58 | printf("\n"); |
| 59 | |
| 60 | |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | print_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 = ⅇ |
| 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; |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 79 | printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %ld Interest Timed Out: %d\n",ccn_charbuf_as_string(nbr->neighbor),(int)nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version,nbr->info_interest_timed_out); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 80 | hashtb_next(e); |
| 81 | } |
| 82 | |
| 83 | hashtb_end(e); |
| 84 | |
| 85 | printf("\n"); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status) |
| 90 | { |
| 91 | printf("update_adjacent_status_to_adl called \n"); |
| 92 | |
| 93 | int res; |
| 94 | struct ndn_neighbor *nnbr; |
| 95 | |
| 96 | struct hashtb_enumerator ee; |
| 97 | struct hashtb_enumerator *e = ⅇ |
| 98 | |
| 99 | hashtb_start(nlsr->adl, e); |
akmhoque | 50206fc | 2012-08-21 11:49:12 -0400 | [diff] [blame] | 100 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
akmhoque | 50206fc | 2012-08-21 11:49:12 -0400 | [diff] [blame] | 101 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 102 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 103 | if (res == HT_OLD_ENTRY) |
| 104 | { |
| 105 | nnbr=e->data; |
| 106 | nnbr->status=status; |
| 107 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 108 | else if(res == HT_NEW_ENTRY) |
| 109 | { |
| 110 | hashtb_delete(e); |
| 111 | } |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 112 | |
| 113 | hashtb_end(e); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 118 | update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 119 | { |
| 120 | printf("update_adjacent_status_to_adl called \n"); |
| 121 | |
| 122 | int res; |
| 123 | struct ndn_neighbor *nnbr; |
| 124 | |
| 125 | struct hashtb_enumerator ee; |
| 126 | struct hashtb_enumerator *e = ⅇ |
| 127 | |
| 128 | hashtb_start(nlsr->adl, e); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 129 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 130 | |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 131 | if( res == HT_OLD_ENTRY ) |
| 132 | { |
| 133 | nnbr=e->data; |
akmhoque | f6432c2 | 2012-08-21 13:18:05 -0400 | [diff] [blame] | 134 | nnbr->last_lsdb_version = version; |
| 135 | //memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
akmhoque | e7c4b6d | 2012-08-21 12:30:25 -0400 | [diff] [blame] | 136 | } |
akmhoque | b903ded | 2012-08-21 12:56:28 -0400 | [diff] [blame] | 137 | else if(res == HT_NEW_ENTRY) |
| 138 | { |
| 139 | hashtb_delete(e); |
| 140 | } |
| 141 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 142 | hashtb_end(e); |
| 143 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 144 | |
| 145 | void |
| 146 | update_adjacent_timed_out_to_adl(struct ccn_charbuf *nbr, int increment) |
| 147 | { |
| 148 | printf("update_adjacent_timed_out_to_adl called \n"); |
| 149 | |
| 150 | int res; |
| 151 | struct ndn_neighbor *nnbr; |
| 152 | |
| 153 | struct hashtb_enumerator ee; |
| 154 | struct hashtb_enumerator *e = ⅇ |
| 155 | |
| 156 | hashtb_start(nlsr->adl, e); |
| 157 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
| 158 | |
| 159 | if( res == HT_OLD_ENTRY ) |
| 160 | { |
| 161 | nnbr=e->data; |
| 162 | nnbr->info_interest_timed_out += increment; |
| 163 | } |
| 164 | else if(res == HT_NEW_ENTRY) |
| 165 | { |
| 166 | hashtb_delete(e); |
| 167 | } |
| 168 | |
| 169 | hashtb_end(e); |
| 170 | } |
| 171 | |
| 172 | void |
| 173 | update_adjacent_timed_out_zero_to_adl(struct ccn_charbuf *nbr) |
| 174 | { |
| 175 | |
| 176 | printf("update_adjacent_timed_out_zero_to_adl called \n"); |
| 177 | int time_out_number=get_timed_out_number(nbr); |
| 178 | update_adjacent_timed_out_to_adl(nbr,-time_out_number); |
| 179 | |
| 180 | } |
| 181 | |
| 182 | |
| 183 | int |
| 184 | get_timed_out_number(struct ccn_charbuf *nbr) |
| 185 | { |
| 186 | |
| 187 | printf("get_timed_out_number called \n"); |
| 188 | |
| 189 | int res,ret=-1; |
| 190 | struct ndn_neighbor *nnbr; |
| 191 | |
| 192 | struct hashtb_enumerator ee; |
| 193 | struct hashtb_enumerator *e = ⅇ |
| 194 | |
| 195 | hashtb_start(nlsr->adl, e); |
| 196 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
| 197 | |
| 198 | if( res == HT_OLD_ENTRY ) |
| 199 | { |
| 200 | nnbr=e->data; |
| 201 | ret=nnbr->info_interest_timed_out; |
| 202 | } |
| 203 | else if(res == HT_NEW_ENTRY) |
| 204 | { |
| 205 | hashtb_delete(e); |
| 206 | } |
| 207 | |
| 208 | hashtb_end(e); |
| 209 | |
| 210 | return ret; |
| 211 | |
| 212 | } |