1 tcp/ip introduction from: tcp/ip 網路管理 craig hunt 著 第一章 綜觀 tcp/ip reference...
Post on 21-Dec-2015
242 views
TRANSCRIPT
1
TCP/IP Introduction
From: TCP/IP 網路管理 Craig Hunt 著第一章 綜觀 TCP/IP
Reference Book:
Computer Networking: A Top Down Approach. 4th edition. Jim Kurose, Keith Ross. Addison-Wesley, July 2007.
2
Outlines
TCP/IP Protocol Stack Internet Protocol ( IP ) User Datagram Protocol ( UDP ) Transmission Control Protocol ( TCP )
3
Part 1
TCP/IP Protocol Stack
4
TCP/IP Introduction
ARPANET & TCP/IP history Internet v.s. internet
Internet: the world wide network based on ARPANET
internet: a network which is constructed from many small networks and interconnected through IP
5
Features of TCP/IP
Open protocol standard Hardware independent Operating system independent A great addressing Identical services based on the same
application protocol
6
TCP/IP Protocol Suite vs. OSI Reference Model
Application Layer
Host-to-host Transport Layer
Internet Layer
Network Access Layer
7
Layers of TCP/IP
由網路應用程式與相關的處理程序所組成
提供端點對端點完整的資料傳遞服務
定義資料段並掌控資料的傳輸路徑
定義存取實體網路的例行程序
4.Application Layer
3. Host-to-host Transport Layer
2. Internet Layer
1. Network Access Layer
8
Flow of Data
encapsulation decapsulation
9
Encapsulation of TCP/IP
header Data
Data
Data
DataReceiveSend
frame
datagram
segment packet
stream message
Encapsulation Decapsulation
Application Layer
Host-to-host Transport Layer
Internet Layer
Network Access Layer
header
header
headerheader
header
TCP UDP
10
Network Access Layer Include OSI 3 lower layers
For each physical specification, there are some corresponding protocols (drivers) in network access layer.
Main Functions: Encapsulate IP datagram into frame Map IP addresses into physical addresses
The commonest protocols in this layer: RFC894: Interface IP-Ethernet RFC826: Address Resolution Protocol (ARP)
11
Internet Layer
Provide the addressing and data encapsulation on heterogeneous networks
The commonest protocols in this layer: RFC 791: Internet Protocol (IP) RFC 792: Internet Control Message Protocol
(ICMP)
12
Routable v.s. Nonroutable
Routable: provide the capability to communicate with hosts in other LANs IP is a routable protocol.
Nonroutable: only communicate with hosts in its own LAN NetBIOS Protocol is nonroutable
13
Host-to-host Transport Layer
Provide end-to-end data delivery The commonest protocols in this layer:
RFC 768: User Datagram Protocol (UDP) Unreliable, best effort
RFC 793: Transmission Control Protocol (TCP)
Connection-oriented, reliable
Users of host-to-host transport layer should choose TCP or UDP depend on their requirements.
14
TCP Connection
15
Application Layer
Define how to use the protocols in the transport layer to deliver data
16
Some Application Protocols (1/2) telnet: Network Terminal Protocol
Provide the service of remote login FTP: File Transfer Protocol
Transfer files between client and server SMTP: Simple Mail Transfer Protocol
Send email POP3: Post Office Protocol
Retrieve email from mailbox HTTP: Hyper Text Transfer Protocol
Send web pages via Internet
17
Some Application Protocols (2/2) DNS: Domain Name System
Mapping the domain name and IP addresses OSPF: Open Shortest Path First
A routing protocol for routers NFS: Network File System
Share files among hosts on the net SNMP: Simple Network Management Protocol
Manage the operation of network DHCP: Dynamic Host Configuration Protocol
Allocate dynamic IP addresses
18
TCP/IP Architecture
UART Ethernet
RS-232CDriver
EthernetDriver
PPP
IP
ARP RARP
ICMP UDP TCP
PING TFTP DNS Telnet FTP SMTP
19
Part 2
Internet Protocol (IP)
20
Internet Protocol (IP) IP provides a basic service of packet
delivery: Define the basic packet unit delivered on
Internet: the format of datagram Define the logical addressing on Internet Put/retrieve data between the network access
layer and the transport layer Determine the route of datagram moving from
source to the destination Perform the segmentation and reassembling of
datagram
21
Features of IP
Connectionless service IP does not exchange control messages
(handshake) with remote host before sending data.
IP is non-reliable IP provides neither error detection nor
error correction. Variable Length of Datagram Best Effort Delivery
22
Connection-oriented vs. Connectionless Connection-oriented
Telephone System Users first establishes a connection, uses the
connection and then releases the connection. All of data are received in order.
Connectionless Postal System No connection is established Data is received out of order due to network
delay.
23
Reliable vs. Unreliable
Reliable: this protocol checks whether packets are received correctly.
Unreliable: this protocol does not check whether packets are received correctly. IP (Internet Protocol) is an unreliable
protocol.
24
Variable Length of Datagram
IP can take over variable-length data from upper layer.
Thus, it is easy to write upper application programs. The minimum size of data in a datagram is
one byte while the maximum is 64K bytes. IP header contains the information to route
the datagram.
25
Best-Effort Delivery IP does not deal with the following problems:
Datagram lost Delay or out of order Datagram destruction Duplicate datagram
Because IP works on any physical networks, underlining network may be unreliable and cause IP datagram lost, duplication, delay, out of order or destruction. Upper layer above IP must handle these questions.
26
The IP Datagram Header Format
Total LengthVersion
Data from upper layer...
Options Padding
Destination IP address
Header ChecksumTime to Live
Source IP address
Protocol
Header Length
Type of Service
FlagsIdentification Fragment Offset
Bit
0 16 314 8 24
1
2
3
4
5
6
Header
Word
27
IP Header (1/4) Version 4 Header Length
32bits per unit Type of Service (TOS)
Reliability, precedence, delay, throughput Total Length
Length of IP datagram (unit: byte)
28
IP Header (2/4)
Identification, Flags, and Fragment Offset A datagram can be split into fragments Identification: identify data fragments Flags: indicate the last fragment Offset: show the position of this segment Maximum transfer unit in data link layer
FDDI 4352 bytes 、 Ethernet 1500 bytes 、 x.25 576 bytes 、 PPP 296 bytes
29
IP Header (3/4)
Time to Live (TTL) max number remaining hops (decremented
at each router) Protocol
Indicate the higher-layer protocol TCP (6), UDP (17)
Header Checksum
30
IP Header (4/4)
Source and Destination IP Addresses 32-bit address in IPv4
Options E.g. timestamp, record route, taken, specify,
list of routers to visit. Padding Data
Variable length, typically a TCP or UDP segment
31
IP Datagram Delivery Determine the routing path based on
destination IP address Encapsulation data and send IP datagram
through the network access layer Extract data and send to the transport layer
According to the protocol number in header Send to the correct module in transport layer
The port number in the header of transport layer indicates the application process
Refer to "Data Transfer.ppt"
32
Internet Control Message Protocol (ICMP)
Use IP to send control messages Common functions:
Flow control Detect unreachable destination redirect the routing path Detect remote host if it is alive
Refer to “ICMP.ppt”
33
Part 3
User Datagram Protocol (UDP)
34
UDP (1/2) Pass individual pieces of data from an
application to IP Connectionless
No handshaking between UDP sender & receiver No connection state at sender& receiver No connection establishment (which can add delay) Each UDP segment handled independently of
others No ACK, inherently unreliable
Best Effort, unreliable
35
UDP (2/2) Simple, high efficiency, small delay
Small segment header No congestion control: UDP can blast away as fast as
desired AP can transmit data in least offer.
Applications A quick, on-shot transmission of data, request/response,
e.g., DNS, SNMP Streaming multimedia: Loss tolerant & rate sensitive, e.g.,
voice
36
UDP Packet
Length
Message from upper layer
Destination Port
Checksum
Source Port
Bit
0 16 31
37
UDP Packet Header
Source Port (16bits) Optional
Destination Port (16bits) Length (16bits)
The length (byte) of header+data Checksum
Optional header + pseudo header + data
Data A message from application layer
38
UDP Pseudoheader
UDP Length0
Destination IP Address
Protocol
Bit
0 16 314 8 24
1
2
3
WordSource IP Address
39
Identify Used Protocols
Protocol numbers
Port numbers
40
Part 4
Transmission Control Protocol
(TCP)
41
TCP (1/2)
Virtual circuit connection Reliable connection creation and closing End-to-end communication
In sequence, without omissions and errors Reliability ( by acknowledge )
End-to-end confirmation, packet retransmission, flow control, congestion control
Full duplex connection Byte stream oriented Applications: HTTP, FTP
42
TCP (2/2) 以三段式交握( Three-way Handshake )來建立與結束連結( Connection )。
提供端點對端點 (end-to end) 傳輸之間的錯誤偵測與更正功能。 TCP 將上層的 data stream 切割成 segment ,每一個 segment 會配上相對應的一個 segment header ,再送到 IP layer 封裝於一個 packet 中。
以確認重傳( Positive Acknowledgement with Re-transmission , PAR )的方式來提供可靠性。
43
TCP Segment
Urgent Pointer
Data from upper layer…
Options Padding
Destination Port
Checksum
Window
Source Port
Sequence Number
FlagRes.Offset
Bit0 16 314 8 24
1
2
3
4
5
6
Header
WordAcknowledge Number
44
The TCP Header (1/5) TCP Port Numbers
Identifying a specific instance of a given application
Well-known port numbers: 0-1023 21: FTP; 23: telnet; 25: SMTP; 80: HTTP
Registered ports: 1024 to 49151 They are assigned by IANA for specific service
A socket pair specifies a unique session. Source address and port number (a socket
address) + Destination address and port number (another socket address)
45
The TCP Header (2/5) Sequence and acknowledge numbers
Identify individual segments Actually count data octets transmitted A given segment with a Sequence Number of
100 and contains 150 octets of data The ack number will be 250 The Sequence Number of the next segment is 250
Data offset: header length (in 32-bit words)
Receive Window The amount of buffer space available for
receiving data
46
The TCP Header (3/5)
Urgent Pointer An offset to the first segment after the
urgent data Indicates the length of the urgent data Critical information to be sent to the user
application as soon as possible
47
The TCP Header (4/5)
Checksum of TCP header, data, and TCP pseudoheader
Option: maximum segment size (MSS) Padding Data
TCP Length0Destination IP AddressProtocol=6
0 16 314 8 241
2
3
Bit
Source IP Address
TCP pseudoheader
48
The TCP Header (5/5) Control bits
URG: 1 if urgent data is included, use urgent pointer field
Urgent Pointer field significant ACK: 1 for an ACK
Acknowledgement field significant PSH: for the push function RST: reset the connection; an error and
abort a session SYN: Synchronize sequence number; 1 for
the initial messages FIN: Finish; close a session; no more data
49
Create A TCP ConnectionClient Server
SYN=1Seq = 2000
SYN=1, ACK=1Seq = 4000
ACK # = 2001Window size
ACK=1 Seq = 2001ACK # = 4001 data
Step 1: client host sends TCP SYN segment to server
specifies initial seq # no data
Step 2: server host receives SYN, replies with SYNACK segment
server allocates buffers specifies server initial seq. #
Step 3: client receives SYN/ACK, replies with ACK segment, which may contain data
50
TCP Slow Start
When a connection begins, increase rate exponentially.
TCP doubles transmission rate every RTT.
Host A
one segment
RTT
Host B
time
two segments
four segments
51
TCP Flow Control TCP treat data as a continuous byte-stream.
TCP must maintain the order of data bytes. TCP uses a buffer to save the received data.
While creating Connection, two hosts use SYN fields to show their ISN.
Based on Sequence Number, receivers reassemble these byte into origin Stream.
Receivers send ACK. Thus, senders will know the rest buffer size in receivers and know how much data can be sent.
52
Fields Used for Flow Control (1/2)
序號( Sequence number, SYN ) : 指出該 Segment 的 data content 第一個 byte 是整個 Stream 的第幾個 byte 。
確認號碼( Acknowledge Number, ACK ) : 指出 Receiver 期待下次收到的 byte 的序號。 同時表示確認已收到的此 Acknowledge
number 之前的所有 bytes 。
53
Fields Used for Flow Control (2/2)
訊窗( Windows ) : 緩衝器( Buffers )所能接收的 byte 數目( Window size )。 控制 Source 所能送出的 Bytes 數目。 Example: Window size=6000 , Sender 最多只能送出 6000 bytes 的資料。
Example: Window size=0 , Sender 必須停止發送封包。
It is a kind of sliding window.
54
Example 1 for Flow Control
1001 2001 3001 4001 5001 6001 7001
Now, upper AP retrieve 1-2000 bytes from buffer.
Receiver gets 2001-3000 bytes
Window
1001 2001 3001 4001 5001 6001 7001
Window (specifies which streams are want to be received)
Window Slides
1
1
means that TCP has received this block.
ISN=0 ACK=2001, Window=2000
ACK=5001, Window=3000
55
Example 2 for Flow Control
56
Traffic Jam Too many sources sending too much
data too fast for network to handle long delays (queueing in router
buffers) lost packets (buffer overflow at
routers)unlimited shared
output link buffers
Host A original data
Host B
receive data
57
Retransmission in TCP
Positive Acknowledgement with Retransmission (PAR)
Senders retransmit segments if no ACK are received before timeout Timeout (the segment is lost) Checksum error: discard this segment
58
Message Loss and Retransmission
Set the timeout for retransmission
59
Adaptive Retransmission Time
Collect and get the mean of round-trip delay. According to the average, Set the timeout of retransmission.
60
How to Set the Value of Timeout
61
Congestion Control
After timeout event Slow start (one segment) Window then grows exponentially To a threshold, then grows linearly
62
Close A TCP ConnectionClient Server
FIN=1Seq = 12500ACK = 7000
FIN=1, ACK=1Seq = 7000
ACK # = 12501
ACK=1Seq = 12501ACK # = 7001
1: client end system sends TCP FIN control segment to server
2: server receives FIN, replies with ACK. Closes connection,
sends FIN. 3: client receives FIN, replies
with ACK. Enters “timed wait” - will respond with ACK to received FINs
4: server, receives ACK. Connection closed.
63
Summary You have know the protocols: IP, UDP, TCP
The header format defines the functionality of a protocol. So we should study the header fields for each protocols.
For each AP, to choose UDP or TCP is a good question.
You can study more about the impact of TCP flow control TCP congestion control