A Discrete-Event Network Simulator
API
 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 
34 TypeId
36 {
37  static TypeId tid =
38  TypeId ("ns3::flame::FlameRtable")
39  .SetParent<Object> ().AddConstructor<FlameRtable> ()
40  .AddAttribute ( "Lifetime",
41  "The lifetime of the routing enrty",
42  TimeValue (Seconds (120)), MakeTimeAccessor (
45  )
46  ;
47  return tid;
48 }
50  m_lifetime (Seconds (120))
51 {
52 }
54 {
55 }
56 void
58 {
59  m_routes.clear ();
60 }
61 void
62 FlameRtable::AddPath (const Mac48Address destination, const Mac48Address retransmitter,
63  const uint32_t interface, const uint8_t cost, const uint16_t seqnum)
64 {
65  std::map<Mac48Address, Route>::iterator i = m_routes.find (destination);
66  if (i == m_routes.end ())
67  {
68  Route newroute;
69  newroute.cost = cost;
70  newroute.retransmitter = retransmitter;
71  newroute.interface = interface;
72  newroute.whenExpire = Simulator::Now () + m_lifetime;
73  newroute.seqnum = seqnum;
74  m_routes[destination] = newroute;
75  return;
76  }
77  i->second.seqnum = seqnum;
78  NS_ASSERT (i != m_routes.end ());
79  i->second.retransmitter = retransmitter;
80  i->second.interface = interface;
81  i->second.cost = cost;
82  i->second.whenExpire = Simulator::Now () + m_lifetime;
83 }
86 {
87  std::map<Mac48Address, Route>::iterator i = m_routes.find (destination);
88  if (i == m_routes.end ())
89  {
90  return LookupResult ();
91  }
92  if ((i->second.whenExpire < Simulator::Now ()))
93  {
94  NS_LOG_DEBUG ("Route has expired, sorry.");
95  m_routes.erase (i);
96  return LookupResult ();
97  }
98  return LookupResult (i->second.retransmitter, i->second.interface, i->second.cost, i->second.seqnum);
99 }
100 bool
102 {
103  return (retransmitter == o.retransmitter && ifIndex == o.ifIndex && cost == o.cost && seqnum == o.seqnum);
104 }
105 
106 bool
108 {
109  return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && cost == MAX_COST
110  && seqnum == 0);
111 }
112 
113 } // namespace flame
114 } // namespace ns3
static const uint32_t MAX_COST
Maximum (the best?) path cost.
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:62
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
std::map< Mac48Address, Route > m_routes
List of routes.
Definition: flame-rtable.h:101
hold objects of type ns3::Time
Definition: nstime.h:961
static Mac48Address GetBroadcast(void)
Time m_lifetime
Lifetime parameter.
Definition: flame-rtable.h:99
Route lookup result, return type of LookupXXX methods.
Definition: flame-rtable.h:45
an EUI-48 address
Definition: mac48-address.h:41
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
bool operator==(const LookupResult &o) const
Compare route lookup results, used by tests.
static TypeId GetTypeId()
Definition: flame-rtable.cc:35
static const uint32_t INTERFACE_ANY
Means all interfaces.
Definition: flame-rtable.h:40
NS_LOG_COMPONENT_DEFINE("FlameProtocolMac")
bool IsValid() const
True for valid route.
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:452
a base class which provides memory management and object aggregation
Definition: object.h:63
Routing table entry.
Definition: flame-rtable.h:90
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: flame-rtable.cc:57
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition: flame-rtable.cc:85