class InputStream(Process): def __init__(self, name, bitrate, sim): Process.__init__(self, name) self.requester = WRequester("Write Requester of %s"%name, sim.params) self.bitrate = bitrate self.rambus = sim.params.rambus self.errors = sim.errors def fillBuffer(self, avgPktSize=0): # Activate BufferControl's process in 100 ms activate(self.requester, self.requester.watchBuffer(), now()+100) # If the average packet size is not redefined, define as bitrate if avgPktSize <= 0: avgPktSize = self.bitrate/10.0 # Continuously fill corresponding buffer with kBs based on the # given average bitrate. while True: sizemb = expovariate(1.0/avgPktSize) sizekB = sizemb*128 #Mb -> KB if self.requester.buffer.freeSpace() < sizekB: self.errors.append("<font color=red>%s Buffer Overflow at %.3f</font>"%(self.name, now())) else: yield put, self, self.requester.buffer, sizekB yield request, self, self.rambus yield hold, self, self.rambus.processTime(sizekB) yield release, self, self.rambus #print "Just added %f kBs to %s at %i"%(sizekB,self.name,now()) yield hold, self, (1000*sizemb/self.bitrate)
def __init__(self, name, bitrate, sim): Process.__init__(self, name) self.requester = WRequester("Write Requester of %s"%name, sim.params) self.bitrate = bitrate self.rambus = sim.params.rambus self.errors = sim.errors