FreeBSD Bugzilla – Attachment 154841 Details for
Bug 196755
SCTP aborts connections when primary is affected by packetloss but secondary path is clean
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
server used for testing
train_server.c (text/x-csrc), 4.15 KB, created by
Michael Tuexen
on 2015-03-26 19:25:47 UTC
(
hide
)
Description:
server used for testing
Filename:
MIME Type:
Creator:
Michael Tuexen
Created:
2015-03-26 19:25:47 UTC
Size:
4.15 KB
patch
obsolete
>/* > * Copyright (c) 2015 Michael Tuexen, tuexen@freebsd.org > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > */ > >#include <sys/types.h> >#include <sys/socket.h> >#include <netinet/in.h> >#include <netinet/sctp.h> >#include <arpa/inet.h> >#include <unistd.h> >#include <pthread.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <time.h> > >#define BUFFER_SIZE (256) >#define ADDR "0.0.0.0" >#define PORT 5001 > >static int fd; > >static void * >receive_thread(void *arg) >{ > char buffer[BUFFER_SIZE]; > > for (;;) { > if (recv(fd, buffer, BUFFER_SIZE, 0) < 0) { > perror("recv"); > break; > } > } > return (NULL); >} > >static void * >send_thread(void *arg) >{ > char buffer[BUFFER_SIZE]; > uint32_t delay; > > memset(&buffer, 'A', BUFFER_SIZE); > srandom(time(NULL) + getpid()); > for (;;) { > if (send(fd, buffer, BUFFER_SIZE, 0) < 0) { > perror("send"); > break; > } > delay = 1000000 - 100000 + random() % 200000; > printf("Sleeping %dms.\n", delay/1000); > usleep(delay); > } > return (NULL); >} > >int >main(void) { > pthread_t recv_tid, send_tid; > struct sockaddr_in addr; > int lfd; > struct sctp_rtoinfo rtoinfo; > struct sctp_paddrparams path_params; > struct sctp_assocparams assoc_params; > > if ((lfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) { > perror("socket"); > } > memset(&rtoinfo, 0, sizeof(struct sctp_rtoinfo)); > rtoinfo.srto_initial = 300; > rtoinfo.srto_min = 100; > rtoinfo.srto_max = 500; > if (setsockopt(lfd, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, sizeof(struct sctp_rtoinfo)) < 0) { > perror("setsockopt"); > } > memset(&assoc_params, 0, sizeof(struct sctp_assocparams)); > assoc_params.sasoc_asocmaxrxt = 5; > if (setsockopt(lfd, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc_params, sizeof(struct sctp_assocparams)) < 0) { > perror("setsockopt"); > } > memset(&path_params, 0, sizeof(struct sctp_paddrparams)); > path_params.spp_address.ss_family = AF_INET; >#if defined(__APPLE__) || defined(__FreeBSD__) > path_params.spp_address.ss_len = sizeof(struct sockaddr_in); >#endif > path_params.spp_hbinterval = 500; > path_params.spp_pathmaxrxt = 2; > path_params.spp_flags = SPP_HB_ENABLE; > if (setsockopt(lfd, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &path_params, sizeof(struct sctp_paddrparams)) < 0) { > perror("setsockopt"); > } > memset(&addr, 0, sizeof(struct sockaddr_in)); >#if defined(__APPLE__) | defined(__FreeBSD__) > addr.sin_len = sizeof(struct sockaddr_in); >#endif > addr.sin_family = AF_INET; > addr.sin_port = htons(PORT); > addr.sin_addr.s_addr = inet_addr(ADDR); > if (bind(lfd, (const struct sockaddr *)&addr, (socklen_t)sizeof(struct sockaddr_in)) < 0) { > perror("bind"); > } > if (listen(lfd, 1) < 0) { > perror("listen"); > } > if ((fd = accept(lfd, NULL, NULL)) < 0) { > perror("accept"); > } > if (close(lfd) < 0) { > perror("close"); > } > pthread_create(&recv_tid, NULL, &receive_thread, (void *)NULL); > pthread_create(&send_tid, NULL, &send_thread, (void *)NULL); > pthread_join(recv_tid, NULL); > pthread_join(send_tid, NULL); > if (close(fd) < 0) { > perror("close"); > } > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 196755
: 154841 |
154842