src/lr-wpan/model/lr-wpan-phy.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Sun, 15 Mar 2015 09:14:50 +0100
changeset 11232 865dcb3bf5a0
parent 11205 29b708f01eb1
child 11265 9fa2628d32cb
permissions -rw-r--r--
Bug 2025 - (lr-wpan) Changing the channel doesn't affect the Tx params
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
 *
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: 10714
diff changeset
    18
 * Author:
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    19
 *  Gary Pei <guangyu.pei@boeing.com>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    20
 *  Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
 */
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: 10714
diff changeset
    22
#include "lr-wpan-phy.h"
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    23
#include "lr-wpan-lqi-tag.h"
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    24
#include "lr-wpan-spectrum-signal-parameters.h"
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    25
#include "lr-wpan-spectrum-value-helper.h"
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    26
#include "lr-wpan-error-model.h"
10736
0de55db7c94e Tweaks to the collision tests
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10730
diff changeset
    27
#include "lr-wpan-net-device.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: 10714
diff changeset
    28
#include <ns3/log.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    29
#include <ns3/abort.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    30
#include <ns3/simulator.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    31
#include <ns3/spectrum-value.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    32
#include <ns3/antenna-model.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    33
#include <ns3/mobility-model.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    34
#include <ns3/spectrum-channel.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    35
#include <ns3/packet.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    36
#include <ns3/packet-burst.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
    37
#include <ns3/net-device.h>
10750
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
    38
#include <ns3/random-variable-stream.h>
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
    39
#include <ns3/double.h>
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10811
diff changeset
    41
