A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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;
55using namespace ns3::lrwpan;
56
57static void
59{
60 if (params.m_status == MacStatus::SUCCESS && params.m_scanType == MLMESCAN_ED)
61 {
62 std::cout << Simulator::Now().As(Time::S) << "| Scan status SUCCESSFUL\n";
63 std::cout << "Results for Energy Scan:"
64 << "\nPage: " << params.m_chPage << "\n";
65 for (std::size_t i = 0; i < params.m_energyDetList.size(); i++)
66 {
67 std::cout << "Channel " << static_cast<uint32_t>(i + 11) << ": "
68 << +params.m_energyDetList[i] << "\n";
69 }
70 }
71}
72
73int
74main(int argc, char* argv[])
75{
77
78 // Create 2 PAN coordinator nodes, and 1 end device
79 Ptr<Node> n0 = CreateObject<Node>();
80 Ptr<Node> n1 = CreateObject<Node>();
81 Ptr<Node> n2 = CreateObject<Node>();
82
83 Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice>();
84 Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice>();
85 Ptr<LrWpanNetDevice> dev2 = CreateObject<LrWpanNetDevice>();
86
87 dev0->SetAddress(Mac16Address("00:01"));
88 dev1->SetAddress(Mac16Address("00:02"));
89 dev2->SetAddress(Mac16Address("00:03"));
90
91 // Configure Spectrum channel
92 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
94 CreateObject<LogDistancePropagationLossModel>();
96 CreateObject<ConstantSpeedPropagationDelayModel>();
97 channel->AddPropagationLossModel(propModel);
98 channel->SetPropagationDelayModel(delayModel);
99
100 dev0->SetChannel(channel);
101 dev1->SetChannel(channel);
102 dev2->SetChannel(channel);
103
104 n0->AddDevice(dev0);
105 n1->AddDevice(dev1);
106 n2->AddDevice(dev2);
107
108 // MAC layer Callbacks hooks
111 dev1->GetMac()->SetMlmeScanConfirmCallback(scb);
112
113 Ptr<ConstantPositionMobilityModel> PanCoordinatorN0Mobility =
114 CreateObject<ConstantPositionMobilityModel>();
115 PanCoordinatorN0Mobility->SetPosition(Vector(0, 0, 0));
116 dev0->GetPhy()->SetMobility(PanCoordinatorN0Mobility);
117
118 Ptr<ConstantPositionMobilityModel> endDeviceN1Mobility =
119 CreateObject<ConstantPositionMobilityModel>();
120 endDeviceN1Mobility->SetPosition(Vector(10, 0, 0));
121 dev1->GetPhy()->SetMobility(endDeviceN1Mobility);
122
123 Ptr<ConstantPositionMobilityModel> PanCoordinatorN2Mobility =
124 CreateObject<ConstantPositionMobilityModel>();
125 PanCoordinatorN2Mobility->SetPosition(Vector(40, 0, 0));
126 dev2->GetPhy()->SetMobility(PanCoordinatorN2Mobility);
127
128 // PAN coordinator N0 starts transmit beacons on channel 12
130 params.m_panCoor = true;
131 params.m_PanId = 5;
132 params.m_bcnOrd = 3;
133 params.m_sfrmOrd = 3;
134 params.m_logCh = 12;
136 Seconds(2.0),
138 dev0->GetMac(),
139 params);
140
141 // PAN coordinator N2 transmit beacons on channel 14
143 params2.m_panCoor = true;
144 params2.m_PanId = 7;
145 params2.m_bcnOrd = 3;
146 params2.m_sfrmOrd = 3;
147 params2.m_logCh = 14;
149 Seconds(2.0),
151 dev2->GetMac(),
152 params2);
153
154 // Device 1 initiate channels scan on channels 11, 12, 13, and 14 looking for energy
155 // Scan Channels represented by bits 0-26 (27 LSB)
156 // ch 14 ch 11
157 // | |
158 // 0x7800 = 0000000000000000111100000000000
159 // scanDuration per channel = aBaseSuperframeDuration * (2^14+1) = 251.65 secs
160 MlmeScanRequestParams scanParams;
161 scanParams.m_chPage = 0;
162 scanParams.m_scanChannels = 0x7800;
163 scanParams.m_scanDuration = 14;
164 scanParams.m_scanType = MLMESCAN_ED;
166 Seconds(2.0),
168 dev1->GetMac(),
169 scanParams);
170
173
175 return 0;
176}
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:588
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
@ S
second
Definition: nstime.h:116
void MlmeStartRequest(MlmeStartRequestParams params) override
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
Definition: lr-wpan-mac.cc:586
void MlmeScanRequest(MlmeScanRequestParams params) override
IEEE 802.15.4-2011, section 6.2.10.1 MLME-SCAN.request Request primitive used to initiate a channel s...
Definition: lr-wpan-mac.cc:625
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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:706
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(LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:320
ns channel
Definition: third.py:88
FtrParams params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
MlmeScanType m_scanType
Indicates the type of scan performed as described in IEEE 802.15.4-2011 (5.1.2.1).
uint32_t m_scanChannels
The channel numbers to be scanned.
uint8_t m_scanDuration
The factor (0-14) used to calculate the length of time to spend scanning.
uint32_t m_chPage
The channel page on which to perform scan.
MLME-START.request params.
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
bool m_panCoor
On true this device will become coordinator.
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.
uint16_t m_PanId
Pan Identifier used by the device.