SCTP in Go
Olivier Van Acker
Department of Computer Science and Information Systems
Birkbeck University of London
London, United Kingdom
Email: olivier@robotmotel.com
Abstract—This paper describes a successful attempt to combine two relatively new technologies: Stream Control Transmission Protocol (SCTP) and the programming language Go,
achieved by extending the existing Go network library with
SCTP.
SCTP is a reliable, message-oriented transport layer protocol,
similar to TCP and UDP. It offers sequenced delivery of messages
over multiple streams, network fault tolerance via multihoming
support, resistance against flooding and masquerade attacks
and congestion avoidance procedures. It has improvements overwider-established network technologies and is gradually gaining
traction in the telecom and Internet industries.
Go is an open source, concurrent, statically typed, compiled
and garbage-collected language, developed by Google Inc. Go’s
main design goals are simplicity and ease of use and it has asyntax broadly similar to C. Go has good support for networked
and multicore computing and as a system language is often used
for networked applications, however it doesn’t yet support SCTP.
By combining SCTP and Go, software engineers can exploit theadvantages of both technologies. The implementation of SCTP
extending the Go network library was done on FreeBSD and
Mac OS X - the two operating systems that contain the most up
to date implementation of the SCTP specification.
Index Terms—Stream Control Transmission Protocol (SCTP);
Transmission Control Protocol (TCP); Go; Networking;I. I NTRODUCTION
This paper will look into combining two relatively newtechnologies: a network protocol called SCTP and the programming language Go. Both technologies claim to offer
improvements over existing technologies: SCTP does awaywith the limitations of the widely used TCP protocol (author?)[8]; and Go was designed with simplicity and minimized programmer effort in mind, thereby preventing a forest of features
getting in the way of program design: Less is exponentiallymore (author?) [6]. The current version of the Go network
library does not support the SCTP protocol and this paper
examines how easy it is to extend the Go network librarywith this protocol. The work in this paper is based on thedissertation submitted for an MSc in Computer Science at
Birkbeck University in London and is available as an open
source project.
A. Relevance
After ten years SCTP as a technology is becoming more
and more relevant. One notable implementation is the use of
SCTP as a data channel in the Web Real-Time Communication(WebRTC) standard (author?) [11], a HTML 5 extension to
enable real time video and audio communication in browsers.

Google inc. and the Mozilla Foundation are each planning
to release a browser this year implementing the WebRTC
standard. Go as a language is very new and it is too early
to say what impact it will have. It does however receive a lotof media attention since it is developed by Google. It is also
growing in popularity because of its ease of use as a concurrent
system language (author?) [1].
B. Outline
Section II presents an overview of Go and SCTP, followedby (section III) a description of how the TCP socket API
is integrated in the Go networking library. This is a starting
point for the design of an SCTP extension to the network
library in Go, described in section IV. Section V explains
the implementation. Section VI analysis the results and VII
concludes.
II. T ECHNOLOGY OVERVIEW
In this section I will give an overview of the main featuresof SCTP and Go.
A. SCTPSCTP was initially developed in response to the demandsof the telecoms industry, which was not satisfied with thereliability and performance of TCP (author?) [10, p. 15].
During the design phase the decision was made to make SCTP
a less telephony-centric IP protocol (author?) [10, p. 16] sothat it could also be used for more generic data transport
purposes.
1) Comparison with TCP: It is fruitful to compare TCP and
SCTP, as TCP is the most widely-used protocol (author?) [5]and SCTP is very similar to it:2) Multihoming: A host is said to be multihomed if it has
multiple IP addresses which can be associated with one ormore physical interfaces connected to the same or different
networks(author?) [2]. TCP can only bind to one network
address at each end of the connection. In the event of a network
failure there is no way to stay connected and send the data overanother physical path without setting up a new connection.
SCTP natively supports multihoming at the transport layer.
This makes it possible to connect and transfer data to andfrom multihomed hosts, so that when one network path fails,
the connection seamlessly fails over using the remaining
paths. And together with concurrent multipath transfer (CMT)(author?) [4] it is possible to increase data throughput by
transferring data simultaneously over multiple links.

