Esempio n. 1
0
        public static DataCenter GetValidDataCenter(Models.Tuple tuple, List <DataCenter> datacenterList)
        {
            var rnd = new Random();

            double[] arrLatency = { 40, 50, 60 };
            foreach (var item in datacenterList)
            {
                var dis = GeoDistance.CalcDistance(tuple.GeoLocation.getLongitude(), tuple.GeoLocation.getLatitude(),
                                                   item.DatacenterCharacteristics.GeoLocation.getLongitude(), item.DatacenterCharacteristics.GeoLocation.getLatitude(),
                                                   GeoCodeCalcMeasurement.Kilometers);

                lock (item)
                { item.DatacenterCharacteristics.DistanceFromTuple = dis; }
                var link = new Link()
                {
                    Source          = tuple.Name,
                    Destination     = item.Name,
                    SDDistance      = dis,
                    Propagationtime = LinkUtility.CalculateLatency(dis, cooperSpeed, tuple.Size, transmitionRate, arrLatency[rnd.Next(arrLatency.Length)])
                };
                lock (CloudUtility.linksList)
                    CloudUtility.linksList.Add(link);
            }
            return(datacenterList.OrderBy(x => x.DatacenterCharacteristics.DistanceFromTuple).FirstOrDefault());
        }
Esempio n. 2
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)
            }
        }
Esempio n. 3
0
 public static int GetRequiredPowerPercentage(Models.Tuple tuple, FogDevice fogdevice)
 {
     lock (Lock)
     {
         return(int.Parse(Math.Ceiling((decimal)(tuple.MIPS / fogdevice.MIPS) * 100).ToString()));
     }
 }
Esempio n. 4
0
 public static bool SendToCloud(Models.Tuple tuple)
 {
     if (tuple.DataType == FogSimulator.EnumDataType.Bulk.ToString() || tuple.DataType == FogSimulator.EnumDataType.Large.ToString())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
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;
         }
     }
 }
Esempio n. 6
0
 public static void ResourceReleased(Models.Tuple tuple, CloudDevice cloud)
 {
     if (cloud != null && tuple.IsServerFound == true && tuple.IsReversed == false)
     {
         lock (Lock)
         {
             cloud.CurrentAllocatedBw   = cloud.CurrentAllocatedBw - tuple.BW;
             cloud.CurrentAllocatedMips = cloud.CurrentAllocatedMips - tuple.MIPS;
             cloud.CurrentAllocatedRam  = cloud.CurrentAllocatedRam - tuple.RAM;
             cloud.CurrentAllocatedSize = cloud.CurrentAllocatedSize - tuple.Size;
         }
     }
 }
Esempio n. 7
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)
            }
        }
Esempio n. 8
0
        public static CloudDevice CloudComputation(Models.Tuple tuple, CloudDevice cloud)
        {
            var rnd = new Random();

            double[] arrLatency = { 40, 50, 60 };
            var      dis        = GeoDistance.CalcDistance(tuple.GeoLocation.getLongitude(), tuple.GeoLocation.getLatitude(),
                                                           cloud.GeoLocation.getLongitude(), cloud.GeoLocation.getLatitude(), GeoCodeCalcMeasurement.Kilometers);

            lock (Lock)
            { cloud.DistanceFromTuple = dis; }
            lock (Lock)
            {
                link.Source          = tuple.Name;
                link.Destination     = cloud.Name;
                link.SDDistance      = dis;
                link.Propagationtime = LinkUtility.CalculateLatency(dis, cooperSpeed, tuple.Size, transmitionRate, arrLatency[rnd.Next(arrLatency.Length)]);
            }
            CloudRersourceUtility.ResourceConsumption(tuple, cloud);
            return(cloud);
        }
Esempio n. 9
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;
             }
         }
     }
 }
