Advanced Computer Networks Department of Computer Science DCS COMSATS Institute of Information Technology Rab Nawaz Jadoon Assistant Professor COMSATS University, Lahore Pakistan Advanced Computer Networks
Lectures Seminars Course Plan Reading of various Research Papers Presentations by the students on selected topics Quizzes and Reports Recommended Books Data Communication & Networks by Behrouz A. Forouzan Computer Networks by Andrew Tannenbaum Department of Computer Science 2
Grading Percentage Grade GP 90% and above A 4 80% to 89% B 3.5 70% to 79% C 3 60% to 69% D 2.5 Below 60% F 0 Department of Computer Science 3
Marks Distribution Description Weight age Quiz/Assignment 25% Midterm 25% Final 50% Department of Computer Science 4
Layer Task The Letter is written, put in envelop and dropped in mailbox. The Letter is picked up, removed from the envelop and read. The Letter is carried from mailbox to a post office. The Letter is carried from the post office to the mailbox. The Letter is delivered to a carrier by the post office. The Letter is delivered from the carrier to the post office Department of Computer Science 5
OSI layers Department of Computer Science 6
Internet Model H2 H3 H4 H5 D5 (Application Layer) D4 ( Transport Layer) D3 ( Network Layer) D2 ( Data Link Layer) Physical Layer Layered Architecture Department of Computer Science 7
Organization of layers TCP/IP protocol suite can be divided into three subgroups Network support layers Deals with the physical aspect of the moving data from one device to other device Electrical specification, physical connections, addressing timing and reliability User support layer Transport layer links the two subgroups Department of Computer Science 8
Physical Layer Functionality of layers Responsible for transmitting individual bits from one node to another. It defines the physical characteristics of the interface between the device and transmission media. Representation of bits into signals. Data rate such as duration of bits. Clock Synchronization of bits. Multiplexing Department of Computer Science 9
Data link Layer Functionality of layers Responsible for transmitting frames from one node to another. Framing: it divides stream of bits received from network layer into manageable data units called frames. Physical addressing Flow Control Error Control: it adds reliability to the physical layer by adding mechanism to detect and retransmit damaged or lost frames. Trailer Access control Department of Computer Science 10
Network Layer Functionality of layers Responsible for original source to final destination delivery of packet across multiple networks. It oversees the delivery of the packets between two systems on the same networks. Logical addressing. Routing Department of Computer Science 11
Transport Layer Functionality of layers Responsible for delivery of a message from process to process delivery. Also maintaining the logical connections between sender and receiver Port Addressing. Segmentation and reassembly. Connection control Flow control Error Control Department of Computer Science 12
Application Layer Functionality of layers Responsible for providing services to user. Mail services File Transfer and access. Remote login Accessing www Department of Computer Science 13
OSI Model Presentation Layer It is concerned with the syntax and semantics of the information exchange between two systems. Translation: sender dependent format to common format. Encryption Compression Department of Computer Science 14
Summary Node-to-Node Delivery (At MAC Layer) Host-to-Host Delivery (At Network Layer) Process-to-Process Delivery (At Transport Layer) Department of Computer Science 15
TCP/IP Suit Department of Computer Science 16
Comparison of Network models Department of Computer Science 17
Functioning of Layers Department of Computer Science 18
Data Link Layer Common responsibilities and functionalities provided by DATA Link Layer, Hop to Hop Delivery Also include framing, addressing, flow control, error control, and media access control. The data link layer divides the stream of bits received from the network layer into manageable data units called frames. The data link layer adds a header to the frame to define the addresses of the sender and receiver of the frame. Department of Computer Science 19
Flow Control Data Link Layer If the rate at which the data are absorbed by the receiver is less than the rate at which data are produced in the sender, the data link layer imposes a flow control mechanism to avoid overwhelming the receiver. Error Control It also adds reliability to the physical layer by adding mechanisms to detect and retransmit damaged, duplicate, or lost frames. Department of Computer Science 20
Access Control DATA Link Layer When two or more devices are connected to the same link, data link layer protocols are necessary to determine which device has control over the link at any given time. Due to this functionality it is also called MAC layer. Department of Computer Science 21
Error Detection and Correction A system must guarantee that the data received should be identical to the data transmitted. Data can be corrupted during transmission. Some applications require that errors be detected and corrected. Many factors can alter one or more bits of a message. Department of Computer Science 22
Error vs. Fault Error Detection and Correction Fault leads to error and error leads to failure. Types of errors Single bit error Single-bit errors are the least likely type of error in serial data transmission. Burst error The term burst error means that 2 or more bits in the data unit have changed from 1 to 0 or from 0 to 1. Department of Computer Science 23
Burst Error DATA Link Layer In figure below, 0100010001000011 was sent, but 0101110101100011 was received. Burst error does not occur in consecutive bits. The length of the burst is measured from the first corrupted bit to the last corrupted bit. Burst error of length 8 Department of Computer Science 24
Redundancy Data link layer The central concept in detecting or correcting errors is redundancy. This is done through by sending extra bits with the data to be sent. These redundant bits are added by the sender and removed by the receiver. It helps the receiver to detect and then correct the corrupted bits. Department of Computer Science 25
Coding Data link layer Redundancy is achieved through various coding schemes. The sender adds redundant bits through a process that creates a relationship between the redundant bits and the actual data bits. The receiver checks the relationships between the two sets of bits to detect or correct the errors. Block coding is used to do the stuff. Department of Computer Science 26
Data Link Layer Sender Encoder Message Receiver Message Decoder Accepted or discarded Generator Checker Message + redundancy Received DATA Unreliable transmission Department of Computer Science 27
DATA Link Layer For block coding we use modulo-2 arithmetic's. In this arithmetic, the modulus N is 2. Mean that use only 0 and 1. Operations in this arithmetic are very simple. The following shows how we can add or subtract 2 bits. In this arithmetic we use the XOR (exclusive OR) operation for both addition and subtraction. Adding: 0+0=0 0+1=1 1+0=1 1+1=0 Subtracting: 0-0=0 0-1=1 1-0 =1 1-1 =0 Department of Computer Science 28
BLOCK Coding In this coding the actual message is divided into blocks each of k-bits, called data words. Then add r redundant bits to each block to make the length n = k + r. The resulting n-bit blocks are called codewords. E.g. The 4B/5B block coding Department of Computer Science 29
Block Coding How can errors be detected by using block coding? Two ways, 1. The receiver has (or can find) a list of valid codeword. 2. The original codeword has changed to an invalid one. Department of Computer Science 30
Example Let us assume that k = 2 and n = 3. Table below shows the list of datawords and codewords. A code for error detection Department of Computer Science 31
Solution Assume the sender encodes the dataword 01 as 011 and sends it to the receiver. Consider the following cases, The receiver receives 011. It is a valid codeword. The codeword is corrupted during transmission, and 111 is received. This is not valid codeword so it is discarded. The codeword is corrupted during transmission, and 000 is received. This is a valid codeword. The receiver incorrectly extracts the dataword 00. Two corrupted bits have made the error undetectable. Department of Computer Science 32
Error Correction Mechanism Structure of encoder and decoder in error correction, Department of Computer Science 33
Hamming Distance It is a central concept in coding for error control. The Hamming distance between two words (of the same size) is the number of differences between the corresponding bits. It is depicted as d(x, y). It can easily done by applying the XOR operation on the two words and count the number of 1 s in the result. The Hamming distance d(10101, 11110) is 3 because 10101 xor 11110 is 01011 (three 1 s). Department of Computer Science 34
Minimum Hamming Distance The minimum Hamming distance is the smallest Hamming distance between all possible pairs in a set of words. For example, d(00000, 01011) = 3 d(01011, 10101) = 4 d(00000, 10101) = 3 d(01011, 11110) = 3 d(00000, 11110) = 4 d(10101, 11110) = 3 The d min in this case is 3. Department of Computer Science 35
LINEAR BLOCK CODES Almost all block codes used today belong to a subset called linear block codes. Non linear block codes are not used widely b/c their structure makes the theoretical analysis and implementation difficult. A linear block code is a code in which the exclusive OR (addition modulo-2) of two valid codewords creates another valid codeword. Department of Computer Science 36
Some Linear Block Codes Following are some linear block codes are, Simple Parity-Check Code Most familiar error-detecting code is the simple parity-check code. A k-bit dataword is changed to an n-bit codeword where n = k + 1. The extra bit, called the parity bit, is selected to make the total number of 1 s in the codeword even. The minimum Hamming distance for this category is d min = 2 The code is a single-bit error-detecting code; it cannot correct any error. Department of Computer Science 37
Simple parity-check code C(5, 4) Simple parity-check code Department of Computer Science 38
Simple parity-check code Encoder and decoder for simple parity-check code. Department of Computer Science 39
Calculating parity mechanism This is normally done by adding the 4 bits of the dataword (modulo-2); the result is the parity bit. In other words, r 0 = a 3 + a 2 + a 1 + a 0 (modulo-2) If the number of 1 s is even, the result is 0; if the number of 1 s is odd, the result is 1. At the reciever end, the addition is done over all 5 bits. The result which is called the syndrome, is just 1 bit. s o = b 3 + b 2 +b 1 + b 0 + q 0 (modulo-2) If s o is equal to 0 then no error, if 1 then the dataword is not extracted and hence the dataword is not created. Department of Computer Science 40
Hamming Codes It is a category of error-correcting codes. These codes were originally designed with d min = 3, which means that they can detect up to two errors or correct one single error. First let us find the relationship between n and k in a Hamming code. We need to choose an integer m >= 3. The values of n and k are then calculated from m as n = 2 m - 1 and k = n - m. The number of check bits r = m. Department of Computer Science 41
Hamming Code Mechanism Department of Computer Science 42
Hamming Code Mechanism A copy of a 4-bit dataword is fed into the generator that creates three parity checks r 0, r 1, and r 2, r 0 = a 2 + a 1 + a 0 r 1 = a 3 + a 2 + a 1 r 2 = a 1 + a 0 + a 3 modulo-2 modulo-2 modulo-2 Each of the parity-check bits handles 3 out of the 4 bits of the dataword. The total number of 1 s in each 4-bit combination (3 dataword bits and 1 parity bit) must be even. Above three equations are not unique. A combination of two equation cannot create the third one. Department of Computer Science 43
Hamming code C(7, 4) Department of Computer Science 44
Hamming Code Mechanism The checker in the decoder creates a 3-bit syndrome (S 2 S 1 S O ) in which each bit is the parity check for 4 out of the 7 bits in the received codeword. s 0 = b 2 + b 1 + b 0 +q 0 modulo-2 s 1 = b 3 + b 2 + b 1 +q 1 modulo-2 s 2 = b 1 + b 0 + b 3 +q 2 modulo-2 The equations used by the checker are the same as those used by the generator with the parity-check bits added to the right-hand side of the equation. Department of Computer Science 45
Hamming Code Mechanism The 3-bit syndrome creates eight different bit patterns (000 to 111) that can represent eight different conditions. Syndrome 000 001 010 011 100 101 110 111 Error None q 0 q 1 b 2 q 2 b 0 b 3 b 1 Generator is not concerned with the four cases shaded b/c there is either no error or an error in the parity bit. In the other four cases, 1 of the bits must be flipped (changed from 0 to 1 or 1 to 0) to find the correct dataword. Department of Computer Science 46
Example Let us trace the path of three datawords from the sender to the destination: Dataword Codeword Received Syndrome 0100 0100011 0100011 000 Result: No error 0111 0111001 0011001 011 Result: b 2 is in error, after flipping b 2 we get 0111 1101 1101000 0001000 101 Result: b 0 is in error, after flipping b 0 we get 0000, the wrong dataword. Note: This code cannot correct two errors. Department of Computer Science 47
Burst Error detection and correction The key is to split a burst error between several codewords. Normally we send a packet or a frame of data. Make the hamming code of size N codeword out of our frame to be sent. Instead of sending one frame, arrange codeword in table and send the bits in the table a column at a time. Bits are sent column by column. (from the left). Department of Computer Science 48
Burst error correction using H. Code Department of Computer Science 49
Cyclic codes are special linear block. Cyclic Codes In a cyclic code, if a codeword is cyclically shifted (rotated), the result is another codeword. For example if 1011000 is a codeword, then 0110001 is also a codeword after left shifting the dataword. Department of Computer Science 50
A CRC is an error-detecting code. Cyclic Redundancy Check Its computation resembles a polynomial long division operation in which the quotient is discarded and the remainder becomes the result. The coefficients are calculated according to the carry-less arithmetic of a finite field. The length of the remainder is always less than the length of the divisor. Department of Computer Science 51
To compute an n-bit binary CRC Computation of CRC Line the bits representing the input in a row. Put the divisor underneath the left-hand end of the row. Here is the first calculation for computing a 3-bit CRC, 11010011101100 <--- input 1011 <--- divisor (4 bits) --------------------- 01100011101100 <--- Result Department of Computer Science 52
Direct method calculation, CRC If the input bit above the leftmost divisor bit is 0, do nothing and move the divisor to the right by one bit. If the input bit above the leftmost divisor bit is 1, the divisor is XORed into the input. The divisor is then shifted one bit to the right, and the process is repeated until the divisor reaches the right-hand end of the input row. Complete calculation is on the next slide. Department of Computer Science 53
CRC Department of Computer Science 54
2 nd Method of Calculating CRC In the encoder, the dataword has k bits(4 here). The codeword has n bits(7 here). The size of the dataword is augmented by adding n k (3 here). The n-bit result is fed into the generator. The generator uses a divisor of size n - k + 1(4 here), predefined and agreed upon i.e. 1011. The generator divides the augmented dataword by the divisor (modulo-2 division). The quotient of the division is discarded; the remainder (r 2 r 1 r o ) is appended to the dataword to create the codeword. Department of Computer Science 55
2 nd Method of Calculating CRC CRC encoder and decoder Department of Computer Science 56
At decoder end, Receives the corrupted codeword. CRC All n bits are fed into checker which is replica of the generator. Remainder produced by the checker is a syndrome of n-k bits, which is fed into decision logic analyzer. If all bits of the syndrome is zero then no error take the 4 leftmost bits of the codeword are accepted, else discarded. Department of Computer Science 57
At Encoder side Department of Computer Science 58
At Decoder Side Department of Computer Science 59
At decoder end If the code word changes during transmission, then, Department of Computer Science 60
Simulation of division in CRC encoder Department of Computer Science 61
Polynomial representation A pattern of Os and 1 s can be represented as a polynomial with coefficients of 0 and 1. The power of each term shows the position of the bit; the coefficient shows the value of the bit. Department of Computer Science 62
Polynomial representation 1 0 0 0 0 1 1 X 6 + x + 1 We have seven bit number, the degree of the polynomial is 6 one less then the number of bits in the pattern. Department of Computer Science 63
Adding and subtracting Polynomial operation Adding or subtracting is done by combining terms and deleting pairs of identical terms. For example adding x 5 + x 4 + x 2 and x 6 + x 4 + x 2 gives just x 6 + x 5. The terms x 4 and x 2 are deleted. If we add three polynomial of the same degree then two of them deleted, one is kept left. Multiplying or Dividing Terms In multiplications, the powers are added. For division subtract the power of the second term from the power of first. Department of Computer Science 64
Polynomial operation Multiplying Two Polynomials Each term of the first polynomial must be multiplied by all terms of the second. The result, of course, is then simplified, and pairs of equal terms are deleted. Shifting Shifting number of bits to the right or left of the given pattern. Shifting left 3 bits: 10011 becomes 10011000 x 4 +x+ 1 becomes x 7 +x 4 +x 3 Shifting right 3 bits: 10011 becomes 10 x 4 + x + 1 becomes x Department of Computer Science 65
CRC division using polynomials Department of Computer Science 66
CHECKSUM The checksum is used in the Internet by several protocols. The checksum is based on the concept of redundancy. Basic Idea Suppose our data is a list of five 4-bit numbers. send the sum of the numbers along with the data. If the set of numbers is (7, 11, 12, 0, 6), we send (7, 11, 12, 0, 6, 36). The receiver adds the five numbers and compares the result with the sum. If the result is same then no error else data is not accepted. Department of Computer Science 67
Checksum Another heuristic is the negative (complement) of the sum called the checksum. We send (7, 11, 12, 0, 6, -36). Receiver add all the numbers, if result is 0 then no error otherwise an error. Department of Computer Science 68
One's Complement The previous example has one major drawback. The data is of 4 bit word (0 to 15) except checksum. One solution is to use the 1 s complement. Using unsigned numbers between 0 and 2 n - 1 using only n bits. If the number has more than n bits, then wrapping the bits. For example, 21 in binary is 10101. We can wrap the leftmost bit and add it to the four rightmost bits. We have (0101 + 1) = 0110 or 6. Department of Computer Science 69
Problem Checksum How can we represent the number -6 in one's complement arithmetic using only four bits? Department of Computer Science 70
Checksum using 1 s complement Let the data to be sent is (7, 11, 12, 0, 6) Figure below show the process at the sender and receiver. Department of Computer Science 71
Sender site: Checksum computation The message is divided into 16-bit words. The value of the checksum word is set to 0. All words including the checksum are added using one's complement addition. The sum is complemented and becomes the checksum. The checksum is sent with the data. Department of Computer Science 72
Receiver Site: Checksum computation The message (including checksum) is divided into 16-bit words. All words are added using one's complement addition. The sum is complemented and becomes the new checksum. If the value of checksum is 0, the message is accepted; otherwise, it is rejected. Department of Computer Science 73
Checksum computation Let us calculate the checksum for a text of 8 characters ("Forouzan"). The text needs to be divided into 2-byte (16-bit) words. We use ASCII to change each byte to a 2-digit hexadecimal number. F is represented as 0x46 and o is represented as 0x6F. Department of Computer Science 74
Solution Department of Computer Science 75
ASCII Chart Department of Computer Science 76
Department of Computer Science 77