--- a/src/routing/aodv/aodv-packet.cc Mon Jul 06 12:54:22 2009 +0400
+++ b/src/routing/aodv/aodv-packet.cc Mon Jul 06 22:51:52 2009 +0400
@@ -148,10 +148,10 @@
#ifdef RUN_SELF_TESTS
/// Unit test for RREQ
-struct RreqHeaderTest : public Test
+struct RreqHeaderTest : public Test
{
RreqHeaderTest () : Test ("AODV/RREQ") {}
- virtual bool RunTests();
+ virtual bool RunTests();
};
/// Test instance
@@ -160,7 +160,7 @@
bool RreqHeaderTest::RunTests ()
{
bool result(true);
-
+
RreqHeader h;
h.SetDst (Ipv4Address("1.2.3.4"));
h.SetDstSeqno (123);
@@ -173,7 +173,7 @@
NS_TEST_ASSERT(h.GetDestinationOnly ());
h.SetUnknownSeqno (true);
NS_TEST_ASSERT(h.GetUnknownSeqno ());
-
+
Ptr<Packet> p = Create<Packet> ();
p->AddHeader (h);
RreqHeader h2;
@@ -182,6 +182,107 @@
NS_TEST_ASSERT_EQUAL (h, h2);
return result;
}
-#endif
+#endif
+
+//-----------------------------------------------------------------------------
+// RREP
+//-----------------------------------------------------------------------------
+
+RrepHeader::RrepHeader() :rp_flags(0), prefixSize(0), rp_hop_count(0), rp_dst_seqno(0)
+{
+ SetAckRequired(false);
+}
+
+TypeId
+RrepHeader::GetInstanceTypeId() const
+{
+ return TypeId();
+}
+
+uint32_t
+RrepHeader::GetSerializedSize () const
+{
+ return 20;
+}
+
+void
+RrepHeader::Serialize (Buffer::Iterator i) const
+{
+ i.WriteU8(type());
+ i.WriteU8(rp_flags);
+ i.WriteU8(prefixSize);
+ i.WriteU8 (rp_hop_count);
+ WriteTo (i, rp_dst);
+ i.WriteHtonU32 (rp_dst_seqno);
+ WriteTo (i, rp_src);
+ i.WriteHtonU32 (rp_lifetime);
+}
+
+uint32_t
+RrepHeader::Deserialize (Buffer::Iterator start)
+{
+ Buffer::Iterator i = start;
+ uint8_t t = i.ReadU8 ();
+ NS_ASSERT (t == type());
+
+ rp_flags = i.ReadU8 ();
+ prefixSize = i.ReadU8 ();
+ rp_hop_count = i.ReadU8 ();
+ ReadFrom (i, rp_dst);
+ rp_dst_seqno = i.ReadNtohU32 ();
+ ReadFrom (i, rp_src);
+ rp_lifetime = i.ReadNtohU32 ();
+
+ uint32_t dist = i.GetDistanceFrom (start);
+ NS_ASSERT (dist == GetSerializedSize ());
+ return dist;
+}
+
+void
+RrepHeader::Print (std::ostream &os) const
+{
+ // TODO
+}
+
+void
+RrepHeader::SetAckRequired (bool f)
+{
+ if (f) rp_flags |= (1 << 1);
+ else rp_flags &= ~(1 << 1);
+}
+
+bool
+RrepHeader::GetAckRequired () const
+{
+ return (rp_flags & (1 << 1));
+}
+
+void
+RrepHeader::SetPrefixSize(uint8_t sz)
+{
+ prefixSize = sz;
+}
+
+uint8_t
+RrepHeader::GetPrefixSize() const
+{
+ return prefixSize;
+}
+
+bool
+RrepHeader::operator==(RrepHeader const & o) const
+{
+ return (rp_flags == o.rp_flags && prefixSize == o.prefixSize &&
+ rp_hop_count == o.rp_hop_count && rp_dst == o.rp_dst &&
+ rp_dst_seqno == o.rp_dst_seqno && rp_src == o.rp_src &&
+ rp_lifetime == o.rp_lifetime);
+}
+
+std::ostream & operator<<(std::ostream & os, RrepHeader const & h)
+{
+ h.Print (os);
+ return os;
+}
+
}}
--- a/src/routing/aodv/aodv-packet.h Mon Jul 06 12:54:22 2009 +0400
+++ b/src/routing/aodv/aodv-packet.h Mon Jul 06 22:51:52 2009 +0400
@@ -28,6 +28,7 @@
#include <iostream>
#include "ns3/header.h"
#include "ns3/ipv4-address.h"
+#include <map>
namespace ns3 {
namespace aodv {
@@ -42,7 +43,6 @@
AODVTYPE_RREP_ACK = 0x10
};
-
/**
* \ingroup aodv
* \brief Route Request (RREQ) Message Format
@@ -119,6 +119,76 @@
std::ostream & operator<<(std::ostream & os, RreqHeader const &);
+/**
+ * \ingroup aodv
+ * \brief Route Reply (RREP) Message Format
+
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type |R|A| Reserved |Prefix Sz| Hop Count |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Destination IP address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Destination Sequence Number |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Originator IP address |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Lifetime |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ */
+class RrepHeader : public Header
+{
+public:
+ RrepHeader();
+ ///\name Header serialization/deserialization
+ //\{
+ TypeId GetInstanceTypeId() const;
+ uint32_t GetSerializedSize () const;
+ void Serialize (Buffer::Iterator start) const;
+ uint32_t Deserialize (Buffer::Iterator start);
+ void Print (std::ostream &os) const;
+ //\}
+
+ ///\name Fields
+ //\{
+ void SetHopCount (uint8_t count) { rp_hop_count = count; }
+ uint8_t GetHopCount () const { return rp_hop_count; }
+ void SetDst (Ipv4Address a) { rp_dst = a; }
+ Ipv4Address GetDst () const { return rp_dst; }
+ void SetDstSeqno (uint32_t s) { rp_dst_seqno = s; }
+ uint32_t GetDstSeqno () const { return rp_dst_seqno; }
+ void SetSrc (Ipv4Address a) { rp_src = a; }
+ Ipv4Address GetSrc () const { return rp_src; }
+ void SetLifeTime (uint32_t t) { rp_lifetime = t; }
+ uint32_t GetLifeTime () const { return rp_lifetime; }
+ //\}
+
+ ///\name Flags
+ //\{
+ void SetAckRequired (bool f);
+ bool GetAckRequired () const;
+ void SetPrefixSize(uint8_t sz);
+ uint8_t GetPrefixSize() const;
+
+ //\}
+
+ bool operator==(RrepHeader const & o) const;
+private:
+ static MessageType type() { return AODVTYPE_RREP; }
+ uint8_t rp_flags; ///< A - acknowledgment required flag
+ uint8_t prefixSize; ///< Prefix Size
+ uint8_t rp_hop_count; ///< Hop Count
+ Ipv4Address rp_dst; ///< Destination IP Address
+ uint32_t rp_dst_seqno; ///< Destination Sequence Number
+ Ipv4Address rp_src; ///< Source IP Address
+ uint32_t rp_lifetime; ///< Lifetime
+};
+
+std::ostream & operator<<(std::ostream & os, RrepHeader const &);
+
+
}
}
#endif /* AODVPACKET_H_ */