A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsr-network-queue.h
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_NETWORK_QUEUE_H
33 #define DSR_NETWORK_QUEUE_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 {
43 
44 enum DsrMessageType
45 {
46  DSR_CONTROL_PACKET = 1,
47  DSR_DATA_PACKET = 2
48 };
54 {
55 public:
58  Time exp = Simulator::Now (), Ptr<Ipv4Route> r = 0)
59  : m_packet (pa),
60  m_srcAddr (s),
61  m_nextHopAddr (n),
62  tstamp (exp),
63  m_ipv4Route (r)
64  {
65  }
70  bool operator== (DsrNetworkQueueEntry const & o) const
71  {
72  return ((m_packet == o.m_packet) && (m_srcAddr == o.m_srcAddr) && (m_nextHopAddr == o.m_nextHopAddr)
73  && (tstamp == o.tstamp) && (m_ipv4Route == o.m_ipv4Route));
74  }
75 
77  //\{
78  Ptr<const Packet> GetPacket () const
79  {
80  return m_packet;
81  }
82  void SetPacket (Ptr<const Packet> p)
83  {
84  m_packet = p;
85  }
86  Ptr<Ipv4Route> GetIpv4Route () const
87  {
88  return m_ipv4Route;
89  }
90  void SetIpv4Route (Ptr<Ipv4Route> route)
91  {
92  m_ipv4Route = route;
93  }
94  Ipv4Address GetSourceAddress () const
95  {
96  return m_srcAddr;
97  }
98  void SetSourceAddress (Ipv4Address addr)
99  {
100  m_srcAddr = addr;
101  }
102  Ipv4Address GetNextHopAddress () const
103  {
104  return m_nextHopAddr;
105  }
106  void SetNextHopAddress (Ipv4Address addr)
107  {
108  m_nextHopAddr = addr;
109  }
110  Time GetInsertedTimeStamp (void) const
111  {
112  return tstamp;
113  }
114  void SetInsertedTimeStamp (Time time)
115  {
116  tstamp = time;
117  }
118  //\}
119 private:
122  Ipv4Address m_srcAddr;
123  Ipv4Address m_nextHopAddr;
124  Time tstamp;
127 };
128 
129 class DsrNetworkQueue : public Object
130 {
131 public:
132  static TypeId GetTypeID (void);
134  DsrNetworkQueue ();
135  DsrNetworkQueue (uint32_t maxLen, Time maxDelay);
136  ~DsrNetworkQueue ();
138  bool Enqueue (DsrNetworkQueueEntry & entry);
140  bool Dequeue (DsrNetworkQueueEntry & entry);
142  uint32_t GetSize ();
143 
144  void SetMaxNetworkSize (uint32_t maxSize);
145  void SetMaxNetworkDelay (Time delay);
146  uint32_t GetMaxNetworkSize (void) const;
147  Time GetMaxNetworkDelay (void) const;
148  void Flush (void);
149 
150  std::vector<DsrNetworkQueueEntry> & GetQueue ()
151  {
152  return m_dsrNetworkQueue;
153  }
154 
155 private:
156  void Cleanup (void);
157  std::vector<DsrNetworkQueueEntry> m_dsrNetworkQueue;
158  uint32_t m_size;
159  uint32_t m_maxSize;
160  Time m_maxDelay;
161 };
162 
163 } // namespace dsr
164 } // namespace ns3
165 
166 #endif /* DSR_NETWORK_QUEUE_H */
keep track of time unit.
Definition: nstime.h:149
DsrNetworkQueueEntry(Ptr< const Packet > pa=0, Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), Ptr< Ipv4Route > r=0)
c-tor
uint32_t GetSize()
Number of entries.
bool operator==(DsrNetworkQueueEntry const &o) const
bool Enqueue(DsrNetworkQueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
bool Dequeue(DsrNetworkQueueEntry &entry)
Return first found (the earliest) entry for given destination.
Ptr< const Packet > m_packet
Data packet.
DSR Network Queue Entry.
Ptr< Ipv4Route > m_ipv4Route
Ipv4Route.
static Time Now(void)
Definition: simulator.cc:179
DsrNetworkQueue()
Default c-tor.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44