示例#1
0
 def get_SFC_relialibility(self, VNF_list):
     SFCReliability = 1
     for i in range(len(VNF_list)):
         vnfid = VNF_list[i]
         # VNFInstance = VNF(vnfid,
         #                   vnfListSingelton.dict_VNFListType[vnfid],
         #                   vnfListSingelton.dict_VNFRequestCPU[vnfid],
         #                   vnfListSingelton.dict_VNFRequestMemory[vnfid],
         #                   vnfListSingelton.dict_locatedVMID[vnfid],
         #                   vnfListSingelton.dict_locatedSFCIDList[vnfid],
         #                   vnfListSingelton.dict_numbersOnSFCList[vnfid],
         #                   vnfListSingelton.dict_VNFReliability[vnfid])
         # print("VNF的可靠性为: %f" %VNFInstance.getVNFRliability(vnfid))
         # SFCReliability *= VNFInstance.getVNFRliability(vnfid)
         VNFInstance = VNF(vnfid, vnfListSingelton.dict_VNFListType[vnfid],
                           vnfListSingelton.dict_VNFRequestCPU[vnfid],
                           vnfListSingelton.dict_VNFRequestMemory[vnfid],
                           vnfListSingelton.dict_locatedVMID[vnfid],
                           vnfListSingelton.dict_locatedSFCIDList[vnfid],
                           vnfListSingelton.dict_numbersOnSFCList[vnfid],
                           vnfListSingelton.dict_VNFReliability[vnfid])
         # 读取所在的VM
         vmid = VNFInstance.get_VM_id(vnfid)
         vmInstance = VM(vmid, vmListSingelton.dict_VMRequestCPU[vmid],
                         vmListSingelton.dict_VMRequestMemory[vmid],
                         vmListSingelton.dict_VMLocatedPhysicalnode[vmid],
                         vmListSingelton.dict_VMReliability[vmid])
         nodeid = vmInstance.get_physicalNode_id(vmid)
         SFCReliability *= nodeListSingelton.dict_provided_reliablity[
             nodeid]
     print("SFC的可靠性为:%f" % SFCReliability)
     return SFCReliability
示例#2
0
    def delayBetweenVNFs(self, VNFIdLeft, VNFRight):

        delay = 1000000
        VNFInstanceLeft = VNF(
            VNFIdLeft, vnfListSingelton.dict_VNFListType[VNFIdLeft],
            vnfListSingelton.dict_VNFRequestCPU[VNFIdLeft],
            vnfListSingelton.dict_VNFRequestMemory[VNFIdLeft],
            vnfListSingelton.dict_locatedVMID[VNFIdLeft],
            vnfListSingelton.dict_locatedSFCIDList[VNFIdLeft],
            vnfListSingelton.dict_numbersOnSFCList[VNFIdLeft],
            vnfListSingelton.dict_VNFReliability[VNFIdLeft])
        VNFInstanceRight = VNF(
            VNFRight, vnfListSingelton.dict_VNFListType[VNFRight],
            vnfListSingelton.dict_VNFRequestCPU[VNFRight],
            vnfListSingelton.dict_VNFRequestMemory[VNFRight],
            vnfListSingelton.dict_locatedVMID[VNFRight],
            vnfListSingelton.dict_locatedSFCIDList[VNFRight],
            vnfListSingelton.dict_numbersOnSFCList[VNFRight],
            vnfListSingelton.dict_VNFReliability[VNFRight])
        vmIdleft = VNFInstanceLeft.get_VM_id(VNFIdLeft)
        vmIdRight = VNFInstanceRight.get_VM_id(VNFRight)
        vmInstanceleft = VM(
            vmIdleft, vmListSingelton.dict_VMRequestCPU[vmIdleft],
            vmListSingelton.dict_VMRequestMemory[vmIdleft],
            vmListSingelton.dict_VMLocatedPhysicalnode[vmIdleft],
            vmListSingelton.dict_VMReliability[vmIdleft])
        vmInstanceright = VM(
            vmIdRight, vmListSingelton.dict_VMRequestCPU[vmIdRight],
            vmListSingelton.dict_VMRequestMemory[vmIdRight],
            vmListSingelton.dict_VMLocatedPhysicalnode[vmIdRight],
            vmListSingelton.dict_VMReliability[vmIdRight])
        LeftphysicalNodeId = vmInstanceleft.get_physicalNode_id(vmIdleft)
        RightphysicalNodeId = vmInstanceright.get_physicalNode_id(vmIdRight)
        # 由拓扑结构获取到左右两个物理节点之间的时延
        for i in range(len(leftPhysicalNodelist)):
            if LeftphysicalNodeId == leftPhysicalNodelist[i]:
                if RightphysicalNodeId == rightPhysicalNodelist[i]:
                    delay = delaylist[i]
            elif LeftphysicalNodeId == rightPhysicalNodelist[i]:
                if RightphysicalNodeId == leftPhysicalNodelist[i]:
                    delay = delaylist[i]
        return delay
