Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(300)

Unified Diff: src/pgbr/model/gradient-calculator/ipv4-pgbr-load-aware-gradient-header.cc

Issue 15530043: New module pgbr (PGBR routing protocol) and extension of topology-read module
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pgbr/model/gradient-calculator/ipv4-pgbr-load-aware-gradient-header.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pgbr/model/gradient-calculator/ipv4-pgbr-load-aware-gradient-header.cc
@@ -0,0 +1,160 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) Waterford Institute of Technology, 2013, Julien Mineraud, BioFINT.
+ *
+ * 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: Julien Mineraud <julien.mineraud@gmail.com>
+ *
+ * Acknowledgements:
+ * This work has received support from Science Foundation Ireland via the
+ * "A Biologically inspired framework supporting network management for
+ * the Future Internet" starting investigator award (grant no. 09/SIRG/I1643).
+ */
+
+#include "ipv4-pgbr-load-aware-gradient-header.h"
+
+namespace ns3 {
+namespace pgbr {
+
+NS_OBJECT_ENSURE_REGISTERED (Ipv4LoadAwareGradientHeader);
+
+TypeId
+Ipv4LoadAwareGradientHeader::GetTypeId (void)
+{
+ static TypeId tid =
+ TypeId ("ns3::pgbr::Ipv4LoadAwareGradientHeader")
+ .SetParent<Header> ()
+ .AddConstructor<Ipv4LoadAwareGradientHeader> ()
+ ;
+ return tid;
+}
+
+TypeId
+Ipv4LoadAwareGradientHeader::GetInstanceTypeId (void) const
+{
+ return GetTypeId ();
+}
+
+Ipv4LoadAwareGradientHeader::Ipv4LoadAwareGradientHeader ()
+: m_packetSequenceNumber(0), m_timeToLive (1), m_linkLoad (0), m_nodeLoad(0)
+{}
+
+Ipv4LoadAwareGradientHeader::~Ipv4LoadAwareGradientHeader ()
+{}
+
+uint32_t
+Ipv4LoadAwareGradientHeader::GetSerializedSize (void) const
+{
+ return 2 + /// Packet Sequence number
+ 1 + /// Time To Live
+ 8 + /// link load
+ 8; /// node load
+}
+
+void
+Ipv4LoadAwareGradientHeader::Print (std::ostream &os) const
+{
+ // TODO
+}
+
+void
+Ipv4LoadAwareGradientHeader::Serialize (Buffer::Iterator start) const
+{
+ Buffer::Iterator i = start;
+ i.WriteHtonU16 (m_packetSequenceNumber);
+ i.WriteU8 (m_timeToLive);
+ NS_ASSERT_MSG (m_linkLoad >= 0 && m_linkLoad <= 1,
+ "During serialisation the link load has to be between 0 and 1, linkload=" << m_linkLoad);
+ i.WriteHtonU64 (ConvertDoubleToInt64 (m_linkLoad));
+ i.WriteHtonU64 (ConvertDoubleToInt64 (m_nodeLoad));
+}
+
+uint32_t
+Ipv4LoadAwareGradientHeader::Deserialize (Buffer::Iterator start)
+{
+ Buffer::Iterator i = start;
+ m_packetSequenceNumber = i.ReadNtohU16 ();
+ m_timeToLive = i.ReadU8 ();
+ m_linkLoad = ConvertInt64ToDouble (i.ReadNtohU64 ());
+ m_nodeLoad = ConvertInt64ToDouble (i.ReadNtohU64 ());
+
+ uint32_t dist = i.GetDistanceFrom (start);
+ NS_ASSERT (dist == GetSerializedSize ());
+ return dist;
+}
+
+void
+Ipv4LoadAwareGradientHeader::SetPacketSequenceNumber (uint16_t seqnum)
+{
+ m_packetSequenceNumber = seqnum;
+}
+
+uint16_t
+Ipv4LoadAwareGradientHeader::GetPacketSequenceNumber (void) const
+{
+ return m_packetSequenceNumber;
+}
+
+void
+Ipv4LoadAwareGradientHeader::SetTimeToLive (uint8_t ttl)
+{
+ m_timeToLive = ttl;
+}
+
+uint8_t
+Ipv4LoadAwareGradientHeader::GetTimeToLive (void) const
+{
+ return m_timeToLive;
+}
+
+void
+Ipv4LoadAwareGradientHeader::SetLinkLoad (double_t linkLoad)
+{
+ m_linkLoad = linkLoad;
+}
+
+double_t
+Ipv4LoadAwareGradientHeader::GetLinkLoad (void) const
+{
+ return m_linkLoad;
+}
+
+void
+Ipv4LoadAwareGradientHeader::SetNodeLoad (double_t nodeLoad)
+{
+ m_nodeLoad = nodeLoad;
+}
+
+double_t
+Ipv4LoadAwareGradientHeader::GetNodeLoad (void) const
+{
+ return m_nodeLoad;
+}
+
+//TODO use something like mantissa / exponent representation using the first
+//32bits for the mantissa and the last 32bits for the exponent
+double_t
+Ipv4LoadAwareGradientHeader::ConvertInt64ToDouble(uint64_t value)
+{
+ return (double_t)(value / 1000000000.0);
+}
+
+uint64_t
+Ipv4LoadAwareGradientHeader::ConvertDoubleToInt64(double_t value)
+{
+ return (uint64_t)(value * 1000000000.0);
+}
+
+}} // namespace pgbr, ns3

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b