-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestFC.py
41 lines (28 loc) · 1.26 KB
/
testFC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from simpy import Environment
from Components.BasicComponent import Unit
from Components.Packets import BasePacket
from Components.Pipelines import FlowControlledPipeline
from Components.Buffers import FlowControlledBuffer
class TestFlowControl(Unit):
def __init__(self,env,name='TestFlowControl',parent=None):
Unit.__init__(self,env,name,parent)
self.dataBuff=FlowControlledBuffer(env, 'Buffer',capacity=4, putBytesPerCycle=1,getBytesPerCycle=1)
self.pipe=FlowControlledPipeline(env, 'Pipe', putBytesPerCycle=1,initCredits=4, depth=8)
self.connect(fromUnit=self.pipe,toUnit=self.dataBuff)
def run(self):
self.env.process(self.sendProcess())
yield self.env.process(self.retrievalProcess())
def sendProcess(self):
for idx in range(10):
pkt=BasePacket()
yield self.pipe.put(pkt)
print('@{} : Finished sending packet {} down the pipeline'.format(self.env.now,idx))
def retrievalProcess(self):
idx=0
while True:
pkt=yield self.dataBuff.get()
print('@{} : Reading packet {} from the buffer. Sending a credit back to the source'.format(self.env.now,idx))
idx+=1
env=Environment()
TestFlowControl(env)
env.run(until=1000)