Implementation of Leaky Bucket Algorithm
To implement the leaky bucket algorithm to simulate network traffic shaping. It demonstrates how a buffer with fixed capacity handles random packet arrivals by adding packets when space is available, dropping excess packets when overflow occurs, and leaking packets at a constant rate to control data transmission and prevent network congestion.
Algorithms
Step 1: Start
Step 2: Read bucket capacity, leak rate, simulation time
Step 3: Initialize bucket = 0
Step 4: Initialize random number generator
Step 5: For t = 0 to simulation_time-1 do:
Step 5.1: Generate random incoming packets (10-100)
Step 5.2: Display current time, incoming packets, bucket before
Step 5.3: If bucket + incoming ≤ capacity then:
bucket = bucket + incoming
Display "incoming Added"
Else:
dropped = incoming - (capacity - bucket)
bucket = capacity
Display "dropped Dropped"
End if
Step 5.4: If bucket > leak_rate then:
bucket = bucket - leak_rate
Else:
bucket = 0
End if
Step 5.5: Display bucket after leaking
Step 6: Stop