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 
36 void
38 {
39  NS_LOG_UNCOND ("At: " << Simulator::Now ()
40  << " Received Set TRX Confirm: " << status);
41 }
42 
49 void
50 ReceivePdDataIndication (uint32_t psduLength,
51  Ptr<Packet> p,
52  uint8_t lqi)
53 {
54  NS_LOG_UNCOND ("At: " << Simulator::Now ()
55  << " Received frame size: " << psduLength << " LQI: " <<
56  (uint16_t) lqi);
57 }
58 
64 void
66 {
67  uint32_t n = 10;
68  Ptr<Packet> p = Create<Packet> (n);
69  sender->PdDataRequest (p->GetSize (), p);
70 }
71 
72 
73 int main (int argc, char *argv[])
74 {
75  CommandLine cmd (__FILE__);
76  cmd.Parse (argc, argv);
77 
79  LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL);
80  LogComponentEnable ("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
81 
82  Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy> ();
83  Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy> ();
84 
85  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
86  sender->SetChannel (channel);
87  receiver->SetChannel (channel);
88  channel->AddRx (sender);
89  channel->AddRx (receiver);
90 
91  // CONFIGURE MOBILITY
92  Ptr<ConstantPositionMobilityModel> senderMobility = CreateObject<ConstantPositionMobilityModel> ();
93  sender->SetMobility (senderMobility);
94  Ptr<ConstantPositionMobilityModel> receiverMobility = CreateObject<ConstantPositionMobilityModel> ();
95  receiver->SetMobility (receiverMobility);
96 
97 
98  sender->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
99  receiver->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
100 
101  sender->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
102  receiver->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
103 
104  receiver->SetPdDataIndicationCallback (MakeCallback (&ReceivePdDataIndication));
105 
106  Simulator::Schedule (Seconds (1.0), &SendOnePacket, sender, receiver);
107 
108  Simulator::Stop (Seconds (10.0));
109 
110  Simulator::Run ();
111 
113 
114  return 0;
115 }
Parse command-line arguments.
Definition: command-line.h:229
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
#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:106
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:113
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:116
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:385
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
cmd
Definition: second.py:35
channel
Definition: third.py:92