A Discrete-Event Network Simulator
API
udp-l4-protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005,2006,2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef UDP_L4_PROTOCOL_H
21 #define UDP_L4_PROTOCOL_H
22 
23 #include "ip-l4-protocol.h"
24 
25 #include "ns3/packet.h"
26 #include "ns3/ptr.h"
27 
28 #include <stdint.h>
29 #include <unordered_map>
30 
31 namespace ns3
32 {
33 
34 class Node;
35 class Socket;
36 class Ipv4EndPointDemux;
37 class Ipv4EndPoint;
38 class Ipv6EndPointDemux;
39 class Ipv6EndPoint;
40 class UdpSocketImpl;
41 class NetDevice;
42 
64 {
65  public:
70  static TypeId GetTypeId();
71  static const uint8_t PROT_NUMBER;
72 
73  UdpL4Protocol();
74  ~UdpL4Protocol() override;
75 
76  // Delete copy constructor and assignment operator to avoid misuse
77  UdpL4Protocol(const UdpL4Protocol&) = delete;
79 
84  void SetNode(Ptr<Node> node);
85 
86  int GetProtocolNumber() const override;
87 
93 
111  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, uint16_t port);
119  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
129  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice,
130  Ipv4Address localAddress,
131  uint16_t localPort,
132  Ipv4Address peerAddress,
133  uint16_t peerPort);
134 
152  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, uint16_t port);
160  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
170  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice,
171  Ipv6Address localAddress,
172  uint16_t localPort,
173  Ipv6Address peerAddress,
174  uint16_t peerPort);
175 
180  void DeAllocate(Ipv4EndPoint* endPoint);
185  void DeAllocate(Ipv6EndPoint* endPoint);
186 
193  bool RemoveSocket(Ptr<UdpSocketImpl> socket);
194 
195  // called by UdpSocket.
204  void Send(Ptr<Packet> packet,
205  Ipv4Address saddr,
206  Ipv4Address daddr,
207  uint16_t sport,
208  uint16_t dport);
218  void Send(Ptr<Packet> packet,
219  Ipv4Address saddr,
220  Ipv4Address daddr,
221  uint16_t sport,
222  uint16_t dport,
223  Ptr<Ipv4Route> route);
232  void Send(Ptr<Packet> packet,
233  Ipv6Address saddr,
234  Ipv6Address daddr,
235  uint16_t sport,
236  uint16_t dport);
246  void Send(Ptr<Packet> packet,
247  Ipv6Address saddr,
248  Ipv6Address daddr,
249  uint16_t sport,
250  uint16_t dport,
251  Ptr<Ipv6Route> route);
252 
253  // inherited from Ipv4L4Protocol
255  const Ipv4Header& header,
256  Ptr<Ipv4Interface> interface) override;
258  const Ipv6Header& header,
259  Ptr<Ipv6Interface> interface) override;
260 
261  void ReceiveIcmp(Ipv4Address icmpSource,
262  uint8_t icmpTtl,
263  uint8_t icmpType,
264  uint8_t icmpCode,
265  uint32_t icmpInfo,
266  Ipv4Address payloadSource,
267  Ipv4Address payloadDestination,
268  const uint8_t payload[8]) override;
269  void ReceiveIcmp(Ipv6Address icmpSource,
270  uint8_t icmpTtl,
271  uint8_t icmpType,
272  uint8_t icmpCode,
273  uint32_t icmpInfo,
274  Ipv6Address payloadSource,
275  Ipv6Address payloadDestination,
276  const uint8_t payload[8]) override;
277 
278  // From IpL4Protocol
281  // From IpL4Protocol
284 
285  protected:
286  void DoDispose() override;
287  /*
288  * This function will notify other components connected to the node that a new stack member is
289  * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
290  * connect them together.
291  */
292  void NotifyNewAggregate() override;
293 
294  private:
298 
299  std::unordered_map<uint64_t, Ptr<UdpSocketImpl>>
301  uint64_t m_socketIndex{0};
304 };
305 
306 } // namespace ns3
307 
308 #endif /* UDP_L4_PROTOCOL_H */
L4 Protocol abstract base class.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Demultiplexes packets to various transport layer endpoints.
A representation of an internet endpoint/connection.
Packet header for IPv4.
Definition: ipv4-header.h:34
Describes an IPv6 address.
Definition: ipv6-address.h:49
Demultiplexer for end points.
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:35
a unique identifier for an interface.
Definition: type-id.h:59
Implementation of the UDP protocol.
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
Ptr< Socket > CreateSocket()
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport)
Send a packet via UDP (IPv4)
Ipv6EndPoint * Allocate6()
Allocate an IPv6 Endpoint.
void SetDownTarget(IpL4Protocol::DownTargetCallback cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
std::unordered_map< uint64_t, Ptr< UdpSocketImpl > > m_sockets
Unordered map of socket IDs and corresponding sockets.
~UdpL4Protocol() override
UdpL4Protocol(const UdpL4Protocol &)=delete
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
int GetProtocolNumber() const override
Returns the protocol number of this protocol.
Ptr< Node > m_node
The node this stack is associated with.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
void ReceiveIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8]) override
Called from lower-level layers to send the ICMP packet up in the stack.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
IpL4Protocol::DownTargetCallback GetDownTarget() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
static TypeId GetTypeId()
Get the type ID.
IpL4Protocol::DownTargetCallback6 GetDownTarget6() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
UdpL4Protocol & operator=(const UdpL4Protocol &)=delete
Ipv4EndPoint * Allocate()
Allocate an IPv4 Endpoint.
IpL4Protocol::RxStatus Receive(Ptr< Packet > p, const Ipv4Header &header, Ptr< Ipv4Interface > interface) override
Called from lower-level layers to send the packet up in the stack.
bool RemoveSocket(Ptr< UdpSocketImpl > socket)
Remove a socket from the internal list.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
void DoDispose() override
Destructor implementation.
void NotifyNewAggregate() override
Notify all Objects aggregated to this one of a new Object being aggregated.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
static const uint8_t PROT_NUMBER
protocol number (0x11)
uint64_t m_socketIndex
Index of the next socket to be created.
uint16_t port
Definition: dsdv-manet.cc:44
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.