Tải bản đầy đủ
3 Layer 2 ¡ª data link layer

3 Layer 2 ¡ª data link layer

Tải bản đầy đủ

Layer 2 — data link layer

97

Layer 2 data flow control — initially called ‘handshaking’
The term handshaking is nowadays used by protocol designers to describe a range of different
procedures, particularly the type of procedures carried out when networking devices speak to
one another for the first time — to ‘introduce themselves’ to one another and indicate what
they are capable of. But originally handshaking was the term used to describe the early data
flow control procedures used to regulate the speed of data transfer across point-to-point data
communications lines. From these early handshaking procedures, today’s datalink (layer 2)
protocols developed. Perhaps the best known of these simple software handshake procedures
are XON/XOFF and ETX/ACK.
In the XON/XOFF handshake protocol, the sender is only allowed to send data having received the XON signal (transmission on — ASCII character 11H) from the receiver.
Should the receiver return XOFF (transmission off — ASCII character 13H), then the sender
is prohibited from sending further data until once more permitted to do so by receipt of a
renewed XON signal. The simple procedure ensures that the receiver is always ready for any
data sent: in particular, that the receiving data buffer is not full. The charm of XON/XOFF
protocol is its simplicity, and this technique is the basis of many modern protocol flow control procedures.
A slightly more complex handshake procedure is offered by the ETX/ACK protocol. In this
protocol, the sender sends each byte or block of data and appends the ETX character (ASCII
03H) as the ‘end text’ character. The sender is then required to wait before sending the next
byte or block until the receiver responds with the ACK (acknowledge) character (ASCII 06H)
signalling its readiness to receive again.
Like XON/XOFF, the ETX/ACK protocol performs the important job of data flow control — ensuring that the sender only sends data when the receiver is ready to receive it. But
while ETX/ACK is extremely effective in ensuring the acknowledgement of data receipt, it has
a number of weaknesses if each data block transmitted has to be individually acknowledged:
• A lot of time is wasted while the sender waits for the next ACK. This severely limits the
effective bit rate of the line — maybe to a level as low as 5–15% of the real line bit rate
(we discussed this effect in Chapter 2 — Figure 2.27);
• The network efficiency is further reduced by the need to carry the ACK characters themselves.
Next in the history of data flow control came the development of the window (or packet
window ). When a window is employed (usually on an end-to-end basis as part of a layer
3 (network) protocol), each of the sent packets is given a sequence number. The receiver
is then only required occasionally to send an ACK, confirming which sequence number is
expected next, and thus by deduction which frames have already been correctly received.
The sender is allowed to continue sending data, as long as the number of packets not
yet acknowledged (ACK) by the receiver is less than the window size. This significantly
increases the efficiency of the ETX/ACK protocol (as compared to XON/XOFF), as long
as the window size is not set too small. On the other hand, if the value is set too big,
the receiver may be swamped with data it cannot handle before it has had a chance to
say ‘stop’.
In the early days of digital networks, datalink and network protocols had to deal with
a relatively high proportion of bit errors. Until the mid-1980s, digital networks typically
operated with a bit error ratio (BER) of around 10−5 (i.e., 1 bit error in every 100 000 bits
(12 500 bytes) sent). Since a typical data block was between 256 and 4096 bytes in size,
this meant that between 2% and 33% of data blocks (layer 2 frames or layer 3 packets)

98

Basic data networks and protocols

contained an error — an unacceptably high proportion. As a result, very robust error correction methods had to be built into protocols and retransmission of corrupted packets had to
be undertaken.
Nowadays, digital networks have much higher quality. Bit error ratios (BER) rarely exceed
10−9 , or in the case of fibre networks, 10−12 . Much fewer blocks are corrupted, and heavyweight error correction is superfluous. Meanwhile, the prices of the electronic storage components required to create large receive buffers have dropped significantly. As a result, the
problem of regulating receive buffer overflows has decreased and the need for performing
error correction has reduced. In consequence, the emphasis of layer 2 protocol design today
has moved to ensuring maximum data flow efficiency over very high bit rate lines.

