A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-mlme.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Ritsumeikan University, Shiga, 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 <ramonet@fc.ritsumei.ac.jp>
18 */
19
20/*
21 * Coordinator End Device
22 * N0 <---------------- N1
23 * (dev0) (dev1)
24 *
25 * This example demonstrate the usage of the MAC primitives involved in
26 * direct transmissions for the beacon enabled mode of IEEE 802.15.4-2011.
27 * A single packet is sent from an end device to the coordinator during the CAP
28 * of the first incoming superframe.
29 *
30 * This example do not demonstrate a full protocol stack usage.
31 * For full protocol stack usage refer to 6lowpan examples.
32 *
33 */
34
35#include <ns3/constant-position-mobility-model.h>
36#include <ns3/core-module.h>
37#include <ns3/log.h>
38#include <ns3/lr-wpan-module.h>
39#include <ns3/packet.h>
40#include <ns3/propagation-delay-model.h>
41#include <ns3/propagation-loss-model.h>
42#include <ns3/simulator.h>
43#include <ns3/single-model-spectrum-channel.h>
44
45#include <iostream>
46
47using namespace ns3;
48using namespace ns3::lrwpan;
49
50void
52{
53 NS_LOG_UNCOND(Simulator::Now().GetSeconds() << " secs | Received BEACON packet of size ");
54}
55
56void
58{
59 NS_LOG_UNCOND(Simulator::Now().GetSeconds()
60 << " secs | Received DATA packet of size " << p->GetSize());
61}
62
63void
65{
66 // In the case of transmissions with the Ack flag activated, the transaction is only
67 // successful if the Ack was received.
68 if (params.m_status == MacStatus::SUCCESS)
69 {
70 NS_LOG_UNCOND(Simulator::Now().GetSeconds() << " secs | Transmission successfully sent");
71 }
72}
73
74void
76{
77 NS_LOG_UNCOND(Simulator::Now().GetSeconds()
78 << "s Coordinator Received DATA packet (size " << p->GetSize() << " bytes)");
79}
80
81void
83{
84 if (params.m_status == MacStatus::SUCCESS)
85 {
86 NS_LOG_UNCOND(Simulator::Now().GetSeconds() << "Beacon status SUCCESSFUL");
87 }
88}
89
90int
91main(int argc, char* argv[])
92{
96 LogComponentEnable("LrWpanCsmaCa", LOG_LEVEL_INFO);
97
98 LrWpanHelper lrWpanHelper;
99
100 // Create 2 nodes, and a NetDevice for each one
101 Ptr<Node> n0 = CreateObject<Node>();
102 Ptr<Node> n1 = CreateObject<Node>();
103
104 Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice>();
105 Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice>();
106
107 dev0->SetAddress(Mac16Address("00:01"));
108 dev1->SetAddress(Mac16Address("00:02"));
109
110 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
112 CreateObject<LogDistancePropagationLossModel>();
114 CreateObject<ConstantSpeedPropagationDelayModel>();
115 channel->AddPropagationLossModel(propModel);
116 channel->SetPropagationDelayModel(delayModel);
117
118 dev0->SetChannel(channel);
119 dev1->SetChannel(channel);
120
121 n0->AddDevice(dev0);
122 n1->AddDevice(dev1);
123
124 ///////////////// Mobility ///////////////////////
125 Ptr<ConstantPositionMobilityModel> sender0Mobility =
126 CreateObject<ConstantPositionMobilityModel>();
127 sender0Mobility->SetPosition(Vector(0, 0, 0));
128 dev0->GetPhy()->SetMobility(sender0Mobility);
129 Ptr<ConstantPositionMobilityModel> sender1Mobility =
130 CreateObject<ConstantPositionMobilityModel>();
131
132 sender1Mobility->SetPosition(Vector(0, 10, 0)); // 10 m distance
133 dev1->GetPhy()->SetMobility(sender1Mobility);
134
135 /////// MAC layer Callbacks hooks/////////////
136
139 dev0->GetMac()->SetMlmeStartConfirmCallback(cb0);
140
143 dev1->GetMac()->SetMcpsDataConfirmCallback(cb1);
144
147 dev1->GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb3);
148
151 dev1->GetMac()->SetMcpsDataIndicationCallback(cb4);
152
155 dev0->GetMac()->SetMcpsDataIndicationCallback(cb5);
156
157 //////////// Manual device association ////////////////////
158 // Note: We manually associate the devices to a PAN coordinator
159 // (i.e. bootstrap is not used);
160 // The PAN COORDINATOR does not need to associate or set its
161 // PAN Id or its own coordinator id, these are set
162 // by the MLME-start.request primitive when used.
163
164 dev1->GetMac()->SetPanId(5);
165 dev1->GetMac()->SetAssociatedCoor(Mac16Address("00:01"));
166
167 ///////////////////// Start transmitting beacons from coordinator ////////////////////////
168
170 params.m_panCoor = true;
171 params.m_PanId = 5;
172 params.m_bcnOrd = 14;
173 params.m_sfrmOrd = 6;
175 Seconds(2.0),
177 dev0->GetMac(),
178 params);
179
180 ///////////////////// Transmission of data Packets from end device //////////////////////
181
182 Ptr<Packet> p1 = Create<Packet>(5);
183 McpsDataRequestParams params2;
184 params2.m_dstPanId = 5;
185 params2.m_srcAddrMode = SHORT_ADDR;
186 params2.m_dstAddrMode = SHORT_ADDR;
187 params2.m_dstAddr = Mac16Address("00:01");
188 params2.m_msduHandle = 0;
189 // params2.m_txOptions = TX_OPTION_ACK; // Enable direct transmission with Ack
190
191 /////////////////////////////////////////////////////////////////////////////////////
192 // Examples of time parameters for transmissions in the first incoming superframe. //
193 /////////////////////////////////////////////////////////////////////////////////////
194
195 // 2.981 sec No time to finish CCA in CAP, the transmission at this time will cause
196 // the packet to be deferred to the next superframe.
197
198 // 2.982 sec No time to finish random backoff delay in CAP, the transmission at this
199 // time will cause the packet to be deferred to the next superframe.
200
201 // 2.93 sec Enough time, the packet can be transmitted within the CAP of the first
202 // superframe
203
204 // MCPS-DATA.request Beacon enabled Direct Transmission (dev1)
205 // Frame transmission from End Device to Coordinator (Direct transmission)
207 Seconds(2.93),
209 dev1->GetMac(),
210 params2,
211 p1);
212
215
217 return 0;
218}
helps to manage and create IEEE 802.15.4 NetDevice objects
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
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 McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p) override
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
Definition: lr-wpan-mac.cc:386
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
void DataIndicationCoordinator(McpsDataIndicationParams params, Ptr< Packet > p)
Definition: lr-wpan-mlme.cc:75
void BeaconIndication(MlmeBeaconNotifyIndicationParams params)
Definition: lr-wpan-mlme.cc:51
void TransEndIndication(McpsDataConfirmParams params)
Definition: lr-wpan-mlme.cc:64
void StartConfirm(MlmeStartConfirmParams params)
Definition: lr-wpan-mlme.cc:82
void DataIndication(McpsDataIndicationParams params, Ptr< Packet > p)
Definition: lr-wpan-mlme.cc:57
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
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
@ 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:104
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 ##.
MCPS-DATA.indication params.
AddressMode m_dstAddrMode
Destination address mode.
Mac16Address m_dstAddr
Destination address.
uint16_t m_dstPanId
Destination PAN identifier.
AddressMode m_srcAddrMode
Source address mode.
MLME-BEACON-NOTIFY.indication params.
MLME-START.confirm params.
MLME-START.request params.