Update
diff --git a/nlsr.c b/nlsr.c
index ad7afc0..0387beb 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -101,6 +101,20 @@
}
printf("Name Prefix: %s \n",name_prefix);
+
+ struct name_prefix *np=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
+ np->name=(char *)malloc(strlen(name_prefix)+1);
+ memcpy(np->name,name_prefix,strlen(name_prefix)+1);
+ np->length=strlen(name_prefix)+1;
+
+ add_name_prefix_to_npl(np);
+ /* Debugging Purpose */
+ print_name_prefix_from_npl();
+
+ free(np->name);
+ free(np);
+
+
}
void
@@ -108,28 +122,52 @@
{
if(command==NULL)
{
- printf(" Wrong Command Format ( ccnneighbor router_id faceX)\n");
+ printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
return;
}
char *rem;
const char *sep=" \t\n";
- char *rtr_id,*face;
+ char *rtr_name,*face;
- rtr_id=strtok_r(command,sep,&rem);
- if(rtr_id==NULL)
+ rtr_name=strtok_r(command,sep,&rem);
+ if(rtr_name==NULL)
{
- printf(" Wrong Command Format ( ccnneighbor router_id faceX)\n");
+ printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
return;
}
face=strtok_r(NULL,sep,&rem);
if(face==NULL)
{
- printf(" Wrong Command Format ( ccnneighbor router_id faceX)\n");
+ printf(" Wrong Command Format ( ccnneighbor router_name faceX)\n");
return;
}
- printf("Router: %s face: %s\n",rtr_id,face);
+ printf("Router: %s face: %s\n",rtr_name,face);
+ int face_id;
+ int res;
+ res=sscanf(face,"face%d",&face_id);
+
+ if(res != 1 )
+ {
+ printf(" Wrong Command Format ( ccnneighbor router_name faceX) where X is integer\n");
+ return;
+ }
+
+ struct ndn_neighbor *nbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*));
+ nbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
+ nbr->neighbor->name=(char *)malloc(strlen(rtr_name)+1);
+ memcpy(nbr->neighbor->name,rtr_name,strlen(rtr_name)+1);
+ nbr->neighbor->length=strlen(rtr_name)+1;
+ nbr->face=face_id;
+ nbr->status=0;
+
+ add_adjacent_to_adl(nbr);
+ print_adjacent_from_adl();
+
+ free(nbr->neighbor->name);
+ free(nbr->neighbor);
+ free(nbr);
}
@@ -191,6 +229,116 @@
return 0;
}
+void
+add_name_prefix_to_npl(struct name_prefix *np)
+{
+
+
+ printf("\nadd_name_prefix called\n");
+ printf("Name Prefix: %s and length: %d \n",np->name,np->length);
+
+ struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->npl, e);
+ res = hashtb_seek(e, np->name, strlen(np->name), 0);
+
+ hnp = e->data;
+ hnp->name=(char *)malloc(np->length);
+ memcpy(hnp->name,np->name,np->length);
+ hnp->length=np->length;
+
+ hashtb_end(e);
+
+ printf("\n");
+
+}
+
+void
+print_name_prefix_from_npl(void)
+{
+ printf("print_name_prefix_from_npl called \n");
+ int i, npl_element;
+ struct name_prefix *np;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->npl, e);
+ npl_element=hashtb_n(nlsr->npl);
+
+ for(i=0;i<npl_element;i++)
+ {
+ np=e->data;
+ printf("Name Prefix: %s and Length: %d \n",np->name,np->length);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ printf("\n");
+}
+
+void
+add_adjacent_to_adl(struct ndn_neighbor *nbr)
+{
+ printf("\nadd_adjacent_to_adl called\n");
+ printf("Neighbor: %s Length: %d Face: %d Status: %d\n",nbr->neighbor->name,nbr->neighbor->length,nbr->face, nbr->status);
+
+ struct ndn_neighbor *hnbr=(struct ndn_neighbor *)malloc(sizeof(struct ndn_neighbor*));
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->adl, e);
+ res = hashtb_seek(e, nbr->neighbor->name , nbr->neighbor->length, 0);
+
+ hnbr = e->data;
+
+ hnbr->neighbor=(struct name_prefix *)malloc(sizeof(struct name_prefix *));
+ hnbr->neighbor->name=(char *)malloc(nbr->neighbor->length);
+ memcpy(hnbr->neighbor->name,nbr->neighbor->name,nbr->neighbor->length);
+ hnbr->neighbor->length=nbr->neighbor->length;
+ hnbr->face=nbr->face;
+ hnbr->status=nbr->status;
+
+ hashtb_end(e);
+
+ printf("\n");
+
+
+}
+
+void
+print_adjacent_from_adl(void)
+{
+ printf("print_adjacent_from_adl called \n");
+ int i, adl_element;
+ struct ndn_neighbor *nbr;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->adl, e);
+ adl_element=hashtb_n(nlsr->adl);
+
+ for(i=0;i<adl_element;i++)
+ {
+ nbr=e->data;
+ printf("Neighbor: %s Length: %d Face: %d Status: %d\n",nbr->neighbor->name,nbr->neighbor->length,nbr->face, nbr->status);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ printf("\n");
+}
+
+
int
main(int argc, char *argv[])
{
@@ -202,7 +350,7 @@
nlsr=(struct nlsr *)malloc(sizeof(struct nlsr));
- nlsr->adl=hashtb_create(200, ¶m_adl);
+ nlsr->adl=hashtb_create(sizeof(struct ndn_neighbor), ¶m_adl);
nlsr->npl = hashtb_create(sizeof(struct name_prefix), ¶m_npl);
nlsr->in_interest.p = &incoming_interest;
nlsr->in_content.p = &incoming_content;