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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [common/] [v2_0/] [tests/] [udp_lo_test.c] - Blame information for rev 279

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

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

powered by: WebSVN 2.1.0

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