A Discrete-Event Network Simulator
API
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;
30
35void
37{
38 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received Set TRX Confirm: " << status);
39}
40
47void
48ReceivePdDataIndication(uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
49{
50 NS_LOG_UNCOND("At: " << Simulator::Now() << " Received frame size: " << psduLength
51 << " LQI: " << (uint16_t)lqi);
52}
53
59void
61{
62 uint32_t n = 10;
63 Ptr<Packet> p = Create<Packet>(n);
64 sender->PdDataRequest(p->GetSize(), p);
65}
66
67int
68main(int argc, char* argv[])
69{
70 CommandLine cmd(__FILE__);
71 cmd.Parse(argc, argv);
72
75 LogComponentEnable("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
76
77 Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy>();
78 Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy>();
79
80 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
81 sender->SetChannel(channel);
82 receiver->SetChannel(channel);
83 channel->AddRx(sender);
84 channel->AddRx(receiver);
85
86 // CONFIGURE MOBILITY
88 CreateObject<ConstantPositionMobilityModel>();
89 sender->SetMobility(senderMobility);
90 Ptr<ConstantPositionMobilityModel> receiverMobility =
91 CreateObject<ConstantPositionMobilityModel>();
92 receiver->SetMobility(receiverMobility);
93
94 sender->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
95 receiver->SetPlmeSetTRXStateConfirmCallback(MakeCallback(&GetSetTRXStateConfirm));
96
97 sender->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
98 receiver->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
99
100 receiver->SetPdDataIndicationCallback(MakeCallback(&ReceivePdDataIndication));
101
102 Simulator::Schedule(Seconds(1.0), &SendOnePacket, sender, receiver);
103
104 Simulator::Stop(Seconds(10.0));
105
106 Simulator::Run();
107
108 Simulator::Destroy();
109
110 return 0;
111}
Parse command-line arguments.
Definition: command-line.h:232
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
#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:109
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:116
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:119
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
void GetSetTRXStateConfirm(LrWpanPhyEnumeration status)
Function called when a the PHY state change is confirmed.
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.
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:691
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:358
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:380
cmd
Definition: second.py:33
channel
Definition: third.py:81