namespace ns3 {
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10811
diff changeset
    43
NS_LOG_COMPONENT_DEFINE ("LrWpanPhy");
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
NS_OBJECT_ENSURE_REGISTERED (LrWpanPhy);
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
// Table 22 in section 6.4.1 of ieee802.15.4
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
const uint32_t LrWpanPhy::aMaxPhyPacketSize = 127; // max PSDU in octets
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
const uint32_t LrWpanPhy::aTurnaroundTime = 12;  // RX-to-TX or TX-to-RX in symbol periods
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    50
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
// IEEE802.15.4-2006 Table 2 in section 6.1.2 (kb/s and ksymbol/s)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
// The index follows LrWpanPhyOption
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
const LrWpanPhyDataAndSymbolRates
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
LrWpanPhy::dataSymbolRates[7] = { { 20.0, 20.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
                                  { 40.0, 40.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
                                  { 250.0, 12.5},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
                                  { 250.0, 50.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
                                  { 100.0, 25.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
                                  { 250.0, 62.5},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
                                  { 250.0, 62.5}};
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
// IEEE802.15.4-2006 Table 19 and Table 20 in section 6.3.
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
// The PHR is 1 octet and it follows phySymbolsPerOctet in Table 23
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
// The index follows LrWpanPhyOption
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
const LrWpanPhyPpduHeaderSymbolNumber
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
LrWpanPhy::ppduHeaderSymbolNumbers[7] = { { 32.0, 8.0, 8.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
                                          { 32.0, 8.0, 8.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
                                          { 2.0, 1.0, 0.4},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
                                          { 6.0, 1.0, 1.6},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
                                          { 8.0, 2.0, 2.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
                                          { 8.0, 2.0, 2.0},
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
                                          { 8.0, 2.0, 2.0}};
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
TypeId
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
LrWpanPhy::GetTypeId (void)
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
  static TypeId tid = TypeId ("ns3::LrWpanPhy")
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    .SetParent<Object> ()
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    .AddConstructor<LrWpanPhy> ()
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    79
    .AddTraceSource ("TrxState",
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    80
                     "The state of the transceiver",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    81
                     MakeTraceSourceAccessor (&LrWpanPhy::m_trxStateLogger),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    82
                     "ns3::LrWpanPhy::StateTracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    83
    .AddTraceSource ("PhyTxBegin",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    84
                     "Trace source indicating a packet has "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    85
                     "begun transmitting over the channel medium",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    86
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyTxBeginTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    87
                     "ns3::Packet::TracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    88
    .AddTraceSource ("PhyTxEnd",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    89
                     "Trace source indicating a packet has been "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    90
                     "completely transmitted over the channel.",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    91
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyTxEndTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    92
                     "ns3::Packet::TracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    93
    .AddTraceSource ("PhyTxDrop",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    94
                     "Trace source indicating a packet has been "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    95
                     "dropped by the device during transmission",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    96
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyTxDropTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    97
                     "ns3::Packet::TracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
    98
    .AddTraceSource ("PhyRxBegin",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    99
                     "Trace source indicating a packet has begun "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   100
                     "being received from the channel medium by the device",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   101
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxBeginTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   102
                     "ns3::Packet::TracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   103
    .AddTraceSource ("PhyRxEnd",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   104
                     "Trace source indicating a packet has been "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   105
                     "completely received from the channel medium "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   106
                     "by the device",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   107
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxEndTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   108
                     "ns3::LrWpanPhy::RxEndTracedCallback")
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   109
    .AddTraceSource ("PhyRxDrop",
11086
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   110
                     "Trace source indicating a packet has been "
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   111
                     "dropped by the device during reception",
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   112
                     MakeTraceSourceAccessor (&LrWpanPhy::m_phyRxDropTrace),
65914b1ed5b3 TracedCallback function signatures, the rest.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   113
                     "ns3::Packet::TracedCallback")
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
  ;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  return tid;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   118
LrWpanPhy::LrWpanPhy (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  : m_edRequest (),
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
    m_setTRXState ()
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
{
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: 10714
diff changeset
   122
  m_trxState = IEEE_802_15_4_PHY_TRX_OFF;
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   123
  m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  // default PHY PIB attributes
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  m_phyPIBAttributes.phyCurrentChannel = 11;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  m_phyPIBAttributes.phyTransmitPower = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
  m_phyPIBAttributes.phyCurrentPage = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
  for (uint32_t i = 0; i < 32; i++)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
      m_phyPIBAttributes.phyChannelsSupported[i] = 0x07ffffff;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  m_phyPIBAttributes.phyCCAMode = 1;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  SetMyPhyOption ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   137
  m_edPower.averagePower = 0.0;
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   138
  m_edPower.lastUpdate = Seconds (0.0);
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   139
  m_edPower.measurementLength = Seconds (0.0);
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   140
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   141
  // default -110 dBm in W for 2.4 GHz
10747
9d94cd7b245f Changed default receiver sensitivity value.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10742
diff changeset
   142
  m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  LrWpanSpectrumValueHelper psdHelper;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  m_txPsd = psdHelper.CreateTxPowerSpectralDensity (m_phyPIBAttributes.phyTransmitPower,
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
                                                    m_phyPIBAttributes.phyCurrentChannel);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  m_noise = psdHelper.CreateNoisePowerSpectralDensity (m_phyPIBAttributes.phyCurrentChannel);
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   147
  m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   148
  m_rxLastUpdate = Seconds (0);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   149
  Ptr<Packet> none_packet = 0;
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   150
  Ptr<LrWpanSpectrumSignalParameters> none_params = 0;
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   151
  m_currentRxPacket = std::make_pair (none_params, true);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   152
  m_currentTxPacket = std::make_pair (none_packet, true);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   153
  m_errorModel = 0;
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: 10714
diff changeset
   154
10750
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   155
  m_random = CreateObject<UniformRandomVariable> ();
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   156
  m_random->SetAttribute ("Min", DoubleValue (0.0));
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   157
  m_random->SetAttribute ("Max", DoubleValue (1.0));
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   158
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   159
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: 10714
diff changeset
   160
  ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   163
LrWpanPhy::~LrWpanPhy (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   168
LrWpanPhy::DoDispose (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
  NS_LOG_FUNCTION (this);
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: 10714
diff changeset
   171
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   172
  // Cancel pending transceiver state change, if one is in progress.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   173
  m_setTRXState.Cancel ();
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   174
  m_trxState = IEEE_802_15_4_PHY_TRX_OFF;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   175
  m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   176
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
  m_mobility = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
  m_device = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
  m_channel = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
  m_txPsd = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
  m_noise = 0;
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   182
  m_signal = 0;
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   183
  m_errorModel = 0;
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: 10714
diff changeset
   184
  m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
  m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
  m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
  m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t > ();
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: 10714
diff changeset
   188
  m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > ();
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
  m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier > ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
  SpectrumPhy::DoDispose ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   195
Ptr<NetDevice>
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   196
LrWpanPhy::GetDevice (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
  return m_device;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   203
Ptr<MobilityModel>
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   204
LrWpanPhy::GetMobility (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
  return m_mobility;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
void
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   212
LrWpanPhy::SetDevice (Ptr<NetDevice> d)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
  NS_LOG_FUNCTION (this << d);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  m_device = d;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
void
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   220
LrWpanPhy::SetMobility (Ptr<MobilityModel> m)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
  NS_LOG_FUNCTION (this << m);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
  m_mobility = m;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
LrWpanPhy::SetChannel (Ptr<SpectrumChannel> c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
  NS_LOG_FUNCTION (this << c);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
  m_channel = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
Ptr<SpectrumChannel>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
LrWpanPhy::GetChannel (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
{
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: 10714
diff changeset
   238
  NS_LOG_FUNCTION (this);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
  return m_channel;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
Ptr<const SpectrumModel>
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   244
LrWpanPhy::GetRxSpectrumModel (void) const
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
{
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: 10714
diff changeset
   246
  NS_LOG_FUNCTION (this);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  if (m_txPsd)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
      return m_txPsd->GetSpectrumModel ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
      return 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
10714
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   257
Ptr<AntennaModel>
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   258
LrWpanPhy::GetRxAntenna (void)
10714
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   259
{
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: 10714
diff changeset
   260
  NS_LOG_FUNCTION (this);
10714
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   261
  return m_antenna;
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   262
}
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   263
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   264
void
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   265
LrWpanPhy::SetAntenna (Ptr<AntennaModel> a)
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   266
{
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   267
  NS_LOG_FUNCTION (this << a);
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   268
  m_antenna = a;
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   269
}
03e748ce8893 align with SpectrumPhy antenna model changes for ns-3.14
Tom Henderson <tomh@tomh.org>
parents: 10713
diff changeset
   270
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
void
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   272
LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
{
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   274
  NS_LOG_FUNCTION (this << spectrumRxParams);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   275
  LrWpanSpectrumValueHelper psdHelper;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   276
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   277
  if (!m_edRequest.IsExpired ())
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   278
    {
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   279
      // Update the average receive power during ED.
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   280
      Time now = Simulator::Now ();
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   281
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   282
      m_edPower.lastUpdate = now;
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   283
    }
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   284
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   285
  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   286
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   287
  if ( lrWpanRxParams == 0)
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   288
    {
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   289
      CheckInterference ();
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   290
      m_signal->AddSignal (spectrumRxParams->psd);
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   291
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   292
      // Update peak power if CCA is in progress.
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   293
      if (!m_ccaRequest.IsExpired ())
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   294
        {
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   295
          double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   296
          if (m_ccaPeakPower < power)
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   297
            {
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   298
              m_ccaPeakPower = power;
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   299
            }
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   300
        }
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   301
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   302
      Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   303
      return;
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   304
    }
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   305
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   306
  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   307
  NS_ASSERT (p != 0);
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   308
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   309
  // Prevent PHY from receiving another packet while switching the transceiver state.
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   310
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ())
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
    {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   312
      // The specification doesn't seem to refer to BUSY_RX, but vendor
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   313
      // data sheets suggest that this is a substate of the RX_ON state
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   314
      // that is entered after preamble detection when the digital receiver
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   315
      // is enabled.  Here, for now, we use BUSY_RX to mark the period between
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   316
      // StartRx() and EndRx() states.
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   317
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   318
      // We are going to BUSY_RX state when receiving the first bit of an SHR,
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   319
      // as opposed to real receivers, which should go to this state only after
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   320
      // successfully receiving the SHR.
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: 10714
diff changeset
   321
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   322
      // If synchronizing to the packet is possible, change to BUSY_RX state,
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   323
      // otherwise drop the packet and stay in RX state. The actual synchronization
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   324
      // is not modeled.
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   325
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   326
      // Add any incoming packet to the current interference before checking the
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   327
      // SINR.
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   328
      NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   329
      m_signal->AddSignal (lrWpanRxParams->psd);
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   330
      Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   331
      *interferenceAndNoise -= *lrWpanRxParams->psd;
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   332
      *interferenceAndNoise += *m_noise;
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   333
      double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
10730
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
   334
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
   335
      // Std. 802.15.4-2006, appendix E, Figure E.2
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
   336
      // At SNR < -5 the BER is less than 10e-1.
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
   337
      // It's useless to even *try* to decode the packet.
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   338
      if (10 * log10 (sinr) > -5)
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   339
        {
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   340
          ChangeTrxState (IEEE_802_15_4_PHY_BUSY_RX);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   341
          m_currentRxPacket = std::make_pair (lrWpanRxParams, false);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   342
          m_phyRxBeginTrace (p);
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   343
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   344
          m_rxLastUpdate = Simulator::Now ();
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: 10714
diff changeset
   345
        }
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   346
      else
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   347
        {
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   348
          m_phyRxDropTrace (p);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   349
        }
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: 10714
diff changeset
   350
    }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   351
  else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   352
    {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   353
      // Drop the new packet.
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: 10714
diff changeset
   354
      NS_LOG_DEBUG (this << " packet collision");
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   355
      m_phyRxDropTrace (p);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   356
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   357
      // Check if we correctly received the old packet up to now.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   358
      CheckInterference ();
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   359
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   360
      // Add the incoming packet to the current interference after we have
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   361
      // checked for successfull reception of the current packet for the time
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   362
      // before the additional interference.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   363
      m_signal->AddSignal (lrWpanRxParams->psd);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
    }
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: 10714
diff changeset
   365
  else
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   366
    {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   367
      // Simply drop the packet.
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: 10714
diff changeset
   368
      NS_LOG_DEBUG (this << " transceiver not in RX state");
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   369
      m_phyRxDropTrace (p);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   370
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   371
      // Add the signal power to the interference, anyway.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   372
      m_signal->AddSignal (lrWpanRxParams->psd);
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   373
    }
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   374
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   375
  // Update peak power if CCA is in progress.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   376
  if (!m_ccaRequest.IsExpired ())
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   377
    {
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   378
      double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   379
      if (m_ccaPeakPower < power)
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   380
        {
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   381
          m_ccaPeakPower = power;
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   382
        }
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: 10714
diff changeset
   383
    }
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   384
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   385
  // Always call EndRx to update the interference.
10730
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
   386
  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   387
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   388
  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   391
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
   392
LrWpanPhy::CheckInterference (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
{
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   394
  // Calculate whether packet was lost.
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   395
  LrWpanSpectrumValueHelper psdHelper;
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   396
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   397
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   398
  // We are currently receiving a packet.
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   399
  if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   400
    {
10738
0cf3ef65b4c0 Add back debugging code, seems we have a bug in interference handling.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10737
diff changeset
   401
      // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   402
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   403
      Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
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: 10714
diff changeset
   404
      if (m_errorModel != 0)
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   405
        {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   406
          // How many bits did we receive since the last calculation?
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   407
          double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   408
          uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000));
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   409
          Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   410
          *interferenceAndNoise -= *currentRxParams->psd;
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   411
          *interferenceAndNoise += *m_noise;
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   412
          double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   413
          double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   414
10740
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   415
          // The LQI is the total packet success rate scaled to 0-255.
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   416
          // If not already set, initialize to 255.
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   417
          LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   418
          currentPacket->PeekPacketTag (tag);
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   419
          uint8_t lqi = tag.Get ();
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   420
          tag.Set (lqi - (per * lqi));
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   421
          currentPacket->ReplacePacketTag (tag);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   422
10750
8a9e91fac9c0 First Doxygen documentation batch and code cleanups.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10748
diff changeset
   423
          if (m_random->GetValue () < per)
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: 10714
diff changeset
   424
            {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   425
              // The packet was destroyed, drop the packet after reception.
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   426
              m_currentRxPacket.second = true;
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: 10714
diff changeset
   427
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   428
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   429
      else
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   430
        {
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: 10714
diff changeset
   431
          NS_LOG_WARN ("Missing ErrorModel");
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   432
        }
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   433
    }
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   434
  m_rxLastUpdate = Simulator::Now ();
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   435
}
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   436
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   437
void
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   438
LrWpanPhy::EndRx (Ptr<SpectrumSignalParameters> par)
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   439
{
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   440
  NS_LOG_FUNCTION (this);
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   441
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   442
  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   443
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   444
  if (!m_edRequest.IsExpired ())
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   445
    {
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   446
      // Update the average receive power during ED.
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   447
      Time now = Simulator::Now ();
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   448
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   449
      m_edPower.lastUpdate = now;
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   450
    }
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   451
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   452
  CheckInterference ();
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   453
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   454
  // Update the interference.
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   455
  m_signal->RemoveSignal (par->psd);
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   456
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   457
  if (params == 0)
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   458
    {
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   459
      NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   460
      return;
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   461
    }
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   462
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
   463
  // If this is the end of the currently received packet, check if reception was successful.
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   464
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   465
  if (currentRxParams == params)
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   466
    {
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   467
      Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   468
      NS_ASSERT (currentPacket != 0);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   469
10740
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   470
      // If there is no error model attached to the PHY, we always report the maximum LQI value.
aaaf22c97012 Added LQI calculation as the PER of the complete packet scaled to 255.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10738
diff changeset
   471
      LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   472
      currentPacket->PeekPacketTag (tag);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   473
      m_phyRxEndTrace (currentPacket, tag.Get ());
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   474
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   475
      if (!m_currentRxPacket.second)
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   476
        {
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   477
          // The packet was successfully received, push it up the stack.
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: 10714
diff changeset
   478
          if (!m_pdDataIndicationCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   479
            {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   480
              m_pdDataIndicationCallback (currentPacket->GetSize (), currentPacket, tag.Get ());
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: 10714
diff changeset
   481
            }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   482
        }
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   483
      else
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   484
        {
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   485
          // The packet was destroyed, drop it.
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   486
          m_phyRxDropTrace (currentPacket);
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   487
        }
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   488
      Ptr<LrWpanSpectrumSignalParameters> none = 0;
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: 10714
diff changeset
   489
      m_currentRxPacket = std::make_pair (none, true);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   490
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   491
      // We may be waiting to apply a pending state change.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   492
      if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   493
        {
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: 10714
diff changeset
   494
          // Only change the state immediately, if the transceiver is not already
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   495
          // switching the state.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   496
          if (!m_setTRXState.IsRunning ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   497
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   498
              NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   499
              ChangeTrxState (m_trxStatePending);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   500
              m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   501
              if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   502
                {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   503
                  m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   504
                }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   505
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   506
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   507
      else
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   508
        {
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
   509
          ChangeTrxState (IEEE_802_15_4_PHY_RX_ON);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   510
        }
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
LrWpanPhy::PdDataRequest (const uint32_t psduLength, Ptr<Packet> p)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
  NS_LOG_FUNCTION (this << psduLength << p);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
  if (psduLength > aMaxPhyPacketSize)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
      if (!m_pdDataConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
        {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
          m_pdDataConfirmCallback (IEEE_802_15_4_PHY_UNSPECIFIED);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
        }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   525
      NS_LOG_DEBUG ("Drop packet because psduLength too long: " << psduLength);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
      return;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   529
  // Prevent PHY from sending a packet while switching the transceiver state.
10760
d7d73e3ceb3c Apply utils/check-style.py script on lr-wpan source code again
Tom Henderson <tomh@tomh.org>
parents: 10758
diff changeset
   530
  if (!m_setTRXState.IsRunning ())
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
    {
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   532
      if (m_trxState == IEEE_802_15_4_PHY_TX_ON)
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   533
        {
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   534
          //send down
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   535
          NS_ASSERT (m_channel);
10713
84e9327f67ba align lr-wpan with ns-3.13 spectrum API changes
Gary Pei <guangyu.pei@boeing.com>
parents: 10712
diff changeset
   536
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   537
          // Remove a possible LQI tag from a previous transmission of the packet.
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   538
          LrWpanLqiTag lqiTag;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   539
          p->RemovePacketTag (lqiTag);
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: 10714
diff changeset
   540
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   541
          Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters> ();
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   542
          txParams->duration = CalculateTxTime (p);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   543
          txParams->txPhy = GetObject<SpectrumPhy> ();
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   544
          txParams->psd = m_txPsd;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   545
          txParams->txAntenna = m_antenna;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   546
          Ptr<PacketBurst> pb = CreateObject<PacketBurst> ();
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   547
          pb->AddPacket (p);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   548
          txParams->packetBurst = pb;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   549
          m_channel->StartTx (txParams);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   550
          m_pdDataRequest = Simulator::Schedule (txParams->duration, &LrWpanPhy::EndTx, this);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   551
          ChangeTrxState (IEEE_802_15_4_PHY_BUSY_TX);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   552
          m_phyTxBeginTrace (p);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   553
          m_currentTxPacket.first = p;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   554
          m_currentTxPacket.second = false;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   555
          return;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   556
        }
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   557
      else if ((m_trxState == IEEE_802_15_4_PHY_RX_ON)
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   558
               || (m_trxState == IEEE_802_15_4_PHY_TRX_OFF)
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   559
               || (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) )
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   560
        {
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   561
          if (!m_pdDataConfirmCallback.IsNull ())
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   562
            {
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   563
              m_pdDataConfirmCallback (m_trxState);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   564
            }
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   565
          // Drop packet, hit PhyTxDrop trace
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   566
          m_phyTxDropTrace (p);
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   567
          return;
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   568
        }
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   569
      else
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   570
        {
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   571
          NS_FATAL_ERROR ("This should be unreachable, or else state " << m_trxState << " should be added as a case");
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   572
        }
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
    }
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   574
  else
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
    {
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   576
      // TODO: This error code is not covered by the standard.
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   577
      // What is the correct behavior in this case?
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
      if (!m_pdDataConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
        {
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   580
          m_pdDataConfirmCallback (IEEE_802_15_4_PHY_UNSPECIFIED);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
        }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   582
      // Drop packet, hit PhyTxDrop trace
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   583
      m_phyTxDropTrace (p);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   584
      return;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
LrWpanPhy::PlmeCcaRequest (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
  NS_LOG_FUNCTION (this);
10736
0de55db7c94e Tweaks to the collision tests
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10730
diff changeset
   592
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: 10714
diff changeset
   593
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON || m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
    {
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   595
      m_ccaPeakPower = 0.0;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
      Time ccaTime = Seconds (8.0 / GetDataOrSymbolRate (false));
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: 10714
diff changeset
   597
      m_ccaRequest = Simulator::Schedule (ccaTime, &LrWpanPhy::EndCca, this);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   598
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   599
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
      if (!m_plmeCcaConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
        {
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: 10714
diff changeset
   603
          if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   604
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   605
              m_plmeCcaConfirmCallback (IEEE_802_15_4_PHY_TRX_OFF);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   606
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   607
          else
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   608
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   609
              m_plmeCcaConfirmCallback (IEEE_802_15_4_PHY_BUSY);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   610
            }
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
LrWpanPhy::PlmeEdRequest (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
  NS_LOG_FUNCTION (this);
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   619
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON || m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
    {
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   621
      // Average over the powers of all signals received until EndEd()
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   622
      m_edPower.averagePower = 0;
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   623
      m_edPower.lastUpdate = Simulator::Now ();
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   624
      m_edPower.measurementLength = Seconds (8.0 / GetDataOrSymbolRate (false));
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
   625
      m_edRequest = Simulator::Schedule (m_edPower.measurementLength, &LrWpanPhy::EndEd, this);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
    {
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   629
      LrWpanPhyEnumeration result = m_trxState;
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   630
      if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX)
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   631
        {
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   632
          result = IEEE_802_15_4_PHY_TX_ON;
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   633
        }
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   634
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
      if (!m_plmeEdConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
        {
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   637
          m_plmeEdConfirmCallback (result, 0);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   638
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   639
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   642
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
LrWpanPhy::PlmeGetAttributeRequest (LrWpanPibAttributeIdentifier id)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   644
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   645
  NS_LOG_FUNCTION (this << id);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   646
  LrWpanPhyEnumeration status;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   647
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
  switch (id)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
    case phyCurrentChannel:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
    case phyChannelsSupported:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
    case phyTransmitPower:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
    case phyCCAMode:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
    case phyCurrentPage:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
    case phyMaxFrameDuration:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   656
    case phySHRDuration:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   657
    case phySymbolsPerOctet:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   658
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   659
        status = IEEE_802_15_4_PHY_SUCCESS;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   660
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   661
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
    default:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
        status = IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
  if (!m_plmeGetAttributeConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
    {
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: 10714
diff changeset
   670
      LrWpanPhyPibAttributes retValue;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   671
      memcpy (&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
      m_plmeGetAttributeConfirmCallback (status,id,&retValue);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   676
// Section 6.2.2.7.3
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
  NS_LOG_FUNCTION (this << state);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   682
  // Check valid states (Table 14)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   683
  NS_ABORT_IF ( (state != IEEE_802_15_4_PHY_RX_ON)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   684
                && (state != IEEE_802_15_4_PHY_TRX_OFF)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   685
                && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   686
                && (state != IEEE_802_15_4_PHY_TX_ON) );
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   687
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   688
  NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << state);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   689
  // this method always overrides previous state setting attempts
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: 10714
diff changeset
   690
  if (!m_setTRXState.IsExpired ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   691
    {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   692
      if (m_trxStatePending == state)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   693
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   694
          // Simply wait for the ongoing state switch.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   695
          return;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   696
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   697
      else
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   698
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   699
          NS_LOG_DEBUG ("Cancel m_setTRXState");
10721
ac0a504fa91e - Fixed error in MAC state machine when sending an ACK and enqueuing a data packet at the same time.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10720
diff changeset
   700
          // Keep the transceiver state as the old state before the switching attempt.
10760
d7d73e3ceb3c Apply utils/check-style.py script on lr-wpan source code again
Tom Henderson <tomh@tomh.org>
parents: 10758
diff changeset
   701
          m_setTRXState.Cancel ();
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: 10714
diff changeset
   702
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   703
    }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   704
  if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
    {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   706
      m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   709
  if (state == m_trxState)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
    {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   711
      if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   713
          m_plmeSetTRXStateConfirmCallback (state);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
        }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   715
      return;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   716
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   717
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   718
  if ( ((state == IEEE_802_15_4_PHY_RX_ON)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   719
        || (state == IEEE_802_15_4_PHY_TRX_OFF))
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   720
       && (m_trxState == IEEE_802_15_4_PHY_BUSY_TX) )
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   721
    {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   722
      NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   723
      m_trxStatePending = state;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   724
      return;  // Send PlmeSetTRXStateConfirm later
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   725
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   726
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   727
  // specification talks about being in RX_ON and having received
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   728
  // a valid SFD.  Here, we are not modelling at that level of
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   729
  // granularity, so we just test for BUSY_RX state (any part of
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   730
  // a packet being actively received)
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: 10714
diff changeset
   731
  if (state == IEEE_802_15_4_PHY_TRX_OFF)
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   732
    {
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   733
      CancelEd (state);
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   734
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: 10714
diff changeset
   735
      if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   736
          && (m_currentRxPacket.first) && (!m_currentRxPacket.second))
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   737
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   738
          NS_LOG_DEBUG ("Receiver has valid SFD; defer state change");
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   739
          m_trxStatePending = state;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   740
          return;  // Send PlmeSetTRXStateConfirm later
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   741
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   742
      else if (m_trxState == IEEE_802_15_4_PHY_RX_ON || m_trxState == IEEE_802_15_4_PHY_TX_ON)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   743
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   744
          ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   745
          if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   746
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   747
              m_plmeSetTRXStateConfirmCallback (state);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   748
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   749
          return;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   750
        }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   751
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   752
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   753
  if (state == IEEE_802_15_4_PHY_TX_ON)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   754
    {
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   755
      CancelEd (state);
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
   756
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   757
      NS_LOG_DEBUG ("turn on PHY_TX_ON");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   758
      if ((m_trxState == IEEE_802_15_4_PHY_BUSY_RX) || (m_trxState == IEEE_802_15_4_PHY_RX_ON))
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   760
          if (m_currentRxPacket.first)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
            {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   762
              //terminate reception if needed
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   763
              //incomplete reception -- force packet discard
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   764
              NS_LOG_DEBUG ("force TX_ON, terminate reception");
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
              m_currentRxPacket.second = true;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
            }
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: 10714
diff changeset
   767
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   768
          // If CCA is in progress, cancel CCA and return BUSY.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   769
          if (!m_ccaRequest.IsExpired ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   770
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   771
              m_ccaRequest.Cancel ();
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   772
              if (!m_plmeCcaConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   773
                {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   774
                  m_plmeCcaConfirmCallback (IEEE_802_15_4_PHY_BUSY);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   775
                }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   776
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   777
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   778
          m_trxStatePending = IEEE_802_15_4_PHY_TX_ON;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   779
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   780
          // Delay for turnaround time
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: 10714
diff changeset
   781
          // TODO: Does it also take aTurnaroundTime to switch the transceiver state,
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   782
          //       even when the receiver is not busy? (6.9.2)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   783
          Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   784
          m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXState, this);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   785
          return;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   786
        }
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: 10714
diff changeset
   787
      else if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX || m_trxState == IEEE_802_15_4_PHY_TX_ON)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
        {
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: 10714
diff changeset
   789
          // We do NOT change the transceiver state here. We only report that
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   790
          // the transceiver is already in TX_ON state.
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
          if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
            {
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: 10714
diff changeset
   793
              m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   794
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   795
          return;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   796
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   797
      else if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   798
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   799
          ChangeTrxState (IEEE_802_15_4_PHY_TX_ON);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   800
          if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   801
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   802
              m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TX_ON);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
            }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   804
          return;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   806
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   807
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   808
  if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   809
    {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   810
      if (m_trxState == IEEE_802_15_4_PHY_TRX_OFF)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   811
        {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   812
          NS_LOG_DEBUG ("force TRX_OFF, was already off");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   813
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   814
      else
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   815
        {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   816
          NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   817
          if (m_currentRxPacket.first)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   818
            {   //terminate reception if needed
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   819
                //incomplete reception -- force packet discard
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   820
              NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   821
              m_currentRxPacket.second = true;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   822
            }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   823
          if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   824
            {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   825
              NS_LOG_DEBUG ("force TRX_OFF, terminate transmission");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   826
              m_currentTxPacket.second = true;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   827
            }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   828
          ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   829
          // Clear any other state
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   830
          m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   831
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   832
      if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   833
        {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   834
          m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   835
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   836
      return;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   837
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   838
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: 10714
diff changeset
   839
  if (state == IEEE_802_15_4_PHY_RX_ON)
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   840
    {
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: 10714
diff changeset
   841
      if (m_trxState == IEEE_802_15_4_PHY_TX_ON || m_trxState == IEEE_802_15_4_PHY_TRX_OFF)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   842
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   843
          // Turnaround delay
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   844
          // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   845
          //       even when the transmitter is not busy? (6.9.1)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   846
          m_trxStatePending = IEEE_802_15_4_PHY_RX_ON;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   847
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   848
          Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   849
          m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXState, this);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   850
          return;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   851
        }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   852
      else if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   853
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   854
          if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   855
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   856
              m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_RX_ON);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   857
            }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   858
          return;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   859
        }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   860
    }
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: 10714
diff changeset
   861
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   862
  NS_FATAL_ERROR ("Unexpected transition from state " << m_trxState << " to state " << state);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
bool
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
LrWpanPhy::ChannelSupported (uint8_t channel)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
  NS_LOG_FUNCTION (this << channel);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
  bool retValue = false;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
  for (uint32_t i = 0; i < 32; i++)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
      if ((m_phyPIBAttributes.phyChannelsSupported[i] & (1 << channel)) != 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
        {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
          retValue = true;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
          break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
  return retValue;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
LrWpanPhy::PlmeSetAttributeRequest (LrWpanPibAttributeIdentifier id,
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: 10714
diff changeset
   885
                                    LrWpanPhyPibAttributes* attribute)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
{
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: 10714
diff changeset
   887
  NS_LOG_FUNCTION (this << id << attribute);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
  NS_ASSERT (attribute);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
  LrWpanPhyEnumeration status = IEEE_802_15_4_PHY_SUCCESS;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
  switch (id)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
    case phyCurrentChannel:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
        if (!ChannelSupported (attribute->phyCurrentChannel))
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
            status = IEEE_802_15_4_PHY_INVALID_PARAMETER;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
        if (m_phyPIBAttributes.phyCurrentChannel != attribute->phyCurrentChannel)
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: 10714
diff changeset
   900
          {
11232
865dcb3bf5a0 Bug 2025 - (lr-wpan) Changing the channel doesn't affect the Tx params
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11205
diff changeset
   901
            // Cancel a pending transceiver state change.
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: 10714
diff changeset
   902
            // Switch off the transceiver.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   903
            // TODO: Is switching off the transceiver the right choice?
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   904
            m_trxState = IEEE_802_15_4_PHY_TRX_OFF;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   905
            if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   906
              {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   907
                m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   908
                m_setTRXState.Cancel ();
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   909
                if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   910
                  {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   911
                    m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_TRX_OFF);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   912
                  }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   913
              }
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   914
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
   915
            // Any packet in transmission or reception will be corrupted.
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
            if (m_currentRxPacket.first)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
              {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
                m_currentRxPacket.second = true;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
              }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   920
            if (PhyIsBusy ())
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
              {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
                m_currentTxPacket.second = true;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
                m_pdDataRequest.Cancel ();
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
                m_currentTxPacket.first = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
                if (!m_pdDataConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   926
                  {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
                    m_pdDataConfirmCallback (IEEE_802_15_4_PHY_TRX_OFF);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
                  }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
              }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   930
            m_phyPIBAttributes.phyCurrentChannel = attribute->phyCurrentChannel;
11232
865dcb3bf5a0 Bug 2025 - (lr-wpan) Changing the channel doesn't affect the Tx params
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11205
diff changeset
   931
            LrWpanSpectrumValueHelper psdHelper;
865dcb3bf5a0 Bug 2025 - (lr-wpan) Changing the channel doesn't affect the Tx params
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11205
diff changeset
   932
            m_txPsd = psdHelper.CreateTxPowerSpectralDensity (m_phyPIBAttributes.phyTransmitPower, m_phyPIBAttributes.phyCurrentChannel);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
    case phyChannelsSupported:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
      {   // only the first element is considered in the array
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
        if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
          {    //5 MSBs reserved
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
            status = IEEE_802_15_4_PHY_INVALID_PARAMETER;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
        else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
            m_phyPIBAttributes.phyChannelsSupported[0] = attribute->phyChannelsSupported[0];
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
    case phyTransmitPower:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   950
        if (attribute->phyTransmitPower > 0xbf)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   952
            status = IEEE_802_15_4_PHY_INVALID_PARAMETER;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
        else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   956
            m_phyPIBAttributes.phyTransmitPower = attribute->phyTransmitPower;
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   957
            LrWpanSpectrumValueHelper psdHelper;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
   958
            m_txPsd = psdHelper.CreateTxPowerSpectralDensity (m_phyPIBAttributes.phyTransmitPower, m_phyPIBAttributes.phyCurrentChannel);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
    case phyCCAMode:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   963
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   964
        if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   966
            status = IEEE_802_15_4_PHY_INVALID_PARAMETER;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   967
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   968
        else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   969
          {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   970
            m_phyPIBAttributes.phyCCAMode = attribute->phyCCAMode;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   971
          }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   972
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   973
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   974
    default:
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   975
      {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   976
        status = IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   977
        break;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   978
      }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   980
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
  if (!m_plmeSetAttributeConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
      m_plmeSetAttributeConfirmCallback (status, id);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
LrWpanPhy::SetPdDataIndicationCallback (PdDataIndicationCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
  m_pdDataIndicationCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
LrWpanPhy::SetPdDataConfirmCallback (PdDataConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
  m_pdDataConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
LrWpanPhy::SetPlmeCcaConfirmCallback (PlmeCcaConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1005
  m_plmeCcaConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1008
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1009
LrWpanPhy::SetPlmeEdConfirmCallback (PlmeEdConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1010
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1011
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
  m_plmeEdConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
LrWpanPhy::SetPlmeGetAttributeConfirmCallback (PlmeGetAttributeConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
  m_plmeGetAttributeConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1020
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1021
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1022
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1023
LrWpanPhy::SetPlmeSetTRXStateConfirmCallback (PlmeSetTRXStateConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1024
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
  m_plmeSetTRXStateConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
LrWpanPhy::SetPlmeSetAttributeConfirmCallback (PlmeSetAttributeConfirmCallback c)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
  m_plmeSetAttributeConfirmCallback = c;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
void
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1037
LrWpanPhy::ChangeTrxState (LrWpanPhyEnumeration newState)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
{
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1039
  NS_LOG_LOGIC (this << " state: " << m_trxState << " -> " << newState);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1040
  m_trxStateLogger (Simulator::Now (), m_trxState, newState);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1041
  m_trxState = newState;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1042
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1043
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1044
bool
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1045
LrWpanPhy::PhyIsBusy (void) const
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1046
{
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: 10714
diff changeset
  1047
  NS_LOG_FUNCTION (this << m_trxState);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1048
  return ((m_trxState == IEEE_802_15_4_PHY_BUSY_TX)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1049
          || (m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1050
          || (m_trxState == IEEE_802_15_4_PHY_BUSY));
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
void
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1054
LrWpanPhy::CancelEd (LrWpanPhyEnumeration state)
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1055
{
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1056
  NS_LOG_FUNCTION (this);
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1057
  NS_ASSERT (state == IEEE_802_15_4_PHY_TRX_OFF || state == IEEE_802_15_4_PHY_TX_ON);
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1058
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1059
  if (!m_edRequest.IsExpired ())
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1060
    {
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1061
      m_edRequest.Cancel ();
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1062
      if (!m_plmeEdConfirmCallback.IsNull ())
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1063
        {
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1064
          m_plmeEdConfirmCallback (state, 0);
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1065
        }
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1066
    }
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1067
}
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1068
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1069
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
  1070
LrWpanPhy::EndEd (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
  NS_LOG_FUNCTION (this);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1073
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
  1074
  m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1075
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1076
  uint8_t energyLevel;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
  // Per IEEE802.15.4-2006 sec 6.9.7
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1079
  double ratio = m_edPower.averagePower / m_rxSensitivity;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
  ratio = 10.0 * log10 (ratio);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
  if (ratio <= 10.0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
    {  // less than 10 dB
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1083
      energyLevel = 0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1084
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1085
  else if (ratio >= 40.0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1086
    { // less than 40 dB
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
      energyLevel = 255;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1090
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
      // in-between with linear increase per sec 6.9.7
10748
167fad4925ff Bug fixes and test for energy detection code.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10747
diff changeset
  1092
      energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1093
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1095
  if (!m_plmeEdConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1096
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1097
      m_plmeEdConfirmCallback (IEEE_802_15_4_PHY_SUCCESS, energyLevel);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1098
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1099
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1100
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
  1102
LrWpanPhy::EndCca (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1103
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1104
  NS_LOG_FUNCTION (this);
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: 10714
diff changeset
  1105
  LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1107
  // Update peak power.
11205
29b708f01eb1 bug 1774: compute signal power around channel, not across whole band
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11086
diff changeset
  1108
  double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1109
  if (m_ccaPeakPower < power)
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1110
    {
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1111
      m_ccaPeakPower = power;
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1112
    }
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1113
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1114
  if (PhyIsBusy ())
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
    {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1116
      sensedChannelState = IEEE_802_15_4_PHY_BUSY;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1117
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1118
  else if (m_phyPIBAttributes.phyCCAMode == 1)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1119
    { //sec 6.9.9 ED detection
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
      // -- ED threshold at most 10 dB above receiver sensitivity.
10811
31dbab5c8a28 bug 1924 - sensing radius and CCA
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10760
diff changeset
  1121
      if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1122
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1123
          sensedChannelState = IEEE_802_15_4_PHY_BUSY;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1124
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1125
      else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1127
          sensedChannelState = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1130
  else if (m_phyPIBAttributes.phyCCAMode == 2)
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1131
    {
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1132
      //sec 6.9.9 carrier sense only
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1133
      if (m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
        {
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1135
          // We currently do not model PPDU reception in detail. Instead we model
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1136
          // packet reception starting with the first bit of the preamble.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1137
          // Therefore, this code will never be reached, as PhyIsBusy() would
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1138
          // already lead to a channel busy condition.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1139
          // TODO: Change this, if we also model preamble and SFD detection.
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1140
          sensedChannelState = IEEE_802_15_4_PHY_BUSY;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1141
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
      else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1144
          sensedChannelState = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1145
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1146
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
  else if (m_phyPIBAttributes.phyCCAMode == 3)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
    { //sect 6.9.9 both
10811
31dbab5c8a28 bug 1924 - sensing radius and CCA
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10760
diff changeset
  1149
      if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1150
          && m_trxState == IEEE_802_15_4_PHY_BUSY_RX)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
        {
10742
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1152
          // Again, this code will never be reached, if we are already receiving
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1153
          // a packet, as PhyIsBusy() would already lead to a channel busy condition.
f44545c197c2 Make ED and CCA interference aware.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10740
diff changeset
  1154
          // TODO: Change this, if we also model preamble and SFD detection.
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1155
          sensedChannelState = IEEE_802_15_4_PHY_BUSY;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
      else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
        {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1159
          sensedChannelState = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1161
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1162
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1164
      NS_ASSERT_MSG (false, "Invalid CCA mode");
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1165
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1167
  NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1168
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1169
  if (!m_plmeCcaConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1170
    {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1171
      m_plmeCcaConfirmCallback (sensedChannelState);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1172
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1173
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1174
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1175
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
  1176
LrWpanPhy::EndSetTRXState (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1177
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1178
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1179
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1180
  NS_ABORT_IF ( (m_trxStatePending != IEEE_802_15_4_PHY_RX_ON) && (m_trxStatePending != IEEE_802_15_4_PHY_TX_ON) );
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: 10714
diff changeset
  1181
  ChangeTrxState (m_trxStatePending);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1182
  m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1183
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1184
  if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1185
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1186
      m_plmeSetTRXStateConfirmCallback (m_trxState);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1187
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1188
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1189
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1190
void
10758
9ae6fc0e8032 Added firing of missing MAC TX trace sources.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10754
diff changeset
  1191
LrWpanPhy::EndTx (void)
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1192
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1193
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1194
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1195
  NS_ABORT_IF ( (m_trxState != IEEE_802_15_4_PHY_BUSY_TX) && (m_trxState != IEEE_802_15_4_PHY_TRX_OFF));
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1196
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1197
  if (m_currentTxPacket.second == false)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1198
    {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1199
      NS_LOG_DEBUG ("Packet successfully transmitted");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1200
      m_phyTxEndTrace (m_currentTxPacket.first);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1201
      if (!m_pdDataConfirmCallback.IsNull ())
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1202
        {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1203
          m_pdDataConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1204
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1205
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1206
  else
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1207
    {
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1208
      NS_LOG_DEBUG ("Packet transmission aborted");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1209
      m_phyTxDropTrace (m_currentTxPacket.first);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1210
      if (!m_pdDataConfirmCallback.IsNull ())
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1211
        {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1212
          // See if this is ever entered in another state
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1213
          NS_ASSERT (m_trxState ==  IEEE_802_15_4_PHY_TRX_OFF);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1214
          m_pdDataConfirmCallback (m_trxState);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1215
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1216
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1217
  m_currentTxPacket.first = 0;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1218
  m_currentTxPacket.second = false;
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: 10714
diff changeset
  1219
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1220
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1221
  // We may be waiting to apply a pending state change.
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1222
  if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1223
    {
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: 10714
diff changeset
  1224
      // Only change the state immediately, if the transceiver is not already
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1225
      // switching the state.
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1226
      if (!m_setTRXState.IsRunning ())
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1227
        {
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: 10714
diff changeset
  1228
          NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1229
          ChangeTrxState (m_trxStatePending);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1230
          m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1231
          if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1232
            {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1233
              m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1234
            }
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1235
        }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1236
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1237
  else
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1238
    {
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: 10714
diff changeset
  1239
      if (m_trxState != IEEE_802_15_4_PHY_TRX_OFF)
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1240
        {
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1241
          ChangeTrxState (IEEE_802_15_4_PHY_TX_ON);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1242
        }
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1243
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1244
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1245
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1246
Time
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1247
LrWpanPhy::CalculateTxTime (Ptr<const Packet> packet)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1248
{
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: 10714
diff changeset
  1249
  NS_LOG_FUNCTION (this << packet);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1250
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1251
  bool isData = true;
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
  1252
  Time txTime = GetPpduHeaderTxTime ();
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1253
10730
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
  1254
  txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
  return txTime;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1258
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1259
double
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
LrWpanPhy::GetDataOrSymbolRate (bool isData)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1261
{
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: 10714
diff changeset
  1262
  NS_LOG_FUNCTION (this << isData);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1263
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
  double rate = 0.0;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1265
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1266
  NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1267
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1268
  if (isData)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1269
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1270
      rate = dataSymbolRates [m_phyOption].bitRate;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1271
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1272
  else
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1273
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1274
      rate = dataSymbolRates [m_phyOption].symbolRate;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1275
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1276
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1277
  return (rate * 1000.0);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1278
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1279
10728
62d4098c1c22 First version with interference handling.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10722
diff changeset
  1280
Time
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1281
LrWpanPhy::GetPpduHeaderTxTime (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1282
{
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: 10714
diff changeset
  1283
  NS_LOG_FUNCTION (this);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1284
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1285
  bool isData = false;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1286
  double totalPpduHdrSymbols;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1287
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1288
  NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1289
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1290
  totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1291
    + ppduHeaderSymbolNumbers[m_phyOption].shrSfd
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1292
    + ppduHeaderSymbolNumbers[m_phyOption].phr;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1293
10730
3db83bcc026d Tweaks to Rx values
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10729
diff changeset
  1294
  return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1295
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1296
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1297
// IEEE802.15.4-2006 Table 2 in section 6.1.2
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1298
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1299
LrWpanPhy::SetMyPhyOption (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1300
{
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: 10714
diff changeset
  1301
  NS_LOG_FUNCTION (this);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1302
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1303
  m_phyOption = IEEE_802_15_4_INVALID_PHY_OPTION;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1304
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1305
  if (m_phyPIBAttributes.phyCurrentPage == 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1306
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1307
      if (m_phyPIBAttributes.phyCurrentChannel == 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1308
        {  // 868 MHz BPSK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1309
          m_phyOption = IEEE_802_15_4_868MHZ_BPSK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1310
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1311
      else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
        {  // 915 MHz BPSK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
          m_phyOption = IEEE_802_15_4_915MHZ_BPSK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1314
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1315
      else if (m_phyPIBAttributes.phyCurrentChannel <= 26)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1316
        {  // 2.4 GHz MHz O-QPSK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1317
          m_phyOption = IEEE_802_15_4_2_4GHZ_OQPSK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1318
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1319
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1320
  else if (m_phyPIBAttributes.phyCurrentPage == 1)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1321
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1322
      if (m_phyPIBAttributes.phyCurrentChannel == 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1323
        {  // 868 MHz ASK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1324
          m_phyOption = IEEE_802_15_4_868MHZ_ASK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1325
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1326
      else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1327
        {  // 915 MHz ASK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1328
          m_phyOption = IEEE_802_15_4_915MHZ_ASK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1329
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1330
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1331
  else if (m_phyPIBAttributes.phyCurrentPage == 2)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1332
    {
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1333
      if (m_phyPIBAttributes.phyCurrentChannel == 0)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1334
        {  // 868 MHz O-QPSK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1335
          m_phyOption = IEEE_802_15_4_868MHZ_OQPSK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1336
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1337
      else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1338
        {  // 915 MHz O-QPSK
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1339
          m_phyOption = IEEE_802_15_4_915MHZ_OQPSK;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1340
        }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1341
    }
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1342
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1343
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1344
LrWpanPhyOption
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1345
LrWpanPhy::GetMyPhyOption (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1346
{
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: 10714
diff changeset
  1347
  NS_LOG_FUNCTION (this);
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1348
  return m_phyOption;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1349
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1350
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1351
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1352
LrWpanPhy::SetTxPowerSpectralDensity (Ptr<SpectrumValue> txPsd)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1353
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1354
  NS_LOG_FUNCTION (this << txPsd);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1355
  NS_ASSERT (txPsd);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1356
  m_txPsd = txPsd;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1357
  NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1358
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1359
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1360
void
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1361
LrWpanPhy::SetNoisePowerSpectralDensity (Ptr<const SpectrumValue> noisePsd)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1362
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1363
  NS_LOG_FUNCTION (this << noisePsd);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1364
  NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1365
  NS_ASSERT (noisePsd);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1366
  m_noise = noisePsd;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1367
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1368
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1369
Ptr<const SpectrumValue>
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1370
LrWpanPhy::GetNoisePowerSpectralDensity (void)
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1371
{
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1372
  NS_LOG_FUNCTION (this);
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1373
  return m_noise;
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1374
}
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1375
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1376
void
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1377
LrWpanPhy::SetErrorModel (Ptr<LrWpanErrorModel> e)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1378
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1379
  NS_LOG_FUNCTION (this << e);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1380
  NS_ASSERT (e);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1381
  m_errorModel = e;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1382
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1383
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1384
Ptr<LrWpanErrorModel>
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1385
LrWpanPhy::GetErrorModel (void) const
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1386
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1387
  NS_LOG_FUNCTION (this);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1388
  return m_errorModel;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1389
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents: 10711
diff changeset
  1390
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: 10714
diff changeset
  1391
uint64_t
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1392
LrWpanPhy::GetPhySHRDuration (void) const
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1393
{
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1394
  NS_LOG_FUNCTION (this);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1395
  NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1396
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1397
  return ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
10760
d7d73e3ceb3c Apply utils/check-style.py script on lr-wpan source code again
Tom Henderson <tomh@tomh.org>
parents: 10758
diff changeset
  1398
         + ppduHeaderSymbolNumbers[m_phyOption].shrSfd;
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: 10714
diff changeset
  1399
}
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1400
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1401
double
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1402
LrWpanPhy::GetPhySymbolsPerOctet (void) const
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1403
{
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1404
  NS_LOG_FUNCTION (this);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1405
  NS_ASSERT (m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1406
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1407
  return dataSymbolRates [m_phyOption].symbolRate / (dataSymbolRates [m_phyOption].bitRate / 8);
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1408
}
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10714
diff changeset
  1409
10754
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1410
int64_t
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1411
LrWpanPhy::AssignStreams (int64_t stream)
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1412
{
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1413
  NS_LOG_FUNCTION (this);
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1414
  m_random->SetStream (stream);
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1415
  return 1;
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1416
}
e02848bde991 enable assignment of lr-wpan random variable stream indices
Tom Henderson <tomh@tomh.org>
parents: 10750
diff changeset
  1417
10711
a6dfe3e184c0 Initial lr-wpan checkin
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1418
} // namespace ns3