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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
7 */
8
9/* [00:01] [00:02] [00:03]
10 * PAN 5 Coordinator End Device PAN 7 Coordinator
11 * N0 (dev0) ----------------N1 (dev1) ------------------------------ N2 (dev2)
12 * Channel 12 ED Scan Channels 11-14 Channel 14
13 *
14 * |--------10 m----------------|----------30 m -----------------------|
15 *
16 * This example demonstrate the usage of the MAC ED Scan primitive as
17 * described by IEEE 802.15.4-2011.
18 *
19 * At the beginning of the simulation, PAN coordinators N0 (Channel 12) and N2 (Channel 14)
20 * start transmitting beacon frames on their respective channels. At the same time,
21 * end device N1 will scan through channels (11,12,13 and 14) looking for energy.
22 * i.e. multiple energy scans on each channel (PLME-ED calls). The results of the Max energy
23 * read registered for each channel is shown after the last channel scan is finished.
24 *
25 * The radio uses the default Sensibility and Rx Power provided by the
26 * LogDistancePropagationLossModel. The simulation might take a few seconds to complete.
27 *
28 * ED range: 0 - 255
29 */
30
31#include <ns3/constant-position-mobility-model.h>
32#include <ns3/core-module.h>
33#include <ns3/log.h>
34#include <ns3/lr-wpan-module.h>
35#include <ns3/packet.h>
36#include <ns3/propagation-delay-model.h>
37#include <ns3/propagation-loss-model.h>
38#include <ns3/simulator.h>
39#include <ns3/single-model-spectrum-channel.h>
40
41#include <iostream>
42
43using namespace ns3;
44using namespace ns3::lrwpan;
45
46static void
48{
49 if (params.m_status == MacStatus::SUCCESS && params.m_scanType == MLMESCAN_ED)
50 {
51 std::cout << Simulator::Now().As(Time::S) << "| Scan status SUCCESSFUL\n";
52 std::cout << "Results for Energy Scan:"
53 << "\nPage: " << params.m_chPage << "\n";
54 for (std::size_t i = 0; i < params.m_energyDetList.size(); i++)
55 {
56 std::cout << "Channel " << static_cast<uint32_t>(i + 11) << ": "
57 << +params.m_energyDetList[i] << "\n";
58 }
59 }
60}
61
62int
63main(int argc, char* argv[])
64{
66
67 // Create 2 PAN coordinator nodes, and 1 end device
71
75
76 dev0->SetAddress(Mac16Address("00:01"));
77 dev1->SetAddress(Mac16Address("00:02"));
78 dev2->SetAddress(Mac16Address("00:03"));
79
80 // Configure Spectrum channel
86 channel->AddPropagationLossModel(propModel);
87 channel->SetPropagationDelayModel(delayModel);
88
89 dev0->SetChannel(channel);
90 dev1->SetChannel(channel);
91 dev2->SetChannel(channel);
92
93 n0->AddDevice(dev0);
94 n1->AddDevice(dev1);
95 n2->AddDevice(dev2);
96
97 // MAC layer Callbacks hooks
100 dev1->GetMac()->SetMlmeScanConfirmCallback(scb);
101
102 Ptr<ConstantPositionMobilityModel> PanCoordinatorN0Mobility =
104 PanCoordinatorN0Mobility->SetPosition(Vector(0, 0, 0));
105 dev0->GetPhy()->SetMobility(PanCoordinatorN0Mobility);
106
107 Ptr<ConstantPositionMobilityModel> endDeviceN1Mobility =
109 endDeviceN1Mobility->SetPosition(Vector(10, 0, 0));
110 dev1->GetPhy()->SetMobility(endDeviceN1Mobility);
111
112 Ptr<ConstantPositionMobilityModel> PanCoordinatorN2Mobility =
114 PanCoordinatorN2Mobility->SetPosition(Vector(40, 0, 0));
115 dev2->GetPhy()->SetMobility(PanCoordinatorN2Mobility);
116
117 // PAN coordinator N0 starts transmit beacons on channel 12
119 params.m_panCoor = true;
120 params.m_PanId = 5;
121 params.m_bcnOrd = 3;
122 params.m_sfrmOrd = 3;
123 params.m_logCh = 12;
125 Seconds(2.0),
127 dev0->GetMac(),
128 params);
129
130 // PAN coordinator N2 transmit beacons on channel 14
132 params2.m_panCoor = true;
133 params2.m_PanId = 7;
134 params2.m_bcnOrd = 3;
135 params2.m_sfrmOrd = 3;
136 params2.m_logCh = 14;
138 Seconds(2.0),
140 dev2->GetMac(),
141 params2);
142
143 // Device 1 initiate channels scan on channels 11, 12, 13, and 14 looking for energy
144 // Scan Channels represented by bits 0-26 (27 LSB)
145 // ch 14 ch 11
146 // | |
147 // 0x7800 = 0000000000000000111100000000000
148 // scanDuration per channel = aBaseSuperframeDuration * (2^14+1) = 251.65 secs
149 MlmeScanRequestParams scanParams;
150 scanParams.m_chPage = 0;
151 scanParams.m_scanChannels = 0x7800;
152 scanParams.m_scanDuration = 14;
153 scanParams.m_scanType = MLMESCAN_ED;
155 Seconds(2.0),
157 dev1->GetMac(),
158 scanParams);
159
162
164 return 0;
165}
This class can contain 16 bit addresses.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:577
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ S
second
Definition nstime.h:105
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...
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...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:684
LogLevel
Logging severity classes and levels.
Definition log.h:83
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition log.h:107
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition log.h:108
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition log.cc:309
channel
Definition third.py:77
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.
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.