Layer 2 (datalink) protocol functions and packet format (HDLC, higher layer
datalink control)
The bitstream carried by the physical layer (layer 1) is divided up into blocks of data (called
frames) by the headers and trailers of the layer 2 (datalink) protocol. The user data is sandwiched between a header and a trailer. Figure 3.22 illustrates one of the most widely used
layer 2 protocols, HDLC (higher level datalink control). HDLC is used for synchronous data
transfer across point-to-point data lines. The headers and trailer of HDLC carry the information the protocol needs (the protocol control information (PCI)) to do its work, in order of
transmission:

Flag
The flag indicates the start and end of each frame. A single flag separates each frame from
the next (HDLC uses synchronous transmission). The flag is coded with the synchronisation
byte (SYN) used for byte and character synchronisation as described in Chapter 2. SYN is a
1 byte field with the value ‘0111 1110’.
Since the flag is the means used to determine the total length of the frame, it is important
that the same pattern ‘0111 1110’ does not appear in any of the other fields of the frame,
otherwise the end of the frame would be incorrectly determined. This is done by a process
called bit stuffing.7 The process of bit stuffing entails inserting an extra bit of binary value
‘0’ after any sequence of five simultaneous ‘1’s’. The extra ‘0’ bit is removed by the HDLC
receiver, by simply converting any received patterns of ‘111110’ into ‘11111’.

Address
The address is the layer 2 address. This is not the same as (and should not be confused
with) the network address used by layer 3 protocols to identify the destination end-point in
the network (a telephone number or an IP address is a layer 3 address). The layer 2 address
field labels a frame as either a command or a response and indicates the DTE or DCE as the
intended destination. When identified as a command frame, the address identifies the DCE or
DTE of a point-to-point link to which the command is being sent. Similarly, in a response
frame (in which a given DTE or DCE provides information in response to a command) the
7
Do not get confused between bit stuffing carried out by a layer 2 protocol such as HDLC and the coding
changes (violations) performed by the line codes of the physical layer (layer 1) (as discussed in chapter 2). The
two mechanisms work entirely independently of one another. ITU-T refers to the layer 2 bit stuffing process
as adding transparency).

Layer 2 — data link layer

99

address identifies the DCE or DTE sending the response. Except in the case of shared media
(LANs), it is unusual in the case of a point-to-point datalink that more than a few addresses
are actually in use.8 LANS (local area networks) use this field in an adapted form of HDLC
(called LLC — link layer control ) to identify the intended destination device within the LAN
as discussed in Chapter 4.
A datalink or medium using HDLC must always have a designated primary station (usually
the DCE) and at least one secondary station (usually the DTE). The primary station controls
the link. The secondary station may only send when the primary station grants permission. In
the case of a LAN or a bus-configured network access line (such as the S/T interface of basic
rate ISDN, BRI ), there are multiple stations.
In the balanced mode of HDLC, each of the stations connected to the datalink or shared
medium acts simultaneously as both a primary and a secondary station, thereby giving them all
equal priority and eliminating the single controller. The LAPB (link access protocol balanced)
used in ISDN BRI (basic rate interface) is a variation of the balanced form of HDLC.

