25#include "IEEE802_11.h"
26#include "IEEE802_11_Phy.h"
28#define RATE_UP_INDEX 19
29#define RATE_DOWN_INDEX 3
32 unsigned int maxPhyindex;
33 unsigned int minPhyindex;
34 unsigned int* currentPhyindex;
35 int* currentDroppedCount;
36 int* currentReceivedCount;
39static PGENERIC_RATE_ADAPTATION get_rate_adaptation_data(NETSIM_ID devid,NETSIM_ID ifid)
41 return (PGENERIC_RATE_ADAPTATION)(IEEE802_11_PHY(devid,ifid)->rateAdaptationData);
44static void set_rate_adaptation_data(NETSIM_ID devid,NETSIM_ID ifid,PGENERIC_RATE_ADAPTATION rate)
46 IEEE802_11_PHY(devid,ifid)->rateAdaptationData = rate;
49void free_rate_adaptation_data(PIEEE802_11_PHY_VAR phy)
51 PGENERIC_RATE_ADAPTATION rate = (PGENERIC_RATE_ADAPTATION)phy->rateAdaptationData;
54 free(rate->currentDroppedCount);
55 free(rate->currentPhyindex);
56 free(rate->currentReceivedCount);
58 phy->rateAdaptationData=NULL;
62unsigned int get_max_phy_index(NETSIM_ID devid,NETSIM_ID ifid)
64 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(devid,ifid);
65 switch(phy->PhyProtocol)
70 return get_ofdm_phy_max_index();
72 return get_dsss_phy_max_index();
75 return get_ht_phy_max_index(phy->PhyProtocol,phy->nGuardInterval);
77 return get_he_phy_max_index(phy->PhyProtocol,phy->nGuardInterval);
79 fnNetSimError(
"Unknown phy protocol %d in %s.\n",phy->PhyProtocol,__FUNCTION__);
84static unsigned int get_min_phy_index(NETSIM_ID devid,NETSIM_ID ifid)
86 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(devid,ifid);
87 switch(phy->PhyProtocol)
92 return get_ofdm_phy_min_index();
94 return get_dsss_phy_min_index();
97 return get_ht_phy_min_index(phy->PhyProtocol,phy->nGuardInterval);
99 return get_he_phy_min_index(phy->PhyProtocol,phy->nGuardInterval);
101 fnNetSimError(
"Unknown phy protocol %d in %s.\n",phy->PhyProtocol,__FUNCTION__);
106void Generic_Rate_adaptation_init(NETSIM_ID nDevId,NETSIM_ID nifid)
109 PGENERIC_RATE_ADAPTATION rate=(PGENERIC_RATE_ADAPTATION)calloc(1,
sizeof* rate);
110 set_rate_adaptation_data(nDevId,nifid,rate);
112 rate->currentDroppedCount=(
int*)calloc(NETWORK->nDeviceCount+1,
sizeof* rate->currentDroppedCount);
113 rate->currentPhyindex=(
unsigned int*)calloc(NETWORK->nDeviceCount+1,
sizeof* rate->currentPhyindex);
114 rate->currentReceivedCount=(
int*)calloc(NETWORK->nDeviceCount+1,
sizeof* rate->currentReceivedCount);
116 rate->maxPhyindex = get_max_phy_index(nDevId,nifid);
117 rate->minPhyindex = get_min_phy_index(nDevId,nifid);
118 for(i=0;i<=NETWORK->nDeviceCount;i++)
119 rate->currentPhyindex[i]=rate->maxPhyindex;
122void packet_drop_notify(NETSIM_ID devid,NETSIM_ID ifid,NETSIM_ID rcvid)
124 PGENERIC_RATE_ADAPTATION rate = get_rate_adaptation_data(devid,ifid);
126 rate->currentDroppedCount[rcvid]++;
128 if(rate->currentDroppedCount[rcvid] > RATE_DOWN_INDEX)
130 if(rate->currentPhyindex[rcvid] > rate->minPhyindex)
131 rate->currentPhyindex[rcvid]--;
132 rate->currentDroppedCount[rcvid]=0;
135 rate->currentReceivedCount[rcvid] = 0;
138void packet_recv_notify(NETSIM_ID devid,NETSIM_ID ifid,NETSIM_ID rcvid)
140 PGENERIC_RATE_ADAPTATION rate = get_rate_adaptation_data(devid,ifid);
141 rate->currentReceivedCount[rcvid]++;
143 if(rate->currentReceivedCount[rcvid] > RATE_UP_INDEX)
145 if(rate->currentPhyindex[rcvid] < rate->maxPhyindex)
146 rate->currentPhyindex[rcvid]++;
147 rate->currentReceivedCount[rcvid]=0;
150 rate->currentDroppedCount[rcvid] = 0;
153unsigned int get_rate_index(NETSIM_ID devid,NETSIM_ID ifid,NETSIM_ID rcvid)
155 return get_rate_adaptation_data(devid,ifid)->currentPhyindex[rcvid];