View | Details | Raw Unified | Return to bug 962
Collapse All | Expand All

(-)52904cc0aa8a (+52 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c)  2011 CTTC
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Nicola Baldo <nbaldo@cttc.es>
19
 */
20
21
22
#include "generic-phy.h"
23
#include <ns3/log.h>
24
25
26
NS_LOG_COMPONENT_DEFINE ("GenericPhy");
27
28
namespace ns3 {
29
30
31
NS_OBJECT_ENSURE_REGISTERED (GenericPhy);
32
33
34
GenericPhy::GenericPhy ()
35
{
36
  NS_LOG_FUNCTION (this);
37
}
38
39
TypeId
40
GenericPhy::GetTypeId (void)
41
{
42
  static TypeId tid = TypeId ("ns3::GenericPhy")
43
    .SetParent<Object> ()
44
  ;
45
  return tid;
46
}
47
48
GenericPhy::~GenericPhy ()
49
{
50
}
51
52
} // namespace ns3
(-)a/src/network/utils/generic-phy.h (-1 / +27 lines)
 Lines 1-6    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
2
/*
3
 * Copyright (c)  2010 CTTC
3
 * Copyright (c)  2010,2011 CTTC
4
 *
4
 *
5
 * This program is free software; you can redistribute it and/or modify
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
6
 * it under the terms of the GNU General Public License version 2 as
 Lines 22-30    Link Here 
22
#define GENERIC_PHY_H
22
#define GENERIC_PHY_H
23
23
24
#include <ns3/callback.h>
24
#include <ns3/callback.h>
25
#include <ns3/object.h>
25
26
26
namespace ns3 {
27
namespace ns3 {
27
28
29
class Packet;
28
30
29
/**
31
/**
30
 * This method allows the MAC to instruct the PHY to start a
32
 * This method allows the MAC to instruct the PHY to start a
 Lines 67-72    Link Here 
67
 */
69
 */
68
typedef Callback< void, Ptr<Packet> > GenericPhyRxEndOkCallback;
70
typedef Callback< void, Ptr<Packet> > GenericPhyRxEndOkCallback;
69
71
72
73
/**
74
 * The GenericPhy Object is provided as a base class for all objects
75
 * that use the GenericPhy interface. The purpose of having such an
76
 * object is to allow making any PHY object that uses the GenericPhy
77
 * interface reachable through the attribute system via an upper
78
 * layer object (such as NetDevice), but without resorting to an
79
 * opaque Ptr<Object> which would give some problems.
80
 * See https://www.nsnam.org/bugzilla/show_bug.cgi?id=962 for the
81
 * related discussion.
82
 * 
83
 */
84
class GenericPhy : public Object
85
{
86
public:
87
  GenericPhy ();
88
  virtual ~GenericPhy ();
89
90
  // inherited from Object
91
  static TypeId GetTypeId (void);
92
};
93
94
95
70
} // namespace ns3
96
} // namespace ns3
71
97
72
98
(-)a/src/network/wscript (+1 lines)
 Lines 45-50    Link Here 
45
        'utils/packet-socket-factory.cc',
45
        'utils/packet-socket-factory.cc',
46
        'utils/pcap-file.cc',
46
        'utils/pcap-file.cc',
47
        'utils/pcap-file-wrapper.cc',
47
        'utils/pcap-file-wrapper.cc',
48
        'utils/generic-phy.cc',
48
        'utils/queue.cc',
49
        'utils/queue.cc',
49
        'utils/radiotap-header.cc',
50
        'utils/radiotap-header.cc',
50
        'utils/simple-channel.cc',
51
        'utils/simple-channel.cc',
(-)a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc (-1 / +1 lines)
 Lines 110-116    Link Here 
110
      Ptr<HalfDuplexIdealPhy>  phy = (m_phy.Create ())->GetObject<HalfDuplexIdealPhy> ();
110
      Ptr<HalfDuplexIdealPhy>  phy = (m_phy.Create ())->GetObject<HalfDuplexIdealPhy> ();
111
      NS_ASSERT (phy);
111
      NS_ASSERT (phy);
112
112
113
      dev->SetPhy (phy);
113
      dev->SetPhy (phy->GetObject<GenericPhy> ());
114
114
115
      NS_ASSERT (node);
115
      NS_ASSERT (node);