Control field
The control field controls the flow of data across the datalink and normally comprises 8 bits.
This field sets the ‘mode’ of transfer to be used. It arranges for data flow control by determining
the ‘readiness’ of the link and organises the acknowledgment or retransmission of blocks,
frames or packets. It also disconnects the link and generally provides information about the
line status. In some layer 2 protocols, additional controls are provided, e.g., for authorisation of
the user before use of the link or for secure transfer of data (e.g., by encryption). As necessary,
the control field may be extended by an integral multiple of 8 further bits to accommodate
such controls.
The control field may contain one of three different types of frame, called information
frames (I-frames), supervisory frames (S-frames) or unnumbered frames (U-frames). In reality,
the messages are all of the same basic format: the different names merely serve to categorise
the different types of controls. All I-frames begin with bit 1 = ‘0’, all S-frames with the first
two bits ‘10’ and all U-frames with the bit values ‘11’, as Table 3.6 illustrates.
HDLC offers only three commands (in U-frame format): SNRM, SABM and disconnect.
These set the configuration of the link. The response messages (also in U-frame format) merely
acknowledge these commands. Normal data frames are sent as I-frames. When a datalink is
running smoothly, the frames received at one end of the link contain the receive sequence
number (N(R)) to acknowledge the receipt of all the frames sent — up to and including the
N(R)−1th frame). The values used by N(R) correspond with the send sequence numbers
[N(S)] which appear in the I-frames sent in the opposite direction. The transmission of N(S)
and N(R) sequence numbers in this way allows for full data flow control, but simultaneously
also for full duplex operation of the datalink. Only when there is a ‘hiccup’ in the data flow,
8
The normal address field of 8 bits allows 256 different addresses for devices sharing the physical medium
(i.e., for multipoint networks), although 2 of these addresses are reserved. These are ‘1111 1111’ which is the
all stations (or broadcast address) and ‘0000 0000’ which is the no stations address (ignored by all stations,
but used for network testing purposes). A frame with the all stations address is used when sending the same
command to all stations (e.g., a flow control command: ‘stop sending’). Meanwhile, a frame with a no stations
address in a ring topology network will progress around the ring and return (or loopback ) without being
removed by a receiving station, provided the ring is not broken by a failure. If necessary, the HDLC address
field can be extended by any integral number of a further 8 bits. Use of the longer address space is made in the
case of LANs, where unique numbers are allocated to individual network access cards (e.g., a PC ethernet card)
at the time of their manufacture. These addresses are 48-bits in length and allocated by IEEE. Sometimes they
are referred to as the IEEE-address, but also as the MAC (media-specific access control)-name or MAC-address.

100

Basic data networks and protocols

Table 3.6
Frame
type

I-frame

HDLC control field signals and coding (bit 1 is the least significant bit — the first bit sent)
Signal
type

I

Signal purpose

Sequence numbers of sent
frames N(S) and next
frame number expected
to be received N(R),
effectively an
acknowledgement of all
previously received
frames
S-frame RR
Receive ready and
acknowledgement of all
frames up to and
including N(R)-1th
RNR
Receive not ready, but
acknowledgement of all
frames up to and
including N(R)-1th
REJ
Reject, requests
retransmission of all
frames from and
including N(R)th
SREJ
Selective Reject, requests
retransmission only of
the N(R)th
U-frame SNRM Set normal response mode;
secondary stations may
only send frames when
polled by the primary
station by setting P(poll
bit) = ‘1’
SABM Set asynchronous balanced
mode; secondary stations
may send at any time
DISC
Disconnect
UA
Unnumbered
acknowledgement;
acknowledges having
received a U-frame with
a ‘set’ command
DM
Disconnected mode;
notification of a protocol
error

C
F

o
i

n
e

t
l

r
d

o-

l
-

--

Remarks

1

2

3

4

5

6

7

8

0

N

(S

)

P/F

N

(R

)

P = Poll bit
F = Final bit

1

0

0

0

P/F

N

(R

)

P = Poll bit
F = Final bit

1

0

1

0

P/F

N

(R

)

P = Poll bit
F = Final bit

1

0

0

1

P/F

N

(R

)

P = Poll bit
F = Final bit

1

0

1

1

P/F

N

(R

)

P = Poll bit
F = Final bit

1

1

0

0

P

0

0

1

P = Poll bit

1

1

1

1

P

1

0

0

P = Poll bit

1
1

1
1

0
0

0
0

P
F

0
1

1
1

0
0

P = Poll bit
P = Poll bit

1

1

1

1

F

0

0

0

F = Final bit

do supervisory messages (s-frames) need to be used to sort things out (calling a temporary
halt in communication or requesting the retransmission of a particular numbered frame).
The poll bit (P) is set to ‘1’ when one station wishes to solicit (i.e., poll ) a response from
the other. The final bit (F) is set to ‘1’ to indicate the corresponding response to the poll.
In the normal HDLC frame, the control field has a length of 8 bits (1 byte), and the sequence
numbers are three bits in length or modulo 8. In other words the count goes from 0 to 7 and
then restarts at 0 again — counting continuously. In order for the acknowledgement process to