3) In-built message boundaries: In TCP there are no markers to indicate the start or end of a specific piece of data (auser message). All data sent over the socket is converted into
a byte stream and an application must add its own mechanism
to be able to reconstruct the messages. In SCTP the message
boundaries of the data sent are preserved in the protocol. In theevent of the message being larger than the maximum package
size a notofication is sent to the application layer more is on
its way.
4) Protection against Denial of Service (DOS) attacks:
Another disadvantage of TCP is that it is open to ’SYN flood
attack’, a specific type of attack which can drain the serverof resources, resulting in a denial of service (nothing else canconnect). To prevent this, SCTP uses a four-way handshake toestablish the connection, whereas TCP only uses a three-way
handshake. With a four-way handshake the originator has todouble-acknowledge itself (”is it really you?”) by resending
a cookie it previously received from the destination server
before that server will assign resources to the connection. This
prevents timeouts on the server side and thus makes this typeof denial of service impossible. To reduce start up delay, actual
data can also be sent during the second part of the handshake.

Figure 2: Head of line blocking
9 user messages ready to be send

9

8

7

6

5

4

3

2

1

3

2

1

1 to 7 are send, message 4 does not arrive

9

8

7

6

5

7

6

5

7 to 4 are resend

9

8

4

Figure 3: Associations and streams
Application

Application

Streams

Streams

Port

Multiple IP addresses

SCTP

Port
SCTP

IP

IP

Figure 1: Initiating a network connection
IP network(a) TCP handshake(b) SCTP handshake
SCTP association

5) SCTP Multistreaming: SCTP user messages in a single
SCTP socket connection can be sent and delivered to theapplication layer over independent streams. In case of two setsof user messages A and B, each set delivered sequentially, themessages of set A can be sent over a different stream than B.
And in case a messages in set A gets missing and part of thesequence needs to be resent this will not effect the data of set
B if it is sent over a different stream. This tackels the ’headof line blocking’ problem (figure 2) where messages alreadydelivered need to be redelivered because they have to arrivein order and becuase one message did not arrive.
6) Associations: A connection between a SCTP server andclient is called an association. An association gets initiatedby a request from a SCTP client. So a listening server canaccept incoming requests from multiple clients. Messages sent
over the assocation have an association id attached to them.
to make it possible to know where they come from. Within
a single association you can have multiple streams for datatransmission (See figure 3)
7) Two programming models: SCTP has two interfaces for
implementation in a networked application: one-to-one andone-to-many. A single socket in a one-to-many model can havemultiple incoming associations, meaning that multiple clientscan connect to a single server listening on a single socket.
The one-to-one model can only have a single association
per socket. The one-to-one model is for easy migration ofexisting TCP applications, it maps one-to-one to the system
calls TCP makes to establish a connection. But it can only
have one connection per association, and thus only a single
client can connect to a server. The one-to-one interface makes
migrating an existing application a relatively painless exercise.
If you want to upgrade your existing TCP application to a
one-to-many SCTP application, significant retooling is needed.
(author?) [7, p. 267]
8) Socket API: Figure 4 is an overview of two applications
communicating over an IP network using a transport protocol(TCP, UDP or SCTP). The software engineer writing the clientand server in the application layer only has to know about
the function calls exposing the functionality in the transportlayer. This collection of functions is called the socket API. A
socket is an endpoint for networked communication; multiple
processes can open sockets via the API and data written into
one socket can be read from another. The socket API consistof functions which can open and close the socket, send dataover it and set the behavior of a socket using ’socket options’.
An example of such behavior is the enabling or disabling ofdata buffering before sending to reduce the number of packets
to sent over the network and therefore improve efficiency

Figure 4: Socket API

User processapplication protocol

Networked
clientFigure 6: Ancillary data embedded in sendmsg() data structure
msghdrNetworked
serverapplication layer

Socket API
TCP
UDP
SCTP

Transport protocol

TCP
UDP
SCTP

transport layer

Kernelmsg_namesockaddr

msg_iov

iovec

SCTP_SNDINFO

msg_control

IPIP

network layer

snd_flags
snd_ppid
snd_context

cmsghdrIP protocol

snd_sid

cmsg_level&

sctp_sndinfo

snd_assoc_id

cmsg_type
Ethernet protocol

EthernetdriverEthernetdriverdatalink layer

Ethernet

Table I: Ancillary data mappings
sid
ssn
ppid
aid

(Nagle’s algorithm).
Figure 5: TCP and SCTP socket API
TCP
ServerSCTP
ClientServersocket()socket()bind()bind()

listen()socket()accept()connect()

recv()

flags

Clientstream identifier
stream sequence number
identifier set by peer
association id

and ancillary data (see appendix E). SCTP adds extra metadata which contains information about the message being sent
and its connection. Table I gives an overview of the ancillarydata mapped to the return variables.
B. Go language overview

listen()socket()send()

recvmsg()

sendmsg()send()

recv()

sendmsg()

recvmsg()

close()

close()

close()

close()

