Index: src/rns/model/rns-header.h |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/rns/model/rns-header.h |
@@ -0,0 +1,124 @@ |
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
+/* |
+ * Copyright (c) 2012 Michal Paszta |
+ * |
+ * This program is free software; you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 2 as |
+ * published by the Free Software Foundation; |
+ * |
+ * This program is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with this program; if not, write to the Free Software |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
+ * |
+ * Author: Michal Paszta |
+ */ |
+ |
+#ifndef RNS_HEADER_H_ |
+#define RNS_HEADER_H_ |
+ |
+#include <iostream> |
+#include "ns3/header.h" |
+#include <ns3/ipv4.h> |
+#include <ns3/address-utils.h> |
+ |
+#define RNS_DEFAULT_FLOAT_ACCURACY 1000.0 |
+ |
+namespace ns3 { |
+namespace rns { |
+ |
+/** |
+ * \ingroup rns |
+ * \brief RNS header class |
+ * |
+ * RNS header relies on the higher-level class header to provide node |
+ * identification. The structure of the header depends on the size of the |
+ * identifier. |
+ * |
+ */ |
+template <class IdType> |
+class RnsHeader : public Header |
+{ |
+public: |
+ RnsHeader () : |
+ m_headerFloatAccuracy (RNS_DEFAULT_FLOAT_ACCURACY), |
+ m_status(0), |
+ m_range(0), |
+ m_x(0), |
+ m_y(0), |
+ m_entriesNumber(0), |
+ PositionInRnsHeader(false) |
+ {} |
+ RnsHeader(uint8_t status, double range, IdType addr) : |
+ m_headerFloatAccuracy (RNS_DEFAULT_FLOAT_ACCURACY), |
+ m_id (addr), |
+ m_status (status), |
+ m_range (range*m_headerFloatAccuracy), |
+ m_x(0), |
+ m_y(0), |
+ m_entriesNumber(0), |
+ PositionInRnsHeader(false) |
+ {} |
+ |
+ virtual ~RnsHeader () {}; |
+ static TypeId GetTypeId (void); |
+ virtual TypeId GetInstanceTypeId (void) const |
+ { |
+ return GetTypeId(); |
+ } |
+ virtual uint32_t GetSerializedSize () const; |
+ virtual void Serialize (Buffer::Iterator start) const; |
+ virtual uint32_t Deserialize (Buffer::Iterator start); |
+ virtual void Print (std::ostream &os) const |
+ { |
+ os << "Status: " << m_status |
+ << "Range: " << m_range |
+ << "Id: " << m_id; |
+ } |
+ |
+ void SetId (IdType id) {m_id = id;} |
+ void SetNewStatus (uint8_t newStatus) {m_status = newStatus;} |
+ void SetRange(double range){m_range=(uint32_t)(range*m_headerFloatAccuracy);} |
+ void SetX(double x){m_x = (uint32_t)(x * m_headerFloatAccuracy);} |
+ void SetY(double y){m_y = (uint32_t)(y * m_headerFloatAccuracy);} |
+ void SetHeaderFloatAccuracy (double acc){m_headerFloatAccuracy = acc;} |
+ void SetPositionInRnsHeader (bool p){PositionInRnsHeader = p;} |
+ void SetEntriesNumber (uint32_t n) {m_entriesNumber = n;} |
+ void SetRrns (std::vector<IdType> rrns) {m_rrns = rrns; m_entriesNumber = rrns.size();} |
+ |
+ IdType GetId(void){return m_id;} |
+ uint8_t GetNewStatus(void) {return m_status;} |
+ double GetRange (void) {return ((double)m_range)/m_headerFloatAccuracy;} |
+ double GetX(void) {return ((double)m_x)/m_headerFloatAccuracy;} |
+ double GetY(void) {return ((double)m_y)/m_headerFloatAccuracy;} |
+ double GetHeaderFloatAccuracy (void) {return m_headerFloatAccuracy;} |
+ bool GetPositionInRnsHeader(void) {return PositionInRnsHeader;} |
+ uint32_t GetEntriesNumber (void) {return m_entriesNumber;} |
+ std::vector<IdType> GetRrns(void) {return m_rrns;} |
+ |
+private: |
+ double m_headerFloatAccuracy; |
+ |
+ IdType m_id; |
+ uint8_t m_status; |
+ uint32_t m_range; |
+ uint32_t m_x; |
+ uint32_t m_y; |
+ uint32_t m_entriesNumber; |
+ |
+ std::vector<IdType> m_rrns; |
+ |
+ bool PositionInRnsHeader; |
+}; |
+ |
+ |
+ |
+} // namespace rns |
+} // namespace ns3 |
+ |
+ |
+#endif /* RNS_HEADER_H_ */ |