A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
flame-rtable.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Kirill Andreev <andreev@iitp.ru>
7
*/
8
#include "
flame-rtable.h
"
9
10
#include "ns3/assert.h"
11
#include "ns3/log.h"
12
#include "ns3/simulator.h"
13
#include "ns3/test.h"
14
15
namespace
ns3
16
{
17
18
NS_LOG_COMPONENT_DEFINE
(
"FlameRtable"
);
19
20
namespace
flame
21
{
22
23
NS_OBJECT_ENSURE_REGISTERED
(
FlameRtable
);
24
25
TypeId
26
FlameRtable::GetTypeId
()
27
{
28
static
TypeId
tid =
TypeId
(
"ns3::flame::FlameRtable"
)
29
.
SetParent
<
Object
>()
30
.SetGroupName(
"Mesh"
)
31
.AddConstructor<
FlameRtable
>()
32
.AddAttribute(
"Lifetime"
,
33
"The lifetime of the routing entry"
,
34
TimeValue
(
Seconds
(120)),
35
MakeTimeAccessor
(&
FlameRtable::m_lifetime
),
36
MakeTimeChecker
());
37
return
tid;
38
}
39
40
FlameRtable::FlameRtable
()
41
:
m_lifetime
(
Seconds
(120))
42
{
43
}
44
45
FlameRtable::~FlameRtable
()
46
{
47
}
48
49
void
50
FlameRtable::DoDispose
()
51
{
52
m_routes
.clear();
53
}
54
55
void
56
FlameRtable::AddPath
(
const
Mac48Address
destination,
57
const
Mac48Address
retransmitter,
58
const
uint32_t
interface,
59
const
uint8_t cost,
60
const
uint16_t seqnum)
61
{
62
auto
i =
m_routes
.find(destination);
63
if
(i ==
m_routes
.end())
64
{
65
Route
newroute;
66
newroute.
cost
= cost;
67
newroute.
retransmitter
= retransmitter;
68
newroute.
interface
= interface;
69
newroute.
whenExpire
=
Simulator::Now
() +
m_lifetime
;
70
newroute.
seqnum
= seqnum;
71
m_routes
[destination] = newroute;
72
return
;
73
}
74
i->second.seqnum = seqnum;
75
NS_ASSERT
(i !=
m_routes
.end());
76
i->second.retransmitter = retransmitter;
77
i->second.interface = interface;
78
i->second.cost = cost;
79
i->second.whenExpire =
Simulator::Now
() +
m_lifetime
;
80
}
81
82
FlameRtable::LookupResult
83
FlameRtable::Lookup
(
Mac48Address
destination)
84
{
85
auto
i =
m_routes
.find(destination);
86
if
(i ==
m_routes
.end())
87
{
88
return
LookupResult
();
89
}
90
if
(i->second.whenExpire <
Simulator::Now
())
91
{
92
NS_LOG_DEBUG
(
"Route has expired, sorry."
);
93
m_routes
.erase(i);
94
return
LookupResult
();
95
}
96
return
LookupResult
(i->second.retransmitter,
97
i->second.interface,
98
i->second.cost,
99
i->second.seqnum);
100
}
101
102
bool
103
FlameRtable::LookupResult::operator==
(
const
FlameRtable::LookupResult
& o)
const
104
{
105
return
(
retransmitter
== o.
retransmitter
&&
ifIndex
== o.
ifIndex
&&
cost
== o.
cost
&&
106
seqnum
== o.
seqnum
);
107
}
108
109
bool
110
FlameRtable::LookupResult::IsValid
()
const
111
{
112
return
!(
retransmitter
==
Mac48Address::GetBroadcast
() &&
ifIndex
==
INTERFACE_ANY
&&
113
cost
==
MAX_COST
&&
seqnum
== 0);
114
}
115
116
}
// namespace flame
117
}
// namespace ns3
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::Mac48Address::GetBroadcast
static Mac48Address GetBroadcast()
Definition
mac48-address.cc:144
ns3::Object::Object
Object()
Constructor.
Definition
object.cc:96
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::TimeValue
Definition
nstime.h:1432
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
ns3::flame::FlameRtable
Routing table for FLAME.
Definition
flame-rtable.h:28
ns3::flame::FlameRtable::Lookup
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition
flame-rtable.cc:83
ns3::flame::FlameRtable::DoDispose
void DoDispose() override
Destructor implementation.
Definition
flame-rtable.cc:50
ns3::flame::FlameRtable::FlameRtable
FlameRtable()
Definition
flame-rtable.cc:40
ns3::flame::FlameRtable::INTERFACE_ANY
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition
flame-rtable.h:31
ns3::flame::FlameRtable::AddPath
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:56
ns3::flame::FlameRtable::~FlameRtable
~FlameRtable() override
Definition
flame-rtable.cc:45
ns3::flame::FlameRtable::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
flame-rtable.cc:26
ns3::flame::FlameRtable::m_routes
std::map< Mac48Address, Route > m_routes
List of routes.
Definition
flame-rtable.h:126
ns3::flame::FlameRtable::m_lifetime
Time m_lifetime
Lifetime parameter.
Definition
flame-rtable.h:124
ns3::flame::FlameRtable::MAX_COST
static const uint32_t MAX_COST
Maximum (the best?) path cost.
Definition
flame-rtable.h:33
uint32_t
flame-rtable.h
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition
assert.h:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition
log.h:257
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1345
ns3::flame
Definition
flame-header.cc:17
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition
nstime.h:1433
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition
nstime.h:1453
ns3::flame::FlameRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition
flame-rtable.h:37
ns3::flame::FlameRtable::LookupResult::ifIndex
uint32_t ifIndex
IF index.
Definition
flame-rtable.h:39
ns3::flame::FlameRtable::LookupResult::seqnum
uint16_t seqnum
sequence number
Definition
flame-rtable.h:41
ns3::flame::FlameRtable::LookupResult::IsValid
bool IsValid() const
Definition
flame-rtable.cc:110
ns3::flame::FlameRtable::LookupResult::operator==
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Definition
flame-rtable.cc:103
ns3::flame::FlameRtable::LookupResult::retransmitter
Mac48Address retransmitter
retransmitter
Definition
flame-rtable.h:38
ns3::flame::FlameRtable::LookupResult::cost
uint8_t cost
cost
Definition
flame-rtable.h:40
ns3::flame::FlameRtable::Route
Routing table entry.
Definition
flame-rtable.h:115
ns3::flame::FlameRtable::Route::seqnum
uint32_t seqnum
sequence number
Definition
flame-rtable.h:120
ns3::flame::FlameRtable::Route::whenExpire
Time whenExpire
expire when?
Definition
flame-rtable.h:119
ns3::flame::FlameRtable::Route::retransmitter
Mac48Address retransmitter
retransmitter
Definition
flame-rtable.h:116
ns3::flame::FlameRtable::Route::cost
uint32_t cost
cost
Definition
flame-rtable.h:118
ns3::flame::FlameRtable::Route::interface
uint32_t interface
interface
Definition
flame-rtable.h:117
src
mesh
model
flame
flame-rtable.cc
Generated on Wed Jun 11 2025 13:15:35 for ns-3 by
1.13.2