Esempio n. 10
0
 public void UpdateStartupDictionaryForKey(RegistryKey registryKey, bool isChecked)
 {
     if (registryKey == null)
     {
         return;
     }
     String[] valueNames = registryKey.GetValueNames();
     foreach (string valueName in valueNames)
     {
         string filePath = (string)registryKey.GetValue(valueName);
         filePath = Utils.ExtractFilePath(filePath);
         if (filePath == null)
         {
             continue;
         }
         Models.Tuple <string, bool> tuple = new Models.Tuple <string, bool>(valueName, isChecked);
         if (startupItemDictionary.ContainsKey(filePath))
         {
             Models.Tuple <string, bool> val = startupItemDictionary[filePath];
             tuple.y = tuple.y || val.y;
         }
         startupItemDictionary[filePath] = tuple;
     }
 }
Esempio n. 11
0
 public static void ResourceConsumption(Models.Tuple tuple, CloudDevice cloud)
 {
     lock (Lock)
     {
         if (cloud.CurrentAllocatedBw <= cloud.UpBW &&
             cloud.CurrentAllocatedMips <= cloud.MIPS &&
             cloud.CurrentAllocatedRam <= cloud.RAM &&
             cloud.CurrentAllocatedSize <= cloud.Size)
         {
             cloud.CurrentAllocatedBw   = cloud.CurrentAllocatedBw + tuple.BW;
             cloud.CurrentAllocatedMips = cloud.CurrentAllocatedMips + tuple.MIPS;
             cloud.CurrentAllocatedRam  = cloud.CurrentAllocatedRam + tuple.RAM;
             cloud.CurrentAllocatedSize = cloud.CurrentAllocatedSize + tuple.Size;
         }
         else
         {
             lock (Lock)
             {
                 tuple.IsReversed    = true; //return IsReversed when server is fully occupied.
                 tuple.IsServerFound = true;
             }
         }
     }
 }
Esempio n. 12
0
        public static bool CloudSimulationForFog(Models.Tuple tuple, bool fcfs, int _service, List <string> datacenter)
        {//i am here
            if (tuple != null)
            {
                resultList = new ConcurrentBag <Results>();
                Random rnd       = new Random();
                var    result    = new Results();
                var    tupleList = new List <Models.Tuple>();

                #region Cloud

                bool[] bit = { true };
                var    b   = rnd.Next(bit.Length);

                // create service
                var service = ServicesUtility.GetServices()[_service];

                #endregion Cloud
                #region Tuple
                lock (Lock)
                    tupleList.Add(tuple);

                #endregion Tuple

                List <Task> myTaskList = new List <Task>();
                if (fcfs)
                {
                    watch.Start();
                    lock (Lock)
                    {
                        foreach (var item in tupleList)
                        {
                            item.QueueDelay = watch.Elapsed.Milliseconds;
                            CloudUtility.CloudSimForFog(item, service, datacenter);
                        }
                    }
                    watch.Stop();
                }
                else
                {
                    watch.Start();
                    lock (Lock)
                    {
                        foreach (var item in tupleList)
                        {
                            //commented by ali for testing
                            //myTaskList.Add(Task.Factory.StartNew(() =>
                            //{
                            item.QueueDelay = watch.Elapsed.Milliseconds;
                            CloudUtility.CloudSimForFog(item, service, datacenter);
                            //}));
                        }
                    }

                    watch.Stop();
                    Task.WaitAll(myTaskList.ToArray());
                }
                return(true);
            }
            return(false);
        }
 public void UpdateStartupDictionaryForKey(RegistryKey registryKey, bool isChecked)
 {
     if (registryKey == null) return;
     String[] valueNames = registryKey.GetValueNames();
     foreach (string valueName in valueNames) {
         string filePath = (string) registryKey.GetValue(valueName);
         filePath = Utils.ExtractFilePath(filePath);
         if (filePath == null) continue;
         Models.Tuple<string, bool> tuple = new Models.Tuple<string, bool>(valueName, isChecked);
         if (startupItemDictionary.ContainsKey(filePath)) {
             Models.Tuple<string, bool> val = startupItemDictionary[filePath];
             tuple.y = tuple.y || val.y;
         }
         startupItemDictionary[filePath] = tuple;
     }
 }
