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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
9#ifndef IPV6_END_POINT_H
10#define IPV6_END_POINT_H
11
12#include "ipv6-header.h"
13#include "ipv6-interface.h"
14
15#include "ns3/callback.h"
16#include "ns3/ipv6-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 ipv6
29 *
30 * \brief A representation of an IPv6 endpoint/connection
31 *
32 * This class provides an Internet four-tuple (source and destination ports
33 * and addresses). These are used in the ns3::Ipv6EndPointDemux 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 */
40{
41 public:
42 /**
43 * \brief Constructor.
44 * \param addr the IPv6 address
45 * \param port the port
46 */
47 Ipv6EndPoint(Ipv6Address addr, uint16_t port);
48
50
51 /**
52 * \brief Get the local address.
53 * \return the local address
54 */
56
57 /**
58 * \brief Set the local address.
59 * \param addr the address to set
60 */
62
63 /**
64 * \brief Get the local port.
65 * \return the local port
66 */
67 uint16_t GetLocalPort() const;
68
69 /**
70 * \brief Set the local port.
71 * \param port the port to set
72 */
73 void SetLocalPort(uint16_t port);
74
75 /**
76 * \brief Get the peer address.
77 * \return the peer address
78 */
80
81 /**
82 * \brief Get the peer port.
83 * \return the peer port
84 */
85 uint16_t GetPeerPort() const;
86
87 /**
88 * \brief Set the peer information (address and port).
89 * \param addr peer address
90 * \param port peer port
91 */
92 void SetPeer(Ipv6Address addr, uint16_t port);
93
94 /**
95 * \brief Bind a socket to specific device.
96 *
97 * This method corresponds to using setsockopt() SO_BINDTODEVICE
98 * of real network or BSD sockets. If set on a socket, this option will
99 * force packets to leave the bound device regardless of the device that
100 * IP routing would naturally choose. In the receive direction, only
101 * packets received from the bound interface will be delivered.
102 *
103 * This option has no particular relationship to binding sockets to
104 * an address via Socket::Bind (). It is possible to bind sockets to a
105 * specific IP address on the bound interface by calling both
106 * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
107 * is also possible to bind to mismatching device and address, even if
108 * the socket can not receive any packets as a result.
109 *
110 * \param netdevice Pointer to Netdevice of desired interface
111 */
112 void BindToNetDevice(Ptr<NetDevice> netdevice);
113
114 /**
115 * \brief Returns socket's bound netdevice, if any.
116 *
117 * This method corresponds to using getsockopt() SO_BINDTODEVICE
118 * of real network or BSD sockets.
119 *
120 *
121 * \returns Pointer to interface.
122 */
124
125 /**
126 * \brief Set the reception callback.
127 * \param callback callback function
128 */
129 void SetRxCallback(
130 Callback<void, Ptr<Packet>, Ipv6Header, uint16_t, Ptr<Ipv6Interface>> callback);
131
132 /**
133 * \brief Set the ICMP callback.
134 * \param callback callback function
135 */
137
138 /**
139 * \brief Set the default destroy callback.
140 * \param callback callback function
141 */
142 void SetDestroyCallback(Callback<void> callback);
143
144 /**
145 * \brief Forward the packet to the upper level.
146 *
147 * Called from an L4Protocol implementation to notify an endpoint of a
148 * packet reception.
149 *
150 * \param p the packet
151 * \param header the packet header
152 * \param port source port
153 * \param incomingInterface incoming interface
154 */
155 void ForwardUp(Ptr<Packet> p,
156 Ipv6Header header,
157 uint16_t port,
158 Ptr<Ipv6Interface> incomingInterface);
159
160 /**
161 * \brief Forward the ICMP packet to the upper level.
162 *
163 * Called from an L4Protocol implementation to notify an endpoint of
164 * an icmp message reception.
165 *
166 * \param src source IPv6 address
167 * \param ttl time-to-live
168 * \param type ICMPv6 type
169 * \param code ICMPv6 code
170 * \param info ICMPv6 info
171 */
172 void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info);
173
174 /**
175 * \brief Enable or Disable the endpoint Rx capability.
176 * \param enabled true if Rx is enabled
177 */
178 void SetRxEnabled(bool enabled);
179
180 /**
181 * \brief Checks if the endpoint can receive packets.
182 * \returns true if the endpoint can receive packets.
183 */
184 bool IsRxEnabled() const;
185
186 private:
187 /**
188 * \brief The local address.
189 */
191
192 /**
193 * \brief The local port.
194 */
195 uint16_t m_localPort;
196
197 /**
198 * \brief The peer address.
199 */
201
202 /**
203 * \brief The peer port.
204 */
205 uint16_t m_peerPort;
206
207 /**
208 * \brief The NetDevice the EndPoint is bound to (if any).
209 */
211
212 /**
213 * \brief The RX callback.
214 */
216
217 /**
218 * \brief The ICMPv6 callback.
219 */
221
222 /**
223 * \brief The destroy callback.
224 */
226
227 /**
228 * \brief true if the endpoint can receive packets.
229 */
231};
232
233} /* namespace ns3 */
234
235#endif /* IPV6_END_POINT_H */
Callback template class.
Definition callback.h:422
Describes an IPv6 address.
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.
Ipv6EndPoint(Ipv6Address addr, uint16_t port)
Constructor.
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:24
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.