OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [common/] [current/] [tests/] [udp_lo_test.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/udp_lo_test.c
4
// 
5
//      Simple UDP throughput test
6
//
7
//==========================================================================
8
// ####BSDALTCOPYRIGHTBEGIN####                                             
9
// -------------------------------------------                              
10
// Portions of this software may have been derived from FreeBSD, OpenBSD,   
11
// or other sources, and if so are covered by the appropriate copyright     
12
// and license included herein.                                             
13
// -------------------------------------------                              
14
// ####BSDALTCOPYRIGHTEND####                                               
15
//==========================================================================
16
//#####DESCRIPTIONBEGIN####
17
//
18
// Author(s):    sorin@netappi.com 
19
// Contributors: gthomas,sorin@netappi.com, hmt
20
// Date:         2000-05-24
21
 
22
 
23
// Network throughput test code
24
 
25
#include <network.h>
26
 
27
#include <cyg/infra/testcase.h>
28
 
29
#define SOURCE_PORT 9990
30
#define SINK_PORT   9991
31
 
32
#define NUM_BUF 1024
33
#define MAX_BUF 8192
34
static unsigned char data_buf[MAX_BUF];
35
static unsigned char data_buf_write[MAX_BUF]="Client UDP is alive. You may continue ....";
36
 
37
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
38
static char stack_server[STACK_SIZE];
39
static cyg_thread server_thread_data;
40
static cyg_handle_t server_thread_handle;
41
 
42
static char stack_client[STACK_SIZE];
43
static cyg_thread client_thread_data;
44
static cyg_handle_t client_thread_handle;
45
 
46
 
47
#define MAIN_THREAD_PRIORITY     CYGPKG_NET_THREAD_PRIORITY-4
48
 
49
void
50
pexit(char *s)
51
{
52
    CYG_TEST_FAIL_FINISH( s );
53
}
54
 
55
 
56
void server(void)
57
{
58
    int s_source;
59
    struct sockaddr_in local,c_addr;
60
    socklen_t c_len;
61
    int len;
62
 
63
    char *hello_string=" Hello eCos network \n";
64
    diag_printf("UDP SERVER:");
65
    diag_printf(hello_string);
66
 
67
    s_source = socket(AF_INET, SOCK_DGRAM, 0);
68
    if (s_source < 0) {
69
        pexit("stream socket");
70
    }
71
    memset(&local, 0, sizeof(local));
72
    local.sin_family = AF_INET;
73
    local.sin_len = sizeof(local);
74
    local.sin_port = ntohs(SOURCE_PORT);
75
    local.sin_addr.s_addr = htonl(INADDR_ANY);  //accepts everyone...
76
    if(bind(s_source, (struct sockaddr *) &local, sizeof(local)) < 0) {
77
        pexit("bind /source/ error");
78
    }
79
    c_len = sizeof(c_addr);
80
 
81
    if ((len = recvfrom(s_source, data_buf, sizeof(data_buf),0,
82
                        (struct sockaddr *)&c_addr,&c_len)) < 0  ) {
83
        CYG_TEST_FAIL_FINISH("I/O error");
84
    }
85
    diag_printf("SERVER : message arrived from %s\n",inet_ntoa(c_addr.sin_addr));
86
    diag_printf("SERVER : Message : %s\n",data_buf);
87
    close(s_source);
88
}
89
 
90
void client(void)
91
{
92
    int s_source;
93
    struct sockaddr_in local;
94
    int len;
95
 
96
    diag_printf("client:started\n");
97
 
98
    s_source = socket(AF_INET, SOCK_DGRAM, 0);
99
    if (s_source < 0) {
100
        pexit("stream socket");
101
    }
102
    memset(&local, 0, sizeof(local));
103
    local.sin_family = AF_INET;
104
    local.sin_len = sizeof(local);
105
    local.sin_port = htons(SOURCE_PORT);
106
    local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
107
    if ( (len= sendto(s_source,data_buf_write,sizeof(data_buf_write),
108
                      0,(struct sockaddr *)&local,sizeof(local))) < 0 ) {
109
        CYG_TEST_FAIL_FINISH("Error writing buffer");
110
    }
111
    close(s_source);
112
}
113
 
114
void
115
udp_server(cyg_addrword_t param)
116
{
117
    init_all_network_interfaces();
118
    diag_printf("Start UDP server - test\n");
119
    cyg_thread_resume(client_thread_handle);    // Start the other one
120
#if NLOOP > 0
121
    server();
122
    CYG_TEST_PASS_FINISH("Server returned OK");
123
#endif
124
    CYG_TEST_NA( "No loopback devs" );
125
}
126
 
127
void
128
udp_client(cyg_addrword_t param)
129
{
130
    diag_printf("Start UDP client - test\n");
131
#if NLOOP > 0
132
    client();
133
#endif
134
}
135
 
136
 
137
 
138
void
139
cyg_start(void)
140
{
141
    CYG_TEST_INIT();
142
 
143
    cyg_thread_create(MAIN_THREAD_PRIORITY,     // Priority
144
                      udp_server,               // entry
145
                      0,                        // entry parameter
146
                      "UDP loopback server",    // Name
147
                      &stack_server[0],         // Stack
148
                      STACK_SIZE,               // Size
149
                      &server_thread_handle,    // Handle
150
                      &server_thread_data       // Thread data structure
151
            );
152
    cyg_thread_resume(server_thread_handle);    // Start it
153
 
154
    cyg_thread_create(MAIN_THREAD_PRIORITY,     // Priority
155
                      udp_client,               // entry
156
                      0,                        // entry parameter
157
                      "UDP loopback client",    // Name
158
                      &stack_client[0],         // Stack
159
                      STACK_SIZE,               // Size
160
                      &client_thread_handle,    // Handle
161
                      &client_thread_data       // Thread data structure
162
            );
163
    cyg_scheduler_start();
164
}
165
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.