116
      phy->SetMobility (node->GetObject<MobilityModel> ());
116
      phy->SetMobility (node->GetObject<MobilityModel> ());
(-)a/src/spectrum/helper/spectrum-analyzer-helper.cc (-1 / +3 lines)
 Lines 29-34    Link Here 
29
#include "ns3/non-communicating-net-device.h"
29
#include "ns3/non-communicating-net-device.h"
30
#include "ns3/output-stream-wrapper.h"
30
#include "ns3/output-stream-wrapper.h"
31
#include "ns3/trace-helper.h"
31
#include "ns3/trace-helper.h"
32
#include "ns3/generic-phy.h"
33
32
#include "spectrum-analyzer-helper.h"
34
#include "spectrum-analyzer-helper.h"
33
35
34
36
 Lines 139-145    Link Here 
139
      Ptr<SpectrumAnalyzer>  phy = m_phy.Create ()->GetObject<SpectrumAnalyzer> ();
141
      Ptr<SpectrumAnalyzer>  phy = m_phy.Create ()->GetObject<SpectrumAnalyzer> ();
140
      NS_ASSERT (phy);
142
      NS_ASSERT (phy);
141
143
142
      dev->SetPhy (phy);
144
      dev->SetPhy (phy->GetObject<GenericPhy> ());
143
145
144
      NS_ASSERT (node);
146
      NS_ASSERT (node);
145
      phy->SetMobility (node->GetObject<MobilityModel> ());
147
      phy->SetMobility (node->GetObject<MobilityModel> ());
(-)a/src/spectrum/helper/waveform-generator-helper.cc (-1 / +2 lines)
 Lines 27-32    Link Here 
27
#include "ns3/spectrum-channel.h"
27
#include "ns3/spectrum-channel.h"
28
#include "ns3/waveform-generator.h"
28
#include "ns3/waveform-generator.h"
29
#include "ns3/non-communicating-net-device.h"
29
#include "ns3/non-communicating-net-device.h"
30
#include "ns3/generic-phy.h"
30
#include "waveform-generator-helper.h"
31
#include "waveform-generator-helper.h"
31
32
32
33
 Lines 95-101    Link Here 
95
      Ptr<WaveformGenerator>  phy = m_phy.Create ()->GetObject<WaveformGenerator> ();
96
      Ptr<WaveformGenerator>  phy = m_phy.Create ()->GetObject<WaveformGenerator> ();
96
      NS_ASSERT (phy);
97
      NS_ASSERT (phy);
97
98
98
      dev->SetPhy (phy);
99
      dev->SetPhy (phy->GetObject<GenericPhy> ());
99
100
100
      NS_ASSERT (node);
101
      NS_ASSERT (node);
101
      phy->SetMobility (node->GetObject<MobilityModel> ());
102
      phy->SetMobility (node->GetObject<MobilityModel> ());
(-)a/src/spectrum/model/aloha-noack-net-device.cc (-3 / +3 lines)
 Lines 82-88    Link Here 
82
                   PointerValue (),
82
                   PointerValue (),
83
                   MakePointerAccessor (&AlohaNoackNetDevice::GetPhy,
83
                   MakePointerAccessor (&AlohaNoackNetDevice::GetPhy,
84
                                        &AlohaNoackNetDevice::SetPhy),
84
                                        &AlohaNoackNetDevice::SetPhy),
85
                   MakePointerChecker<Object> ())
85
                   MakePointerChecker<GenericPhy> ())
86
    .AddTraceSource ("MacTx",
86
    .AddTraceSource ("MacTx",
87
                     "Trace source indicating a packet has arrived for transmission by this device",
87
                     "Trace source indicating a packet has arrived for transmission by this device",
88
                     MakeTraceSourceAccessor (&AlohaNoackNetDevice::m_macTxTrace))
88
                     MakeTraceSourceAccessor (&AlohaNoackNetDevice::m_macTxTrace))
 Lines 248-261    Link Here 
