A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
udp-socket.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 * 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 * Authors: George F. Riley<riley@ece.gatech.edu>
19 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 */
21
22#ifndef UDP_SOCKET_H
23#define UDP_SOCKET_H
24
25#include "ns3/callback.h"
26#include "ns3/object.h"
27#include "ns3/ptr.h"
28#include "ns3/socket.h"
29#include "ns3/traced-callback.h"
30
31namespace ns3
32{
33
34class Node;
35class Packet;
36
37/**
38 * \ingroup socket
39 * \ingroup udp
40 *
41 * \brief (abstract) base class of all UdpSockets
42 *
43 * This class exists solely for hosting UdpSocket attributes that can
44 * be reused across different implementations, and for declaring
45 * UDP-specific multicast API.
46 */
47class UdpSocket : public Socket
48{
49 public:
50 /**
51 * Get the type ID.
52 * \brief Get the type ID.
53 * \return the object TypeId
54 */
55 static TypeId GetTypeId();
56
57 UdpSocket();
58 ~UdpSocket() override;
59
60 /**
61 * \brief Corresponds to socket option MCAST_JOIN_GROUP
62 *
63 * \param interface interface number, or 0
64 * \param groupAddress multicast group address
65 * \returns on success, zero is returned. On error, -1 is returned,
66 * and errno is set appropriately
67 *
68 * Enable reception of multicast datagrams for this socket on the
69 * interface number specified. If zero is specified as
70 * the interface, then a single local interface is chosen by
71 * system. In the future, this function will generate trigger IGMP
72 * joins as necessary when IGMP is implemented, but for now, this
73 * just enables multicast datagram reception in the system if not already
74 * enabled for this interface/groupAddress combination.
75 *
76 * \attention IGMP is not yet implemented in ns-3
77 *
78 * This function may be called repeatedly on a given socket but each
79 * join must be for a different multicast address, or for the same
80 * multicast address but on a different interface from previous joins.
81 * This enables host multihoming, and the ability to join the same
82 * group on different interfaces.
83 */
84 virtual int MulticastJoinGroup(uint32_t interface, const Address& groupAddress) = 0;
85
86 /**
87 * \brief Corresponds to socket option MCAST_LEAVE_GROUP
88 *
89 * \param interface interface number, or 0
90 * \param groupAddress multicast group address
91 * \returns on success, zero is returned. On error, -1 is returned,
92 * and errno is set appropriately
93 *
94 * Disable reception of multicast datagrams for this socket on the
95 * interface number specified. If zero is specified as
96 * the interfaceIndex, then a single local interface is chosen by
97 * system. In the future, this function will generate trigger IGMP
98 * leaves as necessary when IGMP is implemented, but for now, this
99 * just disables multicast datagram reception in the system if this
100 * socket is the last for this interface/groupAddress combination.
101 *
102 * \attention IGMP is not yet implemented in ns-3
103 */
104 virtual int MulticastLeaveGroup(uint32_t interface, const Address& groupAddress) = 0;
105
106 private:
107 // Indirect the attribute setting and getting through private virtual methods
108 /**
109 * \brief Set the receiving buffer size
110 * \param size the buffer size
111 */
112 virtual void SetRcvBufSize(uint32_t size) = 0;
113 /**
114 * \brief Get the receiving buffer size
115 * \returns the buffer size
116 */
117 virtual uint32_t GetRcvBufSize() const = 0;
118 /**
119 * \brief Set the IP multicast TTL
120 * \param ipTtl the IP multicast TTL
121 */
122 virtual void SetIpMulticastTtl(uint8_t ipTtl) = 0;
123 /**
124 * \brief Get the IP multicast TTL
125 * \returns the IP multicast TTL
126 */
127 virtual uint8_t GetIpMulticastTtl() const = 0;
128 /**
129 * \brief Set the IP multicast interface
130 * \param ipIf the IP multicast interface
131 */
132 virtual void SetIpMulticastIf(int32_t ipIf) = 0;
133 /**
134 * \brief Get the IP multicast interface
135 * \returns the IP multicast interface
136 */
137 virtual int32_t GetIpMulticastIf() const = 0;
138 /**
139 * \brief Set the IP multicast loop capability
140 *
141 * This means that the socket will receive the packets
142 * sent by itself on a multicast address.
143 * Equivalent to setsockopt IP_MULTICAST_LOOP
144 *
145 * \param loop the IP multicast loop capability
146 */
147 virtual void SetIpMulticastLoop(bool loop) = 0;
148 /**
149 * \brief Get the IP multicast loop capability
150 *
151 * This means that the socket will receive the packets
152 * sent by itself on a multicast address.
153 * Equivalent to setsockopt IP_MULTICAST_LOOP
154 *
155 * \returns the IP multicast loop capability
156 */
157 virtual bool GetIpMulticastLoop() const = 0;
158 /**
159 * \brief Set the MTU discover capability
160 *
161 * \param discover the MTU discover capability
162 */
163 virtual void SetMtuDiscover(bool discover) = 0;
164 /**
165 * \brief Get the MTU discover capability
166 *
167 * \returns the MTU discover capability
168 */
169 virtual bool GetMtuDiscover() const = 0;
170};
171
172} // namespace ns3
173
174#endif /* UDP_SOCKET_H */
a polymophic address class
Definition: address.h:101
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:68
a unique identifier for an interface.
Definition: type-id.h:59
(abstract) base class of all UdpSockets
Definition: udp-socket.h:48
~UdpSocket() override
Definition: udp-socket.cc:87
virtual void SetIpMulticastIf(int32_t ipIf)=0
Set the IP multicast interface.
virtual int MulticastLeaveGroup(uint32_t interface, const Address &groupAddress)=0
Corresponds to socket option MCAST_LEAVE_GROUP.
virtual int MulticastJoinGroup(uint32_t interface, const Address &groupAddress)=0
Corresponds to socket option MCAST_JOIN_GROUP.
virtual void SetRcvBufSize(uint32_t size)=0
Set the receiving buffer size.
virtual bool GetMtuDiscover() const =0
Get the MTU discover capability.
virtual int32_t GetIpMulticastIf() const =0
Get the IP multicast interface.
virtual uint8_t GetIpMulticastTtl() const =0
Get the IP multicast TTL.
static TypeId GetTypeId()
Get the type ID.
Definition: udp-socket.cc:37
virtual void SetIpMulticastLoop(bool loop)=0
Set the IP multicast loop capability.
virtual bool GetIpMulticastLoop() const =0
Get the IP multicast loop capability.
virtual void SetMtuDiscover(bool discover)=0
Set the MTU discover capability.
virtual void SetIpMulticastTtl(uint8_t ipTtl)=0
Set the IP multicast TTL.
virtual uint32_t GetRcvBufSize() const =0
Get the receiving buffer size.
Every class exported by the ns3 library is enclosed in the ns3 namespace.