Esempio n. 14
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);
 }
Esempio n. 15
0
 public static double JobLoad(Models.Tuple tuple, double timeDiff)
 {
     return(tuple.MIPS * timeDiff);
 }
Esempio n. 16
0
        public static void CloudSim(Models.Tuple tuple, Services service, List <string> datacenter)
        {
            Debug.WriteLine("CloudSim" + tuple.ID);

            try
            {
                Stopwatch watch  = new Stopwatch();
                var       result = new Results();
                watch.Start();
                result.InitiatesTime = watch.Elapsed.TotalMilliseconds.ToString();

                var Broker = new CloudBroker()
                {
                    Service        = service,
                    DatacenterList = DataCenterBusiness.GetDataCenterList().Where(a => datacenter.Any(z => a.Name.Contains(z))).ToList(),
                    Tuple          = tuple,
                    // create VM
                    SelectedVM = new VM(service.ID, 1, service.MIPS, service.NumberOfPes, service.RAM, service.BW, service.Size, service.Name,
                                        new CloudletScheduler(), new GeoLocation(47.599949, -122.326815))
                };

                Broker.SelectedDataCenter = BrokerUtility.GetValidDataCenter(Broker.Tuple, Broker.DatacenterList);
                if (Broker.SelectedDataCenter != null)
                {
                    lock (Lock)
                    {
                        result.Link = linksList.Where(x => x.Source == tuple.Name && x.Destination == Broker.SelectedDataCenter.Name && x != null).FirstOrDefault();
                        result.Link.Propagationtime = Math.Round(result.Link.Propagationtime, 3);// + tuple.QueueDelay;
                    }
                    // returns the host by finding the appropirate and then add the vm into the vmlist of host object.
                    Broker.SelectedHost = BrokerUtility.GetHostFromDataCenter(Broker.SelectedDataCenter, Broker.SelectedVM);
                    if (Broker.SelectedHost != null)
                    {
                        result.CloudBroker           = Broker;
                        tuple.InternalProcessingTime = Math.Round(watch.Elapsed.TotalMilliseconds, 3);
                        tuple.IsServed = true;
                        // it will execute on policy 4
                        if (FogSimulator.IsCreateCache)
                        {
                            lock (cloudCahce)
                            {
                                cloudCahce.Add(new CloudCache()
                                {
                                    DataType = tuple.DataType, Cloud = Broker.SelectedDataCenter.Name, InternalProcessingTime = tuple.InternalProcessingTime, link = result.Link
                                });
                            }
                        }
                        ResourceUtility.ReleaseResources(Broker.SelectedHost, Broker.SelectedVM);
                    }
                    else
                    {
                        tuple.IsServerFound = false; tuple.IsServed = false;
                    }

                    result.ElapsedTime = (watch.Elapsed.TotalMilliseconds + result.Link.Propagationtime) - Convert.ToDouble(result.InitiatesTime);
                }
                else
                {
                    tuple.IsReversed = true;
                }
                result.Tuple = tuple;
                watch.Stop();
                // result.InActiveFogDecives = fogList.Where(x => x.IsActive == false).ToList();
                CloudSimulator.resultList.Add(result);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
Esempio n. 17
0
 public static List <FogDevice> GetRequiredFogs(Models.Tuple tuple, IEnumerable <FogDevice> devices)
 {
     return(devices.Where(a => (a.MIPS - a.CurrentAllocatedMips) > tuple.MIPS).ToList());
 }
Esempio n. 18
0
 public static List <FogDevice> GetRequiredFogsMRR(Models.Tuple tuple, IEnumerable <FogDevice> devices)
 {
     //return devices.Where(a => (a.MIPS - a.CurrentAllocatedMips) > tuple.MIPS && a.MaxCapacity > 0).ToList();
     return(devices.Where(a => (a.MIPS - a.CurrentAllocatedMips) > tuple.MIPS && a.RAM - a.CurrentAllocatedRam > tuple.RAM).ToList());
 }