src/internet-node/udp-header.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 03 Aug 2007 17:26:10 +0200
changeset 1133 2878564d62ff
parent 1126 06484dd65e76
child 1151 527d7b7e25af
permissions -rw-r--r--
fix valgrind warnings
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
 * All rights reserved.
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
 *
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
 * 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
     7
 * 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
     8
 * 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
     9
 *
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
 * 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
    11
 * 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
    12
 * 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
    13
 * 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
    14
 *
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
 * 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
    16
 * 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
    17
 * 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
    18
 *
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
 * 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
    20
 */
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
    21
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
    22
#ifndef UDP_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
    23
#define UDP_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
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
#include <stdint.h>
1133
2878564d62ff fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1126
diff changeset
    26
#include <string>
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
#include "ns3/header.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 463
diff changeset
    28
#include "ns3/ipv4-address.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
    29
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
    30
namespace ns3 {
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    31
/**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    32
 * \brief Packet header for UDP packets
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    33
 */
1126
06484dd65e76 add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
    34
class UdpHeader : public Header 
06484dd65e76 add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
    35
{
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
    36
public:
1133
2878564d62ff fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1126
diff changeset
    37
  static std::string GetUid (void);
1126
06484dd65e76 add GetUid methods to all headers and trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 795
diff changeset
    38
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    39
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    40
   * \brief Constructor
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    41
   *
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    42
   * Creates a null header
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    43
   */
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
    44
  UdpHeader ();
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
    45
  virtual ~UdpHeader ();
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
640
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    47
  /**
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    48
   * \brief Enable checksum calculation for UDP (XXX currently has no effect)
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    49
   */
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
    50
  static void EnableChecksums (void);
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    51
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    52
   * \param port the destination port for this UdpHeader
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    53
   */
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
    54
  void SetDestination (uint16_t port);
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    55
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    56
   * \param port The source port for this UdpHeader
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    57
   */
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
    58
  void SetSource (uint16_t port);
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    59
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    60
   * \return The source port for this UdpHeader
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    61
   */
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
    62
  uint16_t GetSource (void) const;
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    63
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    64
   * \return the destination port for this UdpHeader
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    65
   */
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
    66
  uint16_t GetDestination (void) const;
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    67
  /**
640
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    68
   * \param size The payload size in bytes
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 524
diff changeset
    69
   */
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
    70
  void 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
    71
640
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    72
  /**
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    73
   * \param source the ip source to use in the underlying
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    74
   *        ip packet.
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    75
   * \param destination the ip destination to use in the
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    76
   *        underlying ip packet.
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    77
   * \param protocol the protocol number to use in the underlying
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    78
   *        ip packet.
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    79
   *
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    80
   * If you want to use udp checksums, you should call this
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    81
   * method prior to adding the header to a packet.
028db47a657f beautify the dox output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    82
   */
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
    83
  void InitializeChecksum (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
    84
                           Ipv4Address 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
    85
                           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
    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
private:
795
cd108c9817d0 add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 640
diff changeset
    88
  virtual std::string DoGetName (void) 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
    89
  virtual void PrintTo (std::ostream &os) 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
    90
  virtual uint32_t 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
    91
  virtual void SerializeTo (Buffer::Iterator start) const;
463
c2082308e01a merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 235
diff changeset
    92
  virtual uint32_t DeserializeFrom (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
    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
  uint16_t m_sourcePort;
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
  uint16_t m_destinationPort;
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
  uint16_t 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
    97
  uint16_t m_initialChecksum;
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
  static bool 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
   100
};
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
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
}; // namespace ns3
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
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
#endif /* UDP_HEADER */