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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#ifndef IPV4_END_POINT_H
21#define IPV4_END_POINT_H
22
23#include "ipv4-header.h"
24#include "ipv4-interface.h"
25
26#include "ns3/callback.h"
27#include "ns3/ipv4-address.h"
28#include "ns3/net-device.h"
29
30#include <stdint.h>
31
32namespace ns3
33{
34
35class Header;
36class Packet;
37
38/**
39 * \ingroup ipv4
40 *
41 * \brief A representation of an internet endpoint/connection
42 *
43 * This class provides an internet four-tuple (source and destination ports
44 * and addresses). These are used in the ns3::Ipv4EndPointDemux as targets
45 * of lookups. The class also has a callback for notification to higher
46 * layers that a packet from a lower layer was received. In the ns3
47 * internet-stack, these notifications are automatically registered to be
48 * received by the corresponding socket.
49 */
50
52{
53 public:
54 /**
55 * \brief Constructor.
56 * \param address the IPv4 address
57 * \param port the port
58 */
59 Ipv4EndPoint(Ipv4Address address, uint16_t port);
61
62 /**
63 * \brief Get the local address.
64 * \return the local address
65 */
67
68 /**
69 * \brief Set the local address.
70 * \param address the address to set
71 */
72 void SetLocalAddress(Ipv4Address address);
73
74 /**
75 * \brief Get the local port.
76 * \return the local port
77 */
78 uint16_t GetLocalPort() const;
79
80 /**
81 * \brief Get the peer address.
82 * \return the peer address
83 */
85
86 /**
87 * \brief Get the peer port.
88 * \return the peer port
89 */
90 uint16_t GetPeerPort() const;
91
92 /**
93 * \brief Set the peer information (address and port).
94 * \param address peer address
95 * \param port peer port
96 */
97 void SetPeer(Ipv4Address address, uint16_t port);
98
99 /**
100 * \brief Bind a socket to specific device.
101 *
102 * This method corresponds to using setsockopt() SO_BINDTODEVICE
103 * of real network or BSD sockets. If set on a socket, this option will
104 * force packets to leave the bound device regardless of the device that
105 * IP routing would naturally choose. In the receive direction, only
106 * packets received from the bound interface will be delivered.
107 *
108 * This option has no particular relationship to binding sockets to
109 * an address via Socket::Bind (). It is possible to bind sockets to a
110 * specific IP address on the bound interface by calling both
111 * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
112 * is also possible to bind to mismatching device and address, even if
113 * the socket can not receive any packets as a result.
114 *
115 * \param netdevice Pointer to Netdevice of desired interface
116 */
117 void BindToNetDevice(Ptr<NetDevice> netdevice);
118
119 /**
120 * \brief Returns socket's bound netdevice, if any.
121 *
122 * This method corresponds to using getsockopt() SO_BINDTODEVICE
123 * of real network or BSD sockets.
124 *
125 *
126 * \returns Pointer to interface.
127 */
129
130 // Called from socket implementations to get notified about important events.
131 /**
132 * \brief Set the reception callback.
133 * \param callback callback function
134 */
135 void SetRxCallback(
136 Callback<void, Ptr<Packet>, Ipv4Header, uint16_t, Ptr<Ipv4Interface>> callback);
137 /**
138 * \brief Set the ICMP callback.
139 * \param callback callback function
140 */
142 /**
143 * \brief Set the default destroy callback.
144 * \param callback callback function
145 */
146 void SetDestroyCallback(Callback<void> callback);
147
148 /**
149 * \brief Forward the packet to the upper level.
150 *
151 * Called from an L4Protocol implementation to notify an endpoint of a
152 * packet reception.
153 * \param p the packet
154 * \param header the packet header
155 * \param sport source port
156 * \param incomingInterface incoming interface
157 */
158 void ForwardUp(Ptr<Packet> p,
159 const Ipv4Header& header,
160 uint16_t sport,
161 Ptr<Ipv4Interface> incomingInterface);
162
163 /**
164 * \brief Forward the ICMP packet to the upper level.
165 *
166 * Called from an L4Protocol implementation to notify an endpoint of
167 * an icmp message reception.
168 *
169 * \param icmpSource source IP address
170 * \param icmpTtl time-to-live
171 * \param icmpType ICMP type
172 * \param icmpCode ICMP code
173 * \param icmpInfo ICMP info
174 */
175 void ForwardIcmp(Ipv4Address icmpSource,
176 uint8_t icmpTtl,
177 uint8_t icmpType,
178 uint8_t icmpCode,
179 uint32_t icmpInfo);
180
181 /**
182 * \brief Enable or Disable the endpoint Rx capability.
183 * \param enabled true if Rx is enabled
184 */
185 void SetRxEnabled(bool enabled);
186
187 /**
188 * \brief Checks if the endpoint can receive packets.
189 * \returns true if the endpoint can receive packets.
190 */
191 bool IsRxEnabled() const;
192
193 private:
194 /**
195 * \brief The local address.
196 */
198
199 /**
200 * \brief The local port.
201 */
202 uint16_t m_localPort;
203
204 /**
205 * \brief The peer address.
206 */
208
209 /**
210 * \brief The peer port.
211 */
212 uint16_t m_peerPort;
213
214 /**
215 * \brief The NetDevice the EndPoint is bound to (if any).
216 */
218
219 /**
220 * \brief The RX callback.
221 */
223
224 /**
225 * \brief The ICMPv6 callback.
226 */
228
229 /**
230 * \brief The destroy callback.
231 */
233
234 /**
235 * \brief true if the endpoint can receive packets.
236 */
238};
239
240} // namespace ns3
241
242#endif /* IPV4_END_POINT_H */
Callback template class.
Definition: callback.h:438
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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.
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:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.