Computer Networks Framing Saad Mneimneh Computer Siene Hunter College of CUNY New York Introdution Who framed Roger rabbit? A detetive, a woman, and a rabbit in a network of trouble We will skip the physial layer and the detail of how ommuniation signals are sent and reeived. In doing so, we are simply going to assume (a orret assumption) that we are apable of sending bits over a single link. Using this abstration, the DLC layer beomes responsible for reliable transmission of pakets over a single link. Reliable transmission of pakets means that every paket is delivered one, only one, without errors, and in order. To ahieve this goal, the DLC layer performs three operations: Framing: determines start and end of pakets (all we see is a string of bits) and their order by inserting paket headers Error detetion: determines when errors exist using paket trailers Error orretion: retransmits pakets ontaining errors 2 Framing The main problem is to deide where suessive pakets start and end. Therefore, the DLC enapsulates the paket into a frame by adding its own header and trailer. header paket trailer frame Figure : From paket to frame Moreover, if there is a period of idle fills between suessive frames (a synhronous bit pipe keeps on sending even if there is no data), it beomes also neessary to separate
idle fills from frames. Even when idle fills are replaed by dead periods (intermittent bit pipe), the problem is not simplified, beause often there are no dead periods. For instane, where is the data in the following string of bits:... 0000000000000... 2. Charater based framing Charater based odes, suh as ASCII (7 bits and parity bit), provide binary representation for keyboard haraters and terminal ontrol haraters. The idea in harater based framing is that suh odes an also provide representation for various ommuniation haraters: SYN: a string of SYN haraters provide idle fill between frames when a sending DLC has no data to send (but a synhronous modem requires bits) STX: start of text ETX: end of text frame SYN SYN STX header paket ETX CRC SYN SYN trailer added by DLC for error detetion (later) Figure 2: Charater based frame One disadvantage of harater based framing is that the frame must ontain an integer number of haraters; otherwise, the haraters annot be read orretly. This also raises a question: how do we send binary data? For instane, a paket is a binary string of arbitrary length. Even more important is that a paket may possibly ontain, say the ETX harater, whih ould be wrongly interpreted as end of frame. To solve these problems, a speial ontrol harater DLE (Data Link Esape) is inserted before any intentional use of the ommuniation ontrol haraters. The DLE harater is not inserted before the possible appearane of these haraters as part of the binary data. Of ourse this raises another question: what if DLE itself appears in the data? Well, then we an insert a DLE before eah appearane of DLE in the data. For example DLE ETX (but not DLE DLE ETX) is end of frame, and DLE DLE ETX (but not DLE DLE DLE ETX) is DLE ETX in the data. frame SYN SYN DLE STX header paket DLE ETX CRC SYN SYN Figure 3: The DLE esape harater Charater based framing adds too muh overhead; for instane, at least 6 haraters/paket need to be added for synhronous bit pipes: SYN SYN DLE STX... DLE ETX. This was the primary framing method from 960 to 975, e.g. ARPANET.
2.2 Length field The basi problem as seen so far is to inform the reeiving DLC where eah idle fill ends and where eah frame ends. In priniple, an idle fill is easy to identify beause it is represented by a fixed string. The end of a frame, however, is harder to indiate beause the frame onsists of arbitrary and unknown bit string. Therefore, one solution is to inlude a length field of ertain number of bits in the header (e.g. DECNET). length Idle fill paket CRC Idle fill header paket CRC header Figure 4: Length field in header As it an be seen from the above figure, one synhronized, DLC an always tell where the next frame starts. However, one drawbak of this tehnique is the diffiulty to reover from errors in the length field; for instane, a resynhronization is needed after suh an error. Another drawbak of this tehnique is that the length field restrits the paket size; the length field must ontain at least log 2 MaxF ramesize + bits (that s the overhead). Therefore, if L is the size of the length field in bits, then L > log 2 MaxF ramesize and MaxF ramesize < 2 L bits. 2.3 Fixed length pakets/frames In networks with fixed length pakets, the length field is impliit (not needed) beause all pakets (and hene frames) have the same size. An example of suh networks is ATM, where all pakets are 53 bytes long. This framing tehnique requires synhronization upon initialization. Another drawbak is that message length often not a multiple of paket size. In this ase, the last paket of the message will ontain idle fills (what happens to the overhead?) 2.4 Bit oriented framing In harater based framing, DLE ETX indiates the end of the frame, and it is avoided within the frame itself by doubling eah DLE harater in the data. In bit oriented framing, a speial binary flag indiates the end of the frame, and it is avoided within the frame itself by using a tehnique alled bit stuffing. Therefore, the onept is the same, but the main differene is that a flag, unlike DLE ETX, an be of any length (later we see how to set that length to minimize the overhead). Standard protools use 00 as the binary flat, we denote it by 0 6 0. The same flag an be used to indiate the start of the frame. 00.................. 00 Standard DLCs have also an abort apability in whih a frame an be aborted by sending seven or more onseutive s (5 onseutive s mean the link is idle). Therefore, 0, i.e. 0 6 is the atual bit string that must be avoided in the data by bit stuffing.
Bit stuffing was invented by IBM in 970, and works as follows: The sender DLC inserts (stuffs) a 0 after eah appearane of five onseutive s, and appends the flag 0 6 0 (without stuffing) at the end of the frame. The reeiver DLC deletes the first 0 after eah string of five onseutive s. If six onseutive s are seen, this is interpreted as the end of the frame. stuffed bits 0 0 0 0 0 0 0 Figure 5: Bit stuffing Something to think about: whih ones of the above stuffed bits an be avoided (provided the reeiver s rule for deleting stuffed bits is hanged aordingly)? Assume that the flag has the pattern 0 j 0. How long should the flag be. Let us onsider the overhead. On one hand, if j inreases, we have less stuffing but a longer flag. On the other hand, if j dereases, we have more stuffing but a shorter flag. For the sake of our analysis, let us assume a random string of bits with p(0) = p() = /2. Therefore, insertion after the i th bit ours with probability (/2) j. 0. {{.. j Also another type of insertion after the i th bit ours with probability (/2) 2j 0. {{... {{.. j j Sine (/2) 2j << (/2) j, we an ignore suh event and events of insertion due to yet longer strings of s. The probability of stuffing after the i th bit is approximately 2 j, whih is also E[# stuffed bits @ i], the expeted number of insertions after the i th bit. By the linearity of expetation, E[# stuffed bits K] K2 j (be areful at boundary), where K is the length of the frame. Therefore, E[# stuffed bits] = E[K]2 j E[overhead] = E[K]2 j + j + 2 {{ {{ stuffed flag
Minimizing with respet to j, we need smallest j suh that E[K]2 j + j + 2 < E[K]2 (j+) + (j + ) + 2 j j + Figure 6: Minimizing overhead E[k]2 (j+) < The smallest j that satisfies the above inequality is j = log 2 E[k]. We an show that (homework?): log 2 E[K] + 2.94 E[overhead] log 2 E[K] + 3 2.5 What is the best overhead? Length field based framing and bit oriented framing are omparable in their overhead, log 2 K where K is the length of the frame. Can we do better? Information theory tells us NO. Essentially, we are enoding information about the length of the frame at the sending DLC and transmitting it to the reeiving DLC. At least we need a number of bits equal to the entropy H = K max k= p(k) log 2 p(k) When distribution is uniform, i.e. p =, H = log 2. 2.6 Maximum paket size Reall that the transport layer is the one responsible for breaking messages into pakets. So how should the transport layer hoose the maximum paket size? Pratially speaking, this is not a big deal sine IP fragments pakets further if neessary. Usually paket size is about 500 bytes (from Ethernet). But theoretially speaking, for a given overhead of V bits, what is the best maximum paket size? Let M be the message length. Then we have M + M V
bits to send V V V Rest V M The overhead per message is V. If inreases, we have a small overhead per message; therefore, less bits to transmit. But sine the message might need to traverse many links, a larger paket size may result in a slower delivery time, beause eah intermediate node must wait until it ompletely reeives a paket before relaying it. reeiver 2 3 4 j sender Figure 7: Traversing links This additional total waiting time an be omputed as: ( + V )(j ) where is the apaity of a link in bps (bandwidth). Therefore, small overhead per message, larger wait bigger overhead, but smaller wait Whih value of ahieves the best tradeoff? Let us minimize the time to deliver the message. The time needed for the message to traverse j links is: (Kmax + V )(j ) T = + M + M V + P + Q where P and Q are the propagation delay and the queuing delay respetively. Therefore, the expeted value of T is approximately given by: (Kmax + V )(j ) E[T ] = + and we need to minimize E[M] + E[M] V + P + Q (j ) + E[M] V By taking the first derivative with respet to and setting it to zero, we get E[M]V = j Referenes Dimitri Bertsekas and Robert Gallager, Data Networks Larry Peterson and Brue Davie, Computer Networks: A Systems Approah