Projects Inventory

Simulation of Data Link Layer Protocols Gaming Project in C++

Explanation

  1. Header Files:
    • <iostream>: For input and output operations.
    • <vector>: Used here just for completeness in case of extension.
    • Advertisement
    • <string>: To handle string operations.
    • <cstdlib>: For functions like std::rand().
    • <ctime>: For seeding the random number generator.
  2. Frame Class:
    • Constructor: Initializes a frame with data and calculates its checksum.
    • Advertisement
    • getData(): Returns the data of the frame.
    • getChecksum(): Returns the checksum of the frame.
    • isCorrupted(): Checks if the frame has been corrupted by comparing the calculated checksum with the stored checksum.
    • calculateChecksum(): Computes a simple checksum by summing ASCII values of characters in the data and taking modulo 256.
  3. DataLinkLayer Class:
    • sendFrame(): Simulates sending a frame by storing it in receivedFrame.
    • receiveFrame(): Checks the received frame for corruption and outputs the result.
    • Advertisement
  4. main() Function:
    • Seeds the random number generator.
    • Creates an instance of DataLinkLayer.
    • Creates a frame with some data and sends it.
    • Simulates potential corruption by altering the frame’s data.
    • Receives and checks the frame to detect any corruption.
Exit mobile version