source: network-demos/ttcp/rtems_ttcp.c @ d6b60f5

4.11network-demos-4-10-branchnetwork-demos-4-9-branch
Last change on this file since d6b60f5 was d6b60f5, checked in by Joel Sherrill <joel.sherrill@…>, on 09/25/07 at 16:09:21

2007-09-25 Joel Sherrill <joel.sherrill@…>

  • Makefile: Build native ttcp as side-effect of main build.
  • rtems_ttcp.c: Fix warning.
  • Property mode set to 100644
File size: 5.0 KB
Line 
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 <rtems/cpuuse.h>
30#include <sys/types.h>
31#include <sys/socket.h>
32#include <netinet/in.h>
33#include <netdb.h>
34#include <sys/time.h>
35#include <stdlib.h>
36#include <signal.h>
37
38/*
39 * Glue between UNIX-style ttcp code and RTEMS
40 */
41int rtems_ttcp_main (int argc, char **argv);
42
43static int
44select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
45{
46  rtems_panic ("select()");
47  return 0;
48}
49
50#define _SYS_RESOURCE_H_
51#define RUSAGE_SELF     0               /* calling process */
52#define RUSAGE_CHILDREN -1              /* terminated child processes */
53struct rusage {
54        struct timeval ru_utime;        /* user time used */
55        struct timeval ru_stime;        /* system time used */
56        int ru_maxrss;          /* maximum resident set size */
57        int ru_ixrss;           /* currently 0 */
58        int ru_idrss;           /* integral resident set size */
59        int ru_isrss;           /* currently 0 */
60        int ru_minflt;          /* page faults not requiring physical I/O */
61        int ru_majflt;          /* page faults requiring physical I/O */
62        int ru_nswap;           /* swaps */
63        int ru_inblock;         /* block input operations */
64        int ru_oublock;         /* block output operations */
65        int ru_msgsnd;          /* messages sent */
66        int ru_msgrcv;          /* messages received */
67        int ru_nsignals;        /* signals received */
68        int ru_nvcsw;           /* voluntary context switches */
69        int ru_nivcsw;          /* involuntary context switches */
70};
71int
72getrusage(int ignored, struct rusage *ru)
73{
74        rtems_clock_time_value now;
75        static struct rusage nullUsage;
76
77        rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now);
78        *ru = nullUsage;
79        ru->ru_stime.tv_sec  = now.seconds;
80        ru->ru_stime.tv_usec = now.microseconds;
81        ru->ru_utime.tv_sec  = 0;
82        ru->ru_utime.tv_usec = 0;
83        return 0;
84}
85
86static void
87rtems_ttcp_exit (int code)
88{
89        rtems_cpu_usage_report();
90        rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) );
91        rtems_bsdnet_show_mbuf_stats ();
92        rtems_bsdnet_show_if_stats ();
93        rtems_bsdnet_show_ip_stats ();
94        rtems_bsdnet_show_tcp_stats ();
95        exit (code);
96}
97
98/*
99 * Task to run UNIX ttcp command
100 */
101char *__progname;
102static void
103ttcpTask (rtems_task_argument arg)
104{
105        int code;
106        int argc;
107        char arg0[10];
108        char *argv[20];
109        char linebuf[200];
110
111        for (;;) {
112                char *cp;
113
114                /*
115                 * Set up first argument
116                 */
117                argc = 1;
118                strcpy (arg0, "ttcp");
119                argv[0] = __progname = arg0;
120
121#if (defined (WRITE_TEST_ONLY))
122                strcpy (linebuf, "-s -t crux");
123#elif (defined (READ_TEST_ONLY))
124                strcpy (linebuf, "-s -r");
125#else
126                /*
127                 * Read a line
128                 */
129                printf (">>> %s ", argv[0]);
130                fflush (stdout);
131                fgets (linebuf, sizeof linebuf, stdin);
132#endif
133
134                /*
135                 * Break line into arguments
136                 */
137                cp = linebuf;
138                for (;;) {
139                        while (isspace (*cp))
140                                *cp++ = '\0';
141                        if (*cp == '\0')
142                                break;
143                        if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) {
144                                printf ("Too many arguments.\n");
145                                argc = 0;
146                                break;
147                        }
148                        argv[argc++] = cp;
149                        while (!isspace (*cp)) {
150                                if (*cp == '\0')
151                                        break;
152                                cp++;
153                        }
154                }
155                if (argc > 1) {
156                        argv[argc] = NULL;
157                        break;
158                }
159                printf ("You must give some arguments!\n");
160                printf ("At the very least, you must provide\n");
161                printf ("         -r\n");
162                printf ("or\n");
163                printf ("         -t destination.internet.address\n");
164        }
165        rtems_cpu_usage_reset();
166        code = rtems_ttcp_main (argc, argv);
167        rtems_ttcp_exit (code);
168}
169
170/*
171 * Test network throughput
172 */
173void
174test_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"
Note: See TracBrowser for help on using the repository browser.