OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /*· |
| 3 * Copyright (c) 2012 Michal Paszta |
| 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: Michal Paszta· |
| 19 */ |
| 20 |
| 21 #ifndef RNS_HEADER_H_ |
| 22 #define RNS_HEADER_H_ |
| 23 |
| 24 #include <iostream> |
| 25 #include "ns3/header.h" |
| 26 #include <ns3/ipv4.h> |
| 27 #include <ns3/address-utils.h> |
| 28 |
| 29 #define RNS_DEFAULT_FLOAT_ACCURACY 1000.0 |
| 30 |
| 31 namespace ns3 { |
| 32 namespace rns { |
| 33 |
| 34 /** |
| 35 * \ingroup rns |
| 36 * \brief RNS header class |
| 37 *· |
| 38 * RNS header relies on the higher-level class header to provide node |
| 39 * identification. The structure of the header depends on the size of the |
| 40 * identifier. |
| 41 * |
| 42 */ |
| 43 template <class IdType> |
| 44 class RnsHeader : public Header |
| 45 { |
| 46 public: |
| 47 RnsHeader () : |
| 48 m_headerFloatAccuracy (RNS_DEFAULT_FLOAT_ACCURACY), |
| 49 m_status(0), |
| 50 m_range(0), |
| 51 m_x(0), |
| 52 m_y(0), |
| 53 m_entriesNumber(0), |
| 54 PositionInRnsHeader(false) |
| 55 {} |
| 56 RnsHeader(uint8_t status, double range, IdType addr) : |
| 57 m_headerFloatAccuracy (RNS_DEFAULT_FLOAT_ACCURACY), |
| 58 m_id (addr), |
| 59 m_status (status), |
| 60 m_range (range*m_headerFloatAccuracy), |
| 61 m_x(0), |
| 62 m_y(0), |
| 63 m_entriesNumber(0), |
| 64 PositionInRnsHeader(false) |
| 65 {} |
| 66 |
| 67 virtual ~RnsHeader () {}; |
| 68 static TypeId GetTypeId (void); |
| 69 virtual TypeId GetInstanceTypeId (void) const |
| 70 { |
| 71 return GetTypeId(); |
| 72 } |
| 73 virtual uint32_t GetSerializedSize () const; |
| 74 virtual void Serialize (Buffer::Iterator start) const; |
| 75 virtual uint32_t Deserialize (Buffer::Iterator start); |
| 76 virtual void Print (std::ostream &os) const |
| 77 { |
| 78 os << "Status: " << m_status |
| 79 << "Range: " << m_range |
| 80 << "Id: " << m_id; |
| 81 } |
| 82 |
| 83 void SetId (IdType id) {m_id = id;} |
| 84 void SetNewStatus (uint8_t newStatus) {m_status = newStatus;} |
| 85 void SetRange(double range){m_range=(uint32_t)(range*m_headerFloatAccuracy);} |
| 86 void SetX(double x){m_x = (uint32_t)(x * m_headerFloatAccuracy);} |
| 87 void SetY(double y){m_y = (uint32_t)(y * m_headerFloatAccuracy);} |
| 88 void SetHeaderFloatAccuracy (double acc){m_headerFloatAccuracy = acc;} |
| 89 void SetPositionInRnsHeader (bool p){PositionInRnsHeader = p;} |
| 90 void SetEntriesNumber (uint32_t n) {m_entriesNumber = n;} |
| 91 void SetRrns (std::vector<IdType> rrns) {m_rrns = rrns; m_entriesNumber = rrns
.size();} |
| 92 |
| 93 IdType GetId(void){return m_id;} |
| 94 uint8_t GetNewStatus(void) {return m_status;} |
| 95 double GetRange (void) {return ((double)m_range)/m_headerFloatAccuracy;} |
| 96 double GetX(void) {return ((double)m_x)/m_headerFloatAccuracy;} |
| 97 double GetY(void) {return ((double)m_y)/m_headerFloatAccuracy;} |
| 98 double GetHeaderFloatAccuracy (void) {return m_headerFloatAccuracy;} |
| 99 bool GetPositionInRnsHeader(void) {return PositionInRnsHeader;} |
| 100 uint32_t GetEntriesNumber (void) {return m_entriesNumber;} |
| 101 std::vector<IdType> GetRrns(void) {return m_rrns;} |
| 102 |
| 103 private: |
| 104 double m_headerFloatAccuracy; |
| 105 |
| 106 IdType m_id; |
| 107 uint8_t m_status; |
| 108 uint32_t m_range; |
| 109 uint32_t m_x; |
| 110 uint32_t m_y; |
| 111 uint32_t m_entriesNumber; |
| 112 |
| 113 std::vector<IdType> m_rrns; |
| 114 |
| 115 bool PositionInRnsHeader; |
| 116 }; |
| 117 |
| 118 |
| 119 |
| 120 } // namespace rns |
| 121 } // namespace ns3 |
| 122 |
| 123 |
| 124 #endif /* RNS_HEADER_H_ */ |
OLD | NEW |