4

Is it possible to force SCTP to send all data completely ordered?

Let's do this experiment:

1) Take this SCTP-discard-server and this SCTP-client.

2) Let the client count to 100 a lot of times and send a byte each time respectively to the server.

for(long i=0; i< 1000000000; i++){
    char temp = (char)(i%100) + 1;
    usrsctp_sendv(
        sock, (void *)&temp, 1,
        NULL, 0, NULL, 0, SCTP_SENDV_NOINFO, 0
    );
}

3) Let the server count along the same way and compare its number with the received one.

printf("%d %d\n", (int)buffer[0], (int)(test));
if ((int)test != (int)buffer[0]) break;

Some seconds later:

66 66
67 67
68 68
69 69
51 70

Voila!

I compiled this with $ gcc discard_server.c -Wall -lusrsctp using gcc7.3.0 on my Ubuntu 18.04 machine. And yes, I have already tried disabling every kind of nagel-algorithms via SCTP_NODELAY.

What did I miss? Thanks in advance for any hint.

user1511417
  • 1,880
  • 3
  • 20
  • 41

2 Answers2

3

What you probably missing is the fact that SCTP does not guarantee sequential delivery within association. Sequential delivery is guaranteed only within a stream.

As RFC 4960 chapter 1.5.2 says:

Internally, SCTP assigns a Stream Sequence Number to each message passed to it by the SCTP user. On the receiving side, SCTP ensures that messages are delivered to the SCTP user in sequence within a given stream. However, while one stream may be blocked waiting for the next in-sequence user message, delivery from other streams may proceed.

I guess you have more then one steam configured and the implementation that you using distributes the load between streams. This should be easy to confirm with wireshark trace.

If you carry about message order you should specify stream id when you send your data and check stream id when it arrives.

Community
  • 1
  • 1
1

I found out, that usrsctp_sendv(..) can fail, if the socket buffer is full for example. This is what happened.

I tried while(usrsctp_sendv(..) < 0) and now client and server count along the right way.

user1511417
  • 1,880
  • 3
  • 20
  • 41