A Discrete-Event Network Simulator
API
example-ping-lr-wpan-mesh-under.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2019 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19 */
20
21#include <fstream>
22#include "ns3/core-module.h"
23#include "ns3/internet-module.h"
24#include "ns3/internet-apps-module.h"
25#include "ns3/mobility-module.h"
26#include "ns3/spectrum-module.h"
27#include "ns3/propagation-module.h"
28#include "ns3/sixlowpan-module.h"
29#include "ns3/lr-wpan-module.h"
30#include "ns3/csma-module.h"
31
32using namespace ns3;
33
34int main (int argc, char** argv)
35{
36 bool verbose = false;
37
38 Packet::EnablePrinting ();
39
40 CommandLine cmd (__FILE__);
41 cmd.AddValue ("verbose", "turn on log components", verbose);
42 cmd.Parse (argc, argv);
43
44 if (verbose)
45 {
46 LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
47 LogComponentEnable ("LrWpanMac", LOG_LEVEL_ALL);
48 LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL);
49 LogComponentEnable ("LrWpanNetDevice", LOG_LEVEL_ALL);
50 LogComponentEnable ("SixLowPanNetDevice", LOG_LEVEL_ALL);
51 }
52
53 uint32_t nWsnNodes = 4;
54 NodeContainer wsnNodes;
55 wsnNodes.Create (nWsnNodes);
56
57 NodeContainer wiredNodes;
58 wiredNodes.Create (1);
59 wiredNodes.Add (wsnNodes.Get (0));
60
62 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
63 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
64 "MinX", DoubleValue (0.0),
65 "MinY", DoubleValue (0.0),
66 "DeltaX", DoubleValue (80),
67 "DeltaY", DoubleValue (80),
68 "GridWidth", UintegerValue (10),
69 "LayoutType", StringValue ("RowFirst"));
70 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
71 mobility.Install (wsnNodes);
72
73 LrWpanHelper lrWpanHelper;
74 // Add and install the LrWpanNetDevice for each node
75 NetDeviceContainer lrwpanDevices = lrWpanHelper.Install (wsnNodes);
76
77 // Fake PAN association and short address assignment.
78 // This is needed because the lr-wpan module does not provide (yet)
79 // a full PAN association procedure.
80 lrWpanHelper.AssociateToPan (lrwpanDevices, 0);
81
82 InternetStackHelper internetv6;
83 internetv6.Install (wsnNodes);
84 internetv6.Install (wiredNodes.Get (0));
85
86 SixLowPanHelper sixLowPanHelper;
87 NetDeviceContainer sixLowPanDevices = sixLowPanHelper.Install (lrwpanDevices);
88
89 CsmaHelper csmaHelper;
90 NetDeviceContainer csmaDevices = csmaHelper.Install (wiredNodes);
91
93 ipv6.SetBase (Ipv6Address ("2001:cafe::"), Ipv6Prefix (64));
94 Ipv6InterfaceContainer wiredDeviceInterfaces;
95 wiredDeviceInterfaces = ipv6.Assign (csmaDevices);
96 wiredDeviceInterfaces.SetForwarding (1, true);
97 wiredDeviceInterfaces.SetDefaultRouteInAllNodes (1);
98
99 ipv6.SetBase (Ipv6Address ("2001:f00d::"), Ipv6Prefix (64));
100 Ipv6InterfaceContainer wsnDeviceInterfaces;
101 wsnDeviceInterfaces = ipv6.Assign (sixLowPanDevices);
102 wsnDeviceInterfaces.SetForwarding (0, true);
103 wsnDeviceInterfaces.SetDefaultRouteInAllNodes (0);
104
105 for (uint32_t i = 0; i < sixLowPanDevices.GetN (); i++)
106 {
107 Ptr<NetDevice> dev = sixLowPanDevices.Get (i);
108 dev->SetAttribute ("UseMeshUnder", BooleanValue (true));
109 dev->SetAttribute ("MeshUnderRadius", UintegerValue (10));
110 }
111
112 uint32_t packetSize = 10;
113 uint32_t maxPacketCount = 5;
114 Time interPacketInterval = Seconds (1.);
115 Ping6Helper ping6;
116
117 ping6.SetLocal (wsnDeviceInterfaces.GetAddress (nWsnNodes - 1, 1));
118 ping6.SetRemote (wiredDeviceInterfaces.GetAddress (0, 1));
119
120 ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
121 ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
122 ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
123 ApplicationContainer apps = ping6.Install (wsnNodes.Get (nWsnNodes - 1));
124
125 apps.Start (Seconds (1.0));
126 apps.Stop (Seconds (10.0));
127
128 AsciiTraceHelper ascii;
129 lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream ("Ping-6LoW-lr-wpan-meshunder-lr-wpan.tr"));
130 lrWpanHelper.EnablePcapAll (std::string ("Ping-6LoW-lr-wpan-meshunder-lr-wpan"), true);
131
132 csmaHelper.EnableAsciiAll (ascii.CreateFileStream ("Ping-6LoW-lr-wpan-meshunder-csma.tr"));
133 csmaHelper.EnablePcapAll (std::string ("Ping-6LoW-lr-wpan-meshunder-csma"), true);
134
135 Simulator::Stop (Seconds (10));
136
137 Simulator::Run ();
138 Simulator::Destroy ();
139
140}
141
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.
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...
Manage ASCII trace files for device models.
Definition: trace-helper.h:163
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.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Parse command-line arguments.
Definition: command-line.h:229
build a set of CsmaNetDevice objects
Definition: csma-helper.h:47
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:225
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
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.
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.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
helps to manage and create IEEE 802.15.4 NetDevice objects
void AssociateToPan(NetDeviceContainer c, uint16_t panId)
Associate the nodes to the same PAN.
NetDeviceContainer Install(NodeContainer c)
Install a LrWpanNetDevice and the associated structures (e.g., channel) in the nodes.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in 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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
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 ...
Ping6 application helper.
Definition: ping6-helper.h:39
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:40
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:50
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:45
void SetLocal(Ipv6Address ip)
Set the local IPv6 address.
Definition: ping6-helper.cc:35
Setup a sixlowpan stack to be used as a shim between IPv6 and a generic NetDevice.
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
Hold variables of type string.
Definition: string.h:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold an unsigned integer type.
Definition: uinteger.h:44
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
cmd
Definition: second.py:35
csmaDevices
Definition: second.py:67
mobility
Definition: third.py:107
bool verbose
static const uint32_t packetSize
Pcket size generated at the AP.