학습 후기

컴퓨터 네트워크 (KOCW 한양대학교 이석복 )

Torchbearer 2025. 1. 28. 00:26

2. 어플리케이션 계층

전송단위: Message

- 네트워크 어플리케이션의 원리

HTTP: hypertext transfer protocol

1) 링크 포함된 텍스트를 전송하는 프로토콜

2) request, response

=> (Transport 계층) TCP 사용 (TCP connection 필요)

3) stateless

 

persistent HTTP / Non-persistent HTTP: TCP conection 계속 사용할지 여부

Non-persistent HTTP response time = 2RTT + file transmission time

RTT: time for a small packet to travel from clientto server and back

 

Sample problem

- Control message: K bit long

- Base HTML object: L bits

- N referfence objects, each L bit long

- Link bandwidth: R bps

- Propagation delay: d seconds

 

persistent HTTP

(K/R + d) + (K/R + d) + (K/R + d)

(L/R + d) + (L/R + d) ... N ... + (L/R + d) + (L/R + d)

 

Non-persistent HTTP

(K/R + d) + (K/R + d) + (K/R + d)

(N * L/R + d) + (N * L/R + d) 

 

=> 웹 브라우저는 효율적인 방식인 Non-persistent HTTP를 쓰도록 내부적으로 구현되어 있을 것

 

- Cookies: keeping "state"

- Web caches (proxy server)

목표: satisfy client request without involving origin server / 일관성 문제 발생

 

Caching example

LAN utilization: 15%

access link utilization: 99%

1) Increase bandwidth of access link

2) Install cache (hit rate: 0.4)

=> utilization of access link reduced to 60%

 

Cache 일관성 문제 해결방안

Conditional GET

HTTP request msg: if-modified-since: <date>

HTTP response msg: 304 Not modifed or 200 OK <data>

 

- DNS (Domain Name System)

a distributed, hierarchical database

 

Root DNS Servers

Root DNS Servers / com DNS servers

Root DNS Servers / com DNS servers / yahoo.com DNS servers 

Root DNS Servers / com DNS servers / amazon.com DNS servers

Root DNS Servers / org DNS servers 

Root DNS Servers / org DNS servers / pbs.org DNS servers

Root DNS Servers / edu DNS servers

Root DNS Servers / edu DNS servers / poly.edu DNS servers

Root DNS Servers / edu DNS servers / umass.edu DNS servers

 

top-level domain(TLD) DNS servers: responsible for com, org, net, edu, and all top-level-country domains

authoritative DNS servers: organiztion's own DNS servers, providing authoritative hostname to IP mappings for organization's named hosts

Local DNS name server : each ISP (residential ISP, company, university) has one / has local caches of recent name-to-address translation pairs / acts as proxy, forwards query into hierarchy

 

DNS records

DNS: distributed db storing resource records(RR)

RR format: (name, value, type, ttl)

type=A : name is hostname / value is IP address

type=NS : name is domain(e.g., foo.com) / value if hostname of authoritative name server for this domain

 

DNS: UDP 사용 (속도↑, 데이터 유실 시 피해 ↓)

 

- UDP와 TCP를 이용한 Socket 프로그래밍

socket: An interface between application and network (프로세스 간 통신을 위해 운영체제가 제공해주는 인터페이스: socket API)

SOCK_STREAM (a.k.a. TCP) / SOCK_DGRAM( a.k.a. UDP)

 

Server : socket / bind / listen / accept (blocking) / read / write

Client : socket / connect (blocking) / read / write

 

 

Electronic Mail 

Three major components:

- user agents (mail reader)

- mail servers 

- simple mail transfer protocol: SMTP

 

 

3. 전송 계층

전송단위: Segment

Multiplexing(다양한 프로세스에서 하나의 소켓 인터페이스를 통해 나감) / demultiplexing(하나의 소켓 인터페이스를 통해 다양한 프로세스로 들어옴)

 

Connectionless demux (UDP)

- C/S Socket 간 connection이 없음. => C/S Socket 간 1:1 매핑이 아님.

- Header에 필드로 source port / destination port 저장 (단순히 port만 보고 통신)

 

Connection-oriented demux (TCP)

