- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/tcp_discard_cli.c
r321 r331 2 2 * TINET (TCP/IP Protocol Stack) 3 3 * 4 * Copyright (C) 2001-20 09by Dep. of Computer Science and Engineering4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering 5 5 * Tomakomai National College of Technology, JAPAN 6 6 * … … 58 58 #endif /* of #ifdef TARGET_KERNEL_JSP */ 59 59 60 #include <tinet_defs.h>61 #include <tinet_config.h>62 63 #include <net/if.h>64 #include <net/if_ppp.h>65 #include <net/if_loop.h>66 #include <net/ethernet.h>67 #include <net/net.h>68 #include <net/net_var.h>69 #include <net/net_timer.h>70 71 60 #include <netinet/in.h> 72 61 #include <netinet/in_itron.h> 73 #include <netinet/ip.h>74 #include <netinet/ip6.h>75 #include <netinet/tcp.h>76 62 77 63 #include <netapp/netapp.h> 78 64 #include <netapp/netapp_var.h> 79 #include <netapp/ discard.h>65 #include <netapp/tcp_discard_cli.h> 80 66 81 67 #ifdef USE_TCP_DISCARD_CLI … … 88 74 89 75 /*#define SHOW_RCV_RANGE*/ 76 77 /* 送信間隔 */ 78 79 #ifdef TOPPERS_S810_CLG3_85 80 81 #define START_DLY (10*SYSTIM_HZ) 82 #define SND_ITV (5*SYSTIM_HZ) 83 #define SLP_ITV (30*SYSTIM_HZ) 84 85 #else /* of #ifdef TOPPERS_S810_CLG3_85 */ 86 87 #define START_DLY (10*SYSTIM_HZ) 88 #define SND_ITV (5*SYSTIM_HZ) 89 #define SLP_ITV (60*SYSTIM_HZ) 90 91 #endif /* of #ifdef TOPPERS_S810_CLG3_85 */ 92 93 /* 自動実行 */ 94 95 #if defined(TCP_DISCARD_CLI_AUTO_RUN_STR) 96 #else 97 #if 0 98 #if defined(SUPPORT_INET6) 99 #define TCP_DISCARD_CLI_AUTO_RUN_STR "fd90:cce5:25f6:ff81:201:2ff:fe81:e7c9 - 0" 100 #else 101 #define TCP_DISCARD_CLI_AUTO_RUN_STR "172.25.129.142 - 0" 102 #endif 103 #endif 104 #endif 90 105 91 106 /* … … 143 158 case TFN_TCP_CLS_CEP: 144 159 if (nblk_error < 0) 145 syslog(LOG_NOTICE, "[TDC :%02dCBN] close error: %s", cepid, itron_strerror(nblk_error));160 syslog(LOG_NOTICE, "[TDCn:%02u CBN] close error: %s", cepid, itron_strerror(nblk_error)); 146 161 syscall(sig_sem(SEM_TCP_DISCARD_CLI_NBLK_READY)); 147 162 break; … … 162 177 */ 163 178 164 static void179 static ER 165 180 send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno) 166 181 { … … 183 198 184 199 if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) { 185 syslog(LOG_NOTICE, "[TDC :%02dSND] connect error: %s", cepid, itron_strerror(error));186 return ;200 syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error)); 201 return error; 187 202 } 188 203 … … 191 206 192 207 if (nblk_error != E_OK) 193 syslog(LOG_NOTICE, "[TDC :%02dSND] connect error: %s", cepid, itron_strerror(nblk_error));208 syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(nblk_error)); 194 209 else { 195 210 get_tim(&time); 196 syslog(LOG_NOTICE, "[TDC :%02d SND] connecting: %6ld, to: %s.%d",211 syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to: %s.%d", 197 212 cepid, time / SYSTIM_HZ, IP2STR(NULL, ipaddr), nblk_dst.portno); 198 213 … … 202 217 while (soff < SND_BUF_SIZE) { 203 218 if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) { 204 syslog(LOG_NOTICE, "[TDC :%02dSND] send error: %s",219 syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s", 205 220 cepid, itron_strerror(slen)); 206 221 goto cls_ret; … … 211 226 212 227 #ifdef SHOW_RCV_RANGE 213 syslog(LOG_NOTICE, "[TDC :%02d SND] snd: %2d, len: %4d, off: %4d",228 syslog(LOG_NOTICE, "[TDCn:%02u SND] send: %7lu, len: %4u, off: %4u", 214 229 cepid, scount, (uint16_t)slen, soff); 215 230 #endif /* of #ifdef SHOW_RCV_RANGE */ 216 231 217 syscall(dly_tsk(500 + net _rand() % SYSTIM_HZ));232 syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ)); 218 233 } 219 234 } … … 221 236 cls_ret: 222 237 get_tim(&time); 223 syslog(LOG_NOTICE, "[TDC :%02d SND] finished: %6ld, snd: %4d, len: %ld",238 syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu", 224 239 cepid, time / SYSTIM_HZ, scount, total); 225 240 226 241 if ((error = tcp_sht_cep(cepid)) < 0) 227 syslog(LOG_NOTICE, "[TDC :%02dSND] shutdown error: %s", cepid, itron_strerror(error));242 syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error)); 228 243 229 244 if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK) 230 syslog(LOG_NOTICE, "[TDC :%02dSND] close error: %s", cepid, itron_strerror(error));245 syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error)); 231 246 232 247 /* 開放が完了するまで待つ。*/ 233 248 syscall(wai_sem(SEM_TCP_DISCARD_CLI_NBLK_READY)); 234 249 } 250 251 return E_OK; 235 252 } 236 253 … … 241 258 */ 242 259 243 static void260 static ER 244 261 send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno) 245 262 { … … 266 283 267 284 if ((error = TCP_CON_CEP(cepid, &src, &dst, 60 * 1000)) != E_OK) { 268 syslog(LOG_NOTICE, "[TDC :%02dSND] connect error: %s", cepid, itron_strerror(error));269 return ;285 syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error)); 286 return error; 270 287 } 271 288 272 289 get_tim(&time); 273 syslog(LOG_NOTICE, "[TDC :%02d SND] connecting: %6ld, to: %s.%d",290 syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to: %s.%d", 274 291 cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno); 275 292 … … 279 296 while (soff < SND_BUF_SIZE) { 280 297 if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) { 281 syslog(LOG_NOTICE, "[TDC :%02dSND] send error: %s", cepid, itron_strerror(slen));298 syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s", cepid, itron_strerror(slen)); 282 299 goto cls_ret; 283 300 } … … 287 304 288 305 #ifdef SHOW_RCV_RANGE 289 syslog(LOG_NOTICE, "[TDC :%02d SND] snd: %3d, len: %4d, off: %4d",306 syslog(LOG_NOTICE, "[TDCn:%02u SND] send: %7lu, len: %4u, off: %4u", 290 307 cepid, scount, (uint16_t)slen, soff); 291 308 #endif /* of #ifdef SHOW_RCV_RANGE */ 292 309 293 syscall(dly_tsk(500 + net _rand() % SYSTIM_HZ));310 syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ)); 294 311 } 295 312 } … … 297 314 cls_ret: 298 315 get_tim(&time); 299 syslog(LOG_NOTICE, "[TDC :%02d SND] finished: %6ld, snd: %4d, len: %ld",316 syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu", 300 317 cepid, time / SYSTIM_HZ, scount, total); 301 318 302 319 if ((error = tcp_sht_cep(cepid)) < 0) 303 syslog(LOG_NOTICE, "[TDC :%02dSND] shutdown error: %s", cepid, itron_strerror(error));320 syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error)); 304 321 305 322 if ((error = tcp_cls_cep(cepid, TMO_FEVR)) < 0) 306 syslog(LOG_NOTICE, "[TDC:%02d SND] close error: %s", cepid, itron_strerror(error)); 323 syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error)); 324 325 return E_OK; 307 326 } 308 327 309 328 #endif /* of #ifdef USE_TCP_NON_BLOCKING */ 329 330 /* 331 * getcomd -- コマンドを得る。 332 */ 333 334 #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR 335 336 static char * 337 getcomd (ID cepid, bool_t retry) 338 { 339 ER error; 340 char *line = NULL; 341 static char auto_run_str[] = TCP_DISCARD_CLI_AUTO_RUN_STR; 342 static int_t count = 0; 343 344 if (retry || (count == 0)) { 345 line = auto_run_str; 346 dly_tsk(3 * 1000); 347 } 348 else { 349 while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) { 350 syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error)); 351 dly_tsk(SLP_ITV); 352 } 353 } 354 355 count ++; 356 return line; 357 } 358 359 #else /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */ 360 361 static char * 362 getcomd (ID cepid, bool_t retry) 363 { 364 ER error; 365 char *line = NULL; 366 367 while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) { 368 syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error)); 369 dly_tsk(SLP_ITV); 370 } 371 return line; 372 } 373 374 #endif /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */ 310 375 311 376 void 312 377 tcp_discard_cli_task (intptr_t exinf) 313 378 { 379 ID tskid, cepid; 314 380 T_IN_ADDR addr; 315 ID tskid, cepid; 316 int_t rep; 317 uint32_t count; 381 ER error; 382 uint8_t *line; 383 int_t rep, count; 384 bool_t retry = false; 318 385 uint16_t portno; 319 uint8_t *line;386 char apip; 320 387 321 388 #ifdef USE_TCP_EXTENTIONS 322 389 323 ER error;324 390 T_TCP_CCEP ccep; 325 391 326 392 #endif /* of #ifdef USE_TCP_EXTENTIONS */ 327 393 394 #ifdef TCP_ECHO_CLI_AUTO_RUN_STR 395 dly_tsk(START_DLY); 396 #endif 328 397 get_tid(&tskid); 329 syslog(LOG_NOTICE, "[TCP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf); 398 399 #if defined(SUPPORT_INET6) 400 apip = API_PROTO_IPV6; 401 #if defined(SUPPORT_INET4) 402 syslog(LOG_NOTICE, "[TCPn DISCARD CLI:%d,%d] started.", tskid, (ID)exinf); 403 #else 404 syslog(LOG_NOTICE, "[TCP6 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf); 405 #endif 406 #else 407 apip = API_PROTO_IPV4; 408 syslog(LOG_NOTICE, "[TCP4 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf); 409 #endif 410 330 411 while (true) { 331 if (rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line) == E_OK) { 332 line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */ 333 334 if ('0' <= *line && *line <= '9') { /* Port No */ 335 line = get_int(&rep, line); 336 portno = (uint16_t)rep; 412 line = skip_blanks(getcomd((ID)exinf, retry)); 413 414 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) { 415 syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], unknown host.", 416 (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 417 dly_tsk(SLP_ITV); 418 syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", (ID)exinf); 419 retry = true; 420 continue; 421 } 422 else 423 retry = false; 424 425 line = skip_blanks(line); 426 if ('0' <= *line && *line <= '9') { /* Port No */ 427 line = get_int(&rep, line); 428 portno = (uint16_t)rep; 429 } 430 else { 431 line ++; 432 portno = DISCARD_SRV_PORTNO; 433 } 434 435 line = skip_blanks(line); 436 if ('0' <= *line && *line <= '9') /* Repeat */ 437 line = get_int(&rep, line); 438 else 439 rep = 1; 440 441 #ifdef USE_TCP_EXTENTIONS 442 443 ccep.cepatr = 0; 444 ccep.sbufsz = TCP_DISCARD_CLI_SWBUF_SIZE; 445 ccep.rbufsz = 0; 446 ccep.rbuf = NADR; 447 448 #ifdef TCP_CFG_SWBUF_CSAVE 449 ccep.sbuf = NADR; 450 #else 451 ccep.sbuf = tcp_discard_cli_swbuf; 452 #endif 453 #ifdef USE_TCP_NON_BLOCKING 454 ccep.callback = (FP)callback_nblk_tcp_discard_cli; 455 #else 456 ccep.callback = NULL; 457 #endif 458 459 if ((error = ALLOC_TCP_CEP(&cepid, tskid, &ccep)) != E_OK) { 460 syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP create error: %s", cepid, itron_strerror(error)); 461 continue; 462 } 463 464 #else /* of #ifdef USE_TCP_EXTENTIONS */ 465 466 cepid = (ID)exinf; 467 468 #endif /* of #ifdef USE_TCP_EXTENTIONS */ 469 470 tcp_discard_cli_valid = true; 471 count = 0; 472 while (rep == 0 || count < rep) { 473 if (!tcp_discard_cli_valid) { 474 syslog(LOG_NOTICE, "[TDCn:%02u TSK] canceled.", cepid); 475 break; 476 } 477 478 count ++; 479 if (rep == 0) { 480 syslog(LOG_NOTICE, "[TDCn:%02u TSK] start: repeat: %d", cepid, count); 481 error = send_tcp_discard(cepid, &addr, portno); 482 syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh: repeat: %d", cepid, count); 337 483 } 338 484 else { 339 line ++; 340 portno = DISCARD_SRV_PORTNO; 341 } 342 343 line = skip_blanks(line); 344 if ('0' <= *line && *line <= '9') /* Repeat */ 345 line = get_int(&rep, line); 346 else 347 rep = 1; 485 syslog(LOG_NOTICE, "[TDCn:%02u TSK] start: repeat: %d/%d", cepid, count, rep); 486 error = send_tcp_discard(cepid, &addr, portno); 487 syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh: repeat: %d/%d", cepid, count, rep); 488 } 489 490 if (error != E_OK) { 491 syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], error: %s", 492 cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ, itron_strerror(error)); 493 tslp_tsk(SLP_ITV); 494 syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", cepid); 495 } 496 497 #if defined(SND_ITV) 498 #if SND_ITV > 0 499 if (count < rep) { 500 uint_t itv; 501 502 itv = SND_ITV; 503 syslog(LOG_NOTICE, "[TDCn:%02u TSK] interval: %d[s].", cepid, itv / SYSTIM_HZ); 504 syscall(dly_tsk(SND_ITV)); 505 } 506 #endif 507 #endif 508 } 348 509 349 510 #ifdef USE_TCP_EXTENTIONS 350 511 351 ccep.cepatr = 0; 352 ccep.sbufsz = TCP_DISCARD_CLI_SWBUF_SIZE; 353 ccep.rbufsz = 0; 354 ccep.rbuf = NADR; 355 356 #ifdef TCP_CFG_SWBUF_CSAVE 357 ccep.sbuf = NADR; 358 #else 359 ccep.sbuf = tcp_discard_cli_swbuf; 360 #endif 361 #ifdef USE_TCP_NON_BLOCKING 362 ccep.callback = (FP)callback_nblk_tcp_discard_cli; 363 #else 364 ccep.callback = NULL; 365 #endif 366 367 if ((error = alloc_tcp_cep(&cepid, tskid, &ccep)) != E_OK) { 368 syslog(LOG_NOTICE, "[TDC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error)); 369 continue; 370 } 371 372 #else /* of #ifdef USE_TCP_EXTENTIONS */ 373 374 cepid = (ID)exinf; 512 if ((error = FREE_TCP_CEP(cepid)) != E_OK) 513 syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP delete error: %s", cepid, itron_strerror(error)); 375 514 376 515 #endif /* of #ifdef USE_TCP_EXTENTIONS */ 377 516 378 tcp_discard_cli_valid = true;379 for (count = rep; count -- > 0; ) {380 if (!tcp_discard_cli_valid) {381 syslog(LOG_NOTICE, "[TDC:%02d TSK] canceled.", (ID)exinf);382 break;383 }384 syslog(LOG_NOTICE, "[TDC:%02d TSK] start: repeat: %d/%d",385 (ID)exinf, rep - count, rep);386 send_tcp_discard(cepid, &addr, portno);387 syslog(LOG_NOTICE, "[TDC:%02d TSK] finished: repeat: %d/%d",388 (ID)exinf, rep - count, rep);389 syscall(dly_tsk(500 + net_rand() % SYSTIM_HZ));390 }391 392 #ifdef USE_TCP_EXTENTIONS393 394 if ((error = free_tcp_cep(cepid)) != E_OK)395 syslog(LOG_NOTICE, "[TDC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));396 397 #endif /* of #ifdef USE_TCP_EXTENTIONS */398 399 }400 517 } 401 518 }
Note:
See TracChangeset
for help on using the changeset viewer.