summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-21 13:22:35 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-21 13:22:35 +0000
commit0c9330e967a2926a2424155c941904e7d4d5815f (patch)
treef245bdd9ac409389b1054bf0862028a1ba969be2
parentRemoved -- now provided by RTEMS (diff)
downloadnetwork-demos-0c9330e967a2926a2424155c941904e7d4d5815f.tar.bz2
KA9Q -> FreeBSD changes from Eric Norum
-rw-r--r--netdemo/Makefile10
-rw-r--r--netdemo/init.c123
-rw-r--r--netdemo/test.c117
-rw-r--r--tftpTest/Makefile4
-rw-r--r--tftpTest/init.c127
-rw-r--r--tftpTest/test.c57
-rw-r--r--ttcp/Makefile25
-rw-r--r--ttcp/README15
-rw-r--r--ttcp/init.c205
-rw-r--r--ttcp/rtems_ttcp.c82
10 files changed, 156 insertions, 609 deletions
diff --git a/netdemo/Makefile b/netdemo/Makefile
index fa6acbb..716d064 100644
--- a/netdemo/Makefile
+++ b/netdemo/Makefile
@@ -1,14 +1,10 @@
-#
-# $Id$
-#
-
SAMPLE=netdemo
PGM=${ARCH}/$(SAMPLE).exe
-MANAGERS=io message event semaphore timer rate_monotonic region
+MANAGERS=io event semaphore
# C source names, if any, go here -- minus the .c
-C_PIECES= init test
+C_PIECES= init test
C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
@@ -35,7 +31,7 @@ include $(PROJECT_ROOT)/make/leaf.cfg
DEFINES +=
CPPFLAGS +=
CFLAGS +=
-CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000 # KA9Q needs more space
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000
CFLAGS_OPTIMIZE_V +=
CFLAGS_DEBUG_V += -v -qrtems_debug
diff --git a/netdemo/init.c b/netdemo/init.c
index cb6437f..cba6e1a 100644
--- a/netdemo/init.c
+++ b/netdemo/init.c
@@ -11,16 +11,8 @@
* University of Saskatchewan
* Saskatoon, Saskatchewan, CANADA
* eric@skatter.usask.ca
- *
- * $Id$
- */
-
-/*
- * Include user provided information
*/
-#include "../usercfg.h"
-
#include <bsp.h>
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
@@ -30,13 +22,11 @@
#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
#define CONFIGURE_MAXIMUM_SEMAPHORES 20
#define CONFIGURE_MAXIMUM_TASKS 20
-#define CONFIGURE_MAXIMUM_TIMERS 10
-#define CONFIGURE_MAXIMUM_PERIODS 1
#define CONFIGURE_MICROSECONDS_PER_TICK 10486
#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
-#define CONFIGURE_INIT_TASK_PRIORITY 100
+#define CONFIGURE_INIT_TASK_PRIORITY 120
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
RTEMS_NO_TIMESLICE | \
RTEMS_NO_ASR | \
@@ -48,24 +38,8 @@ rtems_task Init (rtems_task_argument argument);
#include <confdefs.h>
#include <stdio.h>
-#include <rtems_ka9q.h>
-
-
-#if (defined (USE_BOOTP))
-#include <bootp.h>
-#endif
-
-/*
- * Suspend execution for the specified number of seconds
- */
-static void
-delay_task (int seconds)
-{
- rtems_interval ticksPerSecond;
-
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
- rtems_task_wake_after (seconds * ticksPerSecond);
-}
+#include <rtems/rtems_bsdnet.h>
+#include "../networkconfig.h"
/*
* RTEMS Startup Task
@@ -73,96 +47,9 @@ delay_task (int seconds)
rtems_task
Init (rtems_task_argument ignored)
{
- printf( "\n\n*** ETHERNET DEMO TEST ***\n" );
-
- /*
- * Start KA9Q
- */
- puts( "Starting KA9Q" );
- rtems_ka9q_start (50);
-
- /*
- * Hook up drivers
- */
- puts( "Attaching to the network" );
- if (rtems_ka9q_execute_command ("attach rtems broadcast y"
-#if !(defined (USE_BOOTP))
- " ip " MY_IP_ADDRESS
-#endif
- " ether " MY_ETHERNET_ADDRESS))
- rtems_panic ("Can't attach Ethernet driver.\n");
-
-#if (defined (TRACE_NETWORK_DRIVER))
- /*
- * Turn on debugging
- */
- puts( "Enabling debug mode of KA9Q" );
- if (rtems_ka9q_execute_command ("trace rtems input <stdout>")
- || rtems_ka9q_execute_command ("trace rtems output <stdout>")
- || rtems_ka9q_execute_command ("trace rtems ascii <stdout>"))
- rtems_panic ("Can't set tracing for Ethernet driver.\n");
-#endif
+ int doSocket(void);
- /*
- * Configure the driver
- */
- if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
- rtems_panic ("Can't configure Ethernet driver.\n");
-
- /*
- * Add the ethernet broadcast address to the ARP table.
- */
- if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
- rtems_panic ("Can't add broadcast entry to ARP table.\n");
-
-#if (defined (USE_BOOTP))
- {
- int i;
- /*
- * Get BOOTP information
- */
- for (i = 0 ; ; ) {
- if (rtems_ka9q_execute_command ("bootp") == 0)
- break;
- if (++i == 10)
- rtems_panic ("Can't get information from BOOTP server.\n");
- delay_task (i);
- }
- if (BootpFileName)
- printf ("BOOTP filename: `%s'\n", BootpFileName);
- else
- printf ("BOOTP -- No filename!\n");
- }
-#else
- if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
- rtems_panic ("Can't set netmask.\n");
- if (rtems_ka9q_execute_command ("route add default rtems"))
- rtems_panic ("Can't add default route.\n");
- printf ("Routing table after adding default route\n");
- rtems_ka9q_execute_command ("route");
-#endif
-
- /*
- * Issue a gratuitous ARP request to update tables in
- * other hosts on this network.
- */
- if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
- rtems_panic ("Can't send gratuitous ARP.\n");
-
- /*
- * Everything is now running
- */
- printf ("NETWORK INITIALIZED!\n");
-
- /*
- * See if sockets work properly
- */
+ rtems_bsdnet_initialize_network ();
doSocket ();
-
- /*
- * Wind things up
- */
- delay_task (2);
- rtems_ka9q_execute_command ("detach rtems");
exit (0);
}
diff --git a/netdemo/test.c b/netdemo/test.c
index b1ab46c..a58f7e1 100644
--- a/netdemo/test.c
+++ b/netdemo/test.c
@@ -1,5 +1,5 @@
/*
- * Test KA9Q networking
+ * Test RTEMS networking
*
* This program may be distributed and used for any purpose.
* I ask only that you:
@@ -11,46 +11,44 @@
* University of Saskatchewan
* Saskatoon, Saskatchewan, CANADA
* eric@skatter.usask.ca
- *
- * $Id$
*/
-
#include <stdio.h>
+#include <string.h>
+#include <errno.h>
#include <unistd.h>
#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
#include <rtems/error.h>
-#include <socket.h>
-#include <sockaddr.h>
-#include <netuser.h>
-#include <rtems_ka9q.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
-#include "../usercfg.h"
+#define NSERVER 2
+#define BASE_PORT 24742
-/*
- * Display the contents of several KA9Q tables
- */
-static void
-show_ka9q_tables (void)
+#define DATA_SINK_HOST ((128 << 24) | (233 << 16) | (14 << 8) | 60)
+
+void showbroad(int s)
+{
+ int opt;
+ int optlen = sizeof opt;
+
+ if (getsockopt (s, SOL_SOCKET, SO_BROADCAST, &opt, &optlen) < 0)
+ printf ("getsockopt failed: %s\n", strerror (errno));
+ printf ("Opt:%d Optlen:%d\n", opt, optlen);
+}
+
+static
+void
+showStatistics (void)
{
- printf ("\n****************** MALLOC Statistics ***************\n");
- malloc_dump ();
- printf ("\n****************** MBUF Statistics ***************\n");
- mbufstat ();
- mbufsizes ();
- printf ("\n****************** Routing Table ***************\n");
- rtems_ka9q_execute_command ("route");
- printf ("\n****************** ARP Table ***************\n");
- rtems_ka9q_execute_command ("arp");
- printf ("\n****************** Driver Statistics ***************\n");
- rtems_ka9q_execute_command ("ifconfig rtems");
- printf ("\n****************** Ip Statistics ***************\n");
- rtems_ka9q_execute_command ("ip status");
- printf ("\n****************** ICMP Statistics ***************\n");
- rtems_ka9q_execute_command ("icmp status");
- printf ("\n****************** UDP Statistics ***************\n");
- rtems_ka9q_execute_command ("udp status");
- printf ("\n****************** TCP Statistics ***************\n");
- rtems_ka9q_execute_command ("tcp status");
+ rtems_bsdnet_show_inet_routes ();
+ rtems_bsdnet_show_mbuf_stats ();
+ rtems_bsdnet_show_if_stats ();
+ rtems_bsdnet_show_ip_stats ();
+ rtems_bsdnet_show_icmp_stats ();
+ rtems_bsdnet_show_udp_stats ();
+ rtems_bsdnet_show_tcp_stats ();
}
/*
@@ -61,40 +59,54 @@ transmitUdp (void)
{
int s;
int i;
+ int opt;
static struct sockaddr_in myAddr, farAddr;
static char cbuf[800];
- static char bigbuf[20000];
+ static char bigbuf[9000];
printf ("Create socket.\n");
s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0)
rtems_panic ("Can't create socket: %s", strerror (errno));
myAddr.sin_family = AF_INET;
- myAddr.sin_port = 1234;
- myAddr.sin_addr.s_addr = INADDR_ANY;
+ myAddr.sin_port = htons (1234);
+ myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
printf ("Bind socket.\n");
if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
rtems_panic ("Can't bind socket: %s", strerror (errno));
farAddr.sin_family = AF_INET;
- farAddr.sin_port = 9; /* The `discard' port */
- farAddr.sin_addr.s_addr = 0xFFFFFFFF;
+ farAddr.sin_port = htons (9); /* The `discard' port */
+#if 1
+ farAddr.sin_addr.s_addr = htonl (0xFFFFFFFF);
+ if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) >= 0)
+ printf ("Broadcast succeeded, but should not have!\n");
+showbroad (s);
+ opt = 1;
+ if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, &opt, sizeof opt) < 0)
+ rtems_panic ("Can't set socket broadcast: %s", strerror (errno));
+showbroad (s);
for (i = 0 ; i < 5 ; i++) {
if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
rtems_panic ("Can't broadcast: %s", strerror (errno));
}
- farAddr.sin_addr.s_addr = aton (DATA_SINK_HOST);
+#endif
+ farAddr.sin_addr.s_addr = htonl (DATA_SINK_HOST);
+#if 1
for (i = 0 ; i < 500 ; i++) {
if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
rtems_panic ("Can't send: %s", strerror (errno));
if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
rtems_panic ("Can't send: %s", strerror (errno));
}
+#endif
+#if 1
for (i = 0 ; i < 2 ; i++) {
if (sendto (s, bigbuf, sizeof bigbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
rtems_panic ("Can't send: %s", strerror (errno));
if (sendto (s, bigbuf, sizeof bigbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
rtems_panic ("Can't send: %s", strerror (errno));
}
+#endif
close (s);
}
@@ -115,19 +127,21 @@ transmitTcp (void)
if (s < 0)
rtems_panic ("Can't create socket: %s", strerror (errno));
myAddr.sin_family = AF_INET;
- myAddr.sin_port = 1234;
- myAddr.sin_addr.s_addr = INADDR_ANY;
+ myAddr.sin_port = htons (1234);
+ myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
printf ("Bind socket.\n");
if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
rtems_panic ("Can't bind socket: %s", strerror (errno));
farAddr.sin_family = AF_INET;
- farAddr.sin_port = 9; /* The `discard' port */
- farAddr.sin_addr.s_addr = aton (DATA_SINK_HOST);
+ farAddr.sin_port = htons (9); /* The `discard' port */
+ farAddr.sin_addr.s_addr = htonl (DATA_SINK_HOST);
+ printf ("Connect socket.\n");
if (connect (s, (struct sockaddr *)&farAddr, sizeof farAddr) < 0) {
printf ("Can't connect socket: %s\n", strerror (errno));
close (s);
return;
}
+ printf ("Write to socket.\n");
for (i = 0 ; i < 500 ; i++) {
if (write (s, cbuf, sizeof cbuf) < 0)
rtems_panic ("Can't send: %s", strerror (errno));
@@ -154,9 +168,8 @@ echoTask (rtems_task_argument fd)
int n;
rtems_status_code sc;
- printf( "echoTask on %d\n", fd );
for (;;) {
-#if 0
+#if 1
n = read (fd, cbuf, sizeof cbuf);
#else
n = read (fd, cbuf, 1);
@@ -171,8 +184,6 @@ echoTask (rtems_task_argument fd)
printf ("Received: %d\n", n);
if (send (fd, cbuf, n, 0) < 0)
rtems_panic ("Error sending message: %s", strerror (errno));
- if (cbuf[0] == '\007')
- show_ka9q_tables ();
if (cbuf[0] == 'Q')
break;
}
@@ -198,7 +209,7 @@ echoServer (unsigned short port)
if (s < 0)
rtems_panic ("Can't create socket: %s", strerror (errno));
myAddr.sin_family = AF_INET;
- myAddr.sin_port = port;
+ myAddr.sin_port = htons (port);
myAddr.sin_addr.s_addr = INADDR_ANY;
memset (myAddr.sin_zero, '\0', sizeof myAddr.sin_zero);
printf ("Bind socket.\n");
@@ -214,7 +225,7 @@ echoServer (unsigned short port)
if (s1 < 0)
rtems_panic ("Can't accept connection: %s", strerror (errno));
else
- printf ("ACCEPTED:%lX\n", farAddr.sin_addr.s_addr);
+ printf ("ACCEPTED:%lX\n", ntohl (farAddr.sin_addr.s_addr));
/*
* Start an echo task
@@ -258,6 +269,7 @@ doSocket (void)
rtems_status_code sc;
rtems_task_priority my_priority;
+#if 1
/*
* Spawn other servers
*/
@@ -280,6 +292,7 @@ doSocket (void)
return;
}
}
+#endif
/*
* Wait for characters from console terminal
@@ -287,7 +300,6 @@ doSocket (void)
for (;;) {
switch (getchar ()) {
case '\004':
- printf( "Exiting test\n" );
return;
case 't':
@@ -305,10 +317,7 @@ doSocket (void)
break;
case 's':
- /*
- * Show what's been accomplished
- */
- show_ka9q_tables ();
+ showStatistics ();
break;
}
}
diff --git a/tftpTest/Makefile b/tftpTest/Makefile
index e9f7bdd..7750586 100644
--- a/tftpTest/Makefile
+++ b/tftpTest/Makefile
@@ -1,7 +1,7 @@
SAMPLE=tftp
PGM=${ARCH}/$(SAMPLE).exe
-MANAGERS=io event semaphore timer rate_monotonic
+MANAGERS=io event semaphore
# C source names, if any, go here -- minus the .c
C_PIECES= init test
@@ -31,7 +31,7 @@ include $(PROJECT_ROOT)/make/leaf.cfg
DEFINES +=
CPPFLAGS +=
CFLAGS +=
-CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0x40000 # KA9Q needs more space
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0x40000
CFLAGS_OPTIMIZE_V +=
CFLAGS_DEBUG_V += -qrtems_debug # -v
diff --git a/tftpTest/init.c b/tftpTest/init.c
index 569a03d..2ff7a67 100644
--- a/tftpTest/init.c
+++ b/tftpTest/init.c
@@ -1,10 +1,10 @@
/*
- * Test RTEMS/KA9Q TFTP device driver
- *
+ * RTEMS configuration/initialization
+ *
* This program may be distributed and used for any purpose.
* I ask only that you:
- * 1. Leave this author information intact.
- * 2. Document any changes you make.
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
*
* W. Eric Norum
* Saskatchewan Accelerator Laboratory
@@ -13,23 +13,26 @@
* eric@skatter.usask.ca
*/
-#include "../usercfg.h"
-
#include <bsp.h>
-#include <rtems/error.h>
-#include <tftp.h>
-#include <rtems_ka9q.h>
-#include <stdio.h>
+#include <rtems/tftp.h>
+#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
-#define CONFIGURE_EXECUTIVE_RAM_SIZE (128*1024)
-#define CONFIGURE_MAXIMUM_SEMAPHORES 10
-#define CONFIGURE_MAXIMUM_TIMERS 5
-#define CONFIGURE_MAXIMUM_PERIODS 1
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TASKS 20
#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY 100
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+ RTEMS_NO_TIMESLICE | \
+ RTEMS_NO_ASR | \
+ RTEMS_INTERRUPT_LEVEL(0))
+
#define CONFIGURE_INIT
rtems_task Init (rtems_task_argument argument);
@@ -42,10 +45,9 @@ rtems_driver_address_table Device_drivers[] = {
#include <confdefs.h>
-#if (defined (USE_BOOTP))
-#include <bootp.h>
-#endif
-extern void testTFTP (void);
+#include <stdio.h>
+#include <rtems/rtems_bsdnet.h>
+#include "../networkconfig.h"
/*
* RTEMS Startup Task
@@ -53,91 +55,18 @@ extern void testTFTP (void);
rtems_task
Init (rtems_task_argument ignored)
{
- int i;
- rtems_task_priority oldPri;
- rtems_interval ticksPerSecond;
-
- /*
- * Get some timing information
- */
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
-
- /*
- * Start KA9Q
- */
- rtems_task_set_priority (RTEMS_SELF, 30, &oldPri);
- rtems_ka9q_start (20);
+ const char *hostname, *filename;
- /*
- * Hook up drivers
- */
-#if (defined (USE_BOOTP))
- if (rtems_ka9q_execute_command ("attach rtems broadcast y"
- " ether " MY_ETHERNET_ADDRESS))
-#else
- if (rtems_ka9q_execute_command ("attach rtems broadcast y"
- " ip " MY_IP_ADDRESS
- " ether " MY_ETHERNET_ADDRESS))
-#endif
- rtems_panic ("Can't attach Ethernet driver.\n");
-
- /*
- * Configure the driver
- */
- if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
- rtems_panic ("Can't configure Ethernet driver.\n");
-
- /*
- * Add the ethernet broadcast address to the ARP table.
- */
- if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
- rtems_panic ("Can't add broadcast entry to ARP table.\n");
+ rtems_bsdnet_initialize_network ();
-#if (defined (USE_BOOTP))
- {
- int i;
- /*
- * Get BOOTP information
- */
- for (i = 0 ; ; ) {
- if (rtems_ka9q_execute_command ("bootp") == 0)
- break;
- if (++i == 10)
- rtems_panic ("Can't get information from BOOTP server.\n");
- delay_task (i);
- }
- if (BootpFileName)
- printf ("BOOTP filename: `%s'\n", BootpFileName);
- else
- printf ("BOOTP -- No filename!\n");
- }
+#if (defined (RTEMS_USE_BOOTP))
+ hostname = NULL;
+ filename = rtems_bsdnet_bootp_boot_file_name;
#else
- if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
- rtems_panic ("Can't set netmask.\n");
- if (rtems_ka9q_execute_command ("route add default rtems"))
- rtems_panic ("Can't add default route.\n");
- printf ("Routing table after adding default route\n");
- rtems_ka9q_execute_command ("route");
+ hostname = RTEMS_TFTP_TEST_HOST_NAME;
+ filename = RTEMS_TFTP_TEST_FILE_NAME;
#endif
- /*
- * Issue a gratuitous ARP request to update tables in
- * other hosts on this network.
- */
-
- if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
- rtems_panic ("Can't send gratuitous ARP.\n");
-
-
- /*
- * Test TFTP driver
- */
- testTFTP ();
-
- /*
- * Wind things up
- */
- rtems_task_wake_after (2 * ticksPerSecond);
- rtems_ka9q_execute_command ("detach rtems");
+ testTFTP (hostname, filename);
exit (0);
}
diff --git a/tftpTest/test.c b/tftpTest/test.c
index 1d40af8..a17183a 100644
--- a/tftpTest/test.c
+++ b/tftpTest/test.c
@@ -14,14 +14,12 @@
*/
#include <stdio.h>
+#include <errno.h>
+#include <string.h>
#include <rtems.h>
#include <rtems/error.h>
#include <sys/fcntl.h>
#include <unistd.h>
-#include <bootp.h>
-#include <netuser.h>
-
-#include "../usercfg.h"
static char cbuf[1024];
static char *fullname;
@@ -42,7 +40,6 @@ showRate (unsigned long totalRead)
/ elapsed));
}
printf (".\n");
-rtems_ka9q_execute_command ("ifconfig rtems");
}
static void
@@ -106,37 +103,10 @@ testFread (void)
}
static int
-makeFullname (rtems_unsigned32 host, const char *file)
+makeFullname (const char *hostname, const char *file)
{
- const char *hostname;
-#if !defined(USE_BOOTP)
- static char name[16];
-#endif
-
-#if 0
- printf( "makeFullname(0x08%x, %s)\n", host, file);
-#endif
-
-#if (defined (USE_BOOTP))
- if (host) {
- hostname = rtems_hostname_for_address (BootpHost.s_addr, 0);
- if (hostname == NULL) {
- printf ("No host to read from!\n");
- return 0;
- }
- } else {
- hostname = "";
- }
-#else
- if (host) {
- sprintf( name, "%d.%d.%d.%d", host >> 24, (host >> 16) & 0xff,
- (host >> 8) & 0xff, host & 0xff
- );
- hostname = name;
- } else {
+ if (hostname == NULL)
hostname = "";
- }
-#endif
fullname = realloc (fullname, 8 + strlen (file) + strlen (hostname));
sprintf (fullname, "/TFTP/%s/%s", hostname, file);
printf ("Read `%s'.\n", fullname);
@@ -144,12 +114,12 @@ makeFullname (rtems_unsigned32 host, const char *file)
}
void
-testTFTP (void)
+testTFTP (const char *hostname, const char *filename)
{
/*
* Check that invalid file names are reported as such
*/
- if (makeFullname (0, "")) {
+ if (makeFullname (hostname, "")) {
testRawRead ();
testFread ();
}
@@ -157,24 +127,15 @@ testTFTP (void)
/*
* Check that non-existent files are reported as such
*/
- if (makeFullname (0, "BAD-FILE-NAME")) {
+ if (makeFullname (hostname, "BAD-FILE-NAME")) {
testRawRead ();
testFread ();
}
/*
- * Check read speed
+ * Check that read works
*/
-#if (defined (USE_BOOTP))
- if (BootpFileName == NULL) {
- printf ("Nothing to read!\n");
- return;
- }
- if (makeFullname (BootpHost.s_addr, BootpFileName)) {
-#else
- if (makeFullname (aton (DATA_SOURCE_HOST), DATA_SOURCE_FILE)) {
-#endif
-
+ if (makeFullname (hostname, filename)) {
testRawRead ();
testFread ();
}
diff --git a/ttcp/Makefile b/ttcp/Makefile
index 5b46a4b..39f2d68 100644
--- a/ttcp/Makefile
+++ b/ttcp/Makefile
@@ -1,18 +1,14 @@
-#
-# $Revision$ $Date$ $Author$
-#
-
SAMPLE=ttcp
PGM=${ARCH}/$(SAMPLE).exe
-MANAGERS=io event message rate_monotonic semaphore timer
+MANAGERS=io event semaphore
# C source names, if any, go here -- minus the .c
-C_PIECES= init rtems_ttcp
+C_PIECES= init rtems_ttcp
C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
-H_FILES=
+H_FILES=
DOCTYPES=
DOCS=$(DOCTYPES:%=$(SAMPLE).%)
@@ -34,9 +30,10 @@ include $(PROJECT_ROOT)/make/leaf.cfg
DEFINES +=
CPPFLAGS +=
-CFLAGS += -I./include
-CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0x200000 # KA9Q needs more space
+CFLAGS +=
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000
CFLAGS_OPTIMIZE_V +=
+CFLAGS_DEBUG_V += -v -qrtems_debug
LD_PATHS +=
LD_LIBS +=
@@ -48,7 +45,7 @@ LD_LIBS +=
# 'make clobber' already includes 'make clean'
#
-CLEAN_ADDITIONS +=
+CLEAN_ADDITIONS +=
CLOBBER_ADDITIONS +=
all: ${ARCH} $(SRCS) $(PGM)
@@ -56,7 +53,7 @@ all: ${ARCH} $(SRCS) $(PGM)
${PGM}: $(OBJS) $(LINK_FILES)
$(make-exe)
-install: $(INSTALL_TARGET)
-
-$(INSTALL_TARGET): all
- cp ${PGM} $(INSTALL_TARGET)
+# Install the program(s), appending _g or _p as appropriate.
+# for include files, just use $(INSTALL)
+install: all
+ $(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
diff --git a/ttcp/README b/ttcp/README
index 8eb9ed3..5f209ab 100644
--- a/ttcp/README
+++ b/ttcp/README
@@ -1,22 +1,7 @@
-#
-# $Id$
-#
-
This directory contains an RTEMS application for measuring TCP/UDP
network throughput. The ttcp_orig subdirectory contains the original
UNIX program which can be compiled and run on your host machine.
-The RTEMS version of the test program is a little clumsy to use. You
-have to edit the rtems_ttcp.c source file and change the ttcp_argv
-array of strings to set the arguments you want passed to the ttcp
-task.
-
-It does work, though. The best throughputs I've seen so far are:
- 68360 card can transmit a TCP stream at 198 kbytes/second.
- 68360 card can receive a TCP stream at 119 kbytes/second.
-In both cases, the other end of the transfer was a 486DX2/66 running
-OPENSTEP/MACH 4.1.
-
One noteworthy item is that I was able to get the UNIX test program
running under RTEMS with no changes to the test program itself. The
entire UNIX source file is included, without changes, into the RTEMS
diff --git a/ttcp/init.c b/ttcp/init.c
index 4df07c9..68cbff7 100644
--- a/ttcp/init.c
+++ b/ttcp/init.c
@@ -3,8 +3,8 @@
*
* This program may be distributed and used for any purpose.
* I ask only that you:
- * 1. Leave this author information intact.
- * 2. Document any changes you make.
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
*
* W. Eric Norum
* Saskatchewan Accelerator Laboratory
@@ -13,20 +13,24 @@
* eric@skatter.usask.ca
*/
-#include "../usercfg.h"
-
#include <bsp.h>
#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
-#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
-#define CONFIGURE_MAXIMUM_SEMAPHORES 20
-#define CONFIGURE_MAXIMUM_TASKS 20
-#define CONFIGURE_MAXIMUM_TIMERS 10
-#define CONFIGURE_MAXIMUM_PERIODS 1
-#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TASKS 20
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+
+#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY 100
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+ RTEMS_NO_TIMESLICE | \
+ RTEMS_NO_ASR | \
+ RTEMS_INTERRUPT_LEVEL(0))
#define CONFIGURE_INIT
rtems_task Init (rtems_task_argument argument);
@@ -34,49 +38,8 @@ rtems_task Init (rtems_task_argument argument);
#include <confdefs.h>
#include <stdio.h>
-#include <rtems_ka9q.h>
-
-#if (defined (USE_BOOTP))
-#include <bootp.h>
-#endif
-
-volatile int ttcp_running;
-
-/*
- * Suspend execution for the specified number of seconds
- */
-static void
-delay_task (int seconds)
-{
- rtems_task_wake_after ((seconds * 1000000) / BSP_Configuration.microseconds_per_tick);
-}
-
-/*
- * Display the contents of several KA9Q tables
- */
-void
-show_ka9q_tables (void)
-{
- printf ("\n****************** MALLOC Statistics ***************\n");
- malloc_dump ();
- printf ("\n****************** MBUF Statistics ***************\n");
- mbufstat ();
- mbufsizes ();
- printf ("\n****************** Routing Table ***************\n");
- rtems_ka9q_execute_command ("route");
- printf ("\n****************** ARP Table ***************\n");
- rtems_ka9q_execute_command ("arp");
- printf ("\n****************** Driver Statistics ***************\n");
- rtems_ka9q_execute_command ("ifconfig rtems");
- printf ("\n****************** Ip Statistics ***************\n");
- rtems_ka9q_execute_command ("ip status");
- printf ("\n****************** ICMP Statistics ***************\n");
- rtems_ka9q_execute_command ("icmp status");
- printf ("\n****************** UDP Statistics ***************\n");
- rtems_ka9q_execute_command ("udp status");
- printf ("\n****************** TCP Statistics ***************\n");
- rtems_ka9q_execute_command ("tcp status");
-}
+#include <rtems/rtems_bsdnet.h>
+#include "../networkconfig.h"
/*
* RTEMS Startup Task
@@ -84,141 +47,7 @@ show_ka9q_tables (void)
rtems_task
Init (rtems_task_argument ignored)
{
- rtems_task_priority oldPri;
- rtems_mode old_mode;
-
-#if (defined (m68040))
- /*
- * Hook up FPSP
- */
- M68kFPSPInstallExceptionHandlers ();
-
- /*
- * Turn on instruction cache
- */
- asm volatile ("cinva bc");
- asm volatile ("movec %0,itt0" : : "d" (0x00ffc004));
- asm volatile ("movec %0,dtt0" : : "d" (0x00ffc040));
- asm volatile ("cinva bc\n\t"
- "movec %0,cacr" : : "d" (0x80008000));
-#endif
-
- ttcp_running = 0;
-
- /*
- * Start KA9Q
- */
- rtems_task_set_priority (RTEMS_SELF, 30, &oldPri);
- rtems_ka9q_start (30);
-
- /*
- * Hook up drivers
- */
- if (rtems_ka9q_execute_command ("attach rtems"
- /* " rbuf 24 tbuf 5" */
- " rbuf 100 tbuf 10"
-#if !(defined (USE_BOOTP))
- " ip " MY_IP_ADDRESS
-#endif
- " ether " MY_ETHERNET_ADDRESS))
- rtems_panic ("Can't attach Ethernet driver.\n");
-
-#if (defined (TRACE_NETWORK_DRIVER))
- /*
- * Turn on debugging
- */
- puts( "Enabling debug mode of KA9Q" );
- if (rtems_ka9q_execute_command ("trace rtems input <stdout>")
- || rtems_ka9q_execute_command ("trace rtems output <stdout>")
- || rtems_ka9q_execute_command ("trace rtems ascii <stdout>"))
- rtems_panic ("Can't set tracing for Ethernet driver.\n");
-#endif
-
-
- /*
- * Configure the driver
- */
- if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
- rtems_panic ("Can't configure Ethernet driver.\n");
-
- /*
- * Add the ethernet broadcast address to the ARP table.
- */
- if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
- rtems_panic ("Can't add broadcast entry to ARP table.\n");
-
-#if (defined (USE_BOOTP))
- {
- int i;
- /*
- * Get BOOTP information
- */
- for (i = 0 ; ; ) {
- if (rtems_ka9q_execute_command ("bootp") == 0)
- break;
- if (++i == 10)
- rtems_panic ("Can't get information from BOOTP server.\n");
- delay_task (i);
- }
- if (BootpFileName)
- printf ("BOOTP filename: `%s'\n", BootpFileName);
- else
- printf ("BOOTP -- No filename!\n");
- }
-#else
- if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
- rtems_panic ("Can't set netmask.\n");
- if (rtems_ka9q_execute_command ("route add default rtems"))
- rtems_panic ("Can't add default route.\n");
- printf ("Routing table after adding default route\n");
- rtems_ka9q_execute_command ("route");
-#endif
- /*
- * Issue a gratuitous ARP request to update tables in
- * other hosts on this network.
- */
- if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
- rtems_panic ("Can't send gratuitous ARP.\n");
-
- rtems_ka9q_execute_command ("tcp window");
- rtems_ka9q_execute_command ("tcp window 4096");
- rtems_ka9q_execute_command ("tcp window");
-
- /*
- * Whew!
- */
- printf ("NETWORK INITIALIZED!\n");
-
- /*
- * Let other tasks preempt this one
- */
- rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode);
-
- /*
- * See if sockets work properly
- */
+ rtems_bsdnet_initialize_network ();
test_network ();
-
- /*
- * Wait for characters from console terminal
- */
- do {
- rtems_task_wake_after( 1 );
- } while ( !ttcp_running );
- printf( "Now accepting input from the console\n" );
- for (;;) {
- switch (getchar ()) {
- case '\004':
- printf( "Exiting test\n" );
- return;
-
- case 's':
- /*
- * Show what's been accomplished
- */
- show_ka9q_tables ();
- break;
- }
- }
exit (0);
}
diff --git a/ttcp/rtems_ttcp.c b/ttcp/rtems_ttcp.c
index 356e5b3..cb97b99 100644
--- a/ttcp/rtems_ttcp.c
+++ b/ttcp/rtems_ttcp.c
@@ -2,7 +2,7 @@
* A collection of hacks, glue, and patches to
* provide a `UNIX-like' environment to ttcp.
*
- * Some of the code here should migrate to the libc
+ * Some of the code here may migrate to the libc
* support routines some day. Some of the more sleazy
* hacks should never make it outside this file!
*
@@ -19,12 +19,14 @@
*/
#include <stdio.h>
+#include <ctype.h>
#include <rtems.h>
-#include <rtems_ka9q.h>
+#include <rtems/rtems_bsdnet.h>
#include <rtems/error.h>
-#include <socket.h>
-#include <sockaddr.h>
-#include <netuser.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
#include <sys/time.h>
/*
@@ -32,26 +34,6 @@
*/
int rtems_ttcp_main (int argc, char **argv);
-#define ENOBUFS 2000
-
-struct hostent {
- char *h_name; /* official name of host */
- char **h_aliases; /* alias list */
- int h_addrtype; /* host address type */
- int h_length; /* length of address */
- char **h_addr_list; /* list of addresses from name server */
- #define h_addr h_addr_list[0] /* address, for backward compatiblity */
-};
-
-#define SOL_SOCKET 0
-#define SO_DEBUG 0
-
-static struct hostent *
-gethostbyname (const char *cp)
-{
- rtems_panic ("gethostbyname()");
-}
-
static int
select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
@@ -64,14 +46,6 @@ static void
return 0;;
}
-static char *
-rtems_inet_ntoa (struct in_addr in)
-{
- return inet_ntoa (in.s_addr);
-}
-#define inet_ntoa rtems_inet_ntoa
-#define inet_addr(cp) resolve(cp)
-
int
gettimeofday (struct timeval *tp, struct timezone *tzp)
{
@@ -119,21 +93,16 @@ getrusage(int ignored, struct rusage *ru)
return 0;
}
-void show_ka9q_tables (void);
-
static void
rtems_ttcp_exit (int code)
{
- rtems_interval ticksPerSecond;
-
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
- rtems_task_wake_after (ticksPerSecond * 2);
- show_ka9q_tables ();
+ rtems_bsdnet_show_mbuf_stats ();
+ rtems_bsdnet_show_if_stats ();
+ rtems_bsdnet_show_ip_stats ();
+ rtems_bsdnet_show_tcp_stats ();
exit (code);
}
-extern volatile int ttcp_running;
-
/*
* Task to run UNIX ttcp command
*/
@@ -157,12 +126,18 @@ ttcpTask (rtems_task_argument arg)
strcpy (arg0, "ttcp");
argv[0] = __progname = arg0;
+#if (defined (WRITE_TEST_ONLY))
+ strcpy (linebuf, "-s -t crux");
+#elif (defined (READ_TEST_ONLY))
+ strcpy (linebuf, "-s -r");
+#else
/*
* Read a line
*/
printf (">>> %s ", argv[0]);
fflush (stdout);
fgets (linebuf, sizeof linebuf, stdin);
+#endif
/*
* Break line into arguments
@@ -195,23 +170,10 @@ ttcpTask (rtems_task_argument arg)
printf ("or\n");
printf (" -t destination.internet.address\n");
}
- ttcp_running = 1;
code = rtems_ttcp_main (argc, argv);
rtems_ttcp_exit (code);
}
-static int
-rtems_ttcp_bind (int s, struct sockaddr *name, int namelen)
-{
- struct sockaddr_in *in = (struct sockaddr_in *)name;
- /*
- * KA9Q doesn't like 0 port numbers
- */
- if (in->sin_port == 0)
- in->sin_port = 2662;
- return bind (s, name, namelen);
-}
-
/*
* Test network throughput
*/
@@ -258,19 +220,11 @@ test_network (void)
printf ("Can't start task; %s\n", rtems_status_text (sc));
return;
}
- /* rtems_task_suspend (RTEMS_SELF); */
+ rtems_task_suspend (RTEMS_SELF);
}
#define main rtems_ttcp_main
#define exit(code) close(fd),rtems_ttcp_exit(code)
-#define bind rtems_ttcp_bind
#define read_timer rtems_read_timer
-/*
- * RTEMS/KA9Q code expects port numbers in host byte order!
- */
-#define htons(x) (x)
-
-#undef delay
-
#include "ttcp_orig/ttcp.c"