author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 01 Oct 2007 14:15:56 +0200 | |
changeset 1866 | e7dbcc4df546 |
parent 1524 | 3ead2b66f2e4 |
child 1867 | 16deaedc0380 |
permissions | -rw-r--r-- |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005,2006,2007 INRIA |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* All rights reserved. |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License version 2 as |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
|
742
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
22 |
#ifndef UDP_L4_PROTOCOL_H |
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
23 |
#define UDP_L4_PROTOCOL_H |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include <stdint.h> |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
#include "ns3/packet.h" |
524
082ffdd8fbd7
move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
515
diff
changeset
|
28 |
#include "ns3/ipv4-address.h" |
557
927a5bb6432a
convert UdpSocket and Udp to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
29 |
#include "ns3/ptr.h" |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
#include "ipv4-end-point-demux.h" |
295
5fc7ae0d0300
remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
241
diff
changeset
|
31 |
#include "ipv4-l4-protocol.h" |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
namespace ns3 { |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
|
728
95c426b1cb60
rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
35 |
class Node; |
345
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
295
diff
changeset
|
36 |
class TraceResolver; |
47b41507a45a
move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
295
diff
changeset
|
37 |
class TraceContext; |
453
ddbb935800d8
remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
38 |
class Socket; |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
39 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
40 |
* \brief Implementation of the UDP protocol |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
41 |
*/ |
742
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
42 |
class UdpL4Protocol : public Ipv4L4Protocol { |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
public: |
295
5fc7ae0d0300
remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
241
diff
changeset
|
44 |
static const uint8_t PROT_NUMBER; |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
45 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
46 |
* \brief Constructor |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
47 |
* \param node The node this protocol is associated with |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
48 |
*/ |
742
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
49 |
UdpL4Protocol (Ptr<Node> node); |
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
50 |
virtual ~UdpL4Protocol (); |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
|
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
52 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
53 |
* \return A smart Socket pointer to a UdpSocket, allocated by this instance |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
54 |
* of the UDP protocol |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
55 |
*/ |
568
e1660959ecbb
use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
557
diff
changeset
|
56 |
Ptr<Socket> CreateSocket (void); |
453
ddbb935800d8
remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
345
diff
changeset
|
57 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
58 |
Ipv4EndPoint *Allocate (void); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
59 |
Ipv4EndPoint *Allocate (Ipv4Address address); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
60 |
Ipv4EndPoint *Allocate (uint16_t port); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
61 |
Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
62 |
Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort, |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
Ipv4Address peerAddress, uint16_t peerPort); |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
|
515
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
513
diff
changeset
|
65 |
void DeAllocate (Ipv4EndPoint *endPoint); |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
513
diff
changeset
|
66 |
|
240
7da682f99bf9
add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
67 |
// called by UdpSocket. |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
68 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
69 |
* \brief Send a packet via UDP |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
70 |
* \param packet The packet to send |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
71 |
* \param saddr The source Ipv4Address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
72 |
* \param daddr The destination Ipv4Address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
73 |
* \param sport The source port number |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
74 |
* \param dport The destination port number |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
75 |
*/ |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1524
diff
changeset
|
76 |
void Send (Ptr<Packet> packet, |
240
7da682f99bf9
add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
77 |
Ipv4Address saddr, Ipv4Address daddr, |
7da682f99bf9
add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
78 |
uint16_t sport, uint16_t dport); |
632
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
79 |
/** |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
80 |
* \brief Recieve a packet up the protocol stack |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
81 |
* \param p The Packet to dump the contents into |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
82 |
* \param source The source's Ipv4Address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
83 |
* \param destination The destinations Ipv4Address |
1e419ebb4012
Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
607
diff
changeset
|
84 |
*/ |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
85 |
// inherited from Ipv4L4Protocol |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1524
diff
changeset
|
86 |
virtual void Receive(Ptr<Packet> p, |
295
5fc7ae0d0300
remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
241
diff
changeset
|
87 |
Ipv4Address const &source, |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1412
diff
changeset
|
88 |
Ipv4Address const &destination, |
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1412
diff
changeset
|
89 |
Ptr<Ipv4Interface> interface); |
513
b7c7ea629de9
make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
504
diff
changeset
|
90 |
protected: |
b7c7ea629de9
make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
504
diff
changeset
|
91 |
virtual void DoDispose (void); |
b7c7ea629de9
make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
504
diff
changeset
|
92 |
private: |
728
95c426b1cb60
rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
632
diff
changeset
|
93 |
Ptr<Node> m_node; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
453
diff
changeset
|
94 |
Ipv4EndPointDemux *m_endPoints; |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
}; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
96 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
97 |
}; // namespace ns3 |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
98 |
|
742
b73f8e30c75e
Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
741
diff
changeset
|
99 |
#endif /* UDP_L4_PROTOCOL_H */ |