src/internet-stack/icmpv4.cc
author Josh Pelkey <jpelkey@gatech.edu>
Sun, 16 May 2010 20:10:14 -0400
changeset 6301 58799c1b94b0
parent 4575 ee3191a0b560
permissions -rw-r--r--
register icmpv4 objects
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
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> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
    ;
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)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
{}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
Icmpv4Header::~Icmpv4Header ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
{}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
Icmpv4Header::EnableChecksum (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  m_calcChecksum = true;
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
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
Icmpv4Header::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  return GetTypeId ();
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
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
Icmpv4Header::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  return 4;
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
Icmpv4Header::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  i.WriteU8 (m_type);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  i.WriteU8 (m_code);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  i.WriteHtonU16 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  if (m_calcChecksum)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
      i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
      uint16_t checksum = i.CalculateIpChecksum (i.GetSize ());
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
      i.Next (2);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
      i.WriteU16 (checksum);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
Icmpv4Header::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  m_type = start.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  m_code = start.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  uint16_t checksum;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  checksum = start.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
  return 4;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
Icmpv4Header::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  os << "type=" << (uint32_t)m_type << ", code=" << (uint32_t)m_code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
}
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
Icmpv4Header::SetType (uint8_t type)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
  m_type = type;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
Icmpv4Header::SetCode (uint8_t code)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  m_code = code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
uint8_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
Icmpv4Header::GetType (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  return m_type;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
uint8_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
Icmpv4Header::GetCode (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
  return m_code;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
}
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
 *        Icmpv4Echo
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
 ********************************************************/
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   119
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   120
NS_OBJECT_ENSURE_REGISTERED (Icmpv4Echo);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   121
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
Icmpv4Echo::SetIdentifier (uint16_t id)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
  m_identifier = id;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
Icmpv4Echo::SetSequenceNumber (uint16_t seq)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
  m_sequence = seq;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
Icmpv4Echo::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
{
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   135
  uint32_t size = data->GetSize ();
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   136
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   137
  // 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
   138
  // 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
   139
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   140
  // 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
   141
  // would result in  warning.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   142
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   143
  if (size != m_dataSize)
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   144
    {
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   145
      delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   146
      m_data = new uint8_t[size];
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   147
      m_dataSize = size;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   148
    }
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   149
  data->CopyData (m_data, size);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
Icmpv4Echo::GetIdentifier (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
  return m_identifier;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
Icmpv4Echo::GetSequenceNumber (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
  return m_sequence;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
}
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   161
uint32_t
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   162
Icmpv4Echo::GetDataSize (void) const
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
{
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   164
  return m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
}
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   166
uint32_t
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   167
Icmpv4Echo::GetData (uint8_t payload[]) const
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   168
{
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   169
  memcpy (payload, m_data, m_dataSize);
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   170
  return m_dataSize;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   171
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
Icmpv4Echo::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  static TypeId tid = TypeId ("ns3::Icmpv4Echo")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
    .AddConstructor<Icmpv4Echo> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
    ;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
Icmpv4Echo::Icmpv4Echo ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  : m_identifier (0),
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
    m_sequence (0),
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   184
    m_dataSize (0)
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   185
{
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   186
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   187
  // 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
   188
  // even if m_dataSize is zero.
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   189
  //
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   190
  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
   191
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
Icmpv4Echo::~Icmpv4Echo ()
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   193
{
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   194
  delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   195
  m_data = 0;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   196
  m_dataSize = 0;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   197
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
Icmpv4Echo::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
Icmpv4Echo::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
{
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   206
  return 4 + m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
Icmpv4Echo::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  start.WriteHtonU16 (m_identifier);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
  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
   213
  start.Write (m_data, m_dataSize);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
Icmpv4Echo::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  m_identifier = start.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  m_sequence = start.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  NS_ASSERT (start.GetSize () >= 4);
4575
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   221
  uint32_t size = start.GetSize () - 4;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   222
  if (size != m_dataSize)
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   223
    {
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   224
      delete [] m_data;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   225
      m_data = new uint8_t[size];
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   226
      m_dataSize = size;
ee3191a0b560 variable size buffer for icmpv4 echo header
Craig Dowell <craigdo@ee.washington.edu>
parents: 4521
diff changeset
   227
    }
4521
981e2f0b696b no need to keep around a Ptr<Packet>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3820
diff changeset
   228
  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
   229
  return m_dataSize;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
Icmpv4Echo::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
  os << "identifier=" << m_identifier << ", sequence="  << m_sequence;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
}
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
 *        Icmpv4DestinationUnreachable
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
 ********************************************************/
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   242
NS_OBJECT_ENSURE_REGISTERED (Icmpv4DestinationUnreachable);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   243
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
Icmpv4DestinationUnreachable::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
  static TypeId tid = TypeId ("ns3::Icmpv4DestinationUnreachable")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
    .AddConstructor<Icmpv4DestinationUnreachable> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
    ;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
Icmpv4DestinationUnreachable::Icmpv4DestinationUnreachable ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
  // make sure that thing is initialized to get initialized bytes
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  // when the ip payload's size is smaller than 8 bytes.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
      m_data[j] = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
    }
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
Icmpv4DestinationUnreachable::SetNextHopMtu (uint16_t mtu)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
  m_nextHopMtu = mtu;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
uint16_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
Icmpv4DestinationUnreachable::GetNextHopMtu (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
  return m_nextHopMtu;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
}
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
Icmpv4DestinationUnreachable::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
  data->CopyData (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
Icmpv4DestinationUnreachable::SetHeader (Ipv4Header header)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
  m_header = header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
Icmpv4DestinationUnreachable::GetData (uint8_t payload[8]) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
  memcpy (payload, m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
Ipv4Header 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
Icmpv4DestinationUnreachable::GetHeader (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
  return m_header;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
}
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
Icmpv4DestinationUnreachable::~Icmpv4DestinationUnreachable ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
{}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
Icmpv4DestinationUnreachable::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
  return GetTypeId ();
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
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
Icmpv4DestinationUnreachable::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
  return 4 + m_header.GetSerializedSize () + 8;
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
Icmpv4DestinationUnreachable::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   310
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
  start.WriteU16 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
  start.WriteHtonU16 (m_nextHopMtu);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
  uint32_t size = m_header.GetSerializedSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
  m_header.Serialize (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  start.Next (size);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
  start.Write (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
  
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
Icmpv4DestinationUnreachable::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   323
  i.Next (2);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
  m_nextHopMtu = i.ReadNtohU16 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
  uint32_t read = m_header.Deserialize (i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
  i.Next (read);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
      m_data[j] = i.ReadU8 ();
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
  return i.GetDistanceFrom (start);
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
Icmpv4DestinationUnreachable::Print (std::ostream &os) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
  m_header.Print (os);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
  os << " org data=";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
  for (uint8_t i = 0; i < 8; i++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
      os << (uint32_t) m_data[i];
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
      if (i != 8)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
	{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
	  os << " ";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
	}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   346
}
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
 *        Icmpv4TimeExceeded
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
6301
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   352
NS_OBJECT_ENSURE_REGISTERED (Icmpv4TimeExceeded);
58799c1b94b0 register icmpv4 objects
Josh Pelkey <jpelkey@gatech.edu>
parents: 4575
diff changeset
   353
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   355
Icmpv4TimeExceeded::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   356
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
  static TypeId tid = TypeId ("ns3::Icmpv4TimeExceeded")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   358
    .SetParent<Header> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   359
    .AddConstructor<Icmpv4TimeExceeded> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   360
    ;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
Icmpv4TimeExceeded::Icmpv4TimeExceeded ()
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
  // make sure that thing is initialized to get initialized bytes
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
  // when the ip payload's size is smaller than 8 bytes.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   367
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   368
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   369
      m_data[j] = 0;
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
}
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   375
Icmpv4TimeExceeded::SetData (Ptr<const Packet> data)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   377
  data->CopyData (m_data, 8);
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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   380
Icmpv4TimeExceeded::SetHeader (Ipv4Header header)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   381
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   382
  m_header = 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
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   385
Icmpv4TimeExceeded::GetData (uint8_t payload[8]) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   387
  memcpy (payload, m_data, 8);
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
Ipv4Header 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   390
Icmpv4TimeExceeded::GetHeader (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   391
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   392
  return m_header;
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
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
Icmpv4TimeExceeded::~Icmpv4TimeExceeded ()
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
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   399
Icmpv4TimeExceeded::GetInstanceTypeId (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   400
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   401
  return GetTypeId ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   402
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   403
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
Icmpv4TimeExceeded::GetSerializedSize (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   405
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   406
  return 4 + m_header.GetSerializedSize () + 8;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   409
Icmpv4TimeExceeded::Serialize (Buffer::Iterator start) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   411
  start.WriteU32 (0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
  uint32_t size = m_header.GetSerializedSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
  m_header.Serialize (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
  start.Next (size);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
  start.Write (m_data, 8);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   416
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
  
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   419
Icmpv4TimeExceeded::Deserialize (Buffer::Iterator start)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   420
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
  Buffer::Iterator i = start;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
  i.Next (4);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
  uint32_t read = m_header.Deserialize (i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
  i.Next (read);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
  for (uint8_t j = 0; j < 8; j++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
      m_data[j] = i.ReadU8 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   428
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
  return i.GetDistanceFrom (start);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
Icmpv4TimeExceeded::Print (std::ostream &os) const
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
  m_header.Print (os);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
  os << " org data=";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   436
  for (uint8_t i = 0; i < 8; i++)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   437
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
      os << (uint32_t) m_data[i];
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
      if (i != 8)
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 << " ";
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   442
	}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   443
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   444
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   445
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   446
} // namespace ns3