A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
flame-rtable.cc
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
* Author: Kirill Andreev <andreev@iitp.ru>
19
*/
20
#include "ns3/assert.h"
21
#include "ns3/simulator.h"
22
#include "ns3/test.h"
23
#include "ns3/log.h"
24
25
#include "
flame-rtable.h
"
26
namespace
ns3 {
27
namespace
flame {
28
29
NS_LOG_COMPONENT_DEFINE
(
"FlameRtable"
);
30
31
NS_OBJECT_ENSURE_REGISTERED
(FlameRtable);
32
33
TypeId
34
FlameRtable::GetTypeId
()
35
{
36
static
TypeId
tid =
37
TypeId
(
"ns3::flame::FlameRtable"
)
38
.
SetParent
<
Object
> ().AddConstructor<FlameRtable> ()
39
.AddAttribute (
"Lifetime"
,
40
"The lifetime of the routing enrty"
,
41
TimeValue
(
Seconds
(120)), MakeTimeAccessor (
42
&
FlameRtable::m_lifetime
),
43
MakeTimeChecker ()
44
)
45
;
46
return
tid;
47
}
48
FlameRtable::FlameRtable
() :
49
m_lifetime (
Seconds
(120))
50
{
51
}
52
FlameRtable::~FlameRtable
()
53
{
54
}
55
void
56
FlameRtable::DoDispose
()
57
{
58
m_routes
.clear ();
59
}
60
void
61
FlameRtable::AddPath
(
const
Mac48Address
destination,
const
Mac48Address
retransmitter,
62
const
uint32_t interface,
const
uint8_t cost,
const
uint16_t seqnum)
63
{
64
std::map<Mac48Address, Route>::iterator i =
m_routes
.find (destination);
65
if
(i ==
m_routes
.end ())
66
{
67
Route
newroute;
68
newroute.
cost
= cost;
69
newroute.
retransmitter
= retransmitter;
70
newroute.
interface
= interface;
71
newroute.
whenExpire
=
Simulator::Now
() +
m_lifetime
;
72
newroute.
seqnum
= seqnum;
73
m_routes
[destination] = newroute;
74
return
;
75
}
76
i->second.seqnum = seqnum;
77
NS_ASSERT
(i !=
m_routes
.end ());
78
i->second.retransmitter = retransmitter;
79
i->second.interface = interface;
80
i->second.cost = cost;
81
i->second.whenExpire =
Simulator::Now
() +
m_lifetime
;
82
}
83
FlameRtable::LookupResult
84
FlameRtable::Lookup
(
Mac48Address
destination)
85
{
86
std::map<Mac48Address, Route>::iterator i =
m_routes
.find (destination);
87
if
(i ==
m_routes
.end ())
88
{
89
return
LookupResult
();
90
}
91
if
((i->second.whenExpire <
Simulator::Now
()))
92
{
93
NS_LOG_DEBUG
(
"Route has expired, sorry."
);
94
m_routes
.erase (i);
95
return
LookupResult
();
96
}
97
return
LookupResult
(i->second.retransmitter, i->second.interface, i->second.cost, i->second.seqnum);
98
}
99
bool
100
FlameRtable::LookupResult::operator==
(
const
FlameRtable::LookupResult
& o)
const
101
{
102
return
(
retransmitter
== o.
retransmitter
&&
ifIndex
== o.
ifIndex
&&
cost
== o.
cost
&&
seqnum
== o.
seqnum
);
103
}
104
105
bool
106
FlameRtable::LookupResult::IsValid
()
const
107
{
108
return
!(retransmitter ==
Mac48Address::GetBroadcast
() && ifIndex ==
INTERFACE_ANY
&& cost ==
MAX_COST
109
&& seqnum == 0);
110
}
111
112
}
// namespace flame
113
}
// namespace ns3
src
mesh
model
flame
flame-rtable.cc
Generated on Tue May 14 2013 11:08:28 for ns-3 by
1.8.1.2