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); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 39 | |
| 40 | assert (res == HT_NEW_ENTRY); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 41 | |
| 42 | hnbr = e->data; |
| 43 | |
| 44 | hnbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *)); |
| 45 | hnbr->neighbor->name=(char *)malloc(nbr->neighbor->length); |
| 46 | memcpy(hnbr->neighbor->name,nbr->neighbor->name,nbr->neighbor->length); |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 47 | hnbr->last_lsdb_version=(char *)malloc(15); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 48 | |
| 49 | hnbr->neighbor->length=nbr->neighbor->length; |
| 50 | hnbr->face=nbr->face; |
| 51 | hnbr->status=nbr->status; |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 52 | memcpy(hnbr->last_lsdb_version,"00000000000000",14); |
| 53 | memcpy(hnbr->last_lsdb_version+strlen(hnbr->last_lsdb_version),"\0",1); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 54 | |
| 55 | struct hashtb_param param_luq = {0}; |
| 56 | hnbr->lsa_update_queue=hashtb_create(200, ¶m_luq); |
| 57 | |
| 58 | hashtb_end(e); |
| 59 | |
| 60 | printf("\n"); |
| 61 | |
| 62 | |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | print_adjacent_from_adl(void) |
| 67 | { |
| 68 | printf("print_adjacent_from_adl called \n"); |
| 69 | int i, adl_element; |
| 70 | struct ndn_neighbor *nbr; |
| 71 | |
| 72 | struct hashtb_enumerator ee; |
| 73 | struct hashtb_enumerator *e = ⅇ |
| 74 | |
| 75 | hashtb_start(nlsr->adl, e); |
| 76 | adl_element=hashtb_n(nlsr->adl); |
| 77 | |
| 78 | for(i=0;i<adl_element;i++) |
| 79 | { |
| 80 | nbr=e->data; |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 81 | 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); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 82 | hashtb_next(e); |
| 83 | } |
| 84 | |
| 85 | hashtb_end(e); |
| 86 | |
| 87 | printf("\n"); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status) |
| 92 | { |
| 93 | printf("update_adjacent_status_to_adl called \n"); |
| 94 | |
| 95 | int res; |
| 96 | struct ndn_neighbor *nnbr; |
| 97 | |
| 98 | struct hashtb_enumerator ee; |
| 99 | struct hashtb_enumerator *e = ⅇ |
| 100 | |
| 101 | hashtb_start(nlsr->adl, e); |
akmhoque | 50206fc | 2012-08-21 11:49:12 -0400 | [diff] [blame] | 102 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
akmhoque | 50206fc | 2012-08-21 11:49:12 -0400 | [diff] [blame] | 103 | |
akmhoque | 918ff9a | 2012-08-21 11:34:49 -0400 | [diff] [blame] | 104 | |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 105 | assert( res == HT_OLD_ENTRY); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 106 | |
| 107 | nnbr=e->data; |
| 108 | nnbr->status=status; |
| 109 | |
| 110 | hashtb_end(e); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 115 | update_adjacent_lsdb_version_to_adl(struct ccn_charbuf *nbr, char *version) |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 116 | { |
| 117 | printf("update_adjacent_status_to_adl called \n"); |
| 118 | |
| 119 | int res; |
| 120 | struct ndn_neighbor *nnbr; |
| 121 | |
| 122 | struct hashtb_enumerator ee; |
| 123 | struct hashtb_enumerator *e = ⅇ |
| 124 | |
| 125 | hashtb_start(nlsr->adl, e); |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 126 | res = hashtb_seek(e, nbr->buf, nbr->length, 0); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 127 | |
akmhoque | 2852a22 | 2012-08-21 12:09:00 -0400 | [diff] [blame] | 128 | assert( res == HT_OLD_ENTRY); |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 129 | |
| 130 | nnbr=e->data; |
akmhoque | 6dc9a24 | 2012-08-21 11:23:57 -0400 | [diff] [blame] | 131 | memcpy(nnbr->last_lsdb_version,version,strlen(version)+1); |
| 132 | |
akmhoque | 8a5babe | 2012-08-16 17:39:33 -0500 | [diff] [blame] | 133 | hashtb_end(e); |
| 134 | } |