The way to do this is,
1. Open NetSim.sln file from <NetSim Installation Directory>\src\Simulation folder.
2. Open NAS.c file in the LTE project from the list of projects displayed in the Solution Explorer.
3. Go to fn_NetSim_LTE_ProcessHORequestAck() function and perform the following modifications(lines shown in red):
int fn_NetSim_LTE_ProcessHORequestAck()
{
LTE_UE_MAC* ueMac;
NETSIM_ID nMMEId,nMMEInterface;
LTE_HLR* hlr;
char buf[1000];
FILE *fHLR;
int count=0;
NetSim_BUFFER* buffer=DEVICE_MAC_NW_INTERFACE(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)->pstruAccessBuffer;
NetSim_PACKET* ack=fn_NetSim_Packet_GetPacketFromBuffer(buffer,1);
LTE_HO_INFO* info=(LTE_HO_INFO*)((LTE_MAC_PACKET*)ack->pstruMacData->Packet_MACProtocol)->MessageVar;
fHLR=fopen("LTE_HANDOVER.txt","a+");
//Remove from source enb
LIST_REMOVE((void**)&info->sourceMac->associatedUEInfo,info->info);
info->sourceMac->nAssociatedUECount--;
//Add to target enb
LIST_ADD_LAST((void**)&info->targetMac->associatedUEInfo,info->info);
info->targetMac->nAssociatedUECount++;
//Link correction
fn_NetSim_Stack_RemoveDeviceFromlink(info->nUEId,1,DEVICE_PHYLAYER(info->nSourceENB,1)->nLinkId);
fn_NetSim_Stack_AddDeviceTolink(info->nUEId,1,DEVICE_PHYLAYER(info->nTargetENB,1)->nLinkId);
//Path switch
fn_NetSim_Stack_GetConnectedDevice(info->nSourceENB,2,&nMMEId,&nMMEInterface);
hlr=((LTE_MME*)NETWORK->ppstruDeviceList[nMMEId-1]->deviceVar)->HLR;
sprintf(buf,"\nAt Simulation Time: %f micro sec",pstruEventDetails->dEventTime);
sprintf(buf+strlen(buf),"\n\nHLR OF MME ID:%d Before Handover:\tHLR OF MME ID:%d After Handover:",nMMEId,nMMEId);
sprintf(buf+strlen(buf),"\n********************************\t*******************************\n");
while(hlr)
{
sprintf(buf+strlen(buf),"\nEntry %d:\t\t\t\tEntry %d: \n",count,count);count++;
if(hlr->nUEId==info->nUEId)
{
sprintf(buf+strlen(buf),"\n ENBId: %d \t\t\t\t",hlr->nENBId);
hlr->nENBId=info->nTargetENB;
hlr->nENBInterface=2;
fn_NetSim_Stack_GetConnectedDevice(hlr->nENBId,hlr->nENBInterface,&hlr->nMMEID,&hlr->nMMEInterface);
//break;
sprintf(buf+strlen(buf)," ENBId: %d \n",hlr->nENBId);
sprintf(buf+strlen(buf),"\n UEId : %d \t\t\t\t UEId : %d\n\n",hlr->nUEId,hlr->nUEId);
goto next;
}
sprintf(buf+strlen(buf),"\n ENBId: %d \t\t\t\t ENBId: %d \n",hlr->nENBId,hlr->nENBId);
sprintf(buf+strlen(buf),"\n UEId : %d \t\t\t\t UEId : %d\n\n",hlr->nUEId,hlr->nUEId);
next:
hlr=(LTE_HLR*)LIST_NEXT(hlr);
}
fprintf(fHLR,buf);
fclose(fHLR);
//Change the UE association
ueMac=(LTE_UE_MAC*)DEVICE_MACVAR(info->nUEId,1);
ueMac->nENBId=info->nTargetENB;
ueMac->nENBInterface=1;
//Update metrics
ueMac->metrics.nHandoverCount++;
fn_NetSim_Packet_FreePacket(ack);
return 1;
}
A sample NAS.c file is attached for reference.
4. After performing the modifications, right click on LTE project and select Rebuild.
5. Replace the newly built libLTE.dll in <NetSim Installation Directory>\bin folder after renaming the original libLTE.dll.
6. Now create a NetSim scenario for Handover to occur.
7. Run the scenario.
Whenever handover occurs the HLR table before and after handover will be written to a file named HLR.txt inside the bin folder of NetSim.
Note:
The files attached are related with NetSim v9.1.7 and we recommend you to perform code modifications and create scenarios in the respective version that you have.