TCP/IP Essentials A Lab-Based Approach
Chapter 2 A Single Segment Network -- Data Link Layer
Shivendra Panwar, Shiwen Mao Jeong-dong Ryoo, and Yihan Li
Data Link Layer
!! !!
In this lecture, we will focus on the Data Link Layer. Main tasks of the data link layer:
"! Transfer
Application Layer Transport Layer Network Layer Data Link Layer Physical Layer
data from the network layer of one machine to the network layer of another machine. "! Convert the raw bit stream of the physical layer into groups of bits (frames). "! Perform flow control between sender and receiver.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
TCP/IP Suite
Types of Networks
!!
Point-to-point network
Two end hosts connected by a link Usually for long distance connections "! Examples: dialup, SONET/SDH
"! "!
Point-to-Point Network
!!
Broadcast network
A number of stations share a common transmission medium "! Local networks "! Examples: Ethernet, wireless local area networks
"!
Broadcast Network
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Point-to-Point Networks
!! The
Point-to-Point Protocol (PPP) is a data link protocol. !! The main purpose of PPP is encapsulation and transmission of IP datagrams, or other network layer protocol data, over a serial link. !! Currently, most dial-up Internet access service are provided using PPP.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 4
Point-to-Point Protocol (PPP)
!! PPP
consists of two types of protocols:
Control Protocol (LCP)
"!Link
!! Responsible
for establishing, configuring and negotiating the data-link connection.
"!Network
!! IP
Control Protocol (NCP)
Control Protocol (IPCP), used for transmitting IP datagrams over a PPP link,
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
PPP Encapsulation
!!
PPP frame format
"! Flag:
mark the beginning and ending of a frame "! Protocol: used to multiplex different protocol data "! No addressing, only two end hosts.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Local Area Networks
!! !! !! !!
Local area networks (LANs) typically connect computers within a building or a campus. Almost all LANs are broadcast networks.
"!
exception: switched Ethernet Switched Ethernet LANs have star topology
Typical topologies of LANs are bus or ring.
"!
The protocol that determines who can transmit on a broadcast channel is called Medium Access Control (MAC) protocol.
Bus LAN
Ring LAN
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
MAC and LLC
!!
!!
!!
!!
In any broadcast network, the stations must ensure that only one station transmits at a time on the shared communication channel. The protocol that determines who can transmit on a broadcast channel is called Medium Access Control (MAC) protocol. The MAC protocol is implemented in the MAC sublayer which is the lower sublayer of the data link layer. The higher portion of the data link layer is often called Logical Link Control (LLC).
to Network Layer
Data Link Layer
Logical Link Control Medium Access Control
to Physical Layer
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
LLC
!!
LLC can provide different services to the network layer:
"! acknowledged
connectionless service "! unacknowledged connectionless service "! connection-oriented service
!! !! !!
Framing Error control Addressing
9
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
MAC
!! !!
MAC algorithms are used to resolve collisions and share the medium in a broadcast network. Examples of MAC:
"! Aloha "! Carrier
Sense Multiple Access/Collision Detection (CSMA/CD) "! Carrier Sense Multiple Access/Collision Avoidance (CSMA/CA)
!!
Ethernet
"! An
industry standard since 1982 "! Based on CSMA/CD.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 10
Collisions in Ethernet
!!
!! !!
The collision resolution process of Ethernet requires that a collision is detected while a station is still transmitting. Assume the maximum propagation delay on the bus is a. Restrictions: Each frame should be at least twice as long as the time to detect a collision (2a).
11
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Collisions in Ethernet
t0
A B
A Begins Transmission
t0+a- !
A B
B Begins Transmission
t0+a
A B
B Detects Collision
t0 +2a
A
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
A detects collision just before end of transmission
12
CSMA/CD
!! !! !!
Each station listens before it transmits. If the channel is busy, it waits until the channel goes idle, and then transmits. If the channel is idle it transmits immediately. Continue sensing for 2a seconds.
"! a :
the maximum end-to-end propagation delay.
!!
If collision is detected, stop transmitting data and start to backoff.
"! Backoff:
wait a random amount of time before attempting to retransmit.
13
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Exponential Backoff Algorithm
!! !!
If a station is involved in a collision, it waits a random amount of time before attempting a retransmission.! The random time is determined by the following algorithm:
Set slot time to 2a. "! After first collision wait 0 or 1 time unit. "! After the ith collision, wait a random number between 0 and 2 i-1 time slots. "! Do not increase random number range if i>9. "! Give up after 16 collisions.
"!
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
14
Ethernet Switches
!! In
an Ethernet LAN, hosts can be
"!Attached
to a common cable, or "!Connected by Ethernet switches.
!! Ethernet
"!Offer
switches are MAC layer devices that switch frames between different ports.
guaranteed bandwidth for LAN segments. "!Separate a LAN into collision domains.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
15
Ethernet Encapsulation
Dest. Addr
.
Src. Addr 6
Type 2 Type 0800 2 Type 0806 2 Type 8035 2
Data
46-1500
CRC
4
IP datagram
46-1500
ARP request/reply
28
PAD
18
RARP request/reply
28
PAD
18
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
16
IEEE 802.11 Wireless LANs
!!
Replacement for Ethernet:
wireless channel "! Frequency band: unlicensed radio spectrum at 2.4GHz and 5.7GHz
"!
!!
Data rates:
"! "!
IEEE 802.11b: 1, 2, 5.5, 11 Mbps IEEE 802.11 a and g: 54 Mbps at 2.4GHz and 5.7GHz indoor: 20 - 25 meters outdoor: 50 - 100 meters
!!
Range: transmission power up to 100mW
"! "!
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
17
IEEE 802.11 Protocols
!! !! !! !! !! !!
IEEE 802.11b: 5, 11Mbps IEEE 802.11a: 6, 9, 12, 18, 24, 36, 48, 54Mbps IEEE 802.11g: 54 Mbps IEEE 802.11i: security IEEE 802.11f: Inter Access Point Protocol IEEE 802.11e: Quality of Service enhancement
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
18
IEEE 802.11 Architecture
!!
Two working modes:
!! the ad hoc mode
!! the infrastructure mode
! Fixed Access Point (AP) provides: !! connection to wireline network !! relay function ! Handoff, an active host moves from one access point to another.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
! No access point. ! Hosts communicate with each other directly.
19
Extended Service Set
ESS: a set of BSSs interconnected by a distribution System
! ESS and all of its stations appear to be in a single MAC layer ! AP communicate with each other to forward traffic ! Station mobility within an ESS is invisible to the higher layers
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 20
IEEE 802.11 MAC Layer
!! !!
!!
A super time frame consists of Contention-free Period and Contention period. These two periods are variable length. Their duration depends on the traffic load at the AP and at the mobile hosts. Different channel access control schemes are used for these two periods.
A Super Frame A Super Frame
Contention-free Period
Contention Period
Contention-free Period
Contention Period time
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
21
IEEE 802.11 MAC Layer
!!
Point Coordination Function (PCF):
"! For
delay sensitive service "! Used in Contention free period "! Use polling for channel access control
!!
Distributed Coordination Function (DCF):
"! For
best-effort data service "! Use CSMA/CA for channel access control "! RTS/CTS scheme is used to solve hidden-terminal problem
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 22
CSMA/CA
!!
Why not CSMA/CD?
"! difficult
to sense collisions when transmitting due to weak received signals (fading)
!!
CSMA/CA:
"! CSMA: carrier sensing !! Carrier: do not send !! No carrier: send !! Needs to be enhanced in wireless networks "! CA: collision avoidance !! random backoff !! priority ack protocol
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
23
CSMA/CA : Backoff
!! !! !!
Immediate access when medium is free " IFS (Inter Frame Space) When medium is not free, defer until the end of current frame transmission + IFS To begin backoff procedure:
"! "! "!
Choose a random number in (0, Cwindow) Listen to determine if the channel is busy for each time slot Decrement backoff time by one slot if channel is idle
!! !!
Suspend backoff procedure if channel is busy in a time slot Resume backoff when the channel becomes idle again.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
24
IEEE 802.11 Priorities
!!
Priorities:
"! Defined
!!
through different inter frame spaces "! SIFS (Short Inter Frame Spacing)
Highest priority, for ACK, CTS, Polling response
"! PIFS (PCF IFS) !! Medium priority, for time-bounded service using PCF "! DIFS(DCF, Distributed Coordination Function IFS) !! Lowest priority, for asynchronous data service
DIFS Medium Busy Direct access if the medium is free " DIFS Panwar, Mao, Ryoo, Li: TCP/IP Essentials SIFS 25 DIFS PIFS Contention Next Frame
CSMA/CA : Backoff
DIFS Frame defer B C D
Generate a random, number begin backoff Channel busy suspend backoff counting
DIFS CWindow
DIFS CWindow
DIFS Frame
DIFS
Frame defer Frame defer
Channel idle Resume backoff
Frame
Backoff counter reaches 0 and channel is idle, transmit
!!
Cwindow:
"! "!
Increases after each failure: 31, 63, 127, 255, 511, 1023, then give up Reset to 31 after each successful transmission
26
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
CSMA/CA : ACK Protocol
SIFS DIFS Source data ACK Contention Window Others Next frame
Dest.
!! !!
Receiver of directed frames returns an 14 Byte ACK immediately when CRC is correct. If no ACK received, the sender will retransmit after a random backoff
27
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Exposed/Hidden Terminal Problems
W Z X Y W Y Z
The exposed terminal problem ! Y will not transmit to X even though it can do so
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
The hidden terminal problem ! Y finds that medium is free and transmits a packet to W
28
RTS/CTS
!! The
sender send Request-to-Send (RTS): 20bytes !! Receiver returns Clear-to-Send (CTS): 14 bytes !! Then transmission begins !! Solves hidden terminal problem
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
29
IEEE 802.11 Frame Format
!! More
"! 30
fields than other data-link protocols !! High overhead:
byte header, RTC/CTS, ACK "! Four Address fields: BSSID, Source Address, Destination
Address, Receiving Station Address, Transmitting station Address
!! Different
"! all
frame types for different tasks:
30
fields are not present in all types of frames
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
The Address Resolution Protocol
!!
!! !! !!
IP addresses are not recognizable in the interface layer where physical addresses (or MAC addresses) are used. Different kinds of physical networks use different addressing schemes. Address Resolution Protocol (ARP): maps an IP address to a MAC address. Reverse Address Resolution Protocol (RARP): maps a MAC address to an IP address.
31
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
ARP Process
!! When
a source host wants to send an IP packet to a destination, it first broadcasts an ARP request asking for the MAC address corresponding to the destination IP address. !! The destination host will return an ARP reply with its MAC address.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 32
ARP Packet Format
!! !! !! !!
28bytes long. An ARP request or ARP reply is encapsulated in an Ethernet frame. Protocol Type: set to 0x0806 for ARP messages. Operation field: specifies ARP request (1), ARP reply (2), RARP request (3), or RARP reply (4).
33
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
ARP Request
!! Ethernet
destination: ff:ff:ff:ff:ff:ff (broadcast address) Ethernet Address: not set.
!! Target
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
34
ARP Reply
!!
!!
The ARP reply is sent by the node whose IP address matches the target IP address in the ARP request. "! It fills its MAC address into the target Ethernet address field of the ARP request. "! It then swaps the two sender addresses (Ethernet and IP addresses) with the two target addresses, sets the op field to 2. "! The ARP reply is sent back to the source host only. All other nodes receiving the broadcast ARP ignore the request, since their IP addresses do not match the target IP address.
35
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
ARP Cache
!! !! !!
Sending an ARP request/reply for each IP datagram is inefficient. Each host maintains an ARP cache containing the recent resolved IP addresses. A source host first checks it ARP cache for the destination MAC address,
"! If
an entry is found, sends out the IP packet within an Ethernet frame. "! Otherwise, sends out an ARP request.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
36
Manipulating the ARP Table
!!
Elements of an entry in the ARP table:
"! An
IP address "! A MAC address "! Flags
!! !!
A normal entry expires after 20 minutes after it is created or the last time it is referred. Manipulate ARP table by the arp command:
"! arp
a: Displays all entries in the ARP table. "! arp b: Deletes an entry in the ARP table. "! arp s: Inserts an entry into the ARP table.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 37
Proxy ARP
!! !! !!
Hide the two physical networks from each other. A router answers ARP requests targeted for a host. Host A and B are configured to be in the same logical subnet
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
38
Gratuitous ARP
!! !! !!
!!
Occurs when a host sends an ARP request resolving its own IP address. Usually happens when the interface is configured at bootstrap time. The interface uses gratuitous ARP to determine if there are other hosts using the same IP address. The senders IP and MAC address are broadcast, and other hosts will insert this mapping into their ARP tables.
39
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Loopback Interface
!!
!! !!
!! !!
Most TCP implementations have a loopback interface with IP address 127.0.0.1 and name localhost. The localhost behaves as a separate data link interface. A packet that is sent to the loopback interface moves down the protocol stack and is returned back by the driver software for the localhost device. Used for debugging. Packets sent to loopback interface will not appear on network.
40
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Network Interface Operations
Functional Diagram of an Ethernet Interface Card
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 41
Maximum Transmission Unit
!! There
is a limit on the frame size of each data link layer protocol. !! This limit is called maximum transmission unit (MTU). !! MTUs for various data link layers:
"!Ethernet:
1500 "!FDDI: 4352
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 42
ICMP
!! !! !! !!
The Internet Control Message Protocol (ICMP) is a network layer protocol used for error and control messages in the Internet. ICMP provides an error reporting mechanism of routers to the sources. All ICMP packets are encapsulated as IP datagrams. The packet format is simple:
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
43
Types of ICMP Packets
!!
Many ICMP packet types exist, each with its own format.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
44
ICMP Message Types
!! !!
ICMP messages are either query messages or error messages. ICMP query messages:
!! !! !! !!
Echo request / Echo reply Router advertisement / Router solicitation Timestamp request / Timestamp reply Address mask request / Address mask reply Host unreachable Source quench Time exceeded Parameter problem
45
!!
ICMP error messages:
!! !! !! !!
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
ICMP Error Messages
!!
!!
Each ICMP error message contains the header and at least the first 8 bytes of the IP datagram payload that triggered the error message. To prevent that too many ICMP messages, ICMP error messages are not sent
"! for
multiple fragments of the same IP datagrams "! in response to an error message "! in response to a broadcast packet
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
46
ICMP Error Message Types
!!
There are 16 different ICMP error messages (codes) of type Destination Unreachable (Type = 3)
Message Type Network unreachable Host unreachable Protocol unreachable Port unreachable Fragmentation needed but bit not set Source route failed Destination network unknown Destination node unknown Code 8 9 10 11 12 13 14 15 Message Type Source host isolated Destination network administratively prohibited Destination host administratively prohibited Network unreachable for TOS Host unreachable for TOS Communication administratively prohibited by filtering host precedence violation precedence cutoff in effect
47
Code 0 1 2 3 4 5 6 7
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
ICMP Port Unreachable
!!
If, in the destination host, the IP module cannot deliver the datagram because the indicated protocol module or process port is not active, the destination host may send a port unreachable message to the source host.
R e q u e st a se at a port N rvice o. 1234
Client
abl h c a nre e
Server
No process is waiting at Port 1234
Port
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
48
PING
!! PING
(Packet InterNet Gopher) is a program that utilizes the ICMP echo request and echo reply messages. !! PING is used to verify if a certain host is up and running. It is used extensively for fault isolation in IP networks. !! PING can be used with a wide variety of options.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials 49
Echo Request and Reply
!! !! !!
Pings are handled directly by the kernel. Each Ping is translated into an ICMP Echo Request. The Pinged host responds with an ICMP Echo Reply.
ICMP ECH O REQUE ST
Host 1
ICMP
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
Host 2
EC EP R O H LY
50
Echo Request/Reply Message Format
!! !!
Identifier is set to process ID of querying process. Sequence number is incremented for each new echo request.
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
51
Sock Traffic Generator
!!
Sock is a test program.
"! Can
be run as a client or as a server "! Use UDP or TCP.
!!
Sock operates in one of the following four modes:
"! Interactive
client "! Interactive server "! Source client "! Sink server
Panwar, Mao, Ryoo, Li: TCP/IP Essentials
52