示例#3
0
    def get_SFC_relialibility1(self, vnflist, updatevnfid, nodeid_in):
        print("////////计算SFC可靠性的新方法")
        print("updatevnfid = %d" % updatevnfid)
        print("nodeid = %d" % nodeid_in)
        SFCReliability = 1
        for i in range(len(vnflist)):
            vnfid = vnflist[i]
            print("vnfid = %d" % vnfid)
            if vnfid == updatevnfid:
                print("vnfid == updatevnfid")
                nodeid = nodeid_in
                SFCReliability *= nodeListSingelton.dict_provided_reliablity[
                    nodeid_in]
                print("nodeid = %d" % nodeid_in)
                print(
                    "nodeListSingelton.dict_provided_reliablity[nodeid] = %f" %
                    nodeListSingelton.dict_provided_reliablity[nodeid_in])

            else:
                VNFInstance = VNF(
                    vnfid, vnfListSingelton.dict_VNFListType[vnfid],
                    vnfListSingelton.dict_VNFRequestCPU[vnfid],
                    vnfListSingelton.dict_VNFRequestMemory[vnfid],
                    vnfListSingelton.dict_locatedVMID[vnfid],
                    vnfListSingelton.dict_locatedSFCIDList[vnfid],
                    vnfListSingelton.dict_numbersOnSFCList[vnfid],
                    vnfListSingelton.dict_VNFReliability[vnfid])
                # 读取所在的VM
                vmid = VNFInstance.get_VM_id(vnfid)
                vmInstance = VM(
                    vmid, vmListSingelton.dict_VMRequestCPU[vmid],
                    vmListSingelton.dict_VMRequestMemory[vmid],
                    vmListSingelton.dict_VMLocatedPhysicalnode[vmid],
                    vmListSingelton.dict_VMReliability[vmid])
                nodeid = vmInstance.get_physicalNode_id(vmid)
                SFCReliability *= nodeListSingelton.dict_provided_reliablity[
                    nodeid]
                print("nodeid = %d" % nodeid)
                print("nodeListSingelton.dict_provided_reliablity[nodeid] %f" %
                      nodeListSingelton.dict_provided_reliablity[nodeid])
        print("SFC的新的可靠性为:%f" % SFCReliability)
        return SFCReliability
 def getMigrationTime(self, migrated_SFC_id, needMigratedVNFList,
                      destinationPhysicalNodeList):
     # 存放此SFC上需要迁移的VNF们的迁移所需要的时间
     VNFsMigrationTimeList = []
     # 由SFC的ID得到此条SFC上所有的VNF
     SFCInstance = SFC(
         migrated_SFC_id, sfcListSingleton.dict_maxDelay[migrated_SFC_id],
         sfcListSingleton.dict_minReliability[migrated_SFC_id],
         sfcListSingleton.dict_VNFList[migrated_SFC_id],
         sfcListSingleton.dict_createdtime[migrated_SFC_id])
     VNFList = SFCInstance.getVNFList
     total_time = 0
     # 寻找此SFC上应当进行迁移的VNF(s),根据不同的迁移情形分别获取,在本项目中的其他位置实现此方法
     # 假设此时在此处已经获取到了需要迁移的VNF,即为needMigratedVNFList,此列表作为输入参数由外部传入
     # 系统开始运行之前随机给每个VNF赋一个迁移时间的系数,当迁移发生时,此系数乘以源至目的地的距离,作为相对迁移时间。
     # 也就是说还需要一个迁移目的地列表,此处同样作为输入参数传入,源到目的地之间的距离直接用拓扑中的时延来代替
     for i in range(len(needMigratedVNFList)):
         vnfid = needMigratedVNFList[i]
         VNFInstance = VNF(vnfid, vnfListSingelton.dict_VNFListType[vnfid],
                           vnfListSingelton.dict_VNFRequestCPU[vnfid],
                           vnfListSingelton.dict_VNFRequestMemory[vnfid],
                           vnfListSingelton.dict_locatedVMID[vnfid],
                           vnfListSingelton.dict_locatedSFCIDList[vnfid],
                           vnfListSingelton.dict_numbersOnSFCList[vnfid],
                           vnfListSingelton.dict_VNFReliability[vnfid])
         VMId = VNFInstance.get_VM_id(needMigratedVNFList[i])
         VMInstance = VM(VMId, vmListSingelton.dict_VMRequestCPU[VMId],
                         vmListSingelton.dict_VMRequestMemory[VMId],
                         vmListSingelton.dict_VMLocatedPhysicalnode[VMId],
                         vmListSingelton.dict_VMReliability[VMId])
         physicalNodeId = VMInstance.get_physicalNode_id(VMId)
         # physicalNodeId与destinationPhysicalNodeList[i]两个物理节点之间的时延
         delayBetweenSandDNodes = SFCInstance.getDelayBetweenPhysicalNode(
             physicalNodeId, destinationPhysicalNodeList[i])
         # 计算出此VNF迁移所花费的时间,并将其存放进VNFsMigrationTimeList中的第i个位置
         VNFsMigrationTimeList.append(
             delayBetweenSandDNodes *
             VNFInstance.migration_time_coefficient)
         total_time += delayBetweenSandDNodes * VNFInstance.migration_time_coefficient
     return total_time
    def getDelayIncreationOfSFC(self, migrated_SFC_id, SFCDelayBeforMigration):
        SFCInstance = SFC(
            migrated_SFC_id, sfcListSingleton.dict_maxDelay[migrated_SFC_id],
            sfcListSingleton.dict_minReliability[migrated_SFC_id],
            sfcListSingleton.dict_VNFList[migrated_SFC_id],
            sfcListSingleton.dict_createdtime[migrated_SFC_id])
        VNFList = SFCInstance.getVNFList()
        print(VNFList)
        nodeidlist = []
        i = 0
        for vnfid in VNFList:
            if vnfid == 15:
                VNFinstance = VNF(
                    vnfid, vnfListSingelton.dict_VNFListType[vnfid],
                    vnfListSingelton.dict_VNFRequestCPU[vnfid],
                    vnfListSingelton.dict_VNFRequestMemory[vnfid],
                    vnfListSingelton.dict_locatedVMID[vnfid],
                    vnfListSingelton.dict_locatedSFCIDList[vnfid],
                    vnfListSingelton.dict_numbersOnSFCList[vnfid],
                    vnfListSingelton.dict_VNFReliability[vnfid])
                vmid = VNFinstance.get_VM_id(vnfid)
                VMinstance = VM(
                    vmid, vmListSingelton.dict_VMRequestCPU[vmid],
                    vmListSingelton.dict_VMRequestMemory[vmid],
                    vmListSingelton.dict_VMLocatedPhysicalnode[vmid],
                    vmListSingelton.dict_VMReliability[vmid])
                nodeid = VMinstance.get_physicalNode_id(vmid)

                print("before node id = %d" % nodeid)

                VMinstance.setPhysicalNodeId(16)

        SFCDelayAfterMigration = SFCInstance.get_SFC_delay(VNFList)

        print("SFCDelayAfterMigration = %f" % SFCDelayAfterMigration)
        print("SFCDelayBeforMigration = %f" % SFCDelayBeforMigration)
        print(SFCDelayAfterMigration - SFCDelayBeforMigration)
        return SFCDelayAfterMigration - SFCDelayBeforMigration
