14#include "ns3/icmpv6-header.h"
15#include "ns3/inet6-socket-address.h"
16#include "ns3/ipv6-address.h"
17#include "ns3/ipv6-header.h"
18#include "ns3/ipv6-interface.h"
19#include "ns3/ipv6-l3-protocol.h"
20#include "ns3/ipv6-packet-info-tag.h"
21#include "ns3/ipv6-raw-socket-factory.h"
24#include "ns3/net-device.h"
25#include "ns3/nstime.h"
26#include "ns3/packet.h"
27#include "ns3/pointer.h"
28#include "ns3/random-variable-stream.h"
29#include "ns3/simulator.h"
30#include "ns3/socket.h"
31#include "ns3/string.h"
32#include "ns3/uinteger.h"
47 .SetGroupName(
"Internet-Apps")
48 .AddConstructor<
Radvd>()
50 "AdvertisementJitter",
51 "Uniform variable to provide jitter between min and max values of AdvInterval",
114 if ((*it)->IsSendAdvert())
194 std::list<Ptr<RadvdPrefix>> prefixes = config->GetPrefixes();
199 raHdr.
SetFlagM(config->IsManagedFlag());
200 raHdr.
SetFlagO(config->IsOtherConfigFlag());
201 raHdr.
SetFlagH(config->IsHomeAgentFlag());
207 if (config->IsSourceLLAddress())
210 Address addr = ipv6->GetNetDevice(config->GetInterface())->GetAddress();
212 p->AddHeader(llaHdr);
215 if (config->GetLinkMtu())
219 p->AddHeader(mtuHdr);
223 for (
auto jt = prefixes.begin(); jt != prefixes.end(); jt++)
227 prefixHdr.
SetPrefix((*jt)->GetNetwork());
232 if ((*jt)->IsOnLinkFlag())
237 if ((*jt)->IsAutonomousFlag())
242 if ((*jt)->IsRouterAddrFlag())
249 p->AddHeader(prefixHdr);
253 m_sendSockets[config->GetInterface()]->GetSockName(sockAddr);
271 p->AddPacketTag(ttl);
279 auto delay =
static_cast<uint64_t
>(
280 m_jitter->GetValue(config->GetMinRtrAdvInterval(), config->GetMaxRtrAdvInterval()) +
282 if (config->IsInitialRtrAdv())
290 NS_LOG_INFO(
"Reschedule in " << delay <<
" milliseconds");
309 while ((packet = socket->RecvFrom(from)))
314 if (!packet->RemovePacketTag(interfaceInfo))
316 NS_ABORT_MSG(
"No incoming interface on RADVD message, aborting.");
321 uint32_t ipInterfaceIndex = ipv6->GetInterfaceForDevice(dev);
328 packet->RemoveHeader(hdr);
330 packet->CopyData(&type,
sizeof(type));
335 packet->RemoveHeader(rsHdr);
336 NS_LOG_INFO(
"Received ICMPv6 Router Solicitation from "
341 if (ipInterfaceIndex == (*it)->GetInterface())
356 bool scheduleSingle =
true;
363 scheduleSingle =
false;
371 static_cast<int64_t
>(
374 scheduleSingle =
false;
a polymophic address class
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
ICMPv6 link-layer address option.
ICMPv6 Router Advertisement header.
void SetLifeTime(uint16_t l)
Set the node Life time (Neighbor Discovery).
void SetFlagH(bool h)
Set the H flag.
void SetRetransmissionTime(uint32_t r)
Set the node Retransmission time (Neighbor Discovery).
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
void SetFlagO(bool o)
Set the O flag.
void SetFlagM(bool m)
Set the M flag.
void SetReachableTime(uint32_t r)
Set the node Reachable time (Neighbor Discovery).
uint32_t GetSerializedSize() const override
Get the serialized size.
ICMPv6 Router Solicitation header.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
Describes an IPv6 address.
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 layer implementation.
This class implements a tag that carries socket ancillary data to the socket interface.
uint32_t GetRecvIf() const
Get the tag's receiving interface.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
Router advertisement daemon.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this Application object.
EventIdMap m_solicitedEventIds
Event ID map for solicited RAs.
Ptr< UniformRandomVariable > m_jitter
Variable to provide jitter in advertisement interval.
void DoDispose() override
Destructor implementation.
void Send(Ptr< RadvdInterface > config, Ipv6Address dst=Ipv6Address::GetAllNodesMulticast(), bool reschedule=false)
Send a packet.
~Radvd() override
Destructor.
Ptr< Socket > m_recvSocket
Raw socket to receive RS.
void HandleRead(Ptr< Socket > socket)
Handle received packet, especially router solicitation.
static const uint32_t MAX_RA_DELAY_TIME
Default value for maximum delay of RA (ms)
static const uint32_t MAX_INITIAL_RTR_ADVERT_INTERVAL
Default value for maximum initial RA advertisements interval (ms)
static const uint32_t MIN_DELAY_BETWEEN_RAS
Default value for minimum delay between RA advertisements (ms)
EventIdMap m_unsolicitedEventIds
Event ID map for unsolicited RAs.
static TypeId GetTypeId()
Get the type ID.
SocketMap m_sendSockets
Raw socket to send RA.
void StopApplication() override
Application specific shutdown code.
void AddConfiguration(Ptr< RadvdInterface > routerInterface)
Add configuration for an interface;.
RadvdInterfaceList m_configurations
List of configuration for interface.
void StartApplication() override
Application specific startup code.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
static Time Now()
Return the current simulation virtual time.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
virtual int ShutdownSend()=0
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Callback< R, Args... > MakeNullCallback()
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...