Layer 2 — data link layer

101

work correctly, the layer 2 window size must be set at 7 or less, thereby limiting the sender
to sending no more than 7 unacknowledged frames. If it were to send eight or more frames
without first receiving an acknowledgement, then different unacknowledged frames would
share the same sequence number. It would then be impossible to tell which of the two frames
was being acknowledged, or from which of the two frames retransmission should occur. Since
small window sizes (e.g., 7) can lead to very inefficient usage of high bit rate lines (as we
saw in Chapter 2 — Figure 2.28), HDLC is sometimes used instead in a modulo 128 mode.
In this case, the control field is extended to 16 bits, thus enabling both N(S) and N(R) fields
to be extended to 7 bits each. The extended N(S) and N(R) fields allow a sequence number
count from 0 to 127, and thus a window size of up to 127 unacknowledged frames.
The commands and responses carried by the HDLC control field are communicated directly
between layer 2 protocol handlers. The physical layer hardware and software are oblivious to
the layer 2 communication. This is layered and peer-to-peer communication!

User data field
The user data is the information itself. This field may contain only real end-user information
but more likely is that it contains the PCI (protocol control information) of a higher layer
protocol (e.g., PCI for one or more of the layers 3, 4, 5, 6, 7) in addition to the real user
information. This will become clearer in Figure 3.28.

Frame check sequence (FCS)
The frame check sequence (FCS) is normally a 16-bit code used for detection of errors in
received frames. A cyclic redundancy check (CRC)9 is used to set and check the value which
appears in this field.

Least significant bit (LSB) sent first
The order of transmission to line of an HDLC frame is always ‘flag-address-control-information-FCS-flag’ and each of the individual frames is always sent least significant bit (LSB) first.

Well-known layer 2 protocols
Apart from HDLC, other well-known and widely used layer 2 protocols include: SDLC (synchronous datalink control) which is part of IBM’s SNA (systems network architecture) (it was
the protocol from which HDLC was developed); LLC (logical link control — IEEE 802.2)10
as used in LANs, LAPB (link access protocol balanced) used in X.25 packet networks, SLIP
(serial line internet protocol) and PPP (point-to-point protocol)11 — part of the IP (Internet
Protocol) suite. All of these are similar to, or based upon, HDLC.

Media access control (MAC)
In some layer 2 protocols, the various functions are split into further sub-layers. In the case
of the datalink layer (IEEE 802.2) used in LANs, for example, this is comprised not only
9

See chapter 2.
See chapter 4.
11
See chapter 8.
10

102

Basic data networks and protocols

of the logical link control (LLC) but also of the media access control (MAC) layer. The
approximate ‘split’ of responsibilities is that the LLC assumes responsibility for the ‘higher
level’ functions of control, supervision, user data transfer and frame check sequencing, while
the MAC takes over medium-specific tasks related to the interface with the physical layer.
Thus the prime tasks undertaken by the MAC-layer are those of addressing and coordination
with the physical layer.
The first MACs appeared during the emergence of LANs (local area networks), when HDLC
had to be adapted to cope with multiple devices communicating using a shared medium. This
required a more powerful capability for addressing than the point-to-point datalink networks
which had previously existed. The emergence of MAC-protocols also lead to the standardisation by IEEE of the 48-bit address format and numbering plan hardcoded into network
adapter cards at their time of manufacture. These addresses are variously referred to as MACaddresses, MAC-names or IEEE-addresses. We shall return to the subject of the local area
network MAC protocol and addresses in more detail in Chapter 4.