9) SCTP Socket API: Figure 5 is an overview of both the
TCP and SCTP socket APIs and gives the order in which thesystem calls would be used in a simple client server application
sending and receiving messages. The server first creates asocket, this returns a file descriptor which can be used by thebind function to to make a request to assign a address to it.
After this the server can start listening to incoming connections
with the listen() function. After this point TCP is different from
SCTP. The TCP client actively connects to the peer and theserver accepts the connection with the accept() and connect()functions. With SCTP the connection set up hand handshakehappens implicitly when sending and receiving a message. At
this point the server and client can exchange messages andfinally the connection terminates with the close() function.
10) Socket I/O functions and ancillary data: The sendmsg()
and recvmsg() functions (see appendix D for definition) are
the most general of all socket I/O functions (author?) [7, p.
390] and can be used in combination with all protocols in thetransport layer. Both functions have room for message data

In this section I will give a short overview of the mainfeatures and characteristics of the Go language and provide
more detail where relevant to the project.
1) Data: Go has a syntax broadly similar to the C andJava languages. Variables are declared either by variable namefollowed by data type, or by name only with data type inferred(known as ’type inference’).’ With the initialization operator :=variables can be declared and initialized in a single statement.
If not initialized explicitly, the variable is set to a default value.
Here are some examples:var number i n t
var f i r s t _ n a m e , last_name s t r i n g
var g r e e t i n g = h e l l o ( " o l i v i e r " )f r a c t a l : = make ( [ ] uint64 , 10)

Go has two ways to create data structures: i) with ’new’,
where the data structure is initialized to zero; ii) with ’make’,
where the data structure is initialized to a specified value.
var p ∗ [ ] i n t = new ( [ ] i n t )var v [ ] i n t = make ( [ ] i n t , 100)

An asterisk indicates that the variable is a pointer.
2) Functions: Unlike most commonly-used languages Go
functions and methods can return multiple values. The following function expects a string and integer as input parameters
and returns a string and an error. If the count integer is zerothe function will return a nil and an error, otherwise it returns
the greeting and nil as error.

func h e l l o ( name s t r i n g , count i n t ) ( g r e e t i n gstring , e r r e r r o r ) {i f count = 0 {r e t u r n n i l , e r r o r s . New( " Cannot say
h e l l o zero t i m e s " )}g r e e t i n g = " H e l l o " + name , n i lreturn}ing example, in function main, a cat object gets created,
it talks and then gets cast (type changed) to an animal
object:type animal i n t e r f a c e {Talk ( )}type Catfunc ( c Cat ) T a l k ( ) {f m t . P r i n t l n ( "Meow" )}This hello function can be be called in the following
manner:g r e e t i n g , e r r : = h e l l o ( " paard " , 0 )i f err != n i l {println ( " error ! " )} else {println ( greeting )}Or if we are not interested in one of the return values, ablank identifier _ can be used to discard the value:g r e e t i n g , _ : = h e l l o ( " paard " , 1 )3) Object and methods: In Go data structures (objects) aredefined as follows:
type Person s t r u c t {name s t r i n g
age i n t}Functionality can be added to an object by defining methods
associated with it. A difference between Go and other objectoriented languages like Java is that in Go this functionality isdefined outside of the object, for example:
func ( p Person ) SayHello ( name S t r i n g ) {r e t u r n " H e l l o " + name " , my name i s " + p . name}In the above example the SayHello method has a string as
input and is associated with a Person object p.
Methods can be associated with any type, not just objects.
In the following example the Add() method is associated withan Array of strings:
type NameArray [ ] s t r i n gfunc ( na NameArray ) Add ( name s t r i n g ) [ ] s t r i n g {...
}It’s worth noting that Go has objects but not inheritance.
4) Interfaces : As with other object oriented languages,
you can specify behavior of an object by using interfaces
and also implement multiple interfaces per object. The interfaces does not have to be explicitly named: as soon as
the type implements the methods of the interface the compiler knows the relation between the two. In the follow-

func main ( ) {var c Catc . Talk ( )a : = animal ( c )a . Talk ( )}/ / Cast from c a t t o animal5) Pointers: Although Go has pointers (references to memory locations), they are implemented differently than in alanguage like C. Pointer arithmetic is not possible so Go
pointers can only be used to pass values by reference. At alower level Go pointers can be converted to C pointers.
6) Concurrency: Go has a basic primitive for concurrency called a goroutine. The name is not only a play on
a programming component called coroutine but is also its
implementation of it in the language. Coroutines are methods
which call on each other, data comes in, gets processed andgets passed to a the next coroutine. One of the advantages ofcoroutines is they are generally easier to create and understand[Knuth V1 p193]. But the main advantage is that it lends
itself very well for distributed computing where data gets
passed around from one processor to another, maybe even ona different computer.
In Go every function can become a goroutine by simple
putting go in front of it. A gorouting can than communicate
its input and output via channels. This concept is called
Communicating sequential processes (CSP) and is surprisingly
versatile in its use. (author?) [3] Here an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