示例#6
0
 def find_a_SFC(self, MaxSFCDelay, MinSFCReliablity, VNFTyprList,
                VNFRequestCPU, VNFRequestMemory):
     print("发现一条SFC方法")
     # 存储根据VNF类型和所需CPU、内存资源条件筛选出来的VNFs
     VNFList = []
     for i in range(len(VNFTyprList)):
         aVNFInstance = VNF()
         vmInstance = VM()
         physicalInstace = PhysicalNode()
         vmId = aVNFInstance.get_VM_id(self.getAVNFByType())
         physicalNodeId = vmInstance.get_physicalNode_id(vmId)
         if (physicalInstace.getAvailable_CPU(physicalNodeId) >
                 VNFRequestCPU
                 and physicalInstace.getAvailable_Memory(physicalNodeId) >
                 VNFRequestMemory):
             # 将此VNF的id加入到list中,作为此SFC中的一环
             VNFList.append(self.getAVNFByType())
     # 所有需要的VNF都找到了,一条SFC就挑选出来了
     sfcid = sfcListSingleton.getSFCCount() + 1
     sfcInstance = SFC(sfcid, MaxSFCDelay, MinSFCReliablity, VNFList,
                       datetime.datetime.now())
     # 接下来判断此SFC是否满足时延和可靠性的约束
     if (sfcInstance.get_SFC_delay(VNFList) < MaxSFCDelay):
         if (sfcInstance.get_SFC_relialibility(VNFList) > MinSFCReliablity
                 and sfcInstance.SFC_id
                 not in sfcListSingleton.SFCList):  # 此SFC没有被选择过
             sfcInstance.setDelay(sfcInstance.get_SFC_delay(VNFList))
             # SFC满足要求,返回值是SFC实例
             sfcListSingleton.addSFCCount()
             sfcInstance.SFC_id = sfcListSingleton.getSFCCount() + 1
             sfcListSingleton.addSFC(sfcListSingleton.getSFCCount() + 1)
             return sfcInstance
         else:
             print("此SFC实例的可靠性不满足要求")
     else:
         print("此SFC实例的时延不满足要求")
