A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
udp-socket-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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 #ifndef UDP_SOCKET_IMPL_H
21 #define UDP_SOCKET_IMPL_H
22 
23 #include <stdint.h>
24 #include <queue>
25 #include "ns3/callback.h"
26 #include "ns3/traced-callback.h"
27 #include "ns3/socket.h"
28 #include "ns3/ptr.h"
29 #include "ns3/ipv4-address.h"
30 #include "ns3/udp-socket.h"
31 #include "ns3/ipv4-interface.h"
32 #include "icmpv4.h"
33 
34 namespace ns3 {
35 
36 class Ipv4EndPoint;
37 class Ipv6EndPoint;
38 class Node;
39 class Packet;
40 class UdpL4Protocol;
41 class Ipv6Header;
42 class Ipv6Interface;
43 
52 class UdpSocketImpl : public UdpSocket
53 {
54 public:
59  static TypeId GetTypeId (void);
63  UdpSocketImpl ();
64  virtual ~UdpSocketImpl ();
65 
70  void SetNode (Ptr<Node> node);
75  void SetUdp (Ptr<UdpL4Protocol> udp);
76 
77  virtual enum SocketErrno GetErrno (void) const;
78  virtual enum SocketType GetSocketType (void) const;
79  virtual Ptr<Node> GetNode (void) const;
80  virtual int Bind (void);
81  virtual int Bind6 (void);
82  virtual int Bind (const Address &address);
83  virtual int Close (void);
84  virtual int ShutdownSend (void);
85  virtual int ShutdownRecv (void);
86  virtual int Connect (const Address &address);
87  virtual int Listen (void);
88  virtual uint32_t GetTxAvailable (void) const;
89  virtual int Send (Ptr<Packet> p, uint32_t flags);
90  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &address);
91  virtual uint32_t GetRxAvailable (void) const;
92  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
93  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
94  Address &fromAddress);
95  virtual int GetSockName (Address &address) const;
96  virtual int MulticastJoinGroup (uint32_t interfaceIndex, const Address &groupAddress);
97  virtual int MulticastLeaveGroup (uint32_t interfaceIndex, const Address &groupAddress);
98  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
99  virtual bool SetAllowBroadcast (bool allowBroadcast);
100  virtual bool GetAllowBroadcast () const;
101 
102 private:
103  // Attributes set through UdpSocket base class
104  virtual void SetRcvBufSize (uint32_t size);
105  virtual uint32_t GetRcvBufSize (void) const;
106  virtual void SetIpMulticastTtl (uint8_t ipTtl);
107  virtual uint8_t GetIpMulticastTtl (void) const;
108  virtual void SetIpMulticastIf (int32_t ipIf);
109  virtual int32_t GetIpMulticastIf (void) const;
110  virtual void SetIpMulticastLoop (bool loop);
111  virtual bool GetIpMulticastLoop (void) const;
112  virtual void SetMtuDiscover (bool discover);
113  virtual bool GetMtuDiscover (void) const;
114 
115 
116  friend class UdpSocketFactory;
117  // invoked by Udp class
118 
123  int FinishBind (void);
124 
133  void ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, Ptr<Ipv4Interface> incomingInterface);
134 
143  void ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface);
144 
151  void Destroy (void);
152 
159  void Destroy6 (void);
160 
164  void DeallocateEndPoint (void);
165 
171  int DoSend (Ptr<Packet> p);
178  int DoSendTo (Ptr<Packet> p, const Address &daddr);
186  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
194  int DoSendTo (Ptr<Packet> p, Ipv6Address daddr, uint16_t dport);
195 
205  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo);
206 
216  void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo);
217 
218  // Connections to other layers of TCP/IP
225 
227  uint16_t m_defaultPort;
229 
233  bool m_connected;
235 
236  std::queue<Ptr<Packet> > m_deliveryQueue;
237  uint32_t m_rxAvailable;
238 
239  // Socket attributes
240  uint32_t m_rcvBufSize;
242  int32_t m_ipMulticastIf;
245 };
246 
247 } // namespace ns3
248 
249 #endif /* UDP_SOCKET_IMPL_H */
(abstract) base class of all UdpSockets
Definition: udp-socket.h:46
bool m_shutdownSend
Send no longer allowed.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
Doxygen introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
Callback template class.
Definition: callback.h:924
enum SocketErrno m_errno
Socket error code.
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
bool m_allowBroadcast
Allow send broadcast packets.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:174
std::queue< Ptr< Packet > > m_deliveryQueue
Queue for incoming packets.
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual int Close(void)
Close a socket.
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
uint32_t m_rxAvailable
Number of available bytes to be received.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
A sockets interface to UDP.
bool m_connected
Connection established.
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:86
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void ForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual int ShutdownRecv(void)
virtual int GetSockName(Address &address) const
Get socket address.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
int DoSendTo(Ptr< Packet > p, const Address &daddr)
Send a packet to a specific destination.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
int DoSend(Ptr< Packet > p)
Send a packet.
void SetNode(Ptr< Node > node)
Set the associated node.
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
UdpSocketImpl()
Create an unbound udp socket.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
uint8_t m_ipMulticastTtl
Multicast TTL.
Address m_defaultAddress
Default address.
virtual enum SocketType GetSocketType(void) const
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
int FinishBind(void)
Finish the binding process.
static TypeId GetTypeId(void)
Get the type ID.
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
bool m_shutdownRecv
Receive no longer allowed.
Ptr< Node > m_node
the associated node
virtual int ShutdownSend(void)
Describes an IPv6 address.
Definition: ipv6-address.h:46
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
uint32_t m_rcvBufSize
Receive buffer size.
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
bool m_ipMulticastLoop
Allow multicast loop.
virtual int Listen(void)
Listen for incoming connections.
uint16_t m_defaultPort
Default port.
A representation of an internet IPv6 endpoint/connection.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
int32_t m_ipMulticastIf
Multicast Interface.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
tuple address
Definition: first.py:37
API to create UDP socket instances.
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
a unique identifier for an interface.
Definition: type-id.h:49
bool m_mtuDiscover
Allow MTU discovery.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
A representation of an internet endpoint/connection.
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.