NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Burst.c
1/************************************************************************************
2 * Copyright (C) 2023 *
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"
16unsigned int nBurstId=0;
17/**
18Burst is used for the standard communications between the basestation and the mobile, and typically
19transfers the digitised voice data.
20This function is used to form the burst.
21*/
22int fn_NetSim_Cellular_FormBurst(NetSim_PACKET* packet,Cellular_MS_MAC* MSMac)
23{
24 unsigned int flag=0;
25 double dPacketSize;
26 NetSim_PACKET* temp,*temp1;
27 NETSIM_ID nApplicationId=packet->pstruAppData->nApplicationId;
28 NETSIM_ID nSourceId=packet->nSourceId;
29 NETSIM_ID nDestinationId = get_first_dest_from_packet(packet);
30 if(MSMac->pstruPacketList==NULL)
31 {
32 NETSIM_ID i,j;
33 MSMac->pstruPacketList=calloc(NETWORK->nApplicationCount+1,sizeof* MSMac->pstruPacketList);
34 for(i=0;i<NETWORK->nApplicationCount+1;i++)
35 {
36 MSMac->pstruPacketList[i]=calloc(NETWORK->nDeviceCount,sizeof* MSMac->pstruPacketList[i]);
37 for(j=0;j<NETWORK->nDeviceCount;j++)
38 {
39 MSMac->pstruPacketList[i][j]=calloc(NETWORK->nDeviceCount,sizeof* MSMac->pstruPacketList[i][j]);
40 }
41 }
42 }
43 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
44 {
45 dPacketSize=packet->pstruNetworkData->dPacketSize;
46 nBurstId++;
47 temp1=MSMac->pstruPacketList[nApplicationId][nSourceId-1][nDestinationId-1];
48 if(temp1==NULL)flag=1;
49 while(temp1 && temp1->pstruNextPacket)
50 temp1=temp1->pstruNextPacket;//move last
51 while(dPacketSize>0)
52 {
53 Cellular_PACKET* gsmPacket=calloc(1,sizeof* gsmPacket);
54 temp=fn_NetSim_Packet_CopyPacket(packet);
55 temp->pstruMacData->dArrivalTime=packet->pstruNetworkData->dEndTime;
56 if(dPacketSize>=GSM_PAYLOAD)
57 {
58 temp->pstruMacData->dPayload=GSM_PAYLOAD;
59 temp->pstruAppData->dPayload=GSM_PAYLOAD;
60 temp->pstruTransportData->dPayload=GSM_PAYLOAD;
61 temp->pstruNetworkData->dPayload=GSM_PAYLOAD;
62 }
63 else
64 {
65 temp->pstruMacData->dPayload=dPacketSize;
66 temp->pstruAppData->dPayload=dPacketSize;
67 temp->pstruTransportData->dPayload=dPacketSize;
68 temp->pstruNetworkData->dPayload=dPacketSize;
69 }
70 dPacketSize-=GSM_PAYLOAD;
71 temp->pstruMacData->nMACProtocol=MAC_PROTOCOL_GSM;
72 temp->pstruMacData->Packet_MACProtocol=gsmPacket;
73 gsmPacket->nId=nBurstId;
74 gsmPacket->originalPacket=packet;
75 gsmPacket->nApplicationId=nApplicationId;
76 if(dPacketSize<=0)
77 gsmPacket->isLast=1;
78 if(temp1)
79 {
80 temp1->pstruNextPacket=temp;
81 temp1=temp;
82 }
83 else
84 {
85 temp1=temp;
86 MSMac->pstruPacketList[nApplicationId][nSourceId-1][nDestinationId-1]=temp;
87 }
88 }
89 }
90 else if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_CDMA)
91 {
92 Cellular_PACKET* gsmPacket=calloc(1,sizeof* gsmPacket);
93 temp1=MSMac->pstruPacketList[nApplicationId][nSourceId-1][nDestinationId-1];
94 if(temp1==NULL)flag=1;
95 while(temp1 && temp1->pstruNextPacket)
96 temp1=temp1->pstruNextPacket;//move last
97 temp=packet;
98 temp->pstruMacData->dArrivalTime=packet->pstruNetworkData->dEndTime;
99 temp->pstruMacData->dPayload=packet->pstruNetworkData->dPacketSize;
100 temp->pstruMacData->nMACProtocol=MAC_PROTOCOL_CDMA;
101 temp->pstruMacData->Packet_MACProtocol=gsmPacket;
102 gsmPacket->nId=1;
103 gsmPacket->originalPacket=packet;
104 gsmPacket->nApplicationId=nApplicationId;
105 gsmPacket->isLast=1;
106 if(temp1)
107 {
108 temp1->pstruNextPacket=temp;
109 temp1=temp;
110 }
111 else
112 {
113 temp1=temp;
114 MSMac->pstruPacketList[nApplicationId][nSourceId-1][nDestinationId-1]=temp;
115 }
116 }
117 if(flag && MSMac->pstruAllocatedChannel)
118 {
119 //Transmit next packet
120 Cellular_PACKET* gsmPacket;
121 Cellular_CHANNEL* channel=MSMac->pstruAllocatedChannel;
122 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->nApplicationId][channel->nMSId-1][channel->nDestId-1];
123 packet->pstruMacData->dEndTime=pstruEventDetails->dEventTime;
124 if(pstruEventDetails->nProtocolId==MAC_PROTOCOL_GSM)
125 packet->pstruMacData->dOverhead=GSM_OVERHEAD;
126 else
127 packet->pstruMacData->dOverhead=0;
128 packet->pstruMacData->dPacketSize=packet->pstruMacData->dOverhead+packet->pstruMacData->dPayload;
129 packet->pstruMacData->dStartTime=pstruEventDetails->dEventTime;
130 gsmPacket=packet->pstruMacData->Packet_MACProtocol;
131 gsmPacket->nTimeSlot=channel->nTimeSlot;
132 //Write physical out event
133 if(DEVICE_PHYLAYER(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)->dLastPacketEndTime>pstruEventDetails->dEventTime)
134 pstruEventDetails->dEventTime=DEVICE_PHYLAYER(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)->dLastPacketEndTime;
135 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
136 pstruEventDetails->nApplicationId=packet->pstruAppData->nApplicationId;
137 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
138 pstruEventDetails->nPacketId=packet->nPacketId;
139 pstruEventDetails->nSegmentId=packet->pstruAppData->nSegmentId;
140 pstruEventDetails->pPacket=packet;
141 fnpAddEvent(pstruEventDetails);
142 MSMac->pstruPacketList[channel->nApplicationId][channel->nMSId-1][channel->nDestId-1]=MSMac->pstruPacketList[channel->nApplicationId][channel->nMSId-1][channel->nDestId-1]->pstruNextPacket;
143 }
144 return 1;
145}
146/**
147This function is used to reassemble the burst.
148*/
149int fn_NetSim_Cellular_MS_ReassembleBurst()
150{
151 NetSim_PACKET* temp=pstruEventDetails->pPacket;
152 Cellular_PACKET* gsmPacket=pstruEventDetails->pPacket->pstruMacData->Packet_MACProtocol;
153 if(gsmPacket->isLast)
154 {
155 NetSim_PACKET* packet=gsmPacket->originalPacket;
156 //add network in event
157 pstruEventDetails->dPacketSize=fnGetPacketSize(packet);
158 pstruEventDetails->nEventType=NETWORK_IN_EVENT;
159 pstruEventDetails->nPacketId=packet->nPacketId;
160 pstruEventDetails->nProtocolId=fn_NetSim_Stack_GetNWProtocol(pstruEventDetails->nDeviceId);
161 pstruEventDetails->pPacket=packet;
162 fnpAddEvent(pstruEventDetails);
163 }
164 if(temp->pstruMacData->nMACProtocol==MAC_PROTOCOL_GSM)
165 fn_NetSim_Packet_FreePacket(temp);
166 return 1;
167}