<<

BEFN$?FN DCCP

;\m\cfg`e^dlck`d\[`XXggc`ZXk`fejn`k_;::G :FE>

8eeX#=fkfc`X The DCCP protocol gives multimedia developers a powerful alternative to TCP and UDP. BY LEANDRO MELO DE SALES

ver the past few years, develop- In this article, I examine the DCCP DCCP inherits the connection-oriented ers have unveiled a new genera- protocol and show how to enable DCCP and congestion-control features from Ftion of network applications that in . Also, I will explain how to use TCP, and, from UDP, DCCP inherits unre- transmit and receive multimedia content the GStreamer DCCP plugin to create a liable transmission. over the Internet. New multimedia appli- simple client-server DCCP application. In addition to connection-oriented and cations based on technologies such as DCCP was first introduced by Kohler congestion-control features, TCP provides Voice over IP, Internet radio, online gam- et al. in July 2001 at the IETF transport reliable data transfer. This reliability fea- ing, and video conferencing are becom- group. The DCCP protocol provides spe- ture limits the transmission rate for a ing increasingly popular thanks to the cific features designed to address some given connection. When packets are lost, availability of development libraries and of the problems developers have faced TCP decreases its transmission rate, and it the abundance of high-speed networks. writing multimedia applications with increases the transmission rate again In the past, most Internet applications TCP and UDP, such as delay and jitter when it sends packets successfully. To have used either the Transmission Con- caused by network congestion. DCCP implement reliable data transfer, when trol Protocol (TCP) or the User Datagram offers a connection-oriented transport TCP loses packets, it retransmits them. In Protocol (UDP) to manage communica- layer for congestion-controlled but unre- this case, new data generated by the ap- tion at the Transport layer of the TCP/ IP liable data transmission. Also, DCCP plication is queued until all lost packets protocol stack, but multimedia develop- provides a framework that enables the are sent. Because of this way of imple- ers now have an alternative to TCP and addition of new congestion-control menting reliable data transfer, TCP might UDP. IETF recently standardized the mechanisms, either added during the lead to a high level flow delay. Conse- Datagram Congestion Control Protocol connection handshake or negotiated quently, the user might experience inter- (DCCP) (RFC4340) [1], a new transport during an established connection. DCCP ruptions in multimedia content. protocol designed to transmit conges- also provides a mechanism for getting On the other hand, UDP is a simple tion-controlled multimedia content. connection statistics, a congestion-con- protocol, implementing minimal func- DCCP is becoming very popular for trol mechanism with Explicit Congestion tions to transport data from one com- multimedia data transmission, mainly Notification (ECN) support, and a puter to another. It is a connectionless because it is more effective than UDP at method for Path Maximum Transmission protocol and does not care about data sharing the available bandwidth. Unit (PMTU) discovery. packet delivery or network congestion

56 ISSUE 93 AUGUST 2008 DCCP BEFN$?FN

control. Also, UDP does not provide 4341) [3] is better for applications that gestion-control mechanisms, making it packet reordering on the receiver end. use the maximum bandwidth available more suitable for applications such as Because of the lack of any type of con- at the network, but it can easily be telephony or streaming media, for which gestion control, UDP might lead to net- adapted to sudden bandwidth changes. a relatively smooth sending rate is work congestion collapse. Hence, a UDP It is similar to TCP congestion control, important. application can send data as much as it which is based on the congestion win- wants, but much of this data might be dow concept. The congestion window J\kLgk_\

AUGUST 2008 ISSUE 93 57 BEFN$?FN DCCP

