--- a/src/routing/aodv/aodv-rqueue.cc Fri Jul 03 15:09:25 2009 +0400
+++ b/src/routing/aodv/aodv-rqueue.cc Fri Jul 03 15:50:19 2009 +0400
@@ -22,125 +22,87 @@
* Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru>
*/
-#include <assert.h>
#include "aodv-rqueue.h"
#include "ns3/simulator.h"
-#include <vector>
-
+#include <algorithm>
namespace ns3 {
- namespace aodv {
+namespace aodv {
-#define CURRENT_TIME Simulator::Now()
- /*
- Packet Queue used by AODV.
- */
+aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT)
+{
+}
- aodv_rqueue::aodv_rqueue() : limit_(AODV_RTQ_MAX_LEN), timeout_(AODV_RTQ_TIMEOUT)
- {
- }
+void
+aodv_rqueue::enque(QueueEntry entry)
+{
+ // Purge any packets that have timed out.
+ purge();
+ entry.enExpire = Simulator::Now() + timeout_;
- void
- aodv_rqueue::enque(QueueEntry entry) {
- /*
- * Purge any packets that have timed out.
- */
- purge();
- entry.enExpire = CURRENT_TIME + timeout_;
+ if (queue.size() == limit_) drop(remove_head()); // drop the most aged packet
+ queue.push_back(entry);
+}
- if (queue.size() == limit_) {
- // decrements lenght of queue
- QueueEntry *p0 = remove_head();
- NS_ASSERT(p0);
- if(p0->enExpire > CURRENT_TIME)
- {
- // drop(p0, DROP_RTR_QFULL);
- drop();
- }
- else {
- // drop(p0, DROP_RTR_QTIMEOUT);
- drop();
- }
- }
- queue.push_back(entry);
+QueueEntry
+aodv_rqueue::deque()
+{
+ purge();
+ return remove_head();
+}
- }
-
-
- QueueEntry*
- aodv_rqueue::deque() {
- QueueEntry * entry;
- /*
- * Purge any packets that have timed out.
- */
- purge();
- entry = remove_head();
- return entry;
-
- }
-
+bool
+aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry)
+{
+ purge();
+ for(std::vector<QueueEntry>::iterator i = queue.begin(); i != queue.end(); ++i)
+ if(i->header.GetDestination() == dst)
+ {
+ entry = *i;
+ queue.erase(i);
+ return true;
+ }
+ return false;
+}
- bool
- aodv_rqueue::deque(Ipv4Address dst, QueueEntry & entry)
- {
- /*
- * Purge any packets that have timed out.
- */
- purge();
- for( std::vector<QueueEntry>::iterator i = queue.begin(); i != queue.end(); ++i)
- if(i->header.GetDestination() == dst)
- {
- entry = *i;
- queue.erase(i);
- return true;
- }
- return false;
- }
+bool
+aodv_rqueue::find(Ipv4Address dst)
+{
+ for( std::vector<QueueEntry>::const_iterator i = queue.begin(); i != queue.end(); ++i)
+ if(i->header.GetDestination() == dst)
+ return true;
+ return false;
+}
- bool
- aodv_rqueue::find(Ipv4Address dst)
- {
- for( std::vector<QueueEntry>::const_iterator i = queue.begin(); i != queue.end(); ++i)
- if(i->header.GetDestination() == dst)
- return true;
- return false;
- }
-
-
-
+QueueEntry
+aodv_rqueue::remove_head()
+{
+ QueueEntry entry = queue.front();
+ queue.erase(queue.begin());
+ return entry;
+}
- /*
- Private Routines
- */
-
- QueueEntry*
- aodv_rqueue::remove_head() {
- QueueEntry * entry = &queue.front();
- queue.erase(queue.begin());
- return entry;
- }
-
-
-
-
-
-
-
+struct IsExpired
+{
+ bool operator() (QueueEntry const & e) const
+ {
+ return (e.enExpire > Simulator::Now());
+ }
+};
- void
- aodv_rqueue::purge()
- {
- QueueEntry * entry;
- for( std::vector<QueueEntry>::iterator i = queue.begin(); i != queue.end(); ++i)
- if(i->enExpire > CURRENT_TIME)
- {
- entry = &(*i);
- queue.erase(i);
- // drop(entry, DROP_RTR_QTIMEOUT);
- drop();
- }
- }
+void
+aodv_rqueue::purge()
+{
+ std::vector<QueueEntry>::iterator i = std::remove_if(queue.begin(), queue.end(), IsExpired());
+ for (std::vector<QueueEntry>::iterator j = i ; j < queue.end(); ++j)
+ drop (*j);
+ queue.erase(i, queue.end());
+}
-
+void
+aodv_rqueue::drop(QueueEntry)
+{
+ // TODO do nothing now.
+}
- }}
+}}
--- a/src/routing/aodv/aodv-rqueue.h Fri Jul 03 15:09:25 2009 +0400
+++ b/src/routing/aodv/aodv-rqueue.h Fri Jul 03 15:50:19 2009 +0400
@@ -21,16 +21,9 @@
*
* Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru>
*/
-
-
-
-
-
-
#ifndef __aodv_rqueue_h__
#define __aodv_rqueue_h_
-//#include <packet.h>
#include "ns3/ipv4-header.h"
#include "ns3/nstime.h"
#include "ns3/packet.h"
@@ -39,13 +32,10 @@
namespace ns3 {
namespace aodv {
-
- /// The maximum number of packets that we allow a routing protocol to buffer.
-#define AODV_RTQ_MAX_LEN 64
-
-
- /// The maximum period of time that a routing protocol is allowed to buffer a packet for.
-#define AODV_RTQ_TIMEOUT 30 // seconds
+/// The maximum number of packets that we allow a routing protocol to buffer.
+#define AODV_RTQ_MAX_LEN 64
+/// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
+#define AODV_RTQ_TIMEOUT 30
struct QueueEntry
{
@@ -54,29 +44,32 @@
Time enExpire;
};
-inline void drop() {}
-class aodv_rqueue {
+class aodv_rqueue
+{
public:
/// default c-tor
aodv_rqueue();
/// Push element in queue.
- void enque(QueueEntry entry);
+ void enque(QueueEntry entry);
/// Returns a element from the head of the queue.
- QueueEntry * deque();
-
+ QueueEntry deque();
+ /// Return first found (the earliest) entry for given destination
bool deque(Ipv4Address dst, QueueEntry & entry);
/// Finds whether a packet with destination dst exists in the queue
bool find(Ipv4Address dst);
private:
std::vector<QueueEntry> queue;
- QueueEntry * remove_head();
+ /// Remove and return first entry from queue
+ QueueEntry remove_head();
void purge();
-// void findPacketWithDst(Ipv4Address dst, Packet*& p, Packet*& prev);
- /// Find packet with destination address dst, return true
+ /// Find packet with destination address dst, return true on success
bool findPacketWithDst(Ipv4Address dst, QueueEntry & entry);
- unsigned int limit_;
- Time timeout_;
+ /// Notify that packet is dropped from queue by timeout
+ void drop (QueueEntry e);
+
+ uint32_t limit_;
+ Time timeout_;
};
}}
--- a/src/routing/aodv/aodv-rtable.h Fri Jul 03 15:09:25 2009 +0400
+++ b/src/routing/aodv/aodv-rtable.h Fri Jul 03 15:50:19 2009 +0400
@@ -136,7 +136,6 @@
std::vector<AODV_Neighbor> rt_nblist;
};
-
/**
* \ingroup aodv
* The Routing Table