NetSim Source Code Help
Loading...
Searching...
No Matches
Burst.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"
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*/
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;
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 }
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);
56 if(dPacketSize>=GSM_PAYLOAD)
57 {
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;
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 }
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;
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;
122 NetSim_PACKET* packet=MSMac->pstruPacketList[channel->nApplicationId][channel->nMSId-1][channel->nDestId-1];
126 else
127 packet->pstruMacData->dOverhead=0;
130 gsmPacket=packet->pstruMacData->Packet_MACProtocol;
131 gsmPacket->nTimeSlot=channel->nTimeSlot;
132 //Write physical out event
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*/
150{
153 if(gsmPacket->isLast)
154 {
155 NetSim_PACKET* packet=gsmPacket->originalPacket;
156 //add network in event
163 }
166 return 1;
167}
unsigned int NETSIM_ID
Definition: Animation.h:45
int fn_NetSim_Cellular_FormBurst(NetSim_PACKET *packet, Cellular_MS_MAC *MSMac)
Definition: Burst.c:22
unsigned int nBurstId
Definition: Burst.c:16
int fn_NetSim_Cellular_MS_ReassembleBurst()
Definition: Burst.c:149
#define GSM_OVERHEAD
Definition: GSM.h:18
#define GSM_PAYLOAD
Definition: GSM.h:17
#define calloc(c, s)
Definition: Memory.h:29
double fnGetPacketSize(NetSim_PACKET *pstruData)
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWProtocol(NETSIM_ID nDeviceId)
@ MAC_PROTOCOL_GSM
Definition: Stack.h:218
@ MAC_PROTOCOL_CDMA
Definition: Stack.h:217
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
@ NETWORK_IN_EVENT
Definition: Stack.h:109
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define DEVICE_PHYLAYER(DeviceId, InterfaceId)
Definition: Stack.h:788
#define fn_NetSim_Packet_CopyPacket(pstruPacket)
Definition: main.h:182
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
NetSim_PACKET **** pstruPacketList
Definition: Cellular.h:219
Cellular_CHANNEL * pstruAllocatedChannel
Definition: Cellular.h:216
unsigned int nId
Definition: Cellular.h:266
NetSim_PACKET * originalPacket
Definition: Cellular.h:267
NETSIM_ID nApplicationId
Definition: Cellular.h:263
unsigned int nTimeSlot
Definition: Cellular.h:261
unsigned int isLast
Definition: Cellular.h:265
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 nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
NETSIM_ID nInterfaceId
Definition: Stack.h:751
UINT nApplicationCount
Definition: Stack.h:736
MAC_LAYER_PROTOCOL nMACProtocol
Definition: Packet.h:223
long long int nPacketId
Definition: Packet.h:256
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition: Packet.h:273
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
Definition: Packet.h:274
NETSIM_ID nSourceId
Definition: Packet.h:263
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276