public void AdmitNewCallToOngoingSession(ISession session, ICall call, IMobileTerminal mobileTerminal)
        {
            if (session == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(session)} is invalid");
            }

            if (call == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(call)} is invalid");
            }

            if (mobileTerminal == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(mobileTerminal)} is invalid");
            }

            TakeNetworkResources(call.Service.ComputeRequiredNetworkResources());

            session.AddToActiveCalls(call);

            var state = mobileTerminal.UpdateMobileTerminalStateWhenAdmitingNewCallToOngoingSession(session.ActiveCalls);

            session.AddToSessionSequence(state);
        }
        public bool CanAdmitNewCallToOngoingSession(ISession session, ICall call, IMobileTerminal mobileTerminal)
        {
            if (session == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(session)} is invalid");
            }

            if (call == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(call)} is invalid");
            }

            if (mobileTerminal == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(mobileTerminal)} is invalid");
            }

            if (!this.Services.Contains(call.Service))
            {
                return(false);
            }

            var requiredNetworkResources = call.Service.ComputeRequiredNetworkResources();

            return(requiredNetworkResources <= AvailableNetworkResources());
        }
        private void StartNewSessionAndAdmitCall(CallStartedEvent evt, IMobileTerminal mobileTerminal, IRat rat)
        {
            var session = new Session(rat.RatId, evt.Time);

            mobileTerminal.SetSessionId(session.SessionId);

            rat.TakeNetworkResources(evt.Call.Service.ComputeRequiredNetworkResources());

            session.AddToActiveCalls(evt.Call);

            var state = mobileTerminal.UpdateMobileTerminalState(session);

            session.AddToSessionSequence(state);

            rat.AddSession(session);
        }
        private void RunNonPredictiveAlgorithm(CallStartedEvent evt, IMobileTerminal mobileTerminal)
        {
            var rats = HetNet.Instance.Rats
                       .Where(x => x.Services.Contains(evt.Call.Service))
                       .OrderBy(x => x.Services.Count)
                       .ToList();

            foreach (var rat in rats)
            {
                if (evt.Call.Service.ComputeRequiredNetworkResources() <= rat.AvailableNetworkResources())
                {
                    StartNewSessionAndAdmitCall(evt, mobileTerminal, rat);
                    return;
                }
            }
            HetNet.Instance.BlockedCalls++;
        }
        private void RunPredictiveAlgorithm(CallStartedEvent evt, IMobileTerminal mobileTerminal)
        {
            //var history = CsvUtils._Instance.Read<CallLogMap,CallLog>($"{Environment.CurrentDirectory}/calllogs.csv").ToList();

            var nextState = evt.Call.Service.GetState();

            if (HetNet.Instance.CallerHistory.Any())
            {
                var group = HetNet.Instance.CallerHistory
                            .Where(x => x.UserId == mobileTerminal.MobileTerminalId)
                            .Select(x => x.SessionSequence)
                            .Select(x => x.ToList().Select(x => (MobileTerminalState)(int.Parse(x.ToString()))))
                            .Select(x => x.Skip(1).Take(2))
                            .Where(x => x.StartsWith(new List <MobileTerminalState> {
                    evt.Call.Service.GetState()
                }))
                            .SelectMany(x => x.Skip(1))
                            .Where(x => x != MobileTerminalState.Idle)
                            .GroupBy(x => x);

                //If group is empty it means prediction has failed
                if (!group.Any())
                {
                    HetNet.Instance.FailedPredictions++;
                }
                else
                {
                    //continue to compute frequency table
                    var prediction = default(IGrouping <MobileTerminalState, MobileTerminalState>);
                    var max        = 0;

                    //If There are ties it takes the last item in the history : Fix this, what decision is made in that case

                    //group.Dump();

                    foreach (var grp in group)
                    {
                        if (grp.Count() > max)
                        {
                            prediction = grp;
                            max        = prediction.Count();
                        }
                        //Console.WriteLine( $"next state is {grp.Key}, Frequency: {grp.Count()}");
                    }
                    nextState = prediction.Key;
                }
            }

            var services = new List <Service> {
                evt.Call.Service
            };

            foreach (var service in nextState.SupportedServices())
            {
                if (!services.Contains(service))
                {
                    services.Add(service);
                }
            }

            var rats = HetNet.Instance.Rats
                       .Where(x => x.Services.ToHashSet().IsSupersetOf(services))
                       .OrderBy(x => x.Services.Count)
                       .ToList();

            //This scheme reserves bandwidth in advance, I considered all the services
            var requiredNetworkResources = 0;

            foreach (var service in services)
            {
                requiredNetworkResources += service.ComputeRequiredNetworkResources();
            }

            foreach (var rat in rats)
            {
                if (requiredNetworkResources <= rat.AvailableNetworkResources())
                {
                    StartNewSessionAndAdmitCall(evt, mobileTerminal, rat);
                    if (evt.Call.Service.GetState() != nextState)
                    {
                        //Successful Prediction means 1. predicted state was not idle 2. call ends up being admited as predicted
                        HetNet.Instance.SuccessfulPredictions++;
                        //Log.Information("----- Successful prediction");
                    }
                    return;
                }
            }
            //All Possible Rats Cannot Admit Call i.e [call in its predicted state]
            HetNet.Instance.BlockedUsingPredictiveScheme++;

            //Try just accommodating the incoming call without predicting before blocking it
            RunNonPredictiveAlgorithm(evt, mobileTerminal);
        }
Ejemplo n.º 6
0
        public void Handover(ICall call, ISession session, IMobileTerminal mobileTerminal, IRat source)
        {
            if (call == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(call)} is invalid");
            }

            if (session == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(session)} is invalid");
            }

            if (mobileTerminal == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(mobileTerminal)} is invalid");
            }

            if (source == null)
            {
                throw new VerticalHandoverPredictionException($"{nameof(source)} is invalid");
            }

            var callsToHandedOverToTargetRat = session.ActiveCalls.Select(x => x.Service).ToList();

            callsToHandedOverToTargetRat.Add(call.Service);

            var rats = Rats
                       .Where(x => x.RatId != session.RatId &&
                              x.Services.ToHashSet().IsSupersetOf(callsToHandedOverToTargetRat))
                       .OrderBy(x => x.Services.Count())
                       .ToList();

            var requiredNetworkResouces = 0;

            foreach (var service in callsToHandedOverToTargetRat)
            {
                requiredNetworkResouces += service.ComputeRequiredNetworkResources();
            }

            foreach (var target in rats)
            {
                if (requiredNetworkResouces <= target.AvailableNetworkResources())
                {
                    UpdateHandovers(call.Service);

                    source.RealeaseNetworkResources(requiredNetworkResouces - call.Service.ComputeRequiredNetworkResources());
                    source.RemoveSession(session);

                    session.SetRatId(target.RatId);

                    target.TakeNetworkResources(requiredNetworkResouces);

                    session.AddToActiveCalls(call);

                    var state = mobileTerminal.UpdateMobileTerminalState(session);

                    session.AddToSessionSequence(state);

                    target.AddSession(session);

                    return;
                }
            }
            //If call cannot be handed over then the incoming call is blocked
            BlockedCalls++;
        }