Commit 945c0520 authored by ikumar's avatar ikumar

Kristine's algorithm with a little modification: doesnt work!!

parent 4e3e74bc
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: cli.c,v 1.4 2001-06-18 01:41:19 ikumar Exp $
* $Id: cli.c,v 1.5 2001-07-19 19:55:57 ikumar Exp $
*/
#include "discvr.h"
......@@ -104,6 +104,7 @@ make_inquiry(topd_inqid_t *tip, u_int16_t ttl, u_int16_t factor)
/* ...and now our nodeID */
nid = find_nodeID();
memcpy((void *)tip->tdi_nodeID, nid, ETHADDRSIZ);
bzero(tip->tdi_p_nodeIF,ETHADDRSIZ);
}
void
......@@ -120,6 +121,7 @@ cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen,
sendto(sockfd, &ti, TOPD_INQ_SIZ, 0, pservaddr, servlen);
//print_tdinq((char *)&ti);
n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
fflush(stdin);
//printf("Receiving in client:==>\n");
//print_tdreply(recvline, n);
}
......
/*$Id: discvr.h,v 1.5 2001-06-18 01:41:19 ikumar Exp $*/
/*$Id: discvr.h,v 1.6 2001-07-19 19:55:57 ikumar Exp $*/
#ifndef _TOPD_DISCVR_H_
#define _TOPD_DISCVR_H_
......@@ -99,5 +99,8 @@ get_ifi_struct(int sock, struct ifi_info * ifihead);
void
addMyID(char* mesg, int size);
void
get_recvIFADDR(char *name,struct ifi_info * ifihead);
#endif /* _TOPD_DISCVR_H_ */
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: forw_requests.c,v 1.7 2001-06-18 01:41:19 ikumar Exp $
* $Id: forw_requests.c,v 1.8 2001-07-19 19:55:57 ikumar Exp $
*/
#include <math.h>
......@@ -32,6 +32,8 @@
*/
char recvbuf[BUFSIZ];
extern u_char myNodeID[ETHADDRSIZ];
extern u_char parent_nodeIF[ETHADDRSIZ];
static double start = 0.0;
double
......@@ -59,6 +61,7 @@ get_ifi_struct(int sock, struct ifi_info * ifihead)
return NULL;
}
/*
void
addMyID(char* mesg, int size)
{
......@@ -67,7 +70,7 @@ addMyID(char* mesg, int size)
memcpy(p->tdnbor_dnode,myNodeID,ETHADDRSIZ);
}
*/
struct ifi_info *
......@@ -77,7 +80,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
int s, n;
int more_time = 1;
fd_set rset,temp_rset;
const int on = 1;
const int on = 1;
char ifname[IFNAMSIZ];
struct topd_inqid *tdi;
struct topd_nborlist *save;
......@@ -86,7 +89,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
struct timeval tv;
int selectReturn;
struct sockaddr name;
int namelen=sizeof(name);
int namelen=sizeof(name);
int *sock_list=NULL, *temp_sock_list=NULL;
int sock_num = 0,i=0;
struct topd_inqid *temp_mesg;
......@@ -134,12 +137,15 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// Adding check for control net... -ik
if(strcmp(ifi->ifi_name,"fxp4")==0) continue;
//memcpy(&(temp_mesg->tdi_p_nodeIF),&(ifi->ifi_haddr),IFHADDRSIZ);
memcpy(&(temp_mesg->tdi_p_nodeIF),&myNodeID,IFHADDRSIZ);
printf("Forwarding the query to interface: \"%s\"\n",ifi->ifi_name);
temp_sock_list = sock_list;
sock_list = (int *)malloc(sizeof(int)*(sock_num+1));
for(i=0;i<sock_num;i++)
{
printf("copying: %d\n",temp_sock_list[i]);
//printf("copying: %d\n",temp_sock_list[i]);
sock_list[i] = temp_sock_list[i];
}
free(temp_sock_list);
......@@ -191,16 +197,17 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
print_tdinq(mesg);
n = sendto(s, mesg, mesglen, 0,
(struct sockaddr *)&sin, sizeof(struct sockaddr_in));
printf("$$$after forwarding the enquiry: ");
print_tdinq(mesg);
//printf("$$$after forwarding the enquiry: ");
//print_tdinq(mesg);
/*
if(getsockname(s, (struct sockaddr *)&name, &namelen)<0)
{
perror("getsockname\n");
}
printf("The address from where i am sending: %s\n",sock_ntop(&name,name.sa_len));
*/
//printf("The address from where i am sending: %s\n",sock_ntop(&name,name.sa_len));
if (n != mesglen) {
perror("Didn't send all of packet");
exit(1);
......@@ -220,7 +227,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
*/
n = 0;
start = tod();
start = tod();
//while ( more_time ) {
while (1) {
double begin, end, elapsed;
......@@ -235,9 +242,9 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
*/
begin = tod();
temp_rset = rset;
printf("entering select **** sec:%d and usec:%d\n",tv.tv_sec,tv.tv_usec);
//printf("entering select **** sec:%d and usec:%d\n",tv.tv_sec,tv.tv_usec);
selectReturn = select(FD_SETSIZE, &temp_rset, NULL, NULL, &tv);
printf("select return: %d\n",selectReturn);
//printf("select return: %d\n",selectReturn);
if( selectReturn < 0 ) {
printf("Error in Select call\n");
perror("select");
......@@ -260,7 +267,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
deadline -= elapsed;
tv.tv_sec = floor(deadline);
tv.tv_usec = (deadline - tv.tv_sec) * 1e+6;
printf("sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec);
//printf("sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec);
......@@ -276,7 +283,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// receive one of my neighbors' list of neighbors through
// "ifi" interface to which I just forwarded the request -ik
printf("Checking socket: %d\n",sock_list[i]);
//printf("Checking socket: %d\n",sock_list[i]);
if (!FD_ISSET(sock_list[i], &temp_rset)) continue;
......@@ -293,15 +300,14 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
if((ifi=get_ifi_struct(sock_list[i],ifihead)) == NULL)
{
printf("Socket \"%d\" is not in any ifi struct\n",sock_list[i]);
fprintf(stderr,"Socket \"%d\" is not in any ifi struct\n",sock_list[i]);
}
printf("The interface on which i received is \"%s\"",ifi->ifi_name);
//printf("The interface on which i received is \"%s\"\n",ifi->ifi_name);
// save the existing list of neighbors which I just received through
// the "ifi" interface... -ik
save = ifi->ifi_nbors;
printf("The value of save: \"%d\"\n",save);
// create a new node for the neighbor link list pointed by "ifi_nbors"
// -ik
......@@ -311,7 +317,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
exit(1);
}
/* skip inquiry ID */
ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n);
ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n-sizeof(topd_inqid_t));
if ( ifi->ifi_nbors->tdnbl_nbors == NULL ) {
perror("Not enough memory for neighbor list.");
exit(1);
......@@ -322,11 +328,12 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// to every message there is a "inquiry ID" attached in the beginning...
// -ik
//print_tdpairs(recvbuf + sizeof(topd_inqid_t),n-sizeof(topd_inqid_t));
memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf + sizeof(topd_inqid_t), n);
memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf +
sizeof(topd_inqid_t), (n-sizeof(topd_inqid_t)));
// The "tdnbl_n" contains the number of neighbors that the node, along this
// interface, has ... -ik
ifi->ifi_nbors->tdnbl_n = n / sizeof(struct topd_nbor);
ifi->ifi_nbors->tdnbl_n = (n-sizeof(topd_inqid_t)) / sizeof(struct topd_nbor);
ifi->ifi_nbors->tdnbl_next = save;
//print_tdpairs(ifi->ifi_nbors->tdnbl_nbors,n-sizeof(topd_inqid_t));
}
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: packet.h,v 1.3 2000-07-18 19:19:28 kwright Exp $
* $Id: packet.h,v 1.6 2001-08-02 21:21:05 ikumar Exp $
*/
#ifndef _TOPD_PACKET_H_
......@@ -42,10 +42,11 @@
* are struct timevals returned by gettimeofday().
*/
typedef struct topd_inqid {
struct timeval tdi_tv;
u_int16_t tdi_ttl;
u_int16_t tdi_factor;
u_char tdi_nodeID[ETHADDRSIZ];
struct timeval tdi_tv;
u_int16_t tdi_ttl;
u_int16_t tdi_factor;
u_char tdi_nodeID[ETHADDRSIZ];
u_char tdi_p_nodeIF[ETHADDRSIZ];
} topd_inqid_t;
#define TOPD_INQ_SIZ ALIGN(sizeof(struct topd_inqid))
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: reply.c,v 1.6 2001-06-14 23:19:23 ikumar Exp $
* $Id: reply.c,v 1.7 2001-07-19 19:55:57 ikumar Exp $
*/
......@@ -27,8 +27,9 @@
#include "util.h"
extern u_char myNodeID[ETHADDRSIZ];
extern u_char parent_nodeIF[ETHADDRSIZ];
extern topd_inqid_t inqid_current;
extern u_char receivingIF[ETHADDRSIZ];
/*
* Concatenate all the individual interfaces' messages into
* one long neighbor list.
......@@ -68,11 +69,16 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors
fprintf(stderr, "ran out of room and you didn't do anything reasonable.\n");
return 0;
}
//printf("My parent's address is:");
//print_nodeID(parent_nodeIF);
memcpy(nid, myNodeID, ETHADDRSIZ);
nid += ETHADDRSIZ;
memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
nid += ETHADDRSIZ;
bzero(nid, ETHADDRSIZ << 1);
memcpy(nid,parent_nodeIF,ETHADDRSIZ);
nid += ETHADDRSIZ;
memcpy(nid,receivingIF,ETHADDRSIZ);
//bzero(nid, ETHADDRSIZ);
if ( sendnbors != 0 ) {
while ( nborl != NULL ) {
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: serv.c,v 1.3 2001-06-14 23:19:23 ikumar Exp $
* $Id: serv.c,v 1.7 2001-08-04 22:58:30 ikumar Exp $
*/
#include "discvr.h"
......@@ -46,12 +46,14 @@ main(int argc, char **argv)
{
perror("bind");
}
printf("The address I am listening on is: %s\n",inet_ntoa(servaddr.sin_addr));
//printf("The address I am listening on is: %s\n",inet_ntoa(servaddr.sin_addr));
/*
if(getsockname(sockfd, (struct sockaddr *)&name, &namelen)<0)
{
perror("getsockname\n");
}
printf("No I am listening on: \"%s\"\n",sock_ntop(&name,name.sa_len));
*/
serv_listen(sockfd, (struct sockaddr *) &cliaddr, sizeof(cliaddr));
/* We'll never get here */
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: serv_listen.c,v 1.7 2001-06-18 01:41:19 ikumar Exp $
* $Id: serv_listen.c,v 1.8 2001-07-19 19:55:57 ikumar Exp $
*/
#include "discvr.h"
......@@ -41,6 +41,8 @@ extern topd_inqid_t inqid_current;
* as the nodeID.
*/
u_char myNodeID[ETHADDRSIZ];
u_char parent_nodeIF[ETHADDRSIZ];
u_char receivingIF[ETHADDRSIZ];
/*
* Return 0 if the inquiry is not from us, 1 if it is.
......@@ -60,11 +62,17 @@ from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead)
int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead)
{
char *name1,*name2;
char *name1,*name2,*name_tmp;
struct ifi_info *ifi;
for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next) {
name1=inet_ntoa(((struct sockaddr_in *)ifi->ifi_addr)->sin_addr);
name2=inet_ntoa(((struct sockaddr_in *)pcliaddr)->sin_addr);
name_tmp=inet_ntoa(((struct sockaddr_in *)ifi->ifi_addr)->sin_addr);
if((name1 = (char*)malloc(sizeof(char)*strlen(name_tmp)))==NULL)
perror("is_my_packet: problem in malloc");
strcpy(name1,name_tmp);
name_tmp=inet_ntoa(((struct sockaddr_in *)pcliaddr)->sin_addr);
if((name2 = (char*)malloc(sizeof(char)*strlen(name_tmp)))==NULL)
perror("is_my_packet: problem in malloc");
strcpy(name2,name_tmp);
//printf("name1:\"%s\" name2:\"%s\"\n",name1,name2);
if(strcmp(name1,name2)==0)
return 1;
......@@ -72,6 +80,22 @@ int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead)
return 0;
}
void
get_recvIFADDR(char *name,struct ifi_info * ifihead)
{
struct ifi_info * ifi=NULL;
for (ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next)
{
if(strcmp(name,ifi->ifi_name)==0)
//Will do this once know the conversion from MAC address to hostname
//-ik
//memcpy(&receivingIF,&(ifi->ifi_haddr),ETHADDRSIZ);
memcpy(&receivingIF,&myNodeID,ETHADDRSIZ);
}
}
/*
* Return 0 if the two inquiries are identical, non-zero if not.
*/
......@@ -116,7 +140,7 @@ print_ifi_info(struct ifi_info *ifihead)
void
serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
{
int flags, class;
int flags, class=NEW;
const int on = 1;
socklen_t len;
ssize_t n;
......@@ -141,7 +165,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
* is supported on FreeBSD. -lkw
*/
if (setsockopt(sockfd, IPPROTO_IP, IP_RECVIF, &on, sizeof(on)) < 0) {
printf("setsockopt of IP_RECVIF");
fprintf(stderr,"setsockopt of IP_RECVIF");
return;
}
......@@ -153,7 +177,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*/
//ik: get the list of interfaces using the function "get_ifi_info" into the
//link list "ifi"
//link list "ifi" and the max hardware address of all the i/fs is the Node ID
for (ifihead = ifi = get_ifi_info(AF_INET, 0);
ifi != NULL; ifi = ifi->ifi_next) {
if ( ifi->ifi_hlen > 0) {
......@@ -161,7 +185,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
}
}
memcpy(&myNodeID, myNodeIDtmp, ETHADDRSIZ);
printf("My node id:");
printf("My node id:");
print_nodeID(myNodeID);
print_ifi_info(ifihead);
......@@ -173,7 +197,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*/
i=0;
for ( ; ; ) {
printf("**********for==>%d\n",i++);
//printf("**********for==>%d\n",i++);
len = clilen;
flags = 0;
n = recvfrom_flags(sockfd, mesg, MAXLINE, &flags,
......@@ -208,6 +232,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*
* We now classify each inquiry.
*/
ifihead = get_ifi_info(AF_INET, 0);
if(inqhead==NULL) class = NEW;
j=0;
......@@ -243,14 +268,22 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
/*
* Save the inquiry ID into inqid_current.
*/
get_recvIFADDR(if_indextoname(pktinfo.ipi_ifindex, ifname),ifihead);
//printf(">>>>>>>The receiving interface is:");
//print_nodeID(receivingIF);
memcpy(&inqid_current, mesg, sizeof(topd_inqid_t));
/* Send string to all interfaces. forward_request() will
* stuff reply into ifi_info.
*/
ifihead = get_ifi_info(AF_INET, 0);
//ifihead = get_ifi_info(AF_INET, 0);
temp_inqid = (struct topd_inqid *)mesg;
memcpy(&parent_nodeIF, &(temp_inqid->tdi_p_nodeIF), ETHADDRSIZ);
//printf("Parents interface:");
//print_nodeID(parent_nodeIF);
t_int = ntohs(temp_inqid->tdi_ttl);
if(t_int==0)
printf("The TTL is zero so i will not forward!!\n");
......@@ -273,8 +306,8 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
//temp->tdi_ttl = htons(t_int);
ifihead=forward_request(ifihead, &pktinfo, mesg, n );
printf("printing after forward===>\n");
print_tdifinbrs(ifihead);
//printf("printing after forward===>\n");
//print_tdifinbrs(ifihead);
}
......@@ -288,7 +321,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
printf("done!\n");
free_ifi_info(ifihead);
printf("I am sending the response to: %s\n",sock_ntop(pcliaddr,sizeof(struct sockaddr)));
printf("Sending response to: %s\n",sock_ntop(pcliaddr,sizeof(struct sockaddr)));
/* send response back to original sender */
sendto(sockfd, reply, n, 0, pcliaddr, sizeof(struct sockaddr));
}
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: util.c,v 1.4 2001-06-18 01:41:19 ikumar Exp $
* $Id: util.c,v 1.5 2001-07-19 19:55:57 ikumar Exp $
*/
#include "discvr.h"
......@@ -175,6 +175,8 @@ print_tdinq(const char *mesg)
ntohs(tip->tdi_ttl),
ntohs(tip->tdi_factor));
print_nodeID(tip->tdi_nodeID);
printf(" PARENT i/f:");
print_nodeID(tip->tdi_p_nodeIF);
}
u_char *max_haddr(u_char *ha1, u_char *ha2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment