본문 바로가기
Computer Science/Computer Network

[Computer Network] 3.1 & 3.2장 Transport Layer 개요 그리고 Multiplexing / Demultiplexing

by jungcow 2023. 6. 24.

Transport Layer에 대해서 천천히, 그리고 자세히 알아가보자.

3장. Transport Layer Services의 개요

Transport-layer Protocol provides for logical communication between processes running on different hosts

 

위의 의미를 알기 위해 logical communication 부터 알아보면,

Transport Layer Services - Logical Communication

  • 두 host 사이에선 통신하기 위해 수많은 intermediate network element (router, link-layer switches) 등을 통과하여 연결이 될 것이다.
  • 이 두 host에서 돌아가는 application 관점에서 볼 때, 두 host가 직접 연결되어 있다고 느끼게 된다. 지구 반대편에 있음에도 말이다.

즉, 물리적인 infrastructure의 세부적인 구현은 신경쓰지 않고, 어떻게 연결되어 있는지보다 어디에 연결이 되어있는지가 주요 focus가 되는 것이 이 logical communiation이라 할 수 있다.

Transport Layer Services - Process-to-Process Logical Communication

그럼 logical communication between processes가 무얼 말하는지 대충 예상이 올 수 있다. 먼저 transport layer와 network layer 부터 비교해보자.

  • transport layer : logical communication between processes
  • network layer : logical communication between hosts

둘 모두 logical communication을 제공하곤 있지만, 메시지 전달에 있어서 전달되는 주체의 종류가 다르다. 하나는 프로세스들간의, 다른 하나는 호스트들간의 logical communication을 제공한다. 아래는 그에 대한 비유 표현이다. 

Transport Layer Services - Transport and Network layers : analogy(비유)

 

network terminology analogy
application messages 우편물
processes 한 집의 형제들
hosts 집들
transport layer protocol 철수와 영희(각각 다른 집에 살고 있음)
network layer protocol 우편 서비스

 

위 analogy를 보면, 철수와 영희는 우편이 어떻게 가는지 그 중간 단계는 신경쓰지 않는 것처럼 transport layer 또한 network core를 포함한 network element 사이에서 어떻게 application message들이 전달되는지 신경쓰지 않는다. 단, transport layer는 집에 도착한 우편물을 형제들 중 누구에게 줘야할지에 대한 service가 이뤄지는 계층인 것이다.

 

이와 같은 이유로 network core들(=routers, switches)에선 transport layer를 포함하고 있지 않고, end system(=host)에서만 transport layer protocol이 포함되어 있는 것이다.

 

trasnport layer에선 이와 같이 process to process logical communication을 제공한다. 그럼 이제, transport layer에 있는 protocol들을 통해, 실제 이를 어떻게 구현하고 있는지를 살펴 봐야겠지 않는가? 아래에서 계속 살펴보자. 

 

Transport Layer Services - UDP & TCP over an IP

  • IP : network layer의 protocol이다. best effort delivery service라고 하는데, 이는 최선의 노력으로 전송하지만 보장할 수 없음을 뜻하는 것이다.
  • 즉, unreliable transmission between two hosts 을 제공한다는 것이다.

IP 위에서의 UDP & TCP가 제공하는 서비스들

  1. host to host delivery에서 process to process delivery로 “확장” 기능을 제공한다.
  2. error detection field 를 통해 에러가 있는지 없는지를 감지하는 기능을 제공한다.

위 process to process delivery로 확장됨에 따라 문제가 생기는 것이 있다.

 

IP는 host-to-host communication을 수행한다. 여기서 IP로 넘어온 packet을 어떻게 적절한 process로 전달할 수 있지?

 

 

즉, 하나의 socket에 대응되는 여러개의 process들 중 적절한 process에게 segment들을 전달시키는 multiplexingdemultiplexing 기능이 필요하다.

 

그렇다. 바로 이 Multiplexing(mux)과 Demultiplexing(Demux) 기능이 바로 Transport Layer에서 기본적으로 제공해주는 Service인 것이다. 이러한 mux와 demux의 기능을 포함하면서 process-to-process communication에 필요한 다른 부가적인 기능을 추가하여 만든 protocol이 바로 UDP와 TCP이다.

 

UDP

  1. unreliable communication 이다.
  2. mux와 demux를 수행한다.
  3. checksum을 통해 error detection을 수행한다. (이부분도 바로 아래에서 살펴볼 예정이다)

TCP

  1. reliable communication 이다.
  2. mux와 demux를 수행한다.
  3. checksum을 통해 error detection을 수행한다.
  4. reliable data transmission을 위한 여러가지 작업들을 수행한다.

TCP의 reliable data transmissioncongestion control 과정은 복잡해서 이부분들은 몇 section에 걸쳐서 살펴볼 것이다.

 

그럼 이제 multiplexing과 demultiplexing이 무엇인지, 어떻게 Transport Layer에선 들어오는 packet에 대해 Mux와 Demux를 수행할 수 있는 것인지 살펴보자.

Mux / Demux

mux/demux diagrma

Mux / Demux - Description

mux / demux 란 어떤 작업을 하는 것을 말하는 걸까? 위에서 언급했듯, host-to-host communication에서 process-to-process communication으로의 확장을 가능하게 한 기술이다.

 

multiplexing at sender

  • 각 process에서 보낸 packet(Transport layer의 PDU는 segment이지만, 여기선 편의상 packet이라고 칭하겠다)들을 구분할 수 있도록 transport layer의 header를 추가한다. 추후에 이 header를 통해 demultiplexing까지 이뤄지도록 한다. 이러한 작업을 multiplexing이라고 한다.

