A dynamic network routing protocol that optimizes path selection and prevents routing inefficiencies in complex network environments.
Traditional routing mechanisms struggle with adapting to network changes, creating inefficient and potentially unstable communication paths.
- Automatic update broadcasts every 30 seconds
- Immediate updates on topology changes
- Configurable update intervals
- Real-time route computation
- Path cost calculation
- Next-hop determination
- Route invalidation and cleanup
- Classless Inter-Domain Routing
- Subnet mask handling
- Network aggregation
- Variable-length subnet masks
- Loop prevention mechanism
- Infinite metric for poisoned routes
- Split-horizon rule implementation
- Count-to-infinity prevention
class Router:
def __init__(self, router_id, neighbors):
self.router_id = router_id
self.neighbors = neighbors
self.routing_table = RoutingTable()
self.update_interval = 30 # seconds
def start(self):
"""Initializes router and starts UDP threads"""
self.server_thread.start()
self.client_thread.start()
class RoutingTable:
def __init__(self):
self.routes = {}
self.invalid_timeout = 180 # seconds
self.flush_timeout = 240 # seconds
def update_route(self, destination, next_hop, metric):
"""Updates routing table entry with new information"""
if metric + 1 >= 16: # RIP infinite metric
self.invalidate_route(destination)
else:
self.routes[destination] = Route(next_hop, metric + 1)
class VirtualRouter:
def __init__(self, config_file):
self.topology = Topology(config_file)
self.router = Router(self.topology.router_id)
def process_update(self, update):
"""Processes received routing updates"""
for route in update.routes:
if self.apply_split_horizon(route):
continue
self.update_routing_table(route)
python virtualrouter.py --config router1.conf
router_id = 1
neighbors = 2,3,4
networks = 192.168.1.0/24,10.0.0.0/8
update_interval = 30
def process_route_update(self, route):
"""
Process incoming route updates
Implements split-horizon with poisoned reverse
"""
if route.next_hop == self.router_id:
route.metric = 16 # Poison reverse
elif route.metric + 1 < 16:
self.routing_table.update(route)
class NetworkAddress:
def __init__(self, address, mask):
self.address = address
self.mask = mask
def matches(self, ip):
"""Check if IP matches network address with mask"""
return (ip & self.mask) == self.address
DEFAULT_CONFIG = {
'UPDATE_INTERVAL': 30, # seconds
'INVALID_TIMEOUT': 180, # seconds
'FLUSH_TIMEOUT': 240, # seconds
'MAX_METRIC': 16, # RIP infinite metric
'POISON_METRIC': 16, # Metric for poisoned routes
}
# Start test network
python test_network.py --routers 4
# Simulate link failure
python test_network.py --fail-link 1-2
# Monitor convergence
python test_network.py --monitor
The implementation has been tested for:
- Convergence time
- CPU and memory usage
- Network overhead
- Route stability
- Python Programming
- Socket Programming
- Concurrent Programming
- UDP Implementation
- Object-Oriented Design
- Network Protocol Implementation
.
├── router.py # Core router implementation
├── routinginfo.py # Routing table and route information
├── topology.py # Network topology management
├── udpclientthread.py # UDP client for sending updates
├── udpserverthread.py # UDP server for receiving updates
└── virtualrouter.py # Virtual router simulation