A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
radvd.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 Strasbourg University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: David Gross <gdavid.devel@gmail.com>
19  * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
20  */
21 
22 // Network topology
23 // //
24 // // n0 R n1
25 // // | _ |
26 // // ====|_|====
27 // // router
28 // // - R sends RA to n0's subnet (2001:1::/64);
29 // // - R sends RA to n1's subnet (2001:2::/64);
30 // // - n0 ping6 n1.
31 // //
32 // // - Tracing of queues and packet receptions to file "radvd.tr"
33 
34 #include <fstream>
35 #include "ns3/core-module.h"
36 #include "ns3/internet-module.h"
37 #include "ns3/csma-module.h"
38 #include "ns3/applications-module.h"
39 
40 #include "ns3/radvd.h"
41 #include "ns3/radvd-interface.h"
42 #include "ns3/radvd-prefix.h"
43 
44 using namespace ns3;
45 
46 NS_LOG_COMPONENT_DEFINE ("RadvdExample");
47 
48 int main (int argc, char** argv)
49 {
50  bool verbose = false;
51 
52  CommandLine cmd;
53  cmd.AddValue ("verbose", "turn on log components", verbose);
54  cmd.Parse (argc, argv);
55 
56  if (verbose)
57  {
58  LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
59  LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
60  LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
61  LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
62  LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
63  LogComponentEnable ("RadvdApplication", LOG_LEVEL_ALL);
64  LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
65  }
66 
67  NS_LOG_INFO ("Create nodes.");
68  Ptr<Node> n0 = CreateObject<Node> ();
69  Ptr<Node> r = CreateObject<Node> ();
70  Ptr<Node> n1 = CreateObject<Node> ();
71 
72  NodeContainer net1 (n0, r);
73  NodeContainer net2 (r, n1);
74  NodeContainer all (n0, r, n1);
75 
76  NS_LOG_INFO ("Create IPv6 Internet Stack");
77  InternetStackHelper internetv6;
78  internetv6.Install (all);
79 
80  NS_LOG_INFO ("Create channels.");
81  CsmaHelper csma;
82  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
83  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
84  NetDeviceContainer d1 = csma.Install (net1); /* n0 - R */
85  NetDeviceContainer d2 = csma.Install (net2); /* R - n1 */
86 
87  NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
88  Ipv6AddressHelper ipv6;
89 
90  /* first subnet */
91  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
93  tmp.Add (d1.Get (0)); /* n0 */
94  Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (tmp); /* n0 interface */
95 
96  NetDeviceContainer tmp2;
97  tmp2.Add (d1.Get (1)); /* R */
98  Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
99  iicr1.SetForwarding (0, true);
100  iicr1.SetDefaultRouteInAllNodes (0);
101  iic1.Add (iicr1);
102 
103  /* second subnet R - n1 */
104  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
105  NetDeviceContainer tmp3;
106  tmp3.Add (d2.Get (0)); /* R */
107  Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
108  iicr2.SetForwarding (0, true);
109  iicr2.SetDefaultRouteInAllNodes (0);
110 
111  NetDeviceContainer tmp4;
112  tmp4.Add (d2.Get (1)); /* n1 */
113  Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (tmp4);
114  iic2.Add (iicr2);
115 
116  /* radvd configuration */
117  RadvdHelper radvdHelper;
118  /* R interface (n0 - R) */
119  radvdHelper.AddAnnouncedPrefix(iic1.GetInterfaceIndex (1), Ipv6Address("2001:1::0"), 64);
120  /* R interface (R - n1) */
121  radvdHelper.AddAnnouncedPrefix(iic2.GetInterfaceIndex (1), Ipv6Address("2001:2::0"), 64);
122 
123  ApplicationContainer radvdApps = radvdHelper.Install (r);
124  radvdApps.Start (Seconds (1.0));
125  radvdApps.Stop (Seconds (10.0));
126 
127  /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
128  uint32_t packetSize = 1024;
129  uint32_t maxPacketCount = 5;
130  Time interPacketInterval = Seconds (1.);
131  Ping6Helper ping6;
132 
133  /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
134  ping6.SetRemote (Ipv6Address ("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
135  ping6.SetIfIndex (iic1.GetInterfaceIndex (0));
136 
137  ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
138  ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
139  ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
140  ApplicationContainer apps = ping6.Install (net1.Get (0));
141  apps.Start (Seconds (2.0));
142  apps.Stop (Seconds (7.0));
143 
144  AsciiTraceHelper ascii;
145  csma.EnableAsciiAll (ascii.CreateFileStream ("radvd.tr"));
146  csma.EnablePcapAll (std::string ("radvd"), true);
147 
148  NS_LOG_INFO ("Run Simulation.");
149  Simulator::Run ();
151  NS_LOG_INFO ("Done.");
152 }
153 
holds a vector of ns3::Application pointers.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Manage ASCII trace files for device models.
Definition: trace-helper.h:128
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:69
Keep track of a set of IPv6 interfaces.
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:50
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:215
#define NS_LOG_INFO(msg)
Definition: log.h:298
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:45
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. ...
ApplicationContainer Install(Ptr< Node > node)
Install the application in a Node.
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.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
hold objects of type ns3::Time
Definition: nstime.h:961
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
Definition: uinteger.h:46
uint32_t GetInterfaceIndex(uint32_t i) const
Get the interface index for the specified node index.
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
int main(int argc, char **argv)
Definition: radvd.cc:48
Parse command-line arguments.
Definition: command-line.h:152
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
keep track of a set of node pointers.
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
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:40
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
Helper class to auto-assign global IPv6 unicast addresses.
Radvd application helper.
Definition: radvd-helper.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:46
void SetIfIndex(uint32_t ifIndex)
Set the out interface index.
Definition: ping6-helper.cc:67
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
hold objects of type ns3::DataRate
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
Describes an IPv6 prefix.
Definition: ipv6-address.h:387
void Parse(int argc, char *argv[])
Parse the program arguments.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Ping6 application helper.
Definition: ping6-helper.h:39
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311
bool verbose