As a quick-reference for those who need to know, since it is mathematically complicated, the value set in the FCS (frame check sequence) field of HDLC is the ones
complement (a mathematical term meaning that the ‘0’s of the binary number are changed
to ‘1’s and vice-versa) of the sum (calculated in binary) of:
1) the remainder of x k (x 15 + x 14 + x 13 + x 12 + x 11 + x 10 + x 9 + x 8 + x7 + x 6 + x 5 +
4
x + x3
+ x 2 + x + 1) divided (modulo 2) by the generator polynomial x 16 x 12 x 5 + 1. k is the
number of bits in the frame existing between the final bit of the opening flag and the first
bit of the FCS, excluding stuffing bits (synchronous transmission) or start and stop bits
(asynchronous transmission);
The expression ‘x 15 + x 14 + x 13 + x 12 + x 11 + x 10 + x 9 + x 8 + x7 + x 6 + x 5 + x 4 +
x 3 + x 2 + x + 1’ means the binary number ‘1111 1111 1111 1111’ and ‘x 16 + x 12 + x 5 +
1’ means the binary number ‘1 0001 0000 0010 0001’ etc. x k means a binary number
starting with a ‘1’ and followed by k bits of value ‘0’. In the general case of any CRC
(cyclic redundancy check) the value to be divided by the generator polynomial always
takes the same form, only the length of the field to be coded (i.e., the value of k) and
the length of the codeword (i.e., the number of ‘1’s in the second number — in our case
15 + 1 = 16) changes].
and:
2) the remainder of the division (modulo 2) by the generator polynomial x 16 + x 12 +
5
x + 1 of the product (i.e., multiplication) of x 16 by the content of the frame (i.e., the data
to be coded). The frame content in this sense is all the bits between the final bit of the
opening flag and the first bit of the FCS, excluding stuffing bits (synchronous transmission)
or start and stop bits (asynchronous transmission).
Usually a register is available in the transmitter for calculating the remainder value
described in (1) above. This register is preset to all ‘1’s and then modified according
to the result of the generator polynomial division. The ones complement of the resulting
remainder is the 16-bit FCS.
At the receiver, the incoming codeword (i.e., the entire frame including address, control,
information and FCS fields, but excluding stuffing bits) is multiplied by x 16 (i.e., shift register of 16 places to the left, filling from the right (least significant bit) from the ‘remainder
register’ which is initially pre-set to all ‘1’s) and then divided (modulo 2) by the generator
polynomial x 16 + x 12 + x 5 + 1. The final content of the ‘remainder register’ is ‘0001 1101
0000 1111’ if there were no transmission errors.

Layer 3 — network layer and network layer addresses

103

3.4 Layer 3 — network layer and network layer addresses
The network (or layer 3 ) protocol is responsible for managing the statistical multiplexing, endto-end carriage of information and other functions which combine and coordinate a number
of datalinks to produce a network service. The distinguishing feature of a network (layer 3)
protocol is its capability to ‘find’, route to and/or switch to remote communications partners
who are not reachable via a single datalink (such as a single point-to-point link or a LAN,
local area network). Thus in communicating between one LAN and another, or between any
two devices across a wide area network (WAN), a network protocol has to be used.
When invoking a layer 3 protocol, an end-user or ‘higher layer application’ (i.e., computer
program) must specify the network address (equivalent to a telephone number) with which
communication is to be established. This address identifies the destination port of the network.
Network layer (layer 3) protocols have a number of responsibilities to fulfil:
• identification of destination network address;
• routing or switching of packets across the individual network nodes and links to the
destination;
• statistical multiplexing of the data supplied by different users for carriage across the network;
• end-to-end data flow control: the flow control conducted by layer 2 protocols only ensure
that the receiving data buffers on each individual link can receive more data. The layer 3
protocol has the more onerous task of trying to ensure a smooth flow of data across all
the datalinks or subnetworks taken together. Uneven ‘hold-ups’ along the route need to
be avoided;
• correct re-sequencing of packets (should they get out of order having travelled via different
routes on their way to the destination); and
• error correction or transmission re-request on a network end-to-end basis.
As with layer 1 and layer 2 protocols, there are a number of alternative layer 3 protocols
available for use in different types of network and there are marked differences between how
they operate. It is, for example, important to understand the differences between connectionoriented and connectionless network protocols, and this we shall study next.