In both cases, git-clone will take a while kernel options; DCCP is enabled under all connections started by DCCP. Note to fetch the kernel source from over the the Networking option as follows: that you also can specify these parame- network. While you wait for the end of ters through a programming language the fetch process, you can read about Networking --> using the setsockopt socket function. DCCP on Linux wiki [7] to learn more Network options --> about DCCP. Once git has downloaded The DCCP Protocol --> K\jk`e^;::G the Linux kernel containing the latest IPerf is a network measurement tool that available version of DCCP, enter in the Inside this option, you can specify the was originally designed to work over newly created directory (in my example, CCIDs and some other DCCP options. TCP and UDP. But thanks to a patchset the my_dccp directory) and check out After you select everything you need, provided by Gerrit Renker, it also sup- the DCCP branch: just compile the kernel using instruc- ports the DCCP protocol, wherein you tions specified in the documentation [8]. can run it as a DCCP client or a server. git-checkout --track -b 5 After you load your new compiled ker- To use IPerf with DCCP support, first dccp origin/dccp nel, you can switch between the CCIDs download and install IPerf [9]. If you are and change the sequence window num- lucky, the process of compiling and in- This command will effectively give you ber by running the following commands: stalling is straightforward with the make the latest changes of the DCCP source and make install procedures. The site code. For future updates of the DCCP sudo sysctl -w 5 source code, run the following command net.dccp.default.seq_window=1000 Listing 4: GStreamer Bus in the source folder: sudo sysctl -w 5 (gst_dccp_server.) net.dccp.default.rx_ccid=2 01 static gboolean bus_event_ git-pull git://5 sudo sysctl -w 5 callback (GstBus *bus, eden-feed.erg.abdn.ac.uk/5 net.dccp.default.tx_ccid=2 GstMessage *msg, gpointer dccp_exp dccp data){ This set specifies 1000 as the sequence 02 The dccp argument is not a folder; it is window and CCID-2 in both directions for the branch previously created with git- 03 GMainLoop *loop = (GMainLoop *) data; checkout. Listing 3: Initializing (gst_ Now that you have the Linux kernel dccp_server.c) 04 05 switch (GST_MESSAGE_TYPE source code with the latest changes of 01 #include the DCCP subtree, you’ll need to set up (msg)) { 02 #include the kernel according to your machine 06 case GST_MESSAGE_EOS: 03 #include archi tecture. Inside the kernel source 07 g_print directory, the Linux kernel configuration 04 ("End-of-stream\n"); is described in the .config file. You can 05 int main (int argc, char 08 g_main_loop_quit change this configuration both from **argv) { (loop); make menuconfig or by directly editing 06 GMainLoop *loop; 09 break; the .config file. To determine what Linux 07 GstElement *pipeline, 10 case GST_MESSAGE_ERROR: { modules are up, use lsmod, and use lspci *filesrc, *mp3parse, 11 gchar *debug; to get a list of devices. Additionally, look *dccpserversink; 12 GError *err; in your hardware documents and vendor 08 GstBus *bus; 13 gst_message_parse_ support. For more on compiling the ker- 09 nel, refer to the Linux kernel documenta- error (msg, &err, &debug); 10 /* initialize GStreamer */ tion [8]. 14 g_free (debug); 11 gst_init (&argc, &argv); If you are familiar with the Linux ker- 15 g_print ("Error: nel compilation process, use the menu- 12 loop = g_main_loop_new %s\n", err->message); (NULL, FALSE); config mechanism to specify the Linux 16 g_error_free (err); 13 17 g_main_loop_quit Installing the GStreamer 14 /* check input arguments (loop); */ DCCP Plugin 18 break; 15 if (argc != 3) { The DCCP plugin for GStreamer is part 19 } of the DCCP and E-Phone project for the 16 g_print ("Usage: %s 20 default: Nokia maemo platform [11]. After you port mp3file_location\n", have downloaded the plugin [12], run argv[0]); 21 break; the following commands: 17 return -1; 22 } ./autogen --prefix=/usr 18 } 23 make 19 return 0; 24 return TRUE; make install 20 } 25 }

58 ISSUE 93 AUGUST 2008 DCCP BEFN$?FN

also provides useful information on IPerf with DCCP. To test DCCP, set a server with the following arguments:

iperf -s -d -l 1424 -i 1

This command tells IPerf to open a DCCP connection (-d option) and to act =`^li\(1>Jki\Xd\iG`g\c`e\n`k_k_i\\\c\d\ekj1X]`c\i\X[\i#XeDG*\eZf[\i#Xe[X;::G as a server (-s option). The server will kiXejd`kk\i% transmit data packets of size 1424 bytes (-l 1424), and it will output reports about function – such as encoding, displaying, reading data from a DCCP socket and the transmission every one second. To or rendering data – as well as the ability pushing it into the pipeline, and the sink run an IPerf client that will connect to to read from or write to files. By combin- elements (dccpserversink and dccpclient- the specified server, execute the follow- ing and linking those elements, the pro- sink) are responsible for receiving data ing command: grammer can build a pipeline for per- from the pipeline and writing it to a forming more complex functions. For ex- DCCP socket. iperf -c SERVER_IP -d -l 5 ample, it is possible to create a pipeline The dccpserversrc and the dccpserver- 1424 -i 1 -t 100 for reading from an MP3 file, decoding sink elements behave as the server, but its contents, and playing the MP3. only dccpserversink can transmit and The -c option specifies the server IP, and Figure 1 represents a GStreamer pipe- only dccpserversrc can receive data. -t specifies the duration of the transmis- line composed by three elements. Data When the server element is initialized, it sion, in seconds. For a quick introduction flows from Element 1 to Element 2 and stays in a wait mode, which means the to DCCP, consider a simple Python appli- finally to Element 3. Element 1 is the plugin is able to accept a new connec- cation that sends hello world to a remote source element, which is responsible for tion from a client element. The dccpcli- application. The Python DCCP server providing data to the pipeline, whereas entsink element can connect to dccp- code is shown in Listing 1, and the Py- Element 3 is responsible for consuming serversrc, and dccpclientsrc can connect thon DCCP client is in Listing 2. data from the pipeline. Between the to dccpserversink. In line 7 of Listing 1, the socket instan- source element and the sink element, If you want to send data from the tiation is done using the values of socket. the pipeline is permitted to use other ele- server to the client, you need to use SOCK_DCCP and socket.IPPROTO_DCCP. ments, such as Element 2 (shown in Fig- dccpclientsrc and dccpserversink ele- socket.IPPROTO_DCCP is equal to 33, ure 1). These intermediary elements are ments. To send data from the client to which is the number allocated to the responsible for processing and modify- server, you need to use the dccpclient- DCCP protocol by IANA (Internet As- ing the content as the data passes along sink and dccpserversrc elements. signed Numbers Authority). The other the pipeline. GStreamer’s gst-launch command lines are very similar to an implementa- We developed the DCCP plugin for supports the creation of pipelines, and tion of a TCP socket connection. The GStreamer to deal with data transmission it is also used to debug plugins. client in Listing 2 connects to the DCCP using the DCCP protocol. This plug-in has server implemented in Listing 1. four elements: dccpserversrc, dccpserver- Listing 6: Verifying Now that the server and client are sink, dccpclientsrc, and dccpclientsink. Elements communicating, it is time to add some The source elements (dccpserversrc 01 if (!pipeline || !filesrc additional multimedia features through and dccpclientsrc) are responsible for || !mp3parse || the GStreamer framework. !dccpserversink) { GStreamer is an open source multime- Listing 5: GStreamer 02 g_print ("One or more dia framework that allows the program- Elements elements could not be mer to write many types of streaming 01 /* defining elements */ instantiated\n"); multimedia applications [10]. Many 03 return -1; well-know applications use GStreamer, 02 pipeline = gst_pipeline_ new ("dccp-audio-sender"); 04 } such as Kaffeine, Amarok, Phonon, , and Totem. The GStreamer 03 filesrc = gst_element_ framework facilitates the process of writ- factory_make ("filesrc", Listing 7: Setting "file-source"); ing multimedia applications, ranging Parameters from audio and video playback to 04 mp3parse = gst_element_ 01 g_object_set (G_OBJECT streaming multimedia content. factory_make ("mp3parse", "mp3parse"); (dccpserversink), "port", atoi(argv[1]), NULL); ;::G>Jki\Xd\iGcl^`e 05 dccpserversink = gst_ GStreamer is a plugin-based framework, element_factory_make 02 g_object_set (G_OBJECT ("dccpserversink", and each plugin contains elements. Each (filesrc), "location", "server-sink"); of these elements provides a specific argv[2], NULL);

AUGUST 2008 ISSUE 93 59 BEFN$?FN DCCP

The basic syntax is: the input to the next specified plugin and Ubuntu. Once you perform the element. GStreamer installation, the last step is to gst-launch 5 As an example of the gst-launch com- compile and install the DCCP Plugin for 5 mand, consider two pipelines to transmit GStreamer (see the box titled “Installing 5 an MP3 stream over the network with the GStreamer DCCP Plugin”). ! 5 DCCP: One works as a DCCP server that The following gst-launch example runs ! 5 streams an MP3 audio file, and the sec- a server accepting DCCP connections. 5 ond pipeline is associated with a DCCP Once a client connects, the server starts ... client that connects to the remote DCCP to stream the audio file named yourmu- server and reproduces the audio content sic.mp3. Note that you can specify the Note the ! character that links the plug- transmitted by the server. CCID with the ccid parameter. in elements, which is similar to the char- To make the example work, you must acter “|” in the Linux shell prompt. This install GStreamer. In this case, you need gst-launch -v filesrc 5 means that the output of an element is the GStreamer-Core, Gst-Base-Plugins, location=yourmusic.mp3 5 and Gst-Ugly-Plugins packages. Do not ! mp3parse ! dccpserversink 5 Listing 8: Attaching bus_ worry about the GStreamer installation; port=9011 ccid=2 event_callback GStreamer is a widely used framework 01 bus = gst_pipeline_get_ available in many Linux package sys- This pipeline initializes the server in bus (GST_PIPELINE (pipeline)); tems for a variety of distributions, such DCCP port 9011. The server will be wait- as Debian, Gentoo, Mandriva, Red Hat, ing for a client to connect to it. When 02 gst_bus_add_watch (bus, bus_event_callback, loop); 03 gst_object_unref (bus); Listing 10: DCCP Client Application (continued on p62) 01 #include 25 break; 04 02 #include 26 } 05 gst_bin_add_many (GST_BIN (pipeline), filesrc, mp3parse, 03 #include 27 dccpserversink, NULL); 04 28 return TRUE; 06 /* Link the elements at 05 static gboolean bus_event_ 29 } the pipeline */ callback (GstBus *bus, 30 GstMessage *msg, gpointer data) 07 gst_element_link_many 31 int main (int argc, char *argv) { (filesrc, mp3parse, { dccpserversink, NULL); 06 32 GMainLoop *loop; 07 GMainLoop *loop = 33 GstElement *pipeline, (GMainLoop *) data; Listing 9: Executing the *dccpclientsrc, *decodebin, Pipeline 08 *alsasink; 01 /* Now set to playing and 09 switch (GST_MESSAGE_TYPE 34 GstBus *bus; (msg)) { iterate. */ 35 10 case GST_MESSAGE_EOS: 02 g_print ("Setting to 36 /* initialize GStreamer */ 11 g_print PLAYING\n"); 37 gst_init (&argc, &argv); ("End-of-stream\n"); 03 gst_element_set_state 38 loop = g_main_loop_new 12 g_main_loop_quit (pipeline, GST_STATE_ (NULL, FALSE); (loop); PLAYING); 39 13 break; 04 g_print ("Running\n"); 40 /* check input arguments */ 14 case GST_MESSAGE_ERROR: { 05 g_main_loop_run (loop); 41 if (argc != 3) { 15 gchar *debug; // start the GStreamer main 42 g_print ("Usage: %s 16 GError *err; loop serverHost serverPort\n", 17 gst_message_parse_error 06 argv[0]); (msg, &err, &debug); 07 /* clean up nicely */ 43 return -1; 18 g_free (debug); 44 } 08 g_print ("Returned, 19 g_print ("Error: %s\n", 45 stopping playback\n"); err->message); 46 /* create elements */ 09 gst_element_set_state 20 g_error_free (err); 47 pipeline = gst_pipeline_ (pipeline, GST_STATE_NULL); 21 g_main_loop_quit new ("audio-sender"); 10 g_print ("Deleting (loop); 48 dccpclientsrc = gst_ pipeline\n"); 22 break; element_factory_make 11 gst_object_unref (GST_ 23 } ("dccpclientsrc", OBJECT (pipeline)); 24 default: "client-source");

60 ISSUE 93 AUGUST 2008 DCCP BEFN$?FN

the connection occurs, the server starts want to use a programming language nouncing the end of the stream or deac- to transmit the MP3 stream using and embed the DCCP plugin into their tivate the GUI stop button when the type CCID-2. The mp3parse element is re- applications. I’ll create the pipeline of the GStreamer bus message is GST_ sponsible for transmitting a stream. To shown in the previous examples, but MESSAGE_EOS. Now comes the most see more information about mp3parse this time through the C programming important part of this example – defining and the other parameters that are avail- language and GObject, a programming the elements and building the GStreamer able, run gst-inspect dccpserversink. library available for GStreamer appli- pipeline. Insert the code shown in List- Next, start the corresponding client: cation and plugin development. ing 5 into the main function (after Start by initializing the GStreamer set- checking the parameter count). gst-launch -v dccpclientsrc 5 tings, as shown in Listing 3. Note that Listing 5 first instantiates a new pipe- host=localhost port=9011 5 Listing 3 also defines GstElements filesrc, line, dccp-audio-sender, which can be ccid=2 ! decodebin ! alsasink mp3parse, and dccpserversink. used for future references in the code. The next step is to instantiate a bus Then the code instantiates the filesrc ele- This GStreamer pipeline initializes the callback function to listen to GStreamer ment with the name file-source. This ele- client and connects to the host localhost pipeline events. A bus is a system that ment will be used to read the specified in port 9011. Once connected, the client takes care of forwarding messages from MP3 file as an argument of the applica- starts to receive the MP3 stream, de- the pipeline to the application. The idea tion. Use the same process to instantiate codes the stream using the decodebin is to set up a message handler on the the elements mp3parse and dccpserver- element, and pipes the stream to the bus that leads the application to control sink. Once all the necessary elements alsasink element, which reproduces the the pipeline when necessary. Put the are instantiated, certify that all are prop- multimedia content in the default audio function shown in Listing 4 above the erly loaded. For this case, proceed as output device. main function defined in Listing 3. shown in Listing 6. Every time an event occurs in the The next step is to set the respective Dlck`d\[`X8ggc`ZXk`fe pipeline, GStreamer calls the gboolean element parameters, as shown in Listing Now it is time to write a complete multi- bus_call function. For example, if you 7. For this application, we need to set media application using the DCCP plug- implement a GUI interface for your ap- two parameters: the port, where the in. The next example is for readers who plication, you can show a message an- server will listen and accept client con- the mathematics of humour

TWELVE Quirky Humans, Over Two Million Geeks around the world can’t be wrong! TWO Lovecraftian Horrors, COME JOIN THE INSANITY! ONE Acerbic A.I., ONE Fluffy Ball of Innocence and TEN Years of Archives EQUALS ONE Daily Cartoon that Covers the Geek Gestalt from zero to infinity!

AUGUST 2008 ISSUE 93 61 BEFN$?FN DCCP

nection from, and the audio file path, To run the gst_dccp_server application, gcc -Wall 5 represented by the parameter location. enter the following command: $(pkg-config --cflags --libs 5 Once all the elements are instantiated -0.10) 5 and the parameters are defined, it is time ./gst_dccp_server 9011 5 gst_dccp_client.c -o 5 to attach the bus callback defined in yourmusic.mp3 gst_dccp_client 5 Listing 4 to the bus of the pipeline. Also, ./ 5 you need to add the elements to the Note that the example uses port 9011, localhost 9011 pipeline and link them (Listing 8). List- which the server will use to open the ing 9 shows how to execute the pipeline. DCCP socket and transmit the stream :feZclj`fe Note that GStreamer runs in a main loop through the network to the remote DCCP I've presented the basic concepts of (line 5). This means that when this main client. DCCP – how to enable DCCP in Linux, loop finishes – for example, when the Now it is time to build a correspond- and how to build a DCCP-based applica- user types Ctrl+C – it is necessary to do ing client application that acts just like tion using the GStreamer DCCP plugin. some clean up (lines 9 and 11). The easi- the gst-launch client command discussed Network analysis and testing applica- est part is to compile the server applica- previously. The DCCP client application tions, such as TTCP, tcpdump, and Wire- tion – just run the following command, is similar to the server application (List- shark already provide support for the which will link the GStreamer libs with ing 10). Basically, you must initialize DCCP protocol, and multimedia tools the example application: GStreamer, check command-line param- such as the open source VLC player ac- eters, instantiate the necessary elements, commodate DCCP streaming. As multi- gcc -Wall $(pkg-config 5 and link them to build the GStreamer media developers become aware of its --cflags --libs 5 pipeline. benefits, you can expect to hear more gstreamer-0.10) 5 Finally, to compile and run the client about DCCP in the coming years. p gst_dccp_server.c -o 5 application, enter the following com- gst_dccp_server mand: INFO [1] RFC 4340: Datagram Congestion Listing 10: DCCP Client Application (continued from p60) Control Protocol (DCCP) 49 decodebin = gst_element_ (dccpclientsrc, decodebin, [2] Leandro M. Sales, Hyggo O. factory_make ("decodebin", alsasink, NULL); Almeida, Angelo Perkusich and Mar- "decodebin"); 65 cello Sales Jr: “On the Performance 50 alsasink = gst_element_ 66 bus = gst_pipeline_get_bus of TCP, UDP, and DCCP over 802.11g factory_make ("alsasink", (GST_PIPELINE (pipeline)); Networks.” In Proceedings of the "alsa-sink"); SAC 2008 23rd ACM Symposium on 67 gst_bus_add_watch (bus, Applied Computing Fortaleza, CE, 51 bus_event_callback, loop); Brazil, pages 2074-2080, 1 2008. 52 if (!pipeline || !alsasink 68 gst_object_unref (bus); || !decodebin || [3] RFC 4341: “Profile for Datagram 69 !dccpclientsrc) { Congestion Control Protocol (DCCP) 70 /* Now set to playing and Congestion Control ID 2: TCP-like 53 g_print ("One or more iterate. */ Congestion Control” elements could not be instantiated\n"); 71 g_print ("Setting to [4] RFC 4342: “Profile for Datagram PLAYING\n"); Congestion Control Protocol (DCCP) 54 return -1; Congestion Control ID 3: TCP- 72 gst_element_set_state 55 } Friendly Rate Control (TFRC)” (pipeline, GST_STATE_PLAYING); 56 [5] RFC 3448: “TCP Friendly Rate Con- 73 g_print ("Running\n"); 57 // set the host and the port trol (TFRC): Protocol Specification” 74 g_main_loop_run (loop); where the server is listening [6] DCCP Git Repository: git://eden-feed. 75 58 g_object_set (G_OBJECT erg. abdn. ac. uk/ dccp_exp (dccpclientsrc), "host", 76 /* clean up nicely */ [7] DCCP on Linux wiki: http:// www. argv[1], NULL); 77 g_print ("Returned, linux-foundation. org/ en/ Net:DCCP 59 g_object_set (G_OBJECT stopping playback\n"); [8] Linux kernel documentation: (dccpclientsrc), "port", 78 gst_element_set_state http:// www. kernel. org/ doc/ atoi(argv[2]), NULL); (pipeline, GST_STATE_NULL); [9] IPerf: http://www. erg. abdn. ac. uk/ 60 79 g_print ("Deleting users/ gerrit/ dccp/ apps/ # iperf 61 /* put all elements in a bin pipeline\n"); [10] GStreamer: */ 80 gst_object_unref (GST_ http:// gstreamer. freedesktop. org/ 62 gst_bin_add_many (GST_BIN OBJECT (pipeline)); [11] Maemo: (pipeline), dccpclientsrc, 81 http:// www. maemo. org/ decodebin, alsasink, NULL); 82 return 0; [12] DCCP plugin for GStreamer: 63 83 } https:// garage. maemo. org/ frs/ ? 64 gst_element_link_many group_id=297

62 ISSUE 93 AUGUST 2008