Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔄 Token Ring Protocol Simulation

C# .NET Networking License

A C# console application that simulates the Token Ring network protocol, featuring token passing, concurrent node communication, CRC-based error detection, binary data encoding, and random noise injection.

📖 Overview

This project was originally developed as a university assignment for the Computer Networks course, using C# and .NET.

The objective was to simulate the Token Ring protocol at the Data Link Layer by implementing a logical ring topology with concurrent nodes, token passing, frame transmission, CRC-based error detection, and random noise injection to emulate transmission errors.

This repository contains a refactored version of the original assignment, featuring cleaner code, improved readability, modern C# syntax, better object-oriented design, and enhanced project documentation while preserving the original simulation behavior.

📚 Original Assignment

The assignment required implementing a console-based simulation of the Token Ring protocol with the following requirements:

  • Simulate a logical ring consisting of at least 10 concurrent nodes.
  • Implement continuous token passing when the network is idle.
  • Allow message transmission only after capturing the free token.
  • Simulate the complete frame lifecycle (source → destination → source).
  • Implement random bit corruption on a predefined communication link.
  • Detect transmission errors using the CRC (Cyclic Redundancy Check) algorithm with the generator polynomial 1011.
  • Display the intermediate CRC calculation steps for debugging purposes.

✨ Features

  • 🔄 Token Ring Simulation

    • Logical ring topology
    • Network consisting of 15 concurrent nodes
    • Continuous token circulation
    • Token capture and release
  • 📦 Frame Transmission

    • Source and destination addressing
    • Payload transmission between nodes
    • Complete frame lifecycle
    • Transmission status confirmation
  • 🛡️ CRC Error Detection

    • Binary payload conversion
    • CRC generation using the 1011 generator polynomial
    • Frame integrity verification
    • Optional CRC debugging mode
  • ⚡ Noise Simulation

    • Random bit flipping
    • Predefined faulty communication link
    • Binary payload visualization
    • Transmission error detection
  • 🧵 Concurrent Execution

    • Independent node execution using Tasks
    • Thread-safe frame exchange with BlockingCollection
    • Continuous network simulation
  • 🖥️ Console Visualization

    • Color-coded event logging
    • Token passing visualization
    • Message transmission logs
    • CRC calculation output

🏗️ Application Architecture

The following diagram illustrates the relationships between the core components used in the Token Ring protocol simulation.

                    Program
                       │
                       ▼
                     Node
        ┌──────────┬────┴────┬──────────┐
        ▼          ▼         ▼          ▼
     Frame       CRC      Noise   BinaryConverter

📂 Project Structure

TokenRingProtocolSimulation/
├── .gitignore
├── TokenRingProtocolSimulation.sln
│
├── Images/
│   ├── 01-token_ring_simulation.png
│   ├── 02-successful_transmission.png
│   ├── 03-crc_debug_mode.png
│   └── 04-crc_error_detection.gif
│
└── TokenRingProtocolSimulation/
    ├── BinaryConverter.cs
    ├── CRC.cs
    ├── Frame.cs
    ├── Node.cs
    ├── Noise.cs
    ├── Program.cs
    └── TokenRingProtocolSimulation.csproj

🛠️ Built With

  • C# 12.0
  • .NET 8
  • Task Parallel Library (TPL)
  • Async / Await
  • BlockingCollection
  • Visual Studio 2022

⭐ Highlights

  • Token Ring network protocol simulation
  • Concurrent node communication using Tasks
  • CRC-based error detection and verification
  • Random bit corruption on a predefined faulty link
  • Refactored codebase with modern C# practices

🎯 Concepts Demonstrated

  • Object-Oriented Programming (OOP)
    The simulation is organized into dedicated classes (Node, Frame, CRC, Noise, and BinaryConverter), each with a clear responsibility.

  • Concurrency
    Multiple network nodes execute concurrently using Task, simulating independent stations communicating over a shared network.

  • Thread-Safe Communication
    BlockingCollection is used to safely exchange frames between concurrent nodes without race conditions.

  • Asynchronous Programming
    async and await are used to simulate network latency while keeping the application responsive.

  • Token Ring Protocol
    The project demonstrates controlled medium access through continuous token passing, ensuring that only the node holding the token can transmit data.

  • Frame-Based Communication
    Messages are encapsulated into frames containing source and destination addresses, payload, CRC, and transmission status information.

  • CRC (Cyclic Redundancy Check)
    A simplified CRC algorithm generates and verifies the Frame Check Sequence (FCS) using polynomial division with the generator polynomial 1011.

  • Binary Data Encoding
    ASCII messages are converted into binary form before transmission and CRC calculation.

  • Network Fault Simulation
    A predefined faulty communication link randomly flips a payload bit to simulate transmission errors.

  • Error Detection
    Corrupted frames are detected through CRC verification, demonstrating how transmission errors can be identified without correcting the data.

  • Encapsulation
    Internal node state and frame information are managed through properties and controlled access to class members.

📸 Screenshots

1. Token Ring Simulation

The simulation starts by creating a logical ring of interconnected nodes. A free token continuously circulates through the network until one of the nodes captures it to initiate a transmission.

Token Ring Simulation


2. Successful Data Transmission

A node captures the free token, creates a data frame, computes the CRC checksum, and sends the message to the destination node. After successful delivery and CRC verification, the sender releases a new free token.

Successful Data Transmission


3. CRC Debug Mode

CRC Debug Mode displays the complete polynomial division process used to generate the Frame Check Sequence (FCS), showing every XOR operation together with the final remainder.

CRC Debug Mode


4. CRC Error Detection

This demonstration shows a frame passing through the predefined faulty network link. A random bit is flipped, the receiver recomputes the CRC, detects a non-zero remainder, reports a CRC error, and the sender marks the transmission as failed before releasing the token.

CRC Error Detection

📋 Requirements

  • Windows 10 / Windows 11
  • .NET 8 SDK
  • Visual Studio 2022 (recommended)

🚀 Running

  1. Clone the repository.
git clone <repository-url>
  1. Open the solution in Visual Studio 2022.

  2. Restore the NuGet packages (if required).

  3. Build the solution.

Build → Build Solution

or simply press:

Ctrl + Shift + B
  1. Run the application.
F5

or click Start in Visual Studio.

  1. When prompted, choose whether to enable CRC Debug Mode by entering:
y

to display the complete CRC calculation process, or

n

to run the standard simulation.

  1. The simulation creates a logical Token Ring network, circulates a free token between nodes, performs frame transmissions, simulates transmission errors on the predefined faulty link, and verifies frame integrity using the CRC algorithm.

📄 License

This project is released under the MIT License.

About

Token Ring protocol simulation with concurrent node communication, CRC error detection and transmission error simulation in C#.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages