16#include "../Application/Application.h"
17#include "AdvancedPlots.h"
18#pragma comment(lib,"AdvancedPlots.lib")
22 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
23 char *pszAppPath_Formal,
24 char *pszWritePath_Formal,
27_declspec(dllexport)
int fn_NetSim_GSM_Configure_F(
void** var);
29_declspec(dllexport)
int fn_NetSim_GSM_Metrics_F(
char* szMetrics);
37 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
38 char *pszAppPath_Formal,
39 char *pszWritePath_Formal,
44 NETWORK=NETWORK_Formal;
45 pstruEventDetails=pstruEventDetails_Formal;
46 return fn_NetSim_GSM_Init_F(NETWORK_Formal,
47 pstruEventDetails_Formal,
54_declspec(dllexport)
int fn_NetSim_GSM_Configure(
void** var)
56 return fn_NetSim_GSM_Configure_F(var);
62_declspec (dllexport)
int fn_NetSim_GSM_Run()
64 return fn_NetSim_Cellular_Run();
70_declspec (dllexport)
char *fn_NetSim_GSM_Trace(
int nSubEvent)
74 case Subevent_DropCall:
76 case Subevent_TxNextBurst:
79 return "GSM_UnknownEvent";
85_declspec(dllexport)
int fn_NetSim_GSM_FreePacket(NetSim_PACKET* pstruPacket)
87 return fn_NetSim_Cellular_FreePacket(pstruPacket);
93_declspec(dllexport)
int fn_NetSim_GSM_CopyPacket(NetSim_PACKET* pstruDestPacket,NetSim_PACKET* pstruSrcPacket)
95 return fn_NetSim_Cellular_CopyPacket(pstruDestPacket,pstruSrcPacket);
100_declspec(dllexport)
int fn_NetSim_GSM_Metrics(
char* szMetrics)
102 return fn_NetSim_GSM_Metrics_F(szMetrics);
107_declspec(dllexport)
char* fn_NetSim_GSM_ConfigPacketTrace()
114_declspec(dllexport)
int fn_NetSim_GSM_WritePacketTrace(NetSim_PACKET* pstruPacket,
char** ppszTrace)
122_declspec(dllexport)
int fn_NetSim_GSM_Finish()
124 LinkPacketLog_close();
128int fn_NetSim_Cellular_AddPacketToBuffer(NetSim_PACKET* packet,NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId)
130 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nDeviceId,nInterfaceId);
131 fn_NetSim_Cellular_FormBurst(packet,MSMac);
135int fn_NetSim_Cellular_AllocateChannel(NetSim_EVENTDETAILS* pstruEventDetails,NetSim_PACKET* packet)
137 ptrAPPLICATION_INFO* appInfo=(ptrAPPLICATION_INFO*)NETWORK->appInfo;
138 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
139 NETSIM_ID nApplicationId=packet->pstruAppData->nApplicationId;
140 if(MSMac->nMSStatusFlag!=Status_IDLE && MSMac->nMSStatusFlag != Status_CallEnd)
142 if(MSMac->nApplicationId!=nApplicationId)
144 unsigned int nProtocol=pstruEventDetails->nProtocolId;
145 NetSim_EVENTDETAILS pevent;
146 APP_CALL_INFO* info=appInfo[nApplicationId-1]->appData;
147 memcpy(&pevent,pstruEventDetails,
sizeof pevent);
149 info->fn_BlockCall(appInfo[nApplicationId-1],
151 get_first_dest_from_packet(packet),
152 pstruEventDetails->dEventTime);
153 pstruEventDetails->nProtocolId=nProtocol;
155 fn_NetSim_Packet_FreePacket(packet);
156 MSMac->MSMetrics.nCallBlocked++;
157 memcpy(pstruEventDetails,&pevent,
sizeof* pstruEventDetails);
162 NetSim_PACKET* request;
163 Cellular_PACKET* cellularPacket=calloc(1,
sizeof* cellularPacket);
164 Cellular_CHANNEL_REQUEST* requestData=calloc(1,
sizeof* requestData);
165 MSMac->nMSStatusFlag=Status_ChannelRequested;
166 MSMac->nApplicationId=nApplicationId;
167 MSMac->nSourceFlag=1;
168 request=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
169 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_ChannelRequest),
170 pstruEventDetails->nDeviceId,
173 pstruEventDetails->nProtocolId);
174 request->pstruMacData->Packet_MACProtocol=cellularPacket;
175 cellularPacket->controlData=requestData;
176 requestData->nApplicationId=nApplicationId;
177 requestData->nMSId=pstruEventDetails->nDeviceId;
178 requestData->nDestId= get_first_dest_from_packet(packet);
179 requestData->nRequestType=PacketType_ChannelRequest;
181 pstruEventDetails->dPacketSize=1;
182 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
183 pstruEventDetails->nPacketId=0;
184 pstruEventDetails->pPacket=request;
185 fnpAddEvent(pstruEventDetails);
186 fn_NetSim_Cellular_AddPacketToBuffer(packet,pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
187 MSMac->MSMetrics.nChannelRequestSent++;
192int fn_NetSim_GSM_BS_PhyOut()
194 Cellular_BS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
195 NetSim_PACKET* packet = pstruEventDetails->pPacket;
196 Cellular_PACKET* gsmPacket=packet->pstruMacData->Packet_MACProtocol;
197 unsigned int nTimeSlot=gsmPacket->nTimeSlot;
199 double dDataRate=DATA_RATE;
200 packet->pstruPhyData->dArrivalTime=pstruEventDetails->dEventTime;
201 dStartTime=fn_NetSim_GSM_GetPacketStartTime(pstruEventDetails->dEventTime,nTimeSlot);
203 packet->pstruPhyData->dOverhead=0;
204 packet->pstruPhyData->dPacketSize=packet->pstruMacData->dPacketSize;
205 packet->pstruPhyData->dPayload=packet->pstruMacData->dPacketSize;
206 packet->pstruPhyData->dStartTime=dStartTime;
207 packet->pstruPhyData->dEndTime=dStartTime+fnGetPacketSize(packet)*8/dDataRate;
208 pstruEventDetails->dEventTime=packet->pstruPhyData->dEndTime;
209 pstruEventDetails->nDeviceId=packet->nReceiverId;
210 pstruEventDetails->nDeviceType=DEVICE_TYPE(packet->nReceiverId);
211 pstruEventDetails->nEventType=PHYSICAL_IN_EVENT;
212 pstruEventDetails->nInterfaceId=1;
213 fnpAddEvent(pstruEventDetails);
215 fn_NetSim_WritePacketTrace(packet);
216 fn_NetSim_Metrics_Add(packet);
220int fn_NetSim_Cellular_SendCallend(NETSIM_ID nMSID,NETSIM_ID nMSInterface,NETSIM_ID nDestinationId,
double time)
222 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSID,nMSInterface);
223 NETSIM_ID nApplicationId=MSMac->nApplicationId;
224 NetSim_PACKET* packet=fn_NetSim_Cellular_createPacket(time,
225 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_CallEnd),
229 pstruEventDetails->nProtocolId);
230 Cellular_PACKET* gsmPacket=calloc(1,
sizeof* gsmPacket);
231 gsmPacket->nApplicationId=nApplicationId;
232 gsmPacket->nTimeSlot=MSMac->pstruAllocatedChannel->nTimeSlot;
233 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
235 pstruEventDetails->dEventTime=time;
236 pstruEventDetails->dPacketSize=1;
237 pstruEventDetails->nApplicationId=nApplicationId;
238 pstruEventDetails->nDeviceId=nMSID;
239 pstruEventDetails->nDeviceType=MOBILESTATION;
240 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
241 pstruEventDetails->nInterfaceId=nMSInterface;
242 pstruEventDetails->nPacketId=0;
243 pstruEventDetails->nProtocolId=pstruEventDetails->nProtocolId;
244 pstruEventDetails->nSegmentId=0;
245 pstruEventDetails->nSubEventType=0;
246 pstruEventDetails->pPacket=packet;
247 fnpAddEvent(pstruEventDetails);
249 fn_NetSim_Cellular_MS_SendChannelRelease(MSMac->pstruAllocatedChannel,nMSID,nMSInterface,time+GSM_CARRIER_LENGTH);
250 if(MSMac->nMSStatusFlag==Status_CallInProgress)
251 MSMac->nMSStatusFlag=Status_IDLE;
253 MSMac->nMSStatusFlag=Status_CallEnd;