A Discrete-Event Network Simulator
API
ipv6-pmtu-cache.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Universita' di Firenze
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 #include "ipv6-pmtu-cache.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("Ipv6PmtuCache");
28 
29 NS_OBJECT_ENSURE_REGISTERED (Ipv6PmtuCache);
30 
32 {
33  static TypeId tid = TypeId ("ns3::Ipv6PmtuCache")
34  .SetParent<Object> ()
35  .SetGroupName ("Internet")
36  .AddAttribute ("CacheExpiryTime",
37  "Validity time for a Path MTU entry. Default is 10 minutes, minimum is 5 minutes.",
38  TimeValue (Seconds (60 * 10)),
40  MakeTimeChecker (Time (Seconds (60 * 5))))
41  ;
42  return tid;
43 }
44 
46 {
47 }
48 
50 {
51 }
52 
54 {
55  for (pathMtuTimerIter iter = m_pathMtuTimer.begin (); iter != m_pathMtuTimer.end (); iter++)
56  {
57  iter->second.Cancel ();
58  }
59  m_pathMtuTimer.clear ();
60  m_pathMtu.clear ();
61 }
62 
64 {
65  NS_LOG_FUNCTION (this << dst);
66 
67  if (m_pathMtu.find (dst) != m_pathMtu.end ())
68  {
69  return m_pathMtu[dst];
70  }
71  return 0;
72 }
73 
74 void Ipv6PmtuCache::SetPmtu (Ipv6Address dst, uint32_t pmtu)
75 {
76  NS_LOG_FUNCTION (this << dst << pmtu);
77 
78  m_pathMtu[dst] = pmtu;
79  if (m_pathMtuTimer.find (dst) != m_pathMtuTimer.end ())
80  {
81  m_pathMtuTimer[dst].Cancel ();
82  }
83  EventId pMtuTimer;
85  m_pathMtuTimer[dst] = pMtuTimer;
86 }
87 
89 {
90  NS_LOG_FUNCTION (this);
91  return m_validityTime;
92 }
93 
95 {
96  NS_LOG_FUNCTION (this << validity);
97 
98  if (validity > Seconds (60 * 5))
99  {
100  m_validityTime = validity;
101  return true;
102  }
103 
104  NS_LOG_LOGIC ("rejecting a PMTU validity timer lesser than 5 minutes");
105  return false;
106 }
107 
109 {
110  NS_LOG_FUNCTION (this << dst);
111 
112  m_pathMtu.erase (dst);
113  m_pathMtuTimer.erase (dst);
114 }
115 
116 }
117 
An identifier for simulation events.
Definition: event-id.h:54
Describes an IPv6 address.
Definition: ipv6-address.h:50
std::map< Ipv6Address, uint32_t > m_pathMtu
Path MTU table.
std::map< Ipv6Address, EventId >::iterator pathMtuTimerIter
Container of the IPv6 PMTU data (Ipv6 destination address and expiration event).
void ClearPmtu(Ipv6Address dst)
Clears the Path MTU for the specific destination.
Ipv6PmtuCache()
Constructor.
std::map< Ipv6Address, EventId > m_pathMtuTimer
Path MTU Expiration table.
~Ipv6PmtuCache()
Destructor.
static TypeId GetTypeId()
Get the type ID.
Time GetPmtuValidityTime() const
Gets the Path MTU validity time.
Time m_validityTime
Path MTU entry validity time.
uint32_t GetPmtu(Ipv6Address dst)
Gets the known Path MTU for the specific destination.
virtual void DoDispose()
Dispose object.
bool SetPmtuValidityTime(Time validity)
Sets the Path MTU validity time (minimum is 5 minutes)
void SetPmtu(Ipv6Address dst, uint32_t pmtu)
Sets the Path MTU for the specific destination.
A base class which provides memory management and object aggregation.
Definition: object.h:88
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
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:1309
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522