文章目录
Reference:
- Computer Networking:A Top-Down Approach,7-th
- PPT of NEU(lx)
-
Nodes: any device that runs a link-layer protocol, include hosts, routers, switches, and WiFi Access points;
-
Links:the communication channels that connect adjacent nodes along the communication path
- wired links
- wireless links
-
Frame:layer-2 packet, encapsulates the datagram;
-
数据链路层的子层 (802委员将局域网的数据链路层拆分为两个子层以适应多种局域网标准):
-
Logical Link Control (LLC, 逻辑链路控制) 子层
-
Medium Access Control (MAC, 媒体接入控制) 子层
-
局域网对LLC子层是透明的:
-
1. Introduction
1.1 The Services Provided by the Link Layer(链路层提供的服务)
- Framing(封装成帧):
- Almost all link-layer protocols encapsulate each network-layer datagram within a link-layer frame before transmission over the link;
- A frame consists of a data field, in which the network-layer datagram is inserted, and a number of header fields;
- The structure of the frame is specified by the link-layer protocol;
- Link access(链路接入):
- A medium access control (MAC) protocol specifies the rules by which a frame is transmitted onto the link.
- Multiple access problem
- MAC protocol serves to coordinate (协调) the frame transmissions of the many nodes.
- MAC addresses used in frame headers to identity source, destination.
- Reliable delivery(可靠传输):
- Often used for links (like wireless link) that are prone to high error rates;
- Seldom used on low bit error link (such as fiber, some twisted pair);
- Error detection and correction(差错检测与纠正):
- Error: Introduced by signal attenuation (信号衰减) and electromagnetic noise (电磁噪声)
- The mechanism to detect bit errors is done by:
- Having the transmitting node including error-dectection bits in the frame
- Having the receiving node perform an error check;
- Error detection in the link layer is usually more sophisticated and is implemented in hardware;
- Error correction:receiver identifies and corrects bit error(s) without resorting to retransmission;
- Half-duplex and full-duplex (半双工与全双工):
- With half duplex, node at both ends of link can transmit, but not at same time
1.2 Where Is the Link Layer Implemented?(链路层在哪实现)
- For the most part, the link layer is implemented in a network adapter(网络适配器), also sometimes known as a network interface card (NIC,网络接口卡);
- Adapter is semi-autonomous (半自主的)
- 适配器的重要功能:
- 串并行转换;
- 缓存数据;
- 在计算机的操作系统安装设备驱动程序;
- 实现以太网协议;
- At the heart of the adapter is the link-layer controller;
- sending side :
- encapsulates datagrame in a frame;
- adds error checking bits, rdt (可靠数据传输), flow control;
- receiving side:
- extracts datagram, passes to rcving node
- extracts datagram, passes to rcving node
- Network adapter’s relationship to other host components and to protocal stack functionality
- The link-layer is a combination of hardware and software;
2. Error-Detection and -Correction Techniques(差错检测与纠错技术)
- At the sending node, data, D, to be protected against bit errors is augmented with error-detection and -correction bits (EDC).
- Typically, the data to be protected includes not only the datagram passed down from the network layer for transmission across the link, but also link-level addressing information, sequence numbers, and other fields in the link frame header.
2.1 Parity Checks (奇偶校验)
-
Single bit Parity (单比特奇偶校验)(even 偶数的; odd 奇数的):
- 偶校验:
-
Two Dimensional Bit Parity (单比特的奇偶校验方案的二维推广,二维奇偶校验):
- d bits in D are divided into i rows and j columns;
- A parity value is computed for each row and for each column;
- The parity of both the column and the row containing the flipped bit will be in error;
- 奇偶校验位本身的错误亦可被检测和纠正;
- Two-dimensional even parity:
-
***Forward error correction (FEC,正向纠错): The ability of the receiver to both detect and correct errors;
2.2 Checksumming Methods (校验和方法)
- In checksumming techniques, the d bits of data (see picture show before) are treated as a sequence of k-bit integers. One simple checksumming method is to simply sum these k-bit integers and use the resulting sum as the error-detection bits. The Internet checksum is based on this approach——bytes of data are treated as 16-bit integers and summed. The 1s complement of this sum then forms the Internet checksum that is carried in the segment header.
- Internet checksum (校验和):used at transport layer only
- Sender:
- treat segment contents as sequence of 16-bit integers
- the internet checksum: addition (1’s complement sum) of segment contents
- sender puts checksum value into UDP checksum field
- Receiver:
- compute checksum of received segment
- check if computed checksum equals checksum field value:
- NO: error detected;
- YES: no error detected;
- But maybe errors nonetheless (依然)
- Sender:
2.3 Cyclic Redundary Check (CRC) (循环冗余校验)
An error-detection technique used widely in today’s computer networks is based on cyclic redundancy check (CRC) codes,which are also known as polynommial.
CRC codes Oprerate as follows:
-
Consider the d-bit piece of data, D, that the sending node wants to send to the receiving node;
-
Choose r+1 bit pattern (generator), denote it as G;
-
Sender: choose r additional bits, R, and append them to D such that:
-
<D, R> exactly divisible by G (using modulo-2 arithmetic);
(All CRC calculations are done in modulo-2 arithmetic without carries in addition or borrows in subtraction)
-
Errors?
- if the remainder is nonzero, an error has occurred;
- otherwise the data is accepted as being corret;
-
- How to compute R:
- D*2^r XOR R = nG;
- Equal to: D*2^r = nG XOR R;
- Equal to: R = D*2^r / (模-2除法) G
- Example:
- All CRC calculations are done in modulo-2 arithmetic without carries in addition or borrows in subtraction.
- All CRC calculations are done in modulo-2 arithmetic without carries in addition or borrows in subtraction.
3. Mutiple Access Links and Protocols (多路访问链路和协议)
- Two types of “links”
- Point-to-point link(点对点链路):
- Consists of a single sender at one end of the link and a single receiver at the other end of the link;
- Protocols designed for point-to-point links
- point-to-point protocol;
- high-level data link control (HDLC);
- Broadcast link(广播链路):
- Example:
- traditional Ethernet;
- HFC;
- Example:
- Point-to-point link(点对点链路):
- Mutiple access protocols(多路访问协议):
- Single shared broadcast channel;
- Two or more simultaneous transmissions by nodes: interference
- collision if node receives two or more signals at the same time;
- Distributed algorithm that determines how nodes share channel, i.e., determine when node can transmit;
- Communication about channel sharing must use channel itself !
- Ideally, a multiple access protocol for a broadcast channel of rate R bits per second should have the following desirable characteristics:
- When only one node has data to send, that node has a throughput of R bps
- When M nodes have data to send, each of these nodes has a throughput of R/M bps
- The protocol is decentralized:
- No master node that represents a single point of failure for the network;
- No special node to coordinate transmissions;
- No synchronization of clocks, slots;
- Simple;
3.1 Channel Partitioning Protocols(信道划分协议)
-
TDMA(时分多路复用): time division multiple access;
-
Divides time into time frames(时间帧) and further divides each time frame into N time slots(时隙), Each time slot is then assigned to one of the N nodes.
-
Advantages:
-
Eliminates collisions and is perfectly fair: Each node gets a dedicated (独占的)
transmission rate of R/N bps during each frame time;
-
-
Drawbacks:
-
A node is limited to an average rate of R/N bps even when it is the only node with packets to send.
-
A node must always wait for its turn in the transmission sequence—again, even
when it is the only node with a frame to send.
-
-
-
FDMA(频分多路复用): frequency division multiple access;
- Divides the R bps channel into different frequencies (each with a bandwidth of R/N) and assigns each frequency to one of the N nodes;
- Shares both the advantages and drawbacks of TDM;
-
CDMA(码分多路复用): code division multiple access;
3.2 Random Access Prototols(随机接入协议)
-
Slotted ALOHA(时隙 ALOHA):
-
Assumptions:
- All frames consist of exactly L bits;
- Time is divided into slots of size L/R seconds (that is, a slot equals the time to transmit one frame);
- Nodes start to transmit frames only at the beginnings of slots;
- The nodes are synchronized so that each node knows when the slots begin;
- If two or more frames collide in a slot, then all the nodes detect the collision event before the slot ends.
-
The operation of slotted ALOHA in each node:
- When the node has a fresh frame to send, it waits until the beginning of the next slot and transmits the entire frame in the slot;
- If there isn’t a collision, the node has successfully transmitted its frame and thus need not consider retransmitting the frame;
- If there is a collision, the node detects the collision before the end of the slot; The node retransmits its frame in each subsequent slot with probability p until the frame is transmitted without a collision.
-
Advantages:
- Allows a node to transmit continuously at the full rate, R, when that node is the only active node;
- Highly decentralized (分散) : each node detects collisions and independently decides when to retransmit;
- Simple;
-
Disadvantages:
- A certain fraction of the slots will have collisions and will therefore be “wasted”;
- ldle slots;
- Clock syschronnization;
-
Efficiency :
-
Define: the long-run fraction (长期占比) of successful slots in the case when there are a large number of active nodes, each always having a large number of frames to send;
假设有
N
个结点有多个帧需要发送,结点在每个时隙发送帧的概率是p
。则某个结点在某个时隙成功发送一个帧的概率为:
p 1 = p ( 1 − p ) N − 1 p_1=p(1-p)^{N-1} p1=p(1−p)N−1
在某个时隙成功发送了一个帧的概率为:
p 2 = N p 1 = N p ( 1 − p ) N − 1 p_2=Np_1=Np(1-p)^{N-1} p2=Np1=Np(1−p)N−1
求 p 2 p_2 p2最大值可得其最大效率为 1 e = 0.37 \frac{1}{e}=0.37 e1=0.37。
-
-
-
Pure ALOHA (unslotted)
-
The slotted ALOHA protocol required that all nodes synchronize their transmissions to start at the beginning of a slot;
-
In pure ALOHA, when a frame first arrives (that is, a network-layer datagram is passed down from the network layer at the sending node), the node immediately transmits the frame in its entirety into the broadcast channel;
- If a transmitted frame experiences a collision with one or more other transmissions, the node will then immediately (after completely transmitting its collided frame) retransmit the frame with probability p.
- Otherwise, the node waits for a frame transmission time.
- After this wait, it then transmits the frame with probability p, or waits (remaining idle) for another frame time with probability 1 – p.
-
Collision probability increases:
- Frame sent at t 0 t_0 t0 collides with other frames sent in [ t 0 − 1 , t 0 + 1 ] [t_0-1, t_0+1] [t0−1,t0+1];
-
Efficiency:
- At any given time, the probability that a node is transmitting a frame is p.
- Suppose this frame begins transmission at time t 0 t_0 t0 .
- The probability that a given node has a successful transmission is:
- p ( 1 − p ) 2 ( N − 1 ) p(1-p)^{2(N-1)} p(1−p)2(N−1);
- Taking Limit : 1/2e = 0.18;
-
-
Carrier Sence Mutiple Access (载波侦听多路访问):
-
传送前监听信道:
- 如果信道空闲,则传送整个帧;
- 如果繁忙,则推迟传送;
-
Collisions can still occur, and once occur, entire packet transmission time wasted;
-
Space-time diagrams (to explain collisions):
-
At time t 0 t_0 t0, node B senses the channel is idle, as no other nodes are currently transmitting. Node B thus begins transmitting, with its bits propagating in both directions along the broadcast medium;
-
The downward propagation of B’s bits in Figure with increasing time indicates that a nonzero amount of time is needed for B’s bits actually to propagate (albeit at near the speed of light) along the broadcast medium;
-
At time t 1 ( t 1 > t 0 ) t_1(t_1>t_0) t1(t1>t0) , node D has a frame to send (Although node B is currently transmitting at time t 1 t_1 t1 , the bits being transmitted by B have yet to reach D, and thus D senses the channel idle at t 1 t_1 t1).
-
In accordance with the CSMA protocol, D thus begins transmitting its frame. A
short time later, B’s transmission begins to interfere with D’s transmission at D.
-
-
The end-to-end channel propagation delay of a broadcast channel play a crucial role in determining its performance and collision probability.
-
-
CSMA with collision detection (CSMA/CD,载波侦听多路访问/冲突检测):
-
In the foundation of CSMA, it adds a collision detection:
-
if detect collision has occurred, it will abort transmittion, and then send out a jamming signal (干扰信号,导致下面的时间延迟);
-
-
Adding collision detection to a multiple access protocol will help protocol performance by not transmitting a useless, damaged (by interference with a frame from another node) frame in its entirety.
-
Collision detection:
- easy in wired LANs;
- 在有线的局域网中监测信号强度
measure signal strength
,如果信号突然增强,则可能是发生了碰撞;
- 在有线的局域网中监测信号强度
- difficult in wireless LANs;
- easy in wired LANs;
-
CSMA/CD dfficiency:
-
T p r o p T_{prop} Tprop = max prop bettween 2 nodes in LAN;
-
T t r a n s T_{trans} Ttrans = time to transmit max-size frame;
e f f i c i e n c y = 1 1 + 5 t p r o p t t r a n s efficiency = \frac 1{1+5\frac{t_{prop}}{t_{trans}}} efficiency=1+5ttranstprop1
-
-
-
CDMA/CA(载波侦听多路访问/冲突避免)
3.3 Taking-Turns Protocols(轮流协议)
略
4 Switched Local Area Networks (交换局域网)
4.1 Link-Layer Addressing and ARP(链路层寻址与地址解析协议)
-
MAC Addresses (LAN Addresses)
-
A link-layer address is variously called a LAN address, a physical address, or a MAC address;
-
A host or router with multiple network interfaces (Adapters) will thus have multiple link-layer addresses associated with it;
-
Each interface(Adapter) connected to a LAN has a unique MAC address
-
Used to forward link-layer frames through the network of switches (Used to get frame from one interface to another physically-connected interface(same network));
-
48 bit MAC address (for most LANs) burned in the adapter ROM;
- 2 48 2^{48} 248 possible MAC address;
- Typically expressed in hexadecimal notation (see picture up):
- No two adapters have the same address
-
MAC address allocation administered by IEEE:
- Manufacturer buys portion of MAC address space (to assure uniqueness);
-
Analogy(类比):
-
MAC address:like Social Security Number or 身份证;
-
IP address:like postal address (邮编号);
-
Mac flat address:Portability(可携带性)(doesn’t change no matter where the adapter goes)
-
IP hierarchical address:Not portable;
- depend on IP subnet to which node is attached;
-
-
-
Address Resolution Protocol (ARP)
-
Translate between network-layer addresses (IP) and link-layer addresses (MAC)
-
How to determine MAC address of A knowing A’s IP address? (ARP)
-
Each IP node (Host, Router) on LAN has ARP table
-
ARP Table:IP/MAC address mappings for some LAN nodes
<IP address: Mac address: TTL>
发送主机中的ARP模块以同一局域网上的任意IP地址作为输入,返回相应的MAC地址;
TTL(Time to Live):Time after which (ARP Table )will by forgotten(typically 20 min);
-
-
ARP protocal:same LAN(subnet)
- A wants to send datagram to B, and B’s MAC address not in A’s ARP table;
- A broadcosts ARP query packet, containg B’s IP address:
- Dest MAC address :广播地址(FF-FF-FF-FF-FF-FF);
- all machines on LAN receives ARP query;
- B receives ARP packet, repies to A with its (B’s) MAC address;
- frame sent to A’s MAC address (unicast, 单波);
- A caches (saves) IP-to-Mac address pair in its ARP table unitl information become old (times out)
- soft state:information that times out (goes away) unless refreshed;
- ARP is “plug-and-play”(急插急用):
- nodes create their ARP tables without intervention(介入) from administrator;
-
Routing to another LAN:
- Two subnets interconnected by a router(Two ARP table in router R, one for each IP network (LAN))
- In routing table at source Host, find router 111.111.111.110.
- In ARP table at source, find MAC address E6-E9-00-17-BB-4B, etc.
- Source A creates datagram with source A, destination B;
- A uses ARP and R’s IP address (111.111.111.110) to get R’s MAC address;
- A creates link-layer frame with R’s MAC address as dest, frame contains A-to-B IP datagram;
- A’s adapter sends frame, R’s adapter receives frame;
- R removes IP datagram from Ethernet frame, sees its destined to B;
- R uses ARP to get B’s MAC address;
- R creates frame containing A-to-B IP datagram sends to B;
-