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