示例#7
0
    def find_a_SFC1(self, MaxSFCDelay, MinSFCReliablity, VNFTyprList,
                    VNFRequestCPU, VNFRequestMemory):
        print("发现一条SFC方法开始")
        # 存储根据VNF类型和所需CPU、内存资源条件筛选出来的VNFs
        VNFList = []
        for i in range(len(VNFTyprList)):
            vnftype = VNFTyprList[i]
            vnfid = self.getAVNFByType(vnftype)
            if vnfid != None:
                aVNFInstance = VNF(
                    vnfid, vnfListSingelton.dict_VNFListType[vnfid],
                    vnfListSingelton.dict_VNFRequestCPU[vnfid],
                    vnfListSingelton.dict_VNFRequestMemory[vnfid],
                    vnfListSingelton.dict_locatedVMID[vnfid],
                    vnfListSingelton.dict_locatedSFCIDList[vnfid],
                    vnfListSingelton.dict_numbersOnSFCList[vnfid],
                    vnfListSingelton.dict_VNFReliability[vnfid])
                vmid = aVNFInstance.get_VM_id(vnfid)
                vmInstance = VM(
                    vmid, vmListSingelton.dict_VMRequestCPU[vmid],
                    vmListSingelton.dict_VMRequestMemory[vmid],
                    vmListSingelton.dict_VMLocatedPhysicalnode[vmid],
                    vmListSingelton.dict_VMReliability[vmid])
                nodeid = vmInstance.get_physicalNode_id(vmid)
                physicalInstace = PhysicalNode(
                    nodeid, nodeListSingelton.dict_capacity_CPU[nodeid],
                    nodeListSingelton.dict_capacity_Memory[nodeid],
                    nodeListSingelton.dict_provided_reliablity[nodeid])
                if (physicalInstace.getAvailable_CPU(nodeid) > VNFRequestCPU[i]
                        and physicalInstace.getAvailable_Memory(nodeid) >
                        VNFRequestMemory[i]):
                    # 将此VNF的id加入到list中,作为此SFC中的一环
                    VNFList.append(vnfid)
            else:
                print("VNFid = none")
        # 所有需要的VNF都找到了,一条SFC就挑选出来了
        sfcid = self.SFCCount + 1
        sfcInstance = SFC(sfcid, MaxSFCDelay, MinSFCReliablity, VNFList,
                          datetime.datetime.now())
        # 接下来判断此SFC是否满足时延和可靠性的约束
        print("SFC的时延与可靠性分别为:")
        delay = sfcInstance.get_SFC_delay(VNFList)
        print("SFC的时延为:%f" % delay)
        reli = sfcInstance.get_SFC_relialibility(VNFList)
        print("SFC的可靠性为:%f" % reli)

        if (sfcInstance.get_SFC_delay(VNFList) < MaxSFCDelay):
            if (sfcInstance.get_SFC_relialibility(VNFList) > MinSFCReliablity):
                # and sfcInstance.SFC_id not in sfcListSingleton.getSFCList()):  # 此SFC没有被选择过
                sfcInstance.setDelay(sfcInstance.get_SFC_delay(VNFList))
                # SFC满足要求,返回值是SFC实例
                sfcListSingleton.addSFCCount()
                sfcInstance.SFC_id = sfcListSingleton.getSFCCount() + 1
                sfcListSingleton.addSFC(sfcListSingleton.getSFCCount() + 1)
                print("SFC基本数据:-------------------------------------")
                print("基本数据--SFC的ID为: %d" % sfcInstance.getSFCId())
                print("基本数据--SFC中的vnflist为:")
                print(VNFList)
                print("基本数据--SFC的时延为: %f" % delay)
                print("基本数据--SFC的可靠性为: %f " % reli)

                with open('D:/pycharm workspace/GraduationProject/res/res.csv',
                          'a+',
                          newline='') as csvfile:
                    writer = csv.writer(csvfile)
                    # 先写入columns_name
                    writer.writerow(["VNFlist", "delay", "reliability"])
                    data = [[[VNFList], delay, reli]]
                    print(data)
                    # 写入多行用writerows
                    writer.writerows(data)
                print("发现一条SFC方法结束")
                return sfcInstance
            else:
                print("此SFC实例的可靠性不满足要求")
        else:
            print("此SFC实例的时延不满足要求")