A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-raw-socket-impl.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_RAW_SOCKET_IMPL_H
10#define IPV6_RAW_SOCKET_IMPL_H
11
12#include "ipv6-header.h"
13
14#include "ns3/ipv6-address.h"
15#include "ns3/socket.h"
16
17#include <list>
18
19namespace ns3
20{
21
22class NetDevice;
23class Node;
24
25/**
26 * \ingroup socket
27 * \ingroup ipv6
28 *
29 * \brief IPv6 raw socket.
30 *
31 * A RAW Socket typically is used to access specific IP layers not usually
32 * available through L4 sockets, e.g., ICMP. The implementer should take
33 * particular care to define the Ipv6RawSocketImpl Attributes, and in
34 * particular the Protocol attribute.
35 * Not setting it will result in a zero protocol at IP level (corresponding
36 * to the HopByHop IPv6 Extension header, i.e., Ipv6ExtensionHopByHopHeader)
37 * when sending data through the socket, which is probably not the intended
38 * behavior.
39 *
40 * A correct example is (from src/applications/model/radvd.cc):
41 * \code
42 if (!m_socket)
43 {
44 TypeId tid = TypeId::LookupByName ("ns3::Ipv6RawSocketFactory");
45 m_socket = Socket::CreateSocket (GetNode (), tid);
46
47 NS_ASSERT (m_socket);
48
49 m_socket->SetAttribute ("Protocol", UintegerValue(Ipv6Header::IPV6_ICMPV6));
50 m_socket->SetRecvCallback (MakeCallback (&Radvd::HandleRead, this));
51 }
52 * \endcode
53 *
54 */
56{
57 public:
58 /**
59 * \brief Get the type ID of this class.
60 * \return type ID
61 */
62 static TypeId GetTypeId();
63
65 ~Ipv6RawSocketImpl() override;
66
67 /**
68 * \brief Set the node associated with this socket.
69 * \param node node to set
70 */
71 void SetNode(Ptr<Node> node);
72
73 Socket::SocketErrno GetErrno() const override;
74
75 /**
76 * \brief Get socket type (NS3_SOCK_RAW)
77 * \return socket type
78 */
79 Socket::SocketType GetSocketType() const override;
80
81 Ptr<Node> GetNode() const override;
82
83 int Bind(const Address& address) override;
84 int Bind() override;
85 int Bind6() override;
86
87 int GetSockName(Address& address) const override;
88 int GetPeerName(Address& address) const override;
89
90 int Close() override;
91 int ShutdownSend() override;
92 int ShutdownRecv() override;
93 int Connect(const Address& address) override;
94 int Listen() override;
95 uint32_t GetTxAvailable() const override;
96 uint32_t GetRxAvailable() const override;
97 int Send(Ptr<Packet> p, uint32_t flags) override;
98 int SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddress) override;
99 Ptr<Packet> Recv(uint32_t maxSize, uint32_t flags) override;
100 Ptr<Packet> RecvFrom(uint32_t maxSize, uint32_t flags, Address& fromAddress) override;
101 void Ipv6JoinGroup(Ipv6Address address,
103 std::vector<Ipv6Address> sourceAddresses) override;
104
105 /**
106 * \brief Set protocol field.
107 * \param protocol protocol to set
108 */
109 void SetProtocol(uint16_t protocol);
110
111 /**
112 * \brief Forward up to receive method.
113 * \param p packet
114 * \param hdr IPv6 header
115 * \param device device
116 * \return true if forwarded, false otherwise
117 */
119
120 bool SetAllowBroadcast(bool allowBroadcast) override;
121 bool GetAllowBroadcast() const override;
122
123 /**
124 * \brief Clean the ICMPv6 filter structure
125 */
127
128 /**
129 * \brief Set the filter to block all the ICMPv6 types
130 */
132
133 /**
134 * \brief Set the filter to pass one ICMPv6 type
135 * \param type the ICMPv6 type to pass
136 */
137 void Icmpv6FilterSetPass(uint8_t type);
138
139 /**
140 * \brief Set the filter to block one ICMPv6 type
141 * \param type the ICMPv6 type to block
142 */
143 void Icmpv6FilterSetBlock(uint8_t type);
144
145 /**
146 * \brief Ask the filter about the status of one ICMPv6 type
147 * \param type the ICMPv6 type
148 * \return true if the ICMP type is passing through
149 */
150 bool Icmpv6FilterWillPass(uint8_t type);
151
152 /**
153 * \brief Ask the filter about the status of one ICMPv6 type
154 * \param type the ICMPv6 type
155 * \return true if the ICMP type is being blocked
156 */
157 bool Icmpv6FilterWillBlock(uint8_t type);
158
159 private:
160 /**
161 * \brief IPv6 raw data and additional information.
162 */
163 struct Data
164 {
165 Ptr<Packet> packet; /**< Packet data */
166 Ipv6Address fromIp; /**< Source address */
167 uint16_t fromProtocol; /**< Protocol used */
168 };
169
170 /**
171 * \brief Dispose object.
172 */
173 void DoDispose() override;
174
175 /**
176 * \brief Last error number.
177 */
179
180 /**
181 * \brief Node.
182 */
184
185 /**
186 * \brief Source address.
187 */
189
190 /**
191 * \brief Destination address.
192 */
194
195 /**
196 * \brief Protocol.
197 */
198 uint16_t m_protocol;
199
200 /**
201 * \brief Packet waiting to be processed.
202 */
203 std::list<Data> m_data;
204
205 /**
206 * \brief Flag to shutdown send capability.
207 */
209
210 /**
211 * \brief Flag to shutdown receive capability.
212 */
214
215 /**
216 * \brief Struct to hold the ICMPv6 filter
217 */
219 {
220 uint32_t icmpv6Filt[8]; //!< ICMPv6 filter specification
221 };
222
223 /**
224 * \brief ICMPv6 filter.
225 */
227};
228
229} /* namespace ns3 */
230
231#endif /* IPV6_RAW_SOCKET_IMPL_H */
a polymophic address class
Definition address.h:90
Describes an IPv6 address.
Packet header for IPv6.
Definition ipv6-header.h:24
bool Icmpv6FilterWillBlock(uint8_t type)
Ask the filter about the status of one ICMPv6 type.
Socket::SocketErrno m_err
Last error number.
void SetProtocol(uint16_t protocol)
Set protocol field.
void Icmpv6FilterSetBlockAll()
Set the filter to block all the ICMPv6 types.
int Listen() override
Listen for incoming connections.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
void Icmpv6FilterSetBlock(uint8_t type)
Set the filter to block one ICMPv6 type.
Ipv6Address m_src
Source address.
Icmpv6Filter m_icmpFilter
ICMPv6 filter.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
int Close() override
Close a socket.
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
Socket::SocketType GetSocketType() const override
Get socket type (NS3_SOCK_RAW)
static TypeId GetTypeId()
Get the type ID of this class.
bool m_shutdownRecv
Flag to shutdown receive capability.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
int GetSockName(Address &address) const override
Get socket address.
bool m_shutdownSend
Flag to shutdown send capability.
bool ForwardUp(Ptr< const Packet > p, Ipv6Header hdr, Ptr< NetDevice > device)
Forward up to receive method.
int Connect(const Address &address) override
Initiate a connection to a remote host.
bool Icmpv6FilterWillPass(uint8_t type)
Ask the filter about the status of one ICMPv6 type.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
Socket::SocketErrno GetErrno() const override
Get last error number.
Ipv6Address m_dst
Destination address.
void DoDispose() override
Dispose object.
std::list< Data > m_data
Packet waiting to be processed.
void Icmpv6FilterSetPass(uint8_t type)
Set the filter to pass one ICMPv6 type.
void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses) override
Joins a IPv6 multicast group.
void Icmpv6FilterSetPassAll()
Clean the ICMPv6 filter structure.
Smart pointer class similar to boost::intrusive_ptr.
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition socket.cc:163
SocketType
Enumeration of the possible socket types.
Definition socket.h:96
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition socket.h:132
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IPv6 raw data and additional information.
Ptr< Packet > packet
Packet data.
uint16_t fromProtocol
Protocol used.
Ipv6Address fromIp
Source address.
Struct to hold the ICMPv6 filter.
uint32_t icmpv6Filt[8]
ICMPv6 filter specification.