A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
radvd-one-prefix.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: David Gross <gdavid.devel@gmail.com>
7 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
8 */
9
10// Network topology
11// //
12// // n0 R n1
13// // | _ |
14// // ====|_|====
15// // router
16// // - R sends RA to n0's subnet (2001:1::/64);
17// // - R sends RA to n1's subnet (2001:2::/64);
18// // - n0 ping n1.
19// //
20// // - Tracing of queues and packet receptions to file "radvd.tr"
21
22#include "ns3/core-module.h"
23#include "ns3/csma-module.h"
24#include "ns3/internet-apps-module.h"
25#include "ns3/internet-module.h"
26#include "ns3/radvd-interface.h"
27#include "ns3/radvd-prefix.h"
28#include "ns3/radvd.h"
29
30#include <fstream>
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("RadvdExample");
35
36int
37main(int argc, char** argv)
38{
39 bool verbose = false;
40
41 CommandLine cmd(__FILE__);
42 cmd.AddValue("verbose", "turn on log components", verbose);
43 cmd.Parse(argc, argv);
44
45 if (verbose)
46 {
47 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
48 LogComponentEnable("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
49 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
50 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
51 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
52 LogComponentEnable("RadvdApplication", LOG_LEVEL_ALL);
54 }
55
56 NS_LOG_INFO("Create nodes.");
60
61 NodeContainer net1(n0, r);
62 NodeContainer net2(r, n1);
63 NodeContainer all(n0, r, n1);
64
65 NS_LOG_INFO("Create IPv6 Internet Stack");
66 InternetStackHelper internetv6;
67 internetv6.Install(all);
68
69 NS_LOG_INFO("Create channels.");
71 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
72 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
73 NetDeviceContainer d1 = csma.Install(net1); /* n0 - R */
74 NetDeviceContainer d2 = csma.Install(net2); /* R - n1 */
75
76 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
78
79 /* first subnet */
80 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
82 tmp.Add(d1.Get(0)); /* n0 */
83 Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress(tmp); /* n0 interface */
84
86 tmp2.Add(d1.Get(1)); /* R */
88 ipv6.Assign(tmp2); /* R interface to the first subnet is just statically assigned */
89 iicr1.SetForwarding(0, true);
90 iic1.Add(iicr1);
91
92 /* second subnet R - n1 */
93 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
95 tmp3.Add(d2.Get(0)); /* R */
96 Ipv6InterfaceContainer iicr2 = ipv6.Assign(tmp3); /* R interface */
97 iicr2.SetForwarding(0, true);
98
100 tmp4.Add(d2.Get(1)); /* n1 */
102 iic2.Add(iicr2);
103
104 /* radvd configuration */
105 RadvdHelper radvdHelper;
106
107 /* R interface (n0 - R) */
108 /* n0 will receive unsolicited (periodic) RA */
109 radvdHelper.AddAnnouncedPrefix(iic1.GetInterfaceIndex(1), Ipv6Address("2001:1::0"), 64);
110
111 /* R interface (R - n1) */
112 /* n1 will have to use RS, as RA are not sent automatically */
113 radvdHelper.AddAnnouncedPrefix(iic2.GetInterfaceIndex(1), Ipv6Address("2001:2::0"), 64);
114 radvdHelper.GetRadvdInterface(iic2.GetInterfaceIndex(1))->SetSendAdvert(false);
115
116 ApplicationContainer radvdApps = radvdHelper.Install(r);
117 radvdApps.Start(Seconds(1.0));
118 radvdApps.Stop(Seconds(10.0));
119
120 /* Create a Ping application to send ICMPv6 echo request from n0 to n1 via R */
121 uint32_t packetSize = 1024;
122 uint32_t maxPacketCount = 5;
123 PingHelper ping(
124 Ipv6Address("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
125
126 ping.SetAttribute("Count", UintegerValue(maxPacketCount));
127 ping.SetAttribute("Size", UintegerValue(packetSize));
128 ApplicationContainer apps = ping.Install(net1.Get(0));
129 apps.Start(Seconds(2.0));
130 apps.Stop(Seconds(7.0));
131
132 AsciiTraceHelper ascii;
133 csma.EnableAsciiAll(ascii.CreateFileStream("radvd.tr"));
134 csma.EnablePcapAll(std::string("radvd"), true);
135
136 NS_LOG_INFO("Run Simulation.");
139 NS_LOG_INFO("Done.");
140
141 return 0;
142}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
uint32_t GetInterfaceIndex(uint32_t i) const
Get the interface index for the specified node index.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
Describes an IPv6 prefix.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
Create a ping application and associate it to a node.
Definition ping-helper.h:31
Smart pointer class similar to boost::intrusive_ptr.
Radvd application helper.
void AddAnnouncedPrefix(uint32_t interface, const Ipv6Address &prefix, uint32_t prefixLength)
Add a new prefix to be announced through an interface.
Ptr< RadvdInterface > GetRadvdInterface(uint32_t interface)
Get the low-level RadvdInterface specification for an interface.
void SetSendAdvert(bool sendAdvert)
Set send advert flag.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.