A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
udp-socket-impl.h
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 
50 class UdpSocketImpl : public UdpSocket
51 {
52 public:
53  static TypeId GetTypeId (void);
57  UdpSocketImpl ();
58  virtual ~UdpSocketImpl ();
59 
60  void SetNode (Ptr<Node> node);
61  void SetUdp (Ptr<UdpL4Protocol> udp);
62 
63  virtual enum SocketErrno GetErrno (void) const;
64  virtual enum SocketType GetSocketType (void) const;
65  virtual Ptr<Node> GetNode (void) const;
66  virtual int Bind (void);
67  virtual int Bind6 (void);
68  virtual int Bind (const Address &address);
69  virtual int Close (void);
70  virtual int ShutdownSend (void);
71  virtual int ShutdownRecv (void);
72  virtual int Connect (const Address &address);
73  virtual int Listen (void);
74  virtual uint32_t GetTxAvailable (void) const;
75  virtual int Send (Ptr<Packet> p, uint32_t flags);
76  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &address);
77  virtual uint32_t GetRxAvailable (void) const;
78  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
79  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
80  Address &fromAddress);
81  virtual int GetSockName (Address &address) const;
82  virtual int MulticastJoinGroup (uint32_t interfaceIndex, const Address &groupAddress);
83  virtual int MulticastLeaveGroup (uint32_t interfaceIndex, const Address &groupAddress);
84  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
85  virtual bool SetAllowBroadcast (bool allowBroadcast);
86  virtual bool GetAllowBroadcast () const;
87 
88 private:
89  // Attributes set through UdpSocket base class
90  virtual void SetRcvBufSize (uint32_t size);
91  virtual uint32_t GetRcvBufSize (void) const;
92  virtual void SetIpMulticastTtl (uint8_t ipTtl);
93  virtual uint8_t GetIpMulticastTtl (void) const;
94  virtual void SetIpMulticastIf (int32_t ipIf);
95  virtual int32_t GetIpMulticastIf (void) const;
96  virtual void SetIpMulticastLoop (bool loop);
97  virtual bool GetIpMulticastLoop (void) const;
98  virtual void SetMtuDiscover (bool discover);
99  virtual bool GetMtuDiscover (void) const;
100 
101 
102  friend class UdpSocketFactory;
103  // invoked by Udp class
104  int FinishBind (void);
105  void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port,
106  Ptr<Ipv4Interface> incomingInterface);
107  void ForwardUp6 (Ptr<Packet> p, Ipv6Header header, uint16_t port);
108  void Destroy (void);
109  void Destroy6 (void);
110  int DoSend (Ptr<Packet> p);
111  int DoSendTo (Ptr<Packet> p, const Address &daddr);
112  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
113  int DoSendTo (Ptr<Packet> p, Ipv6Address daddr, uint16_t dport);
114  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
115  uint8_t icmpType, uint8_t icmpCode,
116  uint32_t icmpInfo);
117  void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
118  uint8_t icmpType, uint8_t icmpCode,
119  uint32_t icmpInfo);
120 
121  Ipv4EndPoint *m_endPoint;
122  Ipv6EndPoint *m_endPoint6;
123  Ptr<Node> m_node;
124  Ptr<UdpL4Protocol> m_udp;
125  Address m_defaultAddress;
126  uint16_t m_defaultPort;
127  TracedCallback<Ptr<const Packet> > m_dropTrace;
128 
129  enum SocketErrno m_errno;
130  bool m_shutdownSend;
131  bool m_shutdownRecv;
132  bool m_connected;
133  bool m_allowBroadcast;
134 
135  std::queue<Ptr<Packet> > m_deliveryQueue;
136  uint32_t m_rxAvailable;
137 
138  // Socket attributes
139  uint32_t m_rcvBufSize;
140  uint8_t m_ipMulticastTtl;
141  int32_t m_ipMulticastIf;
142  bool m_ipMulticastLoop;
143  bool m_mtuDiscover;
146 };
147 
148 } // namespace ns3
149 
150 #endif /* UDP_SOCKET_IMPL_H */
(abstract) base class of all UdpSockets
Definition: udp-socket.h:46
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
Packet header for IPv6.
Definition: ipv6-header.h:33
Callback template class.
Definition: callback.h:369
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:174
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 void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
A sockets interface to UDP.
a polymophic address class
Definition: address.h:86
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
virtual enum SocketErrno GetErrno(void) const
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual int ShutdownRecv(void)
virtual int GetSockName(Address &address) const
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
virtual uint32_t GetRxAvailable(void) const
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this 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.
virtual enum SocketType GetSocketType(void) const
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
virtual int ShutdownSend(void)
Describes an IPv6 address.
Definition: ipv6-address.h:44
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.
virtual int Listen(void)
Listen for incoming connections.
An IPv6 end point, four tuples identification.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
API to create UDP socket instances.
a unique identifier for an interface.
Definition: type-id.h:44
A representation of an internet endpoint/connection.
virtual Ptr< Node > GetNode(void) const