package main
func receiveChan ( c i chan i n t ) {for {i : = <− c iprintln ( i )}}func main ( ) {c i : = make ( chan i n t )go receiveChan ( c i )f o r i : = 0 ; i < 1 0 ; i ++ {c i <− i}}

The receiveChan() function has as input a channel ofintegers. On line 4 an endless for loop starts where line 5
waits for an integer to come in on the channel. The mainfunctions first creates a channel of integers. Line 12 starts thefunction receiveChan as a Go routine in the background. Thisis followed by a loop sending 10 integers over the channel tothe receiveChan function.
7) Much more: There is more to the language like garbage
collection, first class functions, arrays, slices, however the
explanation of this falls outside the scope of this paper. Moreinformation can be found on the Go website 1 .
III. G O NETWORKINGThe following section contains the findings of my researchon how Go combines the system level TCP socket API into
an easy-to-use network library and how that works internally.
Much of the TCP functionality is very similar to the SCTP
stack and this will serve as an example of how to implement
SCTP in Go.
A. The network library
Go provides a portable interface for network I/O. Basicinteraction is provided by the Dial, Listen, ListenPacket andAccept functions which return implementations of the Conn,
PacketConn and Listener interfaces. The Listen function isfor byte stream data connections and the ListenPacket is fordata transfer which includes messages boundaries, like UDPor Unix domain sockets. These functions simplify the accessto the socket API, but if needed the application developer canstill access the socket API in more detail.
Here is an example of a typical TCP client and server
application. The client sends a single message and the server
waits to receive a message, prints it out after receiving andstarts listening again. First a simple client:
1
2
3
4
5
6
7
8
9
10
11

package main
import " n e t "func main ( ) {conn , e r r : = n e t . D i a l ( " t c p " , " l o c a l h o s t :1234 " )i f err != n i l {return}defer conn . Close ( )conn . W r i t e ( [ ] byte ( " H e l l o w o r l d ! " ) )}The function main() is the entry point of the program.
The first step the client performs is ’dialing’ a server with
the TCP protocol (line 5). The Dial() function returns a
connection which is an implementation of the Conn interface.
After checking for errors (6-8) the defer keyword before theconnection close command indicates the connection can befinished as soon as it is no longer needed. In this case it
happens immediately after the write so it does not make muchsense to defer it, but in larger programs with multiple exit
points you only need a single (deferred) close statement, whichmakes it easier to understand and maintain the program.
Next the server:
1 http://golang.org/doc/effective_go.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

package main
import " n e t "func main ( ) {l i s t e n , e r r : = n e t . L i s t e n ( " t c p " , " l o c a l h o s t :1234 ")i f err != n i l {return}b u f f e r : = make ( [ ] byte , 1024)for {conn , e r r : = l i s t e n . Accept ( )i f err != n i l {continue}
conn . Read ( b u f f e r )println ( string ( buffer ) )}}The server gets created with the Listen() method and returns
an object which implements the Listener interface. On line 9
a byte array buffer gets created for the received data. The
following for loop (10 - 17) will continuously wait to accept
an incoming connection (11), check for errors after connect,
read from it (15) and convert the byte array to a string before
printing it (16).
B. Under the hood
Go’s network communication library uses the same socket
API as any C program. In this section I will examine what
happens when a network connection is set up and which socket
API calls are made at what point. The example uses TCP. To
illustrate how Go accesses the socket API I will take the TCP
client described in the previous section as an example andshow how it interacts with the kernel by opening a connection.
Socket and Connect: For a TCP client to create a connection
and send some data the following system calls need to be madein this order:
1) resolve IP address2) socket()3) setsockopt() (optional)4) connect()
In Go all this is wrapped in the net.Dial() call.
Figure 8 shows a sequence diagram of method calls after aclient calls Dial(). First the hostname:port gets parsed and resolved to an IP address (1.1)2 . Net.dialAddr() (1.3) determines
the transport protocol type and calls the relevant method,net.DialTCP() in this case (1.3.1). Next net.internetSocket()gets called which internally calls socket() in the syscall package. Syscall.socket() is an auto-generated method based on C
header files which describe the socket API.
Every network protocol in Go has its own connection type.
As you can see in figure 8 the generic Dial() method eventuallyreaches the specific DialTCP() method which returns a TCPspecific connection type. This type gets cast to the moregeneric Conn type which can be used in the client application.
If TCP-specific functionality is needed the Conn type can be
2 There are more method calls behind this but they are not relevant for thisexamplerecast to a TCPConn which then makes it possible to access
TCP-specific functionality.

