diff --git a/src/lte/model/lte-enb-rrc.cc b/src/lte/model/lte-enb-rrc.cc index b353793d9..3d3edfc90 100644 --- a/src/lte/model/lte-enb-rrc.cc +++ b/src/lte/model/lte-enb-rrc.cc @@ -2635,14 +2635,23 @@ void LteEnbRrc::DoRecvIdealUeContextRemoveRequest (uint16_t rnti) { NS_LOG_FUNCTION (this << rnti); - // TODO: remove after merge of ho_failure branch - // check if the RNTI to be removed is not stale - if (HasUeManager (rnti)) + Ptr ueManager = GetUeManager (rnti); + + if (ueManager->GetState () == UeManager::HANDOVER_JOINING) { - GetUeManager (rnti)->RecvIdealUeContextRemoveRequest (rnti); - // delete the UE context at the eNB - RemoveUe (rnti); + /** + * During the HO, when the RACH failure due to the maximum number of + * re-attempts is reached the UE request the target eNB to deletes its + * context. Upon which, the target eNB sends handover preparation + * failure to the source eNB. + */ + EpcX2Sap::HandoverPreparationFailureParams msg = ueManager->BuildHoPrepFailMsg (); + m_x2SapProvider->SendHandoverPreparationFailure (msg); } + + GetUeManager (rnti)->RecvIdealUeContextRemoveRequest (rnti); + //delete the UE context at the eNB + RemoveUe (rnti); } void diff --git a/src/lte/model/lte-ue-rrc.cc b/src/lte/model/lte-ue-rrc.cc index 53561f5fd..943ddb1ed 100644 --- a/src/lte/model/lte-ue-rrc.cc +++ b/src/lte/model/lte-ue-rrc.cc @@ -731,6 +731,16 @@ LteUeRrc::DoNotifyRandomAccessFailed () * send an RRC Connection Re-establishment and switch to * CONNECTED_REESTABLISHING state. */ + if (!m_leaveConnectedMode) + { + m_leaveConnectedMode = true; + SwitchToState (CONNECTED_PHY_PROBLEM); + m_rrcSapUser->SendIdealUeContextRemoveRequest (m_rnti); + //we should have called NotifyConnectionFailed + //but that method would immediately ask you UE to + //connect rather than doing cell selection again. + m_asSapUser->NotifyConnectionReleased (); + } } break;