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
"
16
unsigned
int
nBurstId
=0;
17
/**
18
Burst is used for the standard communications between the basestation and the mobile, and typically
19
transfers the digitised voice data.
20
This function is used to form the burst.
21
*/
22
int
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
/**
147
This function is used to reassemble the burst.
148
*/
149
int
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
}
NETSIM_ID
unsigned int NETSIM_ID
Definition:
Animation.h:45
fn_NetSim_Cellular_FormBurst
int fn_NetSim_Cellular_FormBurst(NetSim_PACKET *packet, Cellular_MS_MAC *MSMac)
Definition:
Burst.c:22
nBurstId
unsigned int nBurstId
Definition:
Burst.c:16
fn_NetSim_Cellular_MS_ReassembleBurst
int fn_NetSim_Cellular_MS_ReassembleBurst()
Definition:
Burst.c:149
Cellular.h
GSM_OVERHEAD
#define GSM_OVERHEAD
Definition:
GSM.h:18
GSM_PAYLOAD
#define GSM_PAYLOAD
Definition:
GSM.h:17
calloc
#define calloc(c, s)
Definition:
Memory.h:29
fnGetPacketSize
double fnGetPacketSize(NetSim_PACKET *pstruData)
get_first_dest_from_packet
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
fn_NetSim_Stack_GetNWProtocol
NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWProtocol(NETSIM_ID nDeviceId)
MAC_PROTOCOL_GSM
@ MAC_PROTOCOL_GSM
Definition:
Stack.h:218
MAC_PROTOCOL_CDMA
@ MAC_PROTOCOL_CDMA
Definition:
Stack.h:217
NETWORK
EXPORTED struct stru_NetSim_Network * NETWORK
Definition:
Stack.h:742
NETWORK_IN_EVENT
@ NETWORK_IN_EVENT
Definition:
Stack.h:109
PHYSICAL_OUT_EVENT
@ PHYSICAL_OUT_EVENT
Definition:
Stack.h:104
pstruEventDetails
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition:
Stack.h:837
DEVICE_PHYLAYER
#define DEVICE_PHYLAYER(DeviceId, InterfaceId)
Definition:
Stack.h:788
main.h
fn_NetSim_Packet_CopyPacket
#define fn_NetSim_Packet_CopyPacket(pstruPacket)
Definition:
main.h:182
fn_NetSim_Packet_FreePacket
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition:
main.h:177
fnpAddEvent
#define fnpAddEvent(pstruEvent)
Definition:
main.h:191
stru_Cellular_ChannelList
Definition:
Cellular.h:104
stru_Cellular_ChannelList::nTimeSlot
int nTimeSlot
Definition:
Cellular.h:113
stru_Cellular_ChannelList::nDestId
NETSIM_ID nDestId
Definition:
Cellular.h:128
stru_Cellular_ChannelList::nMSId
NETSIM_ID nMSId
Definition:
Cellular.h:122
stru_Cellular_ChannelList::nApplicationId
int nApplicationId
Definition:
Cellular.h:130
stru_Cellular_MS_Mac
Definition:
Cellular.h:204
stru_Cellular_MS_Mac::pstruPacketList
NetSim_PACKET **** pstruPacketList
Definition:
Cellular.h:219
stru_Cellular_MS_Mac::pstruAllocatedChannel
Cellular_CHANNEL * pstruAllocatedChannel
Definition:
Cellular.h:216
stru_Cellular_Packet
Definition:
Cellular.h:260
stru_Cellular_Packet::nId
unsigned int nId
Definition:
Cellular.h:266
stru_Cellular_Packet::originalPacket
NetSim_PACKET * originalPacket
Definition:
Cellular.h:267
stru_Cellular_Packet::nApplicationId
NETSIM_ID nApplicationId
Definition:
Cellular.h:263
stru_Cellular_Packet::nTimeSlot
unsigned int nTimeSlot
Definition:
Cellular.h:261
stru_Cellular_Packet::isLast
unsigned int isLast
Definition:
Cellular.h:265
stru_NetSim_EventDetails::nApplicationId
NETSIM_ID nApplicationId
Definition:
Stack.h:752
stru_NetSim_EventDetails::nEventType
EVENT_TYPE nEventType
Definition:
Stack.h:747
stru_NetSim_EventDetails::nProtocolId
NETSIM_ID nProtocolId
Definition:
Stack.h:748
stru_NetSim_EventDetails::pPacket
struct stru_NetSim_Packet * pPacket
Definition:
Stack.h:754
stru_NetSim_EventDetails::nDeviceId
NETSIM_ID nDeviceId
Definition:
Stack.h:750
stru_NetSim_EventDetails::nPacketId
long long int nPacketId
Definition:
Stack.h:755
stru_NetSim_EventDetails::nInterfaceId
NETSIM_ID nInterfaceId
Definition:
Stack.h:751
stru_NetSim_EventDetails::dEventTime
double dEventTime
Definition:
Stack.h:746
stru_NetSim_EventDetails::nSegmentId
int nSegmentId
Definition:
Stack.h:756
stru_NetSim_EventDetails::dPacketSize
double dPacketSize
Definition:
Stack.h:753
stru_NetSim_Network::nDeviceCount
UINT nDeviceCount
Definition:
Stack.h:734
stru_NetSim_Network::nApplicationCount
UINT nApplicationCount
Definition:
Stack.h:736
stru_NetSim_Packet_AppLayer::dPayload
double dPayload
Definition:
Packet.h:168
stru_NetSim_Packet_AppLayer::nSegmentId
int nSegmentId
Definition:
Packet.h:161
stru_NetSim_Packet_AppLayer::nApplicationId
NETSIM_ID nApplicationId
Definition:
Packet.h:162
stru_NetSim_Packet_MACLayer::dStartTime
double dStartTime
Definition:
Packet.h:215
stru_NetSim_Packet_MACLayer::dPayload
double dPayload
Definition:
Packet.h:218
stru_NetSim_Packet_MACLayer::nMACProtocol
MAC_LAYER_PROTOCOL nMACProtocol
Definition:
Packet.h:223
stru_NetSim_Packet_MACLayer::Packet_MACProtocol
void * Packet_MACProtocol
Definition:
Packet.h:224
stru_NetSim_Packet_MACLayer::dOverhead
double dOverhead
Definition:
Packet.h:219
stru_NetSim_Packet_MACLayer::dArrivalTime
double dArrivalTime
Definition:
Packet.h:214
stru_NetSim_Packet_MACLayer::dEndTime
double dEndTime
Definition:
Packet.h:216
stru_NetSim_Packet_MACLayer::dPacketSize
double dPacketSize
Definition:
Packet.h:217
stru_NetSim_Packet_NetworkLayer::dPayload
double dPayload
Definition:
Packet.h:196
stru_NetSim_Packet_NetworkLayer::dEndTime
double dEndTime
Definition:
Packet.h:194
stru_NetSim_Packet_NetworkLayer::dPacketSize
double dPacketSize
Definition:
Packet.h:195
stru_NetSim_Packet_TransportLayer::dPayload
double dPayload
Definition:
Packet.h:182
stru_NetSim_Packet
Definition:
Packet.h:255
stru_NetSim_Packet::nPacketId
long long int nPacketId
Definition:
Packet.h:256
stru_NetSim_Packet::pstruAppData
struct stru_NetSim_Packet_AppLayer * pstruAppData
Definition:
Packet.h:273
stru_NetSim_Packet::pstruNetworkData
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition:
Packet.h:275
stru_NetSim_Packet::pstruNextPacket
struct stru_NetSim_Packet * pstruNextPacket
Definition:
Packet.h:278
stru_NetSim_Packet::pstruTransportData
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
Definition:
Packet.h:274
stru_NetSim_Packet::nSourceId
NETSIM_ID nSourceId
Definition:
Packet.h:263
stru_NetSim_Packet::pstruMacData
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition:
Packet.h:276
ALL
Component 2
Cellular
Burst.c
Generated on Fri Dec 9 2022 10:22:46 for NetSim Source Code Help by
1.9.5