views:

447

answers:

7

As a part of a personal project, I am making an application level protocol (encapsulated in UDP) which is reliable.

For the implementation of reliability, I have to keep track of which packets i send, and which packets are received at the other receiver end. This is done with the help of a sliding window, and it also maintains the flow-control.

  1. Is there a way to implement reliability apart from standard sliding window/flow control technique.
  2. If No, will someone share his experience/design rationale/code and discuss it over this post.
  3. If Yes, have you implemented it, or if you know any implementation of the concept.
A: 

It might be a better approach to maintain local state in the UDP applications to check that necessary data has been transferred for confirming reliability -- rather than, trying to do complete packet level reliability and flow-control.

Trying to replicate reliability and flow-control mechanisms of TCP in a UDP path is not a good answer at all.

nik
A: 

I sort of agree with Nik on this one, it sounds like you're using UDP to do TCP's job, reliable transmission and flow control. However, sometime's their are reasons to do this yourself.

To answer you're questions, there are UDP based protocols that do reliable transmission and don't care much about ordering, meaning only dropped packets have a performance penalty for making it to the destination (by requiring retransmission).

The best example of this we use daily is a protocol called RADIUS, which we use for Authentication and Accounting on our EVDO network. Each packet between the source and destination get's an identifier field (radius only used 1 byte, you may want more), and each identifier needs to be acked. Now Radius doesn't really use the concept of a sliding window since it's really just a control plane traffic, but it's entirely viable to use the concept from TCP. So, because each packet needs to be acked, you buffer copies of outgoing packets until they are acked by the remote end point, and everyone is happy. Flow control can use feedback from this acknowledgement mechanism to know it can scale up/down the rate of packets, which may be most easily controlled by the size of the list you have for packets transmitted but awaiting acknowledgement.

Just keep in mind, there are literally decades of research into the use of sliding window and adjustments to TCP/IP stacks around packet loss and the sliding window, so you may have something that works, but it may be difficult to replicate the same thing you get in a highly tweaked stack on a modern OS.

The real benefit to this method is you need reliable transport, but you really don't need ordering, because you're sending disjoint pieces of information. This is where TCP/IP breaks down, because a dropped packet stop all packets from making it up the stack until the packet is retransmitted.

Kevin Nisbet
+2  A: 

It's sad that the TCP/IP stack doesn't include a reliable datagram protocol, but it just doesn't. You can search for lots of attempts and proposals.

If this is a personal project, your time is probably the most scarce resource, and unless your goal is to reinvent this particular wheel, just build your protocol on top of TCP and move on.

Norman Ramsey
A: 

You could have a simple Send->Ack protocol. For every packet you require an Ack before proceding with the next (Effectivly this is windows size = 1 packet - which I wouldn't call a sliding window :-)

nos
yes, thats fine, rather i can also have a window of size say 5 to better throughput, but for ultimate throughput from sender i would need a max window, and for maximum throughput of the network i would need a congestion window. i am confused what to do
Vivek Sharma
A: 

You could have something like the following:

Part 1: Initialization

1) Sender sends a packet with the # of packets to be sent. This packet may require some kind of control bit to be set or be a different size so that the receiver can distinguish it from regular packets.

2) Receiver sends ACK to Sender.

3) Repeat steps 1-2 until ACK received by Sender.

Part 2: Send bulk of data

4) Sender then sends all packets with a sequence number attached to the front of the data portion.

5) Receiver receives all the packets and arranges them as specified by the sequence numbers. The receiver keeps a data structure to keep track of which sequence numbers have been received.

Part 3: Send missing data

6) After some timeout period has elapsed with no more packets received, the Receiver sends a message to the Sender requesting the missing packets.

7) Sender sends the missing packets to the Receiver.

8) Repeat steps 6-7 until Receiver has received all required packets.

9) Receiver sends a special "Done" packet to the Sender.

10) Sender sends ACK to Receiver.

11) Repeat steps 10-11 until ACK is received by Receiver.

Data Structure There are a few ways the Receiver can keep track of the missing sequence numbers. The most straight-forward way would be to keep a boolean for each sequence number, however this will be extremely inefficient. You may want to keep a list of missing packet ranges. For example, if there are 100 total packets, you would start with a list with one element [(1-100)]. Each time a packet is received, simply increment the number on the front of that range. Let's say you receive packets 1-12 successfully, miss packets 13-14, received 15-44, miss 45-46, then you end up with something like: [(13-14), (45-46)]. It would be quite easy to put this data structure into a packet and send it off to the Sender. You could maybe make it even better by using a tree instead, not sure.

MahlerFive
@MahlerFive -- 1. By definition SACK implementation is complicated and is useful when you have large buffers, I have to investigate why? 2. How would tree fit in here, it would be interesting to see if it works. 3. I was thinking of making a circular queue of elements as, pointer to the packet, seqno and bool as a Data-Structure, and implementing a cummulative Ack system. Do you think if this is enough/efficient. Please if you other idea, i would be pleased.
Vivek Sharma
A: 

After reading all these answers, learning from other implementations and reading some papers, I am writing/sharing what is most pertinent. First let me talk about Flow control, and later i will talk about reliability.

There are two kinds of flow control--

  • Rate based -- Packets Transmission is done in a timely manner.
  • Window based -- The Standard Window based, can static or dynamic (sliding window).

Rate Based flow controls are difficult to implement, as they are based on RTT(round trip time -- its not as simple as ping's RTT) calculation. If you decide on providing a proprietary congestion control system, and you are providing it from present release, then you can go for rate-based flow control. Explicit congestion control is also there which is router dependent,so its out of picture.

Window based flow control, a window is used to keep track of all the sent packet, until the sender is sure that receiver has received them. Static window is simple to implement but throughput will be miserable. Dynamic window (also know as sliding window) is a better implementation, but a little complex to implement, and depends on various kind of Acknowledgement mechanisms.

Now Reliability...

Reliability is making sure the receiver has received your packet/information. Which means that receiver has to tell the sender, yes I got it. This notification mechanism is called Acknowledgement.

Now one ofcourse needs throughput for the data transfered also. So you should be able to send as many packets as you can, rather MAX[sender's sending limit, receiver's receiving limit], provided you have available bandwidth at both the ends, and throughout the path.

If you combine all the knowledge, although reliability and flow control are different concepts, but implementation wise the underlying mechanism is best implemented, when you use a sliding windows.

so finally in short, I and anyone else if designing a new app protocol and needs it to reliable, sliding window shall be the way to achieve it. If you are planning to implement congestion control then u might as well use a hybrid(window+rate based) approach (uDT) for example.

Vivek Sharma
A: 

You might want to look at SCTP - it's reliable and message-oriented.

Andrew Y