src/internet/model/ipv6-pmtu-cache.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Mon, 12 Aug 2013 06:51:18 +0200
changeset 10127 f4cee68de571
child 10137 3e25a23e7c48
permissions -rw-r--r--
Bug 1721 - Path MTU isn't handled properly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10127
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     2
/*
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     3
 * Copyright (c) 2013 Universita' di Firenze
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     4
 *
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     8
 *
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    12
 * GNU General Public License for more details.
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    13
 *
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    17
 *
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    18
 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    19
 */
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    20
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    21
#include "ipv6-pmtu-cache.h"
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    22
#include "ns3/log.h"
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    23
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    24
NS_LOG_COMPONENT_DEFINE ("Ipv6PmtuCache");
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    25
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    26
namespace ns3 {
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    27
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    28
NS_OBJECT_ENSURE_REGISTERED (Ipv6PmtuCache);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    29
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    30
TypeId Ipv6PmtuCache::GetTypeId ()
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    31
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    32
  static TypeId tid = TypeId ("ns3::Ipv6PmtuCache")
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    33
    .SetParent<Object> ()
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    34
    .AddAttribute ("CacheExpiryTime",
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    35
                   "Validity time for a Path MTU entry. Default is 10 minutes, minimum is 5 minutes.",
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    36
                   TimeValue (Seconds (60 * 10)),
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    37
                   MakeTimeAccessor (&Ipv6PmtuCache::m_validityTime),
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    38
                   MakeTimeChecker (Time (Seconds (60 * 5))))
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    39
  ;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    40
  return tid;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    41
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    42
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    43
Ipv6PmtuCache::Ipv6PmtuCache ()
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    44
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    45
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    46
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    47
Ipv6PmtuCache::~Ipv6PmtuCache ()
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    48
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    49
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    50
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    51
void Ipv6PmtuCache::DoDispose ()
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    52
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    53
  for (pathMtuTimerIter iter = m_pathMtuTimer.begin (); iter != m_pathMtuTimer.end (); iter++)
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    54
    {
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    55
      iter->second.Cancel ();
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    56
    }
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    57
  m_pathMtuTimer.clear ();
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    58
  m_pathMtu.clear ();
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    59
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    60
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    61
uint32_t Ipv6PmtuCache::GetPmtu (Ipv6Address dst)
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    62
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    63
  NS_LOG_FUNCTION (this << dst);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    64
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    65
  if (m_pathMtu.find (dst) != m_pathMtu.end ())
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    66
    {
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    67
      return m_pathMtu[dst];
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    68
    }
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    69
  return 0;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    70
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    71
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    72
void Ipv6PmtuCache::SetPmtu (Ipv6Address dst, uint32_t pmtu)
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    73
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    74
  NS_LOG_FUNCTION (this << dst << pmtu);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    75
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    76
  m_pathMtu[dst] = pmtu;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    77
  if (m_pathMtuTimer.find (dst) != m_pathMtuTimer.end ())
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    78
    {
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    79
      m_pathMtuTimer[dst].Cancel ();
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    80
    }
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    81
  EventId pMtuTimer;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    82
  pMtuTimer = Simulator::Schedule (m_validityTime, &Ipv6PmtuCache::ClearPmtu, this, dst);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    83
  m_pathMtuTimer[dst] = pMtuTimer;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    84
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    85
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    86
Time Ipv6PmtuCache::GetPmtuValidityTime () const
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    87
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    88
  NS_LOG_FUNCTION (this);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    89
  return m_validityTime;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    90
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    91
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    92
bool Ipv6PmtuCache::SetPmtuValidityTime (Time validity)
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    93
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    94
  NS_LOG_FUNCTION (this << validity);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    95
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    96
  if (validity > Seconds (60 * 5))
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    97
    {
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    98
      m_validityTime = validity;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
    99
      return true;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   100
    }
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   101
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   102
  NS_LOG_LOGIC ("rejecting a PMTU validity timer lesser than 5 minutes");
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   103
  return false;
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   104
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   105
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   106
void Ipv6PmtuCache::ClearPmtu (Ipv6Address dst)
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   107
{
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   108
  NS_LOG_FUNCTION (this << dst);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   109
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   110
  m_pathMtu.erase (dst);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   111
  m_pathMtuTimer.erase (dst);
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   112
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   113
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   114
}
f4cee68de571 Bug 1721 - Path MTU isn't handled properly
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
diff changeset
   115