248
}
248
}
249
249
250
void
250
void
251
AlohaNoackNetDevice::SetPhy (Ptr<Object> phy)
251
AlohaNoackNetDevice::SetPhy (Ptr<GenericPhy> phy)
252
{
252
{
253
  NS_LOG_FUNCTION (this << phy);
253
  NS_LOG_FUNCTION (this << phy);
254
  m_phy = phy;
254
  m_phy = phy;
255
}
255
}
256
256
257
257
258
Ptr<Object>
258
Ptr<GenericPhy>
259
AlohaNoackNetDevice::GetPhy () const
259
AlohaNoackNetDevice::GetPhy () const
260
{
260
{
261
  NS_LOG_FUNCTION (this);
261
  NS_LOG_FUNCTION (this);
(-)a/src/spectrum/model/aloha-noack-net-device.h (-3 / +3 lines)
 Lines 137-148    Link Here 
137
   * callbacks, so we do not require that the PHY inherits by any
137
   * callbacks, so we do not require that the PHY inherits by any
138
   * specific class.
138
   * specific class.
139
   */
139
   */
140
  void SetPhy (Ptr<Object> phy);
140
  void SetPhy (Ptr<GenericPhy> phy);
141
141
142
  /**
142
  /**
143
   * @return a reference to the PHY object embedded in this NetDevice.
143
   * @return a reference to the PHY object embedded in this NetDevice.
144
   */
144
   */
145
  Ptr<Object> GetPhy () const;
145
  Ptr<GenericPhy> GetPhy () const;
146
146
147
147
148
148
 Lines 221-227    Link Here 
221
221
222
  Ptr<Packet> m_currentPkt;
222
  Ptr<Packet> m_currentPkt;
223
223
224
  Ptr<Object> m_phy;
224
  Ptr<GenericPhy> m_phy;
225
};
225
};
226
226
227
227
(-)a/src/spectrum/model/half-duplex-ideal-phy.cc (+5 lines)
 Lines 45-50    Link Here 
45
    m_state (IDLE)
45
    m_state (IDLE)
46
{
46
{
47
  m_interference.SetErrorModel (CreateObject<ShannonSpectrumErrorModel> ());
47
  m_interference.SetErrorModel (CreateObject<ShannonSpectrumErrorModel> ());
48
  // this allows to mark this object as being convertable to
49
  // GenericPhy (i.e., calling GetObject<GenericPhy> () returns
50
  // non-null) without inheriting from it (which would require
51
  // multiple inheritance)  
52
  AggregateObject (CreateObject<GenericPhy> ());
48
}
53
}
49
54
50
55
(-)a/src/spectrum/model/non-communicating-net-device.cc (-3 / +4 lines)
 Lines 26-31    Link Here 
26
#include "ns3/uinteger.h"
26
#include "ns3/uinteger.h"
27
#include "ns3/pointer.h"
27
#include "ns3/pointer.h"
28
#include "ns3/channel.h"
28
#include "ns3/channel.h"
29
#include "ns3/generic-phy.h"
29
#include "non-communicating-net-device.h"
30
#include "non-communicating-net-device.h"
30
31
31
32
 Lines 48-54    Link Here 
48
                   PointerValue (),
49
                   PointerValue (),
49
                   MakePointerAccessor (&NonCommunicatingNetDevice::GetPhy,
50
                   MakePointerAccessor (&NonCommunicatingNetDevice::GetPhy,
50
                                        &NonCommunicatingNetDevice::SetPhy),
51
                                        &NonCommunicatingNetDevice::SetPhy),
51
                   MakePointerChecker<Object> ())
52
                   MakePointerChecker<GenericPhy> ())
52
  ;
53
  ;
53
  return tid;
54
  return tid;
54
}
55
}
 Lines 181-194    Link Here 