Connection-oriented network service (CONS) and connectionless network
service (CLNS)
Telephone networks, circuit-switched data networks, X.25- and frame relay-based packetswitched networks, as well as the cell-switched networks of ATM (asynchronous transfer
mode) are examples of connection-oriented switching or connection-oriented network service
(CONS). Under connection-oriented switching, a circuit, virtual circuit (VC), connection or
virtual connection (VC) is established between sender and receiver before information is
conveyed. Thus a telephone connection is first established by dialling the telephone number
before the conversation takes place. This ensures the readiness of the receiver to receive
information before it is sent, there is no point in talking if nobody is listening.
In contrast, a connectionless-network service (CLNS) such as that provided by the Internet protocol (IP) allows messages (i.e., packets) to be despatched, without even checking
the validity of the address. Thus, for example, the postal service is analogous to a connectionless service. The sender posts the entire message (envelope and contents) into the
post box and forgets about it. Sometime later, the receiver receives the message — delivered

104

Basic data networks and protocols

through his letter box (or alternatively: it gets lost somewhere or for some other reason cannot
be delivered!).
The main advantage of a connectionless-network service is that the sender need not wait
for the receiver to be ready and the network need not be encumbered with the extra effort
of setting up a connection. The message, called a packet or datagram is simply despatched.
Since a single packet or datagram (for example, containing a single data file) represents the
entire content of many data communications ‘messages’, it is easier to treat the datagram like
a postal telegram and route it from node to node along its path to the destination based upon
the network address appearing in the header (the equivalent of the telegram’s envelope). The
disadvantage is that the sender gets no clear guarantee or confirmation of message delivery.
The sender is left in doubt: Did the receiver get the message? — Were they simply too lazy
to reply? Or did the receiver not get the message? Was the address not written correctly?
Theoretically, the multiple packets making up a large message, when sent in a connectionless manner, may take different paths through the network to the destination. This would
make it very difficult for ‘eavesdroppers’ to intercept the entire message, so making the communication more ‘secure’. This idea appealed to the military users who were some of the
first users of IP (Internet protocol). On the other hand, the different routes of the different
packets usually lead to different propagation delays and so, in turn, can lead to complications
in the communication between the two end-points. In practice, this is overcome by the use of
deterministic or path-oriented routing (all packets are routed along the same path). But where
this is used (nearly always), the ‘security’ benefit is lost.
One of the important distinctions between connection-oriented and connectionless networks
is the type of device used as a network node in the respective networks. In connection-oriented
networks, it is normal to refer to the network nodes as switches and to the function they carry
out as switching. A switch switches a connection. In contrast, connectionless networks have
no connections to be switched. The nodes of a connectionless network, usually called routers,
merely route and forward datagrams (like the ‘sorters’ in a postal network).
Connection-oriented and connectionless networks have very different strengths and weaknesses. And since we shall concentrate in this book most on the connectionless ways of IP,
let us take just a few moments to consider the comparative strengths of connection-oriented
switching — and I make no apologies for doing so!. While some readers may consider X.25,
frame relay, ATM (asynchronous transfer mode) and other connection-oriented protocols as
only of ‘historic’ significance (i.e., overtaken and replaced by IP-suite protocols), this ignores
their continuing widespread use — including in the backbone of some IP-networks! Not only
this, but the principles (and even the details!) of the protocol operation of connection-oriented
packet-switching (as developed for X.25, frame relay and ATM) are nowadays being adopted
into the IP-suite protocols. The following brief discussion of connection-oriented packet
switching and X.25 will help us later to understand the motivation for using a connectionoriented transport layer protocol in the IP suite: TCP (transmission control protocol). It will
also lay the foundations for understanding MPLS (multiprotocol label-switching). Both TCP
and MPLS are discussed in more detail in Chapter 7.

Circuit-switched, X.25-packet, frame relay and ATM networks are
connection-oriented data networks!
The distinguishing property of a circuit-switched network is the existence throughout the
communication phase of the call, of an unbroken physical and electrical connection between
origin and destination points. The connection is established at call set-up and cleared after the
call. The connection may offer either one direction (simplex) or two direction (duplex) use.
Telephone networks are said to be circuit-switched networks and are also connection-oriented.