2012年11月28日星期三

3310 Computer Network(4)



The main task for this week is a project in which we need to write a short program to implement the function of transmission between two entities, (ie. Two computers with different IP address named Robot and Student respectively) using two different transmission layer protocols – TCP and UDP. What’s more, for the bonus, we need to extend the program to implement the function that measures the different throughput for different receiver buffer size. The foal of the task is to help us get familiar with the usage of socket programming as well as some important properties of sending and receiving data such as buffer size and how port works as well.
To design the program, the most important part is to understand how the connection procedure and properties should be in either TCP or UDP protocols. In the past lecture, we should have known that the procedures for these two transmission modes should be like:




   
Figure 1 : functions flow of connection-oriented socket and connectionless Socket

     Implementing the functions shown above and we can accomplish our basic goal. Besides, there also have some detailed staff that we should take care of.
First of all, when considering the structure object sockaddr_in, it is describing and identifying the socket address family of either the server or the client such as IP address and port number for the socket.
For example, the definition of the family address in the program for the robot is like:

Figure 2 , address family of robot in the program

Secondly, for TCP socket, it is a stream socket which does not preserve message boundary, so in order to avoid the situation that the buffer load the information before all the data is correctly received, a loop is needed for receiving data in TCP protocol. It is the same for the sending procedure. Take the codes of receiving as an example, it is like :
                 Figure 3 The loop for TCP socket receiving
                
     Thirdly, in the bonus part, we need to let the robot continuing sending packets to the destination, lasting for 30 seconds. To solve this problem, a time function is needed, clock_t determines a variable corresponding to a certain time, in the mean time function clock() will return the current time from the computer. By using these two properties and a loop, the continuous sending procedure can be done. In the program, it is like:
   
         Figure 4 Codes fort he big packets transmission part


Through the programming project, though it is a hard and tiring work, my understanding of this course has been deeply developed. Although it is just a tiny little part of computer network, it stands for what is the work procedure like for the engineer to develop and implement those theories we are talking in the class. To discuss a method, or a tactic a easy, but to implement it is a not a easy work, which would always requires for deeply understanding and cautious habits.


TOPIC :Introduciton of Two Functions
In the project, one requirement is to find out the initial receiving buffer size and in addition to modify its value to see how the buffer size would effect the throughput. To accomplish this task, we need two functions which are included in the "winsock2.h" .They are getsockopt() and setsockopt() respectively.
For the function getsockopt(), it’s used to get the information in the socket bind by the user. It’s structure is as the figure shown below:
where:
sockfd : is the description the socket, it should be pointed to the socket
 you are willing to execute.

level :  is determine for the options of the socket, there exit
two levels that are SOL_SOCKET and IPPROTO_TCP.
   optname: the option that the user need to get from the socket
   optval : a pointer that points to the buffer location of the option value.
   optlen : a pointer that points to the length of the buffer area

For the function setsockopt(), it’s used to set the value in the socket bind by the user. It’s structure is as the figure shown below:
where:
sockfd : is the description the socket, it should be pointed to the socket
 you are willing to execute.
level :  is determine for the options of the socket, there exits four levels
which are SOL_SOCKET, IPPROTO_TCP, IPPROTO_IP and IPPROTO_IPV6
 optname: the option that the user need to get from the socket
 optval : a pointer that points to the buffer location of the option value.
 optlen : a pointer that points to the length of the buffer area
    By using these two functions, we can get the information that the default receive buffer size is 8192 bytes. Once the user increase or decrease the buffer size, it can be seen that the throughput of the packets would increase and decrease in pace with the buffer size.

2012年11月8日星期四

3310 Computer Network(3)


3310 Computer Network(3)


    The main topic the course recently talking about is the peer-to-peer protocols, which contains Service Models and ARQ.A Service Model in a given layer specifies the manner in which information is transferred. There are two broad categories of service models: connection oriented and connectionless. In connection-oriented services a connection setup procedure precedes the transfer of information while connectionless do not involve a connection setup procedure.

Figure-1 Connection-oriented transfer service

Figure-2 Connectionless transfer service
    ARQ protocols includes Stop-and-Wait ARQ, Go-Back-N ARQ and Selective Repeat ARQ. The finite state machine (FSM) diagram of the above three ARQ protocols are as following:


Figure-3 Sender and Receiver Algorithms of Stop-and-Wait ARQ


              
               Figure-4 Sender and Receiver Algorithms of Go-Back-N ARQ


Figure-5 Sender and Receiver Algorithms of Selective-Repeat ARQ

    Also, we begin to learn some kinds of procedures and methods to measure the delay time, throughput and efficiency of the network transmission. For all these methods, we have certain assumptions respectively.
    In this section, I come to realize the details about how some of the network protocols work and how people gradually develop them. As we consider peer-to-peer protocols and the services the provide, they are trying to set up the interaction of two or more processes or entities through the exchange of PDUs. In order to accomplish this goal and also considering the cost and so on, different ideas show up and gradually improve the efficiency of network communication. This is also the way for us to research for developing faster, more reliable and efficiency achievements in the future. It is also the fundamental job for an engineer.






TOPIC : Comparison Between ARQ Protocols

Stop-and-Wait ARQ : works well on channels that have low propagation delay. However, the protocol becomes inefficient when the propagation delay is much greater than the time to transmit a frame.


Go-Back-N ARQ : Go-Back-N ARQ is efficient than Stop-and-Wait when the channels are long and as well the error rate is low.



Selective Repeat ARQ: It is the most efficient of the ARQ protocols as it uses the minimum number of retransmissions. However, if the window size is too small, then the transmitter may run out of sequence numbers from time to time and the efficiency will then reduced.

The relationship between transmission efficiency of ARQ Protocols among these ARQs are shown below :



                    
                     Figure-6 Transmission efficiency of ARQ Protocols

                    (where p is the frame error rate )






What’s else, the relationship between the frame size and the efficiency is like:





           Figure-7  Transmission efficiency of ARQ Protocols(frame size)

        -- Where p equals to 1.E-04.