A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/packet.h>
23 #include <ns3/lr-wpan-phy.h>
24 #include <ns3/lr-wpan-mac.h>
25 #include <ns3/simulator.h>
26 #include <ns3/single-model-spectrum-channel.h>
27 #include <ns3/constant-position-mobility-model.h>
28 
29 using namespace ns3;
30 
32 {
33  NS_LOG_UNCOND ("At: " << Simulator::Now ()
34  << " Received Set TRX Confirm: " << status);
35 }
36 
37 void
38 ReceivePdDataIndication (uint32_t psduLength,
39  Ptr<Packet> p,
40  uint8_t lqi)
41 {
42  NS_LOG_UNCOND ("At: " << Simulator::Now ()
43  << " Received frame size: " << psduLength << " LQI: " <<
44  lqi);
45 }
46 
48 {
49  uint32_t n = 10;
50  Ptr<Packet> p = Create<Packet> (n);
51  sender->PdDataRequest (p->GetSize (), p);
52 }
53 
54 
55 int main (int argc, char *argv[])
56 {
58  LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL);
59  LogComponentEnable ("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
60 
61  Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy> ();
62  Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy> ();
63 
64  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
65  sender->SetChannel (channel);
66  receiver->SetChannel (channel);
67  channel->AddRx (sender);
68  channel->AddRx (receiver);
69 
70  // CONFIGURE MOBILITY
71  Ptr<ConstantPositionMobilityModel> senderMobility = CreateObject<ConstantPositionMobilityModel> ();
72  sender->SetMobility (senderMobility);
73  Ptr<ConstantPositionMobilityModel> receiverMobility = CreateObject<ConstantPositionMobilityModel> ();
74  receiver->SetMobility (senderMobility);
75 
76 
78  receiver->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
79 
81  receiver->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
82 
83  receiver->SetPdDataIndicationCallback (MakeCallback (&ReceivePdDataIndication));
84 
85  Simulator::Schedule (Seconds (1.0), &SendOnePacket, sender, receiver);
86 
87  Simulator::Stop (Seconds (10.0));
88 
89  Simulator::Run ();
90 
92 
93  return 0;
94 }
void ReceivePdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:342
void SetPlmeSetTRXStateConfirmCallback(PlmeSetTRXStateConfirmCallback c)
set the callback for the end of an SetTRXState, as part of the interconnections betweenthe PHY and th...
Definition: lr-wpan-phy.cc:981
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
void GetSetTRXStateConfirm(LrWpanPhyEnumeration status)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:214
int main(int argc, char *argv[])
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
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:638
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: lr-wpan-phy.cc:206
prefix all trace prints with function
Definition: log.h:95
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
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:475
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:93
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:318