181
}
182
}
182
183
183
void
184
void
184
NonCommunicatingNetDevice::SetPhy (Ptr<Object> phy)
185
NonCommunicatingNetDevice::SetPhy (Ptr<GenericPhy> phy)
185
{
186
{
186
  NS_LOG_FUNCTION (this << phy);
187
  NS_LOG_FUNCTION (this << phy);
187
  m_phy = phy;
188
  m_phy = phy;
188
}
189
}
189
190
190
191
191
Ptr<Object>
192
Ptr<GenericPhy>
192
NonCommunicatingNetDevice::GetPhy () const
193
NonCommunicatingNetDevice::GetPhy () const
193
{
194
{
194
  NS_LOG_FUNCTION (this);
195
  NS_LOG_FUNCTION (this);
(-)a/src/spectrum/model/non-communicating-net-device.h (-4 / +4 lines)
 Lines 37-43    Link Here 
37
class Channel;
37
class Channel;
38
class SpectrumErrorModel;
38
class SpectrumErrorModel;
39
class Queue;
39
class Queue;
40
40
class GenericPhy;
41
41
42
42
43
/**
43
/**
 Lines 79-90    Link Here 
79
   *
79
   *
80
   * @param phy the Phy object embedded within this device.
80
   * @param phy the Phy object embedded within this device.
81
   */
81
   */
82
  void SetPhy (Ptr<Object> phy);
82
  void SetPhy (Ptr<GenericPhy> phy);
83
83
84
  /**
84
  /**
85
   * @return a reference to the PHY object embedded in this NetDevice.
85
   * @return a reference to the PHY object embedded in this NetDevice.
86
   */
86
   */
87
  Ptr<Object> GetPhy () const;
87
  Ptr<GenericPhy> GetPhy () const;
88
88
89
89
90
90
 Lines 128-134    Link Here 
128
128
129
  uint32_t m_ifIndex;
129
  uint32_t m_ifIndex;
130
130
131
  Ptr<Object> m_phy;
131
  Ptr<GenericPhy> m_phy;
132
};
132
};
133
133
134
134
(-)a/src/spectrum/model/spectrum-analyzer.cc (+6 lines)
 Lines 24-29    Link Here 
24
#include <ns3/double.h>
24
#include <ns3/double.h>
25
#include <ns3/simulator.h>
25
#include <ns3/simulator.h>
26
#include <ns3/trace-source-accessor.h>
26
#include <ns3/trace-source-accessor.h>
27
#include <ns3/generic-phy.h>
27
28
28
NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer");
29
NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer");
29
30
 Lines 41-46    Link Here 
41
    m_active (false)
42
    m_active (false)
42
{
43
{
43
  NS_LOG_FUNCTION (this);
44
  NS_LOG_FUNCTION (this);
45
  // this allows to mark this object as being convertable to
46
  // GenericPhy (i.e., calling GetObject<GenericPhy> () returns
47
  // non-null) without inheriting from it (which would require
48
  // multiple inheritance)  
49
  AggregateObject (CreateObject<GenericPhy> ());
44
}
50
}
45
51
46
52
(-)a/src/spectrum/model/waveform-generator.cc (-2 / +6 lines)
 Lines 24-30    Link Here 
24
#include <ns3/simulator.h>
24
#include <ns3/simulator.h>
25
#include <ns3/double.h>
25
#include <ns3/double.h>
26
#include <ns3/packet-burst.h>
26
#include <ns3/packet-burst.h>
27
27
#include <ns3/generic-phy.h>
28
28
29
NS_LOG_COMPONENT_DEFINE ("WaveformGenerator");
29
NS_LOG_COMPONENT_DEFINE ("WaveformGenerator");
30
30
 Lines 40-46    Link Here 
40
    m_startTime (Seconds (0)),
40
    m_startTime (Seconds (0)),
41
    m_active (false)
41
    m_active (false)
42
{
42
{
43
43
  // this allows to mark this object as being convertable to
44
  // GenericPhy (i.e., calling GetObject<GenericPhy> () returns
45
  // non-null) without inheriting from it (which would require
46
  // multiple inheritance)  
47
  AggregateObject (CreateObject<GenericPhy> ());
44
}
48
}
45
49
46
50
(-)a/src/spectrum/test/spectrum-ideal-phy-test.cc (-1 / +1 lines)
 Lines 192-198    Link Here 
192
  apps.Start (Seconds (0.0));
192
  apps.Start (Seconds (0.0));
193
  apps.Stop (Seconds (testDuration));
193
  apps.Stop (Seconds (testDuration));
194
194
195
  Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxEndOk", MakeCallback (&PhyRxEndOkTrace));
195
  Config::Connect ("/NodeList/*/DeviceList/*/Phy/$ns3::HalfDuplexIdealPhy/RxEndOk", MakeCallback (&PhyRxEndOkTrace));
196
196
197
  g_rxBytes = 0;
197
  g_rxBytes = 0;
198
  Simulator::Stop (Seconds (testDuration+0.000000001));
198
  Simulator::Stop (Seconds (testDuration+0.000000001));

Return to bug 962