A Discrete-Event Network Simulator
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
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("FlameRtable");
19
20namespace flame
21{
22
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::flame::FlameRtable")
30 .SetGroupName("Mesh")
31 .AddConstructor<FlameRtable>()
32 .AddAttribute("Lifetime",
33 "The lifetime of the routing entry",
34 TimeValue(Seconds(120)),
37 return tid;
38}
39
41 : m_lifetime(Seconds(120))
42{
43}
44
48
49void
51{
52 m_routes.clear();
53}
54
55void
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;
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
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
102bool
108
109bool
111{
112 return !(retransmitter == Mac48Address::GetBroadcast() && ifIndex == INTERFACE_ANY &&
113 cost == MAX_COST && seqnum == 0);
114}
115
116} // namespace flame
117} // namespace ns3
an EUI-48 address
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition object.h:78
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Routing table for FLAME.
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
void DoDispose() override
Destructor implementation.
static const uint32_t INTERFACE_ANY
Means all interfaces.
void AddPath(const Mac48Address destination, const Mac48Address retransmitter, const uint32_t interface, const uint8_t cost, const uint16_t seqnum)
Add path.
static TypeId GetTypeId()
Get the type ID.
std::map< Mac48Address, Route > m_routes
List of routes.
Time m_lifetime
Lifetime parameter.
static const uint32_t MAX_COST
Maximum (the best?) path cost.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
Route lookup result, return type of LookupXXX methods.
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
Mac48Address retransmitter
retransmitter
uint32_t seqnum
sequence number
Mac48Address retransmitter
retransmitter