NetSim Source Code Help
Loading...
Searching...
No Matches
GSM_Channel.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 "GSM.h"
16#include "Cellular.h"
17/**
18~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 This function is called from init block for allocating the channel to each BTS if the
20 user choice is FCA (Fixed Carreir allocation).
21 This function first calculate the bandwidth allocated for the GSM
22 Bandwidth = Maximum frequency - Minimum frequency;
23
24 After that, calculate the total no of the channel.
25 Total no of channel = Bandwidth * 8 * (1000/200); // KHz to MHz.
26
27 Calculate no of channel per BTS.
28 no of channel per BTS = (Total no of channel/no of BTS).
29
30 Initiallize the channel list.
31 Allocate channel to the BTS.
32 Set, no of busy channel = 0;
33 set, no of free channel = No of channel per BTS.
34 set, Total no of channel = No of channel per BTS.
35
36 NOTE: In netSim we have only two type of channel:
37 1. Random Access Channel (RACH) First channel of each BTS.
38 2. Traffic Channel.
39
40------------------------------ Input parameters -----------------------------------------------
41
42 This function takes three parameters as input,
43 1. Minimum value of down link frequency
44 2. Maximum value of up link frequency.
45 3. No of BTS.
46 All these parameters are user input.
47
48------------------------------ Output Parameters ----------------------------------------------
49
50 This function return 1 on successfull completion
51~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52*/
54{
55 double dBandWidth;
56 unsigned int nTotalNoOfChannel, nNoOfChannelPerBTS;
57 unsigned int nLoop,nLoop1; // Loop Counter
58 Cellular_CHANNEL *tempChannel1, *tempChannel2=NULL; // Temporary channel list
59 int i=0; // For keeping track of time slot.
60 double dDLFrequencyMin,dDLFrequencyMax,dULFrequencyMin,dULFrequencyMax;
61
62 //Calculating bandwidth = Maximum - Minimum
63 dBandWidth = mscVar->gsmVar->dUpLinkBandwidthMax - mscVar->gsmVar->dUpLinkBandwidthMin;
64
65 //Calculating total number of channel
66 nTotalNoOfChannel = (int)(dBandWidth/mscVar->gsmVar->dChannelBandiwdth); // bandwidth for each channel is 200 KHz.
67 nTotalNoOfChannel = nTotalNoOfChannel*mscVar->gsmVar->nSlotCountInEachCarrier; // Each frequency have 8 time slot.
68
69 //Save the total number of channel
70 mscVar->gsmVar->nChannelCount = nTotalNoOfChannel;
71 //Calculating number of channel per BTS
72 nNoOfChannelPerBTS = nTotalNoOfChannel/mscVar->nBTSCount;
73 if(nNoOfChannelPerBTS <=1)
74 {
75 fnNetSimError("Too less channel for BTS. Increase frequency...");
76 return 0;
77 }
78 dDLFrequencyMin=mscVar->gsmVar->dDownLinkBandwidthMin;
79 dDLFrequencyMax=dDLFrequencyMin+mscVar->gsmVar->dChannelBandiwdth;
80 dULFrequencyMin=mscVar->gsmVar->dUpLinkBandwidthMin;
81 dULFrequencyMax=mscVar->gsmVar->dChannelBandiwdth+dULFrequencyMin;
82 // Loop through each BTS
83 for(nLoop = 0; nLoop < mscVar->nBTSCount; nLoop++,i++)
84 {
85 Cellular_BS_MAC* BSMAC=((Cellular_BS_MAC*)DEVICE_MACVAR(mscVar->BTSList[nLoop],1));
86 //Assign memory for channel
87 BSMAC->nChannelCount=nNoOfChannelPerBTS;
88 BSMAC->nFreeChannel=nNoOfChannelPerBTS;
89 BSMAC->nRACHChannel=1;
90 BSMAC->nTrafficChannel=nNoOfChannelPerBTS-1;
91
92 for(nLoop1=0;nLoop1<nNoOfChannelPerBTS;nLoop1++)
93 {
94 tempChannel1=calloc(1,sizeof* tempChannel1);
95 tempChannel1->dDownLinkMaximumFreqency=dDLFrequencyMax;
96 tempChannel1->dDownLinkMinimumFrequency=dDLFrequencyMin;
97 tempChannel1->dUpLinkMaximumFrequency=dULFrequencyMax;
98 tempChannel1->dUpLinkMinimumFrequency=dULFrequencyMin;
99 tempChannel1->nChannelId=nLoop1+1;
100 if(nLoop1)
102 else
103 tempChannel1->nChannelType=ChannelType_RACH;
104 tempChannel1->nTimeSlot=i;
105 if(BSMAC->pstruChannelList)
106 {
107 tempChannel2->pstru_NextChannel=tempChannel1;
108 tempChannel2=tempChannel1;
109 }
110 else
111 {
112 tempChannel2=tempChannel1;
113 BSMAC->pstruChannelList=tempChannel1;
114 }
115 i++;
116 if(i==mscVar->gsmVar->nSlotCountInEachCarrier)
117 {
118 dDLFrequencyMax += mscVar->gsmVar->dChannelBandiwdth;
119 dDLFrequencyMin += mscVar->gsmVar->dChannelBandiwdth;
120 dULFrequencyMax += mscVar->gsmVar->dChannelBandiwdth;
121 dULFrequencyMin += mscVar->gsmVar->dChannelBandiwdth;
122 i=0;
123 }
124 }
125 }
126 return 1;
127}
128/** This function is used to check whether cellular channel is allocated or not */
129int isCellularChannelAllocated(NETSIM_ID nMSId,NETSIM_ID nInterfaceId,NETSIM_ID nApplicationId)
130{
131 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSId,nInterfaceId);
132 if(MSMac->pstruAllocatedChannel)
133 {
135 while(channel)
136 {
137 if(channel->nMSId == nMSId && channel->nApplicationId==nApplicationId && channel->nAllocationFlag)
138 return 1;
139 channel=channel->pstru_NextChannel;
140 }
141 }
142 return 0;
143}
unsigned int NETSIM_ID
Definition: Animation.h:45
@ ChannelType_TRAFFICCHANNEL
Definition: Cellular.h:37
@ ChannelType_RACH
Definition: Cellular.h:36
int fn_NetSim_FormGSMChannel(DEVVAR_MSC *mscVar)
Definition: GSM_Channel.c:53
int isCellularChannelAllocated(NETSIM_ID nMSId, NETSIM_ID nInterfaceId, NETSIM_ID nApplicationId)
Definition: GSM_Channel.c:129
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define calloc(c, s)
Definition: Memory.h:29
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
struct stru_Cellular_ChannelList * pstruChannelList
Definition: Cellular.h:175
unsigned int nTrafficChannel
Definition: Cellular.h:174
struct stru_Cellular_ChannelList * pstru_NextChannel
Definition: Cellular.h:145
CELLULAR_CHANNEL_TYPE nChannelType
Definition: Cellular.h:137
double dDownLinkMinimumFrequency
Definition: Cellular.h:111
Cellular_CHANNEL * pstruAllocatedChannel
Definition: Cellular.h:216
MSC_GSM * gsmVar
Definition: Cellular.h:185
unsigned int nBTSCount
Definition: Cellular.h:181
NETSIM_ID * BTSList
Definition: Cellular.h:183
unsigned int nSlotCountInEachCarrier
Definition: GSM.h:33
unsigned int nChannelCount
Definition: GSM.h:34
double dChannelBandiwdth
Definition: GSM.h:32
double dDownLinkBandwidthMin
Definition: GSM.h:31
double dUpLinkBandwidthMax
Definition: GSM.h:28
double dUpLinkBandwidthMin
Definition: GSM.h:29