1 | /* |
---|
2 | * A collection of hacks, glue, and patches to |
---|
3 | * provide a `UNIX-like' environment to ttcp. |
---|
4 | * |
---|
5 | * Some of the code here may migrate to the libc |
---|
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 |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | |
---|
23 | #include <stdio.h> |
---|
24 | #include <string.h> |
---|
25 | #include <ctype.h> |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/rtems_bsdnet.h> |
---|
28 | #include <rtems/error.h> |
---|
29 | #include <sys/types.h> |
---|
30 | #include <sys/socket.h> |
---|
31 | #include <netinet/in.h> |
---|
32 | #include <netdb.h> |
---|
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 | #define _SYS_RESOURCE_H_ |
---|
53 | #define RUSAGE_SELF 0 /* calling process */ |
---|
54 | #define RUSAGE_CHILDREN -1 /* terminated child processes */ |
---|
55 | struct rusage { |
---|
56 | struct timeval ru_utime; /* user time used */ |
---|
57 | struct timeval ru_stime; /* system time used */ |
---|
58 | int ru_maxrss; /* maximum resident set size */ |
---|
59 | int ru_ixrss; /* currently 0 */ |
---|
60 | int ru_idrss; /* integral resident set size */ |
---|
61 | int ru_isrss; /* currently 0 */ |
---|
62 | int ru_minflt; /* page faults not requiring physical I/O */ |
---|
63 | int ru_majflt; /* page faults requiring physical I/O */ |
---|
64 | int ru_nswap; /* swaps */ |
---|
65 | int ru_inblock; /* block input operations */ |
---|
66 | int ru_oublock; /* block output operations */ |
---|
67 | int ru_msgsnd; /* messages sent */ |
---|
68 | int ru_msgrcv; /* messages received */ |
---|
69 | int ru_nsignals; /* signals received */ |
---|
70 | int ru_nvcsw; /* voluntary context switches */ |
---|
71 | int ru_nivcsw; /* involuntary context switches */ |
---|
72 | }; |
---|
73 | int |
---|
74 | getrusage(int ignored, struct rusage *ru) |
---|
75 | { |
---|
76 | rtems_clock_time_value now; |
---|
77 | static struct rusage nullUsage; |
---|
78 | |
---|
79 | rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now); |
---|
80 | *ru = nullUsage; |
---|
81 | ru->ru_stime.tv_sec = now.seconds; |
---|
82 | ru->ru_stime.tv_usec = now.microseconds; |
---|
83 | ru->ru_utime.tv_sec = 0; |
---|
84 | ru->ru_utime.tv_usec = 0; |
---|
85 | return 0; |
---|
86 | } |
---|
87 | |
---|
88 | static void |
---|
89 | rtems_ttcp_exit (int code) |
---|
90 | { |
---|
91 | rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) ); |
---|
92 | rtems_bsdnet_show_mbuf_stats (); |
---|
93 | rtems_bsdnet_show_if_stats (); |
---|
94 | rtems_bsdnet_show_ip_stats (); |
---|
95 | rtems_bsdnet_show_tcp_stats (); |
---|
96 | exit (code); |
---|
97 | } |
---|
98 | |
---|
99 | /* |
---|
100 | * Task to run UNIX ttcp command |
---|
101 | */ |
---|
102 | char *__progname; |
---|
103 | static void |
---|
104 | ttcpTask (rtems_task_argument arg) |
---|
105 | { |
---|
106 | int code; |
---|
107 | int argc; |
---|
108 | char arg0[10]; |
---|
109 | char *argv[20]; |
---|
110 | char linebuf[200]; |
---|
111 | |
---|
112 | for (;;) { |
---|
113 | char *cp; |
---|
114 | |
---|
115 | /* |
---|
116 | * Set up first argument |
---|
117 | */ |
---|
118 | argc = 1; |
---|
119 | strcpy (arg0, "ttcp"); |
---|
120 | argv[0] = __progname = arg0; |
---|
121 | |
---|
122 | #if (defined (WRITE_TEST_ONLY)) |
---|
123 | strcpy (linebuf, "-s -t crux"); |
---|
124 | #elif (defined (READ_TEST_ONLY)) |
---|
125 | strcpy (linebuf, "-s -r"); |
---|
126 | #else |
---|
127 | /* |
---|
128 | * Read a line |
---|
129 | */ |
---|
130 | printf (">>> %s ", argv[0]); |
---|
131 | fflush (stdout); |
---|
132 | fgets (linebuf, sizeof linebuf, stdin); |
---|
133 | #endif |
---|
134 | |
---|
135 | /* |
---|
136 | * Break line into arguments |
---|
137 | */ |
---|
138 | cp = linebuf; |
---|
139 | for (;;) { |
---|
140 | while (isspace (*cp)) |
---|
141 | *cp++ = '\0'; |
---|
142 | if (*cp == '\0') |
---|
143 | break; |
---|
144 | if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) { |
---|
145 | printf ("Too many arguments.\n"); |
---|
146 | argc = 0; |
---|
147 | break; |
---|
148 | } |
---|
149 | argv[argc++] = cp; |
---|
150 | while (!isspace (*cp)) { |
---|
151 | if (*cp == '\0') |
---|
152 | break; |
---|
153 | cp++; |
---|
154 | } |
---|
155 | } |
---|
156 | if (argc > 1) { |
---|
157 | argv[argc] = NULL; |
---|
158 | break; |
---|
159 | } |
---|
160 | printf ("You must give some arguments!\n"); |
---|
161 | printf ("At the very least, you must provide\n"); |
---|
162 | printf (" -r\n"); |
---|
163 | printf ("or\n"); |
---|
164 | printf (" -t destination.internet.address\n"); |
---|
165 | } |
---|
166 | code = rtems_ttcp_main (argc, argv); |
---|
167 | rtems_ttcp_exit (code); |
---|
168 | } |
---|
169 | |
---|
170 | /* |
---|
171 | * Test network throughput |
---|
172 | */ |
---|
173 | void |
---|
174 | test_network (void) |
---|
175 | { |
---|
176 | rtems_id tid; |
---|
177 | rtems_status_code sc; |
---|
178 | rtems_time_of_day now; |
---|
179 | rtems_task_priority my_priority; |
---|
180 | |
---|
181 | /* |
---|
182 | * Set up time-of-day clock |
---|
183 | */ |
---|
184 | now.year = 1997; |
---|
185 | now.month = 1; |
---|
186 | now.day = 1; |
---|
187 | now.hour = 0; |
---|
188 | now.minute = 0; |
---|
189 | now.second = 0; |
---|
190 | now.ticks = 0; |
---|
191 | sc = rtems_clock_set (&now); |
---|
192 | if (sc != RTEMS_SUCCESSFUL) { |
---|
193 | printf ("Can't set date/time; %s\n", rtems_status_text (sc)); |
---|
194 | return; |
---|
195 | } |
---|
196 | |
---|
197 | /* |
---|
198 | * Spawn test task |
---|
199 | */ |
---|
200 | rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &my_priority); |
---|
201 | sc = rtems_task_create (rtems_build_name ('T', 'T', 'C', 'P'), |
---|
202 | my_priority, |
---|
203 | 32*1024, |
---|
204 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
205 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
206 | &tid); |
---|
207 | if (sc != RTEMS_SUCCESSFUL) { |
---|
208 | printf ("Can't create task; %s\n", rtems_status_text (sc)); |
---|
209 | return; |
---|
210 | } |
---|
211 | sc = rtems_task_start (tid, ttcpTask, 0); |
---|
212 | if (sc != RTEMS_SUCCESSFUL) { |
---|
213 | printf ("Can't start task; %s\n", rtems_status_text (sc)); |
---|
214 | return; |
---|
215 | } |
---|
216 | rtems_task_suspend (RTEMS_SELF); |
---|
217 | } |
---|
218 | |
---|
219 | #define main rtems_ttcp_main |
---|
220 | #define exit(code) close(fd),rtems_ttcp_exit(code) |
---|
221 | |
---|
222 | #include "ttcp_orig/ttcp.c" |
---|