demultiplexing at receiver

  • 의도한 process가 받게끔 올바른 socket으로 segment를 받도록 하는 것
  • transport layer에서 추가한 header를 통해 packet을 identifying해서 적절한 socket으로 보내주는 작업을 demultiplexing이라고 한다.

Mux / Demux - how demux works

destination host에서 network layer의 IP datagram을 받는다.

  • 각 datagram 안에는 source IPdest IP 정보를 가지고 있다.
  • 각 datagram은 하나의 transport-layer의 segment를 지니고 있다.
  • 각 segment 안에는 source port, dest port number를 가지고 있다.

이 port number가 곧 socket ID이다.

 

port number

  • 16bit의 number(0 ~ 65535)
  • 0 ~ 1023번 port : well known port number(이미 사용되고 있는 port number, specified in RFC 1700번)

other header fields

  • transport layer의 다른 여러 역할을 위한 정보들
  • error control, flow control, congestion control 등을 수행하기 위한 정보들
  • demultiplexing을 설명하고 있으므로 이 정보는 중요하지 않게 설명하고 있음

이렇게 IP address 와 port number를 이용해서 적절한 process로 segment를 전달하게 된다.

 

socket은 application layer와 transport layer 사이의 interface이다.

 

Mux / Demux - Connectionless Demux

Demultiplexing은 Connectionless communicaion이냐 Connection-oriented communication이냐에 따라 socket을 identifying하는 기준이 달라진다. 이것을 한번 알아보자.

UDP socket identified by 2-tuple : ➡ (destination IP addr, destination port number)

  • 위 2개의 항목들을 이용해서 적절한 socket을 찾아 segment를 보낼 수 있다.

과정

host가 UDP segment를 받았다면,

  1. segment 안의 destination port를 체크
  2. UDP segment를 destination port number에 해당하는 socket으로 보냄

 

그럼 왜 UDP segment에 source의 IP와 port numbere가 필요한가?

 

➡ 2개의 tuple로 identifying할 수 있다고 하더라도, destination쪽에서 source쪽으로 다시 segment를 보내고 싶을 때 보낼 수 있도록 같이 넘겨주는 것이라고 한다.

 

즉, UDP socket은 sender가 누구던간에 같은 port로 segment들이 들어온다면, 이것들을 하나의 socket으로 처리한다는 뜻이다. 아래에서 언급할 것이지만, TCP socket은 같은 port로 segment들이 들어온다고 할지라도, process마다 다른 socket을 사용하기 때문에 segment들이 각기 다른 socket으로 들어온다. 이것 또한 high-performance의 web server의 경우 달라지는데, multithread로 동작하는 high-performance의 web server의 경우, 하나의 process에 여러개의 process가 생길 수도 있다. 아래에서 계속된다.

 

Mux / Demux - Connection-Oriented Demux

TCP mux/demux

TCP socket identified by 4-tuple :
source IP address, source port number, destination IP address, destination port number

 

tcp segment가 rcv에 도착 → 적절한 socket으로 보내줘야 함(demux)

  • 위 4개의 정보로 적절한 socket을 identify

server socket과 client용 socket

  • server socket이 있다.
  • 이 server socket으로 client가 요청을 보내오면, 해당 client 전용으로 socket을 할당해준다. 이 때, socket fd를 부여받게 된다.
  • 이 fd에 해당하는 socket을 통해 client와 통신할 수 있게 되는 것이다.

➡ 위 그림에선, source port number까지 전부 같아도 구분해서 connection을 형성하는 것을 알 수 있다.

  • 3개의 segment들이 전부 같은 ip주소 B, port 80번으로 향하고 있는 것을 볼 수 있다.
  • 이들을 전부 4개의 정보들로 구별해서(demultiplexing) 서로 다른 socket들로 통신되도록 하고 있다.

 모든 경우에 process와 socket이 1대1 대응 되는 것은 아니다.

  • high performance를 위해 web server는 multithread로 동작할수 있다.
  • 하나의 process를 사용하면서, thread를 생성하여, 이 thread마다 socket을 할당하여 1대1 연결될 수 있도록 하는 것이다.
  • 즉 이렇게 할 경우, 하나의 process 이지만 여러개의 socket이 연결이 될 수 있다.

 참고 : HTTP (persistent vs non-persistent)

  • persistent : 전체 연결 시간 동안 동일한 서버 소켓을 사용한다.
  • non-persistent : 매 요청/응답 마다 새로운 소켓을 생성/소멸을 반복한다.

💡 TCP connection의 경우 server socket은 “welcoming socket" 으로써 다른 host로부터 연결 요청이 들어오면 그 host에 대한 socket을 생성하고 이후 요청과 응답에 대해서는 이 socket을 사용하도록 한다. 즉, client용 socket을 따로 생성한다는 뜻이다. 이에 따라 socket을 구분하여 segment를 보내기 위해(demultiplexing을 위해) 위에서 언급했던 4-tuple 정보가 필요한 것이다.

요약

  1. transport layer에서의 기본적인 기능은 network layer 위에서 process-to-process 통신을 지원해주는 것이다.
  2. 이를 위해선 multiplexing과 demultiplexing 작업이 필요하다.
  3. 각 transport layer의 protocol마다의 demultiplexing 방법을 학습했다.

 

더 알아보기

Socket Programming을 통해 network application에서 IP주소와 port번호를 어떻게 다루는지를 확인해보자.

출처

Computer Networking: a Top Down Approach 3.1, 3.2