Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 2 as | |
7 * published by the Free Software Foundation; | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 * | |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | |
19 * | |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | |
22 * Information and Telecommunication Technology Center (ITTC) | |
23 * and Department of Electrical Engineering and Computer Science | |
24 * The University of Kansas Lawrence, KS USA. | |
25 * | |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | |
27 */ | |
28 | |
29 | |
30 #include <vector> | |
31 #include "ns3/ipv4-routing-protocol.h" | |
32 #include "ns3/simulator.h" | |
33 #include <string.h> | |
34 #include <sstream> | |
35 | |
36 #ifndef EPIDEMIC_PACKET_QUEUE_H | |
37 #define EPIDEMIC_PACKET_QUEUE_H | |
Peter Barnes
2014/09/23 22:54:27
Include guard should appear before any includes.
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
38 | |
39 | |
40 namespace ns3 { | |
41 namespace Epidemic { | |
42 | |
43 /** | |
44 * \ingroup epidemic | |
45 * \brief epidemic Queue Entry | |
46 */ | |
47 class QueueEntry | |
48 { | |
49 public: | |
50 /// Redefine UnicastForwardCallback | |
Peter Barnes
2014/09/23 22:54:27
Please expand this doc to:
"/// Class local synony
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
51 typedef Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback; | |
52 /// Redefine ErrorCallback | |
Peter Barnes
2014/09/23 22:54:27
Ditto previous comment.
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
53 typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback; | |
54 /// c-tor | |
55 QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (), | |
56 UnicastForwardCallback ucb = UnicastForwardCallback (), | |
57 ErrorCallback ecb = ErrorCallback (), Time exp = Simulator::Now () ,uint32_t packetID = 0) | |
58 : m_packet (pa), | |
59 m_header (h), | |
60 m_ucb (ucb), | |
61 m_ecb (ecb), | |
62 m_expire (exp), | |
63 m_packetID (packetID) | |
64 { | |
65 } | |
66 | |
67 /// Compare queue entries | |
68 bool operator== (QueueEntry const & o) const; | |
69 /// Return the UnicastForwardCallback associated with the queued packet | |
70 UnicastForwardCallback GetUnicastForwardCallback () const; | |
71 /// Set the UnicastForwardCallback associated with the queued packet | |
72 void SetUnicastForwardCallback (UnicastForwardCallback ucb); | |
73 /// Return the ErrorCallback associated with the queued packet | |
74 ErrorCallback GetErrorCallback () const; | |
75 /// Set the ErrorCallback associated with the queued packet | |
76 void SetErrorCallback (ErrorCallback ecb); | |
77 /// Return the queued packet | |
78 Ptr<const Packet> GetPacket () const; | |
79 /// Set the packet pointer | |
80 void SetPacket (Ptr<const Packet> p); | |
81 /// Return the Ipv4Header associated with the queued packet | |
82 Ipv4Header GetIpv4Header () const; | |
83 /// Set the Ipv4Header associated with the queued packet | |
84 void SetIpv4Header (Ipv4Header h); | |
85 /// Set the ExpireTime associated with the queued packet | |
86 void SetExpireTime (Time exp); | |
87 /// Return the ExpireTime associated with the queued packet | |
88 Time GetExpireTime () const; | |
89 /// Return the PacketID associated with the queued packet | |
90 uint32_t GetPacketID () const; | |
91 /// Return the PacketID associated with the queued packet | |
92 void SetPacketID (uint32_t id); | |
93 | |
94 private: | |
95 /// queued packet | |
96 Ptr<const Packet> m_packet; | |
97 /// IP header | |
98 Ipv4Header m_header; | |
99 /// Unicast forward callback | |
100 UnicastForwardCallback m_ucb; | |
101 /// Error callback | |
102 ErrorCallback m_ecb; | |
103 /// Expire time for queue entry | |
104 Time m_expire; | |
105 /// Global packet ID | |
106 uint32_t m_packetID; | |
107 }; | |
108 | |
109 | |
110 // Forward declaration | |
111 class EpidemicSummaryVectorHeader; | |
112 | |
113 /** | |
114 * \ingroup epidemic | |
115 * \brief Epidemic queue | |
116 * This queue contains Epidemic packets. | |
117 */ | |
118 class PacketQueue | |
119 { | |
120 public: | |
121 /** | |
122 * \brief Constructor for PacketQueue | |
123 * \param maxLen maximum length of the queue | |
124 */ | |
125 PacketQueue (uint32_t maxLen) | |
126 : m_maxLen (maxLen) | |
127 { | |
128 } | |
129 /// Push entry in queue mapped with the its packet ID. If it already exists, u pdate it. | |
130 bool Enqueue (QueueEntry & entry); | |
131 /// Return first found (the earliest) entry for given destination | |
132 bool Dequeue (QueueEntry & entry); | |
133 /// Return number of entries | |
134 uint32_t GetSize (); | |
135 /// Return the maximum queue length | |
136 uint32_t GetMaxQueueLen () const; | |
137 /// Set the maximum queue length | |
138 void SetMaxQueueLen (uint32_t len); | |
139 /// Return the queue timeout for each entry | |
140 Time GetQueueTimeout () const; | |
141 /// Set the queue timeout for each entry | |
142 void SetQueueTimeout (Time t); | |
143 | |
144 /// Find a packet in the Epidemic queue based on the packetID. If not found, r eturn and empty QueueEntry | |
145 QueueEntry Find (uint32_t packetID); | |
146 /// Returns the summary vector of a current node's buffer | |
147 EpidemicSummaryVectorHeader GetSummaryVector (); | |
148 /// Returns a summary vector that contains the disjoint packets between the g iven list and current buffer | |
149 EpidemicSummaryVectorHeader FindDisjointPackets (EpidemicSummaryVectorHeader l ist); | |
150 /// Drop expired packet in the current node's buffer | |
151 void DropExpiredPackets (); | |
152 | |
153 private: | |
154 /// Type to connect a global Packet id to a QueueEntry | |
155 typedef std::map<uint32_t, QueueEntry> PacketIdMap; | |
156 /// Type define PacketIdMapPair | |
Peter Barnes
2014/09/23 22:54:27
/// Pair representing a global Packet Id and a Que
mjf.alenazi
2014/11/25 19:51:52
Done.
| |
157 typedef PacketIdMap::value_type PacketIdMapPair; | |
158 /// Map to store queue entries based on the packetID | |
159 PacketIdMap m_map; | |
160 /// Compare two QueueEntry's by expire time. | |
161 static bool IsEarlier (const PacketIdMapPair & e1, | |
162 const PacketIdMapPair & e2); | |
163 | |
164 /// Remove all expired entries | |
165 void Purge (bool oldestOnly /* = false */); | |
166 /// Notify that packet is dropped from queue by timeout | |
167 void Drop (PacketIdMap::iterator en, std::string reason); | |
168 /// The maximum number of packets that we allow a routing protocol to buffer. | |
169 uint32_t m_maxLen; | |
170 | |
171 | |
172 }; | |
173 } //end namespace epidemic | |
174 } //end namespace ns3 | |
175 #endif | |
OLD | NEW |