NetSim Source Code Help
Loading...
Searching...
No Matches
Generic_RateAdaptation.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"
27
28#define RATE_UP_INDEX 19
29#define RATE_DOWN_INDEX 3
30typedef struct
31{
32 unsigned int maxPhyindex;
33 unsigned int minPhyindex;
34 unsigned int* currentPhyindex;
38
40{
42}
43
45{
46 IEEE802_11_PHY(devid,ifid)->rateAdaptationData = rate;
47}
48
50{
52 if(rate)
53 {
55 free(rate->currentPhyindex);
57 free(rate);
58 phy->rateAdaptationData=NULL;
59 }
60}
61
62unsigned int get_max_phy_index(NETSIM_ID devid,NETSIM_ID ifid)
63{
64 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(devid,ifid);
65 switch(phy->PhyProtocol)
66 {
67 case IEEE_802_11a:
68 case IEEE_802_11g:
69 case IEEE_802_11p:
71 case IEEE_802_11b:
73 case IEEE_802_11n:
74 case IEEE_802_11ac:
76 default:
77 fnNetSimError("Unknown phy protocol %d in %s.\n",phy->PhyProtocol,__FUNCTION__);
78 return 0;
79 }
80}
81
82static unsigned int get_min_phy_index(NETSIM_ID devid,NETSIM_ID ifid)
83{
84 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(devid,ifid);
85 switch(phy->PhyProtocol)
86 {
87 case IEEE_802_11a:
88 case IEEE_802_11g:
89 case IEEE_802_11p:
91 case IEEE_802_11b:
93 case IEEE_802_11n:
94 case IEEE_802_11ac:
96 default:
97 fnNetSimError("Unknown phy protocol %d in %s.\n",phy->PhyProtocol,__FUNCTION__);
98 return 0;
99 }
100}
101
103{
104 NETSIM_ID i;
106 set_rate_adaptation_data(nDevId,nifid,rate);
107
109 rate->currentPhyindex=(unsigned int*)calloc(NETWORK->nDeviceCount+1,sizeof* rate->currentPhyindex);
111
112 rate->maxPhyindex = get_max_phy_index(nDevId,nifid);
113 rate->minPhyindex = get_min_phy_index(nDevId,nifid);
114 for(i=0;i<=NETWORK->nDeviceCount;i++)
115 rate->currentPhyindex[i]=rate->maxPhyindex;
116}
117
119{
121
122 rate->currentDroppedCount[rcvid]++;
123 //printf("\nDrop count -- %d\n",rate->currentDroppedCount[rcvid]);
124 if(rate->currentDroppedCount[rcvid] > RATE_DOWN_INDEX)
125 {
126 if(rate->currentPhyindex[rcvid] > rate->minPhyindex)
127 rate->currentPhyindex[rcvid]--;
128 rate->currentDroppedCount[rcvid]=0;
129 //printf("\nIndex for %d to %d is %d\n",devid,rcvid,rate->currentPhyindex[rcvid]);
130 }
131 rate->currentReceivedCount[rcvid] = 0;
132}
133
135{
137 rate->currentReceivedCount[rcvid]++;
138 //printf("\nReceive count -- %d\n",rate->currentReceivedCount[rcvid]);
139 if(rate->currentReceivedCount[rcvid] > RATE_UP_INDEX)
140 {
141 if(rate->currentPhyindex[rcvid] < rate->maxPhyindex)
142 rate->currentPhyindex[rcvid]++;
143 rate->currentReceivedCount[rcvid]=0;
144 //printf("\nIndex for %d to %d is %d\n",devid,rcvid,rate->currentPhyindex[rcvid]);
145 }
146 rate->currentDroppedCount[rcvid] = 0;
147}
148
149unsigned int get_rate_index(NETSIM_ID devid,NETSIM_ID ifid,NETSIM_ID rcvid)
150{
151 return get_rate_adaptation_data(devid,ifid)->currentPhyindex[rcvid];
152}
unsigned int NETSIM_ID
Definition: Animation.h:45
void packet_recv_notify(NETSIM_ID devid, NETSIM_ID ifid, NETSIM_ID rcvid)
unsigned int get_rate_index(NETSIM_ID devid, NETSIM_ID ifid, NETSIM_ID rcvid)
void Generic_Rate_adaptation_init(NETSIM_ID nDevId, NETSIM_ID nifid)
unsigned int get_max_phy_index(NETSIM_ID devid, NETSIM_ID ifid)
void packet_drop_notify(NETSIM_ID devid, NETSIM_ID ifid, NETSIM_ID rcvid)
void free_rate_adaptation_data(PIEEE802_11_PHY_VAR phy)
#define RATE_UP_INDEX
static unsigned int get_min_phy_index(NETSIM_ID devid, NETSIM_ID ifid)
#define RATE_DOWN_INDEX
static PGENERIC_RATE_ADAPTATION get_rate_adaptation_data(NETSIM_ID devid, NETSIM_ID ifid)
static void set_rate_adaptation_data(NETSIM_ID devid, NETSIM_ID ifid, PGENERIC_RATE_ADAPTATION rate)
struct GENERIC_RATE_ADAPTATION * PGENERIC_RATE_ADAPTATION
PIEEE802_11_PHY_VAR IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
unsigned int get_ofdm_phy_min_index()
unsigned int get_ofdm_phy_max_index()
@ IEEE_802_11ac
Definition: IEEE802_11.h:72
@ IEEE_802_11b
Definition: IEEE802_11.h:67
@ IEEE_802_11n
Definition: IEEE802_11.h:70
@ IEEE_802_11g
Definition: IEEE802_11.h:68
@ IEEE_802_11p
Definition: IEEE802_11.h:69
@ IEEE_802_11a
Definition: IEEE802_11.h:66
unsigned int get_dsss_phy_min_index()
unsigned int get_dsss_phy_max_index()
unsigned int get_ht_phy_max_index(IEEE802_11_PROTOCOL protocol, UINT dGI)
unsigned int get_ht_phy_min_index(IEEE802_11_PROTOCOL protocol, UINT dGI)
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
IEEE802_11_PROTOCOL PhyProtocol