Fixed error when a handover is triggered before the previous one is completed
authorBudiarto Herman <budiarto.herman@magister.fi>
Fri, 20 Sep 2013 14:54:09 +0300
changeset 10365 a29c04e7905b
parent 10364 d7735b3a00c6
child 10366 0c0fd7e821bd
Fixed error when a handover is triggered before the previous one is completed
src/lte/model/lte-enb-rrc.cc
--- a/src/lte/model/lte-enb-rrc.cc	Fri Sep 20 14:47:16 2013 +0300
+++ b/src/lte/model/lte-enb-rrc.cc	Fri Sep 20 14:54:09 2013 +0300
@@ -247,14 +247,14 @@
 
     case HANDOVER_JOINING:
       m_handoverJoiningTimeout = Simulator::Schedule (m_rrc->m_handoverJoiningTimeoutDuration, 
-                                                 &LteEnbRrc::HandoverJoiningTimeout, 
-                                                 m_rrc, m_rnti);
+                                                      &LteEnbRrc::HandoverJoiningTimeout,
+                                                      m_rrc, m_rnti);
       break;      
 
     default:
       NS_FATAL_ERROR ("unexpected state " << ToString (m_state));
-      break;      
-    }  
+      break;
+    }
 
 }
 
@@ -496,7 +496,7 @@
 
     default:
       NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
-      break;      
+      break;
     }
 }
 
@@ -551,7 +551,7 @@
       
     default:
       NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
-      break;      
+      break;
     }
 
 }
@@ -576,8 +576,8 @@
   SwitchToState (HANDOVER_LEAVING);
   m_handoverLeavingTimeout = Simulator::Schedule (m_rrc->m_handoverLeavingTimeoutDuration, 
                                                   &LteEnbRrc::HandoverLeavingTimeout, 
-                                                  m_rrc, m_rnti);  
-  NS_ASSERT (handoverCommand.haveMobilityControlInfo);  
+                                                  m_rrc, m_rnti);
+  NS_ASSERT (handoverCommand.haveMobilityControlInfo);
   m_rrc->m_handoverStartTrace (m_imsi, m_rrc->m_cellId, m_rnti, handoverCommand.mobilityControlInfo.targetPhysCellId);
 
   EpcX2SapProvider::SnStatusTransferParams sst;
@@ -621,7 +621,7 @@
 UeManager::SendData (uint8_t bid, Ptr<Packet> p)
 {
   NS_LOG_FUNCTION (this << p << (uint16_t) bid);
-   switch (m_state)
+  switch (m_state)
     {
     case INITIAL_RANDOM_ACCESS:
     case CONNECTION_SETUP:
@@ -1986,13 +1986,29 @@
       NS_LOG_DEBUG (this << " cellId=" << m_cellId
                          << " targetCellId=" << targetCellId
                          << " NRT.NoHo=" << noHo << " NRT.NoX2=" << noX2);
-      isHandoverAllowed = (noHo == false) && (noX2 == false);
+
+      if (noHo || noX2)
+        {
+          isHandoverAllowed = false;
+          NS_LOG_LOGIC (this << " handover to cell " << targetCellId
+                             << " is not allowed by ANR");
+        }
+    }
+
+  Ptr<UeManager> ueManager = GetUeManager (rnti);
+  NS_ASSERT_MSG (ueManager != 0, "Cannot find UE context with RNTI " << rnti);
+
+  if (ueManager->GetState () != UeManager::CONNECTED_NORMALLY)
+    {
+      isHandoverAllowed = false;
+      NS_LOG_LOGIC (this << " handover is not allowed because the UE"
+                         << " rnti=" << rnti << " is in "
+                         << ToString (ueManager->GetState ()) << " state");
     }
 
   if (isHandoverAllowed)
     {
-      Ptr<UeManager> ueManager = GetUeManager (rnti);
-      NS_ASSERT_MSG (ueManager != 0, "Cannot find UE context with RNTI " << rnti);
+      // initiate handover execution
       ueManager->PrepareHandover (targetCellId);
     }
 }