Figure 7: Go SCTP network API
ServerClientnet.ListenPacket()socket()C. Auto-generationbind()

net.Dail()

Native Go functions to access kernel system calls and data
structures can be auto-generated via scripts. In FreeBSD, if thedescription of the system call is present in the syscalls.master
file 3 , the function will be available through the syscall
package. Most system calls which are used in Go are wrapped
in methods to make them fit better the language. The structures
which are passed to the system calls are created in the sameway. The source code directory of the syscall package contains
a file with a link pointing to a header file which describes the
structures.

D. Go non-blocking networking
All networking in Go is non blocking which is not thedefault in the TCP/IP model. As soon as a application tries
to retrieve data from a socket, e.g. via readmsg(), it will notblock until some data comes in, instead it will immediately
move on in the program. Reading data from the socket isnormally done in an endless loop. To make Go actually wait
for sending data back to the application Go implements thereactor design pattern. The implementation of this software
pattern makes use of a mechanism in the kernel where you
can ask the kernel to send a signal back to the application
if certain events occur whilst you keep doing other things in
the program. For example data being written to the socket
descriptor. On BSD the system call kqeueu() and kevent() areused to register and queue events. The functionality of this ishandled by Go’s runtime.

IV. D ESIGNIn the following section I will describe how the different
Go network methods will map to the SCTP socket API.

listen()socket()PacketConn.ReadFrom()

Conn.WriteTo()recvmsg()

sendmsg()

PacketConn.WriteTo()Conn.WriteTo()

sendmsg()

recvmsg()

PacketConn.Close()

Conn.Close()close()

close()

A. Mapping APIs
The SCTP socket API will follow closely the wrapping of
the TCP socket API in the Go network library as describedin section III-B. Figure 7 show the mapping of the socket
API to the different functions and methods. At the server side
the socket(), bind() and listen() functions are bundled into the
ListenPacket() function which resides in the network package(net). The ListenPacket() function returns an implementationof the PacketConn interface (See appendix B). The client
wraps the socket() function into the Dail() function. Thisfunctions returns a Conn (connection) interface which canused for writing messages (Conn.WriteTo()) and these user
messages can be received vie the ReadFrom() method on the
PacketConn interface.
B. SCTP specific1) Receive SCTP specific information : To access SCTP
specific functionality, such as which stream the message has
been sent on, or the association id, net.ListenSCTP() can beused. This method returns a SCTP specific type (SCTPConn)which has the method ReadFromSCTP() and WriteToSCTP()
added to it. These methods return and set the information
contained by the SCTP receive information structure, added
as ancillary data when the system call recvmsg() returns.
2) Send SCTP specific information: To be able to set SCTP
specific send information such as stream id or association id
via the SCTP Send Information Structure, the several methods
on the SCTPConn object can be used (See table II):
Table II: Initialization parameters

3 Systemcall
name/number
http://fxr.watson.org/fxr/source/kern/syscalls.mastermasterfile:

Number of output streams
Max number of input streams
Max number of attempts to connect
Timeout(*SCTPConn) InitNumStreams(n int) error(*SCTPConn) InitMaxInStream(n int) error(*SCTPConn) InitMaxAttempts(n int) error(*SCTPConn) InitMaxInitTimeout(n int) error

