A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-end-point.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#ifndef IPV6_END_POINT_H
21#define IPV6_END_POINT_H
22
23#include "ipv6-header.h"
24#include "ipv6-interface.h"
25
26#include "ns3/callback.h"
27#include "ns3/ipv6-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 ipv6
40 *
41 * \brief A representation of an IPv6 endpoint/connection
42 *
43 * This class provides an Internet four-tuple (source and destination ports
44 * and addresses). These are used in the ns3::Ipv6EndPointDemux 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 */
51{
52 public:
53 /**
54 * \brief Constructor.
55 * \param addr the IPv6 address
56 * \param port the port
57 */
58 Ipv6EndPoint(Ipv6Address addr, uint16_t port);
59
61
62 /**
63 * \brief Get the local address.
64 * \return the local address
65 */
67
68 /**
69 * \brief Set the local address.
70 * \param addr the address to set
71 */
73
74 /**
75 * \brief Get the local port.
76 * \return the local port
77 */
78 uint16_t GetLocalPort() const;
79
80 /**
81 * \brief Set the local port.
82 * \param port the port to set
83 */
84 void SetLocalPort(uint16_t port);
85
86 /**
87 * \brief Get the peer address.
88 * \return the peer address
89 */
91
92 /**
93 * \brief Get the peer port.
94 * \return the peer port
95 */
96 uint16_t GetPeerPort() const;
97
98 /**
99 * \brief Set the peer information (address and port).
100 * \param addr peer address
101 * \param port peer port
102 */
103 void SetPeer(Ipv6Address addr, uint16_t port);
104
105 /**
106 * \brief Bind a socket to specific device.
107 *
108 * This method corresponds to using setsockopt() SO_BINDTODEVICE
109 * of real network or BSD sockets. If set on a socket, this option will
110 * force packets to leave the bound device regardless of the device that
111 * IP routing would naturally choose. In the receive direction, only
112 * packets received from the bound interface will be delivered.
113 *
114 * This option has no particular relationship to binding sockets to
115 * an address via Socket::Bind (). It is possible to bind sockets to a
116 * specific IP address on the bound interface by calling both
117 * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
118 * is also possible to bind to mismatching device and address, even if
119 * the socket can not receive any packets as a result.
120 *
121 * \param netdevice Pointer to Netdevice of desired interface
122 */
123 void BindToNetDevice(Ptr<NetDevice> netdevice);
124
125 /**
126 * \brief Returns socket's bound netdevice, if any.
127 *
128 * This method corresponds to using getsockopt() SO_BINDTODEVICE
129 * of real network or BSD sockets.
130 *
131 *
132 * \returns Pointer to interface.
133 */
135
136 /**
137 * \brief Set the reception callback.
138 * \param callback callback function
139 */
140 void SetRxCallback(
141 Callback<void, Ptr<Packet>, Ipv6Header, uint16_t, Ptr<Ipv6Interface>> callback);
142
143 /**
144 * \brief Set the ICMP callback.
145 * \param callback callback function
146 */
148
149 /**
150 * \brief Set the default destroy callback.
151 * \param callback callback function
152 */
153 void SetDestroyCallback(Callback<void> callback);
154
155 /**
156 * \brief Forward the packet to the upper level.
157 *
158 * Called from an L4Protocol implementation to notify an endpoint of a
159 * packet reception.
160 *
161 * \param p the packet
162 * \param header the packet header
163 * \param port source port
164 * \param incomingInterface incoming interface
165 */
166 void ForwardUp(Ptr<Packet> p,
167 Ipv6Header header,
168 uint16_t port,
169 Ptr<Ipv6Interface> incomingInterface);
170
171 /**
172 * \brief Forward the ICMP packet to the upper level.
173 *
174 * Called from an L4Protocol implementation to notify an endpoint of
175 * an icmp message reception.
176 *
177 * \param src source IPv6 address
178 * \param ttl time-to-live
179 * \param type ICMPv6 type
180 * \param code ICMPv6 code
181 * \param info ICMPv6 info
182 */
183 void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info);
184
185 /**
186 * \brief Enable or Disable the endpoint Rx capability.
187 * \param enabled true if Rx is enabled
188 */
189 void SetRxEnabled(bool enabled);
190
191 /**
192 * \brief Checks if the endpoint can receive packets.
193 * \returns true if the endpoint can receive packets.
194 */
195 bool IsRxEnabled() const;
196
197 private:
198 /**
199 * \brief The local address.
200 */
202
203 /**
204 * \brief The local port.
205 */
206 uint16_t m_localPort;
207
208 /**
209 * \brief The peer address.
210 */
212
213 /**
214 * \brief The peer port.
215 */
216 uint16_t m_peerPort;
217
218 /**
219 * \brief The NetDevice the EndPoint is bound to (if any).
220 */
222
223 /**
224 * \brief The RX callback.
225 */
227
228 /**
229 * \brief The ICMPv6 callback.
230 */
232
233 /**
234 * \brief The destroy callback.
235 */
237
238 /**
239 * \brief true if the endpoint can receive packets.
240 */
242};
243
244} /* namespace ns3 */
245
246#endif /* IPV6_END_POINT_H */
Callback template class.
Definition: callback.h:438
Describes an IPv6 address.
Definition: ipv6-address.h:49
A representation of an IPv6 endpoint/connection.
uint16_t m_peerPort
The peer port.
void ForwardUp(Ptr< Packet > p, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Forward the packet to the upper level.
uint16_t GetLocalPort() const
Get the local port.
void SetPeer(Ipv6Address addr, uint16_t port)
Set the peer information (address and port).
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
Ipv6Address GetPeerAddress() const
Get the peer address.
Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > m_rxCallback
The RX callback.
Ipv6Address m_peerAddr
The peer address.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void SetLocalPort(uint16_t port)
Set the local port.
bool m_rxEnabled
true if the endpoint can receive packets.
Ipv6Address GetLocalAddress() const
Get the local address.
Callback< void > m_destroyCallback
The destroy callback.
Ipv6Address m_localAddr
The local address.
void SetLocalAddress(Ipv6Address addr)
Set the local address.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
uint16_t m_localPort
The local port.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
bool IsRxEnabled() const
Checks if the endpoint can receive packets.
Ptr< NetDevice > GetBoundNetDevice() const
Returns socket's bound netdevice, if any.
uint16_t GetPeerPort() const
Get the peer port.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Packet header for IPv6.
Definition: ipv6-header.h:35
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.