예제 #1
0
    def processOutgoingpackets (self):

        for faceName , face in self.outputFaces.items():
            if not self.facesFlags[faceName]:
                face.append("0")
                self.facesFlags[faceName] = True
                logging.debug(self.name + " ++ " + faceName + "  " + str(face))
예제 #2
0
    def forwardInterestPacketNoCache(self, interestPacket, faceName):
        self.residualPower -= 1
        interestName = interestPacket.name
        outgoingFaceName = self.fib[interestName]

        # we must forward interest
        if self.pit.__contains__(interestName):
            containsEntryFlag = False
            table = self.pit[interestName]
            self.cacheMiss += 1
            for array in table:
                if array[0] == faceName and array[1] == outgoingFaceName:
                    containsEntryFlag = True
            if not containsEntryFlag:
                table.append([faceName, outgoingFaceName, interestPacket.freshness])
                # it is forward
                logging.debug(self.name + ": forward interest packet " + interestName + " to " + outgoingFaceName)
                print (
                        self.name + ": forward interest packet " + interestName + " to " + outgoingFaceName + " pit contains")
                self.sendOut(interestPacket, outgoingFaceName)
        else:
            # it is forward
            self.cacheMiss += 1
            logging.debug(self.name + ": forward interest packet " + interestName + " to " + outgoingFaceName)
            print (
                    self.name + ": forward interest packet " + interestName + " to " + outgoingFaceName + " pit doesn't contain")
            self.sendOut(interestPacket, outgoingFaceName)
            self.pit[interestName] = []
            self.pit[interestName].append([faceName, outgoingFaceName, interestPacket.freshness])
예제 #3
0
 def forwardDataPacketPcasting(self, dataPacket, faceName):
     self.residualPower -= 1
     interestName = dataPacket.name
     if self.pit.__contains__(interestName):
         table = self.pit[interestName]
         ntable = []
         for array in table:
             if array[1] == faceName and self.getFreshness(dataPacket) > array[2]:
                 logging.debug(self.name + ": data packet " + dataPacket.name + " forwarded to " + array[0])
                 self.sendOut(dataPacket, array[0])
             else:
                 ntable.append(array)
         if ntable == []:
             self.pit.pop(interestName)
         else:
             self.pit[interestName] = ntable
     
     print self.name , " pacasting "      
     fu = (float(self.residualPower)/self.totalPower + float(self.residualCacheSize)/self.memorySize + self.getFreshness(dataPacket))/3
     probability = int(fu * 100)
     rand = random.randint(0 , 100)
     print "residualPower/totalPower: " , float(self.residualPower)/self.totalPower , " residualCacheSize/memorySize: " , float(self.residualCacheSize)/self.memorySize , " Freshness: " , self.getFreshness(dataPacket)
     print "fu: " , fu , "probability: " , probability , " rand: " , rand
     if rand < probability:
         self.cacheManagementByFrequency(dataPacket)
예제 #4
0
 def sendOut (self , packet , faceName):             # forward functions use this function
     self.residualPower -= 1
     queue = self.outputFaces[faceName]
     queue.append(packet)
     self.facesFlags[faceName] = True
     logging.debug( self.name+ ": packet "+ packet.name+ " sent out to "+ faceName)
     if packet.__class__ is InterestPacket:
         self.numberOfInterestPacket+=1
     else:
         self.numberOfDataPacket+=1
예제 #5
0
 def wrapper_debug(*args, **kwargs):
     args_repr = [repr(a) for a in args]  # 1
     #kwargs_repr = [f"{k}={v!r}" for k, v in kwargs.items()]  # 2
     #signature = ", ".join(args_repr + kwargs_repr)           # 3
     #print(f"Calling {func.__name__}({signature})")
     logging.debug("====>calling function " + func.__name__)
     # print ("====>calling function " + func.__name__ )
     value = func(*args, **kwargs)
     logging.debug("   ")
     # print ( "   ")
     #print(f"{func.__name__!r} returned {value!r}")           # 4
     return value