A typical server which has access to SCTP specific functionality would look like this:package main
import (" net "
" strconv ")func main ( ) {addr , _ : = n e t . ResolveSCTPAddr ( " s c t p " , " l o c a l h o s t :4242 " )conn , _ : = n e t . ListenSCTP ( " s c t p " , addr )defer conn . Close ( )for {message : = make ( [ ] byte , 1024)_ , _ , stream , _ : = conn . ReadFromSCTP ( message )p r i n t l n ( " stream " + s t r c o n v . I t o a ( i n t ( stream ) ) + " : "+ s t r i n g ( message ) )}}In this program ListenSCTP returns a SCTP connection
type. This type implements Conn and PacketConn interface
and has the ReadFromSCTP method added to it. The println()functions prints the stream id and the user message.
V. I MPLEMENTATIONIn this section I will describe how the SCTP network
functionality can fit into the existing Go network framework.
The main goal of the SCTP application programming interface(API) design is to combine lower-level system calls in aneasy-to-use framework. This framework hides the underlying
complexity of the socket API but if needed gives access to
all the functionality provided by the protocol. To make sure
SCTP fits in the Go design philosophy, less is more, I will
make use as much as possible of the existing components andinterfaces in the Go network package. In the following section
I’ll epackage main
import " n e t "func main ( ) {conn , _ : = n e t . L i s t e n P a c k e t ( " s c t p " , "l o c a l h o s t :4242 " )defer conn . Close ( )message : = make ( [ ] byte , 1024)
conn . ReadFrom ( message )p r i n t ( s t r i n g ( message ) )}After the the main entry point a connection object is created
via the ListenPacket() method. The parameters of this method
indicate that the connection should use the SCTP protocol
and listen on localhost port 4242. The next line defers theclosing of the connection when it is not needed anymore. After
creating a byte array buffer to store incoming data a message isread from the connection. The ReadFrom() method will block
until a message is received. Finally the message is printed andthe program ends.
Receive SCTP-specific information: To access SCTPspecific functionality, such as which stream the message has
been sent on, or the association id, net.ListenSCTP() can beused. This method returns a SCTP-specific type (SCTPConn)which has the method ReadFromSCTP() added to it:( ∗SCTPConn ) . ReadFromSCTP ( message ∗ s t r i n g ) ( s i d
i n t , ssn i n t , p p i d i n t , a i d i n t , addr
SCTPAddr , e r r e r r o r )The ReadFromSCTP() method returns the information contained by the SCTP receive information structure, added asancillary data when the system call recvmsg() returns. A
typical server which has access to SCTP-specific functionality
would look like this:A. Server
For a server to be able to set up a SCTP association it
needs to create a socket, bind to it, optionally set some socket
options and start listening to it. A typical server will accessthe socket API in the following sequence:
1) socket()2) bind()3) listen()4) recvmsg()
The socket(), bind() and listen() functions will be wrapped
into a Listen() method which returns a connection type.
There are three variations: net.Listen(), net.ListenPacket()and net.ListenSCTP(). The Go network library provides thenet.ListenPacket() method for packet-oriented networking like
UDP, and net.Listen() for stream-oriented networking like
TCP. SCTP which is packet-oriented, can also make useof the net.ListenPacket() method. ListenPacket() returns animplementation of the PacketConn interface which can be used
to read and write messages (recvmsg()). A simple SCTP echo
server using the PacketConn interface might look like this:package main
import (" net "
" strconv ")func main ( ) {addr , _ : = n e t . ResolveSCTPAddr ( " s c t p " , " l o c a l h o s t:4242 " )conn , _ : = n e t . ListenSCTP ( " s c t p " , addr )defer conn . Close ( )for {message : = make ( [ ] byte , 1024)_ , _ , stream , _ : = conn . ReadFromSCTP ( message )p r i n t l n ( " stream " + s t r c o n v . I t o a ( i n t ( stream ) )+ " : " + s t r i n g ( message ) )}}In this program ListenSCTP() returns a SCTP connection
type. This type implements the Conn and PacketConn interfaces and adds the ReadFromSCTP() method.
B. Client
In Go a client connection sets itself up with a call to theDial() method. The Dial() method returns the generic Conn

interface. Every network protocol in Go has its own Dial()
method which returns a protocol-specific connection type. In
the case of SCTP this is the PacketConn type which has
underneath it a specific SCTP connection type (SCTPConn).
A simple SCTP client sending a single message would look
like this:package main
import " n e t "func main ( ) {addr , _ : = n e t . ResolveSCTPAddr ( " s c t p " , " l o c a l h o s t:4242 " )conn , _ : = n e t . DialSCTP ( " s c t p " , n i l , addr )defer conn . Close ( )message : = [ ] byte ( " paard " )conn . WriteTo ( message , addr )}B. Fitting like a glove
Since Go already provides methods and interfaces formessage-based data transmission that could be reused, andbecause of the SCTP socket API’s similarity to the TCP socket
API, making SCTP available in the Go network library was a
relatively straightforward task. I was able to reuse the ancillarydata structure from the Unix socket API and had only to add
the SCTP-specific ancillary data to the structure. It was easy
to follow the design philosophy ’less is exponentially more’:
the SCTP socket API could be wrapped in an easier-to-use
API, just as it is done with TCP. This resulted in a Go SCTP
API which can be used in the most simple way, hiding allcomplexity of the protocol or, if needed, it is possible to dive
deeper and make use of more specific SCTP functionality.
C. Issues during implementation

