12 minute read

Transport Layer

Application layer와 Network layer 사이에 있는 layer으로 Application layer에게 많은 기능을 제공한다.

Transport Layer 기능들

Process to process communication

Process는 간단히 말하면 실행되고 있는 프로그램으로 transport layer의 service를 사용한다.

그렇다면 host-to-host와 process-to-process communication의 차이점은 무엇일까?

Host-to-host communication

  • Host-to-host communication은 IP address을 기반으로 작동하고 network layer에서 수행된다.

  • 메세지를 process가 실행되고 있는 host, 즉 computer에까지만 전달할 수 있다.

Process-to-Process communication

  • 한 컴퓨터에서는 여러 process들이 동시에 실행되기 때문에 computer 안의 process에 전달되어야 한다.

  • Transport layer는 이를 Port number을 통해 메세지를 process에까지 전달한다.

joowan1108

Addressing: port numbers

최근 computer들은 모두 multi user, multi programming 환경을 지원하기 때문에 두 host 간에 통신을 하기 위해서는 local host, local process, remote host, remote process의 주소를 알아야 한다.

이때, local host와 remote host는 Network layer에서 IP address을 통해 충분히 할 수 있지만, process의 주소까지는 알지 못한다.

이 process의 주소까지 알아내기 위해서는 Port number가 필요하다. TCP/IP protocol에서는 16bit으로 표현된다

joowan1108

Client process의 port number는 ephemeral (임시적)이고 Protocol의 server process의 port number는 미리 정의된 well-known port number을 사용한다.

joowan1108

ICANN* ranges

ICANN : Internet Corporation of Assigned Names and Numbers

ICANN은 Port number을 범위별로 역할을 정해놓았다.

  • 0~1023: Well-known ports

    알려진 application protocol들을 위해 미리 정의된 port number들이다.

  • 1024~49151: Registered ports

    ICANN이 지정한 port number는 아니다.

    중복을 방지하기 위해 ICANN을 통해서 등록이 가능하다

  • 49152~65535: Dynamic ports

    아무런 control이 없다

    임시적인 사용이나 private use 전용 port number들이다.

Encapsulation and decapsulation

Encapsulation은 Application layer에서 오는 message에 추가적인 정보 header을 더하는 과정이다. Sender에서 수행하는 것이다.

Decapsulation은 Application layer에 message을 전달하기 위해 정보를 분해하여 전달하는 과정이다. Receiver에서 수행하는 것이다.

Transport layer에서의 packet은 user datagram / segments 으로 지칭한다.

joowan1108

Multiplexing and demultiplexing

Multiplexing은 여러 process에서 오는 정보를 모두 하나의 network 연결 매체를 통해 보낼 수 있도록 각각 header을 붙이고 모으는 과정이다.

Demultiplexing은 들어온 정보들의 header를 각각 분석하여 해당되는 process들에게 보낼 수 있도록 여러 개로 분리하는 과정이다.

joowan1108

Flow control

Message receiver 측에서 sender에게 신호를 보내서 message의 전달 속도를 조절하도록 도와주는 기능이다.

Sender와 receiver 사이의 message 전달 흐름은 두 가지로 분류된다.

  1. Pushing

    Receiver의 요청이 없었는데도 sender가 정보를 보내는 경우

    Pushing은 sender의 application layer와 transport layer 사이, 그리고 sender의 transport layer와 receiver의 transport layer 사이에서 일어난다.

    강제로 데이터를 주는것이기 떄문에 flow control을 통해 pushing으로 인해 발생하는 data loss을 방지해야 한다.

  2. Pulling

    Receiver의 요청 후에 sender가 정보를 보내는 경우

    Pulling은 receiver의 application layer와 transport layer 사이에서 일어난다.

    이 경우에는 달라고 해서 주는 것이기 떄문에 flow control이 적용되지 않는다.

joowan1108

joowan1108

Flow control을 원활하게 하기 위해서 buffer을 사용해야 한다.

Error control

Tranport layer의 error control은 다음 4가지의 기능을 수핼한다.

  • 오류가 생긴 packet을 탐지하고 버리는 것 Detecting and discarding corrupted packets
  • 버린 packet들을 기억하고 있다가 다시 보내달라고 요청하는 것 Keeping track of lost and discarded packets and resending them
  • 중복인 packet을 탐지하고 버리는 것 Recognizing duplicate packets and discarding them
  • 순서가 맞지 않은 packets을 처리하는 것 Buffering out-of-order packets until the missing packets arrive

joowan1108

Error control을 하기 위해서 IP address와 port number을 제외한 추가적인 정보가 필요하다.

Transport layer는 각 packet에 Sequence numbers을 붙여서 아직 못 온 것이 있는지, 순서에 맞는지, 어떤 packet에 오류가 났는지를 알아낸다.

