NetSim Source Code Help
Loading...
Searching...
No Matches
RTS_CTS.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
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* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#include "main.h"
25#include "IEEE802_11.h"
26#include "IEEE802_11_Phy.h"
28
30{
31 mac;
32 return ceil(2 * (double)phy->plmeCharacteristics.aSIFSTime
34 + ((getCTSSize() * 8) / phy->dControlFrameDataRate));
35}
36
38 NETSIM_ID txIf,
39 NetSim_PACKET* packet)
40{
41 NETSIM_ID rxId = packet->nReceiverId;
42 NETSIM_ID rxIf = fn_NetSim_Stack_GetConnectedInterface(txId, txIf, rxId);
43
44 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(txId, txIf);
45 fn_NetSim_IEEE802_11_SetDataRate(txId, txIf, rxId, rxIf, packet, pstruEventDetails->dEventTime);
48 packet->pstruMacData->dPayload),
49 txId,
50 txIf);
51 double ctsTime = (getCTSSize() * 8.0) / phy->dControlFrameDataRate;
52 double ackTime = (getAckSize(phy) * 8.0) / phy->dControlFrameDataRate;
53 double rtsTime = (getRTSSize()*8.0) / phy->dBroadcastFrameDataRate;
54
55 return ceil(get_preamble_time(phy) +
56 rtsTime +
59 ctsTime +
62 packetTime +
65 ackTime);
66}
67
69 NETSIM_ID i,
70 double rtsduration)
71{
73 double rtsTime = (getRTSSize() * 8.0) / phy->dControlFrameDataRate;
74 return ceil(rtsduration -
77 rtsTime));
78}
79
81{
82 double d=0;
83 NetSim_PACKET* p=IEEE802_11_CURR_MAC->currentProcessingPacket;
84
86 return false; //Broadcast or multicast packet
87
89 return false; //No RTS CTS for IEEE802.11 control packet
90 while(p)
91 {
93 p=p->pstruNextPacket;
94 }
95 return (d >= IEEE802_11_CURR_MAC->dot11RTSThreshold);
96}
97
99{
101
103 return; //NO RTS-CTS
104
110
111 mac->metrics.nRTSSentCount++;
112
113 //Update the packet processing time
115
116}
117
119{
125
126 IEEE802_11_CURR_MAC->metrics.nRTSReceivedCount++;
127}
128
130{
133 {
134 //Virtual CS Condition
136 return;
137 }
138
140 //Free the RTS packet
142
143 //Send CTS to phy
147 pstruEventDetails->pPacket = packet;
149
150 IEEE802_11_CURR_MAC->metrics.nCTSSentCount++;
151}
152
154{
156
157 NetSim_EVENTDETAILS pevent;
158 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(devId,devIf);
160 double ctstime;
161
162 ctstime = ceil(packet->pstruPhyData->dStartTime
164 + get_preamble_time(phy)
165 + ((getCTSSize() * 8)/phy->dControlFrameDataRate));
166
167 pevent.dEventTime=ctstime+2;
168 pevent.dPacketSize=0;
169 pevent.nDeviceId=devId;
170 pevent.nDeviceType=DEVICE_TYPE(devId);
171 pevent.nEventType=TIMER_EVENT;
172 pevent.nInterfaceId= hdr->sendInterfaceId;
173 pevent.nPacketId=packet->nPacketId;
175 if(packet->pstruAppData)
176 {
177 pevent.nSegmentId=packet->pstruAppData->nSegmentId;
179 }
180 else
181 {
182 pevent.nSegmentId=0;
183 pevent.nApplicationId=0;
184 }
185 pevent.nSubEventType=CTS_TIMEOUT;
186 pevent.pPacket=NULL;
187 pevent.szOtherDetails=NULL;
188 mac->EVENTID.ctsTimeout = fnpAddEvent(&pevent);
189}
190
192{
196 {
197 mac->nRetryCount++;
200 }
201 else
202 {
203 if (mac->waitingforCTS)
204 {
205 NetSim_PACKET* pstruPacket = mac->waitingforCTS;
206
207 if (pstruPacket->DropNotification)
208 pstruPacket->DropNotification(pstruPacket);
211 mac->currentProcessingPacket = NULL;
212 mac->waitingforCTS = NULL;
213 }
214 mac->nRetryCount = 0;
216 }
217}
218
220{
225 mac->waitingforCTS=NULL;
227 //Free CTS packet
230
232 pstruEventDetails->nSubEventType = SEND_MPDU;
235 {
238 }
239 else
240 {
243 }
247}
unsigned int NETSIM_ID
Definition: Animation.h:45
bool fn_NetSim_IEEE802_11_CSMACA_CheckRetryLimit(PIEEE802_11_MAC_VAR mac, UINT frameLength)
Definition: CSMACA.c:646
int fn_NetSim_IEEE802_11_CSMACA_Init()
Definition: CSMACA.c:48
void fn_NetSim_IEEE802_11_CSMACA_IncreaseCW(PIEEE802_11_MAC_VAR mac)
Definition: CSMACA.c:671
PIEEE802_11_MAC_VAR IEEE802_11_MAC(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
PIEEE802_11_PHY_VAR IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
NetSim_PACKET * fn_NetSim_IEEE802_11_CreateCTSPacket(NetSim_PACKET *data)
double getAckSize(void *phy)
@ IEEE802_11_MACSTATE_TXing_CTS
Definition: IEEE802_11.h:163
@ IEEE802_11_MACSTATE_MAC_IDLE
Definition: IEEE802_11.h:154
@ IEEE802_11_MACSTATE_TXing_MPDU
Definition: IEEE802_11.h:159
double getMacOverhead(void *phy, double size)
NetSim_PACKET * fn_NetSim_IEEE802_11_CreateRTSPacket(NetSim_PACKET *data, double duration)
void IEEE802_11_Change_Mac_State(PIEEE802_11_MAC_VAR mac, IEEE802_11_MAC_STATE state)
double getCTSSize()
bool isIEEE802_11_CtrlPacket(NetSim_PACKET *packet)
double getRTSSize()
#define IEEE802_11_CURR_MAC
Definition: IEEE802_11.h:285
int fn_NetSim_IEEE802_11_SetDataRate(NETSIM_ID txId, NETSIM_ID txIf, NETSIM_ID rxId, NETSIM_ID rxIf, NetSim_PACKET *packet, double time)
double fn_NetSim_IEEE802_11_CalculateTransmissionTime(double size, NETSIM_ID nDevId, NETSIM_ID nInterfaceId)
double get_preamble_time(PIEEE802_11_PHY_VAR phy)
#define IEEE802_11_CURR_PHY
#define ackTime(phy)
Definition: Minstrel.c:33
bool isMulticastPacket(NetSim_PACKET *packet)
bool isBroadcastPacket(NetSim_PACKET *packet)
void fn_NetSim_IEEE802_11_RTS_CTS_Init()
Definition: RTS_CTS.c:98
void fn_NetSim_IEEE802_11_RTS_CTS_SendCTS()
Definition: RTS_CTS.c:129
double calculate_CTS_duration(NETSIM_ID d, NETSIM_ID i, double rtsduration)
Definition: RTS_CTS.c:68
void fn_NetSim_IEEE802_11_RTS_CTS_AddCTSTimeOut(NetSim_PACKET *packet, NETSIM_ID devId, NETSIM_ID devIf)
Definition: RTS_CTS.c:153
static bool decide_RTS_CTS_Mechanism()
Definition: RTS_CTS.c:80
static double get_RTS_CTS_Time(PIEEE802_11_MAC_VAR mac, PIEEE802_11_PHY_VAR phy)
Definition: RTS_CTS.c:29
void fn_NetSim_IEEE802_11_RTS_CTS_ProcessCTS()
Definition: RTS_CTS.c:219
void fn_NetSim_IEEE802_11_RTS_CTS_ProcessRTS()
Definition: RTS_CTS.c:118
void fn_NetSim_IEEE802_11_RTS_CTS_CTSTimeOut()
Definition: RTS_CTS.c:191
double calculate_RTS_duration(NETSIM_ID txId, NETSIM_ID txIf, NetSim_PACKET *packet)
Definition: RTS_CTS.c:37
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ MAC_PROTOCOL_IEEE802_11
Definition: Stack.h:208
@ TIMER_EVENT
Definition: Stack.h:114
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
@ MAC_OUT_EVENT
Definition: Stack.h:106
int fnDeleteEvent(unsigned long long int nEventId)
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
NETSIM_ID fn_NetSim_Stack_GetConnectedInterface(NETSIM_ID devId, NETSIM_ID ifid, NETSIM_ID conId)
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
long long int ctsTimeout
Definition: IEEE802_11.h:277
double dPacketProcessingEndTime
Definition: IEEE802_11.h:268
NetSim_PACKET * waitingforCTS
Definition: IEEE802_11.h:257
NetSim_PACKET * currentProcessingPacket
Definition: IEEE802_11.h:256
IEEE802_11_METRICS metrics
Definition: IEEE802_11.h:281
struct stru_802_11_Mac_Var::@0 EVENTID
PLME_CHARACTERISTICS plmeCharacteristics
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
long long int nPacketId
Definition: Packet.h:256
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
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
int(* DropNotification)(struct stru_NetSim_Packet *packet)
Definition: Packet.h:281
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276