A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-end-point.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef IPV4_END_POINT_H
10#define IPV4_END_POINT_H
11
12#include "ipv4-header.h"
13#include "ipv4-interface.h"
14
15#include "ns3/callback.h"
16#include "ns3/ipv4-address.h"
17#include "ns3/net-device.h"
18
19#include <stdint.h>
20
21namespace ns3
22{
23
24class Header;
25class Packet;
26
27/**
28 * \ingroup ipv4
29 *
30 * \brief A representation of an internet endpoint/connection
31 *
32 * This class provides an internet four-tuple (source and destination ports
33 * and addresses). These are used in the ns3::Ipv4EndPointDemux as targets
34 * of lookups. The class also has a callback for notification to higher
35 * layers that a packet from a lower layer was received. In the ns3
36 * internet-stack, these notifications are automatically registered to be
37 * received by the corresponding socket.
38 */
39
41{
42 public:
43 /**
44 * \brief Constructor.
45 * \param address the IPv4 address
46 * \param port the port
47 */
48 Ipv4EndPoint(Ipv4Address address, uint16_t port);
50
51 /**
52 * \brief Get the local address.
53 * \return the local address
54 */
56
57 /**
58 * \brief Set the local address.
59 * \param address the address to set
60 */
61 void SetLocalAddress(Ipv4Address address);
62
63 /**
64 * \brief Get the local port.
65 * \return the local port
66 */
67 uint16_t GetLocalPort() const;
68
69 /**
70 * \brief Get the peer address.
71 * \return the peer address
72 */
74
75 /**
76 * \brief Get the peer port.
77 * \return the peer port
78 */
79 uint16_t GetPeerPort() const;
80
81 /**
82 * \brief Set the peer information (address and port).
83 * \param address peer address
84 * \param port peer port
85 */
86 void SetPeer(Ipv4Address address, uint16_t port);
87
88 /**
89 * \brief Bind a socket to specific device.
90 *
91 * This method corresponds to using setsockopt() SO_BINDTODEVICE
92 * of real network or BSD sockets. If set on a socket, this option will
93 * force packets to leave the bound device regardless of the device that
94 * IP routing would naturally choose. In the receive direction, only
95 * packets received from the bound interface will be delivered.
96 *
97 * This option has no particular relationship to binding sockets to
98 * an address via Socket::Bind (). It is possible to bind sockets to a
99 * specific IP address on the bound interface by calling both
100 * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
101 * is also possible to bind to mismatching device and address, even if
102 * the socket can not receive any packets as a result.
103 *
104 * \param netdevice Pointer to Netdevice of desired interface
105 */
106 void BindToNetDevice(Ptr<NetDevice> netdevice);
107
108 /**
109 * \brief Returns socket's bound netdevice, if any.
110 *
111 * This method corresponds to using getsockopt() SO_BINDTODEVICE
112 * of real network or BSD sockets.
113 *
114 *
115 * \returns Pointer to interface.
116 */
118
119 // Called from socket implementations to get notified about important events.
120 /**
121 * \brief Set the reception callback.
122 * \param callback callback function
123 */
124 void SetRxCallback(
125 Callback<void, Ptr<Packet>, Ipv4Header, uint16_t, Ptr<Ipv4Interface>> callback);
126 /**
127 * \brief Set the ICMP callback.
128 * \param callback callback function
129 */
131 /**
132 * \brief Set the default destroy callback.
133 * \param callback callback function
134 */
135 void SetDestroyCallback(Callback<void> callback);
136
137 /**
138 * \brief Forward the packet to the upper level.
139 *
140 * Called from an L4Protocol implementation to notify an endpoint of a
141 * packet reception.
142 * \param p the packet
143 * \param header the packet header
144 * \param sport source port
145 * \param incomingInterface incoming interface
146 */
147 void ForwardUp(Ptr<Packet> p,
148 const Ipv4Header& header,
149 uint16_t sport,
150 Ptr<Ipv4Interface> incomingInterface);
151
152 /**
153 * \brief Forward the ICMP packet to the upper level.
154 *
155 * Called from an L4Protocol implementation to notify an endpoint of
156 * an icmp message reception.
157 *
158 * \param icmpSource source IP address
159 * \param icmpTtl time-to-live
160 * \param icmpType ICMP type
161 * \param icmpCode ICMP code
162 * \param icmpInfo ICMP info
163 */
164 void ForwardIcmp(Ipv4Address icmpSource,
165 uint8_t icmpTtl,
166 uint8_t icmpType,
167 uint8_t icmpCode,
168 uint32_t icmpInfo);
169
170 /**
171 * \brief Enable or Disable the endpoint Rx capability.
172 * \param enabled true if Rx is enabled
173 */
174 void SetRxEnabled(bool enabled);
175
176 /**
177 * \brief Checks if the endpoint can receive packets.
178 * \returns true if the endpoint can receive packets.
179 */
180 bool IsRxEnabled() const;
181
182 private:
183 /**
184 * \brief The local address.
185 */
187
188 /**
189 * \brief The local port.
190 */
191 uint16_t m_localPort;
192
193 /**
194 * \brief The peer address.
195 */
197
198 /**
199 * \brief The peer port.
200 */
201 uint16_t m_peerPort;
202
203 /**
204 * \brief The NetDevice the EndPoint is bound to (if any).
205 */
207
208 /**
209 * \brief The RX callback.
210 */
212
213 /**
214 * \brief The ICMPv6 callback.
215 */
217
218 /**
219 * \brief The destroy callback.
220 */
222
223 /**
224 * \brief true if the endpoint can receive packets.
225 */
227};
228
229} // namespace ns3
230
231#endif /* IPV4_END_POINT_H */
Callback template class.
Definition callback.h:422
Ipv4 addresses are stored in host order in this class.
A representation of an internet endpoint/connection.
bool m_rxEnabled
true if the endpoint can receive packets.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Ipv4Address GetLocalAddress() const
Get the local address.
void SetLocalAddress(Ipv4Address address)
Set the local address.
uint16_t GetPeerPort() const
Get the peer port.
void ForwardUp(Ptr< Packet > p, const Ipv4Header &header, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
Forward the packet to the upper level.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
uint16_t m_localPort
The local port.
Ptr< NetDevice > GetBoundNetDevice() const
Returns socket's bound netdevice, if any.
Ipv4EndPoint(Ipv4Address address, uint16_t port)
Constructor.
uint16_t GetLocalPort() const
Get the local port.
bool IsRxEnabled() const
Checks if the endpoint can receive packets.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
Ipv4Address GetPeerAddress() const
Get the peer address.
Ipv4Address m_peerAddr
The peer address.
uint16_t m_peerPort
The peer port.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void SetPeer(Ipv4Address address, uint16_t port)
Set the peer information (address and port).
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ipv4Address m_localAddr
The local address.
Callback< void > m_destroyCallback
The destroy callback.
Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > m_rxCallback
The RX callback.
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
uint16_t port
Definition dsdv-manet.cc:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.