A Discrete-Event Network Simulator
API
example-ping-lr-wpan-beacon.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2020 Ritsumeikan University, Shiga, Japan
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: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
19 */
20
21
22#include <fstream>
23#include "ns3/core-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/internet-apps-module.h"
26#include "ns3/mobility-module.h"
27#include "ns3/spectrum-module.h"
28#include "ns3/propagation-module.h"
29#include "ns3/sixlowpan-module.h"
30#include "ns3/lr-wpan-module.h"
31
32using namespace ns3;
33
34
36{
37 // In the case of transmissions with the Ack flag activated, the transaction is only
38 // successful if the Ack was received.
40 {
41 NS_LOG_UNCOND ("**********" << Simulator::Now ().As (Time::S) << " | Transmission successfully sent");
42 }
43}
44
45
46int main (int argc, char** argv)
47{
48
49 bool verbose = false;
50
51 CommandLine cmd (__FILE__);
52 cmd.AddValue ("verbose", "turn on log components", verbose);
53 cmd.Parse (argc, argv);
54
55 if (verbose)
56 {
60 LogComponentEnable ("LrWpanCsmaCa", LOG_LEVEL_INFO);
61 LogComponentEnable ("LrWpanHelper", LOG_LEVEL_ALL);
62 LogComponentEnable ("Ping6Application", LOG_LEVEL_INFO);
63 }
64
65
67 nodes.Create (2);
68
70 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
71 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
72 "MinX", DoubleValue (0.0),
73 "MinY", DoubleValue (0.0),
74 "DeltaX", DoubleValue (20),
75 "DeltaY", DoubleValue (20),
76 "GridWidth", UintegerValue (3),
77 "LayoutType", StringValue ("RowFirst"));
78 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
79 mobility.Install (nodes);
80
81 LrWpanHelper lrWpanHelper;
82 // Add and install the LrWpanNetDevice for each node
83 NetDeviceContainer lrwpanDevices = lrWpanHelper.Install (nodes);
84
85 Ptr<LrWpanNetDevice> dev1 = lrwpanDevices.Get (0)->GetObject<LrWpanNetDevice> ();
86 Ptr<LrWpanNetDevice> dev2 = lrwpanDevices.Get (1)->GetObject<LrWpanNetDevice> ();
87
90 dev1->GetMac ()->SetMcpsDataConfirmCallback (cb1);
91 dev2->GetMac ()->SetMcpsDataConfirmCallback (cb1);
92
93
94 // Fake PAN association, coordinator assignment, short address assignment and initialization
95 // of beacon-enabled mode in 802.15.4-2011.
96 // This is needed because the lr-wpan module does not provide (yet)
97 // a full PAN association procedure.
98
99 // AssociateToBeaconPan (devices, PAN ID, Coordinator Address, Beacon Order, Superframe Order)
100
101 // Must be careful not setting the beacon order (BO) and the superframe order (SO) too far apart
102 // or the ping reply (ICMPV6 echo reply) can time out during the inactive period of the superframe.
103 // A full time table of the BO/SO time equivalence can be found at the end of this document.
104 // The current configuration is BO = 14, SO = 13 :
105
106 // Contention Access Period (CAP) Inactive
107 // (125.82912 secs) (125.82088)
108 // |---------------------------------------------|-------------------------------------------|
109 // Beacon Beacon
110 // Beacon Interval = 251.65 secs
111 // |-----------------------------------------------------------------------------------------|
112
113 lrWpanHelper.AssociateToBeaconPan (lrwpanDevices, 0, Mac16Address ("00:01"), 14,13);
114
115
116 InternetStackHelper internetv6;
117 internetv6.Install (nodes);
118
119 SixLowPanHelper sixlowpan;
120 NetDeviceContainer devices = sixlowpan.Install (lrwpanDevices);
121
123 ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
124 Ipv6InterfaceContainer deviceInterfaces;
125 deviceInterfaces = ipv6.Assign (devices);
126
127
128 // Send ping packets after the 2nd second of the simulation during the
129 // first 8 seconds of the CAP in the incoming superframe
130
131 uint32_t packetSize = 10;
132 uint32_t maxPacketCount = 5;
133 Time interPacketInterval = Seconds (1);
134 Ping6Helper ping6;
135
136 ping6.SetLocal (deviceInterfaces.GetAddress (0, 1));
137 ping6.SetRemote (deviceInterfaces.GetAddress (1, 1));
138
139 ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
140 ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
141 ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
142 ApplicationContainer apps = ping6.Install (nodes.Get (0));
143
144 apps.Start (Seconds (2.0));
145 apps.Stop (Seconds (10.0));
146
147 AsciiTraceHelper ascii;
148 lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream ("Ping-6LoW-lr-wpan-beacon.tr"));
149 lrWpanHelper.EnablePcapAll (std::string ("Ping-6LoW-lr-wpan-beacon"), true);
150
151
152 Simulator::Stop (Seconds (600));
153
154 Simulator::Run ();
155 Simulator::Destroy ();
156
157}
158
159// BO/SO values to time equivalence
160// These times are only valid for a 250kbps O-QPSK modulation,
161// times differ with other modulation configurations.
162
163// +------------------------+
164// | BO/SO | Time (secs) |
165// +------------------------+
166// | 0 | 0.01536 secs |
167// | 1 | 0.03072 secs |
168// | 2 | 0.06144 secs |
169// | 3 | 0.12288 secs |
170// | 4 | 0.24576 secs |
171// | 5 | 0.49152 secs |
172// | 6 | 0.98304 secs |
173// | 7 | 1.96608 secs |
174// | 8 | 3.93216 secs |
175// | 9 | 7.86432 secs |
176// | 10 | 15.72864 secs |
177// | 11 | 31.45728 secs |
178// | 12 | 62.91456 secs |
179// | 13 | 125.82912 secs |
180// | 14 | 251.65 secs |
181// +------------------------+
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.
Parse command-line arguments.
Definition: command-line.h:229
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.
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 AssociateToBeaconPan(NetDeviceContainer c, uint16_t panId, Mac16Address coor, uint8_t bcnOrd, uint8_t sfrmOrd)
Associate the nodes to the same PAN and initiate beacon enabled mode.
NetDeviceContainer Install(NodeContainer c)
Install a LrWpanNetDevice and the associated structures (e.g., channel) in the nodes.
Network layer to device interface.
Ptr< LrWpanMac > GetMac(void) const
Get the MAC used by this NetDevice.
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
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.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
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
static void dataSentMacConfirm(McpsDataConfirmParams params)
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
@ IEEE_802_15_4_SUCCESS
Definition: lr-wpan-mac.h:166
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
devices
Definition: first.py:39
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition: log.h:119
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:385
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
cmd
Definition: second.py:35
mobility
Definition: third.py:107
bool verbose
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:261
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:263
static const uint32_t packetSize
Pcket size generated at the AP.