Sequence number이 범위는 header에서 sequence number을 위해 몇 개의 bit를 허용했는지에 따라 다르다. 만약 m bit라면 sequence number는 0에서 $2^m - 1$의 범위를 가진다.

Receiver는 ACKNOWLEDGE packet을 sender에게 보내서 자기가 어떤 packet을 성공적으로 받았는지를 알려줄 수 있다. 또, sender가 packet을 보낼 때마다 timer을 설정하여 일정 시간 이후에도 ACKNOWLEDGE packet을 받지 못했다면 sender는 손실된 packet이 무엇인지 알 수 있게 되고 이를 다시 전송할 수 있게 된다.

Congestion control

Network 자체에 가해지는 load가 capacity보다 커진다면 congestion이 발생할 수 있다. Congestion이 발생하는 이유는 router/switch 등은 처리할 packet들을 보관하는 자기만의 queue을 갖고 있는데 이 queue을 비우는 속도가 들어오는 속도보다 느려서이다.

Transport layer에서의 congestion은 network layer에서의 congestion의 결과이다.

Connectionless and connection-oriented services

Connectionless

Packet들을 독립적으로 보고 두 host 간의 transport layer가 맞물려서 작동하지 않는다. 따라서 connectionless에서는 sequence number을 필요로 하지 않는다. 이런 이유로 인해 flow control, error control, congestion control을 하지 못한다.

joowan1108

Connection-oriented

Packet들이 서로 관계가 있다고 보기에 sequence number을 사용하고 flow control, error control, congestion control을 한다.

joowan1108

FSM: Finite State Machine

FSM을 사용하면 transport layer을 하나의 state machine으로 해석할 수 있다.

Machine은 event가 발생하기 전까지 항상 어떤 state에 존재한다.

이 event는 두 reaction과 관련이 있다.

  1. 앞으로 할 행동들을 정의하는 것

  2. 다음 state을 결정하는 것

Initial state가 정의되어야 한다

다음은 connection oriented의 FSM이다.

joowan1108

Transport Layer Protocols

Simple Protocol

Flow control, error control 모두 없는 connectionless protocol이다.

Receiver가 어떤 packet을 받든간에 즉시 처리할 수 있다고 간주한다.

joowan1108

joowan1108

Stop and Wait Protocol

Flow control, error control 모두 있는 connection oriented protocol이다.

Sender가 하나의 packet을 보내면 timer을 시작하고 receiver로부터 acknowledgement을 기다린다.

만약에 timer가 끝나기 전까지 acknowledgement가 도착한다면 timer는 종료한다.

Timer가 끝난다면, sender는 직전에 보낸 packet을 다시 보낸다.

Checksum은 전송 과정에서 오류가 나서 값이 바뀐 packet들을 탐지하기 위해 사용된다. 보낸 checksum 값과 받은 checksum 값이 다르다면 corrupted 되었다고 보는 것이다.

Sender의 checksum은 packet의 header에, Receiver의 checksum은 ACK packet에 들어있다.

joowan1108

중복 packet을 방지하기 위해 sequence number와 ACK number을 사용한다.

$\rightarrow$ sequence number가 x인 packet을 보냈다고 하자.

  • Packet이 receiver에게 잘 도착했다면

    ACK는 sender에게 도착하고 sender는 다음 packet인 x+1을 보낸다

  • Packet이 receiver에 도착하지 못했다면

    Sender의 TIMER가 timeout 되고 packet x을 다시 보낸다

  • ACK가 sender에게 도착하지 못했다면

    Sender는 packet x가 잘 못 갔다고 생각하고 packet x을 다시 보낸다

    이때의 packet x은 receiver 입장에서 중복된 packet이다.

이때, acknowledgement number는 receiver가 다음에 받을 것이라고 예상하는 packet number을 의미한다

joowan1108

joowan1108

Stop and wait protocol은 channel의 bandwidth가 크거나 round trip (data가 전송되고 ack packet이 오기까지의 시간)이 길수록 비효율적이다.

Bandwidth(packet을 보낼 수 있는 속도)와 round trip delay(주고 받는데 걸리는 시간)의 곱은 bandwidth delay product (주고 받을 수 있는 bit 수)으로 bandwidth delay product가 클수록 stop and wait protocol은 비효율적이다.

Pipelining

Pipelining은 sender가 receiver에게 이전 packet에 대한 피드백 (ACK)을 받기 전에도 다음 packet을 보낼 수 있는 기능이다.

Stop and wait protocol은 ACK을 받기 전에 그 다음 packet을 보내지 않기 때문에 pipelining이 불가능하다.

하지만 Go back N과 Selective Repeat은 pipelining이 가능하다.

Go Back N Protocol

