~ubuntu-branches/ubuntu/quantal/ns3/quantal

« back to all changes in this revision

Viewing changes to ns-3.13/src/internet/model/udp-header.h

  • Committer: Package Import Robot
  • Author(s): YunQiang Su, Aron Xu, YunQiang Su, Upstream
  • Date: 2012-01-06 00:35:42 UTC
  • mfrom: (10.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120106003542-vcn5g03mhapm991h
Tags: 3.13+dfsg-1
[ Aron Xu ]:
        add tag binary and binary-indep, 
  for not build doc when --binary-arch (Closes: #654493).
[ YunQiang Su ]
        add waf 1.5/1.6 source to debian directory, 
  and build waf from there (Closes: #642217).
[ Upstream ]
  Successfully link with --as-needed option (Closes: #642225).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 
2
/*
 
3
 * Copyright (c) 2005 INRIA
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 2 as
 
7
 * published by the Free Software Foundation;
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 *
 
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
 
19
 */
 
20
 
 
21
#ifndef UDP_HEADER_H
 
22
#define UDP_HEADER_H
 
23
 
 
24
#include <stdint.h>
 
25
#include <string>
 
26
#include "ns3/header.h"
 
27
#include "ns3/ipv4-address.h"
 
28
 
 
29
namespace ns3 {
 
30
/**
 
31
 * \ingroup udp
 
32
 * \brief Packet header for UDP packets
 
33
 *
 
34
 * This class has fields corresponding to those in a network UDP header
 
35
 * (port numbers, payload size, checksum) as well as methods for serialization
 
36
 * to and deserialization from a byte buffer.
 
37
 */
 
38
class UdpHeader : public Header 
 
39
{
 
40
public:
 
41
 
 
42
  /**
 
43
   * \brief Constructor
 
44
   *
 
45
   * Creates a null header
 
46
   */
 
47
  UdpHeader ();
 
48
  ~UdpHeader ();
 
49
 
 
50
  /**
 
51
   * \brief Enable checksum calculation for UDP 
 
52
   */
 
53
  void EnableChecksums (void);
 
54
  /**
 
55
   * \param port the destination port for this UdpHeader
 
56
   */
 
57
  void SetDestinationPort (uint16_t port);
 
58
  /**
 
59
   * \param port The source port for this UdpHeader
 
60
   */
 
61
  void SetSourcePort (uint16_t port);
 
62
  /**
 
63
   * \return The source port for this UdpHeader
 
64
   */
 
65
  uint16_t GetSourcePort (void) const;
 
66
  /**
 
67
   * \return the destination port for this UdpHeader
 
68
   */
 
69
  uint16_t GetDestinationPort (void) const;
 
70
 
 
71
  /**
 
72
   * \param source the ip source to use in the underlying
 
73
   *        ip packet.
 
74
   * \param destination the ip destination to use in the
 
75
   *        underlying ip packet.
 
76
   * \param protocol the protocol number to use in the underlying
 
77
   *        ip packet.
 
78
   *
 
79
   * If you want to use udp checksums, you should call this
 
80
   * method prior to adding the header to a packet.
 
81
   */
 
82
  void InitializeChecksum (Ipv4Address source, 
 
83
                           Ipv4Address destination,
 
84
                           uint8_t protocol);
 
85
 
 
86
  static TypeId GetTypeId (void);
 
87
  virtual TypeId GetInstanceTypeId (void) const;
 
88
  virtual void Print (std::ostream &os) const;
 
89
  virtual uint32_t GetSerializedSize (void) const;
 
90
  virtual void Serialize (Buffer::Iterator start) const;
 
91
  virtual uint32_t Deserialize (Buffer::Iterator start);
 
92
 
 
93
  /**
 
94
   * \brief Is the UDP checksum correct ?
 
95
   * \returns true if the checksum is correct, false otherwise.
 
96
   */
 
97
  bool IsChecksumOk (void) const;
 
98
 
 
99
private:
 
100
  uint16_t CalculateHeaderChecksum (uint16_t size) const;
 
101
  uint16_t m_sourcePort;
 
102
  uint16_t m_destinationPort;
 
103
  uint16_t m_payloadSize;
 
104
 
 
105
  Ipv4Address m_source;
 
106
  Ipv4Address m_destination;
 
107
  uint8_t m_protocol;
 
108
  bool m_calcChecksum;
 
109
  bool m_goodChecksum;
 
110
};
 
111
 
 
112
} // namespace ns3
 
113
 
 
114
#endif /* UDP_HEADER */