[c87143a] | 1 | /* |
---|
| 2 | * A collection of hacks, glue, and patches to |
---|
| 3 | * provide a `UNIX-like' environment to ttcp. |
---|
| 4 | * |
---|
[0c9330e] | 5 | * Some of the code here may migrate to the libc |
---|
[c87143a] | 6 | * support routines some day. Some of the more sleazy |
---|
| 7 | * hacks should never make it outside this file! |
---|
| 8 | * |
---|
| 9 | * This program may be distributed and used for any purpose. |
---|
| 10 | * I ask only that you: |
---|
| 11 | * 1. Leave this author information intact. |
---|
| 12 | * 2. Document any changes you make. |
---|
| 13 | * |
---|
| 14 | * W. Eric Norum |
---|
| 15 | * Saskatchewan Accelerator Laboratory |
---|
| 16 | * University of Saskatchewan |
---|
| 17 | * Saskatoon, Saskatchewan, CANADA |
---|
| 18 | * eric@skatter.usask.ca |
---|
[7ba2ac5] | 19 | * |
---|
| 20 | * $Id$ |
---|
[c87143a] | 21 | */ |
---|
| 22 | |
---|
| 23 | #include <stdio.h> |
---|
[2b13801] | 24 | #include <string.h> |
---|
[0c9330e] | 25 | #include <ctype.h> |
---|
[c87143a] | 26 | #include <rtems.h> |
---|
[0c9330e] | 27 | #include <rtems/rtems_bsdnet.h> |
---|
[c87143a] | 28 | #include <rtems/error.h> |
---|
[0c9330e] | 29 | #include <sys/types.h> |
---|
| 30 | #include <sys/socket.h> |
---|
| 31 | #include <netinet/in.h> |
---|
| 32 | #include <netdb.h> |
---|
[c87143a] | 33 | #include <sys/time.h> |
---|
| 34 | |
---|
| 35 | /* |
---|
| 36 | * Glue between UNIX-style ttcp code and RTEMS |
---|
| 37 | */ |
---|
| 38 | int rtems_ttcp_main (int argc, char **argv); |
---|
| 39 | |
---|
| 40 | static int |
---|
| 41 | select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) |
---|
| 42 | { |
---|
| 43 | rtems_panic ("select()"); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | static void |
---|
| 47 | (*signal(int sig, void (*func)()))() |
---|
| 48 | { |
---|
| 49 | return 0;; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | int |
---|
| 53 | gettimeofday (struct timeval *tp, struct timezone *tzp) |
---|
| 54 | { |
---|
| 55 | rtems_clock_time_value now; |
---|
| 56 | |
---|
| 57 | rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now); |
---|
| 58 | tp->tv_sec = now.seconds; |
---|
| 59 | tp->tv_usec = now.microseconds; |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | #define _SYS_RESOURCE_H_ |
---|
| 64 | #define RUSAGE_SELF 0 /* calling process */ |
---|
| 65 | #define RUSAGE_CHILDREN -1 /* terminated child processes */ |
---|
| 66 | struct rusage { |
---|
| 67 | struct timeval ru_utime; /* user time used */ |
---|
| 68 | struct timeval ru_stime; /* system time used */ |
---|
| 69 | int ru_maxrss; /* maximum resident set size */ |
---|
| 70 | int ru_ixrss; /* currently 0 */ |
---|
| 71 | int ru_idrss; /* integral resident set size */ |
---|
| 72 | int ru_isrss; /* currently 0 */ |
---|
| 73 | int ru_minflt; /* page faults not requiring physical I/O */ |
---|
| 74 | int ru_majflt; /* page faults requiring physical I/O */ |
---|
| 75 | int ru_nswap; /* swaps */ |
---|
| 76 | int ru_inblock; /* block input operations */ |
---|
| 77 | int ru_oublock; /* block output operations */ |
---|
| 78 | int ru_msgsnd; /* messages sent */ |
---|
| 79 | int ru_msgrcv; /* messages received */ |
---|
| 80 | int ru_nsignals; /* signals received */ |
---|
| 81 | int ru_nvcsw; /* voluntary context switches */ |
---|
| 82 | int ru_nivcsw; /* involuntary context switches */ |
---|
| 83 | }; |
---|
| 84 | int |
---|
| 85 | getrusage(int ignored, struct rusage *ru) |
---|
| 86 | { |
---|
| 87 | rtems_clock_time_value now; |
---|
| 88 | static struct rusage nullUsage; |
---|
| 89 | |
---|
| 90 | rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now); |
---|
| 91 | *ru = nullUsage; |
---|
| 92 | ru->ru_stime.tv_sec = now.seconds; |
---|
| 93 | ru->ru_stime.tv_usec = now.microseconds; |
---|
| 94 | ru->ru_utime.tv_sec = 0; |
---|
| 95 | ru->ru_utime.tv_usec = 0; |
---|
| 96 | return 0; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | static void |
---|
| 100 | rtems_ttcp_exit (int code) |
---|
| 101 | { |
---|
[2b13801] | 102 | rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) ); |
---|
[0c9330e] | 103 | rtems_bsdnet_show_mbuf_stats (); |
---|
| 104 | rtems_bsdnet_show_if_stats (); |
---|
| 105 | rtems_bsdnet_show_ip_stats (); |
---|
| 106 | rtems_bsdnet_show_tcp_stats (); |
---|
[c87143a] | 107 | exit (code); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /* |
---|
| 111 | * Task to run UNIX ttcp command |
---|
| 112 | */ |
---|
| 113 | char *__progname; |
---|
| 114 | static void |
---|
| 115 | ttcpTask (rtems_task_argument arg) |
---|
| 116 | { |
---|
| 117 | int code; |
---|
| 118 | int argc; |
---|
| 119 | char arg0[10]; |
---|
| 120 | char *argv[20]; |
---|
| 121 | char linebuf[200]; |
---|
| 122 | |
---|
| 123 | for (;;) { |
---|
| 124 | char *cp; |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Set up first argument |
---|
| 128 | */ |
---|
| 129 | argc = 1; |
---|
| 130 | strcpy (arg0, "ttcp"); |
---|
| 131 | argv[0] = __progname = arg0; |
---|
| 132 | |
---|
[0c9330e] | 133 | #if (defined (WRITE_TEST_ONLY)) |
---|
| 134 | strcpy (linebuf, "-s -t crux"); |
---|
| 135 | #elif (defined (READ_TEST_ONLY)) |
---|
| 136 | strcpy (linebuf, "-s -r"); |
---|
| 137 | #else |
---|
[c87143a] | 138 | /* |
---|
| 139 | * Read a line |
---|
| 140 | */ |
---|
| 141 | printf (">>> %s ", argv[0]); |
---|
| 142 | fflush (stdout); |
---|
| 143 | fgets (linebuf, sizeof linebuf, stdin); |
---|
[0c9330e] | 144 | #endif |
---|
[c87143a] | 145 | |
---|
| 146 | /* |
---|
| 147 | * Break line into arguments |
---|
| 148 | */ |
---|
| 149 | cp = linebuf; |
---|
| 150 | for (;;) { |
---|
| 151 | while (isspace (*cp)) |
---|
| 152 | *cp++ = '\0'; |
---|
| 153 | if (*cp == '\0') |
---|
| 154 | break; |
---|
| 155 | if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) { |
---|
| 156 | printf ("Too many arguments.\n"); |
---|
| 157 | argc = 0; |
---|
| 158 | break; |
---|
| 159 | } |
---|
| 160 | argv[argc++] = cp; |
---|
| 161 | while (!isspace (*cp)) { |
---|
| 162 | if (*cp == '\0') |
---|
| 163 | break; |
---|
| 164 | cp++; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | if (argc > 1) { |
---|
| 168 | argv[argc] = NULL; |
---|
| 169 | break; |
---|
| 170 | } |
---|
| 171 | printf ("You must give some arguments!\n"); |
---|
| 172 | printf ("At the very least, you must provide\n"); |
---|
| 173 | printf (" -r\n"); |
---|
| 174 | printf ("or\n"); |
---|
| 175 | printf (" -t destination.internet.address\n"); |
---|
| 176 | } |
---|
| 177 | code = rtems_ttcp_main (argc, argv); |
---|
| 178 | rtems_ttcp_exit (code); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /* |
---|
| 182 | * Test network throughput |
---|
| 183 | */ |
---|
| 184 | void |
---|
| 185 | test_network (void) |
---|
| 186 | { |
---|
| 187 | rtems_id tid; |
---|
| 188 | rtems_status_code sc; |
---|
| 189 | rtems_time_of_day now; |
---|
| 190 | rtems_task_priority my_priority; |
---|
| 191 | |
---|
| 192 | /* |
---|
| 193 | * Set up time-of-day clock |
---|
| 194 | */ |
---|
| 195 | now.year = 1997; |
---|
| 196 | now.month = 1; |
---|
| 197 | now.day = 1; |
---|
| 198 | now.hour = 0; |
---|
| 199 | now.minute = 0; |
---|
| 200 | now.second = 0; |
---|
| 201 | now.ticks = 0; |
---|
| 202 | sc = rtems_clock_set (&now); |
---|
| 203 | if (sc != RTEMS_SUCCESSFUL) { |
---|
| 204 | printf ("Can't set date/time; %s\n", rtems_status_text (sc)); |
---|
| 205 | return; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | /* |
---|
| 209 | * Spawn test task |
---|
| 210 | */ |
---|
| 211 | rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &my_priority); |
---|
| 212 | sc = rtems_task_create (rtems_build_name ('T', 'T', 'C', 'P'), |
---|
| 213 | my_priority, |
---|
| 214 | 32*1024, |
---|
| 215 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
| 216 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
| 217 | &tid); |
---|
| 218 | if (sc != RTEMS_SUCCESSFUL) { |
---|
| 219 | printf ("Can't create task; %s\n", rtems_status_text (sc)); |
---|
| 220 | return; |
---|
| 221 | } |
---|
| 222 | sc = rtems_task_start (tid, ttcpTask, 0); |
---|
| 223 | if (sc != RTEMS_SUCCESSFUL) { |
---|
| 224 | printf ("Can't start task; %s\n", rtems_status_text (sc)); |
---|
| 225 | return; |
---|
| 226 | } |
---|
[0c9330e] | 227 | rtems_task_suspend (RTEMS_SELF); |
---|
[c87143a] | 228 | } |
---|
| 229 | |
---|
| 230 | #define main rtems_ttcp_main |
---|
| 231 | #define exit(code) close(fd),rtems_ttcp_exit(code) |
---|
| 232 | #define read_timer rtems_read_timer |
---|
[2b13801] | 233 | #undef delay |
---|
[c87143a] | 234 | |
---|
| 235 | #include "ttcp_orig/ttcp.c" |
---|