Computer Networks Summary

Chan - Nov 4 - - Dev Community

Layered Architecture

  • Main purpose: separation of concerns
  • Each layer has its responsibility

What each layer does

  1. It takes input from the layer above it
  2. It communicates with the layer below it to process the input
  3. After processing, it returns output to the layer above it.

OSI Model(The Open Systems Interconnection Model)

  • A conceptual model that enables data communication
  • Consists of 7 layers: physical layer, data-link layer, network layer, transport layer, session layer, presentation layer, and application layer

TCP/IP Protocol Suite

  • A set of protocols used on the Internet
  • Maintained by IETF(Internet Engineering Task Force)
  • Consists of 4 layers: data access layer, internet layer, transport layer, and application layer

Data-Link Layer(Layer 2)

  • Responsible for point-to-point reliable data transfer within the same network
  • HDLC(High-Level Data Link Control) is the most commonly used protocol at this layer

Key Features

  • Error Control: Error detection and correction
  • Flow Control: The sender transmits data at the rate the receiver can receive

Error Detection Techniques

  • Parity bits: count the number of 1s in data and fill the parity bit with 1 if it's even and 0 otherwise
  • CRC(Cyclic Redundancy Check): FCS(Frame Check Sequence)
  • Checksum: Getting the sum of fixed-sized bytes and end-around carry(adding carry to the least significant bit)

In all the techniques mentioned here, the source calculates the result and sends it with data, and the destination recalculates the result and checks if it's the same as the source calculated.

Here's a mock implementation of the sender and the receiver in typescript.

sender.ts

const BINARY = {
  ZERO_STRING: "0",
  ONE_STRING: "1",
} as const;

const countOnes = (binary: string) => {
  return binary.split("").reduce((accumulator, bit) => {
    if (bit === BINARY.ONE_STRING) {
      return accumulator + 1;
    }
    return accumulator;
  }, 0);
};

const isEven = (numberOfOnes: number) => numberOfOnes % 2 === 0;

const getParityBit = (numberOfOnes: number) =>
  isEven(numberOfOnes) ? BINARY.ONE_STRING : BINARY.ZERO_STRING;

const getFrame = (payload: string): string => {
  const numberOfOnes = countOnes(payload);
  const parityBit = getParityBit(numberOfOnes);

  return payload + parityBit;
};
Enter fullscreen mode Exit fullscreen mode

receiver.ts

const isFrameValid = (payload: string, receivedParityBit: string): boolean => {
  const numberOfOnes = countOnes(payload);
  const calculatedParityBit = getParityBit(numberOfOnes);

  if (calculatedParityBit === receivedParityBit) {
    return true;
  }
  return false;
};

Enter fullscreen mode Exit fullscreen mode

Error Correction Techniques

  • Hamming Code: error correction is used when there is a long propagation delay, leading to a long retransmission time

Flow Control Techniques

  • Stop-and-wait flow control: The source sends a single frame and waits until it receives an acknowledgment from the destination.
  • Sliding window flow control: The source simultaneously sends multiple numbered frames up to the window size. The left space in the destination's buffer determines the window size.

Error Control Techniques

  • Stop-and-wait ARQ:
  1. When a frame gets lost: sender timeout => sender retransmission => receiver sends an ACK for the next frame
  2. When a frame gets corrupted: the receiver discards the duplicate packet => receiver sends an ACK for the current frame again
  3. When an ACK gets lost: sender timeout => sender retransmission => receiver discards the duplicate packet => receiver sends an ACK for the next frame
  4. When an ACK gets corrupted: sender timeout => sender retransmission => receiver discards the duplicate packet => receiver sends an ACK for the next frame
  • Go-back-N ARQ: When the receiver receives out-of-order or corrupted packets, it returns the acknowledgment for the last in-order and valid frame
  • Selective-repeat ARQ:

Flow Control

Key Features

Transport Layer(Layer 4)

  • Responsible for end-to-end reliable data transfer across multiple networks
  • TCP(Transport Control Protocol) and UDP(User Datagram Protocol) are most commonly used protocol at this layer

Key Features

  • Error Recovery: Error detection and correction
  • Flow Control: The sender transmits data at the rate the receiver can receive
  • Congestion Control: The sender transmits data at the rate data while being sent

Error Control Techniques

Acknowledgment

  • Positive Acknowledgment:
  • Negative Acknowledgment:
  • Cumulative Acknowledgment:
. . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player