This Python implementation of a network simulator demonstrates the functionality of different network layers with a complete protocol stack approach. It visually shows how data travels through each layer of the network model, demonstrating how protocols operate at each layer.
The simulator implements the full network protocol stack:
- DNS for hostname-to-IP resolution
- Application data processing
- Email and search engine services simulation
- Port Management: Well-known ports (0-1023) and ephemeral ports (1024-65535)
- Process Registration: Process-to-process communication with port allocation
- TCP Implementation:
- Three-way handshake connection establishment
- Sliding window flow control (Go-Back-N protocol)
- Reliable data transmission with acknowledgments
- Error detection and retransmission
- Connection state management
- UDP Implementation:
- Connectionless datagram transmission
- Simple header format with port information
- Flow Control: Reusable sliding window implementation for both transport and data link layers
- Router implementation with routing tables
- IP addressing and subnet management
- Multi-network routing with next-hop determination
- ARP for IP-to-MAC resolution
- Switch implementation with MAC address learning
- Error detection using CRC-32
- Frame creation and processing
- Flow control protocols
- End devices creation
- Hub operation with broadcasting
- Physical signal transmission simulation
- Email service implementation
- Search engine implementation
- DNS for hostname-to-IP resolution
The simulator provides several demo options through an easy-to-use script:
-
Using the batch file (Windows):
run_demo.bat -
Using the shell script (Linux/Mac):
./run_demo.sh -
Directly from command line:
# Run the comprehensive network demo (all layers) python run_network_tests.py comprehensive # Run the router operation demo (focuses on network layer) python run_network_tests.py router # Run the switch operation demo (focuses on data link layer) python run_network_tests.py switch
-
Comprehensive Network Test
- Demonstrates the complete protocol stack
- Shows data flow through all 5 layers
- Includes inter-network routing
- Demonstrates DNS and ARP protocols
- Shows switch and hub operation
-
Router Operation Test
- Focuses on network layer operations
- Demonstrates routing table lookups
- Shows packet forwarding between networks
- Demonstrates TTL processing
-
Switch Operation Test
- Focuses on data link layer operations
- Demonstrates MAC address learning
- Shows frame forwarding based on MAC addresses
- Demonstrates broadcast and unicast handling
-
Follow the prompts to:
- Create a network topology
- Select sender and receiver devices
- Test data transfer between devices
- Test application layer services (email and search)
-
Alternatively, run the comprehensive network demo:
python main.py --demoThis will automatically run a pre-configured demonstration that shows:
- A complex network topology with multiple networks
- Routers with routing tables
- Switches with MAC address tables
- Hub broadcasting
- ARP protocol for MAC address resolution
- IP routing between networks
- DNS for domain name resolution
- CRC for error detection in Data Link layer
-
For Windows users, you can simply double-click on
run_demo.batin the main directory. For Linux/Mac users, you can run./run_demo.shfrom the terminal.
- Physical Layer Test: Create two end devices with a direct connection.
- Data Link Layer Test: Create a switch with multiple connected end devices.
- Hub and Switch Test: Create two hubs connected by a switch with multiple end devices.
- Application Layer Test: Use the email and search engine services.
main.py: Entry point for the simulatornetwork_simulator.py: Main simulator logicend_devices.py: End devices implementationhub.py: Hub implementationswitch.py: Switch implementationrouter.py: Router implementationcrc_for_datalink.py: CRC for error detectiondomain_name_server.py: DNS implementationemail_service.py: Email service implementationsearch_service.py: Search engine implementationsearch_engine_server.py: Search engine server implementation