TCP/IP Protocol
- Application layer - HTTP, FTP, Telnet, SMTP, DNS, etc.
- Transport layer - TCP (reliable stream, ports, flow control,
congestion control), UDP
- Network layer - IP, ICMP, IPv6 (routing)
- Data Link layer - PPP, Ethernet, ATM, etc. (channel sharing)
Packet structure
+------------------+----------------+------------------+---------------+
| Data Link header | Network header | Transport header | Appl. Data... |
+------------------+----------------+------------------+---------------+
Transport Layer
UDP
User Datagram Protocol
Provides an unreliable datagram service between applications
given an unreliable datagram service between hosts
Header (8 bytes)
- Source port, 16 bits (0-65535)
- Destination port, 16 bits (0-65535)
- Length in bytes, 16 bits (0-65535)
- Checksum, XOR of header, 16 bits
If the header checksum fails, the packet is discarded. The data is not
error checked.
TCP
Transport Control Protocol.
Provides a reliable 2-way data stream between remote applications.
TCP header (20 bytes)
- Source port, 16 bits (0-65535)
- Destination port, 16 bits (0-65535)
- Sequence number, 32 bits, number of bytes sent
- Acknowledgment number, 32 bits, number of bytes received
- Header length, 8 bits = 40 unless options are used
- Unused, 2 bits
- URG, 1 bit, unused
- ACK, 1 bit, 1 = received sequence through acknowledgment number
- PSH, 1 bit, unused
- RST, 1 bit
- SYN, 1 bit, 1 = opening connection
- FIN, 1 bit, 1 = closing connection
- Receiver window size, 16 bits (bytes free in buffer, scaled using
option in setup)
- Checksum, 16 bits (XOR of header only)
- Urgent pointer, 16 bits, unused
- Options, variable length (usually 0)
- Data, variable length (usually 0-1500)
Underlying network layer provides an unreliable packet delivery service.
Packets may be lost, duplicated, or delivered out of order.
Reliable stream
Protocol to ensure that all packets are received, and in the correct order.
- Sender sends packet, waits for ACK
- Receiver replies with ACK, seq. number
- Sender marks data as sent
- If checksum fails, packet is discarded
- If ACK times out, sender retransmits all unmarked data
- If same packet is ACKed 3 times, sender resends next packet
(fast resend)
- Receiver ACKs all packets, including duplicates
Connection setup
Protocol to open and close connections.
Action Client state Server state
------ ------------ ------------
CLOSED LISTEN
SYN ---> SYN_SENT SYN_RCVD
<--- SYN+ACK ESTABLISHED ESTABLISHED
... ...
FIN ---> FIN_WAIT_1 CLOSE_WAIT
<--- ACK FIN_WAIT_2
<--- FIN TIME_WAIT LAST_ACK
ACK ---> CLOSED
Wait 30 seconds CLOSED
Flow control
Protocol to ensure that the sender does not send data faster than
the receiver can receive it.
- Receiver sends window size in ACK
- If window is small, sender waits
- If window size is 0, sender sends 1 byte (to get updated window in ACK)
Congestion control
Protocol to ensure that the sender does not send data faster
than the network can transmit it.
- Tahoe
- Send 1 pack, wait for ACK (slow start)
- Send 2, 4, 8, ... up to threshold, wait for ACK
- If timeout, divide threshold by 2 and go back to 1, 2, 4, 8...
- Reno (most commonly used)
- Fast retransmission after 3 ACKs
- Fast recovery, cancel slow start after 3 ACKs
- Vegas
- Uses round trip delays to predict congestion
Network Layer
Routing algorithms
- Global - Link state
- Each node has full knowledge of network
- Each node computes shortest path to destination
- Decentralized - Distance Vector
- Each node knows only its neighbors
- Each node tells its neighbors the distance to all other nodes
- Both algorithms result in global routing tables
The Internet uses a hierarchical network.
- Autonomous System (AS) - a local area network (LAN) using its
own routing protocol
- Wide area network (WAN) - connects AS's
- Gateway - connects a LAN to a WAN
- Router - has 2 or more IP addresses
- LAN - usually a host with more than one network interface
- WAN - usually specialized hardware (no transport layer or above)
IP
Internet Protocol
Provides an unreliable packet delivery service between hosts (routing).
Header (20 bytes)
- Version, 4 bits, IPv4 = 4
- Header length, 4 bits, 4 = 20 bytes
- TOS (Type of Service), 8 bits, unused
- Packet length, 16 bits, (0-65535)
- Identifier for fragment reassembly, 16 bits
- Flags (3 bits), 1 = more fragments follow, 0 = last/only fragment
- Fragmentation offset, 13 bits (0-8191)
- TTL, Time To Live, 8 bits (255-0), decrement each hop, discard if 0
- Upper layer protocol, 8 bits, 6 = TCP, 17 = UDP
- Header checksum, 16 bits
- Source IP address, 32 bits
- Destination IP address, 32 bits
- Options (if any), 0-10 32-bit words
- Data, 0-65515 bytes
Addresses
- Class A: 0-127.x.x.x
- Class B: 128-191.0-255.x.x
- Class C: 192-223.0-255.0-255.x
- Multicast: 224-239.x.x.x
- Localhost: 127.0.0.1
- Broadcast: x.x.x.255
Packet fragmentation
Sender breaks up IP packet into MTU sized units. Receiver reassembles.
- MTU = Maximum Transfer Unit
- Ethernet: MTU = 1500
- Wide area networks: MTU = 576
+----------------+ +----------+ +-----------+ +------------+
| Len = 1500 | | Len = 500| | Len = 500 | | Len = 500 |
| ID = 123 | = | ID = 123 | | ID = 123 | | ID = 123 |
| Flags = 0 | | Flags = 1| | Flags = 1 | | Flags = 0 |
| Frag = 0 | | Frag = 0 | | Frag = 500| | Frag = 1000|
+----------------+ +----------+ +-----------+ +------------+
Routing protocols
RIP - Routing Internet Protocol
- Distance Vector algorithm
- Uses number of hops as cost metric
- Widely used within AS's
- Uses UDP to communicate with neighbors
OSPF - Open Shortest Path First
- Successor to RIP
- Link State algorithm
- Secure (authenticated) transmission of routing tables
- Hierarchical
- Used within AS's
IGRP - Internal Gateway Routing Protocol
- Proprietary (Cisco)
- Distance Vector algorithm
- Used within AS's
BGP - Border Gateway Protocol (or BGP4)
- Used between AS's
- Successor to EGP - Exterior Gateway Protocol
- Distance vector algorithm
ICMP
Internet Control Message Protocol
Format
In data portion of IP packet.
ICMP
type Code
0 0 Echo reply to ping
3 0 Destination network unreachable
3 1 Destination host unreachable
3 2 Destination protocol unreachable
3 3 Destination port unreachable
3 6 Destination network unknown
3 7 Destination host unknown
4 0 Source quench (unused, TCP provides congestion control)
8 0 Echo request by ping
9 0 Router advertisement (used by RIP)
10 0 Router discovery
11 0 TTL expired (router loop, also used by traceroute)
12 0 IP header bad
IPv6
Internet Protocol version 6. Proposed replacement for IPv4.
We will run out of IP addresses in 2005-2010.
- 128 bit IP addresses
- No checksum (provided by TCP and data link layers)
- No packet fragmentation (packets too long are discarded)
- No option fields (uses next header field)
Header format (40 bytes)
- Version, 4 bits, IPv6 = 6
- Priority, 4 bits, replaces TOS
- Flow, 24 bits, identifier for special data types
- Payload length, 16 bits (0-65535)
- Next header, 8 bits (TCP or UDP)
- Hop limit, 8 bits (same as TTL)
- Source address, 128 bits
- Destination address, 128 bits
- Data (cannot exceed MTU)
Back