- C/S Socket 간 connection이 있음. => C/S Socket 간 1:1 매핑임.

- 통신 시, Socket은 하나만 존재하는 것이 아님. (하나의 프로레스가 여러개의 소켓을 가질 수 있음)

- Server 측에서는 최초에 리스닝 소켓을 통해 connection 대기 (accept)

=> Client로부터 연결 요청 수락 시, 새로운 통신 소켓 생성 (source IP address / source Port number/ destination IP address / destination Port number 를 이용하여 새로운 소켓ID 생성)

=> 각각의 새로운 소켓을 통해 Client와 Server간 데이터 송수신

 

UDP segment header 

- source port (16bit)

- dest port (16bit)

- length

- checksum: 오류 탐지, 에러가 있으면 전달X

 

 

 

TCP

outline

principles of reliable data transfer

rdt( reliable data transfer) : 간단히 디자인한 프로토콜

rdt1.0: no error, no loss

rdt2.0: channel with bit errors

- error detection (checksum)

- feedback: control msgs (ACK, NAK) from receiver to sender

rdt2.1

- sequence number

handling duplicates (what happens if ACK/NAK corrupted?): sender adds sequence number to each pkt

rdt2.2: a NAK-free protocol

using ACK, acknowledgemnet number only

rdt3.0: channels with errors & loss

- timer

 

TCP Overview

point-to-poin

reliable, in-order byte steam

pipelined

full duplex data(양방향, sender면서 receiver임)

connection-oriented

flow controlled

 

TCP segment structure

source port # (16bits)

dest port # (16bits)

sequence number (32bits)

- byte stream "number" of first byte in segment's data

acknowledgement number (32bits)

- seq # of next byte expected from other side / cumulative ACK

 

TCP reliable data transfer

RTT(round trip time) C↔S (Client → Server → Client 시간)

매번 Sample RTT 측정하되, 재전송은 측정 X

EstimatedRTT: 최근에 측정된 Sample RTT의 가중치를 높여서 계산 (변화무쌍한 네트워크 환경을 고려)

TimeoutInterval: EstimatedRTT + 4*DevRTT(safety margin)

 

timeout 되기 전에 재전송하는 규칙

TCP fast retransmit : fast retransmit after sender receipt of triple duplicate ACK

if sender receives 3 ACKs for same data 

 

 

TCP flow control

sender에서 window size가 아닌 receive window size  (receiver buffer)를 고려한 만큼 데이터 전송

corner case: when rwnd = 0

=> sender needs to periodically send a probe packet (only 1 byte data) to receiver when receiver's rwnd = 0

 

 

1. 데이터 유실 상황 가정

송신 측

  • 클라이언트가 데이터를 **"Hello World!"**라고 송신한다고 가정합니다.
  • 이 데이터는 네트워크를 통해 패킷 단위로 나누어 전송됩니다. 예를 들어:
    1. 패킷 1: "Hello"
    2. 패킷 2: " "
    3. 패킷 3: "World!"

네트워크

  • 패킷 2(공백)가 네트워크 문제로 유실되었다고 가정합니다.

수신 측

  • 서버는 패킷 1("Hello")과 패킷 3("World!")만 수신하게 되고, 패킷 2가 누락되었음을 TCP 프로토콜에 의해 감지합니다.

2. TCP가 데이터 유실을 감지하는 방식

TCP는 신뢰성 있는 데이터 전송을 위해 시퀀스 번호 ACK(확인 응답) 메커니즘을 사용합니다.

  • 시퀀스 번호: 송신되는 각 패킷에 고유 번호를 붙여 데이터의 순서를 나타냅니다.
  • ACK: 수신 측은 정상적으로 수신된 데이터에 대해 송신 측에 확인 응답을 보냅니다.

예시: 데이터 유실 감지

  1. 클라이언트가 데이터를 송신합니다:
    • 패킷 1: "Hello" (시퀀스 번호 0~4)
    • 패킷 2: " " (시퀀스 번호 5)
    • 패킷 3: "World!" (시퀀스 번호 6~11)
  2. 서버는 패킷 1("Hello")을 수신하고, 이에 대한 ACK(시퀀스 번호 5)를 클라이언트에 보냅니다.
  3. 패킷 2가 유실되었으므로 서버는 패킷 3("World!")를 수신했더라도, 시퀀스 번호 5(패킷 2)가 누락되었음을 감지합니다.
  4. 서버는 누락된 데이터가 있음을 송신 측에 알리기 위해 중복 ACK를 보내거나 타임아웃이 발생하도록 기다립니다.

