3.5.2 reliable data transfer
TCP reliable data transfer
TCP는 network 계층 위의 transport 계층에서 host-to-host reliable data trasfer를 한다. Network 계층은 unreliable transfer을 하기 때문에 TCP는 reliable data transfer를 해야 한다.
- Pipelined segments
- Cumulative ACKs
- Single retransmission timer per connection
<-- 내보낸지 가장 오래된 segment가 timer setting을 결정한다.
▷ Retransmission is triggered by:
- timeout events: ACK이 안 오면, packet loss라고 생각하고 retransmit한다.
- 3 duplicate ACKs (fast retransmission)
TCP sender events:
1. Data received from application layer.
- Create segment with seq #. (이거 보낼게)
cf) seq #: byte stream - Start timer if not already running. (지금 내보내는 segment가 가장 오래된 segment라면(sent, not yet ACKed), timer를 시작한다.)
2. timeout: ACK이 안 온다!
- Timeout은 packet loss 또는 ACK loss에 의해 발생할 수 있지만, packet loss라고 생각하고 retransmit segment that caused timeout.
- Restart timer.
3. ACK received
- Update "sent, ACKed".
- Start timer. (남아있는 sent 중에 가장 오래된 segment로 timer를 시작한다.)
TCP sender

- SendBase: sent 했으나, ACK 받지 못한 첫 번째 번호
- NextSeqNum: 다음 segment의 seq # (window 크기 내에서 사용 가능하지만, 사용하지 않은 첫 번째 번호)

0. 처음 시작:
- NextSeqNum = InitSeqNum
- SendBase = InitSeqNum
1. Data received from application above --> Create segment
- NextSeqNum: 새로운 seq # 설정 (NextSeqNum = NextSeqNum(sent, not-yet ACKed가 됨) + legth(data))
- If (timer currently not running), start timer;
2. Timeout --> Retransmit not-yet-ACKed segment with smallest seq #.
- Start timer.
3. ACK received, with ACK field 'y'. (ACK 번호 y: (y-1)까지 잘 받았고, y를 기대해)
- if (y > SendBase), SendBase = y: 중간에 빠진 ACK이 있더라도 SendBase를 업데이트한다.
- if (there are currently not-yet-ACKed segments), start timer;
else, stop timer;
Cf) What if (y < SendBase)?
SendBase: 이제 ACK되어야 할 번호. 그런데 그것보다 작은 번호를 ACK 받았다?
== 중복 ACK을 받았다는 것!
TCP receiver: ACK generation
Case 1) in-order segment를 받았을 때
▶ Case 1-1) 다른 보낼게 없으면: delay ACK. (for 500ms; maximum 한계)
▶ Case 1-2) 다른 보낼게 있으면(ACK delay하고 있는 segment가 있으면: immediately send single cumulative ACK.
Case 2) out-of-order segment를 받았을 때
▶ Case 2-1) 내가 원하지 않는 순서의 segment가 도착해서 gap이 생겼다: duplicate ACK(중복 ACK) - 기대하는 ACK이 올 때까지
▶ Case 2-2) 내가 원하는 순서의 segment가 도착했다: immediate send ACK.
TCP: retransmission scenarios
Lost ACK scenario

: 중간에 ACK이 없어짐... 다시 보내서 ACK을 받는다.
Premature timeout


: Premature timeout 발생... 좀 더 기다리면 되었을 텐데... 데이터를 다시 전송한다.
하지만! ACK은 그 다음 120번으로 받음! cumulative ACK이니까 오히려좋아! ^^
TCP fast retransmit
- Problem: timeout period는 너무 길다... 그거 다 기다리다간 throughput이 너무 적어지겠어.
- Solution: 3-duplicate ACKs를 받으면, fast retransmit!
: timeout 발생 전에 duplicate ACK을 3번 받으면, segment loss detection 가능 --> fast retransmit!
TCP fast retransmit: example

3.5.3 flow control
TCP flow control
Problem: sender가 receiver에 데이터를 너무 빠르게 보내서, receiver buffer overflow가 발생할 수 있다.
Solution: flow control!
- Flow control: receiver가 sender가 보낼 수 있는 데이터의 양을 컨트롤하는 것

TCP flow control (Cont'd)


1. TCP receiver는 <receive window>를 통해 free buffer space를 sender에게 알려준다.
- RcvBuffer: 총 버퍼 공간
- rwnd: free buffer space
2. Sender limits amount of unACKed data to receiver's rwnd.
2. Receiver buffer가 overflow되지 않는다.
3.5.4 connection management
Agreeing to establish a connection

Connection Management
▶ Handshake:
- Agree to establish connection.
- Agree on connection parameters. (예: starting seq #)

2-way handshake scenarios
Case 1) No problem!

Case 2-1) Problem: half open connection!

Case 2-2) Problem: duplicated data accepted!

TCP 3-way handshake

TCP 3-way handshake: FSM

- server: welcom socket이 listen하고 있다.
- client - SYN(seq = x): SYN msg를 보낸다. 이때, initial seq #를 선택한다.
- server - SYNACK: SYN msg에 대한 ACK을 보낸다. 이때, client의 initial seq #에 대한 ACK을 보내고, 자신도 initial seq #를 선택한다.
- client: establised!
- client - ACK: SYNACK에 대한 ACK을 보낸다.
- server: established!
TCP: Closing a TCP connection
: Closing 할 때는 3-way handshake를 하지 않고, 각자 independent하게 close한다.

- client - FINbit = 1; 난 마지막이야.
- server - ACKbit = 1; 알겠어.
- server - FINbit = 1; 나도 끝낼게.
- client - ACKbit = 1; 알겠어.
Cf) client - TIMED_WAIT
: server의 종료 요청에 대한 ACK이 사라지지 않았는지 확인하는 시간
'Computer Network > 컴퓨터네트워크' 카테고리의 다른 글
| [컴퓨터네트워크] Ch2 연습문제 (0) | 2023.10.26 |
|---|---|
| [컴퓨터네트워크] Ch1 연습문제 (0) | 2023.10.26 |
| [컴퓨터네트워크] 3. Transport Layer (4) (1) | 2023.10.21 |
| [컴퓨터네트워크] 3. Transport Layer (3) (0) | 2023.10.21 |
| [컴퓨터네트워크] 3. Transport Layer (2) (0) | 2023.10.21 |