1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2005,2006,2007 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_L4_PROTOCOL_H |
|
22 #define UDP_L4_PROTOCOL_H |
|
23 |
|
24 #include <stdint.h> |
|
25 |
|
26 #include "ns3/packet.h" |
|
27 #include "ns3/ipv4-address.h" |
|
28 #include "ns3/ptr.h" |
|
29 #include "ipv4-end-point-demux.h" |
|
30 #include "ipv4-l4-protocol.h" |
|
31 |
|
32 namespace ns3 { |
|
33 |
|
34 class Node; |
|
35 class Socket; |
|
36 /** |
|
37 * \brief Implementation of the UDP protocol |
|
38 */ |
|
39 class UdpL4Protocol : public Ipv4L4Protocol { |
|
40 public: |
|
41 static TypeId GetTypeId (void); |
|
42 static const uint8_t PROT_NUMBER; |
|
43 |
|
44 UdpL4Protocol (); |
|
45 virtual ~UdpL4Protocol (); |
|
46 |
|
47 void SetNode (Ptr<Node> node); |
|
48 |
|
49 virtual int GetProtocolNumber (void) const; |
|
50 virtual int GetVersion (void) const; |
|
51 |
|
52 /** |
|
53 * \return A smart Socket pointer to a UdpSocket, allocated by this instance |
|
54 * of the UDP protocol |
|
55 */ |
|
56 Ptr<Socket> CreateSocket (void); |
|
57 |
|
58 Ipv4EndPoint *Allocate (void); |
|
59 Ipv4EndPoint *Allocate (Ipv4Address address); |
|
60 Ipv4EndPoint *Allocate (uint16_t port); |
|
61 Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); |
|
62 Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, |
|
63 Ipv4Address peerAddress, uint16_t peerPort); |
|
64 |
|
65 void DeAllocate (Ipv4EndPoint *endPoint); |
|
66 |
|
67 // called by UdpSocket. |
|
68 /** |
|
69 * \brief Send a packet via UDP |
|
70 * \param packet The packet to send |
|
71 * \param saddr The source Ipv4Address |
|
72 * \param daddr The destination Ipv4Address |
|
73 * \param sport The source port number |
|
74 * \param dport The destination port number |
|
75 */ |
|
76 void Send (Ptr<Packet> packet, |
|
77 Ipv4Address saddr, Ipv4Address daddr, |
|
78 uint16_t sport, uint16_t dport); |
|
79 /** |
|
80 * \brief Receive a packet up the protocol stack |
|
81 * \param p The Packet to dump the contents into |
|
82 * \param source The source's Ipv4Address |
|
83 * \param destination The destinations Ipv4Address |
|
84 * \param interface the interface from which the packet is coming. |
|
85 */ |
|
86 // inherited from Ipv4L4Protocol |
|
87 virtual void Receive(Ptr<Packet> p, |
|
88 Ipv4Address const &source, |
|
89 Ipv4Address const &destination, |
|
90 Ptr<Ipv4Interface> interface); |
|
91 protected: |
|
92 virtual void DoDispose (void); |
|
93 private: |
|
94 Ptr<Node> m_node; |
|
95 Ipv4EndPointDemux *m_endPoints; |
|
96 }; |
|
97 |
|
98 }; // namespace ns3 |
|
99 |
|
100 #endif /* UDP_L4_PROTOCOL_H */ |
|