A Discrete-Event Network Simulator
API
radvd.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 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: David Gross <gdavid.devel@gmail.com>
18 * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19 */
20
21// Network topology
22// //
23// // n0 R n1
24// // | _ |
25// // ====|_|====
26// // router
27// // - R sends RA to n0's subnet (2001:1::/64);
28// // - R sends RA to n1's subnet (2001:2::/64);
29// // - n0 ping6 n1.
30// //
31// // - Tracing of queues and packet receptions to file "radvd.tr"
32
33#include "ns3/radvd.h"
34
35#include "ns3/core-module.h"
36#include "ns3/csma-module.h"
37#include "ns3/internet-apps-module.h"
38#include "ns3/internet-module.h"
39#include "ns3/radvd-interface.h"
40#include "ns3/radvd-prefix.h"
41
42#include <fstream>
43
44using namespace ns3;
45
46NS_LOG_COMPONENT_DEFINE("RadvdExample");
47
48int
49main(int argc, char** argv)
50{
51 bool verbose = false;
52
53 CommandLine cmd(__FILE__);
54 cmd.AddValue("verbose", "turn on log components", verbose);
55 cmd.Parse(argc, argv);
56
57 if (verbose)
58 {
59 LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
60 LogComponentEnable("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
61 LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
62 LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
63 LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
64 LogComponentEnable("RadvdApplication", LOG_LEVEL_ALL);
65 LogComponentEnable("Ping6Application", LOG_LEVEL_ALL);
66 }
67
68 NS_LOG_INFO("Create nodes.");
69 Ptr<Node> n0 = CreateObject<Node>();
70 Ptr<Node> r = CreateObject<Node>();
71 Ptr<Node> n1 = CreateObject<Node>();
72
73 NodeContainer net1(n0, r);
74 NodeContainer net2(r, n1);
75 NodeContainer all(n0, r, n1);
76
77 NS_LOG_INFO("Create IPv6 Internet Stack");
78 InternetStackHelper internetv6;
79 internetv6.Install(all);
80
81 NS_LOG_INFO("Create channels.");
83 csma.SetChannelAttribute("DataRate", DataRateValue(5000000));
84 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
85 NetDeviceContainer d1 = csma.Install(net1); /* n0 - R */
86 NetDeviceContainer d2 = csma.Install(net2); /* R - n1 */
87
88 NS_LOG_INFO("Create networks and assign IPv6 Addresses.");
90
91 /* first subnet */
92 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
94 tmp.Add(d1.Get(0)); /* n0 */
95 Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress(tmp); /* n0 interface */
96
98 tmp2.Add(d1.Get(1)); /* R */
100 ipv6.Assign(tmp2); /* R interface to the first subnet is just statically assigned */
101 iicr1.SetForwarding(0, true);
102 iic1.Add(iicr1);
103
104 /* second subnet R - n1 */
105 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
107 tmp3.Add(d2.Get(0)); /* R */
108 Ipv6InterfaceContainer iicr2 = ipv6.Assign(tmp3); /* R interface */
109 iicr2.SetForwarding(0, true);
110
112 tmp4.Add(d2.Get(1)); /* n1 */
114 iic2.Add(iicr2);
115
116 /* radvd configuration */
117 RadvdHelper radvdHelper;
118
119 /* R interface (n0 - R) */
120 /* n0 will receive unsolicited (periodic) RA */
121 radvdHelper.AddAnnouncedPrefix(iic1.GetInterfaceIndex(1), Ipv6Address("2001:1::0"), 64);
122
123 /* R interface (R - n1) */
124 /* n1 will have to use RS, as RA are not sent automatically */
125 radvdHelper.AddAnnouncedPrefix(iic2.GetInterfaceIndex(1), Ipv6Address("2001:2::0"), 64);
126 radvdHelper.GetRadvdInterface(iic2.GetInterfaceIndex(1))->SetSendAdvert(false);
127
128 ApplicationContainer radvdApps = radvdHelper.Install(r);
129 radvdApps.Start(Seconds(1.0));
130 radvdApps.Stop(Seconds(10.0));
131
132 /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
133 uint32_t packetSize = 1024;
134 uint32_t maxPacketCount = 5;
135 Time interPacketInterval = Seconds(1.);
136 Ping6Helper ping6;
137
138 /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
139 ping6.SetRemote(
140 Ipv6Address("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
141 ping6.SetIfIndex(iic1.GetInterfaceIndex(0));
142
143 ping6.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
144 ping6.SetAttribute("Interval", TimeValue(interPacketInterval));
145 ping6.SetAttribute("PacketSize", UintegerValue(packetSize));
146 ApplicationContainer apps = ping6.Install(net1.Get(0));
147 apps.Start(Seconds(2.0));
148 apps.Stop(Seconds(7.0));
149
150 AsciiTraceHelper ascii;
151 csma.EnableAsciiAll(ascii.CreateFileStream("radvd.tr"));
152 csma.EnablePcapAll(std::string("radvd"), true);
153
154 NS_LOG_INFO("Run Simulation.");
155 Simulator::Run();
156 Simulator::Destroy();
157 NS_LOG_INFO("Done.");
158
159 return 0;
160}
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Definition: trace-helper.h:173
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.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
AttributeValue implementation for DataRate.
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.
Definition: ipv6-address.h:50
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.
Definition: ipv6-address.h:456
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.
Ping6 application helper.
Definition: ping6-helper.h:38
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:41
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:53
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:47
void SetIfIndex(uint32_t ifIndex)
Set the out interface index.
Definition: ping6-helper.cc:71
Radvd application helper.
Definition: radvd-helper.h:41
void AddAnnouncedPrefix(uint32_t interface, Ipv6Address prefix, uint32_t prefixLength)
Add a new prefix to be announced through an interface.
Definition: radvd-helper.cc:39
ApplicationContainer Install(Ptr< Node > node)
Install the application in a Node.
Ptr< RadvdInterface > GetRadvdInterface(uint32_t interface)
Get the low-level RadvdInterface specification for an interface.
Definition: radvd-helper.cc:97
void SetSendAdvert(bool sendAdvert)
Set send advert flag.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1425
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:358
csma
Definition: second.py:56
cmd
Definition: second.py:33
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.