NetSim Source Code Help
Loading...
Searching...
No Matches
GSM.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "Cellular.h"
16#include "../Application/Application.h"
17/* Function prototype */
18_declspec(dllexport) int fn_NetSim_GSM_Init_F(struct stru_NetSim_Network *NETWORK_Formal,
22 int nVersion_Type,
23 void **fnPointer);
24_declspec(dllexport) int fn_NetSim_GSM_Configure_F(void** var);
25
26_declspec(dllexport) int fn_NetSim_GSM_Metrics_F(char* szMetrics);
27
28
29
30
31
32/** This function is used to initialize the GSM parameters in a network */
33_declspec(dllexport) int fn_NetSim_GSM_Init(struct stru_NetSim_Network *NETWORK_Formal,
37 int nVersion_Type,
38 void **fnPointer)
39{
40 NETWORK=NETWORK_Formal;
42 return fn_NetSim_GSM_Init_F(NETWORK_Formal,
47 fnPointer);
48}
49/** This function is called by the NetworkStack.dll, while configuring the Network for GSM protocol */
50_declspec(dllexport) int fn_NetSim_GSM_Configure(void** var)
51{
52 return fn_NetSim_GSM_Configure_F(var);
53}
54/**
55This function is called by NetworkStack.dll, which inturn calls the
56Cellular run function which is present in Cellular.c
57 */
59{
61}
62/**
63This function is called by NetworkStack.dll, while writing the evnt trace
64to get the sub event as a string.
65*/
66_declspec (dllexport) char *fn_NetSim_GSM_Trace(int nSubEvent)
67{
68 switch(nSubEvent%100)
69 {
71 return "DropCall";
73 return "TxNextBurst";
74 default:
75 return "GSM_UnknownEvent";
76 }
77}
78/**
79This function is called by NetworkStack.dll, to free the GSM protocol control packets.
80*/
82{
83 return fn_NetSim_Cellular_FreePacket(pstruPacket);
84}
85/**
86This function is called by NetworkStack.dll, to copy the GSM protocol
87related information to a new packet
88*/
89_declspec(dllexport) int fn_NetSim_GSM_CopyPacket(NetSim_PACKET* pstruDestPacket,NetSim_PACKET* pstruSrcPacket)
90{
91 return fn_NetSim_Cellular_CopyPacket(pstruDestPacket,pstruSrcPacket);
92}
93/**
94This function writes the GSM metrics in Metrics.txt
95*/
96_declspec(dllexport) int fn_NetSim_GSM_Metrics(char* szMetrics)
97{
98 return fn_NetSim_GSM_Metrics_F(szMetrics);
99}
100/**
101This function is used to configure the packet trace
102*/
104{
105 return "";
106}
107/**
108This function is used to write the packet trace
109*/
110_declspec(dllexport) int fn_NetSim_GSM_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
111{
112 return 1;
113}
114/**
115This function is called by NetworkStack.dll, once simulation ends, to free the
116allocated memory
117*/
119{
120 return 1;
121}
122/** This function is used to add a packet to the MAC buffer of the mobile station */
124{
125 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nDeviceId,nInterfaceId);
126 fn_NetSim_Cellular_FormBurst(packet,MSMac);
127 return 1;
128}
129/** This function is used to allocate the channels */
131{
134 NETSIM_ID nApplicationId=packet->pstruAppData->nApplicationId;
135 if(MSMac->nMSStatusFlag!=Status_IDLE && MSMac->nMSStatusFlag != Status_CallEnd)
136 {
137 if(MSMac->nApplicationId!=nApplicationId)
138 {
139 unsigned int nProtocol=pstruEventDetails->nProtocolId;
140 NetSim_EVENTDETAILS pevent;
141 APP_CALL_INFO* info=appInfo[nApplicationId-1]->appData;
142 memcpy(&pevent,pstruEventDetails,sizeof pevent);
143 //Notify application layer
144 info->fn_BlockCall(appInfo[nApplicationId-1],
145 packet->nSourceId,
149 //Delete the packet from access buffer
151 MSMac->MSMetrics.nCallBlocked++;
152 memcpy(pstruEventDetails,&pevent,sizeof* pstruEventDetails);
153 }
154 }
155 else
156 {
157 NetSim_PACKET* request;
158 Cellular_PACKET* cellularPacket=calloc(1,sizeof* cellularPacket);
159 Cellular_CHANNEL_REQUEST* requestData=calloc(1,sizeof* requestData);
160 MSMac->nMSStatusFlag=Status_ChannelRequested;
161 MSMac->nApplicationId=nApplicationId;
162 MSMac->nSourceFlag=1;
166 MSMac->nBTSId,
167 1,
169 request->pstruMacData->Packet_MACProtocol=cellularPacket;
170 cellularPacket->controlData=requestData;
171 requestData->nApplicationId=nApplicationId;
172 requestData->nMSId=pstruEventDetails->nDeviceId;
173 requestData->nDestId= get_first_dest_from_packet(packet);
175 //Add packet to physical out
179 pstruEventDetails->pPacket=request;
182 MSMac->MSMetrics.nChannelRequestSent++;
183 }
184 return 1;
185}
186/** This function is called whenever PHYSICAL OUT event is triggered at the base station */
188{
192 unsigned int nTimeSlot=gsmPacket->nTimeSlot;
193 double dStartTime;
194 double dDataRate=DATA_RATE;
197
198 packet->pstruPhyData->dOverhead=0;
201 packet->pstruPhyData->dStartTime=dStartTime;
202 packet->pstruPhyData->dEndTime=dStartTime+fnGetPacketSize(packet)*8/dDataRate;
209 //Call packet trace function
211 fn_NetSim_Metrics_Add(packet);
212 return 1;
213}
214/** This function is called at the end of a call */
215int fn_NetSim_Cellular_SendCallend(NETSIM_ID nMSID,NETSIM_ID nMSInterface,NETSIM_ID nDestinationId,double time)
216{
217 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSID,nMSInterface);
218 NETSIM_ID nApplicationId=MSMac->nApplicationId;
221 nMSID,
222 nDestinationId,
223 1,
225 Cellular_PACKET* gsmPacket=calloc(1,sizeof* gsmPacket);
226 gsmPacket->nApplicationId=nApplicationId;
227 gsmPacket->nTimeSlot=MSMac->pstruAllocatedChannel->nTimeSlot;
228 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
229 //Add physical out event
232 pstruEventDetails->nApplicationId=nApplicationId;
236 pstruEventDetails->nInterfaceId=nMSInterface;
243 //Release the channel
247 else
249 return 1;
250}
unsigned int NETSIM_ID
Definition: Animation.h:45
int fn_NetSim_Cellular_FormBurst(NetSim_PACKET *packet, Cellular_MS_MAC *MSMac)
Definition: Burst.c:22
int fn_NetSim_Cellular_Run()
Definition: Cellular.c:23
int fn_NetSim_Cellular_MS_SendChannelRelease(Cellular_CHANNEL *channel, NETSIM_ID nMSId, NETSIM_ID nMSInterface, double time)
Definition: Cellular.c:666
#define CELLULAR_PACKET_TYPE(protocol, type)
Definition: Cellular.h:66
NetSim_PACKET * fn_NetSim_Cellular_createPacket(double time, unsigned int nPacketType, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double dSize, MAC_LAYER_PROTOCOL protocol)
@ Subevent_DropCall
Definition: Cellular.h:70
@ Subevent_TxNextBurst
Definition: Cellular.h:71
#define DATA_RATE
Definition: Cellular.h:31
int fn_NetSim_Cellular_FreePacket(NetSim_PACKET *packet)
int fn_NetSim_Cellular_CopyPacket(NetSim_PACKET *pstruDestPacket, NetSim_PACKET *pstruSrcPacket)
@ PacketType_ChannelRequest
Definition: Cellular.h:53
@ PacketType_CallEnd
Definition: Cellular.h:64
@ Status_IDLE
Definition: Cellular.h:42
@ Status_CallInProgress
Definition: Cellular.h:47
@ Status_CallEnd
Definition: Cellular.h:48
@ Status_ChannelRequested
Definition: Cellular.h:43
int fn_NetSim_Cellular_AddPacketToBuffer(NetSim_PACKET *packet, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: GSM.c:123
int fn_NetSim_GSM_Init_F(struct stru_NetSim_Network *NETWORK_Formal, NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
int fn_NetSim_GSM_Init(struct stru_NetSim_Network *NETWORK_Formal, NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
Definition: GSM.c:33
int fn_NetSim_Cellular_AllocateChannel(NetSim_EVENTDETAILS *pstruEventDetails, NetSim_PACKET *packet)
Definition: GSM.c:130
int fn_NetSim_GSM_Finish()
Definition: GSM.c:118
int fn_NetSim_GSM_Run()
Definition: GSM.c:58
char * fn_NetSim_GSM_ConfigPacketTrace()
Definition: GSM.c:103
int fn_NetSim_GSM_CopyPacket(NetSim_PACKET *pstruDestPacket, NetSim_PACKET *pstruSrcPacket)
Definition: GSM.c:89
int fn_NetSim_GSM_Configure_F(void **var)
int fn_NetSim_GSM_WritePacketTrace(NetSim_PACKET *pstruPacket, char **ppszTrace)
Definition: GSM.c:110
int fn_NetSim_GSM_BS_PhyOut()
Definition: GSM.c:187
int fn_NetSim_GSM_FreePacket(NetSim_PACKET *pstruPacket)
Definition: GSM.c:81
int fn_NetSim_GSM_Metrics(char *szMetrics)
Definition: GSM.c:96
int fn_NetSim_Cellular_SendCallend(NETSIM_ID nMSID, NETSIM_ID nMSInterface, NETSIM_ID nDestinationId, double time)
Definition: GSM.c:215
char * fn_NetSim_GSM_Trace(int nSubEvent)
Definition: GSM.c:66
int fn_NetSim_GSM_Metrics_F(char *szMetrics)
int fn_NetSim_GSM_Configure(void **var)
Definition: GSM.c:50
#define GSM_CARRIER_LENGTH
Definition: GSM.h:20
double fn_NetSim_GSM_GetPacketStartTime(double dCurrentTime, unsigned int nTimeSlot)
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define calloc(c, s)
Definition: Memory.h:29
double fnGetPacketSize(NetSim_PACKET *pstruData)
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
NetSim_EVENTDETAILS * pstruEventDetails_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char * pszAppPath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int nVersion_Type
Definition: RIP.h:178
NetSim_EVENTDETAILS char char * pszWritePath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int void ** fnPointer
Definition: RIP.h:178
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ MOBILESTATION
Definition: Stack.h:275
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
@ PHYSICAL_IN_EVENT
Definition: Stack.h:105
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fn_NetSim_Metrics_Add(packet)
Definition: Stack.h:998
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fn_NetSim_WritePacketTrace(pstruPacket)
Definition: main.h:188
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
Structure for Erlang_call application.
Definition: Application.h:313
int(* fn_BlockCall)(ptrAPPLICATION_INFO appInfo, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double time)
Definition: Application.h:325
Structure to store application information.
Definition: Application.h:97
NETSIM_ID nApplicationId
Definition: Cellular.h:210
Cellular_CHANNEL * pstruAllocatedChannel
Definition: Cellular.h:216
MS_STATUS nMSStatusFlag
Definition: Cellular.h:209
NETSIM_ID nApplicationId
Definition: Cellular.h:263
unsigned int nTimeSlot
Definition: Cellular.h:261
NETSIM_ID nApplicationId
Definition: Stack.h:752
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
NETSIM_ID nInterfaceId
Definition: Stack.h:751
void ** appInfo
Definition: Stack.h:739
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
struct stru_NetSim_Packet_PhyLayer * pstruPhyData
Definition: Packet.h:277
NETSIM_ID nReceiverId
Definition: Packet.h:266
NETSIM_ID nSourceId
Definition: Packet.h:263
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276