A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-data.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
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: Tom Henderson <thomas.r.henderson@boeing.com>
18 */
19
20/*
21 * Try to send data end-to-end through a LrWpanMac <-> LrWpanPhy <->
22 * SpectrumChannel <-> LrWpanPhy <-> LrWpanMac chain
23 *
24 * Trace Phy state changes, and Mac DataIndication and DataConfirm events
25 * to stdout
26 */
27#include <ns3/constant-position-mobility-model.h>
28#include <ns3/core-module.h>
29#include <ns3/log.h>
30#include <ns3/lr-wpan-module.h>
31#include <ns3/packet.h>
32#include <ns3/propagation-delay-model.h>
33#include <ns3/propagation-loss-model.h>
34#include <ns3/simulator.h>
35#include <ns3/single-model-spectrum-channel.h>
36
37#include <iostream>
38
39using namespace ns3;
40
46static void
48{
49 NS_LOG_UNCOND("Received packet of size " << p->GetSize());
50}
51
56static void
58{
59 NS_LOG_UNCOND("LrWpanMcpsDataConfirmStatus = " << params.m_status);
60}
61
69static void
70StateChangeNotification(std::string context,
71 Time now,
72 LrWpanPhyEnumeration oldState,
73 LrWpanPhyEnumeration newState)
74{
75 NS_LOG_UNCOND(context << " state change at " << now.As(Time::S) << " from "
78}
79
80int
81main(int argc, char* argv[])
82{
83 bool verbose = false;
84 bool extended = false;
85
86 CommandLine cmd(__FILE__);
87
88 cmd.AddValue("verbose", "turn on all log components", verbose);
89 cmd.AddValue("extended", "use extended addressing", extended);
90
91 cmd.Parse(argc, argv);
92
93 LrWpanHelper lrWpanHelper;
94 if (verbose)
95 {
96 lrWpanHelper.EnableLogComponents();
97 }
98
99 // Enable calculation of FCS in the trailers. Only necessary when interacting with real devices
100 // or wireshark. GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
101
102 // Create 2 nodes, and a NetDevice for each one
103 Ptr<Node> n0 = CreateObject<Node>();
104 Ptr<Node> n1 = CreateObject<Node>();
105
106 Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice>();
107 Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice>();
108
109 if (!extended)
110 {
111 dev0->SetAddress(Mac16Address("00:01"));
112 dev1->SetAddress(Mac16Address("00:02"));
113 }
114 else
115 {
116 Ptr<LrWpanMac> mac0 = dev0->GetMac();
117 Ptr<LrWpanMac> mac1 = dev1->GetMac();
118 mac0->SetExtendedAddress(Mac64Address("00:00:00:00:00:00:00:01"));
119 mac1->SetExtendedAddress(Mac64Address("00:00:00:00:00:00:00:02"));
120 }
121
122 // Each device must be attached to the same channel
123 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
125 CreateObject<LogDistancePropagationLossModel>();
127 CreateObject<ConstantSpeedPropagationDelayModel>();
128 channel->AddPropagationLossModel(propModel);
129 channel->SetPropagationDelayModel(delayModel);
130
131 dev0->SetChannel(channel);
132 dev1->SetChannel(channel);
133
134 // To complete configuration, a LrWpanNetDevice must be added to a node
135 n0->AddDevice(dev0);
136 n1->AddDevice(dev1);
137
138 // Trace state changes in the phy
139 dev0->GetPhy()->TraceConnect("TrxState",
140 std::string("phy0"),
142 dev1->GetPhy()->TraceConnect("TrxState",
143 std::string("phy1"),
145
146 Ptr<ConstantPositionMobilityModel> sender0Mobility =
147 CreateObject<ConstantPositionMobilityModel>();
148 sender0Mobility->SetPosition(Vector(0, 0, 0));
149 dev0->GetPhy()->SetMobility(sender0Mobility);
150 Ptr<ConstantPositionMobilityModel> sender1Mobility =
151 CreateObject<ConstantPositionMobilityModel>();
152 // Configure position 10 m distance
153 sender1Mobility->SetPosition(Vector(0, 10, 0));
154 dev1->GetPhy()->SetMobility(sender1Mobility);
155
158 dev0->GetMac()->SetMcpsDataConfirmCallback(cb0);
159
162 dev0->GetMac()->SetMcpsDataIndicationCallback(cb1);
163
166 dev1->GetMac()->SetMcpsDataConfirmCallback(cb2);
167
170 dev1->GetMac()->SetMcpsDataIndicationCallback(cb3);
171
172 // Tracing
173 lrWpanHelper.EnablePcapAll(std::string("lr-wpan-data"), true);
174 AsciiTraceHelper ascii;
175 Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream("lr-wpan-data.tr");
176 lrWpanHelper.EnableAsciiAll(stream);
177
178 // The below should trigger two callbacks when end-to-end data is working
179 // 1) DataConfirm callback is called
180 // 2) DataIndication callback is called with value of 50
181 Ptr<Packet> p0 = Create<Packet>(50); // 50 bytes of dummy data
183 params.m_dstPanId = 0;
184 if (!extended)
185 {
186 params.m_srcAddrMode = SHORT_ADDR;
187 params.m_dstAddrMode = SHORT_ADDR;
188 params.m_dstAddr = Mac16Address("00:02");
189 }
190 else
191 {
192 params.m_srcAddrMode = EXT_ADDR;
193 params.m_dstAddrMode = EXT_ADDR;
194 params.m_dstExtAddr = Mac64Address("00:00:00:00:00:00:00:02");
195 }
196 params.m_msduHandle = 0;
197 params.m_txOptions = TX_OPTION_ACK;
198 // dev0->GetMac ()->McpsDataRequest (params, p0);
200 Seconds(0.0),
202 dev0->GetMac(),
203 params,
204 p0);
205
206 // Send a packet back at time 2 seconds
207 Ptr<Packet> p2 = Create<Packet>(60); // 60 bytes of dummy data
208 if (!extended)
209 {
210 params.m_dstAddr = Mac16Address("00:01");
211 }
212 else
213 {
214 params.m_dstExtAddr = Mac64Address("00:00:00:00:00:00:00:01");
215 }
217 Seconds(2.0),
219 dev1->GetMac(),
220 params,
221 p2);
222
224
226 return 0;
227}
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:174
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:232
helps to manage and create IEEE 802.15.4 NetDevice objects
static std::string LrWpanPhyEnumerationPrinter(LrWpanPhyEnumeration e)
Transform the LrWpanPhyEnumeration enumeration into a printable string.
void EnableLogComponents()
Helper to enable all LrWpan log components with one statement.
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:384
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
an EUI-64 address
Definition: mac64-address.h:46
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 ...
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 void Run()
Run the simulation.
Definition: simulator.cc:178
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:111
@ TX_OPTION_ACK
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:61
@ SHORT_ADDR
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
static void DataConfirm(McpsDataConfirmParams params)
Function called when a Data confirm is invoked.
Definition: lr-wpan-data.cc:57
static void DataIndication(McpsDataIndicationParams params, Ptr< Packet > p)
Function called when a Data indication is invoked.
Definition: lr-wpan-data.cc:47
static void StateChangeNotification(std::string context, Time now, LrWpanPhyEnumeration oldState, LrWpanPhyEnumeration newState)
Function called when a the PHY state changes.
Definition: lr-wpan-data.cc:70
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:704
@ extended
Definition: ff-mac-common.h:85
ns cmd
Definition: second.py:40
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 ##.
bool verbose
MCPS-DATA.confirm params.
MCPS-DATA.indication params.
MCPS-DATA.request params.