예제 #6
0
 def forwardDataPacketNoCache(self, dataPacket, faceName):
     self.residualPower -= 1
     interestName = dataPacket.name
     if self.pit.__contains__(interestName):
         table = self.pit[interestName]
         ntable = []
         for array in table:
             if array[1] == faceName and self.getFreshness(dataPacket) > array[2]:
                 logging.debug(self.name + ": data packet " + dataPacket.name + " forwarded to " + array[0])
                 self.sendOut(dataPacket, array[0])
             else:
                 ntable.append(array)
         if ntable == []:
             self.pit.pop(interestName)
         else:
             self.pit[interestName] = ntable
예제 #7
0
    def processIncomingPackets(self):

        for faceName, face in self.inputFaces.items():
            self.facesFlags[faceName] = False
        for faceName, face in self.inputFaces.items():
            #logging.debug(self.name + " -- " + faceName + "  " + str(face))
            packet = face.popleft()
            if packet != "0":
                self.inputLoad += 1
                if packet.__class__ is DataPacket:  # it is data
                    if packet.name == self.interestName:
                        logging.debug(
                            self.name +
                            " : my data Recieved ****")  # it must be changed
                        now = time.timeInSeconds
                        self.totalWaitingTime += now - self.lastRequestTimeInsec
                        self.numberOfresponses += 1
                    else:
                        self.forwardDataPacket(packet, faceName)
                else:
                    self.forwardInterestPacket(packet, faceName)
예제 #8
0
    def forwardInterestPacket(self, interestPacket, faceName):
        self.residualPower -= 1
        interestName = interestPacket.name
        outgoingFaceName = self.fib[interestName]
        if self.cs.__contains__(interestName) and interestPacket.freshness < self.getFreshness(self.cs[interestName]['packet']):
            logging.debug(self.name + ": sending interest packet " + interestPacket.name + " back from cs (CACHE HIT!)")
            print (self.name + ": sending interest packet " + interestPacket.name + " " + str(self.getFreshness(self.cs[interestName]['packet'])) + " back from cs (CACHE HIT!)")
            self.sendOut(self.cs[interestName]['packet'], faceName)
            self.cs[interestName]['lastAccess'] = time.timeInSeconds
            self.cs[interestName]['hitRatio'] += 1
            self.cacheHit += 1

        # we must forward interest
        elif self.pit.__contains__(interestName):
            containsEntryFlag = False
            table = self.pit[interestName]
            self.cacheMiss += 1
            for array in table:
                if array[0] == faceName and array[1] == outgoingFaceName:
                    containsEntryFlag = True
            if not containsEntryFlag:
                table.append([faceName, outgoingFaceName, interestPacket.freshness])
                # it is forward
                logging.debug(self.name + ": forward interest packet " + interestPacket.name + " to " + outgoingFaceName)
                print (self.name + ": forward interest packet " + interestPacket.name + " to " + outgoingFaceName + " pit contains")
                self.sendOut(interestPacket, outgoingFaceName)
        else:
            # it is forward
            self.cacheMiss += 1
            logging.debug(self.name + ": forward interest packet " + interestPacket.name + " to " + outgoingFaceName)
            print (
                        self.name + ": forward interest packet " + interestPacket.name + " to " + outgoingFaceName + " pit doesn't contain")
            self.sendOut(interestPacket, outgoingFaceName)
            self.pit[interestName] = []
            self.pit[interestName].append([faceName, outgoingFaceName, interestPacket.freshness])
예제 #9
0
 def forwardDataPacketPathCache(self, dataPacket, faceName):
     self.residualPower -= 1
     interestName = dataPacket.name
     if self.pit.__contains__(interestName):
         table = self.pit[interestName]
         ntable = []
         for array in table:
             if array[1] == faceName and self.getFreshness(dataPacket) > array[2]:
                 logging.debug(self.name + ": data packet " + dataPacket.name + " forwarded to " + array[0])
                 self.sendOut(dataPacket, array[0])
             else:
                 ntable.append(array)
         if ntable == []:
             self.pit.pop(interestName)
         else:
             self.pit[interestName] = ntable
             
     fu = float(self.residualCacheSize)/dataPacket.pathCache
     probability = int ( fu * 100)
     rand = random.randint(0, 100)
     print "fu: " , fu , " probability: " , probability , " rand: " , rand , " dataPacket.pathCache: " , dataPacket.pathCache
     if rand < probability:
         self.cacheManagementByFrequency(dataPacket)
