A Discrete-Event Network Simulator
API
lr-wpan-phy-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Gary Pei <guangyu.pei@boeing.com>
19  */
20 #include <ns3/log.h>
21 #include <ns3/test.h>
22 #include <ns3/command-line.h>
23 #include <ns3/packet.h>
24 #include <ns3/lr-wpan-phy.h>
25 #include <ns3/lr-wpan-mac.h>
26 #include <ns3/simulator.h>
27 #include <ns3/single-model-spectrum-channel.h>
28 #include <ns3/constant-position-mobility-model.h>
29 
30 using namespace ns3;
31 
33 {
34  NS_LOG_UNCOND ("At: " << Simulator::Now ()
35  << " Received Set TRX Confirm: " << status);
36 }
37 
38 void
39 ReceivePdDataIndication (uint32_t psduLength,
40  Ptr<Packet> p,
41  uint8_t lqi)
42 {
43  NS_LOG_UNCOND ("At: " << Simulator::Now ()
44  << " Received frame size: " << psduLength << " LQI: " <<
45  (uint16_t) lqi);
46 }
47 
49 {
50  uint32_t n = 10;
51  Ptr<Packet> p = Create<Packet> (n);
52  sender->PdDataRequest (p->GetSize (), p);
53 }
54 
55 
56 int main (int argc, char *argv[])
57 {
59  cmd.Parse (argc, argv);
60 
62  LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL);
63  LogComponentEnable ("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
64 
65  Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy> ();
66  Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy> ();
67 
68  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
69  sender->SetChannel (channel);
70  receiver->SetChannel (channel);
71  channel->AddRx (sender);
72  channel->AddRx (receiver);
73 
74  // CONFIGURE MOBILITY
75  Ptr<ConstantPositionMobilityModel> senderMobility = CreateObject<ConstantPositionMobilityModel> ();
76  sender->SetMobility (senderMobility);
77  Ptr<ConstantPositionMobilityModel> receiverMobility = CreateObject<ConstantPositionMobilityModel> ();
78  receiver->SetMobility (receiverMobility);
79 
80 
82  receiver->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
83 
85  receiver->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
86 
87  receiver->SetPdDataIndicationCallback (MakeCallback (&ReceivePdDataIndication));
88 
89  Simulator::Schedule (Seconds (1.0), &SendOnePacket, sender, receiver);
90 
91  Simulator::Stop (Seconds (10.0));
92 
93  Simulator::Run ();
94 
96 
97  return 0;
98 }
void ReceivePdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
void SetPlmeSetTRXStateConfirmCallback(PlmeSetTRXStateConfirmCallback c)
set the callback for the end of an SetTRXState, as part of the interconnections betweenthe PHY and th...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
static void Run(void)
Run the simulation.
Definition: simulator.cc:170
void GetSetTRXStateConfirm(LrWpanPhyEnumeration status)
cmd
Definition: second.py:35
channel
Definition: third.py:92
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:233
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:370
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1390
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1610
Parse command-line arguments.
Definition: command-line.h:212
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:134
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:394
void PlmeSetTRXStateRequest(LrWpanPhyEnumeration state)
IEEE 802.15.4-2006 section 6.2.2.7 PLME-SET-TRX-STATE.request Set PHY state.
Definition: lr-wpan-phy.cc:687
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: lr-wpan-phy.cc:225
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
Prefix all trace prints with function.
Definition: log.h:118
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:178
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1064
void PdDataRequest(const uint32_t psduLength, Ptr< Packet > p)
IEEE 802.15.4-2006 section 6.2.1.1 PD-DATA.request Request to transfer MPDU from MAC (transmitting) ...
Definition: lr-wpan-phy.cc:523
Print everything.
Definition: log.h:116
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:105