A Discrete-Event Network Simulator
API
flame-rtable.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 IITP RAS
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: Kirill Andreev <andreev@iitp.ru>
18  */
19 #include "flame-rtable.h"
20 
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include "ns3/test.h"
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("FlameRtable");
30 
31 namespace flame
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(FlameRtable);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId("ns3::flame::FlameRtable")
40  .SetParent<Object>()
41  .SetGroupName("Mesh")
42  .AddConstructor<FlameRtable>()
43  .AddAttribute("Lifetime",
44  "The lifetime of the routing entry",
45  TimeValue(Seconds(120)),
47  MakeTimeChecker());
48  return tid;
49 }
50 
52  : m_lifetime(Seconds(120))
53 {
54 }
55 
57 {
58 }
59 
60 void
62 {
63  m_routes.clear();
64 }
65 
66 void
68  const Mac48Address retransmitter,
69  const uint32_t interface,
70  const uint8_t cost,
71  const uint16_t seqnum)
72 {
73  auto i = m_routes.find(destination);
74  if (i == m_routes.end())
75  {
76  Route newroute;
77  newroute.cost = cost;
78  newroute.retransmitter = retransmitter;
79  newroute.interface = interface;
80  newroute.whenExpire = Simulator::Now() + m_lifetime;
81  newroute.seqnum = seqnum;
82  m_routes[destination] = newroute;
83  return;
84  }
85  i->second.seqnum = seqnum;
86  NS_ASSERT(i != m_routes.end());
87  i->second.retransmitter = retransmitter;
88  i->second.interface = interface;
89  i->second.cost = cost;
90  i->second.whenExpire = Simulator::Now() + m_lifetime;
91 }
92 
95 {
96  auto i = m_routes.find(destination);
97  if (i == m_routes.end())
98  {
99  return LookupResult();
100  }
101  if (i->second.whenExpire < Simulator::Now())
102  {
103  NS_LOG_DEBUG("Route has expired, sorry.");
104  m_routes.erase(i);
105  return LookupResult();
106  }
107  return LookupResult(i->second.retransmitter,
108  i->second.interface,
109  i->second.cost,
110  i->second.seqnum);
111 }
112 
113 bool
115 {
116  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && cost == o.cost &&
117  seqnum == o.seqnum);
118 }
119 
120 bool
122 {
123  return !(retransmitter == Mac48Address::GetBroadcast() && ifIndex == INTERFACE_ANY &&
124  cost == MAX_COST && seqnum == 0);
125 }
126 
127 } // namespace flame
128 } // namespace ns3
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition: object.h:89
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Routing table for FLAME.
Definition: flame-rtable.h:39
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition: flame-rtable.cc:94
void DoDispose() override
Destructor implementation.
Definition: flame-rtable.cc:61
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition: flame-rtable.h:42
void AddPath(const Mac48Address destination, const Mac48Address retransmitter, const uint32_t interface, const uint8_t cost, const uint16_t seqnum)
Add path.
Definition: flame-rtable.cc:67
static TypeId GetTypeId()
Get the type ID.
Definition: flame-rtable.cc:37
std::map< Mac48Address, Route > m_routes
List of routes.
Definition: flame-rtable.h:137
Time m_lifetime
Lifetime parameter.
Definition: flame-rtable.h:135
static const uint32_t MAX_COST
Maximum (the best?) path cost.
Definition: flame-rtable.h:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
Route lookup result, return type of LookupXXX methods.
Definition: flame-rtable.h:48
uint16_t seqnum
sequence number
Definition: flame-rtable.h:52
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Mac48Address retransmitter
retransmitter
Definition: flame-rtable.h:49
Routing table entry.
Definition: flame-rtable.h:126
uint32_t seqnum
sequence number
Definition: flame-rtable.h:131
Mac48Address retransmitter
retransmitter
Definition: flame-rtable.h:127