src/internet/model/icmpv4.cc
author Adrian S Tam <adrian.sw.tam@gmail.com>
Wed, 07 Dec 2011 11:22:10 -0500
changeset 7619 b4dee6307aa7
parent 7385 10beb0e53130
child 9704 1db7690f8e8f
permissions -rw-r--r--
Nagle's algorithm in TCP (closes bug 1039)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7176
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     2
/*
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     3
 * Copyright (c) 2008 INRIA
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     4
 *
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     7
 * published by the Free Software Foundation;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     8
 *
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    12
 * GNU General Public License for more details.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    13
 *
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    15
 * along with this program; if not, write to the Free Software
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    17
 *
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    19
 */
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
    20
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "icmpv4.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/packet.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
namespace ns3 {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
/********************************************************
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
 *        Icmpv4Header
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
 ********************************************************/
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
    30
NS_OBJECT_ENSURE_REGISTERED (Icmpv4Header);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
    31
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
Icmpv4Header::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
  static TypeId tid = TypeId ("ns3::Icmpv4Header")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
    .AddConstructor<Icmpv4Header> ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    38
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
Icmpv4Header::Icmpv4Header ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  : m_type (0),
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
    m_code (0),
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
    m_calcChecksum (false)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    45
{
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    46
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
Icmpv4Header::~Icmpv4Header ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    48
{
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    49
}
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    50
void
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
Icmpv4Header::EnableChecksum (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  m_calcChecksum = true;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    55
TypeId
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
Icmpv4Header::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    60
uint32_t
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
Icmpv4Header::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  return 4;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    65
void
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
Icmpv4Header::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  i.WriteU8 (m_type);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  i.WriteU8 (m_code);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  i.WriteHtonU16 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  if (m_calcChecksum)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
      i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
      uint16_t checksum = i.CalculateIpChecksum (i.GetSize ());
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
      i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
      i.Next (2);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
      i.WriteU16 (checksum);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
    80
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
Icmpv4Header::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  m_type = start.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  m_code = start.ReadU8 ();
7061
15f40cfaf3b3 build fixes for gcc 4.6
Andrey Mazo <mazo@iitp.ru>
parents: 6834
diff changeset
    87
  start.Next (2); // uint16_t checksum = start.ReadNtohU16 ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  return 4;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
Icmpv4Header::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
  os << "type=" << (uint32_t)m_type << ", code=" << (uint32_t)m_code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
Icmpv4Header::SetType (uint8_t type)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  m_type = type;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
Icmpv4Header::SetCode (uint8_t code)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_code = code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
uint8_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
Icmpv4Header::GetType (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  return m_type;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
uint8_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
Icmpv4Header::GetCode (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
  return m_code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
/********************************************************
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
 *        Icmpv4Echo
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
 ********************************************************/
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   120
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   121
NS_OBJECT_ENSURE_REGISTERED (Icmpv4Echo);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   122
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
Icmpv4Echo::SetIdentifier (uint16_t id)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
  m_identifier = id;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
Icmpv4Echo::SetSequenceNumber (uint16_t seq)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
  m_sequence = seq;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
Icmpv4Echo::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
{
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   136
  uint32_t size = data->GetSize ();
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   137
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   138
  // All kinds of optimizations are possible, but let's not get carried away
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   139
  // since this is probably a very uncommon thing in the big picture.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   140
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   141
  // N.B. Zero is a legal size for the alloc below even though a hardcoded zero
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   142
  // would result in  warning.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   143
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   144
  if (size != m_dataSize)
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   145
    {
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   146
      delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   147
      m_data = new uint8_t[size];
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   148
      m_dataSize = size;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   149
    }
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   150
  data->CopyData (m_data, size);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
Icmpv4Echo::GetIdentifier (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  return m_identifier;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
Icmpv4Echo::GetSequenceNumber (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  return m_sequence;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
}
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   162
uint32_t
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   163
Icmpv4Echo::GetDataSize (void) const
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
{
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   165
  return m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
}
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   167
uint32_t
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   168
Icmpv4Echo::GetData (uint8_t payload[]) const
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   169
{
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   170
  memcpy (payload, m_data, m_dataSize);
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   171
  return m_dataSize;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   172
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
Icmpv4Echo::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  static TypeId tid = TypeId ("ns3::Icmpv4Echo")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
    .AddConstructor<Icmpv4Echo> ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   179
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
Icmpv4Echo::Icmpv4Echo ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  : m_identifier (0),
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
    m_sequence (0),
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   185
    m_dataSize (0)
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   186
{
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   187
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   188
  // After construction, m_data is always valid until destruction.  This is true
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   189
  // even if m_dataSize is zero.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   190
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   191
  m_data = new uint8_t[m_dataSize];
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   192
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
Icmpv4Echo::~Icmpv4Echo ()
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   194
{
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   195
  delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   196
  m_data = 0;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   197
  m_dataSize = 0;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   198
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
Icmpv4Echo::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
Icmpv4Echo::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
{
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   207
  return 4 + m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
Icmpv4Echo::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
  start.WriteHtonU16 (m_identifier);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  start.WriteHtonU16 (m_sequence);
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   214
  start.Write (m_data, m_dataSize);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
Icmpv4Echo::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  m_identifier = start.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  m_sequence = start.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  NS_ASSERT (start.GetSize () >= 4);
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   222
  uint32_t size = start.GetSize () - 4;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   223
  if (size != m_dataSize)
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   224
    {
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   225
      delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   226
      m_data = new uint8_t[size];
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   227
      m_dataSize = size;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   228
    }
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   229
  start.Read (m_data, m_dataSize);
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   230
  return m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
Icmpv4Echo::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
  os << "identifier=" << m_identifier << ", sequence="  << m_sequence;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
/********************************************************
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
 *        Icmpv4DestinationUnreachable
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
 ********************************************************/
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   243
NS_OBJECT_ENSURE_REGISTERED (Icmpv4DestinationUnreachable);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   244
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
Icmpv4DestinationUnreachable::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
  static TypeId tid = TypeId ("ns3::Icmpv4DestinationUnreachable")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
    .AddConstructor<Icmpv4DestinationUnreachable> ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   251
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
Icmpv4DestinationUnreachable::Icmpv4DestinationUnreachable ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  // make sure that thing is initialized to get initialized bytes
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
  // when the ip payload's size is smaller than 8 bytes.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
      m_data[j] = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
Icmpv4DestinationUnreachable::SetNextHopMtu (uint16_t mtu)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
  m_nextHopMtu = mtu;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
Icmpv4DestinationUnreachable::GetNextHopMtu (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
  return m_nextHopMtu;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
Icmpv4DestinationUnreachable::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
  data->CopyData (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
Icmpv4DestinationUnreachable::SetHeader (Ipv4Header header)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
  m_header = header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
Icmpv4DestinationUnreachable::GetData (uint8_t payload[8]) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
  memcpy (payload, m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
Ipv4Header 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
Icmpv4DestinationUnreachable::GetHeader (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
  return m_header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
Icmpv4DestinationUnreachable::~Icmpv4DestinationUnreachable ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   298
{
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   299
}
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   300
TypeId
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
Icmpv4DestinationUnreachable::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   305
uint32_t
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
Icmpv4DestinationUnreachable::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
  return 4 + m_header.GetSerializedSize () + 8;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   310
void
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
Icmpv4DestinationUnreachable::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
  start.WriteU16 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
  start.WriteHtonU16 (m_nextHopMtu);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  uint32_t size = m_header.GetSerializedSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
  m_header.Serialize (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
  start.Next (size);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
  start.Write (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   320
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
Icmpv4DestinationUnreachable::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   323
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
  i.Next (2);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
  m_nextHopMtu = i.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
  uint32_t read = m_header.Deserialize (i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
  i.Next (read);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
      m_data[j] = i.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
  return i.GetDistanceFrom (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
Icmpv4DestinationUnreachable::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
  m_header.Print (os);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
  os << " org data=";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
  for (uint8_t i = 0; i < 8; i++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
      os << (uint32_t) m_data[i];
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
      if (i != 8)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   344
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   345
          os << " ";
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   346
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   348
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   349
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   350
/********************************************************
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   351
 *        Icmpv4TimeExceeded
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
 ********************************************************/
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   354
NS_OBJECT_ENSURE_REGISTERED (Icmpv4TimeExceeded);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   355
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   356
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
Icmpv4TimeExceeded::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   358
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   359
  static TypeId tid = TypeId ("ns3::Icmpv4TimeExceeded")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   360
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
    .AddConstructor<Icmpv4TimeExceeded> ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   362
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
Icmpv4TimeExceeded::Icmpv4TimeExceeded ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   367
  // make sure that thing is initialized to get initialized bytes
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   368
  // when the ip payload's size is smaller than 8 bytes.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   369
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   370
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   371
      m_data[j] = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   372
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   373
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   374
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   375
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   377
Icmpv4TimeExceeded::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   378
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   379
  data->CopyData (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   380
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   381
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   382
Icmpv4TimeExceeded::SetHeader (Ipv4Header header)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   384
  m_header = header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   385
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   387
Icmpv4TimeExceeded::GetData (uint8_t payload[8]) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   388
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   389
  memcpy (payload, m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   390
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   391
Ipv4Header 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   392
Icmpv4TimeExceeded::GetHeader (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   393
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   394
  return m_header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   395
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   396
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   397
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   398
Icmpv4TimeExceeded::~Icmpv4TimeExceeded ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   399
{
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   400
}
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   401
TypeId
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   402
Icmpv4TimeExceeded::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   403
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   405
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   406
uint32_t
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
Icmpv4TimeExceeded::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   409
  return 4 + m_header.GetSerializedSize () + 8;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   411
void
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
Icmpv4TimeExceeded::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
  start.WriteU32 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
  uint32_t size = m_header.GetSerializedSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   416
  m_header.Serialize (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
  start.Next (size);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
  start.Write (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   419
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   420
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
Icmpv4TimeExceeded::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
  i.Next (4);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
  uint32_t read = m_header.Deserialize (i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
  i.Next (read);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   428
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
      m_data[j] = i.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
  return i.GetDistanceFrom (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   433
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
Icmpv4TimeExceeded::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   436
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   437
  m_header.Print (os);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
  os << " org data=";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
  for (uint8_t i = 0; i < 8; i++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   441
      os << (uint32_t) m_data[i];
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   442
      if (i != 8)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   443
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   444
          os << " ";
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7061
diff changeset
   445
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   446
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   447
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   448
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   449
} // namespace ns3