A Discrete-Event Network Simulator
API
udp-l4-protocol.h
Go to the documentation of this file.
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/ptr.h"
28 #include "ip-l4-protocol.h"
29 
30 namespace ns3 {
31 
32 class Node;
33 class Socket;
34 class Ipv4EndPointDemux;
35 class Ipv4EndPoint;
36 class Ipv6EndPointDemux;
37 class Ipv6EndPoint;
38 class UdpSocketImpl;
39 class NetDevice;
40 
61 class UdpL4Protocol : public IpL4Protocol {
62 public:
67  static TypeId GetTypeId (void);
68  static const uint8_t PROT_NUMBER;
69 
70  UdpL4Protocol ();
71  virtual ~UdpL4Protocol ();
72 
73  // Delete copy constructor and assignment operator to avoid misuse
74  UdpL4Protocol (const UdpL4Protocol &) = delete;
76 
81  void SetNode (Ptr<Node> node);
82 
83  virtual int GetProtocolNumber (void) const;
84 
90 
95  Ipv4EndPoint *Allocate (void);
108  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
116  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
126  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
127  Ipv4Address localAddress, uint16_t localPort,
128  Ipv4Address peerAddress, uint16_t peerPort);
129 
134  Ipv6EndPoint *Allocate6 (void);
147  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port);
155  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
165  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice,
166  Ipv6Address localAddress, uint16_t localPort,
167  Ipv6Address peerAddress, uint16_t peerPort);
168 
173  void DeAllocate (Ipv4EndPoint *endPoint);
178  void DeAllocate (Ipv6EndPoint *endPoint);
179 
180  // called by UdpSocket.
189  void Send (Ptr<Packet> packet,
190  Ipv4Address saddr, Ipv4Address daddr,
191  uint16_t sport, uint16_t dport);
201  void Send (Ptr<Packet> packet,
202  Ipv4Address saddr, Ipv4Address daddr,
203  uint16_t sport, uint16_t dport, Ptr<Ipv4Route> route);
212  void Send (Ptr<Packet> packet,
213  Ipv6Address saddr, Ipv6Address daddr,
214  uint16_t sport, uint16_t dport);
224  void Send (Ptr<Packet> packet,
225  Ipv6Address saddr, Ipv6Address daddr,
226  uint16_t sport, uint16_t dport, Ptr<Ipv6Route> route);
227 
228  // inherited from Ipv4L4Protocol
230  Ipv4Header const &header,
231  Ptr<Ipv4Interface> interface);
233  Ipv6Header const &header,
234  Ptr<Ipv6Interface> interface);
235 
236  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
237  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
238  Ipv4Address payloadSource,Ipv4Address payloadDestination,
239  const uint8_t payload[8]);
240  virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
241  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
242  Ipv6Address payloadSource,Ipv6Address payloadDestination,
243  const uint8_t payload[8]);
244 
245  // From IpL4Protocol
248  // From IpL4Protocol
249  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
251 
252 protected:
253  virtual void DoDispose (void);
254  /*
255  * This function will notify other components connected to the node that a new stack member is now connected
256  * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
257  */
258  virtual void NotifyNewAggregate ();
259 private:
263 
264  std::vector<Ptr<UdpSocketImpl> > m_sockets;
267 
268 };
269 
270 } // namespace ns3
271 
272 #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:41
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:59
Implementation of the UDP protocol.
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport)
Send a packet via UDP (IPv4)
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
UdpL4Protocol(const UdpL4Protocol &)=delete
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
static TypeId GetTypeId(void)
Get the type ID.
virtual 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])
Called from lower-level layers to send the ICMP packet up in the stack.
Ptr< Node > m_node
the node this stack is associated with
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void SetNode(Ptr< Node > node)
Set node associated with this stack.
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > interface)
Called from lower-level layers to send the packet up in the stack.
UdpL4Protocol & operator=(const UdpL4Protocol &)=delete
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
Ptr< Socket > CreateSocket(void)
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
std::vector< Ptr< UdpSocketImpl > > m_sockets
list of sockets
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
virtual void DoDispose(void)
Destructor implementation.
static const uint8_t PROT_NUMBER
protocol number (0x11)
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.