SampleRate Algorithm:

implemented by

• sample.c
• sample.h

This algorithm conducts a per-MAC destination rate control. For each different destination, link statistics are stored separately.

Description of functions in sample.c:

```   I. static __inline int best_rate_ndx(struct sample_node *sn, int size_bin, int require_acked_before)
```

The objective of this function is to return the bit-rate with the lowest avg. pkt. tx. time.

```   Process information starting from the lowest rate:
1. if ((avg. pkt. tx. time for this pkt. size and bit-rate <= 0) or
((packets have not been acked for this pkt. size and bit-rate) and
(multi-rate retry is disabled)))
process next higher bit-rate;
2. if (processing 9Mbps)
process next higher bit-rate; // 9Mbps is never better than 12Mbps
3. if (successive failures at this rate > 3)
process next higher bit-rate;
4. if (avg. pkt. tx. time for this rate is lowest so far)
set best_rate_index to that of current rate;

if (best rate index found)
return best_rate_index;
else
return -1;
```
```   II. static __inline int pick_sample_ndx(struct sample_node *sn, int size_bin)
```

The objective of this function is to return the index of a "suitable" bit-rate that can be sampled.

```   1. if (no packets have been sent successfully at any of the higher bit-rates)
return (index of lowest bit-rate);
2. current_tx_time = avg. tx. time for the bit-rate at which the card was operating in the previous interval;
3. Process information starting from the index of the lowest rate (for (i = 0); i < max_rate_index; i++)):
1. Choose 1 + the index of the last rate that was sampled + i;
2. if (i == current_rate_index)
proceed to next higher bit-rate;
3. if (perfect_tx_time(rate(i)) > avg. tx. time (current rate))
proceed to next higher bit-rate;
4. if ((last tx. at rate(i) was less than 10 seconds ago) and
(successive failures at rate(i) > 3))
proceed to next higher bit-rate;
5. if ((rate(i) > 11Mbps) and (rate(i) > current rate + 2))
proceed to next higher bit-rate;
6. if (rate(i) == 9Mbps)
process next higher bit-rate; // 9Mbps is never better than 12Mbps
7. if ((current rate == 11Mbps) and (rate(i) > 12Mbps))
proceed to next higher bit-rate;
8. return i;
```