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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gary Pei <guangyu.pei@boeing.com>
7 */
8#include <ns3/command-line.h>
9#include <ns3/constant-position-mobility-model.h>
10#include <ns3/log.h>
11#include <ns3/lr-wpan-mac.h>
12#include <ns3/lr-wpan-phy.h>
13#include <ns3/packet.h>
14#include <ns3/simulator.h>
15#include <ns3/single-model-spectrum-channel.h>
16#include <ns3/test.h>
17
18using namespace ns3;
19using namespace ns3::lrwpan;
20
21/**
22 * Function called when a the PHY state change is confirmed
23 * \param status PHY state
24 */
25void
27{
28 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received Set TRX Confirm: " << status);
29}
30
31/**
32 * Function called when a the PHY receives a packet
33 * \param psduLength PSDU length
34 * \param p packet
35 * \param lqi link quality indication
36 */
37void
38ReceivePdDataIndication(uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
39{
40 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received frame size: " << psduLength
41 << " LQI: " << (uint16_t)lqi);
42}
43
44/**
45 * Send one packet
46 * \param sender sender PHY
47 * \param receiver receiver PHY
48 */
49void
51{
52 uint32_t n = 10;
54 sender->PdDataRequest(p->GetSize(), p);
55}
56
57int
58main(int argc, char* argv[])
59{
60 CommandLine cmd(__FILE__);
61 cmd.Parse(argc, argv);
62
65 LogComponentEnable("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
66
69
71 sender->SetChannel(channel);
72 receiver->SetChannel(channel);
73 channel->AddRx(sender);
74 channel->AddRx(receiver);
75
76 // CONFIGURE MOBILITY
79 sender->SetMobility(senderMobility);
80 Ptr<ConstantPositionMobilityModel> receiverMobility =
82 receiver->SetMobility(receiverMobility);
83
84 sender->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
85 receiver->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
86
87 sender->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
88 receiver->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
89
90 receiver->SetPdDataIndicationCallback(MakeCallback(&ReceivePdDataIndication));
91
92 Simulator::Schedule(Seconds(1.0), &SendOnePacket, sender, receiver);
93
95
97
99
100 return 0;
101}
Parse command-line arguments.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
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
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
@ IEEE_802_15_4_PHY_RX_ON
@ IEEE_802_15_4_PHY_TX_ON
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:291
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
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition log.h:107
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition log.cc:309
channel
Definition third.py:77