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 
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 SetIpTtl (uint8_t ipTtl);
93  virtual uint8_t GetIpTtl (void) const;
94  virtual void SetIpMulticastTtl (uint8_t ipTtl);
95  virtual uint8_t GetIpMulticastTtl (void) const;
96  virtual void SetIpMulticastIf (int32_t ipIf);
97  virtual int32_t GetIpMulticastIf (void) const;
98  virtual void SetIpMulticastLoop (bool loop);
99  virtual bool GetIpMulticastLoop (void) const;
100  virtual void SetMtuDiscover (bool discover);
101  virtual bool GetMtuDiscover (void) const;
102 
103 
104  friend class UdpSocketFactory;
105  // invoked by Udp class
106  int FinishBind (void);
107  void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port,
108  Ptr<Ipv4Interface> incomingInterface);
109  void ForwardUp6 (Ptr<Packet> p, Ipv6Address saddr, Ipv6Address daddr, uint16_t port);
110  void Destroy (void);
111  void Destroy6 (void);
112  int DoSend (Ptr<Packet> p);
113  int DoSendTo (Ptr<Packet> p, const Address &daddr);
114  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
115  int DoSendTo (Ptr<Packet> p, Ipv6Address daddr, uint16_t dport);
116  void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
117  uint8_t icmpType, uint8_t icmpCode,
118  uint32_t icmpInfo);
119  void ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
120  uint8_t icmpType, uint8_t icmpCode,
121  uint32_t icmpInfo);
122 
128  uint16_t m_defaultPort;
130 
136 
137  std::queue<Ptr<Packet> > m_deliveryQueue;
138  uint32_t m_rxAvailable;
139 
140  // Socket attributes
141  uint32_t m_rcvBufSize;
142  uint8_t m_ipTtl;
149 };
150 
151 } // namespace ns3
152 
153 #endif /* UDP_SOCKET_IMPL_H */