3. TCP의 데이터 재전송 과정

TCP는 데이터 유실을 해결하기 위해 두 가지 방법으로 재전송을 수행합니다:

  1. 중복 ACK 기반 재전송:
    • 서버는 마지막으로 성공적으로 수신한 데이터의 ACK(예: 시퀀스 번호 5)를 반복해서 클라이언트로 보냅니다.
    • 클라이언트는 동일한 ACK를 세 번 이상 받으면, 해당 패킷(패킷 2)을 재전송합니다.
  2. 타임아웃 기반 재전송:
    • 송신 측은 특정 시간 동안 해당 데이터에 대한 ACK를 받지 못하면 해당 패킷을 재전송합니다.

4. 데이터 복구 후 처리

재전송된 데이터를 통해 리시브 버퍼가 올바르게 채워지면, TCP는 이를 어플리케이션 계층으로 전달합니다:

  1. 클라이언트는 누락된 패킷 2(" ")를 서버로 재전송합니다.
  2. 서버는 리시브 버퍼에서 누락된 위치(시퀀스 번호 5)를 채웁니다.
  3. 리시브 버퍼가 순서대로 데이터를 정리한 후, 어플리케이션 계층으로 "Hello World!"를 전달합니다.

요약

  • TCP는 데이터 유실을 감지하기 위해 시퀀스 번호 ACK 메커니즘을 사용합니다.
  • 누락된 데이터는 중복 ACK 또는 타임아웃을 통해 재전송됩니다.
  • 리시브 버퍼는 데이터가 올바르게 복구될 때까지 어플리케이션 계층에 데이터를 전달하지 않습니다.
  • 최종적으로 어플리케이션 계층은 유실 없이 완전한 데이터를 받습니다.

 

하나의 전송할 segment 사이즈를 어떻게 결정할지 문제 (Silly Window Syndrome: Sender)

segment 사이즈가 클수록 오버헤드가 낮아져서 효율적임 (TCP header size)

어플리케이션 계층에서 max segmnet size가 다 채워질 때까지 write 하는 것을 기다렸다가 보내는 것은 비효율적

Nagle's alogrithm : Sending TCP sends the first piece of data even if it is only 1 byte. / Sending TCP accumulates data and wait until: Receiving TCP sends an ACK, Or enough data has accumulated to fill a maximum-segment size / Step 2 is repeated for the rest of the transmission

 

Silly Window Syndrome: Receiver (개선을 위한 제안)

- Clark's solution: Receiving RCP announces rwnd = 0 until Enough space to accommodate a segment of maximum size Or half of the buffer is empty

- Delayed ACK: Wait up to 500ms for next segment. If no next segment, send ACK.

 

 

connection management

TCP 3-way handshake

1. TCP sync (C->S): SYNbit=1, Seq=x

2. TCP sync ack (S->C): SYNbit=1, Seq=y, ACKbit=1, ACKnum=x+1

3. TCP ack (http msg) (C->S): ACKbit=1, ACKnum=y+1

 

TCP: closing a connection

1. C->S : FINbit=1, seq=x

2. S->C : ACKbit=1, ACKnum=x+1

3. S->C : FINbit=1, seq=y

4. C->S : ACKbit=1, ACKnum=y+1 (timed wait for 2*max segment lifetime)

 

TCP congestion control: addtive increase multiplicative decrease

한번에 전송하는 segment 사이즈(사이즈가 클수록 오버헤드 감소): cwnd, rwnd 중 작은 값

- additive increase: increase cwnd by 1 MSS(max segment size) every RTT until loss detected (feedback: no ACK)

- multiplicative decrease: cut cwnd in half after loss

 

TCP Slow Start

increase rate exponentially until first loss event: initially cwnd = 1 MSS / double cwnd every RTT / done by incrementing cwnd for every ACK received

