A Discrete-Event Network Simulator
API
dsdv-rtable.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hemanth Narra
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: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_RTABLE_H
33 #define DSDV_RTABLE_H
34 
35 #include <cassert>
36 #include <map>
37 #include <sys/types.h>
38 #include "ns3/ipv4.h"
39 #include "ns3/ipv4-route.h"
40 #include "ns3/timer.h"
41 #include "ns3/net-device.h"
42 #include "ns3/output-stream-wrapper.h"
43 
44 namespace ns3 {
45 namespace dsdv {
47 {
48  VALID = 0, // !< VALID
49  INVALID = 1, // !< INVALID
50 };
51 
57 {
58 public:
72  RoutingTableEntry (Ptr<NetDevice> dev = 0, Ipv4Address dst = Ipv4Address (), uint32_t seqNo = 0,
73  Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), uint32_t hops = 0, Ipv4Address nextHop = Ipv4Address (),
74  Time lifetime = Simulator::Now (), Time SettlingTime = Simulator::Now (), bool changedEntries = false);
75 
82  GetDestination () const
83  {
84  return m_ipv4Route->GetDestination ();
85  }
91  GetRoute () const
92  {
93  return m_ipv4Route;
94  }
99  void
101  {
102  m_ipv4Route = route;
103  }
108  void
110  {
111  m_ipv4Route->SetGateway (nextHop);
112  }
118  GetNextHop () const
119  {
120  return m_ipv4Route->GetGateway ();
121  }
126  void
128  {
129  m_ipv4Route->SetOutputDevice (device);
130  }
137  {
138  return m_ipv4Route->GetOutputDevice ();
139  }
145  GetInterface () const
146  {
147  return m_iface;
148  }
153  void
155  {
156  m_iface = iface;
157  }
162  void
163  SetSeqNo (uint32_t sequenceNumber)
164  {
165  m_seqNo = sequenceNumber;
166  }
171  uint32_t
172  GetSeqNo () const
173  {
174  return m_seqNo;
175  }
180  void
181  SetHop (uint32_t hopCount)
182  {
183  m_hops = hopCount;
184  }
189  uint32_t
190  GetHop () const
191  {
192  return m_hops;
193  }
198  void
199  SetLifeTime (Time lifeTime)
200  {
201  m_lifeTime = lifeTime;
202  }
207  Time
208  GetLifeTime () const
209  {
210  return (Simulator::Now () - m_lifeTime);
211  }
216  void
217  SetSettlingTime (Time settlingTime)
218  {
219  m_settlingTime = settlingTime;
220  }
225  Time
227  {
228  return (m_settlingTime);
229  }
234  void
236  {
237  m_flag = flag;
238  }
243  RouteFlags
244  GetFlag () const
245  {
246  return m_flag;
247  }
252  void
253  SetEntriesChanged (bool entriesChanged)
254  {
255  m_entriesChanged = entriesChanged;
256  }
261  bool
263  {
264  return m_entriesChanged;
265  }
271  bool
272  operator== (Ipv4Address const destination) const
273  {
274  return (m_ipv4Route->GetDestination () == destination);
275  }
280  void
281  Print (Ptr<OutputStreamWrapper> stream) const;
282 
283 private:
284  // Fields
286  uint32_t m_seqNo;
288  uint32_t m_hops;
312 
313 };
314 
320 {
321 public:
323  RoutingTable ();
329  bool
336  bool
337  DeleteRoute (Ipv4Address dst);
344  bool
353  bool
354  LookupRoute (Ipv4Address id, RoutingTableEntry & rt, bool forRouteInput);
360  bool
361  Update (RoutingTableEntry & rt);
367  void
368  GetListOfDestinationWithNextHop (Ipv4Address nxtHp, std::map<Ipv4Address, RoutingTableEntry> & dstList);
373  void
374  GetListOfAllRoutes (std::map<Ipv4Address, RoutingTableEntry> & allRoutes);
379  void
382  void
383  Clear ()
384  {
385  m_ipv4AddressEntry.clear ();
386  }
391  void
392  Purge (std::map<Ipv4Address, RoutingTableEntry> & removedAddresses);
397  void
398  Print (Ptr<OutputStreamWrapper> stream) const;
403  uint32_t
404  RoutingTableSize ();
412  bool
419  bool
427  bool
435  bool
442  EventId
444 
450  {
451  return m_holddownTime;
452  }
458  {
459  m_holddownTime = t;
460  }
461 
462 private:
463  // Fields
465  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
467  std::map<Ipv4Address, EventId> m_ipv4Events;
470 
471 };
472 }
473 }
474 #endif /* DSDV_RTABLE_H */
Time Getholddowntime() const
Get hold down time (time until an invalid route may be deleted)
Definition: dsdv-rtable.h:449
Time m_holddownTime
hold down time of an expired route
Definition: dsdv-rtable.h:469
uint32_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: dsdv-rtable.h:288
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Routing table entry.
Definition: dsdv-rtable.h:56
void SetEntriesChanged(bool entriesChanged)
Set entries changed indicator.
Definition: dsdv-rtable.h:253
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint32_t GetHop() const
Get hop.
Definition: dsdv-rtable.h:190
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:272
Time m_settlingTime
Time for which the node retains an update with changed metric before broadcasting it...
Definition: dsdv-rtable.h:309
EventId GetEventId(Ipv4Address address)
Get the EcentId associated with that address.
Definition: dsdv-rtable.cc:338
uint32_t GetSeqNo() const
Get sequence number.
Definition: dsdv-rtable.h:172
void SetLifeTime(Time lifeTime)
Set lifetime.
Definition: dsdv-rtable.h:199
void SetFlag(RouteFlags flag)
Set route flags.
Definition: dsdv-rtable.h:235
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
Definition: dsdv-rtable.cc:170
void SetNextHop(Ipv4Address nextHop)
Set next hop.
Definition: dsdv-rtable.h:109
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
Definition: dsdv-rtable.cc:136
bool GetEntriesChanged() const
Get entries changed.
Definition: dsdv-rtable.h:262
Ipv4InterfaceAddress GetInterface() const
Get interface address.
Definition: dsdv-rtable.h:145
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:296
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:319
void SetRoute(Ptr< Ipv4Route > route)
Set route.
Definition: dsdv-rtable.h:100
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
uint32_t m_seqNo
Destination Sequence Number.
Definition: dsdv-rtable.h:286
~RoutingTableEntry()
Definition: dsdv-rtable.cc:64
void SetSeqNo(uint32_t sequenceNumber)
Set sequence number.
Definition: dsdv-rtable.h:163
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
Definition: dsdv-rtable.cc:208
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table entry.
Definition: dsdv-rtable.cc:198
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: dsdv-rtable.h:304
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
std::map< Ipv4Address, EventId > m_ipv4Events
an entry in the event table.
Definition: dsdv-rtable.h:467
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
Ptr< Ipv4Route > GetRoute() const
Get route.
Definition: dsdv-rtable.h:91
Time GetSettlingTime() const
Get settling time.
Definition: dsdv-rtable.h:226
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: dsdv-rtable.cc:148
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn&#39;t yet exist in routing table.
Definition: dsdv-rtable.cc:128
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: dsdv-rtable.h:136
Time GetLifeTime() const
Get lifetime.
Definition: dsdv-rtable.h:208
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition: dsdv-rtable.cc:122
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
an entry in the routing table.
Definition: dsdv-rtable.h:465
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
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:183
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
Definition: dsdv-rtable.cc:311
void SetOutputDevice(Ptr< NetDevice > device)
Set output device.
Definition: dsdv-rtable.h:127
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: dsdv-rtable.cc:111
a class to store IPv4 address information on an interface
An identifier for simulation events.
Definition: event-id.h:53
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: dsdv-rtable.cc:252
uint32_t m_entriesChanged
Flag to show if any of the routing table entries were changed with the routing update.
Definition: dsdv-rtable.h:311
RoutingTableEntry(Ptr< NetDevice > dev=0, 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:41
bool operator==(Ipv4Address const destination) const
Compare destination address.
Definition: dsdv-rtable.h:272
Ipv4Address GetDestination() const
Get destination IP address.
Definition: dsdv-rtable.h:82
void Clear()
Delete all entries from routing table.
Definition: dsdv-rtable.h:383
void Setholddowntime(Time t)
Set hold down time (time until an invalid route may be deleted)
Definition: dsdv-rtable.h:457
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for a...
Definition: dsdv-rtable.h:295
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:264
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:72
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: dsdv-rtable.h:306
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: dsdv-rtable.h:302
Ipv4Address GetNextHop() const
Get next hop.
Definition: dsdv-rtable.h:118
RouteFlags GetFlag() const
Get route flags.
Definition: dsdv-rtable.h:244
void SetSettlingTime(Time settlingTime)
Set settling time.
Definition: dsdv-rtable.h:217
void SetHop(uint32_t hopCount)
Set hop.
Definition: dsdv-rtable.h:181
void SetInterface(Ipv4InterfaceAddress iface)
Set interface address.
Definition: dsdv-rtable.h:154