ns-3 PLC model
model/plc-noise.h
00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
00002 /*
00003  * Copyright (c) 2012 University of British Columbia, Vancouver
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation;
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  * Author: Alexander Schloegl <alexander.schloegl@gmx.de>
00019  */
00020 
00021 #ifndef PLC_NOISE_H_
00022 #define PLC_NOISE_H_
00023 
00024 #include <ns3/simple-ref-count.h>
00025 #include <ns3/random-variable.h>
00026 #include <ns3/spectrum-value.h>
00027 
00028 #include "plc-time.h"
00029 #include "plc-channel.h"
00030 
00031 namespace ns3 {
00032 
00033 #define MAX_PULSE_NOISE_DURATION        1
00034 #define MAX_PULSE_GAP_DURATION          2
00035 
00049 class PLC_ColoredNoiseFloor : public SimpleRefCount<PLC_ColoredNoiseFloor>
00050 {
00051 public:
00052 
00053         PLC_ColoredNoiseFloor(double a, double b, double c, Ptr<const SpectrumModel> sm);
00054 
00055         Ptr<SpectrumValue> GetNoisePsd(void);
00056 
00057 protected:
00058         Ptr<SpectrumValue> m_noisePsd;
00059 };
00060 
00084 class PLC_NoiseSource : public Object
00085 {
00086 public:
00087         static TypeId GetTypeId(void);
00088 
00094         enum NoiseSourceType {
00095                 STATIC,
00096                 TIMEVARIANT,
00097                 IMPULSIVE
00098         };
00099 
00100         PLC_NoiseSource() {}
00101 
00109         PLC_NoiseSource(Ptr<PLC_Node> src_node, Ptr<SpectrumValue> noisePsd, NoiseSourceType type);
00110         virtual ~PLC_NoiseSource() = 0;
00111 
00116         void SetNoisePsd(Ptr<SpectrumValue> psd) { m_noisePsd = psd; }
00117 
00121         Ptr<SpectrumValue> GetNoisePsd(void) { return m_noisePsd; }
00122 
00127         NoiseSourceType GetNoiseSourceType(void);
00128 
00134         void SetNode(Ptr<PLC_Node> node) { m_src_node = node; }
00135 
00139         Ptr<PLC_Node> GetNode(void) { return m_src_node; }
00140 
00145         void SetChannel(Ptr<PLC_Channel> channel) { m_channel = channel; }
00146 
00150         Ptr<PLC_Channel> GetChannel(void) { return m_channel; }
00151 
00159         void Init(void);
00160 
00164         virtual void Enable(void);
00165 
00169         virtual void Disable(void);
00170 
00174         bool IsEnabled(void);
00175 
00176 protected:
00177     // pure virtual dummy function to keep pybindgen happy
00178     virtual void pureVirtualDummy(void) = 0;
00179 
00180         NoiseSourceType m_noise_source_type;
00181         uint32_t m_noise_srcId;
00182         Ptr<PLC_Node> m_src_node;
00183         Ptr<SpectrumValue> m_noisePsd;
00184         Ptr<PLC_Channel> m_channel;
00185         Ptr<PLC_TxInterface> m_txInterface;
00186         bool m_is_enabled;
00187         bool m_is_initialized;
00188 };
00189 
00190 class PLC_StaticNoiseSource : public PLC_NoiseSource
00191 {
00192 public:
00193         static TypeId GetTypeId(void);
00194 
00195         PLC_StaticNoiseSource (Ptr<PLC_Node> src_node, Ptr<SpectrumValue> noisePsd);
00196 
00197         void Start (Time duration);
00198 
00199 protected:
00200     // dummy function to keep pybindgen happy
00201     virtual void pureVirtualDummy(void) {}
00202 
00203 private:
00204         Ptr<SpectrumValue> m_noisePsd;
00205 };
00206 
00207 class PLC_ImpulseNoiseSource : public PLC_NoiseSource
00208 {
00209 public:
00210         static TypeId GetTypeId(void);
00211 
00212         PLC_ImpulseNoiseSource();
00213         PLC_ImpulseNoiseSource(Ptr<PLC_Node> m_src_node, Ptr<SpectrumValue> noisePsd, double p);
00214 
00215         void SetProbability(double p);
00216         double GetProbability(void);
00217 
00218 protected:
00219     // dummy function to keep pybindgen happy
00220     virtual void pureVirtualDummy(void) {}
00221 
00222 private:
00223         double m_p;
00224 };
00225 
00238 class PLC_ImpulsiveNoiseSource : public PLC_NoiseSource
00239 {
00240 public:
00241         static TypeId GetTypeId(void);
00242 
00243         PLC_ImpulsiveNoiseSource();
00244         PLC_ImpulsiveNoiseSource(Ptr<PLC_Node> m_src_node, Ptr<SpectrumValue> noisePsd);
00245 
00252         PLC_ImpulsiveNoiseSource(Ptr<PLC_Node> src_node, Ptr<SpectrumValue> noisePsd, RandomVariable *pulselen_gen, RandomVariable *pulsegap_gen);
00253 
00257         void Enable(void);
00258 
00264         void PulseStart(void);
00265 
00271         void PulseEnd(void);
00272 
00273 protected:
00274     // dummy function to keep pybindgen happy
00275     virtual void pureVirtualDummy(void) {}
00276 
00277 private:
00278         RandomVariable          *m_pulse_len;
00279         RandomVariable          *m_pulse_gap;
00280 };
00281 
00282 }
00283 
00284 #endif /* PLC_NOISE_H_ */
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
 All Classes Functions Variables Enumerations