packages/uan/model/uan-header-rc.h
changeset 6622 66d4eab148ce
child 6624 601c5f38d7ca
equal deleted inserted replaced
6621:b30587eaf9e6 6622:66d4eab148ce
       
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2009 University of Washington
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Author: Leonard Tracy <lentracy@gmail.com>
       
    19  */
       
    20 
       
    21 
       
    22 #ifndef UANHEADERRC_H
       
    23 #define UANHEADERRC_H
       
    24 
       
    25 #include "ns3/header.h"
       
    26 #include "ns3/nstime.h"
       
    27 #include "uan-address.h"
       
    28 
       
    29 #include <set>
       
    30 
       
    31 namespace ns3 {
       
    32 namespace uan {
       
    33 
       
    34 /**
       
    35  * \class UanHeaderRcData
       
    36  *
       
    37  * \brief Extra data header information
       
    38  *
       
    39  * Adds prop. delay measure, and frame number info to
       
    40  * transmitted data packet
       
    41  */
       
    42 class UanHeaderRcData : public Header
       
    43 {
       
    44 public:
       
    45   UanHeaderRcData ();
       
    46   /**
       
    47    * \param frameNum Data frame # of reservation being transmitted
       
    48    * \param propDelay  Measured propagation delay found in handshaking
       
    49    * \note Prop. delay is transmitted with 16 bits and ms accuracy
       
    50    */
       
    51   UanHeaderRcData (uint8_t frameNum, Time propDelay);
       
    52   virtual ~UanHeaderRcData ();
       
    53 
       
    54   static TypeId GetTypeId (void);
       
    55 
       
    56   /**
       
    57    * \param frameNum Data frame # of reservation being transmitted
       
    58    */
       
    59   void SetFrameNo (uint8_t frameNum);
       
    60   /**
       
    61    * \param propDelay Measured propagation delay found in handshaking
       
    62    * \note Prop. delay is transmitted with 16 bits and ms accuracy
       
    63    */
       
    64   void SetPropDelay (Time propDelay);
       
    65   /**
       
    66    * \returns Data frame # of reservation being transmitted
       
    67    */
       
    68   uint8_t GetFrameNo (void) const;
       
    69   /**
       
    70    * \returns Measured propagation delay found in handshaking
       
    71    * \note Prop. delay is transmitted with 16 bits and ms accuracy
       
    72    */
       
    73   Time GetPropDelay (void) const;
       
    74 
       
    75   // Inherrited methods
       
    76   virtual uint32_t GetSerializedSize (void) const;
       
    77   virtual void Serialize (Buffer::Iterator start) const;
       
    78   virtual uint32_t Deserialize (Buffer::Iterator start);
       
    79   virtual void Print (std::ostream &os) const;
       
    80   virtual TypeId GetInstanceTypeId (void) const;
       
    81 
       
    82 private:
       
    83   uint8_t m_frameNo;
       
    84   Time m_propDelay;
       
    85 };
       
    86 
       
    87 /**
       
    88  * \class UanHeaderRcRts
       
    89  *
       
    90  * \brief RTS header
       
    91  *
       
    92  * Contains frame #, retry #, # frames, length, and timestamp
       
    93  */
       
    94 class UanHeaderRcRts : public Header
       
    95 {
       
    96 public:
       
    97   UanHeaderRcRts ();
       
    98   /**
       
    99    * \param frameNo Reservation frame #
       
   100    * \param retryNo Retry # of RTS packet
       
   101    * \param noFrames # of data frames in reservation
       
   102    * \param length # of bytes (including headers) in data
       
   103    * \param ts RTS TX timestamp
       
   104    * \note Timestamp is serialized into 32 bits with ms accuracy
       
   105    */
       
   106   UanHeaderRcRts (uint8_t frameNo, uint8_t retryNo, uint8_t noFrames, uint16_t length, Time ts);
       
   107   virtual ~UanHeaderRcRts ();
       
   108 
       
   109   static TypeId GetTypeId (void);
       
   110 
       
   111   /**
       
   112    * \param fno TX frame #
       
   113    */
       
   114   void SetFrameNo (uint8_t fno);
       
   115   /**
       
   116    * \param no Number of data frames included in this reservation request
       
   117    */
       
   118   void SetNoFrames (uint8_t no);
       
   119   /**
       
   120    * \param timeStamp RTS transmission time
       
   121    */
       
   122   void SetTimeStamp (Time timeStamp);
       
   123   /**
       
   124    * \param length Total number of data bytes in reservation (including headers)
       
   125    * \note Timestamp is serialized with 32 bits in ms precision
       
   126    */
       
   127   void SetLength (uint16_t length);
       
   128   /**
       
   129    * \param no Retry number of this RTS (Used to match timestamp to correctly received RTS)
       
   130    */
       
   131   void SetRetryNo (uint8_t no);
       
   132 
       
   133   /**
       
   134    * \returns Frame #
       
   135    */
       
   136   uint8_t GetFrameNo (void) const;
       
   137   /**
       
   138    * \returns # of data frames in reservation
       
   139    */
       
   140   uint8_t GetNoFrames (void) const;
       
   141   /**
       
   142    * \returns TX time of the RTS packet
       
   143    * \note Timestamp is serialized with 32 bits in ms precision
       
   144    */
       
   145   Time GetTimeStamp (void) const;
       
   146   /**
       
   147    * \returns Total # of bytes in data packets for reservation (including headers)
       
   148    */
       
   149   uint16_t GetLength (void) const;
       
   150   /**
       
   151    * \returns Retry number of this RTS packet
       
   152    */
       
   153   uint8_t GetRetryNo (void) const;
       
   154 
       
   155   // Inherrited methods
       
   156   virtual uint32_t GetSerializedSize (void) const;
       
   157   virtual void Serialize (Buffer::Iterator start) const;
       
   158   virtual uint32_t Deserialize (Buffer::Iterator start);
       
   159   virtual void Print (std::ostream &os) const;
       
   160   virtual TypeId GetInstanceTypeId (void) const;
       
   161 
       
   162 private:
       
   163   uint8_t m_frameNo;
       
   164   uint8_t m_noFrames;
       
   165   uint16_t m_length;
       
   166   Time m_timeStamp;
       
   167   uint8_t m_retryNo;
       
   168 };
       
   169 
       
   170 /**
       
   171  * \class UanHeaderRcCtsGlobal
       
   172  *
       
   173  * \brief Cycle broadcast information for
       
   174  */
       
   175 
       
   176 
       
   177 class UanHeaderRcCtsGlobal : public Header
       
   178 {
       
   179 public:
       
   180   /**
       
   181    * \brief Create UanHeaderRcCtsGlobal with fields zeroed out
       
   182    */
       
   183   UanHeaderRcCtsGlobal ();
       
   184   /**
       
   185    * \brief Create object with given window time, time stamp, rate, and retry rate.
       
   186    * \param wt Window time
       
   187    * \param ts Timestamp
       
   188    * \param rate Rate number
       
   189    * \param retryRate  Retry rate value
       
   190    */
       
   191   UanHeaderRcCtsGlobal (Time wt, Time ts, uint16_t rate, uint16_t retryRate);
       
   192   ~UanHeaderRcCtsGlobal ();
       
   193 
       
   194   static TypeId GetTypeId (void);
       
   195 
       
   196   /**
       
   197    * \param rate Rate number corresponding to data rate of current cycle
       
   198    */
       
   199   void SetRateNum (uint16_t rate);
       
   200   /**
       
   201    * \param rate Retry rate number for current cycle
       
   202    */
       
   203   void SetRetryRate (uint16_t rate);
       
   204   /**
       
   205    * \param t Time duration following blocking time to allow RTS transmissions
       
   206    */
       
   207   void SetWindowTime (Time t);
       
   208 
       
   209   /**
       
   210    * \param timeStamp Time of CTS transmission
       
   211    */
       
   212   void SetTxTimeStamp (Time timeStamp);
       
   213 
       
   214   /**
       
   215    * \returns Rate # corresponding to data rate of current cycle
       
   216    */
       
   217   uint16_t GetRateNum (void) const;
       
   218   /**
       
   219    * \returns retry rate # of retry rate for current cycle
       
   220    */
       
   221   uint16_t GetRetryRate (void) const;
       
   222   /**
       
   223    * \returns Time duration after blocking time allowed for RTS transmissions
       
   224    */
       
   225   Time GetWindowTime (void) const;
       
   226   /**
       
   227    * \returns Timestamp of CTS transmission
       
   228    */
       
   229   Time GetTxTimeStamp (void) const;
       
   230 
       
   231   // Inherrited methods
       
   232   virtual uint32_t GetSerializedSize (void) const;
       
   233   virtual void Serialize (Buffer::Iterator start) const;
       
   234   virtual uint32_t Deserialize (Buffer::Iterator start);
       
   235   virtual void Print (std::ostream &os) const;
       
   236   virtual TypeId GetInstanceTypeId (void) const;
       
   237 
       
   238 private:
       
   239   Time m_timeStampTx;
       
   240   Time m_winTime;
       
   241   uint16_t m_retryRate;
       
   242   uint16_t m_rateNum;
       
   243 };
       
   244 /**
       
   245  * \class UanHeaderRcCts
       
   246  *
       
   247  * \brief CTS header
       
   248  *
       
   249  * Includes RTS RX time, CTS TX time, delay until TX, RTS blocking period,
       
   250  * RTS tx period, rate #, and retry rate #
       
   251  */
       
   252 
       
   253 class UanHeaderRcCts : public Header
       
   254 {
       
   255 public:
       
   256   UanHeaderRcCts ();
       
   257   /**
       
   258    * \param frameNo Resrvation frame # being cleared
       
   259    * \param retryNo Retry # of received RTS packet
       
   260    * \param rtsTs RX time of RTS packet at gateway
       
   261    * \param delay Delay until transmission
       
   262    * \param addr Destination of CTS packet
       
   263    * \note Times are serialized, with ms precission, into 32 bit fields.
       
   264    */
       
   265   UanHeaderRcCts (uint8_t frameNo, uint8_t retryNo, Time rtsTs, Time delay, UanAddress addr);
       
   266   virtual ~UanHeaderRcCts ();
       
   267 
       
   268   static TypeId GetTypeId (void);
       
   269 
       
   270   /**
       
   271    * \param frameNo Frame # of RTS being cleared
       
   272    */
       
   273   void SetFrameNo (uint8_t frameNo);
       
   274   /**
       
   275    * \param timeStamp Time of RTS reception
       
   276    */
       
   277   void SetRtsTimeStamp (Time timeStamp);
       
   278   /**
       
   279    * \param delay Time duration, from CTS TX, before first data frame arrival
       
   280    */
       
   281   void SetDelayToTx (Time delay);
       
   282   /**
       
   283    * \param no Retry number of RTS frame being cleared
       
   284    */
       
   285   void SetRetryNo (uint8_t no);
       
   286   /**
       
   287    * \param addr Destination for scheduling info
       
   288    */
       
   289   void SetAddress (UanAddress addr);
       
   290 
       
   291   /**
       
   292    * \returns Frame # of RTS being cleared
       
   293    */
       
   294   uint8_t GetFrameNo (void) const;
       
   295   /**
       
   296    * \returns RX time of RTS being cleared
       
   297    */
       
   298   Time GetRtsTimeStamp (void) const;
       
   299   /**
       
   300    * \returns Delay from TX time of CTS packet until arrival of first data frame
       
   301    */
       
   302   Time GetDelayToTx (void) const;
       
   303   /**
       
   304    * \returns Retry # of RTS packet being cleared
       
   305    */
       
   306   uint8_t GetRetryNo (void) const;
       
   307   /**
       
   308    * \returns Destination for scheduling info
       
   309    */
       
   310   UanAddress GetAddress (void) const;
       
   311 
       
   312   // Inherrited methods
       
   313   virtual uint32_t GetSerializedSize (void) const;
       
   314   virtual void Serialize (Buffer::Iterator start) const;
       
   315   virtual uint32_t Deserialize (Buffer::Iterator start);
       
   316   virtual void Print (std::ostream &os) const;
       
   317   virtual TypeId GetInstanceTypeId (void) const;
       
   318 
       
   319 private:
       
   320   uint8_t m_frameNo;
       
   321   Time m_timeStampRts;
       
   322   uint8_t m_retryNo;
       
   323   Time m_delay;
       
   324   UanAddress m_address;
       
   325 };
       
   326 
       
   327 /**
       
   328  * \class UanHeaderRcAck
       
   329  * \brief Header used for ACK packets by protocol ns3::UanMacRc
       
   330  */
       
   331 class UanHeaderRcAck : public Header
       
   332 {
       
   333 public:
       
   334   UanHeaderRcAck ();
       
   335   virtual ~UanHeaderRcAck ();
       
   336 
       
   337   static TypeId GetTypeId (void);
       
   338 
       
   339   /**
       
   340    * \param frameNo Frame # of reservation being acknowledged
       
   341    */
       
   342   void SetFrameNo (uint8_t frameNo);
       
   343   /**
       
   344    * \param frame Data frame # being nacked
       
   345    */
       
   346   void AddNackedFrame (uint8_t frame);
       
   347 
       
   348   /**
       
   349    * \returns Set of nacked frames
       
   350    */
       
   351   const std::set<uint8_t> &GetNackedFrames (void) const;
       
   352   /**
       
   353    * \returns Reservation frame # being acknowledged.
       
   354    */
       
   355   uint8_t GetFrameNo (void) const;
       
   356   /**
       
   357    * \returns Number of data frames being NACKED
       
   358    */
       
   359   uint8_t GetNoNacks (void) const;
       
   360 
       
   361   // Inherrited methods
       
   362   virtual uint32_t GetSerializedSize (void) const;
       
   363   virtual void Serialize (Buffer::Iterator start) const;
       
   364   virtual uint32_t Deserialize (Buffer::Iterator start);
       
   365   virtual void Print (std::ostream &os) const;
       
   366   virtual TypeId GetInstanceTypeId (void) const;
       
   367 
       
   368 private:
       
   369   uint8_t m_frameNo;
       
   370   std::set<uint8_t> m_nackedFrames;
       
   371 
       
   372 };
       
   373 
       
   374 } // namespace uan
       
   375 } // namespace ns3
       
   376 
       
   377 #endif // UANHEADERRC_H