TCP/IP Basics
Objectives
• Upon completion of this course, you will be
able to:
– Know about TCP/IP protocol suite
– Be familiar with commonly used IP network
devices
Contents
• OSI Model and Layer Function
• TCP/IP Protocol Suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
Post System
Jim N.Y. Pekin
Tom
Post network
To Jim
Post code stamp
Destination address
TCP/IP
Host A Host B
Internet
TCP/IP
• First used protocol suite
• Universal De-facto standard
• Internet standard communication
OSI Model
Application Layer7
Upper layer Presentation Layer6
session Layer5
Layer4 Transport
Layer3 Network
Data layer
Layer2 Data link
Layer1 Physical
Upper Layer Function
Example
Application Network User Interface Telnet
FTP
•Present data ASCII
Presentation •Encryption, EBCDIC
decryption JPEG
Keep different
Sessio applications Authentication
n independent
Data Layer Function
Example
• Reliable and Unreliable transfer TCP
Transport • Use retransmission to ensure UDP
reliability SPX
Provide logical address and path-finding IP
Network method for the working of routers
IPX
• Combine bit to byte and byte to frame 802.3 /
Data Link • Access media by MAC address 802.2
• Error detection without error correction
HDLC
• Transfer bit between devices
Physical • Define voltage, bit rate, physical EIA/TIA-232
connection V.35
Data Encapsulation
Application
Presentatio
Upper Layer n PDU
Session
Data
Transport
TCP Header Upper Layer Data Segment
IP Header Upper Layer Data Network Packet
MAC+LLC Header Upper Layer DataFCS Frame
Data Link
0101110101001000010 Physical Bits
Data Decapsulation
Application
Presentatio
Upper Layer
n Session
Data
Transport Upper Layer
a d er Data
P He
TC
Network r TCP+ Upper Layer Data
e ad e
H
IP
IP + TCP + Upper Layer
Data Link ad er Data
He
LC
AC +L
M
Physical 0101110101001000010
Contents
• OSI model and layer function
• TCP/IP protocol suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
TCP/IP Model vs OSI Model
Applicatio
n
Presentati
on Applicatio
Session
n
Transport Transport
Network Internet
Data Link
Data Link
Physical
TCP/IP Protocol Suite
F T S D T S
T E M N F N
P L T S T M
N P P P
E
T
Applicatio
n 21 23 25 53 69
Applicatio 161
TCP n UDP
Transport
6 17
ARP IP ICMP
Internet Data Link 1
0806 0800
Data Link
Ethernet II (RFC 894 )
Contents
• OSI model and layer function
• TCP/IP protocol suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
Transport Layer
• Segment upper layer data
• Establish end to end connection
• Ensure the reliability of data transfer
Logical connection
TCP Protocol
Bit 0 Bit 15 Bit 16 Bit 31
Source port (16) Destination port (16)
Sequence number (32)
Acknowledgement number (32) 20
Bytes
Header
length (4)Reserved (6)
Code bits (6) Window (16)
Checksum (16) Urgent (16)
Options (0 or 32 if any)
Data (varies)
Port Number Range
F T S D T S
T E M N F N
P L T S T M
N P P P
E
Applicatio
T
n
Applicatio 21 23 25 53 69
Applicatio 161
n n
Transport TCP UDP
Transport
Internet
well-known port number :1-1023
Data Link common port number: 1024-65535
Port Number Function
Source Port Destination Port
Number Number
Destination port = 23
Telnet Z Send packet to my
Process #1 client server Telnet
application
Telnet Z
Process #2
Port multiplexing
SP DP
1028 23
1029 23
Sequence and Ack Number
Sender Receiver
1 2 3 4 5 6 1 2 3 4 5 6
Send 1
Send 2
Send 3
Ack 4
Send 4
Send 5
Send 6
Retransfer 5
Send 5
Ack 7
Code Bits
U A P R S F
R C S S Y I
G K H T N N
• URG: Urgent Pointer field significant
• ACK: Acknowledgment field significant
• PSH: Push function
• RST: Reset the connection
• SYN: Synchronize sequence numbers
• FIN: No more data from sender
Window Control
Window size = 1
Send 1 Receive 1
Ack 2
Send 2 Receive 2
Sender Receiver
Ack 3
Window size = 3
Send 1 Receive 1
Send 2 Receive 2
Send 3 Receive 3
Sender Ack 4 Receiver
Send 4
Connection-oriented Session
TCP connection
Sender Receiver
Establish connection (synchronize)
1
Data transfer (Send Segments)
2
Tear down connection
3
Establish Connection
TCP Three Way Handshake/Open Connection
Host A Host B
Send SYN
(seq=100 ctl=SYN) 1 SYN received
Send SYN, ACK
SYN received 2 (seq=300 ack=101 ctl=SYN,ACK)
Established
(seq=101 ack=301 ctl=ACK) 3 Established
Data Transfer
SP DP Seq. # Ack. # Upper layer data
Host A Host B
SourceDest.
SourceDest. Seq.
Seq. Ack.
Ack.
SourceDest. Seq. Ack.
1028 23 102
102 301
23 1028 301 103
103
1028 23 103
103 302 SourceDest. Seq. Ack.
23 1028 302 104
104
Tear Down Connection
• TCP four way handshakes/connection
terminating
Host A Host B
Close application FIN
1
ACK to FIN
2
FIN
3 Close application
ACK to FIN
4
UDP Protocol
Bit 0 Bit 15 Bit 16 Bit 31
Source port (16) Destination port (16)
8
Bytes
Length (16) Checksum (16)
Data (if any)
• No sequence and acknowledgement
• Unreliable and connectionless
• Efficient and fast
TCP/UDP Comparison
TCP UDP
Connection oriented Connection connectionless
Or connectionless oriented
Reliable or not Reliable unreliable
With traffic
Control Or not Traffic control No traffic control
Transfer speed Slow Fast
overhead of protocol Big Small
Contents
• OSI model and layer function
• TCP/IP protocol suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
Internet/Network Layer
• Define logical address
• Provide path-finding method
routers
Applicatio
n
Transport TCP UDP
6 17
ARP IP ICMP
Internet Data Link 1
Data Link
IP Packet Format
Bit
1 0 Bit 15 Bit 16 Bit 31
Version Header Type
(4) Length (4) of Service (8) Total Length (16)
Flags
Identification (16) (3) Fragment offset (13)
Time to live (8) Protocol (8) Header checksum (16) 20
Bytes
Source IP Address (32)
Destination IP Address (32)
Options (0 or 32 if any)
Upper layer data (varies if any)
Type of Service Field
0 3 7
precedence D T R 0 0
Bits 0-2: Precedence
Bit 3: Delay
Bit 4: Throughput
Bit 5: Reliability
Bits 6-7: Reserved for future use
MTU and Fragmentation
0 15 16 17 18
Identification (16) D M Fragment offset
0 F F (13)
Flags(3
)
Bit 16: Reserved, must be zero
Bit 17: (DF)0=May fragment, 1=Don’t fragment
Bit 18: (MF)0=Last fragment, 1=More fragment
Host B
Host A
RA RB
MTU 1000
Ethernet IP(1500) HDLC IP(750) Ethernet IP(750)
HDLC IP(750) Ethernet IP(750)
IP Address
Host A Host B
Fei_1/1 Fei_1/2
172.16.2.1 172.16.2.1 10.6.24.2 10.250.8.11
0 7 8 15 16 23 24 31
Dotted
Decimal Network Host
Maximum 255 255 255 255
Binary 11111111111111111111111111111111
128
8
4
2
1
64
32
16
128
8
4
2
1
64
32
16
128
8
4
2
1
128
8
4
2
1
64
32
64
32
16
16
Internet Control Message Protocol
Applicatio
n
Transport
IP ICMP
Internet Data Link 1
Data Link
PING and Reachability
Hi B, Host A Host B I am here.
are you there?
ICMP echo reply
Is B reachable?
ICMP echo request
no yes
Destination Unreachable ICMP echo request
• Host or port unreachable
• Network unreachable
Time Exceeded and TTL
A: Tracert 10.1.1.2
1: 172.16.1.1
2: 200.1.1.2
Host A 3: 10.1.1.2 Host B
172.16.1.1 10.1.1.1
200.1.1.2
200.1.1.1
172.16.1.2 10.1.1.2
RA RB
TTL=1
TTL=2
TTL=3
Contents
• OSI model and layer function
• TCP/IP protocol suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
Data Link Layer
• Combine bit to byte and byte to frame
• Access media by physical address (MAC
address)
• SAP associated with upper layer protocols
type
Applicatio • Error detection without error correction
n
Transport
ARP IP ICMP
Internet Data Link 1
0806 0800
Data Link
Ethernet II (RFC 894 )
MAC Address
Ethernet II frame (RFC 894)
Variable Length
# Bytes 8 6 6 2 46-1500 4
Preamble Dest. AddrSrc. Addr Type Data FCS
00.00.d0
xx.xx.xx
IEEE assign
to Sequence ID for NIC
Manufacture
rs
Address Resolution Protocol
I need the MAC
address of IP I got the packet,
Host A Host B
172.16.3.2 I will reply with my
MAC address.
172.16.3.1 172.16.3.2
Other hosts
IP: 172.16.3.2 = ???
IP: 172.16.3.2
Ethernet: 0800.0020.1111
• Map IP to MAC
• Local broadcast
Packet Process Procedure
FTP client FTP server
ftp://10.66.1.100:21 I wanna download a file
SP:1024 DP:21 Seq.100 Ack.200
SIP:10.66.1.1 DIP:10.66.1.100,TTL=100, DF, Protocol=6
SA:01-00-39 DA:01-00-4A type=0800
01010010100010101010101010100010110111000101001
Contents
• OSI model and layer function
• TCP/IP protocol suite
• Transfer Control Protocol
• Internet Protocol
• Address Resolution Protocol
• IP Network Equipment
Hub — Work in Physical Layer
Signal !!
- Forward signal to all ports
except receive port
- Interconnect hosts in same
network
0101101
0101101 0101101
PC1 PC2 PC3
Switch — Work in Data Link Layer
MAC Out
MAC1 1
MAC2 2
- Forward data according
to MAC address
- Interconnect hosts in
same network
MAC2 IP DATA MAC2 IP DATA
1.1.1.1 1.1.1.2 1.1.1.3
MAC1 MAC2 MAC3
Difference between Hub and Switch
100M 10 ports hub 100M 10 ports switch
bandwidth 100M bandwidth>100M*10*2
More
people
So many people!
more slowly
But it does not
matter
Router — Work in Network Layer
NET OUT
1.0.0.0 fei_1/1
2.0.0.0 fei_1/2
- forward according to
fei_1/1 :1.1.1.254
fei_1/2 :2.2.2.254 destination IP address
MAC3
MAC3 - interconnect hosts in
different network
- collect routing information
MAC3 2.2.2.2 data MAC2 2.2.2.2 data
( OSPF 、 BGP )
1.1.1.1 2.2.2.2
G: 1.1.1.254 G:2.2.2.254
MAC1 MAC2
Routing Switch
Router
I’m a switch?
I’m a router?
Interface fei_1/1 RS
ip add 1.1.1.254 255.255.255.0
Interface vlan10
ip add 1.1.1.254
switch 255.255.255.0
1.1.1.1/24 1.1.1.2/24 1.1.1.1/24 1.1.1.2/24
G:1.1.1.254 G:1.1.1.254 G:1.1.1.254 G:1.1.1.254
Routing Switch Working Mode ——
Switching
vlan10:1.1.1.254 vlan20:2.2.2.254
MAC OUT
MAC4 MAC4 MAC4 vlan10
1 3 MAC4 vlan20
2 MAC1 P1
MAC2 1.1.1.2 data MAC2 1.1.1.2 data
The received frame’s
destination MAC address
is different from RS’s
1.1.1.1 1.1.1.2 2.2.2.2 MAC address , switching
G: 1.1.1.254 G: 1.1.1.254 G:2.2.2.254
MAC1 MAC2 MAC3
Routing Switch Working Mode ——
Routing
MAC table
vlan10:1.1.1.254 vlan20:2.2.2.254
MAC INT
MAC4 MAC4 MAC4 vlan10
1 3 MAC4 vlan20
2
NET Out Hardware forwarding table
2.0.0.0 vlan20
DIP OUT
MAC4 2.2.2.2 data MAC3 2.2.2.2 data vlan10
1.0.0.0
2.2.2.2 P3
Route table
1.1.1.1 1.1.1.2 2.2.2.2
G: 1.1.1.254 G: 1.1.1.254 G:2.2.2.254
MAC1 MAC2 MAC3 routing once, switching for
several times
Comparison: Router and Routing Switch
Router Routing Switch
CPU + NP CPU + ASIC (Application Specific
Integrated Circuit)
Less ports, costly More ports, high cost performance
Applicable to network export Applicable to exchange data in large
LAN, routing capability is not as good
as the same level router
Communication in the Same Network Segment
Suppose A will communicate with B
A judges that it is on the same network segment with B
MAC Port
A searches for the MAC address of B in ARP table 00:20:af:00:00:01 fei_1/1
A sends the ARP request packet to find the MAC address of B
Switch
ARP request
Fei_1/1 Fei_1/3
Dest MAC: ff:ff:ff:ff:ff:ff
Fei_1/2
Source MAC:00:20:af:00:00:01
Dest IP: 192.169.1.2
Source IP: 192.169.1.1
A B C
IP: 192.168.1.1 IP: 192.168.1.2 IP: 192.168.1.3
MAC: 00:20:AF:00:00:01 MAC: 00:20:AF:00:00:02 MAC: 00:20:AF:00:00:03
Communication in the same
network—ARP Response
MAC Port
00:20:af:00:00:01 fei_1/1
Switch 00:20:af:00:00:02 fei_1/2
Fei_1/1 Fei_1/3
Fei_1/2
ARP reply
Dest MAC:00:20:af:00:00:01
Source MAC:00:20:af:00:00:02
A B Dest IP: 192.169.1.1 C
Source IP: 192.169.1.2
IP: 192.168.1.1 IP: 192.168.1.2 IP: 192.168.1.3
MAC: 00:20:AF:00:00:01 MAC: 00:20:AF:00:00:02 MAC: 00:20:AF:00:00:03
Communication of Same Network.
MAC Port
00:20:af:00:00:01 fei_1/1
Switch 00:20:af:00:00:02 fei_1/2
Fei_1/1 Fei_1/3
Dest MAC:00:20:af:00:00:02 Fei_1/2
Source MAC:00:20:af:00:00:01
Dest IP: 192.169.1.2
Source IP: 192.169.1.1
A B C
IP: 192.168.1.1 IP: 192.168.1.2 IP: 192.168.1.3
MAC: 00:20:AF:00:00:01 MAC: 00:20:AF:00:00:02 MAC: 00:20:AF:00:00:03
Communication Between Different Networks
Suppose A will communicate with B
1 A judges that B is on a different network segment
2 A searches for the MAC address of GW in ARP Dest network interface
table 10.1.1.0 255.255.255.252 fei_1/1
10.1.1.4 255.255.255.252 fei_1/2
3 A sends packet to B, with the destination MAC 10.1.1.8 255.255.255.252 fei_1/3
Router
address of the GW
fei_1/3:10.1.1.10/30
fei_1/1:10.1.1.2/30 MAC:00:20:AF:00:00:05
MAC:00:20:AF:00:00:04
Dest MAC:00:20:af:00:00:04 fei_1/2:10.1.1.6/30
MAC:00:20:AF:00:00:05
Source MAC:00:20:af:00:00:01
Dest IP: 10.1.1.5
Source IP: 10.1.1.1
A B C
IP: 10.1.1.1/30 IP:10.1.1.5/30 IP: 10.1.1.9/30
G: 10.1.1.2 G: 10.1.1.6 G: 10.1.1.10
MAC:00:20:AF:00:00:01 MAC:00:20:AF:00:00:02 MAC:00:20:AF:00:00:03
Communication between different
networks
Dest MAC:00:20:af:00:00:02
Dest network interface
Source MAC:00:20:af:00:00:05 10.1.1.0 255.255.255.252 fei_1/1
10.1.1.4 255.255.255.252 fei_1/2
Dest IP: 10.1.1.5 10.1.1.8 255.255.255.252 fei_1/3
Router
Source IP: 10.1.1.1
fei_1/3:10.1.1.10/30
fei_1/1:10.1.1.2/30 MAC:00:20:AF:00:00:05
MAC:00:20:AF:00:00:04
fei_1/2:10.1.1.6/30
MAC:00:20:AF:00:00:05
A B C
IP: 10.1.1.1/30 IP:10.1.1.5/30 IP: 10.1.1.9
G: 10.1.1.2 G: 10.1.1.6 G: 10.1.1.10
MAC:00:20:AF:00:00:01 MAC:00:20:AF:00:00:02 MAC:00:20:AF:00:00:03
Communication Process
Get peer IP address
Whether in YES Is the peer MAC YES Data link layer
the same network address in ARP table? encapsulation
with peer
NO NO
Get peer MAC
Address by ARP Send data at
physical layer
YES YES
Is gateway Is the gateway MAC Data link layer
configured ? address in ARP? encapsulation
NO NO
End
Get gateway MAC
Send error message
address by ARP
Summary
• OSI reference model
• TCP protocol suite
• Transport layer
• Network layer
• Data link layer
• IP network equipment
Thank you.