1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2005,2006,2007 INRIA |
|
4 * All rights reserved. |
|
5 * |
|
6 * This program is free software; you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License version 2 as |
|
8 * published by the Free Software Foundation; |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program; if not, write to the Free Software |
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 * |
|
19 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
20 */ |
|
21 |
|
22 #ifndef UDP_H |
|
23 #define UDP_H |
|
24 |
|
25 #include <stdint.h> |
|
26 |
|
27 #include "ns3/packet.h" |
|
28 #include "ns3/ipv4-address.h" |
|
29 #include "ns3/ptr.h" |
|
30 #include "ipv4-end-point-demux.h" |
|
31 #include "ipv4-l4-protocol.h" |
|
32 |
|
33 namespace ns3 { |
|
34 |
|
35 class Node; |
|
36 class TraceResolver; |
|
37 class TraceContext; |
|
38 class Socket; |
|
39 /** |
|
40 * \brief Implementation of the UDP protocol |
|
41 */ |
|
42 class Udp : public Ipv4L4Protocol { |
|
43 public: |
|
44 static const uint8_t PROT_NUMBER; |
|
45 /** |
|
46 * \brief Constructor |
|
47 * \param node The node this protocol is associated with |
|
48 */ |
|
49 Udp (Ptr<Node> node); |
|
50 virtual ~Udp (); |
|
51 |
|
52 virtual TraceResolver *CreateTraceResolver (TraceContext const &context); |
|
53 /** |
|
54 * \return A smart Socket pointer to a UdpSocket, allocated by this instance |
|
55 * of the UDP protocol |
|
56 */ |
|
57 Ptr<Socket> CreateSocket (void); |
|
58 |
|
59 Ipv4EndPoint *Allocate (void); |
|
60 Ipv4EndPoint *Allocate (Ipv4Address address); |
|
61 Ipv4EndPoint *Allocate (uint16_t port); |
|
62 Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); |
|
63 Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, |
|
64 Ipv4Address peerAddress, uint16_t peerPort); |
|
65 |
|
66 void DeAllocate (Ipv4EndPoint *endPoint); |
|
67 |
|
68 // called by UdpSocket. |
|
69 /** |
|
70 * \brief Send a packet via UDP |
|
71 * \param packet The packet to send |
|
72 * \param saddr The source Ipv4Address |
|
73 * \param daddr The destination Ipv4Address |
|
74 * \param sport The source port number |
|
75 * \param dport The destination port number |
|
76 */ |
|
77 void Send (Packet packet, |
|
78 Ipv4Address saddr, Ipv4Address daddr, |
|
79 uint16_t sport, uint16_t dport); |
|
80 /** |
|
81 * \brief Recieve a packet up the protocol stack |
|
82 * \param p The Packet to dump the contents into |
|
83 * \param source The source's Ipv4Address |
|
84 * \param destination The destinations Ipv4Address |
|
85 */ |
|
86 // inherited from Ipv4L4Protocol |
|
87 virtual void Receive(Packet& p, |
|
88 Ipv4Address const &source, |
|
89 Ipv4Address const &destination); |
|
90 protected: |
|
91 virtual void DoDispose (void); |
|
92 private: |
|
93 Ptr<Node> m_node; |
|
94 Ipv4EndPointDemux *m_endPoints; |
|
95 }; |
|
96 |
|
97 }; // namespace ns3 |
|
98 |
|
99 #endif /* UDP_H */ |
|