Friday, November 19, 2010

SIP over TCP and UDP

1. With TCP
- Sender: SIP message is not limited in its size. When user calls system call to send SIP message, this message can be divided into more than 1 TCP segment depending on window size of receiver. Each TCP segment then can be fragmented to more than one IP packets by IP layer. This fragmentation is necessary for sending data through link layer with a particular MTU.
For eg, i want to send 4kB SIP message, so i call send() with input is buffer of this message. The message will be splitted to 2 TCP segments depend on window size at receiver: segment 1 with size of 2,1kB and segment 2 with size of 1,9kB. Then say i use Ethernet interface with MTU is 1500 bytes, so segment 1 is divided into 2 fragments: fragment 1 has size of 1kB, fragment 2 has size of 1,1kB. The same step with segment 2, it will be divided into 2 fragments: one with 1kB and one with 0,9kB. Totally we have 4 IP packets sent through Ethernet interface.

- Receiver: IP layer is in charge of reassemblying IP packets to reproduce the TCP segment. So IP layer returns to transport layer (here is TCP) TCP segments correspond to TCP segments sent from sender.
Kernel then saves that data to kernel's buffer and notify to user by returning recv() or read(). Because a SIP message may be sent used more than 1 segments, receiver may be need to call more than 1 read() to receive all message. So receiver need to check data each time read() return to know the end of message is reached or not.
Return to former example, receiver's IP layer reassembles 2 first packets to reproduce first TCP segment,
then save its data to kernel's buffer. read() then returns to user that data. So user need to check whether he receives all message content or not. If not, he continues calling to read(), wait for second TCP segment come and then check it.

2. With UDP
UDP is datagram protocol, so each time sender call send() or write() with input is buffer to SIP message,
all that SIP message will be contained in UDP datagram before can be fragmented at IP layer. At receiver side, it just calls recv() or read() one time to receive all message. It means that the number of calls to send() at
sender is the same with the number of calls to recv() at receiver.

But unlike TCP, UDP has a limitation in size of data it can transport. So we just can send SIP message with
maximum size of 64kB. And another problem with UDP is if UDP datagram is fragmented by IP layer and any one of these packets lost, receiver has no way to receive all message. So with UDP it is recommended to send SIP message with size lower or equal to (MTU - UDP header - IP header).

5 comments:

  1. Nice blog! Great to have a blog like this which tackles very technical things about computer networking. For those who want to have CCIE Training, this is a very helpful resource to start with.

    ReplyDelete
  2. Thank you for making the effort and spreading this information with all of us. It was indeed very useful and informative while being straight forward and to the point.
    Freeware Software

    ReplyDelete
  3. Thank you for sharing. I just called computer network Lexington to connect all of my devices but found this very helpful.

    ReplyDelete
  4. Thank you for explaining the differences between SIP, TCP, and UDP. I am not tech-savvy whatsoever, so this sounds like Klingon to me, but I still appreciate your explanation. It understood some of it, which means it was written very clearly. I will have to find a computer network services company to help me install and connect everything, so I can try SIP! http://www.portlandcomputercopy.com/home/it-services/

    ReplyDelete
  5. Nice blog! Great to have a blog like this which tackles very technical things about computer networking.


    how to get vine likes

    ReplyDelete