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