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 * @param rssi received signal strength indicator
37 */
38void
39ReceivePdDataIndication(uint32_t psduLength, Ptr<Packet> p, uint8_t lqi, int8_t rssi)
40{
41 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received frame size: " << psduLength << " LQI: "
42 << static_cast<int16_t>(lqi) << " RSSI: " << static_cast<int16_t>(rssi));
43}
44
45/**
46 * Send one packet
47 * @param sender sender PHY
48 * @param receiver receiver PHY
49 */
50void
52{
53 uint32_t n = 10;
55 sender->PdDataRequest(p->GetSize(), p);
56}
57
58int
59main(int argc, char* argv[])
60{
61 CommandLine cmd(__FILE__);
62 cmd.Parse(argc, argv);
63
66 LogComponentEnable("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
67
70
72 sender->SetChannel(channel);
73 receiver->SetChannel(channel);
74 channel->AddRx(sender);
75 channel->AddRx(receiver);
76
77 // CONFIGURE MOBILITY
80 sender->SetMobility(senderMobility);
81 Ptr<ConstantPositionMobilityModel> receiverMobility =
83 receiver->SetMobility(receiverMobility);
84
85 sender->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
86 receiver->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
87
88 sender->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
89 receiver->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
90
91 receiver->SetPdDataIndicationCallback(MakeCallback(&ReceivePdDataIndication));
92
93 Simulator::Schedule(Seconds(1), &SendOnePacket, sender, receiver);
94
96
98
100
101 return 0;
102}
Parse command-line arguments.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
Send one packet.
void GetSetTRXStateConfirm(PhyEnumeration status)
Function called when a the PHY state change is confirmed.
void ReceivePdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi, int8_t rssi)
Function called when a the PHY receives a packet.
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:690
#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:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
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:279
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:108
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition log.h:110
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
Definition log.cc:297
channel
Definition third.py:77