Go Back N의 핵심은 ACK을 받기 전에 여러 개의 packet을 보낼 수 있지만 receiver는 하나의 packet만 buffer 가능하다는 것이다.

joowan1108

Go back N에서 acknowledgment number는 누적값이면서 receiver가 다음에 받을 것이라고 예측하는 packet sequence number이다. 즉, 예를 들어 acknowledge number가 7이라면 packet 0~6은 다 받았고 7을 받을 예정이라고 예측하고 있다고 생각하면 된다.

Send Window

Go Back N의 sender는 ACK가 도착하기 전까지 보낸 packet들을 기억하고 있다가 error나 flow control이 필요할 때 지금까지 보낸 packet들을 재전송해야 한다. Go back N은 이 기억을 send window을 통해 한다.

joowan1108

Window 안에는 보냈지만 아직 acknowledge packet을 못 받은 애들과 보낼 예정인 packet들이 들어있다.

Window는 $S_f$보다 크면서 $S_n$보다는 작은 Acknowledge number가 올 때, slide한다. 왜냐하면 이 뜻은 Acknowledge number - 1까지는 receiver가 잘 받았다고 말하는 것이기 때문이다. 따라서 $S_f$는 acknowledge number까지 이동한다.

joowan1108

Receive Window

Receive window는 필요한 data packet들이 왔는지와 정확한 acknowledgement를 보내는지를 확인하는 역할을 한다.

joowan1108

$R_n$과 동일한 packet이 와야 acknowledge packet을 receiver에게 보낸다.

GBN은 하나의 timer만 사용하고 send window 맨 앞의 sequence number packet에 대해서만 time을 잰다.

Go Back N은 timer가 끝날 때, window 안에서 이미 보낸 packet들을 다 재전송한다. 예를 들어 3,4,5,6을 보냈는데 timer가 끝났다면, 3~6을 모두 재전송해야 한다. 이런 원리 때문에 Go Back N이라고 불린다.

joowan1108

joowan1108

joowan1108

joowan1108

Go Back N은 packet loss가 난다면 그만큼 더 자주 많은 packet들을 재전송 해야 하기 때문에 비효율적이다.

Selective Repeat Protocol

Go Back N의 문제를 해결하기 위해 loss된 packet들만 재전송하는 protocol이 고안되었다.

joowan1108

이 protocol은 이전 protocol들과 매우 다른 성격을 가진다.

  • Selective Repeat Protocol에서는 sender window 크기가 최대 $2^{m-1}$이다.

  • 또, receiver window 크기는 sender window와 동일해야 한다.

Sender window에서는 sequence number의 순서와 상관없이 acknowledge가 안 된 packet을 따로 표시한다.

joowan1108

Receiver window에서는 sequence number가 높더라도 이전 sequence number packet들이 도착할 때까지 기다린다.

joowan1108

Timer는 동일하게 하나만 사용하지만 Acknowledge number가 의미하는 것도 다르다. Selective Repeat에서 acknowledge number는 잘 도착한 packet number을 의미한다.

joowan1108

joowan1108

joowan1108

joowan1108

TCP and UDP

UDP는 8 byte (64 bits)의 고정된 header을 지니고 있다. 이 header는 4 부분으로 나뉘어지는데 각 부분은 동일하게 16 bits이다.

  • Source Port

    sending port을 정의한다. 정의가 안 되어있다면 0으로 된다.

  • Destination Port

    destination port을 의미하며 필수로 들어있어야 한다.

  • Total length

    User datagram의 길이를 명시한다.

  • Checksum

    Error checking을 위해 사용된다.

joowan1108

Client to server, server to client인지는 destination port 와 source port 값의 범위를 통해 알아내는 것이다. Ephemeral port인지 well known port인지 판단

