ns-3 PLC model
|
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_LINK_PERFORMANCE_MODEL_H_ 00022 #define PLC_LINK_PERFORMANCE_MODEL_H_ 00023 00024 #include <map> 00025 #include <ns3/object.h> 00026 #include <ns3/nstime.h> 00027 #include <ns3/traced-value.h> 00028 #include <ns3/trace-source-accessor.h> 00029 #include "plc-defs.h" 00030 #include "plc-interference.h" 00031 #include "plc-dcmc-capacity.h" 00032 00033 namespace ns3 { 00034 00038 class PLC_LinkPerformanceModel : public Object 00039 { 00040 public: 00041 static TypeId GetTypeId (void); 00042 00043 PLC_LinkPerformanceModel (); 00044 PLC_LinkPerformanceModel (Ptr<const SpectrumValue> noiseFloor); 00045 virtual ~PLC_LinkPerformanceModel () = 0; 00046 00047 void SetNoiseFloor(Ptr<const SpectrumValue> noiseFloor); 00048 double GetTotalRxPower(void); 00049 double GetTotalNoisePower(void); 00050 00051 void StartRx(ModulationAndCodingType mcs, Ptr<const SpectrumValue> rxPsd, double requiredInformationBits = 0); 00052 void AlterRxSignal(Ptr<const SpectrumValue> rxPsd); 00053 void AddNoiseSignal(Ptr<const SpectrumValue> noisePsd); 00054 void RemoveNoiseSignal(Ptr<const SpectrumValue> noisePsd); 00055 void EvaluateChunk(void); 00056 bool EndRx(void); 00057 00058 void SetSinrBase(Ptr<const SpectrumValue> sinrBase); 00059 00060 Ptr<PLC_Interference> GetInterference(void) { return m_interference; } 00061 00062 protected: 00063 virtual void DoDispose(void); 00064 virtual void DoStartRx(double requiredInformationBits) = 0; 00065 virtual void DoEvaluateChunk(void) = 0; 00066 virtual bool DoEndRx(void) = 0; 00067 00068 bool m_receiving; 00069 ModulationAndCodingType m_mcs; 00070 Time m_lastChangeTime; 00071 Ptr<PLC_Interference> m_interference; 00072 00073 TracedCallback<Time, Ptr<const SpectrumValue> > m_sinrTracer; 00074 }; 00075 00083 class PLC_ErrorRateModel : public PLC_LinkPerformanceModel 00084 { 00085 public: 00086 enum ChannelCondition 00087 { 00088 EXCELLENT = 0, 00089 GOOD = 1, 00090 MEDIUM = 2, 00091 BAD = 3 00092 }; 00093 00094 static TypeId GetTypeId (void); 00095 00096 PLC_ErrorRateModel(); 00097 PLC_ErrorRateModel(Time block_duration); 00098 00099 void SetChannelCondition(ChannelCondition cond); 00100 void SetBlockDuration(Time duration) { m_block_duration = duration; } 00101 Time GetBlockDuration(void) { return m_block_duration; } 00102 00103 private: 00104 static double s_A[8][3]; 00105 static double s_B[8][3]; 00106 00107 void DoStartRx(double requiredInformationBits); 00108 void DoEvaluateChunk(void); 00109 bool DoEndRx(void); 00110 00111 double GetChunkSuccessRate(uint32_t numBlocks); 00112 double GetBler(ModulationAndCodingType mcs, SpectrumValue& sinr); 00113 00114 Time m_block_duration; 00115 double m_packet_success_rate; 00116 ChannelCondition m_channel_condition; 00117 }; 00118 00122 class PLC_InformationRateModel : public PLC_LinkPerformanceModel 00123 { 00124 public: 00125 struct McsInfo 00126 { 00127 Modulation mod; 00128 short cardinality; 00129 double code_rate; 00130 }; 00131 00132 static TypeId GetTypeId (void); 00133 00134 PLC_InformationRateModel(); 00135 00136 void SetIneffectiveTimeProportion(double prop); 00137 double GetGatheredMutualInformation(void) { return m_gathered_information_bits; } 00138 00139 private: 00140 static McsInfo s_mcs_info[8]; 00141 00142 void DoStartRx(double requiredInformationBits); 00143 void DoEvaluateChunk(void); 00144 bool DoEndRx(void); 00145 00146 double m_ineffective_time_proportion; 00147 double m_required_information_bits; 00148 double m_gathered_information_bits; 00149 }; 00150 00151 } 00152 00153 #endif /* PLC_LINK_PERFORMANCE_MODEL_H_ */