00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 Emmanuelle Laprise 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca 00019 * Derived from the p2p net device file 00020 Transmi */ 00021 00022 #ifndef BACKOFF_H 00023 #define BACKOFF_H 00024 00025 #include <stdint.h> 00026 #include "ns3/nstime.h" 00027 #include "ns3/random-variable.h" 00028 00029 namespace ns3 { 00030 00031 /** 00032 * \brief The backoff class is used for calculating backoff times 00033 * when many net devices can write to the same channel 00034 * 00035 */ 00036 00037 class Backoff { 00038 public: 00039 /** 00040 * Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time) 00041 */ 00042 uint32_t m_minSlots; 00043 00044 /** 00045 * Maximim number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time) 00046 */ 00047 uint32_t m_maxSlots; 00048 00049 /** 00050 * Caps the exponential function when the number of retries reaches m_ceiling. 00051 */ 00052 uint32_t m_ceiling; 00053 00054 /** 00055 * Maximum number of transmission retries before the packet is dropped. 00056 */ 00057 uint32_t m_maxRetries; 00058 00059 /** 00060 * Length of one slot. A slot time, it usually the packet transmission time, if the packet size is fixed. 00061 */ 00062 Time m_slotTime; 00063 00064 Backoff (void); 00065 Backoff (Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t ceiling, uint32_t maxRetries); 00066 00067 /** 00068 * \return The amount of time that the net device should wait before 00069 * trying to retransmit the packet 00070 */ 00071 Time GetBackoffTime(); 00072 00073 /** 00074 * Indicates to the backoff object that the last packet was 00075 * successfully transmitted and that the number of retries should be 00076 * reset to 0. 00077 */ 00078 void ResetBackoffTime (void); 00079 00080 /** 00081 * \return True if the maximum number of retries has been reached 00082 */ 00083 bool MaxRetriesReached (void); 00084 00085 /** 00086 * Increments the number of retries by 1. 00087 */ 00088 void IncrNumRetries (void); 00089 00090 private: 00091 00092 /** 00093 * Number of times that the transmitter has tried to unsuccessfully transmit the current packet. 00094 */ 00095 uint32_t m_numBackoffRetries; 00096 }; 00097 00098 }; // namespace ns3 00099 00100 #endif // BACKOFF_H 00101