16#include "../Application/Application.h"
17#include "AdvancedPlots.h"
18#pragma comment(lib,"AdvancedPlots.lib")
26int fn_NetSim_Cellular_Run()
28 switch(pstruEventDetails->nEventType)
32 switch(pstruEventDetails->nDeviceType)
36 NetSim_BUFFER* buffer=DEVICE_MAC_NW_INTERFACE(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)->pstruAccessBuffer;
39 NetSim_PACKET* packet=fn_NetSim_Packet_GetPacketFromBuffer(buffer,1);
40 NETSIM_ID nAppId=packet->pstruAppData->nApplicationId;
41 if(isCellularChannelAllocated(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId,nAppId))
42 fn_NetSim_Cellular_AddPacketToBuffer(packet,pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
45 ((Cellular_MS_MAC*)DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId))->MSMetrics.nCallGenerated++;
46 fn_NetSim_Cellular_AllocateChannel(pstruEventDetails,packet);
48 }
while(fn_NetSim_GetBufferStatus(buffer));
56 switch(pstruEventDetails->nDeviceType)
60 NetSim_PACKET* packet=pstruEventDetails->pPacket;
61 switch(packet->nControlDataType)
63 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelUngranted):
64 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelGranted):
65 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelUngranted):
66 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelGranted):
67 fn_NetSim_Cellular_ChannelResponse(packet);
68 fn_NetSim_Packet_FreePacket(packet);
70 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallRequest):
71 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallRequest):
72 fn_NetSim_Cellular_MS_ProcessCallRequest();
74 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallAccepted):
75 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallRejected):
76 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallAccepted):
77 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallRejected):
78 fn_NetSim_Cellular_MS_ProcessCallResponse();
80 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallEnd):
81 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallEnd):
83 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
84 if(MSMac->pstruAllocatedChannel)
85 fn_NetSim_Cellular_MS_SendChannelRelease(MSMac->pstruAllocatedChannel,pstruEventDetails->nDeviceId,
86 pstruEventDetails->nInterfaceId,
87 pstruEventDetails->dEventTime);
88 MSMac->nApplicationId=0;
90 MSMac->nMSStatusFlag=Status_IDLE;
93 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_DropCall):
94 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_DropCall):
95 fn_NetSim_Cellular_DropCall();
98 fn_NetSim_Cellular_MS_ReassembleBurst();
105 if(NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ppstruInterfaceList[pstruEventDetails->nInterfaceId-1]->pstruPhysicalLayer->nPhyMedium==PHY_MEDIUM_WIRELESS)
107 NetSim_PACKET* packet=pstruEventDetails->pPacket;
108 switch(packet->nControlDataType)
110 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelRequestForHandover):
111 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelRequest):
112 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelRequestForIncoming):
113 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelRequestForHandover):
114 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelRequest):
115 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelRequestForIncoming):
116 fn_NetSim_Cellular_allocateChannel(packet);
118 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelRelease):
119 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelRelease):
120 fn_NetSim_Cellular_BS_ReleaseChannel();
123 fn_NetSim_Cellular_ForwardToMSC();
129 if(DEVICE_MACLAYER(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)->nMacProtocolId == MAC_PROTOCOL_GSM)
132 fn_NetSim_Cellular_BS_AssignTimeSlot(pstruEventDetails->pPacket,pstruEventDetails->nDeviceId);
133 if(pstruEventDetails->pPacket->pstruAppData && pstruEventDetails->pPacket->pstruAppData->nApplicationId)
134 flag = isCellularChannelAllocated(get_first_dest_from_packet(pstruEventDetails->pPacket),1,pstruEventDetails->pPacket->pstruAppData->nApplicationId);
135 if(flag || pstruEventDetails->pPacket->nControlDataType/100 == MAC_PROTOCOL_GSM)
137 pstruEventDetails->pPacket->nTransmitterId=pstruEventDetails->nDeviceId;
138 pstruEventDetails->pPacket->nReceiverId= get_first_dest_from_packet(pstruEventDetails->pPacket);
139 pstruEventDetails->nInterfaceId=1;
140 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
141 fnpAddEvent(pstruEventDetails);
146 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
151 pstruEventDetails->pPacket->nTransmitterId=pstruEventDetails->nDeviceId;
152 pstruEventDetails->pPacket->nReceiverId= get_first_dest_from_packet(pstruEventDetails->pPacket);
153 pstruEventDetails->nInterfaceId=1;
154 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
155 fnpAddEvent(pstruEventDetails);
162 fn_NetSim_Cellular_Msc_ProcessPacket();
168 case PHYSICAL_OUT_EVENT:
170 switch(pstruEventDetails->nDeviceType)
174 fn_NetSim_Cellular_MS_PhyOut();
178 if(NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ppstruInterfaceList[pstruEventDetails->nInterfaceId-1]->pstruPhysicalLayer->nPhyMedium==PHY_MEDIUM_WIRELESS)
179 fn_NetSim_GSM_BS_PhyOut();
180 else if(NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ppstruInterfaceList[pstruEventDetails->nInterfaceId-1]->pstruPhysicalLayer->nPhyMedium==PHY_MEDIUM_WIRED)
181 fn_NetSim_Cellular_TransmitOnwireline();
184 fnNetSimError(
"Unknown phy medium %d for device %d Interface %d",NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->ppstruInterfaceList[pstruEventDetails->nInterfaceId-1]->pstruPhysicalLayer->nPhyMedium,pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
188 fn_NetSim_Cellular_TransmitOnwireline();
193 case PHYSICAL_IN_EVENT:
196 pstruEventDetails->nEventType=MAC_IN_EVENT;
197 fnpAddEvent(pstruEventDetails);
202 switch(pstruEventDetails->nSubEventType)
204 case CELLULAR_SUBEVENT(MAC_PROTOCOL_CDMA,Subevent_DropCall):
205 case CELLULAR_SUBEVENT(MAC_PROTOCOL_GSM,Subevent_DropCall):
206 fn_NetSim_Cellular_DropCall();
208 case CELLULAR_SUBEVENT(MAC_PROTOCOL_GSM,Subevent_TxNextBurst):
209 case CELLULAR_SUBEVENT(MAC_PROTOCOL_CDMA,Subevent_TxNextBurst):
211 NetSim_PACKET**** list=pstruEventDetails->szOtherDetails;
212 list[pstruEventDetails->pPacket->pstruAppData->nApplicationId][pstruEventDetails->pPacket->nSourceId-1][get_first_dest_from_packet(pstruEventDetails->pPacket)-1]=list[pstruEventDetails->pPacket->pstruAppData->nApplicationId][pstruEventDetails->pPacket->nSourceId-1][get_first_dest_from_packet(pstruEventDetails->pPacket)-1]->pstruNextPacket;
213 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
214 pstruEventDetails->nSubEventType=0;
215 pstruEventDetails->szOtherDetails=NULL;
216 fnpAddEvent(pstruEventDetails);
220 fnNetSimError(
"Unknown timer event for cellular protocol");
226 fnNetSimError(
"Unknown event type for cellular protocol");
237int fn_NetSim_Cellular_allocateChannel(NetSim_PACKET* packet)
239 Cellular_CHANNEL_RESPONSE* response=calloc(1,
sizeof* response);
240 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
241 Cellular_CHANNEL_REQUEST* request=gsmPacket->controlData;
242 Cellular_BS_MAC* BSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
243 Cellular_CHANNEL* channel=BSMac->pstruChannelList;
244 NetSim_PACKET* returnPacket;
245 unsigned int nPacketType;
253 channel->
nMSId=request->nMSId;
254 channel->nDestId=request->nDestId;
257 channel=channel->pstru_NextChannel;
262 response->channel=channel;
263 response->nAllocationFlag=1;
264 nPacketType=CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_ChannelGranted);
268 response->channel=calloc(1,
sizeof* response->channel);
270 response->channel->
nMSId=request->nMSId;
271 response->channel->nDestId=request->nDestId;
272 nPacketType=CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_ChannelUngranted);
274 returnPacket=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
276 pstruEventDetails->nDeviceId,
279 pstruEventDetails->nProtocolId);
280 gsmPacket=calloc(1,
sizeof* gsmPacket);
281 gsmPacket->controlData=response;
282 returnPacket->pstruMacData->Packet_MACProtocol=gsmPacket;
283 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
284 pstruEventDetails->pPacket=returnPacket;
285 fnpAddEvent(pstruEventDetails);
292int fn_NetSim_Cellular_ChannelResponse(NetSim_PACKET* packet)
294 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
295 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
296 Cellular_CHANNEL_RESPONSE* response=gsmPacket->controlData;
297 if(response->nAllocationFlag==1 && MSMac->nMSStatusFlag==Status_ChannelRequested)
299 NetSim_PACKET* packet;
300 Cellular_PACKET* gsmPacket;
301 Cellular_CHANNEL* channel=response->channel;
302 MSMac->pstruAllocatedChannel=channel;
303 packet = fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
304 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_CallRequest),
308 pstruEventDetails->nProtocolId);
309 gsmPacket=calloc(1,
sizeof* gsmPacket);
311 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
312 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
313 pstruEventDetails->nApplicationId=0;
314 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
315 pstruEventDetails->nPacketId=0;
316 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
317 pstruEventDetails->nSegmentId=0;
318 pstruEventDetails->pPacket=packet;
319 fnpAddEvent(pstruEventDetails);
320 MSMac->nMSStatusFlag=Status_CallRequested;
321 MSMac->MSMetrics.nCallRequestSent++;
323 else if(response->nAllocationFlag==1 && MSMac->nMSStatusFlag==Status_ChannelRequestedForIncoming)
326 NetSim_PACKET* packet;
327 Cellular_PACKET* gsmPacket;
328 Cellular_CHANNEL* channel=response->channel;
329 MSMac->pstruAllocatedChannel=channel;
330 packet = fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
331 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_CallAccepted),
335 pstruEventDetails->nProtocolId);
336 gsmPacket=calloc(1,
sizeof* gsmPacket);
338 gsmPacket->nTimeSlot=channel->nTimeSlot;
339 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
340 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
341 pstruEventDetails->nApplicationId=0;
342 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
343 pstruEventDetails->nPacketId=0;
344 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
345 pstruEventDetails->nSegmentId=0;
346 pstruEventDetails->pPacket=packet;
347 fnpAddEvent(pstruEventDetails);
348 MSMac->nMSStatusFlag=Status_CallInProgress;
349 MSMac->MSMetrics.nCallAccepted++;
351 else if(MSMac->nMSStatusFlag==Status_ChannelRequestedForHandover)
353 fn_NetSim_Cellular_ChannelResponseForHandover();
355 else if(response->nAllocationFlag==0 && MSMac->nMSStatusFlag==Status_ChannelRequested)
357 unsigned int nProtocol=pstruEventDetails->nProtocolId;
358 Cellular_CHANNEL* channel=response->channel;
359 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1];
360 ptrAPPLICATION_INFO* appInfo=(ptrAPPLICATION_INFO*)NETWORK->appInfo;
361 APP_CALL_INFO* info=appInfo[packet->pstruAppData->nApplicationId-1]->appData;
362 info->fn_BlockCall(appInfo[packet->pstruAppData->nApplicationId-1],
364 get_first_dest_from_packet(packet),
365 pstruEventDetails->dEventTime);
366 pstruEventDetails->nProtocolId=nProtocol;
369 NetSim_PACKET* temp=packet->pstruNextPacket;
370 fn_NetSim_Packet_FreePacket(packet);
373 MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1]=NULL;
374 MSMac->nMSStatusFlag=Status_IDLE;
375 MSMac->nSourceFlag=0;
376 MSMac->nApplicationId=0;
377 MSMac->MSMetrics.nCallBlocked++;
379 else if(response->nAllocationFlag==0 && MSMac->nMSStatusFlag==Status_ChannelRequestedForIncoming)
382 NetSim_PACKET* packet;
383 Cellular_PACKET* gsmPacket;
384 Cellular_CHANNEL* channel=response->channel;
385 MSMac->pstruAllocatedChannel=NULL;
386 packet = fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
387 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_CallRejected),
391 pstruEventDetails->nProtocolId);
392 gsmPacket=calloc(1,
sizeof* gsmPacket);
394 gsmPacket->nTimeSlot=0;
395 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
396 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
397 pstruEventDetails->nApplicationId=0;
398 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
399 pstruEventDetails->nPacketId=0;
400 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
401 pstruEventDetails->nSegmentId=0;
402 pstruEventDetails->pPacket=packet;
403 fnpAddEvent(pstruEventDetails);
404 MSMac->nMSStatusFlag=Status_IDLE;
405 MSMac->nApplicationId=0;
406 MSMac->MSMetrics.nCallRejected++;
408 else if(MSMac->nMSStatusFlag==Status_CallEnd)
411 Cellular_CHANNEL* channel=response->channel;
416 MSMac->nMSStatusFlag=Status_IDLE;
427int fn_NetSim_Cellular_ForwardToMSC()
429 pstruEventDetails->nInterfaceId=2;
430 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
431 fnpAddEvent(pstruEventDetails);
438int fn_NetSim_Cellular_TransmitOnwireline()
440 NETSIM_ID nConnectedDevice,nConnectedInterface,nLinkId;
442 NetSim_PACKET* packet=pstruEventDetails->pPacket;
443 nLinkId=fn_NetSim_Stack_GetConnectedDevice(pstruEventDetails->nDeviceId,
444 pstruEventDetails->nInterfaceId,
446 &(nConnectedInterface));
447 dDataRate = NETWORK->ppstruNetSimLinks[nLinkId-1]->puniMedProp.pstruWiredLink.dDataRateDown;
448 packet->pstruPhyData->dArrivalTime=pstruEventDetails->dEventTime;
449 packet->pstruPhyData->dEndTime=pstruEventDetails->dEventTime+fnGetPacketSize(packet)*8/dDataRate;
450 packet->pstruPhyData->dStartTime=pstruEventDetails->dEventTime;
451 packet->nTransmitterId=pstruEventDetails->nDeviceId;
452 packet->nReceiverId=nConnectedDevice;
453 pstruEventDetails->dEventTime=packet->pstruPhyData->dEndTime;
454 pstruEventDetails->nDeviceId=nConnectedDevice;
455 pstruEventDetails->nDeviceType=DEVICE_TYPE(nConnectedDevice);
456 pstruEventDetails->nEventType=PHYSICAL_IN_EVENT;
457 pstruEventDetails->nInterfaceId=nConnectedInterface;
458 fnpAddEvent(pstruEventDetails);
460 fn_NetSim_WritePacketTrace(packet);
461 fn_NetSim_Metrics_Add(packet);
473int fn_NetSim_Cellular_VLR(NETSIM_ID nMSCId,NETSIM_ID nId,NETSIM_ID* nBTSId,NETSIM_ID* nInterfaceId)
475 DEVVAR_MSC* devVar=NETWORK->ppstruDeviceList[nMSCId-1]->deviceVar;
476 if(devVar->VLRList[nId-1])
478 *nBTSId=devVar->VLRList[nId-1]->nBTSId;
479 *nInterfaceId=devVar->VLRList[nId-1]->nInterfaceId;
489int fn_NetSim_Cellular_Msc_ProcessPacket()
491 NETSIM_ID nBTSId,nInterfaceId;
492 NetSim_PACKET* packet=pstruEventDetails->pPacket;
493 NETSIM_ID nSourceId=packet->nSourceId;
494 NETSIM_ID nDestinationId= get_first_dest_from_packet(packet);
496 fn_NetSim_Cellular_VLR(pstruEventDetails->nDeviceId,nDestinationId,&nBTSId,&nInterfaceId);
499 packet->nTransmitterId=pstruEventDetails->nDeviceId;
500 packet->nReceiverId=nBTSId;
501 pstruEventDetails->nInterfaceId=nInterfaceId;
502 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
503 fnpAddEvent(pstruEventDetails);
510int fn_NetSim_Cellular_MS_ProcessCallRequest()
512 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
513 NetSim_PACKET* packet=pstruEventDetails->pPacket;
514 NETSIM_ID nSouceId= get_first_dest_from_packet(packet);
515 NETSIM_ID nDestId=packet->nSourceId;
516 MSMac->MSMetrics.nCallRequestReceived++;
517 if(MSMac->nMSStatusFlag == Status_IDLE || MSMac->nMSStatusFlag==Status_CallEnd)
519 NetSim_PACKET* request;
520 Cellular_PACKET* gsmPacket=calloc(1,
sizeof* gsmPacket);
521 Cellular_CHANNEL_REQUEST* requestData=calloc(1,
sizeof* requestData);
522 MSMac->nMSStatusFlag=Status_ChannelRequested;
523 MSMac->nApplicationId=((Cellular_PACKET*)packet->pstruMacData->Packet_MACProtocol)->nApplicationId;
524 request=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
525 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_ChannelRequestForIncoming),
526 pstruEventDetails->nDeviceId,
529 pstruEventDetails->nProtocolId);
530 request->pstruMacData->Packet_MACProtocol=gsmPacket;
531 gsmPacket->controlData=requestData;
532 requestData->nApplicationId=((Cellular_PACKET*)packet->pstruMacData->Packet_MACProtocol)->nApplicationId;;
533 requestData->nMSId=pstruEventDetails->nDeviceId;
534 requestData->nDestId=nDestId;
535 requestData->nRequestType=PacketType_ChannelRequestForIncoming;
537 pstruEventDetails->dPacketSize=1;
538 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
539 pstruEventDetails->nPacketId=0;
540 pstruEventDetails->pPacket=request;
541 fnpAddEvent(pstruEventDetails);
542 MSMac->nMSStatusFlag=Status_ChannelRequestedForIncoming;
543 MSMac->MSMetrics.nChannelRequestSent++;
549 NetSim_PACKET* response;
550 Cellular_PACKET* gsmPacket;
551 response = fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
552 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId, PacketType_CallRejected),
553 get_first_dest_from_packet(packet),
556 pstruEventDetails->nProtocolId);
557 gsmPacket = calloc(1,
sizeof* gsmPacket);
558 gsmPacket->nApplicationId = ((Cellular_PACKET*)packet->pstruMacData->Packet_MACProtocol)->nApplicationId;
559 gsmPacket->nTimeSlot=0;
560 response->pstruMacData->Packet_MACProtocol=gsmPacket;
561 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
562 pstruEventDetails->nApplicationId=0;
563 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
564 pstruEventDetails->nPacketId=0;
565 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
566 pstruEventDetails->nSegmentId=0;
567 pstruEventDetails->pPacket=response;
568 fnpAddEvent(pstruEventDetails);
569 MSMac->MSMetrics.nCallRejected++;
574int fn_NetSim_Cellular_MS_ProcessCallResponse()
576 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
577 switch(pstruEventDetails->pPacket->nControlDataType)
579 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallAccepted):
580 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallAccepted):
582 Cellular_CHANNEL* channel=MSMac->pstruAllocatedChannel;
583 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1];
584 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
585 MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1] = MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1]->pstruNextPacket;
586 MSMac->nMSStatusFlag=Status_CallInProgress;
587 packet->pstruMacData->dEndTime=pstruEventDetails->dEventTime;
588 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
589 packet->pstruMacData->dOverhead=GSM_OVERHEAD;
591 packet->pstruMacData->dOverhead=0;
592 packet->pstruMacData->dPacketSize=packet->pstruMacData->dOverhead+packet->pstruMacData->dPayload;
593 packet->pstruMacData->dStartTime=pstruEventDetails->dEventTime;
594 gsmPacket=packet->pstruMacData->Packet_MACProtocol;
595 gsmPacket->nTimeSlot=channel->nTimeSlot;
597 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
598 pstruEventDetails->nApplicationId=packet->pstruAppData->nApplicationId;
599 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
600 pstruEventDetails->nPacketId=packet->nPacketId;
601 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
602 pstruEventDetails->nSegmentId=packet->pstruAppData->nSegmentId;
604 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
605 pstruEventDetails->pPacket=packet;
606 fnpAddEvent(pstruEventDetails);
609 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_CallRejected):
610 case CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_CallRejected):
612 NetSim_PACKET* current=pstruEventDetails->pPacket;
613 unsigned int nProtocol=pstruEventDetails->nProtocolId;
614 NETSIM_ID nMSId = pstruEventDetails->nDeviceId;
615 NETSIM_ID nMSInterface=pstruEventDetails->nInterfaceId;
616 double time=pstruEventDetails->dEventTime;
617 Cellular_CHANNEL* channel=MSMac->pstruAllocatedChannel;
618 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1];
619 ptrAPPLICATION_INFO* appInfo=(ptrAPPLICATION_INFO*)NETWORK->appInfo;
620 APP_CALL_INFO* info=appInfo[packet->pstruAppData->nApplicationId-1]->appData;
621 info->fn_BlockCall(appInfo[packet->pstruAppData->nApplicationId-1],
623 get_first_dest_from_packet(packet),
624 pstruEventDetails->dEventTime);
625 pstruEventDetails->nProtocolId=nProtocol;
626 fn_NetSim_Cellular_MS_SendChannelRelease(channel,nMSId,nMSInterface,time);
629 NetSim_PACKET* temp=packet->pstruNextPacket;
630 fn_NetSim_Packet_FreePacket(packet);
633 MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1]=NULL;
634 MSMac->nMSStatusFlag=Status_IDLE;
635 MSMac->MSMetrics.nCallBlocked++;
636 fn_NetSim_Packet_FreePacket(current);
643int fn_NetSim_Cellular_BS_AssignTimeSlot(NetSim_PACKET* packet,NETSIM_ID nBTSId)
645 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
646 NETSIM_ID nApplicationId=gsmPacket->nApplicationId;
647 gsmPacket->nTimeSlot=0;
654 Cellular_BS_MAC* BSMac=DEVICE_MACVAR(nBTSId,1);
655 Cellular_CHANNEL* channel=BSMac->pstruChannelList;
659 && channel->
nMSId == get_first_dest_from_packet(packet))
661 gsmPacket->nTimeSlot=channel->nTimeSlot;
664 channel=channel->pstru_NextChannel;
670int fn_NetSim_Cellular_MS_SendChannelRelease(Cellular_CHANNEL* channel,NETSIM_ID nMSId,NETSIM_ID nMSInterface,
double time)
672 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSId,nMSInterface);
673 NetSim_PACKET* packet = fn_NetSim_Cellular_createPacket(time,
674 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_ChannelRelease),
678 pstruEventDetails->nProtocolId);
679 Cellular_PACKET* gsmPacket=calloc(1,
sizeof* gsmPacket);
681 gsmPacket->nTimeSlot=0;
682 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
684 pstruEventDetails->dEventTime=time;
685 pstruEventDetails->dPacketSize=1;
686 pstruEventDetails->nApplicationId=0;
687 pstruEventDetails->nDeviceId=nMSId;
688 pstruEventDetails->nDeviceType=DEVICE_TYPE(nMSId);
689 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
690 pstruEventDetails->nInterfaceId=nMSInterface;
691 pstruEventDetails->nPacketId=0;
692 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
693 pstruEventDetails->nSegmentId=0;
694 pstruEventDetails->nSubEventType=0;
695 pstruEventDetails->pPacket=packet;
696 fnpAddEvent(pstruEventDetails);
697 MSMac->pstruAllocatedChannel=NULL;
701int fn_NetSim_Cellular_BS_ReleaseChannel()
703 Cellular_BS_MAC* BSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
704 Cellular_CHANNEL* channel=BSMac->pstruChannelList;
705 NETSIM_ID nApplicationId=((Cellular_PACKET*)pstruEventDetails->pPacket->pstruMacData->Packet_MACProtocol)->
nApplicationId;
706 NETSIM_ID nMSId=pstruEventDetails->pPacket->nSourceId;
717 channel=channel->pstru_NextChannel;
722int fn_NetSim_Cellular_MS_PhyOut()
724 NETSIM_ID nMSID=pstruEventDetails->nDeviceId;
725 NETSIM_ID nMSInterface=pstruEventDetails->nInterfaceId;
726 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
727 NetSim_PACKET* packet = pstruEventDetails->pPacket;
728 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
729 unsigned int nTimeSlot=gsmPacket->nTimeSlot;
731 double dDataRate=DATA_RATE;
732 packet->pstruPhyData->dArrivalTime=pstruEventDetails->dEventTime;
733 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
734 dStartTime=fn_NetSim_GSM_GetPacketStartTime(pstruEventDetails->dEventTime,nTimeSlot);
736 dStartTime=pstruEventDetails->dEventTime;
737 packet->pstruPhyData->dOverhead=0;
738 packet->pstruPhyData->dPacketSize=packet->pstruMacData->dPacketSize;
739 packet->pstruPhyData->dPayload=packet->pstruMacData->dPacketSize;
740 packet->pstruPhyData->dStartTime=dStartTime;
741 packet->pstruPhyData->dEndTime=dStartTime+fnGetPacketSize(packet)*8/dDataRate;
742 if(packet->nControlDataType == CELLULAR_PACKET_TYPE(MAC_PROTOCOL_GSM,PacketType_ChannelRequestForHandover) ||
743 packet->nControlDataType == CELLULAR_PACKET_TYPE(MAC_PROTOCOL_CDMA,PacketType_ChannelRequestForHandover))
744 packet->nReceiverId=MSMac->nNewBTS;
746 packet->nReceiverId=MSMac->nBTSId;
747 packet->nTransmitterId=pstruEventDetails->nDeviceId;
748 pstruEventDetails->dEventTime=packet->pstruPhyData->dEndTime;
749 pstruEventDetails->nDeviceId=packet->nReceiverId;
750 pstruEventDetails->nDeviceType=BASESTATION;
751 pstruEventDetails->nEventType=PHYSICAL_IN_EVENT;
752 pstruEventDetails->nInterfaceId=MSMac->nBTSInterface;
753 fnpAddEvent(pstruEventDetails);
754 DEVICE_PHYLAYER(nMSID,nMSInterface)->dLastPacketEndTime = pstruEventDetails->dEventTime;
756 fn_NetSim_WritePacketTrace(packet);
757 fn_NetSim_Metrics_Add(packet);
759 if(packet->nControlDataType==CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_DropCall))
761 pstruEventDetails->dPacketSize=0;
762 pstruEventDetails->nApplicationId=0;
763 pstruEventDetails->nDeviceId=nMSID;
764 pstruEventDetails->nDeviceType=MOBILESTATION;
765 pstruEventDetails->nEventType=TIMER_EVENT;
766 pstruEventDetails->nInterfaceId=nMSInterface;
767 pstruEventDetails->nPacketId=0;
768 pstruEventDetails->nSegmentId=0;
769 pstruEventDetails->nSubEventType=CELLULAR_SUBEVENT(pstruEventDetails->nProtocolId,Subevent_DropCall);
770 pstruEventDetails->pPacket=NULL;
771 fnpAddEvent(pstruEventDetails);
773 else if(MSMac->pstruAllocatedChannel &&
774 MSMac->pstruPacketList &&
775 MSMac->pstruPacketList[pstruEventDetails->nApplicationId][packet->nSourceId-1][get_first_dest_from_packet(packet)-1])
778 Cellular_PACKET* gsmPacket;
779 Cellular_CHANNEL* channel=MSMac->pstruAllocatedChannel;
780 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->
nApplicationId][channel->
nMSId-1][channel->nDestId-1];
781 packet->pstruMacData->dEndTime=pstruEventDetails->dEventTime;
782 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
783 packet->pstruMacData->dOverhead=GSM_OVERHEAD;
785 packet->pstruMacData->dOverhead=0;
786 packet->pstruMacData->dPacketSize=packet->pstruMacData->dOverhead+packet->pstruMacData->dPayload;
787 packet->pstruMacData->dStartTime=pstruEventDetails->dEventTime;
788 gsmPacket=packet->pstruMacData->Packet_MACProtocol;
789 gsmPacket->nTimeSlot=channel->nTimeSlot;
791 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
792 pstruEventDetails->dEventTime+=577*8;
793 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
794 pstruEventDetails->nApplicationId=packet->pstruAppData->nApplicationId;
795 pstruEventDetails->nEventType=TIMER_EVENT;
796 pstruEventDetails->nDeviceId=nMSID;
797 pstruEventDetails->nInterfaceId=nMSInterface;
798 pstruEventDetails->nDeviceType=MOBILESTATION;
799 pstruEventDetails->nPacketId=packet->nPacketId;
800 pstruEventDetails->nSegmentId=packet->pstruAppData->nSegmentId;
801 pstruEventDetails->pPacket=packet;
802 pstruEventDetails->nSubEventType=CELLULAR_SUBEVENT(pstruEventDetails->nProtocolId,Subevent_TxNextBurst);
803 pstruEventDetails->szOtherDetails=MSMac->pstruPacketList;
804 fnpAddEvent(pstruEventDetails);
806 else if(packet->pstruAppData && packet->pstruAppData->nAppEndFlag==1 && gsmPacket->isLast==1)
809 fn_NetSim_Cellular_SendCallend(nMSID,
811 get_first_dest_from_packet(packet),
812 pstruEventDetails->dEventTime);
CELLULAR_CHANNEL_TYPE nChannelType