- Random Access Protocols
- E.g. ALOHA, CSMA, CSMA/CD

- Controlled Access Protocols
- E.g. Bitmap, Token Passing, Binary Countdown

Type of data

Expected problems with data:

messages for processes

### **Application**

Depends on protocol (TCP/UDP)

messages for hosts

### **Transport**

Package Loss/Corruption/Out of order delivery

data for link

### **Network**

Package Loss

stream of bits

### **Link**

Individual Bit flips/ number of bits might change

signals in a medium

### **Physical**

signals degrade or interfered with

</br>

FLAG

Header

Payload Field

Trailer

FLAG

### Open Question: What happens if the flag value is found (i.e. naturally occurs) in the data? --- # Framing: Byte stuffing - Special flag bytes delimit frames; occurrences of flags in the data must be stuffed (escaped) - Longer, but easy to resynchronize after error </img> --- # Framing: Byte stuffing </img> - Byte sequences before and after stuffing for a different special byte - escape! --- # Framing: bit stuffing </img> - The flag is six consecutive ones. Within the data, a zero is stuffed after each five consecutive ones to void instances of the flag in the data.

- The original data
- The data as they appear on the line
- The data as stored by receiver after de-stuffing

The number of bit positions in which two codewords differ is called the Hamming distance between these two codewords.

---
# Error Bounds – Hamming distance
#### Example with 2 codewords:
- Codeword #1: 1 0 0 0 1 0 0 1
- Codeword #2: 1 0 1 1 0 0 0 1
- Hamming distance is 3. The number of bit positions in which two codewords differ
---
# Error Detection and Correction
### Hamming distance
0 0 1 0 0 0 0 1 0 0 1 (original codeword)

0 0 1 0 1 0 0 1 0 0 1 (received codeword)

--- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #1: number the bits1 2 3 4 5 6 7 8 9 10 11

0 0 1 0 1 0 0 1 0 0   1  (received codeword)

--- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #2: allocate parity bits and message bits- powers of 2 bits are parity bits and the rest are message bitsp1 p2 m3 p4 m5 m6 m7 p8 m9 m10 m11

0   0   1     0     1    0    0    1    0    0       1     (received codeword)

--- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #3: finding the parity bitsp1 p2 m3 p4 m5 m6 m7 p8 m9 m10 m11

0   0   1     0     1    0    0    1    0    0       1    

- Finding p1: - Count one bit and skip one, starting from p1 but not including p1 value. - Add the 1s. If the result is even then p1 parity is 0, if the result is odd then p1 parity is 1. - p1 is? 1 1 0 0 1 → 1 --- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #3: finding the parity bitsp1 p2 m3 p4 m5 m6 m7 p8 m9 m10 m11

0   0   1     0     1    0    0    1    0    0       1    

- Finding p2: - Count two bits and skip two, starting from p2 but not including p2 value. - Add up the result. If the result is even then p2 parity is 0, if the result is odd then p2 parity is 1 - p2 is? 1 0 0 0 1 → 0 --- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #3: finding the parity bitsp1 p2 m3 p4 m5 m6 m7 p8 m9 m10 m11

0   0   1     0     1    0    0    1    0    0       1    

- Finding p4: - Count four bits and skip four, starting from p4 but not including p4 value. - Add up the result. If the result is even then p4 parity is 0, if the result is odd then p4 parity is 1. - p4 is ? 1 0 0 - - → 1 --- # Error Correction – Hamming code0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #3: finding the parity bitsp1 p2 m3 p4 m5 m6 m7 p8 m9 m10 m11

0 0 1 0 0 0 0 1 0 0 1 (original codeword)

- step #4: compare our result with the received parity bits.
C(yclic)R(edundancy)C(heck) - more advanced technique, which uses manipulations with polynomials.

---
# Error Detection - CRC
- One of the most commonly used error detection codes
### Basic approach:
- Let M1 be the message of n-bits
- M1 is padded with CRC code and send it
- CRC is generated using a given polynomial P1 (or Divisor)
- P1 is agreed between sender and receiver
- Receiver gets M1 + CRC and extracts the M1 using P1
---
# CRC – error detection and correction
</img>
---
# Error Detection – CRC (example)
#### Example: encoding / sender side
M1 = 1 0 1 0</br>
P1 (Divisor) = 1 0 1 1
#### Generate CRC:
1. Add the degree of P1 (P1 length – 1) to M1 as zeros </br> P1 length - 1 = 4 – 1 = 3
2. Add 3 zeros to M1 </br> 1 0 1 0 0 0 0
3. Divide M1 by P1 using XOR
---
# Error Detection – CRC (example)
Transmitted frame: 1 0 1 0 0 1 1
</img>
---
# Error Detection – CRC
#### Example: decoding / receiver side
Message: 1 0 1 0 0 1 1
Divisor: 1 0 1 1
- Divide the received message by the divisor
- If the result is 0, message is correct. Otherwise, message is incorrect.
---
# Error Detection – CRC (example)
</img>
---
# Summary
- Link layer services
- Data Framing
- Error detection and correction