diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 3630aabd7..069f8a949 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -153,6 +153,7 @@ bool TypeHeaderTest::RunTests () TypeHeader h(AODVTYPE_RREQ); NS_TEST_ASSERT(h.IsValid()); + NS_TEST_ASSERT_EQUAL (h.Get(), AODVTYPE_RREQ); TypeHeader h1(13); NS_TEST_ASSERT(!h1.IsValid()); @@ -169,8 +170,10 @@ bool TypeHeaderTest::RunTests () //----------------------------------------------------------------------------- // RREQ //----------------------------------------------------------------------------- -RreqHeader::RreqHeader () : - m_flags (0), m_reserved (0), m_hopCount (0), m_broadcastID (0), m_dstSeqNo (0), m_srcSeqNo (0) +RreqHeader::RreqHeader (uint8_t flags, uint8_t reserved, uint8_t hopCount, uint32_t requestID, Ipv4Address dst, + uint32_t dstSeqNo, Ipv4Address origin, uint32_t originSeqNo) : + m_flags (flags), m_reserved (reserved), m_hopCount (hopCount), m_requestID (requestID), m_dst(dst), + m_dstSeqNo (dstSeqNo), m_origin(origin), m_originSeqNo (originSeqNo) { } @@ -192,11 +195,11 @@ RreqHeader::Serialize (Buffer::Iterator i ) const i.WriteU8 (m_flags); i.WriteU8 (m_reserved); i.WriteU8 (m_hopCount); - i.WriteHtonU32 (m_broadcastID); + i.WriteHtonU32 (m_requestID); WriteTo (i, m_dst); i.WriteHtonU32 (m_dstSeqNo); WriteTo (i, m_origin); - i.WriteHtonU32 (m_srcSeqNo); + i.WriteHtonU32 (m_originSeqNo); } uint32_t @@ -206,11 +209,11 @@ RreqHeader::Deserialize (Buffer::Iterator start ) m_flags = i.ReadU8 (); m_reserved = i.ReadU8 (); m_hopCount = i.ReadU8 (); - m_broadcastID = i.ReadNtohU32 (); + m_requestID = i.ReadNtohU32 (); ReadFrom (i, m_dst); m_dstSeqNo = i.ReadNtohU32 (); ReadFrom (i, m_origin); - m_srcSeqNo = i.ReadNtohU32 (); + m_originSeqNo = i.ReadNtohU32 (); uint32_t dist = i.GetDistanceFrom (start); NS_ASSERT (dist == GetSerializedSize ()); @@ -220,8 +223,8 @@ RreqHeader::Deserialize (Buffer::Iterator start ) void RreqHeader::Print (std::ostream &os ) const { - os << "RREQ ID " << m_broadcastID << "\n" << "destination: ipv4 " << m_dst << " " << "sequence number " << m_dstSeqNo << "\n" << "source: ipv4 " - << m_origin << " " << "sequence number " << m_srcSeqNo << "\n" << "flags:\n" << "Gratuitous RREP " << (*this).GetGratiousRrep () << "\n" + os << "RREQ ID " << m_requestID << "\n" << "destination: ipv4 " << m_dst << " " << "sequence number " << m_dstSeqNo << "\n" << "source: ipv4 " + << m_origin << " " << "sequence number " << m_originSeqNo << "\n" << "flags:\n" << "Gratuitous RREP " << (*this).GetGratiousRrep () << "\n" << "Destination only " << (*this).GetDestinationOnly () << "\n" << "Unknown sequence number " << (*this).GetUnknownSeqno () << "\n"; } @@ -280,54 +283,68 @@ RreqHeader::GetUnknownSeqno () const bool RreqHeader::operator== (RreqHeader const & o ) const { - return (m_flags == o.m_flags && m_reserved == o.m_reserved && m_hopCount == o.m_hopCount && m_broadcastID == o.m_broadcastID && m_dst == o.m_dst - && m_dstSeqNo == o.m_dstSeqNo && m_origin == o.m_origin && m_srcSeqNo == o.m_srcSeqNo); + return (m_flags == o.m_flags && m_reserved == o.m_reserved && m_hopCount == o.m_hopCount && m_requestID == o.m_requestID && m_dst == o.m_dst + && m_dstSeqNo == o.m_dstSeqNo && m_origin == o.m_origin && m_originSeqNo == o.m_originSeqNo); } #ifdef RUN_SELF_TESTS /// Unit test for RREQ struct RreqHeaderTest : public Test +{ + RreqHeaderTest () : + Test ("AODV/RREQ") { - RreqHeaderTest () : Test ("AODV/RREQ") - {} - virtual bool RunTests(); - }; + } + virtual bool + RunTests (); +}; /// Test instance static RreqHeaderTest g_RreqHeaderTest; -bool RreqHeaderTest::RunTests () - { - bool result(true); +bool +RreqHeaderTest::RunTests () +{ + bool result (true); - RreqHeader h; - h.SetDst (Ipv4Address("1.2.3.4")); - h.SetDstSeqno (123); - h.SetOrigin (Ipv4Address("4.3.2.1")); - h.SetOriginSeqno (321); - h.SetId (1); + RreqHeader h (/*flags*/0, /*reserved*/0, /*hopCount*/6, /*requestID*/1, /*dst*/Ipv4Address ("1.2.3.4"), + /*dstSeqNo*/40, /*origin*/Ipv4Address ("4.3.2.1"), /*originSeqNo*/10); + NS_TEST_ASSERT_EQUAL (h.GetGratiousRrep (), false); + NS_TEST_ASSERT_EQUAL (h.GetDestinationOnly (), false); + NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 6); + NS_TEST_ASSERT_EQUAL (h.GetId (), 1); + NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.2.3.4")); + NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 40); + NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.3.2.1")); + NS_TEST_ASSERT_EQUAL (h.GetOriginSeqno (), 10); - h.SetGratiousRrep (true); - NS_TEST_ASSERT(h.GetGratiousRrep ()); - h.SetGratiousRrep (false); - NS_TEST_ASSERT_EQUAL(h.GetGratiousRrep (), 0); - h.SetDestinationOnly (true); - NS_TEST_ASSERT(h.GetDestinationOnly ()); - h.SetDestinationOnly (false); - NS_TEST_ASSERT_EQUAL(h.GetDestinationOnly (), 0); - h.SetUnknownSeqno (true); - NS_TEST_ASSERT(h.GetUnknownSeqno ()); - h.SetUnknownSeqno (false); - NS_TEST_ASSERT_EQUAL(h.GetUnknownSeqno (), 0); + h.SetGratiousRrep (true); + NS_TEST_ASSERT_EQUAL (h.GetGratiousRrep (), true); + h.SetDestinationOnly (true); + NS_TEST_ASSERT_EQUAL (h.GetDestinationOnly (), true); + h.SetUnknownSeqno (true); + NS_TEST_ASSERT_EQUAL (h.GetUnknownSeqno (), true); + h.SetDst (Ipv4Address ("1.1.1.1")); + NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.1.1.1")); + h.SetDstSeqno (5); + NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 5); + h.SetHopCount (7); + NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 7); + h.SetId (55); + NS_TEST_ASSERT_EQUAL (h.GetId (), 55); + h.SetOrigin (Ipv4Address ("4.4.4.4")); + NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.4.4.4")); + h.SetOriginSeqno (23); + NS_TEST_ASSERT_EQUAL (h.GetOriginSeqno (), 23); - Ptr p = Create (); - p->AddHeader (h); - RreqHeader h2; - uint32_t bytes = p->RemoveHeader(h2); - NS_TEST_ASSERT_EQUAL (bytes, 23); - NS_TEST_ASSERT_EQUAL (h, h2); - return result; - } + Ptr p = Create (); + p->AddHeader (h); + RreqHeader h2; + uint32_t bytes = p->RemoveHeader (h2); + NS_TEST_ASSERT_EQUAL (bytes, 23); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} #endif //----------------------------------------------------------------------------- @@ -462,50 +479,58 @@ operator<< (std::ostream & os, RrepHeader const & h ) #ifdef RUN_SELF_TESTS /// Unit test for RREP struct RrepHeaderTest : public Test - { - RrepHeaderTest () : Test ("AODV/RREP") - {} - virtual bool RunTests(); - }; +{ + RrepHeaderTest () : Test ("AODV/RREP") {} + virtual bool + RunTests (); +}; /// Test instance static RrepHeaderTest g_RrepHeaderTest; -bool RrepHeaderTest::RunTests () - { - bool result(true); +bool +RrepHeaderTest::RunTests () +{ + bool result (true); - RrepHeader h (/*prefixSize*/0, /*hopCount*/12, /*dst*/Ipv4Address("1.2.3.4"), /*dstSeqNo*/2, - /*origin*/Ipv4Address("4.3.2.1"), /*lifetime*/Seconds(3)); - NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 0); - NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 12); - NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address("1.2.3.4")); - NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 2); - NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address("4.3.2.1")); - NS_TEST_ASSERT_EQUAL (h.GetLifeTime(), Seconds(3)); - h.SetDst (Ipv4Address("1.1.1.1")); - NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address("1.1.1.1")); - h.SetDstSeqno (123); - NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 123); - h.SetOrigin (Ipv4Address("4.4.4.4")); - NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address("4.4.4.4")); - h.SetLifeTime(MilliSeconds(1200)); - NS_TEST_ASSERT_EQUAL (h.GetLifeTime(), MilliSeconds(1200)); - h.SetAckRequired(true); - NS_TEST_ASSERT(h.GetAckRequired ()); - h.SetAckRequired(false); - NS_TEST_ASSERT(!h.GetAckRequired ()); - h.SetPrefixSize(2); - NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 2); + RrepHeader h (/*prefixSize*/0, /*hopCount*/12, /*dst*/Ipv4Address ("1.2.3.4"), /*dstSeqNo*/2, + /*origin*/Ipv4Address ("4.3.2.1"), /*lifetime*/Seconds (3)); + NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 0); + NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 12); + NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.2.3.4")); + NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 2); + NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.3.2.1")); + NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), Seconds (3)); + h.SetDst (Ipv4Address ("1.1.1.1")); + NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.1.1.1")); + h.SetDstSeqno (123); + NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 123); + h.SetOrigin (Ipv4Address ("4.4.4.4")); + NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.4.4.4")); + h.SetLifeTime (MilliSeconds (1200)); + NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), MilliSeconds (1200)); + h.SetAckRequired (true); + NS_TEST_ASSERT_EQUAL (h.GetAckRequired (), true); + h.SetAckRequired (false); + NS_TEST_ASSERT (!h.GetAckRequired ()); + h.SetPrefixSize (2); + NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 2); + h.SetHopCount (15); + NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 15); - Ptr p = Create (); - p->AddHeader (h); - RrepHeader h2; - uint32_t bytes = p->RemoveHeader(h2); - NS_TEST_ASSERT_EQUAL (bytes, 19); - NS_TEST_ASSERT_EQUAL (h, h2); - return result; - } + h.SetHello (Ipv4Address ("10.0.0.2"), 9, Seconds (15)); + NS_TEST_ASSERT_EQUAL (h.GetDst (), h.GetOrigin ()); + NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 9); + NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), Seconds (15)); + + Ptr p = Create (); + p->AddHeader (h); + RrepHeader h2; + uint32_t bytes = p->RemoveHeader (h2); + NS_TEST_ASSERT_EQUAL (bytes, 19); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} #endif //----------------------------------------------------------------------------- diff --git a/src/routing/aodv/aodv-packet.h b/src/routing/aodv/aodv-packet.h index 4b74499b9..78a46f272 100644 --- a/src/routing/aodv/aodv-packet.h +++ b/src/routing/aodv/aodv-packet.h @@ -98,7 +98,8 @@ std::ostream & operator<<(std::ostream & os, TypeHeader const & h); class RreqHeader : public Header { public: - RreqHeader (); + RreqHeader (uint8_t flags = 0, uint8_t reserved = 0, uint8_t hopCount = 0, uint32_t requestID = 0, Ipv4Address dst = Ipv4Address(), + uint32_t dstSeqNo = 0, Ipv4Address origin = Ipv4Address(), uint32_t originSeqNo = 0); ///\name Header serialization/deserialization //\{ @@ -113,16 +114,16 @@ public: //\{ void SetHopCount (uint8_t count) { m_hopCount = count; } uint8_t GetHopCount () const { return m_hopCount; } - void SetId (uint32_t id) { m_broadcastID = id; } - uint8_t GetId () const { return m_broadcastID; } + void SetId (uint32_t id) { m_requestID = id; } + uint8_t GetId () const { return m_requestID; } void SetDst (Ipv4Address a) { m_dst = a; } Ipv4Address GetDst () const { return m_dst; } void SetDstSeqno (uint32_t s) { m_dstSeqNo = s; } uint32_t GetDstSeqno () const { return m_dstSeqNo; } void SetOrigin (Ipv4Address a) { m_origin = a; } Ipv4Address GetOrigin () const { return m_origin; } - void SetOriginSeqno (uint32_t s) { m_srcSeqNo = s; } - uint32_t GetOriginSeqno () const { return m_srcSeqNo; } + void SetOriginSeqno (uint32_t s) { m_originSeqNo = s; } + uint32_t GetOriginSeqno () const { return m_originSeqNo; } //\} ///\name Flags @@ -140,11 +141,11 @@ private: uint8_t m_flags; ///< |J|R|G|D|U| bit flags, see RFC uint8_t m_reserved; ///< Not used uint8_t m_hopCount; ///< Hop Count - uint32_t m_broadcastID; ///< RREQ ID + uint32_t m_requestID; ///< RREQ ID Ipv4Address m_dst; ///< Destination IP Address uint32_t m_dstSeqNo; ///< Destination Sequence Number Ipv4Address m_origin; ///< Originator IP Address - uint32_t m_srcSeqNo; ///< Source Sequence Number + uint32_t m_originSeqNo; ///< Source Sequence Number }; std::ostream & operator<<(std::ostream & os, RreqHeader const &); @@ -209,12 +210,12 @@ public: bool operator==(RrepHeader const & o) const; private: - uint8_t m_flags; ///< A - acknowledgment required flag - uint8_t m_prefixSize; ///< Prefix Size - uint8_t m_hopCount; ///< Hop Count + uint8_t m_flags; ///< A - acknowledgment required flag + uint8_t m_prefixSize; ///< Prefix Size + uint8_t m_hopCount; ///< Hop Count Ipv4Address m_dst; ///< Destination IP Address uint32_t m_dstSeqNo; ///< Destination Sequence Number - Ipv4Address m_origin; ///< Source IP Address + Ipv4Address m_origin; ///< Source IP Address uint32_t m_lifeTime; ///< Lifetime (in milliseconds) }; diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index b4c95d6b3..1129a12f3 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -634,7 +634,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s RoutingTableEntry toPrev; if (m_routingTable.LookupRoute (src, toPrev)) { - if (toPrev.IsInBlacklist ()) + if (toPrev.IsUnidirectional ()) return; } diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index b725d82f4..c7ebea62f 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -234,6 +234,7 @@ AodvRqueueTest::RunTests () q.Enqueue (e2); Ptr packet2 = Create (); QueueEntry e3 (packet2, h, ucb, ecb, Seconds (1)); + NS_TEST_ASSERT_EQUAL(q.Dequeue(Ipv4Address("3.3.3.3"), e3), false); NS_TEST_ASSERT_EQUAL(q.Dequeue(Ipv4Address("2.2.2.2"), e3), true); NS_TEST_ASSERT_EQUAL (q.Find(Ipv4Address("2.2.2.2")), false); q.Enqueue(e2); diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 0cdcf26e3..b851b77fc 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -189,6 +189,14 @@ AodvRtableEntryTest::RunTests () NS_TEST_ASSERT_EQUAL (rt.GetRreqCnt(), 0); NS_TEST_ASSERT_EQUAL (rt.IsPrecursorListEmpty(), true); + Ptr dev2; + Ipv4InterfaceAddress iface2; + rt.SetOutputDevice(dev2); + NS_TEST_ASSERT_EQUAL (rt.GetOutputDevice (), dev2); + rt.SetInterface(iface2); + NS_TEST_ASSERT_EQUAL (rt.GetInterface(), iface2); + rt.SetValidSeqNo(false); + NS_TEST_ASSERT_EQUAL (rt.GetValidSeqNo (), false); rt.SetFlag(RTF_DOWN); NS_TEST_ASSERT_EQUAL (rt.GetFlag (), RTF_DOWN); rt.SetFlag(RTF_IN_REPAIR); diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 1573fe2c0..3e3fe13f9 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -124,7 +124,6 @@ public: void SetRreqCnt(uint8_t n) { m_reqCount = n; } uint8_t GetRreqCnt() const { return m_reqCount; } void IncrementRreqCnt() { m_reqCount++; } - bool IsInBlacklist () const { return m_blackListState; } void SetUnidirectional(bool u) { m_blackListState = u; } bool IsUnidirectional () const { return m_blackListState; } void SetBalcklistTimeout (Time t) { m_blackListTimeout = t; } diff --git a/src/routing/aodv/id-cache.h b/src/routing/aodv/id-cache.h index 6d3bc8a56..2bca6d6ce 100644 --- a/src/routing/aodv/id-cache.h +++ b/src/routing/aodv/id-cache.h @@ -46,6 +46,7 @@ namespace aodv class IdCache { public: + IdCache () {} void InsertId (Ipv4Address addr, uint32_t id, Time saveTime); bool LookupId (Ipv4Address addr, uint32_t id); void Purge ();