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_INTERFACE_H_ 00022 #define PLC_INTERFACE_H_ 00023 00024 #include <map> 00025 00026 #include <ns3/node.h> 00027 #include <ns3/spectrum-model.h> 00028 #include <ns3/plc-graph.h> 00029 #include <ns3/plc-backbone.h> 00030 #include <ns3/plc-defs.h> 00031 #include <ns3/packet-burst.h> 00032 #include <ns3/spectrum-value.h> 00033 #include <ns3/traced-callback.h> 00034 #include <ns3/data-rate.h> 00035 #include <ns3/event-id.h> 00036 00037 #include "plc-phy.h" 00038 00039 namespace ns3 { 00040 00041 class PLC_Node; 00042 class PLC_Outlet; 00043 class PLC_Graph; 00044 class PLC_BackboneBranch; 00045 class PLC_ChannelTransferImpl; 00046 class PLC_Channel; 00047 class PLC_Phy; 00048 class PLC_TrxMetaInfo; 00049 00059 class PLC_Interface : public Object 00060 { 00061 public: 00062 static TypeId GetTypeId(void); 00063 00069 PLC_Interface(Ptr<PLC_Node> associated_plc_node, Ptr<const SpectrumModel> sm); 00070 virtual ~PLC_Interface() = 0; 00071 00075 Ptr<PLC_Graph> GetGraph(void); 00076 00080 Ptr<PLC_Channel> GetChannel(void); 00081 00086 void SetPhy(Ptr<PLC_Phy> phy); 00087 00091 Ptr<PLC_Phy> GetPhy(void); 00092 00097 void SetNode(Ptr<PLC_Node> node) { this->m_plc_node = node; } 00098 00102 Ptr<PLC_Node> GetNode(void) const { return m_plc_node; } 00103 PLC_Node *GetNodePeekPointer(void) const { return PeekPointer(m_plc_node); } 00104 00108 void Lock(void) { m_mutex.Lock(); } 00109 void Unlock(void) { m_mutex.Unlock(); } 00110 00111 protected: 00112 // pure virtual dummy function to keep pybindgen happy 00113 virtual void pureVirtualDummy(void) = 0; 00114 virtual void DoDispose(void); 00115 00116 mutable PLC_Mutex m_mutex; 00117 Ptr<PLC_Node> m_plc_node; 00118 Ptr<const SpectrumModel> m_spectrum_model; 00119 Ptr<PLC_Phy> m_phy; 00120 }; 00121 00127 class PLC_TxInterface : public PLC_Interface 00128 { 00129 friend class PLC_Outlet; 00130 00131 public: 00132 static TypeId GetTypeId(void); 00133 00139 PLC_TxInterface(Ptr<PLC_Node> associated_plc_node, Ptr<const SpectrumModel> sm); 00140 ~PLC_TxInterface() {} 00141 00146 void SetIdx(uint32_t idx) { m_txIfIdx = idx; } 00147 00151 uint32_t GetTxIfIdx(void) const; 00152 00156 Ptr<const SpectrumValue> GetTxPsd(void) { return m_txPsd; } 00157 00163 void InitializeChannelTransferImpls(void); 00164 00170 void CalculateChannels(void); 00171 00177 PLC_ChannelTransferImpl *GetChannelTransferImpl(PLC_RxInterface *rxInterface); 00178 00185 std::list<PLC_BackboneBranch *> GetBackbonePath(PLC_RxInterface *sink); 00186 00191 PLC_BackbonePath::iterator BackbonePathBegin(PLC_RxInterface *sink); 00192 00197 PLC_BackbonePath::iterator BackbonePathEnd(PLC_RxInterface *sink); 00198 00205 void StartTx(Ptr<const Packet> p, Ptr<const SpectrumValue> txPsd, Time duration, Ptr<const PLC_TrxMetaInfo> metaInfo); 00206 00207 private: 00208 // virtual dummy function to keep pybindgen happy 00209 virtual void pureVirtualDummy(void) {} 00210 virtual void DoStart(void); 00211 virtual void DoDispose(void); 00212 00213 // currently all rx interfaces are taken into account 00214 // even if they are too far away 00215 bool IsWithinRange(PLC_RxInterface *rxInterface); 00216 bool IsCenterFreqWithinRange(PLC_RxInterface *rxInterface); 00217 00218 void RegisterRxInterface(PLC_RxInterface *rxInterface); 00219 00220 // called by PLC_Outlet 00221 void SetChannelTransferImplsOutOfDate(void); 00222 void SetTimeVariantChannel(PLC_RxInterface *rx); 00223 00224 bool m_all_bb_up2date; 00225 uint32_t m_txIfIdx; 00226 Ptr<const SpectrumValue> m_txPsd; 00227 std::map<PLC_RxInterface *, Ptr<PLC_ChannelTransferImpl> > m_channel_transfer_impls; 00228 }; 00229 00235 class PLC_RxInterface : public PLC_Interface 00236 { 00237 public: 00238 static TypeId GetTypeId(void); 00239 00245 PLC_RxInterface(Ptr<PLC_Node> associated_node, Ptr<const SpectrumModel> sm); 00246 ~PLC_RxInterface() {} 00247 00252 void SetIdx(uint32_t idx) { m_rxIfIdx = idx; } 00253 00257 uint32_t GetRxIfIdx(void) const; 00258 00263 void SetOutlet(Ptr<PLC_Outlet> outlet); 00264 00268 Ptr<PLC_Outlet> GetOutlet(void) { return m_outlet; } 00269 00277 void StartRx(Ptr<const Packet> p, uint32_t txId, Ptr<SpectrumValue>& rxPsd, Time duration, Ptr<const PLC_TrxMetaInfo> metaInfo); 00278 00284 void RxPsdChanged(uint32_t txId, Ptr<SpectrumValue> rxSignal); 00285 00286 private: 00287 // virtual dummy function to keep pybindgen happy 00288 virtual void pureVirtualDummy(void) {} 00289 virtual void DoStart(void); 00290 virtual void DoDispose(void); 00291 00292 Ptr<PLC_Outlet> m_outlet; 00293 00294 bool m_is_up_2_date; 00295 uint32_t m_rxIfIdx; 00296 }; 00297 00298 } // namespace ns3 00299 00300 #endif /* PLC_INTERFACE_H_ */