source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/udp6_echo_cli.c@ 352

Last change on this file since 352 was 352, checked in by coas-nagasima, 6 years ago

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 12.3 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
8 * によって公表されている GNU General Public License の Version 2 に記
9 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
10 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
11 * 利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次の条件を満たすこと.
21 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 *
26 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
27 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
28 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
29 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
30 *
31 * @(#) $Id$
32 */
33
34/*
35 * UDP6 ECHO クライアント
36 */
37
38#include <string.h>
39
40#if defined(TARGET_KERNEL_ASP)
41
42#include <kernel.h>
43#include <sil.h>
44#include <t_syslog.h>
45#include "kernel_cfg.h"
46#include "tinet_cfg.h"
47
48#endif /* of #if defined(TARGET_KERNEL_ASP) */
49
50#if defined(TARGET_KERNEL_JSP)
51
52#include <t_services.h>
53#include "kernel_id.h"
54#include "tinet_id.h"
55
56#endif /* of #if defined(TARGET_KERNEL_JSP) */
57
58#include <netinet/in.h>
59#include <netinet/in_itron.h>
60
61#include <netapp/netapp.h>
62#include <netapp/netapp_var.h>
63#include <netapp/udp4_echo_cli.h>
64#include <netapp/udp6_echo_cli.h>
65
66#if defined(USE_UDP6_ECHO_CLI_TSK)
67
68/* echo サーバのポート番号 */
69
70#define ECHO_SRV_PORTNO UINT_C(7)
71
72/* 送信間隔 */
73
74#if defined(TOPPERS_S810_CLG3_85)
75
76#define SLP_ITV (30*SYSTIM_HZ)
77
78#else /* of #if defined(TOPPERS_S810_CLG3_85) */
79
80#define SLP_ITV (60*SYSTIM_HZ)
81
82#endif /* of #if defined(TOPPERS_S810_CLG3_85) */
83
84/* 自動実行 */
85
86#if defined(UDP6_ECHO_CLI_AUTO_RUN_STR)
87#else
88#if 0
89#define UDP6_ECHO_CLI_AUTO_RUN_STR "fe80::211:2fff:fe8a:e8c0 - 1000"
90#endif
91#endif
92
93/*
94 * 全域変数
95 */
96
97bool_t udp6_echo_cli_valid;
98
99/*
100 * 変数
101 */
102
103#define BUF_SIZE 2048
104
105static char udp_buf[BUF_SIZE];
106static T_IPV6EP dst;
107
108#if defined(USE_UDP_NON_BLOCKING)
109
110static ER_UINT nblk_len;
111static ID nblk_tskid;
112
113/*
114 * ノンブロッキングコールのコールバック関数
115 */
116
117ER
118callback_nblk_udp6_echo_cli (ID cepid, FN fncd, void *p_parblk)
119{
120 nblk_len = *(ER_UINT*)p_parblk;
121 syscall(wup_tsk(nblk_tskid));
122 return E_OK;
123 }
124
125/*
126 * udp6_echo_cli -- ECHO/UDP サーバにメッセージを送信する (ノンブロッキングコール使用)。
127 */
128
129static ER
130udp6_echo_cli (ID cepid, T_IN6_ADDR *ipaddr, uint16_t portno, char *line)
131{
132 ER_UINT error;
133 SYSTIM time;
134 uint_t len;
135
136 dst.ipaddr = *ipaddr;
137 dst.portno = portno;
138 len = strlen(line);
139 get_tim(&time);
140 get_tid(&nblk_tskid);
141 if ((error = udp6_snd_dat(cepid, &dst, line, len, TMO_NBLK)) != E_WBLK) {
142 syslog(LOG_NOTICE, "[UEC6:%02u SDN] error: %7lu,%s",
143 cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
144 return error;
145 }
146 else
147 syslog(LOG_NOTICE, "[UEC6:%02u SDN] send: %7lu, to: %s.%d\n"
148 " msg: %s",
149 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, line);
150
151 syscall(slp_tsk());
152 get_tim(&time);
153 if (nblk_len < 0) { /* 0 以下の場合は、エラーコード */
154 syslog(LOG_NOTICE, "[UEC6:%02u CBR] error: %7lu,%s",
155 cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
156 return nblk_len;
157 }
158
159 if ((error = udp6_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_NBLK)) != E_WBLK) {
160 syslog(LOG_NOTICE, "[UEC6:%02u RVN] error: %7lu,%s",
161 cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
162 return error;
163 }
164
165 syscall(slp_tsk());
166 get_tim(&time);
167 if (nblk_len < 0) { /* 0 以下の場合は、エラーコード */
168 syslog(LOG_NOTICE, "[UEC6:%02u RVN] error: %7lu,%s",
169 cepid, time / SYSTIM_HZ, itron_strerror(nblk_len));
170 return nblk_len;
171 }
172 else {
173 udp_buf[nblk_len] = '\0';
174 get_tim(&time);
175 syslog(LOG_NOTICE, "[UEC6:%02u RVN] recv: %7lu,from: %s.%d\n"
176 " msg: %s",
177 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, udp_buf);
178 nblk_len = E_OK;
179 }
180
181 return nblk_len;
182 }
183
184#else /* of #if defined(USE_UDP_NON_BLOCKING) */
185
186#if defined(USE_UDP_CALL_BACK)
187
188/*
189 * コールバック関数
190 */
191
192ER
193callback_udp6_echo_cli (ID cepid, FN fncd, void *p_parblk)
194{
195 SYSTIM time;
196 ER_UINT len;
197
198 get_tim(&time);
199 if ((len = udp6_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_FEVR)) >= 0) {
200 *(udp_buf + len) = '\0';
201 syslog(LOG_NOTICE, "[UEC6:%02u RVC)] recv: %7lu,from: %s.%d\n"
202 " msg: %s",
203 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, udp_buf);
204 }
205 else
206 syslog(LOG_NOTICE, "[UEC6:%02u RVC] error: %7lu,%s",
207 cepid, time / SYSTIM_HZ, itron_strerror(len));
208
209 return E_OK;
210 }
211
212/*
213 * udp6_echo_cli -- ECHO/UDP サーバにメッセージを送信する (コールバック関数使用)。
214 */
215
216static ER
217udp6_echo_cli (ID cepid, T_IN6_ADDR *ipaddr, uint16_t portno, char *line)
218{
219 SYSTIM time;
220 ER_UINT len;
221
222 dst.ipaddr = *ipaddr;
223 dst.portno = portno;
224 len = strlen(line);
225 get_tim(&time);
226 syslog(LOG_NOTICE, "[UEC6:%02u SDC)] send: %7lu, to: %s.%d\n"
227 " msg: %s",
228 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, line);
229 if ((len = udp6_snd_dat(cepid, &dst, line, len, TMO_FEVR)) < 0)
230 syslog(LOG_NOTICE, "[UEC6:%02u SDC] error: %7lu,%s",
231 cepid, time / SYSTIM_HZ, itron_strerror(len));
232
233 return E_OK;
234 }
235
236#else /* of #if defined(USE_UDP_CALL_BACK) */
237
238/*
239 * udp6_echo_cli -- ECHO/UDP サーバにメッセージを送信する (コールバック関数未使用)。
240 */
241
242static ER
243udp6_echo_cli (ID cepid, T_IN6_ADDR *ipaddr, uint16_t portno, char *line)
244{
245 SYSTIM time;
246 ER_UINT len;
247
248 dst.ipaddr = *ipaddr;
249 dst.portno = portno;
250 len = strlen(line);
251 get_tim(&time);
252 syslog(LOG_NOTICE, "[UEC6:%02u SND] send: %7lu, to: %s.%d\n"
253 " msg: %s",
254 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, line);
255 if ((len = udp6_snd_dat(cepid, &dst, line, len, TMO_FEVR)) < 0) {
256 syslog(LOG_NOTICE, "[UEC6:%02u SND] error: %7lu,%s",
257 cepid, time / SYSTIM_HZ, itron_strerror(len));
258 return len;
259 }
260
261 if ((len = udp6_rcv_dat(cepid, &dst, udp_buf, sizeof(udp_buf), 10*1000)) >= 0) {
262 *(udp_buf + len) = '\0';
263 get_tim(&time);
264 syslog(LOG_NOTICE, "[UEC6:%02u RCV] recv: %7lu,from: %s.%d\n"
265 " msg: %s",
266 cepid, time / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, udp_buf);
267 return E_OK;
268 }
269 else {
270 get_tim(&time);
271 syslog(LOG_NOTICE, "[UEC6:%02u RCV] error: %7lu,%s",
272 cepid, time / SYSTIM_HZ, itron_strerror(len));
273 return len;
274 }
275 }
276
277#endif /* of #if defined(USE_UDP_CALL_BACK) */
278
279#endif /* of #if defined(USE_UDP_NON_BLOCKING) */
280
281/*
282 * getcomd -- コマンドを得る。
283 */
284
285#if defined(UDP6_ECHO_CLI_AUTO_RUN_STR)
286
287static char *
288getcomd (ID cepid, bool_t retry)
289{
290 ER error;
291 char *line = NULL;
292 static char auto_run_str[] = UDP6_ECHO_CLI_AUTO_RUN_STR;
293 static int_t count = 0;
294
295 if (retry || count == 0) {
296 line = auto_run_str;
297 dly_tsk(6 * 1000);
298 }
299 else {
300 while ((error = rcv_dtq(DTQ_UDP6_ECHO_CLI, (intptr_t*)&line)) != E_OK) {
301 syslog(LOG_NOTICE, "[UEC6:%02u TSK] error:%s", cepid, itron_strerror(error));
302 dly_tsk(SLP_ITV);
303 }
304 }
305
306 count ++;
307 return line;
308 }
309
310#else /* of #if defined(UDP6_ECHO_CLI_AUTO_RUN_STR) */
311
312static char *
313getcomd (ID cepid, bool_t retry)
314{
315 ER error;
316 char *line = NULL;
317
318 while ((error = rcv_dtq(DTQ_UDP6_ECHO_CLI, (intptr_t*)&line)) != E_OK) {
319 syslog(LOG_NOTICE, "[UEC6:%02u TSK] error:%s", cepid, itron_strerror(error));
320 dly_tsk(SLP_ITV);
321 }
322 return line;
323 }
324
325#endif /* of #if defined(UDP6_ECHO_CLI_AUTO_RUN_STR) */
326
327#define MESSAGE_FORMAT "MSG 1000000"
328
329/*
330 * UDP6 ECHO クライアント送信タスク
331 */
332
333void
334udp6_echo_cli_task (intptr_t exinf)
335{
336 static char msg[sizeof(MESSAGE_FORMAT)] = MESSAGE_FORMAT;
337
338 ID tskid, cepid;
339 ER error = E_OK;
340 SYSTIM time;
341 T_IN6_ADDR addr;
342 char *line, *p;
343 int_t rep;
344 uint32_t count, msgno;
345 bool_t retry = false;
346 uint16_t portno = ECHO_SRV_PORTNO;
347
348#if defined(USE_UDP_EXTENTIONS)
349 T_UDP6_CCEP ccep;
350#endif
351
352 dly_tsk(10*1000);
353 get_tid(&tskid);
354 syslog(LOG_NOTICE, "[UDP6 ECHO CLI:%d,%d] started.", tskid, (ID)exinf);
355 while (true) {
356 line = skip_blanks(getcomd((ID)exinf, retry));
357
358 if ((line = lookup_ipaddr(&addr, line, API_PROTO_IPV6)) == NULL) {
359 syslog(LOG_NOTICE, "[UEC6:%02u TSK] sleep %d.%03u[s], unknown host.",
360 (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
361 dly_tsk(SLP_ITV);
362 syslog(LOG_NOTICE, "[UEC6:%02u TSK] resume.", (ID)exinf);
363 retry = true;
364 continue;
365 }
366
367 line = skip_blanks(line);
368 if ('0' <= *line && *line <= '9') { /* Port No */
369 line = get_int(&rep, line);
370 portno = (uint16_t)rep;
371 }
372 else if (*line == '-')
373 line ++;
374
375#if defined(USE_UDP_EXTENTIONS)
376
377 ccep.cepatr = UINT_C(0);
378 ccep.myaddr.portno = UDP_PORTANY;
379 memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
380
381#ifdef USE_UDP_NON_BLOCKING
382 ccep.callback = (FP)callback_nblk_udp6_echo_cli;
383#else
384 ccep.callback = NULL;
385#endif
386
387 if ((error = alloc_udp6_cep(&cepid, tskid, &ccep)) != E_OK) {
388 syslog(LOG_NOTICE, "[UEC6:%02u TSK] CEP create error:%s", cepid, itron_strerror(error));
389 continue;
390 }
391
392#else/* of #ifdef USE_UDP_EXTENTIONS */
393
394 cepid = (ID)exinf;
395
396#endif /* of #if defined(USE_UDP_EXTENTIONS) */
397
398 line = skip_blanks(line);
399 if ('0' <= *line && *line <= '9') { /* Repeat */
400 line = get_int(&rep, line);
401#if 0
402 if (rep > 1000000)
403 rep = 1000000;
404#endif
405 udp6_echo_cli_valid = true;
406 count = 0;
407 while (rep == 0 || count < rep) {
408 if (!udp6_echo_cli_valid) {
409 syslog(LOG_NOTICE, "[UEC6:%02u TSK] canceled.", cepid);
410 break;
411 }
412
413 count ++;
414 p = &msg[sizeof(MESSAGE_FORMAT)] - 1;
415 for (msgno = count; msgno > 0; msgno /= 10)
416 *(-- p) = msgno % 10 + '0';
417 while (*(p - 2) != 'G')
418 *(-- p) = ' ';
419
420 if ((error = udp6_echo_cli(cepid, &addr, portno, msg)) != E_OK)
421 dly_tsk(30 * SYSTIM_HZ);
422
423 dly_tsk(25 * SYSTIM_HZ + netapp_rand() % (10 * SYSTIM_HZ));
424 }
425 }
426
427 else /* Single Message */
428
429 error = udp6_echo_cli(cepid, &addr, portno, line);
430
431 if (error != E_OK) {
432 get_tim(&time);
433 syslog(LOG_NOTICE, "[UEC6:%02u SND] error: %7lu,%s",
434 cepid, time / SYSTIM_HZ, itron_strerror(error));
435 }
436
437#if defined(USE_UDP_EXTENTIONS)
438
439 if ((error = free_udp6_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
440 syslog(LOG_NOTICE, "[UEC6:%02u TSK] CEP delete error:%s", cepid, itron_strerror(error));
441
442#endif /* of #if defined(USE_UDP_EXTENTIONS) */
443
444 }
445 }
446
447#endif /* of #if defined(USE_UDP6_ECHO_CLI_TSK) */
Note: See TracBrowser for help on using the repository browser.