A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ipv6-pmtu-cache.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Universita' di Firenze
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18  */
19 
20 #include "ipv6-pmtu-cache.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 
25 namespace ns3
26 {
27 
28 NS_LOG_COMPONENT_DEFINE("Ipv6PmtuCache");
29 
30 NS_OBJECT_ENSURE_REGISTERED(Ipv6PmtuCache);
31 
32 TypeId
34 {
35  static TypeId tid =
36  TypeId("ns3::Ipv6PmtuCache")
37  .SetParent<Object>()
38  .SetGroupName("Internet")
39  .AddAttribute(
40  "CacheExpiryTime",
41  "Validity time for a Path MTU entry. Default is 10 minutes, minimum is 5 minutes.",
42  TimeValue(Seconds(60 * 10)),
44  MakeTimeChecker(Time(Seconds(60 * 5))));
45  return tid;
46 }
47 
49 {
50 }
51 
53 {
54 }
55 
56 void
58 {
59  for (auto iter = m_pathMtuTimer.begin(); iter != m_pathMtuTimer.end(); iter++)
60  {
61  iter->second.Cancel();
62  }
63  m_pathMtuTimer.clear();
64  m_pathMtu.clear();
65 }
66 
67 uint32_t
69 {
70  NS_LOG_FUNCTION(this << dst);
71 
72  if (m_pathMtu.find(dst) != m_pathMtu.end())
73  {
74  return m_pathMtu[dst];
75  }
76  return 0;
77 }
78 
79 void
81 {
82  NS_LOG_FUNCTION(this << dst << pmtu);
83 
84  m_pathMtu[dst] = pmtu;
85  if (m_pathMtuTimer.find(dst) != m_pathMtuTimer.end())
86  {
87  m_pathMtuTimer[dst].Cancel();
88  }
89  EventId pMtuTimer;
91  m_pathMtuTimer[dst] = pMtuTimer;
92 }
93 
94 Time
96 {
97  NS_LOG_FUNCTION(this);
98  return m_validityTime;
99 }
100 
101 bool
103 {
104  NS_LOG_FUNCTION(this << validity);
105 
106  if (validity > Seconds(60 * 5))
107  {
108  m_validityTime = validity;
109  return true;
110  }
111 
112  NS_LOG_LOGIC("rejecting a PMTU validity timer lesser than 5 minutes");
113  return false;
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION(this << dst);
120 
121  m_pathMtu.erase(dst);
122  m_pathMtuTimer.erase(dst);
123 }
124 
125 } // namespace ns3
An identifier for simulation events.
Definition: event-id.h:55
Describes an IPv6 address.
Definition: ipv6-address.h:49
void DoDispose() override
Dispose object.
~Ipv6PmtuCache() override
Destructor.
std::map< Ipv6Address, uint32_t > m_pathMtu
Path MTU table.
void ClearPmtu(Ipv6Address dst)
Clears the Path MTU for the specific destination.
Ipv6PmtuCache()
Constructor.
std::map< Ipv6Address, EventId > m_pathMtuTimer
Path MTU Expiration table.
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.
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:89
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533