src/lr-wpan/examples/lr-wpan-phy-test.cc
author Tom Henderson <tomh@tomh.org>
Mon, 28 Sep 2015 20:27:25 -0700
changeset 11676 05ea1489e509
parent 10720 4e4a0de88982
permissions -rw-r--r--
bug 2184: Integer overflow in MacLow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2011 The Boeing Company
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Gary Pei <guangyu.pei@boeing.com>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
#include <ns3/log.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include <ns3/test.h>
10720
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    22
#include <ns3/packet.h>
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include <ns3/lr-wpan-phy.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include <ns3/lr-wpan-mac.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include <ns3/simulator.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include <ns3/single-model-spectrum-channel.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include <ns3/constant-position-mobility-model.h>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
using namespace ns3;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
void GetSetTRXStateConfirm (LrWpanPhyEnumeration status)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
  NS_LOG_UNCOND ("At: " << Simulator::Now ()
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
                        << " Received Set TRX Confirm: " << status);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
ReceivePdDataIndication (uint32_t psduLength,
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    39
                         Ptr<Packet> p,
10720
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    40
                         uint8_t lqi)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
  NS_LOG_UNCOND ("At: " << Simulator::Now ()
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
                        << " Received frame size: " << psduLength << " LQI: " <<
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
                 lqi);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
void SendOnePacket (Ptr<LrWpanPhy> sender, Ptr<LrWpanPhy> receiver)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
  uint32_t n = 10;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
  Ptr<Packet> p = Create<Packet> (n);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
  sender->PdDataRequest (p->GetSize (), p);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
int main (int argc, char *argv[])
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
  LogComponentEnableAll (LOG_PREFIX_FUNC);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
  LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  LogComponentEnable ("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
  Ptr<LrWpanPhy> sender = CreateObject<LrWpanPhy> ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
  Ptr<LrWpanPhy> receiver = CreateObject<LrWpanPhy> ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
  sender->SetChannel (channel);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  receiver->SetChannel (channel);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  channel->AddRx (sender);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  channel->AddRx (receiver);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
  // CONFIGURE MOBILITY
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  Ptr<ConstantPositionMobilityModel> senderMobility = CreateObject<ConstantPositionMobilityModel> ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  sender->SetMobility (senderMobility);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  Ptr<ConstantPositionMobilityModel> receiverMobility = CreateObject<ConstantPositionMobilityModel> ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  receiver->SetMobility (senderMobility);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
  sender->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
  receiver->SetPlmeSetTRXStateConfirmCallback (MakeCallback (&GetSetTRXStateConfirm));
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
  sender->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
  receiver->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
  receiver->SetPdDataIndicationCallback (MakeCallback (&ReceivePdDataIndication));
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
  Simulator::Schedule (Seconds (1.0), &SendOnePacket, sender, receiver);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  Simulator::Stop (Seconds (10.0));
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
  Simulator::Run ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
  Simulator::Destroy ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
  return 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
}