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