A Discrete-Event Network Simulator
API
dsdv-rtable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Hemanth Narra
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Hemanth Narra <hemanth@ittc.ku.com>
18  *
19  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20  * ResiliNets Research Group https://resilinets.org/
21  * Information and Telecommunication Technology Center (ITTC)
22  * and Department of Electrical Engineering and Computer Science
23  * The University of Kansas Lawrence, KS USA.
24  *
25  * Work supported in part by NSF FIND (Future Internet Design) Program
26  * under grant CNS-0626918 (Postmodern Internet Architecture),
27  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28  * US Department of Defense (DoD), and ITTC at The University of Kansas.
29  */
30 
31 #ifndef DSDV_RTABLE_H
32 #define DSDV_RTABLE_H
33 
34 #include "ns3/ipv4-route.h"
35 #include "ns3/ipv4.h"
36 #include "ns3/net-device.h"
37 #include "ns3/output-stream-wrapper.h"
38 #include "ns3/timer.h"
39 
40 #include <cassert>
41 #include <map>
42 #include <sys/types.h>
43 
44 namespace ns3
45 {
46 namespace dsdv
47 {
49 {
50  VALID = 0, // !< VALID
51  INVALID = 1, // !< INVALID
52 };
53 
59 {
60  public:
74  RoutingTableEntry(Ptr<NetDevice> dev = nullptr,
75  Ipv4Address dst = Ipv4Address(),
76  uint32_t seqNo = 0,
78  uint32_t hops = 0,
79  Ipv4Address nextHop = Ipv4Address(),
80  Time lifetime = Simulator::Now(),
81  Time settlingTime = Simulator::Now(),
82  bool changedEntries = false);
83 
85 
91  {
92  return m_ipv4Route->GetDestination();
93  }
94 
100  {
101  return m_ipv4Route;
102  }
103 
109  {
110  m_ipv4Route = route;
111  }
112 
117  void SetNextHop(Ipv4Address nextHop)
118  {
119  m_ipv4Route->SetGateway(nextHop);
120  }
121 
127  {
128  return m_ipv4Route->GetGateway();
129  }
130 
136  {
137  m_ipv4Route->SetOutputDevice(device);
138  }
139 
145  {
146  return m_ipv4Route->GetOutputDevice();
147  }
148 
154  {
155  return m_iface;
156  }
157 
163  {
164  m_iface = iface;
165  }
166 
171  void SetSeqNo(uint32_t sequenceNumber)
172  {
173  m_seqNo = sequenceNumber;
174  }
175 
180  uint32_t GetSeqNo() const
181  {
182  return m_seqNo;
183  }
184 
189  void SetHop(uint32_t hopCount)
190  {
191  m_hops = hopCount;
192  }
193 
198  uint32_t GetHop() const
199  {
200  return m_hops;
201  }
202 
207  void SetLifeTime(Time lifeTime)
208  {
209  m_lifeTime = lifeTime;
210  }
211 
217  {
218  return (Simulator::Now() - m_lifeTime);
219  }
220 
225  void SetSettlingTime(Time settlingTime)
226  {
227  m_settlingTime = settlingTime;
228  }
229 
235  {
236  return m_settlingTime;
237  }
238 
243  void SetFlag(RouteFlags flag)
244  {
245  m_flag = flag;
246  }
247 
253  {
254  return m_flag;
255  }
256 
261  void SetEntriesChanged(bool entriesChanged)
262  {
263  m_entriesChanged = entriesChanged;
264  }
265 
270  bool GetEntriesChanged() const
271  {
272  return m_entriesChanged;
273  }
274 
280  bool operator==(const Ipv4Address destination) const
281  {
282  return (m_ipv4Route->GetDestination() == destination);
283  }
284 
290  void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
291 
292  private:
293  // Fields
295  uint32_t m_seqNo;
297  uint32_t m_hops;
321 };
322 
328 {
329  public:
331  RoutingTable();
337  bool AddRoute(RoutingTableEntry& r);
343  bool DeleteRoute(Ipv4Address dst);
358  bool LookupRoute(Ipv4Address id, RoutingTableEntry& rt, bool forRouteInput);
364  bool Update(RoutingTableEntry& rt);
371  std::map<Ipv4Address, RoutingTableEntry>& dstList);
377  void GetListOfAllRoutes(std::map<Ipv4Address, RoutingTableEntry>& allRoutes);
383 
385  void Clear()
386  {
387  m_ipv4AddressEntry.clear();
388  }
389 
394  void Purge(std::map<Ipv4Address, RoutingTableEntry>& removedAddresses);
400  void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
405  uint32_t RoutingTableSize();
440 
446  {
447  return m_holddownTime;
448  }
449 
455  {
456  m_holddownTime = t;
457  }
458 
459  private:
460  // Fields
462  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
464  std::map<Ipv4Address, EventId> m_ipv4Events;
467 };
468 } // namespace dsdv
469 } // namespace ns3
470 #endif /* DSDV_RTABLE_H */
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to store IPv4 address information on an interface
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
Routing table entry.
Definition: dsdv-rtable.h:59
void SetHop(uint32_t hopCount)
Set hop.
Definition: dsdv-rtable.h:189
uint32_t m_seqNo
Destination Sequence Number.
Definition: dsdv-rtable.h:295
void SetLifeTime(Time lifeTime)
Set lifetime.
Definition: dsdv-rtable.h:207
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table entry.
Definition: dsdv-rtable.cc:192
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for an...
Definition: dsdv-rtable.h:304
RouteFlags GetFlag() const
Get route flags.
Definition: dsdv-rtable.h:252
bool GetEntriesChanged() const
Get entries changed.
Definition: dsdv-rtable.h:270
void SetEntriesChanged(bool entriesChanged)
Set entries changed indicator.
Definition: dsdv-rtable.h:261
Time GetSettlingTime() const
Get settling time.
Definition: dsdv-rtable.h:234
Ipv4Address GetDestination() const
Get destination IP address.
Definition: dsdv-rtable.h:90
Ptr< Ipv4Route > GetRoute() const
Get route.
Definition: dsdv-rtable.h:99
void SetSettlingTime(Time settlingTime)
Set settling time.
Definition: dsdv-rtable.h:225
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: dsdv-rtable.h:315
void SetOutputDevice(Ptr< NetDevice > device)
Set output device.
Definition: dsdv-rtable.h:135
bool m_entriesChanged
Flag to show if any of the routing table entries were changed with the routing update.
Definition: dsdv-rtable.h:320
~RoutingTableEntry()
Definition: dsdv-rtable.cc:68
void SetNextHop(Ipv4Address nextHop)
Set next hop.
Definition: dsdv-rtable.h:117
void SetRoute(Ptr< Ipv4Route > route)
Set route.
Definition: dsdv-rtable.h:108
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: dsdv-rtable.h:313
RoutingTableEntry(Ptr< NetDevice > dev=nullptr, Ipv4Address dst=Ipv4Address(), uint32_t seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint32_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now(), Time settlingTime=Simulator::Now(), bool changedEntries=false)
c-tor
Definition: dsdv-rtable.cc:44
bool operator==(const Ipv4Address destination) const
Compare destination address.
Definition: dsdv-rtable.h:280
Ipv4InterfaceAddress GetInterface() const
Get interface address.
Definition: dsdv-rtable.h:153
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: dsdv-rtable.h:311
Time m_settlingTime
Time for which the node retains an update with changed metric before broadcasting it.
Definition: dsdv-rtable.h:318
uint32_t GetSeqNo() const
Get sequence number.
Definition: dsdv-rtable.h:180
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: dsdv-rtable.h:144
Time GetLifeTime() const
Get lifetime.
Definition: dsdv-rtable.h:216
void SetFlag(RouteFlags flag)
Set route flags.
Definition: dsdv-rtable.h:243
uint32_t GetHop() const
Get hop.
Definition: dsdv-rtable.h:198
uint32_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: dsdv-rtable.h:297
Ipv4Address GetNextHop() const
Get next hop.
Definition: dsdv-rtable.h:126
void SetInterface(Ipv4InterfaceAddress iface)
Set interface address.
Definition: dsdv-rtable.h:162
void SetSeqNo(uint32_t sequenceNumber)
Set sequence number.
Definition: dsdv-rtable.h:171
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:328
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:77
Time m_holddownTime
hold down time of an expired route
Definition: dsdv-rtable.h:466
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: dsdv-rtable.cc:113
bool ForceDeleteIpv4Event(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
Definition: dsdv-rtable.cc:319
void Clear()
Delete all entries from routing table.
Definition: dsdv-rtable.h:385
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: dsdv-rtable.cc:125
void Setholddowntime(Time t)
Set hold down time (time until an invalid route may be deleted)
Definition: dsdv-rtable.h:454
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
Definition: dsdv-rtable.cc:334
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
Definition: dsdv-rtable.cc:132
Time Getholddowntime() const
Get hold down time (time until an invalid route may be deleted)
Definition: dsdv-rtable.h:445
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
an entry in the routing table.
Definition: dsdv-rtable.h:462
void GetListOfDestinationWithNextHop(Ipv4Address nxtHp, std::map< Ipv4Address, RoutingTableEntry > &dstList)
Lookup list of addresses for which nxtHp is the next Hop address.
Definition: dsdv-rtable.cc:178
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
Definition: dsdv-rtable.cc:268
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: dsdv-rtable.cc:144
EventId GetEventId(Ipv4Address address)
Get the EventId associated with that address.
Definition: dsdv-rtable.cc:361
bool AddIpv4Event(Ipv4Address address, EventId id)
Add an event for a destination address so that the update to for that destination is sent after the e...
Definition: dsdv-rtable.cc:295
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition: dsdv-rtable.cc:119
std::map< Ipv4Address, EventId > m_ipv4Events
an entry in the event table.
Definition: dsdv-rtable.h:464
bool AnyRunningEvent(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
Definition: dsdv-rtable.cc:302
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
Definition: dsdv-rtable.cc:224
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
Definition: dsdv-rtable.cc:166
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.