Practice Problem

  1. Assume we have a set of dedicated computers in a system, each designed to perform only a single task. Do we still need host-to-host and process-to-process communication and two levels of addressing?

    • The answer is no.
    • Host-to-host and process-to-process communication are needed because each computer on the Internet is designed to do multiple tasks: to run multiple application-layer programs
  2. Assume you need to write and test a client-server application program on two hosts you have at home. What is the range of port numbers you would choose for the client program?

    • The client port number should be chosen from the dynamic range, 49,152 to 65,535.
  3. What is the range of port numbers you would choose for the server program?

    • The server port number also should be chosen from the dynamic range, 49,152 to 65,535.
  4. Can the two port numbers be the same?

    • Yes, they can be the same. However, it is advisable to choose different port numbers for the server and the client to be able to better debug the programs
  5. Assume that, in a Stop-and-Wait system, the bandwidth of the line is 1 Mbps, and 1 bit takes 20 milliseconds to make a round trip.

    • What is the bandwidth-delay product?

      The bandwidth-delay product is (1 × $10^6$) × (20 × $10^{−3}$) = 20,000 bits The system can send 20,000 bits during the time it takes for the data to go from the sender to the receiver and the acknowledgment to come back

    • If the system data packets are 1,000 bits in length, what is the utilization percentage of the link?

      The link utilization is only 1,000/20,000, or 5 percent

    • What is the utilization percentage of the link in Example 3.5 if we have a protocol that can send up to 15 packets before stopping and worrying about the acknowledgments?

      The bandwidth-delay product is still 20,000 bits. The system can send up to 15 packets or 15,000 bits during a round trip. This means the utilization is 15,000/20,000, or 75 percent. Of course, if there are damaged packets, the utilization percentage is much less because packets have to be resent

  6. In a network, the size of the receive window is 1 packet. Which of the following protocols is being used by the network? Explain your answer.
    • Stop-and-Wait

      The protocol can be Stop-and-Wait with the receive window size of 1 and the send window size of 1.

    • Go-Back-N

      The protocol can also be Go-Back-N with the receive window size of 1 and the send window size of n packets.

    • Selective-Repeat

      The protocol cannot be Selective-Repeat because the size of both windows should be the same (1 packet), which means the protocol is Stop-and-Wait, not Selective-Repeat.

  7. What are the total transmitted frames if we have to send 6 frames using Go-Back-N with the following conditions:

    • Window size = 3
    • Every 4th transmitted frame is lost
    • Given frames are 1 2 3 4 5 6

    $\rightarrow$ 11 frames sent

    joowan1108

  8. Install and compile the Python programs TCPClient and UDPClient on one host and TCPServer and UDPServer on another host.

    • Suppose you run TCPClient before you run TCPServer. What happens? Why?

      TCPClient will throw an error because TCP is a connection-oriented protocol which needs a connection establishment with server and client before it does anything. For a connection establishment to happen, a handshake process has to succeed. Handshake process consists of three steps: 1: the client first sends a request to the server. 2: The server has to send a packet that means server also agreed on connection. 3: Then Client also sends ACK packet. However, if the TCPServer is not running before the TCPClient, handshake process cannot be established which makes it impossible to be connected.

    • Suppose you run UDPClient before you run UDPServer. What happens? Why?

      Because UDP is a connectionless protocol, the server would be able to receive packets successfully. However, since the UDPClient started to send the data before the server was running, some packets would be lost.

    • What happens if you use different port numbers for the client and server sides?

      In TCP, it would fail. The port numbers have to match inorder to establish a connection. However, in UDP, data would be sent successfully but it would just not arrive to the server because of mismatched port numbers.

  9. In a network with fixed value for m > 1, we can either use the Go-Back-N or the Selective-Repeat protocol. Describe the advantage and the disadvantage of using each.

    Go back N is simple because it does not have to buffer out of order packets and only track the expected packet number in the receiver side. But when packets are lost frequently, it has to re-send N packets which makes it inefficient.

    Selective-Repeat’s receiver window is not 1, which makes it easy for the protocol to store the information about which packets were lost and which arrived out of order. So, even though packet loss happens frequently, it does not affect the performance. But SR needs to maintain a buffer to store the out of order packets. Also, if the packets of previous sequence are not received, the sliding cannot happen and cannot be sent to the application layer.

  10. The following is a dump (contents) of a UDP header in hexadecimal format. 0045DF0000580000

    • What is the source port number?

      0045 –> 69

    • What is the destination port number?

      DF00 –> 57088

    • What is the total length of the user datagram?

      88

    • What is the length of the data?

      Total length of data = user datagram length - header length (64 bits, 8 bytes fixed)

    • Is the packet directed from a client to a server or vice versa?

      server to client because source port number is a well known port number

    • What is the application-layer protocol?

      TFTP –> 69 is well known port number for TFTP

  11. Fill in blanks these statements about Transport layer services:

    A. Client process has the …………………… port number

    $\rightarrow$ ephemeral

    B. Server process has the …………………… port number

    $\rightarrow$ well known

    C. Encapsulation happens at the …………………… site and decapsulation happens at the …………………… site

    $\rightarrow$ sender

    $\rightarrow$ receiver

    D. After the host has been selected, the …………………… defines one of the processes on this particular host

    $\rightarrow$ port number

    E. Socket address: the combination of an …………………… and a ……………………

    $\rightarrow$ IP address and port number

  12. Classify the following statements into Flow/Error/Congestion controls

    A. Managing the rate of data transmission between producer and consumer to prevent losing the data items at the consumer site

    $\rightarrow$ flow control

    B. Keeping track of lost and discarded packets and resending them

    $\rightarrow$ error control

    C. The load on the network is greater than the capacity of the network

    $\rightarrow$ congestion control

    D. Recognizing duplicate packets and discarding them

    $\rightarrow$ errir control

  13. problem 13

    joowan1108