Commit 9038d373 authored by Kristin Wright's avatar Kristin Wright

added ttl and factor

parent 706e912f
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: cli.c,v 1.1 2000-07-06 17:42:35 kwright Exp $
* $Id: cli.c,v 1.2 2000-07-13 18:52:51 kwright Exp $
*/
#include "discvr.h"
......@@ -81,7 +81,7 @@ find_nodeID(void)
}
void
make_inquiry(topd_inqid_t *tip)
make_inquiry(topd_inqid_t *tip, u_int16_t ttl, u_int16_t factor)
{
struct timeval tv;
u_char *nid;
......@@ -92,37 +92,47 @@ make_inquiry(topd_inqid_t *tip)
exit(1);
}
tip->tdi_tv.tv_sec = htonl(tv.tv_sec);
tip->tdi_tv.tv_sec = htonl(tv.tv_sec);
tip->tdi_tv.tv_usec = htonl(tv.tv_usec);
/* ...then the ttl and factor... */
tip->tdi_ttl = htons(ttl);
tip->tdi_factor = htons(factor);
/* ...and now our nodeID */
nid = find_nodeID();
memcpy((void *)tip->tdi_nodeID, nid, ETHADDRSIZ);
}
void
cli(FILE *fp, int sockfd, const struct sockaddr *pservaddr, socklen_t servlen)
cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen,
u_int16_t ttl, u_int16_t factor)
{
u_int32_t n;
char recvline[MAXLINE + 1];
topd_inqid_t ti;
make_inquiry(&ti);
make_inquiry(&ti, ttl, factor);
sendto(sockfd, &ti, TOPD_INQ_SIZ, 0, pservaddr, servlen);
print_tdinq((char *)&ti);
n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
print_tdreply(recvline);
print_tdreply(recvline, n);
}
/*
* Note that the TTL is a function of the network diameter that
* we're interested in. The factor parameter is a function of the
* network topology and performance.
*/
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2) {
fprintf(stderr, "usage: cli <Server IPaddress>\n");
if (argc != 4) {
fprintf(stderr, "usage: cli <Server IPaddress> <TTL> <factor>\n");
exit(1);
}
......@@ -133,7 +143,7 @@ main(int argc, char **argv)
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
cli(stdin, sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
cli(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr), atoi(argv[2]), atoi(argv[3]));
exit(0);
}
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: forw_requests.c,v 1.2 2000-07-06 22:53:55 kwright Exp $
* $Id: forw_requests.c,v 1.3 2000-07-13 18:52:51 kwright Exp $
*/
#include "discvr.h"
......@@ -38,6 +38,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
fd_set rset;
const int on = 1;
char ifname[IFNAMSIZ];
struct topd_inqid *tdi;
struct topd_nborlist *save;
struct sockaddr_in sin;
struct ifi_info *ifihead;
......@@ -109,11 +110,15 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* Can't wait forever because
* there may be either no nodes on this interface or
* the nodes that are there may not be responding.
* Also, the packet size *might* exceed our buffer size.
* Our wait delay is equal to the factor times the ttl.
*
* The packet size *might* exceed our buffer size.
* Put in some mechanism to check. -lkw
*/
tv.tv_sec = 5;
tdi = (struct topd_inqid *)mesg;
tv.tv_sec = ntohs(tdi->tdi_ttl) * ntohs(tdi->tdi_factor);
fprintf(stderr, "tv.tv_sec: %d", tv.tv_sec);
tv.tv_usec = 0;
FD_ZERO(&rset);
FD_SET(s, &rset);
......@@ -126,23 +131,34 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
continue;
}
n = recvfrom(s, recvbuf, BUFSIZ, 0, NULL, NULL);
/*
* Be sure to malloc enough space for all of the mesg.
* See note above about possible datagram truncation. -lkw
*/
save = ifi->ifi_nbors;
if ( (ifi->ifi_nbors = (struct topd_nborlist *)malloc(sizeof(struct topd_nborlist))) == NULL) {
perror("Not enough memory for neighbor list.");
exit(1);
}
if (( ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n)) == NULL) {
perror("Not enough memory for neighbor list.");
exit(1);
}
while ( (n = recvfrom(s, recvbuf, BUFSIZ, 0, NULL, NULL)) > 0 ) {
memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf, n);
ifi->ifi_nbors->tdnbl_next = save;
/*
* It's possible that one neighbor responded very quickly
* and other neighbors (perhaps because they have many more
* neighbors whose messages they had to parse) could respond
* slowly. To cover this case, we should continue to try to
* read from the socket until our delay is up.
*/
/*
* Be sure to malloc enough space for all of the mesg.
* See note above about possible datagram truncation. -lkw
*/
save = ifi->ifi_nbors;
ifi->ifi_nbors = (struct topd_nborlist *)malloc(sizeof(struct topd_nborlist));
if ( ifi->ifi_nbors == NULL ) {
perror("Not enough memory for neighbor list.");
exit(1);
}
/* skip inquiry ID */
ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n);
if ( ifi->ifi_nbors->tdnbl_nbors == NULL ) {
perror("Not enough memory for neighbor list.");
exit(1);
}
memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf + sizeof(topd_inqid_t), n);
ifi->ifi_nbors->tdnbl_n = n / sizeof(struct topd_nbor);
ifi->ifi_nbors->tdnbl_next = save;
}
}
}
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: reply.c,v 1.2 2000-07-06 22:51:47 kwright Exp $
* $Id: reply.c,v 1.3 2000-07-13 18:52:51 kwright Exp $
*/
......@@ -36,9 +36,11 @@ extern topd_inqid_t inqid_current;
u_int32_t
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen)
{
struct ifi_info *ifihead;
char *nw;
char *nid;
struct topd_nborlist *nborl;
struct ifi_info *ifihead;
char *nw;
char *nid;
struct topd_nbor *nbor;
nw = (u_char *) mesg;
......@@ -47,37 +49,43 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen)
nw += sizeof(topd_inqid_t);
for (ifihead = ifi; ifi != NULL; ifi = ifi->ifi_next) {
nborl = ifi->ifi_nbors;
/* Add check for control net -LKW */
if (ifi->ifi_flags & !IFF_UP ||
ifi->ifi_flags & IFF_LOOPBACK) {
continue;
}
if (ifi->ifi_nbors == NULL) {
/*
* There are no neighbors on this interface.
* We need only report this interface as a
* dead end. That is, we put down the pair
* [ <myNodeID, ifi->haddr>, <0,0> ]
* for the [path, nbor] pair.
*/
nid = nw;
nw += ETHADDRSIZ << 2; /* we're writing 4 nodeids */
/* We report this interface.
* That is, we put down the pair
* [ <myNodeID, ifi->haddr>, <0,0> ]
* for the [path, nbor] pair.
*/
nid = nw;
nw += ETHADDRSIZ << 2; /* we're writing 4 nodeids */
if ((char *)nw > mesg + mesglen ) {
fprintf(stderr, "ran out of room and you didn't do anything reasonable.\n");
return 0;
}
memcpy(nid, myNodeID, ETHADDRSIZ);
nid += ETHADDRSIZ;
memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
fprintf(stderr, "\there:");
print_haddr(ifi->ifi_haddr, ETHADDRSIZ);
nid += ETHADDRSIZ;
bzero(nid, ETHADDRSIZ << 1);
while ( nborl != NULL ) {
nbor = (struct topd_nbor *)nw;
nw += nborl->tdnbl_n * sizeof(struct topd_nbor);
if ((char *)nw > mesg + mesglen ) {
fprintf(stderr, "ran out of room and you didn't do anything reasonable.\n");
return 0;
return 0;
}
memcpy(nid, myNodeID, ETHADDRSIZ);
nid += ETHADDRSIZ;
memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
fprintf(stderr, "\there:");
print_haddr(ifi->ifi_haddr, ETHADDRSIZ);
nid += ETHADDRSIZ;
bzero(nid, ETHADDRSIZ << 1);
continue;
} else {
/* We have neighbors */
}
memcpy(nbor, nborl->tdnbl_nbors, nborl->tdnbl_n * sizeof(struct topd_nbor));
nborl = nborl->tdnbl_next;
}
}
return (nw - mesg);
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: serv_listen.c,v 1.2 2000-07-06 22:52:36 kwright Exp $
* $Id: serv_listen.c,v 1.3 2000-07-13 18:52:52 kwright Exp $
*/
#include "discvr.h"
......@@ -138,8 +138,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
/* Send string to all interfaces. forward_request() will
* stuff reply into ifi_info.
*/
forward_request(ifihead, &pktinfo, mesg, n );
if ( (reply=(char *)malloc(BUFSIZ)) == NULL) {
......@@ -148,7 +147,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
}
n = compose_reply(ifihead, reply, BUFSIZ);
fprintf(stderr, "replying: ");
print_tdreply(reply);
print_tdreply(reply, n);
/* send response back to original sender */
sendto(sockfd, reply, n, 0, pcliaddr, sizeof(struct sockaddr));
......
......@@ -18,7 +18,7 @@
*
* ---------------------------
*
* $Id: util.c,v 1.1 2000-07-06 17:42:39 kwright Exp $
* $Id: util.c,v 1.2 2000-07-13 18:52:52 kwright Exp $
*/
#include "discvr.h"
......@@ -49,7 +49,7 @@ print_haddr(u_char *haddr, u_short hlen)
if ((i = hlen) > 0) {
ptr = haddr;
do {
fprintf(stderr, "%s%x", (i == hlen) ? "" : ":", *ptr++);
fprintf(stderr, "%s%x", (i == hlen) ? "" : ":", *ptr++);
} while (--i > 0);
}
}
......@@ -57,42 +57,46 @@ print_haddr(u_char *haddr, u_short hlen)
/*
* Print a td reply packet. They are of the form
*
* [Inquiry ID],
* [Path, Dest]
* [Path, Dest]
* [Inquiry ID ]
* [TTL, Factor]
* [Path, Dest ]
* [Path, Dest ]
* [...]
*
* Inquiry IDs consist of a node ID and a
* timestamp.
*
* The TTL and Factor are both unsigned 16-bit
* numbers derived from user parameters.
*
* Paths and destinations consist
* of <node ID, MAC address> pairs. Node IDs
* themselves are MAC addresses.
*/
void
print_tdreply(const char *mesg)
print_tdreply(const char *mesg, size_t nbytes)
{
const u_char *p, *p_node, *p_if, *d_node, *d_if;
struct topd_nbor *p;
print_tdinq(mesg);
p = (struct topd_nbor *) (mesg + sizeof(topd_inqid_t));
p = mesg + sizeof(topd_inqid_t);
p_node = &p[0];
p_if = &p[ETHADDRSIZ];
d_node = &p[ETHADDRSIZ << 1];
d_if = d_node + ETHADDRSIZ;
while( (char *)p < mesg + nbytes ) {
fprintf(stderr, "ROUTE\t\t\t\tDEST\n");
fprintf(stderr, "[");
print_haddr(p_node, ETHADDRSIZ);
fprintf(stderr, "-");
print_haddr(p_if, ETHADDRSIZ);
fprintf(stderr, "] ");
fprintf(stderr, "[");
print_haddr(d_node, ETHADDRSIZ);
fprintf(stderr, "-");
print_haddr(d_if, ETHADDRSIZ);
fprintf(stderr, "]\n\n");
fprintf(stderr, "ROUTE\t\t\t\tDEST\n");
fprintf(stderr, "[");
print_haddr(p->tdnbor_pnode, ETHADDRSIZ);
fprintf(stderr, "-");
print_haddr(p->tdnbor_pif, ETHADDRSIZ);
fprintf(stderr, "] ");
fprintf(stderr, "[");
print_haddr(p->tdnbor_dnode, ETHADDRSIZ);
fprintf(stderr, "-");
print_haddr(p->tdnbor_dif, ETHADDRSIZ);
fprintf(stderr, "]\n\n");
p++;
}
}
/*
......@@ -110,8 +114,11 @@ print_tdinq(const char *mesg)
{
topd_inqid_t *tip = (topd_inqid_t *)mesg;
fprintf(stderr, "\nINQ:%u.%u from node: ",
ntohl(tip->tdi_tv.tv_sec), ntohl(tip->tdi_tv.tv_usec));
fprintf(stderr, "\nINQ:%u.%u TTL:%d FACTOR:%d NODE:",
ntohl(tip->tdi_tv.tv_sec),
ntohl(tip->tdi_tv.tv_usec),
ntohs(tip->tdi_ttl),
ntohs(tip->tdi_factor));
print_nodeID(tip->tdi_nodeID);
}
......
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