OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
| 3 #ifndef GPSR_RQUEUE_H |
| 4 #define GPSR_RQUEUE_H |
| 5 |
| 6 #include <vector> |
| 7 #include "ns3/ipv4-routing-protocol.h" |
| 8 #include "ns3/simulator.h" |
| 9 |
| 10 |
| 11 namespace ns3 { |
| 12 namespace gpsr { |
| 13 |
| 14 /** |
| 15 * \ingroup gpsr |
| 16 * \brief GPSR Queue Entry |
| 17 */ |
| 18 class QueueEntry |
| 19 { |
| 20 public: |
| 21 typedef Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback; |
| 22 typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback; |
| 23 /// c-tor |
| 24 QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (), |
| 25 UnicastForwardCallback ucb = UnicastForwardCallback (), |
| 26 ErrorCallback ecb = ErrorCallback (), Time exp = Simulator::Now ()
) |
| 27 : m_packet (pa), |
| 28 m_header (h), |
| 29 m_ucb (ucb), |
| 30 m_ecb (ecb), |
| 31 m_expire (exp + Simulator::Now ()) |
| 32 { |
| 33 } |
| 34 |
| 35 /** |
| 36 * Compare queue entries |
| 37 * \return true if equal |
| 38 */ |
| 39 bool operator== (QueueEntry const & o) const |
| 40 { |
| 41 return ((m_packet == o.m_packet) && (m_header.GetDestination () == o.m_heade
r.GetDestination ()) && (m_expire == o.m_expire)); |
| 42 } |
| 43 ///\name Fields |
| 44 //\{ |
| 45 UnicastForwardCallback GetUnicastForwardCallback () const |
| 46 { |
| 47 return m_ucb; |
| 48 } |
| 49 void SetUnicastForwardCallback (UnicastForwardCallback ucb) |
| 50 { |
| 51 m_ucb = ucb; |
| 52 } |
| 53 ErrorCallback GetErrorCallback () const |
| 54 { |
| 55 return m_ecb; |
| 56 } |
| 57 void SetErrorCallback (ErrorCallback ecb) |
| 58 { |
| 59 m_ecb = ecb; |
| 60 } |
| 61 Ptr<const Packet> GetPacket () const |
| 62 { |
| 63 return m_packet; |
| 64 } |
| 65 void SetPacket (Ptr<const Packet> p) |
| 66 { |
| 67 m_packet = p; |
| 68 } |
| 69 Ipv4Header GetIpv4Header () const |
| 70 { |
| 71 return m_header; |
| 72 } |
| 73 void SetIpv4Header (Ipv4Header h) |
| 74 { |
| 75 m_header = h; |
| 76 } |
| 77 void SetExpireTime (Time exp) |
| 78 { |
| 79 m_expire = exp + Simulator::Now (); |
| 80 } |
| 81 Time GetExpireTime () const |
| 82 { |
| 83 return m_expire - Simulator::Now (); |
| 84 } |
| 85 //\} |
| 86 private: |
| 87 /// Data packet |
| 88 Ptr<const Packet> m_packet; |
| 89 /// IP header |
| 90 Ipv4Header m_header; |
| 91 /// Unicast forward callback |
| 92 UnicastForwardCallback m_ucb; |
| 93 /// Error callback |
| 94 ErrorCallback m_ecb; |
| 95 /// Expire time for queue entry |
| 96 Time m_expire; |
| 97 }; |
| 98 /** |
| 99 * \ingroup gpsr |
| 100 * \brief GPSR route request queue |
| 101 * |
| 102 * Since GPSR is an on demand routing we queue requests while looking for route. |
| 103 */ |
| 104 class RequestQueue |
| 105 { |
| 106 public: |
| 107 /// Default c-tor |
| 108 RequestQueue (uint32_t maxLen, Time routeToQueueTimeout) |
| 109 : m_maxLen (maxLen), |
| 110 m_queueTimeout (routeToQueueTimeout) |
| 111 { |
| 112 } |
| 113 /// Push entry in queue, if there is no entry with the same packet and destina
tion address in queue. |
| 114 bool Enqueue (QueueEntry & entry); |
| 115 /// Return first found (the earliest) entry for given destination |
| 116 bool Dequeue (Ipv4Address dst, QueueEntry & entry); |
| 117 /// Remove all packets with destination IP address dst |
| 118 void DropPacketWithDst (Ipv4Address dst); |
| 119 /// Finds whether a packet with destination dst exists in the queue |
| 120 bool Find (Ipv4Address dst); |
| 121 /// Number of entries |
| 122 uint32_t GetSize (); |
| 123 ///\name Fields |
| 124 //\{ |
| 125 uint32_t GetMaxQueueLen () const |
| 126 { |
| 127 return m_maxLen; |
| 128 } |
| 129 void SetMaxQueueLen (uint32_t len) |
| 130 { |
| 131 m_maxLen = len; |
| 132 } |
| 133 Time GetQueueTimeout () const |
| 134 { |
| 135 return m_queueTimeout; |
| 136 } |
| 137 void SetQueueTimeout (Time t) |
| 138 { |
| 139 m_queueTimeout = t; |
| 140 } |
| 141 //\} |
| 142 |
| 143 private: |
| 144 std::vector<QueueEntry> m_queue; |
| 145 /// Remove all expired entries |
| 146 void Purge (); |
| 147 /// Notify that packet is dropped from queue by timeout |
| 148 void Drop (QueueEntry en, std::string reason); |
| 149 /// The maximum number of packets that we allow a routing protocol to buffer. |
| 150 uint32_t m_maxLen; |
| 151 /// The maximum period of time that a routing protocol is allowed to buffer a
packet for, seconds. |
| 152 Time m_queueTimeout; |
| 153 static bool IsEqual (QueueEntry en, const Ipv4Address dst) |
| 154 { |
| 155 return (en.GetIpv4Header ().GetDestination () == dst); |
| 156 } |
| 157 }; |
| 158 |
| 159 |
| 160 } |
| 161 } |
| 162 |
| 163 #endif /* GPSR_RQUEUE_H */ |
OLD | NEW |