-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where the Port and REDPort does not drop packets prope…
…rly when downstream nodes have zero buffer. (#16) Co-authored-by: Baochun Li <[email protected]>
- Loading branch information
Showing
3 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
An very simple example of using the test the packet drop in FairPacketSwitch. | ||
It shows a bug in packet dropping process. | ||
""" | ||
import simpy | ||
from ns.packet.dist_generator import DistPacketGenerator | ||
from ns.packet.sink import PacketSink | ||
from ns.switch.switch import FairPacketSwitch | ||
|
||
|
||
def packet_arrival(): | ||
"""Constant packet arrival interval.""" | ||
return 1.0 | ||
|
||
|
||
def const_size(): | ||
"""Constant packet size in bytes.""" | ||
return 1000.0 | ||
|
||
|
||
env = simpy.Environment() | ||
pg1 = DistPacketGenerator( | ||
env, | ||
"flow_0", | ||
packet_arrival, | ||
const_size, | ||
initial_delay=0.0, | ||
finish=3, | ||
flow_id=0, | ||
rec_flow=True, | ||
) | ||
pg2 = DistPacketGenerator( | ||
env, | ||
"flow_1", | ||
packet_arrival, | ||
const_size, | ||
initial_delay=0.1, | ||
finish=3, | ||
flow_id=1, | ||
rec_flow=True, | ||
) | ||
ps = PacketSink(env) | ||
|
||
port_rate = 8000.1 # in bits | ||
buffer_size = 1100 # in bytes | ||
|
||
switch = FairPacketSwitch( | ||
env, | ||
nports=1, | ||
port_rate=port_rate, | ||
buffer_size=buffer_size, | ||
weights=[1, 2], | ||
server="DRR", | ||
debug=True, | ||
) | ||
switch.egress_ports[0].limit_bytes = True | ||
pg1.out = switch | ||
pg2.out = switch | ||
switch.demux.fib = {0: 0, 1: 0} | ||
switch.ports[0].out = ps | ||
|
||
env.run() | ||
|
||
print("\n==========Basic Info==========") | ||
|
||
print( | ||
f"The buffer size is {buffer_size} bytes, the port rate is {port_rate / 8} bytes/sec, " | ||
f"and the packet size is {const_size()} bytes." | ||
) | ||
|
||
print("==========Result==========") | ||
print("For the switch, the packet arrival times for flow 0 are:") | ||
print(pg1.time_rec) | ||
|
||
print("For the switch, the packet arrival times for flow 1 are:") | ||
print(pg2.time_rec) | ||
|
||
print("At the packet sink, packet arrival times for flow 0 are:") | ||
print(ps.arrivals[0]) | ||
|
||
print("At the packet sink, packet arrival times for flow 1 are:") | ||
print(ps.arrivals[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters