Ejemplo n.º 1
0
        public static void ReleasePower(FogDevice nearestFogDevice, Models.Tuple tuple)
        {
            lock (Lock)
            {
                nearestFogDevice.BusyPower      = nearestFogDevice.BusyPower - (GetRequiredPowerPercentage(tuple, nearestFogDevice));
                nearestFogDevice.AvailablePower = 100 - nearestFogDevice.BusyPower;
                /// PowerUtility.CalcPowerValues

                //var obj = new PowerConsumption()
                //{
                //    PowerValue = nearestFogDevice.BusyPower < 86 ? GetPowerConsumption(86) : GetPowerConsumption(int.Parse(nearestFogDevice.BusyPower.ToString())),
                //    Time = DateTime.Now.ToString("hh:mm:ss.fff tt")
                //};
                Debug.WriteLine("ReleasePower-" + nearestFogDevice.BusyPower);

                var obj = new PowerConsumption()
                {
                    PowerValue = (nearestFogDevice.BusyPower < 1) ? CalcPowerValues("1") : (nearestFogDevice.BusyPower > 100) ? CalcPowerValues("100") : CalcPowerValues(nearestFogDevice.BusyPower.ToString()),
                    Time       = DateTime.Now.ToString("hh:mm:ss.fff tt")
                };

                nearestFogDevice.PowerConsumption.Add(obj);

                //GetRequiredPowerPercentage(tuple, nearestFogDevice)
            }
        }
Ejemplo n.º 2
0
 public static bool ResourceConsumptionChanged(FogDevice fogDev, SFog.Models.Tuple tuple, List <FogDevice> deviceList)
 {
     if (fogDev == null)
     {
         return(false);
     }
     lock (Lock)
     {
         var fogDevice = deviceList.FirstOrDefault(x => x.ID.Equals(fogDev.ID));
         if (fogDevice != null)
         {
             // if (fogDevice.CurrentAllocatedBw <= fogDevice.UpBW &&
             // fogDevice.CurrentAllocatedMips <= fogDevice.MIPS &&
             // fogDevice.CurrentAllocatedRam <= fogDevice.RAM &&
             // fogDevice.CurrentAllocatedSize <= fogDevice.Size)
             if ((fogDevice.MIPS - fogDevice.CurrentAllocatedMips) >= tuple.MIPS &&
                 (fogDevice.RAM - fogDevice.CurrentAllocatedRam) >= tuple.RAM)
             {
                 fogDevice.CurrentAllocatedBw   = fogDevice.CurrentAllocatedBw + tuple.BW;
                 fogDevice.CurrentAllocatedMips = fogDevice.CurrentAllocatedMips + tuple.MIPS;
                 fogDevice.CurrentAllocatedRam  = fogDevice.CurrentAllocatedRam + tuple.RAM;
                 fogDevice.CurrentAllocatedSize = fogDevice.CurrentAllocatedSize + tuple.Size;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 3
0
 public static void ResourceReleaseChanged(FogDevice fogDev, SFog.Models.Tuple tuple, List <FogDevice> deviceList)
 {
     lock (Lock)
     {
         var fogDevice = deviceList.FirstOrDefault(x => x.ID.Equals(fogDev.ID));
         if (fogDevice != null)
         {
             fogDevice.CurrentAllocatedBw   = fogDevice.CurrentAllocatedBw - tuple.BW;
             fogDevice.CurrentAllocatedRam  = fogDevice.CurrentAllocatedRam - tuple.RAM;
             fogDevice.CurrentAllocatedSize = fogDevice.CurrentAllocatedSize - tuple.Size;
             double Mips = fogDevice.CurrentAllocatedMips - tuple.MIPS;
             if (Mips < 0)
             {
                 fogDevice.CurrentAllocatedMips = 0;
             }
             else
             {
                 fogDevice.CurrentAllocatedMips = Mips;
             }
         }
         else
         {
         }
     }
 }
Ejemplo n.º 4
0
 public static bool ResourceConsumptionChangedMRR(FogDevice fogDev, SFog.Models.Tuple tuple)
 {
     if (fogDev == null)
     {
         return(false);
     }
     lock (Lock)
     {
         var fogDevice = fogDev;
         if (fogDevice != null)
         {
             // if (fogDevice.CurrentAllocatedBw <= fogDevice.UpBW &&
             // fogDevice.CurrentAllocatedMips <= fogDevice.MIPS &&
             // fogDevice.CurrentAllocatedRam <= fogDevice.RAM &&
             // fogDevice.CurrentAllocatedSize <= fogDevice.Size)
             if ((fogDevice.MIPS - fogDevice.CurrentAllocatedMips) >= tuple.MIPS &&
                 (fogDevice.RAM - fogDevice.CurrentAllocatedRam) >= tuple.RAM)
             {
                 fogDevice.CurrentAllocatedBw   = fogDevice.CurrentAllocatedBw + tuple.BW;
                 fogDevice.CurrentAllocatedMips = fogDevice.CurrentAllocatedMips + tuple.MIPS;
                 fogDevice.CurrentAllocatedRam  = fogDevice.CurrentAllocatedRam + tuple.RAM;
                 fogDevice.CurrentAllocatedSize = fogDevice.CurrentAllocatedSize + tuple.Size;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 5
0
 public static double getFogCapacity(FogDevice currentFog)
 {
     lock (Lock)
     {
         //Fog 500 MIPS;Processors=2; Job MIPS=75;Job Prcessors=1;
         //return currentFog.NumberOfPes > 1 ? Math.Ceiling((currentFog.MIPS / currentFog.NumberOfPes)) : currentFog.MIPS;
         return(currentFog.MIPS);
     }
 }
Ejemplo n.º 6
0
 public static bool IsFullyConsumed(FogDevice fogDevice)
 {
     if (fogDevice.CurrentAllocatedBw >= fogDevice.UpBW ||
         fogDevice.CurrentAllocatedMips >= fogDevice.MIPS ||
         fogDevice.CurrentAllocatedRam >= fogDevice.RAM ||
         fogDevice.CurrentAllocatedSize >= fogDevice.Size)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
 public static void ResourceReleased(Models.Tuple tuple, FogDevice fogDevice)
 {
     if (fogDevice != null && tuple.IsServerFound == true && tuple.IsReversed == false)
     {
         lock (Lock)
         {
             fogDevice.CurrentAllocatedBw   = fogDevice.CurrentAllocatedBw - tuple.BW;
             fogDevice.CurrentAllocatedMips = fogDevice.CurrentAllocatedMips - tuple.MIPS;
             fogDevice.CurrentAllocatedRam  = fogDevice.CurrentAllocatedRam - tuple.RAM;
             fogDevice.CurrentAllocatedSize = fogDevice.CurrentAllocatedSize - tuple.Size;
         }
     }
 }
Ejemplo n.º 8
0
 public static double Consumption(FogDevice currentFog1, double DelTime, double TimeMax, Models.Tuple tuple)
 {
     try
     {
         lock (Lock)
         {
             var currentFog = FogSimulator.getList().FirstOrDefault(x => x.ID.Equals(currentFog1.ID));
             if (currentFog != null)
             {
                 return(Math.Round((tuple.MIPS * DelTime) / (currentFog.MIPS * TimeMax), 4));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(0);
 }
Ejemplo n.º 9
0
        //public static List<double> testlist = new List<double>();

        public static void ConsumePower(FogDevice nearestFogDevice, Models.Tuple tuple)
        {
            lock (Lock)
            {
                Debug.WriteLine("RequiredPowerByTuple-" + GetRequiredPowerPercentage(tuple, nearestFogDevice));
                Debug.WriteLine("ConsumePower-" + nearestFogDevice.BusyPower);

                nearestFogDevice.BusyPower      = nearestFogDevice.BusyPower + (GetRequiredPowerPercentage(tuple, nearestFogDevice));
                nearestFogDevice.AvailablePower = 100 - nearestFogDevice.BusyPower;
                var obj = new PowerConsumption()
                {
                    PowerValue = (nearestFogDevice.BusyPower > 100) ?
                                 CalcPowerValues("100") : (nearestFogDevice.BusyPower < 1) ? CalcPowerValues("1") : CalcPowerValues(nearestFogDevice.BusyPower.ToString()),
                    Time = DateTime.Now.ToString("hh:mm:ss.fff tt")
                };
                nearestFogDevice.PowerConsumption.Add(obj); //log busy percentage of fog device

                //GetRequiredPowerPercentage(tuple, nearestFogDevice)
            }
        }
Ejemplo n.º 10
0
 public static double CalConsPercentage(FogDevice fogDev, List <FogDevice> deviceList)
 {
     lock (Lock)
     {
         var fogDevice = deviceList.FirstOrDefault(x => x.ID.Equals(fogDev.ID));
         if (fogDevice != null)
         {
             double Consumption = Math.Round((fogDevice.CurrentAllocatedMips / fogDev.MIPS) * 100, 3);
             if (Consumption < 0)
             {
             }
             if (Consumption > 100)
             {
             }
             return(Consumption);
         }
         else
         {
             return(0);
         }
     }
 }
Ejemplo n.º 11
0
 public static void ResourceConsumption(Models.Tuple tuple, FogDevice fogDevice)
 {
     lock (Lock)
     {
         if (fogDevice.CurrentAllocatedBw <= fogDevice.UpBW &&
             fogDevice.CurrentAllocatedMips <= fogDevice.MIPS &&
             fogDevice.CurrentAllocatedRam <= fogDevice.RAM &&
             fogDevice.CurrentAllocatedSize <= fogDevice.Size)
         {
             fogDevice.CurrentAllocatedBw   = fogDevice.CurrentAllocatedBw + tuple.BW;
             fogDevice.CurrentAllocatedMips = fogDevice.CurrentAllocatedMips + tuple.MIPS;
             fogDevice.CurrentAllocatedRam  = fogDevice.CurrentAllocatedRam + tuple.RAM;
             fogDevice.CurrentAllocatedSize = fogDevice.CurrentAllocatedSize + tuple.Size;
         }
         else
         {
             lock (Lock)
             {
                 tuple.IsReversed    = true; //return IsReversed when server is fully occupied.
                 tuple.IsServerFound = true;
             }
         }
     }
 }
Ejemplo n.º 12
0
 public static int GetPercentageOfServerFreePower(FogDevice fogDevice)
 {
     return(int.Parse(Math.Ceiling((decimal)((fogDevice.MIPS - fogDevice.CurrentAllocatedMips) / fogDevice.MIPS) * 100).ToString()));
 }