A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aodv-rtable.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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  * Based on
19  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21  *
22  * AODV-UU implementation by Erik Nordström of Uppsala University
23  * http://core.it.uu.se/core/index.php/AODV-UU
24  *
25  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26  * Pavel Boyko <boyko@iitp.ru>
27  */
28 #ifndef AODV_RTABLE_H
29 #define AODV_RTABLE_H
30 
31 #include <stdint.h>
32 #include <cassert>
33 #include <map>
34 #include <sys/types.h>
35 #include "ns3/ipv4.h"
36 #include "ns3/ipv4-route.h"
37 #include "ns3/timer.h"
38 #include "ns3/net-device.h"
39 #include "ns3/output-stream-wrapper.h"
40 
41 namespace ns3 {
42 namespace aodv {
43 
49 {
50  VALID = 0,
51  INVALID = 1,
52  IN_SEARCH = 2,
53 };
54 
60 {
61 public:
63  RoutingTableEntry (Ptr<NetDevice> dev = 0,Ipv4Address dst = Ipv4Address (), bool vSeqNo = false, uint32_t m_seqNo = 0,
64  Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), uint16_t hops = 0,
65  Ipv4Address nextHop = Ipv4Address (), Time lifetime = Simulator::Now ());
66 
68 
70  //\{
76  bool InsertPrecursor (Ipv4Address id);
82  bool LookupPrecursor (Ipv4Address id);
88  bool DeletePrecursor (Ipv4Address id);
90  void DeleteAllPrecursors ();
95  bool IsPrecursorListEmpty () const;
99  void GetPrecursors (std::vector<Ipv4Address> & prec) const;
100  //\}
101 
103  void Invalidate (Time badLinkLifetime);
105  //\{
107  Ptr<Ipv4Route> GetRoute () const { return m_ipv4Route; }
109  void SetNextHop (Ipv4Address nextHop) { m_ipv4Route->SetGateway (nextHop); }
110  Ipv4Address GetNextHop () const { return m_ipv4Route->GetGateway (); }
114  void SetInterface (Ipv4InterfaceAddress iface) { m_iface = iface; }
115  void SetValidSeqNo (bool s) { m_validSeqNo = s; }
116  bool GetValidSeqNo () const { return m_validSeqNo; }
117  void SetSeqNo (uint32_t sn) { m_seqNo = sn; }
118  uint32_t GetSeqNo () const { return m_seqNo; }
119  void SetHop (uint16_t hop) { m_hops = hop; }
120  uint16_t GetHop () const { return m_hops; }
121  void SetLifeTime (Time lt) { m_lifeTime = lt + Simulator::Now (); }
122  Time GetLifeTime () const { return m_lifeTime - Simulator::Now (); }
123  void SetFlag (RouteFlags flag) { m_flag = flag; }
124  RouteFlags GetFlag () const { return m_flag; }
125  void SetRreqCnt (uint8_t n) { m_reqCount = n; }
126  uint8_t GetRreqCnt () const { return m_reqCount; }
128  void SetUnidirectional (bool u) { m_blackListState = u; }
129  bool IsUnidirectional () const { return m_blackListState; }
134  //\}
135 
140  bool operator== (Ipv4Address const dst) const
141  {
142  return (m_ipv4Route->GetDestination () == dst);
143  }
144  void Print (Ptr<OutputStreamWrapper> stream) const;
145 
146 private:
150  uint32_t m_seqNo;
152  uint16_t m_hops;
171 
173  std::vector<Ipv4Address> m_precursorList;
177  uint8_t m_reqCount;
182 };
183 
189 {
190 public:
192  RoutingTable (Time t);
194  //\{
197  //\}
203  bool AddRoute (RoutingTableEntry & r);
209  bool DeleteRoute (Ipv4Address dst);
216  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
220  bool Update (RoutingTableEntry & rt);
222  bool SetEntryState (Ipv4Address dst, RouteFlags state);
224  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
232  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
236  void Clear () { m_ipv4AddressEntry.clear (); }
238  void Purge ();
244  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
246  void Print (Ptr<OutputStreamWrapper> stream) const;
247 
248 private:
249  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
253  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
254 };
255 
256 }
257 }
258 
259 #endif /* AODV_RTABLE_H */