def attachNetDataStream(self, stream, curTime): if self.ready: # attach a stream to the cache instance: # a cache stream is created, 'stream' is added as dependent stream sRateID = sg.STREAM_RATES.index(stream.consumeRate) cacheStreamID = sRateID * sg.NUMBER_CHANNELS + stream.channel if stream.channel in self.strs_cnl_rate[sRateID]: # we have channel with this rate in cache self.strs_cnl_rate[sRateID][stream.channel].append(stream) else: self.strs_cnl_rate[sRateID][stream.channel] = [stream] if self.cacheStreams[cacheStreamID] is None: # FIXME: use ip-address as the dest ip instead... cSt = ns.netDataStream(stream.consumeRate, stream.srcIP, 'cache@' + str(self.ASnum), 0, stream.channel, sg.STREAM_CACHE) cSt.downCacheRef = self path = networkx.shortest_path(sg.gnGraph.netGraph, self.ASnum, sg.gnGraph.ip2as[cSt.srcIP]) if sg.args.hierarchical: # in case of hierarchical caches, # on-demand instantiations are not allowed -> 'first=False' sg.urRef.routeStreamPath_inclCache(path, cSt, curTime, first=False) else: sg.urRef.routeStreamPath(path, cSt, curTime) self.cacheStreams[cacheStreamID] = cSt else: cSt = self.cacheStreams[cacheStreamID] if cSt.beingConsumed: sg.simRef.eventPush( se.event(curTime + sg.PROPAGATION_DELAY, id(stream), sg.EVENT_STREAM_START, stream)) else: if sg.args.waitCacheBoot: self.waitingStreams.append(stream) else: return False if not stream.connectedToCache: stream.upCacheRef = self stream.connectedToCache = True # Update stats thisAS = sg.gnGraph.netGraph.node[self.ASnum] thisAS['cur_Connections'] += 1 self.numStreamsConnected += 1 if self.numStreamsConnected > self.stats_maxConnections_vm: self.stats_maxConnections_vm = self.numStreamsConnected if thisAS['cur_Connections'] > thisAS['stats_maxConnections']: thisAS['stats_maxConnections'] = thisAS['cur_Connections'] return True
def process(self, ev): if ev.type == sg.EVENT_USER_REQUEST: dest_ip, stream_rate, data_size = self.requestQueue.get() hostAs = sg.gnGraph.ip2as[dest_ip] path = networkx.shortest_path( sg.gnGraph.netGraph, hostAs, sg.gnGraph.contentProvider ) serv_ip = sg.gnGraph.netGraph.node[sg.gnGraph.contentProvider]['ip'].exploded ds = ns.netDataStream( stream_rate, serv_ip, dest_ip, data_size, self.genChannelNumber() ) ds.bufferingBegin = ev.time if sg.args.streaming: self.routeStreamPath_inclCache(path, ds, ev.time) else: self.routeStreamPath(path, ds, ev.time) # statistics for user request ds.stats_events.append((ev.time, ev.type)) self.activeStreams += 1 self.numRequestsPerTimePeriod += 1 if self.streamGenActive: sg.simRef.eventPush(self.getNextEvent(ev.time)) elif ev.type == sg.EVENT_NOISE_USER_REQUEST: dest_ip, stream_rate, data_size = self.noiseRequestQueue.get() hostAs = sg.gnGraph.ip2as[dest_ip] servAs = sg.random.choice(sg.gnGraph.contentNodes) serv_ip = sg.gnGraph.as2ip[servAs][0][1].exploded path = networkx.shortest_path(sg.gnGraph.netGraph, hostAs, servAs) ds = ns.netDataStream( stream_rate, serv_ip, dest_ip, data_size, strType=sg.STREAM_NOISE ) self.routeStreamPath(path, ds, ev.time) if sg.simRef.simulatorReady: sg.simRef.eventPush( se.event( ev.time + sg.PROPAGATION_DELAY*len(path), id(ds), sg.EVENT_STREAM_START, ds ) ) else: self.initStreamsList.append(ds) self.activeNoiseStreams += 1 if not sg.simRef.simulationDone: if not sg.simRef.simulatorReady: sg.simRef.eventPush(self.getNoiseEvent(ev.time)) if self.activeNoiseStreams >= self.activeNoiseStreamsMax: for tmpStream in self.initStreamsList: tmpStream.startStreaming(ev.time) tmpStream.bufferingBegin = ev.time self.initStreamsList = [] sg.simRef.simulatorReady = True self.streamGenActive = True # start normal stream sg.simRef.eventPush(self.getNextEvent(ev.time)) elif ev.type == sg.EVENT_CHANGE_REQUEST_RATE: self.streamGenerationRate = self.calcStreamGenRate( self.streamGenRateScenario[self.streamGenRate_next][1] ) self.streamGenRate_next += 1 elif ev.type == sg.EVENT_SIM_FINALIZE: printWithClock("Simulated: {:.1f}s.".format(float(ev.time)) + " -- SIM_FINALIZE: no new streams", pre='\n') self.streamGenActive = False elif ev.type == sg.EVENT_PERIODIC_STATS: sg.simRef.urStatistics_nActCons.append( (ev.time, self.activeStreams) ) reqPerSec = float(self.numRequestsPerTimePeriod) / 10 * 60 sg.simRef.urStatistics_nReqPSec.append((ev.time, reqPerSec)) self.numRequestsPerTimePeriod = 0 if not sg.simRef.simulationDone: sg.simRef.eventPush( se.event( ev.time + 1, id(self), sg.EVENT_PERIODIC_STATS, self ) ) curTime = time.time() printWithClock( "Simulated: {:.1f}s.".format(float(ev.time)) + " active streams = " + str(self.activeStreams) + ", 1 sim-second = {:.1f}s.".format(curTime - self.timer), pre='\r', end='\n' if ev.time % 10 == 0 else '' ) self.timer = curTime else: raise Exception("Unknown event type:" + str(ev.type)) return
def attachNetDataStream(self, stream, curTime): if self.ready: # attach a stream to the cache instance: # a cache stream is created, 'stream' is added as dependent stream sRateID = sg.STREAM_RATES.index(stream.consumeRate) cacheStreamID = sRateID * sg.NUMBER_CHANNELS + stream.channel if stream.channel in self.strs_cnl_rate[sRateID]: # we have channel with this rate in cache self.strs_cnl_rate[sRateID][stream.channel].append( stream ) else: self.strs_cnl_rate[sRateID][stream.channel] = [stream] if self.cacheStreams[cacheStreamID] is None: # FIXME: use ip-address as the dest ip instead... cSt = ns.netDataStream( stream.consumeRate, stream.srcIP, 'cache@'+str(self.ASnum), 0, stream.channel, sg.STREAM_CACHE ) cSt.downCacheRef = self path = networkx.shortest_path( sg.gnGraph.netGraph, self.ASnum, sg.gnGraph.ip2as[cSt.srcIP] ) if sg.args.hierarchical: # in case of hierarchical caches, # on-demand instantiations are not allowed -> 'first=False' sg.urRef.routeStreamPath_inclCache( path, cSt, curTime, first=False ) else: sg.urRef.routeStreamPath(path, cSt, curTime) self.cacheStreams[cacheStreamID] = cSt else: cSt = self.cacheStreams[cacheStreamID] if cSt.beingConsumed: sg.simRef.eventPush( se.event( curTime + sg.PROPAGATION_DELAY, id(stream), sg.EVENT_STREAM_START, stream ) ) else: if sg.args.waitCacheBoot: self.waitingStreams.append(stream) else: return False if not stream.connectedToCache: stream.upCacheRef = self stream.connectedToCache = True # Update stats thisAS = sg.gnGraph.netGraph.node[self.ASnum] thisAS['cur_Connections'] += 1 self.numStreamsConnected += 1 if self.numStreamsConnected > self.stats_maxConnections_vm: self.stats_maxConnections_vm = self.numStreamsConnected if thisAS['cur_Connections'] > thisAS['stats_maxConnections']: thisAS['stats_maxConnections'] = thisAS['cur_Connections'] return True