src/node/ipv4-header.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 05 Jun 2008 15:56:23 -0700
changeset 3235 c2f34dac1b9e
parent 3234 aabbcb2cba71
child 3363 33d1ca2e4ba4
permissions -rw-r--r--
add support for attribtues to bug 34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005 INRIA
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 235
diff changeset
    21
#include "ns3/assert.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1236
diff changeset
    22
#include "ns3/log.h"
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/header.h"
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "ipv4-header.h"
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1236
diff changeset
    26
NS_LOG_COMPONENT_DEFINE ("Ipv4Header");
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
1236
cfa5e0b39281 rework the NS_XX_ENSURE_REGISTERED macros and make sure we typecheck the input to TraceContext::Add and TraceContext::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1234
diff changeset
    28
namespace ns3 {
1152
1d06449f0a98 macros to ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1151
diff changeset
    29
2643
2a3324f4dabe define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
    30
NS_OBJECT_ENSURE_REGISTERED (Ipv4Header);
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
Ipv4Header::Ipv4Header ()
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3234
diff changeset
    33
  : m_calcChecksum (false),
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3234
diff changeset
    34
    m_payloadSize (0),
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
    m_identification (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
    m_tos (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
    m_ttl (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
    m_protocol (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
    m_flags (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
    m_fragmentOffset (0),
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
    m_goodChecksum (true)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
void 
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3234
diff changeset
    45
Ipv4Header::EnableChecksum (void)
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
  m_calcChecksum = true;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
Ipv4Header::SetPayloadSize (uint16_t size)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
  m_payloadSize = size;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
uint16_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
Ipv4Header::GetPayloadSize (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
  return m_payloadSize;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
uint16_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
Ipv4Header::GetIdentification (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
  return m_identification;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
Ipv4Header::SetIdentification (uint16_t identification)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
  m_identification = identification;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
Ipv4Header::SetTos (uint8_t tos)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  m_tos = tos;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
uint8_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
Ipv4Header::GetTos (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
  return m_tos;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
Ipv4Header::SetMoreFragments (void)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  m_flags |= MORE_FRAGMENTS;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
void
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
Ipv4Header::SetLastFragment (void)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
  m_flags &= ~MORE_FRAGMENTS;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
bool 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
Ipv4Header::IsLastFragment (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  return !(m_flags & MORE_FRAGMENTS);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
Ipv4Header::SetDontFragment (void)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
  m_flags |= DONT_FRAGMENT;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
Ipv4Header::SetMayFragment (void)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
  m_flags &= ~DONT_FRAGMENT;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
bool 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
Ipv4Header::IsDontFragment (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
  return (m_flags & DONT_FRAGMENT);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
Ipv4Header::SetFragmentOffset (uint16_t offset)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
{
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 235
diff changeset
   119
  NS_ASSERT (!(offset & (~0x3fff)));
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
  m_fragmentOffset = offset;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
uint16_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
Ipv4Header::GetFragmentOffset (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
{
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 235
diff changeset
   125
  NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
  return m_fragmentOffset;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
Ipv4Header::SetTtl (uint8_t ttl)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
  m_ttl = ttl;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
uint8_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
Ipv4Header::GetTtl (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
  return m_ttl;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
  
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
uint8_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
Ipv4Header::GetProtocol (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  return m_protocol;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
Ipv4Header::SetProtocol (uint8_t protocol)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
  m_protocol = protocol;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
Ipv4Header::SetSource (Ipv4Address source)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
  m_source = source;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
Ipv4Address
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
Ipv4Header::GetSource (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
  return m_source;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
void 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
Ipv4Header::SetDestination (Ipv4Address dst)
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
  m_destination = dst;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
Ipv4Address
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
Ipv4Header::GetDestination (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
  return m_destination;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
bool
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
Ipv4Header::IsChecksumOk (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
  return m_goodChecksum;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
3234
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   180
uint16_t
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   181
Ipv4Header::ChecksumCalculate(Buffer::Iterator &i, uint16_t size)
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   182
{
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   183
  /* see RFC 1071 to understand this code. */
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   184
  uint32_t sum = 0;
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   185
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   186
  for (int j = 0; j < size/2; j++)
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   187
    sum += i.ReadU16 ();
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   188
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   189
  if (size & 1)
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   190
     sum += i.ReadU8 ();
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   191
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   192
  while (sum >> 16)
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   193
    sum = (sum & 0xffff) + (sum >> 16);
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   194
  return ~sum;
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   195
}
2646
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   196
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   197
TypeId 
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   198
Ipv4Header::GetTypeId (void)
795
cd108c9817d0 add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 524
diff changeset
   199
{
2646
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   200
  static TypeId tid = TypeId ("ns3::Ipv4Header")
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   201
    .SetParent<Header> ()
2650
3de4cacb8981 make sure all headers and trailers gets a constructor registered in their TypeId.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2646
diff changeset
   202
    .AddConstructor<Ipv4Header> ()
2646
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   203
    ;
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   204
  return tid;
795
cd108c9817d0 add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 524
diff changeset
   205
}
2646
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   206
TypeId 
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   207
Ipv4Header::GetInstanceTypeId (void) const
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   208
{
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   209
  return GetTypeId ();
c1fef7686472 remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2643
diff changeset
   210
}
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
void 
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1152
diff changeset
   212
Ipv4Header::Print (std::ostream &os) const
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
  // ipv4, right ?
900
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   215
  std::string flags;
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   216
  if (m_flags == 0)
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   217
    {
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   218
      flags = "none";
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   219
    }
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   220
  else if (m_flags & MORE_FRAGMENTS &&
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   221
           m_flags & DONT_FRAGMENT)
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   222
    {
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   223
      flags = "MF|DF";
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   224
    }
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   225
  else if (m_flags & DONT_FRAGMENT)
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   226
    {
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   227
      flags = "DF";
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   228
    }
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   229
  else if (m_flags & MORE_FRAGMENTS)
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   230
    {
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   231
      flags = "MF";
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   232
    }
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   233
  else
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   234
    {
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   235
      flags = "XX";
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   236
    }
2653
b8eff7186c5c improve pretty-printing output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2650
diff changeset
   237
  os << "tos 0x" << std::hex << m_tos << std::dec << " "
900
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   238
     << "ttl " << m_ttl << " "
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   239
     << "id " << m_identification << " "
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   240
     << "offset " << m_fragmentOffset << " "
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   241
     << "flags [" << flags << "] "
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   242
     << "length: " << (m_payloadSize + 5 * 4)
2653
b8eff7186c5c improve pretty-printing output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2650
diff changeset
   243
     << " " 
900
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   244
     << m_source << " > " << m_destination
2087082ba3ed change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
   245
    ;
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
uint32_t 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
Ipv4Header::GetSerializedSize (void) const
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
  return 5 * 4;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
   253
void
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1152
diff changeset
   254
Ipv4Header::Serialize (Buffer::Iterator start) const
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
  Buffer::Iterator i = start;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
  
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
  uint8_t verIhl = (4 << 4) | (5);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
  i.WriteU8 (verIhl);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
  i.WriteU8 (m_tos);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
  i.WriteHtonU16 (m_payloadSize + 5*4);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
  i.WriteHtonU16 (m_identification);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
  uint32_t fragmentOffset = m_fragmentOffset / 8;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
  uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
  if (m_flags & DONT_FRAGMENT) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
    {
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
      flagsFrag |= (1<<6);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
    }
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
  if (m_flags & MORE_FRAGMENTS) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
    {
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
      flagsFrag |= (1<<5);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
    }
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
  i.WriteU8 (flagsFrag);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
  uint8_t frag = fragmentOffset & 0xff;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
  i.WriteU8 (frag);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
  i.WriteU8 (m_ttl);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
  i.WriteU8 (m_protocol);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
  i.WriteHtonU16 (0);
3179
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   279
  i.WriteHtonU32 (m_source.Get ());
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   280
  i.WriteHtonU32 (m_destination.Get ());
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   281
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
  if (m_calcChecksum) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
    {
3234
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   284
      i = start;
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   285
      uint16_t checksum = ChecksumCalculate(i, 20);
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1236
diff changeset
   286
      NS_LOG_LOGIC ("checksum=" <<checksum);
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
      i = start;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
      i.Next (10);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
      i.WriteU16 (checksum);
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
    }
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
}
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
   292
uint32_t
1232
2e8c3f8bb77f remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1152
diff changeset
   293
Ipv4Header::Deserialize (Buffer::Iterator start)
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
{
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
  Buffer::Iterator i = start;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
  uint8_t verIhl = i.ReadU8 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
  uint8_t ihl = verIhl & 0x0f; 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
  uint16_t headerSize = ihl * 4;
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 235
diff changeset
   299
  NS_ASSERT ((verIhl >> 4) == 4);
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
  m_tos = i.ReadU8 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
  uint16_t size = i.ReadNtohU16 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
  m_payloadSize = size - headerSize;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
  m_identification = i.ReadNtohU16 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
  uint8_t flags = i.ReadU8 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
  m_flags = 0;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
  if (flags & (1<<6)) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
    {
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
      m_flags |= DONT_FRAGMENT;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
    }
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
  if (flags & (1<<5)) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
    {
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
      m_flags |= MORE_FRAGMENTS;
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
    }
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
  i.Prev ();
3221
bd02183f788b fix bug 208 for true.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3217
diff changeset
   315
  m_fragmentOffset = i.ReadU8 () & 0x1f;
bd02183f788b fix bug 208 for true.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3217
diff changeset
   316
  m_fragmentOffset <<= 8;
bd02183f788b fix bug 208 for true.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3217
diff changeset
   317
  m_fragmentOffset |= i.ReadU8 ();
bd02183f788b fix bug 208 for true.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3217
diff changeset
   318
  m_fragmentOffset <<= 3;
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
  m_ttl = i.ReadU8 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
  m_protocol = i.ReadU8 ();
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
  i.Next (2); // checksum
3179
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   322
  m_source.Set (i.ReadNtohU32 ());
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   323
  m_destination.Set (i.ReadNtohU32 ());
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
  if (m_calcChecksum) 
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
    {
3234
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   327
      i = start;
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   328
      uint16_t checksum = ChecksumCalculate(i, headerSize);
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   329
      NS_LOG_LOGIC ("checksum=" <<checksum);
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   330
aabbcb2cba71 Add ipv4 header checksum support.
Florian Westphal <fw@strlen.de>
parents: 3221
diff changeset
   331
      m_goodChecksum = (checksum == 0);
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
    }
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
   333
  return GetSerializedSize ();
235
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
}
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
190d5bef3254 add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
}; // namespace ns3