The DialSCTP() method creates the socket and sets default
socket options. Sending the message via WriteTo() will implicitly set up the connection.
Send SCTP-specific information: To be able to set SCTPspecific send information such as stream id or association id
via the SCTP Send Information Structure, the WriteToSCTP()
method can be used:(∗SCTPConn ) . WriteToSCTP ( message ∗ s t r i n g , addr
SCTPAddr , s i d i n t , ssn i n t , p p i d i n t , a i d i n t ,err error )Creating and binding of the socket : The sequence diagramin figure 9 gives an overview of how a socket is created andbind to. At point 1.1.3 in this figure net.internetSocket() returns
a socket descriptor which is used to create the actual SCTP
connection type. At this point the SCTP initialization structure
is set to its default values together with the NODELAY socket
option. The ’no delay’ socket option disables buffering ofbytes sent over the connection. This is also the default setting
for the TCP implementation in Go.
VI. A NALYSIS
A. Performance
For performance testing a client-server application was
designed, with the client sending messages and the server
receiving them. Both a C and a Go version of this application
were created and compared and run against each other. The
data throughput of an SCTP client-server application written in
Go is approximately twice as high as the same program written
in C. Most of the delay happens in the Go client. Unlike the C
implementation, the Go application needs to go through some
additional method calls before it reaches the system call which
sends the data. Go is also garbage-collected, which causes anextra delay because several data structures are redeclared eachtime a message is sent. Another factor to consider is that theimplementation of SCTP in Go is against version 1.0.2 of
Go. This version does not have a compiler which is good at
optimizing. Newer versions of Go address this issue.

During implementation there were two major changes thatcaused unexpected setbacks. The first, as previously mentioned, was the changing SCTP socket API, which made large
parts of the implementation already in place obsolete, forcing
me to rewrite the majority of the implementation. The second
issue was the first official release (1.0) of Go. Until that release
I had sporadically synchronized my version of Go with thelatest changes of the main development tree of the canonical
Go source code repository. Building up to the official release
the Go development team did a considerable amount of work.
With the 1.0 release a large number of changes had to beincorporated into my own branch. As there were many changes
to the internals of Go, this resulted in many merge conflicts
in certain areas, specifically around the implementation of thegeneric Dial and Listen interfaces. Most of the work in thisarea had to be redone.
D. Extensions
There are many extensions to SCTP described in multiple
RFCs. A complete SCTP implementation should include (author?) [9]:1) RFC4960 (basic SCTP)
2) RFC3758 (partial reliability)
3) RFC4895 (authentication)4) RFC5061 (dynamic addresses)
The last three in this list are not included in this implementation.
VII. C ONCLUSION
Because of its similarity to existing protocols available
in the Go networking library, SCTP fits easily into it. The
biggest challenges of this project were the ongoing work on
the SCTP specification and Go itself which made successful
implementation a moving target. More recently (mid-way2012) the APIs of Go and SCTP have been stabilized. It
should be noted however that there are many extensions to
SCTP described in multiple RFCs. The work in this paper
only looks at the bare minimum needed to make SCTP workin Go.

A PPENDIX

A. Future work
A. Conn interface
User land implementation of SCTP in Go: Not all operating
systems support the SCTP protocol natively. It is however
possible to have SCTP running on top of the UDP protocol,
outside the kernel (user land). To make this work a user land
implementation of SCTP on top of UDP needs to be added
to Go. Once this is done SCTP could become available on all
different platforms supported by the Go language.

type Conn i n t e r f a c e {Read ( b [ ] byte ) ( n i n t , e r r e r r o r )W r i t e ( b [ ] byte ) ( n i n t , e r r e r r o r )Close ( ) e r r o rLocalAddr ( ) Addr
RemoteAddr ( ) Addr
SetDeadline ( t t i m e . Time ) e r r o r
SetReadDeadline ( t t i m e . Time ) e r r o r
S e t W r i t e D e a d l i n e ( t t i m e . Time ) e r r o r}

