private void EndSession(ISession session, DateTime end, IRat rat) { if (session == null) { throw new VerticalHandoverPredictionException($"{nameof(session)} is null"); } if (rat == null) { throw new VerticalHandoverPredictionException($"{nameof(rat)} is null"); } rat.RemoveSession(session); session.SetEndTime(end); SessionId = Guid.Empty; var callLog = new CallLog { UserId = MobileTerminalId, SessionId = session.SessionId, StartTime = session.Start, Duration = session.End.Subtract(session.Start), SessionSequence = String.Join("", session.SessionSequence.Select(x => (int)x)) }; IsActive = false; AddCallLog(callLog); //if (Simulator.NetworkSimulator.Instance.SaveCallLogs) //Utils.CsvUtils._Instance.Write<CallLogMap, CallLog>(callLog, $"{Environment.CurrentDirectory}/calllogs.csv"); HetNet.Instance.TotalSessions++; }
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); }
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++; }