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 
30 namespace ns3
31 {
32 
33 class Node;
34 class Socket;
35 class Ipv4EndPointDemux;
36 class Ipv4EndPoint;
37 class Ipv6EndPointDemux;
38 class Ipv6EndPoint;
39 class UdpSocketImpl;
40 class NetDevice;
41 
63 {
64  public:
69  static TypeId GetTypeId();
70  static const uint8_t PROT_NUMBER;
71 
72  UdpL4Protocol();
73  ~UdpL4Protocol() override;
74 
75  // Delete copy constructor and assignment operator to avoid misuse
76  UdpL4Protocol(const UdpL4Protocol&) = delete;
78 
83  void SetNode(Ptr<Node> node);
84 
85  int GetProtocolNumber() const override;
86 
92 
110  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, uint16_t port);
118  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
128  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice,
129  Ipv4Address localAddress,
130  uint16_t localPort,
131  Ipv4Address peerAddress,
132  uint16_t peerPort);
133 
151  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, uint16_t port);
159  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
169  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice,
170  Ipv6Address localAddress,
171  uint16_t localPort,
172  Ipv6Address peerAddress,
173  uint16_t peerPort);
174 
179  void DeAllocate(Ipv4EndPoint* endPoint);
184  void DeAllocate(Ipv6EndPoint* endPoint);
185 
186  // called by UdpSocket.
195  void Send(Ptr<Packet> packet,
196  Ipv4Address saddr,
197  Ipv4Address daddr,
198  uint16_t sport,
199  uint16_t dport);
209  void Send(Ptr<Packet> packet,
210  Ipv4Address saddr,
211  Ipv4Address daddr,
212  uint16_t sport,
213  uint16_t dport,
214  Ptr<Ipv4Route> route);
223  void Send(Ptr<Packet> packet,
224  Ipv6Address saddr,
225  Ipv6Address daddr,
226  uint16_t sport,
227  uint16_t dport);
237  void Send(Ptr<Packet> packet,
238  Ipv6Address saddr,
239  Ipv6Address daddr,
240  uint16_t sport,
241  uint16_t dport,
242  Ptr<Ipv6Route> route);
243 
244  // inherited from Ipv4L4Protocol
246  const Ipv4Header& header,
247  Ptr<Ipv4Interface> interface) override;
249  const Ipv6Header& header,
250  Ptr<Ipv6Interface> interface) override;
251 
252  void ReceiveIcmp(Ipv4Address icmpSource,
253  uint8_t icmpTtl,
254  uint8_t icmpType,
255  uint8_t icmpCode,
256  uint32_t icmpInfo,
257  Ipv4Address payloadSource,
258  Ipv4Address payloadDestination,
259  const uint8_t payload[8]) override;
260  void ReceiveIcmp(Ipv6Address icmpSource,
261  uint8_t icmpTtl,
262  uint8_t icmpType,
263  uint8_t icmpCode,
264  uint32_t icmpInfo,
265  Ipv6Address payloadSource,
266  Ipv6Address payloadDestination,
267  const uint8_t payload[8]) override;
268 
269  // From IpL4Protocol
272  // From IpL4Protocol
275 
276  protected:
277  void DoDispose() override;
278  /*
279  * This function will notify other components connected to the node that a new stack member is
280  * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
281  * connect them together.
282  */
283  void NotifyNewAggregate() override;
284 
285  private:
289 
290  std::vector<Ptr<UdpSocketImpl>> m_sockets;
293 };
294 
295 } // namespace ns3
296 
297 #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:43
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:50
Demultiplexer for end points.
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:36
a unique identifier for an interface.
Definition: type-id.h:60
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...
~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::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
void DoDispose() override
Destructor implementation.
std::vector< Ptr< UdpSocketImpl > > m_sockets
list of sockets
enum 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.
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)
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.