A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
60  RoutingTableEntry (Ptr<NetDevice> dev = 0, Ipv4Address dst = Ipv4Address (), uint32_t m_seqNo = 0,
61  Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), uint32_t hops = 0, Ipv4Address nextHop = Ipv4Address (),
62  Time lifetime = Simulator::Now (), Time SettlingTime = Simulator::Now (), bool changedEntries = false);
63 
66  GetDestination () const
67  {
68  return m_ipv4Route->GetDestination ();
69  }
71  GetRoute () const
72  {
73  return m_ipv4Route;
74  }
75  void
77  {
78  m_ipv4Route = route;
79  }
80  void
82  {
83  m_ipv4Route->SetGateway (nextHop);
84  }
86  GetNextHop () const
87  {
88  return m_ipv4Route->GetGateway ();
89  }
90  void
92  {
93  m_ipv4Route->SetOutputDevice (device);
94  }
96  GetOutputDevice () const
97  {
98  return m_ipv4Route->GetOutputDevice ();
99  }
101  GetInterface () const
102  {
103  return m_iface;
104  }
105  void
107  {
108  m_iface = iface;
109  }
110  void
111  SetSeqNo (uint32_t sequenceNumber)
112  {
113  m_seqNo = sequenceNumber;
114  }
115  uint32_t
116  GetSeqNo () const
117  {
118  return m_seqNo;
119  }
120  void
121  SetHop (uint32_t hopCount)
122  {
123  m_hops = hopCount;
124  }
125  uint32_t
126  GetHop () const
127  {
128  return m_hops;
129  }
130  void
131  SetLifeTime (Time lifeTime)
132  {
133  m_lifeTime = lifeTime;
134  }
135  Time
136  GetLifeTime () const
137  {
138  return (Simulator::Now () - m_lifeTime);
139  }
140  void
141  SetSettlingTime (Time settlingTime)
142  {
143  m_settlingTime = settlingTime;
144  }
145  Time
147  {
148  return (m_settlingTime);
149  }
150  void
152  {
153  m_flag = flag;
154  }
155  RouteFlags
156  GetFlag () const
157  {
158  return m_flag;
159  }
160  void
161  SetEntriesChanged (bool entriesChanged)
162  {
163  m_entriesChanged = entriesChanged;
164  }
165  bool
167  {
168  return m_entriesChanged;
169  }
174  bool
175  operator== (Ipv4Address const destination) const
176  {
177  return (m_ipv4Route->GetDestination () == destination);
178  }
179  void
180  Print (Ptr<OutputStreamWrapper> stream) const;
181 
182 private:
184  // \{
186  uint32_t m_seqNo;
188  uint32_t m_hops;
212  //\}
213 };
214 
220 {
221 public:
223  RoutingTable ();
229  bool
236  bool
237  DeleteRoute (Ipv4Address dst);
244  bool
246  bool
247  LookupRoute (Ipv4Address id, RoutingTableEntry & rt, bool forRouteInput);
253  bool
254  Update (RoutingTableEntry & rt);
260  void
261  GetListOfDestinationWithNextHop (Ipv4Address nxtHp, std::map<Ipv4Address, RoutingTableEntry> & dstList);
266  void
267  GetListOfAllRoutes (std::map<Ipv4Address, RoutingTableEntry> & allRoutes);
269  void
272  void
273  Clear ()
274  {
275  m_ipv4AddressEntry.clear ();
276  }
278  void
279  Purge (std::map<Ipv4Address, RoutingTableEntry> & removedAddresses);
281  void
282  Print (Ptr<OutputStreamWrapper> stream) const;
284  uint32_t
285  RoutingTableSize ();
292  bool
299  bool
307  bool
315  bool
322  EventId
325  // \{
327  {
328  return m_holddownTime;
329  }
331  {
332  m_holddownTime = t;
333  }
334  // \}
335 
336 private:
338  // \{
340  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
342  std::map<Ipv4Address, EventId> m_ipv4Events;
345  // \}
346 };
347 }
348 }
349 #endif /* DSDV_RTABLE_H */
Time m_holddownTime
an entry in the routing table.
Definition: dsdv-rtable.h:344
uint32_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: dsdv-rtable.h:188
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Routing table entry.
Definition: dsdv-rtable.h:56
void SetEntriesChanged(bool entriesChanged)
Definition: dsdv-rtable.h:161
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Time Getholddowntime() const
Definition: dsdv-rtable.h:326
Ipv4Address GetNextHop() const
Definition: dsdv-rtable.h:86
void Print(Ptr< OutputStreamWrapper > stream) const
Definition: dsdv-rtable.cc:197
bool operator==(Ipv4Address const destination) const
Compare destination address.
Definition: dsdv-rtable.h:175
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:271
Time m_settlingTime
Time for which the node retains an update with changed metric before broadcasting it...
Definition: dsdv-rtable.h:209
EventId GetEventId(Ipv4Address address)
Get the EcentId associated with that address.
Definition: dsdv-rtable.cc:337
void SetLifeTime(Time lifeTime)
Definition: dsdv-rtable.h:131
void SetFlag(RouteFlags flag)
Definition: dsdv-rtable.h:151
uint32_t GetSeqNo() const
Definition: dsdv-rtable.h:116
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
Definition: dsdv-rtable.cc:169
void SetNextHop(Ipv4Address nextHop)
Definition: dsdv-rtable.h:81
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
Definition: dsdv-rtable.cc:135
Ptr< Ipv4Route > GetRoute() const
Definition: dsdv-rtable.h:71
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
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:295
RouteFlags GetFlag() const
Definition: dsdv-rtable.h:156
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:219
void SetRoute(Ptr< Ipv4Route > route)
Definition: dsdv-rtable.h:76
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
uint32_t m_seqNo
Destination Sequence Number.
Definition: dsdv-rtable.h:186
~RoutingTableEntry()
Definition: dsdv-rtable.cc:63
void SetSeqNo(uint32_t sequenceNumber)
Definition: dsdv-rtable.h:111
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
Definition: dsdv-rtable.cc:207
Ptr< NetDevice > GetOutputDevice() const
Definition: dsdv-rtable.h:96
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
Time GetSettlingTime() const
Definition: dsdv-rtable.h:146
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: dsdv-rtable.h:204
std::map< Ipv4Address, EventId > m_ipv4Events
an entry in the event table.
Definition: dsdv-rtable.h:342
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: dsdv-rtable.cc:147
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: dsdv-rtable.cc:127
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition: dsdv-rtable.cc:121
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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:340
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:182
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
Definition: dsdv-rtable.cc:310
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
uint32_t GetHop() const
Definition: dsdv-rtable.h:126
void SetOutputDevice(Ptr< NetDevice > device)
Definition: dsdv-rtable.h:91
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: dsdv-rtable.cc:110
a class to store IPv4 address information on an interface
an identifier for simulation events.
Definition: event-id.h:46
Ipv4InterfaceAddress GetInterface() const
Definition: dsdv-rtable.h:101
bool GetEntriesChanged() const
Definition: dsdv-rtable.h:166
uint32_t m_entriesChanged
Flag to show if any of the routing table entries were changed with the routing update.
Definition: dsdv-rtable.h:211
RoutingTableEntry(Ptr< NetDevice > dev=0, Ipv4Address dst=Ipv4Address(), uint32_t m_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:40
Ipv4Address GetDestination() const
Definition: dsdv-rtable.h:66
void Clear()
Delete all entries from routing table.
Definition: dsdv-rtable.h:273
void Setholddowntime(Time t)
Definition: dsdv-rtable.h:330
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:195
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:263
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: dsdv-rtable.cc:251
tuple address
Definition: first.py:37
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:71
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: dsdv-rtable.h:206
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: dsdv-rtable.h:202
Time GetLifeTime() const
Definition: dsdv-rtable.h:136
void SetSettlingTime(Time settlingTime)
Definition: dsdv-rtable.h:141
void SetHop(uint32_t hopCount)
Definition: dsdv-rtable.h:121
void SetInterface(Ipv4InterfaceAddress iface)
Definition: dsdv-rtable.h:106