A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsr-maintain-buff.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Yufei Cheng
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: Yufei Cheng <yfcheng@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 in part by NSF FIND (Future Internet Design) Program
27  * under grant CNS-0626918 (Postmodern Internet Architecture),
28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
30  */
31 
32 #ifndef DSR_MAINTAIN_BUFF_H
33 #define DSR_MAINTAIN_BUFF_H
34 
35 #include <vector>
36 #include "ns3/ipv4-routing-protocol.h"
37 #include "ns3/simulator.h"
38 #include "ns3/ipv4-header.h"
39 #include "dsr-option-header.h"
40 
41 namespace ns3 {
42 namespace dsr {
47 struct LinkKey
48 {
53 
58  bool operator < (LinkKey const & o) const
59  {
60  return ((m_source < o.m_source) && (m_destination < o.m_destination)
61  && (m_ourAdd < o.m_nextHop) && (m_nextHop < o.m_nextHop)
62  );
63  }
64 };
65 
66 struct NetworkKey
67 {
68  uint16_t m_ackId;
73 
78  bool operator < (NetworkKey const & o) const
79  {
80  return ((m_ackId < o.m_ackId) && (m_ourAdd < o.m_ourAdd) && (m_nextHop < o.m_nextHop) && (m_source < o.m_source)
82  );
83  }
84 };
85 
86 struct PassiveKey
87 {
88  uint16_t m_ackId;
91  uint8_t m_segsLeft;
92 
97  bool operator < (PassiveKey const & o) const
98  {
99  return ((m_ackId < o.m_ackId) && (m_source < o.m_source)
101  );
102  }
103 };
104 
110 {
111 public:
112  // / c-tor
115  uint16_t ackId = 0, uint8_t segs = 0, Time exp = Simulator::Now ())
116  : m_packet (pa),
117  m_ourAdd (us),
118  m_nextHop (n),
119  m_src (s),
120  m_dst (dst),
121  m_ackId (ackId),
122  m_segsLeft (segs),
123  m_expire (exp + Simulator::Now ())
124  {
125  }
126 
127  // /\name Fields
128  // \{
130  {
131  return m_packet;
132  }
134  {
135  m_packet = p;
136  }
138  {
139  return m_ourAdd;
140  }
142  {
143  m_ourAdd = us;
144  }
146  {
147  return m_nextHop;
148  }
150  {
151  m_nextHop = n;
152  }
154  {
155  return m_dst;
156  }
158  {
159  m_dst = n;
160  }
162  {
163  return m_src;
164  }
166  {
167  m_src = s;
168  }
169  uint16_t GetAckId () const
170  {
171  return m_ackId;
172  }
173  void SetAckId (uint16_t ackId)
174  {
175  m_ackId = ackId;
176  }
177  uint8_t GetSegsLeft () const
178  {
179  return m_segsLeft;
180  }
181  void SetSegsLeft (uint8_t segs)
182  {
183  m_segsLeft = segs;
184  }
185  void SetExpireTime (Time exp)
186  {
187  m_expire = exp + Simulator::Now ();
188  }
190  {
191  return m_expire - Simulator::Now ();
192  }
193  // \}
194 private:
195  // / Data packet
197  // / Our own ip address
199  // / Next hop Ip address
201  // / The source address
203  // / The destination address
205  // / The data ack id
206  uint16_t m_ackId;
207  // / The ipv4 id
208  uint16_t m_id;
209  // / The segments left field
210  uint8_t m_segsLeft;
211  // / Expire time for queue entry
213 };
218 /************************************************************************************************************************/
220 {
221 public:
222  // / Default c-tor
224  {
225  }
226  // / Push entry in queue, if there is no entry with the same packet and destination address in queue.
227  bool Enqueue (MaintainBuffEntry & entry);
228  // / Return first found (the earliest) entry for given destination
229  bool Dequeue (Ipv4Address dst, MaintainBuffEntry & entry);
230  // / Remove all packets with destination IP address dst
231  void DropPacketWithNextHop (Ipv4Address nextHop);
232  // / Finds whether a packet with destination dst exists in the queue
233  bool Find (Ipv4Address nextHop);
234  // / Number of entries
235  uint32_t GetSize ();
236  // /\name Fields
237  // \{
238  uint32_t GetMaxQueueLen () const
239  {
240  return m_maxLen;
241  }
242  void SetMaxQueueLen (uint32_t len)
243  {
244  m_maxLen = len;
245  }
247  {
249  }
251  {
253  }
254  // / Verify if all the elements in the maintainence buffer entry is the same
255  bool AllEqual (MaintainBuffEntry & entry);
256  // / Verify if the maintain buffer entry is the same in every field for link ack
257  bool LinkEqual (MaintainBuffEntry & entry);
258  // / Verify if the maintain buffer entry is the same in every field for network ack
259  bool NetworkEqual (MaintainBuffEntry & entry);
260  // / Verify if the maintain buffer entry is the same in every field for promiscuous ack
261  bool PromiscEqual (MaintainBuffEntry & entry);
262  // \}
263 
264 private:
265  // / The vector of maintain buffer entries
266  std::vector<MaintainBuffEntry> m_maintainBuffer;
267  std::vector<NetworkKey> m_allNetworkKey;
268  // / Remove all expired entries
269  void Purge ();
270  // / The maximum number of packets that we allow a routing protocol to buffer.
271  uint32_t m_maxLen;
272  // / The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
274  // / Verify if the maintain buffer is equal or not
275  static bool IsEqual (MaintainBuffEntry en, const Ipv4Address nextHop)
276  {
277  return (en.GetNextHop () == nextHop);
278  }
279 };
280 /*******************************************************************************************************************************/
281 } // namespace dsr
282 } // namespace ns3
283 #endif /* DSR_MAINTAIN_BUFF_H */