A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-phy-test.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: Gary Pei <guangyu.pei@boeing.com>
18 */
19#include <ns3/command-line.h>
20#include <ns3/constant-position-mobility-model.h>
21#include <ns3/log.h>
22#include <ns3/lr-wpan-mac.h>
23#include <ns3/lr-wpan-phy.h>
24#include <ns3/packet.h>
25#include <ns3/simulator.h>
26#include <ns3/single-model-spectrum-channel.h>
27#include <ns3/test.h>
28
29using namespace ns3;
30using namespace ns3::lrwpan;
31
32/**
33 * Function called when a the PHY state change is confirmed
34 * \param status PHY state
35 */
36void
38{
39 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received Set TRX Confirm: " << status);
40}
41
42/**
43 * Function called when a the PHY receives a packet
44 * \param psduLength PSDU length
45 * \param p packet
46 * \param lqi link quality indication
47 */
48void
49ReceivePdDataIndication(uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
50{
51 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received frame size: " << psduLength
52 << " LQI: " << (uint16_t)lqi);
53}
54
55/**
56 * Send one packet
57 * \param sender sender PHY
58 * \param receiver receiver PHY
59 */
60void
62{
63 uint32_t n = 10;
64 Ptr<Packet> p = Create<Packet>(n);
65 sender->PdDataRequest(p->GetSize(), p);
66}
67
68int
69main(int argc, char* argv[])
70{
71 CommandLine cmd(__FILE__);
72 cmd.Parse(argc, argv);
73
76 LogComponentEnable("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
77
78 Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy>();
79 Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy>();
80
81 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
82 sender->SetChannel(channel);
83 receiver->SetChannel(channel);
84 channel->AddRx(sender);
85 channel->AddRx(receiver);
86
87 // CONFIGURE MOBILITY
89 CreateObject<ConstantPositionMobilityModel>();
90 sender->SetMobility(senderMobility);
91 Ptr<ConstantPositionMobilityModel> receiverMobility =
92 CreateObject<ConstantPositionMobilityModel>();
93 receiver->SetMobility(receiverMobility);
94
95 sender->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
96 receiver->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
97
98 sender->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
99 receiver->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
100
101 receiver->SetPdDataIndicationCallback(MakeCallback(&ReceivePdDataIndication));
102
103 Simulator::Schedule(Seconds(1.0), &SendOnePacket, sender, receiver);
104
106
108
110
111 return 0;
112}
Parse command-line arguments.
Definition: command-line.h:232
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
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
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:115
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:122
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:125
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
Send one packet.
void ReceivePdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
Function called when a the PHY receives a packet.
void GetSetTRXStateConfirm(PhyEnumeration status)
Function called when a the PHY state change is confirmed.
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_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:320
ns cmd
Definition: second.py:40
ns channel
Definition: third.py:88