TCP: switching from slow start to CA

- when should the exponential increase switch to linear? -> when cwnd gets to 1/2 of its value before timeout.

- on loss event, ssthresh is set to 1/2 of cwnd just before loss event.

 

TCP throughput

TCP의 전송속도: 네트워크 상태에 따라 유동적

UDP의 전송속도: 어플리케이션의 상태

 

TCP fairness: if K TCP sessions share same bottleneck link of bandwidth R, each should have average rate of R/K

 

 

4. 네트워크 계층

forwarding: input 을 output으로 전달

routing: datagram forwarding table을 채워 넣기

 

TCP segment header (20 byte)

IP packet header (20 byte)

 

IP Address (IPv4)

A unique 32-bit number

IP는 호스트가 아닌 네트워크 인터페이스를 지칭함 (라우터는 인터페이스가 여러개이므로, IP주소를 여러개 가짐)

 

Scalability Improved

12.34.158.0/24 is a 24-bit prefix with 2^8 addresses. (앞 24비트는 네트워크 주소, 뒤 8비트는 호스트 주소)

= 24-bit Subnet Mask (머신이 이해하기 쉽게 만든 방식) 255.255.255.0

 

Classless Inter-Domain Routing (CIDR)

Use two 32-bit numbers to represent a network.

Network number = IP address + Mask

같은 서브넷에 존재한 host들은 라우터 거치지 않고 통신 가능

 

 

Network Address Translation (NAT)

외부로 패킷을 보낼 때, 게이트웨이에서 NAT 테이블에 변환 정보를 저장하여 사설 IP를 공인IP로 변경 (클라이언트)

외부에서 내부로 패킷이 들어올 때는, NAT 테이블에 변환 정보를 저장할 수 없어서 홀펀칭을 하지 않는 한 변경이 어려움 (서버)

= 게이트웨이 라우터에서 계층이 다른 전송 계층의 정보(TCP, port)를 볼 뿐만 아니라 변경까지 함. port를 통해 호스트를 구분함.

 

Dynamic Host Configuration Protocol (DHCP)

DHCP client port 68

DHCP server port 67

 

DHCP client-server scenario

1) DHCP discover (C->S)

src: 0.0.0.0 68 (아직 내 ip를 모르므로, 0.0.0.0으로 세팅)

dest: 255.255.255.255 67 ( 서브넷 내, 모든 호스트에게 전송: 브로드캐스트 )

yiaddr: 0.0.0.0

transaction ID: 654

 

2) DHCP offer (S->C)

src: 223.1.2.5 67 (DHCP server)

dest: 255.255.255.255 68 (아직 client ip를 모르므로 브로드캐스트 전송)

yiaddr: 223.1.2.4

transaction ID: 654 (654번이므로, client는 자신에게 온 메시지임을 판단)

lifetime: 3600 secs

 

3) DHCP request (C->S)

src: 0.0.0.0 68

dest: 255.255.255.255 67 (다른 DHCP server가 있을 경우를 대비하여, 그 서버들에게도 알리기 위해 브로드캐스트로 전송)

yiaddr: 223.1.2.4

transaction ID: 655

lifetime: 3600 secs

 

4) DHCP ACK (S->C)

src: 223.1.2.5 67

dest: 255.255.255.255 68

yiaddr: 223.1.2.4

transaction ID: 655

lifetime: 3600 secs

 

DHCP server가 제공하는 정보

- 내 IP addr / subnet mask

- Gateway router IP addr

- DNS server

 

IP fragmentation, reassembly

MTU: network link에서 지원하는 최대 사이즈 (largest possible link-level frame)

MTU 보다 큰 데이터일 경우, 쪼개져서 보내지고, 도착지에서 reassembly 됨.

4000 byte datagram

MTU = 1500 bytes

 

length=4000 / ID=x / fragflag=0 / offset=0

-> 아래 3개 fragment로 쪼개서 전송 (fragmentation)

length=1500 / ID=x / fragflag=1 / offset=0

length=1500 / ID=x / fragflag=1 / offset=185 (1480/8)

length=1040 / ID=x / fragflag=0 / offset=370 (2960/8)

 

 

 

라우팅 알고리즘