예제 #10
0
    def requestGenerator(self):  # this function needs to get time of the day!
        lr = self.lastRequestTime
        if self.lastRequestTime == None:
            rand = random.randint(5, 50)

            if timeComparator("00:00:" + str(rand)) == -1:
                npacket = InterestPacket(self.interestName, 0.5,
                                         time.timeInSeconds)
                self.sendRequest(npacket)
                self.lastRequestTime = getTime()
                self.lastRequestTimeInsec = time.timeInSeconds
                rand = random.randint(20, 60)
                self.nextRequestTime = addTime(rand, getTime(), 1)
        else:
            if timeComparator(self.nextRequestTime) == -1:
                npacket = InterestPacket(self.interestName, 0.5,
                                         time.timeInSeconds)
                self.sendRequest(npacket)
                self.lastRequestTime = getTime()
                self.lastRequestTimeInsec = time.timeInSeconds
                rand = random.randint(20, 60)
                self.nextRequestTime = addTime(rand, getTime(), 1)
        if lr != self.lastRequestTime:
            logging.debug(self.name + "  " + self.lastRequestTime)
예제 #11
0
    def simulationLoop(self):


        while True:
            logging.debug("------------------ countLoop: " + str(self.countLoop) + "-------------------------------" )
            print ("------------------ countLoop: " + str(self.countLoop) + "-------------------------------" )
            self.countLoop+=1
            plusSimulationTime()
            for name , node in self.allNodes.items():
                node.processIncomingPacketsPathCache()

            for name , node in self.allNodes.items():
                #print (node.__class__)
                if node.__class__ is Producer:
                    node.updateState()
                else:
                    node.requestGenerator()

            for name , node in self.allNodes.items():
                node.processOutgoingpackets()

            # for name , node in self.allNodes.items():
            #     print name ," residual power: ", node.residualPower

            terminate = False
            for name , node in self.allNodes.items():
                if node.residualPower <=0:
                    terminate = True
            if terminate :
                break

            if self.countLoop > 1000:
                break



        print "---------------------------------"
        print "final loop count :" , self.countLoop
        print "------Power------"
        sum = 0
        for name, node in self.allNodes.items():
            sum += node.residualPower
        mid = sum/self.allNodes.__len__()

        print "mid residual power :" , mid

        print "------Latancy------"

        for name , node in self.consumers.items():
            latancy = node.totalWaitingTime / node.numberOfresponses
            self.midLatency += latancy
            print name , " avg latancy: " , latancy
        self.midLatency/= self.consumers.__len__()
        print "mid latancy: " , self.midLatency

        print "------Cache Hit------"

        for name , node in self.allNodes.items():
            if node.cacheHit + node.cacheMiss != 0:
                cacheHit = float(node.cacheHit)/(node.cacheHit + node.cacheMiss)
            else:
                cacheHit = 0
            print name , " : cacheHit:" , node.cacheHit ," cacheMiss: ", node.cacheMiss ," Real cache hit: " , cacheHit
            self.totalCache +=node.cacheHit + node.cacheMiss
            self.totalCacheHit += node.cacheHit

        print "total Cache hit = " , (float(self.totalCacheHit) / self.totalCache)/ self.allNodes.__len__()

        print "------#Packets------"

        for name , node in self.allNodes.items():
            print name ," #interest: " , node.numberOfInterestPacket , "  #dataPacket: " , node.numberOfDataPacket
            self.totalPackets+= node.numberOfDataPacket + node.numberOfInterestPacket

        print "total #packets: " , self.totalPackets

        for name, node in self.allNodes.items():
            if node.inputLoad > self.maxLoad:
                self.maxLoad = node.inputLoad
            self.avgLoad+= node.inputLoad

        print "max Input load: " , self.maxLoad , "avg Input load: " , self.avgLoad/self.allNodes.__len__()