Medium Access Control Sublayer: Slides Courtesy: Sweta & Chebrolu
Medium Access Control Sublayer: Slides Courtesy: Sweta & Chebrolu
Chapter 4
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Problem
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Network Topologies
Bus Star
e.g., Ethernet (old-fashioned) e.g., Ethernet Hubs
Ring
e.g., Token Ring
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
The Medium Access Control (MAC)
Sublayer
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Human Analogy
• Speed dating party: couples want to talk with each
other
• Assumption: everyone talks loudly, so everyone
can hear everyone else in the room
• If two speakers talk at the same time, none can
understand what was said.
• How to facilitate meaningful conversations without
interferences?
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Types of MAC Protocols
• Channel Partitioning Protocols
• Random Access Protocols
• Taking Turn Protocols
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Channel Partitioning Protocols
• Key idea: divide resources into smaller “pieces”, and
allocate each piece to each node for exclusive use.
• Time Division Multiple Access (TDMA)
• Uses Time Division Multiplexing (TDM), which
divides time into N time slots
• Disadvantages: sender limited to C/N (C: channel
capacity) even when other senders are idle,
channel access delay
• Frequency Division Multiple Access (FDMA)
• Uses Frequency Division Multiplexing (FDM), which
divides spectrum into N frequency bands
• Disadvantages: sender limited to C/N, sender-
receiver channel coordination
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Random Access Protocols
• Key Idea: If channel is idle, start transmitting. If collision
happens, backoff and try again.
• No a priori coordination among nodes
• Sender transmits at full rate. If two or more transmit at
the same time -> collision.
• Specify
• How to detect collisions?
• How to recover from collisions?
• Disadvantages: High load leads to too many collisions
and wastage of resources.
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Taking Turns Protocols
• Key idea: Quickly poll to see who wants to talk, give time
slots to only speakers.
• Comparisons:
• Channel partitioning protocols: efficient and fair at
high load, inefficient at low load
• Random access protocols: efficient at low load,
inefficient at high load
• Taking turns protocols: make the best of both worlds!
• Two types:
• Centralized: polling
• Decentralized: token passing
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Taking Turns Protocols: Polling
• Key idea: A central coordinator polls nodes in a round
robin fashion.
• Disadvantages:
• Polling overhead (single user will get rate < C)
• Single point of failure (coordinator)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Taking Turns Protocols: Token Passing
• Key idea: Control token passed from one node to the
next in a certain order
• Disadvantages:
• Token overhead
• Single point of failure (token)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Usages
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Outline
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Multiple Access Protocols
• ALOHA »
• CSMA (Carrier Sense Multiple Access) »
• Collision-free protocols »
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
ALOHA
• 1970s: wireless computer network developed at
University of Hawaii to interconnect Hawaiian islands.
• Inspiration to many standards: Ethernet, WiFi, Cellular
• Two versions of ALOHA:
• Pure ALOHA
• Slotted ALOHA
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Pure ALOHA
In pure ALOHA, users transmit frames whenever they
have data; users retry after a random time for collisions
• Sender can check whether collisions happen
through collision signals
• Efficient and low-delay under low load
User
E Collision
Collision Time
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 1
• Many nodes sharing a link -> Need Medium Access
Control (MAC)
• Three broad classes of MAC protocols:
• Channel Partitioning: divide resource into small
”pieces” (time slots, frequency); allocate piece to
node for exclusive use
• Random Access: allow full access to resource but
provide means to recover from collisions
• Taking turns: taking turns to use the resource, but
nodes with more need get longer turns
• Pure ALOHA: transmit frames whenever have data
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Efficiency of Pure ALOHA (1)
• What is the efficiency of pure ALOHA?
• What is the probability that a transmitted frame does
not suffer collision?
• Assumptions:
• Frames are of equal length
• Probability of k transmission attempts (old
retransmissions and new) per frame time (amount of
time needed to transmit a frame) is Poisson with
mean G per frame time.
𝐺 𝑘 𝑒 −𝐺
• Pr[𝑘] =
𝑘!
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Efficiency of Pure ALOHA (2)
• Throughput (average # successful frame transmissions
per frame time):
• 𝑆 = 𝐺𝑃0
• 𝐺: load (average # transmission attempts per frame
time)
• 𝑃0 : probability of a transmission succeeding
Probability of k transmission
attempts during 2 frame times long is
(2𝐺)𝑘 𝑒 −2𝐺
Pr[𝑘] =
𝑘!
𝑃0 : Probability of no additional
transmissions during two frame times
long:
𝑒 −2𝐺
𝑆 = 𝐺𝑒 −2𝐺
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Efficiency of Pure ALOHA (3)
• Maximum Throughput
• G = 0.5
• S = 1/2e = 0.184 (18%)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Slotted ALOHA (1)
• Time divided into discrete intervals (slots)
• Slot interval corresponds to frame time
• Nodes can transmit frames only at beginning of slots.
• Nodes are time synchronized
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Slotted ALOHA (2)
• Throughput:
• S = 𝐺𝑃0
= G*Pr(no transmissions in a frame time) = 𝐺𝑒 −𝐺
𝑡0 𝑡0 + 𝑡 𝑡0 + 2𝑡 𝑡0 + 3𝑡
Vulnerable
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Efficiency of Slotted ALOHA (3)
• Maximum Throughput
• G=1
• S = 1/e = 0.368 (37%)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Example
• Suppose that a radio system uses a 9600 bps
channels for sending call setup request messages to a
base station. Suppose that frames are 120 bits long.
What is the maximum throughput possible with pure
ALOHA and with slotted ALOHA?
• The system transmits frames at a rate of 80
frames/sec
• The maximum throughput for pure ALOHA is 15
frames/sec
• The maximum throughput for slotted ALOHA is 30
frames/sec
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Carrier Sense Multiple Access (CSMA)
• What we have learned:
• Simple random access protocols including Pure
ALOHA and Slotted ALOHA
• Maximum efficiency of ALOHA is poor
• Carrier Sense Multiple Access (CSMA):
• Another class of random access protocols
• More efficient
• Persistent and non-persistent
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Problems with ALOHA
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
CSMA (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Non-Persistent CSMA
• Used in 802.15.4 (Zigbee/Sensor technology)
• If a node has a frame to send, listen to channel:
• If channel busy, do not sense anymore. Wait a
random amount of time and try again
• If channel idle, transmit
• If collision, wait a random amount of time and start
over
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
P-Persistent CSMA
• Employed by 802.11 (WiFi)
• Assumes a slotted system
• If a node has a frame to send, listen to channel on slot
boundaries:
• If channel idle, transmit with probability p (defer to
next slot with probability q=1-p). Repeat till frame
sent or channel busy due to another transmission
• If channel busy, wait till idle. Repeat above.
• If collision, wait a random amount of time and try
again.
• Good tradeoff between non-persistent and 1-persistent
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Efficiency of CSMA
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 2
Two simple random access protocols
• Pure ALOHA & Slotted ALOHA
• Maximum efficiency of both is poor
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
CSMA with Collision Detection (CSMA/CD)
• Problem with persistent and non-persistent CSMA:
• If two stations sense the channel to be idle and begin
transmitting simultaneously, their signals will collide.
• CSMA/CD improvement is to quickly detect the collision
and abruptly stop transmission.
• Listen before talk
• Simultaneous talk, stop talking -> save time and
bandwidth
• Basis of classic Ethernet (1 persistent CSMA/CD)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Collision Detection (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Collision Detection (2)
• Collision detection done by hardware
• Propagation delay affects efficiency
• Longer the propagation delay, higher chances of
collision
• Worst case delay of detecting collision?
• One RTT
• On detecting collision, all senders responsible for the
collision send a jamming signal, so that other nodes
know there is a collision and abort the transmission.
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
CSMA/CD
If a node has a frame to send, listen to channel:
• If channel idle, transmit and listen while transmitting
• If channel busy, wait until channel idle
• If no collision detected, done
• If collision detected, stop transmission, send jamming
signal, wait random time and retry.
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Binary Exponential Backoff (1)
• How long to wait after collision and before retry?
• After collision, time is divided into discrete time slots
whose length is equal to the worst-case delay of
detecting collisions (i.e., one RTT)
• After the n-th collision, wait K time slots
• If n = 1, choose K from {0,1}
• If n = 2, choose K from {0,1,2,3}
• …..
• If n = 10, choose K from {0,1,2,…., 1023}
• If n = m<16, choose K from {0,1,…,2𝑖 -1}, i=
min(m,10)
• If n = 16, report failure, further recovery is up to
higher layers
Binary Exponential Backoff (2)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Collision-Free Protocols
• We have learned so far:
• ALOHA, CSMA
• Both are random access protocols
• Collisions will happen in both protocols
• What we will learn next:
• Collision-Free protocols or taking turn protocols
− Bitmap
− Token ring
• Avoid collisions entirely
• Most are not currently used
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Bitmap
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Token Ring
Token sent round ring defines the sending order
• Station with token may send a frame before passing
• To stop the frame circulating infinitely, either source
or destination removes it from the ring.
• Idea can be used without ring too, e.g., token bus
Token
Station
Direction of
transmission
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Ethernet
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Background
• Very successful and widely used technology
• Kept up with speed race: 10Mbps to 100Gbps
• IEEE 802.3 working group
• Many standards (different speeds, different physical
media)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Classic Ethernet
• 1970s: Metcalfe conceived the idea
• Up to early 1990s:
• Use bus topology based on co-axial cable
• 10Mbps
− Thick Ethernet (10Base5)
− Thin Ethernet (10Base2)
• Medium Access Control: 1-persistent CSMA/CD
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Problems with Bus Topology
• Co-axial cables were expensive
• Break/Fault in co-axial cable affects all nodes
• Adding/removing nodes disrupts the entire network
• Cabling issues lead to star topology
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Star Topology
• Connect via hub or switch
• 10BaseT, 100BaseT (Fast Ethernet), 1000BaseT
(Gigabit Ethernet)
• Based on twisted pair cables
• Low cost, reliable, easy
management/troubleshooting
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Hub
• Operates at the physical layer
• Bits from one link sent out on all other links at the same
rate after boosting up the energy
• No frame buffering
• No MAC protocol at hub
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Interconnection with Hubs
• Can increase coverage range
• Cannot connect 10BaseT with 100BaseT
Hub
Hub Hub
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Interconnection with Switches
• Can increase coverage range
• Can separate collision domains
• Can connect 10BaseT with 100BaseT
Switch
Hub Hub
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Ethernet Services
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Ethernet Frame Structure (1)
• Preamble:
• Each of the first 7 bytes contains bit pattern
10101010 for synchronization
• Last byte containing bit pattern 10101011 is the start
frame delimiter
• Destination & Source address: 6 bytes MAC address
• Type: specify which higher layer protocol the frame is
intended
Bytes
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Ethernet Frame Structure (2)
• Data: IP payload
• Up to 1500 bytes, as buffering large frame in RAM is
expensive
• Pad: fill out the frame such that (Data+Pad) is not
shorter than 46 bytes
• Minimum frame length aims to help distinguish valid
frames from garbage.
• Checksum: error detection
Bytes
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Ethernet Address
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 3
CSMA/CD
• Adds another feature “CD” to improve
performance
• Binary exponential backoff algorithm determines
how long to wait after detecting collisions
Collision-free/taking turn protocols avoids collisions
entirely.
Ethernet underwent significant evolution over the years
• Speed increased from 10Mbps to 100Gbps
• Variety of media (coaxial cable, twisted pair, fiber
optics)
• Switching circumvented need for MAC
• Only constant: frame format
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs – Hidden terminals
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs – Exposed terminals
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs – MACA (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs – MACA (2)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Wireless LANs – MACA (3)
MACA avoids the problem of exposed terminals
• B wants to send data to A; C wants to send data to
another node
• B sends RTS to A first;
• C hears the RTS, so it waits for CTS
• A sends CTS to B;
• After waiting for a certain period time without hearing
CTS (as C is out of the transmission range of A), C
starts transmitting
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 Architecture/Protocol Stack (1)
802.11 networks can be used in two modes
• Infrastructure mode: Wireless clients associate to a
wired AP (Access Point)
• Ad-hoc mode: Wireless clients directly talk to each
other without AP
To Network
Access
Point
Clien
t
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 physical layer
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 - MAC
Two medium access schemes:
• Distributed Coordination Function (DCF)
• Stations contend for transmission opportunities in a
distributed way
• CSMA/CA + ACK (mandatory)
• RTS/CTS (optional, often not used)
• Point Coordination Function (PCF)
• AP sends poll frames to trigger transmissions in a
centralized way
• Not used in practice
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 MAC – CSMA/CA+ACK
• Compared with CSMA/CD, CSMA/CA
− Inserts backoff slots before transmitting data when sense
idle to avoid collisions
− Doesn’t wait for a collision (frame is sent in its entirety)
• ACKs are used for wireless errors (lack of ACK
indicates an error)
» If error, backoff and retry
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 MAC – RTS/CTS
• Virtual channel sensing with the NAV and optional RTS/CTS avoids
hidden terminals
• With virtual sensing, each station keeps a logical record of
when the channel is in use by tracking the NAV(Network
Allocation Vector)
• All stations hear the data frame defer during the acknowledge
period based on NAV of the frame
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
802.11 MAC – Interframe Spacing
• Different interframe intervals add quality of service
− Short intervals give preferred access, e.g., control, VoIP
• MAC has other mechanisms too, e.g., power save
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Data Link Layer Switching
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Motivation
What we have learned so far:
• Two-node network (point-to-point link, building block)
• Network of multiple nodes (multi-point link)
Next: How to join multiple LANs into a larger network?
• Solution: Switching
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Bridge/Switch
• Old name for switch, developed when classic Ethernet
was in use
• Main function: transfer data from an input to one or
more outputs
• Provides Star topology, and thus more scalable
• Runs appropriate data link protocols on each link
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Switching
Which port to forward incoming frames?
• Table in bridge lists each possible destination and which
output port it belongs on
e.g.,
Table at B1:
• D belongs to port 4
Table at B2:
• D belongs to port 1
• E&F belongs to port 2
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Backward Learning
• How to build the table when bridges are first plugged in?
• Backward learning
− Initially, every incoming frame for an unknown destination is
output on all the ports, except the one it arrived on
(flooding).
− Associates source address on frame with input port
− Frame with destination address sent to learned port
− Unlearned destinations are sent to all other ports
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Frame Forwarding Procedure
• For an incoming frame:
• If the port for the destination address is the same as
the source port, discard the frame
• If the port of the destination address and the source
port are different, forward the frame on to the
destination port
• If the destination port is unknown, use flooding and
send the frame on all ports except the source port
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Repeaters, Hubs, Bridges, Switches,
Routers, & Gateways
Devices are named according to the layer they process
• A bridge or LAN switch operates in the Link layer
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 4
Wireless differ from wired communication
• Nodes cannot detect collisions -> collision
avoidance + ACK
• Hidden and exposed terminals -> MACA
802.11 (WiFi)
• CSMA/CA + ACK
− Start with a random backoff when channel is idle
− Loss of ACK indicates an error
• RTS/CTS avoids hidden terminals
Data link switching
• Connect multiple LANs
• Frame forward procedure
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011