A Discrete-Event Network Simulator
API
lr-wpan-ed-scan.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Tokushima University, Japan.
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: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
18 */
19
20/* [00:01] [00:02] [00:03]
21 * PAN 5 Coordinator End Device PAN 7 Coordinator
22 * N0 (dev0) ----------------N1 (dev1) ------------------------------ N2 (dev2)
23 * Channel 12 ED Scan Channels 11-14 Channel 14
24 *
25 * |--------10 m----------------|----------30 m -----------------------|
26 *
27 * This example demonstrate the usage of the MAC ED Scan primitive as
28 * described by IEEE 802.15.4-2011.
29 *
30 * At the beginning of the simulation, PAN coordinators N0 (Channel 12) and N2 (Channel 14)
31 * start transmitting beacon frames on their respective channels. At the same time,
32 * end device N1 will scan through channels (11,12,13 and 14) looking for energy.
33 * i.e. multiple energy scans on each channel (PLME-ED calls). The results of the Max energy
34 * read registered for each channel is shown after the last channel scan is finished.
35 *
36 * The radio uses the default Sensibility and Rx Power provided by the
37 * LogDistancePropagationLossModel. The simulation might take a few seconds to complete.
38 *
39 * ED range: 0 - 255
40 */
41
42#include <ns3/constant-position-mobility-model.h>
43#include <ns3/core-module.h>
44#include <ns3/log.h>
45#include <ns3/lr-wpan-module.h>
46#include <ns3/packet.h>
47#include <ns3/propagation-delay-model.h>
48#include <ns3/propagation-loss-model.h>
49#include <ns3/simulator.h>
50#include <ns3/single-model-spectrum-channel.h>
51
52#include <iostream>
53
54using namespace ns3;
55
56static void
58{
59 if (params.m_status == MLMESCAN_SUCCESS && params.m_scanType == MLMESCAN_ED)
60 {
61 std::cout << Simulator::Now().As(Time::S) << "| Scan status SUCCESSFUL\n";
62 std::cout << "Results for Energy Scan:"
63 << "\nPage: " << params.m_chPage << "\n";
64 for (std::size_t i = 0; i < params.m_energyDetList.size(); i++)
65 {
66 std::cout << "Channel " << static_cast<uint32_t>(i + 11) << ": "
67 << +params.m_energyDetList[i] << "\n";
68 }
69 }
70}
71
72int
73main(int argc, char* argv[])
74{
76
77 // Create 2 PAN coordinator nodes, and 1 end device
78 Ptr<Node> n0 = CreateObject<Node>();
79 Ptr<Node> n1 = CreateObject<Node>();
80 Ptr<Node> n2 = CreateObject<Node>();
81
82 Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice>();
83 Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice>();
84 Ptr<LrWpanNetDevice> dev2 = CreateObject<LrWpanNetDevice>();
85
86 dev0->SetAddress(Mac16Address("00:01"));
87 dev1->SetAddress(Mac16Address("00:02"));
88 dev2->SetAddress(Mac16Address("00:03"));
89
90 // Configure Spectrum channel
91 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
93 CreateObject<LogDistancePropagationLossModel>();
95 CreateObject<ConstantSpeedPropagationDelayModel>();
96 channel->AddPropagationLossModel(propModel);
97 channel->SetPropagationDelayModel(delayModel);
98
99 dev0->SetChannel(channel);
100 dev1->SetChannel(channel);
101 dev2->SetChannel(channel);
102
103 n0->AddDevice(dev0);
104 n1->AddDevice(dev1);
105 n2->AddDevice(dev2);
106
107 // MAC layer Callbacks hooks
110 dev1->GetMac()->SetMlmeScanConfirmCallback(scb);
111
112 Ptr<ConstantPositionMobilityModel> PanCoordinatorN0Mobility =
113 CreateObject<ConstantPositionMobilityModel>();
114 PanCoordinatorN0Mobility->SetPosition(Vector(0, 0, 0));
115 dev0->GetPhy()->SetMobility(PanCoordinatorN0Mobility);
116
117 Ptr<ConstantPositionMobilityModel> endDeviceN1Mobility =
118 CreateObject<ConstantPositionMobilityModel>();
119 endDeviceN1Mobility->SetPosition(Vector(10, 0, 0));
120 dev1->GetPhy()->SetMobility(endDeviceN1Mobility);
121
122 Ptr<ConstantPositionMobilityModel> PanCoordinatorN2Mobility =
123 CreateObject<ConstantPositionMobilityModel>();
124 PanCoordinatorN2Mobility->SetPosition(Vector(40, 0, 0));
125 dev2->GetPhy()->SetMobility(PanCoordinatorN2Mobility);
126
127 // PAN coordinator N0 starts transmit beacons on channel 12
129 params.m_panCoor = true;
130 params.m_PanId = 5;
131 params.m_bcnOrd = 3;
132 params.m_sfrmOrd = 3;
133 params.m_logCh = 12;
134 Simulator::ScheduleWithContext(1,
135 Seconds(2.0),
136 &LrWpanMac::MlmeStartRequest,
137 dev0->GetMac(),
138 params);
139
140 // PAN coordinator N2 transmit beacons on channel 14
142 params2.m_panCoor = true;
143 params2.m_PanId = 7;
144 params2.m_bcnOrd = 3;
145 params2.m_sfrmOrd = 3;
146 params2.m_logCh = 14;
147 Simulator::ScheduleWithContext(1,
148 Seconds(2.0),
149 &LrWpanMac::MlmeStartRequest,
150 dev2->GetMac(),
151 params2);
152
153 // Device 1 initiate channels scan on channels 11, 12, 13, and 14 looking for energy
154 // Scan Channels represented by bits 0-26 (27 LSB)
155 // ch 14 ch 11
156 // | |
157 // 0x7800 = 0000000000000000111100000000000
158 // scanDuration per channel = aBaseSuperframeDuration * (2^14+1) = 251.65 secs
159 MlmeScanRequestParams scanParams;
160 scanParams.m_chPage = 0;
161 scanParams.m_scanChannels = 0x7800;
162 scanParams.m_scanDuration = 14;
163 scanParams.m_scanType = MLMESCAN_ED;
164 Simulator::ScheduleWithContext(1,
165 Seconds(2.0),
166 &LrWpanMac::MlmeScanRequest,
167 dev1->GetMac(),
168 scanParams);
169
170 Simulator::Stop(Seconds(2000));
171 Simulator::Run();
172
173 Simulator::Destroy();
174 return 0;
175}
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
Ptr< LrWpanMac > GetMac() const
Get the MAC used by this NetDevice.
Ptr< LrWpanPhy > GetPhy() const
Get the PHY used by this NetDevice.
void SetAddress(Address address) override
This method indirects to LrWpanMac::SetShortAddress ()
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
@ MLMESCAN_ED
Definition: lr-wpan-mac.h:181
@ MLMESCAN_SUCCESS
Definition: lr-wpan-mac.h:234
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
static void ScanConfirm(MlmeScanConfirmParams params)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
LogLevel
Logging severity classes and levels.
Definition: log.h:94
@ 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
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:380
channel
Definition: third.py:81
MLME-SCAN.confirm params.
Definition: lr-wpan-mac.h:483
LrWpanMlmeScanType m_scanType
Indicates the type of scan performed (ED,ACTIVE,PASSIVE,ORPHAN).
Definition: lr-wpan-mac.h:486
uint32_t m_chPage
The channel page on which the scan was performed.
Definition: lr-wpan-mac.h:488
LrWpanMlmeScanConfirmStatus m_status
The status of the scan request.
Definition: lr-wpan-mac.h:484
std::vector< uint8_t > m_energyDetList
A list of energy measurements, one for each channel searched during ED scan (Not valid for Active,...
Definition: lr-wpan-mac.h:492
MLME-SCAN.request params.
Definition: lr-wpan-mac.h:468
uint32_t m_scanChannels
The channel numbers to be scanned.
Definition: lr-wpan-mac.h:471
uint32_t m_chPage
The channel page on which to perform scan.
Definition: lr-wpan-mac.h:474
uint8_t m_scanDuration
A value used to calculate the length of time to spend scanning [aBaseSuperframeDuration * (2^m_scanDu...
Definition: lr-wpan-mac.h:472
LrWpanMlmeScanType m_scanType
Indicates the type of scan performed as described in IEEE 802.15.4-2011 (5.1.2.1).
Definition: lr-wpan-mac.h:469
MLME-START.request params.
Definition: lr-wpan-mac.h:418
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
Definition: lr-wpan-mac.h:420
bool m_panCoor
On true this device will become coordinator.
Definition: lr-wpan-mac.h:429
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
Definition: lr-wpan-mac.h:426
uint16_t m_PanId
Pan Identifier used by the device.
Definition: lr-wpan-mac.h:419
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.
Definition: lr-wpan-mac.h:428