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"); |
| 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 = ⅇ |
| 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); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 45 | |
| 46 | hnbr->neighbor->length=nbr->neighbor->length; |
| 47 | hnbr->face=nbr->face; |
| 48 | hnbr->status=nbr->status; |
akmhoque | 3b38ee7 | 2012-08-21 09:36:02 -0400 | [diff] [blame] | 49 | hnbr->last_lsdb_version=0; |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 50 | |
| 51 | struct hashtb_param param_luq = {0}; |
| 52 | hnbr->lsa_update_queue=hashtb_create(200, ¶m_luq); |
| 53 | |
| 54 | hashtb_end(e); |
| 55 | |
| 56 | printf("\n"); |
| 57 | |
| 58 | |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | print_adjacent_from_adl(void) |
| 63 | { |
| 64 | printf("print_adjacent_from_adl called \n"); |
| 65 | int i, adl_element; |
| 66 | struct ndn_neighbor *nbr; |
| 67 | |
| 68 | struct hashtb_enumerator ee; |
| 69 | struct hashtb_enumerator *e = ⅇ |
| 70 | |
| 71 | hashtb_start(nlsr->adl, e); |
| 72 | adl_element=hashtb_n(nlsr->adl); |
| 73 | |
| 74 | for(i=0;i<adl_element;i++) |
| 75 | { |
| 76 | nbr=e->data; |
akmhoque | 3b38ee7 | 2012-08-21 09:36:02 -0400 | [diff] [blame] | 77 | printf("Neighbor: %s Length: %d Face: %d Status: %d LSDB Version: %ld \n",nbr->neighbor->name,nbr->neighbor->length,nbr->face, nbr->status, nbr->last_lsdb_version); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 78 | hashtb_next(e); |
| 79 | } |
| 80 | |
| 81 | hashtb_end(e); |
| 82 | |
| 83 | printf("\n"); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status) |
| 88 | { |
| 89 | printf("update_adjacent_status_to_adl called \n"); |
| 90 | |
| 91 | int res; |
| 92 | struct ndn_neighbor *nnbr; |
| 93 | |
| 94 | struct hashtb_enumerator ee; |
| 95 | struct hashtb_enumerator *e = ⅇ |
| 96 | |
| 97 | hashtb_start(nlsr->adl, e); |
| 98 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
| 99 | |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 100 | //assert( res == HT_OLD_ENTRY); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 101 | |
| 102 | nnbr=e->data; |
| 103 | nnbr->status=status; |
| 104 | |
| 105 | hashtb_end(e); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void |
akmhoque | 3b38ee7 | 2012-08-21 09:36:02 -0400 | [diff] [blame] | 110 | update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, long int version) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 111 | { |
| 112 | printf("update_adjacent_status_to_adl called \n"); |
| 113 | |
| 114 | int res; |
| 115 | struct ndn_neighbor *nnbr; |
| 116 | |
| 117 | struct hashtb_enumerator ee; |
| 118 | struct hashtb_enumerator *e = ⅇ |
| 119 | |
| 120 | hashtb_start(nlsr->adl, e); |
| 121 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
| 122 | |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 123 | //assert( res == HT_OLD_ENTRY); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 124 | |
| 125 | nnbr=e->data; |
akmhoque | 3b38ee7 | 2012-08-21 09:36:02 -0400 | [diff] [blame] | 126 | nnbr->last_lsdb_version=version; |
akmhoque | 438b07e | 2012-08-21 10:13:57 -0400 | [diff] [blame] | 127 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 128 | hashtb_end(e); |
| 129 | } |