B. PacketConn interface
R EFERENCES
type PacketConn i n t e r f a c e {ReadFrom ( b [ ] byte ) ( n i n t , addr Addr , e r r e r r o r )[1] WhyweneedgoOReilly
radar.
http://radar.oreilly.com/2012/09/golang.html.
[2] R. Braden. Requirements for internet hosts - communication layers. http://tools.ietf.org/html/rfc1122.
[3] C. A. R. Hoare. Communicating sequential processes.
Communications of the ACM, 21(8):666–677, August
1978.
[4] Janardhan R. Iyengar, Paul D. Amer, and Randall Stewart. Concurrent multipath transfer using SCTP multihoming over independent end-to-end paths. IEEE/ACM
Trans. Netw., 14(5):951–964, October 2006.
[5] B. Penoff, A. Wagner, M. Tuxen, and I. Rungeler.
Portable and performant userspace SCTP stack. In 2012
21st International Conference on Computer Communications and Networks (ICCCN), pages 1 –9, August 2012.
[6] Rob Pike. command center: Less is exponentially more.
http://commandcenter.blogspot.co.uk/2012/06/less-isexponentially-more.html, June 2012.
[7] W. Richard Stevens, Bill Fenner, and Andrew M. Rudoff.
Unix Network Programming: Sockets Networking API v.
1. Addison Wesley, 3 edition, November 2003.
[8] R. Stewart.
RFC 4960 - stream control
transmission
protocol,motivation.
http://tools.ietf.org/html/rfc4960#section-1.1.
[9] Randall Stewart, Michael Tuexen, and Peter Lei. SCTP:
what is it, and how to use it? BSDCan 2008, 2008.
[10] Randall R. Stewart and Qiaobing Xie. Stream Control
Transmission Protocol (SCTP): A Reference Guide. Addison Wesley, 1 edition, October 2001.
[11] Michael Tuexen, Salvatore Loreto, and Randell
Jesup.
RTCWebdatagramconnection.
http://tools.ietf.org/html/draft-ietf-rtcweb-data-channel00.

WriteTo ( b [ ] byte , addr Addr ) ( n i n t , e r r e r r o r )Close ( ) e r r o rLocalAddr ( ) Addr
SetDeadline ( t t i m e . Time ) e r r o r
SetReadDeadline ( t t i m e . Time ) e r r o r
S e t W r i t e D e a d l i n e ( t t i m e . Time ) e r r o r}

C. Listener interface
type L i s t e n e r i n t e r f a c e {Accept ( ) ( c Conn , e r r e r r o r )Close ( ) e r r o rAddr ( ) Addr}

D. Socket IO function definitions s i z e _ t sendmsg ( i n t s , const s t r u c t msghdr ∗msg , i n t f l a g s )s s i z e _ t recvmsg ( i n t s , s t r u c t msghdr ∗msg , i n t f l a g s )E. Message header structure and ancillary datas t r u c t msghdr {void∗msg_name ;/∗socklen_t
msg_namelen ;/∗s t r u c t i o v e c ∗msg_iov ;/∗int
msg_iovlen ;/∗void∗ msg_control ;/∗socklen_t
msg_controllen ; /∗int
msg_flags ;/∗};The msg_control argument,
msg_controllen,
pointstoao p t i o n a l address ∗ /s i z e o f address ∗ /s c a t t e r / gather array ∗/# elements i n msg_iov ∗ /a n c i l l a r y data ∗ /a n c i l l a r y data b u f f e r l e n ∗ /f l a g s on message ∗ /whichbufferhasforlengthotherFigure 8: TCP Client setting up connection

net.Dial()

1:

net.resolveNetAddr()

net.ResolveTCPAddr()

net.dialAddr()

net.DialTCP()

net.internetSockets()syscall.socket()

1.1:
1.1.1:

1.1.2: TCPAddr
1.2: Addr

1.3:
1.3.1:
1.3.1.1:
1.3.1.1.1:

1.3.1.1.2: int

1.3.1.2: netFD
1.3.2: TCPConn

1.4: Conn

Figure 9: Creating and bind

net.ListenPacket()1:

net.ListenSCTP()

net.internetSocket()net.socket()syscall.Socket()syscall.socket()

1.1:
1.1.1: resolve address
1.1.2:

1.1.2.1:
1.1.2.1.1:

1.1.2.1.1.1:
1.1.2.1.1.2:

1.1.2.1.2:
1.1.2.1.3:

1.1.2.1.4:

1.1.3:
1.1.4: listen
1.1.5:

1.1.2.2:

syscall.Bind()protocol control related messages or other miscellaneous ancillary data. The messages are of theform:s t r u c t cmsghdr {s o c k l e n _ t cmsg_len ;/ ∗ data b y t e count , i n c l u d i n g hdr ∗ /int
cmsg_level ; / ∗ o r i g i n a t i n g p r o t o c o l ∗ /int
cmsg_type ;/ ∗ p r o t o c o l −s p e c i f i c t y p e ∗ // ∗ f o l l o w e d by u_char cmsg_data [ ] ; ∗ /};