# /* timetest.c */ /* EMACS_MODES: c !fill */ /* Test times for network read/write */ #include #include "params.h" #include "ip.h" #include "netdefs.h" #include "icmp.h" #define DATASIZ 10 char sendbuf[6 + 32 + DATASIZ]; /* 32 = sizeof (struct ip) */ char recvbuf[6 + 32 + DATASIZ]; long cumstime; /* cum send time in ms */ long cumrtime; /* cum recv time in ms */ long cumrstime; /* cum success recv time in ms */ long cumrftime; /* cum failure recv time in ms */ long cumsend; /* no. of sends */ long cumrecv; /* no. of recvs */ long cumsrecv; /* no. of successful recvs */ long cumfrecv; /* no. of failure recvs */ long sstime; long sftime; long rstime; long rftime; int net; /* net fd */ struct netdf ndf = { /* net descriptor */ MITINET, 63, /* local net test protocol */ {0,0,0,0,}, /* any foreign host */ 0, /* any socket */ 0, /* any local socket */ }; struct in_name myhost = { 022,012,0,010 }; struct in_name in_addr0 = { 0,0,0,0 }; extern int finish (); extern unshort swab (); main () { reg int res; int sstvec[3]; int sftvec[3]; int rstvec[3]; int rftvec[3]; if ((net = netopen (NETDEV, &ndf)) < 0) { printf ("can't open net\n"); exit (1); } signal (SIGINT, finish); signal (SIGAIO, SIG_IGN); makeinet (); /* set up send packet */ for (;;) { /* loop til signal */ qtime (sstvec); /* time send */ res = write (net, sendbuf, sizeof (sendbuf)); qtime (sftvec); sstime = tvec_to_ut(sstvec); sftime = tvec_to_ut(sftvec); printf ("Send from %D to %D\n", sstime, sftime); cumstime += (sftime - sstime); cumsend++; do { qtime (rstvec); /* time each receive */ res = read (net, recvbuf, sizeof (recvbuf)); qtime (rftvec); rstime = tvec_to_ut(rstvec); rftime = tvec_to_ut(rftvec); if (res != 0) { printf ("Successful receive from %D to %D\n", rstime, rftime); cumrstime += (rftime - rstime); cumsrecv++; } else { printf ("Failed receive from %D to %D\n", rstime, rftime); cumrftime += (rftime - rstime); cumfrecv++; } cumrtime += (rftime - rstime); cumrecv++; } while (res != 0); } } makeinet () /* Fill in the internet header on the sendbuffer */ { reg struct ip *pip; pip = (struct ip *)(sendbuf + 6); pip->ip_ihl = IP_IHL; /* yep, do it */ pip->ip_ver = IP_VER; pip->ip_tsrv = IP_TSRV; pip->ip_len = DATASIZ + IPHSIZ; pip->ip_foff = 0; /* %%TBC%% no fragmentation yet */ pip->ip_flgs = 0; /* %%TBC%% no fragmentation yet */ pip->ip_time = IP_TIME; pip->ip_prot = 63; inn_copy (&myhost, &pip->ip_dest); ipswab (pip); /* if needed, swap integer fields */ pip->ip_id = 0; /* regardless, get new inet id */ pip->ip_chksum = CHKSUM; inn_copy (&in_addr0, &pip->ip_src); } finish () /* Finish up and print net stats */ { close (net); printf ("\n Cum time Total Avg time\n"); printf ("Send %D %D %D\n", cumstime, cumsend, (cumstime / cumsend)); printf ("Recv %D %D %D\n", cumrtime, cumrecv, (cumrtime / cumrecv)); printf ("Succ recv %D %D %D\n", cumrstime, cumsrecv, (cumrstime / cumsrecv)); printf ("Fail recv %D %D %D\n", cumrftime, cumfrecv, (cumrftime / cumfrecv)); exit (0); } ipswab( ppkt ) /* * Swap bytes in integer fields (except sumcheck fields) * of internet packet. */ struct ip *ppkt; /* ptr. to internet hdr. of pkt */ { static int swabds[] = { &0->ip_len, &0->ip_id, (&0->ip_id) + 1, }; swaba( (char *)ppkt, swabds, (sizeof(swabds)/sizeof(swabds[0]))); return; } inn_copy (p1, p2) /* Copy the internet name pointed to by p1 to the space pointed to * by p2. */ reg struct in_name *p1; reg struct in_name *p2; { p2->in_net = p1->in_net; p2->in_hhost = p1->in_hhost; p2->in_mhost = p1->in_mhost; p2->in_lhost = p1->in_lhost; }